Can I auto-fit the width of Graphviz nodes using dot? - graphviz

Please does anyone know if there's a way to make Graphviz's dot program (note: not neato, although I'd also be somewhat interested in answers for that) auto-fit the width of nodes to accommodate the labels I specify? At the moment I have this
digraph
{
node [shape=record];
n [label="This is a very long caption"];
}
but the node ends up too small to accommodate the caption:
I found an option called fixedsize, which in theory I should be able to set to false in order to make the nodes expand to fit their labels:
http://www.graphviz.org/doc/info/attrs.html#d:fixedsize
Unfortunately, it doesn't work, as this gives me the same result:
digraph
{
node [shape=record, fixedsize=false];
n [label="This is a very long caption"];
}
Any ideas please?

The node label width in your example actually does auto-fit when using dot.
fixedsize=false (default) and any given value for width however should yield the given value for width if the output format is dot:
Note also that, if the output format is dot, the value given to width
will be the final value.
There may be a problem with your version of graphviz - did you try using a recent version?

Related

graphviz - prevent nodes and edges overlapping without splines

I have a simple fdp graph laid out in graphviz, with a bunch of nodes (rectangle and diamond shaped) having fixed positions, and some of those nodes have child nodes (oval shaped) that I want to be arranged around them automatically.
I want all edges in it to be straight, with no curves or polylines or anything (i.e. as given by splines=false), but I also want those child nodes to not overlap with edges between nodes with fixed positions. The fixed positions are used as I need edges between the fixed nodes to be fully vertical or horizontal. This is something that I probably can achieve by iterating over different start values and hoping that the next one will not have overlaps, but so far this is a bit tiresome.
digraph G {
###GRAPH
layout=fdp
overlap=false
dpi=150
splines=false
inputscale=0.4
# fdp specific:
K=0.50
maxiter=2000
start=1251
###OBJECTS
node[shape=rectangle width=1.0 height=0.4 fixedsize=true]
vendor[label="Поставщик" pos="3,1!"
]
item[label="Товар" pos="0,2!"
]
post[label="Поставка" pos="2,2!"
]
check[label="Чек" pos="1,1!"
]
prod[label="Продажа" pos="0,0!"
]
###SUBOBJECTS
node[shape=oval width=1.5 height=0.5]
edge[arrowhead=none]
{
vendork[label=<<u>ID поставщика</u>>] "Название\nпоставщика" "Контакт\nдля связи"
}->vendor
{
itemk[label=<<u>ID товара</u>>]
Название Тип Подтип Характеристики "Розничная цена"
}->item
{
postk[label=<<u>ID записи</u>>] post1[label="ID товара"]
post2[label="Кол-во"] post3[label="Цена поставки"]
post4[label="Дата"] post5[label="Квитанция"]
}->post
{
prodk[label=<<u>ID продажи</u>>] prod1[label="ID товара"]
prod2[label="Кол-во"] prod3[label="Цена\nпродажи"]
prod4[label="Чек"]
}->prod
{
checkk[label=<<u>ID чека</u>>] Дата Кассир "Сумма" "НДС" "Итого" "Вид оплаты"
}->check
###CONNECTIONS
node[shape=diamond]
edge[arrowhead=open]
vendorpost[label="Поставляет" pos="3,2!"
]
vendorpost->vendor
vendorpost->post[arrowhead=openopen]
postitem[label="Поставлен" pos="1,2!"
]
postitem->item
postitem->post[arrowhead=openopen]
itemprod[label="Продан" pos="0,1!"
]
itemprod->item
itemprod->prod[arrowhead=openopen]
prodcheck[label="Включает" pos="1,0!"
]
prodcheck->prod[arrowhead=openopen]
prodcheck->check
}
(forgive the cyrillics)
I am compiling with no additional parameters (i.e. dot -Tpng graph.gv > graph.png). So far, I get this.
I've tried using neato instead as well, but, in most cases, it gives a pretty weird result, where it seems like it completely ignores the fixed node positions, and draws the child nodes whereever it wants:
I went through the list of attributes in the documentation, and so far none seem to address node/edge overlapping besides splines (unless I've missed something). What should I do to achieve the result I'm looking for?
There are several issues:
layout=fdp causes the fdp layout engine to be used, no matter what the command line says
Use neato -n if you want to nail down the node position (see below)
by adding a ! to the position you are nailing down the pos (it won't change)
dot is not useful here, it is directional (top-down)
If you remove all the !, I think you will get what you want.
So far, one solution I've found is by adding invisible stretched out nodes that cover each edge that is fixed(i.e. between two nodes with fixed positions) by appending this to the graph:
###NO VERTICAL/HORIZONTAL EDGE/NODE INTERSECT HACK
node[style=invis]
node[width=0.1 height=2.0]
t1[label="" pos="0,1.5!"]
t2[label="" pos="0,0.5!"]
t3[label="" pos="1,0.5!"]
t4[label="" pos="3,1.5!"]
node[width=2.0 height=0.1]
t5[label="" pos="2.5,2!"]
t6[label="" pos="1.5,2!"]
t7[label="" pos="0.5,2!"]
t8[label="" pos="0.5,0!"]
node[style=normal]
And this does what I want, i.e. removes all overlaps with fixed edges:
However, this is limited only to edges that are perfectly vertical/horizontal(note that there is still at least 1 overlap in "child" nodes), and overall seems like a really hacky solution as I have to add/change those "support beams" every time I add/change any more nodes to my graph. Is there a better solution to this?

Graphviz with nodes and edges in Russian: edge label has offset and Node is enlarged

I'm drawing diagram with graphviz. I set node and edge labels in Russian. Nodes with Russian labels are much larger than nodes with English labels with the same length. Also edge labels in Russian have offset that labels in English doesn't have.
I tried to use different graphviz tools such as: viz-js.com, Atom editor with graphviz plugin, gvedit. Only gvedit provides correct result, but I can't use it.
Here is sample code:
digraph D {
Anton -> Антон [label="Метка"]
Anton -> Bob [label="Label"]
}
Result is:
Not really an solution / answer but some observations and it is a bit long for a comment.
I tried the given file directly with dot version 2.38.0 (20140413.2041) and got as result:
I also tried with version version 2.40.1 (20161225.0304) and got the same result.
So I think the underlying dot program is working correct.
I also tried http://www.webgraphviz.com/ but here I get the message:
Warning: :3: string ran past end of line Error: :3: syntax error near line 3
and the resulting image is even worse:
So here it looks like the used input encoding is not correct, this might also be the case with the tools OP used.

Increasing rank spacing in graphviz

I have a graph laid out using D3 graphviz. It's laying out in a pretty dense way, and I'd like it to use more of the width of the screen.
I have tried adjusing the ranksep and the ratio, but neither seem to have any effect. I've also tried changing the node border, to no effect. Changing the edge minlength just makes the edges look floppy. I can try giving every node an invisible child, but that seems like a horrible hack.
For clarity, by rank, I mean the horizontal spacing between the columns of nodes. (The graph is laid out left to right.)
Ideally I'd be able to give it an aspect ratio and it'd make the most of that space to lay out the graph in a way that doesn't need too much acrobatics.
Am I missing something obvious?
I may well be using the options incorrectly
or the D3 graphviz implementation may not have those features?
Is there no good way to do this?
I have added :
size = "16.66,8.33!"; // 1200x600 at 72px/in, "!" to force
ratio = "fill"; // see https://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:ratio
at the beginning of the graph declaration (just after digraph G {).
It renders a wider output.
Have a try and tell.

dot graph without labels

I have a graph file to draw using "dot". I don't want to show any label for any node. I am wondering how to do this without specifying a configuration for each node since there are too many nodes in the graph.
Try inserting the following line before all node declarations:
node[label=""];
Of course, nodes which have their label property defined will still have their label displayed.
Also, if I remember correctly, at least one node shapes does not use the label:
node[shape=point]

Prevent overlapping records using graphviz and neato

I am building a dot file to represent computer hardware and the physical connections to a network switch and displays. I have it looking ok when processed by the dot program but I think I really want it processed by neato to create a more "free form" picture as it starts to grom. Right now when I run my large file with neato, everything is overlapping.
I am trying to figure out the syntax on where to define the overlap attribute. Below is a subset of my dot file.
graph g {
node [shape=record,height=.1];
PC8[label="{{<GigE1>GigE1|<GigE2>GigE2}|{<name>PC8}|{<dvi1>dvi1|<dvi2>dvi2|<dvi3>dvi3|<dvi4>dvi4}}"];
PC9[label="{{<GigE1>GigE1|<GigE2>GigE2}|{<name>PC9}|{<dvi1>dvi1|<dvi2>dvi2|<dvi3>dvi3|<dvi4>dvi4}}"];
C1[label = "{{<dvi1>dvi1}|{<name>C1}}"];
C2[label = "{{<dvi1>dvi1}|{<name>C2}}"];
C3[label = "{{<dvi1>dvi1}|{<name>C3}}"];
C4[label = "{{<dvi1>dvi1}|{<name>C4}}"];
D1[label = "{{<dvi1>dvi1}|{<name>D1}}"];
D2[label = "{{<dvi1>dvi1}|{<name>D2}}"];
"PC8":dvi1 -- "C1":dvi1;
"PC8":dvi2 -- "C2":dvi1;
"PC8":dvi3 -- "C3":dvi1;
"PC8":dvi4 -- "C4":dvi1;
"PC9":dvi1 -- "D1":dvi1;
"PC9":dvi2 -- "D2":dvi1;
}
Well, as with most questions...soon after I posted the I figured out the answer. I needed to add graph [overlap=false]; at the top of the file.
Do it like this:
graph g {
overlap = false;
node [shape=record,height=.1];
/* ... */
}
Setting overlap to false will work for neato as the community wiki answer says; however, if the graph exhibits any kind of regularity or symmetry, [overlap=false] will often mess it up by jiggling the nodes around to make them not overlap.
Use [overlap=false] as a last resort.
All node overlaps that are outputted from neato can be viewed as occurring because the nodes are too big relative to the edges. You can make any overlaps go away by making the nodes smaller and preserve symmetry in the graph drawing by setting [overlap=scale]. Quoting the Neato user manual:
To improve clarity, it is sometimes helpful to eliminate overlapping
nodes or edges. One way to eliminate node overlaps is just to scale up
the layout (in terms of the center points of the nodes) as much as
needed. This is enabled by setting the graph attribute overlap=scale.
This transformation preserves the overall geometric relationships in
the layout, but in bad cases can require high scale factors
As the documentation says [overlap=scale] can result in graph drawings that are unacceptably large, but if it does not its output is generally going to be better looking than [overlap=false].

Resources