funnel.src.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. /**
  2. * @license Highcharts JS v8.2.2 (2020-10-22)
  3. *
  4. * Highcharts funnel 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/funnel', ['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, 'Series/FunnelSeries.js', [_modules['Core/Series/Series.js'], _modules['Core/Chart/Chart.js'], _modules['Core/Globals.js'], _modules['Core/Utilities.js']], function (BaseSeries, Chart, H, U) {
  32. /* *
  33. *
  34. * Highcharts funnel module
  35. *
  36. * (c) 2010-2020 Torstein Honsi
  37. *
  38. * License: www.highcharts.com/license
  39. *
  40. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  41. *
  42. * */
  43. var seriesTypes = BaseSeries.seriesTypes;
  44. var noop = H.noop;
  45. var addEvent = U.addEvent,
  46. fireEvent = U.fireEvent,
  47. isArray = U.isArray,
  48. pick = U.pick;
  49. /**
  50. * @private
  51. * @class
  52. * @name Highcharts.seriesTypes.funnel
  53. *
  54. * @augments Highcharts.Series
  55. */
  56. BaseSeries.seriesType('funnel', 'pie',
  57. /**
  58. * Funnel charts are a type of chart often used to visualize stages in a
  59. * sales project, where the top are the initial stages with the most
  60. * clients. It requires that the modules/funnel.js file is loaded.
  61. *
  62. * @sample highcharts/demo/funnel/
  63. * Funnel demo
  64. *
  65. * @extends plotOptions.pie
  66. * @excluding innerSize,size,dataSorting
  67. * @product highcharts
  68. * @requires modules/funnel
  69. * @optionparent plotOptions.funnel
  70. */
  71. {
  72. /**
  73. * Initial animation is by default disabled for the funnel chart.
  74. */
  75. animation: false,
  76. /**
  77. * The center of the series. By default, it is centered in the middle
  78. * of the plot area, so it fills the plot area height.
  79. *
  80. * @type {Array<number|string>}
  81. * @default ["50%", "50%"]
  82. * @since 3.0
  83. */
  84. center: ['50%', '50%'],
  85. /**
  86. * The width of the funnel compared to the width of the plot area,
  87. * or the pixel width if it is a number.
  88. *
  89. * @type {number|string}
  90. * @since 3.0
  91. */
  92. width: '90%',
  93. /**
  94. * The width of the neck, the lower part of the funnel. A number defines
  95. * pixel width, a percentage string defines a percentage of the plot
  96. * area width.
  97. *
  98. * @sample {highcharts} highcharts/demo/funnel/
  99. * Funnel demo
  100. *
  101. * @type {number|string}
  102. * @since 3.0
  103. */
  104. neckWidth: '30%',
  105. /**
  106. * The height of the funnel or pyramid. If it is a number it defines
  107. * the pixel height, if it is a percentage string it is the percentage
  108. * of the plot area height.
  109. *
  110. * @sample {highcharts} highcharts/demo/funnel/
  111. * Funnel demo
  112. *
  113. * @type {number|string}
  114. * @since 3.0
  115. */
  116. height: '100%',
  117. /**
  118. * The height of the neck, the lower part of the funnel. A number
  119. * defines pixel width, a percentage string defines a percentage of the
  120. * plot area height.
  121. *
  122. * @type {number|string}
  123. */
  124. neckHeight: '25%',
  125. /**
  126. * A reversed funnel has the widest area down. A reversed funnel with
  127. * no neck width and neck height is a pyramid.
  128. *
  129. * @since 3.0.10
  130. */
  131. reversed: false,
  132. /**
  133. * To avoid adapting the data label size in Pie.drawDataLabels.
  134. * @ignore-option
  135. */
  136. size: true,
  137. dataLabels: {
  138. connectorWidth: 1,
  139. verticalAlign: 'middle'
  140. },
  141. /**
  142. * Options for the series states.
  143. */
  144. states: {
  145. /**
  146. * @excluding halo, marker, lineWidth, lineWidthPlus
  147. * @apioption plotOptions.funnel.states.hover
  148. */
  149. /**
  150. * Options for a selected funnel item.
  151. *
  152. * @excluding halo, marker, lineWidth, lineWidthPlus
  153. */
  154. select: {
  155. /**
  156. * A specific color for the selected point.
  157. *
  158. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  159. */
  160. color: '#cccccc',
  161. /**
  162. * A specific border color for the selected point.
  163. *
  164. * @type {Highcharts.ColorString}
  165. */
  166. borderColor: '#000000'
  167. }
  168. }
  169. },
  170. // Properties
  171. {
  172. animate: noop,
  173. // Overrides the pie translate method
  174. translate: function () {
  175. var sum = 0,
  176. series = this,
  177. chart = series.chart,
  178. options = series.options,
  179. reversed = options.reversed,
  180. ignoreHiddenPoint = options.ignoreHiddenPoint,
  181. plotWidth = chart.plotWidth,
  182. plotHeight = chart.plotHeight,
  183. cumulative = 0, // start at top
  184. center = options.center,
  185. centerX = getLength(center[0],
  186. plotWidth),
  187. centerY = getLength(center[1],
  188. plotHeight),
  189. width = getLength(options.width,
  190. plotWidth),
  191. tempWidth,
  192. height = getLength(options.height,
  193. plotHeight),
  194. neckWidth = getLength(options.neckWidth,
  195. plotWidth),
  196. neckHeight = getLength(options.neckHeight,
  197. plotHeight),
  198. neckY = (centerY - height / 2) + height - neckHeight,
  199. data = series.data,
  200. path,
  201. fraction,
  202. half = (options.dataLabels.position === 'left' ?
  203. 1 :
  204. 0),
  205. x1,
  206. y1,
  207. x2,
  208. x3,
  209. y3,
  210. x4,
  211. y5;
  212. /**
  213. * Get positions - either an integer or a percentage string must be
  214. * given.
  215. * @private
  216. * @param {number|string|undefined} length
  217. * Length
  218. * @param {number} relativeTo
  219. * Relative factor
  220. * @return {number}
  221. * Relative position
  222. */
  223. function getLength(length, relativeTo) {
  224. return (/%$/).test(length) ?
  225. relativeTo * parseInt(length, 10) / 100 :
  226. parseInt(length, 10);
  227. }
  228. series.getWidthAt = function (y) {
  229. var top = (centerY - height / 2);
  230. return (y > neckY || height === neckHeight) ?
  231. neckWidth :
  232. neckWidth + (width - neckWidth) *
  233. (1 - (y - top) / (height - neckHeight));
  234. };
  235. series.getX = function (y, half, point) {
  236. return centerX + (half ? -1 : 1) *
  237. ((series.getWidthAt(reversed ? 2 * centerY - y : y) / 2) +
  238. point.labelDistance);
  239. };
  240. // Expose
  241. series.center = [centerX, centerY, height];
  242. series.centerX = centerX;
  243. /*
  244. Individual point coordinate naming:
  245. x1,y1 _________________ x2,y1
  246. \ /
  247. \ /
  248. \ /
  249. \ /
  250. \ /
  251. x3,y3 _________ x4,y3
  252. Additional for the base of the neck:
  253. | |
  254. | |
  255. | |
  256. x3,y5 _________ x4,y5
  257. */
  258. // get the total sum
  259. data.forEach(function (point) {
  260. if (!ignoreHiddenPoint || point.visible !== false) {
  261. sum += point.y;
  262. }
  263. });
  264. data.forEach(function (point) {
  265. // set start and end positions
  266. y5 = null;
  267. fraction = sum ? point.y / sum : 0;
  268. y1 = centerY - height / 2 + cumulative * height;
  269. y3 = y1 + fraction * height;
  270. tempWidth = series.getWidthAt(y1);
  271. x1 = centerX - tempWidth / 2;
  272. x2 = x1 + tempWidth;
  273. tempWidth = series.getWidthAt(y3);
  274. x3 = centerX - tempWidth / 2;
  275. x4 = x3 + tempWidth;
  276. // the entire point is within the neck
  277. if (y1 > neckY) {
  278. x1 = x3 = centerX - neckWidth / 2;
  279. x2 = x4 = centerX + neckWidth / 2;
  280. // the base of the neck
  281. }
  282. else if (y3 > neckY) {
  283. y5 = y3;
  284. tempWidth = series.getWidthAt(neckY);
  285. x3 = centerX - tempWidth / 2;
  286. x4 = x3 + tempWidth;
  287. y3 = neckY;
  288. }
  289. if (reversed) {
  290. y1 = 2 * centerY - y1;
  291. y3 = 2 * centerY - y3;
  292. if (y5 !== null) {
  293. y5 = 2 * centerY - y5;
  294. }
  295. }
  296. // save the path
  297. path = [
  298. ['M', x1, y1],
  299. ['L', x2, y1],
  300. ['L', x4, y3]
  301. ];
  302. if (y5 !== null) {
  303. path.push(['L', x4, y5], ['L', x3, y5]);
  304. }
  305. path.push(['L', x3, y3], ['Z']);
  306. // prepare for using shared dr
  307. point.shapeType = 'path';
  308. point.shapeArgs = { d: path };
  309. // for tooltips and data labels
  310. point.percentage = fraction * 100;
  311. point.plotX = centerX;
  312. point.plotY = (y1 + (y5 || y3)) / 2;
  313. // Placement of tooltips and data labels
  314. point.tooltipPos = [
  315. centerX,
  316. point.plotY
  317. ];
  318. point.dlBox = {
  319. x: x3,
  320. y: y1,
  321. topWidth: x2 - x1,
  322. bottomWidth: x4 - x3,
  323. height: Math.abs(pick(y5, y3) - y1),
  324. width: NaN
  325. };
  326. // Slice is a noop on funnel points
  327. point.slice = noop;
  328. // Mimicking pie data label placement logic
  329. point.half = half;
  330. if (!ignoreHiddenPoint || point.visible !== false) {
  331. cumulative += fraction;
  332. }
  333. });
  334. fireEvent(series, 'afterTranslate');
  335. },
  336. // Funnel items don't have angles (#2289)
  337. sortByAngle: function (points) {
  338. points.sort(function (a, b) {
  339. return a.plotY - b.plotY;
  340. });
  341. },
  342. // Extend the pie data label method
  343. drawDataLabels: function () {
  344. var series = this,
  345. data = series.data,
  346. labelDistance = series.options.dataLabels.distance,
  347. leftSide,
  348. sign,
  349. point,
  350. i = data.length,
  351. x,
  352. y;
  353. // In the original pie label anticollision logic, the slots are
  354. // distributed from one labelDistance above to one labelDistance
  355. // below the pie. In funnels we don't want this.
  356. series.center[2] -= 2 * labelDistance;
  357. // Set the label position array for each point.
  358. while (i--) {
  359. point = data[i];
  360. leftSide = point.half;
  361. sign = leftSide ? 1 : -1;
  362. y = point.plotY;
  363. point.labelDistance = pick(point.options.dataLabels &&
  364. point.options.dataLabels.distance, labelDistance);
  365. series.maxLabelDistance = Math.max(point.labelDistance, series.maxLabelDistance || 0);
  366. x = series.getX(y, leftSide, point);
  367. // set the anchor point for data labels
  368. point.labelPosition = {
  369. // initial position of the data label - it's utilized for
  370. // finding the final position for the label
  371. natural: {
  372. x: 0,
  373. y: y
  374. },
  375. 'final': {
  376. // used for generating connector path -
  377. // initialized later in drawDataLabels function
  378. // x: undefined,
  379. // y: undefined
  380. },
  381. // left - funnel on the left side of the data label
  382. // right - funnel on the right side of the data label
  383. alignment: leftSide ? 'right' : 'left',
  384. connectorPosition: {
  385. breakAt: {
  386. x: x + (point.labelDistance - 5) * sign,
  387. y: y
  388. },
  389. touchingSliceAt: {
  390. x: x + point.labelDistance * sign,
  391. y: y
  392. }
  393. }
  394. };
  395. }
  396. seriesTypes[series.options.dataLabels.inside ? 'column' : 'pie'].prototype.drawDataLabels.call(this);
  397. },
  398. alignDataLabel: function (point, dataLabel, options, alignTo, isNew) {
  399. var series = point.series,
  400. reversed = series.options.reversed,
  401. dlBox = point.dlBox || point.shapeArgs,
  402. align = options.align,
  403. verticalAlign = options.verticalAlign,
  404. inside = ((series.options || {}).dataLabels || {}).inside,
  405. centerY = series.center[1],
  406. pointPlotY = (reversed ?
  407. 2 * centerY - point.plotY :
  408. point.plotY),
  409. widthAtLabel = series.getWidthAt(pointPlotY - dlBox.height / 2 +
  410. dataLabel.height),
  411. offset = verticalAlign === 'middle' ?
  412. (dlBox.topWidth - dlBox.bottomWidth) / 4 :
  413. (widthAtLabel - dlBox.bottomWidth) / 2,
  414. y = dlBox.y,
  415. x = dlBox.x;
  416. if (verticalAlign === 'middle') {
  417. y = dlBox.y - dlBox.height / 2 + dataLabel.height / 2;
  418. }
  419. else if (verticalAlign === 'top') {
  420. y = dlBox.y - dlBox.height + dataLabel.height +
  421. options.padding;
  422. }
  423. if (verticalAlign === 'top' && !reversed ||
  424. verticalAlign === 'bottom' && reversed ||
  425. verticalAlign === 'middle') {
  426. if (align === 'right') {
  427. x = dlBox.x - options.padding + offset;
  428. }
  429. else if (align === 'left') {
  430. x = dlBox.x + options.padding - offset;
  431. }
  432. }
  433. alignTo = {
  434. x: x,
  435. y: reversed ? y - dlBox.height : y,
  436. width: dlBox.bottomWidth,
  437. height: dlBox.height
  438. };
  439. options.verticalAlign = 'bottom';
  440. // Call the parent method
  441. if (!inside || point.visible) {
  442. Highcharts.Series.prototype.alignDataLabel.call(this, point, dataLabel, options, alignTo, isNew);
  443. }
  444. if (inside) {
  445. if (!point.visible && point.dataLabel) {
  446. // Avoid animation from top
  447. point.dataLabel.placed = false;
  448. }
  449. // If label is inside and we have contrast, set it:
  450. if (point.contrastColor) {
  451. dataLabel.css({
  452. color: point.contrastColor
  453. });
  454. }
  455. }
  456. }
  457. });
  458. /* eslint-disable no-invalid-this */
  459. addEvent(Chart, 'afterHideAllOverlappingLabels', function () {
  460. this.series.forEach(function (series) {
  461. var dataLabelsOptions = series.options && series.options.dataLabels;
  462. if (isArray(dataLabelsOptions)) {
  463. dataLabelsOptions = dataLabelsOptions[0];
  464. }
  465. if (series.is('pie') &&
  466. series.placeDataLabels &&
  467. dataLabelsOptions &&
  468. !dataLabelsOptions.inside) {
  469. series.placeDataLabels();
  470. }
  471. });
  472. });
  473. /**
  474. * A `funnel` series. If the [type](#series.funnel.type) option is
  475. * not specified, it is inherited from [chart.type](#chart.type).
  476. *
  477. * @extends series,plotOptions.funnel
  478. * @excluding dataParser, dataURL, stack, xAxis, yAxis, dataSorting,
  479. * boostBlending, boostThreshold
  480. * @product highcharts
  481. * @requires modules/funnel
  482. * @apioption series.funnel
  483. */
  484. /**
  485. * An array of data points for the series. For the `funnel` series type,
  486. * points can be given in the following ways:
  487. *
  488. * 1. An array of numerical values. In this case, the numerical values
  489. * will be interpreted as `y` options. Example:
  490. *
  491. * ```js
  492. * data: [0, 5, 3, 5]
  493. * ```
  494. *
  495. * 2. An array of objects with named values. The following snippet shows only a
  496. * few settings, see the complete options set below. If the total number of data
  497. * points exceeds the series' [turboThreshold](#series.funnel.turboThreshold),
  498. * this option is not available.
  499. *
  500. * ```js
  501. * data: [{
  502. * y: 3,
  503. * name: "Point2",
  504. * color: "#00FF00"
  505. * }, {
  506. * y: 1,
  507. * name: "Point1",
  508. * color: "#FF00FF"
  509. * }]
  510. * ```
  511. *
  512. * @sample {highcharts} highcharts/chart/reflow-true/
  513. * Numerical values
  514. * @sample {highcharts} highcharts/series/data-array-of-arrays/
  515. * Arrays of numeric x and y
  516. * @sample {highcharts} highcharts/series/data-array-of-arrays-datetime/
  517. * Arrays of datetime x and y
  518. * @sample {highcharts} highcharts/series/data-array-of-name-value/
  519. * Arrays of point.name and y
  520. * @sample {highcharts} highcharts/series/data-array-of-objects/
  521. * Config objects
  522. *
  523. * @type {Array<number|null|*>}
  524. * @extends series.pie.data
  525. * @excluding sliced
  526. * @product highcharts
  527. * @apioption series.funnel.data
  528. */
  529. /**
  530. * Pyramid series type.
  531. *
  532. * @private
  533. * @class
  534. * @name Highcharts.seriesTypes.pyramid
  535. *
  536. * @augments Highcharts.Series
  537. */
  538. BaseSeries.seriesType('pyramid', 'funnel',
  539. /**
  540. * A pyramid series is a special type of funnel, without neck and reversed
  541. * by default.
  542. *
  543. * @sample highcharts/demo/pyramid/
  544. * Pyramid chart
  545. *
  546. * @extends plotOptions.funnel
  547. * @product highcharts
  548. * @requires modules/funnel
  549. * @optionparent plotOptions.pyramid
  550. */
  551. {
  552. /**
  553. * The pyramid neck width is zero by default, as opposed to the funnel,
  554. * which shares the same layout logic.
  555. *
  556. * @since 3.0.10
  557. */
  558. neckWidth: '0%',
  559. /**
  560. * The pyramid neck width is zero by default, as opposed to the funnel,
  561. * which shares the same layout logic.
  562. *
  563. * @since 3.0.10
  564. */
  565. neckHeight: '0%',
  566. /**
  567. * The pyramid is reversed by default, as opposed to the funnel, which
  568. * shares the layout engine, and is not reversed.
  569. *
  570. * @since 3.0.10
  571. */
  572. reversed: true
  573. });
  574. /**
  575. * A `pyramid` series. If the [type](#series.pyramid.type) option is
  576. * not specified, it is inherited from [chart.type](#chart.type).
  577. *
  578. * @extends series,plotOptions.pyramid
  579. * @excluding dataParser, dataURL, stack, xAxis, yAxis, dataSorting,
  580. * boostThreshold, boostBlending
  581. * @product highcharts
  582. * @requires modules/funnel
  583. * @apioption series.pyramid
  584. */
  585. /**
  586. * An array of data points for the series. For the `pyramid` series
  587. * type, points can be given in the following ways:
  588. *
  589. * 1. An array of numerical values. In this case, the numerical values will be
  590. * interpreted as `y` options. Example:
  591. * ```js
  592. * data: [0, 5, 3, 5]
  593. * ```
  594. *
  595. * 2. An array of objects with named values. The following snippet shows only a
  596. * few settings, see the complete options set below. If the total number of
  597. * data points exceeds the series'
  598. * [turboThreshold](#series.pyramid.turboThreshold), this option is not
  599. * available.
  600. * ```js
  601. * data: [{
  602. * y: 9,
  603. * name: "Point2",
  604. * color: "#00FF00"
  605. * }, {
  606. * y: 6,
  607. * name: "Point1",
  608. * color: "#FF00FF"
  609. * }]
  610. * ```
  611. *
  612. * @sample {highcharts} highcharts/chart/reflow-true/
  613. * Numerical values
  614. * @sample {highcharts} highcharts/series/data-array-of-objects/
  615. * Config objects
  616. *
  617. * @type {Array<number|null|*>}
  618. * @extends series.pie.data
  619. * @excluding sliced
  620. * @product highcharts
  621. * @apioption series.pyramid.data
  622. */
  623. ''; // adds doclets above into transpiled file
  624. });
  625. _registerModule(_modules, 'masters/modules/funnel.src.js', [], function () {
  626. });
  627. }));