/** * @license Highcharts JS v8.2.2 (2020-10-22) * * Client side exporting module * * (c) 2015-2019 Torstein Honsi / Oystein Moseng * * License: www.highcharts.com/license */ 'use strict'; (function (factory) { if (typeof module === 'object' && module.exports) { factory['default'] = factory; module.exports = factory; } else if (typeof define === 'function' && define.amd) { define('highcharts/modules/offline-exporting', ['highcharts', 'highcharts/modules/exporting'], function (Highcharts) { factory(Highcharts); factory.Highcharts = Highcharts; return factory; }); } else { factory(typeof Highcharts !== 'undefined' ? Highcharts : undefined); } }(function (Highcharts) { var _modules = Highcharts ? Highcharts._modules : {}; function _registerModule(obj, path, args, fn) { if (!obj.hasOwnProperty(path)) { obj[path] = fn.apply(null, args); } } _registerModule(_modules, 'Extensions/DownloadURL.js', [_modules['Core/Globals.js']], function (Highcharts) { /* * * * (c) 2015-2020 Oystein Moseng * * License: www.highcharts.com/license * * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!! * * Mixin for downloading content in the browser * * */ var win = Highcharts.win, nav = win.navigator, doc = win.document, domurl = win.URL || win.webkitURL || win, isEdgeBrowser = /Edge\/\d+/.test(nav.userAgent); /** * Convert base64 dataURL to Blob if supported, otherwise returns undefined. * @private * @function Highcharts.dataURLtoBlob * @param {string} dataURL * URL to convert * @return {string|undefined} * Blob */ var dataURLtoBlob = Highcharts.dataURLtoBlob = function (dataURL) { var parts = dataURL .replace(/filename=.*;/, '') .match(/data:([^;]*)(;base64)?,([0-9A-Za-z+/]+)/); if (parts && parts.length > 3 && win.atob && win.ArrayBuffer && win.Uint8Array && win.Blob && domurl.createObjectURL) { // Try to convert data URL to Blob var binStr = win.atob(parts[3]), buf = new win.ArrayBuffer(binStr.length), binary = new win.Uint8Array(buf); for (var i = 0; i < binary.length; ++i) { binary[i] = binStr.charCodeAt(i); } var blob = new win.Blob([binary], { 'type': parts[1] }); return domurl.createObjectURL(blob); } }; /** * Download a data URL in the browser. Can also take a blob as first param. * * @private * @function Highcharts.downloadURL * @param {string|global.URL} dataURL * The dataURL/Blob to download * @param {string} filename * The name of the resulting file (w/extension) * @return {void} */ var downloadURL = Highcharts.downloadURL = function (dataURL, filename) { var a = doc.createElement('a'), windowRef; // IE specific blob implementation // Don't use for normal dataURLs if (typeof dataURL !== 'string' && !(dataURL instanceof String) && nav.msSaveOrOpenBlob) { nav.msSaveOrOpenBlob(dataURL, filename); return; } dataURL = "" + dataURL; // Some browsers have limitations for data URL lengths. Try to convert to // Blob or fall back. Edge always needs that blob. if (isEdgeBrowser || dataURL.length > 2000000) { dataURL = dataURLtoBlob(dataURL) || ''; if (!dataURL) { throw new Error('Failed to convert to blob'); } } // Try HTML5 download attr if supported if (typeof a.download !== 'undefined') { a.href = dataURL; a.download = filename; // HTML5 download attribute doc.body.appendChild(a); a.click(); doc.body.removeChild(a); } else { // No download attr, just opening data URI try { windowRef = win.open(dataURL, 'chart'); if (typeof windowRef === 'undefined' || windowRef === null) { throw new Error('Failed to open window'); } } catch (e) { // window.open failed, trying location.href win.location.href = dataURL; } } }; var exports = { dataURLtoBlob: dataURLtoBlob, downloadURL: downloadURL }; return exports; }); _registerModule(_modules, 'Extensions/OfflineExporting.js', [_modules['Core/Chart/Chart.js'], _modules['Core/Globals.js'], _modules['Core/Renderer/SVG/SVGRenderer.js'], _modules['Core/Utilities.js'], _modules['Extensions/DownloadURL.js']], function (Chart, H, SVGRenderer, U, DownloadURL) { /* * * * Client side exporting module * * (c) 2015 Torstein Honsi / Oystein Moseng * * License: www.highcharts.com/license * * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!! * * */ var win = H.win, doc = H.doc; var addEvent = U.addEvent, error = U.error, extend = U.extend, getOptions = U.getOptions, merge = U.merge; var downloadURL = DownloadURL.downloadURL; var domurl = win.URL || win.webkitURL || win, nav = win.navigator, isMSBrowser = /Edge\/|Trident\/|MSIE /.test(nav.userAgent), // Milliseconds to defer image load event handlers to offset IE bug loadEventDeferDelay = isMSBrowser ? 150 : 0; var imageData; // Dummy object so we can reuse our canvas-tools.js without errors H.CanVGRenderer = {}; /* eslint-disable valid-jsdoc */ /** * Downloads a script and executes a callback when done. * * @private * @function getScript * @param {string} scriptLocation * @param {Function} callback * @return {void} */ function getScript(scriptLocation, callback) { var head = doc.getElementsByTagName('head')[0], script = doc.createElement('script'); script.type = 'text/javascript'; script.src = scriptLocation; script.onload = callback; script.onerror = function () { error('Error loading script ' + scriptLocation); }; head.appendChild(script); } /** * Get blob URL from SVG code. Falls back to normal data URI. * * @private * @function Highcharts.svgToDataURL * @param {string} svg * @return {string} */ function svgToDataUrl(svg) { // Webkit and not chrome var webKit = (nav.userAgent.indexOf('WebKit') > -1 && nav.userAgent.indexOf('Chrome') < 0); try { // Safari requires data URI since it doesn't allow navigation to blob // URLs. Firefox has an issue with Blobs and internal references, // leading to gradients not working using Blobs (#4550) if (!webKit && nav.userAgent.toLowerCase().indexOf('firefox') < 0) { return domurl.createObjectURL(new win.Blob([svg], { type: 'image/svg+xml;charset-utf-16' })); } } catch (e) { // Ignore } return 'data:image/svg+xml;charset=UTF-8,' + encodeURIComponent(svg); } /** * Get data:URL from image URL. Pass in callbacks to handle results. * * @private * @function Highcharts.imageToDataUrl * * @param {string} imageURL * * @param {string} imageType * * @param {*} callbackArgs * callbackArgs is used only by callbacks. * * @param {number} scale * * @param {Function} successCallback * Receives four arguments: imageURL, imageType, callbackArgs, and scale. * * @param {Function} taintedCallback * Receives four arguments: imageURL, imageType, callbackArgs, and scale. * * @param {Function} noCanvasSupportCallback * Receives four arguments: imageURL, imageType, callbackArgs, and scale. * * @param {Function} failedLoadCallback * Receives four arguments: imageURL, imageType, callbackArgs, and scale. * * @param {Function} [finallyCallback] * finallyCallback is always called at the end of the process. All * callbacks receive four arguments: imageURL, imageType, callbackArgs, * and scale. * * @return {void} */ function imageToDataUrl(imageURL, imageType, callbackArgs, scale) { var img = new win.Image(); img.onload = loadHandler; //img.onerror = errorHandler; img.src = imageURL; var canvas = doc.createElement('canvas'), ctx = canvas.getContext && canvas.getContext('2d'), dataURL; canvas.height = img.height * scale; canvas.width = img.width * scale; ctx.drawImage(img, 0, 0, canvas.width, canvas.height); dataURL = canvas.toDataURL(imageType); imageData = dataURL; debugger; return dataURL; } Chart.prototype.getImageData = function ( exportingOptions, chartOptions) { var chart = this, options = merge(chart.options.exporting, exportingOptions), fallbackToExportServer = function (err) { if (options.fallbackToExportServer === false) { if (options.error) { options.error(options, err); } else { error(28, true); // Fallback disabled } } else { chart.exportChart(options); } }, // Return true if the SVG contains images with external data. With the // boost module there are `image` elements with encoded PNGs, these are // supported by svg2pdf and should pass (#10243). hasExternalImages = function () { return [].some.call(chart.container.getElementsByTagName('image'), function (image) { var href = image.getAttribute('href'); return href !== '' && href.indexOf('data:') !== 0; }); }; // If we are on IE and in styled mode, add a whitelist to the renderer for // inline styles that we want to pass through. There are so many styles by // default in IE that we don't want to blacklist them all. if (isMSBrowser && chart.styledMode) { SVGRenderer.prototype.inlineWhitelist = [ /^blockSize/, /^border/, /^caretColor/, /^color/, /^columnRule/, /^columnRuleColor/, /^cssFloat/, /^cursor/, /^fill$/, /^fillOpacity/, /^font/, /^inlineSize/, /^length/, /^lineHeight/, /^opacity/, /^outline/, /^parentRule/, /^rx$/, /^ry$/, /^stroke/, /^textAlign/, /^textAnchor/, /^textDecoration/, /^transform/, /^vectorEffect/, /^visibility/, /^x$/, /^y$/ ]; } // Always fall back on: // - MS browsers: Embedded images JPEG/PNG, or any PDF // - Embedded images and PDF if ((isMSBrowser && (options.type === 'application/pdf' || chart.container.getElementsByTagName('image').length && options.type !== 'image/svg+xml')) || (options.type === 'application/pdf' && hasExternalImages())) { fallbackToExportServer('Image type not supported for this chart/browser.'); return imageData; } var svg = chart.getSVG(); //console.log(svg); //var svgUrl = svgToDataUrl(svg); //var imageType = options.type || 'image/png', scale = options.scale || 1; var imageUrl = 'data:image/svg+xml;charset=utf-8;base64,' + window.btoa(unescape(encodeURIComponent(svg))); return imageUrl; }; // Extend the default options to use the local exporter logic merge(true, getOptions().exporting, { libURL: 'https://code.highcharts.com/8.2.2/lib/', // When offline-exporting is loaded, redefine the menu item definitions // related to download. menuItemDefinitions: { downloadPNG: { textKey: 'downloadPNG', onclick: function () { this.exportChartLocal(); } }, downloadJPEG: { textKey: 'downloadJPEG', onclick: function () { this.exportChartLocal({ type: 'image/jpeg' }); } }, downloadSVG: { textKey: 'downloadSVG', onclick: function () { this.exportChartLocal({ type: 'image/svg+xml' }); } }, downloadPDF: { textKey: 'downloadPDF', onclick: function () { this.exportChartLocal({ type: 'application/pdf' }); } } } }); // Compatibility }); _registerModule(_modules, 'masters/modules/offline-exporting.src.js', [], function () { }); }));