Merge pull request #1536 from fredrikekre/fe/_show
restructure some show methods
This commit is contained in:
commit
f6bc7721a8
@ -922,17 +922,7 @@ end
|
|||||||
# ----------------------------------------------------------------
|
# ----------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
function _show(io::IO, ::MIME"image/png", plt::Plot{PlotlyBackend})
|
function _show(io::IO, ::MIME"text/html", plt::Plot{PlotlyBackend})
|
||||||
# show_png_from_html(io, plt)
|
|
||||||
error("png output from the plotly backend is not supported. Please use plotlyjs instead.")
|
|
||||||
end
|
|
||||||
|
|
||||||
function _show(io::IO, ::MIME"image/svg+xml", plt::Plot{PlotlyBackend})
|
|
||||||
error("svg output from the plotly backend is not supported. Please use plotlyjs instead.")
|
|
||||||
end
|
|
||||||
|
|
||||||
function Base.show(io::IO, ::MIME"text/html", plt::Plot{PlotlyBackend})
|
|
||||||
prepare_output(plt)
|
|
||||||
write(io, html_head(plt) * html_body(plt))
|
write(io, html_head(plt) * html_body(plt))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
@require Revise begin
|
@require Revise begin
|
||||||
Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "plotlyjs.jl"))
|
Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "plotlyjs.jl"))
|
||||||
end
|
end
|
||||||
|
|
||||||
# https://github.com/spencerlyon2/PlotlyJS.jl
|
# https://github.com/spencerlyon2/PlotlyJS.jl
|
||||||
@ -88,8 +88,7 @@ end
|
|||||||
|
|
||||||
# ----------------------------------------------------------------
|
# ----------------------------------------------------------------
|
||||||
|
|
||||||
function Base.show(io::IO, ::MIME"text/html", plt::Plot{PlotlyJSBackend})
|
function _show(io::IO, ::MIME"text/html", plt::Plot{PlotlyJSBackend})
|
||||||
prepare_output(plt)
|
|
||||||
if isijulia() && !_use_remote[]
|
if isijulia() && !_use_remote[]
|
||||||
write(io, PlotlyJS.html_body(PlotlyJS.JupyterPlot(plt.o)))
|
write(io, PlotlyJS.html_body(PlotlyJS.JupyterPlot(plt.o)))
|
||||||
else
|
else
|
||||||
|
|||||||
@ -212,7 +212,7 @@ end
|
|||||||
|
|
||||||
function _show(io::IO, ::MIME"text/plain", plt::Plot{UnicodePlotsBackend})
|
function _show(io::IO, ::MIME"text/plain", plt::Plot{UnicodePlotsBackend})
|
||||||
unicodeplots_rebuild(plt)
|
unicodeplots_rebuild(plt)
|
||||||
map(show, plt.o)
|
foreach(x -> show(io, x), plt.o)
|
||||||
nothing
|
nothing
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -157,17 +157,6 @@ end
|
|||||||
|
|
||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
|
|
||||||
const _mimeformats = Dict(
|
|
||||||
"application/eps" => "eps",
|
|
||||||
"image/eps" => "eps",
|
|
||||||
"application/pdf" => "pdf",
|
|
||||||
"image/png" => "png",
|
|
||||||
"application/postscript" => "ps",
|
|
||||||
"image/svg+xml" => "svg",
|
|
||||||
"text/plain" => "txt",
|
|
||||||
"application/x-tex" => "tex",
|
|
||||||
)
|
|
||||||
|
|
||||||
const _best_html_output_type = KW(
|
const _best_html_output_type = KW(
|
||||||
:pyplot => :png,
|
:pyplot => :png,
|
||||||
:unicodeplots => :txt,
|
:unicodeplots => :txt,
|
||||||
@ -177,7 +166,7 @@ const _best_html_output_type = KW(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# a backup for html... passes to svg or png depending on the html_output_format arg
|
# a backup for html... passes to svg or png depending on the html_output_format arg
|
||||||
function Base.show(io::IO, ::MIME"text/html", plt::Plot)
|
function _show(io::IO, ::MIME"text/html", plt::Plot)
|
||||||
output_type = Symbol(plt.attr[:html_output_format])
|
output_type = Symbol(plt.attr[:html_output_format])
|
||||||
if output_type == :auto
|
if output_type == :auto
|
||||||
output_type = get(_best_html_output_type, backend_name(plt.backend), :svg)
|
output_type = get(_best_html_output_type, backend_name(plt.backend), :svg)
|
||||||
@ -191,21 +180,24 @@ function Base.show(io::IO, ::MIME"text/html", plt::Plot)
|
|||||||
elseif output_type == :txt
|
elseif output_type == :txt
|
||||||
show(io, MIME("text/plain"), plt)
|
show(io, MIME("text/plain"), plt)
|
||||||
else
|
else
|
||||||
error("only png or svg allowed. got: $output_type")
|
error("only png or svg allowed. got: $(repr(output_type))")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function _show(io::IO, m, plt::Plot{B}) where B
|
# delegate mimewritable (showable on julia 0.7) to _show instead
|
||||||
# Base.show_backtrace(STDOUT, backtrace())
|
function Base.mimewritable(m::M, plt::P) where {M<:MIME, P<:Plot}
|
||||||
warn("_show is not defined for this backend. m=", string(m))
|
return method_exists(_show, Tuple{IO, M, P})
|
||||||
end
|
end
|
||||||
|
|
||||||
function _display(plt::Plot)
|
function _display(plt::Plot)
|
||||||
warn("_display is not defined for this backend.")
|
warn("_display is not defined for this backend.")
|
||||||
end
|
end
|
||||||
|
|
||||||
# for writing to io streams... first prepare, then callback
|
# for writing to io streams... first prepare, then callback
|
||||||
for mime in keys(_mimeformats)
|
for mime in ("text/plain", "text/html", "image/png", "image/eps", "image/svg+xml",
|
||||||
@eval function Base.show(io::IO, m::MIME{Symbol($mime)}, plt::Plot{B}) where B
|
"application/eps", "application/pdf", "application/postscript",
|
||||||
|
"application/x-tex")
|
||||||
|
@eval function Base.show(io::IO, m::MIME{Symbol($mime)}, plt::Plot)
|
||||||
prepare_output(plt)
|
prepare_output(plt)
|
||||||
_show(io, m, plt)
|
_show(io, m, plt)
|
||||||
end
|
end
|
||||||
@ -292,7 +284,10 @@ end
|
|||||||
output_type = get(_best_html_output_type, backend_name(plt.backend), :svg)
|
output_type = get(_best_html_output_type, backend_name(plt.backend), :svg)
|
||||||
end
|
end
|
||||||
out = Dict()
|
out = Dict()
|
||||||
if output_type == :png
|
if output_type == :txt
|
||||||
|
mime = "text/plain"
|
||||||
|
out[mime] = sprint(show, MIME(mime), plt)
|
||||||
|
elseif output_type == :png
|
||||||
mime = "image/png"
|
mime = "image/png"
|
||||||
out[mime] = base64encode(show, MIME(mime), plt)
|
out[mime] = base64encode(show, MIME(mime), plt)
|
||||||
elseif output_type == :svg
|
elseif output_type == :svg
|
||||||
@ -308,11 +303,6 @@ end
|
|||||||
out
|
out
|
||||||
end
|
end
|
||||||
|
|
||||||
# default text/plain passes to html... handles Interact issues
|
|
||||||
function Base.show(io::IO, m::MIME"text/plain", plt::Plot)
|
|
||||||
show(io, MIME("text/html"), plt)
|
|
||||||
end
|
|
||||||
|
|
||||||
ENV["MPLBACKEND"] = "Agg"
|
ENV["MPLBACKEND"] = "Agg"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user