Skip to content

Commit

Permalink
Merge pull request #44 from JuliaPluto/use-local-plotly-with-publishe…
Browse files Browse the repository at this point in the history
…d_to_js
  • Loading branch information
disberd authored Mar 21, 2024
2 parents 0a7d304 + f031405 commit 3ca2515
Show file tree
Hide file tree
Showing 11 changed files with 260 additions and 142 deletions.
6 changes: 6 additions & 0 deletions Artifacts.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[plotly-esm-min]
git-tree-sha1 = "68f1084b42e64a8787e28f1c373476c106ecb448"

[[plotly-esm-min.download]]
sha256 = "807e538be455da123e15999673df98ddcfefd4d610aa4416ba3fa28806f24929"
url = "https://github.com/disberd/PlotlyArtifactsESM/releases/download/v2.30.1/plotly-esm-min.tar.gz"
6 changes: 5 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ version = "0.4.6"

[deps]
AbstractPlutoDingetjes = "6e696c72-6542-2067-7265-42206c756150"
Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
BaseDirs = "18cc8868-cbac-4acf-b575-c8ff214dc66f"
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand All @@ -28,6 +29,7 @@ UnitfulExt = "Unitful"

[compat]
AbstractPlutoDingetjes = "1"
Artifacts = "1"
BaseDirs = "1"
Colors = "0.12"
Dates = "1.9"
Expand All @@ -38,6 +40,8 @@ LaTeXStrings = "1"
Markdown = "1.9"
Pkg = "1.9"
PlotlyBase = "0.8"
PlotlyKaleido = "2"
Reexport = "1"
julia = "1.9"
TOML = "1"
Unitful = "1"
julia = "1.9"
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# PlutoPlotly.jl
[![Build Status](https://github.com/disberd/PlutoPlotly.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/disberd/PlutoPlotly.jl/actions/workflows/CI.yml?query=branch%3Amain)
[![Coverage](https://codecov.io/gh/disberd/PlutoPlotly.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/disberd/PlutoPlotly.jl)
[![Aqua QA](https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg)](https://github.com/JuliaTesting/Aqua.jl)

This package provides a wrapper type `PlutoPlot` around the `Plot` type from [PlotlyBase.jl](https://github.com/sglyon/PlotlyBase.jl) that exposes the [plotly library](https://plotly.com/julia/).

Expand Down
74 changes: 42 additions & 32 deletions notebooks/basic_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ md"""
# Tests
"""

# ╔═╡ 51a36d49-1dad-4340-8671-a6a63eb367a2
enable_plutoplotly_offline()

# ╔═╡ c4e4400e-e063-4236-96e5-ca3a60313e37
md"""
## Layout Range
Expand Down Expand Up @@ -514,9 +517,9 @@ PlutoUI = "7f904dfe-b85e-4ff6-b463-dae2292396a8"
[compat]
Colors = "~0.12.10"
PlutoDevMacros = "~0.5.8"
PlutoExtras = "~0.7.9"
PlutoUI = "~0.7.52"
PlutoDevMacros = "~0.7.2"
PlutoExtras = "~0.7.12"
PlutoUI = "~0.7.58"
"""

# ╔═╡ 00000000-0000-0000-0000-000000000002
Expand All @@ -525,13 +528,13 @@ PLUTO_MANIFEST_TOML_CONTENTS = """
julia_version = "1.10.2"
manifest_format = "2.0"
project_hash = "becb366eb1628f34a109423203d027d4a184385e"
project_hash = "b19cebbc09904d344f1a75767d597eb0075f0a44"
[[deps.AbstractPlutoDingetjes]]
deps = ["Pkg"]
git-tree-sha1 = "91bd53c39b9cbfb5ef4b015e8b582d344532bd0a"
git-tree-sha1 = "0f748c81756f2e5e6854298f11ad8b2dfae6911a"
uuid = "6e696c72-6542-2067-7265-42206c756150"
version = "1.2.0"
version = "1.3.0"
[[deps.ArgTools]]
uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"
Expand Down Expand Up @@ -564,6 +567,12 @@ version = "1.1.0+0"
deps = ["Printf"]
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
[[deps.DocStringExtensions]]
deps = ["LibGit2"]
git-tree-sha1 = "2fb1e02f2b635d0845df5d7c167fec4dd739b00d"
uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
version = "0.9.3"
[[deps.Downloads]]
deps = ["ArgTools", "FileWatching", "LibCURL", "NetworkOptions"]
uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
Expand All @@ -580,21 +589,21 @@ version = "0.8.4"
[[deps.Hyperscript]]
deps = ["Test"]
git-tree-sha1 = "8d511d5b81240fc8e6802386302675bdf47737b9"
git-tree-sha1 = "179267cfa5e712760cd43dcae385d7ea90cc25a4"
uuid = "47d2ed2b-36de-50cf-bf87-49c2cf4b8b91"
version = "0.0.4"
version = "0.0.5"
[[deps.HypertextLiteral]]
deps = ["Tricks"]
git-tree-sha1 = "c47c5fa4c5308f27ccaac35504858d8914e102f9"
git-tree-sha1 = "7134810b1afce04bbc1045ca1985fbe81ce17653"
uuid = "ac1192a8-f4b3-4bfe-ba22-af5b92cd3ab2"
version = "0.9.4"
version = "0.9.5"
[[deps.IOCapture]]
deps = ["Logging", "Random"]
git-tree-sha1 = "d75853a0bdbfb1ac815478bacd89cd27b550ace6"
git-tree-sha1 = "8b72179abc660bfab5e28472e019392b97d0985c"
uuid = "b5f81e59-6552-4d32-b1f0-c071b021bf89"
version = "0.2.3"
version = "0.2.4"
[[deps.InteractiveUtils]]
deps = ["Markdown"]
Expand Down Expand Up @@ -647,9 +656,9 @@ version = "0.1.4"
[[deps.MacroTools]]
deps = ["Markdown", "Random"]
git-tree-sha1 = "9ee1618cbf5240e6d4e0371d6f24065083f60c48"
git-tree-sha1 = "2fa9ee3e63fd3a4f7a9a4f4744a52f4856de82df"
uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
version = "0.5.11"
version = "0.5.13"
[[deps.Markdown]]
deps = ["Base64"]
Expand Down Expand Up @@ -678,44 +687,44 @@ version = "0.3.23+4"
[[deps.Parsers]]
deps = ["Dates", "PrecompileTools", "UUIDs"]
git-tree-sha1 = "716e24b21538abc91f6205fd1d8363f39b442851"
git-tree-sha1 = "8489905bcdbcfac64d1daa51ca07c0d8f0283821"
uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
version = "2.7.2"
version = "2.8.1"
[[deps.Pkg]]
deps = ["Artifacts", "Dates", "Downloads", "FileWatching", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"]
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
version = "1.10.0"
[[deps.PlutoDevMacros]]
deps = ["HypertextLiteral", "InteractiveUtils", "MacroTools", "Markdown", "Pkg", "Random", "TOML"]
git-tree-sha1 = "6ce1d9f7c078b493812161349c48735dee275466"
deps = ["AbstractPlutoDingetjes", "DocStringExtensions", "HypertextLiteral", "InteractiveUtils", "MacroTools", "Markdown", "Pkg", "Random", "TOML"]
git-tree-sha1 = "2944f76ac8c11c913a620da0a6b035e2fadf94c1"
uuid = "a0499f29-c39b-4c5c-807c-88074221b949"
version = "0.5.8"
version = "0.7.2"
[[deps.PlutoExtras]]
deps = ["AbstractPlutoDingetjes", "HypertextLiteral", "InteractiveUtils", "Markdown", "PlutoDevMacros", "PlutoUI", "REPL", "Reexport"]
git-tree-sha1 = "aad38509250eaa0840d2aadd73ef23c2a89bdb4a"
deps = ["AbstractPlutoDingetjes", "HypertextLiteral", "InteractiveUtils", "Markdown", "PlutoDevMacros", "PlutoUI", "REPL"]
git-tree-sha1 = "93d8c75734da9192d0639406fe6fb446be0fba4f"
uuid = "ed5d0301-4775-4676-b788-cf71e66ff8ed"
version = "0.7.9"
version = "0.7.12"
[[deps.PlutoUI]]
deps = ["AbstractPlutoDingetjes", "Base64", "ColorTypes", "Dates", "FixedPointNumbers", "Hyperscript", "HypertextLiteral", "IOCapture", "InteractiveUtils", "JSON", "Logging", "MIMEs", "Markdown", "Random", "Reexport", "URIs", "UUIDs"]
git-tree-sha1 = "e47cd150dbe0443c3a3651bc5b9cbd5576ab75b7"
git-tree-sha1 = "71a22244e352aa8c5f0f2adde4150f62368a3f2e"
uuid = "7f904dfe-b85e-4ff6-b463-dae2292396a8"
version = "0.7.52"
version = "0.7.58"
[[deps.PrecompileTools]]
deps = ["Preferences"]
git-tree-sha1 = "03b4c25b43cb84cee5c90aa9b5ea0a78fd848d2f"
git-tree-sha1 = "5aa36f7049a63a1528fe8f7c3f2113413ffd4e1f"
uuid = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
version = "1.2.0"
version = "1.2.1"
[[deps.Preferences]]
deps = ["TOML"]
git-tree-sha1 = "7eb1686b4f04b82f96ed7a4ea5890a4f0c7a09f1"
git-tree-sha1 = "9306f6085165d270f7e3db02af26a400d580f5c6"
uuid = "21216c6a-2e73-6563-6e65-726566657250"
version = "1.4.0"
version = "1.4.3"
[[deps.Printf]]
deps = ["Unicode"]
Expand Down Expand Up @@ -774,14 +783,14 @@ deps = ["InteractiveUtils", "Logging", "Random", "Serialization"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
[[deps.Tricks]]
git-tree-sha1 = "aadb748be58b492045b4f56166b5188aa63ce549"
git-tree-sha1 = "eae1bb484cd63b36999ee58be2de6c178105112f"
uuid = "410a4b4d-49e4-4fbc-ab6d-cb71b17b3775"
version = "0.1.7"
version = "0.1.8"
[[deps.URIs]]
git-tree-sha1 = "b7a5e99f24892b6824a954199a45e9ffcc1c70f0"
git-tree-sha1 = "67db6cc7b3821e19ebe75791a9dd19c9b1188f2b"
uuid = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4"
version = "1.5.0"
version = "1.5.1"
[[deps.UUIDs]]
deps = ["Random", "SHA"]
Expand Down Expand Up @@ -816,6 +825,7 @@ version = "17.4.0+2"
# ╠═72c073fd-5f1b-4af0-901b-aaa901f0f273
# ╠═70dc8fa0-cc32-4ebe-af0d-62b5bb3a82ed
# ╟─acba5003-a456-4c1a-a53f-71a3bec30251
# ╠═51a36d49-1dad-4340-8671-a6a63eb367a2
# ╟─c4e4400e-e063-4236-96e5-ca3a60313e37
# ╟─e047e1b8-1a41-402b-8ed0-90cccbf0c166
# ╠═7c50f0f4-bc18-4f12-a8b6-5eaba151c923
Expand Down
20 changes: 17 additions & 3 deletions src/PlutoPlotly.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module PlutoPlotly

using Reexport
@reexport using PlotlyBase
using PlotlyBase

using HypertextLiteral
using AbstractPlutoDingetjes
Expand All @@ -12,13 +11,28 @@ using Colors
using LaTeXStrings
using Markdown
using Downloads: download
using Artifacts
# This is similar to `@reexport` but does not exports undefined names and can
# also avoid exporting the module name
function re_export(m::Module; skip_modname = false)
mod_name = nameof(m)
nms = names(m)
exprts = filter(nms) do n
isdefined(m, n) && (!skip_modname || n != mod_name)
end
eval(:(using .$mod_name))
eval(:(export $(exprts...)))
end

re_export(PlotlyBase; skip_modname = false)
export PlutoPlot, get_plotly_version, change_plotly_version,
check_plotly_version, force_pluto_mathjax_local, htl_js, add_plotly_listener!,
force_pluto_mathjax_local, htl_js, add_plotly_listener!,
add_class!, remove_class!, add_js_listener!, default_plotly_template,
get_image_options, change_image_options!, plutoplotly_paste_receiver
export plot, push_script!, prepend_cell_selector
export make_subplots
export enable_plutoplotly_offline


include("local_plotly_library.jl")

Expand Down
24 changes: 4 additions & 20 deletions src/basics.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const PLOTLY_VERSION = Ref("2.26.2")
const ARTIFACT_VERSION = VersionNumber(read(joinpath(artifact"plotly-esm-min", "VERSION"), String))
const PLOTLY_VERSION = Ref(ARTIFACT_VERSION)
const DEFAULT_TEMPLATE = Ref(PlotlyBase.templates[PlotlyBase.templates.default])
const JS = HypertextLiteral.JavaScript

Expand Down Expand Up @@ -53,31 +54,14 @@ end


## Plotly Version ##
function change_plotly_version(ver::String)
function change_plotly_version(v)
ver = VersionNumber(v)
maybe_add_plotly_local(ver)
PLOTLY_VERSION[] = ver
end

get_plotly_version() = PLOTLY_VERSION[]

check_plotly_version() = @htl """
<script>
let dv = document.createElement('div')
let ver = window.Plotly?.version
if (!ver) {
dv.innerHTML = "Plotly not loaded!"
return dv
}
if (ver === $(PLOTLY_VERSION[])) {
dv.innerHTML = ver
} else {
dv.innerHTML = "The loaded Plotly version (" + ver + ") is different from the one specified in the package ($(HypertextLiteral.JavaScript(PLOTLY_VERSION[]))), reload the browser page to use the version from PlutoPlotly"
}
return dv
</script>
"""

## Prepend Cell Selector ##
"""
prepend_cell_selector(selector="")
Expand Down
Loading

0 comments on commit 3ca2515

Please sign in to comment.