Loading Snakemake Report...

Please enable Javascript in your browser to see this report.

"); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const win = window.open(''); win.document.write(header + source + footer); win.document.title = "".concat(NAMES[mode], " JSON Source"); } /** * Try to guess the type of spec. * * @param spec Vega or Vega-Lite spec. */ function guessMode(spec, providedMode) { // Decide mode if (spec.$schema) { const parsed = e(spec.$schema); if (providedMode && providedMode !== parsed.library) { var _NAMES$providedMode; console.warn("The given visualization spec is written in ".concat(NAMES[parsed.library], ", but mode argument sets ").concat((_NAMES$providedMode = NAMES[providedMode]) !== null && _NAMES$providedMode !== void 0 ? _NAMES$providedMode : providedMode, ".")); } const mode = parsed.library; if (!satisfies_1(VERSION[mode], "^".concat(parsed.version.slice(1)))) { console.warn("The input spec uses ".concat(NAMES[mode], " ").concat(parsed.version, ", but the current version of ").concat(NAMES[mode], " is v").concat(VERSION[mode], ".")); } return mode; } // try to guess from the provided spec if ('mark' in spec || 'encoding' in spec || 'layer' in spec || 'hconcat' in spec || 'vconcat' in spec || 'facet' in spec || 'repeat' in spec) { return 'vega-lite'; } if ('marks' in spec || 'signals' in spec || 'scales' in spec || 'axes' in spec) { return 'vega'; } return providedMode !== null && providedMode !== void 0 ? providedMode : 'vega'; } function isLoader(o) { return !!(o && 'load' in o); } function createLoader(opts) { return isLoader(opts) ? opts : vega.loader(opts); } function embedOptionsFromUsermeta(parsedSpec) { var _parsedSpec$usermeta$, _parsedSpec$usermeta; const opts = (_parsedSpec$usermeta$ = (_parsedSpec$usermeta = parsedSpec.usermeta) === null || _parsedSpec$usermeta === void 0 ? void 0 : _parsedSpec$usermeta.embedOptions) !== null && _parsedSpec$usermeta$ !== void 0 ? _parsedSpec$usermeta$ : {}; if (vegaImport.isString(opts.defaultStyle)) { // we don't allow styles set via usermeta since it would allow injection of logic (we set the style via innerHTML) opts.defaultStyle = false; } return opts; } /** * Embed a Vega visualization component in a web page. This function returns a promise. * * @param el DOM element in which to place component (DOM node or CSS selector). * @param spec String : A URL string from which to load the Vega specification. * Object : The Vega/Vega-Lite specification as a parsed JSON object. * @param opts A JavaScript object containing options for embedding. */ async function embed(el, spec) { var _parsedOpts$config, _usermetaOpts$config; let opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; let parsedSpec; let loader; if (vegaImport.isString(spec)) { loader = createLoader(opts.loader); parsedSpec = JSON.parse(await loader.load(spec)); } else { parsedSpec = spec; } const loadedEmbedOptions = embedOptionsFromUsermeta(parsedSpec); const usermetaLoader = loadedEmbedOptions.loader; // either create the loader for the first time or create a new loader if the spec has new loader options if (!loader || usermetaLoader) { var _opts$loader; loader = createLoader((_opts$loader = opts.loader) !== null && _opts$loader !== void 0 ? _opts$loader : usermetaLoader); } const usermetaOpts = await loadOpts(loadedEmbedOptions, loader); const parsedOpts = await loadOpts(opts, loader); const mergedOpts = { ...mergeDeep(parsedOpts, usermetaOpts), config: vegaImport.mergeConfig((_parsedOpts$config = parsedOpts.config) !== null && _parsedOpts$config !== void 0 ? _parsedOpts$config : {}, (_usermetaOpts$config = usermetaOpts.config) !== null && _usermetaOpts$config !== void 0 ? _usermetaOpts$config : {}) }; return await _embed(el, parsedSpec, mergedOpts, loader); } async function loadOpts(opt, loader) { var _opt$config; const config = vegaImport.isString(opt.config) ? JSON.parse(await loader.load(opt.config)) : (_opt$config = opt.config) !== null && _opt$config !== void 0 ? _opt$config : {}; const patch = vegaImport.isString(opt.patch) ? JSON.parse(await loader.load(opt.patch)) : opt.patch; return { ...opt, ...(patch ? { patch } : {}), ...(config ? { config } : {}) }; } function getRoot(el) { var _document$head; const possibleRoot = el.getRootNode ? el.getRootNode() : document; return possibleRoot instanceof ShadowRoot ? { root: possibleRoot, rootContainer: possibleRoot } : { root: document, rootContainer: (_document$head = document.head) !== null && _document$head !== void 0 ? _document$head : document.body }; } async function _embed(el, spec) { var _opts$config, _opts$actions, _opts$renderer, _opts$logLevel, _opts$downloadFileNam, _ref, _vega$expressionInter; let opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; let loader = arguments.length > 3 ? arguments[3] : undefined; const config = opts.theme ? vegaImport.mergeConfig(themes[opts.theme], (_opts$config = opts.config) !== null && _opts$config !== void 0 ? _opts$config : {}) : opts.config; const actions = vegaImport.isBoolean(opts.actions) ? opts.actions : mergeDeep({}, DEFAULT_ACTIONS, (_opts$actions = opts.actions) !== null && _opts$actions !== void 0 ? _opts$actions : {}); const i18n = { ...I18N, ...opts.i18n }; const renderer = (_opts$renderer = opts.renderer) !== null && _opts$renderer !== void 0 ? _opts$renderer : 'canvas'; const logLevel = (_opts$logLevel = opts.logLevel) !== null && _opts$logLevel !== void 0 ? _opts$logLevel : vega.Warn; const downloadFileName = (_opts$downloadFileNam = opts.downloadFileName) !== null && _opts$downloadFileNam !== void 0 ? _opts$downloadFileNam : 'visualization'; const element = typeof el === 'string' ? document.querySelector(el) : el; if (!element) { throw new Error("".concat(el, " does not exist")); } if (opts.defaultStyle !== false) { const ID = 'vega-embed-style'; const { root, rootContainer } = getRoot(element); if (!root.getElementById(ID)) { const style = document.createElement('style'); style.id = ID; style.innerHTML = opts.defaultStyle === undefined || opts.defaultStyle === true ? (embedStyle ).toString() : opts.defaultStyle; rootContainer.appendChild(style); } } const mode = guessMode(spec, opts.mode); let vgSpec = PREPROCESSOR[mode](spec, config); if (mode === 'vega-lite') { if (vgSpec.$schema) { const parsed = e(vgSpec.$schema); if (!satisfies_1(VERSION.vega, "^".concat(parsed.version.slice(1)))) { console.warn("The compiled spec uses Vega ".concat(parsed.version, ", but current version is v").concat(VERSION.vega, ".")); } } } element.classList.add('vega-embed'); if (actions) { element.classList.add('has-actions'); } element.innerHTML = ''; // clear container let container = element; if (actions) { const chartWrapper = document.createElement('div'); chartWrapper.classList.add(CHART_WRAPPER_CLASS); element.appendChild(chartWrapper); container = chartWrapper; } const patch = opts.patch; if (patch) { vgSpec = patch instanceof Function ? patch(vgSpec) : applyPatch(vgSpec, patch, true, false).newDocument; } // Set locale. Note that this is a global setting. if (opts.formatLocale) { vega.formatLocale(opts.formatLocale); } if (opts.timeFormatLocale) { vega.timeFormatLocale(opts.timeFormatLocale); } const { ast } = opts; // Do not apply the config to Vega when we have already applied it to Vega-Lite. // This call may throw an Error if parsing fails. const runtime = vega.parse(vgSpec, mode === 'vega-lite' ? {} : config, { ast }); const view = new (opts.viewClass || vega.View)(runtime, { loader, logLevel, renderer, ...(ast ? { expr: (_ref = (_vega$expressionInter = vega.expressionInterpreter) !== null && _vega$expressionInter !== void 0 ? _vega$expressionInter : opts.expr) !== null && _ref !== void 0 ? _ref : expression } : {}) }); view.addSignalListener('autosize', (_, autosize) => { const { type } = autosize; if (type == 'fit-x') { container.classList.add('fit-x'); container.classList.remove('fit-y'); } else if (type == 'fit-y') { container.classList.remove('fit-x'); container.classList.add('fit-y'); } else if (type == 'fit') { container.classList.add('fit-x', 'fit-y'); } else { container.classList.remove('fit-x', 'fit-y'); } }); if (opts.tooltip !== false) { const handler = isTooltipHandler(opts.tooltip) ? opts.tooltip : // user provided boolean true or tooltip options 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; view.hover(hoverSet, updateSet); } if (opts) { if (opts.width != null) { view.width(opts.width); } if (opts.height != null) { view.height(opts.height); } if (opts.padding != null) { view.padding(opts.padding); } } await view.initialize(container, opts.bind).runAsync(); let documentClickHandler; if (actions !== false) { let wrapper = element; if (opts.defaultStyle !== false) { const details = document.createElement('details'); details.title = i18n.CLICK_TO_VIEW_ACTIONS; element.append(details); wrapper = details; const summary = document.createElement('summary'); summary.innerHTML = SVG_CIRCLES; details.append(summary); documentClickHandler = ev => { if (!details.contains(ev.target)) { details.removeAttribute('open'); } }; document.addEventListener('click', documentClickHandler); } const ctrl = document.createElement('div'); wrapper.append(ctrl); ctrl.classList.add('vega-actions'); // add 'Export' action if (actions === true || actions.export !== false) { for (const ext of ['svg', 'png']) { if (actions === true || actions.export === true || actions.export[ext]) { const i18nExportAction = i18n["".concat(ext.toUpperCase(), "_ACTION")]; const exportLink = document.createElement('a'); exportLink.text = i18nExportAction; exportLink.href = '#'; exportLink.target = '_blank'; exportLink.download = "".concat(downloadFileName, ".").concat(ext); // add link on mousedown so that it's correct when the click happens exportLink.addEventListener('mousedown', async function (e) { e.preventDefault(); const url = await view.toImageURL(ext, opts.scaleFactor); this.href = url; }); ctrl.append(exportLink); } } } // add 'View Source' action if (actions === true || actions.source !== false) { const viewSourceLink = document.createElement('a'); viewSourceLink.text = i18n.SOURCE_ACTION; viewSourceLink.href = '#'; viewSourceLink.addEventListener('click', function (e) { var _opts$sourceHeader, _opts$sourceFooter; viewSource(jsonStringifyPrettyCompact(spec), (_opts$sourceHeader = opts.sourceHeader) !== null && _opts$sourceHeader !== void 0 ? _opts$sourceHeader : '', (_opts$sourceFooter = opts.sourceFooter) !== null && _opts$sourceFooter !== void 0 ? _opts$sourceFooter : '', mode); e.preventDefault(); }); ctrl.append(viewSourceLink); } // add 'View Compiled' action if (mode === 'vega-lite' && (actions === true || actions.compiled !== false)) { const compileLink = document.createElement('a'); compileLink.text = i18n.COMPILED_ACTION; compileLink.href = '#'; compileLink.addEventListener('click', function (e) { var _opts$sourceHeader2, _opts$sourceFooter2; viewSource(jsonStringifyPrettyCompact(vgSpec), (_opts$sourceHeader2 = opts.sourceHeader) !== null && _opts$sourceHeader2 !== void 0 ? _opts$sourceHeader2 : '', (_opts$sourceFooter2 = opts.sourceFooter) !== null && _opts$sourceFooter2 !== void 0 ? _opts$sourceFooter2 : '', 'vega'); e.preventDefault(); }); ctrl.append(compileLink); } // add 'Open in Vega Editor' action if (actions === true || actions.editor !== false) { var _opts$editorUrl; const editorUrl = (_opts$editorUrl = opts.editorUrl) !== null && _opts$editorUrl !== void 0 ? _opts$editorUrl : 'https://vega.github.io/editor/'; const editorLink = document.createElement('a'); editorLink.text = i18n.EDITOR_ACTION; editorLink.href = '#'; editorLink.addEventListener('click', function (e) { post(window, editorUrl, { config: config, mode, renderer, spec: jsonStringifyPrettyCompact(spec) }); e.preventDefault(); }); ctrl.append(editorLink); } } function finalize() { if (documentClickHandler) { document.removeEventListener('click', documentClickHandler); } view.finalize(); } return { view, spec, vgSpec, finalize, embedOptions: opts }; } /** * Create a promise to an HTML Div element with an embedded Vega-Lite or Vega visualization. * The element has a value property with the view. By default all actions except for the editor action are disabled. * * The main use case is in [Observable](https://observablehq.com/). */ async function container (spec) { var _opt$actions; let opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; const wrapper = document.createElement('div'); wrapper.classList.add('vega-embed-wrapper'); const div = document.createElement('div'); wrapper.appendChild(div); const actions = opt.actions === true || opt.actions === false ? opt.actions : { export: true, source: false, compiled: true, editor: true, ...((_opt$actions = opt.actions) !== null && _opt$actions !== void 0 ? _opt$actions : {}) }; const result = await embed(div, spec, { actions, ...(opt !== null && opt !== void 0 ? opt : {}) }); wrapper.value = result.view; return wrapper; } /** * Returns true if the object is an HTML element. */ function isElement(obj) { return obj instanceof HTMLElement; } const wrapper = function () { if (arguments.length > 1 && (vegaImport.isString(arguments.length <= 0 ? undefined : arguments[0]) && !isURL(arguments.length <= 0 ? undefined : arguments[0]) || isElement(arguments.length <= 0 ? undefined : arguments[0]) || arguments.length === 3)) { return embed(arguments.length <= 0 ? undefined : arguments[0], arguments.length <= 1 ? undefined : arguments[1], arguments.length <= 2 ? undefined : arguments[2]); } return container(arguments.length <= 0 ? undefined : arguments[0], arguments.length <= 1 ? undefined : arguments[1]); }; wrapper.vegaLite = vegaLite; wrapper.vl = vegaLite; // backwards compatibility wrapper.container = container; wrapper.embed = embed; wrapper.vega = vega; wrapper.default = embed; wrapper.version = version; return wrapper; })); //# sourceMappingURL=vega-embed.js.map