summaryrefslogtreecommitdiff
path: root/web-timeplot/src/data/csv-replay-source.js
diff options
context:
space:
mode:
Diffstat (limited to 'web-timeplot/src/data/csv-replay-source.js')
-rw-r--r--web-timeplot/src/data/csv-replay-source.js60
1 files changed, 0 insertions, 60 deletions
diff --git a/web-timeplot/src/data/csv-replay-source.js b/web-timeplot/src/data/csv-replay-source.js
deleted file mode 100644
index c4e6a66..0000000
--- a/web-timeplot/src/data/csv-replay-source.js
+++ /dev/null
@@ -1,60 +0,0 @@
-import { BaseSource } from './base-source.js';
-
-function clamp(value, min, max) {
- return Math.min(max, Math.max(min, value));
-}
-
-export class CsvReplaySource extends BaseSource {
- constructor(config = {}) {
- super({
- replayRate: 1,
- dataset: [],
- ...config,
- });
- this.sourceType = 'csv-replay';
- this.nextPointIndex = 0;
- }
-
- start(startTimeMs = 0) {
- super.start();
- this.reset(startTimeMs);
- }
-
- reset() {
- this.nextPointIndex = 0;
- }
-
- updateConfig(nextConfig) {
- const datasetChanged = nextConfig.dataset !== this.config.dataset;
- super.updateConfig(nextConfig);
- if (datasetChanged) {
- this.reset();
- }
- }
-
- update(currentPlotTimeMs) {
- if (!this.running || !Array.isArray(this.config.dataset) || this.config.dataset.length === 0) {
- return [];
- }
-
- const replayRate = clamp(this.config.replayRate ?? 1, 0.1, 8);
- const targetDatasetTimeMs = currentPlotTimeMs * replayRate;
- const points = [];
-
- while (this.nextPointIndex < this.config.dataset.length) {
- const datasetPoint = this.config.dataset[this.nextPointIndex];
- if (datasetPoint.timeMs > targetDatasetTimeMs) {
- break;
- }
-
- points.push({
- timeMs: datasetPoint.timeMs / replayRate,
- value: datasetPoint.value,
- sourceId: this.config.id ?? 'csv-replay',
- });
- this.nextPointIndex += 1;
- }
-
- return points;
- }
-}