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 941B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import CodeShape from "./index"
  2. import { v4 as uuid } from "uuid"
  3. import { PolylineShape, ShapeType } from "types"
  4. import { vectorToPoint } from "utils/utils"
  5. export default class Polyline extends CodeShape<PolylineShape> {
  6. constructor(props = {} as Partial<PolylineShape>) {
  7. props.point = vectorToPoint(props.point)
  8. props.points = props.points.map(vectorToPoint)
  9. super({
  10. id: uuid(),
  11. type: ShapeType.Polyline,
  12. isGenerated: false,
  13. name: "Polyline",
  14. parentId: "page0",
  15. childIndex: 0,
  16. point: [0, 0],
  17. points: [[0, 0]],
  18. rotation: 0,
  19. style: {
  20. fill: "none",
  21. stroke: "#000",
  22. strokeWidth: 1,
  23. },
  24. ...props,
  25. })
  26. }
  27. export() {
  28. const shape = { ...this.shape }
  29. shape.point = vectorToPoint(shape.point)
  30. shape.points = shape.points.map(vectorToPoint)
  31. return shape
  32. }
  33. get points() {
  34. return this.shape.points
  35. }
  36. }