import { GraphElement } from "./graphelement"; import { Node } from "./node"; import { Graph } from "./graph"; export interface NodeTypeData { id: number; name: string; color?: string; } export class NodeType extends GraphElement<NodeTypeData, NodeTypeData> implements NodeTypeData { public id: number; public name: string; public color: string; constructor(name?: string, color?: string, graph?: Graph) { super(0, graph); this.name = name; this.color = color; } toJSONSerializableObject(): NodeTypeData { return { id: this.id, name: this.name, color: this.color }; } toHistorySerializableObject(): NodeTypeData { return this.toJSONSerializableObject(); } public fromSerializedObject(data: NodeTypeData): NodeType { Object.assign(this, data); return this; } public delete() { return this.graph.deleteNodeType(this.name); // TODO: Change to id } public toString(): string { return this.name; } public equals(other: GraphElement<NodeTypeData, NodeTypeData>): boolean { if (other.constructor != this.constructor) { return false; } const type = other as NodeType; return type.id === this.id; } }