exporting.src.js 90 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124
  1. /**
  2. * @license Highcharts JS v8.0.0 (2019-12-10)
  3. *
  4. * Exporting module
  5. *
  6. * (c) 2010-2019 Torstein Honsi
  7. *
  8. * License: www.highcharts.com/license
  9. */
  10. 'use strict';
  11. (function (factory) {
  12. if (typeof module === 'object' && module.exports) {
  13. factory['default'] = factory;
  14. module.exports = factory;
  15. } else if (typeof define === 'function' && define.amd) {
  16. define('highcharts/modules/exporting', ['highcharts'], function (Highcharts) {
  17. factory(Highcharts);
  18. factory.Highcharts = Highcharts;
  19. return factory;
  20. });
  21. } else {
  22. factory(typeof Highcharts !== 'undefined' ? Highcharts : undefined);
  23. }
  24. }(function (Highcharts) {
  25. var _modules = Highcharts ? Highcharts._modules : {};
  26. function _registerModule(obj, path, args, fn) {
  27. if (!obj.hasOwnProperty(path)) {
  28. obj[path] = fn.apply(null, args);
  29. }
  30. }
  31. _registerModule(_modules, 'modules/full-screen.src.js', [_modules['parts/Globals.js']], function (H) {
  32. /* *
  33. *
  34. * (c) 2009-2019 Sebastian Bochann
  35. *
  36. * Full screen for Highcharts
  37. *
  38. * License: www.highcharts.com/license
  39. *
  40. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  41. *
  42. * */
  43. /* eslint-disable no-invalid-this, valid-jsdoc */
  44. /**
  45. * The FullScreen class.
  46. * The module allows user to enable full screen mode in StockTools.
  47. * Based on default solutions in browsers.
  48. *
  49. * @private
  50. * @class
  51. * @name Highcharts.FullScreen
  52. *
  53. * @param {Highcharts.HTMLDOMElement} container
  54. * Chart container
  55. */
  56. var FullScreen = H.FullScreen = function (container) {
  57. this.init(container.parentNode);
  58. };
  59. FullScreen.prototype = {
  60. /**
  61. * Init function
  62. * @private
  63. * @param {Highcharts.HTMLDOMElement} container
  64. * Chart container's parent
  65. * @return {void}
  66. */
  67. init: function (container) {
  68. var promise;
  69. if (container.requestFullscreen) {
  70. promise = container.requestFullscreen();
  71. }
  72. else if (container.mozRequestFullScreen) {
  73. promise = container.mozRequestFullScreen();
  74. }
  75. else if (container.webkitRequestFullscreen) {
  76. promise = container.webkitRequestFullscreen();
  77. }
  78. else if (container.msRequestFullscreen) {
  79. promise = container.msRequestFullscreen();
  80. }
  81. if (promise) {
  82. promise['catch'](function () {
  83. alert('Full screen is not supported inside a frame'); // eslint-disable-line no-alert
  84. });
  85. }
  86. }
  87. };
  88. });
  89. _registerModule(_modules, 'mixins/navigation.js', [], function () {
  90. /**
  91. *
  92. * (c) 2010-2018 Paweł Fus
  93. *
  94. * License: www.highcharts.com/license
  95. *
  96. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  97. *
  98. * */
  99. var chartNavigation = {
  100. /**
  101. * Initializes `chart.navigation` object which delegates `update()` methods
  102. * to all other common classes (used in exporting and navigationBindings).
  103. *
  104. * @private
  105. * @param {Highcharts.Chart} chart
  106. * The chart instance.
  107. * @return {void}
  108. */
  109. initUpdate: function (chart) {
  110. if (!chart.navigation) {
  111. chart.navigation = {
  112. updates: [],
  113. update: function (options, redraw) {
  114. this.updates.forEach(function (updateConfig) {
  115. updateConfig.update.call(updateConfig.context, options, redraw);
  116. });
  117. }
  118. };
  119. }
  120. },
  121. /**
  122. * Registers an `update()` method in the `chart.navigation` object.
  123. *
  124. * @private
  125. * @param {Highcharts.ChartNavigationUpdateFunction} update
  126. * The `update()` method that will be called in `chart.update()`.
  127. * @param {Highcharts.Chart} chart
  128. * The chart instance. `update()` will use that as a context
  129. * (`this`).
  130. * @return {void}
  131. */
  132. addUpdate: function (update, chart) {
  133. if (!chart.navigation) {
  134. this.initUpdate(chart);
  135. }
  136. chart.navigation.updates.push({
  137. update: update,
  138. context: chart
  139. });
  140. }
  141. };
  142. return chartNavigation;
  143. });
  144. _registerModule(_modules, 'modules/exporting.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js'], _modules['mixins/navigation.js']], function (H, U, chartNavigationMixin) {
  145. /* *
  146. *
  147. * Exporting module
  148. *
  149. * (c) 2010-2019 Torstein Honsi
  150. *
  151. * License: www.highcharts.com/license
  152. *
  153. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  154. *
  155. * */
  156. /**
  157. * Gets fired after a chart is printed through the context menu item or the
  158. * Chart.print method.
  159. *
  160. * @callback Highcharts.ExportingAfterPrintCallbackFunction
  161. *
  162. * @param {Highcharts.Chart} chart
  163. * The chart on which the event occured.
  164. *
  165. * @param {global.Event} event
  166. * The event that occured.
  167. */
  168. /**
  169. * Gets fired before a chart is printed through the context menu item or the
  170. * Chart.print method.
  171. *
  172. * @callback Highcharts.ExportingBeforePrintCallbackFunction
  173. *
  174. * @param {Highcharts.Chart} chart
  175. * The chart on which the event occured.
  176. *
  177. * @param {global.Event} event
  178. * The event that occured.
  179. */
  180. /**
  181. * Function to call if the offline-exporting module fails to export a chart on
  182. * the client side.
  183. *
  184. * @callback Highcharts.ExportingErrorCallbackFunction
  185. *
  186. * @param {Highcharts.ExportingOptions} options
  187. * The exporting options.
  188. *
  189. * @param {global.Error} err
  190. * The error from the module.
  191. */
  192. /**
  193. * Definition for a menu item in the context menu.
  194. *
  195. * @interface Highcharts.ExportingMenuObject
  196. */ /**
  197. * The text for the menu item.
  198. *
  199. * @name Highcharts.ExportingMenuObject#text
  200. * @type {string|undefined}
  201. */ /**
  202. * If internationalization is required, the key to a language string.
  203. *
  204. * @name Highcharts.ExportingMenuObject#textKey
  205. * @type {string|undefined}
  206. */ /**
  207. * The click handler for the menu item.
  208. *
  209. * @name Highcharts.ExportingMenuObject#onclick
  210. * @type {Highcharts.EventCallbackFunction<Highcharts.Chart>|undefined}
  211. */ /**
  212. * Indicates a separator line instead of an item.
  213. *
  214. * @name Highcharts.ExportingMenuObject#separator
  215. * @type {boolean|undefined}
  216. */
  217. /**
  218. * Possible MIME types for exporting.
  219. *
  220. * @typedef {"image/png"|"image/jpeg"|"application/pdf"|"image/svg+xml"} Highcharts.ExportingMimeTypeValue
  221. */
  222. var discardElement = U.discardElement, extend = U.extend, isObject = U.isObject, objectEach = U.objectEach, pick = U.pick;
  223. // create shortcuts
  224. var defaultOptions = H.defaultOptions, doc = H.doc, Chart = H.Chart, addEvent = H.addEvent, removeEvent = H.removeEvent, fireEvent = H.fireEvent, createElement = H.createElement, css = H.css, merge = H.merge, isTouchDevice = H.isTouchDevice, win = H.win, userAgent = win.navigator.userAgent, SVGRenderer = H.SVGRenderer, symbols = H.Renderer.prototype.symbols, isMSBrowser = /Edge\/|Trident\/|MSIE /.test(userAgent), isFirefoxBrowser = /firefox/i.test(userAgent);
  225. // Add language
  226. extend(defaultOptions.lang
  227. /**
  228. * @optionparent lang
  229. */
  230. , {
  231. /**
  232. * Exporting module only. View the chart in full screen.
  233. *
  234. * @since 7.1.0
  235. * @requires modules/exporting
  236. *
  237. * @private
  238. */
  239. viewFullscreen: 'View in full screen',
  240. /**
  241. * Exporting module only. The text for the menu item to print the chart.
  242. *
  243. * @since 3.0.1
  244. * @requires modules/exporting
  245. *
  246. * @private
  247. */
  248. printChart: 'Print chart',
  249. /**
  250. * Exporting module only. The text for the PNG download menu item.
  251. *
  252. * @since 2.0
  253. * @requires modules/exporting
  254. *
  255. * @private
  256. */
  257. downloadPNG: 'Download PNG image',
  258. /**
  259. * Exporting module only. The text for the JPEG download menu item.
  260. *
  261. * @since 2.0
  262. * @requires modules/exporting
  263. *
  264. * @private
  265. */
  266. downloadJPEG: 'Download JPEG image',
  267. /**
  268. * Exporting module only. The text for the PDF download menu item.
  269. *
  270. * @since 2.0
  271. * @requires modules/exporting
  272. *
  273. * @private
  274. */
  275. downloadPDF: 'Download PDF document',
  276. /**
  277. * Exporting module only. The text for the SVG download menu item.
  278. *
  279. * @since 2.0
  280. * @requires modules/exporting
  281. *
  282. * @private
  283. */
  284. downloadSVG: 'Download SVG vector image',
  285. /**
  286. * Exporting module menu. The tooltip title for the context menu holding
  287. * print and export menu items.
  288. *
  289. * @since 3.0
  290. * @requires modules/exporting
  291. *
  292. * @private
  293. */
  294. contextButtonTitle: 'Chart context menu'
  295. });
  296. if (!defaultOptions.navigation) {
  297. // Buttons and menus are collected in a separate config option set called
  298. // 'navigation'. This can be extended later to add control buttons like
  299. // zoom and pan right click menus.
  300. /**
  301. * A collection of options for buttons and menus appearing in the exporting
  302. * module.
  303. *
  304. * @requires modules/exporting
  305. * @optionparent navigation
  306. */
  307. defaultOptions.navigation = {};
  308. }
  309. merge(true, defaultOptions.navigation, {
  310. /**
  311. * @optionparent navigation.buttonOptions
  312. *
  313. * @private
  314. */
  315. buttonOptions: {
  316. theme: {},
  317. /**
  318. * Whether to enable buttons.
  319. *
  320. * @sample highcharts/navigation/buttonoptions-enabled/
  321. * Exporting module loaded but buttons disabled
  322. *
  323. * @type {boolean}
  324. * @default true
  325. * @since 2.0
  326. * @apioption navigation.buttonOptions.enabled
  327. */
  328. /**
  329. * The pixel size of the symbol on the button.
  330. *
  331. * @sample highcharts/navigation/buttonoptions-height/
  332. * Bigger buttons
  333. *
  334. * @since 2.0
  335. */
  336. symbolSize: 14,
  337. /**
  338. * The x position of the center of the symbol inside the button.
  339. *
  340. * @sample highcharts/navigation/buttonoptions-height/
  341. * Bigger buttons
  342. *
  343. * @since 2.0
  344. */
  345. symbolX: 12.5,
  346. /**
  347. * The y position of the center of the symbol inside the button.
  348. *
  349. * @sample highcharts/navigation/buttonoptions-height/
  350. * Bigger buttons
  351. *
  352. * @since 2.0
  353. */
  354. symbolY: 10.5,
  355. /**
  356. * Alignment for the buttons.
  357. *
  358. * @sample highcharts/navigation/buttonoptions-align/
  359. * Center aligned
  360. *
  361. * @type {Highcharts.AlignValue}
  362. * @since 2.0
  363. */
  364. align: 'right',
  365. /**
  366. * The pixel spacing between buttons.
  367. *
  368. * @since 2.0
  369. */
  370. buttonSpacing: 3,
  371. /**
  372. * Pixel height of the buttons.
  373. *
  374. * @sample highcharts/navigation/buttonoptions-height/
  375. * Bigger buttons
  376. *
  377. * @since 2.0
  378. */
  379. height: 22,
  380. /**
  381. * A text string to add to the individual button.
  382. *
  383. * @sample highcharts/exporting/buttons-text/
  384. * Full text button
  385. * @sample highcharts/exporting/buttons-text-symbol/
  386. * Combined symbol and text
  387. *
  388. * @type {string}
  389. * @default null
  390. * @since 3.0
  391. * @apioption navigation.buttonOptions.text
  392. */
  393. /**
  394. * The vertical offset of the button's position relative to its
  395. * `verticalAlign`.
  396. *
  397. * @sample highcharts/navigation/buttonoptions-verticalalign/
  398. * Buttons at lower right
  399. *
  400. * @type {number}
  401. * @default 0
  402. * @since 2.0
  403. * @apioption navigation.buttonOptions.y
  404. */
  405. /**
  406. * The vertical alignment of the buttons. Can be one of `"top"`,
  407. * `"middle"` or `"bottom"`.
  408. *
  409. * @sample highcharts/navigation/buttonoptions-verticalalign/
  410. * Buttons at lower right
  411. *
  412. * @type {Highcharts.VerticalAlignValue}
  413. * @since 2.0
  414. */
  415. verticalAlign: 'top',
  416. /**
  417. * The pixel width of the button.
  418. *
  419. * @sample highcharts/navigation/buttonoptions-height/
  420. * Bigger buttons
  421. *
  422. * @since 2.0
  423. */
  424. width: 24
  425. }
  426. });
  427. // Presentational attributes
  428. merge(true, defaultOptions.navigation
  429. /**
  430. * A collection of options for buttons and menus appearing in the exporting
  431. * module.
  432. *
  433. * @optionparent navigation
  434. */
  435. , {
  436. /**
  437. * CSS styles for the popup menu appearing by default when the export
  438. * icon is clicked. This menu is rendered in HTML.
  439. *
  440. * @see In styled mode, the menu is styled with the `.highcharts-menu`
  441. * class.
  442. *
  443. * @sample highcharts/navigation/menustyle/
  444. * Light gray menu background
  445. *
  446. * @type {Highcharts.CSSObject}
  447. * @default {"border": "1px solid #999999", "background": "#ffffff", "padding": "5px 0"}
  448. * @since 2.0
  449. *
  450. * @private
  451. */
  452. menuStyle: {
  453. /** @ignore-option */
  454. border: '1px solid #999999',
  455. /** @ignore-option */
  456. background: '#ffffff',
  457. /** @ignore-option */
  458. padding: '5px 0'
  459. },
  460. /**
  461. * CSS styles for the individual items within the popup menu appearing
  462. * by default when the export icon is clicked. The menu items are
  463. * rendered in HTML. Font size defaults to `11px` on desktop and `14px`
  464. * on touch devices.
  465. *
  466. * @see In styled mode, the menu items are styled with the
  467. * `.highcharts-menu-item` class.
  468. *
  469. * @sample {highcharts} highcharts/navigation/menuitemstyle/
  470. * Add a grey stripe to the left
  471. *
  472. * @type {Highcharts.CSSObject}
  473. * @default {"padding": "0.5em 1em", "color": "#333333", "background": "none", "fontSize": "11px/14px", "transition": "background 250ms, color 250ms"}
  474. * @since 2.0
  475. *
  476. * @private
  477. */
  478. menuItemStyle: {
  479. /** @ignore-option */
  480. padding: '0.5em 1em',
  481. /** @ignore-option */
  482. color: '#333333',
  483. /** @ignore-option */
  484. background: 'none',
  485. /** @ignore-option */
  486. fontSize: isTouchDevice ? '14px' : '11px',
  487. /** @ignore-option */
  488. transition: 'background 250ms, color 250ms'
  489. },
  490. /**
  491. * CSS styles for the hover state of the individual items within the
  492. * popup menu appearing by default when the export icon is clicked. The
  493. * menu items are rendered in HTML.
  494. *
  495. * @see In styled mode, the menu items are styled with the
  496. * `.highcharts-menu-item` class.
  497. *
  498. * @sample highcharts/navigation/menuitemhoverstyle/
  499. * Bold text on hover
  500. *
  501. * @type {Highcharts.CSSObject}
  502. * @default {"background": "#335cad", "color": "#ffffff"}
  503. * @since 2.0
  504. *
  505. * @private
  506. */
  507. menuItemHoverStyle: {
  508. /** @ignore-option */
  509. background: '#335cad',
  510. /** @ignore-option */
  511. color: '#ffffff'
  512. },
  513. /**
  514. * A collection of options for buttons appearing in the exporting
  515. * module.
  516. *
  517. * In styled mode, the buttons are styled with the
  518. * `.highcharts-contextbutton` and `.highcharts-button-symbol` classes.
  519. *
  520. * @requires modules/exporting
  521. *
  522. * @private
  523. */
  524. buttonOptions: {
  525. /**
  526. * Fill color for the symbol within the button.
  527. *
  528. * @sample highcharts/navigation/buttonoptions-symbolfill/
  529. * Blue symbol stroke for one of the buttons
  530. *
  531. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  532. * @since 2.0
  533. */
  534. symbolFill: '#666666',
  535. /**
  536. * The color of the symbol's stroke or line.
  537. *
  538. * @sample highcharts/navigation/buttonoptions-symbolstroke/
  539. * Blue symbol stroke
  540. *
  541. * @type {Highcharts.ColorString}
  542. * @since 2.0
  543. */
  544. symbolStroke: '#666666',
  545. /**
  546. * The pixel stroke width of the symbol on the button.
  547. *
  548. * @sample highcharts/navigation/buttonoptions-height/
  549. * Bigger buttons
  550. *
  551. * @since 2.0
  552. */
  553. symbolStrokeWidth: 3,
  554. /**
  555. * A configuration object for the button theme. The object accepts
  556. * SVG properties like `stroke-width`, `stroke` and `fill`.
  557. * Tri-state button styles are supported by the `states.hover` and
  558. * `states.select` objects.
  559. *
  560. * @sample highcharts/navigation/buttonoptions-theme/
  561. * Theming the buttons
  562. *
  563. * @requires modules/exporting
  564. *
  565. * @since 3.0
  566. */
  567. theme: {
  568. /**
  569. * The default fill exists only to capture hover events.
  570. *
  571. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  572. * @default #ffffff
  573. * @apioption navigation.buttonOptions.theme.fill
  574. */
  575. /**
  576. * Default stroke for the buttons.
  577. * @type {Highcharts.ColorString}
  578. * @default none
  579. * @apioption navigation.buttonOptions.theme.stroke
  580. */
  581. /**
  582. * Padding for the button.
  583. */
  584. padding: 5
  585. }
  586. }
  587. });
  588. // Add the export related options
  589. /**
  590. * Options for the exporting module. For an overview on the matter, see
  591. * [the docs](https://www.highcharts.com/docs/export-module/export-module-overview).
  592. *
  593. * @requires modules/exporting
  594. * @optionparent exporting
  595. */
  596. defaultOptions.exporting = {
  597. /**
  598. * Experimental setting to allow HTML inside the chart (added through
  599. * the `useHTML` options), directly in the exported image. This allows
  600. * you to preserve complicated HTML structures like tables or bi-directional
  601. * text in exported charts.
  602. *
  603. * Disclaimer: The HTML is rendered in a `foreignObject` tag in the
  604. * generated SVG. The official export server is based on PhantomJS,
  605. * which supports this, but other SVG clients, like Batik, does not
  606. * support it. This also applies to downloaded SVG that you want to
  607. * open in a desktop client.
  608. *
  609. * @type {boolean}
  610. * @default false
  611. * @since 4.1.8
  612. * @apioption exporting.allowHTML
  613. */
  614. /**
  615. * Additional chart options to be merged into the chart before exporting to
  616. * an image format. This does not apply to printing the chart via the export
  617. * menu.
  618. *
  619. * For example, a common use case is to add data labels to improve
  620. * readability of the exported chart, or to add a printer-friendly color
  621. * scheme to exported PDFs.
  622. *
  623. * @sample {highcharts} highcharts/exporting/chartoptions-data-labels/
  624. * Added data labels
  625. * @sample {highstock} highcharts/exporting/chartoptions-data-labels/
  626. * Added data labels
  627. *
  628. * @type {Highcharts.Options}
  629. * @apioption exporting.chartOptions
  630. */
  631. /**
  632. * Whether to enable the exporting module. Disabling the module will
  633. * hide the context button, but API methods will still be available.
  634. *
  635. * @sample {highcharts} highcharts/exporting/enabled-false/
  636. * Exporting module is loaded but disabled
  637. * @sample {highstock} highcharts/exporting/enabled-false/
  638. * Exporting module is loaded but disabled
  639. *
  640. * @type {boolean}
  641. * @default true
  642. * @since 2.0
  643. * @apioption exporting.enabled
  644. */
  645. /**
  646. * Function to call if the offline-exporting module fails to export
  647. * a chart on the client side, and [fallbackToExportServer](
  648. * #exporting.fallbackToExportServer) is disabled. If left undefined, an
  649. * exception is thrown instead. Receives two parameters, the exporting
  650. * options, and the error from the module.
  651. *
  652. * @see [fallbackToExportServer](#exporting.fallbackToExportServer)
  653. *
  654. * @type {Highcharts.ExportingErrorCallbackFunction}
  655. * @since 5.0.0
  656. * @requires modules/exporting
  657. * @requires modules/offline-exporting
  658. * @apioption exporting.error
  659. */
  660. /**
  661. * Whether or not to fall back to the export server if the offline-exporting
  662. * module is unable to export the chart on the client side. This happens for
  663. * certain browsers, and certain features (e.g.
  664. * [allowHTML](#exporting.allowHTML)), depending on the image type exporting
  665. * to. For very complex charts, it is possible that export can fail in
  666. * browsers that don't support Blob objects, due to data URL length limits.
  667. * It is recommended to define the [exporting.error](#exporting.error)
  668. * handler if disabling fallback, in order to notify users in case export
  669. * fails.
  670. *
  671. * @type {boolean}
  672. * @default true
  673. * @since 4.1.8
  674. * @requires modules/exporting
  675. * @requires modules/offline-exporting
  676. * @apioption exporting.fallbackToExportServer
  677. */
  678. /**
  679. * The filename, without extension, to use for the exported chart.
  680. *
  681. * @sample {highcharts} highcharts/exporting/filename/
  682. * Custom file name
  683. * @sample {highstock} highcharts/exporting/filename/
  684. * Custom file name
  685. *
  686. * @type {string}
  687. * @default chart
  688. * @since 2.0
  689. * @apioption exporting.filename
  690. */
  691. /**
  692. * An object containing additional key value data for the POST form that
  693. * sends the SVG to the export server. For example, a `target` can be set to
  694. * make sure the generated image is received in another frame, or a custom
  695. * `enctype` or `encoding` can be set.
  696. *
  697. * @type {Highcharts.HTMLAttributes}
  698. * @since 3.0.8
  699. * @apioption exporting.formAttributes
  700. */
  701. /**
  702. * Path where Highcharts will look for export module dependencies to
  703. * load on demand if they don't already exist on `window`. Should currently
  704. * point to location of [CanVG](https://github.com/canvg/canvg) library,
  705. * [RGBColor.js](https://github.com/canvg/canvg),
  706. * [jsPDF](https://github.com/yWorks/jsPDF) and
  707. * [svg2pdf.js](https://github.com/yWorks/svg2pdf.js), required for client
  708. * side export in certain browsers.
  709. *
  710. * @type {string}
  711. * @default https://code.highcharts.com/{version}/lib
  712. * @since 5.0.0
  713. * @apioption exporting.libURL
  714. */
  715. /**
  716. * Analogous to [sourceWidth](#exporting.sourceWidth).
  717. *
  718. * @type {number}
  719. * @since 3.0
  720. * @apioption exporting.sourceHeight
  721. */
  722. /**
  723. * The width of the original chart when exported, unless an explicit
  724. * [chart.width](#chart.width) is set, or a pixel width is set on the
  725. * container. The width exported raster image is then multiplied by
  726. * [scale](#exporting.scale).
  727. *
  728. * @sample {highcharts} highcharts/exporting/sourcewidth/
  729. * Source size demo
  730. * @sample {highstock} highcharts/exporting/sourcewidth/
  731. * Source size demo
  732. * @sample {highmaps} maps/exporting/sourcewidth/
  733. * Source size demo
  734. *
  735. * @type {number}
  736. * @since 3.0
  737. * @apioption exporting.sourceWidth
  738. */
  739. /**
  740. * The pixel width of charts exported to PNG or JPG. As of Highcharts
  741. * 3.0, the default pixel width is a function of the [chart.width](
  742. * #chart.width) or [exporting.sourceWidth](#exporting.sourceWidth) and the
  743. * [exporting.scale](#exporting.scale).
  744. *
  745. * @sample {highcharts} highcharts/exporting/width/
  746. * Export to 200px wide images
  747. * @sample {highstock} highcharts/exporting/width/
  748. * Export to 200px wide images
  749. *
  750. * @type {number}
  751. * @since 2.0
  752. * @apioption exporting.width
  753. */
  754. /**
  755. * Default MIME type for exporting if `chart.exportChart()` is called
  756. * without specifying a `type` option. Possible values are `image/png`,
  757. * `image/jpeg`, `application/pdf` and `image/svg+xml`.
  758. *
  759. * @type {Highcharts.ExportingMimeTypeValue}
  760. * @since 2.0
  761. */
  762. type: 'image/png',
  763. /**
  764. * The URL for the server module converting the SVG string to an image
  765. * format. By default this points to Highchart's free web service.
  766. *
  767. * @since 2.0
  768. */
  769. url: 'https://export.highcharts.com/',
  770. /**
  771. * When printing the chart from the menu item in the burger menu, if
  772. * the on-screen chart exceeds this width, it is resized. After printing
  773. * or cancelled, it is restored. The default width makes the chart
  774. * fit into typical paper format. Note that this does not affect the
  775. * chart when printing the web page as a whole.
  776. *
  777. * @since 4.2.5
  778. */
  779. printMaxWidth: 780,
  780. /**
  781. * Defines the scale or zoom factor for the exported image compared
  782. * to the on-screen display. While for instance a 600px wide chart
  783. * may look good on a website, it will look bad in print. The default
  784. * scale of 2 makes this chart export to a 1200px PNG or JPG.
  785. *
  786. * @see [chart.width](#chart.width)
  787. * @see [exporting.sourceWidth](#exporting.sourceWidth)
  788. *
  789. * @sample {highcharts} highcharts/exporting/scale/
  790. * Scale demonstrated
  791. * @sample {highstock} highcharts/exporting/scale/
  792. * Scale demonstrated
  793. * @sample {highmaps} maps/exporting/scale/
  794. * Scale demonstrated
  795. *
  796. * @since 3.0
  797. */
  798. scale: 2,
  799. /**
  800. * Options for the export related buttons, print and export. In addition
  801. * to the default buttons listed here, custom buttons can be added.
  802. * See [navigation.buttonOptions](#navigation.buttonOptions) for general
  803. * options.
  804. *
  805. * @type {Highcharts.Dictionary<*>}
  806. * @requires modules/exporting
  807. */
  808. buttons: {
  809. /**
  810. * Options for the export button.
  811. *
  812. * In styled mode, export button styles can be applied with the
  813. * `.highcharts-contextbutton` class.
  814. *
  815. * @declare Highcharts.ExportingButtonsOptionsObject
  816. * @extends navigation.buttonOptions
  817. * @requires modules/exporting
  818. */
  819. contextButton: {
  820. /**
  821. * A click handler callback to use on the button directly instead of
  822. * the popup menu.
  823. *
  824. * @sample highcharts/exporting/buttons-contextbutton-onclick/
  825. * Skip the menu and export the chart directly
  826. *
  827. * @type {Function}
  828. * @since 2.0
  829. * @apioption exporting.buttons.contextButton.onclick
  830. */
  831. /**
  832. * See [navigation.buttonOptions.symbolFill](
  833. * #navigation.buttonOptions.symbolFill).
  834. *
  835. * @type {Highcharts.ColorString}
  836. * @default #666666
  837. * @since 2.0
  838. * @apioption exporting.buttons.contextButton.symbolFill
  839. */
  840. /**
  841. * The horizontal position of the button relative to the `align`
  842. * option.
  843. *
  844. * @type {number}
  845. * @default -10
  846. * @since 2.0
  847. * @apioption exporting.buttons.contextButton.x
  848. */
  849. /**
  850. * The class name of the context button.
  851. */
  852. className: 'highcharts-contextbutton',
  853. /**
  854. * The class name of the menu appearing from the button.
  855. */
  856. menuClassName: 'highcharts-contextmenu',
  857. /**
  858. * The symbol for the button. Points to a definition function in
  859. * the `Highcharts.Renderer.symbols` collection. The default
  860. * `exportIcon` function is part of the exporting module. Possible
  861. * values are "circle", "square", "diamond", "triangle",
  862. * "triangle-down", "menu", "menuball" or custom shape.
  863. *
  864. * @sample highcharts/exporting/buttons-contextbutton-symbol/
  865. * Use a circle for symbol
  866. * @sample highcharts/exporting/buttons-contextbutton-symbol-custom/
  867. * Custom shape as symbol
  868. *
  869. * @type {Highcharts.SymbolKeyValue|"exportIcon"|"menu"|"menuball"|string}
  870. * @since 2.0
  871. */
  872. symbol: 'menu',
  873. /**
  874. * The key to a [lang](#lang) option setting that is used for the
  875. * button's title tooltip. When the key is `contextButtonTitle`, it
  876. * refers to [lang.contextButtonTitle](#lang.contextButtonTitle)
  877. * that defaults to "Chart context menu".
  878. *
  879. * @since 6.1.4
  880. */
  881. titleKey: 'contextButtonTitle',
  882. /**
  883. * This option is deprecated, use
  884. * [titleKey](#exporting.buttons.contextButton.titleKey) instead.
  885. *
  886. * @deprecated
  887. * @type {string}
  888. * @apioption exporting.buttons.contextButton._titleKey
  889. */
  890. /**
  891. * A collection of strings pointing to config options for the menu
  892. * items. The config options are defined in the
  893. * `menuItemDefinitions` option.
  894. *
  895. * By default, there is the "View in full screen" and "Print" menu
  896. * items, plus one menu item for each of the available export types.
  897. *
  898. * @sample {highcharts} highcharts/exporting/menuitemdefinitions/
  899. * Menu item definitions
  900. * @sample {highstock} highcharts/exporting/menuitemdefinitions/
  901. * Menu item definitions
  902. * @sample {highmaps} highcharts/exporting/menuitemdefinitions/
  903. * Menu item definitions
  904. *
  905. * @type {Array<string>}
  906. * @default ["viewFullscreen", "printChart", "separator", "downloadPNG", "downloadJPEG", "downloadPDF", "downloadSVG"]
  907. * @since 2.0
  908. */
  909. menuItems: [
  910. 'viewFullscreen',
  911. 'printChart',
  912. 'separator',
  913. 'downloadPNG',
  914. 'downloadJPEG',
  915. 'downloadPDF',
  916. 'downloadSVG'
  917. ]
  918. }
  919. },
  920. /**
  921. * An object consisting of definitions for the menu items in the context
  922. * menu. Each key value pair has a `key` that is referenced in the
  923. * [menuItems](#exporting.buttons.contextButton.menuItems) setting,
  924. * and a `value`, which is an object with the following properties:
  925. *
  926. * - **onclick:** The click handler for the menu item
  927. *
  928. * - **text:** The text for the menu item
  929. *
  930. * - **textKey:** If internationalization is required, the key to a language
  931. * string
  932. *
  933. * @sample {highcharts} highcharts/exporting/menuitemdefinitions/
  934. * Menu item definitions
  935. * @sample {highstock} highcharts/exporting/menuitemdefinitions/
  936. * Menu item definitions
  937. * @sample {highmaps} highcharts/exporting/menuitemdefinitions/
  938. * Menu item definitions
  939. *
  940. * @type {Highcharts.Dictionary<Highcharts.ExportingMenuObject>}
  941. * @default {"viewFullscreen": {}, "printChart": {}, "separator": {}, "downloadPNG": {}, "downloadJPEG": {}, "downloadPDF": {}, "downloadSVG": {}}
  942. * @since 5.0.13
  943. */
  944. menuItemDefinitions: {
  945. /**
  946. * @ignore
  947. */
  948. viewFullscreen: {
  949. textKey: 'viewFullscreen',
  950. onclick: function () {
  951. this.fullscreen = new H.FullScreen(this.container);
  952. }
  953. },
  954. /**
  955. * @ignore
  956. */
  957. printChart: {
  958. textKey: 'printChart',
  959. onclick: function () {
  960. this.print();
  961. }
  962. },
  963. /**
  964. * @ignore
  965. */
  966. separator: {
  967. separator: true
  968. },
  969. /**
  970. * @ignore
  971. */
  972. downloadPNG: {
  973. textKey: 'downloadPNG',
  974. onclick: function () {
  975. this.exportChart();
  976. }
  977. },
  978. /**
  979. * @ignore
  980. */
  981. downloadJPEG: {
  982. textKey: 'downloadJPEG',
  983. onclick: function () {
  984. this.exportChart({
  985. type: 'image/jpeg'
  986. });
  987. }
  988. },
  989. /**
  990. * @ignore
  991. */
  992. downloadPDF: {
  993. textKey: 'downloadPDF',
  994. onclick: function () {
  995. this.exportChart({
  996. type: 'application/pdf'
  997. });
  998. }
  999. },
  1000. /**
  1001. * @ignore
  1002. */
  1003. downloadSVG: {
  1004. textKey: 'downloadSVG',
  1005. onclick: function () {
  1006. this.exportChart({
  1007. type: 'image/svg+xml'
  1008. });
  1009. }
  1010. }
  1011. }
  1012. };
  1013. /**
  1014. * Fires after a chart is printed through the context menu item or the
  1015. * `Chart.print` method.
  1016. *
  1017. * @sample highcharts/chart/events-beforeprint-afterprint/
  1018. * Rescale the chart to print
  1019. *
  1020. * @type {Highcharts.ExportingAfterPrintCallbackFunction}
  1021. * @since 4.1.0
  1022. * @context Highcharts.Chart
  1023. * @requires modules/exporting
  1024. * @apioption chart.events.afterPrint
  1025. */
  1026. /**
  1027. * Fires before a chart is printed through the context menu item or
  1028. * the `Chart.print` method.
  1029. *
  1030. * @sample highcharts/chart/events-beforeprint-afterprint/
  1031. * Rescale the chart to print
  1032. *
  1033. * @type {Highcharts.ExportingBeforePrintCallbackFunction}
  1034. * @since 4.1.0
  1035. * @context Highcharts.Chart
  1036. * @requires modules/exporting
  1037. * @apioption chart.events.beforePrint
  1038. */
  1039. /**
  1040. * The post utility
  1041. *
  1042. * @private
  1043. * @function Highcharts.post
  1044. * @param {string} url
  1045. * Post URL
  1046. * @param {object} data
  1047. * Post data
  1048. * @param {Highcharts.Dictionary<string>} [formAttributes]
  1049. * Additional attributes for the post request
  1050. * @return {void}
  1051. */
  1052. H.post = function (url, data, formAttributes) {
  1053. // create the form
  1054. var form = createElement('form', merge({
  1055. method: 'post',
  1056. action: url,
  1057. enctype: 'multipart/form-data'
  1058. }, formAttributes), {
  1059. display: 'none'
  1060. }, doc.body);
  1061. // add the data
  1062. objectEach(data, function (val, name) {
  1063. createElement('input', {
  1064. type: 'hidden',
  1065. name: name,
  1066. value: val
  1067. }, null, form);
  1068. });
  1069. // submit
  1070. form.submit();
  1071. // clean up
  1072. discardElement(form);
  1073. };
  1074. if (H.isSafari) {
  1075. H.win.matchMedia('print').addListener(function (mqlEvent) {
  1076. if (!H.printingChart) {
  1077. return void 0;
  1078. }
  1079. if (mqlEvent.matches) {
  1080. H.printingChart.beforePrint();
  1081. }
  1082. else {
  1083. H.printingChart.afterPrint();
  1084. }
  1085. });
  1086. }
  1087. extend(Chart.prototype, /** @lends Highcharts.Chart.prototype */ {
  1088. /* eslint-disable no-invalid-this, valid-jsdoc */
  1089. /**
  1090. * Exporting module only. A collection of fixes on the produced SVG to
  1091. * account for expando properties, browser bugs, VML problems and other.
  1092. * Returns a cleaned SVG.
  1093. *
  1094. * @private
  1095. * @function Highcharts.Chart#sanitizeSVG
  1096. * @param {string} svg
  1097. * SVG code to sanitize
  1098. * @param {Highcharts.Options} options
  1099. * Chart options to apply
  1100. * @return {string}
  1101. * Sanitized SVG code
  1102. * @requires modules/exporting
  1103. */
  1104. sanitizeSVG: function (svg, options) {
  1105. var split = svg.indexOf('</svg>') + 6, html = svg.substr(split);
  1106. // Remove any HTML added to the container after the SVG (#894, #9087)
  1107. svg = svg.substr(0, split);
  1108. // Move HTML into a foreignObject
  1109. if (options && options.exporting && options.exporting.allowHTML) {
  1110. if (html) {
  1111. html = '<foreignObject x="0" y="0" ' +
  1112. 'width="' + options.chart.width + '" ' +
  1113. 'height="' + options.chart.height + '">' +
  1114. '<body xmlns="http://www.w3.org/1999/xhtml">' +
  1115. html +
  1116. '</body>' +
  1117. '</foreignObject>';
  1118. svg = svg.replace('</svg>', html + '</svg>');
  1119. }
  1120. }
  1121. svg = svg
  1122. .replace(/zIndex="[^"]+"/g, '')
  1123. .replace(/symbolName="[^"]+"/g, '')
  1124. .replace(/jQuery[0-9]+="[^"]+"/g, '')
  1125. .replace(/url\(("|&quot;)(.*?)("|&quot;)\;?\)/g, 'url($2)')
  1126. .replace(/url\([^#]+#/g, 'url(#')
  1127. .replace(/<svg /, '<svg xmlns:xlink="http://www.w3.org/1999/xlink" ')
  1128. .replace(/ (|NS[0-9]+\:)href=/g, ' xlink:href=') // #3567
  1129. .replace(/\n/, ' ')
  1130. // Batik doesn't support rgba fills and strokes (#3095)
  1131. .replace(/(fill|stroke)="rgba\(([ 0-9]+,[ 0-9]+,[ 0-9]+),([ 0-9\.]+)\)"/g, // eslint-disable-line max-len
  1132. '$1="rgb($2)" $1-opacity="$3"')
  1133. // Replace HTML entities, issue #347
  1134. .replace(/&nbsp;/g, '\u00A0') // no-break space
  1135. .replace(/&shy;/g, '\u00AD'); // soft hyphen
  1136. // Further sanitize for oldIE
  1137. if (this.ieSanitizeSVG) {
  1138. svg = this.ieSanitizeSVG(svg);
  1139. }
  1140. return svg;
  1141. },
  1142. /**
  1143. * Return the unfiltered innerHTML of the chart container. Used as hook for
  1144. * plugins. In styled mode, it also takes care of inlining CSS style rules.
  1145. *
  1146. * @see Chart#getSVG
  1147. *
  1148. * @function Highcharts.Chart#getChartHTML
  1149. *
  1150. * @returns {string}
  1151. * The unfiltered SVG of the chart.
  1152. *
  1153. * @requires modules/exporting
  1154. */
  1155. getChartHTML: function () {
  1156. if (this.styledMode) {
  1157. this.inlineStyles();
  1158. }
  1159. return this.container.innerHTML;
  1160. },
  1161. /**
  1162. * Return an SVG representation of the chart.
  1163. *
  1164. * @sample highcharts/members/chart-getsvg/
  1165. * View the SVG from a button
  1166. *
  1167. * @function Highcharts.Chart#getSVG
  1168. *
  1169. * @param {Highcharts.Options} [chartOptions]
  1170. * Additional chart options for the generated SVG representation. For
  1171. * collections like `xAxis`, `yAxis` or `series`, the additional
  1172. * options is either merged in to the original item of the same
  1173. * `id`, or to the first item if a common id is not found.
  1174. *
  1175. * @return {string}
  1176. * The SVG representation of the rendered chart.
  1177. *
  1178. * @fires Highcharts.Chart#event:getSVG
  1179. *
  1180. * @requires modules/exporting
  1181. */
  1182. getSVG: function (chartOptions) {
  1183. var chart = this, chartCopy, sandbox, svg, seriesOptions, sourceWidth, sourceHeight, cssWidth, cssHeight,
  1184. // Copy the options and add extra options
  1185. options = merge(chart.options, chartOptions);
  1186. // Use userOptions to make the options chain in series right (#3881)
  1187. options.plotOptions = merge(chart.userOptions.plotOptions, chartOptions && chartOptions.plotOptions);
  1188. // ... and likewise with time, avoid that undefined time properties are
  1189. // merged over legacy global time options
  1190. options.time = merge(chart.userOptions.time, chartOptions && chartOptions.time);
  1191. // create a sandbox where a new chart will be generated
  1192. sandbox = createElement('div', null, {
  1193. position: 'absolute',
  1194. top: '-9999em',
  1195. width: chart.chartWidth + 'px',
  1196. height: chart.chartHeight + 'px'
  1197. }, doc.body);
  1198. // get the source size
  1199. cssWidth = chart.renderTo.style.width;
  1200. cssHeight = chart.renderTo.style.height;
  1201. sourceWidth = options.exporting.sourceWidth ||
  1202. options.chart.width ||
  1203. (/px$/.test(cssWidth) && parseInt(cssWidth, 10)) ||
  1204. (options.isGantt ? 800 : 600);
  1205. sourceHeight = options.exporting.sourceHeight ||
  1206. options.chart.height ||
  1207. (/px$/.test(cssHeight) && parseInt(cssHeight, 10)) ||
  1208. 400;
  1209. // override some options
  1210. extend(options.chart, {
  1211. animation: false,
  1212. renderTo: sandbox,
  1213. forExport: true,
  1214. renderer: 'SVGRenderer',
  1215. width: sourceWidth,
  1216. height: sourceHeight
  1217. });
  1218. options.exporting.enabled = false; // hide buttons in print
  1219. delete options.data; // #3004
  1220. // prepare for replicating the chart
  1221. options.series = [];
  1222. chart.series.forEach(function (serie) {
  1223. seriesOptions = merge(serie.userOptions, {
  1224. animation: false,
  1225. enableMouseTracking: false,
  1226. showCheckbox: false,
  1227. visible: serie.visible
  1228. });
  1229. // Used for the navigator series that has its own option set
  1230. if (!seriesOptions.isInternal) {
  1231. options.series.push(seriesOptions);
  1232. }
  1233. });
  1234. // Assign an internal key to ensure a one-to-one mapping (#5924)
  1235. chart.axes.forEach(function (axis) {
  1236. if (!axis.userOptions.internalKey) { // #6444
  1237. axis.userOptions.internalKey = H.uniqueKey();
  1238. }
  1239. });
  1240. // generate the chart copy
  1241. chartCopy = new H.Chart(options, chart.callback);
  1242. // Axis options and series options (#2022, #3900, #5982)
  1243. if (chartOptions) {
  1244. ['xAxis', 'yAxis', 'series'].forEach(function (coll) {
  1245. var collOptions = {};
  1246. if (chartOptions[coll]) {
  1247. collOptions[coll] = chartOptions[coll];
  1248. chartCopy.update(collOptions);
  1249. }
  1250. });
  1251. }
  1252. // Reflect axis extremes in the export (#5924)
  1253. chart.axes.forEach(function (axis) {
  1254. var axisCopy = H.find(chartCopy.axes, function (copy) {
  1255. return copy.options.internalKey ===
  1256. axis.userOptions.internalKey;
  1257. }), extremes = axis.getExtremes(), userMin = extremes.userMin, userMax = extremes.userMax;
  1258. if (axisCopy &&
  1259. ((typeof userMin !== 'undefined' &&
  1260. userMin !== axisCopy.min) || (typeof userMax !== 'undefined' &&
  1261. userMax !== axisCopy.max))) {
  1262. axisCopy.setExtremes(userMin, userMax, true, false);
  1263. }
  1264. });
  1265. // Get the SVG from the container's innerHTML
  1266. svg = chartCopy.getChartHTML();
  1267. fireEvent(this, 'getSVG', { chartCopy: chartCopy });
  1268. svg = chart.sanitizeSVG(svg, options);
  1269. // free up memory
  1270. options = null;
  1271. chartCopy.destroy();
  1272. discardElement(sandbox);
  1273. return svg;
  1274. },
  1275. /**
  1276. * @private
  1277. * @function Highcharts.Chart#getSVGForExport
  1278. * @param {Highcharts.ExportingOptions} options
  1279. * @param {Highcharts.Options} chartOptions
  1280. * @return {string}
  1281. * @requires modules/exporting
  1282. */
  1283. getSVGForExport: function (options, chartOptions) {
  1284. var chartExportingOptions = this.options.exporting;
  1285. return this.getSVG(merge({ chart: { borderRadius: 0 } }, chartExportingOptions.chartOptions, chartOptions, {
  1286. exporting: {
  1287. sourceWidth: ((options && options.sourceWidth) ||
  1288. chartExportingOptions.sourceWidth),
  1289. sourceHeight: ((options && options.sourceHeight) ||
  1290. chartExportingOptions.sourceHeight)
  1291. }
  1292. }));
  1293. },
  1294. /**
  1295. * Get the default file name used for exported charts. By default it creates
  1296. * a file name based on the chart title.
  1297. *
  1298. * @function Highcharts.Chart#getFilename
  1299. *
  1300. * @return {string} A file name without extension.
  1301. *
  1302. * @requires modules/exporting
  1303. */
  1304. getFilename: function () {
  1305. var s = this.userOptions.title && this.userOptions.title.text, filename = this.options.exporting.filename;
  1306. if (filename) {
  1307. return filename.replace(/\//g, '-');
  1308. }
  1309. if (typeof s === 'string') {
  1310. filename = s
  1311. .toLowerCase()
  1312. .replace(/<\/?[^>]+(>|$)/g, '') // strip HTML tags
  1313. .replace(/[\s_]+/g, '-')
  1314. .replace(/[^a-z0-9\-]/g, '') // preserve only latin
  1315. .replace(/^[\-]+/g, '') // dashes in the start
  1316. .replace(/[\-]+/g, '-') // dashes in a row
  1317. .substr(0, 24)
  1318. .replace(/[\-]+$/g, ''); // dashes in the end;
  1319. }
  1320. if (!filename || filename.length < 5) {
  1321. filename = 'chart';
  1322. }
  1323. return filename;
  1324. },
  1325. /**
  1326. * Exporting module required. Submit an SVG version of the chart to a server
  1327. * along with some parameters for conversion.
  1328. *
  1329. * @sample highcharts/members/chart-exportchart/
  1330. * Export with no options
  1331. * @sample highcharts/members/chart-exportchart-filename/
  1332. * PDF type and custom filename
  1333. * @sample highcharts/members/chart-exportchart-custom-background/
  1334. * Different chart background in export
  1335. * @sample stock/members/chart-exportchart/
  1336. * Export with Highstock
  1337. *
  1338. * @function Highcharts.Chart#exportChart
  1339. *
  1340. * @param {Highcharts.ExportingOptions} exportingOptions
  1341. * Exporting options in addition to those defined in
  1342. * [exporting](https://api.highcharts.com/highcharts/exporting).
  1343. *
  1344. * @param {Highcharts.Options} chartOptions
  1345. * Additional chart options for the exported chart. For example a
  1346. * different background color can be added here, or `dataLabels` for
  1347. * export only.
  1348. *
  1349. * @return {void}
  1350. *
  1351. * @requires modules/exporting
  1352. */
  1353. exportChart: function (exportingOptions, chartOptions) {
  1354. var svg = this.getSVGForExport(exportingOptions, chartOptions);
  1355. // merge the options
  1356. exportingOptions = merge(this.options.exporting, exportingOptions);
  1357. // do the post
  1358. H.post(exportingOptions.url, {
  1359. filename: exportingOptions.filename ? exportingOptions.filename.replace(/\//g, '-') : this.getFilename(),
  1360. type: exportingOptions.type,
  1361. // IE8 fails to post undefined correctly, so use 0
  1362. width: exportingOptions.width || 0,
  1363. scale: exportingOptions.scale,
  1364. svg: svg
  1365. }, exportingOptions.formAttributes);
  1366. },
  1367. /**
  1368. * Move the chart container(s) to another div.
  1369. *
  1370. * @function Highcharts#moveContainers
  1371. *
  1372. * @private
  1373. *
  1374. * @param {Highcharts.HTMLDOMElement} moveTo
  1375. * Move target
  1376. * @return {void}
  1377. */
  1378. moveContainers: function (moveTo) {
  1379. var chart = this;
  1380. (chart.fixedDiv ? // When scrollablePlotArea is active (#9533)
  1381. [chart.fixedDiv, chart.scrollingContainer] :
  1382. [chart.container]).forEach(function (div) {
  1383. moveTo.appendChild(div);
  1384. });
  1385. },
  1386. /**
  1387. * Prepare chart and document before printing a chart.
  1388. *
  1389. * @function Highcharts#beforePrint
  1390. *
  1391. * @private
  1392. *
  1393. * @return {void}
  1394. *
  1395. * @fires Highcharts.Chart#event:beforePrint
  1396. */
  1397. beforePrint: function () {
  1398. var chart = this, body = doc.body, printMaxWidth = chart.options.exporting.printMaxWidth, printReverseInfo = {
  1399. childNodes: body.childNodes,
  1400. origDisplay: [],
  1401. resetParams: void 0
  1402. };
  1403. var handleMaxWidth;
  1404. chart.isPrinting = true;
  1405. chart.pointer.reset(null, 0);
  1406. fireEvent(chart, 'beforePrint');
  1407. // Handle printMaxWidth
  1408. handleMaxWidth = printMaxWidth && chart.chartWidth > printMaxWidth;
  1409. if (handleMaxWidth) {
  1410. printReverseInfo.resetParams = [
  1411. chart.options.chart.width,
  1412. void 0,
  1413. false
  1414. ];
  1415. chart.setSize(printMaxWidth, void 0, false);
  1416. }
  1417. // hide all body content
  1418. [].forEach.call(printReverseInfo.childNodes, function (node, i) {
  1419. if (node.nodeType === 1) {
  1420. printReverseInfo.origDisplay[i] = node.style.display;
  1421. node.style.display = 'none';
  1422. }
  1423. });
  1424. // pull out the chart
  1425. chart.moveContainers(body);
  1426. // Storage details for undo action after printing
  1427. chart.printReverseInfo = printReverseInfo;
  1428. },
  1429. /**
  1430. * Clena up after printing a chart.
  1431. *
  1432. * @function Highcharts#afterPrint
  1433. *
  1434. * @private
  1435. *
  1436. * @param {Highcharts.Chart} chart
  1437. * Chart that was (or suppose to be) printed
  1438. * @return {void}
  1439. *
  1440. * @fires Highcharts.Chart#event:afterPrint
  1441. */
  1442. afterPrint: function () {
  1443. var chart = this;
  1444. if (!chart.printReverseInfo) {
  1445. return void 0;
  1446. }
  1447. var childNodes = chart.printReverseInfo.childNodes, origDisplay = chart.printReverseInfo.origDisplay, resetParams = chart.printReverseInfo.resetParams;
  1448. // put the chart back in
  1449. chart.moveContainers(chart.renderTo);
  1450. // restore all body content
  1451. [].forEach.call(childNodes, function (node, i) {
  1452. if (node.nodeType === 1) {
  1453. node.style.display = (origDisplay[i] || '');
  1454. }
  1455. });
  1456. chart.isPrinting = false;
  1457. // Reset printMaxWidth
  1458. if (resetParams) {
  1459. chart.setSize.apply(chart, resetParams);
  1460. }
  1461. delete chart.printReverseInfo;
  1462. delete H.printingChart;
  1463. fireEvent(chart, 'afterPrint');
  1464. },
  1465. /**
  1466. * Exporting module required. Clears away other elements in the page and
  1467. * prints the chart as it is displayed. By default, when the exporting
  1468. * module is enabled, a context button with a drop down menu in the upper
  1469. * right corner accesses this function.
  1470. *
  1471. * @sample highcharts/members/chart-print/
  1472. * Print from a HTML button
  1473. *
  1474. * @function Highcharts.Chart#print
  1475. *
  1476. * @return {void}
  1477. *
  1478. * @fires Highcharts.Chart#event:beforePrint
  1479. * @fires Highcharts.Chart#event:afterPrint
  1480. *
  1481. * @requires modules/exporting
  1482. */
  1483. print: function () {
  1484. var chart = this;
  1485. if (chart.isPrinting) { // block the button while in printing mode
  1486. return;
  1487. }
  1488. H.printingChart = chart;
  1489. if (!H.isSafari) {
  1490. chart.beforePrint();
  1491. }
  1492. // Give the browser time to draw WebGL content, an issue that randomly
  1493. // appears (at least) in Chrome ~67 on the Mac (#8708).
  1494. setTimeout(function () {
  1495. win.focus(); // #1510
  1496. win.print();
  1497. // allow the browser to prepare before reverting
  1498. if (!H.isSafari) {
  1499. setTimeout(function () {
  1500. chart.afterPrint();
  1501. }, 1000);
  1502. }
  1503. }, 1);
  1504. },
  1505. /**
  1506. * Display a popup menu for choosing the export type.
  1507. *
  1508. * @private
  1509. * @function Highcharts.Chart#contextMenu
  1510. * @param {string} className
  1511. * An identifier for the menu.
  1512. * @param {Array<string|Highcharts.ExportingMenuObject>} items
  1513. * A collection with text and onclicks for the items.
  1514. * @param {number} x
  1515. * The x position of the opener button
  1516. * @param {number} y
  1517. * The y position of the opener button
  1518. * @param {number} width
  1519. * The width of the opener button
  1520. * @param {number} height
  1521. * The height of the opener button
  1522. * @return {void}
  1523. * @requires modules/exporting
  1524. */
  1525. contextMenu: function (className, items, x, y, width, height, button) {
  1526. var chart = this, navOptions = chart.options.navigation, chartWidth = chart.chartWidth, chartHeight = chart.chartHeight, cacheName = 'cache-' + className, menu = chart[cacheName], menuPadding = Math.max(width, height), // for mouse leave detection
  1527. innerMenu, menuStyle;
  1528. // create the menu only the first time
  1529. if (!menu) {
  1530. // create a HTML element above the SVG
  1531. chart.exportContextMenu = chart[cacheName] = menu =
  1532. createElement('div', {
  1533. className: className
  1534. }, {
  1535. position: 'absolute',
  1536. zIndex: 1000,
  1537. padding: menuPadding + 'px',
  1538. pointerEvents: 'auto'
  1539. }, chart.fixedDiv || chart.container);
  1540. innerMenu = createElement('ul', { className: 'highcharts-menu' }, {
  1541. listStyle: 'none',
  1542. margin: 0,
  1543. padding: 0
  1544. }, menu);
  1545. // Presentational CSS
  1546. if (!chart.styledMode) {
  1547. css(innerMenu, extend({
  1548. MozBoxShadow: '3px 3px 10px #888',
  1549. WebkitBoxShadow: '3px 3px 10px #888',
  1550. boxShadow: '3px 3px 10px #888'
  1551. }, navOptions.menuStyle));
  1552. }
  1553. // hide on mouse out
  1554. menu.hideMenu = function () {
  1555. css(menu, { display: 'none' });
  1556. if (button) {
  1557. button.setState(0);
  1558. }
  1559. chart.openMenu = false;
  1560. css(chart.renderTo, { overflow: 'hidden' }); // #10361
  1561. H.clearTimeout(menu.hideTimer);
  1562. fireEvent(chart, 'exportMenuHidden');
  1563. };
  1564. // Hide the menu some time after mouse leave (#1357)
  1565. chart.exportEvents.push(addEvent(menu, 'mouseleave', function () {
  1566. menu.hideTimer = win.setTimeout(menu.hideMenu, 500);
  1567. }), addEvent(menu, 'mouseenter', function () {
  1568. H.clearTimeout(menu.hideTimer);
  1569. }),
  1570. // Hide it on clicking or touching outside the menu (#2258,
  1571. // #2335, #2407)
  1572. addEvent(doc, 'mouseup', function (e) {
  1573. if (!chart.pointer.inClass(e.target, className)) {
  1574. menu.hideMenu();
  1575. }
  1576. }), addEvent(menu, 'click', function () {
  1577. if (chart.openMenu) {
  1578. menu.hideMenu();
  1579. }
  1580. }));
  1581. // create the items
  1582. items.forEach(function (item) {
  1583. if (typeof item === 'string') {
  1584. item = chart.options.exporting
  1585. .menuItemDefinitions[item];
  1586. }
  1587. if (isObject(item, true)) {
  1588. var element;
  1589. if (item.separator) {
  1590. element = createElement('hr', null, null, innerMenu);
  1591. }
  1592. else {
  1593. element = createElement('li', {
  1594. className: 'highcharts-menu-item',
  1595. onclick: function (e) {
  1596. if (e) { // IE7
  1597. e.stopPropagation();
  1598. }
  1599. menu.hideMenu();
  1600. if (item.onclick) {
  1601. item.onclick
  1602. .apply(chart, arguments);
  1603. }
  1604. },
  1605. innerHTML: (item.text ||
  1606. chart.options.lang[item.textKey])
  1607. }, null, innerMenu);
  1608. if (!chart.styledMode) {
  1609. element.onmouseover = function () {
  1610. css(this, navOptions.menuItemHoverStyle);
  1611. };
  1612. element.onmouseout = function () {
  1613. css(this, navOptions.menuItemStyle);
  1614. };
  1615. css(element, extend({
  1616. cursor: 'pointer'
  1617. }, navOptions.menuItemStyle));
  1618. }
  1619. }
  1620. // Keep references to menu divs to be able to destroy them
  1621. chart.exportDivElements.push(element);
  1622. }
  1623. });
  1624. // Keep references to menu and innerMenu div to be able to destroy
  1625. // them
  1626. chart.exportDivElements.push(innerMenu, menu);
  1627. chart.exportMenuWidth = menu.offsetWidth;
  1628. chart.exportMenuHeight = menu.offsetHeight;
  1629. }
  1630. menuStyle = { display: 'block' };
  1631. // if outside right, right align it
  1632. if (x + chart.exportMenuWidth > chartWidth) {
  1633. menuStyle.right = (chartWidth - x - width - menuPadding) + 'px';
  1634. }
  1635. else {
  1636. menuStyle.left = (x - menuPadding) + 'px';
  1637. }
  1638. // if outside bottom, bottom align it
  1639. if (y + height + chart.exportMenuHeight > chartHeight &&
  1640. button.alignOptions.verticalAlign !== 'top') {
  1641. menuStyle.bottom = (chartHeight - y - menuPadding) + 'px';
  1642. }
  1643. else {
  1644. menuStyle.top = (y + height - menuPadding) + 'px';
  1645. }
  1646. css(menu, menuStyle);
  1647. css(chart.renderTo, { overflow: '' }); // #10361
  1648. chart.openMenu = true;
  1649. fireEvent(chart, 'exportMenuShown');
  1650. },
  1651. /**
  1652. * Add the export button to the chart, with options.
  1653. *
  1654. * @private
  1655. * @function Highcharts.Chart#addButton
  1656. * @param {Highcharts.NavigationButtonOptions} options
  1657. * @return {void}
  1658. * @requires modules/exporting
  1659. */
  1660. addButton: function (options) {
  1661. var chart = this, renderer = chart.renderer, btnOptions = merge(chart.options.navigation.buttonOptions, options), onclick = btnOptions.onclick, menuItems = btnOptions.menuItems, symbol, button, symbolSize = btnOptions.symbolSize || 12;
  1662. if (!chart.btnCount) {
  1663. chart.btnCount = 0;
  1664. }
  1665. // Keeps references to the button elements
  1666. if (!chart.exportDivElements) {
  1667. chart.exportDivElements = [];
  1668. chart.exportSVGElements = [];
  1669. }
  1670. if (btnOptions.enabled === false) {
  1671. return;
  1672. }
  1673. var attr = btnOptions.theme, states = attr.states, hover = states && states.hover, select = states && states.select, callback;
  1674. if (!chart.styledMode) {
  1675. attr.fill = pick(attr.fill, '#ffffff');
  1676. attr.stroke = pick(attr.stroke, 'none');
  1677. }
  1678. delete attr.states;
  1679. if (onclick) {
  1680. callback = function (e) {
  1681. if (e) {
  1682. e.stopPropagation();
  1683. }
  1684. onclick.call(chart, e);
  1685. };
  1686. }
  1687. else if (menuItems) {
  1688. callback = function (e) {
  1689. // consistent with onclick call (#3495)
  1690. if (e) {
  1691. e.stopPropagation();
  1692. }
  1693. chart.contextMenu(button.menuClassName, menuItems, button.translateX, button.translateY, button.width, button.height, button);
  1694. button.setState(2);
  1695. };
  1696. }
  1697. if (btnOptions.text && btnOptions.symbol) {
  1698. attr.paddingLeft = pick(attr.paddingLeft, 25);
  1699. }
  1700. else if (!btnOptions.text) {
  1701. extend(attr, {
  1702. width: btnOptions.width,
  1703. height: btnOptions.height,
  1704. padding: 0
  1705. });
  1706. }
  1707. if (!chart.styledMode) {
  1708. attr['stroke-linecap'] = 'round';
  1709. attr.fill = pick(attr.fill, '#ffffff');
  1710. attr.stroke = pick(attr.stroke, 'none');
  1711. }
  1712. button = renderer
  1713. .button(btnOptions.text, 0, 0, callback, attr, hover, select)
  1714. .addClass(options.className)
  1715. .attr({
  1716. title: pick(chart.options.lang[btnOptions._titleKey || btnOptions.titleKey], '')
  1717. });
  1718. button.menuClassName = (options.menuClassName ||
  1719. 'highcharts-menu-' + chart.btnCount++);
  1720. if (btnOptions.symbol) {
  1721. symbol = renderer
  1722. .symbol(btnOptions.symbol, btnOptions.symbolX - (symbolSize / 2), btnOptions.symbolY - (symbolSize / 2), symbolSize, symbolSize
  1723. // If symbol is an image, scale it (#7957)
  1724. , {
  1725. width: symbolSize,
  1726. height: symbolSize
  1727. })
  1728. .addClass('highcharts-button-symbol')
  1729. .attr({
  1730. zIndex: 1
  1731. })
  1732. .add(button);
  1733. if (!chart.styledMode) {
  1734. symbol.attr({
  1735. stroke: btnOptions.symbolStroke,
  1736. fill: btnOptions.symbolFill,
  1737. 'stroke-width': btnOptions.symbolStrokeWidth || 1
  1738. });
  1739. }
  1740. }
  1741. button
  1742. .add(chart.exportingGroup)
  1743. .align(extend(btnOptions, {
  1744. width: button.width,
  1745. x: pick(btnOptions.x, chart.buttonOffset) // #1654
  1746. }), true, 'spacingBox');
  1747. chart.buttonOffset += ((button.width + btnOptions.buttonSpacing) *
  1748. (btnOptions.align === 'right' ? -1 : 1));
  1749. chart.exportSVGElements.push(button, symbol);
  1750. },
  1751. /**
  1752. * Destroy the export buttons.
  1753. * @private
  1754. * @function Highcharts.Chart#destroyExport
  1755. * @param {global.Event} [e]
  1756. * @return {void}
  1757. * @requires modules/exporting
  1758. */
  1759. destroyExport: function (e) {
  1760. var chart = e ? e.target : this, exportSVGElements = chart.exportSVGElements, exportDivElements = chart.exportDivElements, exportEvents = chart.exportEvents, cacheName;
  1761. // Destroy the extra buttons added
  1762. if (exportSVGElements) {
  1763. exportSVGElements.forEach(function (elem, i) {
  1764. // Destroy and null the svg elements
  1765. if (elem) { // #1822
  1766. elem.onclick = elem.ontouchstart = null;
  1767. cacheName = 'cache-' + elem.menuClassName;
  1768. if (chart[cacheName]) {
  1769. delete chart[cacheName];
  1770. }
  1771. chart.exportSVGElements[i] = elem.destroy();
  1772. }
  1773. });
  1774. exportSVGElements.length = 0;
  1775. }
  1776. // Destroy the exporting group
  1777. if (chart.exportingGroup) {
  1778. chart.exportingGroup.destroy();
  1779. delete chart.exportingGroup;
  1780. }
  1781. // Destroy the divs for the menu
  1782. if (exportDivElements) {
  1783. exportDivElements.forEach(function (elem, i) {
  1784. // Remove the event handler
  1785. H.clearTimeout(elem.hideTimer); // #5427
  1786. removeEvent(elem, 'mouseleave');
  1787. // Remove inline events
  1788. chart.exportDivElements[i] =
  1789. elem.onmouseout =
  1790. elem.onmouseover =
  1791. elem.ontouchstart =
  1792. elem.onclick = null;
  1793. // Destroy the div by moving to garbage bin
  1794. discardElement(elem);
  1795. });
  1796. exportDivElements.length = 0;
  1797. }
  1798. if (exportEvents) {
  1799. exportEvents.forEach(function (unbind) {
  1800. unbind();
  1801. });
  1802. exportEvents.length = 0;
  1803. }
  1804. }
  1805. /* eslint-enable no-invalid-this, valid-jsdoc */
  1806. });
  1807. // These ones are translated to attributes rather than styles
  1808. SVGRenderer.prototype.inlineToAttributes = [
  1809. 'fill',
  1810. 'stroke',
  1811. 'strokeLinecap',
  1812. 'strokeLinejoin',
  1813. 'strokeWidth',
  1814. 'textAnchor',
  1815. 'x',
  1816. 'y'
  1817. ];
  1818. // These CSS properties are not inlined. Remember camelCase.
  1819. SVGRenderer.prototype.inlineBlacklist = [
  1820. /-/,
  1821. /^(clipPath|cssText|d|height|width)$/,
  1822. /^font$/,
  1823. /[lL]ogical(Width|Height)$/,
  1824. /perspective/,
  1825. /TapHighlightColor/,
  1826. /^transition/,
  1827. /^length$/ // #7700
  1828. // /^text (border|color|cursor|height|webkitBorder)/
  1829. ];
  1830. SVGRenderer.prototype.unstyledElements = [
  1831. 'clipPath',
  1832. 'defs',
  1833. 'desc'
  1834. ];
  1835. /**
  1836. * Analyze inherited styles from stylesheets and add them inline
  1837. *
  1838. * @private
  1839. * @function Highcharts.Chart#inlineStyles
  1840. * @return {void}
  1841. *
  1842. * @todo: What are the border styles for text about? In general, text has a lot
  1843. * of properties.
  1844. * @todo: Make it work with IE9 and IE10.
  1845. *
  1846. * @requires modules/exporting
  1847. */
  1848. Chart.prototype.inlineStyles = function () {
  1849. var renderer = this.renderer, inlineToAttributes = renderer.inlineToAttributes, blacklist = renderer.inlineBlacklist, whitelist = renderer.inlineWhitelist, // For IE
  1850. unstyledElements = renderer.unstyledElements, defaultStyles = {}, dummySVG, iframe, iframeDoc;
  1851. // Create an iframe where we read default styles without pollution from this
  1852. // body
  1853. iframe = doc.createElement('iframe');
  1854. css(iframe, {
  1855. width: '1px',
  1856. height: '1px',
  1857. visibility: 'hidden'
  1858. });
  1859. doc.body.appendChild(iframe);
  1860. iframeDoc = iframe.contentWindow.document;
  1861. iframeDoc.open();
  1862. iframeDoc.write('<svg xmlns="http://www.w3.org/2000/svg"></svg>');
  1863. iframeDoc.close();
  1864. /**
  1865. * Make hyphenated property names out of camelCase
  1866. * @private
  1867. * @param {string} prop
  1868. * Property name in camelCase
  1869. * @return {string}
  1870. * Hyphenated property name
  1871. */
  1872. function hyphenate(prop) {
  1873. return prop.replace(/([A-Z])/g, function (a, b) {
  1874. return '-' + b.toLowerCase();
  1875. });
  1876. }
  1877. /**
  1878. * Call this on all elements and recurse to children
  1879. * @private
  1880. * @param {Highcharts.HTMLDOMElement} node
  1881. * Element child
  1882. * @return {void}
  1883. */
  1884. function recurse(node) {
  1885. var styles, parentStyles, cssText = '', dummy, styleAttr, blacklisted, whitelisted, i;
  1886. /**
  1887. * Check computed styles and whether they are in the white/blacklist for
  1888. * styles or atttributes.
  1889. * @private
  1890. * @param {string} val
  1891. * Style value
  1892. * @param {string} prop
  1893. * Style property name
  1894. * @return {void}
  1895. */
  1896. function filterStyles(val, prop) {
  1897. // Check against whitelist & blacklist
  1898. blacklisted = whitelisted = false;
  1899. if (whitelist) {
  1900. // Styled mode in IE has a whitelist instead.
  1901. // Exclude all props not in this list.
  1902. i = whitelist.length;
  1903. while (i-- && !whitelisted) {
  1904. whitelisted = whitelist[i].test(prop);
  1905. }
  1906. blacklisted = !whitelisted;
  1907. }
  1908. // Explicitly remove empty transforms
  1909. if (prop === 'transform' && val === 'none') {
  1910. blacklisted = true;
  1911. }
  1912. i = blacklist.length;
  1913. while (i-- && !blacklisted) {
  1914. blacklisted = (blacklist[i].test(prop) ||
  1915. typeof val === 'function');
  1916. }
  1917. if (!blacklisted) {
  1918. // If parent node has the same style, it gets inherited, no need
  1919. // to inline it. Top-level props should be diffed against parent
  1920. // (#7687).
  1921. if ((parentStyles[prop] !== val || node.nodeName === 'svg') &&
  1922. defaultStyles[node.nodeName][prop] !== val) {
  1923. // Attributes
  1924. if (inlineToAttributes.indexOf(prop) !== -1) {
  1925. node.setAttribute(hyphenate(prop), val);
  1926. // Styles
  1927. }
  1928. else {
  1929. cssText += hyphenate(prop) + ':' + val + ';';
  1930. }
  1931. }
  1932. }
  1933. }
  1934. if (node.nodeType === 1 &&
  1935. unstyledElements.indexOf(node.nodeName) === -1) {
  1936. styles = win.getComputedStyle(node, null);
  1937. parentStyles = node.nodeName === 'svg' ?
  1938. {} :
  1939. win.getComputedStyle(node.parentNode, null);
  1940. // Get default styles from the browser so that we don't have to add
  1941. // these
  1942. if (!defaultStyles[node.nodeName]) {
  1943. /*
  1944. if (!dummySVG) {
  1945. dummySVG = doc.createElementNS(H.SVG_NS, 'svg');
  1946. dummySVG.setAttribute('version', '1.1');
  1947. doc.body.appendChild(dummySVG);
  1948. }
  1949. */
  1950. dummySVG = iframeDoc.getElementsByTagName('svg')[0];
  1951. dummy = iframeDoc.createElementNS(node.namespaceURI, node.nodeName);
  1952. dummySVG.appendChild(dummy);
  1953. // Copy, so we can remove the node
  1954. defaultStyles[node.nodeName] = merge(win.getComputedStyle(dummy, null));
  1955. // Remove default fill, otherwise text disappears when exported
  1956. if (node.nodeName === 'text') {
  1957. delete defaultStyles.text.fill;
  1958. }
  1959. dummySVG.removeChild(dummy);
  1960. }
  1961. // Loop through all styles and add them inline if they are ok
  1962. if (isFirefoxBrowser || isMSBrowser) {
  1963. // Some browsers put lots of styles on the prototype
  1964. for (var p in styles) { // eslint-disable-line guard-for-in
  1965. filterStyles(styles[p], p);
  1966. }
  1967. }
  1968. else {
  1969. objectEach(styles, filterStyles);
  1970. }
  1971. // Apply styles
  1972. if (cssText) {
  1973. styleAttr = node.getAttribute('style');
  1974. node.setAttribute('style', (styleAttr ? styleAttr + ';' : '') + cssText);
  1975. }
  1976. // Set default stroke width (needed at least for IE)
  1977. if (node.nodeName === 'svg') {
  1978. node.setAttribute('stroke-width', '1px');
  1979. }
  1980. if (node.nodeName === 'text') {
  1981. return;
  1982. }
  1983. // Recurse
  1984. [].forEach.call(node.children || node.childNodes, recurse);
  1985. }
  1986. }
  1987. /**
  1988. * Remove the dummy objects used to get defaults
  1989. * @private
  1990. * @return {void}
  1991. */
  1992. function tearDown() {
  1993. dummySVG.parentNode.removeChild(dummySVG);
  1994. }
  1995. recurse(this.container.querySelector('svg'));
  1996. tearDown();
  1997. };
  1998. symbols.menu = function (x, y, width, height) {
  1999. var arr = [
  2000. 'M', x, y + 2.5,
  2001. 'L', x + width, y + 2.5,
  2002. 'M', x, y + height / 2 + 0.5,
  2003. 'L', x + width, y + height / 2 + 0.5,
  2004. 'M', x, y + height - 1.5,
  2005. 'L', x + width, y + height - 1.5
  2006. ];
  2007. return arr;
  2008. };
  2009. symbols.menuball = function (x, y, width, height) {
  2010. var path = [], h = (height / 3) - 2;
  2011. path = path.concat(this.circle(width - h, y, h, h), this.circle(width - h, y + h + 4, h, h), this.circle(width - h, y + 2 * (h + 4), h, h));
  2012. return path;
  2013. };
  2014. /**
  2015. * Add the buttons on chart load
  2016. * @private
  2017. * @function Highcharts.Chart#renderExporting
  2018. * @return {void}
  2019. * @requires modules/exporting
  2020. */
  2021. Chart.prototype.renderExporting = function () {
  2022. var chart = this, exportingOptions = chart.options.exporting, buttons = exportingOptions.buttons, isDirty = chart.isDirtyExporting || !chart.exportSVGElements;
  2023. chart.buttonOffset = 0;
  2024. if (chart.isDirtyExporting) {
  2025. chart.destroyExport();
  2026. }
  2027. if (isDirty && exportingOptions.enabled !== false) {
  2028. chart.exportEvents = [];
  2029. chart.exportingGroup = chart.exportingGroup ||
  2030. chart.renderer.g('exporting-group').attr({
  2031. zIndex: 3 // #4955, // #8392
  2032. }).add();
  2033. objectEach(buttons, function (button) {
  2034. chart.addButton(button);
  2035. });
  2036. chart.isDirtyExporting = false;
  2037. }
  2038. // Destroy the export elements at chart destroy
  2039. addEvent(chart, 'destroy', chart.destroyExport);
  2040. };
  2041. /* eslint-disable no-invalid-this */
  2042. // Add update methods to handle chart.update and chart.exporting.update and
  2043. // chart.navigation.update. These must be added to the chart instance rather
  2044. // than the Chart prototype in order to use the chart instance inside the update
  2045. // function.
  2046. addEvent(Chart, 'init', function () {
  2047. var chart = this;
  2048. /**
  2049. * @private
  2050. * @param {"exporting"|"navigation"} prop
  2051. * Property name in option root
  2052. * @param {Highcharts.ExportingOptions|Highcharts.NavigationOptions} options
  2053. * Options to update
  2054. * @param {boolean} [redraw=true]
  2055. * Whether to redraw
  2056. * @return {void}
  2057. */
  2058. function update(prop, options, redraw) {
  2059. chart.isDirtyExporting = true;
  2060. merge(true, chart.options[prop], options);
  2061. if (pick(redraw, true)) {
  2062. chart.redraw();
  2063. }
  2064. }
  2065. chart.exporting = {
  2066. update: function (options, redraw) {
  2067. update('exporting', options, redraw);
  2068. }
  2069. };
  2070. // Register update() method for navigation. Can not be set the same way as
  2071. // for exporting, because navigation options are shared with bindings which
  2072. // has separate update() logic.
  2073. chartNavigationMixin.addUpdate(function (options, redraw) {
  2074. update('navigation', options, redraw);
  2075. }, chart);
  2076. });
  2077. /* eslint-enable no-invalid-this */
  2078. Chart.prototype.callbacks.push(function (chart) {
  2079. chart.renderExporting();
  2080. addEvent(chart, 'redraw', chart.renderExporting);
  2081. // Uncomment this to see a button directly below the chart, for quick
  2082. // testing of export
  2083. /*
  2084. var button, viewImage, viewSource;
  2085. if (!chart.renderer.forExport) {
  2086. viewImage = function () {
  2087. var div = doc.createElement('div');
  2088. div.innerHTML = chart.getSVGForExport();
  2089. chart.renderTo.parentNode.appendChild(div);
  2090. };
  2091. viewSource = function () {
  2092. var pre = doc.createElement('pre');
  2093. pre.innerHTML = chart.getSVGForExport()
  2094. .replace(/</g, '\n&lt;')
  2095. .replace(/>/g, '&gt;');
  2096. chart.renderTo.parentNode.appendChild(pre);
  2097. };
  2098. viewImage();
  2099. // View SVG Image
  2100. button = doc.createElement('button');
  2101. button.innerHTML = 'View SVG Image';
  2102. chart.renderTo.parentNode.appendChild(button);
  2103. button.onclick = viewImage;
  2104. // View SVG Source
  2105. button = doc.createElement('button');
  2106. button.innerHTML = 'View SVG Source';
  2107. chart.renderTo.parentNode.appendChild(button);
  2108. button.onclick = viewSource;
  2109. }
  2110. //*/
  2111. });
  2112. });
  2113. _registerModule(_modules, 'masters/modules/exporting.src.js', [], function () {
  2114. });
  2115. }));