From 6d156370241e46690e8bc8b0799a260ed0b7830c Mon Sep 17 00:00:00 2001 From: Allen Hill Date: Thu, 27 Oct 2022 09:26:04 -0400 Subject: [PATCH 1/5] Remove Blink dep --- Project.toml | 3 --- src/PlotlyJS.jl | 29 ++++++++--------------------- src/display.jl | 23 ----------------------- 3 files changed, 8 insertions(+), 47 deletions(-) diff --git a/Project.toml b/Project.toml index eb4cb35b..3cc0f867 100644 --- a/Project.toml +++ b/Project.toml @@ -5,7 +5,6 @@ version = "0.18.10" [deps] Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" -Blink = "ad839575-38b3-5650-b840-f874b8c74a25" DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab" JSExpr = "97c1335a-c9c5-57fe-bc5d-ec35cebe8660" JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" @@ -19,13 +18,11 @@ Requires = "ae029012-a4dd-5104-9daa-d747884805df" WebIO = "0f1e0344-ec1d-5b48-a673-e5cf874b6c29" [compat] -Blink = "0.12" JSExpr = "0.5, 1" JSON = "0.20, 0.21" PlotlyBase = "0.8.15" Reexport = "0.2, 1" Requires = "1.0" -WebIO = "0.8" julia = "1.3, 1.4, 1.5, 1.6" [extras] diff --git a/src/PlotlyJS.jl b/src/PlotlyJS.jl index 9d3e514e..ca130a50 100644 --- a/src/PlotlyJS.jl +++ b/src/PlotlyJS.jl @@ -4,6 +4,7 @@ using Base64 using Reexport @reexport using PlotlyBase using JSON +using WebIO using REPL, Pkg, Pkg.Artifacts, DelimitedFiles # stdlib # need to import some functions because methods are meta-generated @@ -14,10 +15,8 @@ import PlotlyBase: extendtraces, prependtraces, prep_kwargs, sizes, _tovec, react, react!, add_trace! -using WebIO using JSExpr using JSExpr: @var, @new -using Blink using Pkg.Artifacts using Requires @@ -41,21 +40,9 @@ make_subplots(;kwargs...) = plot(Layout(Subplots(;kwargs...))) @doc (@doc Subplots) make_subplots -function docs() - schema_path = joinpath(dirname(dirname(@__FILE__)), "deps", "schema.html") - if !isfile(schema_path) - msg = "schema docs not built. Run `Pkg.build(\"PlotlyJS\")` to generate" - error(msg) - end - w = Blink.Window() - wait(w.content) - Blink.content!(w, "html", open(f -> read(f, String), schema_path), fade=false, async=false) -end - - -@enum RENDERERS BLINK IJULIA BROWSER DOCS +@enum RENDERERS IJULIA BROWSER -const DEFAULT_RENDERER = Ref(BLINK) +const DEFAULT_RENDERER = Ref(BROWSER) function set_default_renderer(s::RENDERERS) global DEFAULT_RENDERER @@ -142,11 +129,11 @@ function __init__() Dict( "application/vnd.plotly.v1+json" => JSON.lower(p), "text/plain" => sprint(show, "text/plain", p), - "text/html" => let - buf = IOBuffer() - show(buf, MIME("text/html"), p) - String(resize!(buf.data, buf.size)) - end + # "text/html" => let + # buf = IOBuffer() + # show(buf, MIME("text/html"), p) + # String(resize!(buf.data, buf.size)) + # end ) end end diff --git a/src/display.jl b/src/display.jl index ba1c50ad..06c4781c 100644 --- a/src/display.jl +++ b/src/display.jl @@ -4,7 +4,6 @@ mutable struct SyncPlot plot::PlotlyBase.Plot scope::Scope - window::Union{Nothing,Blink.Window} end Base.getindex(p::SyncPlot, key) = p.scope[key] # look up Observables @@ -15,9 +14,6 @@ end function Base.show(io::IO, mm::MIME"text/html", p::SyncPlot) # if we are rendering docs -- short circuit and display html - if get_renderer() == DOCS - return show(io, mm, p.plot, full_html=false, include_plotlyjs="require-loaded", include_mathjax=missing) - end show(io, mm, p.scope) end Base.show(io::IO, mm::MIME"application/prs.juno.plotpane+html", p::SyncPlot) = show(io, mm, p.scope) @@ -157,25 +153,6 @@ end Base.size(sp::SyncPlot) = size(sp.plot) Base.copy(sp::SyncPlot) = SyncPlot(copy(sp.plot)) -Base.display(::PlotlyJSDisplay, p::SyncPlot) = display_blink(p::SyncPlot) - -function display_blink(p::SyncPlot) - sizeBuffer = 1.15 - plotSize = size(p.plot) - windowOptions = Dict( - "width" => floor(Int, plotSize[1] * sizeBuffer), - "height" => floor(Int, plotSize[2] * sizeBuffer) - ) - p.window = Blink.Window(windowOptions) - Blink.body!(p.window, p.scope) -end - -function Base.close(p::SyncPlot) - if p.window !== nothing && Blink.active(p.window) - close(p.window) - end -end - function send_command(scope, cmd, args...) # The handler for _commands is set up when plot is constructed scope["_commands"][] = [cmd, args...] From f2fab74e1c2c083762956263ffa9ebad5b4f12c8 Mon Sep 17 00:00:00 2001 From: Allen Hill Date: Fri, 28 Oct 2022 20:01:15 -0400 Subject: [PATCH 2/5] Remove unused PlotlyJSDisplay --- src/PlotlyJS.jl | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/PlotlyJS.jl b/src/PlotlyJS.jl index ca130a50..5f5a9ed2 100644 --- a/src/PlotlyJS.jl +++ b/src/PlotlyJS.jl @@ -29,8 +29,6 @@ const _js_cdn_path = "https://cdn.plot.ly/plotly-latest.min.js" const _mathjax_cdn_path = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_SVG" -struct PlotlyJSDisplay <: AbstractDisplay end - # include the rest of the core parts of the package include("display.jl") include("util.jl") @@ -107,16 +105,6 @@ function __init__() isdefined(Main, :IJulia) && Main.IJulia.inited && set_default_renderer(IJULIA) end - # set up display - insert!(Base.Multimedia.displays, findlast(x -> x isa Base.TextDisplay || x isa REPL.REPLDisplay, Base.Multimedia.displays) + 1, PlotlyJSDisplay()) - - atreplinit(i -> begin - while PlotlyJSDisplay() in Base.Multimedia.displays - popdisplay(PlotlyJSDisplay()) - end - insert!(Base.Multimedia.displays, findlast(x -> x isa REPL.REPLDisplay, Base.Multimedia.displays) + 1, PlotlyJSDisplay()) - end) - @require JSON2 = "2535ab7d-5cd8-5a07-80ac-9b1792aadce3" JSON2.write(io::IO, p::SyncPlot) = JSON2.write(io, p.plot) @require JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1" begin JSON3.write(io::IO, p::SyncPlot) = JSON.print(io, p.plot) From 17ac468c7bb9ede3a1b014551598245dae13a651 Mon Sep 17 00:00:00 2001 From: Allen Hill Date: Fri, 28 Oct 2022 20:38:32 -0400 Subject: [PATCH 3/5] Fix missed constructor update after removing Blink --- src/display.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/display.jl b/src/display.jl index 06c4781c..f6265455 100644 --- a/src/display.jl +++ b/src/display.jl @@ -142,7 +142,7 @@ function SyncPlot( # to us on(scope["image"]) do x end - SyncPlot(p, scope, nothing) + SyncPlot(p, scope) end function plot(args...; kwargs...) From ee51a634fa32037b28a26daf47d3863c7b7fba75 Mon Sep 17 00:00:00 2001 From: Allen Hill Date: Mon, 31 Oct 2022 12:24:22 -0400 Subject: [PATCH 4/5] fix cherry-picking --- Project.toml | 1 + src/PlotlyJS.jl | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Project.toml b/Project.toml index 3cc0f867..d4cdc8d1 100644 --- a/Project.toml +++ b/Project.toml @@ -23,6 +23,7 @@ JSON = "0.20, 0.21" PlotlyBase = "0.8.15" Reexport = "0.2, 1" Requires = "1.0" +WebIO = "0.8" julia = "1.3, 1.4, 1.5, 1.6" [extras] diff --git a/src/PlotlyJS.jl b/src/PlotlyJS.jl index 5f5a9ed2..ed1de795 100644 --- a/src/PlotlyJS.jl +++ b/src/PlotlyJS.jl @@ -4,7 +4,6 @@ using Base64 using Reexport @reexport using PlotlyBase using JSON -using WebIO using REPL, Pkg, Pkg.Artifacts, DelimitedFiles # stdlib # need to import some functions because methods are meta-generated @@ -15,6 +14,7 @@ import PlotlyBase: extendtraces, prependtraces, prep_kwargs, sizes, _tovec, react, react!, add_trace! +using WebIO using JSExpr using JSExpr: @var, @new using Pkg.Artifacts @@ -117,11 +117,11 @@ function __init__() Dict( "application/vnd.plotly.v1+json" => JSON.lower(p), "text/plain" => sprint(show, "text/plain", p), - # "text/html" => let - # buf = IOBuffer() - # show(buf, MIME("text/html"), p) - # String(resize!(buf.data, buf.size)) - # end + "text/html" => let + buf = IOBuffer() + show(buf, MIME("text/html"), p) + String(resize!(buf.data, buf.size)) + end ) end end From 1d819251dd0aece2df76b7060c2582a515ce1a98 Mon Sep 17 00:00:00 2001 From: Allen Hill Date: Fri, 28 Oct 2022 20:43:37 -0400 Subject: [PATCH 5/5] Remove unused RENDERER related machinery --- src/PlotlyJS.jl | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/src/PlotlyJS.jl b/src/PlotlyJS.jl index ed1de795..80daa1f1 100644 --- a/src/PlotlyJS.jl +++ b/src/PlotlyJS.jl @@ -38,17 +38,6 @@ make_subplots(;kwargs...) = plot(Layout(Subplots(;kwargs...))) @doc (@doc Subplots) make_subplots -@enum RENDERERS IJULIA BROWSER - -const DEFAULT_RENDERER = Ref(BROWSER) - -function set_default_renderer(s::RENDERERS) - global DEFAULT_RENDERER - DEFAULT_RENDERER[] = s -end - -@inline get_renderer() = DEFAULT_RENDERER[] - list_datasets() = readdir(joinpath(artifact"plotly-artifacts", "datasets")) function check_dataset_exists(name::String) ds = list_datasets() @@ -87,24 +76,6 @@ function __init__() include(joinpath(_pkg_root, "deps", "build.jl")) end - # set default renderer - # First check env var - env_val = get(ENV, "PLOTLY_RENDERER_JULIA", missing) - if !ismissing(env_val) - env_symbol = Symbol(uppercase(env_val)) - options = Dict(v => k for (k, v) in collect(Base.Enums.namemap(PlotlyJS.RENDERERS))) - renderer_int = get(options, env_symbol, missing) - if ismissing(renderer_int) - @warn "Unknown value for env var `PLOTLY_RENDERER_JULIA` \"$(env_val)\", known options are $(string.(keys(options)))" - else - set_default_renderer(RENDERERS(renderer_int)) - end - else - # we have no env-var - # check IJULIA - isdefined(Main, :IJulia) && Main.IJulia.inited && set_default_renderer(IJULIA) - end - @require JSON2 = "2535ab7d-5cd8-5a07-80ac-9b1792aadce3" JSON2.write(io::IO, p::SyncPlot) = JSON2.write(io, p.plot) @require JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1" begin JSON3.write(io::IO, p::SyncPlot) = JSON.print(io, p.plot)