Exporting.js 70 KB

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