Skip to content

Remove Blink dependency #451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -19,7 +18,6 @@ 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"
Expand Down
54 changes: 0 additions & 54 deletions src/PlotlyJS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import PlotlyBase:
using WebIO
using JSExpr
using JSExpr: @var, @new
using Blink
using Pkg.Artifacts
using Requires

Expand All @@ -30,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")
Expand All @@ -41,29 +38,6 @@ 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

const DEFAULT_RENDERER = Ref(BLINK)

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()
Expand Down Expand Up @@ -102,34 +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

# 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)
Expand Down
25 changes: 1 addition & 24 deletions src/display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this function is used when generating the Documenter pages (not for Blink per se).

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)
Expand Down Expand Up @@ -146,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...)
Expand All @@ -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...]
Expand Down