GraphViz: Export as LibreDraw - graphviz

You can generate SVG that can be read by LibreDraw:
neato -Gepsilon=.000000001 -Tsvg
but this does not link the objects, so if you move a node the edge does not follow, which make it much harder to post-process the drawing.
Is there an export format that can be read by LibreDraw, but that links the edges to the nodes, so individuel nodes can be moved without breaking links?

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?

Is there a way to create a table with nodes as cells in Graphviz

While it is pretty easy to create a table of labels in Graphviz, I have not come across a method that teaches a way to create a table of nodes. All the nodes are standalone and clickable svg elements. This can, of course, be done with HTML and div etc. But can we do the same without leaving the Graphviz world?
See figure
Graphviz does not support nodes within "html".
Nor, (to my knowledge) does Graphviz support any SVG "onclick" events (for any nodes).
You might consider postprocessing the SVG output to add the "onclick" code.

GraphViz Dot. How to distribute elements around a boxed size?

I have a dot graphviz file that geneates the following output:
http://www.qlands.com/other_files/test.png
However the output is organized vertically. If I setup the size to be for example 8.27 inches; How can I distribute the elements around a box of 8.27 x 8.27 inches?
Your graph is a directed graph layed out with dot from left to right, and the first rank contains many nodes which results in a very high image.
The main tool to break up graphs with this problem is unflatten:
unflatten is a preprocessor to dot that is used to improve the aspect
ratio of graphs having many leaves or disconnected nodes. The usual
layout for such a graph is generally very wide or tall. unflatten
inserts invisible edges or adjusts the minlen on edges to improve
layout compaction.
You may combine this with other tools and techniques to get the result you want:
Use the unflatten utility - please see this answer for a detailed example using unflatten.
Use invisible edges to introduce new ranks (basically what unflatten does automatically, but with human inspiration... example also here)
If you need the output to be of this exact size, be sure to understand graphviz's various attributes which have an impact on it, such as size, margin, ratio... (see also this and yet another answer providing details)
Finally, you could simply use a different layout (neato for example)

Display labels in line with the edge when using Graphviz

I am using Graphviz 2.30. Horizontal positioning for labels works out, but in a few cases, a modified angle would be desired.
For instance, I tried various values for angle here but without any effect:
ABB -> ABACUS[label="applied", fontname="Arial", fontsize=15, labelangle=110];
How can I display labels in line with (i.e. parallel to) the edge when using a Graphviz digraph.
The entire digraph will not be posted due to an NDA. In addition, the rotation will be applied only to a few labels.
I have read similar threads like this or another (or a thread about alignment for instance) but without any help regarding my issue.
Using dot2latex allows you to specify lblstyle attribute. The value of lblstyle is used by PGF/TikZ in pdf generation.
One can specify parallel labels like this:
digraph G {
edge [lblstyle="above, sloped"];
a -> b [label="ab"];
b -> c [label="bc"];
c -> a [label="ca"];
}
To generate the pdf
$ dot2tex --tikzedgelabel file.dot > file.tex
$ pdflatex file.tex
The result is
Edit: another answer found an option that now exists to align text with edges.
Your best option may be to export the graph as an SVG and use Illustrator or Inkscape to fine-tune it. This is only practical when producing a few graphs.
I frequently have to tweak the output from Graphviz and Gephi; they give me a good starting point though.

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