Built with blockbuilder.org
Last active
June 13, 2020 02:30
-
-
Save domoritz/621e8b4334db4a0b35b8978e5d61b1e7 to your computer and use it in GitHub Desktop.
Vega CSP inline code demo
This file contains hidden or 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
license: mit |
This file contains hidden or 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
<head> | |
<meta http-equiv="Content-Security-Policy" content="script-src self cdn.jsdelivr.net 'unsafe-inline'" /> | |
<script src="https://cdn.jsdelivr.net/npm/vega@5"></script> | |
<script src="https://cdn.jsdelivr.net/npm/vega-interpreter@1"></script> | |
</head> | |
<body> | |
<div id="view"></div> | |
<script type="text/javascript"> | |
var view; | |
fetch('https://vega.github.io/vega/examples/bar-chart.vg.json') | |
.then(res => res.json()) | |
.then(spec => render(spec)) | |
.catch(err => console.error(err)); | |
function render(spec) { | |
// Parse the Vega specification with AST output enabled | |
// Pass a null configuration value as the second argument | |
const runtime = vega.parse(spec, null, { ast: true }); | |
// Call Vega View constructor with an 'expr' interpreter option | |
view = new vega.View(runtime, { | |
expr: vega.expressionInterpreter, | |
renderer: 'svg', // renderer (canvas or svg) | |
container: '#view', // parent DOM container | |
hover: true // enable hover processing | |
}); | |
return view.runAsync(); | |
} | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment