question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

3D plot redraw() inside a listener cause a recursive loop

See original GitHub issue

I 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:open
  • Created 7 years ago
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mikemeycommented, Aug 7, 2020

I’ve found an awful workaround for this issue: place the call to Plotly.redraw/Plotly.restyle in a timeout with a small delay:

setTimeout(() => Plotly.restyle( ... ), 200)

Sometimes I still get multiple calls, but it stops the infinite event loop.

I’ll take a shower, I feel dirty…

1reaction
kelegormcommented, Mar 6, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found