Funnel3DSeries.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. /* *
  2. *
  3. * Highcharts funnel3d series module
  4. *
  5. * (c) 2010-2021 Highsoft AS
  6. *
  7. * Author: Kacper Madej
  8. *
  9. * License: www.highcharts.com/license
  10. *
  11. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  12. *
  13. * */
  14. 'use strict';
  15. var __extends = (this && this.__extends) || (function () {
  16. var extendStatics = function (d, b) {
  17. extendStatics = Object.setPrototypeOf ||
  18. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  19. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  20. return extendStatics(d, b);
  21. };
  22. return function (d, b) {
  23. extendStatics(d, b);
  24. function __() { this.constructor = d; }
  25. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  26. };
  27. })();
  28. import Funnel3DPoint from './Funnel3DPoint.js';
  29. import H from '../../Core/Globals.js';
  30. var noop = H.noop;
  31. import Math3D from '../../Extensions/Math3D.js';
  32. var perspective = Math3D.perspective;
  33. import SeriesRegistry from '../../Core/Series/SeriesRegistry.js';
  34. var Series = SeriesRegistry.series, ColumnSeries = SeriesRegistry.seriesTypes.column;
  35. import U from '../../Core/Utilities.js';
  36. var extend = U.extend, merge = U.merge, pick = U.pick, relativeLength = U.relativeLength;
  37. import './Funnel3DComposition.js';
  38. /* *
  39. *
  40. * Class
  41. *
  42. * */
  43. /**
  44. * The funnel3d series type.
  45. *
  46. * @constructor seriesTypes.funnel3d
  47. * @augments seriesTypes.column
  48. * @requires highcharts-3d
  49. * @requires modules/cylinder
  50. * @requires modules/funnel3d
  51. */
  52. var Funnel3DSeries = /** @class */ (function (_super) {
  53. __extends(Funnel3DSeries, _super);
  54. function Funnel3DSeries() {
  55. var _this = _super !== null && _super.apply(this, arguments) || this;
  56. /* *
  57. *
  58. * Properties
  59. *
  60. * */
  61. _this.center = void 0;
  62. _this.data = void 0;
  63. _this.options = void 0;
  64. _this.points = void 0;
  65. return _this;
  66. /* eslint-enable valid-jsdoc */
  67. }
  68. /* *
  69. *
  70. * Functions
  71. *
  72. * */
  73. /* eslint-disable valid-jsdoc */
  74. /**
  75. * @private
  76. */
  77. Funnel3DSeries.prototype.alignDataLabel = function (point, _dataLabel, options) {
  78. var series = this, dlBoxRaw = point.dlBoxRaw, inverted = series.chart.inverted, below = point.plotY > pick(series.translatedThreshold, series.yAxis.len), inside = pick(options.inside, !!series.options.stacking), dlBox = {
  79. x: dlBoxRaw.x,
  80. y: dlBoxRaw.y,
  81. height: 0
  82. };
  83. options.align = pick(options.align, !inverted || inside ? 'center' : below ? 'right' : 'left');
  84. options.verticalAlign = pick(options.verticalAlign, inverted || inside ? 'middle' : below ? 'top' : 'bottom');
  85. if (options.verticalAlign !== 'top') {
  86. dlBox.y += dlBoxRaw.bottom /
  87. (options.verticalAlign === 'bottom' ? 1 : 2);
  88. }
  89. dlBox.width = series.getWidthAt(dlBox.y);
  90. if (series.options.reversed) {
  91. dlBox.width = dlBoxRaw.fullWidth - dlBox.width;
  92. }
  93. if (inside) {
  94. dlBox.x -= dlBox.width / 2;
  95. }
  96. else {
  97. // swap for inside
  98. if (options.align === 'left') {
  99. options.align = 'right';
  100. dlBox.x -= dlBox.width * 1.5;
  101. }
  102. else if (options.align === 'right') {
  103. options.align = 'left';
  104. dlBox.x += dlBox.width / 2;
  105. }
  106. else {
  107. dlBox.x -= dlBox.width / 2;
  108. }
  109. }
  110. point.dlBox = dlBox;
  111. ColumnSeries.prototype.alignDataLabel.apply(series, arguments);
  112. };
  113. /**
  114. * Override default axis options with series required options for axes.
  115. * @private
  116. */
  117. Funnel3DSeries.prototype.bindAxes = function () {
  118. Series.prototype.bindAxes.apply(this, arguments);
  119. extend(this.xAxis.options, {
  120. gridLineWidth: 0,
  121. lineWidth: 0,
  122. title: null,
  123. tickPositions: []
  124. });
  125. extend(this.yAxis.options, {
  126. gridLineWidth: 0,
  127. title: null,
  128. labels: {
  129. enabled: false
  130. }
  131. });
  132. };
  133. /**
  134. * @private
  135. */
  136. Funnel3DSeries.prototype.translate = function () {
  137. Series.prototype.translate.apply(this, arguments);
  138. var sum = 0, series = this, chart = series.chart, options = series.options, reversed = options.reversed, ignoreHiddenPoint = options.ignoreHiddenPoint, plotWidth = chart.plotWidth, plotHeight = chart.plotHeight, cumulative = 0, // start at top
  139. center = options.center, centerX = relativeLength(center[0], plotWidth), centerY = relativeLength(center[1], plotHeight), width = relativeLength(options.width, plotWidth), tempWidth, getWidthAt, height = relativeLength(options.height, plotHeight), neckWidth = relativeLength(options.neckWidth, plotWidth), neckHeight = relativeLength(options.neckHeight, plotHeight), neckY = (centerY - height / 2) + height - neckHeight, data = series.data, fraction, tooltipPos,
  140. //
  141. y1, y3, y5,
  142. //
  143. h, shapeArgs;
  144. // Return the width at a specific y coordinate
  145. series.getWidthAt = getWidthAt = function (y) {
  146. var top = (centerY - height / 2);
  147. return (y > neckY || height === neckHeight) ?
  148. neckWidth :
  149. neckWidth + (width - neckWidth) *
  150. (1 - (y - top) / (height - neckHeight));
  151. };
  152. // Expose
  153. series.center = [centerX, centerY, height];
  154. series.centerX = centerX;
  155. /*
  156. * Individual point coordinate naming:
  157. *
  158. * _________centerX,y1________
  159. * \ /
  160. * \ /
  161. * \ /
  162. * \ /
  163. * \ /
  164. * ___centerX,y3___
  165. *
  166. * Additional for the base of the neck:
  167. *
  168. * | |
  169. * | |
  170. * | |
  171. * ___centerX,y5___
  172. */
  173. // get the total sum
  174. data.forEach(function (point) {
  175. if (!ignoreHiddenPoint || point.visible !== false) {
  176. sum += point.y;
  177. }
  178. });
  179. data.forEach(function (point) {
  180. // set start and end positions
  181. y5 = null;
  182. fraction = sum ? point.y / sum : 0;
  183. y1 = centerY - height / 2 + cumulative * height;
  184. y3 = y1 + fraction * height;
  185. tempWidth = getWidthAt(y1);
  186. h = y3 - y1;
  187. shapeArgs = {
  188. // for fill setter
  189. gradientForSides: pick(point.options.gradientForSides, options.gradientForSides),
  190. x: centerX,
  191. y: y1,
  192. height: h,
  193. width: tempWidth,
  194. z: 1,
  195. top: {
  196. width: tempWidth
  197. }
  198. };
  199. tempWidth = getWidthAt(y3);
  200. shapeArgs.bottom = {
  201. fraction: fraction,
  202. width: tempWidth
  203. };
  204. // the entire point is within the neck
  205. if (y1 >= neckY) {
  206. shapeArgs.isCylinder = true;
  207. }
  208. else if (y3 > neckY) {
  209. // the base of the neck
  210. y5 = y3;
  211. tempWidth = getWidthAt(neckY);
  212. y3 = neckY;
  213. shapeArgs.bottom.width = tempWidth;
  214. shapeArgs.middle = {
  215. fraction: h ? (neckY - y1) / h : 0,
  216. width: tempWidth
  217. };
  218. }
  219. if (reversed) {
  220. shapeArgs.y = y1 = centerY + height / 2 -
  221. (cumulative + fraction) * height;
  222. if (shapeArgs.middle) {
  223. shapeArgs.middle.fraction = 1 -
  224. (h ? shapeArgs.middle.fraction : 0);
  225. }
  226. tempWidth = shapeArgs.width;
  227. shapeArgs.width = shapeArgs.bottom.width;
  228. shapeArgs.bottom.width = tempWidth;
  229. }
  230. point.shapeArgs = extend(point.shapeArgs, shapeArgs);
  231. // for tooltips and data labels context
  232. point.percentage = fraction * 100;
  233. point.plotX = centerX;
  234. if (reversed) {
  235. point.plotY = centerY + height / 2 -
  236. (cumulative + fraction / 2) * height;
  237. }
  238. else {
  239. point.plotY = (y1 + (y5 || y3)) / 2;
  240. }
  241. // Placement of tooltips and data labels in 3D
  242. tooltipPos = perspective([{
  243. x: centerX,
  244. y: point.plotY,
  245. z: reversed ?
  246. -(width - getWidthAt(point.plotY)) / 2 :
  247. -(getWidthAt(point.plotY)) / 2
  248. }], chart, true)[0];
  249. point.tooltipPos = [tooltipPos.x, tooltipPos.y];
  250. // base to be used when alignment options are known
  251. point.dlBoxRaw = {
  252. x: centerX,
  253. width: getWidthAt(point.plotY),
  254. y: y1,
  255. bottom: shapeArgs.height,
  256. fullWidth: width
  257. };
  258. if (!ignoreHiddenPoint || point.visible !== false) {
  259. cumulative += fraction;
  260. }
  261. });
  262. };
  263. /**
  264. * A funnel3d is a 3d version of funnel series type. Funnel charts are
  265. * a type of chart often used to visualize stages in a sales project,
  266. * where the top are the initial stages with the most clients.
  267. *
  268. * It requires that the `highcharts-3d.js`, `cylinder.js` and
  269. * `funnel3d.js` module are loaded.
  270. *
  271. * @sample highcharts/demo/funnel3d/
  272. * Funnel3d
  273. *
  274. * @extends plotOptions.column
  275. * @excluding allAreas, boostThreshold, colorAxis, compare, compareBase,
  276. * dataSorting, boostBlending
  277. * @product highcharts
  278. * @since 7.1.0
  279. * @requires highcharts-3d
  280. * @requires modules/cylinder
  281. * @requires modules/funnel3d
  282. * @optionparent plotOptions.funnel3d
  283. */
  284. Funnel3DSeries.defaultOptions = merge(ColumnSeries.defaultOptions, {
  285. /** @ignore-option */
  286. center: ['50%', '50%'],
  287. /**
  288. * The max width of the series compared to the width of the plot area,
  289. * or the pixel width if it is a number.
  290. *
  291. * @type {number|string}
  292. * @sample {highcharts} highcharts/demo/funnel3d/ Funnel3d demo
  293. * @product highcharts
  294. */
  295. width: '90%',
  296. /**
  297. * The width of the neck, the lower part of the funnel. A number defines
  298. * pixel width, a percentage string defines a percentage of the plot
  299. * area width.
  300. *
  301. * @type {number|string}
  302. * @sample {highcharts} highcharts/demo/funnel3d/ Funnel3d demo
  303. * @product highcharts
  304. */
  305. neckWidth: '30%',
  306. /**
  307. * The height of the series. If it is a number it defines
  308. * the pixel height, if it is a percentage string it is the percentage
  309. * of the plot area height.
  310. *
  311. * @type {number|string}
  312. * @sample {highcharts} highcharts/demo/funnel3d/ Funnel3d demo
  313. * @product highcharts
  314. */
  315. height: '100%',
  316. /**
  317. * The height of the neck, the lower part of the funnel. A number
  318. * defines pixel width, a percentage string defines a percentage
  319. * of the plot area height.
  320. *
  321. * @type {number|string}
  322. * @sample {highcharts} highcharts/demo/funnel3d/ Funnel3d demo
  323. * @product highcharts
  324. */
  325. neckHeight: '25%',
  326. /**
  327. * A reversed funnel has the widest area down. A reversed funnel with
  328. * no neck width and neck height is a pyramid.
  329. *
  330. * @product highcharts
  331. */
  332. reversed: false,
  333. /**
  334. * By deafult sides fill is set to a gradient through this option being
  335. * set to `true`. Set to `false` to get solid color for the sides.
  336. *
  337. * @product highcharts
  338. */
  339. gradientForSides: true,
  340. animation: false,
  341. edgeWidth: 0,
  342. colorByPoint: true,
  343. showInLegend: false,
  344. dataLabels: {
  345. align: 'right',
  346. crop: false,
  347. inside: false,
  348. overflow: 'allow'
  349. }
  350. });
  351. return Funnel3DSeries;
  352. }(ColumnSeries));
  353. extend(Funnel3DSeries.prototype, {
  354. pointClass: Funnel3DPoint,
  355. translate3dShapes: noop
  356. });
  357. SeriesRegistry.registerSeriesType('funnel3d', Funnel3DSeries);
  358. /* *
  359. *
  360. * Default Export
  361. *
  362. * */
  363. export default Funnel3DSeries;
  364. /* *
  365. *
  366. * API Options
  367. *
  368. * */
  369. /**
  370. * A `funnel3d` series. If the [type](#series.funnel3d.type) option is
  371. * not specified, it is inherited from [chart.type](#chart.type).
  372. *
  373. * @sample {highcharts} highcharts/demo/funnel3d/
  374. * Funnel3d demo
  375. *
  376. * @since 7.1.0
  377. * @extends series.funnel,plotOptions.funnel3d
  378. * @excluding allAreas,boostThreshold,colorAxis,compare,compareBase
  379. * @product highcharts
  380. * @requires highcharts-3d
  381. * @requires modules/cylinder
  382. * @requires modules/funnel3d
  383. * @apioption series.funnel3d
  384. */
  385. /**
  386. * An array of data points for the series. For the `funnel3d` series
  387. * type, points can be given in the following ways:
  388. *
  389. * 1. An array of numerical values. In this case, the numerical values
  390. * will be interpreted as `y` options. The `x` values will be automatically
  391. * calculated, either starting at 0 and incremented by 1, or from `pointStart`
  392. * and `pointInterval` given in the series options. If the axis has
  393. * categories, these will be used. Example:
  394. *
  395. * ```js
  396. * data: [0, 5, 3, 5]
  397. * ```
  398. *
  399. * 2. An array of objects with named values. The following snippet shows only a
  400. * few settings, see the complete options set below. If the total number of data
  401. * points exceeds the series' [turboThreshold](#series.funnel3d.turboThreshold),
  402. * this option is not available.
  403. *
  404. * ```js
  405. * data: [{
  406. * y: 2,
  407. * name: "Point2",
  408. * color: "#00FF00"
  409. * }, {
  410. * y: 4,
  411. * name: "Point1",
  412. * color: "#FF00FF"
  413. * }]
  414. * ```
  415. *
  416. * @sample {highcharts} highcharts/chart/reflow-true/
  417. * Numerical values
  418. * @sample {highcharts} highcharts/series/data-array-of-arrays/
  419. * Arrays of numeric x and y
  420. * @sample {highcharts} highcharts/series/data-array-of-arrays-datetime/
  421. * Arrays of datetime x and y
  422. * @sample {highcharts} highcharts/series/data-array-of-name-value/
  423. * Arrays of point.name and y
  424. * @sample {highcharts} highcharts/series/data-array-of-objects/
  425. * Config objects
  426. *
  427. * @type {Array<number|Array<number>|*>}
  428. * @extends series.column.data
  429. * @product highcharts
  430. * @apioption series.funnel3d.data
  431. */
  432. /**
  433. * By deafult sides fill is set to a gradient through this option being
  434. * set to `true`. Set to `false` to get solid color for the sides.
  435. *
  436. * @type {boolean}
  437. * @product highcharts
  438. * @apioption series.funnel3d.data.gradientForSides
  439. */
  440. ''; // keeps doclets above in transpiled file