exporting.src.js 72 KB

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