Skip to content

Commit aa14a64

Browse files
committed
fix: max hold for various corner cases
max hold needs to work, even when the data is always negative, but this complicates things because the ypoint array is initialized to zeros prior to the first push of data. The new code will wait until an entire frame of data is pushed (since you can push partial frames) and then initialize max hold to -Infinity.
1 parent afc5f49 commit aa14a64

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

js/sigplot.layer1d.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,16 @@
228228
}
229229

230230
// update the position
231-
this.position = (this.position + tle) % this.size;
231+
this.position = (this.position + tle);
232+
// after we get one full buffer of data we can initialize maxhold and
233+
// no longer rescale on first push
234+
if ((this.position >= this.size) && (this.firstpush === false)) {
235+
this.firstpush = true;
236+
if (this.mhpoint) {
237+
this.mhpoint.fill(-Infinity);
238+
}
239+
}
240+
this.position = this.position % this.size;
232241

233242
if (this.tle === undefined) {
234243
tle = Math.floor(m.pavail(this.hcb)) / this.hcb.spa;
@@ -325,12 +334,12 @@
325334
this.maxhold.decay = 0;
326335
}
327336
if (this.mhpoint) {
328-
// clear the maxhold buffer by setting to the current ypoint
329-
this.mhpoint.set(this.ypoint);
337+
// clear the maxhold buffer by setting to negative Infinity
338+
this.mhpoint.fill(-Infinity);
330339
} else {
331340
this.mhptr = new ArrayBuffer(this.pointbufsize);
332341
this.mhpoint = new m.PointArray(this.mhptr);
333-
this.mhpoint.set(this.ypoint);
342+
this.mhpoint.fill(-Infinity);
334343
}
335344
} else if (settings.maxhold === null) {
336345
this.maxhold = undefined;
@@ -349,6 +358,7 @@
349358
if (this.maxhold) {
350359
this.mhptr = new ArrayBuffer(this.pointbufsize);
351360
this.mhpoint = new m.PointArray(this.mhptr);
361+
this.mhpoint.fill(-Infinity);
352362
}
353363
}
354364

@@ -420,6 +430,7 @@
420430
this.ymin = null;
421431
this.ymax = null;
422432
}
433+
this.firstpush = false;
423434
}
424435

425436
this.xdelta = this.hcb.xdelta;
@@ -436,7 +447,6 @@
436447

437448
// if this is the first push of data, request a rescale
438449
if (this.firstpush === false) {
439-
this.firstpush = true;
440450
hdrmod = true;
441451
}
442452
return hdrmod ? true : false;
@@ -470,9 +480,13 @@
470480
this.yptr = new ArrayBuffer(this.pointbufsize);
471481
this.xpoint = new m.PointArray(this.xptr);
472482
this.ypoint = new m.PointArray(this.yptr);
483+
// invalidate max hold buffers
484+
this.mhptr = null;
485+
this.mhpoint = null;
473486
if (this.maxhold) {
474487
this.mhptr = new ArrayBuffer(this.pointbufsize);
475488
this.mhpoint = new m.PointArray(this.mhptr);
489+
this.mhpoint.fill(-Infinity);
476490
}
477491
}
478492

0 commit comments

Comments
 (0)