@@ -5,8 +5,7 @@ module Plotly
55using URIParser
66using 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
1110const _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 ()
275297download_plot (url) = download (RemotePlot (url))
276298download_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
306328end
307329
330+ function savefig_remote (p:: PlotlyJS.SyncPlot , args... ;kwargs... )
331+ savefig_remote (p. plot, args... ; kwargs... )
332+ end
333+
308334end # module
0 commit comments