3

I am creating a graph with nested nodes by using 'D3' and 'dagre' library.

I want to connect node 'Level 1' to 'Middle Level' and then 'Middle Level' to 'Level 3'.

But when I use 'g.setEdge' I got the following error:

Cannot set property 'rank' of undefined

<script type="text/javascript" src="https://d3js.org/d3.v4.min.js"></script>
<script id="js">
        var g = new dagreD3.graphlib.Graph({ compound: true }).setGraph({}).setDefaultEdgeLabel(function () { return {}; });
        g.setNode('a', { label: 'Level 1' });

        g.setNode('b', { label: 'B' });
        g.setNode('g', { label: 'Level 3' });
        g.setNode('group', { label: 'Middle Level', clusterLabelPos: 'top', style: 'fill: #d3d7e8' });
        g.setNode('top_group', { clusterLabelPos: 'bottom', style: 'fill: #ffd47f' });

        g.setParent('top_group', 'group');
        g.setParent('b', 'top_group');

        g.setEdge('group', 'b');
        g.setEdge('b', 'g');

        var render = new dagreD3.render();
        var svg = d3.select("svg"),
            svgGroup = svg.append("g");
        render(d3.select("svg g"), g);
        var xCenterOffset = (svg.attr("width") - g.graph().width) / 2;
        svgGroup.attr("transform", "translate(" + xCenterOffset + ", 20)");
        svg.attr("height", g.graph().height + 40);
</script>
Ali J.
  • 47
  • 4
  • Does your console tell you what line of code the error is coming from? Try adding a `console.log` there to figure out what value is unexpectedly undefined. – anbnyc Apr 26 '19 at 14:41
  • @anbnyc thank you for your comment. Its says the error is on line 1654 – Ali J. Apr 26 '19 at 15:03

0 Answers0