Skip to content

Commit

Permalink
Merge pull request #1615 from pfitzseb/sp/junodisplay
Browse files Browse the repository at this point in the history
Fix display on Juno 0.7
  • Loading branch information
daschw authored Aug 4, 2018
2 parents 8d16563 + adf2af8 commit 4860bf3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 47 deletions.
2 changes: 1 addition & 1 deletion src/backends/gr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ end
function _update_min_padding!(sp::Subplot{GRBackend})
dpi = sp.plt[:thickness_scaling]
if !haskey(ENV, "GKSwstype")
if isijulia() || (isdefined(Main, :Juno) && Juno.isactive())
if isijulia()
ENV["GKSwstype"] = "svg"
end
end
Expand Down
66 changes: 20 additions & 46 deletions src/output.jl
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,12 @@ for mime in ("text/plain", "text/html", "image/png", "image/eps", "image/svg+xml
"application/eps", "application/pdf", "application/postscript",
"application/x-tex")
@eval function Base.show(io::IO, m::MIME{Symbol($mime)}, plt::Plot)
prepare_output(plt)
_show(io, m, plt)
if haskey(io, :juno_plotsize)
showjuno(io, m, plt)
else
prepare_output(plt)
_show(io, m, plt)
end
end
end

Expand Down Expand Up @@ -311,52 +315,22 @@ end
# ---------------------------------------------------------
# Atom PlotPane
# ---------------------------------------------------------
@require Juno = "e5e0dc1b-0480-54bc-9374-aad01c23163d" begin
import Hiccup, Media
function showjuno(io::IO, m, plt)
sz = plt[:size]
dpi = plt[:dpi]
thickness_scaling = plt[:thickness_scaling]

if Juno.isactive()
Media.media(Plot, Media.Plot)
jsize = get(io, :juno_plotsize, [400, 500])

function Juno.render(e::Juno.Editor, plt::Plot)
Juno.render(e, nothing)
end
scale = minimum(jsize[i] / sz[i] for i in 1:2)
plt[:size] = (s * scale for s in sz)
plt[:dpi] = Plots.DPI
plt[:thickness_scaling] *= scale

if get(ENV, "PLOTS_USE_ATOM_PLOTPANE", true) in (true, 1, "1", "true", "yes")
function Juno.render(pane::Juno.PlotPane, plt::Plot)
# temporarily overwrite size to be Atom.plotsize
sz = plt[:size]
dpi = plt[:dpi]
thickness_scaling = plt[:thickness_scaling]
jsize = Juno.plotsize()
jsize[1] == 0 && (jsize[1] = 400)
jsize[2] == 0 && (jsize[2] = 500)

scale = minimum(jsize[i] / sz[i] for i in 1:2)
plt[:size] = (s * scale for s in sz)
plt[:dpi] = Plots.DPI
plt[:thickness_scaling] *= scale
Juno.render(pane, HTML(stringmime(MIME("text/html"), plt)))
plt[:size] = sz
plt[:dpi] = dpi
plt[:thickness_scaling] = thickness_scaling
end
# special handling for PlotlyJS
function Juno.render(pane::Juno.PlotPane, plt::Plot{PlotlyJSBackend})
display(Plots.PlotsDisplay(), plt)
end
else
function Juno.render(pane::Juno.PlotPane, plt::Plot)
display(Plots.PlotsDisplay(), plt)
s = "PlotPane turned off. Unset ENV[\"PLOTS_USE_ATOM_PLOTPANE\"] and restart Julia to enable it."
Juno.render(pane, HTML(s))
end
end
prepare_output(plt)
_show(io, m, plt)

# special handling for plotly... use PlotsDisplay
function Juno.render(pane::Juno.PlotPane, plt::Plot{PlotlyBackend})
display(Plots.PlotsDisplay(), plt)
s = "PlotPane turned off. The plotly backend cannot render in the PlotPane due to javascript issues. Plotlyjs is similar to plotly and is compatible with the plot pane."
Juno.render(pane, HTML(s))
end
end
plt[:size] = sz
plt[:dpi] = dpi
plt[:thickness_scaling] = thickness_scaling
end

0 comments on commit 4860bf3

Please sign in to comment.