@oliasoft-open-source/charts-library 2.5.8 → 2.5.10

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oliasoft-open-source/charts-library",
3
- "version": "2.5.8",
3
+ "version": "2.5.10",
4
4
  "description": "React Chart Library (based on Chart.js and react-chart-js-2)",
5
5
  "main": "index.js",
6
6
  "files": [
package/release-notes.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Charts Library Release Notes
2
2
 
3
+ ## 2.5.10
4
+
5
+ - Fix zoom / pan bug at < 0.1 scale on charts
6
+
7
+ ## 2.5.9
8
+
9
+ - Fix validation for two and more decimal places in charts settings
10
+
3
11
  ## 2.5.8
4
12
 
5
13
  - Disable tooltip animations in `performanceMode`
@@ -25,6 +25,7 @@ const AxesOptionsPopover = ({
25
25
  axes.filter((axis) => axis.max.displayValue || axis.min.displayValue)
26
26
  .length > 0;
27
27
  const handleInputFocus = (e) => e.target.select();
28
+ const zoomOrPanEnabled = zoomEnabled || panEnabled;
28
29
  return (
29
30
  <>
30
31
  {axes.map((axis, i) => {
@@ -36,7 +37,11 @@ const AxesOptionsPopover = ({
36
37
  <Input
37
38
  name="min"
38
39
  // TODO: Fix input values not updating first time when scales reset
39
- value={axis.min.inputValue || scalesMaxMin[axis?.id]?.min}
40
+ value={
41
+ (zoomOrPanEnabled
42
+ ? axis.min.displayValue
43
+ : axis.min.inputValue) || scalesMaxMin[axis?.id]?.min
44
+ }
40
45
  error={
41
46
  !axis.min.valid
42
47
  ? 'Invalid value' //t(InputWarningType.MustBeNumericAndLessThanMax)
@@ -61,7 +66,11 @@ const AxesOptionsPopover = ({
61
66
  <Input
62
67
  name="max"
63
68
  // TODO: Fix input values not updating first time when scales reset
64
- value={axis.max.inputValue || scalesMaxMin[axis?.id]?.max}
69
+ value={
70
+ (zoomOrPanEnabled
71
+ ? axis.max.displayValue
72
+ : axis.max.inputValue) || scalesMaxMin[axis?.id]?.max
73
+ }
65
74
  error={
66
75
  !axis.max.valid
67
76
  ? 'Invalid value' //t(InputWarningType.MustBeNumericAndGreaterThanMin)
@@ -3,7 +3,7 @@ import {
3
3
  getAxisPosition,
4
4
  } from '../../helpers/chart-utils';
5
5
  import { COLORS, LOGARITHMIC_STEPS } from '../../helpers/chart-consts';
6
- import { truncateDecimals } from './line-chart-utils';
6
+ import { truncateDecimals, validNumber } from './line-chart-utils';
7
7
  import { AxisType, ScaleType } from '../../helpers/enums';
8
8
 
9
9
  /**
@@ -57,12 +57,14 @@ const getLineChartAxis = (options, axisType, state, currentScales, i = 0) => {
57
57
  reverse: axisType === AxisType.Y ? additionalAxesOptions.reverse : false,
58
58
  suggestedMax: additionalAxesOptions.suggestedMax,
59
59
  suggestedMin: additionalAxesOptions.suggestedMin,
60
- min: stateAxis.min?.valid
61
- ? stateAxis.min?.value
62
- : additionalAxesOptions?.range?.[axisType]?.min,
63
- max: stateAxis.max?.valid
64
- ? stateAxis.max?.value
65
- : additionalAxesOptions?.range?.[axisType]?.max,
60
+ min:
61
+ stateAxis.min?.valid && validNumber(stateAxis.min?.value)
62
+ ? Number(stateAxis.min?.value)
63
+ : additionalAxesOptions?.range?.[axisType]?.min,
64
+ max:
65
+ stateAxis.max?.valid && validNumber(stateAxis.max?.value)
66
+ ? Number(stateAxis.max?.value)
67
+ : additionalAxesOptions?.range?.[axisType]?.max,
66
68
  title: {
67
69
  display: axisData.label?.length,
68
70
  text: axisData.label,
@@ -144,11 +144,15 @@ export const toNum = (value) => {
144
144
  };
145
145
 
146
146
  export const isLessThanMax = (value, max) => {
147
- return value === undefined || max === undefined || value < max;
147
+ return (
148
+ value === undefined || max === undefined || Number(value) < Number(max)
149
+ );
148
150
  };
149
151
 
150
152
  export const isGreaterThanMin = (value, min) => {
151
- return value === undefined || min === undefined || value > min;
153
+ return (
154
+ value === undefined || min === undefined || Number(value) > Number(min)
155
+ );
152
156
  };
153
157
 
154
158
  /**
@@ -346,22 +346,22 @@ const LineChart = (props) => {
346
346
  payload: [
347
347
  {
348
348
  name: 'min',
349
- value: chart.scales?.x?.min ? chart.scales.x.min.toFixed(1) : 0,
349
+ value: chart.scales?.x?.min ? chart.scales.x.min : 0,
350
350
  id: 'x',
351
351
  },
352
352
  {
353
353
  name: 'max',
354
- value: chart.scales?.x?.max ? chart.scales.x.max.toFixed(1) : 0,
354
+ value: chart.scales?.x?.max ? chart.scales.x.max : 0,
355
355
  id: 'x',
356
356
  },
357
357
  {
358
358
  name: 'min',
359
- value: chart.scales?.y?.min ? chart.scales.y.min.toFixed(1) : 0,
359
+ value: chart.scales?.y?.min ? chart.scales.y.min : 0,
360
360
  id: 'y',
361
361
  },
362
362
  {
363
363
  name: 'max',
364
- value: chart.scales?.y?.max ? chart.scales.y.max.toFixed(1) : 0,
364
+ value: chart.scales?.y?.max ? chart.scales.y.max : 0,
365
365
  id: 'y',
366
366
  },
367
367
  ],
@@ -79,9 +79,7 @@ export const reducer = (state, action) => {
79
79
  }
80
80
  case SET_AXIS_VALUE: {
81
81
  const valiateElement = (name, nextInputValue, id) => {
82
- const nextValue = isNaN(nextInputValue)
83
- ? cleanNumStr(nextInputValue)
84
- : toNum(nextInputValue);
82
+ const nextValue = cleanNumStr(nextInputValue);
85
83
 
86
84
  const axis = newState.axes.find((a) => a.id === id);
87
85
  axis.min = getAxisValue(name === 'min' ? nextValue : axis.min?.value);
@@ -89,11 +87,18 @@ export const reducer = (state, action) => {
89
87
  axis.min.valid =
90
88
  validNumber(axis.min.inputValue ?? '') &&
91
89
  isLessThanMax(axis.min.value, axis.max.value);
92
- axis.min.displayValue = axis.min.valid ? axis.min.value : undefined;
90
+ axis.min.displayValue =
91
+ axis.min.valid && axis.min.value
92
+ ? Number(axis.min.value).toFixed(1)
93
+ : undefined;
94
+
93
95
  axis.max.valid =
94
96
  validNumber(axis.max.inputValue ?? '') &&
95
97
  isGreaterThanMin(axis.max.value, axis.min.value);
96
- axis.max.displayValue = axis.max.valid ? axis.max.value : undefined;
98
+ axis.max.displayValue =
99
+ axis.max.valid && axis.max.value
100
+ ? Number(axis.max.value).toFixed(1)
101
+ : undefined;
97
102
 
98
103
  const elementValue = axis[name];
99
104
  if (elementValue.valid) {