All files / src vega-lite.ts

35.71% Statements 5/14
0% Branches 0/6
0% Functions 0/3
35.71% Lines 5/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30      1x 1x 1x   1x   1x                                        
/**
 * Convert vega-lite to vega first, then render to svg.
 */
import * as YAML from "yamljs";
import * as utility from "./utility";
import * as vega from "./vega";
 
let vl = null;
 
export async function toSVG(spec: string = "", baseURL: string = "") {
  if (!vl) {
    vl = utility.loadDependency("vega-lite/vega-lite.min.js");
  }
 
  spec = spec.trim();
  let d;
  if (spec[0] !== "{") {
    d = YAML.parse(spec);
  } else {
    // json
    d = JSON.parse(spec);
  }
 
  return utility.allowUnsafeEval(() => {
    return utility.allowUnsafeNewFunction(() => {
      return vega.toSVG(JSON.stringify(vl.compile(d).spec), baseURL);
    });
  });
}