Skip to content
This repository was archived by the owner on Mar 30, 2024. It is now read-only.

Commit 173cd7b

Browse files
committed
Graphs -- single category shows tasks
1 parent f81be04 commit 173cd7b

File tree

4 files changed

+43
-15
lines changed

4 files changed

+43
-15
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
latest
2-
0.3.1
2+
0.3.2
33
0.3
44
0

php/load/graphs/BarDailyWork.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ function createGraph(combiData, plainData, singleDayData, canvas){
1717
var minDate = Number.MAX_SAFE_INTEGER;
1818
var maxDate = Number.MIN_SAFE_INTEGER;
1919
var allCategories = {}
20+
var allNames = {}
2021
plainData.forEach(data => {
2122
if( data.begin < minDate ){
2223
minDate = data.begin;
@@ -27,25 +28,36 @@ function createGraph(combiData, plainData, singleDayData, canvas){
2728
if( !allCategories.hasOwnProperty(data.category)){
2829
allCategories[data.category] = 0;
2930
}
31+
if( !allNames.hasOwnProperty(data.name)){
32+
allNames[data.name] = 0;
33+
}
3034
});
35+
if(Object.keys(allCategories).length === 1){
36+
var catsColumn = 'name';
37+
var allCats = allNames;
38+
}
39+
else{
40+
var catsColumn = 'category';
41+
var allCats = allCategories;
42+
}
3143

3244
// fill (empty) categories in each day
3345
let plotdata = {};
3446
let plotdataLabels = [];
3547
for( let timestamp = minDate; timestamp <= maxDate; timestamp += 86400){
3648
let label = getLabelFromTimestamp(timestamp);
37-
plotdata[label] = Object.assign({}, allCategories);
49+
plotdata[label] = Object.assign({}, allCats);
3850
plotdataLabels.push(label)
3951
}
4052
let lastLabel = getLabelFromTimestamp(maxDate);
4153
if( !plotdata.hasOwnProperty(lastLabel)){
42-
plotdata[lastLabel] = Object.assign({}, allCategories);
54+
plotdata[lastLabel] = Object.assign({}, allCats);
4355
plotdataLabels.push(lastLabel)
4456
}
4557

4658
// fill with data
4759
plainData.forEach(data => {
48-
plotdata[getLabelFromTimestamp(data.begin)][data.category] += data.duration;
60+
plotdata[getLabelFromTimestamp(data.begin)][data[catsColumn]] += data.duration;
4961
});
5062

5163
// convert to hours

php/load/graphs/BarDayTimes.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ function createGraph(combiData, plainData, singleDayData, canvas){
55
* The function should return the ChartJS object.
66
*/
77

8+
var allCategories = []
9+
plainData.forEach(data => {
10+
if( !allCategories.includes(data.category) ) {
11+
allCategories.push(data.category)
12+
}
13+
});
14+
var catsColumn = allCategories.length === 1 ? 'name' : 'category';
15+
816
var plotdata = {}
917
plainData.forEach( (v) => {
1018
var begin = new Date(v.begin*1000);
@@ -16,24 +24,24 @@ function createGraph(combiData, plainData, singleDayData, canvas){
1624
var secondsEnd = end.getMinutes() * 60 + end.getSeconds();
1725

1826
for( var hour = hourBegin; hour <= hourEnd; hour++){
19-
if( !plotdata.hasOwnProperty(v.category)){
20-
plotdata[v.category] = []
27+
if( !plotdata.hasOwnProperty(v[catsColumn])){
28+
plotdata[v[catsColumn]] = []
2129
for(var h = 0; h < 24; h++){
22-
plotdata[v.category][h] = 0;
30+
plotdata[v[catsColumn]][h] = 0;
2331
}
2432
}
2533

2634
if( hour !== hourEnd && hour !== hourBegin ){
27-
plotdata[v.category][hour] += 3600;
35+
plotdata[v[catsColumn]][hour] += 3600;
2836
}
2937
else if (hour === hourBegin && hour === hourEnd ){
30-
plotdata[v.category][hour] += v.duration;
38+
plotdata[v[catsColumn]][hour] += v.duration;
3139
}
3240
else if( hour === hourEnd ){
33-
plotdata[v.category][hour] += secondsEnd;
41+
plotdata[v[catsColumn]][hour] += secondsEnd;
3442
}
3543
else if( hour === hourBegin){
36-
plotdata[v.category][hour] += 3600 - secondsBegin;
44+
plotdata[v[catsColumn]][hour] += 3600 - secondsBegin;
3745
}
3846
}
3947
});

php/load/graphs/BarDays.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,24 @@ function createGraph(combiData, plainData, singleDayData, canvas){
55
* The function should return the ChartJS object.
66
*/
77

8+
var allCategories = []
9+
plainData.forEach(data => {
10+
if( !allCategories.includes(data.category) ) {
11+
allCategories.push(data.category)
12+
}
13+
});
14+
var catsColumn = allCategories.length === 1 ? 'name' : 'category';
15+
816
var plotdata = {}
917
plainData.forEach( (v) => {
1018
var day = new Date(v.begin*1000).getDay();
11-
if( !plotdata.hasOwnProperty(v.category)){
12-
plotdata[v.category] = []
19+
if( !plotdata.hasOwnProperty(v[catsColumn])){
20+
plotdata[v[catsColumn]] = []
1321
for(var d = 0; d < 7; d++){
14-
plotdata[v.category][d] = 0;
22+
plotdata[v[catsColumn]][d] = 0;
1523
}
1624
}
17-
plotdata[v.category][day] += v.duration;
25+
plotdata[v[catsColumn]][day] += v.duration;
1826
});
1927

2028
Object.keys(plotdata).forEach(function(category) {

0 commit comments

Comments
 (0)