# all files / candela/VisComponent/mixin/ VegaChart.js

81.13% Statements 43/53
88.57% Branches 31/35
64.29% Functions 9/14
38.46% Lines 5/13
10 statements, 2 functions, 15 branches Ignored

    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
    291×

    1×
    1×

    1×

     import vega from '../../util/vega';

    let VegaChart = (Base, spec) => class extends Base {
      constructor (...args) {
        super(...args);
        this.options = args[1];
      }

      render () {
        this.chart = vega.parseChart(spec, this.el, this.options);
      }

      get serializationFormats () {
        return ['png', 'svg'];
      }

      serialize (format) {
        if (!this.chart) {
          return Promise.reject('The render() method must be called before serialize().');
        }
        return this.chart.then(vobj => {
          return vobj.toImageURL(format);
        });
      }
    };

    export default VegaChart;