Spsa panel #12
No files matched your search
@@ -18,11 +18,13 @@
|
|||||||
var FULL = { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false };
|
var FULL = { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false };
|
||||||
var DAY = { month: 'short', day: '2-digit' };
|
var DAY = { month: 'short', day: '2-digit' };
|
||||||
|
|
||||||
// Never replaced: forms keep what is typed, banners can be dismissed, the graph loads itself
|
// Never replaced: forms keep what is typed, banners can be dismissed, the graphs load themselves.
|
||||||
var PROTECT = 'form, .banner, .llr-history-panel, [data-live-skip], script, style';
|
// The SPSA chart and parameter list ( Tune pages ) are interactive, so their scripts refresh them
|
||||||
|
// from the 'live:patched' event instead.
|
||||||
|
var PROTECT = 'form, .banner, .llr-history-panel, .spsa-chart, #spsa-rows, #spsa-empty, [data-live-skip], script, style';
|
||||||
|
|
||||||
// Attributes that other scripts add after the page loads
|
// Attributes that other scripts, or the reader, add after the page loads ( 'open' is a fold the reader opened )
|
||||||
var KEEP = { 'data-href': true, 'data-epoch': true };
|
var KEEP = { 'data-href': true, 'data-epoch': true, 'open': true };
|
||||||
|
|
||||||
/* ---------- Timestamps ----------
|
/* ---------- Timestamps ----------
|
||||||
The pages print raw epochs and the browser formats them. Remember the
|
The pages print raw epochs and the browser formats them. Remember the
|
||||||
@@ -176,6 +178,10 @@
|
|||||||
stash(fresh);
|
stash(fresh);
|
||||||
patchChildren(content, fresh);
|
patchChildren(content, fresh);
|
||||||
restoreRows();
|
restoreRows();
|
||||||
|
|
||||||
|
// Scripts that own a part of the page that is never patched ( see PROTECT ) refresh it from here
|
||||||
|
document.dispatchEvent(new CustomEvent('live:patched', { detail: { fresh: fresh } }));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,20 +73,7 @@
|
|||||||
this.active = -1;
|
this.active = -1;
|
||||||
this.width = 0;
|
this.width = 0;
|
||||||
|
|
||||||
// Movement from the start value, as a share of the allowed range
|
this.load(data);
|
||||||
this.series = data.names.map(function (name, i) {
|
|
||||||
var span = (data.max[i] - data.min[i]) || 1;
|
|
||||||
return data.points.map(function (point) {
|
|
||||||
return (point[1 + i] - data.start[i]) / span * 100;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Without a choice, follow whichever parameters moved the most
|
|
||||||
var last = this.series.map(function (line, i) {
|
|
||||||
return { index: i, size: Math.abs(line[line.length - 1]) };
|
|
||||||
});
|
|
||||||
last.sort(function (a, b) { return b.size - a.size || a.index - b.index; });
|
|
||||||
this.defaults = last.slice(0, 3).map(function (entry) { return entry.index; });
|
|
||||||
|
|
||||||
root.textContent = '';
|
root.textContent = '';
|
||||||
|
|
||||||
@@ -102,6 +89,33 @@
|
|||||||
this.bind();
|
this.bind();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// What is drawn follows from the server's data. Live updates call this again with newer data.
|
||||||
|
Chart.prototype.load = function (data) {
|
||||||
|
|
||||||
|
this.data = data;
|
||||||
|
|
||||||
|
// Movement from the start value, as a share of the allowed range
|
||||||
|
this.series = data.names.map(function (name, i) {
|
||||||
|
var span = (data.max[i] - data.min[i]) || 1;
|
||||||
|
return data.points.map(function (point) {
|
||||||
|
return (point[1 + i] - data.start[i]) / span * 100;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Without a choice, follow whichever parameters moved the most
|
||||||
|
var last = this.series.map(function (line, i) {
|
||||||
|
return { index: i, size: Math.abs(line[line.length - 1]) };
|
||||||
|
});
|
||||||
|
last.sort(function (a, b) { return b.size - a.size || a.index - b.index; });
|
||||||
|
this.defaults = last.slice(0, 3).map(function (entry) { return entry.index; });
|
||||||
|
};
|
||||||
|
|
||||||
|
// Newer data, same chart: pinned lines and the point being inspected stay as they are
|
||||||
|
Chart.prototype.update = function (data) {
|
||||||
|
this.load(data);
|
||||||
|
this.render();
|
||||||
|
};
|
||||||
|
|
||||||
Chart.prototype.shown = function () {
|
Chart.prototype.shown = function () {
|
||||||
|
|
||||||
var list = this.pinned.slice();
|
var list = this.pinned.slice();
|
||||||
@@ -418,36 +432,77 @@
|
|||||||
html('p', 'spsa-note', root).textContent = text;
|
html('p', 'spsa-note', root).textContent = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
function start() {
|
var chart = null; // the chart on the page, once there is something to draw
|
||||||
|
|
||||||
var root = document.querySelector('.spsa-chart[data-chart]');
|
function mount(root, raw) {
|
||||||
if (!root)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var data;
|
var data;
|
||||||
try {
|
try {
|
||||||
data = JSON.parse(root.getAttribute('data-chart'));
|
data = JSON.parse(raw);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
chart = null;
|
||||||
return note(root, 'The history could not be read.');
|
return note(root, 'The history could not be read.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data.names.length || data.points.length < 2 || !data.games)
|
// The notice about missing history sits beside the chart, and is redone with it
|
||||||
|
var parent = root.parentNode;
|
||||||
|
Array.prototype.slice.call(parent.children).forEach(function (child) {
|
||||||
|
if (child !== root && child.classList.contains('spsa-note'))
|
||||||
|
parent.removeChild(child);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!data.names.length || data.points.length < 2 || !data.games) {
|
||||||
|
chart = null;
|
||||||
return note(root, 'No games have been played yet. The chart appears with the first results.');
|
return note(root, 'No games have been played yet. The chart appears with the first results.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (chart && chart.root === root && root.querySelector('.sch-plot')) {
|
||||||
|
|
||||||
|
// Live update: the same chart, with newer data
|
||||||
|
chart.update(data);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
var items = document.querySelectorAll('#spsa-rows .spsa-row');
|
var items = document.querySelectorAll('#spsa-rows .spsa-row');
|
||||||
var rows = [];
|
var rows = [];
|
||||||
for (var k = 0; k < items.length; k++)
|
for (var k = 0; k < items.length; k++)
|
||||||
rows[parseInt(items[k].getAttribute('data-index'), 10)] = items[k];
|
rows[parseInt(items[k].getAttribute('data-index'), 10)] = items[k];
|
||||||
|
|
||||||
new Chart(root, data, rows);
|
chart = new Chart(root, data, rows);
|
||||||
|
}
|
||||||
|
|
||||||
if (!data.recorded) {
|
if (!data.recorded) {
|
||||||
var message = html('p', 'spsa-note');
|
var message = html('p', 'spsa-note');
|
||||||
|
message.setAttribute('data-live-skip', '');
|
||||||
message.textContent = 'History starts recording with the next result. Until then the chart shows only the start and the current values.';
|
message.textContent = 'History starts recording with the next result. Until then the chart shows only the start and the current values.';
|
||||||
root.parentNode.appendChild(message);
|
parent.appendChild(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function start() {
|
||||||
|
|
||||||
|
var root = document.querySelector('.spsa-chart[data-chart]');
|
||||||
|
if (root)
|
||||||
|
mount(root, root.getAttribute('data-chart'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Live updates ( live.js ) never touch the chart itself. When a fresh page
|
||||||
|
arrives with more history, the data is handed over here instead. */
|
||||||
|
document.addEventListener('live:patched', function (event) {
|
||||||
|
|
||||||
|
var root = document.querySelector('.spsa-chart[data-chart]');
|
||||||
|
var next = event.detail && event.detail.fresh && event.detail.fresh.querySelector('.spsa-chart[data-chart]');
|
||||||
|
if (!root || !next)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var raw = next.getAttribute('data-chart');
|
||||||
|
if (raw === root.getAttribute('data-chart'))
|
||||||
|
return;
|
||||||
|
|
||||||
|
root.setAttribute('data-chart', raw);
|
||||||
|
mount(root, raw);
|
||||||
|
});
|
||||||
|
|
||||||
if (document.readyState === 'loading')
|
if (document.readyState === 'loading')
|
||||||
document.addEventListener('DOMContentLoaded', start);
|
document.addEventListener('DOMContentLoaded', start);
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -1,7 +1,21 @@
|
|||||||
/* SPSA parameter panel: filter by name, sort by how far a parameter moved. */
|
/* 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 () {
|
(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() {
|
function init() {
|
||||||
|
|
||||||
var list = document.getElementById('spsa-rows');
|
var list = document.getElementById('spsa-rows');
|
||||||
@@ -14,7 +28,7 @@
|
|||||||
|
|
||||||
var rows = Array.prototype.slice.call(list.children);
|
var rows = Array.prototype.slice.call(list.children);
|
||||||
|
|
||||||
function apply() {
|
function apply(keepScroll) {
|
||||||
|
|
||||||
var term = search.value.trim().toLowerCase();
|
var term = search.value.trim().toLowerCase();
|
||||||
var shown = 0;
|
var shown = 0;
|
||||||
@@ -34,14 +48,58 @@
|
|||||||
list.appendChild(row);
|
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;
|
list.scrollTop = 0;
|
||||||
|
|
||||||
if (empty)
|
if (empty)
|
||||||
empty.hidden = shown !== 0;
|
empty.hidden = shown !== 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
search.addEventListener('input', apply);
|
function refresh(fresh) {
|
||||||
order.addEventListener('change', apply);
|
|
||||||
|
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')
|
if (document.readyState === 'loading')
|
||||||
|
|||||||
Reference in new issue
Block a user