Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

polyline.ts 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import CodeShape from './index'
  2. import { uniqueId } from 'utils'
  3. import { PolylineShape, ShapeProps, ShapeType } from 'types'
  4. import { defaultStyle } from 'state/shape-styles'
  5. /* ----------------- Start Copy Here ---------------- */
  6. export default class Polyline extends CodeShape<PolylineShape> {
  7. constructor(props = {} as ShapeProps<PolylineShape>) {
  8. super({
  9. id: uniqueId(),
  10. parentId: (window as any).currentPageId,
  11. type: ShapeType.Polyline,
  12. isGenerated: true,
  13. name: 'Polyline',
  14. childIndex: 0,
  15. point: [0, 0],
  16. points: [[0, 0]],
  17. rotation: 0,
  18. isAspectRatioLocked: false,
  19. isLocked: false,
  20. isHidden: false,
  21. ...props,
  22. style: {
  23. ...defaultStyle,
  24. ...props.style,
  25. },
  26. })
  27. }
  28. /**
  29. * Add a point to the polyline's points.
  30. *
  31. * ```ts
  32. * shape.addPoint([100,100])
  33. * ```
  34. */
  35. addPoint(point: number[]): CodeShape<PolylineShape> {
  36. this.utils.setProperty(this.shape, 'points', [...this.points, point])
  37. return this
  38. }
  39. /**
  40. * The polyline's points.
  41. *
  42. * ```ts
  43. * const shapePoints = shape.points
  44. *
  45. * shape.points = [[0,0], [100,100], [100,200]]
  46. * ```
  47. */
  48. get points(): number[][] {
  49. return this.shape.points
  50. }
  51. set points(points: number[][]) {
  52. this.utils.setProperty(this.shape, 'points', points)
  53. }
  54. }