Set the direction of the node on the chart

Suppose this code uses neato:

graph sample { layout=neato overlap=false splines=true tailclip=false headclip=false A -- I A -- J A -- B A -- H A -- E A -- K B -- D B -- C B -- L C -- M C -- N C -- O D -- P D -- Q E -- R F -- A G -- F H -- J } 

This gives us this diagram:

neato diagram

I need to place node X , always fixed at a position south of its parent node. those. if I set a different relationship A -- X , X should always be located south of A And I don’t care where everything else ends.

I looked at the pos attribute, but it doesn't seem to be a solution, since X not in a fixed position, but in a position relative to its relationship.

Also tailport and headport , but they only determine where the / in edge will come from, but they do not really affect the direction of the node.

Update

Additional image to make everything clearer:

x should be south from his parent

I don’t need neato, but I don’t want the graph to look like a tree of UD or LR dots, I don’t want it to be ordered by linearity. circo, fdp, sfdp, twopi is okay too.

+4
source share
2 answers

The neato program supports several modes, one of which can probably give you what you want. In particular, if you set mode = ipsep, you can specify dot-like restrictions that are respected during linking. For example, I take your graph and use the graph attributes

 mode=ipsep diredgeconstraints=true levelsgap=0.5 

The first includes ipsep mode, the second indicates the models support directional edges, as at a point, and the latter indicates how strong the separation should be. Then I set the edge dir attribute to none

 edge[dir=none] 

and add edge A - X [dir = 1]

A value of dir = 1 indicates that this edge should cause a directional constraint. If I run neato, I get an added picture.

neato layout

The Graphviz attribute documentation http://www.graphviz.org/content/attrs provides additional information about these attributes.

+4
source

In response to the updated restrictions, one solution is to output A and X, and then lay out a graph around them:

 graph sample { overlap=false; splines=true; tailclip=false; headclip=false; A [pin=true,pos="0,.2"] X [pin=true,pos="0,.1"] A -- I A -- J A -- B A -- H A -- E A -- K B -- D B -- C B -- L C -- M C -- N C -- O D -- P D -- Q E -- R F -- A G -- F H -- J A -- X 

graph output

I tried linking with both neato and fdp and it seems to create the graph as you want. Naturally, if you want to impose such a restriction on arbitrary pairs of nodes on the same graph, this solution may not work.

--- Earlier answer ---

If you are committed to using neato, I'm not sure there is a way to solve the problem without changing the schedule at the post-processing stage. If neato is just convenient by default, then you should solve your problem by using a dot instead of your layout and using "rankdir = UD", as well as a couple extra kludges if X should be south.

If you only need a restriction to apply for one node X, then placing X and A together in the cluster should complete the task:

 graph sample { rankdir=UD layout=dot overlap=false // .. as before A -- X subgraph clusterone { style=invisible A X } } 

If you need a strict south constraint to apply to arbitrary children of A, then this clustering is accompanied by the trick described in:

How to force all nodes in one column in graphviz?

can do the trick. The clusterrank=local attribute may also be useful in this case, but I'm not sure. Hope this helps.

+4
source

Source: https://habr.com/ru/post/1390303/


All Articles