How to use the vega-lite.compile function in vega-lite

To help you get started, we’ve selected a few vega-lite 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 / lyra / src / js / actions / bindChannel / index.ts View on Github external
// backing dataset should actually be (source, aggregate, etc.).
  (spec.data as InlineData).values = dsUtils.output(dsId);

  // Supply custom cell width/heights to be able to differentiate hardcoded
  // scale ranges generated by Vega-Lite.
  spec.config.view = {
    width: CELLW,
    height: CELLH
  };

  // Force marks to be filled, if we're binding to the fill color property.
  spec.config.mark = {filled: property === 'fill'};

  return {
    input: spec,
    output: vlCompile(spec).spec
  } as CompiledBinding;
}
github vega / voyager / src / components / vega-lite / index.tsx View on Github external
//       {"a": "F", "b": 53},
    //       {"a": "G", "b": 19},
    //       {"a": "H", "b": 87},
    //       {"a": "I", "b": 52}
    //     ]
    //   },
    //   "mark": "bar",
    //   "encoding": {
    //     "x": {"field": "a", "type": "quantitative"},
    //     "y": {"field": "b", "type": "quantitative"}
    //   }
    // };
    const {logger} = this.props;
    const vlSpec = this.props.spec;
    try {
      const spec = vl.compile(vlSpec, logger).spec;
      const runtime = vega.parse(spec, vlSpec.config);
      this.view = new vega.View(runtime)
        .logLevel(vega.Warn)
        .initialize(this.refs[CHART_REF] as any)
        .renderer(this.props.renderer || 'canvas')
        .hover();
      vegaTooltip.vega(this.view);
      this.bindData();
    } catch (err) {
      logger.error(err);
    }
  }
github vega / vega-desktop / viewer / components / VegaRenderer.jsx View on Github external
update() {
    const {spec, format, filePath, renderer} = this.props;
    if (spec) {
      let vegaSpec;

      if (format === FORMAT.VEGA_LITE) {
        try {
          vegaSpec = vl.compile(spec).spec;
        } catch (error) {
          this.showError(`Invalid vega-lite spec: ${error.message}`);
          return;
        }
      } else if (format === FORMAT.UNKNOWN) {
        try {
          vegaSpec = vl.compile(spec).spec;
        } catch (error) {
          vegaSpec = spec;
        }
      } else {
        vegaSpec = spec;
      }

      // Clear existing view
      if (this.view) {
github vega / vega-desktop / viewer / components / VegaRenderer.jsx View on Github external
update() {
    const {spec, format, filePath, renderer} = this.props;
    if (spec) {
      let vegaSpec;

      if (format === FORMAT.VEGA_LITE) {
        try {
          vegaSpec = vl.compile(spec).spec;
        } catch (error) {
          this.showError(`Invalid vega-lite spec: ${error.message}`);
          return;
        }
      } else if (format === FORMAT.UNKNOWN) {
        try {
          vegaSpec = vl.compile(spec).spec;
        } catch (error) {
          vegaSpec = spec;
        }
      } else {
        vegaSpec = spec;
      }

      // Clear existing view
      if (this.view) {
        this.view.finalize();
      }

      this.container.innerHTML = '';

      try {
        const runtime = vg.parse(vegaSpec);
github streamlit / streamlit / frontend / src / components / elements / VegaLiteChart / VegaLiteChart.tsx View on Github external
if (spec.datasets) {
      throw new Error('Datasets should not be passed as part of the spec')
    }

    const datasets = getDataSets(el)

    if (datasets) {
      if (!spec.data) {
        throw new Error(
          'Must specify "data" field when using "dataset"')
      }
      spec.datasets = datasets
    }

    const vgSpec = vl.compile(spec).spec

    // Heuristic to determine the default dataset name.
    const datasetNames = datasets ? Object.keys(datasets) : []
    if (datasetNames.length === 1) {
      this.defaultDataName = datasetNames[0]
    } else if (datasetNames.length === 0 && vgSpec.data) {
      this.defaultDataName = vgSpec.data[0].name
    }

    const runtime = vega.parse(vgSpec)
    const view = new vega.View(runtime, {
      logLevel:  vega.Warn,
      render: 'canvas',
      container: this.element,
    })
github apple / turicreate / src / visualization / client / Turi Create Visualization / src / user_interface / src / elements / Plot / Chart / index.js View on Github external
addSpec(spec){
        this.bubbleOpts = {
            showAllFields: true,
        };

        if (typeof(spec) === 'string') {
            spec = JSON.parse(spec);
        }
        // If size is not specified, default to our default window size, 720x550
        if (!spec.width && !spec.height) {
            spec.width = 720;
            spec.height = 550;
        }
        if (spec['$schema'].startsWith('https://vega.github.io/schema/vega-lite/')) {
            spec = vl.compile(spec).spec;
        }

        this.vega_json = spec;
        this.vega_json.autosize = {"type": "fit", "resize": true, "contains": "padding"};

        if(this.vega_json["metadata"] != null){
            if(this.vega_json["metadata"]["bubbleOpts"] != null){
                this.bubbleOpts = this.vega_json["metadata"]["bubbleOpts"];
            }
        }

        this.vegaLoading = true;
        this.vegaView = new vega.View(vega.parse(this.vega_json), {'renderer': 'svg'})
                                .initialize(this.vega_container)
                                .hover()
                                .run();
github microsoft / SandDance / packages / vega-lite-unit / src / index.ts View on Github external
filenames.forEach(src => {
    const conversion: Conversion = { src, outputs: [] };
    conversions.push(conversion);
    const json = fs.readFileSync(path.join(base, 'input', src), 'utf8');
    let vegaLiteSpec: TopLevelUnitSpec;
    try {
        vegaLiteSpec = JSON.parse(json);
    }
    catch (e) {
        process.stderr.write(e);
    }
    if (vegaLiteSpec) {
        const output = VegaLite.compile(vegaLiteSpec);
        const spec = output.spec as Vega.Spec;
        switch (vegaLiteSpec.mark) {
            case 'bar': {
                const unitStyles = aggregateToUnitStyles(vegaLiteSpec.encoding);
                unitStyles.forEach(unitStyle => {
                    const outputSpec = JSON.parse(JSON.stringify(spec));
                    unitizeBar(vegaLiteSpec, outputSpec, unitStyle);
                    const dest = `${unitStyle}-${src.replace('.vl.', '.vg.')}`;
                    conversion.outputs.push(dest);
                    out(dest, outputSpec);
                });
            }
        }
    }
});
github Kitware / candela / packages / vega / src / mixin / VegaView.js View on Github external
_resizeContent (spec, size) {
    if (spec.spec) {
      spec.spec.width = size.width;
      spec.spec.height = size.height;
    } else {
      spec.width = size.width;
      spec.height = size.height;
    }
    let vegaSpec = spec;
    if (spec.$schema && schemaParser(spec.$schema).library === 'vega-lite') {
      vegaSpec = vegaLiteCompile(spec).spec;
    }
    let handler = new Handler();
    this.view = new View(parse(vegaSpec))
      .renderer(this.options.renderer || 'canvas')
      .tooltip(handler.call)
      .initialize(this.content)
      .hover()
      .run();

    return {
      width: window.parseInt(this.content.firstChild.getAttribute('width')),
      height: window.parseInt(this.content.firstChild.getAttribute('height'))
    };
  }
github datadotworld / chart-builder / src / components / DownloadButton.js View on Github external
getDownloadUrl={() => {
            return urlFromObject(
              require('vega-lite').compile(
                store.config.getSpecWithMinimumAmountOfData(getData())
              ).spec
            )
          }}
          href="##"