2e14b6fb1db16c9cc686c2a9f1c2dbe3c1d4a7a5a7f5ece5b79d35e92350bd50697c4b26444217e60be3fab517de772c0b419071cccba86bccee2010a408dc 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import Path, { PathProps } from '../Path';
  2. import * as roundSectorHelper from '../helper/roundSector';
  3. export class SectorShape {
  4. cx = 0
  5. cy = 0
  6. r0 = 0
  7. r = 0
  8. startAngle = 0
  9. endAngle = Math.PI * 2
  10. clockwise = true
  11. /**
  12. * Corner radius of sector
  13. *
  14. * clockwise, from inside to outside, four corners are
  15. * inner start -> inner end
  16. * outer start -> outer end
  17. *
  18. * 5 => [5, 5, 5, 5]
  19. * [5] => [5, 5, 0, 0]
  20. * [5, 10] => [5, 5, 10, 10]
  21. * [5, 10, 15] => [5, 10, 15, 15]
  22. * [5, 10, 15, 20] => [5, 10, 15, 20]
  23. */
  24. cornerRadius: number | number[] = 0
  25. }
  26. export interface SectorProps extends PathProps {
  27. shape?: Partial<SectorShape>
  28. }
  29. class Sector extends Path<SectorProps> {
  30. shape: SectorShape
  31. constructor(opts?: SectorProps) {
  32. super(opts);
  33. }
  34. getDefaultShape() {
  35. return new SectorShape();
  36. }
  37. buildPath(ctx: CanvasRenderingContext2D, shape: SectorShape) {
  38. roundSectorHelper.buildPath(ctx, shape);
  39. }
  40. isZeroArea() {
  41. return this.shape.startAngle === this.shape.endAngle
  42. || this.shape.r === this.shape.r0;
  43. }
  44. }
  45. Sector.prototype.type = 'sector';
  46. export default Sector;