drilldown.src.js 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187
  1. /**
  2. * @license Highcharts JS v8.2.2 (2020-10-22)
  3. *
  4. * Highcharts Drilldown module
  5. *
  6. * Author: Torstein Honsi
  7. * License: www.highcharts.com/license
  8. *
  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/drilldown', ['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/Drilldown.js', [_modules['Core/Animation/AnimationUtilities.js'], _modules['Core/Axis/Axis.js'], _modules['Core/Chart/Chart.js'], _modules['Core/Color/Color.js'], _modules['Core/Globals.js'], _modules['Core/Options.js'], _modules['Core/Series/Point.js'], _modules['Core/Renderer/SVG/SVGRenderer.js'], _modules['Core/Axis/Tick.js'], _modules['Core/Utilities.js']], function (A, Axis, Chart, Color, H, O, Point, SVGRenderer, Tick, U) {
  32. /* *
  33. *
  34. * Highcharts Drilldown module
  35. *
  36. * Author: Torstein Honsi
  37. *
  38. * License: www.highcharts.com/license
  39. *
  40. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  41. *
  42. * */
  43. var animObject = A.animObject;
  44. var noop = H.noop;
  45. var defaultOptions = O.defaultOptions;
  46. var addEvent = U.addEvent,
  47. removeEvent = U.removeEvent,
  48. extend = U.extend,
  49. fireEvent = U.fireEvent,
  50. format = U.format,
  51. merge = U.merge,
  52. objectEach = U.objectEach,
  53. pick = U.pick,
  54. syncTimeout = U.syncTimeout;
  55. /**
  56. * Gets fired when a drilldown point is clicked, before the new series is added.
  57. * Note that when clicking a category label to trigger multiple series
  58. * drilldown, one `drilldown` event is triggered per point in the category.
  59. *
  60. * @callback Highcharts.DrilldownCallbackFunction
  61. *
  62. * @param {Highcharts.Chart} this
  63. * The chart where the event occurs.
  64. *
  65. * @param {Highcharts.DrilldownEventObject} e
  66. * The drilldown event.
  67. */
  68. /**
  69. * The event arguments when a drilldown point is clicked.
  70. *
  71. * @interface Highcharts.DrilldownEventObject
  72. */ /**
  73. * If a category label was clicked, which index.
  74. * @name Highcharts.DrilldownEventObject#category
  75. * @type {number|undefined}
  76. */ /**
  77. * The original browser event (usually click) that triggered the drilldown.
  78. * @name Highcharts.DrilldownEventObject#originalEvent
  79. * @type {global.Event|undefined}
  80. */ /**
  81. * Prevents the default behaviour of the event.
  82. * @name Highcharts.DrilldownEventObject#preventDefault
  83. * @type {Function}
  84. */ /**
  85. * The originating point.
  86. * @name Highcharts.DrilldownEventObject#point
  87. * @type {Highcharts.Point}
  88. */ /**
  89. * If a category label was clicked, this array holds all points corresponding to
  90. * the category. Otherwise it is set to false.
  91. * @name Highcharts.DrilldownEventObject#points
  92. * @type {boolean|Array<Highcharts.Point>|undefined}
  93. */ /**
  94. * Options for the new series. If the event is utilized for async drilldown, the
  95. * seriesOptions are not added, but rather loaded async.
  96. * @name Highcharts.DrilldownEventObject#seriesOptions
  97. * @type {Highcharts.SeriesOptionsType|undefined}
  98. */ /**
  99. * The event target.
  100. * @name Highcharts.DrilldownEventObject#target
  101. * @type {Highcharts.Chart}
  102. */ /**
  103. * The event type.
  104. * @name Highcharts.DrilldownEventObject#type
  105. * @type {"drilldown"}
  106. */
  107. /**
  108. * This gets fired after all the series have been drilled up. This is especially
  109. * usefull in a chart with multiple drilldown series.
  110. *
  111. * @callback Highcharts.DrillupAllCallbackFunction
  112. *
  113. * @param {Highcharts.Chart} this
  114. * The chart where the event occurs.
  115. *
  116. * @param {Highcharts.DrillupAllEventObject} e
  117. * The final drillup event.
  118. */
  119. /**
  120. * The event arguments when all the series have been drilled up.
  121. *
  122. * @interface Highcharts.DrillupAllEventObject
  123. */ /**
  124. * Prevents the default behaviour of the event.
  125. * @name Highcharts.DrillupAllEventObject#preventDefault
  126. * @type {Function}
  127. */ /**
  128. * The event target.
  129. * @name Highcharts.DrillupAllEventObject#target
  130. * @type {Highcharts.Chart}
  131. */ /**
  132. * The event type.
  133. * @name Highcharts.DrillupAllEventObject#type
  134. * @type {"drillupall"}
  135. */
  136. /**
  137. * Gets fired when drilling up from a drilldown series.
  138. *
  139. * @callback Highcharts.DrillupCallbackFunction
  140. *
  141. * @param {Highcharts.Chart} this
  142. * The chart where the event occurs.
  143. *
  144. * @param {Highcharts.DrillupEventObject} e
  145. * The drillup event.
  146. */
  147. /**
  148. * The event arguments when drilling up from a drilldown series.
  149. *
  150. * @interface Highcharts.DrillupEventObject
  151. */ /**
  152. * Prevents the default behaviour of the event.
  153. * @name Highcharts.DrillupEventObject#preventDefault
  154. * @type {Function}
  155. */ /**
  156. * Options for the new series.
  157. * @name Highcharts.DrillupEventObject#seriesOptions
  158. * @type {Highcharts.SeriesOptionsType|undefined}
  159. */ /**
  160. * The event target.
  161. * @name Highcharts.DrillupEventObject#target
  162. * @type {Highcharts.Chart}
  163. */ /**
  164. * The event type.
  165. * @name Highcharts.DrillupEventObject#type
  166. * @type {"drillup"}
  167. */
  168. var seriesTypes = H.seriesTypes,
  169. PieSeries = seriesTypes.pie,
  170. ColumnSeries = seriesTypes.column,
  171. ddSeriesId = 1;
  172. // Add language
  173. extend(defaultOptions.lang,
  174. /**
  175. * @optionparent lang
  176. */
  177. {
  178. /**
  179. * The text for the button that appears when drilling down, linking back
  180. * to the parent series. The parent series' name is inserted for
  181. * `{series.name}`.
  182. *
  183. * @since 3.0.8
  184. * @product highcharts highmaps
  185. * @requires modules/drilldown
  186. *
  187. * @private
  188. */
  189. drillUpText: '◁ Back to {series.name}'
  190. });
  191. /**
  192. * Options for drill down, the concept of inspecting increasingly high
  193. * resolution data through clicking on chart items like columns or pie slices.
  194. *
  195. * The drilldown feature requires the drilldown.js file to be loaded,
  196. * found in the modules directory of the download package, or online at
  197. * [code.highcharts.com/modules/drilldown.js
  198. * ](https://code.highcharts.com/modules/drilldown.js).
  199. *
  200. * @product highcharts highmaps
  201. * @requires modules/drilldown
  202. * @optionparent drilldown
  203. * @sample {highcharts} highcharts/series-organization/drilldown
  204. * Organization chart drilldown
  205. */
  206. defaultOptions.drilldown = {
  207. /**
  208. * When this option is false, clicking a single point will drill down
  209. * all points in the same category, equivalent to clicking the X axis
  210. * label.
  211. *
  212. * @sample {highcharts} highcharts/drilldown/allowpointdrilldown-false/
  213. * Don't allow point drilldown
  214. *
  215. * @type {boolean}
  216. * @default true
  217. * @since 4.1.7
  218. * @product highcharts
  219. * @apioption drilldown.allowPointDrilldown
  220. */
  221. /**
  222. * An array of series configurations for the drill down. Each series
  223. * configuration uses the same syntax as the [series](#series) option set.
  224. * These drilldown series are hidden by default. The drilldown series is
  225. * linked to the parent series' point by its `id`.
  226. *
  227. * @type {Array<Highcharts.SeriesOptionsType>}
  228. * @since 3.0.8
  229. * @product highcharts highmaps
  230. * @apioption drilldown.series
  231. */
  232. /**
  233. * Additional styles to apply to the X axis label for a point that
  234. * has drilldown data. By default it is underlined and blue to invite
  235. * to interaction.
  236. *
  237. * In styled mode, active label styles can be set with the
  238. * `.highcharts-drilldown-axis-label` class.
  239. *
  240. * @sample {highcharts} highcharts/drilldown/labels/
  241. * Label styles
  242. *
  243. * @type {Highcharts.CSSObject}
  244. * @default { "cursor": "pointer", "color": "#003399", "fontWeight": "bold", "textDecoration": "underline" }
  245. * @since 3.0.8
  246. * @product highcharts highmaps
  247. */
  248. activeAxisLabelStyle: {
  249. /** @ignore-option */
  250. cursor: 'pointer',
  251. /** @ignore-option */
  252. color: '#003399',
  253. /** @ignore-option */
  254. fontWeight: 'bold',
  255. /** @ignore-option */
  256. textDecoration: 'underline'
  257. },
  258. /**
  259. * Additional styles to apply to the data label of a point that has
  260. * drilldown data. By default it is underlined and blue to invite to
  261. * interaction.
  262. *
  263. * In styled mode, active data label styles can be applied with the
  264. * `.highcharts-drilldown-data-label` class.
  265. *
  266. * @sample {highcharts} highcharts/drilldown/labels/
  267. * Label styles
  268. *
  269. * @type {Highcharts.CSSObject}
  270. * @default { "cursor": "pointer", "color": "#003399", "fontWeight": "bold", "textDecoration": "underline" }
  271. * @since 3.0.8
  272. * @product highcharts highmaps
  273. */
  274. activeDataLabelStyle: {
  275. cursor: 'pointer',
  276. color: '#003399',
  277. fontWeight: 'bold',
  278. textDecoration: 'underline'
  279. },
  280. /**
  281. * Set the animation for all drilldown animations. Animation of a drilldown
  282. * occurs when drilling between a column point and a column series,
  283. * or a pie slice and a full pie series. Drilldown can still be used
  284. * between series and points of different types, but animation will
  285. * not occur.
  286. *
  287. * The animation can either be set as a boolean or a configuration
  288. * object. If `true`, it will use the 'swing' jQuery easing and a duration
  289. * of 500 ms. If used as a configuration object, the following properties
  290. * are supported:
  291. *
  292. * - `duration`: The duration of the animation in milliseconds.
  293. *
  294. * - `easing`: A string reference to an easing function set on the `Math`
  295. * object. See
  296. * [the easing demo](https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/plotoptions/series-animation-easing/).
  297. *
  298. * @type {boolean|Partial<Highcharts.AnimationOptionsObject>}
  299. * @since 3.0.8
  300. * @product highcharts highmaps
  301. */
  302. animation: {
  303. /** @internal */
  304. duration: 500
  305. },
  306. /**
  307. * Options for the drill up button that appears when drilling down on a
  308. * series. The text for the button is defined in
  309. * [lang.drillUpText](#lang.drillUpText).
  310. *
  311. * @sample {highcharts} highcharts/drilldown/drillupbutton/
  312. * Drill up button
  313. * @sample {highmaps} highcharts/drilldown/drillupbutton/
  314. * Drill up button
  315. *
  316. * @since 3.0.8
  317. * @product highcharts highmaps
  318. */
  319. drillUpButton: {
  320. /**
  321. * What box to align the button to. Can be either `plotBox` or
  322. * `spacingBox`.
  323. *
  324. * @type {Highcharts.ButtonRelativeToValue}
  325. * @default plotBox
  326. * @since 3.0.8
  327. * @product highcharts highmaps
  328. * @apioption drilldown.drillUpButton.relativeTo
  329. */
  330. /**
  331. * A collection of attributes for the button. The object takes SVG
  332. * attributes like `fill`, `stroke`, `stroke-width` or `r`, the border
  333. * radius. The theme also supports `style`, a collection of CSS
  334. * properties for the text. Equivalent attributes for the hover state
  335. * are given in `theme.states.hover`.
  336. *
  337. * In styled mode, drill-up button styles can be applied with the
  338. * `.highcharts-drillup-button` class.
  339. *
  340. * @sample {highcharts} highcharts/drilldown/drillupbutton/
  341. * Button theming
  342. * @sample {highmaps} highcharts/drilldown/drillupbutton/
  343. * Button theming
  344. *
  345. * @type {object}
  346. * @since 3.0.8
  347. * @product highcharts highmaps
  348. * @apioption drilldown.drillUpButton.theme
  349. */
  350. /**
  351. * Positioning options for the button within the `relativeTo` box.
  352. * Available properties are `x`, `y`, `align` and `verticalAlign`.
  353. *
  354. * @type {Highcharts.AlignObject}
  355. * @since 3.0.8
  356. * @product highcharts highmaps
  357. */
  358. position: {
  359. /**
  360. * Vertical alignment of the button.
  361. *
  362. * @type {Highcharts.VerticalAlignValue}
  363. * @default top
  364. * @product highcharts highmaps
  365. * @apioption drilldown.drillUpButton.position.verticalAlign
  366. */
  367. /**
  368. * Horizontal alignment.
  369. *
  370. * @type {Highcharts.AlignValue}
  371. */
  372. align: 'right',
  373. /**
  374. * The X offset of the button.
  375. */
  376. x: -10,
  377. /**
  378. * The Y offset of the button.
  379. */
  380. y: 10
  381. }
  382. }
  383. };
  384. /**
  385. * Fires when a drilldown point is clicked, before the new series is added. This
  386. * event is also utilized for async drilldown, where the seriesOptions are not
  387. * added by option, but rather loaded async. Note that when clicking a category
  388. * label to trigger multiple series drilldown, one `drilldown` event is
  389. * triggered per point in the category.
  390. *
  391. * Event arguments:
  392. *
  393. * - `category`: If a category label was clicked, which index.
  394. *
  395. * - `originalEvent`: The original browser event (usually click) that triggered
  396. * the drilldown.
  397. *
  398. * - `point`: The originating point.
  399. *
  400. * - `points`: If a category label was clicked, this array holds all points
  401. * corresponding to the category.
  402. *
  403. * - `seriesOptions`: Options for the new series.
  404. *
  405. * @sample {highcharts} highcharts/drilldown/async/
  406. * Async drilldown
  407. *
  408. * @type {Highcharts.DrilldownCallbackFunction}
  409. * @since 3.0.8
  410. * @product highcharts highmaps
  411. * @context Highcharts.Chart
  412. * @requires modules/drilldown
  413. * @apioption chart.events.drilldown
  414. */
  415. /**
  416. * Fires when drilling up from a drilldown series.
  417. *
  418. * @type {Highcharts.DrillupCallbackFunction}
  419. * @since 3.0.8
  420. * @product highcharts highmaps
  421. * @context Highcharts.Chart
  422. * @requires modules/drilldown
  423. * @apioption chart.events.drillup
  424. */
  425. /**
  426. * In a chart with multiple drilldown series, this event fires after all the
  427. * series have been drilled up.
  428. *
  429. * @type {Highcharts.DrillupAllCallbackFunction}
  430. * @since 4.2.4
  431. * @product highcharts highmaps
  432. * @context Highcharts.Chart
  433. * @requires modules/drilldown
  434. * @apioption chart.events.drillupall
  435. */
  436. /**
  437. * The `id` of a series in the [drilldown.series](#drilldown.series) array to
  438. * use for a drilldown for this point.
  439. *
  440. * @sample {highcharts} highcharts/drilldown/basic/
  441. * Basic drilldown
  442. *
  443. * @type {string}
  444. * @since 3.0.8
  445. * @product highcharts
  446. * @requires modules/drilldown
  447. * @apioption series.line.data.drilldown
  448. */
  449. /**
  450. * A general fadeIn method.
  451. *
  452. * @requires module:modules/drilldown
  453. *
  454. * @function Highcharts.SVGElement#fadeIn
  455. *
  456. * @param {boolean|Partial<Highcharts.AnimationOptionsObject>} [animation]
  457. * The animation options for the element fade.
  458. */
  459. SVGRenderer.prototype.Element.prototype.fadeIn = function (animation) {
  460. this
  461. .attr({
  462. opacity: 0.1,
  463. visibility: 'inherit'
  464. })
  465. .animate({
  466. opacity: pick(this.newOpacity, 1) // newOpacity used in maps
  467. }, animation || {
  468. duration: 250
  469. });
  470. };
  471. /**
  472. * Add a series to the chart as drilldown from a specific point in the parent
  473. * series. This method is used for async drilldown, when clicking a point in a
  474. * series should result in loading and displaying a more high-resolution series.
  475. * When not async, the setup is simpler using the
  476. * [drilldown.series](https://api.highcharts.com/highcharts/drilldown.series)
  477. * options structure.
  478. *
  479. * @sample highcharts/drilldown/async/
  480. * Async drilldown
  481. *
  482. * @function Highcharts.Chart#addSeriesAsDrilldown
  483. *
  484. * @param {Highcharts.Point} point
  485. * The point from which the drilldown will start.
  486. *
  487. * @param {Highcharts.SeriesOptionsType} options
  488. * The series options for the new, detailed series.
  489. */
  490. Chart.prototype.addSeriesAsDrilldown = function (point, options) {
  491. this.addSingleSeriesAsDrilldown(point, options);
  492. this.applyDrilldown();
  493. };
  494. Chart.prototype.addSingleSeriesAsDrilldown = function (point, ddOptions) {
  495. var oldSeries = point.series,
  496. xAxis = oldSeries.xAxis,
  497. yAxis = oldSeries.yAxis,
  498. newSeries,
  499. pointIndex,
  500. levelSeries = [],
  501. levelSeriesOptions = [],
  502. level,
  503. levelNumber,
  504. last,
  505. colorProp;
  506. colorProp = this.styledMode ?
  507. { colorIndex: pick(point.colorIndex, oldSeries.colorIndex) } :
  508. { color: point.color || oldSeries.color };
  509. if (!this.drilldownLevels) {
  510. this.drilldownLevels = [];
  511. }
  512. levelNumber = oldSeries.options._levelNumber || 0;
  513. // See if we can reuse the registered series from last run
  514. last = this.drilldownLevels[this.drilldownLevels.length - 1];
  515. if (last && last.levelNumber !== levelNumber) {
  516. last = void 0;
  517. }
  518. ddOptions = extend(extend({
  519. _ddSeriesId: ddSeriesId++
  520. }, colorProp), ddOptions);
  521. pointIndex = oldSeries.points.indexOf(point);
  522. // Record options for all current series
  523. oldSeries.chart.series.forEach(function (series) {
  524. if (series.xAxis === xAxis && !series.isDrilling) {
  525. series.options._ddSeriesId =
  526. series.options._ddSeriesId || ddSeriesId++;
  527. series.options._colorIndex = series.userOptions._colorIndex;
  528. series.options._levelNumber =
  529. series.options._levelNumber || levelNumber; // #3182
  530. if (last) {
  531. levelSeries = last.levelSeries;
  532. levelSeriesOptions = last.levelSeriesOptions;
  533. }
  534. else {
  535. levelSeries.push(series);
  536. // (#10597)
  537. series.purgedOptions = merge({
  538. _ddSeriesId: series.options._ddSeriesId,
  539. _levelNumber: series.options._levelNumber,
  540. selected: series.options.selected
  541. }, series.userOptions);
  542. levelSeriesOptions.push(series.purgedOptions);
  543. }
  544. }
  545. });
  546. // Add a record of properties for each drilldown level
  547. level = extend({
  548. levelNumber: levelNumber,
  549. seriesOptions: oldSeries.options,
  550. seriesPurgedOptions: oldSeries.purgedOptions,
  551. levelSeriesOptions: levelSeriesOptions,
  552. levelSeries: levelSeries,
  553. shapeArgs: point.shapeArgs,
  554. // no graphic in line series with markers disabled
  555. bBox: point.graphic ? point.graphic.getBBox() : {},
  556. color: point.isNull ?
  557. new Color(colorProp.color).setOpacity(0).get() :
  558. colorProp.color,
  559. lowerSeriesOptions: ddOptions,
  560. pointOptions: oldSeries.options.data[pointIndex],
  561. pointIndex: pointIndex,
  562. oldExtremes: {
  563. xMin: xAxis && xAxis.userMin,
  564. xMax: xAxis && xAxis.userMax,
  565. yMin: yAxis && yAxis.userMin,
  566. yMax: yAxis && yAxis.userMax
  567. },
  568. resetZoomButton: this.resetZoomButton
  569. }, colorProp);
  570. // Push it to the lookup array
  571. this.drilldownLevels.push(level);
  572. // Reset names to prevent extending (#6704)
  573. if (xAxis && xAxis.names) {
  574. xAxis.names.length = 0;
  575. }
  576. newSeries = level.lowerSeries = this.addSeries(ddOptions, false);
  577. newSeries.options._levelNumber = levelNumber + 1;
  578. if (xAxis) {
  579. xAxis.oldPos = xAxis.pos;
  580. xAxis.userMin = xAxis.userMax = null;
  581. yAxis.userMin = yAxis.userMax = null;
  582. }
  583. // Run fancy cross-animation on supported and equal types
  584. if (oldSeries.type === newSeries.type) {
  585. newSeries.animate = newSeries.animateDrilldown || noop;
  586. newSeries.options.animation = true;
  587. }
  588. };
  589. Chart.prototype.applyDrilldown = function () {
  590. var drilldownLevels = this.drilldownLevels,
  591. levelToRemove;
  592. if (drilldownLevels && drilldownLevels.length > 0) { // #3352, async loading
  593. levelToRemove = drilldownLevels[drilldownLevels.length - 1].levelNumber;
  594. this.drilldownLevels.forEach(function (level) {
  595. if (level.levelNumber === levelToRemove) {
  596. level.levelSeries.forEach(function (series) {
  597. // Not removed, not added as part of a multi-series
  598. // drilldown
  599. if (series.options &&
  600. series.options._levelNumber === levelToRemove) {
  601. series.remove(false);
  602. }
  603. });
  604. }
  605. });
  606. }
  607. // We have a reset zoom button. Hide it and detatch it from the chart. It
  608. // is preserved to the layer config above.
  609. if (this.resetZoomButton) {
  610. this.resetZoomButton.hide();
  611. delete this.resetZoomButton;
  612. }
  613. this.pointer.reset();
  614. this.redraw();
  615. this.showDrillUpButton();
  616. fireEvent(this, 'afterDrilldown');
  617. };
  618. Chart.prototype.getDrilldownBackText = function () {
  619. var drilldownLevels = this.drilldownLevels,
  620. lastLevel;
  621. if (drilldownLevels && drilldownLevels.length > 0) { // #3352, async loading
  622. lastLevel = drilldownLevels[drilldownLevels.length - 1];
  623. lastLevel.series = lastLevel.seriesOptions;
  624. return format(this.options.lang.drillUpText, lastLevel);
  625. }
  626. };
  627. Chart.prototype.showDrillUpButton = function () {
  628. var chart = this,
  629. backText = this.getDrilldownBackText(),
  630. buttonOptions = chart.options.drilldown.drillUpButton,
  631. attr,
  632. states;
  633. if (!this.drillUpButton) {
  634. attr = buttonOptions.theme;
  635. states = attr && attr.states;
  636. this.drillUpButton = this.renderer.button(backText, null, null, function () {
  637. chart.drillUp();
  638. }, attr, states && states.hover, states && states.select)
  639. .addClass('highcharts-drillup-button')
  640. .attr({
  641. align: buttonOptions.position.align,
  642. zIndex: 7
  643. })
  644. .add()
  645. .align(buttonOptions.position, false, buttonOptions.relativeTo || 'plotBox');
  646. }
  647. else {
  648. this.drillUpButton.attr({
  649. text: backText
  650. })
  651. .align();
  652. }
  653. };
  654. /**
  655. * When the chart is drilled down to a child series, calling `chart.drillUp()`
  656. * will drill up to the parent series.
  657. *
  658. * @requires modules/drilldown
  659. *
  660. * @function Highcharts.Chart#drillUp
  661. */
  662. Chart.prototype.drillUp = function () {
  663. if (!this.drilldownLevels || this.drilldownLevels.length === 0) {
  664. return;
  665. }
  666. var chart = this,
  667. drilldownLevels = chart.drilldownLevels,
  668. levelNumber = drilldownLevels[drilldownLevels.length - 1].levelNumber,
  669. i = drilldownLevels.length,
  670. chartSeries = chart.series,
  671. seriesI,
  672. level,
  673. oldSeries,
  674. newSeries,
  675. oldExtremes,
  676. addSeries = function (seriesOptions) {
  677. var addedSeries;
  678. chartSeries.forEach(function (series) {
  679. if (series.options._ddSeriesId === seriesOptions._ddSeriesId) {
  680. addedSeries = series;
  681. }
  682. });
  683. addedSeries = addedSeries || chart.addSeries(seriesOptions, false);
  684. if (addedSeries.type === oldSeries.type &&
  685. addedSeries.animateDrillupTo) {
  686. addedSeries.animate = addedSeries.animateDrillupTo;
  687. }
  688. if (seriesOptions === level.seriesPurgedOptions) {
  689. newSeries = addedSeries;
  690. }
  691. };
  692. while (i--) {
  693. level = drilldownLevels[i];
  694. if (level.levelNumber === levelNumber) {
  695. drilldownLevels.pop();
  696. // Get the lower series by reference or id
  697. oldSeries = level.lowerSeries;
  698. if (!oldSeries.chart) { // #2786
  699. seriesI = chartSeries.length; // #2919
  700. while (seriesI--) {
  701. if (chartSeries[seriesI].options.id ===
  702. level.lowerSeriesOptions.id &&
  703. chartSeries[seriesI].options._levelNumber ===
  704. levelNumber + 1) { // #3867
  705. oldSeries = chartSeries[seriesI];
  706. break;
  707. }
  708. }
  709. }
  710. oldSeries.xData = []; // Overcome problems with minRange (#2898)
  711. level.levelSeriesOptions.forEach(addSeries);
  712. fireEvent(chart, 'drillup', {
  713. seriesOptions: level.seriesPurgedOptions ||
  714. level.seriesOptions
  715. });
  716. if (newSeries.type === oldSeries.type) {
  717. newSeries.drilldownLevel = level;
  718. newSeries.options.animation =
  719. chart.options.drilldown.animation;
  720. if (oldSeries.animateDrillupFrom && oldSeries.chart) { // #2919
  721. oldSeries.animateDrillupFrom(level);
  722. }
  723. }
  724. newSeries.options._levelNumber = levelNumber;
  725. oldSeries.remove(false);
  726. // Reset the zoom level of the upper series
  727. if (newSeries.xAxis) {
  728. oldExtremes = level.oldExtremes;
  729. newSeries.xAxis.setExtremes(oldExtremes.xMin, oldExtremes.xMax, false);
  730. newSeries.yAxis.setExtremes(oldExtremes.yMin, oldExtremes.yMax, false);
  731. }
  732. // We have a resetZoomButton tucked away for this level. Attatch
  733. // it to the chart and show it.
  734. if (level.resetZoomButton) {
  735. chart.resetZoomButton = level.resetZoomButton;
  736. chart.resetZoomButton.show();
  737. }
  738. }
  739. }
  740. this.redraw();
  741. if (this.drilldownLevels.length === 0) {
  742. this.drillUpButton = this.drillUpButton.destroy();
  743. }
  744. else {
  745. this.drillUpButton.attr({
  746. text: this.getDrilldownBackText()
  747. })
  748. .align();
  749. }
  750. this.ddDupes.length = []; // #3315
  751. // Fire a once-off event after all series have been drilled up (#5158)
  752. fireEvent(chart, 'drillupall');
  753. };
  754. /* eslint-disable no-invalid-this */
  755. // Add update function to be called internally from Chart.update
  756. // (#7600, #12855)
  757. addEvent(Chart, 'afterInit', function () {
  758. var chart = this;
  759. chart.drilldown = {
  760. update: function (options, redraw) {
  761. merge(true, chart.options.drilldown, options);
  762. if (pick(redraw, true)) {
  763. chart.redraw();
  764. }
  765. }
  766. };
  767. });
  768. // Don't show the reset button if we already are displaying the drillUp button.
  769. addEvent(Chart, 'beforeShowResetZoom', function () {
  770. if (this.drillUpButton) {
  771. return false;
  772. }
  773. });
  774. addEvent(Chart, 'render', function () {
  775. (this.xAxis || []).forEach(function (axis) {
  776. axis.ddPoints = {};
  777. axis.series.forEach(function (series) {
  778. var i,
  779. xData = series.xData || [],
  780. points = series.points,
  781. p;
  782. for (i = 0; i < xData.length; i++) {
  783. p = series.options.data[i];
  784. // The `drilldown` property can only be set on an array or an
  785. // object
  786. if (typeof p !== 'number') {
  787. // Convert array to object (#8008)
  788. p = series.pointClass.prototype.optionsToObject
  789. .call({ series: series }, p);
  790. if (p.drilldown) {
  791. if (!axis.ddPoints[xData[i]]) {
  792. axis.ddPoints[xData[i]] = [];
  793. }
  794. axis.ddPoints[xData[i]].push(points ? points[i] : true);
  795. }
  796. }
  797. }
  798. });
  799. // Add drillability to ticks, and always keep it drillability updated
  800. // (#3951)
  801. objectEach(axis.ticks, Tick.prototype.drillable);
  802. });
  803. });
  804. /**
  805. * When drilling up, keep the upper series invisible until the lower series has
  806. * moved into place.
  807. *
  808. * @private
  809. * @function Highcharts.ColumnSeries#animateDrillupTo
  810. * @param {boolean} [init=false]
  811. * Whether to initialize animation
  812. */
  813. ColumnSeries.prototype.animateDrillupTo = function (init) {
  814. if (!init) {
  815. var newSeries = this,
  816. level = newSeries.drilldownLevel;
  817. // First hide all items before animating in again
  818. this.points.forEach(function (point) {
  819. var dataLabel = point.dataLabel;
  820. if (point.graphic) { // #3407
  821. point.graphic.hide();
  822. }
  823. if (dataLabel) {
  824. // The data label is initially hidden, make sure it is not faded
  825. // in (#6127)
  826. dataLabel.hidden = dataLabel.attr('visibility') === 'hidden';
  827. if (!dataLabel.hidden) {
  828. dataLabel.hide();
  829. if (point.connector) {
  830. point.connector.hide();
  831. }
  832. }
  833. }
  834. });
  835. // Do dummy animation on first point to get to complete
  836. syncTimeout(function () {
  837. if (newSeries.points) { // May be destroyed in the meantime, #3389
  838. // Unable to drillup with nodes, #13711
  839. var pointsWithNodes = [];
  840. newSeries.data.forEach(function (el) {
  841. pointsWithNodes.push(el);
  842. });
  843. if (newSeries.nodes) {
  844. pointsWithNodes = pointsWithNodes.concat(newSeries.nodes);
  845. }
  846. pointsWithNodes.forEach(function (point, i) {
  847. // Fade in other points
  848. var verb = i === (level && level.pointIndex) ? 'show' : 'fadeIn', inherit = verb === 'show' ? true : void 0, dataLabel = point.dataLabel;
  849. if (point.graphic) { // #3407
  850. point.graphic[verb](inherit);
  851. }
  852. if (dataLabel && !dataLabel.hidden) { // #6127
  853. dataLabel.fadeIn(); // #7384
  854. if (point.connector) {
  855. point.connector.fadeIn();
  856. }
  857. }
  858. });
  859. }
  860. }, Math.max(this.chart.options.drilldown.animation.duration - 50, 0));
  861. // Reset to prototype
  862. delete this.animate;
  863. }
  864. };
  865. ColumnSeries.prototype.animateDrilldown = function (init) {
  866. var series = this,
  867. chart = this.chart,
  868. drilldownLevels = chart.drilldownLevels,
  869. animateFrom,
  870. animationOptions = animObject(chart.options.drilldown.animation),
  871. xAxis = this.xAxis,
  872. styledMode = chart.styledMode;
  873. if (!init) {
  874. drilldownLevels.forEach(function (level) {
  875. if (series.options._ddSeriesId ===
  876. level.lowerSeriesOptions._ddSeriesId) {
  877. animateFrom = level.shapeArgs;
  878. if (!styledMode) {
  879. // Add the point colors to animate from
  880. animateFrom.fill = level.color;
  881. }
  882. }
  883. });
  884. animateFrom.x += pick(xAxis.oldPos, xAxis.pos) - xAxis.pos;
  885. this.points.forEach(function (point) {
  886. var animateTo = point.shapeArgs;
  887. if (!styledMode) {
  888. // Add the point colors to animate to
  889. animateTo.fill = point.color;
  890. }
  891. if (point.graphic) {
  892. point.graphic
  893. .attr(animateFrom)
  894. .animate(extend(point.shapeArgs, { fill: point.color || series.color }), animationOptions);
  895. }
  896. if (point.dataLabel) {
  897. point.dataLabel.fadeIn(animationOptions);
  898. }
  899. });
  900. // Reset to prototype
  901. delete this.animate;
  902. }
  903. };
  904. /**
  905. * When drilling up, pull out the individual point graphics from the lower
  906. * series and animate them into the origin point in the upper series.
  907. *
  908. * @private
  909. * @function Highcharts.ColumnSeries#animateDrillupFrom
  910. * @param {Highcharts.DrilldownLevelObject} level
  911. * Level container
  912. * @return {void}
  913. */
  914. ColumnSeries.prototype.animateDrillupFrom = function (level) {
  915. var animationOptions = animObject(this.chart.options.drilldown.animation),
  916. group = this.group,
  917. // For 3d column series all columns are added to one group
  918. // so we should not delete the whole group. #5297
  919. removeGroup = group !== this.chart.columnGroup,
  920. series = this;
  921. // Cancel mouse events on the series group (#2787)
  922. series.trackerGroups.forEach(function (key) {
  923. if (series[key]) { // we don't always have dataLabelsGroup
  924. series[key].on('mouseover');
  925. }
  926. });
  927. if (removeGroup) {
  928. delete this.group;
  929. }
  930. this.points.forEach(function (point) {
  931. var graphic = point.graphic,
  932. animateTo = level.shapeArgs,
  933. complete = function () {
  934. graphic.destroy();
  935. if (group && removeGroup) {
  936. group = group.destroy();
  937. }
  938. };
  939. if (graphic && animateTo) {
  940. delete point.graphic;
  941. if (!series.chart.styledMode) {
  942. animateTo.fill = level.color;
  943. }
  944. if (animationOptions.duration) {
  945. graphic.animate(animateTo, merge(animationOptions, { complete: complete }));
  946. }
  947. else {
  948. graphic.attr(animateTo);
  949. complete();
  950. }
  951. }
  952. });
  953. };
  954. if (PieSeries) {
  955. extend(PieSeries.prototype, {
  956. animateDrillupTo: ColumnSeries.prototype.animateDrillupTo,
  957. animateDrillupFrom: ColumnSeries.prototype.animateDrillupFrom,
  958. animateDrilldown: function (init) {
  959. var level = this.chart.drilldownLevels[this.chart.drilldownLevels.length - 1],
  960. animationOptions = this.chart.options.drilldown.animation;
  961. if (this.is('item')) {
  962. animationOptions.duration = 0;
  963. }
  964. // Unable to drill down in the horizontal item series #13372
  965. if (this.center) {
  966. var animateFrom = level.shapeArgs,
  967. start = animateFrom.start,
  968. angle = animateFrom.end - start,
  969. startAngle = angle / this.points.length,
  970. styledMode = this.chart.styledMode;
  971. if (!init) {
  972. this.points.forEach(function (point, i) {
  973. var animateTo = point.shapeArgs;
  974. if (!styledMode) {
  975. animateFrom.fill = level.color;
  976. animateTo.fill = point.color;
  977. }
  978. if (point.graphic) {
  979. point.graphic
  980. .attr(merge(animateFrom, {
  981. start: start + i * startAngle,
  982. end: start + (i + 1) * startAngle
  983. }))[animationOptions ? 'animate' : 'attr'](animateTo, animationOptions);
  984. }
  985. });
  986. // Reset to prototype
  987. delete this.animate;
  988. }
  989. }
  990. }
  991. });
  992. }
  993. Point.prototype.doDrilldown = function (_holdRedraw, category, originalEvent) {
  994. var series = this.series,
  995. chart = series.chart,
  996. drilldown = chart.options.drilldown,
  997. i = (drilldown.series || []).length,
  998. seriesOptions;
  999. if (!chart.ddDupes) {
  1000. chart.ddDupes = [];
  1001. }
  1002. while (i-- && !seriesOptions) {
  1003. if (drilldown.series[i].id === this.drilldown &&
  1004. chart.ddDupes.indexOf(this.drilldown) === -1) {
  1005. seriesOptions = drilldown.series[i];
  1006. chart.ddDupes.push(this.drilldown);
  1007. }
  1008. }
  1009. // Fire the event. If seriesOptions is undefined, the implementer can check
  1010. // for seriesOptions, and call addSeriesAsDrilldown async if necessary.
  1011. fireEvent(chart, 'drilldown', {
  1012. point: this,
  1013. seriesOptions: seriesOptions,
  1014. category: category,
  1015. originalEvent: originalEvent,
  1016. points: (typeof category !== 'undefined' &&
  1017. this.series.xAxis.getDDPoints(category).slice(0))
  1018. }, function (e) {
  1019. var chart = e.point.series && e.point.series.chart,
  1020. seriesOptions = e.seriesOptions;
  1021. if (chart && seriesOptions) {
  1022. if (_holdRedraw) {
  1023. chart.addSingleSeriesAsDrilldown(e.point, seriesOptions);
  1024. }
  1025. else {
  1026. chart.addSeriesAsDrilldown(e.point, seriesOptions);
  1027. }
  1028. }
  1029. });
  1030. };
  1031. /**
  1032. * Drill down to a given category. This is the same as clicking on an axis
  1033. * label.
  1034. *
  1035. * @private
  1036. * @function Highcharts.Axis#drilldownCategory
  1037. * @param {number} x
  1038. * Tick position
  1039. * @param {global.MouseEvent} e
  1040. * Click event
  1041. */
  1042. Axis.prototype.drilldownCategory = function (x, e) {
  1043. this.getDDPoints(x).forEach(function (point) {
  1044. if (point &&
  1045. point.series &&
  1046. point.series.visible &&
  1047. point.doDrilldown) { // #3197
  1048. point.doDrilldown(true, x, e);
  1049. }
  1050. });
  1051. this.chart.applyDrilldown();
  1052. };
  1053. /**
  1054. * Return drillable points for this specific X value.
  1055. *
  1056. * @private
  1057. * @function Highcharts.Axis#getDDPoints
  1058. * @param {number} x
  1059. * Tick position
  1060. * @return {Array<(false|Highcharts.Point)>}
  1061. * Drillable points
  1062. */
  1063. Axis.prototype.getDDPoints = function (x) {
  1064. return (this.ddPoints && this.ddPoints[x] || []);
  1065. };
  1066. /**
  1067. * Make a tick label drillable, or remove drilling on update.
  1068. *
  1069. * @private
  1070. * @function Highcharts.Axis#drillable
  1071. */
  1072. Tick.prototype.drillable = function () {
  1073. var pos = this.pos,
  1074. label = this.label,
  1075. axis = this.axis,
  1076. isDrillable = axis.coll === 'xAxis' && axis.getDDPoints,
  1077. ddPointsX = isDrillable && axis.getDDPoints(pos),
  1078. styledMode = axis.chart.styledMode;
  1079. if (isDrillable) {
  1080. if (label && ddPointsX && ddPointsX.length) {
  1081. label.drillable = true;
  1082. if (!label.basicStyles && !styledMode) {
  1083. label.basicStyles = merge(label.styles);
  1084. }
  1085. label.addClass('highcharts-drilldown-axis-label');
  1086. // #12656 - avoid duplicate of attach event
  1087. if (label.removeOnDrillableClick) {
  1088. removeEvent(label.element, 'click');
  1089. }
  1090. label.removeOnDrillableClick = addEvent(label.element, 'click', function (e) {
  1091. e.preventDefault();
  1092. axis.drilldownCategory(pos, e);
  1093. });
  1094. if (!styledMode) {
  1095. label.css(axis.chart.options.drilldown.activeAxisLabelStyle);
  1096. }
  1097. }
  1098. else if (label && label.drillable && label.removeOnDrillableClick) {
  1099. if (!styledMode) {
  1100. label.styles = {}; // reset for full overwrite of styles
  1101. label.css(label.basicStyles);
  1102. }
  1103. label.removeOnDrillableClick(); // #3806
  1104. label.removeClass('highcharts-drilldown-axis-label');
  1105. }
  1106. }
  1107. };
  1108. // On initialization of each point, identify its label and make it clickable.
  1109. // Also, provide a list of points associated to that label.
  1110. addEvent(Point, 'afterInit', function () {
  1111. var point = this,
  1112. series = point.series;
  1113. if (point.drilldown) {
  1114. // Add the click event to the point
  1115. addEvent(point, 'click', function (e) {
  1116. if (series.xAxis &&
  1117. series.chart.options.drilldown.allowPointDrilldown ===
  1118. false) {
  1119. // #5822, x changed
  1120. series.xAxis.drilldownCategory(point.x, e);
  1121. }
  1122. else {
  1123. point.doDrilldown(void 0, void 0, e);
  1124. }
  1125. });
  1126. }
  1127. return point;
  1128. });
  1129. addEvent(H.Series, 'afterDrawDataLabels', function () {
  1130. var css = this.chart.options.drilldown.activeDataLabelStyle,
  1131. renderer = this.chart.renderer,
  1132. styledMode = this.chart.styledMode;
  1133. this.points.forEach(function (point) {
  1134. var dataLabelsOptions = point.options.dataLabels,
  1135. pointCSS = pick(point.dlOptions,
  1136. dataLabelsOptions && dataLabelsOptions.style, {});
  1137. if (point.drilldown && point.dataLabel) {
  1138. if (css.color === 'contrast' && !styledMode) {
  1139. pointCSS.color = renderer.getContrast(point.color || this.color);
  1140. }
  1141. if (dataLabelsOptions && dataLabelsOptions.color) {
  1142. pointCSS.color = dataLabelsOptions.color;
  1143. }
  1144. point.dataLabel
  1145. .addClass('highcharts-drilldown-data-label');
  1146. if (!styledMode) {
  1147. point.dataLabel
  1148. .css(css)
  1149. .css(pointCSS);
  1150. }
  1151. }
  1152. }, this);
  1153. });
  1154. var applyCursorCSS = function (element,
  1155. cursor,
  1156. addClass,
  1157. styledMode) {
  1158. element[addClass ? 'addClass' : 'removeClass']('highcharts-drilldown-point');
  1159. if (!styledMode) {
  1160. element.css({ cursor: cursor });
  1161. }
  1162. };
  1163. // Mark the trackers with a pointer
  1164. addEvent(H.Series, 'afterDrawTracker', function () {
  1165. var styledMode = this.chart.styledMode;
  1166. this.points.forEach(function (point) {
  1167. if (point.drilldown && point.graphic) {
  1168. applyCursorCSS(point.graphic, 'pointer', true, styledMode);
  1169. }
  1170. });
  1171. });
  1172. addEvent(Point, 'afterSetState', function () {
  1173. var styledMode = this.series.chart.styledMode;
  1174. if (this.drilldown && this.series.halo && this.state === 'hover') {
  1175. applyCursorCSS(this.series.halo, 'pointer', true, styledMode);
  1176. }
  1177. else if (this.series.halo) {
  1178. applyCursorCSS(this.series.halo, 'auto', false, styledMode);
  1179. }
  1180. });
  1181. });
  1182. _registerModule(_modules, 'masters/modules/drilldown.src.js', [], function () {
  1183. });
  1184. }));