Skip to content

Commit 9a2790f

Browse files
committed
ux(cm): dynamic Y-axis scaling based on actual latency data
Replace hardcoded yMax=200ms with dynamic scaling that adapts to the actual data range. Snaps to zone boundaries with ~20-30% headroom so the graph uses its full height instead of showing mostly whitespace.
1 parent 6f64123 commit 9a2790f

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

app/modules/connection_monitor/static/js/connection-monitor-charts.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,25 @@ var CMCharts = (function() {
235235

236236
var lossIndices = Object.keys(lossSet).map(Number).sort(function(a, b) { return a - b; });
237237

238+
// Compute dynamic Y-max from actual data with headroom
239+
var dataMax = 0;
240+
datasets.forEach(function(ds) {
241+
ds.data.forEach(function(v) { if (v != null && v > dataMax) dataMax = v; });
242+
});
243+
// Snap to next threshold zone boundary for clean visuals
244+
var yMax;
245+
if (dataMax <= 30) yMax = Math.max(dataMax * 1.3, 10);
246+
else if (dataMax <= 100) yMax = Math.min(dataMax * 1.2, 120);
247+
else yMax = dataMax * 1.15;
248+
yMax = Math.ceil(yMax);
249+
238250
// PingPlotter-style threshold zones (vertically scaled backgrounds)
239251
// lineColor: transparent suppresses the dashed boundary lines
240252
var zones = [
241253
{ min: 0, max: 30, color: 'rgba(34,197,94,0.12)', lineColor: 'transparent' },
242254
{ min: 30, max: 100, color: 'rgba(234,179,8,0.10)', lineColor: 'transparent' },
243255
{ min: 100, max: 10000, color: 'rgba(239,68,68,0.08)', lineColor: 'transparent' },
244-
{ yMin: 0, yMax: 200 }
256+
{ yMin: 0, yMax: yMax }
245257
];
246258

247259
renderChart(containerId, labels, datasets, 'line', zones, {

0 commit comments

Comments
 (0)