useSeriesHover.tsx 531 B

1234567891011121314151617181920212223
  1. import {useCallback, useRef} from 'react';
  2. import type {ReactEchartsRef} from 'sentry/types/echarts';
  3. export function useSeriesHover() {
  4. const chartRef = useRef<ReactEchartsRef>(null);
  5. const setHoveredSeries = useCallback((seriesId: string | string[]) => {
  6. if (!chartRef.current) {
  7. return;
  8. }
  9. const echartsInstance = chartRef.current.getEchartsInstance();
  10. echartsInstance.dispatchAction({
  11. type: 'highlight',
  12. seriesId,
  13. });
  14. }, []);
  15. return {
  16. chartRef,
  17. setHoveredSeries,
  18. };
  19. }