@@ -4,7 +4,7 @@ import dayjs from 'dayjs'
44import { formatBytes } from 'lib/helpers'
55import { useTheme } from 'next-themes'
66import { ComponentProps , useEffect , useState } from 'react'
7- import { useChartSync } from './useChartSync '
7+ import { useChartHoverState } from './useChartHoverState '
88import {
99 Area ,
1010 Bar ,
@@ -102,11 +102,9 @@ export default function ComposedChart({
102102 docsUrl,
103103} : ComposedChartProps ) {
104104 const { resolvedTheme } = useTheme ( )
105- const {
106- state : syncState ,
107- updateState : updateSyncState ,
108- clearState : clearSyncState ,
109- } = useChartSync ( syncId )
105+ const { hoveredIndex, syncTooltip, setHover, clearHover } = useChartHoverState (
106+ syncId || 'default'
107+ )
110108 const [ _activePayload , setActivePayload ] = useState < any > ( null )
111109 const [ _showMaxValue , setShowMaxValue ] = useState ( showMaxValue )
112110 const [ focusDataIndex , setFocusDataIndex ] = useState < number | null > ( null )
@@ -339,14 +337,7 @@ export default function ComposedChart({
339337 setActivePayload ( e . activePayload )
340338 }
341339
342- if ( syncId ) {
343- updateSyncState ( {
344- activeIndex : e . activeTooltipIndex ,
345- activePayload : e . activePayload ,
346- activeLabel : e . activeLabel ,
347- isHovering : true ,
348- } )
349- }
340+ setHover ( e . activeTooltipIndex )
350341
351342 const activeTimestamp = data [ e . activeTooltipIndex ] ?. timestamp
352343 chartHighlight ?. handleMouseMove ( {
@@ -367,9 +358,7 @@ export default function ComposedChart({
367358 setFocusDataIndex ( null )
368359 setActivePayload ( null )
369360
370- if ( syncId ) {
371- clearSyncState ( )
372- }
361+ clearHover ( )
373362 } }
374363 onClick = { ( tooltipData ) => {
375364 const datum = tooltipData ?. activePayload ?. [ 0 ] ?. payload
@@ -404,7 +393,9 @@ export default function ComposedChart({
404393 attributes = { attributes }
405394 valuePrecision = { valuePrecision }
406395 showTotal = { showTotal }
407- isActiveHoveredChart = { isActiveHoveredChart || ( ! ! syncId && syncState . isHovering ) }
396+ isActiveHoveredChart = {
397+ isActiveHoveredChart || ( ! ! syncId && syncTooltip && hoveredIndex !== null )
398+ }
408399 />
409400 ) : null
410401 }
0 commit comments