create syncplot at show/display
This commit is contained in:
parent
f11b976574
commit
0e79070ad8
@ -2,77 +2,111 @@
|
|||||||
|
|
||||||
# --------------------------------------------------------------------------------------
|
# --------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
function plotlyjs_syncplot(plt::Plot{PlotlyJSBackend})
|
||||||
function _create_backend_figure(plt::Plot{PlotlyJSBackend})
|
plt[:overwrite_figure] && closeall()
|
||||||
if !isplotnull() && plt[:overwrite_figure] && isa(current().o, PlotlyJS.SyncPlot)
|
plt.o = PlotlyJS.plot()
|
||||||
PlotlyJS.SyncPlot(PlotlyJS.Plot(), options = current().o.options)
|
traces = PlotlyJS.GenericTrace[]
|
||||||
else
|
for series_dict in plotly_series(plt)
|
||||||
PlotlyJS.plot()
|
plotly_type = pop!(series_dict, :type)
|
||||||
|
push!(traces, PlotlyJS.GenericTrace(plotly_type; series_dict...))
|
||||||
end
|
end
|
||||||
end
|
PlotlyJS.addtraces!(plt.o, traces...)
|
||||||
|
layout = plotly_layout(plt)
|
||||||
|
|
||||||
function _series_added(plt::Plot{PlotlyJSBackend}, series::Series)
|
|
||||||
syncplot = plt.o
|
|
||||||
pdicts = plotly_series(plt, series)
|
|
||||||
for pdict in pdicts
|
|
||||||
typ = pop!(pdict, :type)
|
|
||||||
gt = PlotlyJS.GenericTrace(typ; pdict...)
|
|
||||||
PlotlyJS.addtraces!(syncplot, gt)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function _series_updated(plt::Plot{PlotlyJSBackend}, series::Series)
|
|
||||||
xsym, ysym = (ispolar(series) ? (:t,:r) : (:x,:y))
|
|
||||||
kw = KW(xsym => (series.plotattributes[:x],), ysym => (series.plotattributes[:y],))
|
|
||||||
z = series[:z]
|
|
||||||
if z != nothing
|
|
||||||
kw[:z] = (isa(z,Surface) ? transpose_z(series, series[:z].surf, false) : z,)
|
|
||||||
end
|
|
||||||
PlotlyJS.restyle!(
|
|
||||||
plt.o,
|
|
||||||
findfirst(isequal(series), plt.series_list),
|
|
||||||
kw
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------
|
|
||||||
|
|
||||||
function _update_plot_object(plt::Plot{PlotlyJSBackend})
|
|
||||||
pdict = plotly_layout(plt)
|
|
||||||
syncplot = plt.o
|
|
||||||
w, h = plt[:size]
|
w, h = plt[:size]
|
||||||
PlotlyJS.relayout!(syncplot, pdict, width = w, height = h)
|
PlotlyJS.relayout!(plt.o, layout, width = w, height = h)
|
||||||
|
return plt.o
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# function _create_backend_figure(plt::Plot{PlotlyJSBackend})
|
||||||
|
# if !isplotnull() && plt[:overwrite_figure] && isa(current().o, PlotlyJS.SyncPlot)
|
||||||
|
# PlotlyJS.SyncPlot(PlotlyJS.Plot(), options = current().o.options)
|
||||||
|
# else
|
||||||
|
# PlotlyJS.plot()
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# function _series_added(plt::Plot{PlotlyJSBackend}, series::Series)
|
||||||
|
# syncplot = plt.o
|
||||||
|
# pdicts = plotly_series(plt, series)
|
||||||
|
# for pdict in pdicts
|
||||||
|
# typ = pop!(pdict, :type)
|
||||||
|
# gt = PlotlyJS.GenericTrace(typ; pdict...)
|
||||||
|
# PlotlyJS.addtraces!(syncplot, gt)
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# function _series_updated(plt::Plot{PlotlyJSBackend}, series::Series)
|
||||||
|
# xsym, ysym = (ispolar(series) ? (:t,:r) : (:x,:y))
|
||||||
|
# kw = KW(xsym => (series.plotattributes[:x],), ysym => (series.plotattributes[:y],))
|
||||||
|
# z = series[:z]
|
||||||
|
# if z != nothing
|
||||||
|
# kw[:z] = (isa(z,Surface) ? transpose_z(series, series[:z].surf, false) : z,)
|
||||||
|
# end
|
||||||
|
# PlotlyJS.restyle!(
|
||||||
|
# plt.o,
|
||||||
|
# findfirst(isequal(series), plt.series_list),
|
||||||
|
# kw
|
||||||
|
# )
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# # ----------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# function _update_plot_object(plt::Plot{PlotlyJSBackend})
|
||||||
|
# pdict = plotly_layout(plt)
|
||||||
|
# syncplot = plt.o
|
||||||
|
# w,h = plt[:size]
|
||||||
|
# PlotlyJS.relayout!(syncplot, pdict, width = w, height = h)
|
||||||
|
# end
|
||||||
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------
|
# ----------------------------------------------------------------
|
||||||
|
|
||||||
_show(io::IO, ::MIME"text/html", plt::Plot{PlotlyJSBackend}) = show(io, MIME("text/html"), plt.o)
|
const _plotlyjs_mimeformats = Dict(
|
||||||
_show(io::IO, ::MIME"image/svg+xml", plt::Plot{PlotlyJSBackend}) = PlotlyJS.savefig(io, plt.o, format="svg")
|
"application/pdf" => "pdf",
|
||||||
_show(io::IO, ::MIME"image/png", plt::Plot{PlotlyJSBackend}) = PlotlyJS.savefig(io, plt.o, format="png")
|
"image/png" => "png",
|
||||||
_show(io::IO, ::MIME"application/pdf", plt::Plot{PlotlyJSBackend}) = PlotlyJS.savefig(io, plt.o, format="pdf")
|
"image/svg+xml" => "svg",
|
||||||
_show(io::IO, ::MIME"image/eps", plt::Plot{PlotlyJSBackend}) = PlotlyJS.savefig(io, plt.o, format="eps")
|
"image/eps" => "eps",
|
||||||
|
)
|
||||||
|
|
||||||
function _show(io::IO, m::MIME"application/vnd.plotly.v1+json", plt::Plot{PlotlyJSBackend})
|
for (mime, fmt) in _plotlyjs_mimeformats
|
||||||
show(io, m, plt.o)
|
@eval _show(io::IO, ::MIME{Symbol($mime)}, plt::Plot{PlotlyJSBackend}) = PlotlyJS.savefig(io, plotlyjs_syncplot(plt), format = $fmt)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
const _plotlyjs_showformats = ["text/html", "application/vnd.plotly.v1+json"]
|
||||||
|
|
||||||
function write_temp_html(plt::Plot{PlotlyJSBackend})
|
for mime in ["text/html", "application/vnd.plotly.v1+json"]
|
||||||
filename = string(tempname(), ".html")
|
@eval _show(io::IO, mime::MIME{Symbol($mime)}, plt::Plot{PlotlyJSBackend}) = show(io, mime, plotlyjs_syncplot(plt))
|
||||||
savefig(plt, filename)
|
|
||||||
filename
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function _display(plt::Plot{PlotlyJSBackend})
|
# _show(io::IO, ::MIME"text/html", plt::Plot{PlotlyJSBackend}) = show(io, ::MIME"text/html", plt.o)
|
||||||
if get(ENV, "PLOTS_USE_ATOM_PLOTPANE", true) in (true, 1, "1", "true", "yes")
|
# _show(io::IO, ::MIME"image/svg+xml", plt::Plot{PlotlyJSBackend}) = PlotlyJS.savefig(io, plt.o, format="svg")
|
||||||
display(plt.o)
|
# _show(io::IO, ::MIME"image/png", plt::Plot{PlotlyJSBackend}) = PlotlyJS.savefig(io, plt.o, format="png")
|
||||||
else
|
# _show(io::IO, ::MIME"application/pdf", plt::Plot{PlotlyJSBackend}) = PlotlyJS.savefig(io, plt.o, format="pdf")
|
||||||
standalone_html_window(plt)
|
# _show(io::IO, ::MIME"image/eps", plt::Plot{PlotlyJSBackend}) = PlotlyJS.savefig(io, plt.o, format="eps")
|
||||||
end
|
|
||||||
end
|
# function _show(io::IO, m::MIME"application/vnd.plotly.v1+json", plt::Plot{PlotlyJSBackend})
|
||||||
|
# show(io, m, plt.o)
|
||||||
|
# end
|
||||||
|
|
||||||
|
|
||||||
|
# function write_temp_html(plt::Plot{PlotlyJSBackend})
|
||||||
|
# filename = string(tempname(), ".html")
|
||||||
|
# savefig(plt, filename)
|
||||||
|
# filename
|
||||||
|
# end
|
||||||
|
|
||||||
|
_display(plt::Plot{PlotlyJSBackend}) = display(plotlyjs_syncplot(plt))
|
||||||
|
|
||||||
|
# function _display(plt::Plot{PlotlyJSBackend})
|
||||||
|
# if get(ENV, "PLOTS_USE_ATOM_PLOTPANE", true) in (true, 1, "1", "true", "yes")
|
||||||
|
# display(plt.o)
|
||||||
|
# else
|
||||||
|
# standalone_html_window(plt)
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
|
||||||
@require WebIO = "0f1e0344-ec1d-5b48-a673-e5cf874b6c29" begin
|
@require WebIO = "0f1e0344-ec1d-5b48-a673-e5cf874b6c29" begin
|
||||||
function WebIO.render(plt::Plot{PlotlyJSBackend})
|
function WebIO.render(plt::Plot{PlotlyJSBackend})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user