Skip to content

Commit e5cb6b2

Browse files
committed
add plot method and test
1 parent 50ea2ae commit e5cb6b2

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/PlotlyLight.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ mutable struct Plot
122122
end
123123
end
124124
Plot(; kw...) = Plot(Config(kw))
125-
(p::Plot)(; kw...) = (push!(p.data, Config(kw)); p)
125+
(p::Plot)(; kw...) = (push!(p.data, Config(kw)); return p)
126+
(p::Plot)(data::Config) = (push!(p.data, data); return p)
126127

127128
StructTypes.StructType(::Plot) = StructTypes.Struct()
128129

@@ -131,6 +132,10 @@ Base.display(::Cobweb.CobwebDisplay, o::Plot) = display(Cobweb.CobwebDisplay(),
131132

132133
Base.show(io::IO, ::MIME"juliavscode/html", o::Plot) = show(io, MIME"text/html"(), o)
133134

135+
function Base.show(io::IO, ::MIME"application/vnd.plotly.v1+json", p::Plot)
136+
JSON3.write(io, Config(; data=p.data, layout=p.layout, config=p.config))
137+
end
138+
134139
function write_plot_div(io::IO, o::Plot)
135140
class, style = Defaults.class, Defaults.style
136141
parent_class, parent_style = Defaults.parent_class, Defaults.parent_style

test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ using Test
77
@test Plot(Config(x = 1:10)) isa Plot
88
@test Plot(Config(x = 1:10), Config(title="Title")) isa Plot
99
@test Plot(Config(x = 1:10), Config(title="Title"), Config(displaylogo=true)) isa Plot
10+
p = Plot()
11+
@test isempty(only(p.data))
12+
p(Config(x=1:10,y=rand(10)))
13+
@test length(p.data) == 2
1014
end
1115
#-----------------------------------------------------------------------------# src
1216
@testset "src" begin

0 commit comments

Comments
 (0)