Pie3DSeries.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /* *
  2. *
  3. * (c) 2010-2021 Torstein Honsi
  4. *
  5. * 3D pie series
  6. *
  7. * License: www.highcharts.com/license
  8. *
  9. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  10. *
  11. * */
  12. 'use strict';
  13. var __extends = (this && this.__extends) || (function () {
  14. var extendStatics = function (d, b) {
  15. extendStatics = Object.setPrototypeOf ||
  16. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  17. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  18. return extendStatics(d, b);
  19. };
  20. return function (d, b) {
  21. extendStatics(d, b);
  22. function __() { this.constructor = d; }
  23. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  24. };
  25. })();
  26. import H from '../../Core/Globals.js';
  27. var deg2rad = H.deg2rad, svg = H.svg;
  28. import Pie3DPoint from './Pie3DPoint.js';
  29. import SeriesRegistry from '../../Core/Series/SeriesRegistry.js';
  30. var PieSeries = SeriesRegistry.seriesTypes.pie;
  31. import U from '../../Core/Utilities.js';
  32. var extend = U.extend, pick = U.pick;
  33. /* *
  34. *
  35. * Class
  36. *
  37. * */
  38. var Pie3DSeries = /** @class */ (function (_super) {
  39. __extends(Pie3DSeries, _super);
  40. function Pie3DSeries() {
  41. return _super !== null && _super.apply(this, arguments) || this;
  42. }
  43. /* *
  44. *
  45. * Functions
  46. *
  47. * */
  48. /* eslint-disable valid-jsdoc */
  49. /**
  50. * @private
  51. */
  52. Pie3DSeries.prototype.addPoint = function () {
  53. _super.prototype.addPoint.apply(this, arguments);
  54. if (this.chart.is3d()) {
  55. // destroy (and rebuild) everything!!!
  56. this.update(this.userOptions, true); // #3845 pass the old options
  57. }
  58. };
  59. /**
  60. * @private
  61. */
  62. Pie3DSeries.prototype.animate = function (init) {
  63. if (!this.chart.is3d()) {
  64. _super.prototype.animate.apply(this, arguments);
  65. }
  66. else {
  67. var animation = this.options.animation, attribs, center = this.center, group = this.group, markerGroup = this.markerGroup;
  68. if (svg) { // VML is too slow anyway
  69. if (animation === true) {
  70. animation = {};
  71. }
  72. // Initialize the animation
  73. if (init) {
  74. // Scale down the group and place it in the center
  75. group.oldtranslateX = pick(group.oldtranslateX, group.translateX);
  76. group.oldtranslateY = pick(group.oldtranslateY, group.translateY);
  77. attribs = {
  78. translateX: center[0],
  79. translateY: center[1],
  80. scaleX: 0.001,
  81. scaleY: 0.001
  82. };
  83. group.attr(attribs);
  84. if (markerGroup) {
  85. markerGroup.attrSetters = group.attrSetters;
  86. markerGroup.attr(attribs);
  87. }
  88. // Run the animation
  89. }
  90. else {
  91. attribs = {
  92. translateX: group.oldtranslateX,
  93. translateY: group.oldtranslateY,
  94. scaleX: 1,
  95. scaleY: 1
  96. };
  97. group.animate(attribs, animation);
  98. if (markerGroup) {
  99. markerGroup.animate(attribs, animation);
  100. }
  101. }
  102. }
  103. }
  104. };
  105. /**
  106. * @private
  107. */
  108. Pie3DSeries.prototype.drawDataLabels = function () {
  109. if (this.chart.is3d()) {
  110. var series = this, chart = series.chart, options3d = chart.options.chart.options3d;
  111. series.data.forEach(function (point) {
  112. var shapeArgs = point.shapeArgs, r = shapeArgs.r,
  113. // #3240 issue with datalabels for 0 and null values
  114. a1 = (shapeArgs.alpha || options3d.alpha) * deg2rad, b1 = (shapeArgs.beta || options3d.beta) * deg2rad, a2 = (shapeArgs.start + shapeArgs.end) / 2, labelPosition = point.labelPosition, connectorPosition = labelPosition.connectorPosition, yOffset = (-r * (1 - Math.cos(a1)) * Math.sin(a2)), xOffset = r * (Math.cos(b1) - 1) * Math.cos(a2);
  115. // Apply perspective on label positions
  116. [
  117. labelPosition.natural,
  118. connectorPosition.breakAt,
  119. connectorPosition.touchingSliceAt
  120. ].forEach(function (coordinates) {
  121. coordinates.x += xOffset;
  122. coordinates.y += yOffset;
  123. });
  124. });
  125. }
  126. _super.prototype.drawDataLabels.apply(this, arguments);
  127. };
  128. /**
  129. * @private
  130. */
  131. Pie3DSeries.prototype.pointAttribs = function (point) {
  132. var attr = _super.prototype.pointAttribs.apply(this, arguments), options = this.options;
  133. if (this.chart.is3d() && !this.chart.styledMode) {
  134. attr.stroke = options.edgeColor || point.color || this.color;
  135. attr['stroke-width'] = pick(options.edgeWidth, 1);
  136. }
  137. return attr;
  138. };
  139. /**
  140. * @private
  141. */
  142. Pie3DSeries.prototype.translate = function () {
  143. _super.prototype.translate.apply(this, arguments);
  144. // Do not do this if the chart is not 3D
  145. if (!this.chart.is3d()) {
  146. return;
  147. }
  148. var series = this, seriesOptions = series.options, depth = seriesOptions.depth || 0, options3d = series.chart.options.chart.options3d, alpha = options3d.alpha, beta = options3d.beta, z = seriesOptions.stacking ?
  149. (seriesOptions.stack || 0) * depth :
  150. series._i * depth;
  151. z += depth / 2;
  152. if (seriesOptions.grouping !== false) {
  153. z = 0;
  154. }
  155. series.data.forEach(function (point) {
  156. var shapeArgs = point.shapeArgs, angle;
  157. point.shapeType = 'arc3d';
  158. shapeArgs.z = z;
  159. shapeArgs.depth = depth * 0.75;
  160. shapeArgs.alpha = alpha;
  161. shapeArgs.beta = beta;
  162. shapeArgs.center = series.center;
  163. angle = (shapeArgs.end + shapeArgs.start) / 2;
  164. point.slicedTranslation = {
  165. translateX: Math.round(Math.cos(angle) *
  166. seriesOptions.slicedOffset *
  167. Math.cos(alpha * deg2rad)),
  168. translateY: Math.round(Math.sin(angle) *
  169. seriesOptions.slicedOffset *
  170. Math.cos(alpha * deg2rad))
  171. };
  172. });
  173. };
  174. return Pie3DSeries;
  175. }(PieSeries));
  176. extend(Pie3DSeries, {
  177. pointClass: Pie3DPoint
  178. });
  179. /* *
  180. *
  181. * Default Export
  182. *
  183. * */
  184. export default Pie3DSeries;
  185. /* *
  186. *
  187. * API Options
  188. *
  189. * */
  190. /**
  191. * The thickness of a 3D pie.
  192. *
  193. * @type {number}
  194. * @default 0
  195. * @since 4.0
  196. * @product highcharts
  197. * @requires highcharts-3d
  198. * @apioption plotOptions.pie.depth
  199. */
  200. ''; // keeps doclets above after transpilation