Skip to content

Commit

Permalink
Merge pull request #73 from GenieFramework/hh-plots-extension
Browse files Browse the repository at this point in the history
add Plots extension
  • Loading branch information
hhaensel authored Oct 11, 2024
2 parents e6f2546 + c22306e commit 6d4347e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,23 @@ Stipple = "4acbeb90-81a0-11ea-1966-bdaff8155998"
DataFrames = "1"
Genie = "5.24.4"
PlotlyBase = "0.8.19"
Plots = "1.4"
Requires = "1"
Stipple = "0.29, 0.30"
julia = "1.6"

[extras]
PlotlyBase = "a03496cd-edff-5a9b-9e67-9cda94a718b5"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[extensions]
StipplePlotlyPlotlyBaseExt = "PlotlyBase"
StipplePlotlyPlotsExt = ["Plots", "PlotlyBase"]

[targets]
test = ["Test", "PlotlyBase"]

[weakdeps]
PlotlyBase = "a03496cd-edff-5a9b-9e67-9cda94a718b5"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
33 changes: 33 additions & 0 deletions ext/StipplePlotlyPlotsExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module StipplePlotlyPlotsExt

using StipplePlotly
using StipplePlotly.Stipple
using StipplePlotly.Charts
import Stipple: render, stipple_parse

if isdefined(Base, :get_extension)
using Plots
using PlotlyBase
else
using ..Plots
using ..PlotlyBase
end

function Stipple.render(pl::Plots.Plot)
# 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

end

0 comments on commit 6d4347e

Please sign in to comment.