Arc.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { __extends } from "tslib";
  2. import Path from '../Path.js';
  3. var ArcShape = (function () {
  4. function ArcShape() {
  5. this.cx = 0;
  6. this.cy = 0;
  7. this.r = 0;
  8. this.startAngle = 0;
  9. this.endAngle = Math.PI * 2;
  10. this.clockwise = true;
  11. }
  12. return ArcShape;
  13. }());
  14. export { ArcShape };
  15. var Arc = (function (_super) {
  16. __extends(Arc, _super);
  17. function Arc(opts) {
  18. return _super.call(this, opts) || this;
  19. }
  20. Arc.prototype.getDefaultStyle = function () {
  21. return {
  22. stroke: '#000',
  23. fill: null
  24. };
  25. };
  26. Arc.prototype.getDefaultShape = function () {
  27. return new ArcShape();
  28. };
  29. Arc.prototype.buildPath = function (ctx, shape) {
  30. var x = shape.cx;
  31. var y = shape.cy;
  32. var r = Math.max(shape.r, 0);
  33. var startAngle = shape.startAngle;
  34. var endAngle = shape.endAngle;
  35. var clockwise = shape.clockwise;
  36. var unitX = Math.cos(startAngle);
  37. var unitY = Math.sin(startAngle);
  38. ctx.moveTo(unitX * r + x, unitY * r + y);
  39. ctx.arc(x, y, r, startAngle, endAngle, !clockwise);
  40. };
  41. return Arc;
  42. }(Path));
  43. Arc.prototype.type = 'arc';
  44. export default Arc;