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
@@ -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