From 274643dfd2f6703dcc3f00da721fe9b8c4281832 Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Fri, 28 Jul 2023 20:29:36 +0200 Subject: [PATCH 1/5] add test workflow --- .github/workflows/jl_test.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/jl_test.yml diff --git a/.github/workflows/jl_test.yml b/.github/workflows/jl_test.yml new file mode 100644 index 0000000..fbd0073 --- /dev/null +++ b/.github/workflows/jl_test.yml @@ -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 From 278efea084799448c22703bd70048b7a1c24eb0b Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Fri, 28 Jul 2023 20:49:42 +0200 Subject: [PATCH 2/5] add Plots conversion via extension --- Project.toml | 14 +++++++++++++- ext/DashBasePlotsExt.jl | 9 +++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 ext/DashBasePlotsExt.jl diff --git a/Project.toml b/Project.toml index 236adb3..f4b2912 100644 --- a/Project.toml +++ b/Project.toml @@ -3,10 +3,22 @@ uuid = "03207cf0-e2b3-4b91-9ca8-690cf0fb507e" authors = ["Alexandr Romanenko "] version = "0.2.0" +[weakdeps] +Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" + +[extensions] +DashBasePlotsExt = "Plots" + [deps] JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1" + +[extras] Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [compat] JSON3 = "1" -julia = "1.2" +julia = "1.9" +Plots = "1" + +[targets] +test = ["Test"] diff --git a/ext/DashBasePlotsExt.jl b/ext/DashBasePlotsExt.jl new file mode 100644 index 0000000..b2918c4 --- /dev/null +++ b/ext/DashBasePlotsExt.jl @@ -0,0 +1,9 @@ +module DashBasePlotsExt + +import Plots +import DashBase + + +DashBase.to_dash(p::Plots.Plot{Plots.PlotlyBackend}) = (data = Plots.plotly_series(p), layout = Plots.plotly_layout(p)) + +end From 1a00ca53afad714c2c7e4c056706756b69f2cccd Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Fri, 28 Jul 2023 20:53:06 +0200 Subject: [PATCH 3/5] add Plots to extras --- Project.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Project.toml b/Project.toml index f4b2912..caf358f 100644 --- a/Project.toml +++ b/Project.toml @@ -14,6 +14,7 @@ JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1" [extras] Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" [compat] JSON3 = "1" From 75adf099f756db28a1dd5d917ad0a070e0f5e27a Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Wed, 2 Aug 2023 11:14:30 +0200 Subject: [PATCH 4/5] add PlotlyBase/PlotlyJS extensions and tests --- Project.toml | 26 +++++++++++++++++--------- ext/DashBasePlotlyBaseExt.jl | 13 +++++++++++++ ext/DashBasePlotlyJSExt.jl | 10 ++++++++++ ext/DashBasePlotsExt.jl | 11 ++++++++++- src/DashBase.jl | 5 +++++ test/runtests.jl | 3 ++- test/test_ext.jl | 25 +++++++++++++++++++++++++ 7 files changed, 82 insertions(+), 11 deletions(-) create mode 100644 ext/DashBasePlotlyBaseExt.jl create mode 100644 ext/DashBasePlotlyJSExt.jl create mode 100644 test/test_ext.jl diff --git a/Project.toml b/Project.toml index caf358f..f7f370c 100644 --- a/Project.toml +++ b/Project.toml @@ -3,23 +3,31 @@ uuid = "03207cf0-e2b3-4b91-9ca8-690cf0fb507e" authors = ["Alexandr Romanenko "] version = "0.2.0" +[deps] +JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1" +PackageExtensionCompat = "65ce6f38-6b18-4e1d-a461-8949797d7930" + [weakdeps] +PlotlyBase = "a03496cd-edff-5a9b-9e67-9cda94a718b5" +PlotlyJS = "f0f68f2c-4968-5e81-91da-67840de0976a" Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" [extensions] +DashBasePlotlyBaseExt = "PlotlyBase" +DashBasePlotlyJSExt = "PlotlyJS" DashBasePlotsExt = "Plots" -[deps] -JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1" - -[extras] -Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" -Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" - [compat] JSON3 = "1" -julia = "1.9" Plots = "1" +julia = "1.6" + +[extras] +PlotlyBase = "a03496cd-edff-5a9b-9e67-9cda94a718b5" +PlotlyJS = "f0f68f2c-4968-5e81-91da-67840de0976a" +PlotlyKaleido = "f2990250-8cf9-495f-b13a-cce12b45703c" +Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Test"] +test = ["Test", "Plots", "PlotlyBase", "PlotlyJS", "PlotlyKaleido"] diff --git a/ext/DashBasePlotlyBaseExt.jl b/ext/DashBasePlotlyBaseExt.jl new file mode 100644 index 0000000..2a7e243 --- /dev/null +++ b/ext/DashBasePlotlyBaseExt.jl @@ -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 diff --git a/ext/DashBasePlotlyJSExt.jl b/ext/DashBasePlotlyJSExt.jl new file mode 100644 index 0000000..ff0e012 --- /dev/null +++ b/ext/DashBasePlotlyJSExt.jl @@ -0,0 +1,10 @@ +module DashBasePlotlyJSExt + +import PlotlyJS +import DashBase + +function DashBase.to_dash(p::PlotlyJS.SyncPlot) + DashBase.to_dash(p.plot) +end + +end diff --git a/ext/DashBasePlotsExt.jl b/ext/DashBasePlotsExt.jl index b2918c4..a3a8ee0 100644 --- a/ext/DashBasePlotsExt.jl +++ b/ext/DashBasePlotsExt.jl @@ -4,6 +4,15 @@ import Plots import DashBase -DashBase.to_dash(p::Plots.Plot{Plots.PlotlyBackend}) = (data = Plots.plotly_series(p), layout = Plots.plotly_layout(p)) +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 diff --git a/src/DashBase.jl b/src/DashBase.jl index 03457dc..88ac6ce 100644 --- a/src/DashBase.jl +++ b/src/DashBase.jl @@ -1,5 +1,6 @@ module DashBase import JSON3 +import PackageExtensionCompat include("components.jl") include("registry.jl") export Component, push_prop!, get_name, get_type, get_namespace, @@ -8,4 +9,8 @@ get_dash_dependencies, get_dash_renderer_pkg, get_componens_pkgs, has_relative_path, has_dev_path, has_external_url, get_type, get_external_url, get_dev_path, get_relative_path +function __init__() + PackageExtensionCompat.@require_extensions +end + end # module diff --git a/test/runtests.jl b/test/runtests.jl index 9c959ab..79c1c93 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,3 +1,4 @@ using Test include("components.jl") -include("registry.jl") \ No newline at end of file +include("test_ext.jl") +include("registry.jl") diff --git a/test/test_ext.jl b/test/test_ext.jl new file mode 100644 index 0000000..4e5e889 --- /dev/null +++ b/test/test_ext.jl @@ -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 + 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 From 57e2d73ff4625bf3eb8b4e16f33102a784f45ef6 Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Wed, 2 Aug 2023 13:46:59 +0200 Subject: [PATCH 5/5] add compats --- Project.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Project.toml b/Project.toml index f7f370c..51efcbe 100644 --- a/Project.toml +++ b/Project.toml @@ -21,6 +21,9 @@ DashBasePlotsExt = "Plots" JSON3 = "1" Plots = "1" julia = "1.6" +PlotlyBase = "0.8" +PlotlyJS = "0.18" +PackageExtensionCompat = "1" [extras] PlotlyBase = "a03496cd-edff-5a9b-9e67-9cda94a718b5"