Skip to content

Commit

Permalink
wip trace
Browse files Browse the repository at this point in the history
  • Loading branch information
joshday committed Feb 2, 2024
1 parent 325775b commit 556fc08
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 41 deletions.
40 changes: 2 additions & 38 deletions deps/generate_trace.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# This file is not included in the PlotlyLight module.
# It is a standalone script that generates files from the Plotly.js schema.
using Pkg
Pkg.activate(@__DIR__)

Expand All @@ -8,17 +6,11 @@ using JSON3, Dates
#-----------------------------------------------------------------------------# Schema
obj = JSON3.read(read(download("https://api.plot.ly/v2/plot-schema?format=json&sha1=%27%27")))

_keys(x) = Tuple(sort!(collect(keys(x))))

traces = _keys(obj.schema.traces)
trace_defs = []

bullet(key::Symbol, val::String) = "- `$(key)`: $(val)\n"
bullet(key::Symbol, val::JSON3.Object) = bullet(key, get(val, :description, ""))
traces = Tuple(sort!(collect(keys(obj.schema.traces))))

open(joinpath(@__DIR__, "..", "src", "trace.jl"), "w") do io
print(io, """
# This file is automatically generated. Do not edit this file directly.
# This file is automatically generated by `deps/generate_trace.jl`. Do not edit this file directly.
# Last update: $(Dates.now()) ET
const trace = let
""")
Expand All @@ -31,31 +23,3 @@ open(joinpath(@__DIR__, "..", "src", "trace.jl"), "w") do io
end
""")
end

# open(joinpath(@__DIR__, "..", "src", "Traces.jl"), "w") do io
# println(io, """
# This file is automatically generated. Do not edit this file directly.
# Last update: $(Dates.now()) ET

# baremodule Traces

# using ..PlotlyLight: Plot, schema, check_attributes
# using Base

# export $(join(traces, ", "))

# const traces = $traces
# """)

# for t in traces
# attributes_obj = obj.schema.traces[t].attributes
# attributes = _keys(obj.schema.traces[t].attributes)

# bullets = [bullet(a, attributes_obj[a]) for a in attributes]

# print(io, """
# $t(; kw...) = (check_attributes(:$t; kw...); Plot(; type=:$t, kw...))
# """)
# end
# println(io, "end # module Traces")
# end
2 changes: 1 addition & 1 deletion src/PlotlyLight.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fix_matrix(x) = x
fix_matrix(x::AbstractMatrix) = eachrow(x)

attributes(t::Symbol) = schema.traces[t].attributes
check_attribute(trace::Symbol, attr::Symbol) = haskey(attributes(trace), attr) || @warn("`\$trace` does not have attribute `\$attr`")
check_attribute(trace::Symbol, attr::Symbol) = haskey(attributes(trace), attr) || @warn("`$trace` does not have attribute `$attr`")
check_attributes(trace::Symbol; kw...) = foreach(k -> check_attribute(trace, k), keys(kw))

#-----------------------------------------------------------------------------# Schema
Expand Down
4 changes: 2 additions & 2 deletions src/trace.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This file is automatically generated. Do not edit this file directly.
# Last update: 2024-02-02T06:55:20.899 ET
# This file is automatically generated by `deps/generate_trace.jl`. Do not edit this file directly.
# Last update: 2024-02-02T09:54:26.618 ET
const trace = let
area(; kw...) = (check_attributes(:area; kw...); Plot(; type=:area, kw...))
bar(; kw...) = (check_attributes(:bar; kw...); Plot(; type=:bar, kw...))
Expand Down
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ html(x) = repr("text/html", x)
@test p4.data[2] == p4.data[3]
end

@testset "trace" begin
@test_warn "`scatter` does not have attribute `X`" trace.scatter(X=1:10);
@test_nowarn trace.scatter(x=1:10);
end

#-----------------------------------------------------------------------------# Aqua
Aqua.test_all(PlotlyLight,
deps_compat=(; ignore =[:REPL, :Random], check_extras = (;ignore=[:Test])),
Expand Down

0 comments on commit 556fc08

Please sign in to comment.