require julia 0.5-; writemime to show

This commit is contained in:
Thomas Breloff 2016-07-19 16:51:05 -04:00
parent 22ac2df595
commit 463e1bcb90
17 changed files with 51 additions and 51 deletions

View File

@ -1,4 +1,4 @@
julia 0.4 julia 0.5-
RecipesBase RecipesBase
PlotUtils PlotUtils

View File

@ -55,7 +55,7 @@ end
# write out html to view the gif... note the rand call which is a hack so the image doesn't get cached # write out html to view the gif... note the rand call which is a hack so the image doesn't get cached
function Base.writemime(io::IO, ::MIME"text/html", agif::AnimatedGif) function Base.show(io::IO, ::MIME"text/html", agif::AnimatedGif)
write(io, "<img src=\"$(relpath(agif.filename))?$(rand())>\" />") write(io, "<img src=\"$(relpath(agif.filename))?$(rand())>\" />")
end end

View File

@ -194,7 +194,7 @@ end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
function Base.writemime(io::IO, ::MIME"image/png", plt::AbstractPlot{BokehBackend}) function Base.show(io::IO, ::MIME"image/png", plt::AbstractPlot{BokehBackend})
# TODO: write a png to io # TODO: write a png to io
warn("mime png not implemented") warn("mime png not implemented")
end end

View File

@ -677,7 +677,7 @@ setGadflyDisplaySize(plt::Plot) = setGadflyDisplaySize(plt.attr[:size]...)
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
function dowritemime{P<:Union{GadflyBackend,ImmerseBackend}}(io::IO, func, plt::AbstractPlot{P}) function doshow{P<:Union{GadflyBackend,ImmerseBackend}}(io::IO, func, plt::AbstractPlot{P})
gplt = getGadflyContext(plt) gplt = getGadflyContext(plt)
setGadflyDisplaySize(plt) setGadflyDisplaySize(plt)
Gadfly.draw(func(io, Compose.default_graphic_width, Compose.default_graphic_height), gplt) Gadfly.draw(func(io, Compose.default_graphic_width, Compose.default_graphic_height), gplt)
@ -692,9 +692,9 @@ getGadflyWriteFunc(::MIME"application/x-tex") = Gadfly.PGF
getGadflyWriteFunc(m::MIME) = error("Unsupported in Gadfly/Immerse: ", m) getGadflyWriteFunc(m::MIME) = error("Unsupported in Gadfly/Immerse: ", m)
for mime in (MIME"image/png", MIME"image/svg+xml", MIME"application/pdf", MIME"application/postscript", MIME"application/x-tex") for mime in (MIME"image/png", MIME"image/svg+xml", MIME"application/pdf", MIME"application/postscript", MIME"application/x-tex")
@eval function Base.writemime{P<:Union{GadflyBackend,ImmerseBackend}}(io::IO, ::$mime, plt::AbstractPlot{P}) @eval function Base.show{P<:Union{GadflyBackend,ImmerseBackend}}(io::IO, ::$mime, plt::AbstractPlot{P})
func = getGadflyWriteFunc($mime()) func = getGadflyWriteFunc($mime())
dowritemime(io, func, plt) doshow(io, func, plt)
end end
end end

View File

@ -311,7 +311,7 @@ function _update_plot_object(plt::Plot{GLVisualizeBackend})
gl_display(plt) gl_display(plt)
end end
# function _writemime(io::IO, ::MIME"image/png", plt::AbstractPlot{GLVisualizeBackend}) # function _show(io::IO, ::MIME"image/png", plt::AbstractPlot{GLVisualizeBackend})
# # TODO: write a png to io # # TODO: write a png to io
# end # end

View File

