@oliasoft-open-source/charts-library 2.17.6 → 2.18.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.
Files changed (84) hide show
  1. package/package.json +26 -34
  2. package/index.js +0 -14
  3. package/release-notes.md +0 -310
  4. package/src/assets/icons/line-and-point.svg +0 -1
  5. package/src/assets/icons/line-only.svg +0 -1
  6. package/src/assets/icons/list-hide.svg +0 -1
  7. package/src/assets/icons/point-only.svg +0 -1
  8. package/src/components/bar-chart/bar-chart-prop-types.js +0 -209
  9. package/src/components/bar-chart/bar-chart.interface.ts +0 -91
  10. package/src/components/bar-chart/bar-chart.jsx +0 -247
  11. package/src/components/bar-chart/bar-chart.module.less +0 -61
  12. package/src/components/bar-chart/get-bar-chart-data-labels.js +0 -42
  13. package/src/components/bar-chart/get-bar-chart-scales.js +0 -123
  14. package/src/components/bar-chart/get-bar-chart-tooltips.js +0 -102
  15. package/src/components/controls/axes-options/axes-options.jsx +0 -270
  16. package/src/components/line-chart/constants/default-translations.js +0 -24
  17. package/src/components/line-chart/constants/line-chart-consts.js +0 -12
  18. package/src/components/line-chart/controls/axes-options/action-types.js +0 -5
  19. package/src/components/line-chart/controls/axes-options/axes-options-form-state.js +0 -97
  20. package/src/components/line-chart/controls/controls.jsx +0 -174
  21. package/src/components/line-chart/controls/controls.module.less +0 -12
  22. package/src/components/line-chart/controls/drag-options.jsx +0 -112
  23. package/src/components/line-chart/controls/legend-options.jsx +0 -36
  24. package/src/components/line-chart/controls/line-options.jsx +0 -64
  25. package/src/components/line-chart/hooks/use-chart-functions.js +0 -257
  26. package/src/components/line-chart/hooks/use-chart-options.js +0 -181
  27. package/src/components/line-chart/hooks/use-chart-plugins.js +0 -35
  28. package/src/components/line-chart/hooks/use-toggle-handler.js +0 -33
  29. package/src/components/line-chart/initialize/config.js +0 -23
  30. package/src/components/line-chart/initialize/initialize-line-chart.js +0 -25
  31. package/src/components/line-chart/line-chart-prop-types.js +0 -292
  32. package/src/components/line-chart/line-chart.interface.ts +0 -121
  33. package/src/components/line-chart/line-chart.jsx +0 -161
  34. package/src/components/line-chart/line-chart.module.less +0 -77
  35. package/src/components/line-chart/plugins/chart-area-text-plugin.js +0 -246
  36. package/src/components/line-chart/plugins/line-chart.minor-gridlines-plugin.js +0 -88
  37. package/src/components/line-chart/plugins/plugin-constants.js +0 -11
  38. package/src/components/line-chart/state/action-types.js +0 -12
  39. package/src/components/line-chart/state/initial-state.js +0 -89
  40. package/src/components/line-chart/state/line-chart-reducer.js +0 -100
  41. package/src/components/line-chart/state/manage-state-in-local-storage.js +0 -86
  42. package/src/components/line-chart/state/use-chart-state.js +0 -141
  43. package/src/components/line-chart/utils/axis-scales/axis-scales.js +0 -165
  44. package/src/components/line-chart/utils/datalabels-alignment/get-alignment-condition.js +0 -13
  45. package/src/components/line-chart/utils/datalabels-alignment/get-alignment-data.js +0 -20
  46. package/src/components/line-chart/utils/datalabels-alignment/get-datalabels-position.js +0 -25
  47. package/src/components/line-chart/utils/generate-line-chart-datasets.js +0 -114
  48. package/src/components/line-chart/utils/get-axes-ranges-from-chart.js +0 -13
  49. package/src/components/line-chart/utils/get-line-chart-data-labels.js +0 -21
  50. package/src/components/line-chart/utils/get-line-chart-scales.js +0 -120
  51. package/src/components/line-chart/utils/get-line-chart-tooltips.js +0 -94
  52. package/src/components/line-chart/utils/line-chart-utils.js +0 -77
  53. package/src/components/line-chart/utils/translations/get-translations.js +0 -17
  54. package/src/components/pie-chart/pie-chart-prop-types.js +0 -111
  55. package/src/components/pie-chart/pie-chart-utils.js +0 -32
  56. package/src/components/pie-chart/pie-chart.interface.ts +0 -61
  57. package/src/components/pie-chart/pie-chart.jsx +0 -450
  58. package/src/components/pie-chart/pie-chart.module.less +0 -61
  59. package/src/components/scatter-chart/scatter-chart.intefrace.ts +0 -33
  60. package/src/components/scatter-chart/scatter-chart.jsx +0 -21
  61. package/src/components/scatter-chart/scatter-chart.module.less +0 -4
  62. package/src/helpers/chart-border-plugin.js +0 -19
  63. package/src/helpers/chart-consts.js +0 -64
  64. package/src/helpers/chart-interface.ts +0 -94
  65. package/src/helpers/chart-utils.js +0 -182
  66. package/src/helpers/container.jsx +0 -60
  67. package/src/helpers/disabled-context.js +0 -8
  68. package/src/helpers/enums.js +0 -96
  69. package/src/helpers/get-chart-annotation.js +0 -106
  70. package/src/helpers/get-custom-legend-plugin-example.js +0 -80
  71. package/src/helpers/get-draggableData.js +0 -32
  72. package/src/helpers/range/estimate-data-series-have-close-values.js +0 -54
  73. package/src/helpers/range/range.js +0 -100
  74. package/src/helpers/text.js +0 -6
  75. package/src/style/external.less +0 -4
  76. package/src/style/fonts/lato/Lato-Bold.woff2 +0 -0
  77. package/src/style/fonts/lato/Lato-BoldItalic.woff2 +0 -0
  78. package/src/style/fonts/lato/Lato-Italic.woff2 +0 -0
  79. package/src/style/fonts/lato/Lato-Regular.woff2 +0 -0
  80. package/src/style/fonts.less +0 -27
  81. package/src/style/global.less +0 -43
  82. package/src/style/reset/reset.less +0 -28
  83. package/src/style/shared.less +0 -11
  84. package/src/style/variables.less +0 -91
