From 2f5564b06fb5e041c3b36462aec9b3ebda08110d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Langenk=C3=A4mper?= Date: Thu, 22 Aug 2024 12:14:41 +0200 Subject: [PATCH 1/3] fill in the missing yearmonths --- .../components/charts/timelinePlot.vue | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/resources/assets/js/projects/components/charts/timelinePlot.vue b/resources/assets/js/projects/components/charts/timelinePlot.vue index 39815a6b4..69a957072 100644 --- a/resources/assets/js/projects/components/charts/timelinePlot.vue +++ b/resources/assets/js/projects/components/charts/timelinePlot.vue @@ -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 < nextDate) { + 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: { @@ -123,6 +142,7 @@ export default { // 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) { @@ -132,6 +152,7 @@ export default { } } } + console.log('idDict: ', idDict); // setup of whole chartdata object // include axis-name in front @@ -142,6 +163,7 @@ export default { // reduce user-timeseries to values only Object.entries(idDict).forEach(entry => { + console.log('entry: ', entry); // calculate the sum over all years and include in the array on position 0 let sum = 0; Object.values(entry[1]).forEach(val => { @@ -156,6 +178,7 @@ export default { chartdata.push([sum, name, ...Object.values(entry[1]),userid]); } }); + console.log('chartdata: ', chartdata); return chartdata; }, createTimelineSeries() { From 48329f8cbbf03aa7be6524500943f6f8e8d3364d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Langenk=C3=A4mper?= Date: Thu, 22 Aug 2024 13:37:47 +0200 Subject: [PATCH 2/3] remove debug msgs --- .../assets/js/projects/components/charts/timelinePlot.vue | 3 --- 1 file changed, 3 deletions(-) diff --git a/resources/assets/js/projects/components/charts/timelinePlot.vue b/resources/assets/js/projects/components/charts/timelinePlot.vue index 69a957072..3391f0c03 100644 --- a/resources/assets/js/projects/components/charts/timelinePlot.vue +++ b/resources/assets/js/projects/components/charts/timelinePlot.vue @@ -152,7 +152,6 @@ export default { } } } - console.log('idDict: ', idDict); // setup of whole chartdata object // include axis-name in front @@ -163,7 +162,6 @@ export default { // reduce user-timeseries to values only Object.entries(idDict).forEach(entry => { - console.log('entry: ', entry); // calculate the sum over all years and include in the array on position 0 let sum = 0; Object.values(entry[1]).forEach(val => { @@ -178,7 +176,6 @@ export default { chartdata.push([sum, name, ...Object.values(entry[1]),userid]); } }); - console.log('chartdata: ', chartdata); return chartdata; }, createTimelineSeries() { From edd7dc1a92390f58a72b0cad963bab4e659ca99b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Langenk=C3=A4mper?= Date: Thu, 22 Aug 2024 13:56:24 +0200 Subject: [PATCH 3/3] fixed too many month that were added --- .../assets/js/projects/components/charts/timelinePlot.vue | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/resources/assets/js/projects/components/charts/timelinePlot.vue b/resources/assets/js/projects/components/charts/timelinePlot.vue index 3391f0c03..4da1edbd5 100644 --- a/resources/assets/js/projects/components/charts/timelinePlot.vue +++ b/resources/assets/js/projects/components/charts/timelinePlot.vue @@ -91,14 +91,14 @@ export default { // 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 < nextDate) { + while (currentDate.getMonth() < nextDate.getMonth() - 1 || currentDate.getFullYear() < nextDate.getFullYear()) { currentDate.setMonth(currentDate.getMonth() + 1); let year = currentDate.getFullYear(); let month = currentDate.getMonth() + 1; @@ -137,8 +137,8 @@ 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]})