import { Attrib, CustomizeShape, CustomizeShapeFactory } from "../../../type"; import { polygonShapeFactory, polygon } from "../style"; import { WholeLine, WholeLineAttrib } from "./whole-line"; import { getWholeLinePolygonPoints } from "../service/whole-line-base"; import { Entity, EntityProps } from "../../entity"; import { Line } from "konva/lib/shapes/Line"; import { Shape } from "konva/lib/Shape"; import { Group } from "konva/lib/Group"; export type WholeLinePolygonAttrib = Attrib & { lineIds: string[]; }; export type WholeLinePolygonProps< T extends WholeLinePolygonAttrib = WholeLinePolygonAttrib > = EntityProps; export class WholeLinePolygon< T extends WholeLinePolygonAttrib = WholeLinePolygonAttrib, R extends Shape | Group = Line > extends Entity { static namespace = "polygon"; get config() { return (this.parent as WholeLine).attrib; } actShape: CustomizeShape; actShapeFactory: CustomizeShapeFactory; constructor(props: WholeLinePolygonProps) { props.zIndex = props.zIndex || polygon.zIndex; props.name = props.name || WholeLinePolygon.namespace + props.attrib.id; super(props); this.actShapeFactory = polygonShapeFactory as unknown as CustomizeShapeFactory; } setActShapeFactory(actShapeFactory: CustomizeShapeFactory) { this.actShapeFactory = actShapeFactory; } initShape() { this.actShape = this.actShapeFactory(this.attrib, this); return this.actShape.shape; } diffRedraw(): void { this.actShape.setData(this.getCoords()); } getCoords() { const result: number[] = []; const points = getWholeLinePolygonPoints(this.config, this.attrib.id); if (!points.some((point) => !point)) { points.forEach(({ x, y }, ndx) => { result[ndx * 2] = x; result[ndx * 2 + 1] = y; }); } return result; } mounted(): void { super.mounted(); this.actShape.common(null); } }