@oliasoft-open-source/charts-library 2.5.13 → 2.5.15
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/release-notes.md +8 -0
- package/src/components/controls/axes-options.jsx +9 -1
- package/src/components/controls/controls.jsx +2 -0
- package/src/components/line-chart/get-line-chart-scales.js +8 -3
- package/src/components/line-chart/line-chart-utils.js +12 -0
- package/src/components/line-chart/line-chart.interface.ts +7 -5
- package/src/components/line-chart/line-chart.jsx +30 -1
- package/src/components/line-chart/state/initial-state.js +10 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oliasoft-open-source/charts-library",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.15",
|
|
4
4
|
"description": "React Chart Library (based on Chart.js and react-chart-js-2)",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
"react-dom": "^17.0"
|
|
91
91
|
},
|
|
92
92
|
"dependencies": {
|
|
93
|
-
"@oliasoft-open-source/react-ui-library": "^3.1
|
|
93
|
+
"@oliasoft-open-source/react-ui-library": "^3.1",
|
|
94
94
|
"chart.js": "^3.9.1",
|
|
95
95
|
"chartjs-plugin-annotation": "^1.4.0",
|
|
96
96
|
"chartjs-plugin-datalabels": "^2.1.0",
|
package/release-notes.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Charts Library Release Notes
|
|
2
2
|
|
|
3
|
+
## 2.5.15
|
|
4
|
+
|
|
5
|
+
- Changed GUI library version to `^3.1`
|
|
6
|
+
|
|
7
|
+
## 2.5.14
|
|
8
|
+
|
|
9
|
+
- Sync axis labels in chart Controls with props
|
|
10
|
+
|
|
3
11
|
## 2.5.13
|
|
4
12
|
|
|
5
13
|
- fixed custom range inputs reset, multi-axis range placeholder values missing
|
|
@@ -15,6 +15,7 @@ import { RiRuler2Line } from 'react-icons/ri';
|
|
|
15
15
|
const AxesOptionsPopover = ({
|
|
16
16
|
onResetAxes,
|
|
17
17
|
axes,
|
|
18
|
+
controlsAxesLabels,
|
|
18
19
|
onSetAxisValue,
|
|
19
20
|
panEnabled,
|
|
20
21
|
scalesMaxMin,
|
|
@@ -31,8 +32,13 @@ const AxesOptionsPopover = ({
|
|
|
31
32
|
{axes.map((axis, i) => {
|
|
32
33
|
// TODO: Translate strings
|
|
33
34
|
if (!axis.min || !axis.max) return null;
|
|
35
|
+
|
|
36
|
+
const axisLabel = controlsAxesLabels.find(
|
|
37
|
+
(el) => el.id === axis.id,
|
|
38
|
+
)?.label;
|
|
39
|
+
|
|
34
40
|
return (
|
|
35
|
-
<Field key={i} label={
|
|
41
|
+
<Field key={i} label={axisLabel || axis.id || ''}>
|
|
36
42
|
<InputGroup small>
|
|
37
43
|
<Input
|
|
38
44
|
name="min"
|
|
@@ -113,6 +119,7 @@ const AxesOptionsPopover = ({
|
|
|
113
119
|
export const AxesOptions = ({
|
|
114
120
|
onResetAxes,
|
|
115
121
|
axes,
|
|
122
|
+
controlsAxesLabels,
|
|
116
123
|
onSetAxisValue,
|
|
117
124
|
panEnabled,
|
|
118
125
|
scalesMaxMin,
|
|
@@ -126,6 +133,7 @@ export const AxesOptions = ({
|
|
|
126
133
|
<AxesOptionsPopover
|
|
127
134
|
onResetAxes={onResetAxes}
|
|
128
135
|
axes={axes}
|
|
136
|
+
controlsAxesLabels={controlsAxesLabels}
|
|
129
137
|
onSetAxisValue={onSetAxisValue}
|
|
130
138
|
panEnabled={panEnabled}
|
|
131
139
|
scalesMaxMin={scalesMaxMin}
|
|
@@ -13,6 +13,7 @@ import styles from './controls.module.less';
|
|
|
13
13
|
|
|
14
14
|
const Controls = ({
|
|
15
15
|
axes,
|
|
16
|
+
controlsAxesLabels,
|
|
16
17
|
chart,
|
|
17
18
|
headerComponent,
|
|
18
19
|
legendEnabled,
|
|
@@ -45,6 +46,7 @@ const Controls = ({
|
|
|
45
46
|
<AxesOptions
|
|
46
47
|
onResetAxes={onResetAxes}
|
|
47
48
|
axes={axes}
|
|
49
|
+
controlsAxesLabels={controlsAxesLabels}
|
|
48
50
|
onSetAxisValue={onSetAxisValue}
|
|
49
51
|
panEnabled={panEnabled}
|
|
50
52
|
scalesMaxMin={scalesMaxMin}
|
|
@@ -3,14 +3,18 @@ import {
|
|
|
3
3
|
getAxisPosition,
|
|
4
4
|
} from '../../helpers/chart-utils';
|
|
5
5
|
import { COLORS, LOGARITHMIC_STEPS } from '../../helpers/chart-consts';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
generateAxisId,
|
|
8
|
+
truncateDecimals,
|
|
9
|
+
validNumber,
|
|
10
|
+
} from './line-chart-utils';
|
|
7
11
|
import { AxisType, ScaleType } from '../../helpers/enums';
|
|
8
12
|
|
|
9
13
|
/**
|
|
10
14
|
* @param {import('./line-chart.interface').ILineChartOptions} options - line chart options object
|
|
11
15
|
* @param {'x'|'y'} axisType
|
|
12
16
|
* @param {import('../../helpers/chart-interface').IInitialState} state - chart state object controlled by useReducer or similar
|
|
13
|
-
* @param {import('./line-chart.interface').
|
|
17
|
+
* @param {import('./line-chart.interface').ILineChartAxis[]} [currentScales]
|
|
14
18
|
* @param {number} [i]
|
|
15
19
|
*/
|
|
16
20
|
const getLineChartAxis = (options, axisType, state, currentScales, i = 0) => {
|
|
@@ -94,7 +98,8 @@ const getLineChartAxes = (options, axisType, state) => {
|
|
|
94
98
|
axisData.position = curr.position || getAxisPosition(axisType, i);
|
|
95
99
|
|
|
96
100
|
const axis = getLineChartAxis(options, axisType, state, axisData, i);
|
|
97
|
-
|
|
101
|
+
const axisId = generateAxisId(axisType, i, true);
|
|
102
|
+
return { ...acc, [axisId]: axis };
|
|
98
103
|
}, {});
|
|
99
104
|
return axes;
|
|
100
105
|
};
|
|
@@ -169,3 +169,15 @@ export const truncateDecimals = (number, digits) => {
|
|
|
169
169
|
|
|
170
170
|
return truncatedNum / multiplier;
|
|
171
171
|
};
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
*
|
|
175
|
+
* @param {'x'|'y'} axisType
|
|
176
|
+
* @param {number} [index] - axis index; optional, 0 by default
|
|
177
|
+
* @param {boolean} [hasMultiAxes] - optional, false by default
|
|
178
|
+
* @return {string} - e.g. x if chart has singular axes; x1, x2 - in case of multiple axes
|
|
179
|
+
*/
|
|
180
|
+
export const generateAxisId = (axisType, index = 0, hasMultiAxes = false) => {
|
|
181
|
+
const i = hasMultiAxes ? index + 1 : '';
|
|
182
|
+
return `${axisType}${i}`;
|
|
183
|
+
};
|
|
@@ -45,18 +45,20 @@ export interface ILineChartAdditionalAxesOptions {
|
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
export interface
|
|
48
|
+
export interface ILineChartAxis<PositionType> {
|
|
49
49
|
label: string;
|
|
50
50
|
position: PositionType;
|
|
51
51
|
color: string;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
export interface ILineChartAxes {
|
|
55
|
+
x: ILineChartAxis<'top' | 'bottom'>[];
|
|
56
|
+
y: ILineChartAxis<'left' | 'right'>[];
|
|
57
|
+
}
|
|
58
|
+
|
|
54
59
|
export interface ILineChartOptions {
|
|
55
60
|
title: string | string[];
|
|
56
|
-
axes:
|
|
57
|
-
x: ILineChartAxes<'top' | 'bottom'>[];
|
|
58
|
-
y: ILineChartAxes<'left' | 'right'>[];
|
|
59
|
-
};
|
|
61
|
+
axes: ILineChartAxes;
|
|
60
62
|
additionalAxesOptions: ILineChartAdditionalAxesOptions;
|
|
61
63
|
chartStyling: IChartStyling;
|
|
62
64
|
tooltip: ILineChartTooltip;
|
|
@@ -72,6 +72,7 @@ import {
|
|
|
72
72
|
PointStyle,
|
|
73
73
|
} from '../../helpers/enums';
|
|
74
74
|
import { getScalesMinMax } from './get-scales-min-max';
|
|
75
|
+
import { generateAxisId } from './line-chart-utils';
|
|
75
76
|
|
|
76
77
|
ChartJS.register(
|
|
77
78
|
LinearScale,
|
|
@@ -343,7 +344,34 @@ const LineChart = (props) => {
|
|
|
343
344
|
};
|
|
344
345
|
});
|
|
345
346
|
};
|
|
346
|
-
const controlsAxes = getControlsAxes();
|
|
347
|
+
const controlsAxes = getControlsAxes(axes);
|
|
348
|
+
|
|
349
|
+
const getControlsAxesLabels = (propsAxes) => {
|
|
350
|
+
if (!Object.keys(propsAxes)?.length) {
|
|
351
|
+
return [];
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
const getAxesLabels = (axes, axisType) => {
|
|
355
|
+
if (!axes[axisType] || !axes[axisType]?.length) {
|
|
356
|
+
return [];
|
|
357
|
+
} else {
|
|
358
|
+
return axes[axisType].map((axisObj, index) => {
|
|
359
|
+
return {
|
|
360
|
+
id: generateAxisId(axisType, index, axes[axisType].length > 1),
|
|
361
|
+
label: axisObj?.label || '',
|
|
362
|
+
};
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
const axesLabels = [
|
|
368
|
+
...getAxesLabels(propsAxes, AxisType.X),
|
|
369
|
+
...getAxesLabels(propsAxes, AxisType.Y),
|
|
370
|
+
];
|
|
371
|
+
return axesLabels;
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
const controlsAxesLabels = getControlsAxesLabels(props.chart.options.axes);
|
|
347
375
|
|
|
348
376
|
const setAxisValuesInSettings = (chart) => {
|
|
349
377
|
const { scales = {} } = chart || {};
|
|
@@ -385,6 +413,7 @@ const LineChart = (props) => {
|
|
|
385
413
|
>
|
|
386
414
|
<Controls
|
|
387
415
|
axes={controlsAxes}
|
|
416
|
+
controlsAxesLabels={controlsAxesLabels}
|
|
388
417
|
chart={chart}
|
|
389
418
|
headerComponent={headerComponent}
|
|
390
419
|
legendEnabled={state.legendEnabled}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AxisType } from '../../../helpers/enums';
|
|
2
2
|
import { setAnnotations } from '../../../helpers/chart-utils';
|
|
3
|
+
import { generateAxisId } from '../line-chart-utils';
|
|
3
4
|
|
|
4
5
|
const initialState = ({
|
|
5
6
|
axes,
|
|
@@ -11,23 +12,25 @@ const initialState = ({
|
|
|
11
12
|
annotationsData,
|
|
12
13
|
}) => {
|
|
13
14
|
/**
|
|
14
|
-
*
|
|
15
|
+
* getStateAxesByType
|
|
15
16
|
* @param {'x'|'y'} axisType
|
|
16
|
-
* @return {{id: string
|
|
17
|
+
* @return {{id: string}[] | []} returns array of objects describing all chart axis or empty array
|
|
17
18
|
*/
|
|
18
19
|
const getStateAxesByType = (axisType) => {
|
|
19
|
-
if (axes[axisType]
|
|
20
|
+
if (!axes[axisType]) {
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (axes[axisType]?.length > 1) {
|
|
20
25
|
return axes[axisType].map((axisObj, index) => {
|
|
21
26
|
return {
|
|
22
|
-
id:
|
|
23
|
-
label: axisObj.label,
|
|
27
|
+
id: generateAxisId(axisType, index, axes[axisType].length > 1),
|
|
24
28
|
};
|
|
25
29
|
});
|
|
26
30
|
} else {
|
|
27
31
|
return [
|
|
28
32
|
{
|
|
29
|
-
id: axisType,
|
|
30
|
-
label: axes[axisType][0].label,
|
|
33
|
+
id: generateAxisId(axisType),
|
|
31
34
|
},
|
|
32
35
|
];
|
|
33
36
|
}
|