You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to use onScaleChange to calculate new data when the user pans or scales the CartesianChart, much like how a graphing calculator plots points from a formula to its current domain.
The problem I am running in to is even when I debounce the callback, it triggers an infinite loop even when the incoming data has not changed its bounds:
// Calcuates new data from 'start' to 'end'constgetNewData=(start: number,end: number)=>{/*formula*/}constPlot=()=>{consttransformState=useChartTransformState({scaleX:1,scaleY:1});const[DATA,setDATA]=useState<Record<string,unknown>[]>([{}]);// Callback that runs on scale change and calculates new data in that rangeconstnewDataOnScaleChange=debounce((xScale: ScaleLinear<number,number>,yScale: ScaleLinear<number,number>)=>{const[newDataStart,newDataEnd]=xScale.domain();setDATA(getNewData(newDataStart,newDataEnd));},100);return(<CartesianChartdata={DATA}onScaleChange={newDataOnScaleChange}transformState={transformState.state}//...xKeys, yKeys, etc./>{/*children*/}
</CartesianChart>)}
It says clearly in the docs that onScaleChange runs when the scale changes OR when there is new data.
Is there any way to prevent the latter? I've been digging through the sources trying to see if there is some way to prevent new data from running the callback. I found the useEffect that runs the onScaleChange, but its dependencies are too complex to patch with a simple 'doNotRunOnNewData' condition.
Is there a better way to do this than with onScaleChange?
The text was updated successfully, but these errors were encountered:
@Casey-Litmer what version of victory-native-xl are you using? Looking at the useEffect that triggers the scale change callback, it looks like it does try to prevent calling the callback if that scale bounds haven't changed at all:
I am trying to use onScaleChange to calculate new data when the user pans or scales the CartesianChart, much like how a graphing calculator plots points from a formula to its current domain.
The problem I am running in to is even when I debounce the callback, it triggers an infinite loop even when the incoming data has not changed its bounds:
It says clearly in the docs that onScaleChange runs when the scale changes OR when there is new data.
Is there any way to prevent the latter? I've been digging through the sources trying to see if there is some way to prevent new data from running the callback. I found the useEffect that runs the onScaleChange, but its dependencies are too complex to patch with a simple 'doNotRunOnNewData' condition.
Is there a better way to do this than with onScaleChange?
The text was updated successfully, but these errors were encountered: