Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fill empty months in timeline chart #910

Merged
merged 3 commits into from
Aug 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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