Skip to content

Commit

Permalink
client: Allow traces that don't align exactly with window.
Browse files Browse the repository at this point in the history
When we request data from the server, we specify the start (t0) and
duration (dt) in seconds, and the server converts these to WFDB frame
numbers; this may not correspond exactly to the start/end of the
window, especially when the record has multiple frequencies and/or has
a non-integer frame frequency.

Therefore, when drawing the plot, look for any trace that overlaps
with the window, not only traces that overlap with the exact window
starting time (t0_ticks).  Furthermore, if we don't have traces for a
particular signal that cover the entire window, don't give up
completely; just draw the traces we do have and keep going.
  • Loading branch information
Benjamin Moody committed Jun 21, 2022
1 parent 25c33b2 commit b6542f7
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions client/js/lightwave.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// file: lightwave.js G. Moody 18 November 2012
// Last revised: 23 April 2019 version 0.68
// Last revised: 15 June 2022 version 0.71
// LightWAVE Javascript code
//
// Copyright (C) 2012-2013 George B. Moody
Expand Down Expand Up @@ -208,6 +208,21 @@ function find_trace(db, record, signame, t) {
return null;
}

// Find the earliest-starting trace that overlaps the given range
function find_trace_in_range(db, record, signame, t0, tf) {
var i, trace = null;

for (i = 0; i < tpool.length; i++) {
if (tpool[i].name === signame &&
tpool[i].t0 < tf && t0 < tpool[i].tf &&
tpool[i].record === record && tpool[i].db === db) {
trace = tpool[i];
tf = trace.t0;
}
}
return trace;
}

// Replace the least-recently-used trace with the contents of s
function set_trace(db, record, s) {
var i, idmin, imin, j, len, ni, p, trace, v, vmean, vmid, vmax, vmin, w;
Expand Down Expand Up @@ -1205,7 +1220,7 @@ function show_plot() {
y0 = y0s[is];
ytop = y0 - svgf;
sname = signals[is].name;
trace = find_trace(db, record, sname, t0_ticks);
trace = find_trace_in_range(db, record, sname, t0_ticks, tf_ticks);

svs += '<g id="sig;;' + html_escape(sname) + '">\n';
if (trace && s_visible[sname] === 1) {
Expand Down Expand Up @@ -1245,7 +1260,7 @@ function show_plot() {
pv = false;
while (tnext < tf) {
if (tnext > t0_ticks) {
trace = find_trace(db, record, sname, tnext);
trace = find_trace_in_range(db, record, sname, tnext, tf);
if (trace === null) {
if (pending < 1) {
read_signals(t0_ticks, true);
Expand All @@ -1259,7 +1274,7 @@ function show_plot() {
autoplay_off();
alert_server_error();
}
return;
break;
}
s = trace.samp;
imin = (tnext - trace.t0)/tps;
Expand Down

0 comments on commit b6542f7

Please sign in to comment.