Skip to content

Commit

Permalink
Merge branch 'master' into compathelper/new_version/2023-06-03-00-41-…
Browse files Browse the repository at this point in the history
…36-699-02759681602
  • Loading branch information
BeastyBlacksmith authored Jan 19, 2024
2 parents 837066c + 457befe commit 4ac3566
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 41 deletions.
3 changes: 2 additions & 1 deletion .github/funding.yml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
github: sglyon
github: [sglyon, JuliaPlots]
open_collective: plotsjl
5 changes: 1 addition & 4 deletions .github/workflows/artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ jobs:
gen-artifacts:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# The plotly version. Bumping this environment variable should do the trick
env:
PLOTLY_VER: 2.3.0

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
Expand All @@ -33,7 +30,7 @@ jobs:
- name: "Get artifact"
run: |
cd $GITHUB_WORKSPACE
julia -e 'include(joinpath(pwd(),"deps","generate_artifacts.jl")); generate_artifacts("'"$PLOTLY_VER"'","'"$GITHUB_SERVER_URL/$GITHUB_REPOSITORY"'")'
julia -e 'include(joinpath(pwd(),"deps","generate_artifacts.jl")); generate_artifacts("'"$GITHUB_SERVER_URL/$GITHUB_REPOSITORY"'")'
- name: "Commit updated Artifacts.toml"
run: |
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ tags/
tags
site/
.ipynb_checkpoints/
assets/plotly-latest.min.js
deps/plotly-latest.min.js
assets/plotly-*.min.js
deps/plotly-*.min.js
deps/plotschema.json
deps/schema.html
deps/*.csv
Expand Down
24 changes: 22 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PlotlyJS"
uuid = "f0f68f2c-4968-5e81-91da-67840de0976a"
authors = ["Spencer Lyon <[email protected]>"]
version = "0.18.10"
version = "0.18.12"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand All @@ -18,19 +18,39 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
WebIO = "0f1e0344-ec1d-5b48-a673-e5cf874b6c29"

[weakdeps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
IJulia = "7073ff75-c697-5162-941a-fcdaad2a7d2a"
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"

[extensions]
CSVExt = "CSV"
DataFramesExt = ["DataFrames", "CSV"]
IJuliaExt = "IJulia"
JSON3Ext = "JSON3"

[compat]
Blink = "0.12"
DelimitedFiles = "1"
CSV = "0.10"
DataFrames = "1"
IJulia = "1"
JSExpr = "0.5, 1"
JSON = "0.20, 0.21"
JSON3 = "1"
PlotlyBase = "0.8.15"
Reexport = "0.2, 1"
Requires = "1.0"
WebIO = "0.8"
julia = "1.3, 1.4, 1.5, 1.6"

[extras]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
IJulia = "7073ff75-c697-5162-941a-fcdaad2a7d2a"
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
test = ["Test", "CSV", "DataFrames", "IJulia", "JSON3"]
4 changes: 3 additions & 1 deletion deps/generate_artifacts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
using Pkg.Artifacts
using Downloads

function generate_artifacts(ver="latest", repo="https://github.com/JuliaPlots/PlotlyJS.jl")
ver = include("./plotly_cdn_version.jl")

function generate_artifacts(repo="https://github.com/JuliaPlots/PlotlyJS.jl")
artifacts_toml = joinpath(dirname(@__DIR__), "Artifacts.toml")

# if Artifacts.toml does not exist we also do not have to remove it
Expand Down
2 changes: 2 additions & 0 deletions deps/plotly_cdn_version.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# run the artifacts.yml Github Action after changing this file
"2.3.0"
14 changes: 14 additions & 0 deletions ext/CSVExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module CSVExt

using PlotlyJS
isdefined(Base, :get_extension) ? (using CSV) : (using ..CSV)

function PlotlyJS.dataset(::Type{CSV.File}, name::String)
ds_path = PlotlyJS.check_dataset_exists(name)
if !endswith(ds_path, "csv")
error("Can only construct CSV.File from a csv data source")
end
CSV.File(ds_path)
end

end
10 changes: 10 additions & 0 deletions ext/DataFramesExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module DataFramesExt

using PlotlyJS
isdefined(Base, :get_extension) ? (using DataFrames) : (using ..DataFrames)
isdefined(Base, :get_extension) ? (using CSV) : (using ..CSV)


PlotlyJS.dataset(::Type{DataFrames.DataFrame}, name::String) = DataFrames.DataFrame(PlotlyJS.dataset(CSV.File, name))

end
21 changes: 21 additions & 0 deletions ext/IJuliaExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module IJuliaExt

using PlotlyJS
isdefined(Base, :get_extension) ? (using IJulia) : (using ..IJulia)
isdefined(Base, :get_extension) ? (using JSON) : (using ..JSON)
isdefined(Base, :get_extension) ? (using PlotlyBase) : (using ..PlotlyBase)


function IJulia.display_dict(p::PlotlyJS.SyncPlot)
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
)
end

end
9 changes: 9 additions & 0 deletions ext/JSON3Ext.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module JSON3Ext

using PlotlyJS
isdefined(Base, :get_extension) ? (using JSON3) : (using ..JSON3)

JSON3.write(io::IO, p::PlotlyJS.SyncPlot) = JSON3.write(io, p.plot)
JSON3.write(p::PlotlyJS.SyncPlot) = JSON3.write(p.plot)

end
51 changes: 21 additions & 30 deletions src/PlotlyJS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ using JSExpr
using JSExpr: @var, @new
using Blink
using Pkg.Artifacts
using Requires
if !isdefined(Base, :get_extension)
using Requires
end

export plot, dataset, list_datasets, make_subplots, savefig, mgrid

# globals for this package
const _pkg_root = dirname(dirname(@__FILE__))
const _js_path = joinpath(artifact"plotly-artifacts", "plotly.min.js")
const _js_cdn_path = "https://cdn.plot.ly/plotly-latest.min.js"
const _js_version = include(joinpath(_pkg_root, "deps", "plotly_cdn_version.jl"))
const _js_cdn_path = "https://cdn.plot.ly/plotly-$(_js_version).min.js"
const _mathjax_cdn_path =
"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_SVG"

Expand Down Expand Up @@ -95,7 +98,7 @@ function __init__()
@warn("Warnings were generated during the last build of PlotlyJS: please check the build log at $_build_log")
end

@async _start_kaleido_process()
kaleido_task = Base.Threads.@spawn _start_kaleido_process()

if !isfile(_js_path)
@info("plotly.js javascript libary not found -- downloading now")
Expand Down Expand Up @@ -130,37 +133,25 @@ function __init__()
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)
JSON3.write(p::SyncPlot) = JSON.json(p.plot)
end
@static if !isdefined(Base, :get_extension)
@require JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1" include("../ext/JSON3Ext.jl")
@require IJulia = "7073ff75-c697-5162-941a-fcdaad2a7d2a" include("../ext/IJuliaExt.jl")

@require IJulia = "7073ff75-c697-5162-941a-fcdaad2a7d2a" begin

function IJulia.display_dict(p::SyncPlot)
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
)
@require CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" begin
include("../ext/CSVExt.jl")
@require DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" begin
include("../ext/DataFramesExt.jl")
end
end
end

@require CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" begin
function dataset(::Type{CSV.File}, name::String)
ds_path = check_dataset_exists(name)
if !endswith(ds_path, "csv")
error("Can only construct CSV.File from a csv data source")
end
CSV.File(ds_path)
end
@require DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" begin
dataset(::Type{DataFrames.DataFrame}, name::String) = DataFrames.DataFrame(dataset(CSV.File, name))
wait(kaleido_task)

if ccall(:jl_generating_output, Cint, ()) == 1
# ensure precompilation of packages depending on PlotlyJS finishes
if isdefined(P, :proc)
close(P.stdin)
wait(P.proc)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function SyncPlot(

# setup scope
deps = [
"Plotly" => joinpath(artifact"plotly-artifacts", "plotly.min.js"),
"Plotly" => _js_path,
joinpath(@__DIR__, "..", "assets", "plotly_webio.bundle.js")
]
scope = Scope(imports=deps)
Expand Down
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@ const M = PlotlyJS
# include("blink.jl")
include("kaleido.jl")

# these are public API
@test isfile(PlotlyJS._js_path)
@test !isempty(PlotlyJS._js_version)
@test !startswith(PlotlyJS._js_version, "v")

end

0 comments on commit 4ac3566

Please sign in to comment.