@oliasoft-open-source/charts-library 4.8.0-beta-3 → 4.8.0-beta-5
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, roundByMagnitude } from "@oliasoft-open-source/units";
|
|
9
|
+
import { round as round$2, displayNumber, isCloseTo, 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 { cloneDeep, defaultTo, findIndex, set as set$2, debounce as debounce$3,
|
|
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";
|
|
13
13
|
/*!
|
|
14
14
|
* @kurkle/color v0.3.2
|
|
15
15
|
* https://github.com/kurkle/color#readme
|
|
@@ -22723,6 +22723,8 @@ 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;
|
|
22726
22728
|
const GRADIENT_COLORS = [
|
|
22727
22729
|
{ offset: 0, color: "rgba(144,238,144,0.8)" },
|
|
22728
22730
|
// Light green
|
|
@@ -22854,18 +22856,6 @@ const setDefaultTheme = () => {
|
|
|
22854
22856
|
defaults$2.color = DEFAULT_COLOR;
|
|
22855
22857
|
defaults$2.borderColor = BORDER_COLOR;
|
|
22856
22858
|
};
|
|
22857
|
-
const isNilOrEmpty = (value) => {
|
|
22858
|
-
if (value === null || value === void 0 || value === "") {
|
|
22859
|
-
return true;
|
|
22860
|
-
}
|
|
22861
|
-
if (Array.isArray(value) && value.length === 0) {
|
|
22862
|
-
return true;
|
|
22863
|
-
}
|
|
22864
|
-
if (typeof value === "object" && Object.keys(value).length === 0) {
|
|
22865
|
-
return true;
|
|
22866
|
-
}
|
|
22867
|
-
return false;
|
|
22868
|
-
};
|
|
22869
22859
|
const isLessThanMax = (value, max) => {
|
|
22870
22860
|
return value === void 0 || max === void 0 || Number(value) < Number(max);
|
|
22871
22861
|
};
|
|
@@ -22876,15 +22866,15 @@ const generateAxisId = (axisType, index2 = 0, hasMultiAxes = false) => {
|
|
|
22876
22866
|
const i2 = hasMultiAxes && index2 !== 0 ? index2 + 1 : "";
|
|
22877
22867
|
return `${axisType}${i2}`;
|
|
22878
22868
|
};
|
|
22869
|
+
const getAxisTypeFromKey = (string) => {
|
|
22870
|
+
var _a2;
|
|
22871
|
+
return ((_a2 = string == null ? void 0 : string.match(/[^0-9/]+/gi)) == null ? void 0 : _a2[0]) ?? "";
|
|
22872
|
+
};
|
|
22879
22873
|
const generateKey = (values) => {
|
|
22880
22874
|
const key = values.join("");
|
|
22881
22875
|
return key;
|
|
22882
22876
|
};
|
|
22883
22877
|
const isPrimitiveValue = (value) => typeof value === "string" || typeof value === "number" || typeof value === "boolean" || value === null;
|
|
22884
|
-
const isRangeValid = (r2) => {
|
|
22885
|
-
if (!r2) return false;
|
|
22886
|
-
return Object.values(r2).some((value) => !isNilOrEmpty(value));
|
|
22887
|
-
};
|
|
22888
22878
|
const getChartStateFromStorage = (persistenceId) => {
|
|
22889
22879
|
if (!persistenceId) return null;
|
|
22890
22880
|
const chartStateKey = `line-chart-state-${persistenceId}`;
|
|
@@ -22895,37 +22885,6 @@ const getChartStateFromStorage = (persistenceId) => {
|
|
|
22895
22885
|
}
|
|
22896
22886
|
return null;
|
|
22897
22887
|
};
|
|
22898
|
-
const removeExpiredChartStates = (maxAgeInHours = 72) => {
|
|
22899
|
-
const currentTime = (/* @__PURE__ */ new Date()).getTime();
|
|
22900
|
-
const maxAgeInMilliseconds = maxAgeInHours * 60 * 60 * 1e3;
|
|
22901
|
-
for (let i2 = 0; i2 < localStorage.length; i2++) {
|
|
22902
|
-
const key = localStorage.key(i2);
|
|
22903
|
-
if (key == null ? void 0 : key.includes("line-chart-state-")) {
|
|
22904
|
-
const chartStateObjectJSON = localStorage.getItem(key);
|
|
22905
|
-
if (chartStateObjectJSON) {
|
|
22906
|
-
const chartStateObject = JSON.parse(chartStateObjectJSON);
|
|
22907
|
-
const storedTime = chartStateObject.timestamp;
|
|
22908
|
-
if (storedTime) {
|
|
22909
|
-
const ageInMilliseconds = currentTime - storedTime;
|
|
22910
|
-
if (ageInMilliseconds > maxAgeInMilliseconds) {
|
|
22911
|
-
localStorage.removeItem(key);
|
|
22912
|
-
}
|
|
22913
|
-
}
|
|
22914
|
-
}
|
|
22915
|
-
}
|
|
22916
|
-
}
|
|
22917
|
-
};
|
|
22918
|
-
const storeChartStateInStorage = (state, persistenceId) => {
|
|
22919
|
-
if (!persistenceId) return;
|
|
22920
|
-
const currentTime = (/* @__PURE__ */ new Date()).getTime();
|
|
22921
|
-
const chartStateKey = `line-chart-state-${persistenceId}`;
|
|
22922
|
-
const chartStateObject = {
|
|
22923
|
-
state,
|
|
22924
|
-
timestamp: currentTime
|
|
22925
|
-
};
|
|
22926
|
-
localStorage.setItem(chartStateKey, JSON.stringify(chartStateObject));
|
|
22927
|
-
removeExpiredChartStates();
|
|
22928
|
-
};
|
|
22929
22888
|
const initialState = ({ options, persistenceId }) => {
|
|
22930
22889
|
const {
|
|
22931
22890
|
additionalAxesOptions: { range: customAxesRange = {} },
|
|
@@ -25029,7 +24988,11 @@ const getDefaultProps$3 = (props) => {
|
|
|
25029
24988
|
}
|
|
25030
24989
|
};
|
|
25031
24990
|
};
|
|
24991
|
+
const DEFAULT_POINT_RADIUS = 2;
|
|
24992
|
+
const DEFAULT_HOVER_RADIUS = 5;
|
|
25032
24993
|
const DEFAULT_BORDER_WIDTH = 1;
|
|
24994
|
+
const BORDER_JOIN_STYLE = "round";
|
|
24995
|
+
const DEFAULT_BACKGROUND_COLOR = "transparent";
|
|
25033
24996
|
const ZOOM_BOX_BACKGROUND_COLOR = "rgba(0, 0, 0, 0.1)";
|
|
25034
24997
|
const DOUBLE_CLICK = "dblclick";
|
|
25035
24998
|
const INIT_KEYS = {
|
|
@@ -25038,6 +25001,153 @@ const INIT_KEYS = {
|
|
|
25038
25001
|
};
|
|
25039
25002
|
const LOWER_BOUND = 1e-4;
|
|
25040
25003
|
const UPPER_BOUND = 1e7;
|
|
25004
|
+
const checkCustomOption = (data, customOptions) => {
|
|
25005
|
+
if (isEmpty(data) || isEmpty(customOptions)) return false;
|
|
25006
|
+
const checkOption = (dataset) => {
|
|
25007
|
+
if (typeof customOptions === "string") {
|
|
25008
|
+
return dataset && has(dataset, customOptions);
|
|
25009
|
+
} else if (isArray$2(customOptions)) {
|
|
25010
|
+
return dataset && some(customOptions, (option) => dataset && has(dataset, option));
|
|
25011
|
+
} else {
|
|
25012
|
+
return dataset && some(
|
|
25013
|
+
Object.values(customOptions),
|
|
25014
|
+
(option) => dataset && has(dataset, option)
|
|
25015
|
+
);
|
|
25016
|
+
}
|
|
25017
|
+
};
|
|
25018
|
+
if (isArray$2(data)) {
|
|
25019
|
+
return some(data, checkOption);
|
|
25020
|
+
} else {
|
|
25021
|
+
return checkOption(data);
|
|
25022
|
+
}
|
|
25023
|
+
};
|
|
25024
|
+
var CUSTOM_OPTION = /* @__PURE__ */ ((CUSTOM_OPTION2) => {
|
|
25025
|
+
CUSTOM_OPTION2["showLine"] = "showLine";
|
|
25026
|
+
CUSTOM_OPTION2["showPoints"] = "showPoints";
|
|
25027
|
+
return CUSTOM_OPTION2;
|
|
25028
|
+
})(CUSTOM_OPTION || {});
|
|
25029
|
+
const generateLineChartDatasets = (datasets, state, options, { label }) => {
|
|
25030
|
+
const copyDataset = [...datasets ?? []];
|
|
25031
|
+
const { annotations, graph } = options ?? {};
|
|
25032
|
+
const {
|
|
25033
|
+
controlAnnotation,
|
|
25034
|
+
showAnnotations,
|
|
25035
|
+
annotationsData = []
|
|
25036
|
+
} = annotations ?? {};
|
|
25037
|
+
if (controlAnnotation && showAnnotations) {
|
|
25038
|
+
const annotationDatasets = annotationsData.map((ann, index2) => {
|
|
25039
|
+
const { type, ...annotation2 } = ann;
|
|
25040
|
+
const color2 = annotation2.color ?? COLORS[index2];
|
|
25041
|
+
const borderDash = ANNOTATION_DASH;
|
|
25042
|
+
const borderWidth = BORDER_WIDTH.INITIAL;
|
|
25043
|
+
return {
|
|
25044
|
+
...annotation2,
|
|
25045
|
+
isAnnotation: true,
|
|
25046
|
+
annotationType: type,
|
|
25047
|
+
label: annotation2.label,
|
|
25048
|
+
annotationIndex: index2,
|
|
25049
|
+
backgroundColor: color2,
|
|
25050
|
+
pointBackgroundColor: color2,
|
|
25051
|
+
borderColor: color2,
|
|
25052
|
+
borderDash,
|
|
25053
|
+
borderWidth,
|
|
25054
|
+
data: [{}]
|
|
25055
|
+
};
|
|
25056
|
+
});
|
|
25057
|
+
copyDataset.push(...annotationDatasets);
|
|
25058
|
+
}
|
|
25059
|
+
return copyDataset == null ? void 0 : copyDataset.map((line, i2) => {
|
|
25060
|
+
var _a2, _b2;
|
|
25061
|
+
const {
|
|
25062
|
+
formation,
|
|
25063
|
+
data = [],
|
|
25064
|
+
pointRadius: pointRadiusProp,
|
|
25065
|
+
pointHoverRadius,
|
|
25066
|
+
borderWidth,
|
|
25067
|
+
borderColor,
|
|
25068
|
+
backgroundColor,
|
|
25069
|
+
pointBackgroundColor,
|
|
25070
|
+
borderDash,
|
|
25071
|
+
showPoints: customShowPoints,
|
|
25072
|
+
showLine: customShowLine
|
|
25073
|
+
} = line ?? {};
|
|
25074
|
+
const { lineEnabled, pointsEnabled, axes = [] } = state ?? {};
|
|
25075
|
+
const { lineTension, spanGaps } = graph ?? {};
|
|
25076
|
+
if (formation) {
|
|
25077
|
+
const axesMin = (_a2 = axes[0]) == null ? void 0 : _a2.min;
|
|
25078
|
+
const axesMax = (_b2 = axes[0]) == null ? void 0 : _b2.max;
|
|
25079
|
+
const [startPoint, endPoint] = data;
|
|
25080
|
+
if (axesMin && (startPoint == null ? void 0 : startPoint.x)) {
|
|
25081
|
+
data[0].x = Math.max(axesMin, startPoint.x);
|
|
25082
|
+
}
|
|
25083
|
+
if (axesMax && (endPoint == null ? void 0 : endPoint.x)) {
|
|
25084
|
+
data[2].x = Math.min(axesMax, endPoint.x);
|
|
25085
|
+
}
|
|
25086
|
+
}
|
|
25087
|
+
const hasCustomOpt = checkCustomOption(line, CUSTOM_OPTION);
|
|
25088
|
+
const filteredData = data.filter(Boolean) || [];
|
|
25089
|
+
const isSinglePoint = (filteredData == null ? void 0 : filteredData.length) === 1;
|
|
25090
|
+
let pointState, lineState;
|
|
25091
|
+
if (customShowPoints !== void 0) {
|
|
25092
|
+
pointState = customShowPoints;
|
|
25093
|
+
} else if (customShowLine === false) {
|
|
25094
|
+
pointState = true;
|
|
25095
|
+
} else {
|
|
25096
|
+
pointState = pointsEnabled || isSinglePoint;
|
|
25097
|
+
}
|
|
25098
|
+
if (customShowLine !== void 0) {
|
|
25099
|
+
lineState = customShowLine;
|
|
25100
|
+
} else if (customShowPoints === false) {
|
|
25101
|
+
lineState = true;
|
|
25102
|
+
} else {
|
|
25103
|
+
lineState = lineEnabled;
|
|
25104
|
+
}
|
|
25105
|
+
const linePointRadius = parseFloat(pointRadiusProp) || DEFAULT_POINT_RADIUS;
|
|
25106
|
+
const hoverRadius = parseFloat(pointHoverRadius) || DEFAULT_HOVER_RADIUS;
|
|
25107
|
+
const indexedColor = COLORS[i2];
|
|
25108
|
+
return {
|
|
25109
|
+
...line,
|
|
25110
|
+
label: (line == null ? void 0 : line.label) ?? `${label} ${i2 + 1}`,
|
|
25111
|
+
data: filteredData,
|
|
25112
|
+
showLine: lineState,
|
|
25113
|
+
lineTension: (line == null ? void 0 : line.lineTension) ?? lineTension,
|
|
25114
|
+
spanGaps,
|
|
25115
|
+
borderWidth: parseFloat(borderWidth) || DEFAULT_BORDER_WIDTH,
|
|
25116
|
+
borderDash: borderDash || [],
|
|
25117
|
+
borderJoinStyle: BORDER_JOIN_STYLE,
|
|
25118
|
+
borderColor: borderColor ?? indexedColor ?? generateRandomColor(COLORS),
|
|
25119
|
+
backgroundColor: backgroundColor ?? DEFAULT_BACKGROUND_COLOR,
|
|
25120
|
+
pointBackgroundColor: pointBackgroundColor ?? indexedColor ?? generateRandomColor(COLORS),
|
|
25121
|
+
pointRadius: pointState ? linePointRadius : 0,
|
|
25122
|
+
pointHoverRadius: hoverRadius,
|
|
25123
|
+
pointHitRadius: (line == null ? void 0 : line.pointHitRadius) ?? hoverRadius,
|
|
25124
|
+
...hasCustomOpt ? { hasCustomOpt } : {}
|
|
25125
|
+
};
|
|
25126
|
+
});
|
|
25127
|
+
};
|
|
25128
|
+
const getAnnotationsData = (data) => {
|
|
25129
|
+
return data == null ? void 0 : data.reduce((acc, obj) => {
|
|
25130
|
+
return {
|
|
25131
|
+
...acc,
|
|
25132
|
+
[obj.annotationAxis]: [...acc[obj.annotationAxis] || [], +obj.value]
|
|
25133
|
+
};
|
|
25134
|
+
}, {});
|
|
25135
|
+
};
|
|
25136
|
+
const getAxisRangeByType = (chartRef, axesType, annotationsData) => {
|
|
25137
|
+
if (!chartRef || !chartRef.current) return null;
|
|
25138
|
+
const metasets = chartRef.current.getSortedVisibleDatasetMetas();
|
|
25139
|
+
const annotDataByType = getAnnotationsData(annotationsData)[axesType] ?? [];
|
|
25140
|
+
let allData = [];
|
|
25141
|
+
metasets.forEach((metaset) => {
|
|
25142
|
+
const data = metaset._parsed.map((parsedData) => parsedData[axesType]).filter((value) => value != null && !isNaN(value));
|
|
25143
|
+
allData = allData.concat(data);
|
|
25144
|
+
});
|
|
25145
|
+
allData = allData.concat(annotDataByType);
|
|
25146
|
+
if (allData.length === 0) return null;
|
|
25147
|
+
const min = Math.min(...allData);
|
|
25148
|
+
const max = Math.max(...allData);
|
|
25149
|
+
return { min, max };
|
|
25150
|
+
};
|
|
25041
25151
|
const calculateDelta$1 = (tickValue, ticks) => {
|
|
25042
25152
|
let delta = ticks.length > 3 ? ticks[2].value - ticks[1].value : ticks[1].value - ticks[0].value;
|
|
25043
25153
|
if (Math.abs(delta) >= 1 && tickValue !== Math.floor(Number(tickValue))) {
|
|
@@ -25144,9 +25254,142 @@ const getLineChartScales = (options, state) => {
|
|
|
25144
25254
|
...yAxes
|
|
25145
25255
|
};
|
|
25146
25256
|
};
|
|
25147
|
-
const
|
|
25257
|
+
const estimateDataSeriesHaveCloseValues = (generatedDatasets) => {
|
|
25258
|
+
var _a2;
|
|
25259
|
+
if (!Array.isArray(generatedDatasets) || !(generatedDatasets == null ? void 0 : generatedDatasets.length)) {
|
|
25260
|
+
return false;
|
|
25261
|
+
}
|
|
25262
|
+
const axesFirstLast = generatedDatasets == null ? void 0 : generatedDatasets.reduce((acc, dataset) => {
|
|
25263
|
+
var _a3, _b2, _c2, _d2;
|
|
25264
|
+
const xAxisId = (dataset == null ? void 0 : dataset.xAxisID) ?? "defaultX";
|
|
25265
|
+
const yAxisId = (dataset == null ? void 0 : dataset.yAxisID) ?? "defaultY";
|
|
25266
|
+
const data = (dataset == null ? void 0 : dataset.data) ?? [];
|
|
25267
|
+
if (data && (data == null ? void 0 : data.length)) {
|
|
25268
|
+
const { x: xFirstCurrent, y: yFirstCurrent } = (data == null ? void 0 : data[0]) ?? {};
|
|
25269
|
+
const { x: xLastCurrent = 0, y: yLastCurrent = 0 } = (data == null ? void 0 : data.at(-1)) ?? {};
|
|
25270
|
+
const xFirstAcc = ((_a3 = acc == null ? void 0 : acc[xAxisId]) == null ? void 0 : _a3.xFirst) ?? xFirstCurrent;
|
|
25271
|
+
const xLastAcc = ((_b2 = acc == null ? void 0 : acc[xAxisId]) == null ? void 0 : _b2.xLast) ?? xLastCurrent;
|
|
25272
|
+
const yFirstAcc = ((_c2 = acc == null ? void 0 : acc[yAxisId]) == null ? void 0 : _c2.yFirst) ?? yFirstCurrent;
|
|
25273
|
+
const yLastAcc = ((_d2 = acc == null ? void 0 : acc[yAxisId]) == null ? void 0 : _d2.yLast) ?? yLastCurrent;
|
|
25274
|
+
const xFirst = Math.min(xFirstCurrent, xFirstAcc);
|
|
25275
|
+
const xLast = Math.max(xLastCurrent, xLastAcc);
|
|
25276
|
+
const yFirst = Math.min(yFirstCurrent, yFirstAcc);
|
|
25277
|
+
const yLast = Math.max(yLastCurrent, yLastAcc);
|
|
25278
|
+
acc = {
|
|
25279
|
+
...acc,
|
|
25280
|
+
[xAxisId]: {
|
|
25281
|
+
...acc[xAxisId],
|
|
25282
|
+
xFirst,
|
|
25283
|
+
xLast
|
|
25284
|
+
},
|
|
25285
|
+
[yAxisId]: {
|
|
25286
|
+
yFirst,
|
|
25287
|
+
yLast
|
|
25288
|
+
}
|
|
25289
|
+
};
|
|
25290
|
+
}
|
|
25291
|
+
return acc;
|
|
25292
|
+
}, {});
|
|
25293
|
+
return (_a2 = Object.values(axesFirstLast)) == null ? void 0 : _a2.some(({ xFirst, xLast, yFirst, yLast }) => {
|
|
25294
|
+
return isCloseTo(xFirst, xLast, { absoluteDiff: MAX_DECIMAL_DIFF }) || isCloseTo(yFirst, yLast, { absoluteDiff: MAX_DECIMAL_DIFF });
|
|
25295
|
+
});
|
|
25296
|
+
};
|
|
25297
|
+
const whiteSpacePercentage = 0.05;
|
|
25298
|
+
const defaultRange = { min: -1, max: 1 };
|
|
25299
|
+
const getSuggestedAxisRange = ({
|
|
25300
|
+
data,
|
|
25301
|
+
beginAtZero = false,
|
|
25302
|
+
autoAxisPadding = false
|
|
25303
|
+
}) => {
|
|
25304
|
+
const dataMin = Math.min(
|
|
25305
|
+
...data.filter((v2) => v2 !== null && v2 !== void 0 && !isNaN(v2))
|
|
25306
|
+
);
|
|
25307
|
+
const dataMax = Math.max(
|
|
25308
|
+
...data.filter((v2) => v2 !== null && v2 !== void 0 && !isNaN(v2))
|
|
25309
|
+
);
|
|
25310
|
+
const isNegative = Math.sign(dataMin) === -1 || Math.sign(dataMax) === -1;
|
|
25311
|
+
const isCloseToZeroWithTolerance = isCloseTo(dataMin, 0, { absoluteDiff: MAX_DECIMAL_DIFF }) && isCloseTo(dataMax, 0, { absoluteDiff: MAX_DECIMAL_DIFF });
|
|
25312
|
+
if (!(data == null ? void 0 : data.length) || isCloseToZeroWithTolerance) {
|
|
25313
|
+
return defaultRange;
|
|
25314
|
+
}
|
|
25315
|
+
if (isCloseTo(dataMin, dataMax, { absoluteDiff: MAX_DECIMAL_DIFF })) {
|
|
25316
|
+
const point = dataMax;
|
|
25317
|
+
const padding2 = point * whiteSpacePercentage;
|
|
25318
|
+
const minAxisValue2 = beginAtZero && !isNegative ? 0 : point - padding2;
|
|
25319
|
+
const maxAxisValue2 = beginAtZero && isNegative ? 0 : point + padding2;
|
|
25320
|
+
const roundedMinAxisValue = round$2(maxAxisValue2, DECIMAL_POINT_TOLERANCE);
|
|
25321
|
+
const roundedMaxAxisValue = round$2(minAxisValue2, DECIMAL_POINT_TOLERANCE);
|
|
25322
|
+
return {
|
|
25323
|
+
min: roundedMinAxisValue < 0 ? roundedMinAxisValue : roundedMaxAxisValue,
|
|
25324
|
+
max: roundedMaxAxisValue < 0 ? roundedMaxAxisValue : roundedMinAxisValue
|
|
25325
|
+
};
|
|
25326
|
+
}
|
|
25327
|
+
if (!autoAxisPadding) {
|
|
25328
|
+
return {
|
|
25329
|
+
min: void 0,
|
|
25330
|
+
max: void 0
|
|
25331
|
+
};
|
|
25332
|
+
}
|
|
25333
|
+
const rangeBeginAtZero = dataMin === 0 || dataMax === 0 || beginAtZero;
|
|
25334
|
+
const positiveAndNegative = Math.sign(dataMin) === -1 && Math.sign(dataMax) === 1;
|
|
25335
|
+
const range = Math.abs(dataMax - dataMin);
|
|
25336
|
+
const padding = autoAxisPadding ? range * whiteSpacePercentage : 0;
|
|
25337
|
+
const minAxisValue = !positiveAndNegative && rangeBeginAtZero && beginAtZero && !isNegative ? 0 : dataMin - padding;
|
|
25338
|
+
const maxAxisValue = !positiveAndNegative && rangeBeginAtZero && beginAtZero && isNegative ? 0 : dataMax + padding;
|
|
25339
|
+
return {
|
|
25340
|
+
min: round$2(minAxisValue, DECIMAL_POINT_TOLERANCE),
|
|
25341
|
+
max: round$2(maxAxisValue, DECIMAL_POINT_TOLERANCE)
|
|
25342
|
+
};
|
|
25343
|
+
};
|
|
25344
|
+
const getAxesDataFromMetasets = (chartRef, scalesKeys, annotationsData) => {
|
|
25345
|
+
var _a2;
|
|
25346
|
+
if (!chartRef || !scalesKeys) return {};
|
|
25347
|
+
const metasets = ((_a2 = chartRef == null ? void 0 : chartRef.current) == null ? void 0 : _a2.getSortedVisibleDatasetMetas()) ?? [];
|
|
25348
|
+
const annotData = getAnnotationsData(annotationsData);
|
|
25349
|
+
return metasets && (scalesKeys == null ? void 0 : scalesKeys.reduce((acc, key) => {
|
|
25350
|
+
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]) ?? []);
|
|
25351
|
+
return {
|
|
25352
|
+
...acc,
|
|
25353
|
+
[key]: [...new Set(data)]
|
|
25354
|
+
};
|
|
25355
|
+
}, {}));
|
|
25356
|
+
};
|
|
25357
|
+
const shouldCalculate = (min, max) => !isNil(min) || !isNil(max);
|
|
25358
|
+
const autoScale = (options, state, generatedDatasets, chartRef) => {
|
|
25359
|
+
const {
|
|
25360
|
+
additionalAxesOptions,
|
|
25361
|
+
annotations: { annotationsData = [], controlAnnotation = false } = {}
|
|
25362
|
+
} = options || {};
|
|
25148
25363
|
const scales = getLineChartScales(options, state) || {};
|
|
25149
|
-
|
|
25364
|
+
const datasets = controlAnnotation ? generatedDatasets.filter(({ isAnnotation }) => !isAnnotation) : generatedDatasets;
|
|
25365
|
+
if (!(additionalAxesOptions == null ? void 0 : additionalAxesOptions.autoAxisPadding) && !estimateDataSeriesHaveCloseValues(datasets)) {
|
|
25366
|
+
return scales;
|
|
25367
|
+
}
|
|
25368
|
+
const scalesKeys = Object.keys(scales) ?? [];
|
|
25369
|
+
const data = getAxesDataFromMetasets(
|
|
25370
|
+
chartRef,
|
|
25371
|
+
scalesKeys,
|
|
25372
|
+
annotationsData
|
|
25373
|
+
);
|
|
25374
|
+
const adjustedScales = data && (scalesKeys == null ? void 0 : scalesKeys.reduce((acc, key) => {
|
|
25375
|
+
const scale = scales[key];
|
|
25376
|
+
const { min: propMin = void 0, max: propMax = void 0 } = scale;
|
|
25377
|
+
const { min: calcMin, max: calcMax } = getAxisRangeByType(chartRef, key, annotationsData) ?? {};
|
|
25378
|
+
const { min: suggestedMin, max: suggestedMax } = getSuggestedAxisRange({
|
|
25379
|
+
data: data[key],
|
|
25380
|
+
beginAtZero: additionalAxesOptions == null ? void 0 : additionalAxesOptions.beginAtZero,
|
|
25381
|
+
autoAxisPadding: additionalAxesOptions == null ? void 0 : additionalAxesOptions.autoAxisPadding
|
|
25382
|
+
});
|
|
25383
|
+
const res = {
|
|
25384
|
+
[key]: {
|
|
25385
|
+
...scale,
|
|
25386
|
+
min: propMin ?? (shouldCalculate(propMin, propMax) ? calcMin : suggestedMin),
|
|
25387
|
+
max: propMax ?? (shouldCalculate(propMin, propMax) ? calcMax : suggestedMax)
|
|
25388
|
+
}
|
|
25389
|
+
};
|
|
25390
|
+
return { ...acc, ...res };
|
|
25391
|
+
}, {}));
|
|
25392
|
+
return adjustedScales ?? scales;
|
|
25150
25393
|
};
|
|
25151
25394
|
const getCondition = (x2, y2, left2, right2, bottom2) => {
|
|
25152
25395
|
const threshold = 100;
|
|
@@ -25696,7 +25939,7 @@ const useChartOptions = ({
|
|
|
25696
25939
|
const datalabels = getLineChartDataLabels(options);
|
|
25697
25940
|
const tooltip = getLineChartToolTips(options);
|
|
25698
25941
|
const scales = useMemo(
|
|
25699
|
-
() => autoScale(options, state),
|
|
25942
|
+
() => autoScale(options, state, generatedDatasets, chartRef),
|
|
25700
25943
|
[options, state, generatedDatasets, chartRef]
|
|
25701
25944
|
);
|
|
25702
25945
|
const dragData = useMemo(
|
|
@@ -25816,145 +26059,6 @@ const useChartPlugins = ({ options, resetZoom: resetZoom2 }) => {
|
|
|
25816
26059
|
];
|
|
25817
26060
|
}, [handleDoubleClick]);
|
|
25818
26061
|
};
|
|
25819
|
-
const getAnnotationsData = (data) => {
|
|
25820
|
-
return data == null ? void 0 : data.reduce((acc, obj) => {
|
|
25821
|
-
return {
|
|
25822
|
-
...acc,
|
|
25823
|
-
[obj.annotationAxis]: [...acc[obj.annotationAxis] || [], +obj.value]
|
|
25824
|
-
};
|
|
25825
|
-
}, {});
|
|
25826
|
-
};
|
|
25827
|
-
const getAxisRangeByType = (chartRef, axesType, annotationsData) => {
|
|
25828
|
-
if (!chartRef || !chartRef.current) return null;
|
|
25829
|
-
const metasets = chartRef.current.getSortedVisibleDatasetMetas();
|
|
25830
|
-
const annotDataByType = getAnnotationsData(annotationsData)[axesType] ?? [];
|
|
25831
|
-
let allData = [];
|
|
25832
|
-
metasets.forEach((metaset) => {
|
|
25833
|
-
const data = metaset._parsed.map((parsedData) => parsedData[axesType]).filter((value) => value != null && !isNaN(value));
|
|
25834
|
-
allData = allData.concat(data);
|
|
25835
|
-
});
|
|
25836
|
-
allData = allData.concat(annotDataByType);
|
|
25837
|
-
if (allData.length === 0) return null;
|
|
25838
|
-
const min = Math.min(...allData);
|
|
25839
|
-
const max = Math.max(...allData);
|
|
25840
|
-
return { min, max };
|
|
25841
|
-
};
|
|
25842
|
-
const useToggleCustomLegendVisibility = (memoState, memoOptions) => {
|
|
25843
|
-
var _a2, _b2;
|
|
25844
|
-
useEffect(() => {
|
|
25845
|
-
var _a3, _b3;
|
|
25846
|
-
if ((_b3 = (_a3 = memoOptions == null ? void 0 : memoOptions.legend) == null ? void 0 : _a3.customLegend) == null ? void 0 : _b3.customLegendPlugin) {
|
|
25847
|
-
const parent = document.getElementById(
|
|
25848
|
-
memoOptions.legend.customLegend.customLegendContainerID
|
|
25849
|
-
);
|
|
25850
|
-
if (parent !== null) {
|
|
25851
|
-
parent.style.visibility = memoState.legendEnabled ? "visible" : "hidden";
|
|
25852
|
-
}
|
|
25853
|
-
}
|
|
25854
|
-
}, [
|
|
25855
|
-
(_b2 = (_a2 = memoOptions == null ? void 0 : memoOptions.legend) == null ? void 0 : _a2.customLegend) == null ? void 0 : _b2.customLegendPlugin,
|
|
25856
|
-
memoState.legendEnabled
|
|
25857
|
-
]);
|
|
25858
|
-
};
|
|
25859
|
-
const useStoreChartStateInStorage = (memoState, persistenceId) => {
|
|
25860
|
-
useEffect(() => {
|
|
25861
|
-
storeChartStateInStorage(memoState, persistenceId);
|
|
25862
|
-
}, [
|
|
25863
|
-
memoState.panEnabled,
|
|
25864
|
-
memoState.lineEnabled,
|
|
25865
|
-
memoState.pointsEnabled,
|
|
25866
|
-
memoState.legendEnabled,
|
|
25867
|
-
memoState.enableDragPoints,
|
|
25868
|
-
memoState.zoomEnabled
|
|
25869
|
-
]);
|
|
25870
|
-
};
|
|
25871
|
-
const useUpdateAxesRanges = ({
|
|
25872
|
-
chartRef,
|
|
25873
|
-
range,
|
|
25874
|
-
state,
|
|
25875
|
-
dispatch,
|
|
25876
|
-
annotationsData
|
|
25877
|
-
}) => {
|
|
25878
|
-
const prevAxes = useRef(state.axes);
|
|
25879
|
-
useEffect(() => {
|
|
25880
|
-
if (range && isRangeValid(range)) {
|
|
25881
|
-
const newAxes = Object.entries(range).map(([key, { min, max }]) => {
|
|
25882
|
-
const { min: minFromData = 0, max: maxFromData = 0 } = getAxisRangeByType(chartRef, key, annotationsData) ?? {};
|
|
25883
|
-
return {
|
|
25884
|
-
id: key,
|
|
25885
|
-
min: min ?? minFromData,
|
|
25886
|
-
max: max ?? maxFromData
|
|
25887
|
-
};
|
|
25888
|
-
});
|
|
25889
|
-
const mergedAxes = [...prevAxes.current ?? []].map((axis) => {
|
|
25890
|
-
const newAxis = newAxes.find((a2) => a2.id === axis.id);
|
|
25891
|
-
return newAxis ? { ...axis, ...newAxis } : axis;
|
|
25892
|
-
});
|
|
25893
|
-
if (!isEqual(mergedAxes, prevAxes.current)) {
|
|
25894
|
-
dispatch({
|
|
25895
|
-
type: UPDATE_AXES_RANGES,
|
|
25896
|
-
payload: { axes: mergedAxes }
|
|
25897
|
-
});
|
|
25898
|
-
prevAxes.current = mergedAxes;
|
|
25899
|
-
}
|
|
25900
|
-
}
|
|
25901
|
-
}, [range]);
|
|
25902
|
-
};
|
|
25903
|
-
const useSaveInitialAxesRanges = (chartRef, dispatch, generatedDatasets) => {
|
|
25904
|
-
var _a2;
|
|
25905
|
-
const prevDatasets = useRef(null);
|
|
25906
|
-
useEffect(() => {
|
|
25907
|
-
var _a3, _b2;
|
|
25908
|
-
if (((_a3 = chartRef == null ? void 0 : chartRef.current) == null ? void 0 : _a3.scales) && !isEqual(prevDatasets.current, generatedDatasets)) {
|
|
25909
|
-
const scales = ((_b2 = chartRef == null ? void 0 : chartRef.current) == null ? void 0 : _b2.scales) ?? {};
|
|
25910
|
-
const initialAxesRanges = Object.entries(scales).map(
|
|
25911
|
-
([id, { min, max, _range: range }]) => ({
|
|
25912
|
-
id,
|
|
25913
|
-
min: (range == null ? void 0 : range.min) ?? min,
|
|
25914
|
-
max: (range == null ? void 0 : range.max) ?? max
|
|
25915
|
-
})
|
|
25916
|
-
);
|
|
25917
|
-
dispatch({
|
|
25918
|
-
type: SAVE_INITIAL_AXES_RANGES,
|
|
25919
|
-
payload: { initialAxesRanges }
|
|
25920
|
-
});
|
|
25921
|
-
prevDatasets.current = generatedDatasets;
|
|
25922
|
-
}
|
|
25923
|
-
}, [(_a2 = chartRef == null ? void 0 : chartRef.current) == null ? void 0 : _a2.scales, generatedDatasets]);
|
|
25924
|
-
};
|
|
25925
|
-
const useChartState = ({
|
|
25926
|
-
chartRef,
|
|
25927
|
-
options,
|
|
25928
|
-
state,
|
|
25929
|
-
dispatch,
|
|
25930
|
-
persistenceId,
|
|
25931
|
-
generatedDatasets
|
|
25932
|
-
}) => {
|
|
25933
|
-
useEffect(() => {
|
|
25934
|
-
return () => {
|
|
25935
|
-
if (chartRef == null ? void 0 : chartRef.current) {
|
|
25936
|
-
const chart2 = chartRef == null ? void 0 : chartRef.current;
|
|
25937
|
-
chart2 == null ? void 0 : chart2.destroy();
|
|
25938
|
-
}
|
|
25939
|
-
};
|
|
25940
|
-
}, []);
|
|
25941
|
-
const memoState = useMemo(() => state, [state]);
|
|
25942
|
-
const memoOptions = useMemo(() => options, [options]);
|
|
25943
|
-
const {
|
|
25944
|
-
additionalAxesOptions: { range = void 0 },
|
|
25945
|
-
annotations: { annotationsData = [] } = {}
|
|
25946
|
-
} = memoOptions;
|
|
25947
|
-
useStoreChartStateInStorage(memoState, persistenceId);
|
|
25948
|
-
useToggleCustomLegendVisibility(memoState, memoOptions);
|
|
25949
|
-
useUpdateAxesRanges({
|
|
25950
|
-
range,
|
|
25951
|
-
state: memoState,
|
|
25952
|
-
dispatch,
|
|
25953
|
-
chartRef,
|
|
25954
|
-
annotationsData
|
|
25955
|
-
});
|
|
25956
|
-
useSaveInitialAxesRanges(chartRef, dispatch, generatedDatasets);
|
|
25957
|
-
};
|
|
25958
26062
|
const WORD_SEPARATOR = " ";
|
|
25959
26063
|
const SEMI_TRANSPARENT = "rgba(0, 0, 0, 0.5)";
|
|
25960
26064
|
const getWords = (text) => {
|
|
@@ -27019,7 +27123,7 @@ const LineChart = (props) => {
|
|
|
27019
27123
|
const { translations, languageKey } = getConfig();
|
|
27020
27124
|
const chart2 = getDefaultProps$3(props);
|
|
27021
27125
|
const {
|
|
27022
|
-
|
|
27126
|
+
data: { datasets } = { datasets: [] },
|
|
27023
27127
|
options,
|
|
27024
27128
|
testId,
|
|
27025
27129
|
persistenceId,
|
|
@@ -27027,7 +27131,6 @@ const LineChart = (props) => {
|
|
|
27027
27131
|
} = chart2;
|
|
27028
27132
|
const { annotations, axes, chartStyling, graph } = options ?? {};
|
|
27029
27133
|
const showCustomLegend = !((_b2 = (_a2 = options == null ? void 0 : options.legend) == null ? void 0 : _a2.customLegend) == null ? void 0 : _b2.customLegendContainerID);
|
|
27030
|
-
console.time("useReducer");
|
|
27031
27134
|
const [state, dispatch] = useReducer(
|
|
27032
27135
|
reducer$1,
|
|
27033
27136
|
{
|
|
@@ -27036,23 +27139,20 @@ const LineChart = (props) => {
|
|
|
27036
27139
|
},
|
|
27037
27140
|
initialState
|
|
27038
27141
|
);
|
|
27039
|
-
console.timeEnd("useReducer");
|
|
27040
|
-
console.time("generatedDatasets");
|
|
27041
27142
|
const generatedDatasets = useMemo(() => {
|
|
27042
|
-
|
|
27143
|
+
const startTimeStamp = performance.now();
|
|
27144
|
+
const result = generateLineChartDatasets(
|
|
27145
|
+
datasets,
|
|
27146
|
+
state,
|
|
27147
|
+
options,
|
|
27148
|
+
translations
|
|
27149
|
+
);
|
|
27150
|
+
const endTimeStamp = performance.now();
|
|
27151
|
+
console.log(
|
|
27152
|
+
`generateLineChartDatasets execution time: ${(endTimeStamp - startTimeStamp).toFixed(5)} ms`
|
|
27153
|
+
);
|
|
27154
|
+
return result;
|
|
27043
27155
|
}, [state.lineEnabled, state.pointsEnabled, axes, annotations, graph]);
|
|
27044
|
-
console.timeEnd("generatedDatasets");
|
|
27045
|
-
console.time("useChartState");
|
|
27046
|
-
useChartState({
|
|
27047
|
-
chartRef,
|
|
27048
|
-
options,
|
|
27049
|
-
state,
|
|
27050
|
-
dispatch,
|
|
27051
|
-
persistenceId,
|
|
27052
|
-
generatedDatasets
|
|
27053
|
-
});
|
|
27054
|
-
console.timeEnd("useChartState");
|
|
27055
|
-
console.time("useChartFunctions");
|
|
27056
27156
|
const { resetZoom: resetZoom2, handleKeyDown, handleKeyUp } = useChartFunctions({
|
|
27057
27157
|
chartRef,
|
|
27058
27158
|
state,
|
|
@@ -27060,8 +27160,6 @@ const LineChart = (props) => {
|
|
|
27060
27160
|
dispatch,
|
|
27061
27161
|
generatedDatasets
|
|
27062
27162
|
});
|
|
27063
|
-
console.timeEnd("useChartFunctions");
|
|
27064
|
-
console.time("useChartOptions");
|
|
27065
27163
|
const useOptions = useChartOptions({
|
|
27066
27164
|
chartRef,
|
|
27067
27165
|
state,
|
|
@@ -27069,10 +27167,7 @@ const LineChart = (props) => {
|
|
|
27069
27167
|
dispatch,
|
|
27070
27168
|
generatedDatasets
|
|
27071
27169
|
});
|
|
27072
|
-
console.timeEnd("useChartOptions");
|
|
27073
|
-
console.time("useChartPlugins");
|
|
27074
27170
|
const usePlugins = useChartPlugins({ options, resetZoom: resetZoom2 });
|
|
27075
|
-
console.timeEnd("useChartPlugins");
|
|
27076
27171
|
return /* @__PURE__ */ jsxs(
|
|
27077
27172
|
"div",
|
|
27078
27173
|
{
|