@ -961,7 +961,7 @@ const _gr_mimeformats = Dict(
for (mime, fmt) in _gr_mimeformats for (mime, fmt) in _gr_mimeformats
@eval function _writemime(io::IO, ::MIME{Symbol($mime)}, plt::Plot{GRBackend}) @eval function _show(io::IO, ::MIME{Symbol($mime)}, plt::Plot{GRBackend})
GR.emergencyclosegks() GR.emergencyclosegks()
wstype = haskey(ENV, "GKS_WSTYPE") ? ENV["GKS_WSTYPE"] : "0" wstype = haskey(ENV, "GKS_WSTYPE") ? ENV["GKS_WSTYPE"] : "0"
filepath = tempname() * "." * $fmt filepath = tempname() * "." * $fmt
@ -969,7 +969,7 @@ for (mime, fmt) in _gr_mimeformats
ENV["GKS_FILEPATH"] = filepath ENV["GKS_FILEPATH"] = filepath
gr_display(plt) gr_display(plt)
GR.emergencyclosegks() GR.emergencyclosegks()
write(io, readall(filepath)) write(io, readstring(filepath))
ENV["GKS_WSTYPE"] = wstype ENV["GKS_WSTYPE"] = wstype
rm(filepath) rm(filepath)
end end

View File

@ -288,12 +288,12 @@ function _make_pgf_plot!(plt::Plot)
end end
function _writemime(io::IO, mime::MIME"image/svg+xml", plt::Plot{PGFPlotsBackend}) function _show(io::IO, mime::MIME"image/svg+xml", plt::Plot{PGFPlotsBackend})
_make_pgf_plot!(plt) _make_pgf_plot!(plt)
writemime(io, mime, plt.o) show(io, mime, plt.o)
end end
function _writemime(io::IO, mime::MIME"application/pdf", plt::Plot{PGFPlotsBackend}) function _show(io::IO, mime::MIME"application/pdf", plt::Plot{PGFPlotsBackend})
_make_pgf_plot!(plt) _make_pgf_plot!(plt)
# prepare the object # prepare the object

View File

@ -567,11 +567,11 @@ end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
function _writemime(io::IO, ::MIME"image/png", plt::Plot{PlotlyBackend}) function _show(io::IO, ::MIME"image/png", plt::Plot{PlotlyBackend})
writemime_png_from_html(io, plt) show_png_from_html(io, plt)
end end
function _writemime(io::IO, ::MIME"image/svg+xml", plt::Plot{PlotlyBackend}) function _show(io::IO, ::MIME"image/svg+xml", plt::Plot{PlotlyBackend})
write(io, html_head(plt) * html_body(plt)) write(io, html_head(plt) * html_body(plt))
end end

View File

@ -63,11 +63,11 @@ end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
function _writemime(io::IO, ::MIME"image/svg+xml", plt::Plot{PlotlyJSBackend}) function _show(io::IO, ::MIME"image/svg+xml", plt::Plot{PlotlyJSBackend})
writemime(io, MIME("text/html"), plt.o) show(io, MIME("text/html"), plt.o)
end end
function _writemime(io::IO, ::MIME"image/png", plt::Plot{PlotlyJSBackend}) function _show(io::IO, ::MIME"image/png", plt::Plot{PlotlyJSBackend})
tmpfn = tempname() * ".png" tmpfn = tempname() * ".png"
PlotlyJS.savefig(plt.o, tmpfn) PlotlyJS.savefig(plt.o, tmpfn)
write(io, read(open(tmpfn))) write(io, read(open(tmpfn)))

View File

@ -1184,7 +1184,7 @@ const _pyplot_mimeformats = Dict(
for (mime, fmt) in _pyplot_mimeformats for (mime, fmt) in _pyplot_mimeformats
@eval function _writemime(io::IO, ::MIME{Symbol($mime)}, plt::Plot{PyPlotBackend}) @eval function _show(io::IO, ::MIME{Symbol($mime)}, plt::Plot{PyPlotBackend})
fig = plt.o fig = plt.o
fig.o[:canvas][:print_figure]( fig.o[:canvas][:print_figure](
io, io,

View File

@ -282,13 +282,13 @@ end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
function Base.writemime(io::IO, ::MIME"image/png", plt::Plot{QwtBackend}) function Base.show(io::IO, ::MIME"image/png", plt::Plot{QwtBackend})
Qwt.refresh(plt.o) Qwt.refresh(plt.o)
Qwt.savepng(plt.o, "/tmp/dfskjdhfkh.png") Qwt.savepng(plt.o, "/tmp/dfskjdhfkh.png")
write(io, readall("/tmp/dfskjdhfkh.png")) write(io, readall("/tmp/dfskjdhfkh.png"))
end end
# function Base.writemime(io::IO, ::MIME"image/png", subplt::Subplot{QwtBackend}) # function Base.show(io::IO, ::MIME"image/png", subplt::Subplot{QwtBackend})
# for plt in subplt.plts # for plt in subplt.plts
# Qwt.refresh(plt.o) # Qwt.refresh(plt.o)
# end # end

View File

@ -67,7 +67,7 @@ end
# "image/png" => "png", # "image/png" => "png",
# "application/postscript" => "ps", # "application/postscript" => "ps",
# "image/svg+xml" => "svg" # "image/svg+xml" => "svg"
function _writemime(io::IO, ::MIME"image/png", plt::Plot{[PkgName]Backend}) function _show(io::IO, ::MIME"image/png", plt::Plot{[PkgName]Backend})
end end
# Display/show the plot (open a GUI window, or browser page, for example). # Display/show the plot (open a GUI window, or browser page, for example).

View File

@ -113,7 +113,7 @@ end
# ------------------------------- # -------------------------------
# since this is such a hack, it's only callable using `png`... should error during normal `writemime` # since this is such a hack, it's only callable using `png`... should error during normal `show`
function png(plt::AbstractPlot{UnicodePlotsBackend}, fn::AbstractString) function png(plt::AbstractPlot{UnicodePlotsBackend}, fn::AbstractString)
fn = addExtension(fn, "png") fn = addExtension(fn, "png")
@ -150,7 +150,7 @@ function _update_plot_object(plt::Plot{UnicodePlotsBackend})
rebuildUnicodePlot!(plt) rebuildUnicodePlot!(plt)
end end
function _writemime(io::IO, ::MIME"text/plain", plt::Plot{UnicodePlotsBackend}) function _show(io::IO, ::MIME"text/plain", plt::Plot{UnicodePlotsBackend})
map(show, plt.o) map(show, plt.o)
nothing nothing
end end

View File

@ -51,7 +51,7 @@ function html_to_png(html_fn, png_fn, w, h)
run(`wkhtmltoimage -f png -q --width $w --height $h --disable-smart-width $html_fn $png_fn`) run(`wkhtmltoimage -f png -q --width $w --height $h --disable-smart-width $html_fn $png_fn`)
end end
function writemime_png_from_html(io::IO, plt::AbstractPlot) function show_png_from_html(io::IO, plt::AbstractPlot)
# write html to a temporary file # write html to a temporary file
html_fn = write_temp_html(plt) html_fn = write_temp_html(plt)

View File

@ -238,10 +238,10 @@ function addWinstonLegend(plt::Plot, wplt)
end end
end end
function Base.writemime(io::IO, ::MIME"image/png", plt::AbstractPlot{WinstonBackend}) function Base.show(io::IO, ::MIME"image/png", plt::AbstractPlot{WinstonBackend})
window, canvas, wplt = getWinstonItems(plt) window, canvas, wplt = getWinstonItems(plt)
addWinstonLegend(plt, wplt) addWinstonLegend(plt, wplt)
writemime(io, "image/png", wplt) show(io, "image/png", wplt)
end end

View File

@ -5,7 +5,7 @@ defaultOutputFormat(plt::Plot) = "png"
function png(plt::Plot, fn::AbstractString) function png(plt::Plot, fn::AbstractString)
fn = addExtension(fn, "png") fn = addExtension(fn, "png")
io = open(fn, "w") io = open(fn, "w")
writemime(io, MIME("image/png"), plt) show(io, MIME("image/png"), plt)
close(io) close(io)
end end
png(fn::AbstractString) = png(current(), fn) png(fn::AbstractString) = png(current(), fn)
@ -13,7 +13,7 @@ png(fn::AbstractString) = png(current(), fn)
function svg(plt::Plot, fn::AbstractString) function svg(plt::Plot, fn::AbstractString)
fn = addExtension(fn, "svg") fn = addExtension(fn, "svg")
io = open(fn, "w") io = open(fn, "w")
writemime(io, MIME("image/svg+xml"), plt) show(io, MIME("image/svg+xml"), plt)
close(io) close(io)
end end
svg(fn::AbstractString) = svg(current(), fn) svg(fn::AbstractString) = svg(current(), fn)
@ -22,7 +22,7 @@ svg(fn::AbstractString) = svg(current(), fn)
function pdf(plt::Plot, fn::AbstractString) function pdf(plt::Plot, fn::AbstractString)
fn = addExtension(fn, "pdf") fn = addExtension(fn, "pdf")
io = open(fn, "w") io = open(fn, "w")
writemime(io, MIME("application/pdf"), plt) show(io, MIME("application/pdf"), plt)
close(io) close(io)
end end
pdf(fn::AbstractString) = pdf(current(), fn) pdf(fn::AbstractString) = pdf(current(), fn)
@ -31,7 +31,7 @@ pdf(fn::AbstractString) = pdf(current(), fn)
function ps(plt::Plot, fn::AbstractString) function ps(plt::Plot, fn::AbstractString)
fn = addExtension(fn, "ps") fn = addExtension(fn, "ps")
io = open(fn, "w") io = open(fn, "w")
writemime(io, MIME("application/postscript"), plt) show(io, MIME("application/postscript"), plt)
close(io) close(io)
end end
ps(fn::AbstractString) = ps(current(), fn) ps(fn::AbstractString) = ps(current(), fn)
@ -40,7 +40,7 @@ ps(fn::AbstractString) = ps(current(), fn)
function tex(plt::Plot, fn::AbstractString) function tex(plt::Plot, fn::AbstractString)
fn = addExtension(fn, "tex") fn = addExtension(fn, "tex")
io = open(fn, "w") io = open(fn, "w")
writemime(io, MIME("application/x-tex"), plt) show(io, MIME("application/x-tex"), plt)
close(io) close(io)
end end
tex(fn::AbstractString) = tex(current(), fn) tex(fn::AbstractString) = tex(current(), fn)
@ -129,26 +129,26 @@ 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.writemime(io::IO, ::MIME"text/html", plt::Plot) function Base.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)
end end
if output_type == :png if output_type == :png
# info("writing png to html output") # info("writing png to html output")
print(io, "<img src=\"data:image/png;base64,", base64encode(writemime, MIME("image/png"), plt), "\" />") print(io, "<img src=\"data:image/png;base64,", base64encode(show, MIME("image/png"), plt), "\" />")
elseif output_type == :svg elseif output_type == :svg
# info("writing svg to html output") # info("writing svg to html output")
writemime(io, MIME("image/svg+xml"), plt) show(io, MIME("image/svg+xml"), plt)
elseif output_type == :txt elseif output_type == :txt
writemime(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: $output_type")
end end
end end
function _writemime(io::IO, m, plt::Plot) function _show(io::IO, m, plt::Plot)
warn("_writemime is not defined for this backend. m=", string(m)) warn("_show is not defined for this backend. m=", string(m))
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.")
@ -156,9 +156,9 @@ 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 keys(_mimeformats)
@eval function Base.writemime(io::IO, m::MIME{Symbol($mime)}, plt::Plot) @eval function Base.show(io::IO, m::MIME{Symbol($mime)}, plt::Plot)
prepare_output(plt) prepare_output(plt)
_writemime(io, m, plt) _show(io, m, plt)
end end
end end
@ -168,7 +168,7 @@ end
if is_installed("FileIO") if is_installed("FileIO")
@eval import FileIO @eval import FileIO
function _writemime(io::IO, ::MIME"image/png", plt::Plot) function _show(io::IO, ::MIME"image/png", plt::Plot)
fn = tempname() fn = tempname()
# first save a pdf file # first save a pdf file
@ -192,12 +192,12 @@ end
# function html_output_format(fmt) # function html_output_format(fmt)
# if fmt == "png" # if fmt == "png"
# @eval function Base.writemime(io::IO, ::MIME"text/html", plt::Plot) # @eval function Base.show(io::IO, ::MIME"text/html", plt::Plot)
# print(io, "<img src=\"data:image/png;base64,", base64(writemime, MIME("image/png"), plt), "\" />") # print(io, "<img src=\"data:image/png;base64,", base64(show, MIME("image/png"), plt), "\" />")
# end # end
# elseif fmt == "svg" # elseif fmt == "svg"
# @eval function Base.writemime(io::IO, ::MIME"text/html", plt::Plot) # @eval function Base.show(io::IO, ::MIME"text/html", plt::Plot)
# writemime(io, MIME("image/svg+xml"), plt) # show(io, MIME("image/svg+xml"), plt)
# end # end
# else # else
# error("only png or svg allowed. got: $fmt") # error("only png or svg allowed. got: $fmt")
@ -225,12 +225,12 @@ function setup_ijulia()
end end
function IJulia.display_dict(plt::Plot) function IJulia.display_dict(plt::Plot)
global _ijulia_output global _ijulia_output
Dict{Compat.ASCIIString, ByteString}(_ijulia_output[1] => sprint(writemime, _ijulia_output[1], plt)) Dict{Compat.ASCIIString, ByteString}(_ijulia_output[1] => sprint(show, _ijulia_output[1], plt))
end end
# default text/plain passes to html... handles Interact issues # default text/plain passes to html... handles Interact issues
function Base.writemime(io::IO, m::MIME"text/plain", plt::Plot) function Base.show(io::IO, m::MIME"text/plain", plt::Plot)
writemime(io, MIME("text/html"), plt) show(io, MIME("text/html"), plt)
end end
end end
set_ijulia_output("text/html") set_ijulia_output("text/html")
@ -264,8 +264,8 @@ function setup_atom()
end end
# # force text/plain to output to the PlotPane # # force text/plain to output to the PlotPane
# function Base.writemime(io::IO, ::MIME"text/plain", plt::Plot) # function Base.show(io::IO, ::MIME"text/plain", plt::Plot)
# # writemime(io::IO, MIME("text/html"), plt) # # show(io::IO, MIME("text/html"), plt)
# Atom.Media.render(pane) # Atom.Media.render(pane)
# end # end

View File

@ -1,4 +1,4 @@
julia 0.4 julia 0.5-
RecipesBase RecipesBase
PlotUtils PlotUtils