arc.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 GuideBase = require('./base');
  10. var Arc = /*#__PURE__*/function (_GuideBase) {
  11. (0, _inheritsLoose2["default"])(Arc, _GuideBase);
  12. var _super = _createSuper(Arc);
  13. function Arc() {
  14. return _GuideBase.apply(this, arguments) || this;
  15. }
  16. var _proto = Arc.prototype;
  17. _proto._initDefaultCfg = function _initDefaultCfg() {
  18. this.type = 'arc';
  19. /**
  20. * start point
  21. * @type {Array | Function}
  22. */
  23. this.start = [];
  24. /**
  25. * end point
  26. * @type {Array | Function}
  27. */
  28. this.end = [];
  29. /**
  30. * style configuration
  31. * @type {Object}
  32. */
  33. this.style = {
  34. stroke: '#999',
  35. lineWidth: 1
  36. };
  37. };
  38. _proto.render = function render(coord, container) {
  39. var self = this;
  40. var start = self.parsePoint(coord, self.start);
  41. var end = self.parsePoint(coord, self.end);
  42. if (!start || !end) {
  43. return;
  44. }
  45. var coordCenter = coord.center;
  46. var radius = Math.sqrt((start.x - coordCenter.x) * (start.x - coordCenter.x) + (start.y - coordCenter.y) * (start.y - coordCenter.y));
  47. var startAngle = Math.atan2(start.y - coordCenter.y, start.x - coordCenter.x);
  48. var endAngle = Math.atan2(end.y - coordCenter.y, end.x - coordCenter.x);
  49. var shape = container.addShape('arc', {
  50. className: 'guide-arc',
  51. attrs: Util.mix({
  52. x: coordCenter.x,
  53. y: coordCenter.y,
  54. r: radius,
  55. startAngle: startAngle,
  56. endAngle: endAngle
  57. }, self.style)
  58. });
  59. self.element = shape;
  60. return shape;
  61. };
  62. return Arc;
  63. }(GuideBase);
  64. GuideBase.Arc = Arc;
  65. module.exports = Arc;