Pie3DSeries.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /* *
  2. *
  3. * (c) 2010-2020 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. import BaseSeries from '../Core/Series/Series.js';
  13. import H from '../Core/Globals.js';
  14. var deg2rad = H.deg2rad, svg = H.svg;
  15. import U from '../Core/Utilities.js';
  16. var pick = U.pick, wrap = U.wrap;
  17. var seriesTypes = BaseSeries.seriesTypes;
  18. /**
  19. * The thickness of a 3D pie.
  20. *
  21. * @type {number}
  22. * @default 0
  23. * @since 4.0
  24. * @product highcharts
  25. * @requires highcharts-3d
  26. * @apioption plotOptions.pie.depth
  27. */
  28. /* eslint-disable no-invalid-this */
  29. wrap(seriesTypes.pie.prototype, 'translate', function (proceed) {
  30. proceed.apply(this, [].slice.call(arguments, 1));
  31. // Do not do this if the chart is not 3D
  32. if (!this.chart.is3d()) {
  33. return;
  34. }
  35. 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 ?
  36. (seriesOptions.stack || 0) * depth :
  37. series._i * depth;
  38. z += depth / 2;
  39. if (seriesOptions.grouping !== false) {
  40. z = 0;
  41. }
  42. series.data.forEach(function (point) {
  43. var shapeArgs = point.shapeArgs, angle;
  44. point.shapeType = 'arc3d';
  45. shapeArgs.z = z;
  46. shapeArgs.depth = depth * 0.75;
  47. shapeArgs.alpha = alpha;
  48. shapeArgs.beta = beta;
  49. shapeArgs.center = series.center;
  50. angle = (shapeArgs.end + shapeArgs.start) / 2;
  51. point.slicedTranslation = {
  52. translateX: Math.round(Math.cos(angle) *
  53. seriesOptions.slicedOffset *
  54. Math.cos(alpha * deg2rad)),
  55. translateY: Math.round(Math.sin(angle) *
  56. seriesOptions.slicedOffset *
  57. Math.cos(alpha * deg2rad))
  58. };
  59. });
  60. });
  61. wrap(seriesTypes.pie.prototype.pointClass.prototype, 'haloPath', function (proceed) {
  62. var args = arguments;
  63. return this.series.chart.is3d() ? [] : proceed.call(this, args[1]);
  64. });
  65. wrap(seriesTypes.pie.prototype, 'pointAttribs', function (proceed, point, state) {
  66. var attr = proceed.call(this, point, state), options = this.options;
  67. if (this.chart.is3d() && !this.chart.styledMode) {
  68. attr.stroke = options.edgeColor || point.color || this.color;
  69. attr['stroke-width'] = pick(options.edgeWidth, 1);
  70. }
  71. return attr;
  72. });
  73. wrap(seriesTypes.pie.prototype, 'drawDataLabels', function (proceed) {
  74. if (this.chart.is3d()) {
  75. var series = this, chart = series.chart, options3d = chart.options.chart.options3d;
  76. series.data.forEach(function (point) {
  77. var shapeArgs = point.shapeArgs, r = shapeArgs.r,
  78. // #3240 issue with datalabels for 0 and null values
  79. 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);
  80. // Apply perspective on label positions
  81. [
  82. labelPosition.natural,
  83. connectorPosition.breakAt,
  84. connectorPosition.touchingSliceAt
  85. ].forEach(function (coordinates) {
  86. coordinates.x += xOffset;
  87. coordinates.y += yOffset;
  88. });
  89. });
  90. }
  91. proceed.apply(this, [].slice.call(arguments, 1));
  92. });
  93. wrap(seriesTypes.pie.prototype, 'addPoint', function (proceed) {
  94. proceed.apply(this, [].slice.call(arguments, 1));
  95. if (this.chart.is3d()) {
  96. // destroy (and rebuild) everything!!!
  97. this.update(this.userOptions, true); // #3845 pass the old options
  98. }
  99. });
  100. wrap(seriesTypes.pie.prototype, 'animate', function (proceed) {
  101. if (!this.chart.is3d()) {
  102. proceed.apply(this, [].slice.call(arguments, 1));
  103. }
  104. else {
  105. var args = arguments, init = args[1], animation = this.options.animation, attribs, center = this.center, group = this.group, markerGroup = this.markerGroup;
  106. if (svg) { // VML is too slow anyway
  107. if (animation === true) {
  108. animation = {};
  109. }
  110. // Initialize the animation
  111. if (init) {
  112. // Scale down the group and place it in the center
  113. group.oldtranslateX = pick(group.oldtranslateX, group.translateX);
  114. group.oldtranslateY = pick(group.oldtranslateY, group.translateY);
  115. attribs = {
  116. translateX: center[0],
  117. translateY: center[1],
  118. scaleX: 0.001,
  119. scaleY: 0.001
  120. };
  121. group.attr(attribs);
  122. if (markerGroup) {
  123. markerGroup.attrSetters = group.attrSetters;
  124. markerGroup.attr(attribs);
  125. }
  126. // Run the animation
  127. }
  128. else {
  129. attribs = {
  130. translateX: group.oldtranslateX,
  131. translateY: group.oldtranslateY,
  132. scaleX: 1,
  133. scaleY: 1
  134. };
  135. group.animate(attribs, animation);
  136. if (markerGroup) {
  137. markerGroup.animate(attribs, animation);
  138. }
  139. }
  140. }
  141. }
  142. });