exporting.src.js 101 KB

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