LLR history: responsive client-side chart with snapping crosshair
- llr_history.js: draws the chart in the browser (fills its card, crisp at any width), nice axis ticks, green/red line + area split at zero, pass/fail bound lines and zones, estimated segments dashed, live-pulse marker, progress-to-bound header, entrance animation - Snapping: crosshair locks to the nearest point and is pulled towards nearby peaks/valleys; mouse, touch scrubbing and keyboard (arrows, Shift x10, Home/End, Escape) with screen-reader announcements - Loading: skeleton, error state with Retry - mytags.llr_history_graph now only returns data (JSON in data-chart); the old static SVG renderer is kept as _llr_history_graph_static - workload.html: LLR gets its own wide card, inline script removed, fixed a stray <tr> in the SPSA parameter table - workload.css: grid placement + chart styles
This commit is contained in:
1 parent
acf5c004cb
commit
8ac2335020
4 files changed
+1196
-208
No files matched your search
@@ -0,0 +1,710 @@
|
||||
/* ==========================================================================
|
||||
OpenBench - LLR history chart
|
||||
|
||||
The server (mytags.llr_history_graph) only supplies data: a <div
|
||||
class="llr-chart" data-chart="{json}">. Everything is drawn here, so the
|
||||
chart fills the width of its card and stays crisp on any screen.
|
||||
|
||||
Interaction
|
||||
- the crosshair snaps to the nearest data point, and is pulled towards
|
||||
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 () {
|
||||
'use strict';
|
||||
|
||||
var SVG_NS = 'http://www.w3.org/2000/svg';
|
||||
var MINUS = '\u2212';
|
||||
var MAGNET = 10; // px a peak / valley may pull the crosshair from the pointer
|
||||
var uid = 0;
|
||||
|
||||
/* ---------- tiny DOM helpers ---------- */
|
||||
|
||||
function svg(name, attrs, parent) {
|
||||
var node = document.createElementNS(SVG_NS, name);
|
||||
for (var key in attrs)
|
||||
if (Object.prototype.hasOwnProperty.call(attrs, key))
|
||||
node.setAttribute(key, attrs[key]);
|
||||
if (parent)
|
||||
parent.appendChild(node);
|
||||
return node;
|
||||
}
|
||||
|
||||
function div(className, parent, text) {
|
||||
var node = document.createElement('div');
|
||||
node.className = className;
|
||||
if (text !== undefined)
|
||||
node.textContent = text;
|
||||
if (parent)
|
||||
parent.appendChild(node);
|
||||
return node;
|
||||
}
|
||||
|
||||
function span(className, parent, text) {
|
||||
var node = document.createElement('span');
|
||||
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) {
|
||||
return String(Math.round(value)).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
||||
}
|
||||
|
||||
function trim(value) {
|
||||
return String(parseFloat(value.toFixed(2)));
|
||||
}
|
||||
|
||||
function compact(value) {
|
||||
var abs = Math.abs(value);
|
||||
if (abs >= 1e6) return trim(value / 1e6) + 'M';
|
||||
if (abs >= 1e3) return trim(value / 1e3) + 'k';
|
||||
return trim(value);
|
||||
}
|
||||
|
||||
function tone(value) {
|
||||
return value > 0 ? 'pos' : value < 0 ? 'neg' : 'zero';
|
||||
}
|
||||
|
||||
function clamp(value, min, max) {
|
||||
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
|
||||
function lowerBound(points, target) {
|
||||
|
||||
var lo = 0, hi = points.length;
|
||||
while (lo < hi) {
|
||||
var mid = (lo + hi) >> 1;
|
||||
if (points[mid].games < target) lo = mid + 1;
|
||||
else hi = mid;
|
||||
}
|
||||
return lo;
|
||||
}
|
||||
|
||||
/* ---------- path helpers ---------- */
|
||||
|
||||
// Keep first / min / max / last of every pixel column, for very long histories
|
||||
function decimate(points, sx) {
|
||||
|
||||
var out = [], i = 0, n = points.length;
|
||||
|
||||
while (i < n) {
|
||||
|
||||
var key = Math.round(sx(points[i].games));
|
||||
var j = i, lo = i, hi = i;
|
||||
|
||||
while (j + 1 < n && Math.round(sx(points[j + 1].games)) === key) {
|
||||
j++;
|
||||
if (points[j].llr < points[lo].llr) lo = j;
|
||||
if (points[j].llr > points[hi].llr) hi = j;
|
||||
}
|
||||
|
||||
var picks = [i, lo, hi, j].filter(function (value, index, all) {
|
||||
return all.indexOf(value) === index;
|
||||
}).sort(function (a, b) { return a - b; });
|
||||
|
||||
for (var k = 0; k < picks.length; k++)
|
||||
out.push(points[picks[k]]);
|
||||
|
||||
i = j + 1;
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// Split into runs of consecutive points for which test(a, b) holds
|
||||
function runs(points, test) {
|
||||
|
||||
var out = [], run = null;
|
||||
|
||||
for (var i = 1; i < points.length; i++) {
|
||||
if (test(points[i - 1], points[i])) {
|
||||
if (!run) { run = [points[i - 1]]; out.push(run); }
|
||||
run.push(points[i]);
|
||||
} else {
|
||||
run = null;
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
/* ======================================================================
|
||||
Chart
|
||||
====================================================================== */
|
||||
|
||||
function LlrChart(root, data) {
|
||||
|
||||
this.root = root;
|
||||
this.lower = Number(data.lower);
|
||||
this.upper = Number(data.upper);
|
||||
this.current = Number(data.current);
|
||||
this.games = Number(data.games);
|
||||
this.finished = !!data.finished;
|
||||
this.active = -1;
|
||||
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) {
|
||||
return { games: Number(p[0]), llr: Number(p[1]), estimated: !!p[2] };
|
||||
}).sort(function (a, b) { return a.games - b.games; });
|
||||
|
||||
this.markExtremes();
|
||||
this.build();
|
||||
this.render();
|
||||
this.bind();
|
||||
}
|
||||
|
||||
// Flag local peaks and valleys of the measured (non estimated) points
|
||||
LlrChart.prototype.markExtremes = function () {
|
||||
|
||||
var real = this.points.filter(function (p) { return !p.estimated; });
|
||||
|
||||
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;
|
||||
|
||||
this.rendered = plotWidth;
|
||||
|
||||
var W = plotWidth;
|
||||
var H = W < 460 ? 196 : 244;
|
||||
var m = { l: 46, r: 14, t: 14, b: 26 };
|
||||
var iw = W - m.l - m.r;
|
||||
var ih = H - m.t - m.b;
|
||||
|
||||
var points = this.points;
|
||||
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 */
|
||||
|
||||
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) {
|
||||
if (p.llr < lo) lo = 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 = lo - pad;
|
||||
var yMax = hi + pad;
|
||||
|
||||
function sx(games) { return m.l + iw * (games / xMax); }
|
||||
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 };
|
||||
|
||||
var zeroY = sy(0);
|
||||
var id = 'llrc' + (++uid);
|
||||
var el = this.svgEl;
|
||||
|
||||
el.textContent = '';
|
||||
el.setAttribute('viewBox', '0 0 ' + W + ' ' + H);
|
||||
el.setAttribute('width', W);
|
||||
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 gradPos = svg('linearGradient', { id: id + '-gp', gradientUnits: 'userSpaceOnUse',
|
||||
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) {
|
||||
|
||||
var y = sy(value);
|
||||
if (y < m.t - 0.5 || y > H - m.b + 0.5)
|
||||
return;
|
||||
|
||||
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) {
|
||||
|
||||
var x = sx(value);
|
||||
svg('line', { 'class': 'llrc-grid llrc-grid-v', x1: x, x2: x, y1: m.t, y2: H - m.b }, 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 */
|
||||
|
||||
if (this.hasBounds) {
|
||||
|
||||
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 */
|
||||
|
||||
var last = points[points.length - 1];
|
||||
var kind = tone(last.llr);
|
||||
|
||||
if (!this.finished)
|
||||
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 + '%'; });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (this.active >= 0)
|
||||
this.setActive(this.active, true);
|
||||
};
|
||||
|
||||
/* ---------- snapping ---------- */
|
||||
|
||||
// Index of the point the crosshair should snap to for a pointer at x (px, svg space)
|
||||
LlrChart.prototype.pick = function (x) {
|
||||
|
||||
var g = this.g, points = this.points;
|
||||
var target = clamp((x - g.m.l) / g.iw, 0, 1) * g.xMax;
|
||||
|
||||
var after = lowerBound(points, target);
|
||||
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;
|
||||
|
||||
// Pull towards a nearby peak / valley
|
||||
var magnet = -1, magnetDistance = MAGNET + 1;
|
||||
|
||||
for (var i = best; i >= 0; i--) {
|
||||
var d = Math.abs(g.sx(points[i].games) - x);
|
||||
if (d > MAGNET) break;
|
||||
if (points[i].extreme && d < magnetDistance) { magnet = i; magnetDistance = d; }
|
||||
}
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
LlrChart.prototype.setActive = function (index, keepTip) {
|
||||
|
||||
if (index < 0 || !this.g) {
|
||||
this.active = -1;
|
||||
this.hover.classList.remove('is-active');
|
||||
this.tip.classList.remove('is-active');
|
||||
return;
|
||||
}
|
||||
|
||||
var g = this.g;
|
||||
var p = this.points[index];
|
||||
var x = g.sx(p.games);
|
||||
var y = g.sy(p.llr);
|
||||
var k = tone(p.llr);
|
||||
|
||||
this.active = index;
|
||||
|
||||
this.hv.setAttribute('x1', x); this.hv.setAttribute('x2', x);
|
||||
this.hh.setAttribute('y1', y); this.hh.setAttribute('y2', y);
|
||||
this.hr.setAttribute('cx', x); this.hr.setAttribute('cy', y);
|
||||
this.hd.setAttribute('cx', x); this.hd.setAttribute('cy', y);
|
||||
this.hr.setAttribute('class', 'llrc-hover-halo is-' + k);
|
||||
this.hd.setAttribute('class', 'llrc-hover-dot is-' + k);
|
||||
this.hover.classList.add('is-active');
|
||||
|
||||
/* Tooltip */
|
||||
|
||||
var tip = this.tip;
|
||||
tip.textContent = '';
|
||||
|
||||
div('llrc-tip-games', tip, commas(p.games) + ' games');
|
||||
|
||||
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 ---------- */
|
||||
|
||||
LlrChart.prototype.pointerX = function (event) {
|
||||
|
||||
var box = this.svgEl.getBoundingClientRect();
|
||||
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) {
|
||||
if (self.g)
|
||||
self.setActive(self.pick(self.pointerX(event)));
|
||||
}
|
||||
|
||||
plot.addEventListener('pointerenter', move);
|
||||
plot.addEventListener('pointermove', move);
|
||||
plot.addEventListener('pointerdown', move);
|
||||
|
||||
plot.addEventListener('pointerleave', function (event) {
|
||||
if (event.pointerType === 'mouse')
|
||||
self.setActive(-1);
|
||||
});
|
||||
|
||||
plot.addEventListener('keydown', function (event) {
|
||||
|
||||
var count = self.points.length;
|
||||
var step = event.shiftKey ? 10 : 1;
|
||||
var index = self.active;
|
||||
|
||||
if (event.key === 'ArrowLeft') index = index < 0 ? count - 1 : index - step;
|
||||
else if (event.key === 'ArrowRight') index = index < 0 ? count - 1 : index + step;
|
||||
else if (event.key === 'Home') index = 0;
|
||||
else if (event.key === 'End') index = count - 1;
|
||||
else if (event.key === 'Escape') { self.setActive(-1); return; }
|
||||
else return;
|
||||
|
||||
event.preventDefault();
|
||||
index = clamp(index, 0, count - 1);
|
||||
self.setActive(index);
|
||||
self.announce(index);
|
||||
});
|
||||
|
||||
plot.addEventListener('blur', function () { self.setActive(-1); });
|
||||
|
||||
// Redraw when the card changes width
|
||||
function redraw() {
|
||||
if (Math.floor(plot.clientWidth) !== self.rendered)
|
||||
self.render();
|
||||
}
|
||||
|
||||
if ('ResizeObserver' in window) {
|
||||
var queued = false;
|
||||
new ResizeObserver(function () {
|
||||
if (queued) return;
|
||||
queued = true;
|
||||
window.requestAnimationFrame(function () { queued = false; redraw(); });
|
||||
}).observe(plot);
|
||||
} else {
|
||||
window.addEventListener('resize', redraw);
|
||||
}
|
||||
};
|
||||
|
||||
/* ======================================================================
|
||||
Loading
|
||||
====================================================================== */
|
||||
|
||||
function showMessage(container, text, retry) {
|
||||
|
||||
container.textContent = '';
|
||||
container.removeAttribute('aria-busy');
|
||||
|
||||
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) {
|
||||
|
||||
var url = container.getAttribute('data-history-url');
|
||||
if (!url)
|
||||
return;
|
||||
|
||||
container.setAttribute('aria-busy', 'true');
|
||||
|
||||
fetch(url, { credentials: 'same-origin' }).then(function (response) {
|
||||
|
||||
if (!response.ok)
|
||||
throw new Error('Unable to load history graph');
|
||||
|
||||
return response.text();
|
||||
|
||||
}).then(function (markup) {
|
||||
|
||||
container.innerHTML = markup;
|
||||
container.removeAttribute('aria-busy');
|
||||
|
||||
var node = container.querySelector('.llr-chart');
|
||||
if (!node)
|
||||
return showMessage(container, 'No LLR history to show yet.');
|
||||
|
||||
try {
|
||||
new LlrChart(node, JSON.parse(node.getAttribute('data-chart')));
|
||||
} catch (error) {
|
||||
showMessage(container, 'Unable to draw the history graph.', function () { load(container); });
|
||||
}
|
||||
|
||||
}).catch(function () {
|
||||
showMessage(container, 'Unable to load the history graph.', function () { load(container); });
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
var container = document.getElementById('llr-history-container');
|
||||
if (container)
|
||||
load(container);
|
||||
});
|
||||
|
||||
})();
|
||||
@@ -0,0 +1,439 @@
|
||||
/* ==========================================================================
|
||||
OpenBench - workload page: layout + LLR history chart
|
||||
Loaded after style.css, so same-specificity rules here win.
|
||||
========================================================================== */
|
||||
|
||||
/* ---------- 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 {
|
||||
min-height: 200px;
|
||||
}
|
||||
|
||||
#content .llrc-skeleton,
|
||||
#content .llrc-message {
|
||||
display: flex;
|
||||
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 {
|
||||
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;
|
||||
cursor: crosshair;
|
||||
touch-action: pan-y;
|
||||
user-select: none;
|
||||
-webkit-user-select: none;
|
||||
}
|
||||
|
||||
#content .llrc-plot:focus-visible {
|
||||
outline: 2px solid var(--accent);
|
||||
outline-offset: 4px;
|
||||
}
|
||||
|
||||
#content .llrc-svg {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: auto;
|
||||
overflow: visible;
|
||||
}
|
||||
|
||||
.llrc-tick {
|
||||
fill: var(--muted);
|
||||
font: 500 10.5px var(--font-mono);
|
||||
}
|
||||
|
||||
.llrc-grid {
|
||||
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;
|
||||
stroke-width: 2;
|
||||
stroke-linecap: round;
|
||||
stroke-linejoin: round;
|
||||
}
|
||||
|
||||
.llrc-line-pos { stroke: var(--ok); }
|
||||
.llrc-line-neg { stroke: var(--bad); }
|
||||
|
||||
.llrc-line-est {
|
||||
stroke-dasharray: 3 4;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.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;
|
||||
pointer-events: none;
|
||||
transition: opacity 0.12s ease;
|
||||
}
|
||||
|
||||
.llrc-hover.is-active {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.llrc-hover-v {
|
||||
stroke: rgba(241, 244, 250, 0.35);
|
||||
stroke-width: 1;
|
||||
stroke-dasharray: 3 3;
|
||||
}
|
||||
|
||||
.llrc-hover-h {
|
||||
stroke: rgba(241, 244, 250, 0.14);
|
||||
stroke-width: 1;
|
||||
}
|
||||
|
||||
.llrc-hover-halo.is-pos { fill: rgba(52, 211, 153, 0.22); }
|
||||
.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;
|
||||
left: 0;
|
||||
top: 0;
|
||||
z-index: 2;
|
||||
min-width: 120px;
|
||||
padding: 8px 10px;
|
||||
background-color: rgba(11, 14, 20, 0.97);
|
||||
border: 1px solid var(--line-strong);
|
||||
border-radius: var(--radius);
|
||||
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
|
||||
font-family: var(--font-mono);
|
||||
font-size: 12px;
|
||||
line-height: 1.45;
|
||||
white-space: nowrap;
|
||||
pointer-events: none;
|
||||
opacity: 0;
|
||||
transform: translateY(2px);
|
||||
transition: opacity 0.12s ease, transform 0.12s ease;
|
||||
}
|
||||
|
||||
#content .llrc-tip.is-active {
|
||||
opacity: 1;
|
||||
transform: none;
|
||||
}
|
||||
|
||||
#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) {
|
||||
|
||||
.llrc-animate .llrc-line-solid,
|
||||
.llrc-animate .llrc-area,
|
||||
.llrc-now-ring {
|
||||
animation: none;
|
||||
}
|
||||
|
||||
.llrc-animate .llrc-line-solid {
|
||||
stroke-dashoffset: 0;
|
||||
}
|
||||
|
||||
#content .llrc-skeleton {
|
||||
animation: none;
|
||||
}
|
||||
}
|
||||
@@ -204,7 +204,7 @@ def machine_name(machine_id):
|
||||
return machine.info['machine_name']
|
||||
except: return 'None'
|
||||
|
||||
def llr_history_graph(test, width=320, height=112):
|
||||
def _llr_history_graph_static(test, width=320, height=112):
|
||||
|
||||
if test.test_mode != 'SPRT':
|
||||
return ''
|
||||
@@ -407,6 +407,36 @@ def llr_history_graph(test, width=320, height=112):
|
||||
return mark_safe(svg)
|
||||
|
||||
|
||||
def llr_history_graph(test):
|
||||
"""Data for the LLR history chart, which is drawn in the browser by llr_history.js"""
|
||||
|
||||
import html as _html
|
||||
import json as _json
|
||||
from django.utils.safestring import mark_safe as _mark_safe
|
||||
|
||||
if test.test_mode != 'SPRT':
|
||||
return ''
|
||||
|
||||
history = [list(point) for point in OpenBench.utils.get_llr_history(test)]
|
||||
|
||||
# The line starts at the origin, and ends on the current state of the test
|
||||
if not history or history[0][0] > 0:
|
||||
history.insert(0, [0, 0.0, False])
|
||||
if history[-1][0] != test.games or history[-1][1] != test.currentllr:
|
||||
history.append([test.games, test.currentllr, False])
|
||||
|
||||
data = {
|
||||
'history' : [[int(p[0]), round(float(p[1]), 4), bool(p[2]) if len(p) > 2 else False] for p in history],
|
||||
'lower' : float(test.lowerllr),
|
||||
'upper' : float(test.upperllr),
|
||||
'current' : float(test.currentllr),
|
||||
'games' : int(test.games),
|
||||
'finished' : bool(test.finished),
|
||||
}
|
||||
|
||||
payload = _html.escape(_json.dumps(data, separators=(',', ':')), quote=True)
|
||||
return _mark_safe('<div class="llr-chart" data-chart="%s"></div>' % payload)
|
||||
|
||||
register = django.template.Library()
|
||||
register.filter('oneDigitPrecision', oneDigitPrecision)
|
||||
register.filter('twoDigitPrecision', twoDigitPrecision)
|
||||
|
||||
@@ -4,187 +4,9 @@
|
||||
{% load static %}
|
||||
|
||||
{% block scripts %}
|
||||
<link rel="stylesheet" href="{% static 'workload.css' %}?{{ static_version }}">
|
||||
<script src="{% static 'copy_text.js' %}?{{ static_version }}"></script>
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
var llrHistoryRequest = null;
|
||||
|
||||
function initializeLlrHistoryWidget(widget) {
|
||||
if (!widget || widget.dataset.initialized === 'true') return;
|
||||
|
||||
widget.dataset.initialized = 'true';
|
||||
|
||||
var history = JSON.parse(widget.dataset.history || '[]');
|
||||
if (!history.length) return;
|
||||
var realPoints = history.filter(function(point) { return !point.estimated; });
|
||||
var peakGames = {};
|
||||
|
||||
for (var r = 1; r < realPoints.length - 1; r++) {
|
||||
var prev = realPoints[r - 1];
|
||||
var curr = realPoints[r];
|
||||
var next = realPoints[r + 1];
|
||||
var isPeak = curr.llr > prev.llr && curr.llr > next.llr;
|
||||
var isValley = curr.llr < prev.llr && curr.llr < next.llr;
|
||||
|
||||
if (isPeak || isValley) {
|
||||
peakGames[curr.games] = true;
|
||||
}
|
||||
}
|
||||
|
||||
var svg = widget.querySelector('.llr-history-graph');
|
||||
var plot = widget.querySelector('.llr-history-plot');
|
||||
var hoverLine = widget.querySelector('.llr-hover-line');
|
||||
var hoverPoint = widget.querySelector('.llr-hover-point');
|
||||
var tooltip = widget.querySelector('.llr-history-tooltip');
|
||||
var viewBox = svg.viewBox.baseVal;
|
||||
|
||||
function clamp(value, min, max) {
|
||||
return Math.max(min, Math.min(max, value));
|
||||
}
|
||||
|
||||
function setActivePoint(point) {
|
||||
hoverLine.setAttribute('x1', point.x);
|
||||
hoverLine.setAttribute('x2', point.x);
|
||||
hoverPoint.setAttribute('cx', point.x);
|
||||
hoverPoint.setAttribute('cy', point.y);
|
||||
hoverPoint.classList.toggle('llr-hover-point-positive', point.llr >= 0);
|
||||
hoverPoint.classList.toggle('llr-hover-point-negative', point.llr < 0);
|
||||
|
||||
tooltip.textContent = point.games + ' games | LLR ' + (point.estimated ? '≈' : '') + point.llr.toFixed(2);
|
||||
tooltip.classList.add('active');
|
||||
|
||||
var left = clamp((point.x / viewBox.width) * plot.clientWidth + 8, 8, plot.clientWidth - tooltip.offsetWidth - 8);
|
||||
var top = clamp((point.y / viewBox.height) * svg.clientHeight - tooltip.offsetHeight - 8, 2, svg.clientHeight - tooltip.offsetHeight - 2);
|
||||
tooltip.style.left = left + 'px';
|
||||
tooltip.style.top = top + 'px';
|
||||
}
|
||||
|
||||
function clearActivePoint() {
|
||||
tooltip.classList.remove('active');
|
||||
hoverLine.classList.remove('active');
|
||||
hoverPoint.classList.remove('active', 'llr-hover-point-positive', 'llr-hover-point-negative');
|
||||
}
|
||||
|
||||
function nearestPoint(clientX) {
|
||||
var rect = svg.getBoundingClientRect();
|
||||
var localX = ((clientX - rect.left) / rect.width) * viewBox.width;
|
||||
var best = history[0];
|
||||
var bestDistance = Math.abs(best.x - localX);
|
||||
var bestPeak = null;
|
||||
var bestPeakDistance = Infinity;
|
||||
|
||||
for (var i = 0; i < history.length; i++) {
|
||||
var distance = Math.abs(history[i].x - localX);
|
||||
if (distance < bestDistance) {
|
||||
best = history[i];
|
||||
bestDistance = distance;
|
||||
}
|
||||
|
||||
if (!history[i].estimated && peakGames[history[i].games] && distance < bestPeakDistance) {
|
||||
bestPeak = history[i];
|
||||
bestPeakDistance = distance;
|
||||
}
|
||||
}
|
||||
|
||||
if (bestPeak && bestPeakDistance <= 5) {
|
||||
return bestPeak;
|
||||
}
|
||||
|
||||
return best;
|
||||
}
|
||||
|
||||
svg.addEventListener('mousemove', function(event) {
|
||||
setActivePoint(nearestPoint(event.clientX));
|
||||
hoverLine.classList.add('active');
|
||||
hoverPoint.classList.add('active');
|
||||
});
|
||||
|
||||
svg.addEventListener('mouseleave', function() {
|
||||
clearActivePoint();
|
||||
});
|
||||
|
||||
svg.addEventListener('mouseenter', function(event) {
|
||||
setActivePoint(nearestPoint(event.clientX));
|
||||
hoverLine.classList.add('active');
|
||||
hoverPoint.classList.add('active');
|
||||
});
|
||||
|
||||
clearActivePoint();
|
||||
}
|
||||
|
||||
function initializeLlrHistoryWidgets(root) {
|
||||
(root || document).querySelectorAll('.llr-history-widget').forEach(function(widget) {
|
||||
initializeLlrHistoryWidget(widget);
|
||||
});
|
||||
}
|
||||
|
||||
function ensureLlrHistoryWidget() {
|
||||
var existing = document.querySelector('.llr-history-widget');
|
||||
if (existing) {
|
||||
initializeLlrHistoryWidget(existing);
|
||||
return Promise.resolve(existing);
|
||||
}
|
||||
|
||||
var container = document.getElementById('llr-history-container');
|
||||
if (!container || !container.dataset.historyUrl) {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
|
||||
if (llrHistoryRequest) {
|
||||
return llrHistoryRequest;
|
||||
}
|
||||
|
||||
llrHistoryRequest = fetch(container.dataset.historyUrl, {
|
||||
credentials: 'same-origin'
|
||||
}).then(function(response) {
|
||||
if (!response.ok) {
|
||||
throw new Error('Unable to load history graph');
|
||||
}
|
||||
|
||||
return response.text();
|
||||
}).then(function(markup) {
|
||||
container.innerHTML = markup;
|
||||
container.removeAttribute('data-history-url');
|
||||
|
||||
var widget = container.querySelector('.llr-history-widget');
|
||||
initializeLlrHistoryWidget(widget);
|
||||
llrHistoryRequest = null;
|
||||
return widget;
|
||||
}).catch(function() {
|
||||
container.innerHTML = '<div class="llr-history-placeholder llr-history-placeholder-error">Unable to load history graph.</div>';
|
||||
llrHistoryRequest = null;
|
||||
return null;
|
||||
});
|
||||
|
||||
return llrHistoryRequest;
|
||||
}
|
||||
|
||||
function queueLlrHistoryWidgetLoad() {
|
||||
var container = document.getElementById('llr-history-container');
|
||||
if (!container || !container.dataset.historyUrl) return;
|
||||
|
||||
function requestGraphAfterPaint() {
|
||||
window.requestAnimationFrame(function() {
|
||||
window.requestAnimationFrame(function() {
|
||||
setTimeout(function() {
|
||||
ensureLlrHistoryWidget();
|
||||
}, 250);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (document.readyState === 'complete') {
|
||||
requestGraphAfterPaint();
|
||||
return;
|
||||
}
|
||||
|
||||
window.addEventListener('load', requestGraphAfterPaint, { once: true });
|
||||
}
|
||||
|
||||
initializeLlrHistoryWidgets(document);
|
||||
queueLlrHistoryWidgetLoad();
|
||||
});
|
||||
</script>
|
||||
<script src="{% static 'llr_history.js' %}?{{ static_version }}" defer></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block page_head %}<div><h1 class="page-title">{{ type|title }} #{{ workload.id }}</h1><p class="page-sub">{{ workload.dev.name|prettyName }} · by {{ workload.author|capfirst }}</p></div><div class="page-actions">{% if workload.deleted %}<span class="badge badge-muted">Deleted</span>{% elif workload.passed %}<span class="badge badge-ok">Passed</span>{% elif workload.failed %}<span class="badge badge-bad">Failed</span>{% elif workload.finished %}<span class="badge badge-info">Finished</span>{% elif not workload.approved %}<span class="badge badge-warn">Awaiting approval</span>{% else %}<span class="badge badge-info"><i class="fa-solid fa-circle-notch fa-spin"></i> Running</span>{% endif %}</div>{% endblock %}
|
||||
@@ -335,7 +157,7 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<!-- Elo, (SPRT/LRR if SPRT, otherwise CONF), Games -->
|
||||
<!-- Elo, (SPRT/LLR if SPRT, otherwise CONF), Games -->
|
||||
{% if type == "TEST" %}
|
||||
<pre class="long-statblock" id="long-statblock">{{workload|longStatBlock|linebreaksbr}}</pre>
|
||||
{% elif type == "TUNE" %}
|
||||
@@ -376,33 +198,20 @@
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
{% if workload.test_mode == "SPRT" %}
|
||||
<div class="llr-history-panel" title="LLR history over the lifetime of the test">
|
||||
<div class="llr-history-label">LLR History</div>
|
||||
<div id="llr-history-container" class="llr-history-loader" data-history-url="{{llr_history_endpoint}}">
|
||||
<div class="llr-history-chart">
|
||||
<div class="llr-history-yaxis">
|
||||
<div></div>
|
||||
<div></div>
|
||||
<div></div>
|
||||
</div>
|
||||
<div class="llr-history-main">
|
||||
<div class="llr-history-plot">
|
||||
<div class="llr-history-placeholder">Loading history graph...</div>
|
||||
</div>
|
||||
<div class="llr-history-xaxis">
|
||||
<div>0</div>
|
||||
<div></div>
|
||||
<div>{{workload.games}} g</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<!-- LLR history for SPRT tests: the data is fetched lazily, and drawn by llr_history.js -->
|
||||
{% if workload.test_mode == "SPRT" %}
|
||||
<div id="llr" class="card">
|
||||
<header class="card-head">
|
||||
<h2 class="card-title">LLR History</h2>
|
||||
</header>
|
||||
<div id="llr-history-container" class="llr-history-loader" data-history-url="{{llr_history_endpoint}}" aria-busy="true">
|
||||
<div class="llrc-skeleton" role="status">Loading history…</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<!-- SPSA Paramater Summary, for Tunes -->
|
||||
{% if type == "TUNE" %}
|
||||
<div id="parameters" class="card">
|
||||
@@ -424,7 +233,7 @@
|
||||
<td> {{ element }} </td>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
<tr>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user