Skip to content

Commit 179c724

Browse files
committed
fix savefig issues
1 parent 195bd2d commit 179c724

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

src/kaleido.jl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ function _start_kaleido_process()
6868
nothing
6969
end
7070

71+
savefig(p::SyncPlot; kwargs...) = savefig(p.plot; kwargs...)
72+
7173
function savefig(
7274
p::Plot;
7375
width::Union{Nothing,Int}=nothing,
@@ -119,6 +121,10 @@ function savefig(
119121
end
120122
end
121123

124+
125+
@inline _get_Plot(p::Plot) = p
126+
@inline _get_Plot(p::SyncPlot) = p.plot
127+
122128
"""
123129
savefig(
124130
io::IO,
@@ -136,21 +142,20 @@ image scale. `width` and `height` set the dimensions, in pixels. Defaults
136142
are taken from `p.layout`, or supplied by plotly
137143
"""
138144
function savefig(io::IO,
139-
p::Plot;
145+
p::Union{SyncPlot,Plot};
140146
width::Union{Nothing,Int}=nothing,
141147
height::Union{Nothing,Int}=nothing,
142148
scale::Union{Nothing,Real}=nothing,
143149
format::String="png")
144-
145-
146150
if format == "html"
147-
return show(io, MIME("text/html"), p, include_mathjax="cdn", include_plotlyjs="cdn", full_html=true)
151+
return show(io, MIME("text/html"), _get_Plot(p), include_mathjax="cdn", include_plotlyjs="cdn", full_html=true)
148152
end
149153

150154
bytes = savefig(p, width=width, height=height, scale=scale, format=format)
151155
write(io, bytes)
152156
end
153157

158+
154159
"""
155160
savefig(
156161
p::Plot, fn::AbstractString;
@@ -167,7 +172,7 @@ image scale. `width` and `height` set the dimensions, in pixels. Defaults
167172
are taken from `p.layout`, or supplied by plotly
168173
"""
169174
function savefig(
170-
p::Plot, fn::AbstractString;
175+
p::Union{SyncPlot,Plot}, fn::AbstractString;
171176
format::Union{Nothing,String}=nothing,
172177
width::Union{Nothing,Int}=nothing,
173178
height::Union{Nothing,Int}=nothing,

test/kaleido.jl

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
function myplot(fn)
1+
function myplot(fn, func)
22
x = 0:0.1:2π
3-
plt = Plot(scatter(x=x, y=sin.(x)))
3+
plt = func(scatter(x=x, y=sin.(x)))
44
savefig(plt, fn)
55
end
66

77
@testset "kaleido" begin
8-
for ext in [PlotlyBase.ALL_FORMATS..., "html"]
9-
if ext === "eps"
10-
continue
8+
for func in [Plot, plot]
9+
for ext in [PlotlyJS.ALL_FORMATS..., "html"]
10+
if ext === "eps"
11+
continue
12+
end
13+
fn = tempname() * "." * ext
14+
@show func, fn
15+
myplot(fn, func) == fn
16+
@test isfile(fn)
17+
rm(fn)
1118
end
12-
@show fn = tempname() * "." * ext
13-
myplot(fn) == fn
14-
@test isfile(fn)
15-
rm(fn)
1619
end
1720
end

0 commit comments

Comments
 (0)