Skip to content

Commit

Permalink
move backend initialization to render(pl:Plots.Plot)
Browse files Browse the repository at this point in the history
  • Loading branch information
hhaensel committed Oct 11, 2024
1 parent eb0c626 commit c22306e
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions ext/StipplePlotlyPlotsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ else
end

function Stipple.render(pl::Plots.Plot)
pl = Plots.plotlybase_syncplot(pl)
delete!(pl.layout.fields, :height)
delete!(pl.layout.fields, :width)
# make sure the PlotlyBase backend is loaded and that the current backend is not changed
already_initialized = true
if !isdefined(Plots, :plotlybase_syncplot)
current_backend = Plots.backend()
Plots.plotly() === current_backend || Plots.backend(current_backend)
already_initialized = false
end

pl = already_initialized ? Plots.plotlybase_syncplot(pl) : Base.invokelatest(Plots.plotlybase_syncplot, pl)
pop!(pl.layout, :height)
pop!(pl.layout, :width)
pl.layout.fields[:margin] = Dict(:l => 50, :b => 50, :r => 50, :t => 60)

return pl
end

function __init__()
current_backend = Plots.backend()
if current_backend !== :plotly
Plots.plotly()
Plots.backend(current_backend)
end
end

end

0 comments on commit c22306e

Please sign in to comment.