How to influence the arrangement of graph elements?

I am trying to visualize a simple finite state graph using Graphviz. The layout created by Graphviz is not really to my liking. I expected a more compact result with shorter edges.

So far I have been trying to use groups and changing the weight of the ribs, but not very good luck. I don’t understand why Graphviz draws a graph the way it does, and how to customize its algorithm to your liking. Are there any options that I can set for this? Or should I use a command other than dot ? I tried neato , but the result looked completely spoiled and again, I do not quite understand what I am doing ...

This is my best result:

Finite State Machine, best result so far

Trying to imagine a better scheme than this, I think that the graph will look better if the red fields are aligned differently, more compact, for example, as shown by the arrows in this figure:

Finite State Machine, imagined better result

I used dot to create a graph, and its source code is as follows:

  1 digraph JobStateDiagram 2 { 3 rankdir=LR; 4 size="8,5"; 5 6 node [style="rounded,filled,bold", shape=box, fixedsize=true, width=1.3, fontname="Arial"]; 7 Created [fillcolor=black, shape=circle, label="", width=0.25]; 8 Destroyed [fillcolor=black, shape=doublecircle, label="", width=0.3]; 9 Empty [fillcolor="#a0ffa0"]; 10 Announced [fillcolor="#a0ffa0"]; 11 Assigned [fillcolor="#a0ffa0"]; 12 Working [fillcolor="#a0ffa0"]; 13 Ready [fillcolor="#a0ffa0"]; 14 TimedOut [fillcolor="#ffa0a0"]; 15 Failed [fillcolor="#ffa0a0"]; 16 17 { 18 rank=source; Created Destroyed; 19 } 20 21 edge [style=bold, fontname="Arial" weight=2] 22 Empty -> Announced [ label="announce" ]; 23 Announced -> Assigned [ label="assign" ]; 24 Assigned -> Working [ label="start" ]; 25 Working -> Ready [ label="finish" ]; 26 Ready -> Empty [ label="revoke" ]; 27 28 edge [fontname="Arial" color="#aaaaaa" weight=1] 29 Announced -> TimedOut [ label="timeout" ]; 30 Assigned -> TimedOut [ label="timeout" ]; 31 Working -> TimedOut [ label="timeout" ]; 32 Working -> Failed [ label="error" ]; 33 TimedOut -> Announced [ label="announce" ]; 34 TimedOut -> Empty [ label="revoke" ]; 35 Failed -> Announced [ label="announce" ]; 36 Failed -> Empty [ label="revoke" ]; 37 38 edge [style=bold, fontname="Arial" weight=1] 39 Created -> Empty [ label="initialize" ]; 40 Empty -> Destroyed [ label="finalize" ]; 41 Announced -> Empty [ label="revoke" ]; 42 Assigned -> Empty [ label="revoke" ]; 43 Working -> Empty [ label="revoke" ]; 44 } 

Also, someone, please let me know if I do any weird things in the Graphviz file above - any feedback would be appreciated.


Update:

More experimentation and attempting some suggestions, such as ports specified by marapet, increased my confusion ... For example, in the image below, why dot chooses to draw these strange detours for Working->Failed and Failed->Announced , as opposed to more direct ones lines?

Graph with strange long edges

+6
source share
1 answer

For me, your result looks good. TimedOut and Failed , of course, everything is to the right, because they have an edge from Working . What dot does best is that, and although you can make some adjustments to customize your chart layouts, I think it's better to use another tool if you want to create a specific chart and manage everything.

Having said that, I quickly tried Graphviz. I changed some lines to create a straight line with all the green nodes and align the red nodes as indicated in your question. I also added boundary concentrators - the result does not look better for me:

 digraph JobStateDiagram { rankdir=LR; size="8,5"; concentrate=true; node [style="rounded,filled,bold", shape=box, fixedsize=true, width=1.3, fontname="Arial"]; Created [fillcolor=black, shape=circle, label="", width=0.25]; Destroyed [fillcolor=black, shape=doublecircle, label="", width=0.3]; Empty [fillcolor="#a0ffa0"]; Failed [fillcolor="#ffa0a0"]; Announced [fillcolor="#a0ffa0"]; Assigned [fillcolor="#a0ffa0"]; Working [fillcolor="#a0ffa0"]; Ready [fillcolor="#a0ffa0"]; TimedOut [fillcolor="#ffa0a0"]; { rank=source; Created; Destroyed; } { rank=same;Announced;Failed; } { rank=same;Assigned;TimedOut; } edge [style=bold, fontname="Arial", weight=100] Empty -> Announced [ label="announce" ]; Announced -> Assigned [ label="assign" ]; Assigned -> Working [ label="start" ]; Working -> Ready [ label="finish" ]; Ready -> Empty [ label="revoke", weight=1 ]; edge [color="#aaaaaa", weight=1] Announced -> TimedOut [ label="timeout" ]; Assigned -> TimedOut [ label="timeout" ]; Working -> TimedOut [ label="timeout" ]; Working -> Failed [ label="error" ]; TimedOut -> Announced [ label="announce" ]; TimedOut -> Empty [ label="revoke" ]; Failed -> Announced [ label="announce" ]; Failed -> Empty [ label="revoke" ]; Created -> Empty [ label="initialize" ]; Empty -> Destroyed [ label="finalize" ]; Announced -> Empty [ label="revoke" ]; Assigned -> Empty [ label="revoke" ]; Working -> Empty [ label="revoke" ]; } 

graphviz output

You can also improve port utilization to control where the edges begin and end.

As for your question about strange things in your dot file: besides line numbers (which ultimately allowed me to make good use of the column mode of my text editor) and alignment , your file looks good to me. I structure my point files in a similar way (graph properties, node list, groupings, edges) when possible. Just keep in mind that the order in which nodes first appear can affect the final layout.

+9
source

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


All Articles