cylinder.src.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. /**
  2. * @license Highcharts JS v9.1.1 (2021-06-04)
  3. *
  4. * Highcharts cylinder 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/cylinder', ['highcharts', 'highcharts/highcharts-3d'], 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/Cylinder/CylinderPoint.js', [_modules['Core/Series/SeriesRegistry.js'], _modules['Core/Utilities.js']], function (SeriesRegistry, U) {
  32. /* *
  33. *
  34. * Highcharts cylinder - a 3D series
  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 ColumnPoint = SeriesRegistry.seriesTypes.column.prototype.pointClass;
  62. var extend = U.extend;
  63. /* *
  64. *
  65. * Class
  66. *
  67. * */
  68. var CylinderPoint = /** @class */ (function (_super) {
  69. __extends(CylinderPoint, _super);
  70. function CylinderPoint() {
  71. /* *
  72. *
  73. * Properties
  74. *
  75. * */
  76. var _this = _super !== null && _super.apply(this,
  77. arguments) || this;
  78. _this.options = void 0;
  79. _this.series = void 0;
  80. return _this;
  81. }
  82. return CylinderPoint;
  83. }(ColumnPoint));
  84. extend(CylinderPoint.prototype, {
  85. shapeType: 'cylinder'
  86. });
  87. /* *
  88. *
  89. * Default Export
  90. *
  91. * */
  92. return CylinderPoint;
  93. });
  94. _registerModule(_modules, 'Series/Cylinder/CylinderComposition.js', [_modules['Core/Color/Color.js'], _modules['Core/Globals.js'], _modules['Extensions/Math3D.js'], _modules['Core/Renderer/RendererRegistry.js'], _modules['Core/Utilities.js']], function (Color, H, Math3D, RendererRegistry, U) {
  95. /* *
  96. *
  97. * Highcharts cylinder - a 3D series
  98. *
  99. * (c) 2010-2021 Highsoft AS
  100. *
  101. * Author: Kacper Madej
  102. *
  103. * License: www.highcharts.com/license
  104. *
  105. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  106. *
  107. * */
  108. var color = Color.parse;
  109. var charts = H.charts,
  110. deg2rad = H.deg2rad;
  111. var perspective = Math3D.perspective;
  112. var merge = U.merge,
  113. pick = U.pick;
  114. /* *
  115. *
  116. * Composition
  117. *
  118. * */
  119. var rendererProto = RendererRegistry.getRendererType().prototype,
  120. cuboidPath = rendererProto.cuboidPath;
  121. // Check if a path is simplified. The simplified path contains only lineTo
  122. // segments, whereas non-simplified contain curves.
  123. var isSimplified = function (path) {
  124. return !path.some(function (seg) { return seg[0] === 'C'; });
  125. };
  126. // cylinder extends cuboid
  127. var cylinderMethods = merge(rendererProto.elements3d.cuboid, {
  128. parts: ['top', 'bottom', 'front', 'back'],
  129. pathType: 'cylinder',
  130. fillSetter: function (fill) {
  131. this.singleSetterForParts('fill', null, {
  132. front: fill,
  133. back: fill,
  134. top: color(fill).brighten(0.1).get(),
  135. bottom: color(fill).brighten(-0.1).get()
  136. });
  137. // fill for animation getter (#6776)
  138. this.color = this.fill = fill;
  139. return this;
  140. }
  141. });
  142. rendererProto.elements3d.cylinder = cylinderMethods;
  143. rendererProto.cylinder = function (shapeArgs) {
  144. return this.element3d('cylinder', shapeArgs);
  145. };
  146. // Generates paths and zIndexes.
  147. rendererProto.cylinderPath = function (shapeArgs) {
  148. var renderer = this,
  149. chart = charts[renderer.chartIndex],
  150. // decide zIndexes of parts based on cubiod logic, for consistency.
  151. cuboidData = cuboidPath.call(renderer,
  152. shapeArgs),
  153. isTopFirst = !cuboidData.isTop,
  154. isFronFirst = !cuboidData.isFront,
  155. top = renderer.getCylinderEnd(chart,
  156. shapeArgs),
  157. bottom = renderer.getCylinderEnd(chart,
  158. shapeArgs,
  159. true);
  160. return {
  161. front: renderer.getCylinderFront(top, bottom),
  162. back: renderer.getCylinderBack(top, bottom),
  163. top: top,
  164. bottom: bottom,
  165. zIndexes: {
  166. top: isTopFirst ? 3 : 0,
  167. bottom: isTopFirst ? 0 : 3,
  168. front: isFronFirst ? 2 : 1,
  169. back: isFronFirst ? 1 : 2,
  170. group: cuboidData.zIndexes.group
  171. }
  172. };
  173. };
  174. // Returns cylinder Front path
  175. rendererProto.getCylinderFront = function (topPath, bottomPath) {
  176. var path = topPath.slice(0, 3);
  177. if (isSimplified(bottomPath)) {
  178. var move = bottomPath[0];
  179. if (move[0] === 'M') {
  180. path.push(bottomPath[2]);
  181. path.push(bottomPath[1]);
  182. path.push(['L', move[1], move[2]]);
  183. }
  184. }
  185. else {
  186. var move = bottomPath[0],
  187. curve1 = bottomPath[1],
  188. curve2 = bottomPath[2];
  189. if (move[0] === 'M' && curve1[0] === 'C' && curve2[0] === 'C') {
  190. path.push(['L', curve2[5], curve2[6]]);
  191. path.push(['C', curve2[3], curve2[4], curve2[1], curve2[2], curve1[5], curve1[6]]);
  192. path.push(['C', curve1[3], curve1[4], curve1[1], curve1[2], move[1], move[2]]);
  193. }
  194. }
  195. path.push(['Z']);
  196. return path;
  197. };
  198. // Returns cylinder Back path
  199. rendererProto.getCylinderBack = function (topPath, bottomPath) {
  200. var path = [];
  201. if (isSimplified(topPath)) {
  202. var move = topPath[0],
  203. line2 = topPath[2];
  204. if (move[0] === 'M' && line2[0] === 'L') {
  205. path.push(['M', line2[1], line2[2]]);
  206. path.push(topPath[3]);
  207. // End at start
  208. path.push(['L', move[1], move[2]]);
  209. }
  210. }
  211. else {
  212. if (topPath[2][0] === 'C') {
  213. path.push(['M', topPath[2][5], topPath[2][6]]);
  214. }
  215. path.push(topPath[3], topPath[4]);
  216. }
  217. if (isSimplified(bottomPath)) {
  218. var move = bottomPath[0];
  219. if (move[0] === 'M') {
  220. path.push(['L', move[1], move[2]]);
  221. path.push(bottomPath[3]);
  222. path.push(bottomPath[2]);
  223. }
  224. }
  225. else {
  226. var curve2 = bottomPath[2],
  227. curve3 = bottomPath[3],
  228. curve4 = bottomPath[4];
  229. if (curve2[0] === 'C' && curve3[0] === 'C' && curve4[0] === 'C') {
  230. path.push(['L', curve4[5], curve4[6]]);
  231. path.push(['C', curve4[3], curve4[4], curve4[1], curve4[2], curve3[5], curve3[6]]);
  232. path.push(['C', curve3[3], curve3[4], curve3[1], curve3[2], curve2[5], curve2[6]]);
  233. }
  234. }
  235. path.push(['Z']);
  236. return path;
  237. };
  238. // Retruns cylinder path for top or bottom
  239. rendererProto.getCylinderEnd = function (chart, shapeArgs, isBottom) {
  240. var _a = shapeArgs.width,
  241. width = _a === void 0 ? 0 : _a,
  242. _b = shapeArgs.height,
  243. height = _b === void 0 ? 0 : _b,
  244. _c = shapeArgs.alphaCorrection,
  245. alphaCorrection = _c === void 0 ? 0 : _c;
  246. // A half of the smaller one out of width or depth (optional, because
  247. // there's no depth for a funnel that reuses the code)
  248. var depth = pick(shapeArgs.depth,
  249. width, 0),
  250. radius = Math.min(width,
  251. depth) / 2,
  252. // Approximated longest diameter
  253. angleOffset = deg2rad * (chart.options.chart.options3d.beta - 90 +
  254. alphaCorrection),
  255. // Could be top or bottom of the cylinder
  256. y = (shapeArgs.y || 0) + (isBottom ? height : 0),
  257. // Use cubic Bezier curve to draw a cricle in x,z (y is constant).
  258. // More math. at spencermortensen.com/articles/bezier-circle/
  259. c = 0.5519 * radius,
  260. centerX = width / 2 + (shapeArgs.x || 0),
  261. centerZ = depth / 2 + (shapeArgs.z || 0),
  262. // points could be generated in a loop, but readability will plummet
  263. points = [{
  264. x: 0,
  265. y: y,
  266. z: radius
  267. }, {
  268. x: c,
  269. y: y,
  270. z: radius
  271. }, {
  272. x: radius,
  273. y: y,
  274. z: c
  275. }, {
  276. x: radius,
  277. y: y,
  278. z: 0
  279. }, {
  280. x: radius,
  281. y: y,
  282. z: -c
  283. }, {
  284. x: c,
  285. y: y,
  286. z: -radius
  287. }, {
  288. x: 0,
  289. y: y,
  290. z: -radius
  291. }, {
  292. x: -c,
  293. y: y,
  294. z: -radius
  295. }, {
  296. x: -radius,
  297. y: y,
  298. z: -c
  299. }, {
  300. x: -radius,
  301. y: y,
  302. z: 0
  303. }, {
  304. x: -radius,
  305. y: y,
  306. z: c
  307. }, {
  308. x: -c,
  309. y: y,
  310. z: radius
  311. }, {
  312. x: 0,
  313. y: y,
  314. z: radius
  315. }],
  316. cosTheta = Math.cos(angleOffset),
  317. sinTheta = Math.sin(angleOffset),
  318. perspectivePoints,
  319. path,
  320. x,
  321. z;
  322. // rotete to match chart's beta and translate to the shape center
  323. points.forEach(function (point, i) {
  324. x = point.x;
  325. z = point.z;
  326. // x′ = (x * cosθ − z * sinθ) + centerX
  327. // z′ = (z * cosθ + x * sinθ) + centerZ
  328. points[i].x = (x * cosTheta - z * sinTheta) + centerX;
  329. points[i].z = (z * cosTheta + x * sinTheta) + centerZ;
  330. });
  331. perspectivePoints = perspective(points, chart, true);
  332. // check for sub-pixel curve issue, compare front and back edges
  333. if (Math.abs(perspectivePoints[3].y - perspectivePoints[9].y) < 2.5 &&
  334. Math.abs(perspectivePoints[0].y - perspectivePoints[6].y) < 2.5) {
  335. // use simplied shape
  336. path = this.toLinePath([
  337. perspectivePoints[0],
  338. perspectivePoints[3],
  339. perspectivePoints[6],
  340. perspectivePoints[9]
  341. ], true);
  342. }
  343. else {
  344. // or default curved path to imitate ellipse (2D circle)
  345. path = this.getCurvedPath(perspectivePoints);
  346. }
  347. return path;
  348. };
  349. // Returns curved path in format of:
  350. // [ M, x, y, ...[C, cp1x, cp2y, cp2x, cp2y, epx, epy]*n_times ]
  351. // (cp - control point, ep - end point)
  352. rendererProto.getCurvedPath = function (points) {
  353. var path = [['M',
  354. points[0].x,
  355. points[0].y]],
  356. limit = points.length - 2,
  357. i;
  358. for (i = 1; i < limit; i += 3) {
  359. path.push([
  360. 'C',
  361. points[i].x, points[i].y,
  362. points[i + 1].x, points[i + 1].y,
  363. points[i + 2].x, points[i + 2].y
  364. ]);
  365. }
  366. return path;
  367. };
  368. });
  369. _registerModule(_modules, 'Series/Cylinder/CylinderSeries.js', [_modules['Series/Cylinder/CylinderPoint.js'], _modules['Core/Series/SeriesRegistry.js'], _modules['Core/Utilities.js']], function (CylinderPoint, SeriesRegistry, U) {
  370. /* *
  371. *
  372. * Highcharts cylinder - a 3D series
  373. *
  374. * (c) 2010-2021 Highsoft AS
  375. *
  376. * Author: Kacper Madej
  377. *
  378. * License: www.highcharts.com/license
  379. *
  380. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  381. *
  382. * */
  383. var __extends = (this && this.__extends) || (function () {
  384. var extendStatics = function (d,
  385. b) {
  386. extendStatics = Object.setPrototypeOf ||
  387. ({ __proto__: [] } instanceof Array && function (d,
  388. b) { d.__proto__ = b; }) ||
  389. function (d,
  390. b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  391. return extendStatics(d, b);
  392. };
  393. return function (d, b) {
  394. extendStatics(d, b);
  395. function __() { this.constructor = d; }
  396. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  397. };
  398. })();
  399. var ColumnSeries = SeriesRegistry.seriesTypes.column;
  400. var extend = U.extend,
  401. merge = U.merge;
  402. /* *
  403. *
  404. * Class
  405. *
  406. * */
  407. /**
  408. * The cylinder series type.
  409. *
  410. * @requires module:highcharts-3d
  411. * @requires module:modules/cylinder
  412. *
  413. * @private
  414. * @class
  415. * @name Highcharts.seriesTypes.cylinder
  416. *
  417. * @augments Highcharts.Series
  418. */
  419. var CylinderSeries = /** @class */ (function (_super) {
  420. __extends(CylinderSeries, _super);
  421. function CylinderSeries() {
  422. /* *
  423. *
  424. * Static Properties
  425. *
  426. * */
  427. var _this = _super !== null && _super.apply(this,
  428. arguments) || this;
  429. /* *
  430. *
  431. * Properties
  432. *
  433. * */
  434. _this.data = void 0;
  435. _this.options = void 0;
  436. _this.points = void 0;
  437. return _this;
  438. }
  439. /**
  440. * A cylinder graph is a variation of a 3d column graph. The cylinder graph
  441. * features cylindrical points.
  442. *
  443. * @sample {highcharts} highcharts/demo/cylinder/
  444. * Cylinder graph
  445. *
  446. * @extends plotOptions.column
  447. * @since 7.0.0
  448. * @product highcharts
  449. * @excluding allAreas, boostThreshold, colorAxis, compare, compareBase,
  450. * dragDrop, boostBlending
  451. * @requires modules/cylinder
  452. * @optionparent plotOptions.cylinder
  453. */
  454. CylinderSeries.defaultOptions = merge(ColumnSeries.defaultOptions);
  455. return CylinderSeries;
  456. }(ColumnSeries));
  457. extend(CylinderSeries.prototype, {
  458. pointClass: CylinderPoint
  459. });
  460. SeriesRegistry.registerSeriesType('cylinder', CylinderSeries);
  461. /* *
  462. *
  463. * Default Export
  464. *
  465. * */
  466. /* *
  467. *
  468. * API Options
  469. *
  470. * */
  471. /**
  472. * A `cylinder` series. If the [type](#series.cylinder.type) option is not
  473. * specified, it is inherited from [chart.type](#chart.type).
  474. *
  475. * @extends series,plotOptions.cylinder
  476. * @since 7.0.0
  477. * @product highcharts
  478. * @excluding allAreas, boostThreshold, colorAxis, compare, compareBase,
  479. * boostBlending
  480. * @requires modules/cylinder
  481. * @apioption series.cylinder
  482. */
  483. /**
  484. * An array of data points for the series. For the `cylinder` series type,
  485. * points can be given in the following ways:
  486. *
  487. * 1. An array of numerical values. In this case, the numerical values will be
  488. * interpreted as `y` options. The `x` values will be automatically
  489. * calculated, either starting at 0 and incremented by 1, or from
  490. * `pointStart` and `pointInterval` given in the series options. If the axis
  491. * has categories, these will be used. Example:
  492. * ```js
  493. * data: [0, 5, 3, 5]
  494. * ```
  495. *
  496. * 2. An array of arrays with 2 values. In this case, the values correspond to
  497. * `x,y`. If the first value is a string, it is applied as the name of the
  498. * point, and the `x` value is inferred.
  499. * ```js
  500. * data: [
  501. * [0, 0],
  502. * [1, 8],
  503. * [2, 9]
  504. * ]
  505. * ```
  506. *
  507. * 3. An array of objects with named values. The following snippet shows only a
  508. * few settings, see the complete options set below. If the total number of
  509. * data points exceeds the series'
  510. * [turboThreshold](#series.cylinder.turboThreshold), this option is not
  511. * available.
  512. *
  513. * ```js
  514. * data: [{
  515. * x: 1,
  516. * y: 2,
  517. * name: "Point2",
  518. * color: "#00FF00"
  519. * }, {
  520. * x: 1,
  521. * y: 4,
  522. * name: "Point1",
  523. * color: "#FF00FF"
  524. * }]
  525. * ```
  526. *
  527. * @sample {highcharts} highcharts/chart/reflow-true/
  528. * Numerical values
  529. * @sample {highcharts} highcharts/series/data-array-of-arrays/
  530. * Arrays of numeric x and y
  531. * @sample {highcharts} highcharts/series/data-array-of-arrays-datetime/
  532. * Arrays of datetime x and y
  533. * @sample {highcharts} highcharts/series/data-array-of-name-value/
  534. * Arrays of point.name and y
  535. * @sample {highcharts} highcharts/series/data-array-of-objects/
  536. * Config objects
  537. *
  538. * @type {Array<number|Array<(number|string),(number|null)>|null|*>}
  539. * @extends series.column.data
  540. * @product highcharts highstock
  541. * @apioption series.cylinder.data
  542. */
  543. ''; // keeps doclets above in the transpiled file
  544. return CylinderSeries;
  545. });
  546. _registerModule(_modules, 'masters/modules/cylinder.src.js', [], function () {
  547. });
  548. }));