Writing beside arrows in doxygen dot graphs - graph

I want to plot a graph in doxygen. I have used the following code.
/*! \mainpage
\dot
digraph example{
node[shape=record, fontname=Helvetica, fontsize=10];
b [label="thread_USRP" ];
c [label="worker1" ];
d [label="worker2" ];
e [label="threadUDP_Tx" ];
b -> c [arrowhead= "open", style = "solid"];
b -> d [arrowhead= "open", style = "solid"];
c -> e [arrowhead= "open", style = "solid"];
d -> e [arrowhead= "open", style = "solid"];
}
\enddot
*/
I want to write something beside the arrows. How can I do that? I also want the arrow from node b to reach a horizontal line and then from the horizontal line I have two arrows that one goes to node c and the other goes to d (something like a tree graph). Can anyone help?
Thanks in advance.

As written in the comment of Having graphs in main page of doxygen the graphviz site (http://graphviz.org/) has a lot of information. In the gallery (http://graphviz.org/gallery/) will give some nice pictures and in e.g. fsm (https://graphviz.gitlab.io/_pages/Gallery/directed/fsm.html) we see a nice example and also the used code:
LR_0 -> LR_2 [ label = "SS(B)" ]
So with the label attribute

Related

create fixed edge directional graphs in dot format with graphviz

Is there anyway to create defined fixed edges directional graphs using dot notation? the following dot notation (fig 2) generates an automated edges that are curved. It doesnt have notations which will generate directions with straight edges (fig 1). Been on hours trying to find anything close, any hints will be great. thank you.
# fig 1
box A --- box B
|. \
|. \
box C. \
box D
# fig 2
digraph G {
node [shape=record];
rankdir="BT"
a -> b [color = red][arrowhead = diamond][taillabel = "tail"]
b -> c [shape = box]
c -> a
}
Not sure what a fixed edge is, but if you don't want splines for edges, look at the splines attribute (https://graphviz.org/docs/attrs/splines/).
Here is you graph with splines=false. You can also try splines=polyline.
You might also connect the edges to specific ports on one or both of the nodes (https://graphviz.org/docs/attr-types/portPos/).
# fig 2
digraph G {
node [shape=record];
// see https://graphviz.org/docs/attrs/splines/
// also look at ports https://graphviz.org/docs/attr-types/portPos/
splines=false // or try splines=polyline
rankdir="BT"
a -> b [color = red][arrowhead = diamond][taillabel = "tail"]
b -> c [shape = box]
c -> a
}
Giving:

Generate Graph from Java data

Let's say I have the following data:
String[][] edges = { "A", "B"}, {"B", "C"}, {"C", "A"} };
Is there a library that would allow me to generate the equivalent in say mermaid:
stateDiagram
A --> B
B --> C
C --> A
or in Plantuml:
#startuml
A --> B
B --> C
C --> A
#enduml
or in dot:
digraph G {
A -> B
B -> C
C -> A
}
Obviously generating the above isn't too difficult as it has no customisation, but I'd like to know if there are libraries allowing for easier generation of above.
The motivation is to have a state machine describing a process and to generate the edges list mentioned above generated through code and the generated graph acting as live documentation.

Ordering flowchart in graphviz

The graph I'd like to produce is a something like this a left-to-right flowchart with a main process at the top, and a series of groupings of stuff below that feed in and out at various points like this:
(though this is a dummy example and I want lots of stuff coming in and out from the top code box, which is why a horizontal layout works better than the default
The problem is that this is made in powerpoint...
I can get something close with this:
digraph example {
graph [
rankdir = LR
]
subgraph cluster_code {
label = "code";
A;
B;
C;
D;
}
subgraph cluster_data {
label = "data";
data_1;
data_2;
}
subgraph cluster_source {
label = "source"
source_1;
source_2
}
A -> B
B -> C
C -> D
data_1 -> A
data_2 -> B
A -> output_1
output_1 -> C
source_1 -> data_1
source_2 -> data_2
#{rank = same; source_2; data_2; A}
}
But if I try to bring the source and data clusters underneath the code cluster using {rank = same; source_2; data_2; A} (this is hashed out above, and I don't repeat the whole code for brevity of the post), I then A, data_2 and source_2 drop out of the box. I think this is something do do with rank and clusters not playing nicely together.
Any hints on getting something like the first graph above?
Am running graphviz via R/Rstudio and DiagrammeR.
It seems that you want to change "rankdir" in the middle of the graph. Quite reasonable, but Graphviz doesn't support it. Here is your graph, using default rankdir and the not-that-well-documented ability to effectively change rankdir by using rank=same in a subgraph. It also reverses edge arrowhead direction - a kludge, but it works.
digraph example {
node [width=1.5]
subgraph cluster_code {
label = "code";
{rank=same
A -> B -> C -> D
}
}
subgraph cluster_data {
label = "data";
data_1;
data_2;
}
subgraph cluster_source {
label = "source"
source_1;
source_2
}
A -> output_1
output_1 -> C
edge[dir=back minlen=2] // minlen makes (rank) space
A -> data_1 // -> A
A -> data_2 // -> A
edge[dir=back minlen=1]
data_1 -> source_1 // -> data_1
data_2 -> source_2 // -> data_2
}
Giving this:

How do I graph the Thompson's construction using graphviz?

I am trying to graph the construction of Thompson using graphviz, and I would like to know if anyone could help me graph one of the rules so that I can do the others.
I attach a reference image: https://en.wikipedia.org/wiki/Thompson%27s_construction#/media/File:Thompson-kleene-star.svg
digraph finite_state_machine {
rankdir=LR;
size="8,5"
node [shape = doublecircle]; s3;
node [shape = circle];
s0 -> s1 [ label = "ε" ];
s0 -> s3 [ label = "ε" ];
s1 -> s2 [ label = "ε" ];
s2 -> s1 [ label = "ε" ];
s2 -> s3 [ label = "ε" ];
}
Graphviz programs try to avoid placing nodes on top of other nodes. You can get the node placement by explicitly providing pos attributes for all the nodes. (Not that difficult, but a nuisance.) You can get neato to generate all straight edges, but you will have to provide the (spline) coordinates for all the arcs. Otherwise you get this:
As an alternative, instead of graphviz, if you use dpic or gpic, this program:
.PS
.defcolor pink rgb #FFC0CB
circlerad=circlerad*.8
## we need to place the large oval before we place nodes on it
Qx: circle invis ; line invis; circle invis; A: line invis;
ellipseht=ellipseht*2;
ellipsewid=ellipsewid*2
E:ellipse at A.c shaded "pink" " N(s)"
move to Qx.w
Q: circle "q" ; arrow "ε" ""; C1: circle ; A: line invis; C2: circle ; arrow "ε" ""; F: circle "f";
circlerad=circlerad*.8
F1:circle at last circle
move to E.n; up; P1: box invis "ε"
arc -> from C2.n to C1.n
arcrad=2
arc -> from Q.s to F.s
### gpic version of greek chars:
# move to E.s; down; box invis "" "\[*e]"
########################################
### dpic/svg version of greek chars
move to E.s; down; box invis "" "ε"
.PE
produced this:
gpic is part of the GNU (Linux) groff package.
dpic can be found here: https://ece.uwaterloo.ca/~aplevich/dpic/

How to specify in DOT file that edges go upwards

I want to render a directed graph like:
A
^ ^
/ \
/ \
B C
But no matter what order I put the statements in, dot insists on generating an image that looks like:
B C
\ /
\ /
v v
A
I've tried specifying the port, but then the edges just wrap around. It doesn't change the position of the nodes.
The solution is rankdir
digraph G {
rankdir="BT"
B->A
C->A
}
rankdir is the solution if you want to build your whole graph from bottom to top. A more flexible approach is to just tell the edges to point backward:
digraph G
{
A -> B[ dir = back ];
A -> C[ dir = back ];
}
yields
You could also write
A -> { B C }[ dir = back ];
Or you could give the general instructions for all edges defined after this instruction to point backward:
edge[ dir = back ];
This can be undone by
edge[ dir = forw ];
Hence,
digraph G
{
edge[ dir = back ];
A -> B;
A -> C;
edge[ dir = forw ];
{ B C } -> D;
}
yields

Resources