arc.js 1.7 KB

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