funnel3d.src.js 34 KB

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