@mui/x-charts
Version:
The community edition of MUI X Charts components.
54 lines • 1.69 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import useEventCallback from '@mui/utils/useEventCallback';
export const useChartInteraction = ({
store
}) => {
const cleanInteraction = useEventCallback(function cleanInteraction() {
store.update({
interaction: _extends({}, store.state.interaction, {
pointer: null
})
});
});
const setLastUpdateSource = useEventCallback(function setLastUpdateSource(interaction) {
if (store.state.interaction.lastUpdate !== interaction) {
store.set('interaction', _extends({}, store.state.interaction, {
lastUpdate: interaction
}));
}
});
const setPointerCoordinate = useEventCallback(function setPointerCoordinate(coordinate) {
store.set('interaction', _extends({}, store.state.interaction, {
pointer: coordinate,
lastUpdate: coordinate !== null ? 'pointer' : store.state.interaction.lastUpdate
}));
});
const handlePointerEnter = useEventCallback(function handlePointerEnter(event) {
store.set('interaction', _extends({}, store.state.interaction, {
pointerType: event.pointerType
}));
});
const handlePointerLeave = useEventCallback(function handlePointerLeave() {
store.set('interaction', _extends({}, store.state.interaction, {
pointerType: null
}));
});
return {
instance: {
cleanInteraction,
setLastUpdateSource,
setPointerCoordinate,
handlePointerEnter,
handlePointerLeave
}
};
};
useChartInteraction.getInitialState = () => ({
interaction: {
item: null,
pointer: null,
lastUpdate: 'pointer',
pointerType: null
}
});
useChartInteraction.params = {};