From 556fc088f646258ecccfac4439ad90c46470abd7 Mon Sep 17 00:00:00 2001 From: Josh Day Date: Fri, 2 Feb 2024 09:54:35 -0500 Subject: [PATCH] wip trace --- deps/generate_trace.jl | 40 ++-------------------------------------- src/PlotlyLight.jl | 2 +- src/trace.jl | 4 ++-- test/runtests.jl | 5 +++++ 4 files changed, 10 insertions(+), 41 deletions(-) diff --git a/deps/generate_trace.jl b/deps/generate_trace.jl index 4a08ec0..c89fbd8 100644 --- a/deps/generate_trace.jl +++ b/deps/generate_trace.jl @@ -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__) @@ -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 """) @@ -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 diff --git a/src/PlotlyLight.jl b/src/PlotlyLight.jl index 09f4081..481c85e 100644 --- a/src/PlotlyLight.jl +++ b/src/PlotlyLight.jl @@ -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 diff --git a/src/trace.jl b/src/trace.jl index 429a124..be820c7 100644 --- a/src/trace.jl +++ b/src/trace.jl @@ -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...)) diff --git a/test/runtests.jl b/test/runtests.jl index 014e251..74536ab 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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])),