@insync-stageplayer/plotly-chart 0.5.27 → 0.5.35-beta.1

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.
Files changed (37) hide show
  1. package/lib/PlotlyGraph/EventMenu.d.ts +13 -0
  2. package/lib/PlotlyGraph/EventMenu.d.ts.map +1 -0
  3. package/lib/PlotlyGraph/EventMenu.js +84 -0
  4. package/lib/PlotlyGraph/EventMenu.js.map +1 -0
  5. package/lib/PlotlyGraph/MarkerTracks.d.ts +17 -0
  6. package/lib/PlotlyGraph/MarkerTracks.d.ts.map +1 -0
  7. package/lib/PlotlyGraph/MarkerTracks.js +248 -0
  8. package/lib/PlotlyGraph/MarkerTracks.js.map +1 -0
  9. package/lib/PlotlyGraph/PlotlyLiveview.d.ts +4 -4
  10. package/lib/PlotlyGraph/PlotlyLiveview.js +297 -297
  11. package/lib/PlotlyGraph/PlotlyPlayback.d.ts +4 -4
  12. package/lib/PlotlyGraph/PlotlyPlayback.d.ts.map +1 -1
  13. package/lib/PlotlyGraph/PlotlyPlayback.js +524 -317
  14. package/lib/PlotlyGraph/PlotlyPlayback.js.map +1 -1
  15. package/lib/PlotlyGraph/PlotlyPlaybackOverlay.d.ts +23 -0
  16. package/lib/PlotlyGraph/PlotlyPlaybackOverlay.d.ts.map +1 -0
  17. package/lib/PlotlyGraph/PlotlyPlaybackOverlay.js +188 -0
  18. package/lib/PlotlyGraph/PlotlyPlaybackOverlay.js.map +1 -0
  19. package/lib/PlotlyGraph/index.d.ts +2 -2
  20. package/lib/PlotlyGraph/index.d.ts.map +1 -1
  21. package/lib/PlotlyGraph/index.js +2 -2
  22. package/lib/PlotlyGraph/index.js.map +1 -1
  23. package/lib/index.d.ts +1 -1
  24. package/lib/index.js +1 -1
  25. package/package.json +5 -3
  26. package/lib/Plotly.d.ts +0 -5
  27. package/lib/Plotly.d.ts.map +0 -1
  28. package/lib/Plotly.js +0 -338
  29. package/lib/Plotly.js.map +0 -1
  30. package/lib/PlotlyGraph/Plotly.d.ts +0 -5
  31. package/lib/PlotlyGraph/Plotly.d.ts.map +0 -1
  32. package/lib/PlotlyGraph/Plotly.js +0 -347
  33. package/lib/PlotlyGraph/Plotly.js.map +0 -1
  34. package/lib/PlotlyLiveview.d.ts +0 -5
  35. package/lib/PlotlyLiveview.d.ts.map +0 -1
  36. package/lib/PlotlyLiveview.js +0 -310
  37. package/lib/PlotlyLiveview.js.map +0 -1
@@ -1,27 +1,27 @@
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) => {
20
- const start = convertDateToMicroseconds(originalFromDate);
21
- const end = convertDateToMicroseconds(originalStopDate);
22
- const length = end - start;
23
- return [start, length];
24
- };
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) => {
20
+ const start = convertDateToMicroseconds(originalFromDate);
21
+ const end = convertDateToMicroseconds(originalStopDate);
22
+ const length = end - start;
23
+ return [start, length];
24
+ };
25
25
  const StyledPlotly = styled(Plot) `
26
26
  rect.nsewdrag.cursor-ew-resize {
27
27
  cursor: zoom-in;
@@ -29,277 +29,277 @@ const StyledPlotly = styled(Plot) `
29
29
  rect.ewdrag.cursor-ew-resize {
30
30
  cursor: grab;
31
31
  }
