Exporting.js 70 KB

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