arc.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 bbox = require('../util/bbox');
  10. var Arc = /*#__PURE__*/function (_Shape) {
  11. (0, _inheritsLoose2["default"])(Arc, _Shape);
  12. var _super = _createSuper(Arc);
  13. function Arc() {
  14. return _Shape.apply(this, arguments) || this;
  15. }
  16. var _proto = Arc.prototype;
  17. _proto._initProperties = function _initProperties() {
  18. _Shape.prototype._initProperties.call(this);
  19. this._attrs.canStroke = true;
  20. this._attrs.canFill = true;
  21. this._attrs.type = 'arc';
  22. };
  23. _proto.getDefaultAttrs = function getDefaultAttrs() {
  24. return {
  25. x: 0,
  26. y: 0,
  27. r: 0,
  28. startAngle: 0,
  29. endAngle: Math.PI * 2,
  30. anticlockwise: false,
  31. lineWidth: 1
  32. };
  33. };
  34. _proto.createPath = function createPath(context) {
  35. var attrs = this.get('attrs');
  36. var x = attrs.x,
  37. y = attrs.y,
  38. r = attrs.r,
  39. startAngle = attrs.startAngle,
  40. endAngle = attrs.endAngle,
  41. anticlockwise = attrs.anticlockwise;
  42. context.beginPath();
  43. if (startAngle !== endAngle) {
  44. context.arc(x, y, r, startAngle, endAngle, anticlockwise);
  45. }
  46. };
  47. _proto.calculateBox = function calculateBox() {
  48. var attrs = this.get('attrs');
  49. var x = attrs.x,
  50. y = attrs.y,
  51. r = attrs.r,
  52. startAngle = attrs.startAngle,
  53. endAngle = attrs.endAngle,
  54. anticlockwise = attrs.anticlockwise;
  55. return bbox.getBBoxFromArc(x, y, r, startAngle, endAngle, anticlockwise);
  56. };
  57. return Arc;
  58. }(Shape);
  59. Shape.Arc = Arc;
  60. module.exports = Arc;