Skip to content

Commit 5316673

Browse files
Relative graphs should not be truncated at 0
1 parent 85074ae commit 5316673

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

site/static/index.html

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
const seriesColors = ["#7cb5ec", "#434348", "#90ed7d", "#f7a35c", "#8085e9", "#f15c80", "#e4d354", "#2b908f", "#f45b5b", "#91e8e1"];
7777
const interpolatedColor = "#fcb0f1";
7878

79-
function tooltipPlugin({onclick, commits, isInterpolated, shiftX = 10, shiftY = 10}) {
79+
function tooltipPlugin({onclick, commits, isInterpolated, absoluteMode, shiftX = 10, shiftY = 10}) {
8080
let tooltipLeftOffset = 0;
8181
let tooltipTopOffset = 0;
8282

@@ -96,10 +96,17 @@
9696
tooltip.style.left = (tooltipLeftOffset + lft + shiftY) + "px";
9797

9898
tooltip.style.borderColor = isInterpolated(dataIdx) ? interpolatedColor : seriesColors[seriesIdx - 1];
99-
let pctSinceStart = (((u.data[seriesIdx][dataIdx] - u.data[seriesIdx][0]) / u.data[seriesIdx][0]) * 100).toFixed(2);
99+
let trailer = "";
100+
if (absoluteMode) {
101+
let pctSinceStart = (((u.data[seriesIdx][dataIdx] - u.data[seriesIdx][0]) / u.data[seriesIdx][0]) * 100).toFixed(2);
102+
trailer = uPlot.fmtNum(u.data[seriesIdx][dataIdx]) + "(" +
103+
pctSinceStart + "% since start)";
104+
} else {
105+
trailer = uPlot.fmtNum(u.data[seriesIdx][dataIdx]) + "% since start";
106+
}
100107
tooltip.textContent = (
101-
fmtDate(new Date(u.data[0][dataIdx] * 1e3)) + " - " + commits[dataIdx][1].slice(0,10) + "\n" +
102-
uPlot.fmtNum(u.data[seriesIdx][dataIdx]) + "(" + pctSinceStart + "% since start)"
108+
fmtDate(new Date(u.data[0][dataIdx] * 1e3)) + " - " +
109+
commits[dataIdx][1].slice(0,10) + "\n" + trailer
103110
);
104111
}
105112

@@ -160,7 +167,8 @@
160167
};
161168
}
162169

163-
function genPlotOpts({title, width, height, yAxisLabel, series, commits, stat, isInterpolated, alpha = 0.3, prox = 5}) {
170+
function genPlotOpts({title, width, height, yAxisLabel, series, commits,
171+
stat, isInterpolated, alpha = 0.3, prox = 5, absoluteMode}) {
164172
return {
165173
title,
166174
width,
@@ -183,7 +191,7 @@
183191
},
184192
scales: {
185193
y: {
186-
range: (self, dataMin, dataMax) => uPlot.rangeNum(0, dataMax, 0.2, true)
194+
range: (self, dataMin, dataMax) => uPlot.rangeNum(absoluteMode ? 0 : dataMin, dataMax, 0.2, true)
187195
}
188196
},
189197
axes: [
@@ -245,6 +253,7 @@
245253
},
246254
commits,
247255
isInterpolated,
256+
absoluteMode,
248257
}),
249258
],
250259
};
@@ -273,6 +282,9 @@
273282
} else if (state.stat == "faults") {
274283
yAxis = "Faults";
275284
}
285+
if (!state.absolute) {
286+
yAxis = "% change from baseline";
287+
}
276288

277289
let yAxisLabel = i == 0 ? yAxis : null;
278290

@@ -309,6 +321,7 @@
309321
isInterpolated(dataIdx) {
310322
return cacheStates.full.is_interpolated.has(dataIdx);
311323
},
324+
absoluteMode: state.absolute,
312325
});
313326

314327
let u = new uPlot(plotOpts, plotData,

0 commit comments

Comments
 (0)