visualizer: skip redraws when they take too long

This commit is contained in:
Simon Ruderich 2024-05-11 14:36:44 +02:00
parent 0df63a998d
commit 7a8c2374c6

View file

@ -56,6 +56,8 @@ function addTrace(type, data) {
updatePause(true); updatePause(true);
updateChart(data.packet); updateChart(data.packet);
updateData(data.packet); updateData(data.packet);
// Redraw
chartConstellation.update();
}; };
span.style.cursor = 'pointer'; span.style.cursor = 'pointer';
} }
@ -114,7 +116,7 @@ function updateChart(packet) {
chartConstellation.data.datasets[0].data = packet['preamble_symbols']; chartConstellation.data.datasets[0].data = packet['preamble_symbols'];
chartConstellation.data.datasets[1].data = packet['header_symbols']; chartConstellation.data.datasets[1].data = packet['header_symbols'];
chartConstellation.data.datasets[2].data = packet['data_symbols']; chartConstellation.data.datasets[2].data = packet['data_symbols'];
chartConstellation.update(); // .update() is deferred, see redrawPlots()
} }
function updateData(packet) { function updateData(packet) {
@ -169,7 +171,25 @@ function addHistory(packet) {
i++; i++;
} }
chartHistory.data.labels.push((new Date() - state.start)/1000); chartHistory.data.labels.push((new Date() - state.start)/1000);
// .update() is deferred, see redrawPlots()
}
let redrawPending = false;
function redrawPlots() {
// Updating the plots is too slow for live updates for all received
// messages. Instead of falling behind, skip redraws when the messages
// arrive too quickly.
if (redrawPending) {
return;
}
redrawPending = true;
window.setTimeout(() => {
chartHistory.update(); chartHistory.update();
chartConstellation.update();
redrawPending = false;
}, 10 /* ms */);
} }
@ -225,6 +245,7 @@ ws.onmessage = (evt) => {
updateChart(msg); updateChart(msg);
updateData(msg); updateData(msg);
addHistory(msg); addHistory(msg);
redrawPlots();
addTrace(tracePacket, { addTrace(tracePacket, {
string: 'P', string: 'P',