Skip to content

Commit

Permalink
Merge pull request #910 from biigle/addMonthWithoutAnnotations
Browse files Browse the repository at this point in the history
 Fill empty months in timeline chart
  • Loading branch information
mzur authored Aug 22, 2024
2 parents 99bbd57 + edd7dc1 commit 7f3cefe
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions resources/assets/js/projects/components/charts/timelinePlot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,30 @@ export default {
let xAxis = this.annotationTimeSeries.map((entry) => {
return entry.yearmonth.toString();
});
// sort the yearmonths entries
xAxis = xAxis.sort();
// filter duplicated yearsmonth
xAxis = [...new Set(xAxis)];
// fill in the missing yearmonths
for (let i = 0; i < xAxis.length - 1; i++) {
let currentYearMonth = xAxis[i];
let nextYearMonth = xAxis[i + 1];
let currentDate = new Date(currentYearMonth);
let nextDate = new Date(nextYearMonth);
while (currentDate.getMonth() < nextDate.getMonth() - 1 || currentDate.getFullYear() < nextDate.getFullYear()) {
currentDate.setMonth(currentDate.getMonth() + 1);
let year = currentDate.getFullYear();
let month = currentDate.getMonth() + 1;
let yearMonth = year + '-' + (month < 10 ? '0' + month : month);
xAxis.splice(i + 1, 0, yearMonth);
i++;
}
}
// sort the years (increasing)
return xAxis.sort();
return xAxis;
},
},
computed: {
Expand Down Expand Up @@ -118,11 +137,12 @@ export default {
}
idDict[id] = yearDict;
}
// console.log('xAxis: ', xAxis);
// console.log('ID: ', id_unique);
// assemble the annotations of each user in correct order of year
// each user has its own year-timeseries in idDict (e.g. {id: {"2020":10, "2021":4, "2022":6]})
for (let yearmonth of xAxis) {
for (let entry of dat) {
if (entry.yearmonth.toString() === yearmonth) {
Expand Down

0 comments on commit 7f3cefe

Please sign in to comment.