funnel3d.src.js 32 KB

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