Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function embedExample($target, spec, actions = true, tooltip = true) {
const vgSpec = compile(spec).spec;
const view = new vega.View(vega.parse(vgSpec), { loader: loader }).renderer('svg').initialize($target);
if (tooltip) {
const handler = new Handler().call;
view.tooltip(handler);
}
view.run();
if (actions) {
select($target)
.append('div')
.attr('class', 'vega-actions')
.append('a')
.text('Open in Vega Editor')
.attr('href', '#')
// tslint:disable-next-line
.on('click', function () {
post(window, editorURL, {
mode: 'vega-lite',
spec: compactStringify(spec),
config: vgSpec.config,
// This call may throw an Error if parsing fails.
const runtime = vega.parse(vgSpec, mode === 'vega-lite' ? {} : config);
const view = new vega.View(runtime, {
loader,
logLevel,
renderer
});
if (opts.tooltip !== false) {
let handler: TooltipHandler;
if (isTooltipHandler(opts.tooltip)) {
handler = opts.tooltip;
} else {
// user provided boolean true or tooltip options
handler = new Handler(opts.tooltip === true ? {} : opts.tooltip).call;
}
view.tooltip(handler);
}
let { hover } = opts;
if (hover === undefined) {
hover = mode === 'vega';
}
if (hover) {
const { hoverSet, updateSet } = (typeof hover === 'boolean' ? {} : hover) as Hover;
view.hover(hoverSet, updateSet);
}
_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'))
};
}
export function embedExample($target: any, spec: TopLevelSpec, actions = true, tooltip = true) {
const {spec: vgSpec} = compile(spec);
const view = new vega.View(vega.parse(vgSpec), {loader: loader}).renderer('svg').initialize($target);
if (tooltip) {
const handler = new Handler().call;
view.tooltip(handler);
}
view.run();
if (actions) {
select($target)
.append('div')
.attr('class', 'vega-actions')
.append('a')
.text('Open in Vega Editor')
.attr('href', '#')
.on('click', function() {
post(window, editorURL, {
mode: 'vega-lite',
spec: compactStringify(spec),