Skip to content

Commit

Permalink
Merge pull request #1885 from sglyon/sl/plotlyjs-fix
Browse files Browse the repository at this point in the history
Sl/plotlyjs fix
  • Loading branch information
mkborregaard authored Jan 11, 2019
2 parents 8951526 + 80a97b0 commit 7750003
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions src/backends/plotlyjs.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

# https://github.com/spencerlyon2/PlotlyJS.jl
# https://github.com/sglyon/PlotlyJS.jl

# --------------------------------------------------------------------------------------

Expand Down Expand Up @@ -50,23 +49,11 @@ end

# ----------------------------------------------------------------

function _show(io::IO, ::MIME"text/html", plt::Plot{PlotlyJSBackend})
if isijulia() && !_use_remote[]
write(io, PlotlyJS.html_body(PlotlyJS.JupyterPlot(plt.o)))
else
show(io, MIME("text/html"), plt.o)
end
end

function plotlyjs_save_hack(io::IO, plt::Plot{PlotlyJSBackend}, ext::String)
tmpfn = tempname() * "." * ext
PlotlyJS.savefig(plt.o, tmpfn)
write(io, read(open(tmpfn)))
end
_show(io::IO, ::MIME"image/svg+xml", plt::Plot{PlotlyJSBackend}) = plotlyjs_save_hack(io, plt, "svg")
_show(io::IO, ::MIME"image/png", plt::Plot{PlotlyJSBackend}) = plotlyjs_save_hack(io, plt, "png")
_show(io::IO, ::MIME"application/pdf", plt::Plot{PlotlyJSBackend}) = plotlyjs_save_hack(io, plt, "pdf")
_show(io::IO, ::MIME"image/eps", plt::Plot{PlotlyJSBackend}) = plotlyjs_save_hack(io, plt, "eps")
_show(io::IO, ::MIME"text/html", plt::Plot{PlotlyJSBackend}) = show(io, MIME("text/html"), plt.o)
_show(io::IO, ::MIME"image/svg+xml", plt::Plot{PlotlyJSBackend}) = PlotlyJS.savefig(io, plt.o, format="svg")
_show(io::IO, ::MIME"image/png", plt::Plot{PlotlyJSBackend}) = PlotlyJS.savefig(io, plt.o, format="png")
_show(io::IO, ::MIME"application/pdf", plt::Plot{PlotlyJSBackend}) = PlotlyJS.savefig(io, plt.o, format="pdf")
_show(io::IO, ::MIME"image/eps", plt::Plot{PlotlyJSBackend}) = PlotlyJS.savefig(io, plt.o, format="eps")

function write_temp_html(plt::Plot{PlotlyJSBackend})
filename = string(tempname(), ".html")
Expand Down

0 comments on commit 7750003

Please sign in to comment.