Skip to content

Commit fdf7d75

Browse files
committed
ENH: added savefig_remote function
1 parent 048d350 commit fdf7d75

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

src/Plotly.jl

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,12 @@ function srcify!(p::Plot; fileopt::Symbol=:overwrite, grid_fn=nothing, kwargs...
205205
end
206206

207207
if fileopt == :overwrite
208-
grid_info = try_me(grid_lookup, grid_fn )
209-
fid = lookup_info["fid"]
210-
if lookup_info == nothing
208+
grid_info = try_me(grid_lookup, grid_fn)
209+
fid = grid_info["fid"]
210+
if grid_info == nothing
211211
fileopt = :create
212212
else
213-
uid_map = grid_overwrite!(data_for_grid; fid=lookup_info["fid"])
213+
uid_map = grid_overwrite!(grid_info, data_for_grid)
214214
@goto add_src_attrs
215215
end
216216
end
@@ -275,4 +275,34 @@ end
275275
download_plot(url) = download(RemotePlot(url))
276276
download_plot(plot::RemotePlot) = download(plot)
277277

278+
function savefig_remote(p::Plot, fn::String, width::Int=8, height::Int=6)
279+
suf = split(fn, ".")[end]
280+
281+
# if html we don't need a plot window
282+
if suf == "html"
283+
open(fn, "w") do f
284+
show(f, MIME"text/html"(), p, js)
285+
end
286+
return p
287+
end
288+
289+
# same for json
290+
if suf == "json"
291+
open(fn, "w") do f
292+
print(f, json(p))
293+
end
294+
return p
295+
end
296+
297+
if suf in ["png", "jpeg", "svg", "pdf", "eps", "webp"]
298+
res = image_generate(p, format=suf, width=width*96, height=height*96)
299+
open(fn, "w") do f
300+
print(f, String(res))
301+
end
302+
else
303+
error("Only html, json, png, jpeg, svg, pdf, eps, and webp output supported")
304+
end
305+
fn
278306
end
307+
308+
end # module

0 commit comments

Comments
 (0)