exporting.src.js 99 KB

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