-
Notifications
You must be signed in to change notification settings - Fork 3
Add conversion of Plots.jl's plotly plots #4
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Changes from all commits
274643d
278efea
1a00ca5
75adf09
57e2d73
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: Julia tests | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
jl_version: ["1.6", "1.8", "1.9"] | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: julia-actions/setup-julia@v1 | ||
with: | ||
version: ${{ matrix.jl_version }} | ||
- uses: julia-actions/julia-buildpkg@v1 | ||
- uses: julia-actions/julia-runtest@v1 | ||
with: | ||
annotate: true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module DashBasePlotlyBaseExt | ||
|
||
import DashBase | ||
import PlotlyBase | ||
import PlotlyBase.JSON | ||
|
||
function DashBase.to_dash(p::PlotlyBase.Plot) | ||
data = JSON.lower(p) | ||
pop!(data, :config, nothing) | ||
return data | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module DashBasePlotlyJSExt | ||
|
||
import PlotlyJS | ||
import DashBase | ||
|
||
function DashBase.to_dash(p::PlotlyJS.SyncPlot) | ||
DashBase.to_dash(p.plot) | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module DashBasePlotsExt | ||
|
||
import Plots | ||
import DashBase | ||
|
||
|
||
function DashBase.to_dash(p::Plots.Plot{Plots.PlotlyBackend}) | ||
return if haskey(Base.loaded_modules, Base.PkgId(Base.UUID("a03496cd-edff-5a9b-9e67-9cda94a718b5"), "PlotlyBase")) && | ||
haskey(Base.loaded_modules, Base.PkgId(Base.UUID("f2990250-8cf9-495f-b13a-cce12b45703c"), "PlotlyKaleido")) | ||
# Note: technically it would be sufficient if PlotlyBase is loaded, but thats how it is currently handled by Plots.jl | ||
Plots.plotlybase_syncplot(p) | ||
else | ||
(data = Plots.plotly_series(p), layout = Plots.plotly_layout(p)) | ||
end | ||
end | ||
DashBase.to_dash(p::Plots.Plot{Plots.PlotlyJSBackend}) = Plots.plotlyjs_syncplot(p) | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
using Test | ||
include("components.jl") | ||
include("registry.jl") | ||
include("test_ext.jl") | ||
include("registry.jl") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using DashBase | ||
using Test | ||
using Plots | ||
plotlyjs() | ||
|
||
@testset "PlotlyJS" begin | ||
pl = @test_nowarn DashBase.to_dash(plot(1:5)) | ||
@test pl isa PlotlyJS.SyncPlot | ||
Comment on lines
+7
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @etpinard do these need to return something readable by JSON3 or is it enough, that they return something that has a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question. Have you tried it inside a Dash.jl callback? |
||
pl = @test_nowarn DashBase.to_dash(pl) | ||
@test haskey(pl, :layout) | ||
@test haskey(pl, :data) | ||
@test haskey(pl, :frames) | ||
@test !haskey(pl, :config) | ||
end | ||
|
||
plotly() | ||
@testset "PlotlyBase" begin | ||
pl = @test_nowarn DashBase.to_dash(plot(1:5)) | ||
@test pl isa PlotlyBase.Plot | ||
pl = @test_nowarn DashBase.to_dash(pl) | ||
@test haskey(pl, :layout) | ||
@test haskey(pl, :data) | ||
@test haskey(pl, :frames) | ||
@test !haskey(pl, :config) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would of course break if PlotlyBase stops importing
JSON
.I think this here is fine for now, but we should probably make the switch to using
JSON3
exclusively inside DashBase.jl and Dash.jl. We should open an issue once this PR is merged.Looks like PlotlyBase does define JSON3-compatible
StructType
s https://github.com/JuliaPlots/PlotlyBase.jl/blob/master/src/json3.jl, but I haven't tested it