circle.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 Shape = require('../shape');
  9. var Circle = /*#__PURE__*/function (_Shape) {
  10. (0, _inheritsLoose2["default"])(Circle, _Shape);
  11. var _super = _createSuper(Circle);
  12. function Circle() {
  13. return _Shape.apply(this, arguments) || this;
  14. }
  15. var _proto = Circle.prototype;
  16. _proto._initProperties = function _initProperties() {
  17. _Shape.prototype._initProperties.call(this);
  18. this._attrs.canFill = true;
  19. this._attrs.canStroke = true;
  20. this._attrs.type = 'circle';
  21. };
  22. _proto.getDefaultAttrs = function getDefaultAttrs() {
  23. return {
  24. x: 0,
  25. y: 0,
  26. r: 0,
  27. lineWidth: 0
  28. };
  29. };
  30. _proto.createPath = function createPath(context) {
  31. var attrs = this.get('attrs');
  32. var x = attrs.x,
  33. y = attrs.y,
  34. r = attrs.r;
  35. context.beginPath();
  36. context.arc(x, y, r, 0, Math.PI * 2, false);
  37. context.closePath();
  38. };
  39. _proto.calculateBox = function calculateBox() {
  40. var attrs = this.get('attrs');
  41. var x = attrs.x,
  42. y = attrs.y,
  43. r = attrs.r;
  44. return {
  45. minX: x - r,
  46. maxX: x + r,
  47. minY: y - r,
  48. maxY: y + r
  49. };
  50. };
  51. return Circle;
  52. }(Shape);
  53. Shape.Circle = Circle;
  54. module.exports = Circle;