davidthings / hdelk

Web-based HDL diagramming tool
https://davidthings.github.io/hdelk/
Apache License 2.0
72 stars 9 forks source link

How do you refresh the graph? #4

Open creativecontrol opened 3 years ago

creativecontrol commented 3 years ago

Hello,

Thanks for making such a simple renderer for ELK. It is very easy to understand and make adjustments to for my needs. I was wondering about a feature that you have in your Editor on the site; Redraw. From what I can tell it is calling a function which just runs hdelk.layout() again with the new information. I've been attempting the same thing but it adds additional labels and ports to the existing SVG objects rather than clearing and redrawing. I've tried several ways of removing and clearing the SVG object from the page but the diagram is still cached in some way. I've attached a couple screenshots to show the issue.

Thanks for your help

One first load: image

After running hdelk.layout() 2 more times with the same data: image

The code I'm using to chose the graph to display"

function displayDiagram(mode="show") {

        let fullGraph = {}; 

        if(mode == "show") {
            fullGraph = {
                children: [
                    ...graph.children,
                    ...networkConns.children
                ],
                edges: [
                    ...graph.edges,
                    ...networkConns.edges
                ]
            }

        } else if (mode == "hide") {
            fullGraph = graph;

        }

        console.log("fullGraph",fullGraph);

        hdelk.layout(fullGraph, "graph");
    }