PNet/js/PElems/Node.ts
2023-06-22 17:47:04 +02:00

37 lines
No EOL
955 B
TypeScript

import { svgNodes } from "..";
import { SVGNode } from "../graphics/SVGNode";
import { Positionable } from "../types";
import { Edge } from "./Edge";
export class Node implements Positionable {
renderedElement: SVGNode;
x: number = 0;
y: number = 0;
name: string;
capacity = 1;
marks = 0;
updateList: Edge[] = [];
constructor(name, x, y) {
this.name = name;
this.x = x;
this.y = y;
this.renderedElement = new SVGNode(this);
this.renderedElement.appendIt(svgNodes);
this.renderedElement.onMove((event) => this.updatePosition(event.x, event.y));
}
updatePoints() {
this.renderedElement.setMarks(this.marks, this.capacity);
}
updatePosition(x: number, y: number) {
this.x = x;
this.y = y;
this.renderedElement.translate(x, y);
for (const elem of this.updateList) {
elem.updatePosition();
}
}
}