Skip to content

How to make tooltip snap to smooth chart in AreaClosed? #1528

Answered by VityaSchel
VityaSchel asked this question in Q&A
Discussion options

You must be logged in to vote

well of course as always I had to figure it out myself...

I analysed each of variables in tooltip handler and slightly modified it.

// tooltip handler
const handleTooltip = useCallback(
  (event: React.TouchEvent<SVGRectElement> | React.MouseEvent<SVGRectElement>) => {
    const mouse = localPoint(event) || { x: 0 }
    const x0 = dateScale.invert(mouse.x)
    
    const closest = (target: number, list: number[]): number => {
      const closestMatch = list.reduce((prev, curr) => Math.abs(curr - target) < Math.abs(prev - target) ? curr : prev)
      return closestMatch
    }
    
    const closestWithIndex = (target: number, list: number[]): number => {
      const closestMatch = closest(t…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@williaster
Comment options

Answer selected by VityaSchel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants