@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,292 +0,0 @@
1
- import PropTypes from 'prop-types';
2
- import { TextLabelPosition } from './plugins/plugin-constants';
3
-
4
- export const LineChartPropTypes = {
5
- table: PropTypes.node,
6
- chart: PropTypes.shape({
7
- persistenceId: PropTypes.string,
8
- testId: PropTypes.string,
9
- data: PropTypes.object.isRequired,
10
- options: PropTypes.shape({
11
- title: PropTypes.oneOfType([
12
- PropTypes.string,
13
- PropTypes.arrayOf(PropTypes.string),
14
- ]),
15
- axes: PropTypes.shape({
16
- x: PropTypes.arrayOf(
17
- PropTypes.shape({
18
- label: PropTypes.string,
19
- position: PropTypes.oneOf(['top', 'bottom']),
20
- color: PropTypes.string,
21
- unit: PropTypes.shape({
22
- options: PropTypes.arrayOf(PropTypes.string),
23
- selectedUnit: PropTypes.string,
24
- setSelectedUnit: PropTypes.func,
25
- }),
26
- }),
27
- ),
28
- y: PropTypes.arrayOf(
29
- PropTypes.shape({
30
- label: PropTypes.string,
31
- position: PropTypes.oneOf(['left', 'right']),
32
- color: PropTypes.string,
33
- }),
34
- ),
35
- }),
36
- additionalAxesOptions: PropTypes.shape({
37
- chartScaleType: PropTypes.oneOf(['linear', 'logarithmic']),
38
- reverse: PropTypes.bool,
39
- beginAtZero: PropTypes.bool,
40
- stepSize: PropTypes.number,
41
- truncateAxisNumbersToDigitsCallback: PropTypes.number,
42
- suggestedMin: PropTypes.number,
43
- suggestedMax: PropTypes.number,
44
- range: PropTypes.shape({
45
- x: PropTypes.shape({
46
- min: PropTypes.number,
47
- max: PropTypes.number,
48
- }),
49
- y: PropTypes.shape({
50
- min: PropTypes.number,
51
- max: PropTypes.number,
52
- }),
53
- }),
54
- autoAxisPadding: PropTypes.bool,
55
- }),
56
- chartStyling: PropTypes.shape({
57
- width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
58
- height: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
59
- maintainAspectRatio: PropTypes.bool,
60
- staticChartHeight: PropTypes.bool,
61
- performanceMode: PropTypes.bool,
62
- squareAspectRatio: PropTypes.bool,
63
- layoutPadding: PropTypes.oneOfType([
64
- PropTypes.number,
65
- PropTypes.shape({
66
- top: PropTypes.number,
67
- bottom: PropTypes.number,
68
- left: PropTypes.number,
69
- right: PropTypes.number,
70
- }),
71
- ]),
72
- }),
73
- tooltip: PropTypes.shape({
74
- tooltips: PropTypes.bool,
75
- showLabelsInTooltips: PropTypes.bool,
76
- hideSimulationName: PropTypes.bool,
77
- }),
78
- graph: PropTypes.shape({
79
- lineTension: PropTypes.number,
80
- spanGaps: PropTypes.bool,
81
- showDataLabels: PropTypes.bool,
82
- showMinorGridlines: PropTypes.bool,
83
- }),
84
- annotations: PropTypes.shape({
85
- labelAnnotation: PropTypes.shape({
86
- showLabel: PropTypes.bool,
87
- text: PropTypes.oneOfType([
88
- PropTypes.string,
89
- PropTypes.arrayOf(PropTypes.string),
90
- ]),
91
- position: PropTypes.string,
92
- fontSize: PropTypes.number,
93
- xOffset: PropTypes.number,
94
- yOffset: PropTypes.number,
95
- maxWidth: PropTypes.number,
96
- lineHeight: PropTypes.number,
97
- }),
98
- showAnnotations: PropTypes.bool,
99
- controlAnnotation: PropTypes.bool,
100
- annotationsData: PropTypes.arrayOf(
101
- PropTypes.shape({
102
- adjustScaleRange: PropTypes.bool,
103
- annotationAxis: PropTypes.oneOf(['x', 'y']),
104
- color: PropTypes.string,
105
- endValue: PropTypes.number,
106
- label: PropTypes.string,
107
- type: PropTypes.string,
108
- value: PropTypes.number,
109
- xMin: PropTypes.number,
110
- xMax: PropTypes.number,
111
- yMin: PropTypes.number,
112
- yMax: PropTypes.number,
113
- }),
114
- ),
115
- }),
116
- legend: PropTypes.shape({
117
- display: PropTypes.bool,
118
- position: PropTypes.oneOf(['top', 'bottom', 'right', 'left']),
119
- align: PropTypes.oneOf(['start', 'center', 'end']),
120
- customLegend: PropTypes.shape({
121
- customLegendPlugin: PropTypes.object,
122
- customLegendContainerID: PropTypes.string,
123
- }),
124
- }),
125
- chartOptions: PropTypes.shape({
126
- showPoints: PropTypes.bool,
127
- enableZoom: PropTypes.bool,
128
- enablePan: PropTypes.bool,
129
- closeOnOutsideClick: PropTypes.bool,
130
- }),
131
- interactions: PropTypes.shape({
132
- onLegendClick: PropTypes.func,
133
- onPointHover: PropTypes.func,
134
- onPointUnhover: PropTypes.func,
135
- onAnimationComplete: PropTypes.func,
136
- }),
137
- depthType: PropTypes.shape({
138
- options: PropTypes.arrayOf(PropTypes.string),
139
- selectedDepthType: PropTypes.string,
140
- setSelectedDepthType: PropTypes.func,
141
- }),
142
- dragData: PropTypes.shape({
143
- enableDragData: PropTypes.bool,
144
- showTooltip: PropTypes.bool,
145
- roundPoints: PropTypes.bool,
146
- dragX: PropTypes.bool,
147
- dragY: PropTypes.bool,
148
- onDragStart: PropTypes.func,
149
- onDrag: PropTypes.func,
150
- onDragEnd: PropTypes.func,
151
- }),
152
- }),
153
- }).isRequired,
154
- };
155
-
156
- export const getDefaultProps = (props) => {
157
- // Add missing nested objects
158
- props.chart.options = props.chart.options || {};
159
- props.chart.options.axes = props.chart.options.axes || {};
160
- props.chart.options.additionalAxesOptions =
161
- props.chart.options.additionalAxesOptions || {};
162
- props.chart.options.chartStyling = props.chart.options.chartStyling || {};
163
- props.chart.options.tooltip = props.chart.options.tooltip || {};
164
- props.chart.options.graph = props.chart.options.graph || {};
165
- props.chart.options.annotations = props.chart.options.annotations || {};
166
- props.chart.options.legend = props.chart.options.legend || {};
167
- props.chart.options.legend.customLegend = props.chart.options.legend
168
- .customLegend || { customLegendPlugin: null, customLegendContainerID: '' };
169
- props.chart.options.chartOptions = props.chart.options.chartOptions || {};
170
- props.chart.options.interactions = props.chart.options.interactions || {};
171
- props.chart.options.dragData = props.chart.options.dragData || {};
172
- // Set defaults for missing properties
173
- const chart = {
174
- persistenceId: props.chart.persistenceId ?? '',
175
- testId: props.chart.testId ?? null,
176
- data: props.chart.data,
177
- options: {
178
- title: props.chart.options.title || '',
179
- axes: {
180
- x: props.chart.options.axes.x || [{}],
181
- y: props.chart.options.axes.y || [{}],
182
- },
183
- additionalAxesOptions: {
184
- chartScaleType:
185
- props.chart.options.additionalAxesOptions.chartScaleType || 'linear',
186
- reverse: props.chart.options.additionalAxesOptions.reverse || false,
187
- beginAtZero:
188
- props.chart.options.additionalAxesOptions.beginAtZero || false,
189
- stepSize: props.chart.options.additionalAxesOptions.stepSize,
190
- truncateAxisNumbersToDigitsCallback:
191
- props.chart.options.additionalAxesOptions
192
- .truncateAxisNumbersToDigitsCallback,
193
- suggestedMin: props.chart.options.additionalAxesOptions.suggestedMin,
194
- suggestedMax: props.chart.options.additionalAxesOptions.suggestedMax,
195
- range: props.chart.options.additionalAxesOptions.range,
196
- autoAxisPadding:
197
- props.chart.options.additionalAxesOptions.autoAxisPadding ?? false,
198
- },
199
- chartStyling: {
200
- width: props.chart.options.chartStyling.width,
201
- height: props.chart.options.chartStyling.height,
202
- maintainAspectRatio:
203
- props.chart.options.chartStyling.maintainAspectRatio || false,
204
- staticChartHeight:
205
- props.chart.options.chartStyling.staticChartHeight || false,
206
- performanceMode:
207
- props.chart.options.chartStyling.performanceMode ?? true,
208
- squareAspectRatio:
209
- props.chart.options.chartStyling.squareAspectRatio || false,
210
- layoutPadding: props.chart.options.chartStyling.layoutPadding || {
211
- top: 0,
212
- bottom: 20,
213
- left: 0,
214
- right: 0,
215
- },
216
- },
217
- tooltip: {
218
- tooltips: props.chart.options.tooltip.tooltips ?? true,
219
- showLabelsInTooltips:
220
- props.chart.options.tooltip.showLabelsInTooltips || false,
221
- hideSimulationName:
222
- props.chart.options.tooltip.hideSimulationName || false,
223
- },
224
- graph: {
225
- lineTension: props.chart.options.graph.lineTension || 0.01,
226
- spanGaps: props.chart.options.graph.spanGaps || false,
227
- showDataLabels: props.chart.options.graph.showDataLabels || false,
228
- showMinorGridlines:
229
- props.chart.options.graph.showMinorGridlines || false,
230
- },
231
- annotations: {
232
- labelAnnotation: {
233
- showLabel:
234
- props.chart.options.annotations.labelAnnotation?.showLabel ?? false,
235
- text: props.chart.options.annotations.labelAnnotation?.text ?? '',
236
- position:
237
- props.chart.options.annotations.labelAnnotation?.position ??
238
- TextLabelPosition.BOTTOM_RIGHT,
239
- fontSize:
240
- props.chart.options.annotations.labelAnnotation?.fontSize ?? 12,
241
- xOffset:
242
- props.chart.options.annotations.labelAnnotation?.xOffset ?? 5,
243
- yOffset:
244
- props.chart.options.annotations.labelAnnotation?.yOffset ?? 5,
245
- maxWidth:
246
- props.chart.options.annotations.labelAnnotation?.maxWidth ?? 300,
247
- lineHeight:
248
- props.chart.options.annotations.labelAnnotation?.lineHeight ?? 12,
249
- },
250
- showAnnotations:
251
- props.chart.options.annotations.showAnnotations ?? false,
252
- controlAnnotation:
253
- props.chart.options.annotations.controlAnnotation || false,
254
- annotationsData: props.chart.options.annotations.annotationsData || [],
255
- },
256
- legend: {
257
- display: props.chart.options.legend.display ?? true,
258
- position: props.chart.options.legend.position || 'bottom',
259
- align: props.chart.options.legend.align || 'center',
260
- customLegend: props.chart.options.legend.customLegend,
261
- usePointStyle: props.chart.options.legend.usePointStyle ?? true,
262
- },
263
- chartOptions: {
264
- showPoints: props.chart.options.chartOptions.showPoints ?? true,
265
- enableZoom: props.chart.options.chartOptions.enableZoom || true,
266
- enablePan: props.chart.options.chartOptions.enablePan || false,
267
- showLine: props.chart.options.chartOptions.showLine ?? true,
268
- closeOnOutsideClick:
269
- props.chart.options.chartOptions.closeOnOutsideClick || false,
270
- },
271
- interactions: {
272
- onLegendClick: props.chart.options.interactions.onLegendClick,
273
- onPointHover: props.chart.options.interactions.onPointHover,
274
- onPointUnhover: props.chart.options.interactions.onPointUnhover,
275
- onAnimationComplete:
276
- props.chart.options.interactions.onAnimationComplete,
277
- },
278
- depthType: props.chart.options.depthType,
279
- dragData: {
280
- enableDragData: props.chart.options.dragData.enableDragData || false,
281
- showTooltip: props.chart.options.dragData.showTooltip || true,
282
- roundPoints: props.chart.options.dragData.roundPoints || true,
283
- dragX: props.chart.options.dragData.dragX || true,
284
- dragY: props.chart.options.dragData.dragY || true,
285
- onDragStart: props.chart.options.dragData.onDragStart,
286
- onDrag: props.chart.options.dragData.onDrag,
287
- onDragEnd: props.chart.options.dragData.onDragEnd,
288
- },
289
- },
290
- };
291
- return chart;
292
- };
@@ -1,121 +0,0 @@
1
- import {
2
- IChartAnnotations, IChartDraggableData,
3
- IChartInteractions,
4
- IChartLegend,
5
- IChartStyling,
6
- } from "../../helpers/chart-interface";
7
-
8
- export interface IChartOptions {
9
- showPoints: boolean;
10
- enableZoom: boolean;
11
- enablePan: boolean;
12
- closeOnOutsideClick: boolean;
13
- }
14
-
15
- export interface ILineChartGraph {
16
- lineTension: number;
17
- spanGaps: boolean;
18
- showDataLabels: boolean;
19
- showMinorGridlines: boolean;
20
- }
21
-
22
- export interface ILineChartTooltip {
23
- tooltips: boolean;
24
- showLabelsInTooltips: boolean;
25
- hideSimulationName: boolean;
26
- }
27
-
28
-
29
- export interface IChartRange {
30
- min: number;
31
- max: number;
32
- }
33
-
34
- export interface ILineChartAdditionalAxesOptions {
35
- chartScaleType: 'linear' | 'logarithmic';
36
- reverse: boolean;
37
- beginAtZero: boolean;
38
- stepSize: number;
39
- truncateAxisNumbersToDigitsCallback: number;
40
- suggestedMin: number;
41
- suggestedMax:number;
42
- range: {
43
- x: IChartRange;
44
- y: IChartRange;
45
- };
46
- autoAxisPadding: boolean;
47
- }
48
-
49
- export interface IUnitOptions {
50
- options: string[],
51
- selectedUnit: string,
52
- setSelectedUnit: () => void,
53
- }
54
-
55
- export interface ILineChartAxis<PositionType> {
56
- label: string;
57
- position: PositionType;
58
- color: string;
59
- unit: IUnitOptions
60
- }
61
-
62
- export interface ILineChartAxes {
63
- x: ILineChartAxis<'top' | 'bottom'>[];
64
- y: ILineChartAxis<'left' | 'right'>[];
65
- }
66
-
67
- export interface IDepthType {
68
- options: string[],
69
- selectedUnit: string,
70
- setSelectedUnit: () => void,
71
- }
72
- export interface ILineChartOptions {
73
- title: string | string[];
74
- axes: ILineChartAxes;
75
- additionalAxesOptions: ILineChartAdditionalAxesOptions;
76
- chartStyling: IChartStyling;
77
- tooltip: ILineChartTooltip;
78
- graph: ILineChartGraph;
79
- annotations: IChartAnnotations;
80
- legend: IChartLegend;
81
- chartOptions: IChartOptions;
82
- interactions: IChartInteractions;
83
- depthType: IDepthType
84
- draggableData :IChartDraggableData;
85
- }
86
-
87
- export interface IDataPoint {
88
- x: number,
89
- y: number,
90
- label?: string[]
91
- }
92
-
93
- export interface ILineChartDataset {
94
- label?: string,
95
- lineTension?: number,
96
- borderColor?: string,
97
- pointBackgroundColor?: string,
98
- backgroundColor?: string,
99
- pointRadius?: number,
100
- pointHoverRadius?: number,
101
- pointHitRadius?: number,
102
- borderWidth?: number,
103
- fill?: boolean,
104
- yAxisID?: string,
105
- formation?: boolean,
106
- data: IDataPoint[],
107
- }
108
-
109
- export interface ILineChartData {
110
- //TODO: revisit data interface definition after project is more stable
111
- testId: string | null;
112
- data: {
113
- labels?: string[],
114
- datasets: ILineChartDataset[]
115
- } | any;
116
- options: ILineChartOptions;
117
- }
118
-
119
- export interface ILineChartProps {
120
- chart: ILineChartData;
121
- }
@@ -1,161 +0,0 @@
1
- import React, { useMemo, useReducer, useRef } from 'react';
2
- import {
3
- CategoryScale,
4
- Chart as ChartJS,
5
- Filler,
6
- Legend,
7
- LinearScale,
8
- LineElement,
9
- LogarithmicScale,
10
- PointElement,
11
- Title,
12
- Tooltip,
13
- } from 'chart.js';
14
- import { Line } from 'react-chartjs-2';
15
- import zoomPlugin from 'chartjs-plugin-zoom';
16
- import dataLabelsPlugin from 'chartjs-plugin-datalabels';
17
- import annotationPlugin from 'chartjs-plugin-annotation';
18
- import dragDataPlugin from 'chartjs-plugin-dragdata';
19
- import styles from './line-chart.module.less';
20
- import { reducer } from './state/line-chart-reducer';
21
- import initialState from './state/initial-state';
22
- import Controls from './controls/controls';
23
- import { getDefaultProps, LineChartPropTypes } from './line-chart-prop-types';
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 { chartAreaTextPlugin } from './plugins/chart-area-text-plugin';
33
- import { getConfig } from './initialize/config';
34
-
35
- ChartJS.register(
36
- LinearScale,
37
- PointElement,
38
- LineElement,
39
- CategoryScale,
40
- LogarithmicScale,
41
- Legend,
42
- Tooltip,
43
- Title,
44
- Filler,
45
- zoomPlugin,
46
- dataLabelsPlugin,
47
- annotationPlugin,
48
- dragDataPlugin,
49
- chartAreaTextPlugin,
50
- );
51
-
52
- /**
53
- * this is a line chart component
54
- * @param {import('./line-chart.interface').ILineChartProps} props
55
- */
56
- const LineChart = (props) => {
57
- setDefaultTheme();
58
- const chartRef = useRef(null);
59
- const { table } = props;
60
- const { translations, languageKey } = getConfig();
61
- const chart = getDefaultProps(props);
62
- const {
63
- data: { datasets },
64
- options,
65
- testId,
66
- persistenceId,
67
- } = chart;
68
- const { annotations, axes, chartStyling, graph } = options;
69
-
70
- /**
71
- * @type {[object, import('react').Dispatch<{type: String, payload: any}>]} useReducer
72
- */
73
- const [state, dispatch] = useReducer(
74
- reducer,
75
- {
76
- options,
77
- persistenceId,
78
- },
79
- initialState,
80
- );
81
-
82
- const generatedDatasets = useMemo(() => {
83
- return generateLineChartDatasets(datasets, state, options, translations);
84
- }, [state.lineEnabled, state.pointsEnabled, axes, annotations, graph]);
85
-
86
- // Call the custom hooks.
87
- useChartState({
88
- chartRef,
89
- options,
90
- state,
91
- generatedDatasets,
92
- dispatch,
93
- persistenceId,
94
- });
95
-
96
- const { resetZoom, handleKeyDown, handleKeyUp } = useChartFunctions({
97
- chartRef,
98
- state,
99
- options,
100
- dispatch,
101
- generatedDatasets,
102
- });
103
-
104
- const useOptions = useChartOptions({
105
- chartRef,
106
- state,
107
- options,
108
- dispatch,
109
- generatedDatasets,
110
- });
111
-
112
- const usePlugins = useChartPlugins({ options, resetZoom });
113
-
114
- return (
115
- <div
116
- key={generateKey([
117
- state.enableDragPoints,
118
- state.zoomEnabled,
119
- state.panEnabled,
120
- languageKey,
121
- ])}
122
- className={getClassName(chartStyling, styles)}
123
- style={{
124
- width: chartStyling.width || AUTO,
125
- height: chartStyling.height || AUTO,
126
- }}
127
- tabIndex={0} //eslint-disable-line jsx-a11y/no-noninteractive-tabindex
128
- onKeyDown={handleKeyDown}
129
- onKeyUp={handleKeyUp}
130
- data-testid={testId}
131
- >
132
- <Controls
133
- props={props}
134
- chartRef={chartRef}
135
- state={state}
136
- options={options}
137
- dispatch={dispatch}
138
- generatedDatasets={generatedDatasets}
139
- translations={translations}
140
- />
141
- {table && state.showTable ? (
142
- <div className={styles.table}>{table}</div>
143
- ) : (
144
- <div className={styles.canvas}>
145
- <Line
146
- ref={chartRef}
147
- data={{
148
- datasets: generatedDatasets,
149
- }}
150
- options={useOptions}
151
- plugins={usePlugins}
152
- />
153
- </div>
154
- )}
155
- </div>
156
- );
157
- };
158
-
159
- LineChart.propTypes = LineChartPropTypes;
160
-
161
- export { LineChart };
@@ -1,77 +0,0 @@
1
- html[data-theme='dark'] .chart canvas {
2
- // Flip chart colors if dark mode enabled
3
- filter: invert(1) hue-rotate(180deg);
4
- }
5
-
6
- .chart {
7
- border: 1px solid rgba(255, 255, 255, 0);
8
- position: relative;
9
- display: flex;
10
- flex-direction: column;
11
- gap: 8px; // Spacing between each section
12
-
13
- .canvas {
14
- flex-grow: 1;
15
- min-height: 0; // Prevents chart exceeding available space
16
- canvas {
17
- width: 100% !important; // Fix for resizing bug
18
- height: 100% !important; // Remove if stretched when maintainAspectRatio=true
19
- }
20
- }
21
-
22
- &.fixedHeight {
23
- display: flex;
24
- align-items: flex-start;
25
- justify-content: flex-start;
26
- height: auto;
27
- }
28
-
29
- &.stretchHeight {
30
- display: flex;
31
- align-items: stretch;
32
- justify-content: stretch;
33
- height: 100%;
34
- }
35
-
36
- &.squareAspectRatio {
37
- aspect-ratio: 1;
38
- min-height: 0;
39
- min-width: 0;
40
- }
41
-
42
- &:focus {
43
- // border: 1px solid #85b7d9;
44
- outline: none; // Remove dotted outline on FF
45
- }
46
-
47
- &::-moz-focus-inner {
48
- border: 0; // Remove dotted outline on FF
49
- }
50
- }
51
-
52
- .zoomForm {
53
- position: absolute;
54
- display: flex;
55
- align-items: center;
56
- justify-content: center;
57
- top: 0;
58
- right: 0;
59
-
60
- .zoomReset {
61
- margin-left: 10px;
62
- }
63
-
64
- .help {
65
- margin-left: 5px;
66
- line-height: 0; // Strip whitespace from icon
67
- }
68
- }
69
-
70
- .autoWeight {
71
- width: auto;
72
- height: auto;
73
- }
74
-
75
- .table {
76
- overflow: auto;
77
- }