From 8ee6565bb452bc522c20de488623e3ff514c1046 Mon Sep 17 00:00:00 2001 From: Rello Date: Sun, 14 Sep 2025 00:09:05 +0700 Subject: [PATCH] Fix time aggregation index after drilldown --- CHANGELOG.md | 1 + js/visualization.js | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0591f9d9..8ced2452 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - date formatting on all rows - fix double report execution after wizard close - correct drilldown aggregation for numeric dimension indices +- adjust time aggregation dimension after drilldown ## 5.8.0 - 2025-07-29 ### Added diff --git a/js/visualization.js b/js/visualization.js index 74dd966d..8b1f58c0 100644 --- a/js/visualization.js +++ b/js/visualization.js @@ -1101,6 +1101,35 @@ OCA.Analytics.Visualization = { return data; }, + /** + * Translate a dimension index after drilldown removed columns. + * + * @param {string|number} dimension - Original dimension index before drilldown. + * @param {Object} drilldown - Drilldown filter mapping column indices to visibility. + * @returns {number} Adjusted zero-based index or -1 if the column was removed. + */ + resolveDimensionIndex: function (dimension, drilldown) { + let idx = parseInt(String(dimension).match(/\d+$/)?.[0], 10); + if (isNaN(idx)) { + return -1; + } + if (drilldown && typeof drilldown === 'object') { + const removed = Object.keys(drilldown) + .filter(key => drilldown[key] === false) + .map(key => parseInt(String(key).match(/\d+$/)?.[0], 10)) + .sort((a, b) => a - b); + for (const r of removed) { + if (r === idx) { + return -1; + } + if (r < idx) { + idx--; + } + } + } + return idx; + }, + /** * Group time based dimensions by day/week/month/year. * @@ -1113,8 +1142,11 @@ OCA.Analytics.Visualization = { return data; } - const dimension = parseInt(tg.dimension.match(/\d+$/)?.[0], 10) - 1; - if (isNaN(dimension)) { + const dimension = OCA.Analytics.Visualization.resolveDimensionIndex( + tg.dimension, + data.options.filteroptions?.drilldown + ); + if (dimension < 0) { return data; }