@oliasoft-open-source/charts-library 3.6.5 → 3.6.6
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 +124 -91
- package/dist/index.js.map +1 -1
- package/dist/src/components/line-chart/hooks/use-chart-functions.d.ts +0 -1
- package/dist/src/components/line-chart/hooks/use-legend-state.d.ts +33 -0
- package/dist/src/components/line-chart/legend/create-style-object.d.ts +26 -0
- package/dist/src/components/line-chart/line-chart.stories.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -23998,48 +23998,9 @@ const useChartFunctions = ({
|
|
|
23998
23998
|
generatedDatasets
|
|
23999
23999
|
}) => {
|
|
24000
24000
|
const {
|
|
24001
|
-
|
|
24002
|
-
interactions: {
|
|
24003
|
-
onLegendClick,
|
|
24004
|
-
onHover: onPointHover,
|
|
24005
|
-
onUnhover: onPointUnhover
|
|
24006
|
-
},
|
|
24001
|
+
interactions: { onHover: onPointHover, onUnhover: onPointUnhover },
|
|
24007
24002
|
axes
|
|
24008
24003
|
} = options;
|
|
24009
|
-
const legendClick = useCallback(
|
|
24010
|
-
(_e2, legendItem2) => {
|
|
24011
|
-
const { datasetIndex } = legendItem2;
|
|
24012
|
-
const chartInstance = chartRef == null ? void 0 : chartRef.current;
|
|
24013
|
-
const { datasets } = (chartInstance == null ? void 0 : chartInstance.data) || {};
|
|
24014
|
-
const dataset = datasets == null ? void 0 : datasets[datasetIndex];
|
|
24015
|
-
const meta = chartInstance == null ? void 0 : chartInstance.getDatasetMeta(datasetIndex);
|
|
24016
|
-
if (meta) {
|
|
24017
|
-
if (meta.hidden === null) {
|
|
24018
|
-
meta.hidden = !dataset.hidden;
|
|
24019
|
-
} else {
|
|
24020
|
-
meta.hidden = null;
|
|
24021
|
-
}
|
|
24022
|
-
}
|
|
24023
|
-
if (annotations.controlAnnotation && (dataset == null ? void 0 : dataset.isAnnotation)) {
|
|
24024
|
-
const { annotationIndex } = dataset;
|
|
24025
|
-
dispatch({ type: "TOGGLE_ANNOTATION", payload: { annotationIndex } });
|
|
24026
|
-
}
|
|
24027
|
-
if (dataset.displayGroup) {
|
|
24028
|
-
datasets == null ? void 0 : datasets.forEach((ds, ix) => {
|
|
24029
|
-
if (ds.displayGroup !== dataset.displayGroup)
|
|
24030
|
-
return;
|
|
24031
|
-
if (chartInstance && meta) {
|
|
24032
|
-
chartInstance.getDatasetMeta(ix).hidden = meta.hidden;
|
|
24033
|
-
}
|
|
24034
|
-
});
|
|
24035
|
-
}
|
|
24036
|
-
if (onLegendClick) {
|
|
24037
|
-
onLegendClick(legendItem2 == null ? void 0 : legendItem2.text, legendItem2.hidden);
|
|
24038
|
-
}
|
|
24039
|
-
chartInstance == null ? void 0 : chartInstance.update();
|
|
24040
|
-
},
|
|
24041
|
-
[onLegendClick, annotations]
|
|
24042
|
-
);
|
|
24043
24004
|
const resetZoom2 = useCallback(() => {
|
|
24044
24005
|
const chartInstance = chartRef == null ? void 0 : chartRef.current;
|
|
24045
24006
|
chartInstance == null ? void 0 : chartInstance.resetZoom();
|
|
@@ -24161,7 +24122,6 @@ const useChartFunctions = ({
|
|
|
24161
24122
|
dispatch({ type: UPDATE_AXES_RANGES, payload: { axes: axes2 } });
|
|
24162
24123
|
}, []);
|
|
24163
24124
|
return {
|
|
24164
|
-
legendClick,
|
|
24165
24125
|
resetZoom: resetZoom2,
|
|
24166
24126
|
onHover,
|
|
24167
24127
|
handleDownload,
|
|
@@ -24669,10 +24629,6 @@ function useMeasure() {
|
|
|
24669
24629
|
const useMeasure$1 = isBrowser && typeof window.ResizeObserver !== "undefined" ? useMeasure : function() {
|
|
24670
24630
|
return [noop, defaultState];
|
|
24671
24631
|
};
|
|
24672
|
-
const getGeneratedLabels = (chart2) => {
|
|
24673
|
-
var _a2, _b2, _c2, _d2, _e2;
|
|
24674
|
-
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)) ?? [];
|
|
24675
|
-
};
|
|
24676
24632
|
const legend = "_legend_wpro0_1";
|
|
24677
24633
|
const isDragging = "_isDragging_wpro0_8";
|
|
24678
24634
|
const legendItems = "_legendItems_wpro0_11";
|
|
@@ -24806,7 +24762,95 @@ const LegendItem = ({ hidden, dataset, handleClick }) => {
|
|
|
24806
24762
|
}
|
|
24807
24763
|
);
|
|
24808
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 legendClick = useCallback(
|
|
24779
|
+
(_e2, legendItem2) => {
|
|
24780
|
+
const { datasetIndex } = legendItem2;
|
|
24781
|
+
const chartInstance = chartRef == null ? void 0 : chartRef.current;
|
|
24782
|
+
const { datasets } = (chartInstance == null ? void 0 : chartInstance.data) || {};
|
|
24783
|
+
const dataset = datasets == null ? void 0 : datasets[datasetIndex];
|
|
24784
|
+
const meta = chartInstance == null ? void 0 : chartInstance.getDatasetMeta(datasetIndex);
|
|
24785
|
+
const newHiddenState = !hiddenStates[datasetIndex];
|
|
24786
|
+
setHiddenStates((prevHiddenStates) => ({
|
|
24787
|
+
...prevHiddenStates,
|
|
24788
|
+
[datasetIndex]: newHiddenState
|
|
24789
|
+
}));
|
|
24790
|
+
if (meta) {
|
|
24791
|
+
if (meta.hidden === null) {
|
|
24792
|
+
meta.hidden = !(dataset == null ? void 0 : dataset.hidden);
|
|
24793
|
+
} else {
|
|
24794
|
+
meta.hidden = null;
|
|
24795
|
+
}
|
|
24796
|
+
}
|
|
24797
|
+
if (annotations.controlAnnotation && (dataset == null ? void 0 : dataset.isAnnotation)) {
|
|
24798
|
+
const { annotationIndex } = dataset;
|
|
24799
|
+
dispatch({ type: "TOGGLE_ANNOTATION", payload: { annotationIndex } });
|
|
24800
|
+
}
|
|
24801
|
+
if (dataset.displayGroup) {
|
|
24802
|
+
datasets == null ? void 0 : datasets.forEach((ds, ix) => {
|
|
24803
|
+
if (ds.displayGroup !== dataset.displayGroup)
|
|
24804
|
+
return;
|
|
24805
|
+
if (chartInstance && meta) {
|
|
24806
|
+
chartInstance.getDatasetMeta(ix).hidden = meta.hidden;
|
|
24807
|
+
}
|
|
24808
|
+
});
|
|
24809
|
+
}
|
|
24810
|
+
if (onLegendClick) {
|
|
24811
|
+
onLegendClick(legendItem2 == null ? void 0 : legendItem2.text, legendItem2.hidden);
|
|
24812
|
+
}
|
|
24813
|
+
chartInstance == null ? void 0 : chartInstance.update();
|
|
24814
|
+
},
|
|
24815
|
+
[chartRef, annotations, onLegendClick, hiddenStates]
|
|
24816
|
+
);
|
|
24817
|
+
const legend2 = useMemo(
|
|
24818
|
+
() => getLegend(options, legendClick),
|
|
24819
|
+
[legendEnabled]
|
|
24820
|
+
);
|
|
24821
|
+
const customLegendPlugin = useMemo(
|
|
24822
|
+
() => ({
|
|
24823
|
+
[CUSTOM_LEGEND_PLUGIN_NAME]: (customLegend == null ? void 0 : customLegend.customLegendPlugin) && {
|
|
24824
|
+
containerID: customLegend == null ? void 0 : customLegend.customLegendContainerID
|
|
24825
|
+
}
|
|
24826
|
+
}),
|
|
24827
|
+
[customLegend]
|
|
24828
|
+
);
|
|
24829
|
+
return {
|
|
24830
|
+
legendClick,
|
|
24831
|
+
hiddenStates,
|
|
24832
|
+
legend: legend2,
|
|
24833
|
+
customLegendPlugin
|
|
24834
|
+
};
|
|
24835
|
+
};
|
|
24809
24836
|
const LEGEND_MARGIN = 4;
|
|
24837
|
+
const createLegendStyle = (legendPosition, chart2) => {
|
|
24838
|
+
const { height = 0, width = 0, chartArea } = chart2;
|
|
24839
|
+
const { top: top2, left: left2, bottom: bottom2, right: right2 } = chartArea;
|
|
24840
|
+
return {
|
|
24841
|
+
left: legendPosition.includes("left") ? left2 : void 0,
|
|
24842
|
+
right: legendPosition.includes("right") ? width - right2 : void 0,
|
|
24843
|
+
top: legendPosition.includes("top") ? top2 : void 0,
|
|
24844
|
+
bottom: legendPosition.includes("bottom") ? height - bottom2 : void 0,
|
|
24845
|
+
maxHeight: 0.5 * (bottom2 - top2 - LEGEND_MARGIN * 2),
|
|
24846
|
+
maxWidth: 0.5 * (right2 - left2 - LEGEND_MARGIN * 2),
|
|
24847
|
+
margin: LEGEND_MARGIN
|
|
24848
|
+
};
|
|
24849
|
+
};
|
|
24850
|
+
const getGeneratedLabels = (chart2) => {
|
|
24851
|
+
var _a2, _b2, _c2, _d2, _e2;
|
|
24852
|
+
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)) ?? [];
|
|
24853
|
+
};
|
|
24810
24854
|
const LegendPanel = forwardRef((props, ref) => {
|
|
24811
24855
|
const {
|
|
24812
24856
|
legendPosition,
|
|
@@ -24817,32 +24861,28 @@ const LegendPanel = forwardRef((props, ref) => {
|
|
|
24817
24861
|
generatedDatasets,
|
|
24818
24862
|
isDragging: isDragging2
|
|
24819
24863
|
} = props;
|
|
24820
|
-
const [refresh, setRefresh] = useState(false);
|
|
24821
24864
|
const { legendEnabled } = state;
|
|
24822
|
-
const
|
|
24865
|
+
const chart2 = chartRef.current;
|
|
24866
|
+
if (!chart2)
|
|
24867
|
+
return null;
|
|
24868
|
+
const {
|
|
24869
|
+
data: { datasets }
|
|
24870
|
+
} = chart2;
|
|
24871
|
+
const { legendClick, hiddenStates } = useLegendState({
|
|
24823
24872
|
chartRef,
|
|
24824
|
-
state,
|
|
24825
24873
|
options,
|
|
24826
|
-
|
|
24827
|
-
|
|
24874
|
+
state,
|
|
24875
|
+
dispatch
|
|
24828
24876
|
});
|
|
24829
24877
|
const { onToggleLegend } = useToggleHandlers(dispatch);
|
|
24830
|
-
const
|
|
24831
|
-
|
|
24832
|
-
|
|
24833
|
-
|
|
24834
|
-
|
|
24835
|
-
|
|
24836
|
-
|
|
24837
|
-
const style =
|
|
24838
|
-
left: legendPosition.includes("left") ? left2 : void 0,
|
|
24839
|
-
right: legendPosition.includes("right") ? width - right2 : void 0,
|
|
24840
|
-
top: legendPosition.includes("top") ? top2 : void 0,
|
|
24841
|
-
bottom: legendPosition.includes("bottom") ? height - bottom2 : void 0,
|
|
24842
|
-
maxHeight: 0.5 * (bottom2 - top2 - LEGEND_MARGIN * 2),
|
|
24843
|
-
maxWidth: 0.5 * (right2 - left2 - LEGEND_MARGIN * 2),
|
|
24844
|
-
margin: LEGEND_MARGIN
|
|
24845
|
-
};
|
|
24878
|
+
const [items, setItems] = useState([]);
|
|
24879
|
+
useEffect(() => {
|
|
24880
|
+
if (!chart2)
|
|
24881
|
+
return;
|
|
24882
|
+
const newItems = getGeneratedLabels(chart2);
|
|
24883
|
+
setItems(newItems);
|
|
24884
|
+
}, [generatedDatasets, chart2]);
|
|
24885
|
+
const style = createLegendStyle(legendPosition, chart2);
|
|
24846
24886
|
return /* @__PURE__ */ jsxs(
|
|
24847
24887
|
"div",
|
|
24848
24888
|
{
|
|
@@ -24863,15 +24903,12 @@ const LegendPanel = forwardRef((props, ref) => {
|
|
|
24863
24903
|
icon: legendEnabled ? /* @__PURE__ */ jsx(TbX, {}) : /* @__PURE__ */ jsx(TbList, {})
|
|
24864
24904
|
}
|
|
24865
24905
|
) }),
|
|
24866
|
-
/* @__PURE__ */ jsx("div", { className: styles$2.legendItems, children: items.map((item) => /* @__PURE__ */ jsx(
|
|
24906
|
+
/* @__PURE__ */ jsx("div", { className: styles$2.legendItems, children: items.map((item, idx) => /* @__PURE__ */ jsx(
|
|
24867
24907
|
LegendItem,
|
|
24868
24908
|
{
|
|
24869
|
-
hidden:
|
|
24909
|
+
hidden: hiddenStates[idx],
|
|
24870
24910
|
dataset: datasets[item.datasetIndex],
|
|
24871
|
-
handleClick: (event) =>
|
|
24872
|
-
legendClick(event, item);
|
|
24873
|
-
setRefresh(!refresh);
|
|
24874
|
-
}
|
|
24911
|
+
handleClick: (event) => legendClick(event, item)
|
|
24875
24912
|
},
|
|
24876
24913
|
`${item.datasetIndex}-hidden-${item.hidden}`
|
|
24877
24914
|
)) })
|
|
@@ -25712,7 +25749,6 @@ const useChartOptions = ({
|
|
|
25712
25749
|
dispatch,
|
|
25713
25750
|
generatedDatasets
|
|
25714
25751
|
}) => {
|
|
25715
|
-
var _a2, _b2;
|
|
25716
25752
|
const {
|
|
25717
25753
|
interactions: { onAnimationComplete },
|
|
25718
25754
|
annotations: {
|
|
@@ -25734,29 +25770,28 @@ const useChartOptions = ({
|
|
|
25734
25770
|
zoomEnabled,
|
|
25735
25771
|
panEnabled,
|
|
25736
25772
|
lineEnabled,
|
|
25737
|
-
showAnnotationLineIndex
|
|
25738
|
-
legendEnabled
|
|
25773
|
+
showAnnotationLineIndex
|
|
25739
25774
|
} = state;
|
|
25740
25775
|
const [hoveredPoint, setHoveredPoint] = useState(null);
|
|
25741
|
-
const {
|
|
25742
|
-
|
|
25743
|
-
|
|
25744
|
-
|
|
25745
|
-
|
|
25746
|
-
|
|
25747
|
-
|
|
25748
|
-
|
|
25749
|
-
|
|
25776
|
+
const { updateAxesRangesFromChart, onHover } = useChartFunctions({
|
|
25777
|
+
chartRef,
|
|
25778
|
+
state,
|
|
25779
|
+
options,
|
|
25780
|
+
dispatch,
|
|
25781
|
+
generatedDatasets
|
|
25782
|
+
});
|
|
25783
|
+
const { legendClick, legend: legend2, customLegendPlugin } = useLegendState({
|
|
25784
|
+
chartRef,
|
|
25785
|
+
options,
|
|
25786
|
+
state,
|
|
25787
|
+
dispatch
|
|
25788
|
+
});
|
|
25750
25789
|
const datalabels = getLineChartDataLabels(options);
|
|
25751
25790
|
const tooltip = getLineChartToolTips(options);
|
|
25752
25791
|
const annotation2 = useMemo(
|
|
25753
25792
|
() => getAnnotation(options, state),
|
|
25754
25793
|
[showAnnotationLineIndex, legendClick]
|
|
25755
25794
|
);
|
|
25756
|
-
const legend2 = useMemo(
|
|
25757
|
-
() => getLegend(options, legendClick),
|
|
25758
|
-
[legendEnabled]
|
|
25759
|
-
);
|
|
25760
25795
|
const scales = useMemo(
|
|
25761
25796
|
() => autoScale(options, state, generatedDatasets, chartRef),
|
|
25762
25797
|
[options, state, generatedDatasets, chartRef]
|
|
@@ -25798,9 +25833,7 @@ const useChartOptions = ({
|
|
|
25798
25833
|
tooltip,
|
|
25799
25834
|
legend: { ...legend2, display: false },
|
|
25800
25835
|
// hide default legend for line chart only
|
|
25801
|
-
|
|
25802
|
-
containerID: (_b2 = options.legend.customLegend) == null ? void 0 : _b2.customLegendContainerID
|
|
25803
|
-
},
|
|
25836
|
+
customLegendPlugin,
|
|
25804
25837
|
chartAreaBorder: {
|
|
25805
25838
|
borderColor: BORDER_COLOR
|
|
25806
25839
|
},
|