From 463e1bcb90ee6250d76a34b0ccadb4d0b1141a40 Mon Sep 17 00:00:00 2001 From: Thomas Breloff Date: Tue, 19 Jul 2016 16:51:05 -0400 Subject: [PATCH] require julia 0.5-; writemime to show --- REQUIRE | 2 +- src/animation.jl | 2 +- src/backends/bokeh.jl | 2 +- src/backends/gadfly.jl | 6 ++--- src/backends/glvisualize.jl | 2 +- src/backends/gr.jl | 4 ++-- src/backends/pgfplots.jl | 6 ++--- src/backends/plotly.jl | 6 ++--- src/backends/plotlyjs.jl | 6 ++--- src/backends/pyplot.jl | 2 +- src/backends/qwt.jl | 4 ++-- src/backends/template.jl | 2 +- src/backends/unicodeplots.jl | 4 ++-- src/backends/web.jl | 2 +- src/backends/winston.jl | 4 ++-- src/output.jl | 46 ++++++++++++++++++------------------ test/REQUIRE | 2 +- 17 files changed, 51 insertions(+), 51 deletions(-) diff --git a/REQUIRE b/REQUIRE index 0303ac8f..f0aaec83 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,4 +1,4 @@ -julia 0.4 +julia 0.5- RecipesBase PlotUtils diff --git a/src/animation.jl b/src/animation.jl index edd90fe8..da90fb63 100644 --- a/src/animation.jl +++ b/src/animation.jl @@ -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, "\" />") end diff --git a/src/backends/bokeh.jl b/src/backends/bokeh.jl index 286267de..5ba50bd4 100644 --- a/src/backends/bokeh.jl +++ b/src/backends/bokeh.jl @@ -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 diff --git a/src/backends/gadfly.jl b/src/backends/gadfly.jl index 1a1df404..3c2569ff 100644 --- a/src/backends/gadfly.jl +++ b/src/backends/gadfly.jl @@ -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 diff --git a/src/backends/glvisualize.jl b/src/backends/glvisualize.jl index 55749ec4..18c422b8 100644 --- a/src/backends/glvisualize.jl +++ b/src/backends/glvisualize.jl @@ -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 diff --git a/src/backends/gr.jl b/src/backends/gr.jl index b093e631..ba75d2e8 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -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 diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index 23e897c8..caac2e23 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -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 diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 3aee0a1e..272eb46d 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -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 diff --git a/src/backends/plotlyjs.jl b/src/backends/plotlyjs.jl index dd7561cd..a96587e6 100644 --- a/src/backends/plotlyjs.jl +++ b/src/backends/plotlyjs.jl @@ -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))) diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 24efb1ba..cd25e145 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -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, diff --git a/src/backends/qwt.jl b/src/backends/qwt.jl index c311f3db..253f2a37 100644 --- a/src/backends/qwt.jl +++ b/src/backends/qwt.jl @@ -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 diff --git a/src/backends/template.jl b/src/backends/template.jl index 82b009ab..71fabbf9 100644 --- a/src/backends/template.jl +++ b/src/backends/template.jl @@ -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). diff --git a/src/backends/unicodeplots.jl b/src/backends/unicodeplots.jl index ba447cf6..f8b5d84e 100644 --- a/src/backends/unicodeplots.jl +++ b/src/backends/unicodeplots.jl @@ -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 diff --git a/src/backends/web.jl b/src/backends/web.jl index 4681316b..14e100cd 100644 --- a/src/backends/web.jl +++ b/src/backends/web.jl @@ -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) diff --git a/src/backends/winston.jl b/src/backends/winston.jl index db9ca629..2e13522e 100644 --- a/src/backends/winston.jl +++ b/src/backends/winston.jl @@ -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 diff --git a/src/output.jl b/src/output.jl index e115a4bf..ab219591 100644 --- a/src/output.jl +++ b/src/output.jl @@ -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, "") + print(io, "") 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, "") +# @eval function Base.show(io::IO, ::MIME"text/html", plt::Plot) +# print(io, "") # 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 diff --git a/test/REQUIRE b/test/REQUIRE index e8355306..ff933afb 100644 --- a/test/REQUIRE +++ b/test/REQUIRE @@ -1,4 +1,4 @@ -julia 0.4 +julia 0.5- RecipesBase PlotUtils