xanderdeseyn / react-native-responsive-linechart

A customizable and responsive line or area chart for react-native
https://react-native-responsive-linechart.surge.sh
MIT License
202 stars 46 forks source link

Access close tooltip handler #51

Closed tlow92 closed 3 years ago

tlow92 commented 3 years ago

Hi,

is it possible to access setTooltipIndex in order to be able to close the tooltip in some cases?

The reason is, that often times you have different time periods that you can choose from. I am changing the x and y domain using state variable but the tooltip stays open, if you change the domain.

So either I could use the setTooltipIndex or the library has to close the tooltip when domain prop is changed.

if you think it's not possible right now, but what change you prefer I could provide a PR with changes.

xanderdeseyn commented 3 years ago

I think I'd prefer exposing setTooltipIndex. I'll try to implement it today or tomorrow!

xanderdeseyn commented 3 years ago

It's implemented but I don't have time to update the docs right now. You can use it though, just put a ref on and call setTooltipIndex!

tlow92 commented 3 years ago

Thanks, can confirm that it is working! Really useful!

D-Navadiya commented 3 years ago

I am having the similar problem, tried to set and receive the ref on Tooltip, Line and Chart component/s but unsuccessful, where do I put the ref and get the value of it?

D-Navadiya commented 3 years ago

just checked out the code, I am pretty sure I need to use it on Line component, not sure why it isn't working, it's a React Function component, doing something like, ` import React from 'react'; import { Chart, } from 'react-native-responsive-linechart';

function CustomChart () { const chartTooltipRef = React.useRef(null); return ( <Chart ... > <Line ref={chartTooltipRef} ... /> ) } `

D-Navadiya commented 3 years ago

Nevermind, turns out that I was using an older version of the library. My bad, should've checked before posting here.

Thanks :) Appreciate the hard work on this library.