Skip to content

Commit f5653f4

Browse files
committed
make code easier to read, add save image example to readme
1 parent 467dfb0 commit f5653f4

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ Plot()(
5555

5656
<br><br>
5757

58-
# 📄 Saving HTML files with [Cobweb.jl](https://github.com/joshday/Cobweb.jl)
58+
# 📄 Saving Plots
59+
60+
## Save HTML files with [Cobweb.jl](https://github.com/joshday/Cobweb.jl)
5961

6062
```julia
6163
using Cobweb: Page
@@ -65,6 +67,14 @@ page = Page(p)
6567
save(page, "myplot.html")
6668
```
6769

70+
## Save images with [PlotlyKaleido.jl](https://github.com/JuliaPlots/PlotlyKaleido.jl)
71+
72+
```julia
73+
using PlotlyKaleido
74+
75+
PlotlyKaleido.savefig(p, "myplot.png")
76+
```
77+
6878
<br><br>
6979

7080
# 📖 Docs

src/PlotlyLight.jl

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,25 @@ end
104104
p.layout.title.text = "My Title!"
105105
p
106106
"""
107-
Base.@kwdef mutable struct Plot
108-
data::Vector{Config} = Config[]
109-
layout::Config = Defaults.layout[]
110-
config::Config = Defaults.config[]
111-
id::String = randstring(10) # id of graphDiv
112-
js::Cobweb.Javascript = Cobweb.Javascript("console.log('plot created!')")
113-
end
114-
function Plot(traces, layout=Defaults.layout[], config=Defaults.config[]; kw...)
115-
data = traces isa Config ? [traces] : traces
116-
Plot(; kw..., data,
117-
layout = merge(layout, Defaults.layout[]),
118-
config = merge(config, Defaults.config[])
119-
)
107+
mutable struct Plot
108+
data::Vector{Config}
109+
layout::Config
110+
config::Config
111+
id::String # id of graphDiv
112+
js::Cobweb.Javascript
113+
114+
function Plot(
115+
data::Union{Config, Vector{Config}},
116+
layout::Config = Defaults.layout[],
117+
config::Config = Defaults.config[];
118+
# kw
119+
id::AbstractString = randstring(10),
120+
js::Cobweb.Javascript = Cobweb.Javascript("console.log('plot created!')")
121+
)
122+
new(data isa Config ? [data] : data, layout, config, string(id), js)
123+
end
120124
end
125+
Plot(; kw...) = Plot(Config(kw))
121126
(p::Plot)(; kw...) = (push!(p.data, Config(kw)); p)
122127

123128
StructTypes.StructType(::Plot) = StructTypes.Struct()

0 commit comments

Comments
 (0)