LLR history: redraw in place when newer data arrives
This commit is contained in:
1 parent
6a024f3e5a
commit
deb68caa64
1 file changed
+52
-1
@@ -269,6 +269,25 @@
|
|||||||
this.setActive(this.active);
|
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 ---------- */
|
/* ---------- snapping ---------- */
|
||||||
|
|
||||||
Graph.prototype.pick = function (x) {
|
Graph.prototype.pick = function (x) {
|
||||||
@@ -417,13 +436,45 @@
|
|||||||
if (!node)
|
if (!node)
|
||||||
return showError(container, 'No history to show yet.');
|
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 () {
|
}).catch(function () {
|
||||||
showError(container, 'Unable to load history graph.');
|
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 () {
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
var container = document.getElementById('llr-history-container');
|
var container = document.getElementById('llr-history-container');
|
||||||
if (container)
|
if (container)
|
||||||
|
|||||||
Reference in new issue
Block a user