@oliasoft-open-source/charts-library 2.13.4 → 2.14.0-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.
- package/package.json +2 -2
- package/release-notes.md +4 -0
- package/src/components/controls/axes-options/axes-options.jsx +43 -9
- package/src/components/line-chart/constants/default-translations.js +24 -0
- package/src/components/line-chart/{line-chart-consts.js → constants/line-chart-consts.js} +1 -0
- package/src/components/line-chart/controls/axes-options/action-types.js +5 -0
- package/src/components/{controls → line-chart/controls}/axes-options/axes-options-form-state.js +19 -20
- package/src/components/line-chart/controls/controls.jsx +174 -0
- package/src/components/line-chart/controls/drag-options.jsx +112 -0
- package/src/components/line-chart/controls/legend-options.jsx +36 -0
- package/src/components/{controls → line-chart/controls}/line-options.jsx +18 -8
- package/src/components/line-chart/hooks/use-chart-functions.js +257 -0
- package/src/components/line-chart/hooks/use-chart-options.js +155 -0
- package/src/components/line-chart/hooks/use-chart-plugins.js +26 -0
- package/src/components/line-chart/hooks/use-toggle-handler.js +33 -0
- package/src/components/line-chart/line-chart.jsx +54 -447
- package/src/components/line-chart/state/initial-state.js +7 -8
- package/src/components/line-chart/state/line-chart-reducer.js +68 -86
- package/src/components/line-chart/state/use-chart-state.js +73 -12
- package/src/components/line-chart/{axis-scales → utils/axis-scales}/axis-scales.js +3 -3
- package/src/components/line-chart/{datalabels-alignment → utils/datalabels-alignment}/get-datalabels-position.js +1 -1
- package/src/components/line-chart/utils/generate-line-chart-datasets.js +114 -0
- package/src/components/line-chart/{get-line-chart-data-labels.js → utils/get-line-chart-data-labels.js} +2 -2
- package/src/components/line-chart/{get-line-chart-scales.js → utils/get-line-chart-scales.js} +11 -11
- package/src/components/line-chart/{get-line-chart-tooltips.js → utils/get-line-chart-tooltips.js} +6 -3
- package/src/components/line-chart/utils/get-translations/get-translations.js +17 -0
- package/src/helpers/chart-utils.js +3 -5
- package/src/helpers/enums.js +9 -0
- package/src/components/controls/controls.jsx +0 -114
- package/src/components/controls/drag-options.jsx +0 -98
- package/src/components/controls/legend-options.jsx +0 -25
- /package/src/components/{controls → line-chart/controls}/controls.module.less +0 -0
- /package/src/components/line-chart/{datalabels-alignment → utils/datalabels-alignment}/get-alignment-condition.js +0 -0
- /package/src/components/line-chart/{datalabels-alignment → utils/datalabels-alignment}/get-alignment-data.js +0 -0
- /package/src/components/line-chart/{get-axes-ranges-from-chart.js → utils/get-axes-ranges-from-chart.js} +0 -0
- /package/src/components/line-chart/{line-chart-utils.js → utils/line-chart-utils.js} +0 -0
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
useEffect,
|
|
3
|
-
useLayoutEffect,
|
|
4
|
-
useReducer,
|
|
5
|
-
useRef,
|
|
6
|
-
useState,
|
|
7
|
-
} from 'react';
|
|
1
|
+
import React, { useMemo, useReducer, useRef } from 'react';
|
|
8
2
|
import {
|
|
9
3
|
CategoryScale,
|
|
10
4
|
Chart as ChartJS,
|
|
@@ -22,66 +16,21 @@ import zoomPlugin from 'chartjs-plugin-zoom';
|
|
|
22
16
|
import dataLabelsPlugin from 'chartjs-plugin-datalabels';
|
|
23
17
|
import annotationPlugin from 'chartjs-plugin-annotation';
|
|
24
18
|
import dragDataPlugin from 'chartjs-plugin-dragdata';
|
|
25
|
-
import { triggerBase64Download } from 'react-base64-downloader';
|
|
26
19
|
import styles from './line-chart.module.less';
|
|
27
20
|
import { reducer } from './state/line-chart-reducer';
|
|
28
21
|
import initialState from './state/initial-state';
|
|
29
|
-
import
|
|
30
|
-
DISABLE_DRAG_OPTIONS,
|
|
31
|
-
RESET_AXES_RANGES,
|
|
32
|
-
SAVE_INITIAL_AXES_RANGES,
|
|
33
|
-
TOGGLE_ANNOTATION,
|
|
34
|
-
TOGGLE_DRAG_POINTS,
|
|
35
|
-
TOGGLE_LEGEND,
|
|
36
|
-
TOGGLE_LINE,
|
|
37
|
-
TOGGLE_PAN,
|
|
38
|
-
TOGGLE_POINTS,
|
|
39
|
-
TOGGLE_TABLE,
|
|
40
|
-
TOGGLE_ZOOM,
|
|
41
|
-
UPDATE_AXES_RANGES,
|
|
42
|
-
} from './state/action-types';
|
|
43
|
-
import Controls from '../controls/controls';
|
|
22
|
+
import Controls from './controls/controls';
|
|
44
23
|
import { getDefaultProps, LineChartPropTypes } from './line-chart-prop-types';
|
|
45
|
-
import
|
|
46
|
-
import
|
|
47
|
-
import {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
} from './line-chart-consts';
|
|
56
|
-
|
|
57
|
-
import getAnnotation from '../../helpers/get-chart-annotation';
|
|
58
|
-
import {
|
|
59
|
-
generateRandomColor,
|
|
60
|
-
getChartFileName,
|
|
61
|
-
getClassName,
|
|
62
|
-
getLegend,
|
|
63
|
-
getPlugins,
|
|
64
|
-
setDefaultTheme,
|
|
65
|
-
} from '../../helpers/chart-utils';
|
|
66
|
-
import {
|
|
67
|
-
ANIMATION_DURATION,
|
|
68
|
-
AUTO,
|
|
69
|
-
BORDER_COLOR,
|
|
70
|
-
COLORS,
|
|
71
|
-
CUSTOM_LEGEND_PLUGIN_NAME,
|
|
72
|
-
} from '../../helpers/chart-consts';
|
|
73
|
-
import {
|
|
74
|
-
AxisType,
|
|
75
|
-
ChartHoverMode,
|
|
76
|
-
Key,
|
|
77
|
-
PanZoomMode,
|
|
78
|
-
PointStyle,
|
|
79
|
-
} from '../../helpers/enums';
|
|
80
|
-
import getDraggableData from '../../helpers/get-draggableData';
|
|
81
|
-
import { generateAxisId, generateKey } from './line-chart-utils';
|
|
82
|
-
import { autoScale } from './axis-scales/axis-scales';
|
|
83
|
-
import useChartState from './state/use-chart-state';
|
|
84
|
-
import { getAxesRangesFromChart } from './get-axes-ranges-from-chart';
|
|
24
|
+
import { getClassName, setDefaultTheme } from '../../helpers/chart-utils';
|
|
25
|
+
import { AUTO } from '../../helpers/chart-consts';
|
|
26
|
+
import { generateLineChartDatasets } from './utils/generate-line-chart-datasets';
|
|
27
|
+
import { useChartFunctions } from './hooks/use-chart-functions';
|
|
28
|
+
import { useChartOptions } from './hooks/use-chart-options';
|
|
29
|
+
import { useChartPlugins } from './hooks/use-chart-plugins';
|
|
30
|
+
import { generateKey } from './utils/line-chart-utils';
|
|
31
|
+
import { useChartState } from './state/use-chart-state';
|
|
32
|
+
import { defaultTranslations } from './constants/default-translations';
|
|
33
|
+
import { getTranslations } from './utils/get-translations/get-translations';
|
|
85
34
|
|
|
86
35
|
ChartJS.register(
|
|
87
36
|
LinearScale,
|
|
@@ -106,21 +55,16 @@ ChartJS.register(
|
|
|
106
55
|
const LineChart = (props) => {
|
|
107
56
|
setDefaultTheme();
|
|
108
57
|
const chartRef = useRef(null);
|
|
109
|
-
const
|
|
58
|
+
const { table, translations: translationsRaw } = props;
|
|
59
|
+
const translations = getTranslations(translationsRaw);
|
|
110
60
|
const chart = getDefaultProps(props);
|
|
111
|
-
const { options, testId, persistenceId } = chart;
|
|
112
|
-
const { headerComponent, subheaderComponent, table } = props;
|
|
113
61
|
const {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
legend,
|
|
121
|
-
depthType,
|
|
122
|
-
dragData,
|
|
123
|
-
} = options;
|
|
62
|
+
data: { datasets },
|
|
63
|
+
options,
|
|
64
|
+
testId,
|
|
65
|
+
persistenceId,
|
|
66
|
+
} = chart;
|
|
67
|
+
const { annotations, axes, chartStyling, graph } = options;
|
|
124
68
|
|
|
125
69
|
/**
|
|
126
70
|
* @type {[object, import('react').Dispatch<{type: String, payload: any}>]} useReducer
|
|
@@ -134,269 +78,39 @@ const LineChart = (props) => {
|
|
|
134
78
|
initialState,
|
|
135
79
|
);
|
|
136
80
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
const axes = Object.entries(range).map(([key, { min, max }]) => {
|
|
141
|
-
return {
|
|
142
|
-
id: key,
|
|
143
|
-
min: min ?? 0,
|
|
144
|
-
max: max ?? 0,
|
|
145
|
-
};
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
dispatch({
|
|
149
|
-
type: UPDATE_AXES_RANGES,
|
|
150
|
-
payload: { axes },
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
}, [props.chart.options]);
|
|
154
|
-
|
|
155
|
-
useEffect(() => {
|
|
156
|
-
if (chartRef) {
|
|
157
|
-
//save the initial axis ranges in state (we need this for resetting ranges)
|
|
158
|
-
dispatch({
|
|
159
|
-
type: SAVE_INITIAL_AXES_RANGES,
|
|
160
|
-
payload: { initialAxesRanges: getAxesRangesFromChart(chartRef, axes) },
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
}, []);
|
|
164
|
-
|
|
165
|
-
// Call the custom hook.
|
|
166
|
-
useChartState(options, state, persistenceId);
|
|
167
|
-
|
|
168
|
-
const generateLineChartDatasets = (datasets) => {
|
|
169
|
-
const copyDataset = [...datasets];
|
|
170
|
-
|
|
171
|
-
// Add annotations to dataset to have them appear in legend.
|
|
172
|
-
if (
|
|
173
|
-
annotations.controlAnnotation &&
|
|
174
|
-
annotations.showAnnotations &&
|
|
175
|
-
annotations.annotationsData?.length
|
|
176
|
-
) {
|
|
177
|
-
annotations.annotationsData.forEach((annotation, index) => {
|
|
178
|
-
const color = annotation.color || COLORS[index];
|
|
179
|
-
copyDataset.push({
|
|
180
|
-
isAnnotation: true,
|
|
181
|
-
label: annotation.label,
|
|
182
|
-
annotationIndex: index,
|
|
183
|
-
backgroundColor: color,
|
|
184
|
-
pointBackgroundColor: color,
|
|
185
|
-
borderColor: color,
|
|
186
|
-
data: [{}],
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
const generatedDatasets = copyDataset.map((line, i) => {
|
|
192
|
-
if (line.formation) {
|
|
193
|
-
const axesMin = state.axes[0]?.min;
|
|
194
|
-
const axesMax = state.axes[0]?.max;
|
|
195
|
-
// line with formation flag has 3 points: start point, mid-point with label, and end point.
|
|
196
|
-
const [startPoint, midPointWithLabel, endPoint] = line.data;
|
|
197
|
-
|
|
198
|
-
if (axesMin && startPoint?.x) {
|
|
199
|
-
line.data[0].x = axesMin < startPoint?.x ? axesMin : startPoint?.x;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
if (axesMax && endPoint?.x) {
|
|
203
|
-
line.data[2].x = axesMax > endPoint?.x ? axesMax : endPoint?.x;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
/*
|
|
207
|
-
Remove invalid falsy data points OW-9855
|
|
208
|
-
Points should be an object of {x, y} pairs
|
|
209
|
-
This is an extra guard to prevent crashes if parent apps pass bad inputs
|
|
210
|
-
*/
|
|
211
|
-
line.data = line?.data?.filter(Boolean) || [];
|
|
212
|
-
|
|
213
|
-
line.showLine = state.lineEnabled;
|
|
214
|
-
const linePointRadius = line.pointRadius
|
|
215
|
-
? parseFloat(line.pointRadius)
|
|
216
|
-
: DEFAULT_POINT_RADIUS;
|
|
217
|
-
const pointHoverRadius = line.pointHoverRadius
|
|
218
|
-
? parseFloat(line.pointHoverRadius)
|
|
219
|
-
: DEFAULT_HOVER_RADIUS;
|
|
220
|
-
const indexedColor = COLORS[i];
|
|
221
|
-
|
|
222
|
-
return {
|
|
223
|
-
...line,
|
|
224
|
-
lineTension: graph.lineTension,
|
|
225
|
-
spanGaps: graph.spanGaps,
|
|
226
|
-
borderWidth: parseFloat(line.borderWidth) || DEFAULT_BORDER_WIDTH,
|
|
227
|
-
borderDash: line.borderDash || [],
|
|
228
|
-
borderJoinStyle: BORDER_JOIN_STYLE,
|
|
229
|
-
borderColor:
|
|
230
|
-
line.borderColor || indexedColor || generateRandomColor(COLORS),
|
|
231
|
-
backgroundColor: line.backgroundColor || DEFAULT_BACKGROUND_COLOR,
|
|
232
|
-
pointBackgroundColor:
|
|
233
|
-
line.pointBackgroundColor ||
|
|
234
|
-
indexedColor ||
|
|
235
|
-
generateRandomColor(COLORS),
|
|
236
|
-
pointRadius:
|
|
237
|
-
state.pointsEnabled === true
|
|
238
|
-
? linePointRadius
|
|
239
|
-
: DEFAULT_LINE_POINT_RADIUS,
|
|
240
|
-
pointHoverRadius,
|
|
241
|
-
pointHitRadius: line.pointHitRadius || pointHoverRadius,
|
|
242
|
-
};
|
|
243
|
-
});
|
|
244
|
-
return generatedDatasets;
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
const generatedDatasets = generateLineChartDatasets(chart.data.datasets);
|
|
248
|
-
|
|
249
|
-
const legendClick = (e, legendItem) => {
|
|
250
|
-
const index = legendItem.datasetIndex;
|
|
251
|
-
const chartInstance = chartRef.current;
|
|
252
|
-
const { datasets } = chartInstance.data;
|
|
253
|
-
const dataset = datasets[index];
|
|
254
|
-
const meta = chartInstance.getDatasetMeta(index);
|
|
255
|
-
meta.hidden = meta.hidden === null ? !dataset.hidden : null;
|
|
81
|
+
const generatedDatasets = useMemo(() => {
|
|
82
|
+
return generateLineChartDatasets(datasets, state, options, translations);
|
|
83
|
+
}, [state.lineEnabled, state.pointsEnabled, axes, annotations, graph]);
|
|
256
84
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
dispatch({ type: TOGGLE_ANNOTATION, payload: { annotationIndex } });
|
|
260
|
-
}
|
|
85
|
+
// Call the custom hooks.
|
|
86
|
+
useChartState({ chartRef, options, state, dispatch, persistenceId });
|
|
261
87
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
if (interactions.onLegendClick) {
|
|
273
|
-
interactions.onLegendClick(legendItem?.text, legendItem.hidden);
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
chartInstance.update();
|
|
277
|
-
};
|
|
278
|
-
|
|
279
|
-
const resetZoom = () => {
|
|
280
|
-
const chartInstance = chartRef.current;
|
|
281
|
-
chartInstance.resetZoom();
|
|
282
|
-
dispatch({ type: RESET_AXES_RANGES });
|
|
283
|
-
};
|
|
284
|
-
|
|
285
|
-
const onHover = (evt, hoveredItems) => {
|
|
286
|
-
if (!hoveredItems?.length && interactions.onPointUnhover && hoveredPoint) {
|
|
287
|
-
setHoveredPoint(null);
|
|
288
|
-
interactions.onPointUnhover(evt);
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
if (hoveredItems?.length && interactions.onPointHover) {
|
|
292
|
-
const { index, datasetIndex } = hoveredItems[0];
|
|
293
|
-
const dataset = generatedDatasets[datasetIndex];
|
|
294
|
-
const point = dataset?.data[index];
|
|
295
|
-
|
|
296
|
-
if (point && hoveredPoint !== point) {
|
|
297
|
-
setHoveredPoint(point);
|
|
298
|
-
interactions.onPointHover(evt, datasetIndex, index, generatedDatasets);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
};
|
|
302
|
-
|
|
303
|
-
const handleDownload = () => {
|
|
304
|
-
const chart = chartRef.current;
|
|
305
|
-
// Add temporary canvas background
|
|
306
|
-
const { ctx } = chart;
|
|
307
|
-
ctx.save();
|
|
308
|
-
ctx.globalCompositeOperation = 'destination-over';
|
|
309
|
-
ctx.fillStyle = 'white';
|
|
310
|
-
ctx.fillRect(0, 0, chart.width, chart.height);
|
|
311
|
-
ctx.restore();
|
|
312
|
-
|
|
313
|
-
const base64Image = chart.toBase64Image();
|
|
314
|
-
const fileName = getChartFileName(state.axes);
|
|
315
|
-
|
|
316
|
-
triggerBase64Download(base64Image, fileName);
|
|
317
|
-
};
|
|
318
|
-
|
|
319
|
-
const handleKeyDown = (evt) => {
|
|
320
|
-
if (evt.key === Key.Shift) {
|
|
321
|
-
const chart = chartRef.current;
|
|
322
|
-
chart.config.options.plugins.zoom.zoom.mode = PanZoomMode.Y;
|
|
323
|
-
chart.config.options.plugins.zoom.pan.mode = PanZoomMode.Y;
|
|
324
|
-
chart.update();
|
|
325
|
-
}
|
|
326
|
-
};
|
|
327
|
-
|
|
328
|
-
const handleKeyUp = (evt) => {
|
|
329
|
-
if (evt.key === Key.Shift) {
|
|
330
|
-
const chart = chartRef.current;
|
|
331
|
-
chart.config.options.plugins.zoom.zoom.mode = PanZoomMode.Z;
|
|
332
|
-
chart.config.options.plugins.zoom.pan.mode = PanZoomMode.Z;
|
|
333
|
-
chart.update();
|
|
334
|
-
}
|
|
335
|
-
};
|
|
336
|
-
|
|
337
|
-
const getControlsAxes = () => {
|
|
338
|
-
return state.axes.map((axis, i) => {
|
|
339
|
-
const axisType = i ? AxisType.Y : AxisType.X; // only first element is 'x' - rest is 'y'
|
|
340
|
-
const min = axis.min ?? additionalAxesOptions?.range?.[axisType]?.min;
|
|
341
|
-
const max = axis.max ?? additionalAxesOptions?.range?.[axisType]?.max;
|
|
342
|
-
// we need to get all axes element to array to set unit.
|
|
343
|
-
const axesArray = axes.x.concat(axes.y);
|
|
344
|
-
const unit = axesArray?.[i]?.unit;
|
|
345
|
-
return {
|
|
346
|
-
...axis,
|
|
347
|
-
//only add min and max properties if they are defined:
|
|
348
|
-
...(min ? { min } : {}),
|
|
349
|
-
...(max ? { max } : {}),
|
|
350
|
-
...(unit ? { unit } : {}),
|
|
351
|
-
};
|
|
88
|
+
const { resetZoom, handleDownload, handleKeyDown, handleKeyUp } =
|
|
89
|
+
useChartFunctions({
|
|
90
|
+
chartRef,
|
|
91
|
+
state,
|
|
92
|
+
options,
|
|
93
|
+
dispatch,
|
|
94
|
+
generatedDatasets,
|
|
352
95
|
});
|
|
353
|
-
};
|
|
354
|
-
const controlsAxes = getControlsAxes(axes);
|
|
355
|
-
|
|
356
|
-
const getControlsAxesLabels = (propsAxes) => {
|
|
357
|
-
if (!Object.keys(propsAxes)?.length) {
|
|
358
|
-
return [];
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
const getAxesLabels = (axes, axisType) => {
|
|
362
|
-
if (!axes[axisType] || !axes[axisType]?.length) {
|
|
363
|
-
return [];
|
|
364
|
-
} else {
|
|
365
|
-
return axes[axisType].map((axisObj, index) => {
|
|
366
|
-
return {
|
|
367
|
-
id: generateAxisId(axisType, index, axes[axisType].length > 1),
|
|
368
|
-
label: axisObj?.label || '',
|
|
369
|
-
};
|
|
370
|
-
});
|
|
371
|
-
}
|
|
372
|
-
};
|
|
373
96
|
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
97
|
+
const useOptions = useChartOptions({
|
|
98
|
+
chartRef,
|
|
99
|
+
state,
|
|
100
|
+
options,
|
|
101
|
+
dispatch,
|
|
102
|
+
generatedDatasets,
|
|
103
|
+
});
|
|
380
104
|
|
|
381
|
-
const
|
|
382
|
-
|
|
383
|
-
const updateAxesRangesFromChart = (chart) => {
|
|
384
|
-
const { scales = {} } = chart || {};
|
|
385
|
-
const axes = Object.entries(scales).map(([key, { min, max }]) => {
|
|
386
|
-
return {
|
|
387
|
-
id: key,
|
|
388
|
-
min: min ?? 0,
|
|
389
|
-
max: max ?? 0,
|
|
390
|
-
};
|
|
391
|
-
});
|
|
392
|
-
dispatch({
|
|
393
|
-
type: UPDATE_AXES_RANGES,
|
|
394
|
-
payload: { axes },
|
|
395
|
-
});
|
|
396
|
-
};
|
|
105
|
+
const usePlugins = useChartPlugins({ options, resetZoom });
|
|
397
106
|
|
|
398
107
|
return (
|
|
399
108
|
<div
|
|
109
|
+
key={generateKey([
|
|
110
|
+
state.enableDragPoints,
|
|
111
|
+
state.zoomEnabled,
|
|
112
|
+
state.panEnabled,
|
|
113
|
+
])}
|
|
400
114
|
className={getClassName(chartStyling, styles)}
|
|
401
115
|
style={{
|
|
402
116
|
width: chartStyling.width || AUTO,
|
|
@@ -408,132 +122,25 @@ const LineChart = (props) => {
|
|
|
408
122
|
data-testid={testId}
|
|
409
123
|
>
|
|
410
124
|
<Controls
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
onResetAxes={() => {
|
|
419
|
-
dispatch({ type: RESET_AXES_RANGES });
|
|
420
|
-
}}
|
|
421
|
-
onUpdateAxes={({ axes }) => {
|
|
422
|
-
dispatch({ type: UPDATE_AXES_RANGES, payload: { axes } });
|
|
423
|
-
}}
|
|
424
|
-
onToggleLegend={() => dispatch({ type: TOGGLE_LEGEND })}
|
|
425
|
-
onToggleLine={() => dispatch({ type: TOGGLE_LINE })}
|
|
426
|
-
onTogglePan={() => dispatch({ type: TOGGLE_PAN })}
|
|
427
|
-
onTogglePoints={() => dispatch({ type: TOGGLE_POINTS })}
|
|
428
|
-
onToggleTable={() => dispatch({ type: TOGGLE_TABLE })}
|
|
429
|
-
onToggleZoom={() => dispatch({ type: TOGGLE_ZOOM })}
|
|
430
|
-
panEnabled={state.panEnabled}
|
|
431
|
-
pointsEnabled={state.pointsEnabled}
|
|
432
|
-
initialAxesRanges={state.initialAxesRanges}
|
|
433
|
-
showTable={state.showTable}
|
|
434
|
-
subheaderComponent={subheaderComponent}
|
|
435
|
-
table={table}
|
|
436
|
-
zoomEnabled={state.zoomEnabled}
|
|
437
|
-
depthType={depthType}
|
|
438
|
-
enableDragPoints={state.enableDragPoints}
|
|
439
|
-
isDragDataAllowed={dragData.enableDragData}
|
|
440
|
-
onToggleDragPoints={() => dispatch({ type: TOGGLE_DRAG_POINTS })}
|
|
441
|
-
onDisableDragOptions={() => dispatch({ type: DISABLE_DRAG_OPTIONS })}
|
|
125
|
+
props={props}
|
|
126
|
+
chartRef={chartRef}
|
|
127
|
+
state={state}
|
|
128
|
+
options={options}
|
|
129
|
+
dispatch={dispatch}
|
|
130
|
+
generatedDatasets={generatedDatasets}
|
|
131
|
+
translations={translations}
|
|
442
132
|
/>
|
|
443
133
|
{table && state.showTable ? (
|
|
444
134
|
<div className={styles.table}>{table}</div>
|
|
445
135
|
) : (
|
|
446
136
|
<div className={styles.canvas}>
|
|
447
137
|
<Line
|
|
448
|
-
key={generateKey([
|
|
449
|
-
state.enableDragPoints,
|
|
450
|
-
state.zoomEnabled,
|
|
451
|
-
state.panEnabled,
|
|
452
|
-
])}
|
|
453
138
|
ref={chartRef}
|
|
454
139
|
data={{
|
|
455
140
|
datasets: generatedDatasets,
|
|
456
141
|
}}
|
|
457
|
-
options={
|
|
458
|
-
|
|
459
|
-
maintainAspectRatio: chartStyling.maintainAspectRatio,
|
|
460
|
-
aspectRatio: chartStyling.squareAspectRatio ? 1 : null, // 1 equals square aspect ratio
|
|
461
|
-
animation: chartStyling.performanceMode
|
|
462
|
-
? false
|
|
463
|
-
: {
|
|
464
|
-
duration: ANIMATION_DURATION.FAST,
|
|
465
|
-
onComplete: interactions.onAnimationComplete,
|
|
466
|
-
},
|
|
467
|
-
hover: {
|
|
468
|
-
mode: ChartHoverMode.Nearest,
|
|
469
|
-
intersect: true,
|
|
470
|
-
},
|
|
471
|
-
elements: {
|
|
472
|
-
line: {
|
|
473
|
-
pointStyle: PointStyle.Circle,
|
|
474
|
-
showLine: state.lineEnabled,
|
|
475
|
-
},
|
|
476
|
-
},
|
|
477
|
-
scales: autoScale(options, state, generatedDatasets),
|
|
478
|
-
plugins: {
|
|
479
|
-
// title: getTitle(options),
|
|
480
|
-
datalabels: getLineChartDataLabels(options),
|
|
481
|
-
annotation: getAnnotation(options, state),
|
|
482
|
-
zoom: {
|
|
483
|
-
pan: {
|
|
484
|
-
enabled: state.panEnabled,
|
|
485
|
-
mode: PanZoomMode.XY,
|
|
486
|
-
onPanComplete({ chart }) {
|
|
487
|
-
updateAxesRangesFromChart(chart);
|
|
488
|
-
},
|
|
489
|
-
},
|
|
490
|
-
zoom: {
|
|
491
|
-
mode: PanZoomMode.XY,
|
|
492
|
-
drag: {
|
|
493
|
-
enabled: state.zoomEnabled,
|
|
494
|
-
threshold: 3,
|
|
495
|
-
backgroundColor: ZOOM_BOX_BACKGROUND_COLOR,
|
|
496
|
-
borderColor: BORDER_COLOR,
|
|
497
|
-
borderWidth: 1,
|
|
498
|
-
},
|
|
499
|
-
onZoomComplete({ chart }) {
|
|
500
|
-
updateAxesRangesFromChart(chart);
|
|
501
|
-
},
|
|
502
|
-
},
|
|
503
|
-
},
|
|
504
|
-
tooltip: getLineChartToolTips(options),
|
|
505
|
-
legend: getLegend(options, legendClick, state),
|
|
506
|
-
[CUSTOM_LEGEND_PLUGIN_NAME]: options.legend.customLegend
|
|
507
|
-
.customLegendPlugin && {
|
|
508
|
-
containerID:
|
|
509
|
-
options.legend.customLegend.customLegendContainerID,
|
|
510
|
-
},
|
|
511
|
-
chartAreaBorder: {
|
|
512
|
-
borderColor: BORDER_COLOR,
|
|
513
|
-
},
|
|
514
|
-
...(state.enableDragPoints ? getDraggableData(options) : {}),
|
|
515
|
-
},
|
|
516
|
-
events: [
|
|
517
|
-
'mousemove',
|
|
518
|
-
'mouseout',
|
|
519
|
-
'click',
|
|
520
|
-
'touchstart',
|
|
521
|
-
'touchmove',
|
|
522
|
-
'dblclick',
|
|
523
|
-
],
|
|
524
|
-
}}
|
|
525
|
-
plugins={[
|
|
526
|
-
...getPlugins(graph, legend, state),
|
|
527
|
-
{
|
|
528
|
-
id: 'customEventCatcher',
|
|
529
|
-
beforeEvent(chart, args, pluginOptions) {
|
|
530
|
-
const { event } = args;
|
|
531
|
-
if (event.type === 'dblclick') {
|
|
532
|
-
resetZoom();
|
|
533
|
-
}
|
|
534
|
-
},
|
|
535
|
-
},
|
|
536
|
-
]}
|
|
142
|
+
options={useOptions}
|
|
143
|
+
plugins={usePlugins}
|
|
537
144
|
/>
|
|
538
145
|
</div>
|
|
539
146
|
)}
|
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
import { AxisType } from '../../../helpers/enums';
|
|
2
2
|
import { setAnnotations } from '../../../helpers/chart-utils';
|
|
3
|
-
import { generateAxisId } from '../line-chart-utils';
|
|
3
|
+
import { generateAxisId } from '../utils/line-chart-utils';
|
|
4
4
|
import { getChartStateFromStorage } from './manage-state-in-local-storage';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
|
|
8
7
|
Initial chart state for the line chart.
|
|
8
|
+
|
|
9
9
|
@param {Object} options - The chart options.
|
|
10
10
|
@return {Object} The initial chart state.
|
|
11
11
|
*/
|
|
12
12
|
const initialState = ({ options, persistenceId }) => {
|
|
13
13
|
const {
|
|
14
14
|
additionalAxesOptions: { range: customAxesRange },
|
|
15
|
-
annotations,
|
|
15
|
+
annotations: { annotationsData },
|
|
16
16
|
axes,
|
|
17
|
-
chartOptions,
|
|
18
|
-
legend,
|
|
17
|
+
chartOptions: { enableZoom, enablePan, showPoints, showLine },
|
|
18
|
+
legend: { display },
|
|
19
19
|
dragData,
|
|
20
20
|
} = options;
|
|
21
|
-
const { enableZoom, enablePan, showPoints, showLine } = chartOptions;
|
|
22
21
|
/**
|
|
23
22
|
* getStateAxesByType
|
|
24
23
|
* @param {'x'|'y'} axisType
|
|
@@ -79,9 +78,9 @@ const initialState = ({ options, persistenceId }) => {
|
|
|
79
78
|
panEnabled: panEnabled ?? enablePan,
|
|
80
79
|
pointsEnabled: pointsEnabled ?? showPoints,
|
|
81
80
|
lineEnabled: lineEnabled ?? showLine,
|
|
82
|
-
legendEnabled: legendEnabled ??
|
|
81
|
+
legendEnabled: legendEnabled ?? display,
|
|
83
82
|
axes: stateAxes,
|
|
84
|
-
showAnnotationLineIndex: setAnnotations(
|
|
83
|
+
showAnnotationLineIndex: setAnnotations(annotationsData),
|
|
85
84
|
showTable: false,
|
|
86
85
|
enableDragPoints: dragData.enableDragData && enableDragPoints,
|
|
87
86
|
};
|