plotly.js icon indicating copy to clipboard operation
plotly.js copied to clipboard

Plotting a 3D graph with config option `staticPlot` turned on results in blank graph

Open etpinard opened this issue 10 years ago • 5 comments

http://codepen.io/etpinard/pen/QNBWoK

should display an image and the graph div.

etpinard avatar Apr 21 '16 13:04 etpinard

Post https://github.com/plotly/plotly.js/pull/1939, I'm thinking we should drop the staticPlot config option and make users call:

var img = document.createElement('img')

Plotly
  .toImage({data: data, layout: layout})
  .then(imgData => img.src = imgData)

to generate static images. No need to support staticPlot: true and toImage.

etpinard avatar Aug 15 '17 02:08 etpinard

So that staticPlot option is handy for a few reason. We are currently displaying many graphs on the one page (in react), we are unable to call toImage, as by the time we get around to it the context has already been lost, or the plot has not been rendered.

We ideally want to start with a static plot, however toImage requires creating a non static-plot first, which uses more webgl contexts . I also believe staticPlot correctly resizes aswell.

McPonolith avatar Sep 09 '22 11:09 McPonolith

Right, staticPlot has other useful effects, like omitting most of the invisible elements used only to capture interactions, and changing some of the antialiasing settings for better print behavior. So I definitely think it deserves to stay.

Seems like what this requires is when staticPlot is enabled we wait until the webgl rendering is complete, then pull the images out of its canvases and into image elements, and finally dispose of the webgl contexts and canvases entirely.

@McPonolith if you're creating many graphs simultaneously this still may cause problems of too many contexts, and us dropping some. I guess in principle we could stash some global state saying "we're rendering a webgl plot as static" and have any others wait until previous ones are done and have released their contexts before they even try to render. Still not 100% clear that this would work, as in my experience browsers don't always handle these resources on the schedule we want them to!

alexcjohnson avatar Sep 09 '22 16:09 alexcjohnson

Was just bit by this issue. Hoping to see it worked on.

harahu avatar Mar 15 '23 10:03 harahu

I confirm staticPlot: true works as expected on 3D graphs on up to v1.37.1.

blokhin avatar Mar 26 '24 18:03 blokhin