Alignment of "starting" end "ending" nodes

582 views
Skip to first unread message

Daniel Hoyos

unread,
Apr 3, 2014, 9:41:14 AM4/3/14
to da...@googlegroups.com
Hi,

I'm currently working on a visualization of Data Flows using dagre-d3.
I thought about aligning starting node (nodes whihc do not have incoming edges) always to the top, while Ending Nodes (no outgoing Edges) should be aligned to the bottom.
Do you see any possibility or hint to achieve such behaviour?

Thanks a lot,
Daniel

Chris Pettitt

unread,
Apr 3, 2014, 10:26:02 PM4/3/14
to Daniel Hoyos, da...@googlegroups.com
You can explicitly tell dagre to align specific nodes to the top or bottom of the graph. For example:

digraph {
a1 [rank=min]
a2 [rank=min]
a3 [rank=min]

d1 [rank=max]
d2 [rank=max]
d3 [rank=max]

a1 -> d1
a2 -> b2 -> c2 -> d2
a3 -> d3
}

Example Output:


--
You received this message because you are subscribed to the Google Groups "dagre" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dagre+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

hendrik luuk

unread,
Jul 21, 2014, 11:20:02 AM7/21/14
to da...@googlegroups.com, lo...@cb-net.org
Is it possible to specify nodes' ranks using JSON notation? I'm aware of the possibilities listed in https://github.com/cpettitt/dagre/issues/54, but not sure how this applies to JSON input. Taking the previous example, I would like to pass the following JSON object to dagreD3.json.decode:

    {
        name: 'graph3',
        nodes: [
    { id: 'a1', value: { label: 'a1', rank: 'min'} },
            { id: 'a2', value: { label: 'a2', rank: 'min'} },
            { id: 'b2', value: { label: 'b2'} },
            { id: 'c2', value: { label: 'c2'} },
            { id: 'a3', value: { label: 'a3', rank: 'min'} },
            { id: 'd1', value: { label: 'd1', rank: 'max'} },
            { id: 'd2', value: { label: 'd2', rank: 'max'} },
            { id: 'd3', value: { label: 'd3', rank: 'max'} }
        ],
        links: [
            { u: 'a1', v: 'd1', value: { label: 'edge0' } },
            { u: 'a2', v: 'b2', value: { label: 'edge1' } },
            { u: 'b2', v: 'c2', value: { label: 'edge2' } },
            { u: 'c2', v: 'd2', value: { label: 'edge3' } },
    { u: 'a3', v: 'd3', value: { label: 'edge4' } }
        ]
    }

Thanks,
Hendrik

Chris Pettitt

unread,
Jul 21, 2014, 11:17:56 PM7/21/14
to hendrik luuk, da...@googlegroups.com, lo...@cb-net.org
Hi Hendrik,


The current implementation does not have support for graph attributes, but there is no reason it shouldn’t allow it.

Let’s assume the data structure you have below is called “jsonGraph”. You could load it into dagreD3 with:

var graph = dagreD3.json.decode(jsonGraph.nodes, jsonGraph.links)
graph.graph({ name: jsonGraph.name })
renderer.run(graph, svgRoot)

The name doesn’t do anything in dagreD3, so you could omit the second line.

Regards,
Chris

On Jul 21, 2014, at 8:20 AM, hendrik luuk <hendri...@gmail.com> wrote:

Is it possible to specify nodes' ranks using JSON notation? I'm aware of the possibilities listed inhttps://github.com/cpettitt/dagre/issues/54, but not sure how this applies to JSON input. Taking the previous example, I would like to pass the following JSON object to dagreD3.json.decode:
Reply all
Reply to author
Forward
0 new messages