require julia 0.5-; writemime to show
This commit is contained in:
parent
22ac2df595
commit
463e1bcb90
@ -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
|
||||
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())>\" />")
|
||||
end
|
||||
|
||||
|
||||
@ -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
|
||||
warn("mime png not implemented")
|
||||
end
|
||||
|
||||
@ -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)
|
||||
setGadflyDisplaySize(plt)
|
||||
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)
|
||||
|
||||
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())
|
||||
dowritemime(io, func, plt)
|
||||
doshow(io, func, plt)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -311,7 +311,7 @@ function _update_plot_object(plt::Plot{GLVisualizeBackend})
|
||||
gl_display(plt)
|
||||
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
|
||||
# end
|
||||
|
||||
|
||||
@ -961,7 +961,7 @@ const _gr_mimeformats = Dict(
|
||||
|
||||
|
||||
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()
|
||||
wstype = haskey(ENV, "GKS_WSTYPE") ? ENV["GKS_WSTYPE"] : "0"
|
||||
filepath = tempname() * "." * $fmt
|
||||
@ -969,7 +969,7 @@ for (mime, fmt) in _gr_mimeformats
|
||||
ENV["GKS_FILEPATH"] = filepath
|
||||
gr_display(plt)
|
||||
GR.emergencyclosegks()
|
||||
write(io, readall(filepath))
|
||||
write(io, readstring(filepath))
|
||||
ENV["GKS_WSTYPE"] = wstype
|
||||
rm(filepath)
|
||||
end
|
||||
|
||||
@ -288,12 +288,12 @@ function _make_pgf_plot!(plt::Plot)
|
||||
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)
|
||||
writemime(io, mime, plt.o)
|
||||
show(io, mime, plt.o)
|
||||
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)
|
||||
|
||||
# prepare the object
|
||||
|
||||
@ -567,11 +567,11 @@ end
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
|
||||
function _writemime(io::IO, ::MIME"image/png", plt::Plot{PlotlyBackend})
|
||||
writemime_png_from_html(io, plt)
|
||||
function _show(io::IO, ::MIME"image/png", plt::Plot{PlotlyBackend})
|
||||
show_png_from_html(io, plt)
|
||||
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))
|
||||
end
|
||||
|
||||
|
||||
@ -63,11 +63,11 @@ end
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
function _writemime(io::IO, ::MIME"image/svg+xml", plt::Plot{PlotlyJSBackend})
|
||||
writemime(io, MIME("text/html"), plt.o)
|
||||
function _show(io::IO, ::MIME"image/svg+xml", plt::Plot{PlotlyJSBackend})
|
||||
show(io, MIME("text/html"), plt.o)
|
||||
end
|
||||
|
||||
function _writemime(io::IO, ::MIME"image/png", plt::Plot{PlotlyJSBackend})
|
||||
function _show(io::IO, ::MIME"image/png", plt::Plot{PlotlyJSBackend})
|
||||
tmpfn = tempname() * ".png"
|
||||
PlotlyJS.savefig(plt.o, tmpfn)
|
||||
write(io, read(open(tmpfn)))
|
||||
|
||||
@ -1184,7 +1184,7 @@ const _pyplot_mimeformats = Dict(
|
||||
|
||||
|
||||
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.o[:canvas][:print_figure](
|
||||
io,
|
||||
|
||||
@ -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.savepng(plt.o, "/tmp/dfskjdhfkh.png")
|
||||
write(io, readall("/tmp/dfskjdhfkh.png"))
|
||||
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
|
||||
# Qwt.refresh(plt.o)
|
||||
# end
|
||||
|
||||
@ -67,7 +67,7 @@ end
|
||||
# "image/png" => "png",
|
||||
# "application/postscript" => "ps",
|
||||
# "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
|
||||
|
||||
# Display/show the plot (open a GUI window, or browser page, for example).
|
||||
|
||||
@ -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)
|
||||
fn = addExtension(fn, "png")
|
||||
|
||||
@ -150,7 +150,7 @@ function _update_plot_object(plt::Plot{UnicodePlotsBackend})
|
||||
rebuildUnicodePlot!(plt)
|
||||
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)
|
||||
nothing
|
||||
end
|
||||
|
||||
@ -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`)
|
||||
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
|
||||
html_fn = write_temp_html(plt)
|
||||
|
||||
|
||||
@ -238,10 +238,10 @@ function addWinstonLegend(plt::Plot, wplt)
|
||||
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)
|
||||
addWinstonLegend(plt, wplt)
|
||||
writemime(io, "image/png", wplt)
|
||||
show(io, "image/png", wplt)
|
||||
end
|
||||
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@ defaultOutputFormat(plt::Plot) = "png"
|
||||
function png(plt::Plot, fn::AbstractString)
|
||||
fn = addExtension(fn, "png")
|
||||
io = open(fn, "w")
|
||||
writemime(io, MIME("image/png"), plt)
|
||||
show(io, MIME("image/png"), plt)
|
||||
close(io)
|
||||
end
|
||||
png(fn::AbstractString) = png(current(), fn)
|
||||
@ -13,7 +13,7 @@ png(fn::AbstractString) = png(current(), fn)
|
||||
function svg(plt::Plot, fn::AbstractString)
|
||||
fn = addExtension(fn, "svg")
|
||||
io = open(fn, "w")
|
||||
writemime(io, MIME("image/svg+xml"), plt)
|
||||
show(io, MIME("image/svg+xml"), plt)
|
||||
close(io)
|
||||
end
|
||||
svg(fn::AbstractString) = svg(current(), fn)
|
||||
@ -22,7 +22,7 @@ svg(fn::AbstractString) = svg(current(), fn)
|
||||
function pdf(plt::Plot, fn::AbstractString)
|
||||
fn = addExtension(fn, "pdf")
|
||||
io = open(fn, "w")
|
||||
writemime(io, MIME("application/pdf"), plt)
|
||||
show(io, MIME("application/pdf"), plt)
|
||||
close(io)
|
||||
end
|
||||
pdf(fn::AbstractString) = pdf(current(), fn)
|
||||
@ -31,7 +31,7 @@ pdf(fn::AbstractString) = pdf(current(), fn)
|
||||
function ps(plt::Plot, fn::AbstractString)
|
||||
fn = addExtension(fn, "ps")
|
||||
io = open(fn, "w")
|
||||
writemime(io, MIME("application/postscript"), plt)
|
||||
show(io, MIME("application/postscript"), plt)
|
||||
close(io)
|
||||
end
|
||||
ps(fn::AbstractString) = ps(current(), fn)
|
||||
@ -40,7 +40,7 @@ ps(fn::AbstractString) = ps(current(), fn)
|
||||
function tex(plt::Plot, fn::AbstractString)
|
||||
fn = addExtension(fn, "tex")
|
||||
io = open(fn, "w")
|
||||
writemime(io, MIME("application/x-tex"), plt)
|
||||
show(io, MIME("application/x-tex"), plt)
|
||||
close(io)
|
||||
end
|
||||
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
|
||||
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])
|
||||
if output_type == :auto
|
||||
output_type = get(_best_html_output_type, backend_name(plt.backend), :svg)
|
||||
end
|
||||
if output_type == :png
|
||||
# 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
|
||||
# info("writing svg to html output")
|
||||
writemime(io, MIME("image/svg+xml"), plt)
|
||||
show(io, MIME("image/svg+xml"), plt)
|
||||
elseif output_type == :txt
|
||||
writemime(io, MIME("text/plain"), plt)
|
||||
show(io, MIME("text/plain"), plt)
|
||||
else
|
||||
error("only png or svg allowed. got: $output_type")
|
||||
end
|
||||
end
|
||||
|
||||
function _writemime(io::IO, m, plt::Plot)
|
||||
warn("_writemime is not defined for this backend. m=", string(m))
|
||||
function _show(io::IO, m, plt::Plot)
|
||||
warn("_show is not defined for this backend. m=", string(m))
|
||||
end
|
||||
function _display(plt::Plot)
|
||||
warn("_display is not defined for this backend.")
|
||||
@ -156,9 +156,9 @@ end
|
||||
|
||||
# for writing to io streams... first prepare, then callback
|
||||
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)
|
||||
_writemime(io, m, plt)
|
||||
_show(io, m, plt)
|
||||
end
|
||||
end
|
||||
|
||||
@ -168,7 +168,7 @@ end
|
||||
|
||||
if is_installed("FileIO")
|
||||
@eval import FileIO
|
||||
function _writemime(io::IO, ::MIME"image/png", plt::Plot)
|
||||
function _show(io::IO, ::MIME"image/png", plt::Plot)
|
||||
fn = tempname()
|
||||
|
||||
# first save a pdf file
|
||||
@ -192,12 +192,12 @@ end
|
||||
|
||||
# function html_output_format(fmt)
|
||||
# if fmt == "png"
|
||||
# @eval function Base.writemime(io::IO, ::MIME"text/html", plt::Plot)
|
||||
# print(io, "<img src=\"data:image/png;base64,", base64(writemime, MIME("image/png"), plt), "\" />")
|
||||
# @eval function Base.show(io::IO, ::MIME"text/html", plt::Plot)
|
||||
# print(io, "<img src=\"data:image/png;base64,", base64(show, MIME("image/png"), plt), "\" />")
|
||||
# end
|
||||
# elseif fmt == "svg"
|
||||
# @eval function Base.writemime(io::IO, ::MIME"text/html", plt::Plot)
|
||||
# writemime(io, MIME("image/svg+xml"), plt)
|
||||
# @eval function Base.show(io::IO, ::MIME"text/html", plt::Plot)
|
||||
# show(io, MIME("image/svg+xml"), plt)
|
||||
# end
|
||||
# else
|
||||
# error("only png or svg allowed. got: $fmt")
|
||||
@ -225,12 +225,12 @@ function setup_ijulia()
|
||||
end
|
||||
function IJulia.display_dict(plt::Plot)
|
||||
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
|
||||
|
||||
# default text/plain passes to html... handles Interact issues
|
||||
function Base.writemime(io::IO, m::MIME"text/plain", plt::Plot)
|
||||
writemime(io, MIME("text/html"), plt)
|
||||
function Base.show(io::IO, m::MIME"text/plain", plt::Plot)
|
||||
show(io, MIME("text/html"), plt)
|
||||
end
|
||||
end
|
||||
set_ijulia_output("text/html")
|
||||
@ -264,8 +264,8 @@ function setup_atom()
|
||||
end
|
||||
|
||||
# # force text/plain to output to the PlotPane
|
||||
# function Base.writemime(io::IO, ::MIME"text/plain", plt::Plot)
|
||||
# # writemime(io::IO, MIME("text/html"), plt)
|
||||
# function Base.show(io::IO, ::MIME"text/plain", plt::Plot)
|
||||
# # show(io::IO, MIME("text/html"), plt)
|
||||
# Atom.Media.render(pane)
|
||||
# end
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
julia 0.4
|
||||
julia 0.5-
|
||||
|
||||
RecipesBase
|
||||
PlotUtils
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user