dagre icon indicating copy to clipboard operation
dagre copied to clipboard

When each node has its own child nodes, their child nodes will not affect each other. Now they will be displayed equally

Open LeonsCd opened this issue 2 years ago • 2 comments

if (isNode(element)) {
      const { data,id } = element
      if(id!=="0"){
        const {parentId} = data
        if(parentId===0||parentId){
          g.setParent(id, parentId+"");
        }
      }
      g.setNode(element.id, {
        width: element.__rf?.width,
        height: element.__rf?.height,
      });
    } else {
      g.setEdge(element.source, element.target);
    }

I used setEdge before but i got the graph drawn by the nodes of the second level is evenly spaced, so I think they are caused by no parent-child relationship So you see that code i added the setParent I hope they can divide the space equally in their own area but i failed Uncaught TypeError: Cannot set properties of undefined (setting 'rank') i don't know what to use

LeonsCd avatar Apr 19 '22 07:04 LeonsCd

  const g = new dagre.graphlib.Graph({compound: true });
  g.setGraph({ rankdir: isHorizontal ? "LR" : "TB", nodesep: 12, ranksep: 80 });

  g.setDefaultEdgeLabel(() => ({}));

LeonsCd avatar Apr 19 '22 07:04 LeonsCd

Its child nodes will affect each other and divide the spacing between them equally

LeonsCd avatar Apr 19 '22 07:04 LeonsCd