LLR history: back to a simple graph, back in the Actions card, fixed snapping

- Simple graph again: plot with grid, 3 y labels, games axis, bounds/zero
  when in range, green/red line, hover marker + one-line tooltip. Removed the
  header, progress bar, legend, area fill, zones, pulse and animations.
  Colours are unchanged.
- The LLR panel is back at the end of the Actions card (below Adjust) where it
  was originally; the separate LLR card and its grid placement are gone.
- Snapping: the marker now locks onto every visible peak and valley. Peaks
  are found with a swing filter (a turning point counts once the line has
  moved >= 3px away from it), so plateaus and tiny wiggles no longer steal
  the snap from the real peaks. The first and latest points snap as well.
This commit is contained in:
claude committed 2026-10-09 22:15:23 +02:00
1 parent 8ac2335020
commit 56e22e6936
3 files changed
+241 -835

No files matched your search

+170 -447
View File
@@ -1,15 +1,12 @@
/* ========================================================================== /* ==========================================================================
OpenBench - LLR history chart OpenBench - LLR history graph
The server (mytags.llr_history_graph) only supplies data: a <div The server (mytags.llr_history_graph) supplies the data as a
class="llr-chart" data-chart="{json}">. Everything is drawn here, so the <div class="llr-chart" data-chart="{json}">, and the graph is drawn here
chart fills the width of its card and stays crisp on any screen. so that it fills the width of its panel.
Interaction Hovering snaps the marker to the nearest point of the graph, and to the
- the crosshair snaps to the nearest data point, and is pulled towards peaks / valleys of the line when the pointer is near one.
local peaks / valleys when the pointer is close to one
- mouse, touch (horizontal scrub, vertical scroll still works) and
keyboard (arrows, Shift = x10, Home / End, Escape)
========================================================================== */ ========================================================================== */
(function () { (function () {
@@ -17,10 +14,13 @@
var SVG_NS = 'http://www.w3.org/2000/svg'; var SVG_NS = 'http://www.w3.org/2000/svg';
var MINUS = '\u2212'; var MINUS = '\u2212';
var MAGNET = 10; // px a peak / valley may pull the crosshair from the pointer var HEIGHT = 124;
var MARGIN = { l: 40, r: 8, t: 8, b: 20 };
var MAGNET = 12; // px: how far a peak / valley pulls the marker
var SWING = 3; // px: smallest rise / fall that counts as a peak / valley
var uid = 0; var uid = 0;
/* ---------- tiny DOM helpers ---------- */ /* ---------- helpers ---------- */
function svg(name, attrs, parent) { function svg(name, attrs, parent) {
var node = document.createElementNS(SVG_NS, name); var node = document.createElementNS(SVG_NS, name);
@@ -32,75 +32,32 @@
return node; return node;
} }
function div(className, parent, text) { function div(className, parent) {
var node = document.createElement('div'); var node = document.createElement('div');
node.className = className; node.className = className;
if (text !== undefined)
node.textContent = text;
if (parent) if (parent)
parent.appendChild(node); parent.appendChild(node);
return node; return node;
} }
function span(className, parent, text) { function fmt(value) {
var node = document.createElement('span'); return value.toFixed(2).replace('-', MINUS);
node.className = className;
if (text !== undefined)
node.textContent = text;
if (parent)
parent.appendChild(node);
return node;
}
/* ---------- number formatting ---------- */
function fmt(value, digits) {
return value.toFixed(digits).replace('-', MINUS);
} }
function commas(value) { function commas(value) {
return String(Math.round(value)).replace(/\B(?=(\d{3})+(?!\d))/g, ','); return String(Math.round(value)).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
} }
function trim(value) {
return String(parseFloat(value.toFixed(2)));
}
function compact(value) { function compact(value) {
var abs = Math.abs(value); if (value >= 1e6) return parseFloat((value / 1e6).toFixed(1)) + 'M';
if (abs >= 1e6) return trim(value / 1e6) + 'M'; if (value >= 1e3) return parseFloat((value / 1e3).toFixed(1)) + 'k';
if (abs >= 1e3) return trim(value / 1e3) + 'k'; return String(Math.round(value));
return trim(value);
}
function tone(value) {
return value > 0 ? 'pos' : value < 0 ? 'neg' : 'zero';
} }
function clamp(value, min, max) { function clamp(value, min, max) {
return Math.max(min, Math.min(max, value)); return Math.max(min, Math.min(max, value));
} }
/* ---------- scales ---------- */
function niceTicks(min, max, target) {
var span = max - min;
if (!(span > 0) || !(target > 0))
return [min];
var raw = span / target;
var mag = Math.pow(10, Math.floor(Math.log(raw) / Math.LN10));
var norm = raw / mag;
var step = (norm < 1.5 ? 1 : norm < 3 ? 2 : norm < 7 ? 5 : 10) * mag;
var ticks = [];
for (var i = Math.ceil(min / step); i * step <= max + step * 1e-9; i++)
ticks.push(parseFloat((i * step).toPrecision(12)));
return ticks;
}
// Index of the first point with games >= target // Index of the first point with games >= target
function lowerBound(points, target) { function lowerBound(points, target) {
@@ -113,9 +70,7 @@
return lo; return lo;
} }
/* ---------- path helpers ---------- */ // Keep the first / min / max / last point of every pixel column
// Keep first / min / max / last of every pixel column, for very long histories
function decimate(points, sx) { function decimate(points, sx) {
var out = [], i = 0, n = points.length; var out = [], i = 0, n = points.length;
@@ -131,12 +86,11 @@
if (points[j].llr > points[hi].llr) hi = j; if (points[j].llr > points[hi].llr) hi = j;
} }
var picks = [i, lo, hi, j].filter(function (value, index, all) { [i, lo, hi, j].filter(function (value, index, all) {
return all.indexOf(value) === index; return all.indexOf(value) === index;
}).sort(function (a, b) { return a - b; }); }).sort(function (a, b) { return a - b; }).forEach(function (k) {
out.push(points[k]);
for (var k = 0; k < picks.length; k++) });
out.push(points[picks[k]]);
i = j + 1; i = j + 1;
} }
@@ -144,462 +98,251 @@
return out; return out;
} }
// Split into runs of consecutive points for which test(a, b) holds /* Peaks and valleys: every turning point of the line where it rises or
function runs(points, test) { falls by at least `threshold` before turning around. Flat stretches and
tiny wiggles (smaller than a few pixels) are ignored, so what snaps is
exactly what is visible on the graph. */
function findPivots(points, threshold) {
var out = [], run = null; var pivots = [];
var trend = 0, hi = 0, lo = 0;
for (var i = 1; i < points.length; i++) { for (var i = 1; i < points.length; i++) {
if (test(points[i - 1], points[i])) {
if (!run) { run = [points[i - 1]]; out.push(run); } var value = points[i].llr;
run.push(points[i]);
} else { if (value >= points[hi].llr) hi = i;
run = null; if (value <= points[lo].llr) lo = i;
if (trend >= 0 && points[hi].llr - value >= threshold) {
pivots.push(hi);
trend = -1; hi = i; lo = i;
}
else if (trend <= 0 && value - points[lo].llr >= threshold) {
pivots.push(lo);
trend = 1; hi = i; lo = i;
} }
} }
return out; return pivots;
} }
/* ====================================================================== /* ======================================================================
Chart Graph
====================================================================== */ ====================================================================== */
function LlrChart(root, data) { function Graph(root, data) {
this.root = root; this.root = root;
this.lower = Number(data.lower); this.lower = Number(data.lower);
this.upper = Number(data.upper); this.upper = Number(data.upper);
this.current = Number(data.current);
this.games = Number(data.games); this.games = Number(data.games);
this.finished = !!data.finished;
this.active = -1; this.active = -1;
this.rendered = 0; this.rendered = 0;
this.animated = false;
this.hasBounds = isFinite(this.lower) && isFinite(this.upper) && this.upper > this.lower;
this.points = data.history.map(function (p) { this.points = data.history.map(function (p) {
return { games: Number(p[0]), llr: Number(p[1]), estimated: !!p[2] }; return { games: Number(p[0]), llr: Number(p[1]), estimated: !!p[2] };
}).sort(function (a, b) { return a.games - b.games; }); }).sort(function (a, b) { return a.games - b.games; });
this.markExtremes(); root.textContent = '';
this.build();
this.plot = div('llrg-plot', root);
this.plot.tabIndex = 0;
this.plot.setAttribute('role', 'img');
this.plot.setAttribute('aria-label', 'LLR history. Use the arrow keys to inspect the points.');
this.svgEl = svg('svg', { 'class': 'llrg-svg', 'aria-hidden': 'true' }, this.plot);
this.tip = div('llrg-tip', this.plot);
this.render(); this.render();
this.bind(); this.bind();
} }
// Flag local peaks and valleys of the measured (non estimated) points Graph.prototype.render = function () {
LlrChart.prototype.markExtremes = function () {
var real = this.points.filter(function (p) { return !p.estimated; }); var W = Math.floor(this.plot.clientWidth);
if (W < 120)
for (var i = 1; i < real.length - 1; i++) {
var prev = real[i - 1], curr = real[i], next = real[i + 1];
if ((curr.llr > prev.llr && curr.llr > next.llr) ||
(curr.llr < prev.llr && curr.llr < next.llr))
curr.extreme = true;
}
};
LlrChart.prototype.ratio = function (llr) {
if (!this.hasBounds)
return 0;
var bound = llr >= 0 ? this.upper : this.lower;
return bound ? clamp(llr / bound, 0, 1) : 0;
};
LlrChart.prototype.build = function () {
var root = this.root;
root.textContent = '';
root.classList.add('llrc');
var kind = tone(this.current);
var ratio = this.ratio(this.current);
var goal = this.current >= 0 ? 'pass' : 'fail';
/* Header: current value, progress towards the nearest bound, games */
var head = div('llrc-head', root);
var stat = div('llrc-stat', head);
span('llrc-stat-label', stat, 'LLR');
span('llrc-value is-' + kind, stat, fmt(this.current, 2));
if (this.hasBounds)
span('llrc-of', stat, '/ ' + fmt(this.current >= 0 ? this.upper : this.lower, 2));
if (this.hasBounds) {
var progress = div('llrc-progress', head);
var top = div('llrc-progress-top', progress);
span('', top, Math.round(ratio * 100) + '% to ' + goal + ' bound');
var bar = div('llrc-bar', progress);
this.fill = span('is-' + (this.current >= 0 ? 'pos' : 'neg'), bar);
this.fill.style.width = '0%';
this.fillTarget = ratio * 100;
}
div('llrc-games', head, commas(this.games) + ' games');
/* Plot */
this.plot = div('llrc-plot', root);
this.plot.tabIndex = 0;
this.plot.setAttribute('role', 'img');
this.plot.setAttribute('aria-label',
'LLR history: ' + fmt(this.current, 2) + ' after ' + commas(this.games) +
' games. Use the arrow keys to inspect individual points.');
this.svgEl = svg('svg', { 'class': 'llrc-svg', 'aria-hidden': 'true' }, this.plot);
this.tip = div('llrc-tip', this.plot);
this.live = div('llrc-sr', root);
this.live.setAttribute('aria-live', 'polite');
/* Legend */
var legend = div('llrc-legend', root);
var key = span('llrc-key', legend);
span('llrc-swatch llrc-swatch-line', key);
span('', key, 'LLR');
if (this.points.some(function (p) { return p.estimated; })) {
key = span('llrc-key', legend);
span('llrc-swatch llrc-swatch-est', key);
span('', key, 'Estimated');
}
if (this.hasBounds) {
key = span('llrc-key', legend);
span('llrc-swatch llrc-swatch-bound', key);
span('', key, 'Bounds');
}
span('llrc-hint', legend, 'Hover, drag or use \u2190 \u2192 to inspect');
};
LlrChart.prototype.render = function () {
var plotWidth = Math.floor(this.plot.clientWidth);
if (plotWidth < 160)
return; return;
this.rendered = plotWidth; this.rendered = W;
var W = plotWidth; var H = HEIGHT, m = MARGIN;
var H = W < 460 ? 196 : 244;
var m = { l: 46, r: 14, t: 14, b: 26 };
var iw = W - m.l - m.r; var iw = W - m.l - m.r;
var ih = H - m.t - m.b; var ih = H - m.t - m.b;
var points = this.points; var points = this.points;
var xMax = Math.max(points[points.length - 1].games, this.games, 1); var xMax = Math.max(points[points.length - 1].games, this.games, 1);
/* Domain: all the data, zero, and both bounds, so progress is always visible */ /* Vertical range: what was observed, and zero, with a minimum height */
var lo = 0, hi = 0; var lo = 0, hi = 0;
if (this.hasBounds) { lo = Math.min(lo, this.lower); hi = Math.max(hi, this.upper); }
var maxPos = 0, minNeg = 0;
points.forEach(function (p) { points.forEach(function (p) {
if (p.llr < lo) lo = p.llr; if (p.llr < lo) lo = p.llr;
if (p.llr > hi) hi = p.llr; if (p.llr > hi) hi = p.llr;
if (p.llr > maxPos) maxPos = p.llr;
if (p.llr < minNeg) minNeg = p.llr;
}); });
var pad = (hi - lo) * 0.07 || 1; var yMin, yMax;
var yMin = lo - pad; if (hi - lo < 0.75) {
var yMax = hi + pad; var center = (lo + hi) / 2;
yMin = center - 0.375;
yMax = center + 0.375;
} else {
var pad = Math.max((hi - lo) * 0.15, 0.15);
yMin = lo - pad;
yMax = hi + pad;
}
function sx(games) { return m.l + iw * (games / xMax); } function sx(games) { return m.l + iw * (games / xMax); }
function sy(value) { return m.t + ih * (1 - (value - yMin) / (yMax - yMin)); } function sy(value) { return m.t + ih * (1 - (value - yMin) / (yMax - yMin)); }
this.g = { W: W, H: H, m: m, iw: iw, ih: ih, xMax: xMax, sx: sx, sy: sy }; this.g = { W: W, H: H, m: m, iw: iw, ih: ih, xMax: xMax, sx: sx, sy: sy };
/* Peaks and valleys, plus both ends, are what the marker snaps to */
var pivots = findPivots(points, SWING * (yMax - yMin) / ih);
pivots.push(0, points.length - 1);
this.pivots = pivots.filter(function (value, index, all) {
return all.indexOf(value) === index;
}).sort(function (a, b) { return a - b; });
/* Drawing */
var el = this.svgEl;
var id = 'llrg' + (++uid);
var zeroY = sy(0); var zeroY = sy(0);
var id = 'llrc' + (++uid);
var el = this.svgEl;
el.textContent = ''; el.textContent = '';
el.setAttribute('viewBox', '0 0 ' + W + ' ' + H); el.setAttribute('viewBox', '0 0 ' + W + ' ' + H);
el.setAttribute('width', W); el.setAttribute('width', W);
el.setAttribute('height', H); el.setAttribute('height', H);
/* Defs: gradients for the area under the curve, clips to split green / red at zero */
var defs = svg('defs', {}, el); var defs = svg('defs', {}, el);
var above = svg('clipPath', { id: id + '-a' }, defs);
svg('rect', { x: m.l, y: m.t, width: iw, height: Math.max(zeroY - m.t, 0) }, above);
var below = svg('clipPath', { id: id + '-b' }, defs);
svg('rect', { x: m.l, y: zeroY, width: iw, height: Math.max(m.t + ih - zeroY, 0) }, below);
var gradPos = svg('linearGradient', { id: id + '-gp', gradientUnits: 'userSpaceOnUse', svg('rect', { 'class': 'llrg-bg', x: m.l, y: m.t, width: iw, height: ih }, el);
x1: 0, x2: 0, y1: sy(maxPos), y2: zeroY }, defs);
svg('stop', { offset: '0', 'class': 'llrc-stop-pos', 'stop-opacity': '0.34' }, gradPos);
svg('stop', { offset: '1', 'class': 'llrc-stop-pos', 'stop-opacity': '0.02' }, gradPos);
var gradNeg = svg('linearGradient', { id: id + '-gn', gradientUnits: 'userSpaceOnUse',
x1: 0, x2: 0, y1: zeroY, y2: sy(minNeg) }, defs);
svg('stop', { offset: '0', 'class': 'llrc-stop-neg', 'stop-opacity': '0.02' }, gradNeg);
svg('stop', { offset: '1', 'class': 'llrc-stop-neg', 'stop-opacity': '0.34' }, gradNeg);
var clipPos = svg('clipPath', { id: id + '-cp' }, defs);
svg('rect', { x: m.l, y: m.t - 2, width: iw, height: Math.max(zeroY - m.t + 2, 0) }, clipPos);
var clipNeg = svg('clipPath', { id: id + '-cn' }, defs);
svg('rect', { x: m.l, y: zeroY, width: iw, height: Math.max(H - m.b - zeroY + 2, 0) }, clipNeg);
/* Zones beyond the bounds */
if (this.hasBounds) {
svg('rect', { 'class': 'llrc-zone-pos', x: m.l, y: m.t,
width: iw, height: Math.max(sy(this.upper) - m.t, 0) }, el);
svg('rect', { 'class': 'llrc-zone-neg', x: m.l, y: sy(this.lower),
width: iw, height: Math.max(H - m.b - sy(this.lower), 0) }, el);
}
/* Grid and axis labels */
var boundYs = this.hasBounds ? [sy(this.upper), sy(this.lower)] : [];
niceTicks(yMin, yMax, ih / 38).forEach(function (value) {
// Horizontal grid + labels: top, middle, bottom
[yMax, (yMin + yMax) / 2, yMin].forEach(function (value) {
var y = sy(value); var y = sy(value);
if (y < m.t - 0.5 || y > H - m.b + 0.5) svg('line', { 'class': 'llrg-grid', x1: m.l, x2: m.l + iw, y1: y, y2: y }, el);
return; var label = svg('text', { 'class': 'llrg-tick', x: m.l - 6, y: y, dy: '0.32em', 'text-anchor': 'end' }, el);
label.textContent = fmt(value);
svg('line', { 'class': value === 0 ? 'llrc-zero' : 'llrc-grid',
x1: m.l, x2: W - m.r, y1: y, y2: y }, el);
var nearBound = boundYs.some(function (by) { return Math.abs(by - y) < 9; });
if (nearBound && value !== 0)
return;
var label = svg('text', { 'class': 'llrc-tick', x: m.l - 8, y: y, dy: '0.32em',
'text-anchor': 'end' }, el);
label.textContent = fmt(value, Math.abs(value) % 1 ? 1 : 0);
}); });
niceTicks(0, xMax, iw / 96).forEach(function (value) { // Vertical grid
[0.25, 0.5, 0.75].forEach(function (fraction) {
var x = sx(value); var x = m.l + iw * fraction;
svg('line', { 'class': 'llrc-grid llrc-grid-v', x1: x, x2: x, y1: m.t, y2: H - m.b }, el); svg('line', { 'class': 'llrg-grid', x1: x, x2: x, y1: m.t, y2: m.t + ih }, el);
if (x > W - m.r - 12 && value !== xMax)
return;
var label = svg('text', { 'class': 'llrc-tick', x: x, y: H - 8,
'text-anchor': value === 0 ? 'start' : 'middle' }, el);
label.textContent = compact(value);
}); });
/* Bounds */ // Games axis
[[0, 'start', m.l], [xMax / 2, 'middle', m.l + iw / 2], [xMax, 'end', m.l + iw]].forEach(function (tick) {
if (this.hasBounds) { var label = svg('text', { 'class': 'llrg-tick', x: tick[2], y: H - 5, 'text-anchor': tick[1] }, el);
label.textContent = tick[0] === 0 ? '0' : compact(tick[0]);
var upperY = sy(this.upper), lowerY = sy(this.lower);
svg('line', { 'class': 'llrc-bound llrc-bound-pos', x1: m.l, x2: W - m.r, y1: upperY, y2: upperY }, el);
svg('line', { 'class': 'llrc-bound llrc-bound-neg', x1: m.l, x2: W - m.r, y1: lowerY, y2: lowerY }, el);
var upperLabel = svg('text', { 'class': 'llrc-bound-label llrc-bound-label-pos',
x: m.l + 8, y: upperY - 6 }, el);
upperLabel.textContent = 'PASS ' + fmt(this.upper, 2);
var lowerLabel = svg('text', { 'class': 'llrc-bound-label llrc-bound-label-neg',
x: m.l + 8, y: lowerY + 14 }, el);
lowerLabel.textContent = 'FAIL ' + fmt(this.lower, 2);
}
/* Series: drawn twice and clipped, so the line is green above zero and red below */
var drawn = points.length > iw * 1.5 ? decimate(points, sx) : points;
function path(list) {
return list.map(function (run) {
return run.map(function (p, i) {
return (i ? 'L' : 'M') + sx(p.games).toFixed(1) + ' ' + sy(p.llr).toFixed(1);
}).join('');
}).join('');
}
var solid = path(runs(drawn, function (a, b) { return !a.estimated && !b.estimated; }));
var dashed = path(runs(drawn, function (a, b) { return a.estimated || b.estimated; }));
var area = '';
if (drawn.length > 1) {
area = 'M' + sx(drawn[0].games).toFixed(1) + ' ' + zeroY.toFixed(1) +
drawn.map(function (p) { return 'L' + sx(p.games).toFixed(1) + ' ' + sy(p.llr).toFixed(1); }).join('') +
'L' + sx(drawn[drawn.length - 1].games).toFixed(1) + ' ' + zeroY.toFixed(1) + 'Z';
}
[['pos', id + '-cp', id + '-gp'], ['neg', id + '-cn', id + '-gn']].forEach(function (side) {
var group = svg('g', { 'clip-path': 'url(#' + side[1] + ')' }, el);
if (area)
svg('path', { 'class': 'llrc-area', d: area, fill: 'url(#' + side[2] + ')' }, group);
if (dashed)
svg('path', { 'class': 'llrc-line llrc-line-est llrc-line-' + side[0], d: dashed }, group);
if (solid)
svg('path', { 'class': 'llrc-line llrc-line-solid llrc-line-' + side[0], d: solid,
pathLength: '1' }, group);
}); });
/* Latest value */ // Bounds and zero, when they are in range
var lower = this.lower, upper = this.upper;
var last = points[points.length - 1]; [[lower, 'llrg-bound'], [0, 'llrg-zero'], [upper, 'llrg-bound']].forEach(function (guide) {
var kind = tone(last.llr); if (guide[0] >= yMin && guide[0] <= yMax) {
var y = sy(guide[0]);
if (!this.finished) svg('line', { 'class': guide[1], x1: m.l, x2: m.l + iw, y1: y, y2: y }, el);
svg('circle', { 'class': 'llrc-now-ring is-' + kind, cx: sx(last.games), cy: sy(last.llr), r: 5 }, el);
svg('circle', { 'class': 'llrc-now is-' + kind, cx: sx(last.games), cy: sy(last.llr), r: 3.5 }, el);
/* Crosshair */
var hover = svg('g', { 'class': 'llrc-hover' }, el);
this.hv = svg('line', { 'class': 'llrc-hover-v', y1: m.t, y2: H - m.b }, hover);
this.hh = svg('line', { 'class': 'llrc-hover-h', x1: m.l, x2: W - m.r }, hover);
this.hr = svg('circle', { 'class': 'llrc-hover-halo', r: 8 }, hover);
this.hd = svg('circle', { 'class': 'llrc-hover-dot', r: 4.5 }, hover);
this.hover = hover;
/* One-off entrance animation */
if (!this.animated) {
this.animated = true;
this.root.classList.add('llrc-animate');
if (this.fill) {
var fill = this.fill, target = this.fillTarget;
window.requestAnimationFrame(function () {
window.requestAnimationFrame(function () { fill.style.width = target + '%'; });
});
} }
} });
// The line: green above zero, red below
var drawn = points.length > iw * 1.5 ? decimate(points, sx) : points;
var d = drawn.map(function (p, i) {
return (i ? 'L' : 'M') + sx(p.games).toFixed(1) + ' ' + sy(p.llr).toFixed(1);
}).join('');
svg('path', { 'class': 'llrg-line llrg-line-pos', d: d, 'clip-path': 'url(#' + id + '-a)' }, el);
svg('path', { 'class': 'llrg-line llrg-line-neg', d: d, 'clip-path': 'url(#' + id + '-b)' }, el);
// Marker
this.hoverLine = svg('line', { 'class': 'llrg-hover-line', y1: m.t, y2: m.t + ih }, el);
this.hoverDot = svg('circle', { 'class': 'llrg-hover-dot', r: 3.5 }, el);
if (this.active >= 0) if (this.active >= 0)
this.setActive(this.active, true); this.setActive(this.active);
}; };
/* ---------- snapping ---------- */ /* ---------- snapping ---------- */
// Index of the point the crosshair should snap to for a pointer at x (px, svg space) Graph.prototype.pick = function (x) {
LlrChart.prototype.pick = function (x) {
var g = this.g, points = this.points; var g = this.g, points = this.points;
var target = clamp((x - g.m.l) / g.iw, 0, 1) * g.xMax; var target = clamp((x - g.m.l) / g.iw, 0, 1) * g.xMax;
var after = lowerBound(points, target); // Nearest point
var after = Math.min(lowerBound(points, target), points.length - 1);
var before = Math.max(after - 1, 0); var before = Math.max(after - 1, 0);
after = Math.min(after, points.length - 1); var best = Math.abs(g.sx(points[before].games) - x) <= Math.abs(g.sx(points[after].games) - x) ? before : after;
var best = Math.abs(g.sx(points[before].games) - x) <= Math.abs(g.sx(points[after].games) - x) // Nearest peak / valley, if the pointer is close enough to one
? before : after;
// Pull towards a nearby peak / valley
var magnet = -1, magnetDistance = MAGNET + 1; var magnet = -1, magnetDistance = MAGNET + 1;
for (var i = 0; i < this.pivots.length; i++) {
for (var i = best; i >= 0; i--) { var distance = Math.abs(g.sx(points[this.pivots[i]].games) - x);
var d = Math.abs(g.sx(points[i].games) - x); if (distance < magnetDistance) {
if (d > MAGNET) break; magnet = this.pivots[i];
if (points[i].extreme && d < magnetDistance) { magnet = i; magnetDistance = d; } magnetDistance = distance;
} }
for (var j = best + 1; j < points.length; j++) {
var e = Math.abs(g.sx(points[j].games) - x);
if (e > MAGNET) break;
if (points[j].extreme && e < magnetDistance) { magnet = j; magnetDistance = e; }
} }
return magnet >= 0 ? magnet : best; return magnet >= 0 ? magnet : best;
}; };
LlrChart.prototype.setActive = function (index, keepTip) { Graph.prototype.setActive = function (index) {
if (index < 0 || !this.g) { if (index < 0 || !this.g) {
this.active = -1; this.active = -1;
this.hover.classList.remove('is-active'); this.hoverLine.classList.remove('active');
this.tip.classList.remove('is-active'); this.hoverDot.classList.remove('active', 'llrg-pos', 'llrg-neg');
this.tip.classList.remove('active');
return; return;
} }
var g = this.g; var g = this.g, p = this.points[index];
var p = this.points[index]; var x = g.sx(p.games), y = g.sy(p.llr);
var x = g.sx(p.games);
var y = g.sy(p.llr);
var k = tone(p.llr);
this.active = index; this.active = index;
this.hv.setAttribute('x1', x); this.hv.setAttribute('x2', x); this.hoverLine.setAttribute('x1', x);
this.hh.setAttribute('y1', y); this.hh.setAttribute('y2', y); this.hoverLine.setAttribute('x2', x);
this.hr.setAttribute('cx', x); this.hr.setAttribute('cy', y); this.hoverDot.setAttribute('cx', x);
this.hd.setAttribute('cx', x); this.hd.setAttribute('cy', y); this.hoverDot.setAttribute('cy', y);
this.hr.setAttribute('class', 'llrc-hover-halo is-' + k); this.hoverDot.setAttribute('class', 'llrg-hover-dot active ' + (p.llr >= 0 ? 'llrg-pos' : 'llrg-neg'));
this.hd.setAttribute('class', 'llrc-hover-dot is-' + k); this.hoverLine.classList.add('active');
this.hover.classList.add('is-active');
/* Tooltip */ this.tip.textContent = commas(p.games) + ' games | LLR ' + (p.estimated ? '\u2248' : '') + fmt(p.llr);
this.tip.classList.add('active');
var tip = this.tip; var left = clamp(x + 8, 0, g.W - this.tip.offsetWidth);
tip.textContent = ''; var top = clamp(y - this.tip.offsetHeight - 8, 0, g.H - this.tip.offsetHeight);
div('llrc-tip-games', tip, commas(p.games) + ' games'); this.tip.style.left = left + 'px';
this.tip.style.top = top + 'px';
var row = div('llrc-tip-llr', tip);
span('llrc-tip-label', row, p.estimated ? 'LLR \u2248' : 'LLR');
span('llrc-tip-value is-' + k, row, fmt(p.llr, 2));
if (this.hasBounds) {
var pct = Math.round(this.ratio(p.llr) * 100);
div('llrc-tip-sub', tip, pct + '% to ' + (p.llr >= 0 ? 'pass' : 'fail') + ' bound');
}
if (p.estimated)
div('llrc-tip-sub', tip, 'estimated');
tip.classList.add('is-active');
var w = tip.offsetWidth, h = tip.offsetHeight;
var left = x + 14;
if (left + w > g.W - 2) left = x - w - 14;
var top = y - h - 12;
if (top < 0) top = y + 14;
tip.style.left = Math.max(left, 0) + 'px';
tip.style.top = Math.max(top, 0) + 'px';
}; };
/* ---------- events ---------- */ /* ---------- events ---------- */
LlrChart.prototype.pointerX = function (event) { Graph.prototype.bind = function () {
var box = this.svgEl.getBoundingClientRect(); var self = this, plot = this.plot;
return (event.clientX - box.left) * (this.g.W / (box.width || this.g.W));
};
LlrChart.prototype.announce = function (index) {
var p = this.points[index];
this.live.textContent = commas(p.games) + ' games, LLR ' + fmt(p.llr, 2) + (p.estimated ? ', estimated' : '');
};
LlrChart.prototype.bind = function () {
var self = this;
var plot = this.plot;
function move(event) { function move(event) {
if (self.g) if (!self.g)
self.setActive(self.pick(self.pointerX(event))); return;
var box = self.svgEl.getBoundingClientRect();
var x = (event.clientX - box.left) * (self.g.W / (box.width || self.g.W));
self.setActive(self.pick(x));
} }
plot.addEventListener('pointerenter', move); plot.addEventListener('pointerenter', move);
plot.addEventListener('pointermove', move); plot.addEventListener('pointermove', move);
plot.addEventListener('pointerdown', move); plot.addEventListener('pointerdown', move);
plot.addEventListener('pointerleave', function (event) { plot.addEventListener('pointerleave', function (event) {
if (event.pointerType === 'mouse') if (event.pointerType === 'mouse')
self.setActive(-1); self.setActive(-1);
@@ -607,26 +350,23 @@
plot.addEventListener('keydown', function (event) { plot.addEventListener('keydown', function (event) {
var count = self.points.length; var last = self.points.length - 1;
var step = event.shiftKey ? 10 : 1; var step = event.shiftKey ? 10 : 1;
var index = self.active; var index = self.active;
if (event.key === 'ArrowLeft') index = index < 0 ? count - 1 : index - step; if (event.key === 'ArrowLeft') index = index < 0 ? last : index - step;
else if (event.key === 'ArrowRight') index = index < 0 ? count - 1 : index + step; else if (event.key === 'ArrowRight') index = index < 0 ? last : index + step;
else if (event.key === 'Home') index = 0; else if (event.key === 'Home') index = 0;
else if (event.key === 'End') index = count - 1; else if (event.key === 'End') index = last;
else if (event.key === 'Escape') { self.setActive(-1); return; } else if (event.key === 'Escape') { self.setActive(-1); return; }
else return; else return;
event.preventDefault(); event.preventDefault();
index = clamp(index, 0, count - 1); self.setActive(clamp(index, 0, last));
self.setActive(index);
self.announce(index);
}); });
plot.addEventListener('blur', function () { self.setActive(-1); }); plot.addEventListener('blur', function () { self.setActive(-1); });
// Redraw when the card changes width
function redraw() { function redraw() {
if (Math.floor(plot.clientWidth) !== self.rendered) if (Math.floor(plot.clientWidth) !== self.rendered)
self.render(); self.render();
@@ -648,22 +388,9 @@
Loading Loading
====================================================================== */ ====================================================================== */
function showMessage(container, text, retry) { function showError(container, text) {
container.textContent = '';
container.removeAttribute('aria-busy'); container.removeAttribute('aria-busy');
container.innerHTML = '<div class="llr-history-placeholder llr-history-placeholder-error">' + text + '</div>';
var box = div('llrc-message', container);
span('', box, text);
if (retry) {
var button = document.createElement('button');
button.type = 'button';
button.className = 'anchorbutton btn-start llrc-retry';
button.textContent = 'Retry';
button.addEventListener('click', retry);
box.appendChild(button);
}
} }
function load(container) { function load(container) {
@@ -688,16 +415,12 @@
var node = container.querySelector('.llr-chart'); var node = container.querySelector('.llr-chart');
if (!node) if (!node)
return showMessage(container, 'No LLR history to show yet.'); return showError(container, 'No history to show yet.');
try { new Graph(node, JSON.parse(node.getAttribute('data-chart')));
new LlrChart(node, JSON.parse(node.getAttribute('data-chart')));
} catch (error) {
showMessage(container, 'Unable to draw the history graph.', function () { load(container); });
}
}).catch(function () { }).catch(function () {
showMessage(container, 'Unable to load the history graph.', function () { load(container); }); showError(container, 'Unable to load history graph.');
}); });
} }
+62 -377
View File
@@ -1,161 +1,18 @@
/* ========================================================================== /* ==========================================================================
OpenBench - workload page: layout + LLR history chart OpenBench - workload page: LLR history graph
Loaded after style.css, so same-specificity rules here win. (the panel itself, its label and the placeholder are styled in style.css)
========================================================================== */ ========================================================================== */
/* ---------- Layout ---------- */
#content .workload-container {
grid-template-columns: minmax(0, 1fr) 372px;
}
#content #config { grid-column: 1; grid-row: 1; }
#content #llr { grid-column: 1; grid-row: 2; }
#content #actions { grid-column: 2; grid-row: 1 / span 2; padding-bottom: 16px; }
#content #parameters,
#content #results {
grid-column: 1 / -1;
grid-row: auto;
}
@media (max-width: 1100px) {
#content .workload-container {
grid-template-columns: minmax(0, 1fr);
}
#content #config,
#content #llr,
#content #actions,
#content #parameters,
#content #results {
grid-column: 1;
grid-row: auto;
}
#content #actions {
order: -1;
}
}
/* ---------- LLR card ---------- */
#content .llr-history-loader { #content .llr-history-loader {
min-height: 200px; width: 100%;
} }
#content .llrc-skeleton, #content .llr-history-placeholder {
#content .llrc-message { width: 100%;
display: flex; height: 124px;
align-items: center;
justify-content: center;
gap: 14px;
min-height: 220px;
padding: 24px;
color: var(--muted);
font-size: 13px;
text-align: center;
} }
#content .llrc-skeleton { #content .llrg-plot {
background: linear-gradient(100deg, transparent 30%, rgba(255, 255, 255, 0.035) 50%, transparent 70%) 0 0 / 200% 100%;
animation: llrc-shimmer 1.4s linear infinite;
}
#content .llrc-retry {
padding: 6px 12px;
}
@keyframes llrc-shimmer {
to { background-position: -200% 0; }
}
#content .llrc {
position: relative;
padding: 18px 20px 14px;
}
/* Header */
#content .llrc-head {
display: flex;
flex-wrap: wrap;
align-items: flex-end;
gap: 12px 32px;
margin-bottom: 16px;
}
#content .llrc-stat {
display: flex;
align-items: baseline;
gap: 8px;
}
#content .llrc-stat-label {
color: var(--muted);
font-size: 11.5px;
font-weight: 600;
letter-spacing: 0.1em;
}
#content .llrc-value {
font-family: var(--font-mono);
font-size: 30px;
font-weight: 600;
letter-spacing: -0.02em;
line-height: 1;
font-variant-numeric: tabular-nums;
}
#content .llrc-value.is-pos { color: var(--ok); }
#content .llrc-value.is-neg { color: var(--bad); }
#content .llrc-value.is-zero { color: var(--color-font1); }
#content .llrc-of {
color: var(--muted);
font-family: var(--font-mono);
font-size: 13px;
}
#content .llrc-progress {
flex: 1 1 200px;
max-width: 340px;
min-width: 180px;
}
#content .llrc-progress-top {
margin-bottom: 7px;
color: var(--muted);
font-size: 12px;
}
#content .llrc-bar {
height: 4px;
overflow: hidden;
background-color: var(--line-strong);
border-radius: var(--radius);
}
#content .llrc-bar > span {
display: block;
height: 100%;
transition: width 0.7s cubic-bezier(0.2, 0.8, 0.2, 1);
}
#content .llrc-bar > .is-pos { background-color: var(--ok); }
#content .llrc-bar > .is-neg { background-color: var(--bad); }
#content .llrc-games {
margin-left: auto;
color: var(--muted);
font-family: var(--font-mono);
font-size: 12.5px;
}
/* Plot */
#content .llrc-plot {
position: relative; position: relative;
cursor: crosshair; cursor: crosshair;
touch-action: pan-y; touch-action: pan-y;
@@ -163,171 +20,91 @@
-webkit-user-select: none; -webkit-user-select: none;
} }
#content .llrc-plot:focus-visible { #content .llrg-plot:focus-visible {
outline: 2px solid var(--accent); outline: 2px solid var(--accent);
outline-offset: 4px; outline-offset: 4px;
} }
#content .llrc-svg { #content .llrg-svg {
display: block; display: block;
width: 100%; width: 100%;
height: auto; height: auto;
overflow: visible; overflow: visible;
} }
.llrc-tick { .llrg-bg {
fill: var(--color1);
stroke: var(--line-strong);
stroke-width: 1;
}
.llrg-grid {
stroke: rgba(197, 204, 217, 0.09);
stroke-width: 1;
shape-rendering: crispEdges;
}
.llrg-zero {
stroke: #6E7FA6;
stroke-width: 1;
opacity: 0.7;
}
.llrg-bound {
stroke: var(--bad);
stroke-width: 1;
stroke-dasharray: 4 3;
opacity: 0.8;
}
.llrg-tick {
fill: var(--muted); fill: var(--muted);
font: 500 10.5px var(--font-mono); font: 500 10px var(--font-mono);
} }
.llrc-grid { .llrg-line {
stroke: rgba(197, 204, 217, 0.07);
stroke-width: 1;
shape-rendering: crispEdges;
}
.llrc-grid-v {
stroke: rgba(197, 204, 217, 0.04);
}
.llrc-zero {
stroke: rgba(197, 204, 217, 0.3);
stroke-width: 1;
shape-rendering: crispEdges;
}
.llrc-zone-pos { fill: rgba(52, 211, 153, 0.05); }
.llrc-zone-neg { fill: rgba(248, 113, 113, 0.05); }
.llrc-bound {
stroke-width: 1;
stroke-dasharray: 5 4;
opacity: 0.85;
}
.llrc-bound-pos { stroke: var(--ok); }
.llrc-bound-neg { stroke: var(--bad); }
.llrc-bound-label {
font: 600 10px var(--font-mono);
letter-spacing: 0.08em;
opacity: 0.9;
}
.llrc-bound-label-pos { fill: var(--ok); }
.llrc-bound-label-neg { fill: var(--bad); }
.llrc-stop-pos { stop-color: var(--ok); }
.llrc-stop-neg { stop-color: var(--bad); }
.llrc-line {
fill: none; fill: none;
stroke-width: 2; stroke-width: 2;
stroke-linecap: round; stroke-linecap: round;
stroke-linejoin: round; stroke-linejoin: round;
} }
.llrc-line-pos { stroke: var(--ok); } .llrg-line-pos { stroke: var(--ok); }
.llrc-line-neg { stroke: var(--bad); } .llrg-line-neg { stroke: var(--bad); }
.llrc-line-est { .llrg-hover-line {
stroke-dasharray: 3 4; stroke: var(--color-font1);
opacity: 0.9; stroke-width: 1;
} stroke-dasharray: 2 2;
.llrc-animate .llrc-line-solid {
stroke-dasharray: 1;
stroke-dashoffset: 1;
animation: llrc-draw 0.9s cubic-bezier(0.22, 0.7, 0.2, 1) 0.05s forwards;
}
.llrc-animate .llrc-area {
animation: llrc-fade 0.8s ease 0.25s both;
}
@keyframes llrc-draw { to { stroke-dashoffset: 0; } }
@keyframes llrc-fade { from { opacity: 0; } to { opacity: 1; } }
/* Latest value marker */
.llrc-now {
stroke: var(--color2);
stroke-width: 2;
}
.llrc-now.is-pos { fill: var(--ok); }
.llrc-now.is-neg { fill: var(--bad); }
.llrc-now.is-zero { fill: var(--color-font1); }
.llrc-now-ring {
fill: none;
stroke-width: 1.5;
transform-box: fill-box;
transform-origin: center;
animation: llrc-pulse 2s ease-out infinite;
}
.llrc-now-ring.is-pos { stroke: var(--ok); }
.llrc-now-ring.is-neg { stroke: var(--bad); }
.llrc-now-ring.is-zero { stroke: var(--color-font1); }
@keyframes llrc-pulse {
0% { transform: scale(0.7); opacity: 0.8; }
100% { transform: scale(2.6); opacity: 0; }
}
/* Crosshair */
.llrc-hover {
opacity: 0; opacity: 0;
pointer-events: none;
transition: opacity 0.12s ease;
} }
.llrc-hover.is-active { .llrg-hover-dot {
opacity: 1; fill: var(--color-font1);
stroke-width: 1.5;
opacity: 0;
} }
.llrc-hover-v { .llrg-hover-line.active,
stroke: rgba(241, 244, 250, 0.35); .llrg-hover-dot.active {
stroke-width: 1; opacity: 0.85;
stroke-dasharray: 3 3;
} }
.llrc-hover-h { .llrg-hover-dot.llrg-pos { stroke: var(--ok); }
stroke: rgba(241, 244, 250, 0.14); .llrg-hover-dot.llrg-neg { stroke: var(--bad); }
stroke-width: 1;
}
.llrc-hover-halo.is-pos { fill: rgba(52, 211, 153, 0.22); } #content .llrg-tip {
.llrc-hover-halo.is-neg { fill: rgba(248, 113, 113, 0.22); }
.llrc-hover-halo.is-zero { fill: rgba(241, 244, 250, 0.2); }
.llrc-hover-dot {
stroke: var(--color1);
stroke-width: 2;
}
.llrc-hover-dot.is-pos { fill: var(--ok); }
.llrc-hover-dot.is-neg { fill: var(--bad); }
.llrc-hover-dot.is-zero { fill: var(--color-font1); }
/* Tooltip */
#content .llrc-tip {
position: absolute; position: absolute;
left: 0; left: 0;
top: 0; top: 0;
z-index: 2; z-index: 1;
min-width: 120px; padding: 0.2rem 0.5rem 0.18rem;
padding: 8px 10px; background-color: rgba(11, 14, 20, 0.96);
background-color: rgba(11, 14, 20, 0.97);
border: 1px solid var(--line-strong); border: 1px solid var(--line-strong);
border-radius: var(--radius); border-radius: var(--radius);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45); color: var(--color-font1);
font-family: var(--font-mono); font-family: var(--font-mono);
font-size: 12px; font-size: 0.72rem;
line-height: 1.45;
white-space: nowrap; white-space: nowrap;
pointer-events: none; pointer-events: none;
opacity: 0; opacity: 0;
@@ -335,105 +112,13 @@
transition: opacity 0.12s ease, transform 0.12s ease; transition: opacity 0.12s ease, transform 0.12s ease;
} }
#content .llrc-tip.is-active { #content .llrg-tip.active {
opacity: 1; opacity: 1;
transform: none; transform: translateY(0);
}
#content .llrc-tip-games {
color: var(--color-font1);
font-weight: 600;
}
#content .llrc-tip-llr {
display: flex;
justify-content: space-between;
gap: 16px;
}
#content .llrc-tip-label {
color: var(--muted);
}
#content .llrc-tip-value.is-pos { color: var(--ok); }
#content .llrc-tip-value.is-neg { color: var(--bad); }
#content .llrc-tip-value.is-zero { color: var(--color-font1); }
#content .llrc-tip-sub {
color: var(--muted);
font-size: 11px;
}
/* Legend */
#content .llrc-legend {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 6px 18px;
margin-top: 10px;
color: var(--muted);
font-size: 12px;
}
#content .llrc-key {
display: inline-flex;
align-items: center;
gap: 8px;
}
#content .llrc-swatch {
display: inline-block;
width: 18px;
height: 0;
}
#content .llrc-swatch-line { border-top: 2px solid var(--ok); }
#content .llrc-swatch-est { border-top: 2px dotted var(--ok); }
#content .llrc-swatch-bound { border-top: 1px dashed var(--muted); }
#content .llrc-hint {
margin-left: auto;
opacity: 0.8;
}
#content .llrc-sr {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip: rect(0 0 0 0);
white-space: nowrap;
}
@media (max-width: 640px) {
#content .llrc {
padding: 16px 12px 12px;
}
#content .llrc-hint {
display: none;
}
#content .llrc-value {
font-size: 26px;
}
} }
@media (prefers-reduced-motion: reduce) { @media (prefers-reduced-motion: reduce) {
#content .llrg-tip {
.llrc-animate .llrc-line-solid, transition: none;
.llrc-animate .llrc-area,
.llrc-now-ring {
animation: none;
}
.llrc-animate .llrc-line-solid {
stroke-dashoffset: 0;
}
#content .llrc-skeleton {
animation: none;
} }
} }
+9 -11
View File
@@ -198,19 +198,17 @@
</div> </div>
</div> </div>
</form> </form>
</div>
<!-- LLR history for SPRT tests: the data is fetched lazily, and drawn by llr_history.js --> <!-- LLR history for SPRT tests: fetched lazily, and drawn by llr_history.js -->
{% if workload.test_mode == "SPRT" %} {% if workload.test_mode == "SPRT" %}
<div id="llr" class="card"> <div class="llr-history-panel" title="LLR history over the lifetime of the test">
<header class="card-head"> <div class="llr-history-label">LLR History</div>
<h2 class="card-title">LLR History</h2> <div id="llr-history-container" class="llr-history-loader" data-history-url="{{llr_history_endpoint}}">
</header> <div class="llr-history-placeholder">Loading history graph...</div>
<div id="llr-history-container" class="llr-history-loader" data-history-url="{{llr_history_endpoint}}" aria-busy="true"> </div>
<div class="llrc-skeleton" role="status">Loading history&hellip;</div>
</div> </div>
</div> {% endif %}
{% endif %} </div>
<!-- SPSA Paramater Summary, for Tunes --> <!-- SPSA Paramater Summary, for Tunes -->
{% if type == "TUNE" %} {% if type == "TUNE" %}