How to use the vega.headless function in vega

To help you get started, we’ve selected a few vega examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vega / vega / benchmarks / index.js View on Github external
function _vg1(spec, name, viewFactory, restore) {
  var deferred = Q.defer(),
      start, messages;

  viewFactory = viewFactory || vg1.headless.View.Factory;

  try {
    messages = JSON.parse(fs.readFileSync('results.raw/'+name+'.json').toString());
  } catch(e) {
    messages = [];
  }   

  start = Date.now();

  vg1.parse.spec(spec, function(chart) {
    var view = chart();
    view.render = function() {};
    view.update();
    messages.push({type: 'vg1', time: Date.now() - start});
    console.log(messages[messages.length-1]);
github uwdata / vegaserver / server.js View on Github external
app.post('/', function (req, res, next) {
  var spec = JSON.parse(req.body),
  header = req.params.header === "true",
  format = req.params.header || "svg";

  if (format === "svg") {
    console.log("Rendering an SVG");
    res.set('Content-Type', 'image/svg+xml');

    vg.headless.render(
      {spec: spec, renderer:"svg"},
      function(err, data) {
        if (err) return next(err);
        res.send((header ? svgHeader : "") + data.svg);
      }
    );

  } else if (format === "png") {
    console.log("Rendering a PNG");
    res.set('Content-Type', 'image/png');

    vg.headless.render(
      {spec: spec, renderer: "canvas"},
      function(err, data) {
        if (err) return next(err);
        var stream = data.canvas.createPNGStream();