live.js already polled /tune/<id>, but patching the page in place would have wiped the chart, reordered the parameter rows under their listeners, dropped pinned lines and closed any fold the reader had opened. - live.js: leave the chart, the parameter list and its empty notice alone, keep the 'open' attribute of folds, and fire a 'live:patched' event with the fresh page after every patch. - spsa_chart.js: on that event, hand the new history to the existing chart (pinned lines and the inspected point stay), or build it if the first results have just arrived. - spsa_panel.js: on that event, refresh the numbers, bars and limit markers of each row in place, and re-sort when sorted by movement without jumping the scroll position.
111 lines
3.9 KiB
JavaScript
111 lines
3.9 KiB
JavaScript
/* SPSA parameter panel: filter by name, sort by how far a parameter moved.
|
|
|
|
Live updates ( live.js ) never replace the rows, so the order, the filter,
|
|
the pinned lines and the hover all survive a refresh. The numbers in the
|
|
rows are brought up to date here, from the page that was just fetched. */
|
|
|
|
(function () {
|
|
|
|
// The parts of a row that only show numbers ( nothing in them carries a listener )
|
|
var CELLS = ['.spsa-track-wrap', '.spsa-value', '.spsa-delta'];
|
|
|
|
function flash(el) {
|
|
el.classList.remove('live-flash');
|
|
void el.offsetWidth;
|
|
el.classList.add('live-flash');
|
|
setTimeout(function () { el.classList.remove('live-flash'); }, 1500);
|
|
}
|
|
|
|
function init() {
|
|
|
|
var list = document.getElementById('spsa-rows');
|
|
var search = document.getElementById('spsa-filter');
|
|
var order = document.getElementById('spsa-sort');
|
|
var empty = document.getElementById('spsa-empty');
|
|
|
|
if (!list || !search || !order)
|
|
return;
|
|
|
|
var rows = Array.prototype.slice.call(list.children);
|
|
|
|
function apply(keepScroll) {
|
|
|
|
var term = search.value.trim().toLowerCase();
|
|
var shown = 0;
|
|
|
|
rows.sort(function (a, b) {
|
|
if (order.value === 'drift')
|
|
return parseFloat(b.dataset.drift) - parseFloat(a.dataset.drift);
|
|
if (order.value === 'name')
|
|
return a.dataset.name.localeCompare(b.dataset.name);
|
|
return parseInt(a.dataset.index, 10) - parseInt(b.dataset.index, 10);
|
|
});
|
|
|
|
rows.forEach(function (row) {
|
|
var match = row.dataset.name.indexOf(term) !== -1;
|
|
row.hidden = !match;
|
|
shown += match ? 1 : 0;
|
|
list.appendChild(row);
|
|
});
|
|
|
|
// A new order or filter starts at the top; a refresh leaves the reader where they are
|
|
if (!keepScroll)
|
|
list.scrollTop = 0;
|
|
|
|
if (empty)
|
|
empty.hidden = shown !== 0;
|
|
}
|
|
|
|
function refresh(fresh) {
|
|
|
|
var incoming = {};
|
|
Array.prototype.forEach.call(fresh.querySelectorAll('#spsa-rows .spsa-row'), function (row) {
|
|
incoming[row.getAttribute('data-index')] = row;
|
|
});
|
|
|
|
var moved = false;
|
|
|
|
rows.forEach(function (row) {
|
|
|
|
var next = incoming[row.getAttribute('data-index')];
|
|
if (!next)
|
|
return;
|
|
|
|
if (row.getAttribute('data-drift') !== next.getAttribute('data-drift')) {
|
|
row.setAttribute('data-drift', next.getAttribute('data-drift'));
|
|
moved = true;
|
|
}
|
|
|
|
row.classList.toggle('at-bound', next.classList.contains('at-bound'));
|
|
|
|
CELLS.forEach(function (selector) {
|
|
var current = row.querySelector(selector), latest = next.querySelector(selector);
|
|
if (!current || !latest || current.innerHTML === latest.innerHTML)
|
|
return;
|
|
current.innerHTML = latest.innerHTML;
|
|
if (selector !== '.spsa-track-wrap')
|
|
flash(current);
|
|
});
|
|
});
|
|
|
|
// Sorted by how far they moved: the order itself may have changed
|
|
if (moved && order.value === 'drift')
|
|
apply(true);
|
|
}
|
|
|
|
search.addEventListener('input', function () { apply(false); });
|
|
order.addEventListener('change', function () { apply(false); });
|
|
|
|
document.addEventListener('live:patched', function (event) {
|
|
if (event.detail && event.detail.fresh)
|
|
refresh(event.detail.fresh);
|
|
});
|
|
}
|
|
|
|
if (document.readyState === 'loading')
|
|
document.addEventListener('DOMContentLoaded', init);
|
|
else
|
|
init();
|
|
|
|
})();
|