funnel3d.src.js 26 KB

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