32
- `;
33
- export const PlotlyLiveview = withResizeDetector(({ xRange, data, metadata, onStopSelect, onDrag, xScaleTickFormat, scrubbing, yAxisLabel, displaySecondYAxis, displayArrow, }) => {
34
- const [plotData, setPlotData] = useState([]);
35
- const [nowLine, setNowline] = useState(1);
36
- const [layout, setLayout] = useState(null);
37
- const selectedTheme = useSelectedTheme();
38
- const [yAxisLabelLeft, setYAxisLabelLeft] = useState("");
39
- const [yAxisLabelRight, setYAxisLabelRight] = useState("");
40
- const updateLayout = useCallback(() => {
41
- let annotations = [
42
- {
43
- xref: "paper",
44
- yref: "paper",
45
- x: nowLine,
46
- xanchor: "right",
47
- y: 1,
48
- yanchor: "bottom",
49
- text: "",
50
- showarrow: displayArrow,
51
- arrowhead: 0,
52
- ax: 0,
53
- ay: 1000,
54
- arrowcolor: "red",
55
- },
56
- ];
57
- const convertXRangeFrom = xScaleTickFormat.includes(":")
58
- ? convertMicrosecondstoDateFormat(xRange.from > 0 ? xRange.from : 0)
59
- : xRange.from / 1e6;
60
- const convertXRangeTo = xScaleTickFormat.includes(":")
61
- ? convertMicrosecondstoDateFormat(xRange.from > 0 ? xRange.from + xRange.length : xRange.length)
62
- : (xRange.from + xRange.length) / 1e6;
63
- let defaultLayout = {
64
- // this hovermode setting creates a hover-over legend for all the signals at the same time. It also adds a spike line
65
- hovermode: "x unified",
66
- yaxis: {
67
- fixedrange: true,
68
- rangemode: "tozero",
69
- hoverformat: ".2f",
70
- range: [0, 1],
71
- title: yAxisLabelLeft,
72
- showline: true,
73
- showticklabels: false,
74
- linewidth: 2,
75
- linecolor: selectedTheme.colors.accent,
76
- tickformat: null,
77
- },
78
- xaxis: {
79
- rangemode: "tozero",
80
- showline: true,
81
- linewidth: 2,
82
- linecolor: selectedTheme.colors.accent,
83
- fixedrange: true,
84
- range: [convertXRangeFrom, convertXRangeTo],
85
- showticklabels: (data === null || data === void 0 ? void 0 : data.length) === 0 ? false : true,
86
- tickformat: xScaleTickFormat.includes(":") ? "%H:%M:%S" : null,
87
- },
88
- showlegend: false,
89
- autosize: true,
90
- margin: { l: 25, r: 10, t: 20, b: 20 },
91
- paper_bgcolor: selectedTheme.colors.background,
92
- plot_bgcolor: selectedTheme.colors.background,
93
- font: { color: selectedTheme.colors.foreground },
94
- };
95
- // Check if a second y-axis needs to be added
96
- if (displaySecondYAxis && metadata.length == 2) {
97
- const yAxis2 = {
98
- fixedrange: true,
99
- title: yAxisLabelRight,
100
- anchor: "x",
101
- overlaying: "y",
102
- side: "right",
103
- };
104
- defaultLayout = Object.assign(Object.assign({}, defaultLayout), { yaxis2: yAxis2 });
105
- }
106
- // when scrubbing plotly is in charge, this to prevent the xRange to update and mess while
107
- // still scrubbing in plotly
108
- if (!scrubbing) {
109
- setLayout(Object.assign(Object.assign({}, defaultLayout), { annotations }));
110
- }
111
- }, [
112
- selectedTheme,
113
- xRange,
114
- xScaleTickFormat,
115
- yAxisLabelLeft,
116
- yAxisLabelRight,
117
- displaySecondYAxis,
118
- displayArrow,
119
- scrubbing,
120
- metadata,
121
- nowLine,
122
- ]);
123
- const onRelayout = (e) => {
124
- if (e["xaxis.range[0]"] && e["xaxis.range[1]"]) {
125
- let selection;
126
- if (xScaleTickFormat.includes(":")) {
127
- const [from, length] = getMicroSecondStartAndLength(e["xaxis.range[0]"], e["xaxis.range[1]"]);
128
- selection = {
129
- from: from,
130
- length: length,
131
- };
132
- }
133
- else {
134
- selection = {
135
- from: e["xaxis.range[0]"] * 1e6,
136
- length: (e["xaxis.range[1]"] - e["xaxis.range[0]"]) * 1e6,
137
- };
138
- }
139
- onStopSelect({ selection });
140
- }
141
- };
142
- const onRelayouting = (e) => {
143
- if (e["xaxis.range[0]"] && e["xaxis.range[1]"]) {
144
- let seekTime;
145
- if (xScaleTickFormat.includes(":")) {
146
- const [from, length] = getMicroSecondStartAndLength(e["xaxis.range[0]"], e["xaxis.range[1]"]);
147
- seekTime = (length / 2 + from) * 1e6;
148
- }
149
- else {
150
- seekTime =
151
- ((e["xaxis.range[1]"] - e["xaxis.range[0]"]) / 2 +
152
- e["xaxis.range[0]"]) *
153
- 1e6;
154
- }
155
- onDrag(seekTime);
156
- }
157
- };
158
- useEffect(() => {
159
- updateLayout();
160
- const plotDataArr = [];
161
- data.forEach((signal, idx) => {
162
- const x = signal.map((item) => {
163
- if (xScaleTickFormat.includes(":")) {
164
- const xDateFormatted = convertMicrosecondstoDateFormat(+item.x);
165
- return xDateFormatted;
166
- }
167
- else {
168
- const xDateFormatted = +item.x / 1e6;
169
- return xDateFormatted;
170
- }
171
- });
172
- const y = signal.map((item) => {
173
- return item.y;
174
- });
175
- const signalData = {
176
- x,
177
- y,
178
- hoverinfo: "skip",
179
- type: "scattergl",
180
- mode: metadata[idx].frequency * (xRange.length / 1000 / 1000) > 250
181
- ? "lines"
182
- : "lines+markers",
183
- name: metadata[idx].name,
184
- marker: {
185
- color: metadata[idx].color,
186
- size: 5,
187
- line: {
188
- color: metadata[idx].color,
189
- width: 1,
190
- },
191
- },
192
- };
193
- plotDataArr.push(signalData);
194
- });
195
- // Check if a second y-axis needs to be added
196
- if (displaySecondYAxis && metadata.length == 2) {
197
- plotDataArr[1] = Object.assign(Object.assign({}, plotDataArr[1]), { yaxis: "y2" });
198
- }
199
- // Setting y-axis labels if needed and meeting the requirements
200
- if (metadata.length == 1) {
201
- setYAxisLabelLeft(yAxisLabel ? metadata[0].name : "");
202
- }
203
- else if (metadata.length == 2 && displaySecondYAxis) {
204
- setYAxisLabelLeft(yAxisLabel ? metadata[0].name : "");
205
- setYAxisLabelRight(yAxisLabel ? metadata[1].name : "");
206
- }
207
- else {
208
- setYAxisLabelLeft("");
209
- setYAxisLabelRight("");
210
- }
211
- setPlotData(plotDataArr);
212
- }, [
213
- data,
214
- metadata,
215
- updateLayout,
216
- xScaleTickFormat,
217
- xRange,
218
- scrubbing,
219
- yAxisLabel,
220
- displaySecondYAxis,
221
- ]);
222
- useEffect(() => {
223
- if (xRange.from < 0) {
224
- let d = (xRange.length / 2 + (xRange.from * xRange.length) / xRange.length) /
225
- xRange.length;
226
- setNowline(d);
227
- }
228
- else {
229
- setNowline(1);
230
- }
231
- sessionStorage.removeItem("nl");
232
- }, [plotData, xRange, nowLine]);
233
- const shouldNormalize = React.useMemo(() => {
234
- const units = metadata.reduce((acc, curr) => {
235
- if (curr != undefined && acc.indexOf(curr === null || curr === void 0 ? void 0 : curr.unit) < 0) {
236
- return [...acc, curr.unit];
237
- }
238
- return acc;
239
- }, []);
240
- return units.length > 1;
241
- }, [metadata]);
242
- const normalized = React.useMemo(() => {
243
- if (plotData.length <= 0)
244
- return;
245
- if (shouldNormalize) {
246
- const newLinesData = plotData.map((item, i) => {
247
- const line = metadata[i];
248
- const { min, max } = line;
249
- const lineRange = max - min;
250
- return Object.assign(Object.assign({}, item), { y: item.y.map((value) => {
251
- return (value - min) / lineRange;
252
- }) });
253
- });
254
- return newLinesData;
255
- }
256
- return plotData;
257
- }, [shouldNormalize, plotData, metadata]);
258
- return (React.createElement(StyledPlotly, { useResizeHandler: true, className: "plot-div", data: normalized, layout: layout, style: { width: "100%", height: "100%" }, config: {
259
- displaylogo: false,
260
- displayModeBar: false,
261
- responsive: true,
262
- }, onRelayout: (e) => onRelayout(e), onRelayouting: (e) => onRelayouting(e) }));
263
- });
264
- PlotlyLiveview.defaultProps = {
265
- xRange: null,
266
- data: [],
267
- metadata: [],
268
- onStopSelect: () => { },
269
- onDrag: () => { },
270
- xScaleTickFormat: "SS",
271
- scrubbing: false,
272
- yAxisLabel: false,
273
- displaySecondYAxis: false,
274
- displayArrow: true,
275
- selectedTheme: null,
276
- };
277
- const dataElement = PropTypes.shape({
278
- x: PropTypes.number,
279
- y: PropTypes.number,
280
- });
281
- const metadataElement = PropTypes.shape({
282
- name: PropTypes.string,
283
- color: PropTypes.string,
284
- });
285
- PlotlyLiveview.propTypes = {
286
- xRange: PropTypes.shape({
287
- from: PropTypes.number,
288
- length: PropTypes.number,
289
- }),
290
- data: PropTypes.arrayOf(PropTypes.arrayOf(dataElement), PropTypes.arrayOf(dataElement)),
291
- metadata: PropTypes.arrayOf(metadataElement),
292
- onStopSelect: PropTypes.func,
293
- onDrag: PropTypes.func,
294
- xScaleTickFormat: PropTypes.string,
295
- scrubbing: PropTypes.bool,
296
- yAxisLabel: PropTypes.bool,
297
- displaySecondYAxis: PropTypes.bool,
298
- displayArrow: PropTypes.bool,
299
- selectedTheme: PropTypes.shape({
300
- colors: PropTypes.shape({
301
- background: PropTypes.string,
302
- }),
303
- }),
304
- };
32
+ `;
33
+ export const PlotlyLiveview = withResizeDetector(({ xRange, data, metadata, onStopSelect, onDrag, xScaleTickFormat, scrubbing, yAxisLabel, displaySecondYAxis, displayArrow, }) => {
34
+ const [plotData, setPlotData] = useState([]);
35
+ const [nowLine, setNowline] = useState(1);
36
+ const [layout, setLayout] = useState(null);
37
+ const selectedTheme = useSelectedTheme();
38
+ const [yAxisLabelLeft, setYAxisLabelLeft] = useState("");
39
+ const [yAxisLabelRight, setYAxisLabelRight] = useState("");
40
+ const updateLayout = useCallback(() => {
41
+ let annotations = [
42
+ {
43
+ xref: "paper",
44
+ yref: "paper",
45
+ x: nowLine,
46
+ xanchor: "right",
47
+ y: 1,
48
+ yanchor: "bottom",
49
+ text: "",
50
+ showarrow: displayArrow,
51
+ arrowhead: 0,
52
+ ax: 0,
53
+ ay: 1000,
54
+ arrowcolor: "red",
55
+ },
56
+ ];
57
+ const convertXRangeFrom = xScaleTickFormat.includes(":")
58
+ ? convertMicrosecondstoDateFormat(xRange.from > 0 ? xRange.from : 0)
59
+ : xRange.from / 1e6;
60
+ const convertXRangeTo = xScaleTickFormat.includes(":")
61
+ ? convertMicrosecondstoDateFormat(xRange.from > 0 ? xRange.from + xRange.length : xRange.length)
62
+ : (xRange.from + xRange.length) / 1e6;
63
+ let defaultLayout = {
64
+ // this hovermode setting creates a hover-over legend for all the signals at the same time. It also adds a spike line
65
+ hovermode: "x unified",
66
+ yaxis: {
67
+ fixedrange: true,
68
+ rangemode: "tozero",
69
+ hoverformat: ".2f",
70
+ range: [0, 1],
71
+ title: yAxisLabelLeft,
72
+ showline: true,
73
+ showticklabels: false,
74
+ linewidth: 2,
75
+ linecolor: selectedTheme.colors.accent,
76
+ tickformat: null,
77
+ },
78
+ xaxis: {
79
+ rangemode: "tozero",
80
+ showline: true,
81
+ linewidth: 2,
82
+ linecolor: selectedTheme.colors.accent,
83
+ fixedrange: true,
84
+ range: [convertXRangeFrom, convertXRangeTo],
85
+ showticklabels: (data === null || data === void 0 ? void 0 : data.length) === 0 ? false : true,
86
+ tickformat: xScaleTickFormat.includes(":") ? "%H:%M:%S" : null,
87
+ },
88
+ showlegend: false,
89
+ autosize: true,
90
+ margin: { l: 25, r: 10, t: 20, b: 20 },
91
+ paper_bgcolor: selectedTheme.colors.background,
92
+ plot_bgcolor: selectedTheme.colors.background,
93
+ font: { color: selectedTheme.colors.foreground },
94
+ };
95
+ // Check if a second y-axis needs to be added
96
+ if (displaySecondYAxis && metadata.length == 2) {
97
+ const yAxis2 = {
98
+ fixedrange: true,
99
+ title: yAxisLabelRight,
100
+ anchor: "x",
101
+ overlaying: "y",
102
+ side: "right",
103
+ };
104
+ defaultLayout = Object.assign(Object.assign({}, defaultLayout), { yaxis2: yAxis2 });
105
+ }
106
+ // when scrubbing plotly is in charge, this to prevent the xRange to update and mess while
107
+ // still scrubbing in plotly
108
+ if (!scrubbing) {
109
+ setLayout(Object.assign(Object.assign({}, defaultLayout), { annotations }));
110
+ }
111
+ }, [
112
+ selectedTheme,
113
+ xRange,
114
+ xScaleTickFormat,
115
+ yAxisLabelLeft,
116
+ yAxisLabelRight,
117
+ displaySecondYAxis,
118
+ displayArrow,
119
+ scrubbing,
120
+ metadata,
121
+ nowLine,
122
+ ]);
123
+ const onRelayout = (e) => {
124
+ if (e["xaxis.range[0]"] && e["xaxis.range[1]"]) {
125
+ let selection;
126
+ if (xScaleTickFormat.includes(":")) {
127
+ const [from, length] = getMicroSecondStartAndLength(e["xaxis.range[0]"], e["xaxis.range[1]"]);
128
+ selection = {
129
+ from: from,
130
+ length: length,
131
+ };
132
+ }
133
+ else {
134
+ selection = {
135
+ from: e["xaxis.range[0]"] * 1e6,
136
+ length: (e["xaxis.range[1]"] - e["xaxis.range[0]"]) * 1e6,
137
+ };
138
+ }
139
+ onStopSelect({ selection });
140
+ }
141
+ };
142
+ const onRelayouting = (e) => {
143
+ if (e["xaxis.range[0]"] && e["xaxis.range[1]"]) {
144
+ let seekTime;
145
+ if (xScaleTickFormat.includes(":")) {
146
+ const [from, length] = getMicroSecondStartAndLength(e["xaxis.range[0]"], e["xaxis.range[1]"]);
147
+ seekTime = (length / 2 + from) * 1e6;
148
+ }
149
+ else {
150
+ seekTime =
151
+ ((e["xaxis.range[1]"] - e["xaxis.range[0]"]) / 2 +
152
+ e["xaxis.range[0]"]) *
153
+ 1e6;
154
+ }
155
+ onDrag(seekTime);
156
+ }
157
+ };
158
+ useEffect(() => {
159
+ updateLayout();
160
+ const plotDataArr = [];
161
+ data.forEach((signal, idx) => {
162
+ const x = signal.map((item) => {
163
+ if (xScaleTickFormat.includes(":")) {
164
+ const xDateFormatted = convertMicrosecondstoDateFormat(+item.x);
165
+ return xDateFormatted;
166
+ }
167
+ else {
168
+ const xDateFormatted = +item.x / 1e6;
169
+ return xDateFormatted;
170
+ }
171
+ });
172
+ const y = signal.map((item) => {
173
+ return item.y;
174
+ });
175
+ const signalData = {
176
+ x,
177
+ y,
178
+ hoverinfo: "skip",
179
+ type: "scattergl",
180
+ mode: metadata[idx].frequency * (xRange.length / 1000 / 1000) > 250
181
+ ? "lines"
182
+ : "lines+markers",
183
+ name: metadata[idx].name,
184
+ marker: {
185
+ color: metadata[idx].color,
186
+ size: 5,
187
+ line: {
188
+ color: metadata[idx].color,
189
+ width: 1,
190
+ },
191
+ },
192
+ };
193
+ plotDataArr.push(signalData);
194
+ });
195
+ // Check if a second y-axis needs to be added
196
+ if (displaySecondYAxis && metadata.length == 2) {
197
+ plotDataArr[1] = Object.assign(Object.assign({}, plotDataArr[1]), { yaxis: "y2" });
198
+ }
199
+ // Setting y-axis labels if needed and meeting the requirements
200
+ if (metadata.length == 1) {
201
+ setYAxisLabelLeft(yAxisLabel ? metadata[0].name : "");
202
+ }
203
+ else if (metadata.length == 2 && displaySecondYAxis) {
204
+ setYAxisLabelLeft(yAxisLabel ? metadata[0].name : "");
205
+ setYAxisLabelRight(yAxisLabel ? metadata[1].name : "");
206
+ }
207
+ else {
208
+ setYAxisLabelLeft("");
209
+ setYAxisLabelRight("");
210
+ }
211
+ setPlotData(plotDataArr);
212
+ }, [
213
+ data,
214
+ metadata,
215
+ updateLayout,
216
+ xScaleTickFormat,
217
+ xRange,
218
+ scrubbing,
219
+ yAxisLabel,
220
+ displaySecondYAxis,
221
+ ]);
222
+ useEffect(() => {
223
+ if (xRange.from < 0) {
224
+ let d = (xRange.length / 2 + (xRange.from * xRange.length) / xRange.length) /
225
+ xRange.length;
226
+ setNowline(d);
227
+ }
228
+ else {
229
+ setNowline(1);
230
+ }
231
+ sessionStorage.removeItem("nl");
232
+ }, [plotData, xRange, nowLine]);
233
+ const shouldNormalize = React.useMemo(() => {
234
+ const units = metadata.reduce((acc, curr) => {
235
+ if (curr != undefined && acc.indexOf(curr === null || curr === void 0 ? void 0 : curr.unit) < 0) {
236
+ return [...acc, curr.unit];
237
+ }
238
+ return acc;
239
+ }, []);
240
+ return units.length > 1;
241
+ }, [metadata]);
242
+ const normalized = React.useMemo(() => {
243
+ if (plotData.length <= 0)
244
+ return;
245
+ if (shouldNormalize) {
246
+ const newLinesData = plotData.map((item, i) => {
247
+ const line = metadata[i];
248
+ const { min, max } = line;
249
+ const lineRange = max - min;
250
+ return Object.assign(Object.assign({}, item), { y: item.y.map((value) => {
251
+ return (value - min) / lineRange;
252
+ }) });
253
+ });
254
+ return newLinesData;
255
+ }
256
+ return plotData;
257
+ }, [shouldNormalize, plotData, metadata]);
258
+ return (React.createElement(StyledPlotly, { useResizeHandler: true, className: "plot-div", data: normalized, layout: layout, style: { width: "100%", height: "100%" }, config: {
259
+ displaylogo: false,
260
+ displayModeBar: false,
261
+ responsive: true,
262
+ }, onRelayout: (e) => onRelayout(e), onRelayouting: (e) => onRelayouting(e) }));
263
+ });
264
+ PlotlyLiveview.defaultProps = {
265
+ xRange: null,
266
+ data: [],
267
+ metadata: [],
268
+ onStopSelect: () => { },
269
+ onDrag: () => { },
270
+ xScaleTickFormat: "SS",
271
+ scrubbing: false,
272
+ yAxisLabel: false,
273
+ displaySecondYAxis: false,
274
+ displayArrow: true,
275
+ selectedTheme: null,
276
+ };
277
+ const dataElement = PropTypes.shape({
278
+ x: PropTypes.number,
279
+ y: PropTypes.number,
280
+ });
281
+ const metadataElement = PropTypes.shape({
282
+ name: PropTypes.string,
283
+ color: PropTypes.string,
284
+ });
285
+ PlotlyLiveview.propTypes = {
286
+ xRange: PropTypes.shape({
287
+ from: PropTypes.number,
288
+ length: PropTypes.number,
289
+ }),
290
+ data: PropTypes.arrayOf(PropTypes.arrayOf(dataElement), PropTypes.arrayOf(dataElement)),
291
+ metadata: PropTypes.arrayOf(metadataElement),
292
+ onStopSelect: PropTypes.func,
293
+ onDrag: PropTypes.func,
294
+ xScaleTickFormat: PropTypes.string,
295
+ scrubbing: PropTypes.bool,
296
+ yAxisLabel: PropTypes.bool,
297
+ displaySecondYAxis: PropTypes.bool,
298
+ displayArrow: PropTypes.bool,
299
+ selectedTheme: PropTypes.shape({
300
+ colors: PropTypes.shape({
301
+ background: PropTypes.string,
302
+ }),
303
+ }),
304
+ };
305
305
  //# sourceMappingURL=PlotlyLiveview.js.map
@@ -1,5 +1,5 @@
1
- export const PlotlyPlayback: React.ForwardRefExoticComponent<Pick<Omit<Omit<Omit<any, "targetRef"> & {
2
- targetRef?: any;
3
- }, "width">, "height">, string | number | symbol> & React.RefAttributes<HTMLElement>>;
4
- import React from "react";
1
+ export const PlotlyPlayback: React.ForwardRefExoticComponent<Pick<Omit<Omit<Omit<any, "targetRef"> & {
2
+ targetRef?: any;
3
+ }, "width">, "height">, string | number | symbol> & React.RefAttributes<HTMLElement>>;
4
+ import React from "react";
5
5
  //# sourceMappingURL=PlotlyPlayback.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PlotlyPlayback.d.ts","sourceRoot":"","sources":["../../src/PlotlyGraph/PlotlyPlayback.js"],"names":[],"mappings":"AAyDA;;sFAqSE"}
1
+ {"version":3,"file":"PlotlyPlayback.d.ts","sourceRoot":"","sources":["../../src/PlotlyGraph/PlotlyPlayback.js"],"names":[],"mappings":"AAkFA;;sFAyjBE"}