exporting.src.js 102 KB

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