Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
loadJSON('examples/specs/' + example + '.vl.json', function(vlSpec: TopLevelSpec) {
const vgSpec = vl.compile(vlSpec).spec;
const runtime = vega.parse(vgSpec); // may throw an Error if parsing fails
new vega.View(runtime)
.logLevel(vega.Warn)
.initialize(document.querySelector('.viz#'+ example + '> div.view'))
.renderer('canvas')
.run();
d3.select('.viz#'+ example + '> .desc').text(vlSpec.description || '');
});
});
const vega = require('vega'),
path = require('path'),
args = require('./args'),
read = require('./read');
function load(file) {
return require(path.resolve(file));
}
const Levels = {
error: vega.Error,
warn: vega.Warn,
info: vega.Info,
debug: vega.Debug
};
module.exports = function(type, callback, opt) {
// parse command line arguments
const arg = args(type);
// set baseURL, if specified. default to input spec directory
const base = arg.base || (arg._[0] ? path.dirname(arg._[0]) : null);
// set log level, defaults to logging warning messages
const loglevel = Levels[String(arg.loglevel).toLowerCase()] || vega.Warn;
// load config file, if specified
const config = arg.config ? load(arg.config) : null;
module.exports = function(type, callback, opt) {
// parse command line arguments
const arg = args(type);
// set baseURL, if specified. default to input spec directory
const base = arg.base || (arg._[0] ? path.dirname(arg._[0]) : null);
// set log level, defaults to logging warning messages
const loglevel = Levels[String(arg.loglevel).toLowerCase()] || vega.Warn;
// load config file, if specified
const config = arg.config ? load(arg.config) : null;
// set output image scale factor
const scale = arg.scale || undefined;
// use a seeded random number generator, if specified
if (typeof arg.seed !== 'undefined') {
if (Number.isNaN(arg.seed)) throw 'Illegal seed value: must be a valid number.';
vega.setRandom(vega.randomLCG(arg.seed));
}
// load custom number format locale, if specified
if (arg.format) vega.formatLocale(load(arg.format));
return parsePromise.then(function(runtime) {
ctrl.view = new vg.View(runtime)
.initialize(el)
.logLevel(vg.Warn)
.hover();
// Register all event listeners to the new view
listeners.register();
// the update() method initiates visual encoding and rendering:
// View has to update once before scene is ready
ctrl.update();
// Re-parse complete: null out the completed promise
parsePromise = null;
});
};
// {"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);
}
}
height: dimension.height - (this.props.heightOffset || 0),
data: {
name: this.state.id,
},
};
if (this.props.width) {
if (typeof this.props.width === 'function') {
vlSpec.width = this.props.width(dimension, this.state.data);
} else {
vlSpec.width = this.props.width;
}
}
const spec = vl.compile(vlSpec).spec;
const runtime = vega.parse(spec);
this.view = new vega.View(runtime)
.logLevel(vega.Warn)
.initialize(el)
.renderer('svg')
.hover();
if (this.props.tooltipOptions && Object.keys(this.props.tooltipOptions).length) {
vegaTooltip.vega(this.view, this.props.tooltipOptions);
} else {
vegaTooltip.vega(this.view);
}
this.bindData();
} catch (err) {
console.log('ERROR: Failed to compile vega spec ', err);
}
};
renderVega(props) {
this.refs.chart.style.width = this.refs.chart.getBoundingClientRect().width + 'px';
let runtime;
let view;
runtime = vega.parse(props.vegaSpec);
view = new vega.View(runtime)
.logLevel(vega.Warn)
.initialize(this.refs.chart)
.renderer(props.renderer)
if (props.mode === MODES.Vega) {
view.hover()
}
view.run();
this.refs.chart.style.width = 'auto';
if (this.props.tooltip) {
vegaTooltip.vega(view);
}
window.VEGA_DEBUG.view = view;
async constructView() {
let { spec, data } = this.props
const loader = vega.loader()
const logLevel = vega.Warn
const renderer = 'svg'
spec = vl.compile(spec).spec
const runtime = vega.parse(spec)
const view = new vega.View(runtime, {
loader,
logLevel,
renderer
}).initialize()
view.change('source', vega.changeset().insert(data))
const svgString: string = await view.toSVG()
const blob = new Blob([svgString], { type: 'image/svg+xml' })
async constructView() {
const { spec, data, onViewRender } = this.props
const loader = vega.loader()
const logLevel = vega.Warn
const renderer = 'svg'
try {
const vgSpec = vl.compile(spec).spec
const runtime = vega.parse(vgSpec)
const view = new vega.View(runtime, {
loader,
logLevel,
renderer
})
.initialize(this.nodeRef.current)
.change('source', vega.changeset().insert(data))
try {