I’m trying to get Vega to plot in the Juno plotting pane. I can define the method signature correctly, in that calling a Vega.jl barplot() function will trigger the Media.render function, but if I substitute valid JavaScript/HTML into my call, I don’t get a plot. Any help would be appreciated
using Vega
using Media
#Register what a VegaVisualization is
media(Vega.VegaVisualization, Media.Graphical)
#Define how to render a VegaVisualization and where
function Media.render(pane::Atom.PlotPane, v::VegaVisualization)
#This does work as-is when uncommented and barplot() called
#rand = randstring()
#a = "<h1>Hello, World!!!$rand</h1>"
#This renders a Vega plot when in a plain text .html file (i.e. in Chrome)
a = """
<script src="https://johnmyleswhite.github.io/Vega.jl/javascripts/d3.min.js"></script>
<script src="https://johnmyleswhite.github.io/Vega.jl/javascripts/topojson.js"></script>
<script src="https://johnmyleswhite.github.io/Vega.jl/javascripts/d3.layout.cloud.js"></script>
<script src="https://johnmyleswhite.github.io/Vega.jl/javascripts/vega.min.js"></script>
<div id="test"></div>
<script type="text/javascript">
// parse a spec and create a visualization view
function parse(spec) {
vg.parse.spec(spec, function(chart) { chart({el:"#test"}).update(); });
}
parse({"name":"Vega Visualization","height":450,"padding":"auto","marks":[{"properties":{"enter":{"x":{"field":"x","scale":"x"},"y2":{"field":"y2","scale":"y"},"width":{"offset":-1,"scale":"x","band":true},"fill":{"field":"group","scale":"group"},"y":{"field":"y","scale":"y"}}},"from":{"data":"table_cgr7d"},"type":"rect"}],"axes":[{"layer":"front","properties":{"title":{"fontSize":{"value":14}}},"title":"x","grid":false,"type":"x","scale":"x"},{"layer":"front","properties":{"title":{"fontSize":{"value":14}}},"title":"y","grid":false,"type":"y","scale":"y"}],"data":[{"name":"table_cgr7d","values":[{"x2":0,"x":1,"y2":0,"group":1,"y":1},{"x2":0,"x":2,"y2":0,"group":1,"y":2},{"x2":0,"x":3,"y2":0,"group":1,"y":3},{"x2":0,"x":4,"y2":0,"group":1,"y":2},{"x2":0,"x":5,"y2":0,"group":1,"y":1}]}],"scales":[{"name":"x","range":"width","domain":{"sort":true,"data":"table_cgr7d","field":"x"},"type":"ordinal"},{"name":"y","range":"height","domain":{"data":"table_cgr7d","field":"y"},"type":"linear"},{"name":"group","range":["rgb(166,206,227)","rgb( 31,120,180)","rgb(178,223,138)","rgb( 51,160, 44)","rgb(251,154,153)","rgb(227, 26, 28)","rgb(253,191,111)","rgb(255,127, 0)","rgb(202,178,214)","rgb(106, 61,154)","rgb(255,255,153)","rgb(177, 89, 40)"],"domain":{"data":"table_cgr7d","field":"group"},"type":"ordinal"}],"width":450});
</script>
"""
Media.render(pane, Atom.div(Atom.d(), Atom.HTML(stringmime(MIME("text/html"), a))))
end
#Returns a VegaVisualization, will trigger "Hello, World" but not make a Vega plot
barplot(x = [1,2,3], y = [4,5,7])