Skip to content

Commit 2afb114

Browse files
authored
Merge pull request #4 from BeastyBlacksmith/master
Add conversion of Plots.jl's plotly plots
2 parents 8abcb89 + 57e2d73 commit 2afb114

File tree

8 files changed

+119
-3
lines changed

8 files changed

+119
-3
lines changed

.github/workflows/jl_test.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Julia tests
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
fail-fast: false
10+
matrix:
11+
jl_version: ["1.6", "1.8", "1.9"]
12+
steps:
13+
- uses: actions/checkout@v2
14+
- uses: julia-actions/setup-julia@v1
15+
with:
16+
version: ${{ matrix.jl_version }}
17+
- uses: julia-actions/julia-buildpkg@v1
18+
- uses: julia-actions/julia-runtest@v1
19+
with:
20+
annotate: true

Project.toml

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,32 @@ version = "0.2.0"
55

66
[deps]
77
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
8-
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
8+
PackageExtensionCompat = "65ce6f38-6b18-4e1d-a461-8949797d7930"
9+
10+
[weakdeps]
11+
PlotlyBase = "a03496cd-edff-5a9b-9e67-9cda94a718b5"
12+
PlotlyJS = "f0f68f2c-4968-5e81-91da-67840de0976a"
13+
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
14+
15+
[extensions]
16+
DashBasePlotlyBaseExt = "PlotlyBase"
17+
DashBasePlotlyJSExt = "PlotlyJS"
18+
DashBasePlotsExt = "Plots"
919

1020
[compat]
1121
JSON3 = "1"
12-
julia = "1.2"
22+
Plots = "1"
23+
julia = "1.6"
24+
PlotlyBase = "0.8"
25+
PlotlyJS = "0.18"
26+
PackageExtensionCompat = "1"
27+
28+
[extras]
29+
PlotlyBase = "a03496cd-edff-5a9b-9e67-9cda94a718b5"
30+
PlotlyJS = "f0f68f2c-4968-5e81-91da-67840de0976a"
31+
PlotlyKaleido = "f2990250-8cf9-495f-b13a-cce12b45703c"
32+
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
33+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
34+
35+
[targets]
36+
test = ["Test", "Plots", "PlotlyBase", "PlotlyJS", "PlotlyKaleido"]

ext/DashBasePlotlyBaseExt.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module DashBasePlotlyBaseExt
2+
3+
import DashBase
4+
import PlotlyBase
5+
import PlotlyBase.JSON
6+
7+
function DashBase.to_dash(p::PlotlyBase.Plot)
8+
data = JSON.lower(p)
9+
pop!(data, :config, nothing)
10+
return data
11+
end
12+
13+
end

ext/DashBasePlotlyJSExt.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module DashBasePlotlyJSExt
2+
3+
import PlotlyJS
4+
import DashBase
5+
6+
function DashBase.to_dash(p::PlotlyJS.SyncPlot)
7+
DashBase.to_dash(p.plot)
8+
end
9+
10+
end

ext/DashBasePlotsExt.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module DashBasePlotsExt
2+
3+
import Plots
4+
import DashBase
5+
6+
7+
function DashBase.to_dash(p::Plots.Plot{Plots.PlotlyBackend})
8+
return if haskey(Base.loaded_modules, Base.PkgId(Base.UUID("a03496cd-edff-5a9b-9e67-9cda94a718b5"), "PlotlyBase")) &&
9+
haskey(Base.loaded_modules, Base.PkgId(Base.UUID("f2990250-8cf9-495f-b13a-cce12b45703c"), "PlotlyKaleido"))
10+
# Note: technically it would be sufficient if PlotlyBase is loaded, but thats how it is currently handled by Plots.jl
11+
Plots.plotlybase_syncplot(p)
12+
else
13+
(data = Plots.plotly_series(p), layout = Plots.plotly_layout(p))
14+
end
15+
end
16+
DashBase.to_dash(p::Plots.Plot{Plots.PlotlyJSBackend}) = Plots.plotlyjs_syncplot(p)
17+
18+
end

src/DashBase.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module DashBase
22
import JSON3
3+
import PackageExtensionCompat
34
include("components.jl")
45
include("registry.jl")
56
export Component, push_prop!, get_name, get_type, get_namespace,
@@ -8,4 +9,8 @@ get_dash_dependencies, get_dash_renderer_pkg, get_componens_pkgs,
89
has_relative_path, has_dev_path, has_external_url, get_type,
910
get_external_url, get_dev_path, get_relative_path
1011

12+
function __init__()
13+
PackageExtensionCompat.@require_extensions
14+
end
15+
1116
end # module

test/runtests.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
using Test
22
include("components.jl")
3-
include("registry.jl")
3+
include("test_ext.jl")
4+
include("registry.jl")

test/test_ext.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using DashBase
2+
using Test
3+
using Plots
4+
plotlyjs()
5+
6+
@testset "PlotlyJS" begin
7+
pl = @test_nowarn DashBase.to_dash(plot(1:5))
8+
@test pl isa PlotlyJS.SyncPlot
9+
pl = @test_nowarn DashBase.to_dash(pl)
10+
@test haskey(pl, :layout)
11+
@test haskey(pl, :data)
12+
@test haskey(pl, :frames)
13+
@test !haskey(pl, :config)
14+
end
15+
16+
plotly()
17+
@testset "PlotlyBase" begin
18+
pl = @test_nowarn DashBase.to_dash(plot(1:5))
19+
@test pl isa PlotlyBase.Plot
20+
pl = @test_nowarn DashBase.to_dash(pl)
21+
@test haskey(pl, :layout)
22+
@test haskey(pl, :data)
23+
@test haskey(pl, :frames)
24+
@test !haskey(pl, :config)
25+
end

0 commit comments

Comments
 (0)