From deb68caa64f318c511c6b81a2a1f8483be775f9b Mon Sep 17 00:00:00 2001 From: claude Date: Sun, 11 Oct 2026 17:49:25 +0200 Subject: [PATCH] LLR history: redraw in place when newer data arrives --- OpenBench/static/llr_history.js | 53 ++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/OpenBench/static/llr_history.js b/OpenBench/static/llr_history.js index 5ed27a1..5d2a9f0 100644 --- a/OpenBench/static/llr_history.js +++ b/OpenBench/static/llr_history.js @@ -269,6 +269,25 @@ this.setActive(this.active); }; + /* Live updates: take a newer answer from the server and redraw in place. + The plot, and whichever point is being inspected, stay where they are. */ + + Graph.prototype.update = function (data) { + + this.lower = Number(data.lower); + this.upper = Number(data.upper); + this.games = Number(data.games); + + 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; }); + + if (this.active >= this.points.length) + this.active = -1; + + this.render(); + }; + /* ---------- snapping ---------- */ Graph.prototype.pick = function (x) { @@ -417,13 +436,45 @@ if (!node) return showError(container, 'No history to show yet.'); - new Graph(node, JSON.parse(node.getAttribute('data-chart'))); + graph = new Graph(node, JSON.parse(node.getAttribute('data-chart'))); }).catch(function () { showError(container, 'Unable to load history graph.'); }); } + var graph = null; + + function refresh(container) { + + var url = container.getAttribute('data-history-url'); + if (!url || !graph) + return Promise.resolve(); + + return fetch(url, { credentials: 'same-origin', cache: 'no-store' }).then(function (response) { + + if (!response.ok) + throw new Error('Unable to refresh history graph'); + + return response.text(); + + }).then(function (markup) { + + var holder = document.createElement('div'); + holder.innerHTML = markup; + + var node = holder.querySelector('.llr-chart'); + if (node) + graph.update(JSON.parse(node.getAttribute('data-chart'))); + }); + } + + // Called by live.js whenever the page has been brought up to date + window.refreshLLRHistory = function () { + var container = document.getElementById('llr-history-container'); + return container ? refresh(container).catch(function () { /* keep the current graph */ }) : Promise.resolve(); + }; + document.addEventListener('DOMContentLoaded', function () { var container = document.getElementById('llr-history-container'); if (container)