@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,141 +0,0 @@
1
- import { useCallback, useEffect, useMemo, useRef } from 'react';
2
- import { isEqual } from 'lodash';
3
- import { storeChartStateInStorage } from './manage-state-in-local-storage';
4
- import { SAVE_INITIAL_AXES_RANGES, UPDATE_AXES_RANGES } from './action-types';
5
- import { getAxesRangesFromChart } from '../utils/get-axes-ranges-from-chart';
6
-
7
- /**
8
- * Hook for toggling the visibility of the custom legend.
9
- *
10
- * @param memoState - The memoized state object.
11
- * @param memoOptions - The memoized options object.
12
- */
13
- const useToggleCustomLegendVisibility = (memoState, memoOptions) => {
14
- useEffect(() => {
15
- if (memoOptions.legend.customLegend.customLegendPlugin) {
16
- // Get the parent element of the custom legend container and toggle its visibility based on the state.
17
- const parent = document.getElementById(
18
- memoOptions.legend.customLegend.customLegendContainerID,
19
- );
20
- parent.style.visibility = memoState.legendEnabled ? 'visible' : 'hidden';
21
- }
22
- }, [
23
- memoOptions.legend.customLegend.customLegendPlugin,
24
- memoState.legendEnabled,
25
- ]);
26
- };
27
-
28
- /**
29
- * Hook for storing the chart state in local storage.
30
- *
31
- * @param memoState - The memoized state object.
32
- * @param persistenceId - The chart persistenceId.
33
- */
34
- const useStoreChartStateInStorage = (memoState, persistenceId) => {
35
- useEffect(() => {
36
- // Store the chart state in local storage.
37
- storeChartStateInStorage(memoState, persistenceId);
38
- }, [
39
- memoState.panEnabled,
40
- memoState.lineEnabled,
41
- memoState.pointsEnabled,
42
- memoState.legendEnabled,
43
- memoState.enableDragPoints,
44
- memoState.zoomEnabled,
45
- ]);
46
- };
47
-
48
- /**
49
- * Hook for updating the axes ranges in the chart state.
50
- *
51
- * @param range - The range to the chart.
52
- * @param dispatch - The dispatch function for state management.
53
- */
54
- const useUpdateAxesRanges = (range, dispatch) => {
55
- const prevRange = useRef();
56
-
57
- const updateAxesRanges = useCallback(() => {
58
- if (range && range.x && range.y && !isEqual(range, prevRange.current)) {
59
- const axes = Object.entries(range).map(([key, { min, max }]) => ({
60
- id: key,
61
- min: min ?? 0,
62
- max: max ?? 0,
63
- }));
64
- dispatch({
65
- type: UPDATE_AXES_RANGES,
66
- payload: { axes },
67
- });
68
- prevRange.current = range;
69
- }
70
- }, [range]);
71
-
72
- useEffect(() => {
73
- updateAxesRanges();
74
- }, [updateAxesRanges]);
75
- };
76
-
77
- /**
78
- * A custom hook to save the initial axes ranges of a chart when the generated datasets change.
79
- *
80
- * @param {Object} chartRef - A reference to the chart object.
81
- * @param {Array} axes - An array of axes configurations.
82
- * @param {Array} generatedDatasets - An array of generated datasets for the chart.
83
- * @param {Function} dispatch - A dispatch function from the useContext hook for managing the state.
84
- */
85
- const useSaveInitialAxesRanges = (
86
- chartRef,
87
- axes,
88
- generatedDatasets,
89
- dispatch,
90
- ) => {
91
- const prevGeneratedDatasets = useRef();
92
-
93
- const saveInitialAxesRanges = useCallback(() => {
94
- if (
95
- chartRef &&
96
- !isEqual(generatedDatasets, prevGeneratedDatasets.current)
97
- ) {
98
- const initialAxesRanges = getAxesRangesFromChart(chartRef, axes);
99
- dispatch({
100
- type: SAVE_INITIAL_AXES_RANGES,
101
- payload: { initialAxesRanges },
102
- });
103
- prevGeneratedDatasets.current = generatedDatasets;
104
- }
105
- }, [chartRef, generatedDatasets]);
106
-
107
- useEffect(() => {
108
- saveInitialAxesRanges();
109
- }, [saveInitialAxesRanges, generatedDatasets]);
110
- };
111
-
112
- /**
113
- * Hook for managing the state of the chart.
114
- *
115
- * @param chartRef - The reference to the chart.
116
- * @param options - The chart options.
117
- * @param state - The chart state.
118
- * @param {Array} generatedDatasets - An array of generated datasets for the chart.
119
- * @param dispatch - The dispatch function for state management.
120
- * @param persistenceId - The chart persistenceId.
121
- */
122
- export const useChartState = ({
123
- chartRef,
124
- options,
125
- state,
126
- generatedDatasets,
127
- dispatch,
128
- persistenceId,
129
- }) => {
130
- const memoState = useMemo(() => state, [state]);
131
- const memoOptions = useMemo(() => options, [options]);
132
- const {
133
- additionalAxesOptions: { range },
134
- axes,
135
- } = memoOptions;
136
-
137
- useStoreChartStateInStorage(memoState, persistenceId);
138
- useToggleCustomLegendVisibility(memoState, memoOptions);
139
- useUpdateAxesRanges(range, dispatch);
140
- useSaveInitialAxesRanges(chartRef, axes, generatedDatasets, dispatch);
141
- };
@@ -1,165 +0,0 @@
1
- import getLineChartScales from '../get-line-chart-scales';
2
- import { AxisType } from '../../../../helpers/enums';
3
- import { getAxisTypeFromKey } from '../line-chart-utils';
4
- import { estimateDataSeriesHaveCloseValues } from '../../../../helpers/range/estimate-data-series-have-close-values';
5
- import { getSuggestedAxisRange } from '../../../../helpers/range/range';
6
-
7
- /**
8
- Function that counts the number of occurences of "x" and "y" in an array and returns the one with the highest count.
9
- @param {Array} scalesKeys - An array of strings that may contain "x" or "y".
10
- @return {string} - Returns "x" if "x" occurs more times, "y" if "y" occurs more times, or null if they occur the same number of times.
11
- */
12
- const checkMultiAxis = (scalesKeys) => {
13
- let counts = {
14
- x: 0,
15
- y: 0,
16
- };
17
-
18
- scalesKeys.forEach((axeKey) => {
19
- const key = getAxisTypeFromKey(axeKey);
20
- counts[key]++;
21
- });
22
- const res =
23
- (counts.x > counts.y && AxisType.X) ||
24
- (counts.y > counts.x && AxisType.Y) ||
25
- (counts.x === counts.y && null);
26
-
27
- return res;
28
- };
29
-
30
- /**
31
- Function that returns an object containing all the values for a specific key in an array of objects,
32
- grouped by the unique values of another key in the same objects.
33
- @param {Array} data - An array of objects to search for the keys.
34
- @return {Object} - Returns an object with keys representing the unique values for the annotationAxis key in the data array,
35
- and values representing an array of all values for the value key in the data array.
36
- */
37
- const getAnnotationsData = (data) => {
38
- return data.reduce((acc, obj) => {
39
- return {
40
- ...acc,
41
- [obj.annotationAxis]: [...(acc[obj.annotationAxis] || []), obj.value],
42
- };
43
- }, {});
44
- };
45
-
46
- /**
47
- * return data for each axes
48
- * @function getAxesData
49
- * @return {object}
50
- */
51
- const getAxesData = (scalesKeys, datasets, annotationsData) => {
52
- const allData =
53
- datasets?.reduce((acc, item) => [...acc, ...item.data], []) ?? [];
54
-
55
- /**
56
- * return data by key and depends on axes count
57
- * @function getData
58
- * @return {object}
59
- */
60
- const getData = () => {
61
- return scalesKeys.reduce((acc, axeKey) => {
62
- const key = getAxisTypeFromKey(axeKey);
63
- const data = getAnnotationsData(annotationsData);
64
- const formData = allData
65
- ?.map((val) => val?.[key])
66
- .concat(data[key] || []);
67
-
68
- return {
69
- ...acc,
70
- [axeKey]: [...new Set(formData)],
71
- };
72
- }, {});
73
- };
74
-
75
- /**
76
- Function that returns an object containing the unique values for a multi axis key in an array of objects.
77
- @return {Object} - Returns an object with key representing the found key in the scalesKeys array,
78
- and values representing an array of unique values for that key in the datasets array. If no key is found, an empty object is returned.
79
- */
80
- const getDataForMultiAxes = () => {
81
- const multiAxesKey = checkMultiAxis(scalesKeys);
82
- const axes = scalesKeys?.filter((key) => key?.includes(multiAxesKey)) ?? [];
83
- const data = getAnnotationsData(annotationsData);
84
- const [first, second] = axes;
85
-
86
- /**
87
- * Reduces an array of objects and returns an array of values from the specified key
88
- * @param {Array} arr - The array of objects to be reduced
89
- * @param {string} key - The key to extract the values from
90
- * @returns {Array} - An array of values from the specified key
91
- */
92
- const reduceData = (arr, key) =>
93
- arr.reduce((acc, { [key]: value }) => [...acc, value], []);
94
-
95
- return datasets.reduce(
96
- (acc, obj) => {
97
- const include = Object.values(obj).some((val) => axes.includes(val));
98
- const key = include ? second : first;
99
-
100
- return {
101
- ...acc,
102
- [key]: [
103
- ...new Set([
104
- ...acc[key],
105
- ...reduceData(obj?.data, multiAxesKey),
106
- ...((!include && data?.[multiAxesKey]) || []),
107
- ]),
108
- ],
109
- };
110
- },
111
- { [first]: [], [second]: [] },
112
- );
113
- };
114
-
115
- return {
116
- ...getData(),
117
- ...getDataForMultiAxes(),
118
- };
119
- };
120
-
121
- /**
122
- * Auto scales axis ranges (mix, max) if no explicit range is set
123
- * - overrides some edge cases not handled well by default chart.js
124
- * - supports optional padding when `autoAxisPadding` is set
125
- * - otherwise does not set min/max (falls back to chart.js default)
126
- *
127
- * @function autoScale
128
- * @return {object} scales
129
- */
130
- export const autoScale = (options, state, generatedDatasets) => {
131
- const { additionalAxesOptions = {}, annotations = {} } = options || {};
132
- const { annotationsData = [] } = annotations || {};
133
- const scales = getLineChartScales(options, state) || {};
134
-
135
- if (
136
- !additionalAxesOptions?.autoAxisPadding &&
137
- !estimateDataSeriesHaveCloseValues(generatedDatasets)
138
- ) {
139
- return scales;
140
- }
141
- const scalesKeys = Object.keys(scales) ?? [];
142
- const data =
143
- getAxesData(scalesKeys, generatedDatasets, annotationsData) ?? {};
144
-
145
- const adjustedScales = scalesKeys?.reduce((acc, key) => {
146
- const { min: propMin = undefined, max: propMax = undefined } = scales[key];
147
- const { min, max } = getSuggestedAxisRange({
148
- data: data[key],
149
- beginAtZero: additionalAxesOptions?.beginAtZero,
150
- autoAxisPadding: additionalAxesOptions?.autoAxisPadding,
151
- });
152
-
153
- const res = {
154
- [key]: {
155
- ...scales[key],
156
- min: propMin ?? min,
157
- max: propMax ?? max,
158
- },
159
- };
160
-
161
- return { ...acc, ...res };
162
- }, {});
163
-
164
- return adjustedScales ?? scales;
165
- };
@@ -1,13 +0,0 @@
1
- /** returning boolean condition depends on label position and chart area
2
- *
3
- * @return {object} - returning object with boolean props
4
- */
5
- export const getCondition = (x, y, left, right, bottom) => {
6
- const threshold = 100;
7
- const overLeftSide = x - threshold <= left;
8
- const overRightSide = x + threshold >= right;
9
- const overBottomSide =
10
- x + threshold >= left && x + threshold < right && y + threshold >= bottom;
11
-
12
- return { overLeftSide, overRightSide, overBottomSide };
13
- };
@@ -1,20 +0,0 @@
1
- /** returning destructured data from context
2
- *
3
- * @return {object}
4
- */
5
- export const getAlignmentData = (context) => {
6
- const { chart = {}, dataIndex = 0, datasetIndex = 0 } = context || {};
7
- const { chartArea = {} } = chart;
8
- const { left = null, right = null, bottom = null } = chartArea;
9
-
10
- const meta = chart.getDatasetMeta(datasetIndex);
11
- const { x = null, y = null } = meta?.data?.[dataIndex] || {};
12
-
13
- return {
14
- x,
15
- y,
16
- left,
17
- right,
18
- bottom,
19
- };
20
- };
@@ -1,25 +0,0 @@
1
- import { getCondition } from './get-alignment-condition';
2
- import { getAlignmentData } from './get-alignment-data';
3
- import { AlignOptions } from '../../../../helpers/enums';
4
-
5
- /** returning position depends on condition
6
- *
7
- * @return {string} - position
8
- */
9
- export const getPosition = () => {
10
- return (context) => {
11
- const { x, y, left, right, bottom } = getAlignmentData(context);
12
- const {
13
- overLeftSide = false,
14
- overRightSide = false,
15
- overBottomSide = false,
16
- } = getCondition(x, y, left, right, bottom);
17
-
18
- return (
19
- (overLeftSide && AlignOptions.Right) ||
20
- (overRightSide && AlignOptions.Left) ||
21
- (overBottomSide && AlignOptions.End) ||
22
- AlignOptions.Start
23
- );
24
- };
25
- };
@@ -1,114 +0,0 @@
1
- import { COLORS } from '../../../helpers/chart-consts';
2
- import {
3
- BORDER_JOIN_STYLE,
4
- DEFAULT_BACKGROUND_COLOR,
5
- DEFAULT_BORDER_WIDTH,
6
- DEFAULT_HOVER_RADIUS,
7
- DEFAULT_LINE_POINT_RADIUS,
8
- DEFAULT_POINT_RADIUS,
9
- } from '../constants/line-chart-consts';
10
- import { generateRandomColor } from '../../../helpers/chart-utils';
11
-
12
- /**
13
- * Generates line chart datasets based on the provided datasets, state, and options.
14
- *
15
- * @param {Array} datasets - The initial datasets for the line chart.
16
- * @param {Object} state - The state object containing chart settings (e.g., lineEnabled, pointsEnabled, axes).
17
- * @param {Object} options - The options object containing additional settings (e.g., annotations, graph).
18
- * @param {Object} translations - The getTranslations object with the label property
19
- * @returns {Array} - The generated line chart datasets with applied settings and configurations.
20
- */
21
- export const generateLineChartDatasets = (
22
- datasets,
23
- state,
24
- options,
25
- { label },
26
- ) => {
27
- const copyDataset = [...datasets];
28
- const { annotations, graph } = options;
29
- const {
30
- controlAnnotation,
31
- showAnnotations,
32
- annotationsData = [],
33
- } = annotations;
34
- // Add annotations to dataset to have them appear in legend.
35
- if (controlAnnotation && showAnnotations) {
36
- const annotationDatasets = annotationsData.map((annotation, index) => {
37
- const color = annotation.color ?? COLORS[index];
38
-
39
- // Create an annotation dataset
40
- return {
41
- isAnnotation: true,
42
- label: annotation.label,
43
- annotationIndex: index,
44
- backgroundColor: color,
45
- pointBackgroundColor: color,
46
- borderColor: color,
47
- data: [{}],
48
- };
49
- });
50
-
51
- // Add annotation datasets to the copyDataset array
52
- copyDataset.push(...annotationDatasets);
53
- }
54
-
55
- // Map over the copyDataset array and generate line chart datasets with applied settings and configurations
56
- return copyDataset.map((line, i) => {
57
- // Destructure properties from the line, state, and graph objects
58
- const {
59
- formation,
60
- data = [],
61
- pointRadius,
62
- pointHoverRadius,
63
- borderWidth,
64
- borderColor,
65
- backgroundColor,
66
- pointBackgroundColor,
67
- borderDash,
68
- } = line ?? {};
69
- const { lineEnabled, pointsEnabled, axes = [] } = state ?? {};
70
- const { lineTension, spanGaps } = graph ?? {};
71
-
72
- // Adjust the start and end points of the line if it has a formation flag
73
- if (formation) {
74
- const axesMin = axes[0]?.min;
75
- const axesMax = axes[0]?.max;
76
- const [startPoint, midPointWithLabel, endPoint] = data;
77
-
78
- if (axesMin && startPoint?.x) {
79
- data[0].x = Math.max(axesMin, startPoint.x);
80
- }
81
-
82
- if (axesMax && endPoint?.x) {
83
- data[2].x = Math.min(axesMax, endPoint.x);
84
- }
85
- }
86
-
87
- // Remove invalid falsy data points (OW-9855)
88
- const filteredData = data.filter(Boolean) || [];
89
-
90
- const linePointRadius = parseFloat(pointRadius) || DEFAULT_POINT_RADIUS;
91
- const hoverRadius = parseFloat(pointHoverRadius) || DEFAULT_HOVER_RADIUS;
92
- const indexedColor = COLORS[i];
93
-
94
- // Return the dataset with applied settings and configurations
95
- return {
96
- ...line,
97
- label: line.label || `${label} ${i + 1}`,
98
- data: filteredData,
99
- showLine: lineEnabled,
100
- lineTension,
101
- spanGaps,
102
- borderWidth: parseFloat(borderWidth) || DEFAULT_BORDER_WIDTH,
103
- borderDash: borderDash || [],
104
- borderJoinStyle: BORDER_JOIN_STYLE,
105
- borderColor: borderColor ?? indexedColor ?? generateRandomColor(COLORS),
106
- backgroundColor: backgroundColor ?? DEFAULT_BACKGROUND_COLOR,
107
- pointBackgroundColor:
108
- pointBackgroundColor ?? indexedColor ?? generateRandomColor(COLORS),
109
- pointRadius: pointsEnabled ? linePointRadius : DEFAULT_LINE_POINT_RADIUS,
110
- pointHoverRadius: hoverRadius,
111
- pointHitRadius: line.pointHitRadius ?? hoverRadius,
112
- };
113
- });
114
- };
@@ -1,13 +0,0 @@
1
- export const getAxesRangesFromChart = (chartRef, axes) => {
2
- const { scales = {} } = chartRef.current || {};
3
- return Object.entries(scales).map(([key, { min, max }], i) => {
4
- const axesArray = axes.x.concat(axes.y);
5
- const unit = axesArray?.[i]?.unit;
6
- return {
7
- id: key,
8
- min,
9
- max,
10
- ...(unit ? { unit } : {}),
11
- };
12
- });
13
- };
@@ -1,21 +0,0 @@
1
- import { AUTO } from '../../../helpers/chart-consts';
2
- import { getPosition } from './datalabels-alignment/get-datalabels-position';
3
-
4
- /**
5
- * adjusts the position of the label depends on chart area
6
- *
7
- * @param {import('../line-chart.interface').ILineChartOptions} options - line chart options object
8
- * @return {object} - returning position, if label exist in datasets item
9
- */
10
- const getLineChartDataLabels = (options) => {
11
- return options.graph.showDataLabels
12
- ? {
13
- display: AUTO,
14
- align: getPosition(),
15
- formatter: (value, context) =>
16
- context.dataset.data[context.dataIndex].label || '',
17
- }
18
- : { display: false };
19
- };
20
-
21
- export default getLineChartDataLabels;
@@ -1,120 +0,0 @@
1
- import {
2
- generateRandomColor,
3
- getAxisPosition,
4
- } from '../../../helpers/chart-utils';
5
- import { COLORS, LOGARITHMIC_STEPS } from '../../../helpers/chart-consts';
6
- import { generateAxisId, truncateDecimals } from './line-chart-utils';
7
- import { AxisType, ScaleType } from '../../../helpers/enums';
8
-
9
- /**
10
- * @param {import('../line-chart.interface').ILineChartOptions} options - line chart options object
11
- * @param {'x'|'y'} axisType
12
- * @param {import('../../../helpers/chart-interface').IInitialState} state - chart state object controlled by useReducer or similar
13
- * @param {import('../line-chart.interface').ILineChartAxis[]} [currentScales]
14
- * @param {number} [i]
15
- */
16
- const getLineChartAxis = (options, axisType, state, currentScales, i = 0) => {
17
- const axisData = currentScales || options.axes[axisType][0];
18
- const stateAxis = state.axes.filter((axis) => axis.id.startsWith(axisType))[
19
- i
20
- ];
21
-
22
- const { additionalAxesOptions } = options;
23
-
24
- const getTicks = () => {
25
- const truncateAxisNumbersToDigitsCallback = Number.isInteger(
26
- additionalAxesOptions.truncateAxisNumbersToDigitsCallback,
27
- )
28
- ? {
29
- callback: (tick) =>
30
- truncateDecimals(
31
- tick,
32
- additionalAxesOptions.truncateAxisNumbersToDigitsCallback,
33
- ),
34
- }
35
- : {};
36
-
37
- const ticks =
38
- additionalAxesOptions.chartScaleType === ScaleType.Logarithmic
39
- ? {
40
- callback: (tick) => {
41
- return LOGARITHMIC_STEPS.includes(tick)
42
- ? tick.toLocaleString()
43
- : '';
44
- },
45
- }
46
- : {
47
- stepSize:
48
- axisData.stepSize ||
49
- (axisType === AxisType.Y ? additionalAxesOptions.stepSize : null),
50
- ...truncateAxisNumbersToDigitsCallback,
51
- };
52
- return {
53
- ...ticks,
54
- includeBounds: false, //OW-10088 disable irregular axis ticks
55
- };
56
- };
57
-
58
- return {
59
- type: additionalAxesOptions.chartScaleType,
60
- position: axisData.position,
61
- beginAtZero: additionalAxesOptions.beginAtZero,
62
- reverse: axisType === AxisType.Y ? additionalAxesOptions.reverse : false,
63
- suggestedMax: additionalAxesOptions.suggestedMax,
64
- suggestedMin: additionalAxesOptions.suggestedMin,
65
- min: stateAxis?.min ?? additionalAxesOptions?.range?.[axisType]?.min,
66
- max: stateAxis?.max ?? additionalAxesOptions?.range?.[axisType]?.max,
67
- title: {
68
- display: axisData.label?.length,
69
- text: axisData.label,
70
- padding: 0,
71
- },
72
- ticks: getTicks(),
73
- grid: {
74
- ...axisData.gridLines,
75
- },
76
- };
77
- };
78
-
79
- /**
80
- * @param {import('../line-chart.interface').ILineChartOptions} options - line chart options object
81
- * @param {'x'|'y'} axisType
82
- * @param {import('../../../helpers/chart-interface').IInitialState} state - chart state object controlled by useReducer or similar
83
- */
84
- const getLineChartAxes = (options, axisType, state) => {
85
- const axesData = options.axes[axisType];
86
- const axes = axesData.reduce((acc, curr, i) => {
87
- const axisData = curr;
88
- axisData.color = curr.color || COLORS[i] || generateRandomColor(COLORS);
89
- axisData.position = curr.position || getAxisPosition(axisType, i);
90
-
91
- const axis = getLineChartAxis(options, axisType, state, axisData, i);
92
- const axisId = generateAxisId(axisType, i, true);
93
- return { ...acc, [axisId]: axis };
94
- }, {});
95
- return axes;
96
- };
97
-
98
- /**
99
- *
100
- * @param {import('../line-chart.interface').ILineChartOptions} options - line chart options object
101
- * @param {import('../../../helpers/chart-interface').IInitialState} state - chart state object controlled by useReducer or similar
102
- */
103
- const getLineChartScales = (options, state) => {
104
- const hasMultipleXAxes = options.axes.x?.length > 1;
105
- const hasMultipleYAxes = options.axes.y?.length > 1;
106
-
107
- const xAxes = hasMultipleXAxes
108
- ? getLineChartAxes(options, AxisType.X, state)
109
- : { x: getLineChartAxis(options, AxisType.X, state) };
110
- const yAxes = hasMultipleYAxes
111
- ? getLineChartAxes(options, AxisType.Y, state)
112
- : { y: getLineChartAxis(options, AxisType.Y, state) };
113
-
114
- return {
115
- ...xAxes,
116
- ...yAxes,
117
- };
118
- };
119
-
120
- export default getLineChartScales;