@oliasoft-open-source/charts-library 3.3.6-beta-5 → 3.3.7

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