@oliasoft-open-source/charts-library 2.13.5 → 2.14.0-beta-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/components/controls/axes-options/axes-options.jsx +43 -9
- package/src/components/line-chart/constants/default-translations.js +24 -0
- package/src/components/line-chart/{line-chart-consts.js → constants/line-chart-consts.js} +1 -0
- package/src/components/line-chart/controls/axes-options/action-types.js +5 -0
- package/src/components/{controls → line-chart/controls}/axes-options/axes-options-form-state.js +19 -20
- package/src/components/line-chart/controls/controls.jsx +174 -0
- package/src/components/line-chart/controls/drag-options.jsx +112 -0
- package/src/components/line-chart/controls/legend-options.jsx +36 -0
- package/src/components/{controls → line-chart/controls}/line-options.jsx +18 -8
- package/src/components/line-chart/hooks/use-chart-functions.js +257 -0
- package/src/components/line-chart/hooks/use-chart-options.js +155 -0
- package/src/components/line-chart/hooks/use-chart-plugins.js +26 -0
- package/src/components/line-chart/hooks/use-toggle-handler.js +33 -0
- package/src/components/line-chart/line-chart.jsx +53 -410
- package/src/components/line-chart/state/initial-state.js +7 -8
- package/src/components/line-chart/state/line-chart-reducer.js +68 -86
- package/src/components/line-chart/state/use-chart-state.js +2 -1
- package/src/components/line-chart/{axis-scales → utils/axis-scales}/axis-scales.js +3 -3
- package/src/components/line-chart/{datalabels-alignment → utils/datalabels-alignment}/get-datalabels-position.js +1 -1
- package/src/components/line-chart/utils/generate-line-chart-datasets.js +114 -0
- package/src/components/line-chart/{get-line-chart-data-labels.js → utils/get-line-chart-data-labels.js} +2 -2
- package/src/components/line-chart/{get-line-chart-scales.js → utils/get-line-chart-scales.js} +11 -11
- package/src/components/line-chart/{get-line-chart-tooltips.js → utils/get-line-chart-tooltips.js} +6 -3
- package/src/components/line-chart/utils/get-translations/get-translations.js +17 -0
- package/src/helpers/chart-utils.js +3 -5
- package/src/helpers/enums.js +9 -0
- package/src/components/controls/controls.jsx +0 -114
- package/src/components/controls/drag-options.jsx +0 -98
- package/src/components/controls/legend-options.jsx +0 -25
- /package/src/components/{controls → line-chart/controls}/controls.module.less +0 -0
- /package/src/components/line-chart/{datalabels-alignment → utils/datalabels-alignment}/get-alignment-condition.js +0 -0
- /package/src/components/line-chart/{datalabels-alignment → utils/datalabels-alignment}/get-alignment-data.js +0 -0
- /package/src/components/line-chart/{get-axes-ranges-from-chart.js → utils/get-axes-ranges-from-chart.js} +0 -0
- /package/src/components/line-chart/{line-chart-utils.js → utils/line-chart-utils.js} +0 -0
|
@@ -15,104 +15,86 @@ import {
|
|
|
15
15
|
} from './action-types';
|
|
16
16
|
|
|
17
17
|
export const reducer = (state, action) => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
return produce(state, (draft) => {
|
|
19
|
+
switch (action.type) {
|
|
20
|
+
case TOGGLE_ZOOM: {
|
|
21
|
+
draft.zoomEnabled = !draft.zoomEnabled;
|
|
22
|
+
if (draft.panEnabled) {
|
|
23
|
+
draft.panEnabled = false;
|
|
24
|
+
}
|
|
25
|
+
if (draft.enableDragPoints) {
|
|
26
|
+
draft.enableDragPoints = false;
|
|
27
|
+
}
|
|
28
|
+
break;
|
|
24
29
|
}
|
|
25
|
-
|
|
26
|
-
|
|
30
|
+
case TOGGLE_PAN: {
|
|
31
|
+
draft.panEnabled = !draft.panEnabled;
|
|
32
|
+
if (draft.zoomEnabled) {
|
|
33
|
+
draft.zoomEnabled = false;
|
|
34
|
+
}
|
|
35
|
+
break;
|
|
27
36
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
newState.panEnabled = !newState.panEnabled;
|
|
32
|
-
if (newState.zoomEnabled) {
|
|
33
|
-
newState.zoomEnabled = false;
|
|
37
|
+
case TOGGLE_POINTS: {
|
|
38
|
+
draft.pointsEnabled = !draft.pointsEnabled;
|
|
39
|
+
break;
|
|
34
40
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
case TOGGLE_LEGEND: {
|
|
50
|
-
return {
|
|
51
|
-
...newState,
|
|
52
|
-
legendEnabled: !newState.legendEnabled,
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
case TOGGLE_TABLE: {
|
|
56
|
-
return {
|
|
57
|
-
...newState,
|
|
58
|
-
showTable: !newState.showTable,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
case SAVE_INITIAL_AXES_RANGES: {
|
|
62
|
-
return produce(state, (draft) => {
|
|
41
|
+
case TOGGLE_LINE: {
|
|
42
|
+
draft.lineEnabled = !draft.lineEnabled;
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
case TOGGLE_LEGEND: {
|
|
46
|
+
draft.legendEnabled = !draft.legendEnabled;
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
case TOGGLE_TABLE: {
|
|
50
|
+
draft.showTable = !draft.showTable;
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
case SAVE_INITIAL_AXES_RANGES: {
|
|
63
54
|
const { initialAxesRanges } = action.payload;
|
|
64
55
|
draft.initialAxesRanges = initialAxesRanges;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return produce(state, (draft) => {
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
case UPDATE_AXES_RANGES: {
|
|
69
59
|
const { axes } = action.payload;
|
|
70
60
|
draft.axes = axes;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const { axes } = state;
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
case RESET_AXES_RANGES: {
|
|
64
|
+
const { axes } = draft;
|
|
76
65
|
draft.axes = axes.map((axis) => ({
|
|
77
66
|
id: axis.id,
|
|
78
67
|
}));
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
case TOGGLE_ANNOTATION:
|
|
82
|
-
const { annotationIndex } = action.payload;
|
|
83
|
-
const updatedIndexes = newState.showAnnotationLineIndex.includes(
|
|
84
|
-
annotationIndex,
|
|
85
|
-
)
|
|
86
|
-
? newState.showAnnotationLineIndex.filter((v) => v !== annotationIndex)
|
|
87
|
-
: [...newState.showAnnotationLineIndex, annotationIndex];
|
|
88
|
-
return {
|
|
89
|
-
...newState,
|
|
90
|
-
showAnnotationLineIndex: updatedIndexes,
|
|
91
|
-
};
|
|
92
|
-
case TOGGLE_DRAG_POINTS: {
|
|
93
|
-
newState.enableDragPoints = !newState.enableDragPoints;
|
|
94
|
-
if (newState.panEnabled) {
|
|
95
|
-
newState.panEnabled = false;
|
|
68
|
+
break;
|
|
96
69
|
}
|
|
97
|
-
|
|
98
|
-
|
|
70
|
+
case TOGGLE_ANNOTATION: {
|
|
71
|
+
const { annotationIndex } = action.payload;
|
|
72
|
+
const updatedIndexes = draft.showAnnotationLineIndex.includes(
|
|
73
|
+
annotationIndex,
|
|
74
|
+
)
|
|
75
|
+
? draft.showAnnotationLineIndex.filter((v) => v !== annotationIndex)
|
|
76
|
+
: [...draft.showAnnotationLineIndex, annotationIndex];
|
|
77
|
+
draft.showAnnotationLineIndex = updatedIndexes;
|
|
78
|
+
break;
|
|
99
79
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
80
|
+
case TOGGLE_DRAG_POINTS: {
|
|
81
|
+
draft.enableDragPoints = !draft.enableDragPoints;
|
|
82
|
+
if (draft.panEnabled) {
|
|
83
|
+
draft.panEnabled = false;
|
|
84
|
+
}
|
|
85
|
+
if (draft.zoomEnabled) {
|
|
86
|
+
draft.zoomEnabled = false;
|
|
87
|
+
}
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
case DISABLE_DRAG_OPTIONS: {
|
|
91
|
+
if (draft.enableDragPoints || draft.panEnabled || draft.zoomEnabled) {
|
|
92
|
+
draft.enableDragPoints = false;
|
|
93
|
+
draft.panEnabled = false;
|
|
94
|
+
draft.zoomEnabled = false;
|
|
95
|
+
}
|
|
96
|
+
break;
|
|
111
97
|
}
|
|
112
|
-
return newState;
|
|
113
|
-
}
|
|
114
|
-
default: {
|
|
115
|
-
return newState;
|
|
116
98
|
}
|
|
117
|
-
}
|
|
99
|
+
});
|
|
118
100
|
};
|
|
@@ -2,7 +2,7 @@ import { useCallback, useEffect, useMemo, useRef } from 'react';
|
|
|
2
2
|
import { isEqual } from 'lodash';
|
|
3
3
|
import { storeChartStateInStorage } from './manage-state-in-local-storage';
|
|
4
4
|
import { SAVE_INITIAL_AXES_RANGES, UPDATE_AXES_RANGES } from './action-types';
|
|
5
|
-
import { getAxesRangesFromChart } from '../get-axes-ranges-from-chart';
|
|
5
|
+
import { getAxesRangesFromChart } from '../utils/get-axes-ranges-from-chart';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Hook for toggling the visibility of the custom legend.
|
|
@@ -103,6 +103,7 @@ const useSaveInitialAxesRanges = (chartRef, axes, dispatch) => {
|
|
|
103
103
|
* @param chartRef - The reference to the chart.
|
|
104
104
|
* @param options - The chart options.
|
|
105
105
|
* @param state - The chart state.
|
|
106
|
+
* @param dispatch - The dispatch function for state management.
|
|
106
107
|
* @param persistenceId - The chart persistenceId.
|
|
107
108
|
*/
|
|
108
109
|
export const useChartState = ({
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import getLineChartScales from '../get-line-chart-scales';
|
|
2
|
-
import { AxisType } from '
|
|
2
|
+
import { AxisType } from '../../../../helpers/enums';
|
|
3
3
|
import { getAxisTypeFromKey } from '../line-chart-utils';
|
|
4
|
-
import { estimateDataSeriesHaveCloseValues } from '
|
|
5
|
-
import { getSuggestedAxisRange } from '
|
|
4
|
+
import { estimateDataSeriesHaveCloseValues } from '../../../../helpers/range/estimate-data-series-have-close-values';
|
|
5
|
+
import { getSuggestedAxisRange } from '../../../../helpers/range/range';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
Function that counts the number of occurences of "x" and "y" in an array and returns the one with the highest count.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getCondition } from './get-alignment-condition';
|
|
2
2
|
import { getAlignmentData } from './get-alignment-data';
|
|
3
|
-
import { AlignOptions } from '
|
|
3
|
+
import { AlignOptions } from '../../../../helpers/enums';
|
|
4
4
|
|
|
5
5
|
/** returning position depends on condition
|
|
6
6
|
*
|
|
@@ -0,0 +1,114 @@
|
|
|
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 translations object containing translations string
|
|
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
|
+
translations,
|
|
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 || `${translations.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,10 +1,10 @@
|
|
|
1
|
-
import { AUTO } from '
|
|
1
|
+
import { AUTO } from '../../../helpers/chart-consts';
|
|
2
2
|
import { getPosition } from './datalabels-alignment/get-datalabels-position';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* adjusts the position of the label depends on chart area
|
|
6
6
|
*
|
|
7
|
-
* @param {import('
|
|
7
|
+
* @param {import('../line-chart.interface').ILineChartOptions} options - line chart options object
|
|
8
8
|
* @return {object} - returning position, if label exist in datasets item
|
|
9
9
|
*/
|
|
10
10
|
const getLineChartDataLabels = (options) => {
|
package/src/components/line-chart/{get-line-chart-scales.js → utils/get-line-chart-scales.js}
RENAMED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
generateRandomColor,
|
|
3
3
|
getAxisPosition,
|
|
4
|
-
} from '
|
|
5
|
-
import { COLORS, LOGARITHMIC_STEPS } from '
|
|
4
|
+
} from '../../../helpers/chart-utils';
|
|
5
|
+
import { COLORS, LOGARITHMIC_STEPS } from '../../../helpers/chart-consts';
|
|
6
6
|
import { generateAxisId, truncateDecimals } from './line-chart-utils';
|
|
7
|
-
import { AxisType, ScaleType } from '
|
|
7
|
+
import { AxisType, ScaleType } from '../../../helpers/enums';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* @param {import('
|
|
10
|
+
* @param {import('../line-chart.interface').ILineChartOptions} options - line chart options object
|
|
11
11
|
* @param {'x'|'y'} axisType
|
|
12
|
-
* @param {import('
|
|
13
|
-
* @param {import('
|
|
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
14
|
* @param {number} [i]
|
|
15
15
|
*/
|
|
16
16
|
const getLineChartAxis = (options, axisType, state, currentScales, i = 0) => {
|
|
@@ -19,7 +19,7 @@ const getLineChartAxis = (options, axisType, state, currentScales, i = 0) => {
|
|
|
19
19
|
i
|
|
20
20
|
];
|
|
21
21
|
|
|
22
|
-
const { additionalAxesOptions
|
|
22
|
+
const { additionalAxesOptions } = options;
|
|
23
23
|
|
|
24
24
|
const getTicks = () => {
|
|
25
25
|
const truncateAxisNumbersToDigitsCallback = Number.isInteger(
|
|
@@ -77,9 +77,9 @@ const getLineChartAxis = (options, axisType, state, currentScales, i = 0) => {
|
|
|
77
77
|
};
|
|
78
78
|
|
|
79
79
|
/**
|
|
80
|
-
* @param {import('
|
|
80
|
+
* @param {import('../line-chart.interface').ILineChartOptions} options - line chart options object
|
|
81
81
|
* @param {'x'|'y'} axisType
|
|
82
|
-
* @param {import('
|
|
82
|
+
* @param {import('../../../helpers/chart-interface').IInitialState} state - chart state object controlled by useReducer or similar
|
|
83
83
|
*/
|
|
84
84
|
const getLineChartAxes = (options, axisType, state) => {
|
|
85
85
|
const axesData = options.axes[axisType];
|
|
@@ -97,8 +97,8 @@ const getLineChartAxes = (options, axisType, state) => {
|
|
|
97
97
|
|
|
98
98
|
/**
|
|
99
99
|
*
|
|
100
|
-
* @param {import('
|
|
101
|
-
* @param {import('
|
|
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
102
|
*/
|
|
103
103
|
const getLineChartScales = (options, state) => {
|
|
104
104
|
const hasMultipleXAxes = options.axes.x?.length > 1;
|
package/src/components/line-chart/{get-line-chart-tooltips.js → utils/get-line-chart-tooltips.js}
RENAMED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { ChartHoverMode, Position, TooltipLabel } from '
|
|
2
|
-
import {
|
|
1
|
+
import { ChartHoverMode, Position, TooltipLabel } from '../../../helpers/enums';
|
|
2
|
+
import {
|
|
3
|
+
afterLabelCallback,
|
|
4
|
+
getTooltipLabel,
|
|
5
|
+
} from '../../../helpers/chart-utils';
|
|
3
6
|
|
|
4
7
|
/**
|
|
5
|
-
* @param {import('
|
|
8
|
+
* @param {import('../line-chart.interface').ILineChartOptions} options - line chart options object
|
|
6
9
|
*/
|
|
7
10
|
const getLineChartToolTips = (options) => {
|
|
8
11
|
const getTooltipLabels = (dataset) => {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { defaultTranslations } from '../../constants/default-translations';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Merges custom translations with the default translations.
|
|
5
|
+
* If a custom translation is provided for a key, it will override the default one.
|
|
6
|
+
* @param {object} translations - Custom translations.
|
|
7
|
+
* @returns {object} - The resulting translations object, containing both default and custom translations.
|
|
8
|
+
*/
|
|
9
|
+
export const getTranslations = (translations = {}) => {
|
|
10
|
+
return Object.keys(defaultTranslations).reduce(
|
|
11
|
+
(acc, key) => ({
|
|
12
|
+
...acc,
|
|
13
|
+
[key]: translations[key] || defaultTranslations[key],
|
|
14
|
+
}),
|
|
15
|
+
{},
|
|
16
|
+
);
|
|
17
|
+
};
|
|
@@ -3,8 +3,8 @@ import { defaults } from 'chart.js';
|
|
|
3
3
|
import cx from 'classnames';
|
|
4
4
|
import { chartMinorGridlinesPlugin } from '../components/line-chart/line-chart.minor-gridlines-plugin';
|
|
5
5
|
import {
|
|
6
|
-
CUSTOM_LEGEND_PLUGIN_NAME,
|
|
7
6
|
BORDER_COLOR,
|
|
7
|
+
CUSTOM_LEGEND_PLUGIN_NAME,
|
|
8
8
|
DEFAULT_CHART_NAME,
|
|
9
9
|
DEFAULT_COLOR,
|
|
10
10
|
DEFAULT_FONT_FAMILY,
|
|
@@ -19,10 +19,9 @@ import { chartAreaBorderPlugin } from './chart-border-plugin';
|
|
|
19
19
|
* @param {import('../components/bar-chart/bar-chart.interface').IBarChartGraph |
|
|
20
20
|
* import('../components/line-chart/line-chart.interface').ILineChartGraph } graph - graph data from chart options
|
|
21
21
|
* @param {import('../helpers/chart-interface').IChartLegend} legend
|
|
22
|
-
* @param {import('./chart-interface').IInitialState} state - chart state object controlled by useReducer or similar
|
|
23
22
|
* @return {[]}
|
|
24
23
|
*/
|
|
25
|
-
export const getPlugins = (graph, legend
|
|
24
|
+
export const getPlugins = (graph, legend) => {
|
|
26
25
|
let plugins = [];
|
|
27
26
|
if (graph.showMinorGridlines) {
|
|
28
27
|
plugins.push(chartMinorGridlinesPlugin);
|
|
@@ -131,7 +130,7 @@ export const getClassName = (chartStyling, styles) => {
|
|
|
131
130
|
* @returns {*}
|
|
132
131
|
*/
|
|
133
132
|
export const getLegend = (options, clickHandler, state = null) => {
|
|
134
|
-
const { legend
|
|
133
|
+
const { legend } = options;
|
|
135
134
|
return {
|
|
136
135
|
position: legend.position || Position.Top,
|
|
137
136
|
display: !legend?.customLegend?.customLegendPlugin
|
|
@@ -144,7 +143,6 @@ export const getLegend = (options, clickHandler, state = null) => {
|
|
|
144
143
|
boxHeight: LEGEND_LABEL_BOX_SIZE,
|
|
145
144
|
boxWidth: LEGEND_LABEL_BOX_SIZE,
|
|
146
145
|
usePointStyle: true,
|
|
147
|
-
filter: (item, data) => !data.datasets[item.datasetIndex].hideLegend,
|
|
148
146
|
},
|
|
149
147
|
onClick: clickHandler,
|
|
150
148
|
};
|
package/src/helpers/enums.js
CHANGED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Button, Text, Tooltip } from '@oliasoft-open-source/react-ui-library';
|
|
3
|
-
import {
|
|
4
|
-
RiFileDownloadLine,
|
|
5
|
-
RiLineChartLine,
|
|
6
|
-
RiTableLine,
|
|
7
|
-
} from 'react-icons/ri';
|
|
8
|
-
import { LineOptions } from './line-options';
|
|
9
|
-
import { DragOptions } from './drag-options';
|
|
10
|
-
import { AxesOptions } from './axes-options/axes-options';
|
|
11
|
-
import { LegendOptions } from './legend-options';
|
|
12
|
-
import styles from './controls.module.less';
|
|
13
|
-
|
|
14
|
-
const Controls = ({
|
|
15
|
-
axes,
|
|
16
|
-
controlsAxesLabels,
|
|
17
|
-
chart,
|
|
18
|
-
headerComponent,
|
|
19
|
-
legendEnabled,
|
|
20
|
-
lineEnabled,
|
|
21
|
-
onDownload,
|
|
22
|
-
onResetAxes,
|
|
23
|
-
onUpdateAxes,
|
|
24
|
-
onToggleLegend,
|
|
25
|
-
onToggleLine,
|
|
26
|
-
onTogglePan,
|
|
27
|
-
onTogglePoints,
|
|
28
|
-
onToggleTable,
|
|
29
|
-
onToggleZoom,
|
|
30
|
-
panEnabled,
|
|
31
|
-
pointsEnabled,
|
|
32
|
-
initialAxesRanges,
|
|
33
|
-
showTable,
|
|
34
|
-
subheaderComponent,
|
|
35
|
-
table,
|
|
36
|
-
zoomEnabled,
|
|
37
|
-
depthType,
|
|
38
|
-
enableDragPoints,
|
|
39
|
-
isDragDataAllowed,
|
|
40
|
-
onToggleDragPoints,
|
|
41
|
-
onDisableDragOptions,
|
|
42
|
-
}) => {
|
|
43
|
-
return (
|
|
44
|
-
<>
|
|
45
|
-
<div className={styles.controls}>
|
|
46
|
-
{!!chart.options.title && <Text bold>{chart.options.title}</Text>}
|
|
47
|
-
{headerComponent}
|
|
48
|
-
<div className={styles.buttons}>
|
|
49
|
-
{!showTable && (
|
|
50
|
-
<>
|
|
51
|
-
<AxesOptions
|
|
52
|
-
initialAxesRanges={initialAxesRanges}
|
|
53
|
-
axes={axes}
|
|
54
|
-
controlsAxesLabels={controlsAxesLabels}
|
|
55
|
-
onUpdateAxes={onUpdateAxes}
|
|
56
|
-
onResetAxes={onResetAxes}
|
|
57
|
-
depthType={depthType}
|
|
58
|
-
/>
|
|
59
|
-
<LineOptions
|
|
60
|
-
lineEnabled={lineEnabled}
|
|
61
|
-
pointsEnabled={pointsEnabled}
|
|
62
|
-
onToggleLine={onToggleLine}
|
|
63
|
-
onTogglePoints={onTogglePoints}
|
|
64
|
-
/>
|
|
65
|
-
<LegendOptions
|
|
66
|
-
legendEnabled={legendEnabled}
|
|
67
|
-
onToggleLegend={onToggleLegend}
|
|
68
|
-
/>
|
|
69
|
-
<Tooltip text="Download as PNG" placement="bottom-end">
|
|
70
|
-
<Button
|
|
71
|
-
small
|
|
72
|
-
basic
|
|
73
|
-
colored="muted"
|
|
74
|
-
round
|
|
75
|
-
icon={<RiFileDownloadLine />}
|
|
76
|
-
onClick={onDownload}
|
|
77
|
-
/>
|
|
78
|
-
</Tooltip>
|
|
79
|
-
<DragOptions
|
|
80
|
-
panEnabled={panEnabled}
|
|
81
|
-
zoomEnabled={zoomEnabled}
|
|
82
|
-
onTogglePan={onTogglePan}
|
|
83
|
-
onToggleZoom={onToggleZoom}
|
|
84
|
-
enableDragPoints={enableDragPoints}
|
|
85
|
-
isDragDataAllowed={isDragDataAllowed}
|
|
86
|
-
onToggleDragPoints={onToggleDragPoints}
|
|
87
|
-
onDisableDragOptions={onDisableDragOptions}
|
|
88
|
-
/>
|
|
89
|
-
</>
|
|
90
|
-
)}
|
|
91
|
-
|
|
92
|
-
{table ? (
|
|
93
|
-
<Tooltip
|
|
94
|
-
text={showTable ? 'Show chart' : 'Show table'}
|
|
95
|
-
placement="bottom-end"
|
|
96
|
-
>
|
|
97
|
-
<Button
|
|
98
|
-
small
|
|
99
|
-
basic
|
|
100
|
-
colored="muted"
|
|
101
|
-
round
|
|
102
|
-
icon={showTable ? <RiLineChartLine /> : <RiTableLine />}
|
|
103
|
-
onClick={onToggleTable}
|
|
104
|
-
/>
|
|
105
|
-
</Tooltip>
|
|
106
|
-
) : null}
|
|
107
|
-
</div>
|
|
108
|
-
</div>
|
|
109
|
-
{subheaderComponent}
|
|
110
|
-
</>
|
|
111
|
-
);
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
export default Controls;
|