@oliasoft-open-source/charts-library 4.7.9 → 4.8.0-beta-2

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
@@ -6,10 +6,10 @@ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
6
6
  import * as React from "react";
7
7
  import React__default, { forwardRef, useRef, useEffect, createContext as createContext$2, memo, useLayoutEffect, useState, useCallback, useMemo, isValidElement, cloneElement, useContext, useReducer } from "react";
8
8
  import { produce } from "immer";
9
- import { round as round$2, displayNumber, isCloseTo, roundByMagnitude } from "@oliasoft-open-source/units";
9
+ import { round as round$2, displayNumber, roundByMagnitude } from "@oliasoft-open-source/units";
10
10
  import cx from "classnames";
11
11
  import { Portal, Icon, Menu, Tooltip as Tooltip$2, Button, Popover, Field, InputGroup, NumberInput, InputGroupAddon, Select, ButtonGroup, Spacer, Flex, Text } from "@oliasoft-open-source/react-ui-library";
12
- import { isEmpty, isArray as isArray$2, some, has, isNil, cloneDeep, defaultTo, findIndex, set as set$2, debounce as debounce$3, map as map$3, find, get as get$1, noop as noop$2 } from "lodash";
12
+ import { isEmpty, isArray as isArray$2, some, has, cloneDeep, defaultTo, findIndex, set as set$2, debounce as debounce$3, isNil, map as map$3, find, get as get$1, noop as noop$2 } from "lodash";
13
13
  /*!
14
14
  * @kurkle/color v0.3.2
15
15
  * https://github.com/kurkle/color#readme
@@ -22723,8 +22723,6 @@ const ANIMATION_DURATION = {
22723
22723
  };
22724
22724
  const DEFAULT_CHART_NAME = "new_chart";
22725
22725
  const CUSTOM_LEGEND_PLUGIN_NAME = "htmlLegend";
22726
- const DECIMAL_POINT_TOLERANCE = 9;
22727
- const MAX_DECIMAL_DIFF = 1 / 10 ** DECIMAL_POINT_TOLERANCE;
22728
22726
  const GRADIENT_COLORS = [
22729
22727
  { offset: 0, color: "rgba(144,238,144,0.8)" },
22730
22728
  // Light green
@@ -22878,10 +22876,6 @@ const generateAxisId = (axisType, index2 = 0, hasMultiAxes = false) => {
22878
22876
  const i2 = hasMultiAxes && index2 !== 0 ? index2 + 1 : "";
22879
22877
  return `${axisType}${i2}`;
22880
22878
  };
22881
- const getAxisTypeFromKey = (string) => {
22882
- var _a2;
22883
- return ((_a2 = string == null ? void 0 : string.match(/[^0-9/]+/gi)) == null ? void 0 : _a2[0]) ?? "";
22884
- };
22885
22879
  const generateKey = (values) => {
22886
22880
  const key = values.join("");
22887
22881
  return key;
@@ -25172,29 +25166,6 @@ const generateLineChartDatasets = (datasets, state, options, { label }) => {
25172
25166
  };
25173
25167
  });
25174
25168
  };
25175
- const getAnnotationsData = (data) => {
25176
- return data == null ? void 0 : data.reduce((acc, obj) => {
25177
- return {
25178
- ...acc,
25179
- [obj.annotationAxis]: [...acc[obj.annotationAxis] || [], +obj.value]
25180
- };
25181
- }, {});
25182
- };
25183
- const getAxisRangeByType = (chartRef, axesType, annotationsData) => {
25184
- if (!chartRef || !chartRef.current) return null;
25185
- const metasets = chartRef.current.getSortedVisibleDatasetMetas();
25186
- const annotDataByType = getAnnotationsData(annotationsData)[axesType] ?? [];
25187
- let allData = [];
25188
- metasets.forEach((metaset) => {
25189
- const data = metaset._parsed.map((parsedData) => parsedData[axesType]).filter((value) => value != null && !isNaN(value));
25190
- allData = allData.concat(data);
25191
- });
25192
- allData = allData.concat(annotDataByType);
25193
- if (allData.length === 0) return null;
25194
- const min = Math.min(...allData);
25195
- const max = Math.max(...allData);
25196
- return { min, max };
25197
- };
25198
25169
  const calculateDelta$1 = (tickValue, ticks) => {
25199
25170
  let delta = ticks.length > 3 ? ticks[2].value - ticks[1].value : ticks[1].value - ticks[0].value;
25200
25171
  if (Math.abs(delta) >= 1 && tickValue !== Math.floor(Number(tickValue))) {
@@ -25301,142 +25272,9 @@ const getLineChartScales = (options, state) => {
25301
25272
  ...yAxes
25302
25273
  };
25303
25274
  };
25304
- const estimateDataSeriesHaveCloseValues = (generatedDatasets) => {
25305
- var _a2;
25306
- if (!Array.isArray(generatedDatasets) || !(generatedDatasets == null ? void 0 : generatedDatasets.length)) {
25307
- return false;
25308
- }
25309
- const axesFirstLast = generatedDatasets == null ? void 0 : generatedDatasets.reduce((acc, dataset) => {
25310
- var _a3, _b2, _c2, _d2;
25311
- const xAxisId = (dataset == null ? void 0 : dataset.xAxisID) ?? "defaultX";
25312
- const yAxisId = (dataset == null ? void 0 : dataset.yAxisID) ?? "defaultY";
25313
- const data = (dataset == null ? void 0 : dataset.data) ?? [];
25314
- if (data && (data == null ? void 0 : data.length)) {
25315
- const { x: xFirstCurrent, y: yFirstCurrent } = (data == null ? void 0 : data[0]) ?? {};
25316
- const { x: xLastCurrent = 0, y: yLastCurrent = 0 } = (data == null ? void 0 : data.at(-1)) ?? {};
25317
- const xFirstAcc = ((_a3 = acc == null ? void 0 : acc[xAxisId]) == null ? void 0 : _a3.xFirst) ?? xFirstCurrent;
25318
- const xLastAcc = ((_b2 = acc == null ? void 0 : acc[xAxisId]) == null ? void 0 : _b2.xLast) ?? xLastCurrent;
25319
- const yFirstAcc = ((_c2 = acc == null ? void 0 : acc[yAxisId]) == null ? void 0 : _c2.yFirst) ?? yFirstCurrent;
25320
- const yLastAcc = ((_d2 = acc == null ? void 0 : acc[yAxisId]) == null ? void 0 : _d2.yLast) ?? yLastCurrent;
25321
- const xFirst = Math.min(xFirstCurrent, xFirstAcc);
25322
- const xLast = Math.max(xLastCurrent, xLastAcc);
25323
- const yFirst = Math.min(yFirstCurrent, yFirstAcc);
25324
- const yLast = Math.max(yLastCurrent, yLastAcc);
25325
- acc = {
25326
- ...acc,
25327
- [xAxisId]: {
25328
- ...acc[xAxisId],
25329
- xFirst,
25330
- xLast
25331
- },
25332
- [yAxisId]: {
25333
- yFirst,
25334
- yLast
25335
- }
25336
- };
25337
- }
25338
- return acc;
25339
- }, {});
25340
- return (_a2 = Object.values(axesFirstLast)) == null ? void 0 : _a2.some(({ xFirst, xLast, yFirst, yLast }) => {
25341
- return isCloseTo(xFirst, xLast, { absoluteDiff: MAX_DECIMAL_DIFF }) || isCloseTo(yFirst, yLast, { absoluteDiff: MAX_DECIMAL_DIFF });
25342
- });
25343
- };
25344
- const whiteSpacePercentage = 0.05;
25345
- const defaultRange = { min: -1, max: 1 };
25346
- const getSuggestedAxisRange = ({
25347
- data,
25348
- beginAtZero = false,
25349
- autoAxisPadding = false
25350
- }) => {
25351
- const dataMin = Math.min(
25352
- ...data.filter((v2) => v2 !== null && v2 !== void 0 && !isNaN(v2))
25353
- );
25354
- const dataMax = Math.max(
25355
- ...data.filter((v2) => v2 !== null && v2 !== void 0 && !isNaN(v2))
25356
- );
25357
- const isNegative = Math.sign(dataMin) === -1 || Math.sign(dataMax) === -1;
25358
- const isCloseToZeroWithTolerance = isCloseTo(dataMin, 0, { absoluteDiff: MAX_DECIMAL_DIFF }) && isCloseTo(dataMax, 0, { absoluteDiff: MAX_DECIMAL_DIFF });
25359
- if (!(data == null ? void 0 : data.length) || isCloseToZeroWithTolerance) {
25360
- return defaultRange;
25361
- }
25362
- if (isCloseTo(dataMin, dataMax, { absoluteDiff: MAX_DECIMAL_DIFF })) {
25363
- const point = dataMax;
25364
- const padding2 = point * whiteSpacePercentage;
25365
- const minAxisValue2 = beginAtZero && !isNegative ? 0 : point - padding2;
25366
- const maxAxisValue2 = beginAtZero && isNegative ? 0 : point + padding2;
25367
- const roundedMinAxisValue = round$2(maxAxisValue2, DECIMAL_POINT_TOLERANCE);
25368
- const roundedMaxAxisValue = round$2(minAxisValue2, DECIMAL_POINT_TOLERANCE);
25369
- return {
25370
- min: roundedMinAxisValue < 0 ? roundedMinAxisValue : roundedMaxAxisValue,
25371
- max: roundedMaxAxisValue < 0 ? roundedMaxAxisValue : roundedMinAxisValue
25372
- };
25373
- }
25374
- if (!autoAxisPadding) {
25375
- return {
25376
- min: void 0,
25377
- max: void 0
25378
- };
25379
- }
25380
- const rangeBeginAtZero = dataMin === 0 || dataMax === 0 || beginAtZero;
25381
- const positiveAndNegative = Math.sign(dataMin) === -1 && Math.sign(dataMax) === 1;
25382
- const range = Math.abs(dataMax - dataMin);
25383
- const padding = autoAxisPadding ? range * whiteSpacePercentage : 0;
25384
- const minAxisValue = !positiveAndNegative && rangeBeginAtZero && beginAtZero && !isNegative ? 0 : dataMin - padding;
25385
- const maxAxisValue = !positiveAndNegative && rangeBeginAtZero && beginAtZero && isNegative ? 0 : dataMax + padding;
25386
- return {
25387
- min: round$2(minAxisValue, DECIMAL_POINT_TOLERANCE),
25388
- max: round$2(maxAxisValue, DECIMAL_POINT_TOLERANCE)
25389
- };
25390
- };
25391
- const getAxesDataFromMetasets = (chartRef, scalesKeys, annotationsData) => {
25392
- var _a2;
25393
- if (!chartRef || !scalesKeys) return {};
25394
- const metasets = ((_a2 = chartRef == null ? void 0 : chartRef.current) == null ? void 0 : _a2.getSortedVisibleDatasetMetas()) ?? [];
25395
- const annotData = getAnnotationsData(annotationsData);
25396
- return metasets && (scalesKeys == null ? void 0 : scalesKeys.reduce((acc, key) => {
25397
- const data = metasets.filter((dataset) => Object.values(dataset).includes(key)).flatMap((dataset) => dataset._parsed).map((parsedData) => parsedData[getAxisTypeFromKey(key)]).concat((annotData == null ? void 0 : annotData[key]) ?? []);
25398
- return {
25399
- ...acc,
25400
- [key]: [...new Set(data)]
25401
- };
25402
- }, {}));
25403
- };
25404
- const shouldCalculate = (min, max) => !isNil(min) || !isNil(max);
25405
- const autoScale = (options, state, generatedDatasets, chartRef) => {
25406
- const {
25407
- additionalAxesOptions,
25408
- annotations: { annotationsData = [], controlAnnotation = false } = {}
25409
- } = options || {};
25275
+ const autoScale = (options, state) => {
25410
25276
  const scales = getLineChartScales(options, state) || {};
25411
- const datasets = controlAnnotation ? generatedDatasets.filter(({ isAnnotation }) => !isAnnotation) : generatedDatasets;
25412
- if (!(additionalAxesOptions == null ? void 0 : additionalAxesOptions.autoAxisPadding) && !estimateDataSeriesHaveCloseValues(datasets)) {
25413
- return scales;
25414
- }
25415
- const scalesKeys = Object.keys(scales) ?? [];
25416
- const data = getAxesDataFromMetasets(
25417
- chartRef,
25418
- scalesKeys,
25419
- annotationsData
25420
- );
25421
- const adjustedScales = data && (scalesKeys == null ? void 0 : scalesKeys.reduce((acc, key) => {
25422
- const scale = scales[key];
25423
- const { min: propMin = void 0, max: propMax = void 0 } = scale;
25424
- const { min: calcMin, max: calcMax } = getAxisRangeByType(chartRef, key, annotationsData) ?? {};
25425
- const { min: suggestedMin, max: suggestedMax } = getSuggestedAxisRange({
25426
- data: data[key],
25427
- beginAtZero: additionalAxesOptions == null ? void 0 : additionalAxesOptions.beginAtZero,
25428
- autoAxisPadding: additionalAxesOptions == null ? void 0 : additionalAxesOptions.autoAxisPadding
25429
- });
25430
- const res = {
25431
- [key]: {
25432
- ...scale,
25433
- min: propMin ?? (shouldCalculate(propMin, propMax) ? calcMin : suggestedMin),
25434
- max: propMax ?? (shouldCalculate(propMin, propMax) ? calcMax : suggestedMax)
25435
- }
25436
- };
25437
- return { ...acc, ...res };
25438
- }, {}));
25439
- return adjustedScales ?? scales;
25277
+ return scales;
25440
25278
  };
25441
25279
  const getCondition = (x2, y2, left2, right2, bottom2) => {
25442
25280
  const threshold = 100;
@@ -25986,7 +25824,7 @@ const useChartOptions = ({
25986
25824
  const datalabels = getLineChartDataLabels(options);
25987
25825
  const tooltip = getLineChartToolTips(options);
25988
25826
  const scales = useMemo(
25989
- () => autoScale(options, state, generatedDatasets, chartRef),
25827
+ () => autoScale(options, state),
25990
25828
  [options, state, generatedDatasets, chartRef]
25991
25829
  );
25992
25830
  const dragData = useMemo(
@@ -26106,6 +25944,29 @@ const useChartPlugins = ({ options, resetZoom: resetZoom2 }) => {
26106
25944
  ];
26107
25945
  }, [handleDoubleClick]);
26108
25946
  };
25947
+ const getAnnotationsData = (data) => {
25948
+ return data == null ? void 0 : data.reduce((acc, obj) => {
25949
+ return {
25950
+ ...acc,
25951
+ [obj.annotationAxis]: [...acc[obj.annotationAxis] || [], +obj.value]
25952
+ };
25953
+ }, {});
25954
+ };
25955
+ const getAxisRangeByType = (chartRef, axesType, annotationsData) => {
25956
+ if (!chartRef || !chartRef.current) return null;
25957
+ const metasets = chartRef.current.getSortedVisibleDatasetMetas();
25958
+ const annotDataByType = getAnnotationsData(annotationsData)[axesType] ?? [];
25959
+ let allData = [];
25960
+ metasets.forEach((metaset) => {
25961
+ const data = metaset._parsed.map((parsedData) => parsedData[axesType]).filter((value) => value != null && !isNaN(value));
25962
+ allData = allData.concat(data);
25963
+ });
25964
+ allData = allData.concat(annotDataByType);
25965
+ if (allData.length === 0) return null;
25966
+ const min = Math.min(...allData);
25967
+ const max = Math.max(...allData);
25968
+ return { min, max };
25969
+ };
26109
25970
  const useToggleCustomLegendVisibility = (memoState, memoOptions) => {
26110
25971
  var _a2, _b2;
26111
25972
  useEffect(() => {