3D plot redraw() inside a listener cause a recursive loop
See original GitHub issueI have the following code to be executed:
this.$.plot3d.on('plotly_click', function(d){
self.data[1].x.push(parseFloat(d.points[0].x))
self.data[1].y.push(parseFloat(d.points[0].y))
self.data[1].z.push(parseFloat(d.points[0].z))
redrawing = true
Plotly.redraw(self.$.plot3d);
})
It just adds a 3D point (x,y,z) to a trace and then it redraws the plot. If I do like this, as far as I seen, the redraw method somewhere trigger again the plotly_click event and this cause a recursive loop.
I used an ugly workaround to fix this, which is the following:
this.$.plot3d.on('plotly_click', function(d){
if(!redrawing){
self.data[1].x.push(parseFloat(d.points[0].x))
self.data[1].y.push(parseFloat(d.points[0].y))
self.data[1].z.push(parseFloat(d.points[0].z))
redrawing = true
Plotly.redraw(self.$.plot3d);
} else {
redrawing = false
}
})
But it’s not hte best way. Am I do correctly redrawing the graph in a listener? Is there any other way (maybe the right one) to redraw a graph after a point selection? Is this allowed?
Thank you
Issue Analytics
- State:
- Created 7 years ago
- Comments:14 (4 by maintainers)
Top Results From Across the Web
python - Recursive function not refreshing a list inside a loop
I think the reason is that you are using a mutable argument as the default value in the function, which is a bad...
Read more >rgl: 3D Visualization Using OpenGL
Description Provides medium to high level functions for 3D interactive graphics, including functions modelled on base graphics (plot3d(), etc.) ...
Read more >What affects redraw rate on 3d plots in the qt toolkit? - help
I have a 3d plot that I update using a loop in an .oct file by setting xdata/ydata/zdata properties and then forcing a...
Read more >Understanding common frustrations with React Hooks
Editor's note · “React Hook cannot be called inside a callback” · “React Hooks must be called in a React function component or...
Read more >Drawing on Canvas - Eloquent JavaScript
The <circle> and <rect> tags, which do not exist in HTML, do have a meaning in SVG—they draw shapes using the style and...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’ve found an awful workaround for this issue: place the call to Plotly.redraw/Plotly.restyle in a timeout with a small delay:
Sometimes I still get multiple calls, but it stops the infinite event loop.
I’ll take a shower, I feel dirty…
Ok, how I see problem. in 1.6.0 version was presented fix for issue #240. It added click events for 3D scattergl. But it was done in strange way: clicks are firing on each redrawing while mouse button is down. For example, in same case 2D event is fired once mouse is up. But this is only part of issue.
Somewhere between 1.9.0 and 1.10.0 some change was done that makes things go recursively: now, if mouse was down and in it’s callback was redrawing event fires and fires again even after mouse was released, so
selection.buttons == true
all the time.May be it was force redrawing, may be - some other change.
I hope, that info will help somebody to fix that problem, I still can’t get root of problem, what need to change. And while we are using both 2d and 3d scenes it’s hard to make easy way to overcome that problem.