Skip to content

Commit

Permalink
move to PhantomJS
Browse files Browse the repository at this point in the history
  • Loading branch information
fredo-dedup committed Mar 29, 2017
1 parent 3d6b24f commit 72240af
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions src/atom_integration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,27 @@
show(plt)
end

# if package Wkhtmltox is present redirect rendering to Juno's plot pane
# if package PhantomJS is present redirect rendering to Juno's plot pane
try
import Wkhtmltox
import PhantomJS

Media.media(VegaLiteVis, Media.Plot)

Media.render(e::Atom.Editor, plt::VegaLiteVis) =
Media.render(e, nothing)

function Media.render(pane::Atom.PlotPane, plt::VegaLiteVis)
# create a temporary file
tmppath = string(tempname(), ".vegalite.html")
open(tmppath, "w") do io
writehtml(io, plt)
end
# write html to an IOBuffer()
pio = IOBuffer()
VegaLite.writehtml(pio, plt)
seekstart(pio)

png_fn = string(tempname(), ".png")
# convert to png
png = PhantomJS.renderhtml(pio, clipToSelector=".marks", format="png")

Wkhtmltox.img_init(1)
is = Wkhtmltox.ImgSettings("in" => tmppath,
"out" => png_fn,
"fmt" => "png") # png format output
conv = Wkhtmltox.ImgConverter(is)
Wkhtmltox.run(conv)

conv = nothing
Wkhtmltox.img_deinit()

Media.render(pane, Atom.div(Atom.img(src=png_fn)))
Media.render(pane,
Atom.div(
Atom.img(src = "data:image/png;base64," * base64encode(png))))
end
end

Expand Down

0 comments on commit 72240af

Please sign in to comment.