@oliasoft-open-source/charts-library 2.5.12 → 2.5.13
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 +1 -1
- package/release-notes.md +4 -0
- package/src/components/line-chart/get-scales-min-max.js +12 -0
- package/src/components/line-chart/line-chart.jsx +26 -37
- package/src/components/line-chart/state/action-types.js +1 -0
- package/src/components/line-chart/state/initial-state.js +1 -1
- package/src/components/line-chart/state/line-chart-reducer.js +6 -0
package/package.json
CHANGED
package/release-notes.md
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const getScalesMinMax = (chartRef) => {
|
|
2
|
+
const { scales = {} } = chartRef.current || {};
|
|
3
|
+
return Object.keys(scales).reduce((acc, key) => {
|
|
4
|
+
return {
|
|
5
|
+
...acc,
|
|
6
|
+
[key]: {
|
|
7
|
+
min: scales[key]?.min,
|
|
8
|
+
max: scales[key]?.max,
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
}, {});
|
|
12
|
+
};
|
|
@@ -21,6 +21,7 @@ import styles from './line-chart.module.less';
|
|
|
21
21
|
import { reducer } from './state/line-chart-reducer';
|
|
22
22
|
import initialState from './state/initial-state';
|
|
23
23
|
import {
|
|
24
|
+
SET_AXIS_MIN_MAX,
|
|
24
25
|
SET_AXIS_VALUE,
|
|
25
26
|
SET_POINTS_ZOOM_DEFAULTS,
|
|
26
27
|
TOGGLE_ANNOTATION,
|
|
@@ -70,6 +71,7 @@ import {
|
|
|
70
71
|
PanZoomMode,
|
|
71
72
|
PointStyle,
|
|
72
73
|
} from '../../helpers/enums';
|
|
74
|
+
import { getScalesMinMax } from './get-scales-min-max';
|
|
73
75
|
|
|
74
76
|
ChartJS.register(
|
|
75
77
|
LinearScale,
|
|
@@ -131,6 +133,9 @@ const LineChart = (props) => {
|
|
|
131
133
|
if (chartOptions.enablePan !== true) {
|
|
132
134
|
dispatch({ type: TOGGLE_PAN });
|
|
133
135
|
}
|
|
136
|
+
if (chartRef) {
|
|
137
|
+
dispatch({ type: SET_AXIS_MIN_MAX, payload: getScalesMinMax(chartRef) });
|
|
138
|
+
}
|
|
134
139
|
}, []);
|
|
135
140
|
|
|
136
141
|
useEffect(() => {
|
|
@@ -341,47 +346,31 @@ const LineChart = (props) => {
|
|
|
341
346
|
const controlsAxes = getControlsAxes();
|
|
342
347
|
|
|
343
348
|
const setAxisValuesInSettings = (chart) => {
|
|
349
|
+
const { scales = {} } = chart || {};
|
|
350
|
+
const getPayload = (scales) => {
|
|
351
|
+
return Object.keys(scales).reduce((acc, key) => {
|
|
352
|
+
return [
|
|
353
|
+
...acc,
|
|
354
|
+
{
|
|
355
|
+
name: 'min',
|
|
356
|
+
value: scales[key]?.min ? scales[key].min : 0,
|
|
357
|
+
id: key,
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
name: 'max',
|
|
361
|
+
value: scales[key]?.max ? scales[key].max : 0,
|
|
362
|
+
id: key,
|
|
363
|
+
},
|
|
364
|
+
];
|
|
365
|
+
}, []);
|
|
366
|
+
};
|
|
367
|
+
|
|
344
368
|
dispatch({
|
|
345
369
|
type: SET_AXIS_VALUE,
|
|
346
|
-
payload:
|
|
347
|
-
{
|
|
348
|
-
name: 'min',
|
|
349
|
-
value: chart.scales?.x?.min ? chart.scales.x.min : 0,
|
|
350
|
-
id: 'x',
|
|
351
|
-
},
|
|
352
|
-
{
|
|
353
|
-
name: 'max',
|
|
354
|
-
value: chart.scales?.x?.max ? chart.scales.x.max : 0,
|
|
355
|
-
id: 'x',
|
|
356
|
-
},
|
|
357
|
-
{
|
|
358
|
-
name: 'min',
|
|
359
|
-
value: chart.scales?.y?.min ? chart.scales.y.min : 0,
|
|
360
|
-
id: 'y',
|
|
361
|
-
},
|
|
362
|
-
{
|
|
363
|
-
name: 'max',
|
|
364
|
-
value: chart.scales?.y?.max ? chart.scales.y.max : 0,
|
|
365
|
-
id: 'y',
|
|
366
|
-
},
|
|
367
|
-
],
|
|
370
|
+
payload: getPayload(scales),
|
|
368
371
|
});
|
|
369
372
|
};
|
|
370
373
|
|
|
371
|
-
const getScalesMaxMin = () => {
|
|
372
|
-
const chart = chartRef.current;
|
|
373
|
-
return {
|
|
374
|
-
x: {
|
|
375
|
-
min: chart?.scales?.x?.min,
|
|
376
|
-
max: chart?.scales?.x?.max,
|
|
377
|
-
},
|
|
378
|
-
y: {
|
|
379
|
-
min: chart?.scales?.y?.min,
|
|
380
|
-
max: chart?.scales?.y?.max,
|
|
381
|
-
},
|
|
382
|
-
};
|
|
383
|
-
};
|
|
384
|
-
|
|
385
374
|
return (
|
|
386
375
|
<div
|
|
387
376
|
className={getClassName(chartStyling, styles)}
|
|
@@ -415,7 +404,7 @@ const LineChart = (props) => {
|
|
|
415
404
|
onToggleZoom={() => dispatch({ type: TOGGLE_ZOOM })}
|
|
416
405
|
panEnabled={state.panEnabled}
|
|
417
406
|
pointsEnabled={state.pointsEnabled}
|
|
418
|
-
scalesMaxMin={
|
|
407
|
+
scalesMaxMin={state.scalesMinMax}
|
|
419
408
|
showTable={state.showTable}
|
|
420
409
|
subheaderComponent={subheaderComponent}
|
|
421
410
|
table={table}
|
|
@@ -8,3 +8,4 @@ export const SET_AXIS_VALUE = 'SET_AXIS_VALUE';
|
|
|
8
8
|
export const SET_POINTS_ZOOM_DEFAULTS = 'SET_POINTS_ZOOM_DEFAULTS';
|
|
9
9
|
export const TOGGLE_ANNOTATION = 'TOGGLE_ANNOTATION';
|
|
10
10
|
export const TOGGLE_TABLE = 'TOGGLE_TABLE';
|
|
11
|
+
export const SET_AXIS_MIN_MAX = 'SET_AXIS_MIN_MAX';
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
SET_POINTS_ZOOM_DEFAULTS,
|
|
17
17
|
TOGGLE_ANNOTATION,
|
|
18
18
|
TOGGLE_TABLE,
|
|
19
|
+
SET_AXIS_MIN_MAX,
|
|
19
20
|
} from './action-types';
|
|
20
21
|
import { getAxisValue } from '../../../helpers/chart-utils';
|
|
21
22
|
|
|
@@ -137,6 +138,11 @@ export const reducer = (state, action) => {
|
|
|
137
138
|
...newState,
|
|
138
139
|
showAnnotationLineIndex: updatedIndexes,
|
|
139
140
|
};
|
|
141
|
+
case SET_AXIS_MIN_MAX:
|
|
142
|
+
return {
|
|
143
|
+
...newState,
|
|
144
|
+
scalesMinMax: action.payload,
|
|
145
|
+
};
|
|
140
146
|
default: {
|
|
141
147
|
return newState;
|
|
142
148
|
}
|