circle.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  2. var Shape = require('../shape');
  3. var Circle =
  4. /*#__PURE__*/
  5. function (_Shape) {
  6. _inheritsLoose(Circle, _Shape);
  7. function Circle() {
  8. return _Shape.apply(this, arguments) || this;
  9. }
  10. var _proto = Circle.prototype;
  11. _proto._initProperties = function _initProperties() {
  12. _Shape.prototype._initProperties.call(this);
  13. this._attrs.canFill = true;
  14. this._attrs.canStroke = true;
  15. this._attrs.type = 'circle';
  16. };
  17. _proto.getDefaultAttrs = function getDefaultAttrs() {
  18. return {
  19. x: 0,
  20. y: 0,
  21. r: 0,
  22. lineWidth: 0
  23. };
  24. };
  25. _proto.createPath = function createPath(context) {
  26. var attrs = this.get('attrs');
  27. var x = attrs.x,
  28. y = attrs.y,
  29. r = attrs.r;
  30. context.beginPath();
  31. context.arc(x, y, r, 0, Math.PI * 2, false);
  32. context.closePath();
  33. };
  34. _proto.calculateBox = function calculateBox() {
  35. var attrs = this.get('attrs');
  36. var x = attrs.x,
  37. y = attrs.y,
  38. r = attrs.r;
  39. return {
  40. minX: x - r,
  41. maxX: x + r,
  42. minY: y - r,
  43. maxY: y + r
  44. };
  45. };
  46. return Circle;
  47. }(Shape);
  48. Shape.Circle = Circle;
  49. module.exports = Circle;