SunburstPoint.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* *
  2. *
  3. * This module implements sunburst charts in Highcharts.
  4. *
  5. * (c) 2016-2021 Highsoft AS
  6. *
  7. * Authors: Jon Arild Nygard
  8. *
  9. * License: www.highcharts.com/license
  10. *
  11. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  12. *
  13. * */
  14. 'use strict';
  15. var __extends = (this && this.__extends) || (function () {
  16. var extendStatics = function (d, b) {
  17. extendStatics = Object.setPrototypeOf ||
  18. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  19. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  20. return extendStatics(d, b);
  21. };
  22. return function (d, b) {
  23. extendStatics(d, b);
  24. function __() { this.constructor = d; }
  25. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  26. };
  27. })();
  28. import SeriesRegistry from '../../Core/Series/SeriesRegistry.js';
  29. var Point = SeriesRegistry.series.prototype.pointClass, TreemapPoint = SeriesRegistry.seriesTypes.treemap.prototype.pointClass;
  30. import U from '../../Core/Utilities.js';
  31. var correctFloat = U.correctFloat, extend = U.extend;
  32. /* *
  33. *
  34. * Class
  35. *
  36. * */
  37. var SunburstPoint = /** @class */ (function (_super) {
  38. __extends(SunburstPoint, _super);
  39. function SunburstPoint() {
  40. /* *
  41. *
  42. * Properties
  43. *
  44. * */
  45. var _this = _super !== null && _super.apply(this, arguments) || this;
  46. _this.node = void 0;
  47. _this.options = void 0;
  48. _this.series = void 0;
  49. _this.shapeExisting = void 0;
  50. return _this;
  51. /* eslint-enable valid-jsdoc */
  52. }
  53. /* *
  54. *
  55. * Functions
  56. *
  57. * */
  58. /* eslint-disable valid-jsdoc */
  59. SunburstPoint.prototype.getDataLabelPath = function (label) {
  60. var renderer = this.series.chart.renderer, shapeArgs = this.shapeExisting, start = shapeArgs.start, end = shapeArgs.end, angle = start + (end - start) / 2, // arc middle value
  61. upperHalf = angle < 0 &&
  62. angle > -Math.PI ||
  63. angle > Math.PI, r = (shapeArgs.r + (label.options.distance || 0)), moreThanHalf;
  64. // Check if point is a full circle
  65. if (start === -Math.PI / 2 &&
  66. correctFloat(end) === correctFloat(Math.PI * 1.5)) {
  67. start = -Math.PI + Math.PI / 360;
  68. end = -Math.PI / 360;
  69. upperHalf = true;
  70. }
  71. // Check if dataLabels should be render in the
  72. // upper half of the circle
  73. if (end - start > Math.PI) {
  74. upperHalf = false;
  75. moreThanHalf = true;
  76. }
  77. if (this.dataLabelPath) {
  78. this.dataLabelPath = this.dataLabelPath.destroy();
  79. }
  80. this.dataLabelPath = renderer
  81. .arc({
  82. open: true,
  83. longArc: moreThanHalf ? 1 : 0
  84. })
  85. // Add it inside the data label group so it gets destroyed
  86. // with the label
  87. .add(label);
  88. this.dataLabelPath.attr({
  89. start: (upperHalf ? start : end),
  90. end: (upperHalf ? end : start),
  91. clockwise: +upperHalf,
  92. x: shapeArgs.x,
  93. y: shapeArgs.y,
  94. r: (r + shapeArgs.innerR) / 2
  95. });
  96. return this.dataLabelPath;
  97. };
  98. SunburstPoint.prototype.isValid = function () {
  99. return true;
  100. };
  101. SunburstPoint.prototype.shouldDraw = function () {
  102. return !this.isNull;
  103. };
  104. return SunburstPoint;
  105. }(TreemapPoint));
  106. extend(SunburstPoint.prototype, {
  107. getClassName: Point.prototype.getClassName,
  108. haloPath: Point.prototype.haloPath,
  109. setState: Point.prototype.setState
  110. });
  111. /* *
  112. *
  113. * Defaul Export
  114. *
  115. * */
  116. export default SunburstPoint;