You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

polyline.ts 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import CodeShape from './index'
  2. import { uniqueId } from 'utils/utils'
  3. import { PolylineShape, ShapeType } from 'types'
  4. import { defaultStyle } from 'state/shape-styles'
  5. import Utils from './utils'
  6. export default class Polyline extends CodeShape<PolylineShape> {
  7. constructor(props = {} as Partial<PolylineShape>) {
  8. props.point = Utils.vectorToPoint(props.point)
  9. props.points = props.points.map(Utils.vectorToPoint)
  10. super({
  11. id: uniqueId(),
  12. seed: Math.random(),
  13. parentId: (window as any).currentPageId,
  14. type: ShapeType.Polyline,
  15. isGenerated: true,
  16. name: 'Polyline',
  17. childIndex: 0,
  18. point: [0, 0],
  19. points: [[0, 0]],
  20. rotation: 0,
  21. isAspectRatioLocked: false,
  22. isLocked: false,
  23. isHidden: false,
  24. style: defaultStyle,
  25. ...props,
  26. })
  27. }
  28. export(): PolylineShape {
  29. const shape = { ...this.shape }
  30. shape.point = Utils.vectorToPoint(shape.point)
  31. shape.points = shape.points.map(Utils.vectorToPoint)
  32. return shape
  33. }
  34. get points(): number[][] {
  35. return this.shape.points
  36. }
  37. }