cylinder.src.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. /**
  2. * @license Highcharts JS v9.0.1 (2021-02-16)
  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/Utilities.js']], function (Color, H, Math3D, 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. RendererProto = H.Renderer.prototype;
  112. var perspective = Math3D.perspective;
  113. var merge = U.merge,
  114. pick = U.pick;
  115. /* *
  116. *
  117. * Composition
  118. *
  119. * */
  120. var 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. // A half of the smaller one out of width or depth (optional, because
  241. // there's no depth for a funnel that reuses the code)
  242. var depth = pick(shapeArgs.depth,
  243. shapeArgs.width),
  244. radius = Math.min(shapeArgs.width,
  245. depth) / 2,
  246. // Approximated longest diameter
  247. angleOffset = deg2rad * (chart.options.chart.options3d.beta - 90 +
  248. (shapeArgs.alphaCorrection || 0)),
  249. // Could be top or bottom of the cylinder
  250. y = shapeArgs.y + (isBottom ? shapeArgs.height : 0),
  251. // Use cubic Bezier curve to draw a cricle in x,z (y is constant).
  252. // More math. at spencermortensen.com/articles/bezier-circle/
  253. c = 0.5519 * radius,
  254. centerX = shapeArgs.width / 2 + shapeArgs.x,
  255. centerZ = depth / 2 + shapeArgs.z,
  256. // points could be generated in a loop, but readability will plummet
  257. points = [{
  258. x: 0,
  259. y: y,
  260. z: radius
  261. }, {
  262. x: c,
  263. y: y,
  264. z: radius
  265. }, {
  266. x: radius,
  267. y: y,
  268. z: c
  269. }, {
  270. x: radius,
  271. y: y,
  272. z: 0
  273. }, {
  274. x: radius,
  275. y: y,
  276. z: -c
  277. }, {
  278. x: c,
  279. y: y,
  280. z: -radius
  281. }, {
  282. x: 0,
  283. y: y,
  284. z: -radius
  285. }, {
  286. x: -c,
  287. y: y,
  288. z: -radius
  289. }, {
  290. x: -radius,
  291. y: y,
  292. z: -c
  293. }, {
  294. x: -radius,
  295. y: y,
  296. z: 0
  297. }, {
  298. x: -radius,
  299. y: y,
  300. z: c
  301. }, {
  302. x: -c,
  303. y: y,
  304. z: radius
  305. }, {
  306. x: 0,
  307. y: y,
  308. z: radius
  309. }],
  310. cosTheta = Math.cos(angleOffset),
  311. sinTheta = Math.sin(angleOffset),
  312. perspectivePoints,
  313. path,
  314. x,
  315. z;
  316. // rotete to match chart's beta and translate to the shape center
  317. points.forEach(function (point, i) {
  318. x = point.x;
  319. z = point.z;
  320. // x′ = (x * cosθ − z * sinθ) + centerX
  321. // z′ = (z * cosθ + x * sinθ) + centerZ
  322. points[i].x = (x * cosTheta - z * sinTheta) + centerX;
  323. points[i].z = (z * cosTheta + x * sinTheta) + centerZ;
  324. });
  325. perspectivePoints = perspective(points, chart, true);
  326. // check for sub-pixel curve issue, compare front and back edges
  327. if (Math.abs(perspectivePoints[3].y - perspectivePoints[9].y) < 2.5 &&
  328. Math.abs(perspectivePoints[0].y - perspectivePoints[6].y) < 2.5) {
  329. // use simplied shape
  330. path = this.toLinePath([
  331. perspectivePoints[0],
  332. perspectivePoints[3],
  333. perspectivePoints[6],
  334. perspectivePoints[9]
  335. ], true);
  336. }
  337. else {
  338. // or default curved path to imitate ellipse (2D circle)
  339. path = this.getCurvedPath(perspectivePoints);
  340. }
  341. return path;
  342. };
  343. // Returns curved path in format of:
  344. // [ M, x, y, ...[C, cp1x, cp2y, cp2x, cp2y, epx, epy]*n_times ]
  345. // (cp - control point, ep - end point)
  346. RendererProto.getCurvedPath = function (points) {
  347. var path = [['M',
  348. points[0].x,
  349. points[0].y]],
  350. limit = points.length - 2,
  351. i;
  352. for (i = 1; i < limit; i += 3) {
  353. path.push([
  354. 'C',
  355. points[i].x, points[i].y,
  356. points[i + 1].x, points[i + 1].y,
  357. points[i + 2].x, points[i + 2].y
  358. ]);
  359. }
  360. return path;
  361. };
  362. });
  363. _registerModule(_modules, 'Series/Cylinder/CylinderSeries.js', [_modules['Series/Cylinder/CylinderPoint.js'], _modules['Core/Series/SeriesRegistry.js'], _modules['Core/Utilities.js']], function (CylinderPoint, SeriesRegistry, U) {
  364. /* *
  365. *
  366. * Highcharts cylinder - a 3D series
  367. *
  368. * (c) 2010-2021 Highsoft AS
  369. *
  370. * Author: Kacper Madej
  371. *
  372. * License: www.highcharts.com/license
  373. *
  374. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  375. *
  376. * */
  377. var __extends = (this && this.__extends) || (function () {
  378. var extendStatics = function (d,
  379. b) {
  380. extendStatics = Object.setPrototypeOf ||
  381. ({ __proto__: [] } instanceof Array && function (d,
  382. b) { d.__proto__ = b; }) ||
  383. function (d,
  384. b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  385. return extendStatics(d, b);
  386. };
  387. return function (d, b) {
  388. extendStatics(d, b);
  389. function __() { this.constructor = d; }
  390. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  391. };
  392. })();
  393. var ColumnSeries = SeriesRegistry.seriesTypes.column;
  394. var extend = U.extend,
  395. merge = U.merge;
  396. /* *
  397. *
  398. * Class
  399. *
  400. * */
  401. /**
  402. * The cylinder series type.
  403. *
  404. * @requires module:highcharts-3d
  405. * @requires module:modules/cylinder
  406. *
  407. * @private
  408. * @class
  409. * @name Highcharts.seriesTypes.cylinder
  410. *
  411. * @augments Highcharts.Series
  412. */
  413. var CylinderSeries = /** @class */ (function (_super) {
  414. __extends(CylinderSeries, _super);
  415. function CylinderSeries() {
  416. /* *
  417. *
  418. * Static Properties
  419. *
  420. * */
  421. var _this = _super !== null && _super.apply(this,
  422. arguments) || this;
  423. /* *
  424. *
  425. * Properties
  426. *
  427. * */
  428. _this.data = void 0;
  429. _this.options = void 0;
  430. _this.points = void 0;
  431. return _this;
  432. }
  433. /**
  434. * A cylinder graph is a variation of a 3d column graph. The cylinder graph
  435. * features cylindrical points.
  436. *
  437. * @sample {highcharts} highcharts/demo/cylinder/
  438. * Cylinder graph
  439. *
  440. * @extends plotOptions.column
  441. * @since 7.0.0
  442. * @product highcharts
  443. * @excluding allAreas, boostThreshold, colorAxis, compare, compareBase,
  444. * dragDrop, boostBlending
  445. * @requires modules/cylinder
  446. * @optionparent plotOptions.cylinder
  447. */
  448. CylinderSeries.defaultOptions = merge(ColumnSeries.defaultOptions);
  449. return CylinderSeries;
  450. }(ColumnSeries));
  451. extend(CylinderSeries.prototype, {
  452. pointClass: CylinderPoint
  453. });
  454. SeriesRegistry.registerSeriesType('cylinder', CylinderSeries);
  455. /* *
  456. *
  457. * Default Export
  458. *
  459. * */
  460. /* *
  461. *
  462. * API Options
  463. *
  464. * */
  465. /**
  466. * A `cylinder` series. If the [type](#series.cylinder.type) option is not
  467. * specified, it is inherited from [chart.type](#chart.type).
  468. *
  469. * @extends series,plotOptions.cylinder
  470. * @since 7.0.0
  471. * @product highcharts
  472. * @excluding allAreas, boostThreshold, colorAxis, compare, compareBase,
  473. * boostBlending
  474. * @requires modules/cylinder
  475. * @apioption series.cylinder
  476. */
  477. /**
  478. * An array of data points for the series. For the `cylinder` series type,
  479. * points can be given in the following ways:
  480. *
  481. * 1. An array of numerical values. In this case, the numerical values will be
  482. * interpreted as `y` options. The `x` values will be automatically
  483. * calculated, either starting at 0 and incremented by 1, or from
  484. * `pointStart` and `pointInterval` given in the series options. If the axis
  485. * has categories, these will be used. Example:
  486. * ```js
  487. * data: [0, 5, 3, 5]
  488. * ```
  489. *
  490. * 2. An array of arrays with 2 values. In this case, the values correspond to
  491. * `x,y`. If the first value is a string, it is applied as the name of the
  492. * point, and the `x` value is inferred.
  493. * ```js
  494. * data: [
  495. * [0, 0],
  496. * [1, 8],
  497. * [2, 9]
  498. * ]
  499. * ```
  500. *
  501. * 3. An array of objects with named values. The following snippet shows only a
  502. * few settings, see the complete options set below. If the total number of
  503. * data points exceeds the series'
  504. * [turboThreshold](#series.cylinder.turboThreshold), this option is not
  505. * available.
  506. *
  507. * ```js
  508. * data: [{
  509. * x: 1,
  510. * y: 2,
  511. * name: "Point2",
  512. * color: "#00FF00"
  513. * }, {
  514. * x: 1,
  515. * y: 4,
  516. * name: "Point1",
  517. * color: "#FF00FF"
  518. * }]
  519. * ```
  520. *
  521. * @sample {highcharts} highcharts/chart/reflow-true/
  522. * Numerical values
  523. * @sample {highcharts} highcharts/series/data-array-of-arrays/
  524. * Arrays of numeric x and y
  525. * @sample {highcharts} highcharts/series/data-array-of-arrays-datetime/
  526. * Arrays of datetime x and y
  527. * @sample {highcharts} highcharts/series/data-array-of-name-value/
  528. * Arrays of point.name and y
  529. * @sample {highcharts} highcharts/series/data-array-of-objects/
  530. * Config objects
  531. *
  532. * @type {Array<number|Array<(number|string),(number|null)>|null|*>}
  533. * @extends series.column.data
  534. * @product highcharts highstock
  535. * @apioption series.cylinder.data
  536. */
  537. ''; // keeps doclets above in the transpiled file
  538. return CylinderSeries;
  539. });
  540. _registerModule(_modules, 'masters/modules/cylinder.src.js', [], function () {
  541. });
  542. }));