Funnel3DSeries.js 26 KB

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