Skip to content
Snippets Groups Projects
graphelement.ts 1.6 KiB
Newer Older
Maximilian Giller's avatar
Maximilian Giller committed
import { Graph } from "./graph";
import { SerializableItem } from "../helper/serializableitem";

export class GraphElement extends SerializableItem {
    protected isNode: boolean;
    protected isLink: boolean;

    public graph: Graph;
    constructor(graph: Graph = undefined) {
        super();
        this.graph = graph;
        this.isNode = false;
        this.isLink = false;
    }

    public get node(): boolean {
        return this.isNode;
    }

    public get link(): boolean {
        return this.isLink;
    }

    /**
     * Removes element from its parent graph.
     * @returns True, if successful.
     */
    public delete(): boolean {
Maximilian Giller's avatar
Maximilian Giller committed
        throw new Error('Function "delete()" has not been implemented.');
    }

    /**
     * Adds the element to the given graph.
     * @param graph Graph to add element to.
     * @returns True, if successful.
     */
    public add(graph: Graph = this.graph): boolean {
Maximilian Giller's avatar
Maximilian Giller committed
        throw new Error('Function "add(graph)" has not been implemented.');
    }

    /**
     * Needs to be implemented to create a filtered version for storing in the data history.
     * @returns Filtered object.
     */
    public getCleanInstance(): any {
Maximilian Giller's avatar
Maximilian Giller committed
        throw new Error(
            'Function "getCleanInstance()" has not been implemented.'
        );

    /**
     * Compares to objects. Can be a custom implementation.
     * @returns True, if given object is identical.
     */
    public equals(other: GraphElement): boolean {
        return (
            other.node == this.node &&
            other.link == this.link &&
            other.id == this.id
        );
    }
Maximilian Giller's avatar
Maximilian Giller committed
}