funnel3d.src.js 40 KB

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