Skip to content

Commit bcccaf9

Browse files
authored
Merge pull request #9 from plotly/fixup-plots-to_dash
Fixup `DashBasePlotsExt`
2 parents 2afb114 + e8aa7cf commit bcccaf9

File tree

6 files changed

+71
-45
lines changed

6 files changed

+71
-45
lines changed

Project.toml

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

66
[deps]
77
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
8-
PackageExtensionCompat = "65ce6f38-6b18-4e1d-a461-8949797d7930"
8+
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
99

10-
[weakdeps]
11-
PlotlyBase = "a03496cd-edff-5a9b-9e67-9cda94a718b5"
12-
PlotlyJS = "f0f68f2c-4968-5e81-91da-67840de0976a"
13-
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
10+
[compat]
11+
JSON3 = "1"
12+
PlotlyBase = "0.8"
13+
PlotlyJS = "0.18"
14+
Plots = "1"
15+
Requires = "1.3"
16+
julia = "1.6"
1417

1518
[extensions]
1619
DashBasePlotlyBaseExt = "PlotlyBase"
1720
DashBasePlotlyJSExt = "PlotlyJS"
1821
DashBasePlotsExt = "Plots"
1922

20-
[compat]
21-
JSON3 = "1"
22-
Plots = "1"
23-
julia = "1.6"
24-
PlotlyBase = "0.8"
25-
PlotlyJS = "0.18"
26-
PackageExtensionCompat = "1"
27-
2823
[extras]
2924
PlotlyBase = "a03496cd-edff-5a9b-9e67-9cda94a718b5"
3025
PlotlyJS = "f0f68f2c-4968-5e81-91da-67840de0976a"
@@ -34,3 +29,8 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3429

3530
[targets]
3631
test = ["Test", "Plots", "PlotlyBase", "PlotlyJS", "PlotlyKaleido"]
32+
33+
[weakdeps]
34+
PlotlyBase = "a03496cd-edff-5a9b-9e67-9cda94a718b5"
35+
PlotlyJS = "f0f68f2c-4968-5e81-91da-67840de0976a"
36+
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"

ext/DashBasePlotlyBaseExt.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
module DashBasePlotlyBaseExt
22

3-
import DashBase
4-
import PlotlyBase
5-
import PlotlyBase.JSON
3+
using DashBase
4+
5+
isdefined(Base, :get_extension) ? (using PlotlyBase) : (using ..PlotlyBase)
6+
7+
const JSON = PlotlyBase.JSON
68

79
function DashBase.to_dash(p::PlotlyBase.Plot)
810
data = JSON.lower(p)

ext/DashBasePlotlyJSExt.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
module DashBasePlotlyJSExt
22

3-
import PlotlyJS
4-
import DashBase
3+
using DashBase
4+
5+
isdefined(Base, :get_extension) ? (using PlotlyJS) : (using ..PlotlyJS)
56

67
function DashBase.to_dash(p::PlotlyJS.SyncPlot)
78
DashBase.to_dash(p.plot)

ext/DashBasePlotsExt.jl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
module DashBasePlotsExt
22

3-
import Plots
4-
import DashBase
3+
using DashBase
54

5+
isdefined(Base, :get_extension) ? (using Plots) : (using ..Plots)
66

77
function DashBase.to_dash(p::Plots.Plot{Plots.PlotlyBackend})
88
return if haskey(Base.loaded_modules, Base.PkgId(Base.UUID("a03496cd-edff-5a9b-9e67-9cda94a718b5"), "PlotlyBase")) &&
99
haskey(Base.loaded_modules, Base.PkgId(Base.UUID("f2990250-8cf9-495f-b13a-cce12b45703c"), "PlotlyKaleido"))
1010
# 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)
11+
sp = Plots.plotlybase_syncplot(p)
12+
DashBase.to_dash(sp)
1213
else
13-
(data = Plots.plotly_series(p), layout = Plots.plotly_layout(p))
14+
Dict(:data => Plots.plotly_series(p), :layout => Plots.plotly_layout(p))
1415
end
1516
end
16-
DashBase.to_dash(p::Plots.Plot{Plots.PlotlyJSBackend}) = Plots.plotlyjs_syncplot(p)
17+
18+
function DashBase.to_dash(p::Plots.Plot{Plots.PlotlyJSBackend})
19+
sp = Plots.plotlyjs_syncplot(p)
20+
return DashBase.to_dash(sp)
21+
end
1722

1823
end

src/DashBase.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
module DashBase
22
import JSON3
3-
import PackageExtensionCompat
43
include("components.jl")
54
include("registry.jl")
65
export Component, push_prop!, get_name, get_type, get_namespace,
@@ -9,8 +8,16 @@ get_dash_dependencies, get_dash_renderer_pkg, get_componens_pkgs,
98
has_relative_path, has_dev_path, has_external_url, get_type,
109
get_external_url, get_dev_path, get_relative_path
1110

11+
@static if !isdefined(Base, :get_extension)
12+
using Requires
13+
end
14+
1215
function __init__()
13-
PackageExtensionCompat.@require_extensions
16+
@static if !isdefined(Base, :get_extension)
17+
@require PlotlyBase = "a03496cd-edff-5a9b-9e67-9cda94a718b5" include("../ext/DashBasePlotlyBaseExt.jl")
18+
@require PlotlyJS = "f0f68f2c-4968-5e81-91da-67840de0976a" include("../ext/DashBasePlotlyJSExt.jl")
19+
@require Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" include("../ext/DashBasePlotsExt.jl")
20+
end
1421
end
1522

1623
end # module

test/test_ext.jl

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,36 @@
1-
using DashBase
21
using Test
3-
using Plots
4-
plotlyjs()
2+
using DashBase
3+
import PlotlyBase
4+
import PlotlyJS
5+
import Plots
6+
7+
function run_assertions(pl)
8+
obj = @test_nowarn DashBase.to_dash(pl)
9+
@test obj isa Dict{Symbol, Any}
10+
@test obj[:data][1][:y] == [1, 2, 3, 4, 5]
11+
@test haskey(obj, :layout)
12+
@test haskey(obj, :frames)
13+
@test !haskey(obj, :config)
14+
end
15+
16+
@testset "DashBasePlotlyBaseExt" begin
17+
pl = PlotlyBase.Plot(1:5)
18+
run_assertions(pl)
19+
end
20+
21+
@testset "DashBasePlotsJSExt" begin
22+
pl = PlotlyJS.plot(1:5)
23+
run_assertions(pl)
24+
end
525

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)
26+
@testset "DashBasePlotsExt + plotlyjs()" begin
27+
Plots.plotlyjs()
28+
pl = Plots.plot(1:5)
29+
run_assertions(pl)
1430
end
1531

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)
32+
@testset "DashBasePlotsExt + plotly()" begin
33+
Plots.plotly()
34+
pl = Plots.plot(1:5)
35+
run_assertions(pl)
2536
end

0 commit comments

Comments
 (0)