Skip to content

Commit

Permalink
ENH: use PlotlyJS.savefig(::IO, ...) methods instead of former `plotl…
Browse files Browse the repository at this point in the history
…yjs_save_hack` hack
  • Loading branch information
sglyon committed Jan 8, 2019
1 parent ffea050 commit 80a97b0
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 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,17 +49,11 @@ 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 80a97b0

Please sign in to comment.