@oliasoft-open-source/charts-library 3.7.0-beta-2 → 3.7.0-beta-3
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 +333 -177
- package/dist/index.js.map +1 -1
- package/dist/src/components/bar-chart/get-bar-chart-data-labels.d.ts +1 -2
- package/dist/src/components/bar-chart/get-bar-chart-scales.d.ts +1 -2
- package/dist/src/components/common/common.interface.d.ts +2 -1
- package/dist/src/components/common/helpers/chart-border-plugin.d.ts +2 -2
- package/dist/src/components/common/helpers/chart-utils.d.ts +91 -0
- package/dist/src/components/common/helpers/get-custom-legend-plugin-example.d.ts +1 -1
- package/dist/src/components/line-chart/controls/axes-options/axes-options-interfaces.d.ts +2 -2
- package/dist/src/components/line-chart/controls/controls-interfaces.d.ts +2 -2
- package/dist/src/components/line-chart/controls/drag-options-interfaces.d.ts +1 -1
- package/dist/src/components/line-chart/controls/line-options.d.ts +2 -1
- package/dist/src/components/line-chart/hooks/use-chart-functions.d.ts +2 -13
- package/dist/src/components/line-chart/hooks/use-chart-plugins.d.ts +7 -0
- package/dist/src/components/line-chart/hooks/use-chart-state.d.ts +2 -3
- package/dist/src/components/line-chart/hooks/use-generated-labels.d.ts +1 -0
- package/dist/src/components/line-chart/hooks/use-legend-state.d.ts +40 -0
- package/dist/src/components/line-chart/legend/create-style-object.d.ts +26 -0
- package/dist/src/components/line-chart/legend/legend-interface.d.ts +1 -1
- package/dist/src/components/line-chart/line-chart-get-default-props.d.ts +2 -99
- package/dist/src/components/line-chart/line-chart.interface.d.ts +3 -3
- package/dist/src/components/line-chart/line-chart.stories.d.ts +72 -0
- package/dist/src/components/line-chart/state/initial-state.d.ts +4 -26
- package/dist/src/components/line-chart/utils/__tests__/get-line-chart-tooltips.test.d.ts +1 -0
- package/dist/src/components/line-chart/utils/axis-formatting/axis-formatting.d.ts +1 -1
- package/dist/src/components/line-chart/utils/check-custom-option/check-custom-option.d.ts +15 -0
- package/dist/src/components/line-chart/utils/check-custom-option/check-custom-option.test.d.ts +1 -0
- package/dist/src/components/line-chart/utils/enums.d.ts +4 -0
- package/dist/src/components/line-chart/utils/get-axis-range-by-type.d.ts +10 -0
- package/dist/src/components/line-chart/utils/get-generated-labels.d.ts +1 -0
- package/package.json +2 -1
- package/dist/declaration.d.ts +0 -17
- /package/dist/src/components/line-chart/utils/{get-line-chart-tooltips.test.d.ts → __tests__/get-axis-range-by-type.test.d.ts} +0 -0
package/dist/index.js
CHANGED
|
@@ -7,11 +7,11 @@ var __publicField = (obj, key, value) => {
|
|
|
7
7
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
8
8
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
9
9
|
import React, { forwardRef, useRef, useEffect, createContext as createContext$2, memo, useLayoutEffect, useState, useCallback, useMemo, isValidElement, cloneElement, useContext, useReducer } from "react";
|
|
10
|
-
import { round as round$2,
|
|
10
|
+
import { round as round$2, displayNumber, isCloseTo, roundByMagnitude, toNum } from "@oliasoft-open-source/units";
|
|
11
11
|
import cx from "classnames";
|
|
12
12
|
import { produce } from "immer";
|
|
13
13
|
import { Icon, Tooltip as Tooltip$2, Button, Flex, Text, Menu, Popover, Field, InputGroup, NumberInput, InputGroupAddon, Select, ButtonGroup, Spacer, Portal } from "@oliasoft-open-source/react-ui-library";
|
|
14
|
-
import { debounce as debounce$3, isEqual } from "lodash";
|
|
14
|
+
import { isEmpty, isArray as isArray$2, some, has, debounce as debounce$3, isEqual } from "lodash";
|
|
15
15
|
import { roundNumberToPrecision } from "@oliasoft-open-source/units/dist/rounding/rounding";
|
|
16
16
|
/*!
|
|
17
17
|
* @kurkle/color v0.3.2
|
|
@@ -13369,7 +13369,12 @@ const getAxisPosition = (axisType, i2) => {
|
|
|
13369
13369
|
return i2 % 2 === 0 ? positionA : positionB;
|
|
13370
13370
|
};
|
|
13371
13371
|
const getClassName = (chartStyling, styles2) => {
|
|
13372
|
-
const {
|
|
13372
|
+
const {
|
|
13373
|
+
width,
|
|
13374
|
+
height,
|
|
13375
|
+
staticChartHeight = false,
|
|
13376
|
+
squareAspectRatio: squareAspectRatio2 = 0
|
|
13377
|
+
} = chartStyling;
|
|
13373
13378
|
const squareAspectRatioStyle = squareAspectRatio2 ? styles2.squareAspectRatio : "";
|
|
13374
13379
|
let heightStyles = "";
|
|
13375
13380
|
if (width || height) {
|
|
@@ -22766,7 +22771,8 @@ const initialState = ({ options, persistenceId }) => {
|
|
|
22766
22771
|
axes: stateAxes,
|
|
22767
22772
|
showAnnotationLineIndex: setAnnotations(annotationsData),
|
|
22768
22773
|
showTable: false,
|
|
22769
|
-
enableDragPoints: dragData.enableDragData && enableDragPoints
|
|
22774
|
+
enableDragPoints: (dragData == null ? void 0 : dragData.enableDragData) && enableDragPoints,
|
|
22775
|
+
initialAxesRanges: []
|
|
22770
22776
|
};
|
|
22771
22777
|
};
|
|
22772
22778
|
var DefaultContext = {
|
|
@@ -22871,7 +22877,8 @@ const LineOptions = ({
|
|
|
22871
22877
|
onToggleLine,
|
|
22872
22878
|
onTogglePoints,
|
|
22873
22879
|
pointsEnabled,
|
|
22874
|
-
translations
|
|
22880
|
+
translations,
|
|
22881
|
+
hasCustomOpt
|
|
22875
22882
|
}) => {
|
|
22876
22883
|
const options = [
|
|
22877
22884
|
{
|
|
@@ -22901,17 +22908,26 @@ const LineOptions = ({
|
|
|
22901
22908
|
}
|
|
22902
22909
|
];
|
|
22903
22910
|
const selectedOption = options.find((option) => option.selected);
|
|
22904
|
-
return /* @__PURE__ */ jsx(
|
|
22905
|
-
|
|
22911
|
+
return /* @__PURE__ */ jsx(
|
|
22912
|
+
Tooltip$2,
|
|
22906
22913
|
{
|
|
22907
|
-
|
|
22908
|
-
|
|
22909
|
-
|
|
22910
|
-
|
|
22911
|
-
|
|
22912
|
-
|
|
22914
|
+
text: selectedOption == null ? void 0 : selectedOption.label,
|
|
22915
|
+
placement: "bottom",
|
|
22916
|
+
enabled: !hasCustomOpt,
|
|
22917
|
+
children: /* @__PURE__ */ jsx(
|
|
22918
|
+
Button,
|
|
22919
|
+
{
|
|
22920
|
+
small: true,
|
|
22921
|
+
basic: true,
|
|
22922
|
+
colored: "muted",
|
|
22923
|
+
round: true,
|
|
22924
|
+
icon: selectedOption == null ? void 0 : selectedOption.icon,
|
|
22925
|
+
onClick: selectedOption == null ? void 0 : selectedOption.onClick,
|
|
22926
|
+
disabled: hasCustomOpt
|
|
22927
|
+
}
|
|
22928
|
+
)
|
|
22913
22929
|
}
|
|
22914
|
-
)
|
|
22930
|
+
);
|
|
22915
22931
|
};
|
|
22916
22932
|
function TbHandStop(props) {
|
|
22917
22933
|
return GenIcon({ "tag": "svg", "attr": { "viewBox": "0 0 24 24", "strokeWidth": "2", "stroke": "currentColor", "fill": "none", "strokeLinecap": "round", "strokeLinejoin": "round" }, "child": [{ "tag": "path", "attr": { "stroke": "none", "d": "M0 0h24v24H0z", "fill": "none" } }, { "tag": "path", "attr": { "d": "M8 13v-7.5a1.5 1.5 0 0 1 3 0v6.5" } }, { "tag": "path", "attr": { "d": "M11 5.5v-2a1.5 1.5 0 1 1 3 0v8.5" } }, { "tag": "path", "attr": { "d": "M14 5.5a1.5 1.5 0 0 1 3 0v6.5" } }, { "tag": "path", "attr": { "d": "M17 7.5a1.5 1.5 0 0 1 3 0v8.5a6 6 0 0 1 -6 6h-2h.208a6 6 0 0 1 -5.012 -2.7a69.74 69.74 0 0 1 -.196 -.3c-.312 -.479 -1.407 -2.388 -3.286 -5.728a1.5 1.5 0 0 1 .536 -2.022a1.867 1.867 0 0 1 2.28 .28l1.47 1.47" } }] })(props);
|
|
@@ -23982,41 +23998,9 @@ const useChartFunctions = ({
|
|
|
23982
23998
|
generatedDatasets
|
|
23983
23999
|
}) => {
|
|
23984
24000
|
const {
|
|
23985
|
-
|
|
23986
|
-
interactions: {
|
|
23987
|
-
onLegendClick,
|
|
23988
|
-
onHover: onPointHover,
|
|
23989
|
-
onUnhover: onPointUnhover
|
|
23990
|
-
},
|
|
23991
|
-
additionalAxesOptions,
|
|
24001
|
+
interactions: { onHover: onPointHover, onUnhover: onPointUnhover },
|
|
23992
24002
|
axes
|
|
23993
24003
|
} = options;
|
|
23994
|
-
const legendClick = useCallback(
|
|
23995
|
-
(_e2, legendItem2) => {
|
|
23996
|
-
const { datasetIndex } = legendItem2;
|
|
23997
|
-
const chartInstance = chartRef == null ? void 0 : chartRef.current;
|
|
23998
|
-
const { datasets } = (chartInstance == null ? void 0 : chartInstance.data) || {};
|
|
23999
|
-
const dataset = datasets[datasetIndex];
|
|
24000
|
-
const meta = chartInstance.getDatasetMeta(datasetIndex);
|
|
24001
|
-
meta.hidden = meta.hidden === null ? !dataset.hidden : null;
|
|
24002
|
-
if (annotations.controlAnnotation && dataset.isAnnotation) {
|
|
24003
|
-
const { annotationIndex } = dataset;
|
|
24004
|
-
dispatch({ type: "TOGGLE_ANNOTATION", payload: { annotationIndex } });
|
|
24005
|
-
}
|
|
24006
|
-
if (dataset.displayGroup) {
|
|
24007
|
-
datasets == null ? void 0 : datasets.forEach((ds, ix) => {
|
|
24008
|
-
if (ds.displayGroup !== dataset.displayGroup)
|
|
24009
|
-
return;
|
|
24010
|
-
chartInstance.getDatasetMeta(ix).hidden = meta.hidden;
|
|
24011
|
-
});
|
|
24012
|
-
}
|
|
24013
|
-
if (onLegendClick) {
|
|
24014
|
-
onLegendClick(legendItem2 == null ? void 0 : legendItem2.text, legendItem2.hidden);
|
|
24015
|
-
}
|
|
24016
|
-
chartInstance == null ? void 0 : chartInstance.update();
|
|
24017
|
-
},
|
|
24018
|
-
[onLegendClick, annotations]
|
|
24019
|
-
);
|
|
24020
24004
|
const resetZoom2 = useCallback(() => {
|
|
24021
24005
|
const chartInstance = chartRef == null ? void 0 : chartRef.current;
|
|
24022
24006
|
chartInstance == null ? void 0 : chartInstance.resetZoom();
|
|
@@ -24087,18 +24071,6 @@ const useChartFunctions = ({
|
|
|
24087
24071
|
},
|
|
24088
24072
|
[chartRef]
|
|
24089
24073
|
);
|
|
24090
|
-
const controlsAxes = state.axes.map((axis, i2) => {
|
|
24091
|
-
var _a2, _b2, _c2, _d2;
|
|
24092
|
-
const axisType = i2 ? AxisType.Y : AxisType.X;
|
|
24093
|
-
const min = axis.min ?? ((_b2 = (_a2 = additionalAxesOptions == null ? void 0 : additionalAxesOptions.range) == null ? void 0 : _a2[axisType]) == null ? void 0 : _b2.min);
|
|
24094
|
-
const max = axis.max ?? ((_d2 = (_c2 = additionalAxesOptions == null ? void 0 : additionalAxesOptions.range) == null ? void 0 : _c2[axisType]) == null ? void 0 : _d2.max);
|
|
24095
|
-
return {
|
|
24096
|
-
...axis,
|
|
24097
|
-
// only add min and max properties if they are defined:
|
|
24098
|
-
...min ? { min } : {},
|
|
24099
|
-
...max ? { max } : {}
|
|
24100
|
-
};
|
|
24101
|
-
});
|
|
24102
24074
|
const getControlsAxesLabels = useCallback(
|
|
24103
24075
|
(propsAxes) => {
|
|
24104
24076
|
var _a2;
|
|
@@ -24150,13 +24122,11 @@ const useChartFunctions = ({
|
|
|
24150
24122
|
dispatch({ type: UPDATE_AXES_RANGES, payload: { axes: axes2 } });
|
|
24151
24123
|
}, []);
|
|
24152
24124
|
return {
|
|
24153
|
-
legendClick,
|
|
24154
24125
|
resetZoom: resetZoom2,
|
|
24155
24126
|
onHover,
|
|
24156
24127
|
handleDownload,
|
|
24157
24128
|
handleKeyDown,
|
|
24158
24129
|
handleKeyUp,
|
|
24159
|
-
controlsAxes,
|
|
24160
24130
|
controlsAxesLabels: getControlsAxesLabels(axes),
|
|
24161
24131
|
updateAxesRangesFromChart,
|
|
24162
24132
|
onResetAxes,
|
|
@@ -24230,10 +24200,11 @@ const reducer = (state, action) => {
|
|
|
24230
24200
|
});
|
|
24231
24201
|
case actionTypes.UnitUpdated:
|
|
24232
24202
|
return produce(state, (draft) => {
|
|
24203
|
+
var _a2;
|
|
24233
24204
|
const { name, value, id } = action.payload;
|
|
24234
|
-
const
|
|
24235
|
-
if (
|
|
24236
|
-
|
|
24205
|
+
const unit = (_a2 = draft.find((a2) => a2.id === id)) == null ? void 0 : _a2.unit;
|
|
24206
|
+
if (unit && name) {
|
|
24207
|
+
unit[name] = value;
|
|
24237
24208
|
}
|
|
24238
24209
|
});
|
|
24239
24210
|
default:
|
|
@@ -24248,9 +24219,9 @@ const AxesOptionsPopover = (optionsPopover) => {
|
|
|
24248
24219
|
controlsAxesLabels,
|
|
24249
24220
|
onUpdateAxes,
|
|
24250
24221
|
onResetAxes,
|
|
24251
|
-
close,
|
|
24252
24222
|
depthType,
|
|
24253
|
-
translations
|
|
24223
|
+
translations,
|
|
24224
|
+
close
|
|
24254
24225
|
} = optionsPopover;
|
|
24255
24226
|
const [depthTypeState, setDepthTypeState] = useState(
|
|
24256
24227
|
depthType == null ? void 0 : depthType.selectedDepthType
|
|
@@ -24281,8 +24252,8 @@ const AxesOptionsPopover = (optionsPopover) => {
|
|
|
24281
24252
|
if (valid) {
|
|
24282
24253
|
const sanitizedFormState = formState.map((axis) => ({
|
|
24283
24254
|
...axis,
|
|
24284
|
-
min:
|
|
24285
|
-
max:
|
|
24255
|
+
min: typeof axis.min === "string" ? Number(axis.min) : axis.min,
|
|
24256
|
+
max: typeof axis.max === "string" ? Number(axis.max) : axis.max
|
|
24286
24257
|
}));
|
|
24287
24258
|
onUpdateAxes({
|
|
24288
24259
|
axes: sanitizedFormState
|
|
@@ -24324,7 +24295,9 @@ const AxesOptionsPopover = (optionsPopover) => {
|
|
|
24324
24295
|
(el) => el.id === axis.id
|
|
24325
24296
|
);
|
|
24326
24297
|
const axisLabel = axisControl == null ? void 0 : axisControl.label;
|
|
24327
|
-
const axisState = formState.find(
|
|
24298
|
+
const axisState = formState.find(
|
|
24299
|
+
(a2) => a2.id === axis.id
|
|
24300
|
+
);
|
|
24328
24301
|
const axisErrors = errors == null ? void 0 : errors.find((a2) => a2.id === axis.id);
|
|
24329
24302
|
const { min, max, unit } = axisState || {};
|
|
24330
24303
|
const minErrorMsg = ((_a3 = axisErrors == null ? void 0 : axisErrors.min) == null ? void 0 : _a3[0]) ? translations[axisErrors.min[0]] : null;
|
|
@@ -24368,7 +24341,7 @@ const AxesOptionsPopover = (optionsPopover) => {
|
|
|
24368
24341
|
{
|
|
24369
24342
|
name: "selectedUnit",
|
|
24370
24343
|
options: (_c2 = axis == null ? void 0 : axis.unit) == null ? void 0 : _c2.options,
|
|
24371
|
-
value: unit == null ? void 0 : unit.selectedUnit,
|
|
24344
|
+
value: typeof unit !== "string" ? unit == null ? void 0 : unit.selectedUnit : void 0,
|
|
24372
24345
|
onChange: (e2) => {
|
|
24373
24346
|
onEditUnit({
|
|
24374
24347
|
name: e2.target.name,
|
|
@@ -24472,6 +24445,27 @@ const ControlsPortal = ({
|
|
|
24472
24445
|
}
|
|
24473
24446
|
return children;
|
|
24474
24447
|
};
|
|
24448
|
+
const checkCustomOption = (data, customOptions) => {
|
|
24449
|
+
if (isEmpty(data) || isEmpty(customOptions))
|
|
24450
|
+
return false;
|
|
24451
|
+
const checkOption = (dataset) => {
|
|
24452
|
+
if (typeof customOptions === "string") {
|
|
24453
|
+
return has(dataset, customOptions);
|
|
24454
|
+
} else if (isArray$2(customOptions)) {
|
|
24455
|
+
return some(customOptions, (option) => has(dataset, option));
|
|
24456
|
+
} else {
|
|
24457
|
+
return some(
|
|
24458
|
+
Object.values(customOptions),
|
|
24459
|
+
(option) => has(dataset, option)
|
|
24460
|
+
);
|
|
24461
|
+
}
|
|
24462
|
+
};
|
|
24463
|
+
if (isArray$2(data)) {
|
|
24464
|
+
return some(data, (dataset) => checkOption(dataset));
|
|
24465
|
+
} else {
|
|
24466
|
+
return checkOption(data);
|
|
24467
|
+
}
|
|
24468
|
+
};
|
|
24475
24469
|
const Controls = ({
|
|
24476
24470
|
headerComponent,
|
|
24477
24471
|
subheaderComponent,
|
|
@@ -24503,19 +24497,14 @@ const Controls = ({
|
|
|
24503
24497
|
onToggleDragPoints,
|
|
24504
24498
|
onDisableDragOptions
|
|
24505
24499
|
} = useToggleHandlers(dispatch);
|
|
24506
|
-
const {
|
|
24507
|
-
handleDownload,
|
|
24508
|
-
controlsAxes,
|
|
24509
|
-
controlsAxesLabels,
|
|
24510
|
-
onResetAxes,
|
|
24511
|
-
onUpdateAxes
|
|
24512
|
-
} = useChartFunctions({
|
|
24500
|
+
const { handleDownload, controlsAxesLabels, onResetAxes, onUpdateAxes } = useChartFunctions({
|
|
24513
24501
|
chartRef,
|
|
24514
24502
|
state,
|
|
24515
24503
|
options,
|
|
24516
24504
|
dispatch,
|
|
24517
24505
|
generatedDatasets
|
|
24518
24506
|
});
|
|
24507
|
+
const hasCustomOpt = checkCustomOption(generatedDatasets, "hasCustomOpt");
|
|
24519
24508
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
24520
24509
|
/* @__PURE__ */ jsxs("div", { className: styles$3.controls, children: [
|
|
24521
24510
|
!!options.title && /* @__PURE__ */ jsx(Text, { bold: true, children: options.title }),
|
|
@@ -24526,7 +24515,7 @@ const Controls = ({
|
|
|
24526
24515
|
AxesOptions,
|
|
24527
24516
|
{
|
|
24528
24517
|
initialAxesRanges,
|
|
24529
|
-
axes:
|
|
24518
|
+
axes: state.axes,
|
|
24530
24519
|
controlsAxesLabels,
|
|
24531
24520
|
onUpdateAxes,
|
|
24532
24521
|
onResetAxes,
|
|
@@ -24541,7 +24530,8 @@ const Controls = ({
|
|
|
24541
24530
|
pointsEnabled,
|
|
24542
24531
|
onToggleLine,
|
|
24543
24532
|
onTogglePoints,
|
|
24544
|
-
translations
|
|
24533
|
+
translations,
|
|
24534
|
+
hasCustomOpt
|
|
24545
24535
|
}
|
|
24546
24536
|
),
|
|
24547
24537
|
/* @__PURE__ */ jsx(
|
|
@@ -24570,7 +24560,7 @@ const Controls = ({
|
|
|
24570
24560
|
onTogglePan,
|
|
24571
24561
|
onToggleZoom,
|
|
24572
24562
|
enableDragPoints,
|
|
24573
|
-
isDragDataAllowed: dragData.enableDragData,
|
|
24563
|
+
isDragDataAllowed: dragData == null ? void 0 : dragData.enableDragData,
|
|
24574
24564
|
onToggleDragPoints,
|
|
24575
24565
|
onDisableDragOptions,
|
|
24576
24566
|
translations
|
|
@@ -24772,9 +24762,143 @@ const LegendItem = ({ hidden, dataset, handleClick }) => {
|
|
|
24772
24762
|
}
|
|
24773
24763
|
);
|
|
24774
24764
|
};
|
|
24765
|
+
const useLegendState = ({
|
|
24766
|
+
chartRef,
|
|
24767
|
+
options,
|
|
24768
|
+
state,
|
|
24769
|
+
dispatch
|
|
24770
|
+
}) => {
|
|
24771
|
+
const {
|
|
24772
|
+
annotations,
|
|
24773
|
+
interactions: { onLegendClick },
|
|
24774
|
+
legend: { customLegend }
|
|
24775
|
+
} = options;
|
|
24776
|
+
const { legendEnabled } = state;
|
|
24777
|
+
const [hiddenStates, setHiddenStates] = useState([]);
|
|
24778
|
+
const upsertHiddenState = ({ label, datasetIndex, hidden }) => {
|
|
24779
|
+
setHiddenStates((prevStates) => {
|
|
24780
|
+
const existingIndex = prevStates.findIndex(
|
|
24781
|
+
(state2) => state2.label === label
|
|
24782
|
+
);
|
|
24783
|
+
const newStates = [...prevStates];
|
|
24784
|
+
const newState = { label, datasetIndex, hidden };
|
|
24785
|
+
if (existingIndex !== -1) {
|
|
24786
|
+
newStates[existingIndex] = newState;
|
|
24787
|
+
} else {
|
|
24788
|
+
newStates.push(newState);
|
|
24789
|
+
}
|
|
24790
|
+
return newStates;
|
|
24791
|
+
});
|
|
24792
|
+
};
|
|
24793
|
+
const clearNonExistentDatasets = (datasets) => {
|
|
24794
|
+
const existingLabels = datasets.map((ds) => ds.label);
|
|
24795
|
+
setHiddenStates(
|
|
24796
|
+
(prevStates) => prevStates.filter((state2) => existingLabels.includes(state2.label))
|
|
24797
|
+
);
|
|
24798
|
+
};
|
|
24799
|
+
const legendClick = useCallback(
|
|
24800
|
+
(_e2, legendItem2) => {
|
|
24801
|
+
const { datasetIndex } = legendItem2;
|
|
24802
|
+
const chartInstance = chartRef == null ? void 0 : chartRef.current;
|
|
24803
|
+
const { datasets } = (chartInstance == null ? void 0 : chartInstance.data) || {};
|
|
24804
|
+
const dataset = datasets == null ? void 0 : datasets[datasetIndex];
|
|
24805
|
+
const meta = chartInstance == null ? void 0 : chartInstance.getDatasetMeta(datasetIndex);
|
|
24806
|
+
const isDatasetVisible = (chartInstance == null ? void 0 : chartInstance.isDatasetVisible(datasetIndex)) ?? true;
|
|
24807
|
+
upsertHiddenState({
|
|
24808
|
+
label: dataset.label,
|
|
24809
|
+
datasetIndex,
|
|
24810
|
+
hidden: isDatasetVisible
|
|
24811
|
+
});
|
|
24812
|
+
chartInstance == null ? void 0 : chartInstance.setDatasetVisibility(datasetIndex, !isDatasetVisible);
|
|
24813
|
+
if (annotations.controlAnnotation && (dataset == null ? void 0 : dataset.isAnnotation)) {
|
|
24814
|
+
const { annotationIndex } = dataset;
|
|
24815
|
+
dispatch({ type: TOGGLE_ANNOTATION, payload: { annotationIndex } });
|
|
24816
|
+
}
|
|
24817
|
+
if (dataset.displayGroup) {
|
|
24818
|
+
datasets == null ? void 0 : datasets.forEach((ds, ix) => {
|
|
24819
|
+
if (ds.displayGroup !== dataset.displayGroup)
|
|
24820
|
+
return;
|
|
24821
|
+
if (chartInstance && meta) {
|
|
24822
|
+
chartInstance.getDatasetMeta(ix).hidden = meta.hidden;
|
|
24823
|
+
}
|
|
24824
|
+
});
|
|
24825
|
+
}
|
|
24826
|
+
if (onLegendClick) {
|
|
24827
|
+
onLegendClick(legendItem2 == null ? void 0 : legendItem2.text, legendItem2.hidden);
|
|
24828
|
+
}
|
|
24829
|
+
chartInstance == null ? void 0 : chartInstance.update();
|
|
24830
|
+
},
|
|
24831
|
+
[chartRef, annotations, onLegendClick, hiddenStates]
|
|
24832
|
+
);
|
|
24833
|
+
const legend2 = useMemo(
|
|
24834
|
+
() => getLegend(options, legendClick),
|
|
24835
|
+
[legendEnabled]
|
|
24836
|
+
);
|
|
24837
|
+
const customLegendPlugin = useMemo(
|
|
24838
|
+
() => ({
|
|
24839
|
+
[CUSTOM_LEGEND_PLUGIN_NAME]: (customLegend == null ? void 0 : customLegend.customLegendPlugin) && {
|
|
24840
|
+
containerID: customLegend == null ? void 0 : customLegend.customLegendContainerID
|
|
24841
|
+
}
|
|
24842
|
+
}),
|
|
24843
|
+
[customLegend]
|
|
24844
|
+
);
|
|
24845
|
+
return {
|
|
24846
|
+
legendClick,
|
|
24847
|
+
hiddenStates,
|
|
24848
|
+
legend: legend2,
|
|
24849
|
+
customLegendPlugin,
|
|
24850
|
+
upsertHiddenState,
|
|
24851
|
+
clearNonExistentDatasets
|
|
24852
|
+
};
|
|
24853
|
+
};
|
|
24775
24854
|
const LEGEND_MARGIN = 4;
|
|
24855
|
+
const createLegendStyle = (legendPosition, chart2) => {
|
|
24856
|
+
const { height = 0, width = 0, chartArea } = chart2;
|
|
24857
|
+
const { top: top2, left: left2, bottom: bottom2, right: right2 } = chartArea;
|
|
24858
|
+
return {
|
|
24859
|
+
left: legendPosition.includes("left") ? left2 : void 0,
|
|
24860
|
+
right: legendPosition.includes("right") ? width - right2 : void 0,
|
|
24861
|
+
top: legendPosition.includes("top") ? top2 : void 0,
|
|
24862
|
+
bottom: legendPosition.includes("bottom") ? height - bottom2 : void 0,
|
|
24863
|
+
maxHeight: 0.5 * (bottom2 - top2 - LEGEND_MARGIN * 2),
|
|
24864
|
+
maxWidth: 0.5 * (right2 - left2 - LEGEND_MARGIN * 2),
|
|
24865
|
+
margin: LEGEND_MARGIN
|
|
24866
|
+
};
|
|
24867
|
+
};
|
|
24868
|
+
const getGeneratedLabels = (chart2) => {
|
|
24869
|
+
var _a2, _b2, _c2, _d2, _e2;
|
|
24870
|
+
return ((_e2 = (_d2 = (_c2 = (_b2 = (_a2 = chart2 == null ? void 0 : chart2.options) == null ? void 0 : _a2.plugins) == null ? void 0 : _b2.legend) == null ? void 0 : _c2.labels) == null ? void 0 : _d2.generateLabels) == null ? void 0 : _e2.call(_d2, chart2)) ?? [];
|
|
24871
|
+
};
|
|
24872
|
+
const useGeneratedLabels = (chartRef, generatedDatasets) => {
|
|
24873
|
+
const [items, setItems] = useState([]);
|
|
24874
|
+
useEffect(() => {
|
|
24875
|
+
const chart2 = chartRef.current;
|
|
24876
|
+
if (!chart2)
|
|
24877
|
+
return;
|
|
24878
|
+
const newItems = getGeneratedLabels(chart2);
|
|
24879
|
+
setItems(newItems);
|
|
24880
|
+
}, [generatedDatasets, chartRef]);
|
|
24881
|
+
return items;
|
|
24882
|
+
};
|
|
24883
|
+
const LegendItems = ({
|
|
24884
|
+
items,
|
|
24885
|
+
hiddenStates,
|
|
24886
|
+
datasets,
|
|
24887
|
+
legendClick
|
|
24888
|
+
}) => /* @__PURE__ */ jsx("div", { className: styles$2.legendItems, children: items.map((item) => {
|
|
24889
|
+
var _a2;
|
|
24890
|
+
const hiddenState = ((_a2 = hiddenStates.find((state) => state.label === item.text)) == null ? void 0 : _a2.hidden) ?? false;
|
|
24891
|
+
return /* @__PURE__ */ jsx(
|
|
24892
|
+
LegendItem,
|
|
24893
|
+
{
|
|
24894
|
+
hidden: hiddenState,
|
|
24895
|
+
dataset: datasets[item.datasetIndex],
|
|
24896
|
+
handleClick: (event) => legendClick(event, item)
|
|
24897
|
+
},
|
|
24898
|
+
`${item.datasetIndex}-hidden-${item.hidden}`
|
|
24899
|
+
);
|
|
24900
|
+
}) });
|
|
24776
24901
|
const LegendPanel = forwardRef((props, ref) => {
|
|
24777
|
-
var _a2, _b2, _c2, _d2;
|
|
24778
24902
|
const {
|
|
24779
24903
|
legendPosition,
|
|
24780
24904
|
chartRef,
|
|
@@ -24784,32 +24908,25 @@ const LegendPanel = forwardRef((props, ref) => {
|
|
|
24784
24908
|
generatedDatasets,
|
|
24785
24909
|
isDragging: isDragging2
|
|
24786
24910
|
} = props;
|
|
24787
|
-
const [refresh, setRefresh] = useState(false);
|
|
24788
24911
|
const { legendEnabled } = state;
|
|
24789
|
-
const
|
|
24912
|
+
const chart2 = chartRef == null ? void 0 : chartRef.current;
|
|
24913
|
+
if (!chart2)
|
|
24914
|
+
return null;
|
|
24915
|
+
const {
|
|
24916
|
+
data: { datasets }
|
|
24917
|
+
} = chart2;
|
|
24918
|
+
const { legendClick, hiddenStates, clearNonExistentDatasets } = useLegendState({
|
|
24790
24919
|
chartRef,
|
|
24791
|
-
state,
|
|
24792
24920
|
options,
|
|
24793
|
-
|
|
24794
|
-
|
|
24921
|
+
state,
|
|
24922
|
+
dispatch
|
|
24795
24923
|
});
|
|
24796
24924
|
const { onToggleLegend } = useToggleHandlers(dispatch);
|
|
24797
|
-
const
|
|
24798
|
-
|
|
24799
|
-
|
|
24800
|
-
|
|
24801
|
-
|
|
24802
|
-
const { top: top2, left: left2, bottom: bottom2, right: right2 } = chartArea;
|
|
24803
|
-
const items = ((_d2 = (_c2 = (_b2 = (_a2 = chart2 == null ? void 0 : chart2.options) == null ? void 0 : _a2.plugins) == null ? void 0 : _b2.legend) == null ? void 0 : _c2.labels) == null ? void 0 : _d2.generateLabels(chart2)) ?? [];
|
|
24804
|
-
const style = {
|
|
24805
|
-
left: legendPosition.includes("left") ? left2 : void 0,
|
|
24806
|
-
right: legendPosition.includes("right") ? width - right2 : void 0,
|
|
24807
|
-
top: legendPosition.includes("top") ? top2 : void 0,
|
|
24808
|
-
bottom: legendPosition.includes("bottom") ? height - bottom2 : void 0,
|
|
24809
|
-
maxHeight: 0.5 * (bottom2 - top2 - LEGEND_MARGIN * 2),
|
|
24810
|
-
maxWidth: 0.5 * (right2 - left2 - LEGEND_MARGIN * 2),
|
|
24811
|
-
margin: LEGEND_MARGIN
|
|
24812
|
-
};
|
|
24925
|
+
const items = useGeneratedLabels(chartRef, generatedDatasets);
|
|
24926
|
+
const style = createLegendStyle(legendPosition, chart2);
|
|
24927
|
+
useEffect(() => {
|
|
24928
|
+
clearNonExistentDatasets(generatedDatasets);
|
|
24929
|
+
}, [generatedDatasets]);
|
|
24813
24930
|
return /* @__PURE__ */ jsxs(
|
|
24814
24931
|
"div",
|
|
24815
24932
|
{
|
|
@@ -24830,18 +24947,15 @@ const LegendPanel = forwardRef((props, ref) => {
|
|
|
24830
24947
|
icon: legendEnabled ? /* @__PURE__ */ jsx(TbX, {}) : /* @__PURE__ */ jsx(TbList, {})
|
|
24831
24948
|
}
|
|
24832
24949
|
) }),
|
|
24833
|
-
/* @__PURE__ */ jsx(
|
|
24834
|
-
|
|
24950
|
+
/* @__PURE__ */ jsx(
|
|
24951
|
+
LegendItems,
|
|
24835
24952
|
{
|
|
24836
|
-
|
|
24837
|
-
|
|
24838
|
-
|
|
24839
|
-
|
|
24840
|
-
|
|
24841
|
-
|
|
24842
|
-
},
|
|
24843
|
-
`${item.datasetIndex}-hidden-${item.hidden}`
|
|
24844
|
-
)) })
|
|
24953
|
+
items,
|
|
24954
|
+
hiddenStates,
|
|
24955
|
+
datasets,
|
|
24956
|
+
legendClick
|
|
24957
|
+
}
|
|
24958
|
+
)
|
|
24845
24959
|
]
|
|
24846
24960
|
}
|
|
24847
24961
|
);
|
|
@@ -24974,9 +25088,20 @@ const TextLabelPosition = {
|
|
|
24974
25088
|
BOTTOM_CENTER: "bottom-center",
|
|
24975
25089
|
BOTTOM_RIGHT: "bottom-right"
|
|
24976
25090
|
};
|
|
25091
|
+
const defaultAxis = (position) => ({
|
|
25092
|
+
label: "",
|
|
25093
|
+
position,
|
|
25094
|
+
color: "",
|
|
25095
|
+
unit: {
|
|
25096
|
+
options: [],
|
|
25097
|
+
selectedUnit: "",
|
|
25098
|
+
setSelectedUnit: () => {
|
|
25099
|
+
}
|
|
25100
|
+
}
|
|
25101
|
+
});
|
|
24977
25102
|
const defaultAxes$1 = (axes) => ({
|
|
24978
|
-
x: (axes == null ? void 0 : axes.x) || [
|
|
24979
|
-
y: (axes == null ? void 0 : axes.y) || [
|
|
25103
|
+
x: (axes == null ? void 0 : axes.x) || [defaultAxis("bottom")],
|
|
25104
|
+
y: (axes == null ? void 0 : axes.y) || [defaultAxis("left")]
|
|
24980
25105
|
});
|
|
24981
25106
|
const defaultAdditionalAxesOptions$1 = (options) => ({
|
|
24982
25107
|
chartScaleType: (options == null ? void 0 : options.chartScaleType) || "linear",
|
|
@@ -25070,7 +25195,7 @@ const getDefaultProps$2 = (props) => {
|
|
|
25070
25195
|
return {
|
|
25071
25196
|
persistenceId: (chart2 == null ? void 0 : chart2.persistenceId) ?? "",
|
|
25072
25197
|
controlsPortalId: (chart2 == null ? void 0 : chart2.controlsPortalId) ?? "",
|
|
25073
|
-
testId: (chart2 == null ? void 0 : chart2.testId) ??
|
|
25198
|
+
testId: (chart2 == null ? void 0 : chart2.testId) ?? void 0,
|
|
25074
25199
|
data: chart2 == null ? void 0 : chart2.data,
|
|
25075
25200
|
options: {
|
|
25076
25201
|
title: (options == null ? void 0 : options.title) ?? "",
|
|
@@ -25104,6 +25229,11 @@ const INIT_KEYS = {
|
|
|
25104
25229
|
};
|
|
25105
25230
|
const LOWER_BOUND = 1e-4;
|
|
25106
25231
|
const UPPER_BOUND = 1e7;
|
|
25232
|
+
var CUSTOM_OPTION = /* @__PURE__ */ ((CUSTOM_OPTION2) => {
|
|
25233
|
+
CUSTOM_OPTION2["showLine"] = "showLine";
|
|
25234
|
+
CUSTOM_OPTION2["showPoints"] = "showPoints";
|
|
25235
|
+
return CUSTOM_OPTION2;
|
|
25236
|
+
})(CUSTOM_OPTION || {});
|
|
25107
25237
|
const generateLineChartDatasets = (datasets, state, options, { label }) => {
|
|
25108
25238
|
const copyDataset = [...datasets];
|
|
25109
25239
|
const { annotations, graph } = options;
|
|
@@ -25145,7 +25275,9 @@ const generateLineChartDatasets = (datasets, state, options, { label }) => {
|
|
|
25145
25275
|
borderColor,
|
|
25146
25276
|
backgroundColor,
|
|
25147
25277
|
pointBackgroundColor,
|
|
25148
|
-
borderDash
|
|
25278
|
+
borderDash,
|
|
25279
|
+
showPoints = true,
|
|
25280
|
+
showLine
|
|
25149
25281
|
} = line ?? {};
|
|
25150
25282
|
const { lineEnabled, pointsEnabled, axes = [] } = state ?? {};
|
|
25151
25283
|
const { lineTension, spanGaps } = graph ?? {};
|
|
@@ -25163,14 +25295,15 @@ const generateLineChartDatasets = (datasets, state, options, { label }) => {
|
|
|
25163
25295
|
const filteredData = data.filter(Boolean) || [];
|
|
25164
25296
|
const isSinglePoint = (filteredData == null ? void 0 : filteredData.length) === 1;
|
|
25165
25297
|
const linePointRadius = parseFloat(pointRadiusProp) || DEFAULT_POINT_RADIUS;
|
|
25166
|
-
const pointRadius = pointsEnabled || isSinglePoint ? linePointRadius : 0;
|
|
25298
|
+
const pointRadius = (pointsEnabled || isSinglePoint) && showPoints ? linePointRadius : 0;
|
|
25167
25299
|
const hoverRadius = parseFloat(pointHoverRadius) || DEFAULT_HOVER_RADIUS;
|
|
25168
25300
|
const indexedColor = COLORS[i2];
|
|
25301
|
+
const hasCustomOpt = checkCustomOption(line, CUSTOM_OPTION);
|
|
25169
25302
|
return {
|
|
25170
25303
|
...line,
|
|
25171
25304
|
label: line.label || `${label} ${i2 + 1}`,
|
|
25172
25305
|
data: filteredData,
|
|
25173
|
-
showLine: lineEnabled,
|
|
25306
|
+
showLine: showLine ?? lineEnabled,
|
|
25174
25307
|
lineTension,
|
|
25175
25308
|
spanGaps,
|
|
25176
25309
|
borderWidth: parseFloat(borderWidth) || DEFAULT_BORDER_WIDTH,
|
|
@@ -25181,7 +25314,8 @@ const generateLineChartDatasets = (datasets, state, options, { label }) => {
|
|
|
25181
25314
|
pointBackgroundColor: pointBackgroundColor ?? indexedColor ?? generateRandomColor(COLORS),
|
|
25182
25315
|
pointRadius,
|
|
25183
25316
|
pointHoverRadius: hoverRadius,
|
|
25184
|
-
pointHitRadius: line.pointHitRadius ?? hoverRadius
|
|
25317
|
+
pointHitRadius: line.pointHitRadius ?? hoverRadius,
|
|
25318
|
+
...hasCustomOpt ? { hasCustomOpt } : {}
|
|
25185
25319
|
};
|
|
25186
25320
|
});
|
|
25187
25321
|
};
|
|
@@ -25192,7 +25326,7 @@ const calculateDelta$1 = (tickValue, ticks) => {
|
|
|
25192
25326
|
}
|
|
25193
25327
|
return delta;
|
|
25194
25328
|
};
|
|
25195
|
-
const formatAxisLabelNumbers = (tickValue, ticks
|
|
25329
|
+
const formatAxisLabelNumbers = (tickValue, ticks) => {
|
|
25196
25330
|
if (tickValue === 0 || tickValue === null) {
|
|
25197
25331
|
return "0";
|
|
25198
25332
|
}
|
|
@@ -25471,23 +25605,29 @@ const getLineChartDataLabels = (options) => {
|
|
|
25471
25605
|
formatter: (_value, context) => context.dataset.data[context.dataIndex].label || ""
|
|
25472
25606
|
} : { display: false };
|
|
25473
25607
|
};
|
|
25474
|
-
const annotationEnter = (
|
|
25608
|
+
const annotationEnter = (element, chart2) => {
|
|
25475
25609
|
var _a2;
|
|
25476
25610
|
if ((_a2 = element.options.scaleID) == null ? void 0 : _a2.includes(AxisType.X)) {
|
|
25477
25611
|
element.options.label.xAdjust = chart2.chartArea.left;
|
|
25478
25612
|
}
|
|
25479
25613
|
element.options.borderWidth = BORDER_WIDTH.HOVERED;
|
|
25480
|
-
if (element.options.label)
|
|
25614
|
+
if (element.options.label) {
|
|
25615
|
+
element.label.options.display = true;
|
|
25481
25616
|
element.options.label.enabled = true;
|
|
25617
|
+
}
|
|
25482
25618
|
chart2.draw();
|
|
25483
25619
|
chart2.canvas.style.cursor = CursorStyle.Pointer;
|
|
25620
|
+
return true;
|
|
25484
25621
|
};
|
|
25485
|
-
const annotationLeave = (
|
|
25622
|
+
const annotationLeave = (element, chart2) => {
|
|
25486
25623
|
element.options.borderWidth = BORDER_WIDTH.INITIAL;
|
|
25487
|
-
if (element.options.label)
|
|
25624
|
+
if (element.options.label) {
|
|
25625
|
+
element.label.options.display = false;
|
|
25488
25626
|
element.options.label.enabled = false;
|
|
25627
|
+
}
|
|
25489
25628
|
chart2.draw();
|
|
25490
25629
|
chart2.canvas.style.cursor = CursorStyle.Initial;
|
|
25630
|
+
return true;
|
|
25491
25631
|
};
|
|
25492
25632
|
const generateAnnotations = (options, state) => {
|
|
25493
25633
|
const { annotationsData } = (options == null ? void 0 : options.annotations) || {};
|
|
@@ -25506,22 +25646,22 @@ const generateAnnotations = (options, state) => {
|
|
|
25506
25646
|
const label = type === "line" ? {
|
|
25507
25647
|
backgroundColor: color2,
|
|
25508
25648
|
content: curr == null ? void 0 : curr.label,
|
|
25509
|
-
|
|
25649
|
+
display: false,
|
|
25510
25650
|
position: Position.Top
|
|
25511
25651
|
} : {
|
|
25512
25652
|
content: curr == null ? void 0 : curr.label,
|
|
25513
|
-
|
|
25653
|
+
display: true,
|
|
25514
25654
|
font: { weight: "normal" }
|
|
25515
25655
|
};
|
|
25516
|
-
const enter = (
|
|
25656
|
+
const enter = ({ element }, { chart: chart2 }) => {
|
|
25517
25657
|
if (type !== "line")
|
|
25518
25658
|
return;
|
|
25519
|
-
annotationEnter(
|
|
25659
|
+
annotationEnter(element, chart2);
|
|
25520
25660
|
};
|
|
25521
|
-
const leave = (
|
|
25661
|
+
const leave = ({ element }, { chart: chart2 }) => {
|
|
25522
25662
|
if (type !== "line")
|
|
25523
25663
|
return;
|
|
25524
|
-
annotationLeave(
|
|
25664
|
+
annotationLeave(element, chart2);
|
|
25525
25665
|
};
|
|
25526
25666
|
const annotation2 = {
|
|
25527
25667
|
...curr,
|
|
@@ -25653,7 +25793,6 @@ const useChartOptions = ({
|
|
|
25653
25793
|
dispatch,
|
|
25654
25794
|
generatedDatasets
|
|
25655
25795
|
}) => {
|
|
25656
|
-
var _a2, _b2;
|
|
25657
25796
|
const {
|
|
25658
25797
|
interactions: { onAnimationComplete },
|
|
25659
25798
|
annotations: {
|
|
@@ -25675,29 +25814,28 @@ const useChartOptions = ({
|
|
|
25675
25814
|
zoomEnabled,
|
|
25676
25815
|
panEnabled,
|
|
25677
25816
|
lineEnabled,
|
|
25678
|
-
showAnnotationLineIndex
|
|
25679
|
-
legendEnabled
|
|
25817
|
+
showAnnotationLineIndex
|
|
25680
25818
|
} = state;
|
|
25681
25819
|
const [hoveredPoint, setHoveredPoint] = useState(null);
|
|
25682
|
-
const {
|
|
25683
|
-
|
|
25684
|
-
|
|
25685
|
-
|
|
25686
|
-
|
|
25687
|
-
|
|
25688
|
-
|
|
25689
|
-
|
|
25690
|
-
|
|
25820
|
+
const { updateAxesRangesFromChart, onHover } = useChartFunctions({
|
|
25821
|
+
chartRef,
|
|
25822
|
+
state,
|
|
25823
|
+
options,
|
|
25824
|
+
dispatch,
|
|
25825
|
+
generatedDatasets
|
|
25826
|
+
});
|
|
25827
|
+
const { legendClick, legend: legend2, customLegendPlugin } = useLegendState({
|
|
25828
|
+
chartRef,
|
|
25829
|
+
options,
|
|
25830
|
+
state,
|
|
25831
|
+
dispatch
|
|
25832
|
+
});
|
|
25691
25833
|
const datalabels = getLineChartDataLabels(options);
|
|
25692
25834
|
const tooltip = getLineChartToolTips(options);
|
|
25693
25835
|
const annotation2 = useMemo(
|
|
25694
25836
|
() => getAnnotation(options, state),
|
|
25695
25837
|
[showAnnotationLineIndex, legendClick]
|
|
25696
25838
|
);
|
|
25697
|
-
const legend2 = useMemo(
|
|
25698
|
-
() => getLegend(options, legendClick),
|
|
25699
|
-
[legendEnabled]
|
|
25700
|
-
);
|
|
25701
25839
|
const scales = useMemo(
|
|
25702
25840
|
() => autoScale(options, state, generatedDatasets, chartRef),
|
|
25703
25841
|
[options, state, generatedDatasets, chartRef]
|
|
@@ -25739,9 +25877,7 @@ const useChartOptions = ({
|
|
|
25739
25877
|
tooltip,
|
|
25740
25878
|
legend: { ...legend2, display: false },
|
|
25741
25879
|
// hide default legend for line chart only
|
|
25742
|
-
|
|
25743
|
-
containerID: (_b2 = options.legend.customLegend) == null ? void 0 : _b2.customLegendContainerID
|
|
25744
|
-
},
|
|
25880
|
+
customLegendPlugin,
|
|
25745
25881
|
chartAreaBorder: {
|
|
25746
25882
|
borderColor: BORDER_COLOR
|
|
25747
25883
|
},
|
|
@@ -25796,7 +25932,7 @@ const useChartPlugins = ({ options, resetZoom: resetZoom2 }) => {
|
|
|
25796
25932
|
[resetZoom2]
|
|
25797
25933
|
);
|
|
25798
25934
|
const handleDoubleClick = useCallback(
|
|
25799
|
-
(
|
|
25935
|
+
(_2, args) => {
|
|
25800
25936
|
const { event } = args;
|
|
25801
25937
|
if (event.type === DOUBLE_CLICK) {
|
|
25802
25938
|
debouncedResetZoom();
|
|
@@ -25828,6 +25964,23 @@ const getAxesRangesFromChart = (chartRef, axes) => {
|
|
|
25828
25964
|
};
|
|
25829
25965
|
});
|
|
25830
25966
|
};
|
|
25967
|
+
const getAxisRangeByType = (chartRef, axesType, annotationsData) => {
|
|
25968
|
+
if (!chartRef || !chartRef.current)
|
|
25969
|
+
return null;
|
|
25970
|
+
const metasets = chartRef.current.getSortedVisibleDatasetMetas();
|
|
25971
|
+
const annotDataByType = getAnnotationsData(annotationsData)[axesType] ?? [];
|
|
25972
|
+
let allData = [];
|
|
25973
|
+
metasets.forEach((metaset) => {
|
|
25974
|
+
const data = metaset._parsed.map((parsedData) => parsedData[axesType]).filter((value) => value != null && !isNaN(value));
|
|
25975
|
+
allData = allData.concat(data);
|
|
25976
|
+
});
|
|
25977
|
+
allData = allData.concat(annotDataByType);
|
|
25978
|
+
if (allData.length === 0)
|
|
25979
|
+
return null;
|
|
25980
|
+
const min = Math.min(...allData);
|
|
25981
|
+
const max = Math.max(...allData);
|
|
25982
|
+
return { min, max };
|
|
25983
|
+
};
|
|
25831
25984
|
const useToggleCustomLegendVisibility = (memoState, memoOptions) => {
|
|
25832
25985
|
var _a2, _b2;
|
|
25833
25986
|
useEffect(() => {
|
|
@@ -25858,18 +26011,23 @@ const useStoreChartStateInStorage = (memoState, persistenceId) => {
|
|
|
25858
26011
|
]);
|
|
25859
26012
|
};
|
|
25860
26013
|
const useUpdateAxesRanges = ({
|
|
26014
|
+
chartRef,
|
|
25861
26015
|
range,
|
|
25862
26016
|
state,
|
|
25863
|
-
dispatch
|
|
26017
|
+
dispatch,
|
|
26018
|
+
annotationsData
|
|
25864
26019
|
}) => {
|
|
25865
26020
|
const prevAxes = useRef(state.axes);
|
|
25866
26021
|
useEffect(() => {
|
|
25867
26022
|
if (range && isRangeValid(range)) {
|
|
25868
|
-
const newAxes = Object.entries(range).map(([key, { min, max }]) =>
|
|
25869
|
-
|
|
25870
|
-
|
|
25871
|
-
|
|
25872
|
-
|
|
26023
|
+
const newAxes = Object.entries(range).map(([key, { min, max }]) => {
|
|
26024
|
+
const { min: minFromData = 0, max: maxFromData = 0 } = getAxisRangeByType(chartRef, key, annotationsData) ?? {};
|
|
26025
|
+
return {
|
|
26026
|
+
id: key,
|
|
26027
|
+
min: min ?? minFromData,
|
|
26028
|
+
max: max ?? maxFromData
|
|
26029
|
+
};
|
|
26030
|
+
});
|
|
25873
26031
|
const mergedAxes = [...prevAxes.current ?? []].map((axis) => {
|
|
25874
26032
|
const newAxis = newAxes.find((a2) => a2.id === axis.id);
|
|
25875
26033
|
return newAxis ? { ...axis, ...newAxis } : axis;
|
|
@@ -25884,27 +26042,21 @@ const useUpdateAxesRanges = ({
|
|
|
25884
26042
|
}
|
|
25885
26043
|
}, [range]);
|
|
25886
26044
|
};
|
|
25887
|
-
const useSaveInitialAxesRanges = (chartRef, axes,
|
|
25888
|
-
|
|
25889
|
-
|
|
25890
|
-
if (chartRef && !isEqual(generatedDatasets, prevGeneratedDatasets.current)) {
|
|
26045
|
+
const useSaveInitialAxesRanges = (chartRef, axes, dispatch) => {
|
|
26046
|
+
useEffect(() => {
|
|
26047
|
+
if (chartRef.current) {
|
|
25891
26048
|
const initialAxesRanges = getAxesRangesFromChart(chartRef, axes);
|
|
25892
26049
|
dispatch({
|
|
25893
26050
|
type: SAVE_INITIAL_AXES_RANGES,
|
|
25894
26051
|
payload: { initialAxesRanges }
|
|
25895
26052
|
});
|
|
25896
|
-
prevGeneratedDatasets.current = generatedDatasets;
|
|
25897
26053
|
}
|
|
25898
|
-
}, [
|
|
25899
|
-
useEffect(() => {
|
|
25900
|
-
saveInitialAxesRanges();
|
|
25901
|
-
}, [saveInitialAxesRanges, generatedDatasets]);
|
|
26054
|
+
}, []);
|
|
25902
26055
|
};
|
|
25903
26056
|
const useChartState = ({
|
|
25904
26057
|
chartRef,
|
|
25905
26058
|
options,
|
|
25906
26059
|
state,
|
|
25907
|
-
generatedDatasets,
|
|
25908
26060
|
dispatch,
|
|
25909
26061
|
persistenceId
|
|
25910
26062
|
}) => {
|
|
@@ -25912,12 +26064,19 @@ const useChartState = ({
|
|
|
25912
26064
|
const memoOptions = useMemo(() => options, [options]);
|
|
25913
26065
|
const {
|
|
25914
26066
|
additionalAxesOptions: { range = void 0 },
|
|
26067
|
+
annotations: { annotationsData = [] } = {},
|
|
25915
26068
|
axes
|
|
25916
26069
|
} = memoOptions;
|
|
25917
26070
|
useStoreChartStateInStorage(memoState, persistenceId);
|
|
25918
26071
|
useToggleCustomLegendVisibility(memoState, memoOptions);
|
|
25919
|
-
useUpdateAxesRanges({
|
|
25920
|
-
|
|
26072
|
+
useUpdateAxesRanges({
|
|
26073
|
+
range,
|
|
26074
|
+
state: memoState,
|
|
26075
|
+
dispatch,
|
|
26076
|
+
chartRef,
|
|
26077
|
+
annotationsData
|
|
26078
|
+
});
|
|
26079
|
+
useSaveInitialAxesRanges(chartRef, axes, dispatch);
|
|
25921
26080
|
};
|
|
25922
26081
|
const WORD_SEPARATOR = " ";
|
|
25923
26082
|
const SEMI_TRANSPARENT = "rgba(0, 0, 0, 0.5)";
|
|
@@ -26123,6 +26282,7 @@ Chart$2.register(
|
|
|
26123
26282
|
chartAreaTextPlugin
|
|
26124
26283
|
);
|
|
26125
26284
|
const LineChart = (props) => {
|
|
26285
|
+
var _a2, _b2;
|
|
26126
26286
|
setDefaultTheme();
|
|
26127
26287
|
const chartRef = useRef(null);
|
|
26128
26288
|
const { table: table2 } = props;
|
|
@@ -26136,7 +26296,7 @@ const LineChart = (props) => {
|
|
|
26136
26296
|
controlsPortalId
|
|
26137
26297
|
} = chart2;
|
|
26138
26298
|
const { annotations, axes, chartStyling, graph } = options;
|
|
26139
|
-
const showCustomLegend = !options.legend.customLegend.customLegendContainerID;
|
|
26299
|
+
const showCustomLegend = !((_b2 = (_a2 = options == null ? void 0 : options.legend) == null ? void 0 : _a2.customLegend) == null ? void 0 : _b2.customLegendContainerID);
|
|
26140
26300
|
const [state, dispatch] = useReducer(
|
|
26141
26301
|
reducer$1,
|
|
26142
26302
|
{
|
|
@@ -26152,7 +26312,6 @@ const LineChart = (props) => {
|
|
|
26152
26312
|
chartRef,
|
|
26153
26313
|
options,
|
|
26154
26314
|
state,
|
|
26155
|
-
generatedDatasets,
|
|
26156
26315
|
dispatch,
|
|
26157
26316
|
persistenceId
|
|
26158
26317
|
});
|
|
@@ -39049,7 +39208,7 @@ const defaultInteractions = (interactions) => ({
|
|
|
39049
39208
|
onUnhover: interactions == null ? void 0 : interactions.onUnhover
|
|
39050
39209
|
});
|
|
39051
39210
|
const defaultDragData = (dragData) => ({
|
|
39052
|
-
enableDragData: (dragData == null ? void 0 : dragData.enableDragData)
|
|
39211
|
+
enableDragData: (dragData == null ? void 0 : dragData.enableDragData) ?? false,
|
|
39053
39212
|
showTooltip: (dragData == null ? void 0 : dragData.showTooltip) ?? true,
|
|
39054
39213
|
roundPoints: (dragData == null ? void 0 : dragData.roundPoints) ?? true,
|
|
39055
39214
|
dragX: (dragData == null ? void 0 : dragData.dragX) ?? true,
|
|
@@ -39311,7 +39470,7 @@ const BarChart = (props) => {
|
|
|
39311
39470
|
const [pointHover, setPointHover] = useState(false);
|
|
39312
39471
|
const chart2 = getDefaultProps(props);
|
|
39313
39472
|
const { options, testId } = chart2;
|
|
39314
|
-
const { annotations, chartStyling, interactions, graph } = chart2.options;
|
|
39473
|
+
const { annotations, chartStyling, interactions, graph, dragData } = chart2.options;
|
|
39315
39474
|
const [visibleAnnotationsIndices, setVisibleAnnotationsIndices] = useState(
|
|
39316
39475
|
setAnnotations(annotations.annotationsData)
|
|
39317
39476
|
);
|
|
@@ -39436,9 +39595,6 @@ const BarChart = (props) => {
|
|
|
39436
39595
|
mode: ChartHoverMode.Nearest,
|
|
39437
39596
|
intersect: true
|
|
39438
39597
|
},
|
|
39439
|
-
// elements: {
|
|
39440
|
-
// bar: { pointStyle: PointStyle.Circle },
|
|
39441
|
-
// },
|
|
39442
39598
|
scales: getBarChartScales(chart2),
|
|
39443
39599
|
plugins: {
|
|
39444
39600
|
title: getTitle(options),
|
|
@@ -39454,7 +39610,7 @@ const BarChart = (props) => {
|
|
|
39454
39610
|
chartAreaBorder: {
|
|
39455
39611
|
borderColor: BORDER_COLOR
|
|
39456
39612
|
},
|
|
39457
|
-
dragData: getDraggableData(options)
|
|
39613
|
+
dragData: (dragData == null ? void 0 : dragData.enableDragData) && getDraggableData(options)
|
|
39458
39614
|
}
|
|
39459
39615
|
},
|
|
39460
39616
|
plugins: getPlugins(graph, options.legend)
|