Exporting.js 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004
  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 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. // When chart initialized with the table,
  1473. // wrong button text displayed, #14352.
  1474. if (item.textKey === 'viewData' && chart.isDataTableVisible) {
  1475. item.textKey = 'hideData';
  1476. }
  1477. element = createElement('li', {
  1478. className: 'highcharts-menu-item',
  1479. onclick: function (e) {
  1480. if (e) { // IE7
  1481. e.stopPropagation();
  1482. }
  1483. menu.hideMenu();
  1484. if (item.onclick) {
  1485. item.onclick
  1486. .apply(chart, arguments);
  1487. }
  1488. },
  1489. innerHTML: (item.text ||
  1490. chart.options.lang[item.textKey])
  1491. }, null, innerMenu);
  1492. if (!chart.styledMode) {
  1493. element.onmouseover = function () {
  1494. css(this, navOptions.menuItemHoverStyle);
  1495. };
  1496. element.onmouseout = function () {
  1497. css(this, navOptions.menuItemStyle);
  1498. };
  1499. css(element, extend({
  1500. cursor: 'pointer'
  1501. }, navOptions.menuItemStyle));
  1502. }
  1503. }
  1504. // Keep references to menu divs to be able to destroy them
  1505. chart.exportDivElements.push(element);
  1506. }
  1507. });
  1508. // Keep references to menu and innerMenu div to be able to destroy
  1509. // them
  1510. chart.exportDivElements.push(innerMenu, menu);
  1511. chart.exportMenuWidth = menu.offsetWidth;
  1512. chart.exportMenuHeight = menu.offsetHeight;
  1513. }
  1514. menuStyle = { display: 'block' };
  1515. // if outside right, right align it
  1516. if (x + chart.exportMenuWidth > chartWidth) {
  1517. menuStyle.right = (chartWidth - x - width - menuPadding) + 'px';
  1518. }
  1519. else {
  1520. menuStyle.left = (x - menuPadding) + 'px';
  1521. }
  1522. // if outside bottom, bottom align it
  1523. if (y + height + chart.exportMenuHeight > chartHeight &&
  1524. button.alignOptions.verticalAlign !== 'top') {
  1525. menuStyle.bottom = (chartHeight - y - menuPadding) + 'px';
  1526. }
  1527. else {
  1528. menuStyle.top = (y + height - menuPadding) + 'px';
  1529. }
  1530. css(menu, menuStyle);
  1531. css(chart.renderTo, { overflow: '' }); // #10361
  1532. chart.openMenu = true;
  1533. fireEvent(chart, 'exportMenuShown');
  1534. },
  1535. /**
  1536. * Add the export button to the chart, with options.
  1537. *
  1538. * @private
  1539. * @function Highcharts.Chart#addButton
  1540. * @param {Highcharts.NavigationButtonOptions} options
  1541. * @return {void}
  1542. * @requires modules/exporting
  1543. */
  1544. addButton: function (options) {
  1545. 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;
  1546. if (!chart.btnCount) {
  1547. chart.btnCount = 0;
  1548. }
  1549. // Keeps references to the button elements
  1550. if (!chart.exportDivElements) {
  1551. chart.exportDivElements = [];
  1552. chart.exportSVGElements = [];
  1553. }
  1554. if (btnOptions.enabled === false) {
  1555. return;
  1556. }
  1557. var attr = btnOptions.theme, states = attr.states, hover = states && states.hover, select = states && states.select, callback;
  1558. if (!chart.styledMode) {
  1559. attr.fill = pick(attr.fill, '#ffffff');
  1560. attr.stroke = pick(attr.stroke, 'none');
  1561. }
  1562. delete attr.states;
  1563. if (onclick) {
  1564. callback = function (e) {
  1565. if (e) {
  1566. e.stopPropagation();
  1567. }
  1568. onclick.call(chart, e);
  1569. };
  1570. }
  1571. else if (menuItems) {
  1572. callback = function (e) {
  1573. // consistent with onclick call (#3495)
  1574. if (e) {
  1575. e.stopPropagation();
  1576. }
  1577. chart.contextMenu(button.menuClassName, menuItems, button.translateX, button.translateY, button.width, button.height, button);
  1578. button.setState(2);
  1579. };
  1580. }
  1581. if (btnOptions.text && btnOptions.symbol) {
  1582. attr.paddingLeft = pick(attr.paddingLeft, 25);
  1583. }
  1584. else if (!btnOptions.text) {
  1585. extend(attr, {
  1586. width: btnOptions.width,
  1587. height: btnOptions.height,
  1588. padding: 0
  1589. });
  1590. }
  1591. if (!chart.styledMode) {
  1592. attr['stroke-linecap'] = 'round';
  1593. attr.fill = pick(attr.fill, '#ffffff');
  1594. attr.stroke = pick(attr.stroke, 'none');
  1595. }
  1596. button = renderer
  1597. .button(btnOptions.text, 0, 0, callback, attr, hover, select)
  1598. .addClass(options.className)
  1599. .attr({
  1600. title: pick(chart.options.lang[btnOptions._titleKey || btnOptions.titleKey], '')
  1601. });
  1602. button.menuClassName = (options.menuClassName ||
  1603. 'highcharts-menu-' + chart.btnCount++);
  1604. if (btnOptions.symbol) {
  1605. symbol = renderer
  1606. .symbol(btnOptions.symbol, btnOptions.symbolX - (symbolSize / 2), btnOptions.symbolY - (symbolSize / 2), symbolSize, symbolSize
  1607. // If symbol is an image, scale it (#7957)
  1608. , {
  1609. width: symbolSize,
  1610. height: symbolSize
  1611. })
  1612. .addClass('highcharts-button-symbol')
  1613. .attr({
  1614. zIndex: 1
  1615. })
  1616. .add(button);
  1617. if (!chart.styledMode) {
  1618. symbol.attr({
  1619. stroke: btnOptions.symbolStroke,
  1620. fill: btnOptions.symbolFill,
  1621. 'stroke-width': btnOptions.symbolStrokeWidth || 1
  1622. });
  1623. }
  1624. }
  1625. button
  1626. .add(chart.exportingGroup)
  1627. .align(extend(btnOptions, {
  1628. width: button.width,
  1629. x: pick(btnOptions.x, chart.buttonOffset) // #1654
  1630. }), true, 'spacingBox');
  1631. chart.buttonOffset += ((button.width + btnOptions.buttonSpacing) *
  1632. (btnOptions.align === 'right' ? -1 : 1));
  1633. chart.exportSVGElements.push(button, symbol);
  1634. },
  1635. /**
  1636. * Destroy the export buttons.
  1637. * @private
  1638. * @function Highcharts.Chart#destroyExport
  1639. * @param {global.Event} [e]
  1640. * @return {void}
  1641. * @requires modules/exporting
  1642. */
  1643. destroyExport: function (e) {
  1644. var chart = e ? e.target : this, exportSVGElements = chart.exportSVGElements, exportDivElements = chart.exportDivElements, exportEvents = chart.exportEvents, cacheName;
  1645. // Destroy the extra buttons added
  1646. if (exportSVGElements) {
  1647. exportSVGElements.forEach(function (elem, i) {
  1648. // Destroy and null the svg elements
  1649. if (elem) { // #1822
  1650. elem.onclick = elem.ontouchstart = null;
  1651. cacheName = 'cache-' + elem.menuClassName;
  1652. if (chart[cacheName]) {
  1653. delete chart[cacheName];
  1654. }
  1655. chart.exportSVGElements[i] = elem.destroy();
  1656. }
  1657. });
  1658. exportSVGElements.length = 0;
  1659. }
  1660. // Destroy the exporting group
  1661. if (chart.exportingGroup) {
  1662. chart.exportingGroup.destroy();
  1663. delete chart.exportingGroup;
  1664. }
  1665. // Destroy the divs for the menu
  1666. if (exportDivElements) {
  1667. exportDivElements.forEach(function (elem, i) {
  1668. // Remove the event handler
  1669. U.clearTimeout(elem.hideTimer); // #5427
  1670. removeEvent(elem, 'mouseleave');
  1671. // Remove inline events
  1672. chart.exportDivElements[i] =
  1673. elem.onmouseout =
  1674. elem.onmouseover =
  1675. elem.ontouchstart =
  1676. elem.onclick = null;
  1677. // Destroy the div by moving to garbage bin
  1678. discardElement(elem);
  1679. });
  1680. exportDivElements.length = 0;
  1681. }
  1682. if (exportEvents) {
  1683. exportEvents.forEach(function (unbind) {
  1684. unbind();
  1685. });
  1686. exportEvents.length = 0;
  1687. }
  1688. }
  1689. /* eslint-enable no-invalid-this, valid-jsdoc */
  1690. });
  1691. // These ones are translated to attributes rather than styles
  1692. SVGRenderer.prototype.inlineToAttributes = [
  1693. 'fill',
  1694. 'stroke',
  1695. 'strokeLinecap',
  1696. 'strokeLinejoin',
  1697. 'strokeWidth',
  1698. 'textAnchor',
  1699. 'x',
  1700. 'y'
  1701. ];
  1702. // These CSS properties are not inlined. Remember camelCase.
  1703. SVGRenderer.prototype.inlineBlacklist = [
  1704. /-/,
  1705. /^(clipPath|cssText|d|height|width)$/,
  1706. /^font$/,
  1707. /[lL]ogical(Width|Height)$/,
  1708. /perspective/,
  1709. /TapHighlightColor/,
  1710. /^transition/,
  1711. /^length$/ // #7700
  1712. // /^text (border|color|cursor|height|webkitBorder)/
  1713. ];
  1714. SVGRenderer.prototype.unstyledElements = [
  1715. 'clipPath',
  1716. 'defs',
  1717. 'desc'
  1718. ];
  1719. /**
  1720. * Analyze inherited styles from stylesheets and add them inline
  1721. *
  1722. * @private
  1723. * @function Highcharts.Chart#inlineStyles
  1724. * @return {void}
  1725. *
  1726. * @todo: What are the border styles for text about? In general, text has a lot
  1727. * of properties.
  1728. * @todo: Make it work with IE9 and IE10.
  1729. *
  1730. * @requires modules/exporting
  1731. */
  1732. Chart.prototype.inlineStyles = function () {
  1733. var renderer = this.renderer, inlineToAttributes = renderer.inlineToAttributes, blacklist = renderer.inlineBlacklist, whitelist = renderer.inlineWhitelist, // For IE
  1734. unstyledElements = renderer.unstyledElements, defaultStyles = {}, dummySVG, iframe, iframeDoc;
  1735. // Create an iframe where we read default styles without pollution from this
  1736. // body
  1737. iframe = doc.createElement('iframe');
  1738. css(iframe, {
  1739. width: '1px',
  1740. height: '1px',
  1741. visibility: 'hidden'
  1742. });
  1743. doc.body.appendChild(iframe);
  1744. iframeDoc = iframe.contentWindow.document;
  1745. iframeDoc.open();
  1746. iframeDoc.write('<svg xmlns="http://www.w3.org/2000/svg"></svg>');
  1747. iframeDoc.close();
  1748. /**
  1749. * Make hyphenated property names out of camelCase
  1750. * @private
  1751. * @param {string} prop
  1752. * Property name in camelCase
  1753. * @return {string}
  1754. * Hyphenated property name
  1755. */
  1756. function hyphenate(prop) {
  1757. return prop.replace(/([A-Z])/g, function (a, b) {
  1758. return '-' + b.toLowerCase();
  1759. });
  1760. }
  1761. /**
  1762. * Call this on all elements and recurse to children
  1763. * @private
  1764. * @param {Highcharts.HTMLDOMElement} node
  1765. * Element child
  1766. * @return {void}
  1767. */
  1768. function recurse(node) {
  1769. var styles, parentStyles, cssText = '', dummy, styleAttr, blacklisted, whitelisted, i;
  1770. /**
  1771. * Check computed styles and whether they are in the white/blacklist for
  1772. * styles or atttributes.
  1773. * @private
  1774. * @param {string} val
  1775. * Style value
  1776. * @param {string} prop
  1777. * Style property name
  1778. * @return {void}
  1779. */
  1780. function filterStyles(val, prop) {
  1781. // Check against whitelist & blacklist
  1782. blacklisted = whitelisted = false;
  1783. if (whitelist) {
  1784. // Styled mode in IE has a whitelist instead.
  1785. // Exclude all props not in this list.
  1786. i = whitelist.length;
  1787. while (i-- && !whitelisted) {
  1788. whitelisted = whitelist[i].test(prop);
  1789. }
  1790. blacklisted = !whitelisted;
  1791. }
  1792. // Explicitly remove empty transforms
  1793. if (prop === 'transform' && val === 'none') {
  1794. blacklisted = true;
  1795. }
  1796. i = blacklist.length;
  1797. while (i-- && !blacklisted) {
  1798. blacklisted = (blacklist[i].test(prop) ||
  1799. typeof val === 'function');
  1800. }
  1801. if (!blacklisted) {
  1802. // If parent node has the same style, it gets inherited, no need
  1803. // to inline it. Top-level props should be diffed against parent
  1804. // (#7687).
  1805. if ((parentStyles[prop] !== val || node.nodeName === 'svg') &&
  1806. defaultStyles[node.nodeName][prop] !== val) {
  1807. // Attributes
  1808. if (!inlineToAttributes ||
  1809. inlineToAttributes.indexOf(prop) !== -1) {
  1810. if (val) {
  1811. node.setAttribute(hyphenate(prop), val);
  1812. }
  1813. // Styles
  1814. }
  1815. else {
  1816. cssText += hyphenate(prop) + ':' + val + ';';
  1817. }
  1818. }
  1819. }
  1820. }
  1821. if (node.nodeType === 1 &&
  1822. unstyledElements.indexOf(node.nodeName) === -1) {
  1823. styles = win.getComputedStyle(node, null);
  1824. parentStyles = node.nodeName === 'svg' ?
  1825. {} :
  1826. win.getComputedStyle(node.parentNode, null);
  1827. // Get default styles from the browser so that we don't have to add
  1828. // these
  1829. if (!defaultStyles[node.nodeName]) {
  1830. /*
  1831. if (!dummySVG) {
  1832. dummySVG = doc.createElementNS(H.SVG_NS, 'svg');
  1833. dummySVG.setAttribute('version', '1.1');
  1834. doc.body.appendChild(dummySVG);
  1835. }
  1836. */
  1837. dummySVG = iframeDoc.getElementsByTagName('svg')[0];
  1838. dummy = iframeDoc.createElementNS(node.namespaceURI, node.nodeName);
  1839. dummySVG.appendChild(dummy);
  1840. // Copy, so we can remove the node
  1841. defaultStyles[node.nodeName] = merge(win.getComputedStyle(dummy, null));
  1842. // Remove default fill, otherwise text disappears when exported
  1843. if (node.nodeName === 'text') {
  1844. delete defaultStyles.text.fill;
  1845. }
  1846. dummySVG.removeChild(dummy);
  1847. }
  1848. // Loop through all styles and add them inline if they are ok
  1849. if (isFirefoxBrowser || isMSBrowser) {
  1850. // Some browsers put lots of styles on the prototype
  1851. for (var p in styles) { // eslint-disable-line guard-for-in
  1852. filterStyles(styles[p], p);
  1853. }
  1854. }
  1855. else {
  1856. objectEach(styles, filterStyles);
  1857. }
  1858. // Apply styles
  1859. if (cssText) {
  1860. styleAttr = node.getAttribute('style');
  1861. node.setAttribute('style', (styleAttr ? styleAttr + ';' : '') + cssText);
  1862. }
  1863. // Set default stroke width (needed at least for IE)
  1864. if (node.nodeName === 'svg') {
  1865. node.setAttribute('stroke-width', '1px');
  1866. }
  1867. if (node.nodeName === 'text') {
  1868. return;
  1869. }
  1870. // Recurse
  1871. [].forEach.call(node.children || node.childNodes, recurse);
  1872. }
  1873. }
  1874. /**
  1875. * Remove the dummy objects used to get defaults
  1876. * @private
  1877. * @return {void}
  1878. */
  1879. function tearDown() {
  1880. dummySVG.parentNode.remove();
  1881. // Remove trash from DOM that stayed after each exporting
  1882. iframe.remove();
  1883. }
  1884. recurse(this.container.querySelector('svg'));
  1885. tearDown();
  1886. };
  1887. symbols.menu = function (x, y, width, height) {
  1888. var arr = [
  1889. ['M', x, y + 2.5],
  1890. ['L', x + width, y + 2.5],
  1891. ['M', x, y + height / 2 + 0.5],
  1892. ['L', x + width, y + height / 2 + 0.5],
  1893. ['M', x, y + height - 1.5],
  1894. ['L', x + width, y + height - 1.5]
  1895. ];
  1896. return arr;
  1897. };
  1898. symbols.menuball = function (x, y, width, height) {
  1899. var path = [], h = (height / 3) - 2;
  1900. 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));
  1901. return path;
  1902. };
  1903. /**
  1904. * Add the buttons on chart load
  1905. * @private
  1906. * @function Highcharts.Chart#renderExporting
  1907. * @return {void}
  1908. * @requires modules/exporting
  1909. */
  1910. Chart.prototype.renderExporting = function () {
  1911. var chart = this, exportingOptions = chart.options.exporting, buttons = exportingOptions.buttons, isDirty = chart.isDirtyExporting || !chart.exportSVGElements;
  1912. chart.buttonOffset = 0;
  1913. if (chart.isDirtyExporting) {
  1914. chart.destroyExport();
  1915. }
  1916. if (isDirty && exportingOptions.enabled !== false) {
  1917. chart.exportEvents = [];
  1918. chart.exportingGroup = chart.exportingGroup ||
  1919. chart.renderer.g('exporting-group').attr({
  1920. zIndex: 3 // #4955, // #8392
  1921. }).add();
  1922. objectEach(buttons, function (button) {
  1923. chart.addButton(button);
  1924. });
  1925. chart.isDirtyExporting = false;
  1926. }
  1927. // Destroy the export elements at chart destroy
  1928. addEvent(chart, 'destroy', chart.destroyExport);
  1929. };
  1930. /* eslint-disable no-invalid-this */
  1931. // Add update methods to handle chart.update and chart.exporting.update and
  1932. // chart.navigation.update. These must be added to the chart instance rather
  1933. // than the Chart prototype in order to use the chart instance inside the update
  1934. // function.
  1935. addEvent(Chart, 'init', function () {
  1936. var chart = this;
  1937. /**
  1938. * @private
  1939. * @param {"exporting"|"navigation"} prop
  1940. * Property name in option root
  1941. * @param {Highcharts.ExportingOptions|Highcharts.NavigationOptions} options
  1942. * Options to update
  1943. * @param {boolean} [redraw=true]
  1944. * Whether to redraw
  1945. * @return {void}
  1946. */
  1947. function update(prop, options, redraw) {
  1948. chart.isDirtyExporting = true;
  1949. merge(true, chart.options[prop], options);
  1950. if (pick(redraw, true)) {
  1951. chart.redraw();
  1952. }
  1953. }
  1954. chart.exporting = {
  1955. update: function (options, redraw) {
  1956. update('exporting', options, redraw);
  1957. }
  1958. };
  1959. // Register update() method for navigation. Can not be set the same way as
  1960. // for exporting, because navigation options are shared with bindings which
  1961. // has separate update() logic.
  1962. chartNavigationMixin.addUpdate(function (options, redraw) {
  1963. update('navigation', options, redraw);
  1964. }, chart);
  1965. });
  1966. /* eslint-enable no-invalid-this */
  1967. Chart.prototype.callbacks.push(function (chart) {
  1968. chart.renderExporting();
  1969. addEvent(chart, 'redraw', chart.renderExporting);
  1970. // Uncomment this to see a button directly below the chart, for quick
  1971. // testing of export
  1972. /*
  1973. var button, viewImage, viewSource;
  1974. if (!chart.renderer.forExport) {
  1975. viewImage = function () {
  1976. var div = doc.createElement('div');
  1977. div.innerHTML = chart.getSVGForExport();
  1978. chart.renderTo.parentNode.appendChild(div);
  1979. };
  1980. viewSource = function () {
  1981. var pre = doc.createElement('pre');
  1982. pre.innerHTML = chart.getSVGForExport()
  1983. .replace(/</g, '\n&lt;')
  1984. .replace(/>/g, '&gt;');
  1985. chart.renderTo.parentNode.appendChild(pre);
  1986. };
  1987. viewImage();
  1988. // View SVG Image
  1989. button = doc.createElement('button');
  1990. button.innerHTML = 'View SVG Image';
  1991. chart.renderTo.parentNode.appendChild(button);
  1992. button.onclick = viewImage;
  1993. // View SVG Source
  1994. button = doc.createElement('button');
  1995. button.innerHTML = 'View SVG Source';
  1996. chart.renderTo.parentNode.appendChild(button);
  1997. button.onclick = viewSource;
  1998. }
  1999. //*/
  2000. });