@@ -1,36 +0,0 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import { Button, Icon, Tooltip } from '@oliasoft-open-source/react-ui-library';
4
- import { RiListUnordered } from 'react-icons/ri';
5
- import listHideIcon from '../../../assets/icons/list-hide.svg';
6
-
7
- export const LegendOptions = ({
8
- legendEnabled,
9
- onToggleLegend,
10
- translations: { hideLegend, showLegend },
11
- }) => {
12
- const tooltipText = legendEnabled ? hideLegend : showLegend;
13
- const icon = legendEnabled ? (
14
- <RiListUnordered />
15
- ) : (
16
- <Icon icon={listHideIcon} />
17
- );
18
-
19
- return (
20
- <Tooltip text={tooltipText} placement="bottom">
21
- <Button
22
- small
23
- basic
24
- colored="muted"
25
- round
26
- icon={icon}
27
- onClick={onToggleLegend}
28
- />
29
- </Tooltip>
30
- );
31
- };
32
-
33
- LegendOptions.propTypes = {
34
- legendEnabled: PropTypes.bool.isRequired,
35
- onToggleLegend: PropTypes.func.isRequired,
36
- };
@@ -1,64 +0,0 @@
1
- import React from 'react';
2
- import { Button, Icon, Tooltip } from '@oliasoft-open-source/react-ui-library';
3
- import PropTypes from 'prop-types';
4
- import lineOnlyIcon from '../../../assets/icons/line-only.svg';
5
- import pointOnlyIcon from '../../../assets/icons/point-only.svg';
6
- import lineAndPointIcon from '../../../assets/icons/line-and-point.svg';
7
-
8
- export const LineOptions = ({
9
- lineEnabled,
10
- onToggleLine,
11
- onTogglePoints,
12
- pointsEnabled,
13
- translations,
14
- }) => {
15
- const options = [
16
- {
17
- label: translations.pointsLines,
18
- icon: <Icon icon={lineAndPointIcon} />,
19
- selected: pointsEnabled && lineEnabled,
20
- onClick: () => {
21
- onTogglePoints();
22
- },
23
- },
24
- {
25
- label: translations.linesOnly,
26
- icon: <Icon icon={lineOnlyIcon} />,
27
- selected: !pointsEnabled && lineEnabled,
28
- onClick: () => {
29
- onTogglePoints();
30
- onToggleLine();
31
- },
32
- },
33
- {
34
- label: translations.pointsOnly,
35
- icon: <Icon icon={pointOnlyIcon} />,
36
- selected: pointsEnabled && !lineEnabled,
37
- onClick: () => {
38
- onToggleLine();
39
- },
40
- },
41
- ];
42
-
43
- const selectedOption = options.find((option) => option.selected);
44
-
45
- return (
46
- <Tooltip text={selectedOption.label} placement="bottom">
47
- <Button
48
- small
49
- basic
50
- colored="muted"
51
- round
52
- icon={selectedOption.icon}
53
- onClick={selectedOption.onClick}
54
- />
55
- </Tooltip>
56
- );
57
- };
58
-
59
- LineOptions.propTypes = {
60
- lineEnabled: PropTypes.bool.isRequired,
61
- onToggleLine: PropTypes.func.isRequired,
62
- onTogglePoints: PropTypes.func.isRequired,
63
- pointsEnabled: PropTypes.bool.isRequired,
64
- };
@@ -1,257 +0,0 @@
1
- import { useCallback } from 'react';
2
- import { triggerBase64Download } from 'react-base64-downloader';
3
- import { AxisType, Key, PanZoomMode } from '../../../helpers/enums';
4
- import { getChartFileName } from '../../../helpers/chart-utils';
5
- import { generateAxisId } from '../utils/line-chart-utils';
6
- import { RESET_AXES_RANGES, UPDATE_AXES_RANGES } from '../state/action-types';
7
-
8
- /**
9
- * Custom hook that encapsulates the chart-related functions and their dependencies
10
- * @param {Object} chartRef - Chart reference
11
- * @param {Object} state - The component state
12
- * @param {Object} options - Chart options
13
- * @param {Function} dispatch - Dispatch function from useReducer
14
- * @param {Array} generatedDatasets - Chart datasets
15
- * @returns {Object} An object containing the chart-related functions
16
- */
17
- export const useChartFunctions = ({
18
- chartRef,
19
- state,
20
- options,
21
- dispatch,
22
- generatedDatasets,
23
- }) => {
24
- const {
25
- annotations,
26
- interactions: { onLegendClick, onPointHover, onPointUnhover },
27
- additionalAxesOptions,
28
- axes,
29
- } = options;
30
-
31
- /**
32
- * Handles legend click events
33
- * @param {Event} e - Click event
34
- * @param {Object} legendItem - Legend item data
35
- */
36
- const legendClick = useCallback(
37
- (e, legendItem) => {
38
- const { datasetIndex } = legendItem;
39
- const chartInstance = chartRef.current;
40
- const { datasets } = chartInstance.data;
41
- const dataset = datasets[datasetIndex];
42
- const meta = chartInstance.getDatasetMeta(datasetIndex);
43
- meta.hidden = meta.hidden === null ? !dataset.hidden : null;
44
-
45
- if (annotations.controlAnnotation && dataset.isAnnotation) {
46
- const { annotationIndex } = dataset;
47
- dispatch({ type: 'TOGGLE_ANNOTATION', payload: { annotationIndex } });
48
- }
49
-
50
- // Show/hide entire display group
51
- if (dataset.displayGroup) {
52
- datasets.forEach((ds, ix) => {
53
- if (ds.displayGroup !== dataset.displayGroup) return;
54
- chartInstance.getDatasetMeta(ix).hidden = meta.hidden;
55
- });
56
- }
57
-
58
- if (onLegendClick) {
59
- onLegendClick(legendItem?.text, legendItem.hidden);
60
- }
61
-
62
- chartInstance.update();
63
- },
64
- [onLegendClick, annotations],
65
- );
66
-
67
- /**
68
- * Resets the chart zoom and updates the axes ranges
69
- * @returns {Function} Memoized resetZoom function
70
- */
71
- const resetZoom = useCallback(() => {
72
- const chartInstance = chartRef.current;
73
- chartInstance.resetZoom();
74
- dispatch({ type: 'RESET_AXES_RANGES' });
75
- }, [chartRef]);
76
-
77
- /**
78
- * Handles the hover event on chart points
79
- * @param {Object} hoveredPoint - Currently hovered point
80
- * @param {Function} setHoveredPoint - Setter function for hoveredPoint state
81
- * @returns {Function} Memoized onHover function
82
- */
83
- const onHover = useCallback((hoveredPoint, setHoveredPoint) => {
84
- return (evt, hoveredItems) => {
85
- if (!hoveredItems?.length && onPointUnhover && hoveredPoint) {
86
- setHoveredPoint(null);
87
- onPointUnhover(evt);
88
- }
89
-
90
- if (hoveredItems?.length && onPointHover) {
91
- const { index, datasetIndex } = hoveredItems[0];
92
- const dataset = generatedDatasets[datasetIndex];
93
- const point = dataset?.data[index];
94
-
95
- if (point && hoveredPoint !== point) {
96
- setHoveredPoint(point);
97
- onPointHover(evt, datasetIndex, index, generatedDatasets);
98
- }
99
- }
100
- };
101
- }, []);
102
-
103
- /**
104
- * Handles the download of the chart as an image
105
- * @returns {Function} Memoized handleDownload function
106
- */
107
- const handleDownload = useCallback(() => {
108
- const chart = chartRef.current;
109
-
110
- // Add temporary canvas background
111
- const { ctx } = chart;
112
- ctx.save();
113
- ctx.globalCompositeOperation = 'destination-over';
114
- ctx.fillStyle = 'white';
115
- ctx.fillRect(0, 0, chart.width, chart.height);
116
- ctx.restore();
117
-
118
- const base64Image = chart.toBase64Image();
119
- const fileName = getChartFileName(state.axes);
120
-
121
- triggerBase64Download(base64Image, fileName);
122
- }, [chartRef, state.axes]);
123
-
124
- /**
125
- * Handles the key down event for the chart
126
- * @returns {Function} Memoized handleKeyDown function
127
- */
128
- const handleKeyDown = useCallback(
129
- (evt) => {
130
- if (evt.key === Key.Shift) {
131
- const chart = chartRef.current;
132
- chart.config.options.plugins.zoom.zoom.mode = PanZoomMode.Y;
133
- chart.config.options.plugins.zoom.pan.mode = PanZoomMode.Y;
134
- chart.update();
135
- }
136
- },
137
- [chartRef],
138
- );
139
-
140
- /**
141
- * Handles the key up event for the chart
142
- * @returns {Function} Memoized handleKeyUp function
143
- */
144
- const handleKeyUp = useCallback(
145
- (evt) => {
146
- if (evt.key === Key.Shift) {
147
- const chart = chartRef.current;
148
- chart.config.options.plugins.zoom.zoom.mode = PanZoomMode.Z;
149
- chart.config.options.plugins.zoom.pan.mode = PanZoomMode.Z;
150
- chart.update();
151
- }
152
- },
153
- [chartRef],
154
- );
155
-
156
- /**
157
- * Get the controls axes based on the state and additionalAxesOptions.
158
- * @returns {Array} Array of controls axes.
159
- */
160
- const controlsAxes = state.axes.map((axis, i) => {
161
- const axisType = i ? AxisType.Y : AxisType.X; // only first element is 'x' - rest is 'y'
162
- const min = axis.min ?? additionalAxesOptions?.range?.[axisType]?.min;
163
- const max = axis.max ?? additionalAxesOptions?.range?.[axisType]?.max;
164
- return {
165
- ...axis,
166
- // only add min and max properties if they are defined:
167
- ...(min ? { min } : {}),
168
- ...(max ? { max } : {}),
169
- };
170
- });
171
-
172
- /**
173
- * Get the controls axes labels based on the propsAxes.
174
- * @param {Object} propsAxes - Props axes object.
175
- * @returns {Array} Array of controls axes labels.
176
- */
177
- const getControlsAxesLabels = useCallback(
178
- (propsAxes) => {
179
- if (!Object.keys(propsAxes)?.length) {
180
- return [];
181
- }
182
-
183
- const getAxesLabels = (axes, axisType) => {
184
- if (!axes[axisType] || !axes[axisType]?.length) {
185
- return [];
186
- } else {
187
- return axes[axisType].map((axisObj, index) => {
188
- return {
189
- id: generateAxisId(axisType, index, axes[axisType].length > 1),
190
- label: axisObj?.label || '',
191
- };
192
- });
193
- }
194
- };
195
-
196
- const axesLabels = [
197
- ...getAxesLabels(propsAxes, AxisType.X),
198
- ...getAxesLabels(propsAxes, AxisType.Y),
199
- ];
200
- return axesLabels;
201
- },
202
- [axes],
203
- );
204
-
205
- /**
206
- * Update axes ranges from the chart.
207
- * @param {Object} chart - Chart instance.
208
- */
209
- const updateAxesRangesFromChart = useCallback(() => {
210
- const { scales = {} } = chartRef?.current || {};
211
- const axes = Object.entries(scales).map(([key, { min, max }]) => {
212
- return {
213
- id: key,
214
- min: min ?? 0,
215
- max: max ?? 0,
216
- };
217
- });
218
- dispatch({
219
- type: UPDATE_AXES_RANGES,
220
- payload: { axes },
221
- });
222
- }, [axes]);
223
-
224
- /**
225
- * Handler for resetting axes ranges.
226
- * @type {Function}
227
- */
228
- const onResetAxes = useCallback(() => {
229
- // Dispatch the RESET_AXES_RANGES action
230
- dispatch({ type: RESET_AXES_RANGES });
231
- }, []);
232
-
233
- /**
234
- * Handler for updating axes ranges.
235
- * @param {Object} axesInfo - Object containing axes information.
236
- * @param {Array} axesInfo.axes - Array of axes to update.
237
- * @type {Function}
238
- */
239
- const onUpdateAxes = useCallback(({ axes }) => {
240
- // Dispatch the UPDATE_AXES_RANGES action with payload
241
- dispatch({ type: UPDATE_AXES_RANGES, payload: { axes } });
242
- }, []);
243
-
244
- return {
245
- legendClick,
246
- resetZoom,
247
- onHover,
248
- handleDownload,
249
- handleKeyDown,
250
- handleKeyUp,
251
- controlsAxes,
252
- controlsAxesLabels: getControlsAxesLabels(axes),
253
- updateAxesRangesFromChart,
254
- onResetAxes,
255
- onUpdateAxes,
256
- };
257
- };
@@ -1,181 +0,0 @@
1
- import { useMemo, useState } from 'react';
2
- import {
3
- ANIMATION_DURATION,
4
- BORDER_COLOR,
5
- CUSTOM_LEGEND_PLUGIN_NAME,
6
- } from '../../../helpers/chart-consts';
7
- import {
8
- ChartHoverMode,
9
- Events,
10
- PanZoomMode,
11
- PointStyle,
12
- } from '../../../helpers/enums';
13
- import { autoScale } from '../utils/axis-scales/axis-scales';
14
- import getLineChartDataLabels from '../utils/get-line-chart-data-labels';
15
- import getAnnotation from '../../../helpers/get-chart-annotation';
16
- import { ZOOM_BOX_BACKGROUND_COLOR } from '../constants/line-chart-consts';
17
- import getLineChartToolTips from '../utils/get-line-chart-tooltips';
18
- import { getLegend } from '../../../helpers/chart-utils';
19
- import getDraggableData from '../../../helpers/get-draggableData';
20
- import { useChartFunctions } from './use-chart-functions';
21
-
22
- /**
23
- * Custom hook to generate chart options.
24
- * @function
25
- * @param {Object} chartRef - The chart reference.
26
- * @param {Object} state - The chart state.
27
- * @param {Object} options - The chart options.
28
- * @param {Function} dispatch - The dispatch function for state management.
29
- * @param {Array} generatedDatasets - The generated datasets.
30
- * @returns {Object} The chart options object.
31
- */
32
- export const useChartOptions = ({
33
- chartRef,
34
- state,
35
- options,
36
- dispatch,
37
- generatedDatasets,
38
- }) => {
39
- const {
40
- interactions: { onAnimationComplete },
41
- annotations: {
42
- labelAnnotation: {
43
- showLabel,
44
- text,
45
- position,
46
- fontSize,
47
- xOffset,
48
- yOffset,
49
- maxWidth,
50
- lineHeight,
51
- },
52
- },
53
- chartStyling: { layoutPadding },
54
- } = options;
55
-
56
- const {
57
- enableDragPoints,
58
- zoomEnabled,
59
- panEnabled,
60
- lineEnabled,
61
- showAnnotationLineIndex,
62
- legendEnabled,
63
- } = state;
64
-
65
- const [hoveredPoint, setHoveredPoint] = useState(null);
66
- const { legendClick, updateAxesRangesFromChart, onHover } = useChartFunctions(
67
- {
68
- chartRef,
69
- state,
70
- options,
71
- dispatch,
72
- generatedDatasets,
73
- },
74
- );
75
-
76
- const datalabels = getLineChartDataLabels(options);
77
- const tooltip = getLineChartToolTips(options);
78
- const annotation = useMemo(
79
- () => getAnnotation(options, state),
80
- [showAnnotationLineIndex, legendClick],
81
- );
82
- const legend = useMemo(
83
- () => getLegend(options, legendClick, state),
84
- [legendEnabled],
85
- );
86
-
87
- const scales = useMemo(
88
- () => autoScale(options, state, generatedDatasets),
89
- [options, state, generatedDatasets],
90
- );
91
-
92
- const dragData = useMemo(
93
- () => enableDragPoints && getDraggableData(options),
94
- [enableDragPoints, options],
95
- );
96
-
97
- const panOptions = useMemo(
98
- () => ({
99
- enabled: panEnabled,
100
- mode: PanZoomMode.XY,
101
- onPanComplete({ chart }) {
102
- updateAxesRangesFromChart(chart);
103
- },
104
- }),
105
- [panEnabled],
106
- );
107
-
108
- const zoomOptions = useMemo(
109
- () => ({
110
- mode: PanZoomMode.XY,
111
- drag: {
112
- enabled: zoomEnabled,
113
- threshold: 3,
114
- backgroundColor: ZOOM_BOX_BACKGROUND_COLOR,
115
- borderColor: BORDER_COLOR,
116
- borderWidth: 1,
117
- },
118
- onZoomComplete({ chart }) {
119
- updateAxesRangesFromChart(chart);
120
- },
121
- }),
122
- [zoomEnabled],
123
- );
124
-
125
- const plugins = {
126
- datalabels,
127
- annotation,
128
- zoom: { pan: panOptions, zoom: zoomOptions },
129
- tooltip,
130
- legend,
131
- [CUSTOM_LEGEND_PLUGIN_NAME]: options.legend.customLegend
132
- .customLegendPlugin && {
133
- containerID: options.legend.customLegend.customLegendContainerID,
134
- },
135
- chartAreaBorder: {
136
- borderColor: BORDER_COLOR,
137
- },
138
- chartAreaText: {
139
- showLabel,
140
- text,
141
- position,
142
- fontSize,
143
- xOffset,
144
- yOffset,
145
- maxWidth,
146
- lineHeight,
147
- },
148
- ...dragData,
149
- };
150
-
151
- return useMemo(
152
- () => ({
153
- layout: {
154
- padding: layoutPadding,
155
- },
156
- onHover: onHover(hoveredPoint, setHoveredPoint),
157
- maintainAspectRatio: options.chartStyling.maintainAspectRatio,
158
- aspectRatio: options.chartStyling.squareAspectRatio ? 1 : null,
159
- animation: options.chartStyling.performanceMode
160
- ? false
161
- : {
162
- duration: ANIMATION_DURATION.FAST,
163
- onComplete: onAnimationComplete,
164
- },
165
- hover: {
166
- mode: ChartHoverMode.Nearest,
167
- intersect: true,
168
- },
169
- elements: {
170
- line: {
171
- pointStyle: PointStyle.Circle,
172
- showLine: lineEnabled,
173
- },
174
- },
175
- scales,
176
- plugins,
177
- events: Events,
178
- }),
179
- [state, options],
180
- );
181
- };
@@ -1,35 +0,0 @@
1
- import { useCallback, useMemo } from 'react';
2
- import { debounce } from 'lodash';
3
- import { getPlugins } from '../../../helpers/chart-utils';
4
- import { DOUBLE_CLICK } from '../constants/line-chart-consts';
5
-
6
- export const useChartPlugins = ({ options, resetZoom }) => {
7
- const { graph, legend } = options;
8
-
9
- const debouncedResetZoom = useCallback(
10
- debounce(() => {
11
- resetZoom();
12
- }, 100), // 300ms debounce delay
13
- [resetZoom],
14
- );
15
-
16
- const handleDoubleClick = useCallback(
17
- (chart, args) => {
18
- const { event } = args;
19
- if (event.type === DOUBLE_CLICK) {
20
- debouncedResetZoom();
21
- }
22
- },
23
- [debouncedResetZoom],
24
- );
25
-
26
- return useMemo(() => {
27
- return [
28
- ...getPlugins(graph, legend),
29
- {
30
- id: 'customEventCatcher',
31
- beforeEvent: handleDoubleClick,
32
- },
33
- ];
34
- }, [handleDoubleClick]);
35
- };
@@ -1,33 +0,0 @@
1
- import { useCallback } from 'react';
2
- import {
3
- DISABLE_DRAG_OPTIONS,
4
- TOGGLE_DRAG_POINTS,
5
- TOGGLE_LEGEND,
6
- TOGGLE_LINE,
7
- TOGGLE_PAN,
8
- TOGGLE_POINTS,
9
- TOGGLE_TABLE,
10
- TOGGLE_ZOOM,
11
- } from '../state/action-types';
12
-
13
- export const useToggleHandlers = (dispatch) => {
14
- const createToggleHandler = useCallback(
15
- (type) => () => {
16
- dispatch({ type });
17
- },
18
- [dispatch],
19
- );
20
-
21
- const toggleHandlers = {
22
- onToggleLegend: createToggleHandler(TOGGLE_LEGEND),
23
- onToggleLine: createToggleHandler(TOGGLE_LINE),
24
- onTogglePan: createToggleHandler(TOGGLE_PAN),
25
- onTogglePoints: createToggleHandler(TOGGLE_POINTS),
26
- onToggleTable: createToggleHandler(TOGGLE_TABLE),
27
- onToggleZoom: createToggleHandler(TOGGLE_ZOOM),
28
- onToggleDragPoints: createToggleHandler(TOGGLE_DRAG_POINTS),
29
- onDisableDragOptions: createToggleHandler(DISABLE_DRAG_OPTIONS),
30
- };
31
-
32
- return toggleHandlers;
33
- };
@@ -1,23 +0,0 @@
1
- import { INIT_KEYS } from '../constants/line-chart-consts';
2
- import { getTranslations } from '../utils/translations/get-translations';
3
-
4
- const config = {
5
- [INIT_KEYS.TRANSLATIONS]: getTranslations(),
6
- [INIT_KEYS.LANGUAGE_KEY]: 'en',
7
- };
8
-
9
- /**
10
- * Retrieve the value for the given key from the config object.
11
- * @param {string} key - The key to access the corresponding value in the config object.
12
- * @returns {*} - The value associated with the given key in the config object or config.
13
- */
14
- export const getConfig = (key) => (key ? config[key] : config);
15
-
16
- /**
17
- * Set a new value for the given key in the config object.
18
- * @param {string} key - The key to access the corresponding value in the config object.
19
- * @param {*} newValue - The new value to be set for the given key.
20
- */
21
- export const setConfig = (key, newValue) => {
22
- config[key] = newValue;
23
- };
@@ -1,25 +0,0 @@
1
- import { INIT_KEYS } from '../constants/line-chart-consts';
2
- import { setConfig } from './config';
3
- import { getTranslations } from '../utils/translations/get-translations';
4
- import { isPrimitiveValue } from '../utils/line-chart-utils';
5
-
6
- /**
7
- * Initialize the charts library with the provided configurations.
8
- * This function will store the configuration options in a config object.
9
- * @param {object} options - An object containing the configuration options for the library.
10
- * @param {object} options.translations - The translations to be used in the library.
11
- * @param {string} options.languageKey - The language key to be stored in the config object, used for translations.
12
- * @param {...object} options - Any additional options to be stored in the config object.
13
- */
14
- export const initializeLineChart = ({ languageKey = 'en', ...options }) => {
15
- setConfig(INIT_KEYS.LANGUAGE_KEY, languageKey);
16
-
17
- Object.entries(options).forEach(([key, value]) => {
18
- if (key === INIT_KEYS.TRANSLATIONS) {
19
- setConfig(key, getTranslations(value));
20
- } else {
21
- const newValue = isPrimitiveValue(value) ? value : { ...value };
22
- setConfig(key, newValue);
23
- }
24
- });
25
- };