Note that there are some explanatory texts on larger screens.

plurals
  1. POHow does a script optimally layout a pure hierarchical graphviz/dot graph?
    primarykey
    data
    text
    <p>I am about to write a script that generates graphviz/dot graphs with the following two characteristics:</p> <ol> <li>All except one node have excactly one parent node (so, it's a tree).</li> <li>If two or more node share the sampe parent node, they themselves are in a specific order.</li> </ol> <p>With these characteristics, I'd like my resulting (that is dot-generated graph) to look like so:</p> <ol> <li>No edges should cross</li> <li>Nodes with the same parent should have the same distance from the graphs top border.</li> <li>Nodes with the same parent should be drawn from left to right according to their ordering</li> </ol> <p>However, I can't make dot behave the way I'd like. Here's a dot file to demonstrate my problem:</p> <pre><code>digraph G { node [shape=plaintext fontname="Arial"]; 0 [label="zero" ]; 1 [label="one" ]; 2 [label="two" ]; 3 [label="three" ]; 4 [label="four" ]; 5 [label="five" ]; 6 [label="six" ]; 7 [label="seven" ]; 8 [label="eight" ]; 9 [label="nine" ]; 10 [label="ten" ]; 11 [label="eleven" ]; 12 [label="twelve" ]; 13 [label="thirteen" ]; 14 [label="fourteen" ]; 15 [label="fivteen" ]; 16 [label="sixteen" ]; 17 [label="seventeen" ]; 18 [label="eighteen" ]; 19 [label="nineteen" ]; 20 [label="twenty" ]; 21 [label="twenty-one"]; 22 [label="twenty-two"]; 0 -&gt; 1 [arrowhead=none]; 1 -&gt; 2 [arrowhead=none]; 2 -&gt; 7 [arrowhead=none]; 7 -&gt; 8 [arrowhead=none]; 8 -&gt; 9 [arrowhead=none]; 8 -&gt; 10 [arrowhead=none]; 9 -&gt; 10 [color="#aaaaaa" constraint=false]; 10 -&gt; 11 [arrowhead=none]; 10 -&gt; 12 [arrowhead=none]; 11 -&gt; 12 [color="#aaaaaa" constraint=false]; 7 -&gt; 13 [arrowhead=none]; 8 -&gt; 13 [color="#aaaaaa" constraint=false]; 13 -&gt; 14 [arrowhead=none]; 7 -&gt; 15 [arrowhead=none]; 13 -&gt; 15 [color="#aaaaaa" constraint=false]; 15 -&gt; 16 [arrowhead=none]; 15 -&gt; 17 [arrowhead=none]; 16 -&gt; 17 [color="#aaaaaa" constraint=false]; 2 -&gt; 3 [arrowhead=none]; 7 -&gt; 3 [color="#aaaaaa" constraint=false]; 3 -&gt; 4 [arrowhead=none]; 2 -&gt; 5 [arrowhead=none]; 3 -&gt; 5 [color="#aaaaaa" constraint=false]; 5 -&gt; 6 [arrowhead=none]; 2 -&gt; 18 [arrowhead=none]; 5 -&gt; 18 [color="#aaaaaa" constraint=false]; 18 -&gt; 19 [arrowhead=none]; 19 -&gt; 20 [arrowhead=none]; 19 -&gt; 21 [arrowhead=none]; 20 -&gt; 21 [color="#aaaaaa" constraint=false]; 18 -&gt; 22 [arrowhead=none]; 19 -&gt; 22 [color="#aaaaaa" constraint=false]; } </code></pre> <p>results in </p> <p><img src="https://i.stack.imgur.com/qg2kX.jpg" alt="Resulting graph"></p> <p>Note, the ordering between siblings is indicated by the grey edges (arrows).</p> <p>So, for example, I am happy with the <em>seven -> three -> five -> eighteen</em> siblings, since they are drawn from left to right in their correct order (as indicated by the arrows).</p> <p>But I am unhappy with the siblings <em>eight -> thirteen -> fivteen</em> because their edges cross other edges and because their ordering is not from left to right, as I'd like.</p> <p>Also, <em>nine -> ten</em>, <em>twenty -> twenty-one</em> and <em>nineteen -> twenty-two</em> are in the wrong direction.</p> <p>I am aware that I could probably get to a picture as I want <em>if</em> I used additional (invisible) edges and the <code>weight</code> attribute and possibly even more features. But as the graphs (and there are many of those) are generated by a script, I can't do that manually.</p> <p>So, is there a way to achieve what I want?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload