Funnel3DSeries.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. /* *
  2. *
  3. * Highcharts funnel3d series module
  4. *
  5. * (c) 2010-2020 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. import Color from '../Core/Color/Color.js';
  15. var color = Color.parse;
  16. import H from '../Core/Globals.js';
  17. var charts = H.charts, RendererProto = H.Renderer.prototype;
  18. import Math3D from '../Extensions/Math3D.js';
  19. var perspective = Math3D.perspective;
  20. import Series from '../Core/Series/Series.js';
  21. var seriesTypes = Series.seriesTypes;
  22. import U from '../Core/Utilities.js';
  23. var error = U.error, extend = U.extend, merge = U.merge, pick = U.pick, relativeLength = U.relativeLength;
  24. var cuboidPath = RendererProto.cuboidPath, funnel3dMethods;
  25. /**
  26. * The funnel3d series type.
  27. *
  28. * @constructor seriesTypes.funnel3d
  29. * @augments seriesTypes.column
  30. * @requires highcharts-3d
  31. * @requires modules/cylinder
  32. * @requires modules/funnel3d
  33. */
  34. Series.seriesType('funnel3d', 'column',
  35. /**
  36. * A funnel3d is a 3d version of funnel series type. Funnel charts are
  37. * a type of chart often used to visualize stages in a sales project,
  38. * where the top are the initial stages with the most clients.
  39. *
  40. * It requires that the `highcharts-3d.js`, `cylinder.js` and
  41. * `funnel3d.js` module are loaded.
  42. *
  43. * @sample highcharts/demo/funnel3d/
  44. * Funnel3d
  45. *
  46. * @extends plotOptions.column
  47. * @excluding allAreas, boostThreshold, colorAxis, compare, compareBase,
  48. * dataSorting, boostBlending
  49. * @product highcharts
  50. * @since 7.1.0
  51. * @requires highcharts-3d
  52. * @requires modules/cylinder
  53. * @requires modules/funnel3d
  54. * @optionparent plotOptions.funnel3d
  55. */
  56. {
  57. /** @ignore-option */
  58. center: ['50%', '50%'],
  59. /**
  60. * The max width of the series compared to the width of the plot area,
  61. * or the pixel width if it is a number.
  62. *
  63. * @type {number|string}
  64. * @sample {highcharts} highcharts/demo/funnel3d/ Funnel3d demo
  65. * @product highcharts
  66. */
  67. width: '90%',
  68. /**
  69. * The width of the neck, the lower part of the funnel. A number defines
  70. * pixel width, a percentage string defines a percentage of the plot
  71. * area width.
  72. *
  73. * @type {number|string}
  74. * @sample {highcharts} highcharts/demo/funnel3d/ Funnel3d demo
  75. * @product highcharts
  76. */
  77. neckWidth: '30%',
  78. /**
  79. * The height of the series. If it is a number it defines
  80. * the pixel height, if it is a percentage string it is the percentage
  81. * of the plot area height.
  82. *
  83. * @type {number|string}
  84. * @sample {highcharts} highcharts/demo/funnel3d/ Funnel3d demo
  85. * @product highcharts
  86. */
  87. height: '100%',
  88. /**
  89. * The height of the neck, the lower part of the funnel. A number
  90. * defines pixel width, a percentage string defines a percentage
  91. * of the plot area height.
  92. *
  93. * @type {number|string}
  94. * @sample {highcharts} highcharts/demo/funnel3d/ Funnel3d demo
  95. * @product highcharts
  96. */
  97. neckHeight: '25%',
  98. /**
  99. * A reversed funnel has the widest area down. A reversed funnel with
  100. * no neck width and neck height is a pyramid.
  101. *
  102. * @product highcharts
  103. */
  104. reversed: false,
  105. /**
  106. * By deafult sides fill is set to a gradient through this option being
  107. * set to `true`. Set to `false` to get solid color for the sides.
  108. *
  109. * @product highcharts
  110. */
  111. gradientForSides: true,
  112. animation: false,
  113. edgeWidth: 0,
  114. colorByPoint: true,
  115. showInLegend: false,
  116. dataLabels: {
  117. align: 'right',
  118. crop: false,
  119. inside: false,
  120. overflow: 'allow'
  121. }
  122. }, {
  123. // Override default axis options with series required options for axes
  124. bindAxes: function () {
  125. H.Series.prototype.bindAxes.apply(this, arguments);
  126. extend(this.xAxis.options, {
  127. gridLineWidth: 0,
  128. lineWidth: 0,
  129. title: null,
  130. tickPositions: []
  131. });
  132. extend(this.yAxis.options, {
  133. gridLineWidth: 0,
  134. title: null,
  135. labels: {
  136. enabled: false
  137. }
  138. });
  139. },
  140. translate3dShapes: H.noop,
  141. translate: function () {
  142. H.Series.prototype.translate.apply(this, arguments);
  143. 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
  144. 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,
  145. //
  146. y1, y3, y5,
  147. //
  148. h, shapeArgs;
  149. // Return the width at a specific y coordinate
  150. series.getWidthAt = getWidthAt = function (y) {
  151. var top = (centerY - height / 2);
  152. return (y > neckY || height === neckHeight) ?
  153. neckWidth :
  154. neckWidth + (width - neckWidth) *
  155. (1 - (y - top) / (height - neckHeight));
  156. };
  157. // Expose
  158. series.center = [centerX, centerY, height];
  159. series.centerX = centerX;
  160. /*
  161. * Individual point coordinate naming:
  162. *
  163. * _________centerX,y1________
  164. * \ /
  165. * \ /
  166. * \ /
  167. * \ /
  168. * \ /
  169. * ___centerX,y3___
  170. *
  171. * Additional for the base of the neck:
  172. *
  173. * | |
  174. * | |
  175. * | |
  176. * ___centerX,y5___
  177. */
  178. // get the total sum
  179. data.forEach(function (point) {
  180. if (!ignoreHiddenPoint || point.visible !== false) {
  181. sum += point.y;
  182. }
  183. });
  184. data.forEach(function (point) {
  185. // set start and end positions
  186. y5 = null;
  187. fraction = sum ? point.y / sum : 0;
  188. y1 = centerY - height / 2 + cumulative * height;
  189. y3 = y1 + fraction * height;
  190. tempWidth = getWidthAt(y1);
  191. h = y3 - y1;
  192. shapeArgs = {
  193. // for fill setter
  194. gradientForSides: pick(point.options.gradientForSides, options.gradientForSides),
  195. x: centerX,
  196. y: y1,
  197. height: h,
  198. width: tempWidth,
  199. z: 1,
  200. top: {
  201. width: tempWidth
  202. }
  203. };
  204. tempWidth = getWidthAt(y3);
  205. shapeArgs.bottom = {
  206. fraction: fraction,
  207. width: tempWidth
  208. };
  209. // the entire point is within the neck
  210. if (y1 >= neckY) {
  211. shapeArgs.isCylinder = true;
  212. }
  213. else if (y3 > neckY) {
  214. // the base of the neck
  215. y5 = y3;
  216. tempWidth = getWidthAt(neckY);
  217. y3 = neckY;
  218. shapeArgs.bottom.width = tempWidth;
  219. shapeArgs.middle = {
  220. fraction: h ? (neckY - y1) / h : 0,
  221. width: tempWidth
  222. };
  223. }
  224. if (reversed) {
  225. shapeArgs.y = y1 = centerY + height / 2 -
  226. (cumulative + fraction) * height;
  227. if (shapeArgs.middle) {
  228. shapeArgs.middle.fraction = 1 -
  229. (h ? shapeArgs.middle.fraction : 0);
  230. }
  231. tempWidth = shapeArgs.width;
  232. shapeArgs.width = shapeArgs.bottom.width;
  233. shapeArgs.bottom.width = tempWidth;
  234. }
  235. point.shapeArgs = extend(point.shapeArgs, shapeArgs);
  236. // for tooltips and data labels context
  237. point.percentage = fraction * 100;
  238. point.plotX = centerX;
  239. if (reversed) {
  240. point.plotY = centerY + height / 2 -
  241. (cumulative + fraction / 2) * height;
  242. }
  243. else {
  244. point.plotY = (y1 + (y5 || y3)) / 2;
  245. }
  246. // Placement of tooltips and data labels in 3D
  247. tooltipPos = perspective([{
  248. x: centerX,
  249. y: point.plotY,
  250. z: reversed ?
  251. -(width - getWidthAt(point.plotY)) / 2 :
  252. -(getWidthAt(point.plotY)) / 2
  253. }], chart, true)[0];
  254. point.tooltipPos = [tooltipPos.x, tooltipPos.y];
  255. // base to be used when alignment options are known
  256. point.dlBoxRaw = {
  257. x: centerX,
  258. width: getWidthAt(point.plotY),
  259. y: y1,
  260. bottom: shapeArgs.height,
  261. fullWidth: width
  262. };
  263. if (!ignoreHiddenPoint || point.visible !== false) {
  264. cumulative += fraction;
  265. }
  266. });
  267. },
  268. alignDataLabel: function (point, dataLabel, options) {
  269. 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 = {
  270. x: dlBoxRaw.x,
  271. y: dlBoxRaw.y,
  272. height: 0
  273. };
  274. options.align = pick(options.align, !inverted || inside ? 'center' : below ? 'right' : 'left');
  275. options.verticalAlign = pick(options.verticalAlign, inverted || inside ? 'middle' : below ? 'top' : 'bottom');
  276. if (options.verticalAlign !== 'top') {
  277. dlBox.y += dlBoxRaw.bottom /
  278. (options.verticalAlign === 'bottom' ? 1 : 2);
  279. }
  280. dlBox.width = series.getWidthAt(dlBox.y);
  281. if (series.options.reversed) {
  282. dlBox.width = dlBoxRaw.fullWidth - dlBox.width;
  283. }
  284. if (inside) {
  285. dlBox.x -= dlBox.width / 2;
  286. }
  287. else {
  288. // swap for inside
  289. if (options.align === 'left') {
  290. options.align = 'right';
  291. dlBox.x -= dlBox.width * 1.5;
  292. }
  293. else if (options.align === 'right') {
  294. options.align = 'left';
  295. dlBox.x += dlBox.width / 2;
  296. }
  297. else {
  298. dlBox.x -= dlBox.width / 2;
  299. }
  300. }
  301. point.dlBox = dlBox;
  302. seriesTypes.column.prototype.alignDataLabel.apply(series, arguments);
  303. }
  304. }, /** @lends seriesTypes.funnel3d.prototype.pointClass.prototype */ {
  305. shapeType: 'funnel3d',
  306. hasNewShapeType: H
  307. .seriesTypes.column.prototype
  308. .pointClass.prototype
  309. .hasNewShapeType
  310. });
  311. /**
  312. * A `funnel3d` series. If the [type](#series.funnel3d.type) option is
  313. * not specified, it is inherited from [chart.type](#chart.type).
  314. *
  315. * @sample {highcharts} highcharts/demo/funnel3d/
  316. * Funnel3d demo
  317. *
  318. * @since 7.1.0
  319. * @extends series.funnel,plotOptions.funnel3d
  320. * @excluding allAreas,boostThreshold,colorAxis,compare,compareBase
  321. * @product highcharts
  322. * @requires highcharts-3d
  323. * @requires modules/cylinder
  324. * @requires modules/funnel3d
  325. * @apioption series.funnel3d
  326. */
  327. /**
  328. * An array of data points for the series. For the `funnel3d` series
  329. * type, points can be given in the following ways:
  330. *
  331. * 1. An array of numerical values. In this case, the numerical values
  332. * will be interpreted as `y` options. The `x` values will be automatically
  333. * calculated, either starting at 0 and incremented by 1, or from `pointStart`
  334. * and `pointInterval` given in the series options. If the axis has
  335. * categories, these will be used. Example:
  336. *
  337. * ```js
  338. * data: [0, 5, 3, 5]
  339. * ```
  340. *
  341. * 2. An array of objects with named values. The following snippet shows only a
  342. * few settings, see the complete options set below. If the total number of data
  343. * points exceeds the series' [turboThreshold](#series.funnel3d.turboThreshold),
  344. * this option is not available.
  345. *
  346. * ```js
  347. * data: [{
  348. * y: 2,
  349. * name: "Point2",
  350. * color: "#00FF00"
  351. * }, {
  352. * y: 4,
  353. * name: "Point1",
  354. * color: "#FF00FF"
  355. * }]
  356. * ```
  357. *
  358. * @sample {highcharts} highcharts/chart/reflow-true/
  359. * Numerical values
  360. * @sample {highcharts} highcharts/series/data-array-of-arrays/
  361. * Arrays of numeric x and y
  362. * @sample {highcharts} highcharts/series/data-array-of-arrays-datetime/
  363. * Arrays of datetime x and y
  364. * @sample {highcharts} highcharts/series/data-array-of-name-value/
  365. * Arrays of point.name and y
  366. * @sample {highcharts} highcharts/series/data-array-of-objects/
  367. * Config objects
  368. *
  369. * @type {Array<number|Array<number>|*>}
  370. * @extends series.column.data
  371. * @product highcharts
  372. * @apioption series.funnel3d.data
  373. */
  374. /**
  375. * By deafult sides fill is set to a gradient through this option being
  376. * set to `true`. Set to `false` to get solid color for the sides.
  377. *
  378. * @type {boolean}
  379. * @product highcharts
  380. * @apioption series.funnel3d.data.gradientForSides
  381. */
  382. funnel3dMethods = merge(RendererProto.elements3d.cuboid, {
  383. parts: [
  384. 'top', 'bottom',
  385. 'frontUpper', 'backUpper',
  386. 'frontLower', 'backLower',
  387. 'rightUpper', 'rightLower'
  388. ],
  389. mainParts: ['top', 'bottom'],
  390. sideGroups: [
  391. 'upperGroup', 'lowerGroup'
  392. ],
  393. sideParts: {
  394. upperGroup: ['frontUpper', 'backUpper', 'rightUpper'],
  395. lowerGroup: ['frontLower', 'backLower', 'rightLower']
  396. },
  397. pathType: 'funnel3d',
  398. // override opacity and color setters to control opacity
  399. opacitySetter: function (opacity) {
  400. var funnel3d = this, parts = funnel3d.parts, chart = H.charts[funnel3d.renderer.chartIndex], filterId = 'group-opacity-' + opacity + '-' + chart.index;
  401. // use default for top and bottom
  402. funnel3d.parts = funnel3d.mainParts;
  403. funnel3d.singleSetterForParts('opacity', opacity);
  404. // restore
  405. funnel3d.parts = parts;
  406. if (!chart.renderer.filterId) {
  407. chart.renderer.definition({
  408. tagName: 'filter',
  409. id: filterId,
  410. children: [{
  411. tagName: 'feComponentTransfer',
  412. children: [{
  413. tagName: 'feFuncA',
  414. type: 'table',
  415. tableValues: '0 ' + opacity
  416. }]
  417. }]
  418. });
  419. funnel3d.sideGroups.forEach(function (groupName) {
  420. funnel3d[groupName].attr({
  421. filter: 'url(#' + filterId + ')'
  422. });
  423. });
  424. // styled mode
  425. if (funnel3d.renderer.styledMode) {
  426. chart.renderer.definition({
  427. tagName: 'style',
  428. textContent: '.highcharts-' + filterId +
  429. ' {filter:url(#' + filterId + ')}'
  430. });
  431. funnel3d.sideGroups.forEach(function (group) {
  432. group.addClass('highcharts-' + filterId);
  433. });
  434. }
  435. }
  436. return funnel3d;
  437. },
  438. fillSetter: function (fill) {
  439. // extract alpha channel to use the opacitySetter
  440. var funnel3d = this, fillColor = color(fill), alpha = fillColor.rgba[3], partsWithColor = {
  441. // standard color for top and bottom
  442. top: color(fill).brighten(0.1).get(),
  443. bottom: color(fill).brighten(-0.2).get()
  444. };
  445. if (alpha < 1) {
  446. fillColor.rgba[3] = 1;
  447. fillColor = fillColor.get('rgb');
  448. // set opacity through the opacitySetter
  449. funnel3d.attr({
  450. opacity: alpha
  451. });
  452. }
  453. else {
  454. // use default for full opacity
  455. fillColor = fill;
  456. }
  457. // add gradient for sides
  458. if (!fillColor.linearGradient &&
  459. !fillColor.radialGradient &&
  460. funnel3d.gradientForSides) {
  461. fillColor = {
  462. linearGradient: { x1: 0, x2: 1, y1: 1, y2: 1 },
  463. stops: [
  464. [0, color(fill).brighten(-0.2).get()],
  465. [0.5, fill],
  466. [1, color(fill).brighten(-0.2).get()]
  467. ]
  468. };
  469. }
  470. // gradient support
  471. if (fillColor.linearGradient) {
  472. // color in steps, as each gradient will generate a key
  473. funnel3d.sideGroups.forEach(function (sideGroupName) {
  474. var box = funnel3d[sideGroupName].gradientBox, gradient = fillColor.linearGradient, alteredGradient = merge(fillColor, {
  475. linearGradient: {
  476. x1: box.x + gradient.x1 * box.width,
  477. y1: box.y + gradient.y1 * box.height,
  478. x2: box.x + gradient.x2 * box.width,
  479. y2: box.y + gradient.y2 * box.height
  480. }
  481. });
  482. funnel3d.sideParts[sideGroupName].forEach(function (partName) {
  483. partsWithColor[partName] = alteredGradient;
  484. });
  485. });
  486. }
  487. else {
  488. merge(true, partsWithColor, {
  489. frontUpper: fillColor,
  490. backUpper: fillColor,
  491. rightUpper: fillColor,
  492. frontLower: fillColor,
  493. backLower: fillColor,
  494. rightLower: fillColor
  495. });
  496. if (fillColor.radialGradient) {
  497. funnel3d.sideGroups.forEach(function (sideGroupName) {
  498. var gradBox = funnel3d[sideGroupName].gradientBox, centerX = gradBox.x + gradBox.width / 2, centerY = gradBox.y + gradBox.height / 2, diameter = Math.min(gradBox.width, gradBox.height);
  499. funnel3d.sideParts[sideGroupName].forEach(function (partName) {
  500. funnel3d[partName].setRadialReference([
  501. centerX, centerY, diameter
  502. ]);
  503. });
  504. });
  505. }
  506. }
  507. funnel3d.singleSetterForParts('fill', null, partsWithColor);
  508. // fill for animation getter (#6776)
  509. funnel3d.color = funnel3d.fill = fill;
  510. // change gradientUnits to userSpaceOnUse for linearGradient
  511. if (fillColor.linearGradient) {
  512. [funnel3d.frontLower, funnel3d.frontUpper].forEach(function (part) {
  513. var elem = part.element, grad = elem && funnel3d.renderer.gradients[elem.gradient];
  514. if (grad && grad.attr('gradientUnits') !== 'userSpaceOnUse') {
  515. grad.attr({
  516. gradientUnits: 'userSpaceOnUse'
  517. });
  518. }
  519. });
  520. }
  521. return funnel3d;
  522. },
  523. adjustForGradient: function () {
  524. var funnel3d = this, bbox;
  525. funnel3d.sideGroups.forEach(function (sideGroupName) {
  526. // use common extremes for groups for matching gradients
  527. var topLeftEdge = {
  528. x: Number.MAX_VALUE,
  529. y: Number.MAX_VALUE
  530. }, bottomRightEdge = {
  531. x: -Number.MAX_VALUE,
  532. y: -Number.MAX_VALUE
  533. };
  534. // get extremes
  535. funnel3d.sideParts[sideGroupName].forEach(function (partName) {
  536. var part = funnel3d[partName];
  537. bbox = part.getBBox(true);
  538. topLeftEdge = {
  539. x: Math.min(topLeftEdge.x, bbox.x),
  540. y: Math.min(topLeftEdge.y, bbox.y)
  541. };
  542. bottomRightEdge = {
  543. x: Math.max(bottomRightEdge.x, bbox.x + bbox.width),
  544. y: Math.max(bottomRightEdge.y, bbox.y + bbox.height)
  545. };
  546. });
  547. // store for color fillSetter
  548. funnel3d[sideGroupName].gradientBox = {
  549. x: topLeftEdge.x,
  550. width: bottomRightEdge.x - topLeftEdge.x,
  551. y: topLeftEdge.y,
  552. height: bottomRightEdge.y - topLeftEdge.y
  553. };
  554. });
  555. },
  556. zIndexSetter: function () {
  557. // this.added won't work, because zIndex is set after the prop is set,
  558. // but before the graphic is really added
  559. if (this.finishedOnAdd) {
  560. this.adjustForGradient();
  561. }
  562. // run default
  563. return this.renderer.Element.prototype.zIndexSetter.apply(this, arguments);
  564. },
  565. onAdd: function () {
  566. this.adjustForGradient();
  567. this.finishedOnAdd = true;
  568. }
  569. });
  570. RendererProto.elements3d.funnel3d = funnel3dMethods;
  571. RendererProto.funnel3d = function (shapeArgs) {
  572. var renderer = this, funnel3d = renderer.element3d('funnel3d', shapeArgs), styledMode = renderer.styledMode,
  573. // hide stroke for Firefox
  574. strokeAttrs = {
  575. 'stroke-width': 1,
  576. stroke: 'none'
  577. };
  578. // create groups for sides for oppacity setter
  579. funnel3d.upperGroup = renderer.g('funnel3d-upper-group').attr({
  580. zIndex: funnel3d.frontUpper.zIndex
  581. }).add(funnel3d);
  582. [
  583. funnel3d.frontUpper,
  584. funnel3d.backUpper,
  585. funnel3d.rightUpper
  586. ].forEach(function (upperElem) {
  587. if (!styledMode) {
  588. upperElem.attr(strokeAttrs);
  589. }
  590. upperElem.add(funnel3d.upperGroup);
  591. });
  592. funnel3d.lowerGroup = renderer.g('funnel3d-lower-group').attr({
  593. zIndex: funnel3d.frontLower.zIndex
  594. }).add(funnel3d);
  595. [
  596. funnel3d.frontLower,
  597. funnel3d.backLower,
  598. funnel3d.rightLower
  599. ].forEach(function (lowerElem) {
  600. if (!styledMode) {
  601. lowerElem.attr(strokeAttrs);
  602. }
  603. lowerElem.add(funnel3d.lowerGroup);
  604. });
  605. funnel3d.gradientForSides = shapeArgs.gradientForSides;
  606. return funnel3d;
  607. };
  608. // eslint-disable-next-line valid-jsdoc
  609. /**
  610. * Generates paths and zIndexes.
  611. * @private
  612. */
  613. RendererProto.funnel3dPath = function (shapeArgs) {
  614. // Check getCylinderEnd for better error message if
  615. // the cylinder module is missing
  616. if (!this.getCylinderEnd) {
  617. error('A required Highcharts module is missing: cylinder.js', true, charts[this.chartIndex]);
  618. }
  619. var renderer = this, chart = charts[renderer.chartIndex],
  620. // adjust angles for visible edges
  621. // based on alpha, selected through visual tests
  622. alphaCorrection = shapeArgs.alphaCorrection = 90 -
  623. Math.abs((chart.options.chart.options3d.alpha % 180) - 90),
  624. // set zIndexes of parts based on cubiod logic, for consistency
  625. cuboidData = cuboidPath.call(renderer, merge(shapeArgs, {
  626. depth: shapeArgs.width,
  627. width: (shapeArgs.width + shapeArgs.bottom.width) / 2
  628. })), isTopFirst = cuboidData.isTop, isFrontFirst = !cuboidData.isFront, hasMiddle = !!shapeArgs.middle,
  629. //
  630. top = renderer.getCylinderEnd(chart, merge(shapeArgs, {
  631. x: shapeArgs.x - shapeArgs.width / 2,
  632. z: shapeArgs.z - shapeArgs.width / 2,
  633. alphaCorrection: alphaCorrection
  634. })), bottomWidth = shapeArgs.bottom.width, bottomArgs = merge(shapeArgs, {
  635. width: bottomWidth,
  636. x: shapeArgs.x - bottomWidth / 2,
  637. z: shapeArgs.z - bottomWidth / 2,
  638. alphaCorrection: alphaCorrection
  639. }), bottom = renderer.getCylinderEnd(chart, bottomArgs, true),
  640. //
  641. middleWidth = bottomWidth, middleTopArgs = bottomArgs, middleTop = bottom, middleBottom = bottom, ret,
  642. // masking for cylinders or a missing part of a side shape
  643. useAlphaCorrection;
  644. if (hasMiddle) {
  645. middleWidth = shapeArgs.middle.width;
  646. middleTopArgs = merge(shapeArgs, {
  647. y: shapeArgs.y + shapeArgs.middle.fraction * shapeArgs.height,
  648. width: middleWidth,
  649. x: shapeArgs.x - middleWidth / 2,
  650. z: shapeArgs.z - middleWidth / 2
  651. });
  652. middleTop = renderer.getCylinderEnd(chart, middleTopArgs, false);
  653. middleBottom = renderer.getCylinderEnd(chart, middleTopArgs, false);
  654. }
  655. ret = {
  656. top: top,
  657. bottom: bottom,
  658. frontUpper: renderer.getCylinderFront(top, middleTop),
  659. zIndexes: {
  660. group: cuboidData.zIndexes.group,
  661. top: isTopFirst !== 0 ? 0 : 3,
  662. bottom: isTopFirst !== 1 ? 0 : 3,
  663. frontUpper: isFrontFirst ? 2 : 1,
  664. backUpper: isFrontFirst ? 1 : 2,
  665. rightUpper: isFrontFirst ? 2 : 1
  666. }
  667. };
  668. ret.backUpper = renderer.getCylinderBack(top, middleTop);
  669. useAlphaCorrection = (Math.min(middleWidth, shapeArgs.width) /
  670. Math.max(middleWidth, shapeArgs.width)) !== 1;
  671. ret.rightUpper = renderer.getCylinderFront(renderer.getCylinderEnd(chart, merge(shapeArgs, {
  672. x: shapeArgs.x - shapeArgs.width / 2,
  673. z: shapeArgs.z - shapeArgs.width / 2,
  674. alphaCorrection: useAlphaCorrection ? -alphaCorrection : 0
  675. }), false), renderer.getCylinderEnd(chart, merge(middleTopArgs, {
  676. alphaCorrection: useAlphaCorrection ? -alphaCorrection : 0
  677. }), !hasMiddle));
  678. if (hasMiddle) {
  679. useAlphaCorrection = (Math.min(middleWidth, bottomWidth) /
  680. Math.max(middleWidth, bottomWidth)) !== 1;
  681. merge(true, ret, {
  682. frontLower: renderer.getCylinderFront(middleBottom, bottom),
  683. backLower: renderer.getCylinderBack(middleBottom, bottom),
  684. rightLower: renderer.getCylinderFront(renderer.getCylinderEnd(chart, merge(bottomArgs, {
  685. alphaCorrection: useAlphaCorrection ?
  686. -alphaCorrection : 0
  687. }), true), renderer.getCylinderEnd(chart, merge(middleTopArgs, {
  688. alphaCorrection: useAlphaCorrection ?
  689. -alphaCorrection : 0
  690. }), false)),
  691. zIndexes: {
  692. frontLower: isFrontFirst ? 2 : 1,
  693. backLower: isFrontFirst ? 1 : 2,
  694. rightLower: isFrontFirst ? 1 : 2
  695. }
  696. });
  697. }
  698. return ret;
  699. };