@oliasoft-open-source/charts-library 3.6.0 → 3.6.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/dist/index.js CHANGED
@@ -25828,6 +25828,23 @@ const getAxesRangesFromChart = (chartRef, axes) => {
25828
25828
  };
25829
25829
  });
25830
25830
  };
25831
+ const getAxisRangeByType = (chartRef, axesType, annotationsData) => {
25832
+ if (!chartRef || !chartRef.current)
25833
+ return null;
25834
+ const metasets = chartRef.current.getSortedVisibleDatasetMetas();
25835
+ const annotDataByType = getAnnotationsData(annotationsData)[axesType] ?? [];
25836
+ let allData = [];
25837
+ metasets.forEach((metaset) => {
25838
+ const data = metaset._parsed.map((parsedData) => parsedData[axesType]).filter((value) => value != null && !isNaN(value));
25839
+ allData = allData.concat(data);
25840
+ });
25841
+ allData = allData.concat(annotDataByType);
25842
+ if (allData.length === 0)
25843
+ return null;
25844
+ const min = Math.min(...allData);
25845
+ const max = Math.max(...allData);
25846
+ return { min, max };
25847
+ };
25831
25848
  const useToggleCustomLegendVisibility = (memoState, memoOptions) => {
25832
25849
  var _a2, _b2;
25833
25850
  useEffect(() => {
@@ -25858,18 +25875,23 @@ const useStoreChartStateInStorage = (memoState, persistenceId) => {
25858
25875
  ]);
25859
25876
  };
25860
25877
  const useUpdateAxesRanges = ({
25878
+ chartRef,
25861
25879
  range,
25862
25880
  state,
25863
- dispatch
25881
+ dispatch,
25882
+ annotationsData
25864
25883
  }) => {
25865
25884
  const prevAxes = useRef(state.axes);
25866
25885
  useEffect(() => {
25867
25886
  if (range && isRangeValid(range)) {
25868
- const newAxes = Object.entries(range).map(([key, { min, max }]) => ({
25869
- id: key,
25870
- min: min ?? 0,
25871
- max: max ?? 0
25872
- }));
25887
+ const newAxes = Object.entries(range).map(([key, { min, max }]) => {
25888
+ const { min: minFromData = 0, max: maxFromData = 0 } = getAxisRangeByType(chartRef, key, annotationsData) ?? {};
25889
+ return {
25890
+ id: key,
25891
+ min: min ?? minFromData,
25892
+ max: max ?? maxFromData
25893
+ };
25894
+ });
25873
25895
  const mergedAxes = [...prevAxes.current ?? []].map((axis) => {
25874
25896
  const newAxis = newAxes.find((a2) => a2.id === axis.id);
25875
25897
  return newAxis ? { ...axis, ...newAxis } : axis;
@@ -25912,11 +25934,18 @@ const useChartState = ({
25912
25934
  const memoOptions = useMemo(() => options, [options]);
25913
25935
  const {
25914
25936
  additionalAxesOptions: { range = void 0 },
25937
+ annotations: { annotationsData = [] } = {},
25915
25938
  axes
25916
25939
  } = memoOptions;
25917
25940
  useStoreChartStateInStorage(memoState, persistenceId);
25918
25941
  useToggleCustomLegendVisibility(memoState, memoOptions);
25919
- useUpdateAxesRanges({ range, state: memoState, dispatch });
25942
+ useUpdateAxesRanges({
25943
+ range,
25944
+ state: memoState,
25945
+ dispatch,
25946
+ chartRef,
25947
+ annotationsData
25948
+ });
25920
25949
  useSaveInitialAxesRanges(chartRef, axes, generatedDatasets, dispatch);
25921
25950
  };
25922
25951
  const WORD_SEPARATOR = " ";