Skip to content

Commit

Permalink
fix interactvity bug, load vtk/plotyl only once per div
Browse files Browse the repository at this point in the history
  • Loading branch information
j-fu committed Feb 20, 2023
1 parent 373aad3 commit b0de0d9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PlutoVista"
uuid = "646e1f28-b900-46d7-9d87-d554eb38a413"
authors = ["Juergen Fuhrmann <[email protected]>"]
version = "0.8.22"
version = "0.8.23"

[deps]
ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
Expand Down
9 changes: 5 additions & 4 deletions src/plutoplotlyplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ function PlutoPlotlyPlot(;resolution=(300,300), kwargs...)
end



const plotly = read(joinpath(@__DIR__, "..", "imports", "plotly.min.js"), String)
const plutoplotlyplot = read(joinpath(@__DIR__, "..", "src_js", "plutoplotlyplot.js"), String)

Expand All @@ -64,7 +63,6 @@ Show plotly plot.
function Base.show(io::IO, ::Union{MIME"text/html", MIME"juliavscode/html"}, p::PlutoPlotlyPlot)
result="""
<script>
$(plotly)
$(plutoplotlyplot)
var jsdict = $(Main.PlutoRunner.publish_to_js(p.jsdict))
plutoplotlyplot("$(p.uuid)",jsdict,$(p.w), $(p.h))
Expand All @@ -73,9 +71,12 @@ function Base.show(io::IO, ::Union{MIME"text/html", MIME"juliavscode/html"}, p::
# updating only works when the div remains as output from another cell
# so we can't create a plot and update it in the cell with the draing commands
if !p.update
result=result*"""
result="""
<script>
$(plotly)
</script>
<div id="$(p.uuid)" style= "width: $(p.w)px; height: $(p.h)px; ; display: inline-block;style="white-space:nowrap;"></div>
"""
"""*result
end
p.update=true
write(io,result)
Expand Down
9 changes: 6 additions & 3 deletions src/plutovtkplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const vtk = read(joinpath(@__DIR__, "..", "imports", "vtk.js"), String)
const canvascolorbar = read(joinpath(@__DIR__, "..", "src_js", "canvascolorbar.js"), String)
const plutovtkplot = read(joinpath(@__DIR__, "..", "src_js", "plutovtkplot.js"), String)


"""
Base.show(io::IO,::MIME"text/html",p::PlutoVTKPlot)
Expand All @@ -68,7 +69,10 @@ function Base.show(io::IO, ::MIME"text/html", p::PlutoVTKPlot)
uuidcbar="$(p.uuid)"*"cbar"
div=""
if !p.update
div="""
div="""
<script>
$(vtk)
</script>
<div style="white-space:nowrap;">
<div id="$(p.uuid)" style= "width: $(p.w-60)px; height: $(p.h-60)px; display: inline-block; "></div>
<canvas id="$(uuidcbar)" width=60, height="$(p.h-25)" style="display: inline-block; "></canvas>
Expand All @@ -77,7 +81,6 @@ function Base.show(io::IO, ::MIME"text/html", p::PlutoVTKPlot)
end
result="""
<script>
$(vtk)
$(plutovtkplot)
$(canvascolorbar)
const jsdict = $(Main.PlutoRunner.publish_to_js(p.jsdict))
Expand All @@ -86,7 +89,7 @@ function Base.show(io::IO, ::MIME"text/html", p::PlutoVTKPlot)
</script>
"""
p.update=true
write(io,result*div)
write(io,div*result)
end


Expand Down

2 comments on commit b0de0d9

@j-fu
Copy link
Owner Author

@j-fu j-fu commented on b0de0d9 Feb 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/78125

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.8.23 -m "<description of version>" b0de0d9d317f913982a7e0eae228be00f95d3812
git push origin v0.8.23

Please sign in to comment.