circle.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
  4. var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
  5. var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
  6. function _createSuper(Derived) { return function () { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
  7. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  8. var Util = require('../../util/common');
  9. var Abstract = require('./abstract');
  10. var Circle = /*#__PURE__*/function (_Abstract) {
  11. (0, _inheritsLoose2["default"])(Circle, _Abstract);
  12. var _super = _createSuper(Circle);
  13. function Circle() {
  14. return _Abstract.apply(this, arguments) || this;
  15. }
  16. var _proto = Circle.prototype;
  17. _proto._initDefaultCfg = function _initDefaultCfg() {
  18. _Abstract.prototype._initDefaultCfg.call(this);
  19. this.startAngle = -Math.PI / 2; // start angle,in radian
  20. this.endAngle = Math.PI * 3 / 2; // end angle, in radian
  21. this.radius = null; // radius
  22. this.center = null; // center
  23. };
  24. _proto.getOffsetPoint = function getOffsetPoint(value) {
  25. var startAngle = this.startAngle,
  26. endAngle = this.endAngle;
  27. var angle = startAngle + (endAngle - startAngle) * value;
  28. return this._getCirclePoint(angle);
  29. };
  30. _proto._getCirclePoint = function _getCirclePoint(angle, radius) {
  31. var self = this;
  32. var center = self.center;
  33. radius = radius || self.radius;
  34. return {
  35. x: center.x + Math.cos(angle) * radius,
  36. y: center.y + Math.sin(angle) * radius
  37. };
  38. };
  39. _proto.getTextAlignInfo = function getTextAlignInfo(point, offset) {
  40. var self = this;
  41. var offsetVector = self.getOffsetVector(point, offset);
  42. var align;
  43. var baseLine = 'middle';
  44. if (offsetVector[0] > 0) {
  45. align = 'left';
  46. } else if (offsetVector[0] < 0) {
  47. align = 'right';
  48. } else {
  49. align = 'center';
  50. if (offsetVector[1] > 0) {
  51. baseLine = 'top';
  52. } else if (offsetVector[1] < 0) {
  53. baseLine = 'bottom';
  54. }
  55. }
  56. return {
  57. textAlign: align,
  58. textBaseline: baseLine
  59. };
  60. };
  61. _proto.getAxisVector = function getAxisVector(point) {
  62. var center = this.center;
  63. var factor = this.offsetFactor;
  64. return [(point.y - center.y) * factor, (point.x - center.x) * -1 * factor];
  65. };
  66. _proto.drawLine = function drawLine(lineCfg) {
  67. var center = this.center,
  68. radius = this.radius,
  69. startAngle = this.startAngle,
  70. endAngle = this.endAngle;
  71. var container = this.getContainer(lineCfg.top);
  72. container.addShape('arc', {
  73. className: 'axis-line',
  74. attrs: Util.mix({
  75. x: center.x,
  76. y: center.y,
  77. r: radius,
  78. startAngle: startAngle,
  79. endAngle: endAngle
  80. }, lineCfg)
  81. });
  82. };
  83. return Circle;
  84. }(Abstract);
  85. Abstract.Circle = Circle;
  86. module.exports = Circle;