fix(admin): clip rate chart at 100% — SVG clipPath + data cap
Deploy to Production / deploy (push) Successful in 3m13s

Two-layer fix:
- SVG clipPath on plot area: path physically cannot escape chart bounds
- Chart flush caps rpm at rateLimit: timing drift (two batches in one
  5 s window) no longer causes visual overshoot
Live label still shows true req/min and % including values > 100%.

Co-Authored-By: Mira Rehfeld <noreply@anthropic.com>
This commit is contained in:
Carsten Rehfeld
2026-05-17 01:12:10 +02:00
parent 4908d5d6e0
commit de597f1d8b
3 changed files with 10 additions and 4 deletions
@@ -185,7 +185,12 @@
var ly = yS(rateLimit);
svg.append('line').attr('x1', ML).attr('x2', W).attr('y1', ly).attr('y2', ly).attr('class', 'rate-limit-line');
var path = svg.append('path').attr('class', 'rate-area');
// Clip path — area can never escape the plot region regardless of data spikes
var clipId = 'rc-' + sid.slice(0, 8);
svg.append('defs').append('clipPath').attr('id', clipId)
.append('rect').attr('x', ML).attr('y', 0).attr('width', W - ML).attr('height', CH);
var path = svg.append('path').attr('class', 'rate-area').attr('clip-path', 'url(#' + clipId + ')');
function fmt(n) {
return n >= 1e6 ? (n / 1e6).toFixed(1) + 'M' : n >= 1e3 ? (n / 1e3).toFixed(1) + 'k' : String(n);
@@ -200,8 +205,9 @@
}
// Chart bucket: flush accumulated delta every 5 s regardless of poll rate
// Cap at rateLimit so the area never visually exceeds 100% (live label shows true value)
setInterval(function () {
var rpm = Math.round(accDelta * (60000 / CHART_TICK));
var rpm = Math.min(Math.round(accDelta * (60000 / CHART_TICK)), rateLimit);
buf.push(rpm); buf.shift();
path.attr('d', areaFn(buf));
accDelta = 0;
@@ -106,6 +106,6 @@ nav {
<script>var __D = {statsJson.raw};</script>
<script src="https://cdn.jsdelivr.net/npm/d3@7/dist/d3.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/topojson-client@3/dist/topojson-client.min.js"></script>
<script src="/admin.js?v=6"></script>
<script src="/admin.js?v=7"></script>
</body>
</html>
@@ -151,6 +151,6 @@ button.promote:hover { background: #2ea043; }
<script>var __D = {dataJson.raw};</script>
<script src="https://cdn.jsdelivr.net/npm/d3@7/dist/d3.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/topojson-client@3/dist/topojson-client.min.js"></script>
<script src="/admin.js?v=6"></script>
<script src="/admin.js?v=7"></script>
</body>
</html>