@insync-stageplayer/plotly-chart 0.5.35-beta.1 → 0.5.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Plotly.d.ts +5 -0
- package/lib/Plotly.d.ts.map +1 -0
- package/lib/Plotly.js +338 -0
- package/lib/Plotly.js.map +1 -0
- package/lib/PlotlyGraph/EventMenu.d.ts +12 -12
- package/lib/PlotlyGraph/EventMenu.js +65 -65
- package/lib/PlotlyGraph/MarkerTracks.d.ts +16 -16
- package/lib/PlotlyGraph/MarkerTracks.d.ts.map +1 -1
- package/lib/PlotlyGraph/MarkerTracks.js +239 -241
- package/lib/PlotlyGraph/MarkerTracks.js.map +1 -1
- package/lib/PlotlyGraph/Plotly.d.ts +5 -0
- package/lib/PlotlyGraph/Plotly.d.ts.map +1 -0
- package/lib/PlotlyGraph/Plotly.js +347 -0
- package/lib/PlotlyGraph/Plotly.js.map +1 -0
- package/lib/PlotlyGraph/PlotlyLiveview.d.ts +4 -4
- package/lib/PlotlyGraph/PlotlyLiveview.js +297 -297
- package/lib/PlotlyGraph/PlotlyPlayback.d.ts +4 -4
- package/lib/PlotlyGraph/PlotlyPlayback.d.ts.map +1 -1
- package/lib/PlotlyGraph/PlotlyPlayback.js +308 -524
- package/lib/PlotlyGraph/PlotlyPlayback.js.map +1 -1
- package/lib/PlotlyGraph/PlotlyPlaybackOverlay.d.ts +22 -22
- package/lib/PlotlyGraph/PlotlyPlaybackOverlay.d.ts.map +1 -1
- package/lib/PlotlyGraph/PlotlyPlaybackOverlay.js +146 -145
- package/lib/PlotlyGraph/PlotlyPlaybackOverlay.js.map +1 -1
- package/lib/PlotlyGraph/index.d.ts +2 -2
- package/lib/PlotlyGraph/index.d.ts.map +1 -1
- package/lib/PlotlyGraph/index.js +2 -2
- package/lib/PlotlyGraph/index.js.map +1 -1
- package/lib/PlotlyLiveview.d.ts +5 -0
- package/lib/PlotlyLiveview.d.ts.map +1 -0
- package/lib/PlotlyLiveview.js +310 -0
- package/lib/PlotlyLiveview.js.map +1 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/package.json +3 -5
|
@@ -1,48 +1,28 @@
|
|
|
1
|
-
import React, { useCallback, useEffect, useState
|
|
2
|
-
import Plot from "react-plotly.js";
|
|
3
|
-
import PropTypes from "prop-types";
|
|
4
|
-
import { withResizeDetector } from "react-resize-detector";
|
|
5
|
-
import { useTheme as useSelectedTheme, styled, } from "@insync-stageplayer/ui-components";
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
};
|
|
27
|
-
const convertMicrosecondsToDate = (inputTime) => {
|
|
28
|
-
const date = new Date(inputTime / 1000 - 3600 * 1000);
|
|
29
|
-
const pad = function (num) {
|
|
30
|
-
return (num < 10 ? "0" : "") + num;
|
|
31
|
-
};
|
|
32
|
-
return (date.getFullYear() +
|
|
33
|
-
"-" +
|
|
34
|
-
pad(date.getMonth() + 1) +
|
|
35
|
-
"-" +
|
|
36
|
-
pad(date.getDate()) +
|
|
37
|
-
" " +
|
|
38
|
-
pad(date.getHours()) +
|
|
39
|
-
":" +
|
|
40
|
-
pad(date.getMinutes()) +
|
|
41
|
-
":" +
|
|
42
|
-
pad(date.getSeconds()) +
|
|
43
|
-
"." +
|
|
44
|
-
pad(date.getMilliseconds()));
|
|
45
|
-
};
|
|
1
|
+
import React, { useCallback, useEffect, useState } from "react";
|
|
2
|
+
import Plot from "react-plotly.js";
|
|
3
|
+
import PropTypes from "prop-types";
|
|
4
|
+
import { withResizeDetector } from "react-resize-detector";
|
|
5
|
+
import { useTheme as useSelectedTheme, styled, } from "@insync-stageplayer/ui-components";
|
|
6
|
+
const convertMicrosecondstoDateFormat = (inputMicroseconds) => {
|
|
7
|
+
let convertedDate = new Date(+inputMicroseconds / 1000);
|
|
8
|
+
return adjustWithLocalTimeZone(convertedDate);
|
|
9
|
+
};
|
|
10
|
+
const adjustWithLocalTimeZone = (date) => {
|
|
11
|
+
let adjustedDate = new Date(date.getTime() + date.getTimezoneOffset() * 60 * 1000);
|
|
12
|
+
return adjustedDate;
|
|
13
|
+
};
|
|
14
|
+
const convertDateToMicroseconds = (inputDate) => {
|
|
15
|
+
const convertIntoDate = new Date(inputDate);
|
|
16
|
+
return (convertIntoDate.getTime() * 1000 -
|
|
17
|
+
convertIntoDate.getTimezoneOffset() * 60 * 1000 * 1000);
|
|
18
|
+
};
|
|
19
|
+
const getMicroSecondStartAndLength = (originalFromDate, originalStopDate, totalTime) => {
|
|
20
|
+
const start = convertDateToMicroseconds(originalFromDate);
|
|
21
|
+
const end = convertDateToMicroseconds(originalStopDate);
|
|
22
|
+
let sLength = end - start;
|
|
23
|
+
const length = sLength + (totalTime % 1000) === totalTime ? totalTime : sLength;
|
|
24
|
+
return [start, length];
|
|
25
|
+
};
|
|
46
26
|
const StyledPlotly = styled(Plot) `
|
|
47
27
|
rect.nsewdrag.cursor-ew-resize {
|
|
48
28
|
cursor: zoom-in;
|
|
@@ -55,483 +35,287 @@ const StyledPlotly = styled(Plot) `
|
|
|
55
35
|
cursor: grab;
|
|
56
36
|
pointer-events: none !important;
|
|
57
37
|
}
|
|
58
|
-
`;
|
|
59
|
-
export const PlotlyPlayback = withResizeDetector(({ xRange, data, metadata, onStopSelect, onDrag, xScaleTickFormat, scrubbing, yAxisLabel, displaySecondYAxis, displayArrow, totalTime,
|
|
60
|
-
var _a;
|
|
61
|
-
const [plotData, setPlotData] = useState([]);
|
|
62
|
-
const [nowLine, setNowline] = useState((_a = sessionStorage.getItem("nl")) !== null && _a !== void 0 ? _a : 0);
|
|
63
|
-
const [layout, setLayout] = useState(null);
|
|
64
|
-
const selectedTheme = useSelectedTheme();
|
|
65
|
-
const [yAxisLabelLeft, setYAxisLabelLeft] = useState("");
|
|
66
|
-
const [yAxisLabelRight, setYAxisLabelRight] = useState("");
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
:
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
:
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
anchor: "
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
? signal.map((item) => {
|
|
342
|
-
if (xScaleTickFormat.includes(":")) {
|
|
343
|
-
const xDateFormatted = convertMicrosecondstoDateFormat(+item.x);
|
|
344
|
-
return xDateFormatted;
|
|
345
|
-
}
|
|
346
|
-
else {
|
|
347
|
-
const xValue = +item.x / 1e6;
|
|
348
|
-
return xValue;
|
|
349
|
-
}
|
|
350
|
-
})
|
|
351
|
-
: signal[0].map((item) => {
|
|
352
|
-
if (xScaleTickFormat.includes(":")) {
|
|
353
|
-
const xDateFormatted = convertMicrosecondstoDateFormat(+item);
|
|
354
|
-
return xDateFormatted;
|
|
355
|
-
}
|
|
356
|
-
else {
|
|
357
|
-
const xValue = +item / 1e6;
|
|
358
|
-
return xValue;
|
|
359
|
-
}
|
|
360
|
-
});
|
|
361
|
-
// For Noldus we need to filter out the y from the objects, MARIN directly returns a Plotly optimized format
|
|
362
|
-
const yVal = selectedTheme.name === "noldus"
|
|
363
|
-
? signal.map((item) => {
|
|
364
|
-
return item.y;
|
|
365
|
-
})
|
|
366
|
-
: signal[1];
|
|
367
|
-
const y = handleYValue(yVal, idx);
|
|
368
|
-
const sharedSignalData = {
|
|
369
|
-
x,
|
|
370
|
-
y,
|
|
371
|
-
type: "scattergl",
|
|
372
|
-
mode: metadata[idx].frequency * (xRange.length / 1000 / 1000) > 250
|
|
373
|
-
? "lines"
|
|
374
|
-
: "lines+markers",
|
|
375
|
-
name: metadata[idx].name,
|
|
376
|
-
marker: {
|
|
377
|
-
color: metadata[idx].color,
|
|
378
|
-
size: 5,
|
|
379
|
-
line: {
|
|
380
|
-
color: metadata[idx].color,
|
|
381
|
-
width: 1,
|
|
382
|
-
},
|
|
383
|
-
},
|
|
384
|
-
};
|
|
385
|
-
const signalData = getSignalData(sharedSignalData, yVal);
|
|
386
|
-
plotDataArr.push(signalData);
|
|
387
|
-
});
|
|
388
|
-
// Check if a second y-axis needs to be added
|
|
389
|
-
if (displaySecondYAxis && metadata.length == 2) {
|
|
390
|
-
plotDataArr[1] = Object.assign(Object.assign({}, plotDataArr[1]), { yaxis: "y2" });
|
|
391
|
-
}
|
|
392
|
-
// Setting y-axis labels if needed and meeting the requirements
|
|
393
|
-
if (metadata.length == 1) {
|
|
394
|
-
setYAxisLabelLeft(yAxisLabel ? metadata[0].name : "");
|
|
395
|
-
setYAxisLabelLeftColor(yAxisLabel ? selectedTheme.colors.foreground : "");
|
|
396
|
-
}
|
|
397
|
-
else if (metadata.length == 2 && displaySecondYAxis) {
|
|
398
|
-
setYAxisLabelLeft(yAxisLabel ? metadata[0].name : "");
|
|
399
|
-
setYAxisLabelLeftColor(yAxisLabel ? metadata[0].color : "");
|
|
400
|
-
setYAxisLabelRight(yAxisLabel ? metadata[1].name : "");
|
|
401
|
-
setYAxisLabelRightColor(yAxisLabel ? metadata[1].color : "");
|
|
402
|
-
}
|
|
403
|
-
else {
|
|
404
|
-
setYAxisLabelLeft("");
|
|
405
|
-
setYAxisLabelRight("");
|
|
406
|
-
setYAxisLabelLeftColor("");
|
|
407
|
-
setYAxisLabelRightColor("");
|
|
408
|
-
}
|
|
409
|
-
setPlotData(plotDataArr);
|
|
410
|
-
}, [
|
|
411
|
-
data,
|
|
412
|
-
metadata,
|
|
413
|
-
xScaleTickFormat,
|
|
414
|
-
xRange.length,
|
|
415
|
-
yAxisLabel,
|
|
416
|
-
displaySecondYAxis,
|
|
417
|
-
selectedTheme.colors.foreground,
|
|
418
|
-
selectedTheme.name,
|
|
419
|
-
]);
|
|
420
|
-
useEffect(() => {
|
|
421
|
-
updateLayout();
|
|
422
|
-
}, [updateLayout]);
|
|
423
|
-
useEffect(() => {
|
|
424
|
-
if (!scrubbing) {
|
|
425
|
-
setNowline(xRange.nowline);
|
|
426
|
-
}
|
|
427
|
-
sessionStorage.setItem("nl", xRange.nowline);
|
|
428
|
-
}, [scrubbing, xRange.nowline]);
|
|
429
|
-
const afterPlot = () => {
|
|
430
|
-
//console.log(plotlyRef.current);
|
|
431
|
-
//console.log(plotlyRef.current.el);
|
|
432
|
-
// TODO: get from plotlyRef instead of document
|
|
433
|
-
var layer = document.getElementsByClassName("axesclip")[0].firstChild;
|
|
434
|
-
const yAxisSignalLeft = layer.x.baseVal.value;
|
|
435
|
-
const yAxisSignalWidth = layer.width.baseVal.value;
|
|
436
|
-
const xAxisSignalTop = layer.y.baseVal.value;
|
|
437
|
-
const xAxisSignalHeight = layer.height.baseVal.value;
|
|
438
|
-
onRenderedLeft(yAxisSignalLeft);
|
|
439
|
-
onRenderedWidth(yAxisSignalWidth);
|
|
440
|
-
onRenderedTop(xAxisSignalTop);
|
|
441
|
-
onRenderedHeight(xAxisSignalHeight);
|
|
442
|
-
// TODO: get from plotlyRef instead of document
|
|
443
|
-
const scrubbar = document.getElementsByClassName("ewdrag")[0];
|
|
444
|
-
const scrubbarHeight = scrubbar.height.baseVal.value;
|
|
445
|
-
onRenderedScrubbar(scrubbarHeight);
|
|
446
|
-
};
|
|
447
|
-
const handleYValue = (yVal, idx) => {
|
|
448
|
-
// Noldus wants the Y data to be relative between 0 and 1
|
|
449
|
-
// MARIN data engineers always wants the data as it is
|
|
450
|
-
if (selectedTheme.name === "noldus" || shouldNormalize) {
|
|
451
|
-
const { min, max } = metadata[idx];
|
|
452
|
-
const range = max - min;
|
|
453
|
-
const y = yVal.map((value) => {
|
|
454
|
-
return (value - min) / range;
|
|
455
|
-
});
|
|
456
|
-
return y;
|
|
457
|
-
}
|
|
458
|
-
else {
|
|
459
|
-
return yVal;
|
|
460
|
-
}
|
|
461
|
-
};
|
|
462
|
-
const getSignalData = (sharedSignalData, yVal) => {
|
|
463
|
-
if (selectedTheme.name === "noldus") {
|
|
464
|
-
const noldusSignalData = {
|
|
465
|
-
hovertemplate: "%{customdata:.2f}",
|
|
466
|
-
customdata: yVal.map((point) => `${point}`), // Setting raw data for each point
|
|
467
|
-
};
|
|
468
|
-
return Object.assign(Object.assign({}, sharedSignalData), noldusSignalData);
|
|
469
|
-
}
|
|
470
|
-
else {
|
|
471
|
-
if (shouldNormalize) {
|
|
472
|
-
const marinSignalData = {
|
|
473
|
-
hovertemplate: "%{customdata}",
|
|
474
|
-
customdata: yVal.map((point) => `${point}`),
|
|
475
|
-
};
|
|
476
|
-
return Object.assign(Object.assign({}, sharedSignalData), marinSignalData);
|
|
477
|
-
}
|
|
478
|
-
else {
|
|
479
|
-
return sharedSignalData;
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
};
|
|
483
|
-
return (React.createElement(StyledPlotly, { useResizeHandler: true, className: "plot-div", data: plotData, layout: layout, style: { width: "100%", height: percentageHeight + "%" }, config: {
|
|
484
|
-
displaylogo: false,
|
|
485
|
-
displayModeBar: false,
|
|
486
|
-
responsive: true,
|
|
487
|
-
doubleClick: false,
|
|
488
|
-
showTips: false,
|
|
489
|
-
}, onRelayout: (e) => onRelayout(e), onRelayouting: (e) => onRelayouting(e), onAfterPlot: () => afterPlot(), ref: plotlyRef }));
|
|
490
|
-
});
|
|
491
|
-
PlotlyPlayback.defaultProps = {
|
|
492
|
-
xRange: null,
|
|
493
|
-
data: [],
|
|
494
|
-
metadata: [],
|
|
495
|
-
onStopSelect: () => { },
|
|
496
|
-
onDrag: () => { },
|
|
497
|
-
xScaleTickFormat: "SS",
|
|
498
|
-
scrubbing: false,
|
|
499
|
-
yAxisLabel: false,
|
|
500
|
-
displaySecondYAxis: false,
|
|
501
|
-
displayArrow: true,
|
|
502
|
-
selectedTheme: null,
|
|
503
|
-
totalTime: null,
|
|
504
|
-
startPositionCurrentTimeIndicator: "0.5",
|
|
505
|
-
};
|
|
506
|
-
const dataElement = PropTypes.shape({
|
|
507
|
-
x: PropTypes.number,
|
|
508
|
-
y: PropTypes.number,
|
|
509
|
-
});
|
|
510
|
-
const metadataElement = PropTypes.shape({
|
|
511
|
-
name: PropTypes.string,
|
|
512
|
-
color: PropTypes.string,
|
|
513
|
-
});
|
|
514
|
-
PlotlyPlayback.propTypes = {
|
|
515
|
-
xRange: PropTypes.shape({
|
|
516
|
-
from: PropTypes.number,
|
|
517
|
-
length: PropTypes.number,
|
|
518
|
-
}),
|
|
519
|
-
data: PropTypes.arrayOf(PropTypes.arrayOf(dataElement), PropTypes.arrayOf(dataElement)),
|
|
520
|
-
metadata: PropTypes.arrayOf(metadataElement),
|
|
521
|
-
onStopSelect: PropTypes.func,
|
|
522
|
-
onDrag: PropTypes.func,
|
|
523
|
-
xScaleTickFormat: PropTypes.string,
|
|
524
|
-
scrubbing: PropTypes.bool,
|
|
525
|
-
yAxisLabel: PropTypes.bool,
|
|
526
|
-
displaySecondYAxis: PropTypes.bool,
|
|
527
|
-
displayArrow: PropTypes.bool,
|
|
528
|
-
selectedTheme: PropTypes.shape({
|
|
529
|
-
colors: PropTypes.shape({
|
|
530
|
-
background: PropTypes.string,
|
|
531
|
-
}),
|
|
532
|
-
name: PropTypes.string,
|
|
533
|
-
}),
|
|
534
|
-
totalTime: PropTypes.number,
|
|
535
|
-
startPositionCurrentTimeIndicator: PropTypes.string,
|
|
536
|
-
};
|
|
38
|
+
`;
|
|
39
|
+
export const PlotlyPlayback = withResizeDetector(({ xRange, data, metadata, onStopSelect, onDrag, xScaleTickFormat, scrubbing, yAxisLabel, displaySecondYAxis, displayArrow, totalTime, }) => {
|
|
40
|
+
var _a;
|
|
41
|
+
const [plotData, setPlotData] = useState([]);
|
|
42
|
+
const [nowLine, setNowline] = useState((_a = sessionStorage.getItem("nl")) !== null && _a !== void 0 ? _a : 0);
|
|
43
|
+
const [layout, setLayout] = useState(null);
|
|
44
|
+
const selectedTheme = useSelectedTheme();
|
|
45
|
+
const [yAxisLabelLeft, setYAxisLabelLeft] = useState("");
|
|
46
|
+
const [yAxisLabelRight, setYAxisLabelRight] = useState("");
|
|
47
|
+
const updateLayout = useCallback(() => {
|
|
48
|
+
let annotations = [
|
|
49
|
+
{
|
|
50
|
+
xref: "paper",
|
|
51
|
+
yref: "paper",
|
|
52
|
+
x: nowLine,
|
|
53
|
+
xanchor: "right",
|
|
54
|
+
y: 1,
|
|
55
|
+
yanchor: "bottom",
|
|
56
|
+
text: "",
|
|
57
|
+
showarrow: displayArrow,
|
|
58
|
+
arrowhead: 0,
|
|
59
|
+
ax: 0,
|
|
60
|
+
ay: 1000,
|
|
61
|
+
arrowcolor: "red",
|
|
62
|
+
},
|
|
63
|
+
];
|
|
64
|
+
const convertXRangeFrom = xScaleTickFormat.includes(":")
|
|
65
|
+
? convertMicrosecondstoDateFormat(xRange.from > 0
|
|
66
|
+
? xRange.length === totalTime
|
|
67
|
+
? 0
|
|
68
|
+
: xRange.from + xRange.length > totalTime
|
|
69
|
+
? totalTime - xRange.length
|
|
70
|
+
: xRange.from
|
|
71
|
+
: 0)
|
|
72
|
+
: xRange.from / 1e6;
|
|
73
|
+
const convertXRangeTo = xScaleTickFormat.includes(":")
|
|
74
|
+
? convertMicrosecondstoDateFormat(xRange.from > 0
|
|
75
|
+
? xRange.length === totalTime
|
|
76
|
+
? xRange.length
|
|
77
|
+
: xRange.from + xRange.length > totalTime
|
|
78
|
+
? totalTime
|
|
79
|
+
: xRange.from + xRange.length
|
|
80
|
+
: xRange.length)
|
|
81
|
+
: (xRange.from + xRange.length) / 1e6;
|
|
82
|
+
let defaultLayout = {
|
|
83
|
+
// this hovermode setting creates a hover-over legend for all the signals at the same time. It also adds a spike line
|
|
84
|
+
hovermode: "x unified",
|
|
85
|
+
yaxis: {
|
|
86
|
+
fixedrange: true,
|
|
87
|
+
rangemode: "",
|
|
88
|
+
hoverformat: ".2f",
|
|
89
|
+
range: selectedTheme.name === "noldus" ? [0, 1] : [],
|
|
90
|
+
title: yAxisLabelLeft,
|
|
91
|
+
showline: true,
|
|
92
|
+
showticklabels: false,
|
|
93
|
+
linewidth: 2,
|
|
94
|
+
linecolor: selectedTheme.colors.accent,
|
|
95
|
+
tickformat: null,
|
|
96
|
+
},
|
|
97
|
+
xaxis: {
|
|
98
|
+
rangemode: "",
|
|
99
|
+
showline: false,
|
|
100
|
+
linewidth: 2,
|
|
101
|
+
linecolor: selectedTheme.colors.accent,
|
|
102
|
+
fixedrange: false,
|
|
103
|
+
range: [convertXRangeFrom, convertXRangeTo],
|
|
104
|
+
tickformat: xScaleTickFormat.includes(":") ? "%H:%M:%S" : null,
|
|
105
|
+
},
|
|
106
|
+
showlegend: false,
|
|
107
|
+
autosize: true,
|
|
108
|
+
margin: { l: 25, r: 10, t: 20, b: 20 },
|
|
109
|
+
paper_bgcolor: selectedTheme.colors.background,
|
|
110
|
+
plot_bgcolor: selectedTheme.colors.background,
|
|
111
|
+
font: { color: selectedTheme.colors.foreground },
|
|
112
|
+
};
|
|
113
|
+
// Check if a second y-axis needs to be added
|
|
114
|
+
if (displaySecondYAxis && metadata.length == 2) {
|
|
115
|
+
const yAxis2 = {
|
|
116
|
+
fixedrange: true,
|
|
117
|
+
title: yAxisLabelRight,
|
|
118
|
+
anchor: "x",
|
|
119
|
+
overlaying: "y",
|
|
120
|
+
side: "right",
|
|
121
|
+
};
|
|
122
|
+
defaultLayout = Object.assign(Object.assign({}, defaultLayout), { yaxis2: yAxis2 });
|
|
123
|
+
}
|
|
124
|
+
// when scrubbing plotly is in charge, this to prevent the xRange to update and mess while
|
|
125
|
+
// still scrubbing in plotly
|
|
126
|
+
if (!scrubbing) {
|
|
127
|
+
setLayout(Object.assign(Object.assign({}, defaultLayout), { annotations }));
|
|
128
|
+
}
|
|
129
|
+
}, [
|
|
130
|
+
selectedTheme,
|
|
131
|
+
xRange,
|
|
132
|
+
xScaleTickFormat,
|
|
133
|
+
yAxisLabelLeft,
|
|
134
|
+
yAxisLabelRight,
|
|
135
|
+
displaySecondYAxis,
|
|
136
|
+
displayArrow,
|
|
137
|
+
scrubbing,
|
|
138
|
+
metadata,
|
|
139
|
+
nowLine,
|
|
140
|
+
]);
|
|
141
|
+
const onRelayout = (e) => {
|
|
142
|
+
if (e["xaxis.range[0]"] && e["xaxis.range[1]"]) {
|
|
143
|
+
let selection;
|
|
144
|
+
if (xScaleTickFormat.includes(":")) {
|
|
145
|
+
const [from, length] = getMicroSecondStartAndLength(e["xaxis.range[0]"], e["xaxis.range[1]"], totalTime);
|
|
146
|
+
selection = {
|
|
147
|
+
from: from,
|
|
148
|
+
length: length,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
selection = {
|
|
153
|
+
from: e["xaxis.range[0]"] * 1e6,
|
|
154
|
+
length: (e["xaxis.range[1]"] - e["xaxis.range[0]"]) * 1e6,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
onStopSelect({ selection });
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
const onRelayouting = (e) => {
|
|
161
|
+
if (e["xaxis.range[0]"] && e["xaxis.range[1]"]) {
|
|
162
|
+
let seekTime;
|
|
163
|
+
if (xScaleTickFormat.includes(":")) {
|
|
164
|
+
const [from, length] = getMicroSecondStartAndLength(e["xaxis.range[0]"], e["xaxis.range[1]"], totalTime);
|
|
165
|
+
const possibleSeekTime = length * nowLine + from;
|
|
166
|
+
seekTime =
|
|
167
|
+
possibleSeekTime > totalTime
|
|
168
|
+
? totalTime
|
|
169
|
+
: possibleSeekTime < 0
|
|
170
|
+
? 0
|
|
171
|
+
: possibleSeekTime;
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
seekTime =
|
|
175
|
+
((e["xaxis.range[1]"] - e["xaxis.range[0]"]) / 2 +
|
|
176
|
+
e["xaxis.range[0]"]) *
|
|
177
|
+
1e6;
|
|
178
|
+
}
|
|
179
|
+
onDrag(seekTime);
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
useEffect(() => {
|
|
183
|
+
updateLayout();
|
|
184
|
+
const plotDataArr = [];
|
|
185
|
+
data.forEach((signal, idx) => {
|
|
186
|
+
const x = signal.map((item) => {
|
|
187
|
+
if (xScaleTickFormat.includes(":")) {
|
|
188
|
+
const xDateFormatted = convertMicrosecondstoDateFormat(+item.x);
|
|
189
|
+
return xDateFormatted;
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
const xDateFormatted = +item.x / 1e6;
|
|
193
|
+
return xDateFormatted;
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
const yVal = signal.map((item) => {
|
|
197
|
+
return item.y;
|
|
198
|
+
});
|
|
199
|
+
const { min, max } = metadata[idx];
|
|
200
|
+
const range = max - min;
|
|
201
|
+
const y = yVal.map((value) => {
|
|
202
|
+
return (value - min) / range;
|
|
203
|
+
});
|
|
204
|
+
const signalData = {
|
|
205
|
+
x,
|
|
206
|
+
y,
|
|
207
|
+
hovertemplate: "%{customdata:.2f}",
|
|
208
|
+
customdata: yVal.map((point) => `${point}`),
|
|
209
|
+
type: "scattergl",
|
|
210
|
+
mode: metadata[idx].frequency * (xRange.length / 1000 / 1000) > 250
|
|
211
|
+
? "lines"
|
|
212
|
+
: "lines+markers",
|
|
213
|
+
name: metadata[idx].name,
|
|
214
|
+
marker: {
|
|
215
|
+
color: metadata[idx].color,
|
|
216
|
+
size: 5,
|
|
217
|
+
line: {
|
|
218
|
+
color: metadata[idx].color,
|
|
219
|
+
width: 1,
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
};
|
|
223
|
+
plotDataArr.push(signalData);
|
|
224
|
+
});
|
|
225
|
+
// Check if a second y-axis needs to be added
|
|
226
|
+
if (displaySecondYAxis && metadata.length == 2) {
|
|
227
|
+
plotDataArr[1] = Object.assign(Object.assign({}, plotDataArr[1]), { yaxis: "y2" });
|
|
228
|
+
}
|
|
229
|
+
// Setting y-axis labels if needed and meeting the requirements
|
|
230
|
+
if (metadata.length == 1) {
|
|
231
|
+
setYAxisLabelLeft(yAxisLabel ? metadata[0].name : "");
|
|
232
|
+
}
|
|
233
|
+
else if (metadata.length == 2 && displaySecondYAxis) {
|
|
234
|
+
setYAxisLabelLeft(yAxisLabel ? metadata[0].name : "");
|
|
235
|
+
setYAxisLabelRight(yAxisLabel ? metadata[1].name : "");
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
setYAxisLabelLeft("");
|
|
239
|
+
setYAxisLabelRight("");
|
|
240
|
+
}
|
|
241
|
+
setPlotData(plotDataArr);
|
|
242
|
+
}, [
|
|
243
|
+
data,
|
|
244
|
+
metadata,
|
|
245
|
+
updateLayout,
|
|
246
|
+
xScaleTickFormat,
|
|
247
|
+
xRange,
|
|
248
|
+
scrubbing,
|
|
249
|
+
yAxisLabel,
|
|
250
|
+
displaySecondYAxis,
|
|
251
|
+
]);
|
|
252
|
+
useEffect(() => {
|
|
253
|
+
if (!scrubbing) {
|
|
254
|
+
if (xRange.from < 0) {
|
|
255
|
+
let d = (xRange.length / 2 + xRange.from) / xRange.length;
|
|
256
|
+
setNowline(d);
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
if (xRange.length === totalTime) {
|
|
260
|
+
setNowline(0.5 + xRange.from / totalTime);
|
|
261
|
+
}
|
|
262
|
+
else if (xRange.from + xRange.length > totalTime) {
|
|
263
|
+
setNowline(0.5 + (xRange.from - (totalTime - xRange.length)) / xRange.length);
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
setNowline(0.5);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
sessionStorage.setItem("nl", nowLine);
|
|
271
|
+
}, [plotData, xRange]);
|
|
272
|
+
return (React.createElement(StyledPlotly, { useResizeHandler: true, className: "plot-div", data: plotData, layout: layout, style: { width: "100%", height: "100%" }, config: {
|
|
273
|
+
displaylogo: false,
|
|
274
|
+
displayModeBar: false,
|
|
275
|
+
responsive: true,
|
|
276
|
+
}, onRelayout: (e) => onRelayout(e), onRelayouting: (e) => onRelayouting(e) }));
|
|
277
|
+
});
|
|
278
|
+
PlotlyPlayback.defaultProps = {
|
|
279
|
+
xRange: null,
|
|
280
|
+
data: [],
|
|
281
|
+
metadata: [],
|
|
282
|
+
onStopSelect: () => { },
|
|
283
|
+
onDrag: () => { },
|
|
284
|
+
xScaleTickFormat: "SS",
|
|
285
|
+
scrubbing: false,
|
|
286
|
+
yAxisLabel: false,
|
|
287
|
+
displaySecondYAxis: false,
|
|
288
|
+
displayArrow: true,
|
|
289
|
+
selectedTheme: null,
|
|
290
|
+
totalTime: null,
|
|
291
|
+
};
|
|
292
|
+
const dataElement = PropTypes.shape({
|
|
293
|
+
x: PropTypes.number,
|
|
294
|
+
y: PropTypes.number,
|
|
295
|
+
});
|
|
296
|
+
const metadataElement = PropTypes.shape({
|
|
297
|
+
name: PropTypes.string,
|
|
298
|
+
color: PropTypes.string,
|
|
299
|
+
});
|
|
300
|
+
PlotlyPlayback.propTypes = {
|
|
301
|
+
xRange: PropTypes.shape({
|
|
302
|
+
from: PropTypes.number,
|
|
303
|
+
length: PropTypes.number,
|
|
304
|
+
}),
|
|
305
|
+
data: PropTypes.arrayOf(PropTypes.arrayOf(dataElement), PropTypes.arrayOf(dataElement)),
|
|
306
|
+
metadata: PropTypes.arrayOf(metadataElement),
|
|
307
|
+
onStopSelect: PropTypes.func,
|
|
308
|
+
onDrag: PropTypes.func,
|
|
309
|
+
xScaleTickFormat: PropTypes.string,
|
|
310
|
+
scrubbing: PropTypes.bool,
|
|
311
|
+
yAxisLabel: PropTypes.bool,
|
|
312
|
+
displaySecondYAxis: PropTypes.bool,
|
|
313
|
+
displayArrow: PropTypes.bool,
|
|
314
|
+
selectedTheme: PropTypes.shape({
|
|
315
|
+
colors: PropTypes.shape({
|
|
316
|
+
background: PropTypes.string,
|
|
317
|
+
}),
|
|
318
|
+
}),
|
|
319
|
+
totalTime: PropTypes.number,
|
|
320
|
+
};
|
|
537
321
|
//# sourceMappingURL=PlotlyPlayback.js.map
|