-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b42de82
commit b202dc0
Showing
8 changed files
with
571 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
###################################################################### | ||
# | ||
# IJulia Integration | ||
# | ||
# - consist in defining a writemime(::IO, m::MIME"text/html", v::VegaLiteVis) | ||
# including scripts that load the required libraries (D3, vega, vega-lite) | ||
# - Will it work with other html backends ? probably not. | ||
# | ||
###################################################################### | ||
|
||
import Base.writemime | ||
|
||
# FIXME : Apparently, loading local js files is not allowed by the browser | ||
# => libraries are loaded externally in the `require.config` | ||
|
||
# function jslibpath(url...) | ||
# libpath = Pkg.dir("VegaLite", "assets", "bower_components", url...) | ||
# replace(libpath, "\\", "/") # for windows... | ||
# end | ||
# // d3: "$(jslibpath("d3","d3.min.js"))", | ||
# // vega: "$(jslibpath("vega", "vega.js"))", | ||
# // vegalite: "$(jslibpath("vega-lite", "vega-lite.js"))", | ||
# // vegaembed: "$(jslibpath("vega-embed", "vega-embed.js"))" | ||
|
||
|
||
function writemime(io::IO, m::MIME"text/html", v::VegaLiteVis) | ||
divid = "vl" * randstring(10) # generated id for this plot | ||
|
||
fh = """ | ||
<div> | ||
<div id="$divid"></div> | ||
<meta charset="utf-8"> | ||
<script type="text/javascript"> | ||
require.config({ | ||
paths: { | ||
d3: "https://d3js.org/d3.v3.min", | ||
vega: "https://vega.github.io/vega/vega", | ||
vegalite: "https://vega.github.io/vega-lite/vega-lite", | ||
vegaembed: "https://vega.github.io/vega-editor/vendor/vega-embed" | ||
} | ||
}); | ||
require(["d3"], function(d3){ | ||
window.d3 = d3; | ||
require(["vega"], function(vg) { | ||
window.vg = vg | ||
require(["vegalite"], function(vgl) { | ||
var embedSpec = { | ||
mode: "vega-lite", | ||
renderer: "$(SVG ? "svg" : "canvas")", | ||
actions: $SAVE_BUTTONS, | ||
spec: $(JSON.json(v.vis)) | ||
} | ||
var vgSpec = vgl.compile(embedSpec.spec).spec; | ||
vg.parse.spec(vgSpec, function(chart) { chart({el:\"#$divid\"}).update(); }); | ||
}); | ||
}); | ||
}); | ||
</script> | ||
</div> | ||
""" | ||
# FIXME : understand why vega-embed can't be loaded | ||
# SVG and SAVE_BUTTONS flags are ignored | ||
# vg.embed("#$divid", embedSpec, function(error, result) { | ||
|
||
write(io, fh) | ||
end | ||
|
||
|
||
export writemime |
Oops, something went wrong.