Skip to content

Instantly share code, notes, and snippets.

@domoritz
Last active June 13, 2020 02:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save domoritz/621e8b4334db4a0b35b8978e5d61b1e7 to your computer and use it in GitHub Desktop.
Save domoritz/621e8b4334db4a0b35b8978e5d61b1e7 to your computer and use it in GitHub Desktop.
Vega CSP inline code demo
license: mit
<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