diff --git a/src/main.js b/src/main.js index 11ff578..12a35c4 100644 --- a/src/main.js +++ b/src/main.js @@ -3,14 +3,17 @@ import "./styles.css"; // --- Configuration ----------------------------------------------------------- // Timing, axis labels, and display constants. Latency above maxLatency is -// clamped to "unreachable". The history buffer holds maxHistoryPoints -// samples (historyDuration / updateInterval). +// clamped to "unreachable". The sparkline Y-axis is capped at +// graphMaxLatency — values above it pin to the top of the chart but still +// display their real value in the latency figure. The history buffer holds +// maxHistoryPoints samples (historyDuration / updateInterval). const CONFIG = Object.freeze({ updateInterval: 2000, historyDuration: 300, requestTimeout: 1500, maxLatency: 1500, - yAxisTicks: [0, 250, 500, 750, 1000, 1500], + graphMaxLatency: 1000, + yAxisTicks: [0, 250, 500, 750, 1000], xAxisTicks: [0, 60, 120, 180, 240, 300], canvasHeight: 80, get maxHistoryPoints() { @@ -240,7 +243,11 @@ class SparklineRenderer { const len = history.length; const pw = cw / (CONFIG.maxHistoryPoints - 1); const getX = (i) => m.left + cw - (len - 1 - i) * pw; - const getY = (lat) => m.top + ch - (lat / CONFIG.maxLatency) * ch; + const getY = (lat) => + m.top + + ch - + (Math.min(lat, CONFIG.graphMaxLatency) / CONFIG.graphMaxLatency) * + ch; SparklineRenderer._drawErrors(ctx, history, getX, m.top, ch); SparklineRenderer._drawLine(ctx, history, getX, getY); @@ -252,7 +259,7 @@ class SparklineRenderer { ctx.textAlign = "right"; ctx.textBaseline = "middle"; for (const tick of CONFIG.yAxisTicks) { - const y = m.top + ch - (tick / CONFIG.maxLatency) * ch; + const y = m.top + ch - (tick / CONFIG.graphMaxLatency) * ch; ctx.strokeStyle = "rgba(255,255,255,0.1)"; ctx.lineWidth = 1; ctx.beginPath(); @@ -461,7 +468,7 @@ function updateHostRow(host, index) { const avg = host.averageLatency(); if (host.status === "online" && avg !== null) { statusEl.textContent = `avg: ${avg}ms`; - statusEl.className = "status-text text-xs text-gray-400 mt-1"; + statusEl.className = `status-text text-xs mt-1 ${latencyClass(avg, "online")}`; } else if (host.status === "offline") { statusEl.textContent = "unreachable"; statusEl.className = "status-text text-xs text-red-400 mt-1";