exporting.src.js 97 KB

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