Skip to content

Commit fc6b998

Browse files
committed
feat: progress towards working maxhold
1 parent 4a0613e commit fc6b998

File tree

3 files changed

+85
-11
lines changed

3 files changed

+85
-11
lines changed

js/m.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,12 +1113,12 @@
11131113
* @param {number} count Number of input vector elements to move, starting with 0th element of <vec>. Cannot exceed vector lengths,
11141114
* taking into account the strides.
11151115
*/
1116-
m.vmovmax = function(src, sstride, dest, dstride, count) {
1116+
m.vmovmax = function(src, sstride, dest, dstride, count, decay) {
11171117
if (count === undefined) {
11181118
count = src.length;
11191119
}
11201120
count = Math.min(src.length, count);
1121-
1121+
11221122
for (var i = 0; i < count; i++) {
11231123
var s = i * sstride;
11241124
var d = i * dstride;
@@ -1128,6 +1128,7 @@
11281128
if (d >= dest.length) {
11291129
break;
11301130
}
1131+
dest[d] = dest[d] * Math.exp(-decay);
11311132
dest[d] = Math.max(dest[d], src[s]);
11321133
}
11331134
};

js/sigplot.layer1d.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,12 @@
128128
if (options.mode) {
129129
this.mode = options.mode;
130130
}
131-
131+
132132
if (options.maxhold !== undefined) {
133133
this.maxhold = options.maxhold;
134+
if (this.maxhold.decay === undefined) {
135+
this.maxhold.decay = 0;
136+
}
134137
}
135138

136139
// pipe data requires a valid size on overlay, but
@@ -316,6 +319,15 @@
316319
this.ybuf = new ArrayBuffer(this.ybufn);
317320
}
318321

322+
if (settings.maxhold !== undefined) {
323+
this.maxhold = settings.maxhold;
324+
if (this.maxhold.decay === undefined) {
325+
this.maxhold.decay = 0;
326+
}
327+
// clear the maxhold buffer by setting to the current ypoint
328+
this.mhpoint.set(this.ypoint);
329+
}
330+
319331
if (settings.framesize !== undefined) {
320332
this.size = settings.framesize;
321333
this.xstart = this.hcb.xstart + (this.imin) * this.xdelta;
@@ -325,11 +337,16 @@
325337
this.xmax = Math.max(this.hcb.xstart, d);
326338
this.ybufn = this.size * Math.max(this.skip * m.PointArray.BYTES_PER_ELEMENT, m.PointArray.BYTES_PER_ELEMENT);
327339
this.ybuf = new ArrayBuffer(this.ybufn);
340+
if (this.maxhold !== undefined) {
341+
this.mhptr = new ArrayBuffer(this.pointbufsize);
342+
this.mhpoint = new m.PointArray(this.mhptr);
343+
}
328344
}
329345

330346
if (settings.color !== undefined) {
331347
this.color = settings.color;
332348
}
349+
333350
},
334351

335352
reload: function(data, hdrmod) {
@@ -581,9 +598,9 @@
581598
m.vsmul(this.ypoint, dbscale, this.ypoint);
582599
}
583600
mxmn = m.vmxmn(this.ypoint, npts);
584-
601+
585602
if ((this.maxhold !== undefined) && (this.mhpoint)) {
586-
m.vmovmax(this.ypoint, 1, this.mhpoint, 1);
603+
m.vmovmax(this.ypoint, 1, this.mhpoint, 1, undefined, this.maxhold.decay);
587604
}
588605

589606
qmax = mxmn.smax;

test/tests.interactive-layer1d.js

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,21 +1507,77 @@ interactiveTest('1d max-hold', 'does the plot have a max hold feature', function
15071507
framesize: 2048,
15081508
name: "Test",
15091509
maxhold: {
1510-
decay: 0,
1510+
decay: 0.01, // slow decay
15111511
color: "red",
1512-
traceoptions: {dashed: true}
1512+
traceoptions: {
1513+
dashed: true
1514+
}
1515+
}
1516+
});
1517+
1518+
var offset = 0;
1519+
window.setInterval(function() {
1520+
offset = (offset + 200) % 2048
1521+
}, 2000);
1522+
1523+
ifixture.interval = window.setInterval(function() {
1524+
var random = [];
1525+
for (var i = 0; i < 2048; i += 1) {
1526+
1527+
if ((i > offset) && (i < offset + 500)) {
1528+
random.push(Math.random() * 3);
1529+
} else {
1530+
random.push(Math.random());
1531+
}
1532+
}
1533+
plot.push(lyr0, random);
1534+
}, 100);
1535+
});
1536+
1537+
interactiveTest('1d max-hold reset', 'does the plot have a max hold feature that resets every 5 seconds', function(assert) {
1538+
var container = document.getElementById('plot');
1539+
var plot = new sigplot.Plot(container, {
1540+
legend: true,
1541+
autol: 5
1542+
});
1543+
assert.notEqual(plot, null);
1544+
var lyr0 = plot.overlay_pipe({
1545+
type: 1000
1546+
}, {
1547+
framesize: 2048,
1548+
name: "Test",
1549+
maxhold: {
1550+
decay: 0, // never decay
1551+
color: "red",
1552+
traceoptions: {
1553+
dashed: true
1554+
}
15131555
}
15141556
});
15151557

15161558
var offset = 0;
1517-
window.setInterval(function() { offset = (offset + 200) % 2048}, 2000);
1559+
window.setInterval(function() {
1560+
offset = (offset + 200) % 2048
1561+
}, 2000);
1562+
1563+
window.setInterval(function() {
1564+
plot.change_settings({
1565+
maxhold: {
1566+
decay: 0, // never decay
1567+
color: "red",
1568+
traceoptions: {
1569+
dashed: true
1570+
}
1571+
}
1572+
})
1573+
}, 5000);
15181574

15191575
ifixture.interval = window.setInterval(function() {
15201576
var random = [];
15211577
for (var i = 0; i < 2048; i += 1) {
1522-
1523-
if ((i > offset) && (i < offset +500)) {
1524-
random.push(Math.random() *3);
1578+
1579+
if ((i > offset) && (i < offset + 500)) {
1580+
random.push(Math.random() * 3);
15251581
} else {
15261582
random.push(Math.random());
15271583
}

0 commit comments

Comments
 (0)