@oliasoft-open-source/charts-library 2.14.0 → 2.14.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oliasoft-open-source/charts-library",
3
- "version": "2.14.0",
3
+ "version": "2.14.1",
4
4
  "description": "React Chart Library (based on Chart.js and react-chart-js-2)",
5
5
  "homepage": "https://gitlab.com/oliasoft-open-source/charts-library",
6
6
  "bugs": {
package/release-notes.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Charts Library Release Notes
2
2
 
3
+ ## 2.14.1
4
+ - Fix save initAxesRange when dataset changed by parent component([OW-11332](https://oliasoft.atlassian.net/browse/OW-11332))
5
+
3
6
  ## 2.14.0
4
7
  - Refactored line chart, for better performance, readable and reduce not needed re-renders
5
8
 
@@ -80,7 +80,14 @@ const LineChart = (props) => {
80
80
  }, [state.lineEnabled, state.pointsEnabled, axes, annotations, graph]);
81
81
 
82
82
  // Call the custom hooks.
83
- useChartState({ chartRef, options, state, dispatch, persistenceId });
83
+ useChartState({
84
+ chartRef,
85
+ options,
86
+ state,
87
+ generatedDatasets,
88
+ dispatch,
89
+ persistenceId,
90
+ });
84
91
 
85
92
  const { resetZoom, handleDownload, handleKeyDown, handleKeyUp } =
86
93
  useChartFunctions({
@@ -75,26 +75,38 @@ const useUpdateAxesRanges = (range, dispatch) => {
75
75
  };
76
76
 
77
77
  /**
78
- * Hook for saving the initial axes ranges in the chart state.
78
+ * A custom hook to save the initial axes ranges of a chart when the generated datasets change.
79
79
  *
80
- * @param chartRef - The reference to the chart.
81
- * @param axes - The axes data.
82
- * @param dispatch - The dispatch function for state management.
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.
83
84
  */
84
- const useSaveInitialAxesRanges = (chartRef, axes, dispatch) => {
85
+ const useSaveInitialAxesRanges = (
86
+ chartRef,
87
+ axes,
88
+ generatedDatasets,
89
+ dispatch,
90
+ ) => {
91
+ const prevGeneratedDatasets = useRef();
92
+
85
93
  const saveInitialAxesRanges = useCallback(() => {
86
- if (chartRef) {
94
+ if (
95
+ chartRef &&
96
+ !isEqual(generatedDatasets, prevGeneratedDatasets.current)
97
+ ) {
87
98
  const initialAxesRanges = getAxesRangesFromChart(chartRef, axes);
88
99
  dispatch({
89
100
  type: SAVE_INITIAL_AXES_RANGES,
90
101
  payload: { initialAxesRanges },
91
102
  });
103
+ prevGeneratedDatasets.current = generatedDatasets;
92
104
  }
93
- }, [chartRef]);
105
+ }, [chartRef, generatedDatasets]);
94
106
 
95
107
  useEffect(() => {
96
108
  saveInitialAxesRanges();
97
- }, [saveInitialAxesRanges]);
109
+ }, [saveInitialAxesRanges, generatedDatasets]);
98
110
  };
99
111
 
100
112
  /**
@@ -103,6 +115,7 @@ const useSaveInitialAxesRanges = (chartRef, axes, dispatch) => {
103
115
  * @param chartRef - The reference to the chart.
104
116
  * @param options - The chart options.
105
117
  * @param state - The chart state.
118
+ * @param {Array} generatedDatasets - An array of generated datasets for the chart.
106
119
  * @param dispatch - The dispatch function for state management.
107
120
  * @param persistenceId - The chart persistenceId.
108
121
  */
@@ -110,6 +123,7 @@ export const useChartState = ({
110
123
  chartRef,
111
124
  options,
112
125
  state,
126
+ generatedDatasets,
113
127
  dispatch,
114
128
  persistenceId,
115
129
  }) => {
@@ -123,5 +137,5 @@ export const useChartState = ({
123
137
  useStoreChartStateInStorage(memoState, persistenceId);
124
138
  useToggleCustomLegendVisibility(memoState, memoOptions);
125
139
  useUpdateAxesRanges(range, dispatch);
126
- useSaveInitialAxesRanges(chartRef, axes, dispatch);
140
+ useSaveInitialAxesRanges(chartRef, axes, generatedDatasets, dispatch);
127
141
  };