summaryrefslogtreecommitdiff
path: root/src/plot/plot-buffer.js
blob: b13cdd819a114fc74c9a06010d3e65883c092fbf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
export class PlotBuffer {
    constructor(maxPoints = 1600) {
        this.maxPoints = maxPoints;
        this.points = [];
    }

    addPoint(point) {
        this.points.push(point);
        if (this.points.length > this.maxPoints) {
            this.points.splice(0, this.points.length - this.maxPoints);
        }
    }

    clear() {
        this.points = [];
    }

    getVisiblePoints(currentPlotTimeMs, windowDurationMs) {
        const minTime = currentPlotTimeMs - windowDurationMs;
        return this.points.filter((point) => point.timeMs >= minTime && point.timeMs <= currentPlotTimeMs);
    }
}