Skip to content

Commit 2d12d4b

Browse files
committed
WIP: make sure to handle folder names in path when posting a plot
1 parent fdf7d75 commit 2d12d4b

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

src/Plotly.jl

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ module Plotly
55
using URIParser
66
using Reexport
77
@reexport using PlotlyJS
8-
export post
9-
export set_credentials_file, RemotePlot, download_plot
8+
export set_credentials_file, RemotePlot, download_plot, savefig_remote, post
109

1110
const _SRC_ATTRS = let
1211
_src_attr_path = joinpath(dirname(PlotlyJS._js_path), "src_attrs.csv")
@@ -78,7 +77,20 @@ function post(p::Plot; fileopt=:overwrite, filename=nothing, kwargs...)
7877
end
7978
end
8079
if fileopt == :create
81-
res = plot_create(clean_p; filename=filename, kwargs...)
80+
if filename == nothing
81+
res = plot_create(clean_p; kwargs...)
82+
else
83+
parent_path = dirname(filename)
84+
if !isempty(parent_path)
85+
res = plot_create(
86+
clean_p; parent_path=parent_path,
87+
filename=basename(filename), kwargs...
88+
)
89+
else
90+
res = plot_create(clean_p; filename=filename, kwargs...)
91+
end
92+
end
93+
8294
return RemotePlot(res["file"]["web_url"])
8395
else
8496
error("fileopt must be one of `overwrite` and `create`")
@@ -206,10 +218,10 @@ function srcify!(p::Plot; fileopt::Symbol=:overwrite, grid_fn=nothing, kwargs...
206218

207219
if fileopt == :overwrite
208220
grid_info = try_me(grid_lookup, grid_fn)
209-
fid = grid_info["fid"]
210221
if grid_info == nothing
211222
fileopt = :create
212223
else
224+
fid = grid_info["fid"]
213225
uid_map = grid_overwrite!(grid_info, data_for_grid)
214226
@goto add_src_attrs
215227
end
@@ -220,7 +232,17 @@ function srcify!(p::Plot; fileopt::Symbol=:overwrite, grid_fn=nothing, kwargs...
220232
for (i, (k, v)) in enumerate(data_for_grid)
221233
v["order"] = i-1
222234
end
223-
res = grid_create(Dict("cols" => data_for_grid); filename=grid_fn, kwargs...)
235+
parent_path = dirname(grid_fn)
236+
if !isempty(parent_path)
237+
root_name = basename(grid_fn)
238+
res = grid_create(
239+
Dict("cols" => data_for_grid);
240+
parent_path=parent_path, filename=root_name, kwargs...
241+
)
242+
else
243+
res = grid_create(Dict("cols" => data_for_grid); filename=grid_fn, kwargs...)
244+
end
245+
224246
fid = res["file"]["fid"]
225247

226248
uid_map = Dict()
@@ -275,7 +297,7 @@ end
275297
download_plot(url) = download(RemotePlot(url))
276298
download_plot(plot::RemotePlot) = download(plot)
277299

278-
function savefig_remote(p::Plot, fn::String, width::Int=8, height::Int=6)
300+
function savefig_remote(p::Plot, fn::String; width::Int=8, height::Int=6)
279301
suf = split(fn, ".")[end]
280302

281303
# if html we don't need a plot window
@@ -305,4 +327,8 @@ function savefig_remote(p::Plot, fn::String, width::Int=8, height::Int=6)
305327
fn
306328
end
307329

330+
function savefig_remote(p::PlotlyJS.SyncPlot, args...;kwargs...)
331+
savefig_remote(p.plot, args...; kwargs...)
332+
end
333+
308334
end # module

0 commit comments

Comments
 (0)