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 diff --git a/Project.toml b/Project.toml index 236adb3..51efcbe 100644 --- a/Project.toml +++ b/Project.toml @@ -5,8 +5,32 @@ version = "0.2.0" [deps] JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1" -Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +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" [compat] JSON3 = "1" -julia = "1.2" +Plots = "1" +julia = "1.6" +PlotlyBase = "0.8" +PlotlyJS = "0.18" +PackageExtensionCompat = "1" + +[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", "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 new file mode 100644 index 0000000..a3a8ee0 --- /dev/null +++ b/ext/DashBasePlotsExt.jl @@ -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 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