OpenSource For You

Vega runtime

-

Vega provides a runtime that takes Vega specificat­ion as input and displays the visualisat­ion in the browser using HTML5 Canvas. The following code snippet shows how this is done:

<html> <head> <title>Vega Runtime Sample</title> <!-- Add reference to D3, Vega JS --> <script src="http://trifacta.github.io/vega/lib/d3.v3.min. js"></script> <script src="http://trifacta.github.io/vega/lib/d3.geo. projection.min.js"></script> <script src="http://trifacta.github.io/vega/vega.js"></ script> </head> <body> <div id="vis"></div> </body> <script type="text/javascript"> // Parse a vega specificat­ion @URL and create a visualizat­ion view and add // chart component to DIV @vis // vg.parse.spec is the entry point for the runtime to render the chart. function parse(spec) { vg.parse.spec(spec, function(chart) { chart({el:"#vis"}). update(); }); } parse("/vegaSpecif­icationURL.json"); </script> </html>

The callback function takes the name of the DOM element and the set of optional arguments, such as the data to visualise on-demand and some basic properties related to the viewport.

Newspapers in English

Newspapers from India