@oliasoft-open-source/charts-library 3.6.3 → 3.6.5-beta-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 +72 -53
- package/dist/index.js.map +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 +0 -8
- package/dist/src/components/line-chart/hooks/use-chart-state.d.ts +2 -3
- package/dist/src/components/line-chart/line-chart.stories.d.ts +32 -0
- 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/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import { round as round$2, displayNumber, isCloseTo, roundByMagnitude, toNum } f
|
|
|
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
|
|
@@ -22877,7 +22877,8 @@ const LineOptions = ({
|
|
|
22877
22877
|
onToggleLine,
|
|
22878
22878
|
onTogglePoints,
|
|
22879
22879
|
pointsEnabled,
|
|
22880
|
-
translations
|
|
22880
|
+
translations,
|
|
22881
|
+
hasCustomOpt
|
|
22881
22882
|
}) => {
|
|
22882
22883
|
const options = [
|
|
22883
22884
|
{
|
|
@@ -22907,17 +22908,26 @@ const LineOptions = ({
|
|
|
22907
22908
|
}
|
|
22908
22909
|
];
|
|
22909
22910
|
const selectedOption = options.find((option) => option.selected);
|
|
22910
|
-
return /* @__PURE__ */ jsx(
|
|
22911
|
-
|
|
22911
|
+
return /* @__PURE__ */ jsx(
|
|
22912
|
+
Tooltip$2,
|
|
22912
22913
|
{
|
|
22913
|
-
|
|
22914
|
-
|
|
22915
|
-
|
|
22916
|
-
|
|
22917
|
-
|
|
22918
|
-
|
|
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
|
+
)
|
|
22919
22929
|
}
|
|
22920
|
-
)
|
|
22930
|
+
);
|
|
22921
22931
|
};
|
|
22922
22932
|
function TbHandStop(props) {
|
|
22923
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);
|
|
@@ -23994,7 +24004,6 @@ const useChartFunctions = ({
|
|
|
23994
24004
|
onHover: onPointHover,
|
|
23995
24005
|
onUnhover: onPointUnhover
|
|
23996
24006
|
},
|
|
23997
|
-
additionalAxesOptions,
|
|
23998
24007
|
axes
|
|
23999
24008
|
} = options;
|
|
24000
24009
|
const legendClick = useCallback(
|
|
@@ -24101,18 +24110,6 @@ const useChartFunctions = ({
|
|
|
24101
24110
|
},
|
|
24102
24111
|
[chartRef]
|
|
24103
24112
|
);
|
|
24104
|
-
const controlsAxes = state.axes.map((axis, i2) => {
|
|
24105
|
-
var _a2, _b2, _c2, _d2;
|
|
24106
|
-
const axisType = i2 ? AxisType.Y : AxisType.X;
|
|
24107
|
-
const min = axis.min ?? ((_b2 = (_a2 = additionalAxesOptions == null ? void 0 : additionalAxesOptions.range) == null ? void 0 : _a2[axisType]) == null ? void 0 : _b2.min);
|
|
24108
|
-
const max = axis.max ?? ((_d2 = (_c2 = additionalAxesOptions == null ? void 0 : additionalAxesOptions.range) == null ? void 0 : _c2[axisType]) == null ? void 0 : _d2.max);
|
|
24109
|
-
return {
|
|
24110
|
-
...axis,
|
|
24111
|
-
// only add min and max properties if they are defined:
|
|
24112
|
-
...min ? { min } : {},
|
|
24113
|
-
...max ? { max } : {}
|
|
24114
|
-
};
|
|
24115
|
-
});
|
|
24116
24113
|
const getControlsAxesLabels = useCallback(
|
|
24117
24114
|
(propsAxes) => {
|
|
24118
24115
|
var _a2;
|
|
@@ -24170,7 +24167,6 @@ const useChartFunctions = ({
|
|
|
24170
24167
|
handleDownload,
|
|
24171
24168
|
handleKeyDown,
|
|
24172
24169
|
handleKeyUp,
|
|
24173
|
-
controlsAxes,
|
|
24174
24170
|
controlsAxesLabels: getControlsAxesLabels(axes),
|
|
24175
24171
|
updateAxesRangesFromChart,
|
|
24176
24172
|
onResetAxes,
|
|
@@ -24187,7 +24183,7 @@ const initializeFormState = ({
|
|
|
24187
24183
|
initialAxesRanges,
|
|
24188
24184
|
axes = []
|
|
24189
24185
|
}) => {
|
|
24190
|
-
|
|
24186
|
+
const res = (initialAxesRanges == null ? void 0 : initialAxesRanges.map((initialAxisRange) => {
|
|
24191
24187
|
const currentAxisRange = axes.find((a2) => a2.id === initialAxisRange.id);
|
|
24192
24188
|
return {
|
|
24193
24189
|
id: initialAxisRange.id,
|
|
@@ -24196,6 +24192,8 @@ const initializeFormState = ({
|
|
|
24196
24192
|
unit: currentAxisRange == null ? void 0 : currentAxisRange.unit
|
|
24197
24193
|
};
|
|
24198
24194
|
})) || [];
|
|
24195
|
+
console.log(res);
|
|
24196
|
+
return res;
|
|
24199
24197
|
};
|
|
24200
24198
|
const isEmptyString = (value) => value === "";
|
|
24201
24199
|
const createErrorMessages = (value, compareTo, type) => {
|
|
@@ -24263,9 +24261,9 @@ const AxesOptionsPopover = (optionsPopover) => {
|
|
|
24263
24261
|
controlsAxesLabels,
|
|
24264
24262
|
onUpdateAxes,
|
|
24265
24263
|
onResetAxes,
|
|
24266
|
-
close,
|
|
24267
24264
|
depthType,
|
|
24268
|
-
translations
|
|
24265
|
+
translations,
|
|
24266
|
+
close
|
|
24269
24267
|
} = optionsPopover;
|
|
24270
24268
|
const [depthTypeState, setDepthTypeState] = useState(
|
|
24271
24269
|
depthType == null ? void 0 : depthType.selectedDepthType
|
|
@@ -24278,6 +24276,7 @@ const AxesOptionsPopover = (optionsPopover) => {
|
|
|
24278
24276
|
},
|
|
24279
24277
|
initializeFormState
|
|
24280
24278
|
);
|
|
24279
|
+
console.log(formState);
|
|
24281
24280
|
const { errors, valid } = validateAxes(formState);
|
|
24282
24281
|
const onEditValue = ({ name, value, id }) => {
|
|
24283
24282
|
dispatch({
|
|
@@ -24489,6 +24488,27 @@ const ControlsPortal = ({
|
|
|
24489
24488
|
}
|
|
24490
24489
|
return children;
|
|
24491
24490
|
};
|
|
24491
|
+
const checkCustomOption = (data, customOptions) => {
|
|
24492
|
+
if (isEmpty(data) || isEmpty(customOptions))
|
|
24493
|
+
return false;
|
|
24494
|
+
const checkOption = (dataset) => {
|
|
24495
|
+
if (typeof customOptions === "string") {
|
|
24496
|
+
return has(dataset, customOptions);
|
|
24497
|
+
} else if (isArray$2(customOptions)) {
|
|
24498
|
+
return some(customOptions, (option) => has(dataset, option));
|
|
24499
|
+
} else {
|
|
24500
|
+
return some(
|
|
24501
|
+
Object.values(customOptions),
|
|
24502
|
+
(option) => has(dataset, option)
|
|
24503
|
+
);
|
|
24504
|
+
}
|
|
24505
|
+
};
|
|
24506
|
+
if (isArray$2(data)) {
|
|
24507
|
+
return some(data, (dataset) => checkOption(dataset));
|
|
24508
|
+
} else {
|
|
24509
|
+
return checkOption(data);
|
|
24510
|
+
}
|
|
24511
|
+
};
|
|
24492
24512
|
const Controls = ({
|
|
24493
24513
|
headerComponent,
|
|
24494
24514
|
subheaderComponent,
|
|
@@ -24520,19 +24540,14 @@ const Controls = ({
|
|
|
24520
24540
|
onToggleDragPoints,
|
|
24521
24541
|
onDisableDragOptions
|
|
24522
24542
|
} = useToggleHandlers(dispatch);
|
|
24523
|
-
const {
|
|
24524
|
-
handleDownload,
|
|
24525
|
-
controlsAxes,
|
|
24526
|
-
controlsAxesLabels,
|
|
24527
|
-
onResetAxes,
|
|
24528
|
-
onUpdateAxes
|
|
24529
|
-
} = useChartFunctions({
|
|
24543
|
+
const { handleDownload, controlsAxesLabels, onResetAxes, onUpdateAxes } = useChartFunctions({
|
|
24530
24544
|
chartRef,
|
|
24531
24545
|
state,
|
|
24532
24546
|
options,
|
|
24533
24547
|
dispatch,
|
|
24534
24548
|
generatedDatasets
|
|
24535
24549
|
});
|
|
24550
|
+
const hasCustomOpt = checkCustomOption(generatedDatasets, "hasCustomOpt");
|
|
24536
24551
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
24537
24552
|
/* @__PURE__ */ jsxs("div", { className: styles$3.controls, children: [
|
|
24538
24553
|
!!options.title && /* @__PURE__ */ jsx(Text, { bold: true, children: options.title }),
|
|
@@ -24543,7 +24558,7 @@ const Controls = ({
|
|
|
24543
24558
|
AxesOptions,
|
|
24544
24559
|
{
|
|
24545
24560
|
initialAxesRanges,
|
|
24546
|
-
axes:
|
|
24561
|
+
axes: state.axes,
|
|
24547
24562
|
controlsAxesLabels,
|
|
24548
24563
|
onUpdateAxes,
|
|
24549
24564
|
onResetAxes,
|
|
@@ -24558,7 +24573,8 @@ const Controls = ({
|
|
|
24558
24573
|
pointsEnabled,
|
|
24559
24574
|
onToggleLine,
|
|
24560
24575
|
onTogglePoints,
|
|
24561
|
-
translations
|
|
24576
|
+
translations,
|
|
24577
|
+
hasCustomOpt
|
|
24562
24578
|
}
|
|
24563
24579
|
),
|
|
24564
24580
|
/* @__PURE__ */ jsx(
|
|
@@ -25135,6 +25151,11 @@ const INIT_KEYS = {
|
|
|
25135
25151
|
};
|
|
25136
25152
|
const LOWER_BOUND = 1e-4;
|
|
25137
25153
|
const UPPER_BOUND = 1e7;
|
|
25154
|
+
var CUSTOM_OPTION = /* @__PURE__ */ ((CUSTOM_OPTION2) => {
|
|
25155
|
+
CUSTOM_OPTION2["showLine"] = "showLine";
|
|
25156
|
+
CUSTOM_OPTION2["showPoints"] = "showPoints";
|
|
25157
|
+
return CUSTOM_OPTION2;
|
|
25158
|
+
})(CUSTOM_OPTION || {});
|
|
25138
25159
|
const generateLineChartDatasets = (datasets, state, options, { label }) => {
|
|
25139
25160
|
const copyDataset = [...datasets];
|
|
25140
25161
|
const { annotations, graph } = options;
|
|
@@ -25176,7 +25197,9 @@ const generateLineChartDatasets = (datasets, state, options, { label }) => {
|
|
|
25176
25197
|
borderColor,
|
|
25177
25198
|
backgroundColor,
|
|
25178
25199
|
pointBackgroundColor,
|
|
25179
|
-
borderDash
|
|
25200
|
+
borderDash,
|
|
25201
|
+
showPoints = true,
|
|
25202
|
+
showLine
|
|
25180
25203
|
} = line ?? {};
|
|
25181
25204
|
const { lineEnabled, pointsEnabled, axes = [] } = state ?? {};
|
|
25182
25205
|
const { lineTension, spanGaps } = graph ?? {};
|
|
@@ -25194,14 +25217,15 @@ const generateLineChartDatasets = (datasets, state, options, { label }) => {
|
|
|
25194
25217
|
const filteredData = data.filter(Boolean) || [];
|
|
25195
25218
|
const isSinglePoint = (filteredData == null ? void 0 : filteredData.length) === 1;
|
|
25196
25219
|
const linePointRadius = parseFloat(pointRadiusProp) || DEFAULT_POINT_RADIUS;
|
|
25197
|
-
const pointRadius = pointsEnabled || isSinglePoint ? linePointRadius : 0;
|
|
25220
|
+
const pointRadius = (pointsEnabled || isSinglePoint) && showPoints ? linePointRadius : 0;
|
|
25198
25221
|
const hoverRadius = parseFloat(pointHoverRadius) || DEFAULT_HOVER_RADIUS;
|
|
25199
25222
|
const indexedColor = COLORS[i2];
|
|
25223
|
+
const hasCustomOpt = checkCustomOption(line, CUSTOM_OPTION);
|
|
25200
25224
|
return {
|
|
25201
25225
|
...line,
|
|
25202
25226
|
label: line.label || `${label} ${i2 + 1}`,
|
|
25203
25227
|
data: filteredData,
|
|
25204
|
-
showLine: lineEnabled,
|
|
25228
|
+
showLine: showLine ?? lineEnabled,
|
|
25205
25229
|
lineTension,
|
|
25206
25230
|
spanGaps,
|
|
25207
25231
|
borderWidth: parseFloat(borderWidth) || DEFAULT_BORDER_WIDTH,
|
|
@@ -25212,7 +25236,8 @@ const generateLineChartDatasets = (datasets, state, options, { label }) => {
|
|
|
25212
25236
|
pointBackgroundColor: pointBackgroundColor ?? indexedColor ?? generateRandomColor(COLORS),
|
|
25213
25237
|
pointRadius,
|
|
25214
25238
|
pointHoverRadius: hoverRadius,
|
|
25215
|
-
pointHitRadius: line.pointHitRadius ?? hoverRadius
|
|
25239
|
+
pointHitRadius: line.pointHitRadius ?? hoverRadius,
|
|
25240
|
+
...hasCustomOpt ? { hasCustomOpt } : {}
|
|
25216
25241
|
};
|
|
25217
25242
|
});
|
|
25218
25243
|
};
|
|
@@ -25943,27 +25968,22 @@ const useUpdateAxesRanges = ({
|
|
|
25943
25968
|
}
|
|
25944
25969
|
}, [range]);
|
|
25945
25970
|
};
|
|
25946
|
-
const useSaveInitialAxesRanges = (chartRef, axes,
|
|
25947
|
-
|
|
25948
|
-
|
|
25949
|
-
if (chartRef && !isEqual(generatedDatasets, prevGeneratedDatasets.current)) {
|
|
25971
|
+
const useSaveInitialAxesRanges = (chartRef, axes, dispatch) => {
|
|
25972
|
+
useEffect(() => {
|
|
25973
|
+
if (chartRef.current) {
|
|
25950
25974
|
const initialAxesRanges = getAxesRangesFromChart(chartRef, axes);
|
|
25975
|
+
console.log("initialAxesRanges", initialAxesRanges);
|
|
25951
25976
|
dispatch({
|
|
25952
25977
|
type: SAVE_INITIAL_AXES_RANGES,
|
|
25953
25978
|
payload: { initialAxesRanges }
|
|
25954
25979
|
});
|
|
25955
|
-
prevGeneratedDatasets.current = generatedDatasets;
|
|
25956
25980
|
}
|
|
25957
|
-
}, [
|
|
25958
|
-
useEffect(() => {
|
|
25959
|
-
saveInitialAxesRanges();
|
|
25960
|
-
}, [saveInitialAxesRanges, generatedDatasets]);
|
|
25981
|
+
}, []);
|
|
25961
25982
|
};
|
|
25962
25983
|
const useChartState = ({
|
|
25963
25984
|
chartRef,
|
|
25964
25985
|
options,
|
|
25965
25986
|
state,
|
|
25966
|
-
generatedDatasets,
|
|
25967
25987
|
dispatch,
|
|
25968
25988
|
persistenceId
|
|
25969
25989
|
}) => {
|
|
@@ -25983,7 +26003,7 @@ const useChartState = ({
|
|
|
25983
26003
|
chartRef,
|
|
25984
26004
|
annotationsData
|
|
25985
26005
|
});
|
|
25986
|
-
useSaveInitialAxesRanges(chartRef, axes,
|
|
26006
|
+
useSaveInitialAxesRanges(chartRef, axes, dispatch);
|
|
25987
26007
|
};
|
|
25988
26008
|
const WORD_SEPARATOR = " ";
|
|
25989
26009
|
const SEMI_TRANSPARENT = "rgba(0, 0, 0, 0.5)";
|
|
@@ -26219,7 +26239,6 @@ const LineChart = (props) => {
|
|
|
26219
26239
|
chartRef,
|
|
26220
26240
|
options,
|
|
26221
26241
|
state,
|
|
26222
|
-
generatedDatasets,
|
|
26223
26242
|
dispatch,
|
|
26224
26243
|
persistenceId
|
|
26225
26244
|
});
|