React-diagrams: Clear canvas ?

Created on 16 Jul 2019  路  2Comments  路  Source: projectstorm/react-diagrams

Hi,

I was wondering as to how I could clear the entire canvas through code? Is there a function for that?

Thanks.

question

All 2 comments

Don't know if there's one function to clear the entire canvas, maybe someone can chime in. For now, check out the source code for DiagramModel.ts. You can find all of the links/nodes and remove all of them iteratively. You would also have to remove any listeners on the DiagramModel by setting it to null if desired.

    removeLink(link: LinkModel | string) {
        link = this.getLink(link);
        delete this.links[link.getID()];
        this.iterateListeners((listener, event) => {
            if (listener.linksUpdated) {
                listener.linksUpdated({ ...event, link: link as LinkModel, isCreated: false });
            }
        });
    }

    removeNode(node: NodeModel | string) {
        node = this.getNode(node);
        delete this.nodes[node.getID()];
        this.iterateListeners((listener, event) => {
            if (listener.nodesUpdated) {
                listener.nodesUpdated({ ...event, node: node as NodeModel, isCreated: false });
            }
        });
    }

    getLinks(): { [s: string]: LinkModel } {
        return this.links;
    }

    getNodes(): { [s: string]: NodeModel } {
        return this.nodes;
    }
Was this page helpful?
0 / 5 - 0 ratings

Related issues

Naveenraj006 picture Naveenraj006  路  3Comments

kmannislands picture kmannislands  路  3Comments

t-gacema picture t-gacema  路  4Comments

abhijitnandy2011 picture abhijitnandy2011  路  3Comments

M2Costa picture M2Costa  路  3Comments