Skip to content

Instantly share code, notes, and snippets.

@domoritz
Last active June 13, 2020 02:38
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/7d3b8ed06c079608491a6d4a185f7fd1 to your computer and use it in GitHub Desktop.
Save domoritz/7d3b8ed06c079608491a6d4a185f7fd1 to your computer and use it in GitHub Desktop.
Vega CSP test
license: mit
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="Content-Security-Policy" content="script-src self cdn.jsdelivr.net bl.ocks.org blockbuilder.org" />
<title>Vega CSP Test</title>
<script src="https://cdn.jsdelivr.net/npm/vega@5"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-interpreter"></script>
</head>
<body>
<div id="view"></div>
<script src="main.js"></script>
</body>
</html>
let 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();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment