exporting.src.js 100 KB

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