@oliasoft-open-source/charts-library 2.5.3 → 2.5.4
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/package.json
CHANGED
package/release-notes.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useEffect, useReducer, useRef } from 'react';
|
|
1
|
+
import React, { useEffect, useReducer, useRef, useState } from 'react';
|
|
2
2
|
import {
|
|
3
3
|
CategoryScale,
|
|
4
4
|
Chart as ChartJS,
|
|
@@ -94,7 +94,7 @@ ChartJS.register(
|
|
|
94
94
|
const LineChart = (props) => {
|
|
95
95
|
setDefaultTheme();
|
|
96
96
|
const chartRef = useRef(null);
|
|
97
|
-
|
|
97
|
+
const [hoveredPoint, setHoveredPoint] = useState(null);
|
|
98
98
|
const chart = getDefaultProps(props);
|
|
99
99
|
const { options, testId } = chart;
|
|
100
100
|
const { headerComponent, subheaderComponent, table } = props;
|
|
@@ -276,18 +276,19 @@ const LineChart = (props) => {
|
|
|
276
276
|
};
|
|
277
277
|
|
|
278
278
|
const onHover = (evt, hoveredItems, chartInstance) => {
|
|
279
|
-
if (
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
interactions.onPointUnhover(evt);
|
|
283
|
-
}
|
|
279
|
+
if (!hoveredItems?.length && interactions.onPointUnhover && hoveredPoint) {
|
|
280
|
+
setHoveredPoint(null);
|
|
281
|
+
interactions.onPointUnhover(evt);
|
|
284
282
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
283
|
+
|
|
284
|
+
if (hoveredItems?.length && interactions.onPointHover) {
|
|
285
|
+
const { index, datasetIndex } = hoveredItems[0];
|
|
286
|
+
const dataset = generatedDatasets[datasetIndex];
|
|
287
|
+
const point = dataset?.data[index];
|
|
288
|
+
|
|
289
|
+
if (point && hoveredPoint !== point) {
|
|
290
|
+
setHoveredPoint(point);
|
|
291
|
+
interactions.onPointHover(evt, datasetIndex, index, generatedDatasets);
|
|
291
292
|
}
|
|
292
293
|
}
|
|
293
294
|
};
|
|
@@ -593,3 +593,22 @@ SquareAspectRatioFillContainer.decorators = [
|
|
|
593
593
|
</div>
|
|
594
594
|
),
|
|
595
595
|
];
|
|
596
|
+
|
|
597
|
+
export const OnPointHover = Template.bind({});
|
|
598
|
+
OnPointHover.args = {
|
|
599
|
+
chart: {
|
|
600
|
+
...basicChart,
|
|
601
|
+
options: {
|
|
602
|
+
...basicChart.options,
|
|
603
|
+
interactions: {
|
|
604
|
+
onPointHover: (evt, datasetIndex, pointIndex, datasets) => {
|
|
605
|
+
console.log({ evt });
|
|
606
|
+
console.log(datasets[datasetIndex].data[pointIndex]);
|
|
607
|
+
},
|
|
608
|
+
onPointUnhover: () => {
|
|
609
|
+
console.log('No point hovered');
|
|
610
|
+
},
|
|
611
|
+
},
|
|
612
|
+
},
|
|
613
|
+
},
|
|
614
|
+
};
|