@oliasoft-open-source/charts-library 3.6.7 → 3.6.8
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
|
@@ -24774,7 +24774,28 @@ const useLegendState = ({
|
|
|
24774
24774
|
legend: { customLegend }
|
|
24775
24775
|
} = options;
|
|
24776
24776
|
const { legendEnabled } = state;
|
|
24777
|
-
const [hiddenStates, setHiddenStates] = useState(
|
|
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
|
+
};
|
|
24778
24799
|
const legendClick = useCallback(
|
|
24779
24800
|
(_e2, legendItem2) => {
|
|
24780
24801
|
const { datasetIndex } = legendItem2;
|
|
@@ -24782,21 +24803,16 @@ const useLegendState = ({
|
|
|
24782
24803
|
const { datasets } = (chartInstance == null ? void 0 : chartInstance.data) || {};
|
|
24783
24804
|
const dataset = datasets == null ? void 0 : datasets[datasetIndex];
|
|
24784
24805
|
const meta = chartInstance == null ? void 0 : chartInstance.getDatasetMeta(datasetIndex);
|
|
24785
|
-
const
|
|
24786
|
-
|
|
24787
|
-
|
|
24788
|
-
|
|
24789
|
-
|
|
24790
|
-
|
|
24791
|
-
|
|
24792
|
-
meta.hidden = !(dataset == null ? void 0 : dataset.hidden);
|
|
24793
|
-
} else {
|
|
24794
|
-
meta.hidden = null;
|
|
24795
|
-
}
|
|
24796
|
-
}
|
|
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);
|
|
24797
24813
|
if (annotations.controlAnnotation && (dataset == null ? void 0 : dataset.isAnnotation)) {
|
|
24798
24814
|
const { annotationIndex } = dataset;
|
|
24799
|
-
dispatch({ type:
|
|
24815
|
+
dispatch({ type: TOGGLE_ANNOTATION, payload: { annotationIndex } });
|
|
24800
24816
|
}
|
|
24801
24817
|
if (dataset.displayGroup) {
|
|
24802
24818
|
datasets == null ? void 0 : datasets.forEach((ds, ix) => {
|
|
@@ -24830,7 +24846,9 @@ const useLegendState = ({
|
|
|
24830
24846
|
legendClick,
|
|
24831
24847
|
hiddenStates,
|
|
24832
24848
|
legend: legend2,
|
|
24833
|
-
customLegendPlugin
|
|
24849
|
+
customLegendPlugin,
|
|
24850
|
+
upsertHiddenState,
|
|
24851
|
+
clearNonExistentDatasets
|
|
24834
24852
|
};
|
|
24835
24853
|
};
|
|
24836
24854
|
const LEGEND_MARGIN = 4;
|
|
@@ -24862,6 +24880,24 @@ const useGeneratedLabels = (chartRef, generatedDatasets) => {
|
|
|
24862
24880
|
}, [generatedDatasets, chartRef]);
|
|
24863
24881
|
return items;
|
|
24864
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
|
+
}) });
|
|
24865
24901
|
const LegendPanel = forwardRef((props, ref) => {
|
|
24866
24902
|
const {
|
|
24867
24903
|
legendPosition,
|
|
@@ -24879,7 +24915,7 @@ const LegendPanel = forwardRef((props, ref) => {
|
|
|
24879
24915
|
const {
|
|
24880
24916
|
data: { datasets }
|
|
24881
24917
|
} = chart2;
|
|
24882
|
-
const { legendClick, hiddenStates } = useLegendState({
|
|
24918
|
+
const { legendClick, hiddenStates, clearNonExistentDatasets } = useLegendState({
|
|
24883
24919
|
chartRef,
|
|
24884
24920
|
options,
|
|
24885
24921
|
state,
|
|
@@ -24888,6 +24924,9 @@ const LegendPanel = forwardRef((props, ref) => {
|
|
|
24888
24924
|
const { onToggleLegend } = useToggleHandlers(dispatch);
|
|
24889
24925
|
const items = useGeneratedLabels(chartRef, generatedDatasets);
|
|
24890
24926
|
const style = createLegendStyle(legendPosition, chart2);
|
|
24927
|
+
useEffect(() => {
|
|
24928
|
+
clearNonExistentDatasets(generatedDatasets);
|
|
24929
|
+
}, [generatedDatasets]);
|
|
24891
24930
|
return /* @__PURE__ */ jsxs(
|
|
24892
24931
|
"div",
|
|
24893
24932
|
{
|
|
@@ -24908,15 +24947,15 @@ const LegendPanel = forwardRef((props, ref) => {
|
|
|
24908
24947
|
icon: legendEnabled ? /* @__PURE__ */ jsx(TbX, {}) : /* @__PURE__ */ jsx(TbList, {})
|
|
24909
24948
|
}
|
|
24910
24949
|
) }),
|
|
24911
|
-
/* @__PURE__ */ jsx(
|
|
24912
|
-
|
|
24950
|
+
/* @__PURE__ */ jsx(
|
|
24951
|
+
LegendItems,
|
|
24913
24952
|
{
|
|
24914
|
-
|
|
24915
|
-
|
|
24916
|
-
|
|
24917
|
-
|
|
24918
|
-
|
|
24919
|
-
)
|
|
24953
|
+
items,
|
|
24954
|
+
hiddenStates,
|
|
24955
|
+
datasets,
|
|
24956
|
+
legendClick
|
|
24957
|
+
}
|
|
24958
|
+
)
|
|
24920
24959
|
]
|
|
24921
24960
|
}
|
|
24922
24961
|
);
|
|
@@ -39169,7 +39208,7 @@ const defaultInteractions = (interactions) => ({
|
|
|
39169
39208
|
onUnhover: interactions == null ? void 0 : interactions.onUnhover
|
|
39170
39209
|
});
|
|
39171
39210
|
const defaultDragData = (dragData) => ({
|
|
39172
|
-
enableDragData: (dragData == null ? void 0 : dragData.enableDragData)
|
|
39211
|
+
enableDragData: (dragData == null ? void 0 : dragData.enableDragData) ?? false,
|
|
39173
39212
|
showTooltip: (dragData == null ? void 0 : dragData.showTooltip) ?? true,
|
|
39174
39213
|
roundPoints: (dragData == null ? void 0 : dragData.roundPoints) ?? true,
|
|
39175
39214
|
dragX: (dragData == null ? void 0 : dragData.dragX) ?? true,
|
|
@@ -39431,7 +39470,7 @@ const BarChart = (props) => {
|
|
|
39431
39470
|
const [pointHover, setPointHover] = useState(false);
|
|
39432
39471
|
const chart2 = getDefaultProps(props);
|
|
39433
39472
|
const { options, testId } = chart2;
|
|
39434
|
-
const { annotations, chartStyling, interactions, graph } = chart2.options;
|
|
39473
|
+
const { annotations, chartStyling, interactions, graph, dragData } = chart2.options;
|
|
39435
39474
|
const [visibleAnnotationsIndices, setVisibleAnnotationsIndices] = useState(
|
|
39436
39475
|
setAnnotations(annotations.annotationsData)
|
|
39437
39476
|
);
|
|
@@ -39571,7 +39610,7 @@ const BarChart = (props) => {
|
|
|
39571
39610
|
chartAreaBorder: {
|
|
39572
39611
|
borderColor: BORDER_COLOR
|
|
39573
39612
|
},
|
|
39574
|
-
dragData: getDraggableData(options)
|
|
39613
|
+
dragData: (dragData == null ? void 0 : dragData.enableDragData) && getDraggableData(options)
|
|
39575
39614
|
}
|
|
39576
39615
|
},
|
|
39577
39616
|
plugins: getPlugins(graph, options.legend)
|