OfflineExporting.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. /* *
  2. *
  3. * Client side exporting module
  4. *
  5. * (c) 2015 Torstein Honsi / Oystein Moseng
  6. *
  7. * License: www.highcharts.com/license
  8. *
  9. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  10. *
  11. * */
  12. import Chart from '../Core/Chart/Chart.js';
  13. import H from '../Core/Globals.js';
  14. var win = H.win, doc = H.doc;
  15. import O from '../Core/Options.js';
  16. var getOptions = O.getOptions;
  17. import SVGRenderer from '../Core/Renderer/SVG/SVGRenderer.js';
  18. import U from '../Core/Utilities.js';
  19. var addEvent = U.addEvent, error = U.error, extend = U.extend, fireEvent = U.fireEvent, merge = U.merge;
  20. import DownloadURL from '../Extensions/DownloadURL.js';
  21. var downloadURL = DownloadURL.downloadURL;
  22. var domurl = win.URL || win.webkitURL || win,
  23. // Milliseconds to defer image load event handlers to offset IE bug
  24. loadEventDeferDelay = H.isMS ? 150 : 0;
  25. // Dummy object so we can reuse our canvas-tools.js without errors
  26. H.CanVGRenderer = {};
  27. /* eslint-disable valid-jsdoc */
  28. /**
  29. * Downloads a script and executes a callback when done.
  30. *
  31. * @private
  32. * @function getScript
  33. * @param {string} scriptLocation
  34. * @param {Function} callback
  35. * @return {void}
  36. */
  37. function getScript(scriptLocation, callback) {
  38. var head = doc.getElementsByTagName('head')[0], script = doc.createElement('script');
  39. script.type = 'text/javascript';
  40. script.src = scriptLocation;
  41. script.onload = callback;
  42. script.onerror = function () {
  43. error('Error loading script ' + scriptLocation);
  44. };
  45. head.appendChild(script);
  46. }
  47. /**
  48. * Get blob URL from SVG code. Falls back to normal data URI.
  49. *
  50. * @private
  51. * @function Highcharts.svgToDataURL
  52. * @param {string} svg
  53. * @return {string}
  54. */
  55. function svgToDataUrl(svg) {
  56. // Webkit and not chrome
  57. var userAgent = win.navigator.userAgent;
  58. var webKit = (userAgent.indexOf('WebKit') > -1 &&
  59. userAgent.indexOf('Chrome') < 0);
  60. try {
  61. // Safari requires data URI since it doesn't allow navigation to blob
  62. // URLs. Firefox has an issue with Blobs and internal references,
  63. // leading to gradients not working using Blobs (#4550)
  64. if (!webKit && !H.isFirefox) {
  65. return domurl.createObjectURL(new win.Blob([svg], {
  66. type: 'image/svg+xml;charset-utf-16'
  67. }));
  68. }
  69. }
  70. catch (e) {
  71. // Ignore
  72. }
  73. return 'data:image/svg+xml;charset=UTF-8,' + encodeURIComponent(svg);
  74. }
  75. /**
  76. * Get data:URL from image URL. Pass in callbacks to handle results.
  77. *
  78. * @private
  79. * @function Highcharts.imageToDataUrl
  80. *
  81. * @param {string} imageURL
  82. *
  83. * @param {string} imageType
  84. *
  85. * @param {*} callbackArgs
  86. * callbackArgs is used only by callbacks.
  87. *
  88. * @param {number} scale
  89. *
  90. * @param {Function} successCallback
  91. * Receives four arguments: imageURL, imageType, callbackArgs, and scale.
  92. *
  93. * @param {Function} taintedCallback
  94. * Receives four arguments: imageURL, imageType, callbackArgs, and scale.
  95. *
  96. * @param {Function} noCanvasSupportCallback
  97. * Receives four arguments: imageURL, imageType, callbackArgs, and scale.
  98. *
  99. * @param {Function} failedLoadCallback
  100. * Receives four arguments: imageURL, imageType, callbackArgs, and scale.
  101. *
  102. * @param {Function} [finallyCallback]
  103. * finallyCallback is always called at the end of the process. All
  104. * callbacks receive four arguments: imageURL, imageType, callbackArgs,
  105. * and scale.
  106. *
  107. * @return {void}
  108. */
  109. function imageToDataUrl(imageURL, imageType, callbackArgs, scale, successCallback, taintedCallback, noCanvasSupportCallback, failedLoadCallback, finallyCallback) {
  110. var img = new win.Image(), taintedHandler, loadHandler = function () {
  111. setTimeout(function () {
  112. var canvas = doc.createElement('canvas'), ctx = canvas.getContext && canvas.getContext('2d'), dataURL;
  113. try {
  114. if (!ctx) {
  115. noCanvasSupportCallback(imageURL, imageType, callbackArgs, scale);
  116. }
  117. else {
  118. canvas.height = img.height * scale;
  119. canvas.width = img.width * scale;
  120. ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
  121. // Now we try to get the contents of the canvas.
  122. try {
  123. dataURL = canvas.toDataURL(imageType);
  124. successCallback(dataURL, imageType, callbackArgs, scale);
  125. }
  126. catch (e) {
  127. taintedHandler(imageURL, imageType, callbackArgs, scale);
  128. }
  129. }
  130. }
  131. finally {
  132. if (finallyCallback) {
  133. finallyCallback(imageURL, imageType, callbackArgs, scale);
  134. }
  135. }
  136. // IE bug where image is not always ready despite calling load
  137. // event.
  138. }, loadEventDeferDelay);
  139. },
  140. // Image load failed (e.g. invalid URL)
  141. errorHandler = function () {
  142. failedLoadCallback(imageURL, imageType, callbackArgs, scale);
  143. if (finallyCallback) {
  144. finallyCallback(imageURL, imageType, callbackArgs, scale);
  145. }
  146. };
  147. // This is called on load if the image drawing to canvas failed with a
  148. // security error. We retry the drawing with crossOrigin set to Anonymous.
  149. taintedHandler = function () {
  150. img = new win.Image();
  151. taintedHandler = taintedCallback;
  152. // Must be set prior to loading image source
  153. img.crossOrigin = 'Anonymous';
  154. img.onload = loadHandler;
  155. img.onerror = errorHandler;
  156. img.src = imageURL;
  157. };
  158. img.onload = loadHandler;
  159. img.onerror = errorHandler;
  160. img.src = imageURL;
  161. }
  162. /* eslint-enable valid-jsdoc */
  163. /**
  164. * Get data URL to an image of an SVG and call download on it options object:
  165. *
  166. * - **filename:** Name of resulting downloaded file without extension. Default
  167. * is `chart`.
  168. *
  169. * - **type:** File type of resulting download. Default is `image/png`.
  170. *
  171. * - **scale:** Scaling factor of downloaded image compared to source. Default
  172. * is `1`.
  173. *
  174. * - **libURL:** URL pointing to location of dependency scripts to download on
  175. * demand. Default is the exporting.libURL option of the global Highcharts
  176. * options pointing to our server.
  177. *
  178. * @function Highcharts.downloadSVGLocal
  179. *
  180. * @param {string} svg
  181. * The generated SVG
  182. *
  183. * @param {Highcharts.ExportingOptions} options
  184. * The exporting options
  185. *
  186. * @param {Function} failCallback
  187. * The callback function in case of errors
  188. *
  189. * @param {Function} [successCallback]
  190. * The callback function in case of success
  191. *
  192. * @return {void}
  193. */
  194. function downloadSVGLocal(svg, options, failCallback, successCallback) {
  195. var svgurl, blob, objectURLRevoke = true, finallyHandler, libURL = (options.libURL || getOptions().exporting.libURL), dummySVGContainer = doc.createElement('div'), imageType = options.type || 'image/png', filename = ((options.filename || 'chart') +
  196. '.' +
  197. (imageType === 'image/svg+xml' ? 'svg' : imageType.split('/')[1])), scale = options.scale || 1;
  198. // Allow libURL to end with or without fordward slash
  199. libURL = libURL.slice(-1) !== '/' ? libURL + '/' : libURL;
  200. /* eslint-disable valid-jsdoc */
  201. /**
  202. * @private
  203. */
  204. function svgToPdf(svgElement, margin) {
  205. var width = svgElement.width.baseVal.value + 2 * margin, height = svgElement.height.baseVal.value + 2 * margin, pdf = new win.jsPDF(// eslint-disable-line new-cap
  206. height > width ? 'p' : 'l', // setting orientation to portrait if height exceeds width
  207. 'pt', [width, height]);
  208. // Workaround for #7090, hidden elements were drawn anyway. It comes
  209. // down to https://github.com/yWorks/svg2pdf.js/issues/28. Check this
  210. // later.
  211. [].forEach.call(svgElement.querySelectorAll('*[visibility="hidden"]'), function (node) {
  212. node.parentNode.removeChild(node);
  213. });
  214. // Workaround for #13948, multiple stops in linear gradient set to 0
  215. // causing error in Acrobat
  216. var gradients = svgElement.querySelectorAll('linearGradient');
  217. for (var index = 0; index < gradients.length; index++) {
  218. var gradient = gradients[index];
  219. var stops = gradient.querySelectorAll('stop');
  220. var i = 0;
  221. while (i < stops.length &&
  222. stops[i].getAttribute('offset') === '0' &&
  223. stops[i + 1].getAttribute('offset') === '0') {
  224. stops[i].remove();
  225. i++;
  226. }
  227. }
  228. // Workaround for #15135, zero width spaces, which Highcharts uses to
  229. // break lines, are not correctly rendered in PDF. Replace it with a
  230. // regular space and offset by some pixels to compensate.
  231. [].forEach.call(svgElement.querySelectorAll('tspan'), function (tspan) {
  232. if (tspan.textContent === '\u200B') {
  233. tspan.textContent = ' ';
  234. tspan.setAttribute('dx', -5);
  235. }
  236. });
  237. win.svg2pdf(svgElement, pdf, { removeInvalid: true });
  238. return pdf.output('datauristring');
  239. }
  240. /**
  241. * @private
  242. * @return {void}
  243. */
  244. function downloadPDF() {
  245. dummySVGContainer.innerHTML = svg;
  246. var textElements = dummySVGContainer.getElementsByTagName('text'), titleElements, svgData,
  247. // Copy style property to element from parents if it's not there.
  248. // Searches up hierarchy until it finds prop, or hits the chart
  249. // container.
  250. setStylePropertyFromParents = function (el, propName) {
  251. var curParent = el;
  252. while (curParent && curParent !== dummySVGContainer) {
  253. if (curParent.style[propName]) {
  254. el.style[propName] =
  255. curParent.style[propName];
  256. break;
  257. }
  258. curParent = curParent.parentNode;
  259. }
  260. };
  261. // Workaround for the text styling. Making sure it does pick up settings
  262. // for parent elements.
  263. [].forEach.call(textElements, function (el) {
  264. // Workaround for the text styling. making sure it does pick up the
  265. // root element
  266. ['font-family', 'font-size'].forEach(function (property) {
  267. setStylePropertyFromParents(el, property);
  268. });
  269. el.style['font-family'] = (el.style['font-family'] &&
  270. el.style['font-family'].split(' ').splice(-1));
  271. // Workaround for plotband with width, removing title from text
  272. // nodes
  273. titleElements = el.getElementsByTagName('title');
  274. [].forEach.call(titleElements, function (titleElement) {
  275. el.removeChild(titleElement);
  276. });
  277. });
  278. svgData = svgToPdf(dummySVGContainer.firstChild, 0);
  279. try {
  280. downloadURL(svgData, filename);
  281. if (successCallback) {
  282. successCallback();
  283. }
  284. }
  285. catch (e) {
  286. failCallback(e);
  287. }
  288. }
  289. /* eslint-enable valid-jsdoc */
  290. // Initiate download depending on file type
  291. if (imageType === 'image/svg+xml') {
  292. // SVG download. In this case, we want to use Microsoft specific Blob if
  293. // available
  294. try {
  295. if (typeof win.navigator.msSaveOrOpenBlob !== 'undefined') {
  296. blob = new MSBlobBuilder();
  297. blob.append(svg);
  298. svgurl = blob.getBlob('image/svg+xml');
  299. }
  300. else {
  301. svgurl = svgToDataUrl(svg);
  302. }
  303. downloadURL(svgurl, filename);
  304. if (successCallback) {
  305. successCallback();
  306. }
  307. }
  308. catch (e) {
  309. failCallback(e);
  310. }
  311. }
  312. else if (imageType === 'application/pdf') {
  313. if (win.jsPDF && win.svg2pdf) {
  314. downloadPDF();
  315. }
  316. else {
  317. // Must load pdf libraries first. // Don't destroy the object URL
  318. // yet since we are doing things asynchronously. A cleaner solution
  319. // would be nice, but this will do for now.
  320. objectURLRevoke = true;
  321. getScript(libURL + 'jspdf.js', function () {
  322. getScript(libURL + 'svg2pdf.js', function () {
  323. downloadPDF();
  324. });
  325. });
  326. }
  327. }
  328. else {
  329. // PNG/JPEG download - create bitmap from SVG
  330. svgurl = svgToDataUrl(svg);
  331. finallyHandler = function () {
  332. try {
  333. domurl.revokeObjectURL(svgurl);
  334. }
  335. catch (e) {
  336. // Ignore
  337. }
  338. };
  339. // First, try to get PNG by rendering on canvas
  340. imageToDataUrl(svgurl, imageType, {}, scale, function (imageURL) {
  341. // Success
  342. try {
  343. downloadURL(imageURL, filename);
  344. if (successCallback) {
  345. successCallback();
  346. }
  347. }
  348. catch (e) {
  349. failCallback(e);
  350. }
  351. }, function () {
  352. // Failed due to tainted canvas
  353. // Create new and untainted canvas
  354. var canvas = doc.createElement('canvas'), ctx = canvas.getContext('2d'), imageWidth = svg.match(/^<svg[^>]*width\s*=\s*\"?(\d+)\"?[^>]*>/)[1] * scale, imageHeight = svg.match(/^<svg[^>]*height\s*=\s*\"?(\d+)\"?[^>]*>/)[1] * scale, downloadWithCanVG = function () {
  355. ctx.drawSvg(svg, 0, 0, imageWidth, imageHeight);
  356. try {
  357. downloadURL(win.navigator.msSaveOrOpenBlob ?
  358. canvas.msToBlob() :
  359. canvas.toDataURL(imageType), filename);
  360. if (successCallback) {
  361. successCallback();
  362. }
  363. }
  364. catch (e) {
  365. failCallback(e);
  366. }
  367. finally {
  368. finallyHandler();
  369. }
  370. };
  371. canvas.width = imageWidth;
  372. canvas.height = imageHeight;
  373. if (win.canvg) {
  374. // Use preloaded canvg
  375. downloadWithCanVG();
  376. }
  377. else {
  378. // Must load canVG first. // Don't destroy the object URL
  379. // yet since we are doing things asynchronously. A cleaner
  380. // solution would be nice, but this will do for now.
  381. objectURLRevoke = true;
  382. // Get RGBColor.js first, then canvg
  383. getScript(libURL + 'rgbcolor.js', function () {
  384. getScript(libURL + 'canvg.js', function () {
  385. downloadWithCanVG();
  386. });
  387. });
  388. }
  389. },
  390. // No canvas support
  391. failCallback,
  392. // Failed to load image
  393. failCallback,
  394. // Finally
  395. function () {
  396. if (objectURLRevoke) {
  397. finallyHandler();
  398. }
  399. });
  400. }
  401. }
  402. /* eslint-disable valid-jsdoc */
  403. /**
  404. * Get SVG of chart prepared for client side export. This converts embedded
  405. * images in the SVG to data URIs. It requires the regular exporting module. The
  406. * options and chartOptions arguments are passed to the getSVGForExport
  407. * function.
  408. *
  409. * @private
  410. * @function Highcharts.Chart#getSVGForLocalExport
  411. * @param {Highcharts.ExportingOptions} options
  412. * @param {Highcharts.Options} chartOptions
  413. * @param {Function} failCallback
  414. * @param {Function} successCallback
  415. * @return {void}
  416. */
  417. Chart.prototype.getSVGForLocalExport = function (options, chartOptions, failCallback, successCallback) {
  418. var chart = this, images, imagesEmbedded = 0, chartCopyContainer, chartCopyOptions, el, i, l, href,
  419. // After grabbing the SVG of the chart's copy container we need to do
  420. // sanitation on the SVG
  421. sanitize = function (svg) {
  422. return chart.sanitizeSVG(svg, chartCopyOptions);
  423. },
  424. // When done with last image we have our SVG
  425. checkDone = function () {
  426. if (imagesEmbedded === images.length) {
  427. successCallback(sanitize(chartCopyContainer.innerHTML));
  428. }
  429. },
  430. // Success handler, we converted image to base64!
  431. embeddedSuccess = function (imageURL, imageType, callbackArgs) {
  432. ++imagesEmbedded;
  433. // Change image href in chart copy
  434. callbackArgs.imageElement.setAttributeNS('http://www.w3.org/1999/xlink', 'href', imageURL);
  435. checkDone();
  436. };
  437. // Hook into getSVG to get a copy of the chart copy's container (#8273)
  438. chart.unbindGetSVG = addEvent(chart, 'getSVG', function (e) {
  439. chartCopyOptions = e.chartCopy.options;
  440. chartCopyContainer = e.chartCopy.container.cloneNode(true);
  441. });
  442. // Trigger hook to get chart copy
  443. chart.getSVGForExport(options, chartOptions);
  444. images = chartCopyContainer.getElementsByTagName('image');
  445. try {
  446. // If there are no images to embed, the SVG is okay now.
  447. if (!images.length) {
  448. // Use SVG of chart copy
  449. successCallback(sanitize(chartCopyContainer.innerHTML));
  450. return;
  451. }
  452. // Go through the images we want to embed
  453. for (i = 0, l = images.length; i < l; ++i) {
  454. el = images[i];
  455. href = el.getAttributeNS('http://www.w3.org/1999/xlink', 'href');
  456. if (href) {
  457. imageToDataUrl(href, 'image/png', { imageElement: el }, options.scale, embeddedSuccess,
  458. // Tainted canvas
  459. failCallback,
  460. // No canvas support
  461. failCallback,
  462. // Failed to load source
  463. failCallback);
  464. // Hidden, boosted series have blank href (#10243)
  465. }
  466. else {
  467. ++imagesEmbedded;
  468. el.parentNode.removeChild(el);
  469. checkDone();
  470. }
  471. }
  472. }
  473. catch (e) {
  474. failCallback(e);
  475. }
  476. // Clean up
  477. chart.unbindGetSVG();
  478. };
  479. /* eslint-enable valid-jsdoc */
  480. /**
  481. * Exporting and offline-exporting modules required. Export a chart to an image
  482. * locally in the user's browser.
  483. *
  484. * @function Highcharts.Chart#exportChartLocal
  485. *
  486. * @param {Highcharts.ExportingOptions} [exportingOptions]
  487. * Exporting options, the same as in
  488. * {@link Highcharts.Chart#exportChart}.
  489. *
  490. * @param {Highcharts.Options} [chartOptions]
  491. * Additional chart options for the exported chart. For example a
  492. * different background color can be added here, or `dataLabels`
  493. * for export only.
  494. *
  495. * @return {void}
  496. *
  497. * @requires modules/exporting
  498. */
  499. Chart.prototype.exportChartLocal = function (exportingOptions, chartOptions) {
  500. var chart = this, options = merge(chart.options.exporting, exportingOptions), fallbackToExportServer = function (err) {
  501. if (options.fallbackToExportServer === false) {
  502. if (options.error) {
  503. options.error(options, err);
  504. }
  505. else {
  506. error(28, true); // Fallback disabled
  507. }
  508. }
  509. else {
  510. chart.exportChart(options);
  511. }
  512. }, svgSuccess = function (svg) {
  513. // If SVG contains foreignObjects all exports except SVG will fail,
  514. // as both CanVG and svg2pdf choke on this. Gracefully fall back.
  515. if (svg.indexOf('<foreignObject') > -1 &&
  516. options.type !== 'image/svg+xml') {
  517. fallbackToExportServer('Image type not supported' +
  518. 'for charts with embedded HTML');
  519. }
  520. else {
  521. downloadSVGLocal(svg, extend({ filename: chart.getFilename() }, options), fallbackToExportServer, function () { return fireEvent(chart, 'exportChartLocalSuccess'); });
  522. }
  523. },
  524. // Return true if the SVG contains images with external data. With the
  525. // boost module there are `image` elements with encoded PNGs, these are
  526. // supported by svg2pdf and should pass (#10243).
  527. hasExternalImages = function () {
  528. return [].some.call(chart.container.getElementsByTagName('image'), function (image) {
  529. var href = image.getAttribute('href');
  530. return href !== '' && href.indexOf('data:') !== 0;
  531. });
  532. };
  533. // If we are on IE and in styled mode, add a whitelist to the renderer for
  534. // inline styles that we want to pass through. There are so many styles by
  535. // default in IE that we don't want to blacklist them all.
  536. if (H.isMS && chart.styledMode) {
  537. SVGRenderer.prototype.inlineWhitelist = [
  538. /^blockSize/,
  539. /^border/,
  540. /^caretColor/,
  541. /^color/,
  542. /^columnRule/,
  543. /^columnRuleColor/,
  544. /^cssFloat/,
  545. /^cursor/,
  546. /^fill$/,
  547. /^fillOpacity/,
  548. /^font/,
  549. /^inlineSize/,
  550. /^length/,
  551. /^lineHeight/,
  552. /^opacity/,
  553. /^outline/,
  554. /^parentRule/,
  555. /^rx$/,
  556. /^ry$/,
  557. /^stroke/,
  558. /^textAlign/,
  559. /^textAnchor/,
  560. /^textDecoration/,
  561. /^transform/,
  562. /^vectorEffect/,
  563. /^visibility/,
  564. /^x$/,
  565. /^y$/
  566. ];
  567. }
  568. // Always fall back on:
  569. // - MS browsers: Embedded images JPEG/PNG, or any PDF
  570. // - Embedded images and PDF
  571. if ((H.isMS &&
  572. (options.type === 'application/pdf' ||
  573. chart.container.getElementsByTagName('image').length &&
  574. options.type !== 'image/svg+xml')) || (options.type === 'application/pdf' &&
  575. hasExternalImages())) {
  576. fallbackToExportServer('Image type not supported for this chart/browser.');
  577. return;
  578. }
  579. chart.getSVGForLocalExport(options, chartOptions || {}, fallbackToExportServer, svgSuccess);
  580. };
  581. // Extend the default options to use the local exporter logic
  582. merge(true, getOptions().exporting, {
  583. libURL: 'https://code.highcharts.com/9.1.0/lib/',
  584. // When offline-exporting is loaded, redefine the menu item definitions
  585. // related to download.
  586. menuItemDefinitions: {
  587. downloadPNG: {
  588. textKey: 'downloadPNG',
  589. onclick: function () {
  590. this.exportChartLocal();
  591. }
  592. },
  593. downloadJPEG: {
  594. textKey: 'downloadJPEG',
  595. onclick: function () {
  596. this.exportChartLocal({
  597. type: 'image/jpeg'
  598. });
  599. }
  600. },
  601. downloadSVG: {
  602. textKey: 'downloadSVG',
  603. onclick: function () {
  604. this.exportChartLocal({
  605. type: 'image/svg+xml'
  606. });
  607. }
  608. },
  609. downloadPDF: {
  610. textKey: 'downloadPDF',
  611. onclick: function () {
  612. this.exportChartLocal({
  613. type: 'application/pdf'
  614. });
  615. }
  616. }
  617. }
  618. });
  619. // Compatibility
  620. H.downloadSVGLocal = downloadSVGLocal;