PlotlyJS.jl icon indicating copy to clipboard operation
PlotlyJS.jl copied to clipboard

Plot window does not scale to fit plot size

Open dsfenn opened this issue 4 years ago • 3 comments

I think it would be nice if the plot window resized itself to fit the plot contents when the plot is first displayed. It seems that right now, the behavior is the inverse, which makes the size parameter to plot() have no effect when using PlotlyJS directly.

When using Plots with the PlotlyJS backend, the window size is independent of the size of the plot content. For anyone creating large figures, this means that the user has to continually adjust the window size every time a new plot is created in order to be able to see the contents, which can get tedious.

Both issues could be addressed by modifying display_blink() to request a window with a specific size--perhaps something like this:

function display_blink(p::SyncPlot) 
    sizeBuffer = 1.15
    plotSize = size(p.plot)
    windowOptions = Dict("width"=>floor(Int,plotSize[1]*sizeBuffer), "height"=>floor(Int,plotSize[2]*sizeBuffer))
    p.window = Blink.Window(windowOptions)
    Blink.body!(p.window, p.scope)
end

This is working well for me, but I'm not very familiar with PlotlyJS's code, and I don't know if there's a better way to do it.

dsfenn avatar Mar 12 '20 17:03 dsfenn

That's great, thanks for taking a look at this. would you be willing to open a pull request?

sglyon avatar Mar 12 '20 18:03 sglyon

Sure--I've never done it before, so I'll read up on it and give it a try.

dsfenn avatar Mar 12 '20 21:03 dsfenn

ok thank you for being willing.

if you need any help with that please reach out

sglyon avatar Mar 13 '20 19:03 sglyon