arc.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. "use strict";
  2. exports.__esModule = true;
  3. exports["default"] = void 0;
  4. var _common = require("../../util/common");
  5. var _base = _interopRequireDefault(require("./base"));
  6. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  7. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  8. var Arc = /*#__PURE__*/function (_GuideBase) {
  9. _inheritsLoose(Arc, _GuideBase);
  10. function Arc() {
  11. return _GuideBase.apply(this, arguments) || this;
  12. }
  13. var _proto = Arc.prototype;
  14. _proto._initDefaultCfg = function _initDefaultCfg() {
  15. this.type = 'arc';
  16. /**
  17. * start point
  18. * @type {Array | Function}
  19. */
  20. this.start = [];
  21. /**
  22. * end point
  23. * @type {Array | Function}
  24. */
  25. this.end = [];
  26. /**
  27. * style configuration
  28. * @type {Object}
  29. */
  30. this.style = {
  31. stroke: '#999',
  32. lineWidth: 1
  33. };
  34. };
  35. _proto.render = function render(coord, container) {
  36. var self = this;
  37. var start = self.parsePoint(coord, self.start);
  38. var end = self.parsePoint(coord, self.end);
  39. if (!start || !end) {
  40. return;
  41. }
  42. var coordCenter = coord.center;
  43. var radius = Math.sqrt((start.x - coordCenter.x) * (start.x - coordCenter.x) + (start.y - coordCenter.y) * (start.y - coordCenter.y));
  44. var startAngle = Math.atan2(start.y - coordCenter.y, start.x - coordCenter.x);
  45. var endAngle = Math.atan2(end.y - coordCenter.y, end.x - coordCenter.x);
  46. var shape = container.addShape('arc', {
  47. className: 'guide-arc',
  48. attrs: (0, _common.mix)({
  49. x: coordCenter.x,
  50. y: coordCenter.y,
  51. r: radius,
  52. startAngle: startAngle,
  53. endAngle: endAngle
  54. }, self.style)
  55. });
  56. self.element = shape;
  57. return shape;
  58. };
  59. return Arc;
  60. }(_base["default"]);
  61. _base["default"].Arc = Arc;
  62. var _default = Arc;
  63. exports["default"] = _default;