Atom PlotPane finally working

This commit is contained in:
Thomas Breloff 2016-08-26 16:14:05 -04:00
parent 8a40ac8991
commit 966dede6e8

View File

@ -155,7 +155,8 @@ function Base.show(io::IO, ::MIME"text/html", plt::Plot)
end end
end end
function _show(io::IO, m, plt::Plot) function _show{B}(io::IO, m, plt::Plot{B})
# Base.show_backtrace(STDOUT, backtrace())
warn("_show 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)
@ -164,7 +165,7 @@ 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.show(io::IO, m::MIME{Symbol($mime)}, plt::Plot) @eval function Base.show{B}(io::IO, m::MIME{Symbol($mime)}, plt::Plot{B})
prepare_output(plt) prepare_output(plt)
_show(io, m, plt) _show(io, m, plt)
end end
@ -253,47 +254,50 @@ function setup_atom()
# @require Atom begin # @require Atom begin
if isatom() if isatom()
# @eval import Atom, Media # @eval import Atom, Media
@eval import Atom @eval import Atom, Media
Media.media(Plot, Media.Plot)
# default text/plain passes to html... handles Interact issues # default text/plain passes to html
function Base.show(io::IO, m::MIME"text/plain", plt::Plot) @eval function Base.show{B}(io::IO, m::MIME{Symbol("text/plain")}, plt::Plot{B})
show(io, MIME("text/html"), plt) # show(io, MIME("text/html"), plt)
print(io, "Plot{$B}()")
end end
# for inline values, display the plot (gui) and return a graph icon # for inline values, display the plot (gui) and return a graph icon
function Atom.Media.render(::Atom.Inline, plt::Plot) function Atom.Media.render(::Atom.Inline, plt::Plot)
# info("using Media.render") # # info("using Media.render")
display(plt) # display(plt)
Atom.icon("graph") # Media.render(Atom.icon("graph"))
# Media.render(Atom.PlotPane(), plt)
nothing
end end
if get(ENV, "PLOTS_USE_ATOM_PLOTPANE", false) in (true, 1, "1", "true", "yes") # if get(ENV, "PLOTS_USE_ATOM_PLOTPANE", false) in (true, 1, "1", "true", "yes")
# # connects the render function # # # connects the render function
# for T in (GadflyBackend,ImmerseBackend,PyPlotBackend,GRBackend) # # for T in (GadflyBackend,ImmerseBackend,PyPlotBackend,GRBackend)
# Atom.Media.media(Plot{T}, Atom.Media.Plot) # # Atom.Media.media(Plot{T}, Atom.Media.Plot)
# end # # end
Atom.Media.media(Plot, Atom.Media.Graphical) # Atom.Media.media(Plot, Atom.Media.Graphical)
# Atom.Media.media{T <: Union{GadflyBackend,ImmerseBackend,PyPlotBackend,GRBackend}}(Plot{T}, Atom.Media.Plot) # # Atom.Media.media{T <: Union{GadflyBackend,ImmerseBackend,PyPlotBackend,GRBackend}}(Plot{T}, Atom.Media.Plot)
# Atom.displaysize(::Plot) = (535, 379) # # Atom.displaysize(::Plot) = (535, 379)
# Atom.displaytitle(plt::Plot) = "Plots.jl (backend: $(backend(plt)))" # # Atom.displaytitle(plt::Plot) = "Plots.jl (backend: $(backend(plt)))"
# this is like "display"... sends an html div with the plot to the PlotPane # this is like "display"... sends an html div with the plot to the PlotPane
function Atom.Media.render(pane::Atom.PlotPane, plt::Plot) function Media.render(pane::Atom.PlotPane, plt::Plot)
@show "here" Media.render(pane, Atom.div(Atom.d(), Atom.HTML(stringmime(MIME("text/html"), plt))))
Atom.Media.render(pane, Atom.div(Atom.d(), Atom.HTML(stringmime(MIME("text/html"), plt))))
end end
# # force text/plain to output to the PlotPane # # # force text/plain to output to the PlotPane
# function Base.show(io::IO, ::MIME"text/plain", plt::Plot) # # function Base.show(io::IO, ::MIME"text/plain", plt::Plot)
# # show(io::IO, MIME("text/html"), plt) # # # show(io::IO, MIME("text/html"), plt)
# Atom.Media.render(pane) # # Atom.Media.render(pane)
# end # # end
# function Atom.Media.render(pane::Atom.PlotPane, plt::Plot{PlotlyBackend}) # # function Atom.Media.render(pane::Atom.PlotPane, plt::Plot{PlotlyBackend})
# html = Media.render(pane, Atom.div(Atom.d(), Atom.HTML(stringmime(MIME("text/html"), plt)))) # # html = Media.render(pane, Atom.div(Atom.d(), Atom.HTML(stringmime(MIME("text/html"), plt))))
# # end
# end # end
end end
end end
end