@oliasoft-open-source/charts-library 3.8.0-beta-3 → 3.8.1-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 +66 -90
- package/dist/index.js.map +1 -1
- package/dist/src/components/line-chart/hooks/use-chart-options.d.ts +302 -0
- package/dist/src/components/line-chart/line-chart.interface.d.ts +32 -25
- package/dist/src/components/line-chart/line-chart.stories.d.ts +32 -65
- package/dist/src/components/line-chart/plugins/plugin-constants.d.ts +0 -1
- package/dist/src/components/line-chart/utils/check-custom-option/check-custom-option.d.ts +1 -1
- package/dist/src/components/line-chart/utils/elipsis-annotation/ellipsis-annotation.d.ts +1 -0
- package/dist/src/components/line-chart/utils/generate-line-chart-datasets.d.ts +3 -8
- package/package.json +1 -1
- package/dist/src/components/line-chart/plugins/custom-point-ellipsis-plugin.d.ts +0 -6
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
|
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
10
|
import { produce } from "immer";
|
|
11
|
-
import { round as round$2, displayNumber, isCloseTo, roundByMagnitude,
|
|
11
|
+
import { round as round$2, displayNumber, isCloseTo, roundByMagnitude, toNum } from "@oliasoft-open-source/units";
|
|
12
12
|
import cx from "classnames";
|
|
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
14
|
import { isEmpty, isArray as isArray$2, some, has, debounce as debounce$3 } from "lodash";
|
|
@@ -24957,7 +24957,6 @@ const TextLabelPosition = {
|
|
|
24957
24957
|
BOTTOM_CENTER: "bottom-center",
|
|
24958
24958
|
BOTTOM_RIGHT: "bottom-right"
|
|
24959
24959
|
};
|
|
24960
|
-
const DEGTORAD = 90;
|
|
24961
24960
|
const defaultAxis = (position) => ({
|
|
24962
24961
|
label: "",
|
|
24963
24962
|
position,
|
|
@@ -25009,24 +25008,17 @@ const defaultGraph$2 = (graph) => ({
|
|
|
25009
25008
|
showMinorGridlines: (graph == null ? void 0 : graph.showMinorGridlines) ?? false
|
|
25010
25009
|
});
|
|
25011
25010
|
const defaultAnnotations$1 = (annotations) => {
|
|
25012
|
-
var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2
|
|
25011
|
+
var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2;
|
|
25013
25012
|
return {
|
|
25014
|
-
pointEllipsisAnnotation: {
|
|
25015
|
-
radiusX: ((_a2 = annotations == null ? void 0 : annotations.pointEllipsisAnnotation) == null ? void 0 : _a2.radiusX) ?? 10,
|
|
25016
|
-
radiusY: ((_b2 = annotations == null ? void 0 : annotations.pointEllipsisAnnotation) == null ? void 0 : _b2.radiusY) ?? 5,
|
|
25017
|
-
color: (_c2 = annotations == null ? void 0 : annotations.pointEllipsisAnnotation) == null ? void 0 : _c2.color,
|
|
25018
|
-
rotation: ((_d2 = annotations == null ? void 0 : annotations.pointEllipsisAnnotation) == null ? void 0 : _d2.rotation) ?? DEGTORAD,
|
|
25019
|
-
lineWidth: ((_e2 = annotations == null ? void 0 : annotations.pointEllipsisAnnotation) == null ? void 0 : _e2.lineWidth) ?? 1
|
|
25020
|
-
},
|
|
25021
25013
|
labelAnnotation: {
|
|
25022
|
-
showLabel: ((
|
|
25023
|
-
text: ((
|
|
25024
|
-
position: ((
|
|
25025
|
-
fontSize: ((
|
|
25026
|
-
xOffset: ((
|
|
25027
|
-
yOffset: ((
|
|
25028
|
-
maxWidth: ((
|
|
25029
|
-
lineHeight: ((
|
|
25014
|
+
showLabel: ((_a2 = annotations == null ? void 0 : annotations.labelAnnotation) == null ? void 0 : _a2.showLabel) ?? false,
|
|
25015
|
+
text: ((_b2 = annotations == null ? void 0 : annotations.labelAnnotation) == null ? void 0 : _b2.text) ?? "",
|
|
25016
|
+
position: ((_c2 = annotations == null ? void 0 : annotations.labelAnnotation) == null ? void 0 : _c2.position) ?? TextLabelPosition.BOTTOM_RIGHT,
|
|
25017
|
+
fontSize: ((_d2 = annotations == null ? void 0 : annotations.labelAnnotation) == null ? void 0 : _d2.fontSize) ?? 12,
|
|
25018
|
+
xOffset: ((_e2 = annotations == null ? void 0 : annotations.labelAnnotation) == null ? void 0 : _e2.xOffset) ?? 5,
|
|
25019
|
+
yOffset: ((_f2 = annotations == null ? void 0 : annotations.labelAnnotation) == null ? void 0 : _f2.yOffset) ?? 5,
|
|
25020
|
+
maxWidth: ((_g2 = annotations == null ? void 0 : annotations.labelAnnotation) == null ? void 0 : _g2.maxWidth) ?? 300,
|
|
25021
|
+
lineHeight: ((_h2 = annotations == null ? void 0 : annotations.labelAnnotation) == null ? void 0 : _h2.lineHeight) ?? 12
|
|
25030
25022
|
},
|
|
25031
25023
|
showAnnotations: (annotations == null ? void 0 : annotations.showAnnotations) ?? false,
|
|
25032
25024
|
controlAnnotation: (annotations == null ? void 0 : annotations.controlAnnotation) ?? false,
|
|
@@ -25171,11 +25163,14 @@ const generateLineChartDatasets = (datasets, state, options, { label }) => {
|
|
|
25171
25163
|
}
|
|
25172
25164
|
const filteredData = data.filter(Boolean) || [];
|
|
25173
25165
|
const isSinglePoint = (filteredData == null ? void 0 : filteredData.length) === 1;
|
|
25174
|
-
const linePointRadius = parseFloat(pointRadiusProp) || DEFAULT_POINT_RADIUS;
|
|
25166
|
+
const linePointRadius = parseFloat(String(pointRadiusProp)) || DEFAULT_POINT_RADIUS;
|
|
25175
25167
|
const pointRadius = (pointsEnabled || isSinglePoint) && showPoints ? linePointRadius : 0;
|
|
25176
|
-
const hoverRadius = parseFloat(pointHoverRadius) || DEFAULT_HOVER_RADIUS;
|
|
25168
|
+
const hoverRadius = parseFloat(String(pointHoverRadius)) || DEFAULT_HOVER_RADIUS;
|
|
25177
25169
|
const indexedColor = COLORS[i2];
|
|
25178
|
-
const hasCustomOpt = checkCustomOption(
|
|
25170
|
+
const hasCustomOpt = checkCustomOption(
|
|
25171
|
+
line,
|
|
25172
|
+
CUSTOM_OPTION
|
|
25173
|
+
);
|
|
25179
25174
|
return {
|
|
25180
25175
|
...line,
|
|
25181
25176
|
label: line.label || `${label} ${i2 + 1}`,
|
|
@@ -25183,7 +25178,7 @@ const generateLineChartDatasets = (datasets, state, options, { label }) => {
|
|
|
25183
25178
|
showLine: showLine ?? lineEnabled,
|
|
25184
25179
|
lineTension,
|
|
25185
25180
|
spanGaps,
|
|
25186
|
-
borderWidth: parseFloat(borderWidth) || DEFAULT_BORDER_WIDTH,
|
|
25181
|
+
borderWidth: parseFloat(String(borderWidth)) || DEFAULT_BORDER_WIDTH,
|
|
25187
25182
|
borderDash: borderDash || [],
|
|
25188
25183
|
borderJoinStyle: BORDER_JOIN_STYLE,
|
|
25189
25184
|
borderColor: borderColor ?? indexedColor ?? generateRandomColor(COLORS),
|
|
@@ -25192,7 +25187,6 @@ const generateLineChartDatasets = (datasets, state, options, { label }) => {
|
|
|
25192
25187
|
pointRadius,
|
|
25193
25188
|
pointHoverRadius: hoverRadius,
|
|
25194
25189
|
pointHitRadius: line.pointHitRadius ?? hoverRadius,
|
|
25195
|
-
showEllipsesAnnotation: (line == null ? void 0 : line.showEllipsesAnnotation) ?? false,
|
|
25196
25190
|
...hasCustomOpt ? { hasCustomOpt } : {}
|
|
25197
25191
|
};
|
|
25198
25192
|
});
|
|
@@ -25664,6 +25658,46 @@ const getDraggableData = (options) => {
|
|
|
25664
25658
|
}
|
|
25665
25659
|
} : {};
|
|
25666
25660
|
};
|
|
25661
|
+
const ellipseAnnotationsConfig = ({
|
|
25662
|
+
data,
|
|
25663
|
+
borderColor: pointBorderColor
|
|
25664
|
+
}) => {
|
|
25665
|
+
return data == null ? void 0 : data.map(({ ellipseOptions }, index2) => {
|
|
25666
|
+
if (!ellipseOptions)
|
|
25667
|
+
return;
|
|
25668
|
+
const {
|
|
25669
|
+
xMinPoint,
|
|
25670
|
+
xMaxPoint,
|
|
25671
|
+
yMinPoint,
|
|
25672
|
+
yMaxPoint,
|
|
25673
|
+
rotation,
|
|
25674
|
+
borderColor = pointBorderColor,
|
|
25675
|
+
backgroundColor = "rgba(0, 0, 0, 0)"
|
|
25676
|
+
} = ellipseOptions ?? {};
|
|
25677
|
+
return {
|
|
25678
|
+
id: `ellipse${index2}`,
|
|
25679
|
+
type: "ellipse",
|
|
25680
|
+
xMin: xMinPoint,
|
|
25681
|
+
xMax: xMaxPoint,
|
|
25682
|
+
yMin: yMinPoint,
|
|
25683
|
+
yMax: yMaxPoint,
|
|
25684
|
+
rotation,
|
|
25685
|
+
borderColor,
|
|
25686
|
+
backgroundColor
|
|
25687
|
+
};
|
|
25688
|
+
}).filter(Boolean);
|
|
25689
|
+
};
|
|
25690
|
+
const ellipsisAnnotation = (datasets) => {
|
|
25691
|
+
return datasets.flatMap((dataset) => ellipseAnnotationsConfig(dataset)).reduce(
|
|
25692
|
+
(acc, annotation2) => {
|
|
25693
|
+
if (annotation2) {
|
|
25694
|
+
acc[annotation2.id] = annotation2;
|
|
25695
|
+
}
|
|
25696
|
+
return acc;
|
|
25697
|
+
},
|
|
25698
|
+
{}
|
|
25699
|
+
);
|
|
25700
|
+
};
|
|
25667
25701
|
const useChartOptions = ({
|
|
25668
25702
|
chartRef,
|
|
25669
25703
|
state,
|
|
@@ -25748,9 +25782,15 @@ const useChartOptions = ({
|
|
|
25748
25782
|
}),
|
|
25749
25783
|
[zoomEnabled]
|
|
25750
25784
|
);
|
|
25785
|
+
const mergedAnnotation = {
|
|
25786
|
+
...annotation2.annotations,
|
|
25787
|
+
...ellipsisAnnotation(generatedDatasets)
|
|
25788
|
+
};
|
|
25751
25789
|
const plugins = {
|
|
25752
25790
|
datalabels,
|
|
25753
|
-
annotation:
|
|
25791
|
+
annotation: {
|
|
25792
|
+
annotations: mergedAnnotation
|
|
25793
|
+
},
|
|
25754
25794
|
zoom: { pan: panOptions, zoom: zoomOptions },
|
|
25755
25795
|
tooltip,
|
|
25756
25796
|
legend: { ...legend2, display: false },
|
|
@@ -25800,67 +25840,6 @@ const useChartOptions = ({
|
|
|
25800
25840
|
[state, options, chartRef]
|
|
25801
25841
|
);
|
|
25802
25842
|
};
|
|
25803
|
-
const customPointEllipsisPlugin = (options) => {
|
|
25804
|
-
var _a2;
|
|
25805
|
-
const { radiusX, radiusY, rotation, lineWidth, color: color2 } = ((_a2 = options == null ? void 0 : options.annotations) == null ? void 0 : _a2.pointEllipsisAnnotation) ?? {};
|
|
25806
|
-
return {
|
|
25807
|
-
id: "ellipseAnnotation",
|
|
25808
|
-
afterDatasetsDraw: (chart2) => {
|
|
25809
|
-
var _a3, _b2, _c2;
|
|
25810
|
-
const { ctx, chartArea } = chart2;
|
|
25811
|
-
if (isEmpty((_a3 = options == null ? void 0 : options.annotations) == null ? void 0 : _a3.pointEllipsisAnnotation))
|
|
25812
|
-
return;
|
|
25813
|
-
(_c2 = (_b2 = chart2 == null ? void 0 : chart2.data) == null ? void 0 : _b2.datasets) == null ? void 0 : _c2.forEach(
|
|
25814
|
-
(dataset, datasetIndex) => {
|
|
25815
|
-
const meta = chart2.getDatasetMeta(datasetIndex);
|
|
25816
|
-
if (!meta.hidden && dataset.showEllipsesAnnotation) {
|
|
25817
|
-
meta.data.forEach((element, index2) => {
|
|
25818
|
-
var _a4, _b3;
|
|
25819
|
-
const pointElement = element;
|
|
25820
|
-
const { x: x2, y: y2 } = ((_a4 = pointElement.getCenterPoint) == null ? void 0 : _a4.call(pointElement)) || {
|
|
25821
|
-
x: 0,
|
|
25822
|
-
y: 0
|
|
25823
|
-
};
|
|
25824
|
-
if (x2 < chartArea.left || x2 > chartArea.right || y2 < chartArea.top || y2 > chartArea.bottom) {
|
|
25825
|
-
return;
|
|
25826
|
-
}
|
|
25827
|
-
const { ellipseOptions } = (_b3 = dataset == null ? void 0 : dataset.data) == null ? void 0 : _b3[index2];
|
|
25828
|
-
const {
|
|
25829
|
-
radiusX: ellipseRadiusX = radiusX ?? 0,
|
|
25830
|
-
radiusY: ellipseRadiusY = radiusY ?? 0,
|
|
25831
|
-
rotation: ellipseRotation = rotation,
|
|
25832
|
-
lineWidth: ellipseLineWidth = lineWidth,
|
|
25833
|
-
color: ellipseColor = color2
|
|
25834
|
-
} = ellipseOptions ?? {};
|
|
25835
|
-
const borderPointPixel = {
|
|
25836
|
-
x: chart2.scales.x.getPixelForValue(Math.abs(ellipseRadiusX)),
|
|
25837
|
-
y: chart2.scales.y.getPixelForValue(Math.abs(ellipseRadiusY))
|
|
25838
|
-
};
|
|
25839
|
-
const customRadiusX = Math.abs(borderPointPixel.x - x2);
|
|
25840
|
-
const customRadiusY = Math.abs(borderPointPixel.y - y2);
|
|
25841
|
-
const customRotation = to$2(Number(ellipseRotation), "deg", "rad");
|
|
25842
|
-
ctx.save();
|
|
25843
|
-
ctx.strokeStyle = ellipseColor ?? color2 ?? dataset.borderColor ?? COLORS[datasetIndex];
|
|
25844
|
-
ctx.lineWidth = ellipseLineWidth ?? lineWidth ?? 1;
|
|
25845
|
-
ctx.beginPath();
|
|
25846
|
-
ctx.ellipse(
|
|
25847
|
-
x2,
|
|
25848
|
-
y2,
|
|
25849
|
-
customRadiusX,
|
|
25850
|
-
customRadiusY,
|
|
25851
|
-
customRotation,
|
|
25852
|
-
0,
|
|
25853
|
-
2 * Math.PI
|
|
25854
|
-
);
|
|
25855
|
-
ctx.stroke();
|
|
25856
|
-
ctx.restore();
|
|
25857
|
-
});
|
|
25858
|
-
}
|
|
25859
|
-
}
|
|
25860
|
-
);
|
|
25861
|
-
}
|
|
25862
|
-
};
|
|
25863
|
-
};
|
|
25864
25843
|
const useChartPlugins = ({ options, resetZoom: resetZoom2 }) => {
|
|
25865
25844
|
const { graph, legend: legend2 } = options;
|
|
25866
25845
|
const debouncedResetZoom = useCallback(
|
|
@@ -25879,15 +25858,13 @@ const useChartPlugins = ({ options, resetZoom: resetZoom2 }) => {
|
|
|
25879
25858
|
},
|
|
25880
25859
|
[debouncedResetZoom]
|
|
25881
25860
|
);
|
|
25882
|
-
const ellipsePlugin = customPointEllipsisPlugin(options);
|
|
25883
25861
|
return useMemo(() => {
|
|
25884
25862
|
return [
|
|
25885
25863
|
...getPlugins(graph, legend2),
|
|
25886
25864
|
{
|
|
25887
25865
|
id: "customEventCatcher",
|
|
25888
25866
|
beforeEvent: handleDoubleClick
|
|
25889
|
-
}
|
|
25890
|
-
ellipsePlugin
|
|
25867
|
+
}
|
|
25891
25868
|
];
|
|
25892
25869
|
}, [handleDoubleClick]);
|
|
25893
25870
|
};
|
|
@@ -26223,8 +26200,7 @@ Chart$2.register(
|
|
|
26223
26200
|
plugin$1,
|
|
26224
26201
|
plugin,
|
|
26225
26202
|
annotation,
|
|
26226
|
-
chartAreaTextPlugin
|
|
26227
|
-
customPointEllipsisPlugin()
|
|
26203
|
+
chartAreaTextPlugin
|
|
26228
26204
|
);
|
|
26229
26205
|
const LineChart = (props) => {
|
|
26230
26206
|
var _a2, _b2;
|