Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Show dashed comparison line for the current incomplete interval in top graph (#6222)

Sanne de Vries7a31d4447bb8
diff --git a/assets/js/dashboard/stats/graph/graph-util.js b/assets/js/dashboard/stats/graph/graph-util.js
index 948a3edf82..ef66a15322 100644
--- a/assets/js/dashboard/stats/graph/graph-util.js
+++ b/assets/js/dashboard/stats/graph/graph-util.js
@@ -25,12 +25,16 @@ function plottable(dataArray) {
})
}
-const buildComparisonDataset = function (comparisonPlot) {
+const buildComparisonDataset = function (comparisonPlot, presentIndex) {
if (!comparisonPlot) return []
+ const data = presentIndex
+ ? comparisonPlot.slice(0, presentIndex)
+ : comparisonPlot
+
return [
{
- data: plottable(comparisonPlot),
+ data: plottable(data),
borderColor: 'rgba(99, 102, 241, 0.3)',
pointBackgroundColor: 'rgba(99, 102, 241, 0.2)',
pointHoverBackgroundColor: 'rgba(99, 102, 241, 0.5)',
@@ -38,6 +42,21 @@ const buildComparisonDataset = function (comparisonPlot) {
}
]
}
+
+const buildDashedComparisonDataset = function (comparisonPlot, presentIndex) {
+ if (!comparisonPlot || !presentIndex) return []
+ const dashedPart = comparisonPlot.slice(presentIndex - 1, presentIndex + 1)
+ const dashedPlot = new Array(presentIndex - 1).concat(dashedPart)
+ return [
+ {
+ data: plottable(dashedPlot),
+ borderDash: [3, 3],
+ borderColor: 'rgba(99, 102, 241, 0.3)',
+ pointHoverBackgroundColor: 'rgba(99, 102, 241, 0.5)',
+ yAxisID: 'yComparison'
+ }
+ ]
+}
const buildDashedDataset = function (plot, presentIndex) {
if (!presentIndex) return []
const dashedPart = plot.slice(presentIndex - 1, presentIndex + 1)
@@ -90,7 +109,8 @@ export const buildDataSet = (
const dataset = [
...buildMainPlotDataset(plot, present_index),
...buildDashedDataset(plot, present_index),
- ...buildComparisonDataset(comparisonPlot)
+ ...buildComparisonDataset(comparisonPlot, present_index),
+ ...buildDashedComparisonDataset(comparisonPlot, present_index)
]
return dataset.map((item) => Object.assign(item, defaultOptions))