Add label nodes next to a node and make them close by - graphviz

The goal is to render an org-chart, where certain individuals have extra colored "labels" attached to them, representing their role in the scenario. Those labels are supposed to be directly to the left of the individual.
By making the individual and their labels part of a sub-graph, and then telling it that the labels and the person node are all {rank=same;...}, I was able to force the labels to appear where I wanted them.
However, there is a huge distance between the labels and the node that they are annotating. Nothing I have tried seems to fix it.
How do I make it so that the "label" nodes are as close to the node they are supposed to label as they are to one another?
digraph scenario {
outputorder=edgesfirst
rankdir=TB
graph [ splines=true ]
subgraph cluster_spec {
ranksep="0.25 equally"
style="filled";
bgcolor="#f7f7f7";
node [
style="filled",
fillcolor="#f7f7f7",
fontname="sans-serif",
fontsize="10",
shape=circle,
width="0.75in",
fixedsize="shape",
color="black"
]
manager [ label="manager", fillcolor="#00a000", fontcolor="#ffffff" ];
accessor [ label="accessor", fillcolor="#a00000", fontcolor="#ffffff" ];
submitter [ label="submitter", fillcolor="#ffff00", fontcolor="#000000" ];
owner [ label="owner", fillcolor="#0000a0", fontcolor="#ffffff" ];
backup [ label="backup", fillcolor="#a000a0", fontcolor="#ffffff" ];
{rank=same; "submitter" -> "accessor" [ color="#808080", dir="both" ]}
"manager" -> "submitter" [ color="black" ]
"owner" -> "submitter" [ color="black" ]
{rank=same; "submitter" -> "backup" [ color="#808080", dir="both" ]}
"manager" -> "accessor" [ color="black" ]
"owner" -> "accessor" [ color="black" ]
{rank=same; "accessor" -> "backup" [ label="same", color="red:green", dir="both" ]}
{rank=same; "manager" -> "owner" [ label="same", color="red:green", dir="both" ]}
"manager" -> "backup" [ color="black" ]
"owner" -> "backup" [ color="black" ]
}
subgraph cluster_final {
color=white;
ranksep="0.25 equally"
nodesep="0.125"
node [
fontname="sans-serif"
shape=circle,
style="filled",
fillcolor="#e7e7e7",
width="1.5in",
fixedsize=shape,
]
edge [
color="#000080",
headclip=true,
tailclip=true
]
subgraph "cluster_emma-7246-roles" {
{ rank=same;
"emma-7246-submitter" [ shape="cds", label="submitter", style="filled", fillcolor="#ffff00", height="0.75in", width="1.5in", fontcolor="#000000", fontsize="24"]
"emma-7246" [ label="emma-7246" ]
"emma-7246-submitter" -> "emma-7246" [ color="#f0f0f0", len="0.125" ];
}
}
subgraph "cluster_edmund-0712-roles" {
{ rank=same;
"edmund-0712-accessor" [ shape="cds", label="accessor", style="filled", fillcolor="#a00000", height="0.75in", width="1.5in", fontcolor="#ffffff", fontsize="24"]
"edmund-0712-backup" [ shape="cds", label="backup", style="filled", fillcolor="#a000a0", height="0.75in", width="1.5in", fontcolor="#ffffff", fontsize="24"]
"edmund-0712" [ label="edmund-0712" ]
"edmund-0712-accessor" -> "edmund-0712" [ color="#f0f0f0", len="0.125" ];
"edmund-0712-backup" -> "edmund-0712" [ color="#f0f0f0", len="0.125" ];
}
}
subgraph "cluster_emma-8949-roles" {
{ rank=same;
"emma-8949-manager" [ shape="cds", label="manager", style="filled", fillcolor="#00a000", height="0.75in", width="1.5in", fontcolor="#ffffff", fontsize="24"]
"emma-8949-owner" [ shape="cds", label="owner", style="filled", fillcolor="#0000a0", height="0.75in", width="1.5in", fontcolor="#ffffff", fontsize="24"]
"emma-8949" [ label="emma-8949" ]
"emma-8949-manager" -> "emma-8949" [ color="#f0f0f0", len="0.125" ];
"emma-8949-owner" -> "emma-8949" [ color="#f0f0f0", len="0.125" ];
}
}
"edmund-9898" -> "emma-8949"
"emma-8949" -> "edmund-0712"
"emma-8949" -> "emma-7246"
}
}
NOTE: If I take out the first subgraph, then the second one renders the way I expect it to. Something about the presence of the first subgraph is interfering with the layout and rendering of the second one.

Related

graphviz subgraph show from top to down

I am using graphviz to draw a construction of a tree step by step.
It shows like the following:
The tree should show from top to down, not left to right.
The constructing code of the above image:
digraph test1 {
subgraph cluster000005 {
node_1 [label="2, 4"]
node_2 [label=1]
node_1 -> node_2
node_3 [label=3]
node_1 -> node_3
node_4 [label=5]
node_1 -> node_4
label="add 5"
}
subgraph cluster000004 {
node_5 [label=2]
node_6 [label=1]
node_5 -> node_6
node_7 [label="3, 4"]
node_5 -> node_7
label="add 4"
}
subgraph cluster000003 {
node_8 [label=2]
node_9 [label=1]
node_8 -> node_9
node_10 [label=3]
node_8 -> node_10
label="add 3"
}
subgraph cluster000002 {
node_11 [label="1, 2"]
label="add 2"
}
subgraph cluster000001 {
node_12 [label=1]
label="add 1"
}
rankdir=LR
}
Is this what you are after?
remove rankdir statement
add invisible edges to stack clusters (vertically)
lots of fiddling to get clusters to align nicely - added surrounding clusters
This:
digraph test1 {
// added "invisible clusters" to get the "real clusters"
// to align vertically
// don't understand why this was necessary
subgraph clusterInvis1 {
subgraph cluster000005 {
node_1 [label="2, 4" ]
node_2 [label=1]
node_3 [label=3]
node_4 [label=5]
node_1 -> node_2
node_1 -> node_3
node_1 -> node_4
label="add 5"
}
subgraph clusterInvis2 {
subgraph cluster000004 {
node_5 [label=2]
node_6 [label=1]
node_7 [label="3, 4"]
node_5 -> node_6
node_5 -> node_7
label="add 4"
}
subgraph cluster000003 {
node_8 [label=2 ]
node_9 [label=1]
node_10 [label=3 ]
node_8 -> node_9
node_8 -> node_10
label="add 3"
}
peripheries=0 // place here for cluster only (not nodes)
}
peripheries=0 // place here for cluster only (not nodes)
}
subgraph cluster000002 {
node_11 [label="1, 2" ]
label="add 2"
}
subgraph cluster000001 {
node_12 [label=1 ]
label="add 1"
}
//rankdir=LR
edge [style=invis]
node_12 -> node_11 -> node_8
// shorthand to define two edges
{node_9 node_10} -> node_5
{node_6 node_7} -> node_1
}
Gives:

How to add a custom key-value pair to a grok pattern?

How can I add a custom key-value pair to a grok pattern?
For example, I would like to add a key-value pair of "city": [["New York]] to the data result, even though it doesn't exist in the log line.
How do I do this? Tyvm, Keith :^)
Complete, Minimal, and Verifiable Example
Data:
WARN 10/11/2017 kmiklas
Grok:
%{WORD:logLevel}\s%{DATE:date}\s%{USER:user}
{
"logLevel": [
[
"WARN"
]
],
"date": [
[
"10/11/2017"
]
],
"DATE_US": [
[
"10/11/2017"
]
],
"MONTHNUM": [
[
"10",
null
]
],
"MONTHDAY": [
[
"11",
null
]
],
"YEAR": [
[
"2017",
null
]
],
"DATE_EU": [
[
null
]
],
"user": [
[
"kmiklas"
]
],
"USERNAME": [
[
"kmiklas"
]
]
}
I understand that will be a fixed field, so you need to use the mutate method, like this:
mutate { add_field => { "city" => [["New York"]] } }
if you want the new field to be only in some logs you need to include if
if "some_test" in [message]{mutate.....}

How to create an edge from a node to a subgraph in Graphviz Dot?

I want to create a graph that looks like this, i. e. where an edge goes from the node Manufacturer of means of production to the subgraph with the same name.
I wrote the following code for this:
digraph G {
rankdir=LR;
compound=true;
graph [fontname="Liberation Mono"];
node [fontname="Liberation Mono"];
edge [fontname="Liberation Mono"];
subgraph cluster0 {
label="System components";
mmp [label="Manufacturer of means of production", shape=box];
}
subgraph cluster1 {
t1start [label="Start of tact 1", shape=point]
t1end [label="End of tact 1", shape=point ]
subgraph cluster1_mmp {
label="Manufacturer of means of production"
cluster1_1 [label="Node 1", color=white]
subgraph cluster1_1_1 {
label="Technological cycle 1"
cluster1_1_1 [label="Node 2", color=white]
}
subgraph cluster1_1_2 {
label="Technological cycle 2"
cluster1_1_2 [label="Node 2", color=white]
}
}
}
subgraph cluster2 {
label="Такт 2"
t2start [label="Start of tact 2", shape=point]
t2end [label="End of tact 2", shape=point]
}
t1end -> t2start
mmp -> cluster1_1 [ltail=cluster1_mmp];
}
If I try to compile this code ("C:\Program Files (x86)\Graphviz2.38\bin\"dot.exe -Tpng -ograph.png graph.dot ), I get the warning Warning: mmp -> cluster1_1: tail not inside tail cluster cluster1_mmp.
How can I fix it and make the edge go to the subgraph?
Update 1:
Below you can find the image of the expected result -- an edge that goes from a node to a subgraph (subgraph, not a node inside the subgraph). This edge is red in the image below.
Update 2: Changed the code like shown below.
digraph G {
rankdir=LR;
compound=true;
graph [fontname="Liberation Mono"];
node [fontname="Liberation Mono"];
edge [fontname="Liberation Mono"];
subgraph cluster0 {
label="System components";
mmp [label="Manufacturer of means of production", shape=box];
}
subgraph cluster1 {
t1start [label="Start of tact 1", shape=point]
t1end [label="End of tact 1", shape=point ]
subgraph cluster1_mmp {
label="Manufacturer of means of production"
testNode [label="Node 1", color=white]
subgraph cluster1_1_1 {
label="Technological cycle 1"
cluster1_1_1 [label="Node 2", color=white]
}
subgraph cluster1_1_2 {
label="Technological cycle 2"
cluster1_1_2 [label="Node 2", color=white]
}
}
}
subgraph cluster2 {
label="Такт 2"
t2start [label="Start of tact 2", shape=point]
t2end [label="End of tact 2", shape=point]
}
t1end -> t2start
mmp -> cluster1 [ltail=cluster0, lhead=cluster1, label=" "];
}
You need to change your last line
mmp -> cluster1_1 [ltail=cluster1_mmp];
to
mmp -> cluster1_1 [lhead=cluster1 label=" "]
And then the graph comes as expected
Also if you want the edge to start from outside the box then you would do
mmp -> cluster1_1 [ltail=cluster0 lhead=cluster1 label=" "];
Edit
The final code used
digraph G {
rankdir=LR;
compound=true;
graph [fontname="Liberation Mono"];
node [fontname="Liberation Mono"];
edge [fontname="Liberation Mono"];
subgraph cluster0 {
label="System components";
mmp [label="Manufacturer of means of production", shape=box];
}
subgraph cluster1 {
t1start [label="Start of tact 1", shape=point]
t1end [label="End of tact 1", shape=point ]
subgraph cluster1_mmp {
label="Manufacturer of means of production"
cluster1_1 [label="Node 1", color=white]
subgraph cluster1_1_1 {
label="Technological cycle 1"
cluster1_1_1 [label="Node 2", color=white]
}
subgraph cluster1_1_2 {
label="Technological cycle 2"
cluster1_1_2 [label="Node 2", color=white]
}
}
}
subgraph cluster2 {
label="Такт 2"
t2start [label="Start of tact 2", shape=point]
t2end [label="End of tact 2", shape=point]
}
t1end -> t2start
mmp -> cluster1_1 [lhead=cluster1 label=" "]
}
The fiddle link for the same
Urm, did you just mean "lhead=cluster1_mmp" rather than ltail?
Your edge is specified as:
mmp -> cluster1_1 [ltail=cluster1_mmp];
The error message you have is "Warning: mmp -> cluster1_1: tail not inside tail cluster cluster1_mmp"
This says that your tail is not inside the tail cluster. The tail cluster is cluster1_mmp. cluster1_1, which is what you're trying to connect to is definitely inside cluster1_mmp. This explains your confusion.
Only after much investigation with a GraphvizFiddle did I eventually remember that with an arrow the pointy end is the head (that is, the syntax is tail -> head).
So, cluster1_1, the node you're trying to says is in cluster1_mmp is the head of the arrow. That's why your ltail specification isn't working. Changing it to lhead gets rid of the error message and generates a graph that looks like your picture. The arrow goes to the subgraph, exactly what you asked for in your question.
Here's are two GraphvizFiddles, one of the original code generating the original error and one with ltail changed to lhead which matches your picture.
(I'm sure I've spent ages debugging the same problem in my own graphs. Perhaps Graphviz could get an update to check if the the ltail parameter would make sense for the arrow head and vice versa and spit out a more helpful error message.)

Draw an ordered hierarchy using Graphviz

I have an ordered hierarchy which I'd like to plot using Graphviz (or some other visualisation program).
Ideally the plot would draw the leading and trailing vector of a node and maintain the correct level in the hierarchy. What I'm most unsure of is how to maintain the levels of hierarchy since trailing vectors can return to their superior/parent.
If it is unclear what exactly I am asking for then at 47 minutes of this video https://www.youtube.com/watch?v=sWgDk-o-6ZE there is a picture in the presentation.
I'd like to know if it is possible and what the graphviz (.gv) file might look like.
Thanks!
I wrote a Prolog program to produce genealogical 'trees', like this one
Here the DB is small, but it works fairly well for larger data sets... the .gv computed by the program, submitted to Graphviz for rendering:
digraph "graph_window" {
node [
style = "radial"
fillcolor = "white"
shape = "ellipse"
label = ""
]
edge [
arrowhead = "vee"
]
subgraph "1" {
rank = "same"
rankdir = "LR"
subgraph "['Cecilia Cavendish-Bentinck','Claude Bowes-Lyon']" {
"'Cecilia Cavendish-Bentinck'" [
fillcolor = "white:red"
label = "Cecilia Cavendish-Bentinck"
]
"'Claude Bowes-Lyon'" [
fillcolor = "white:green"
label = "Claude Bowes-Lyon"
]
}
subgraph "['George V','Princess Mary of Teck']" {
"'George V'" [
fillcolor = "white:green"
label = "George V"
]
"'Princess Mary of Teck'" [
fillcolor = "white:red"
label = "Princess Mary of Teck"
]
}
}
subgraph "2" {
rank = "same"
rankdir = "LR"
subgraph "['George VI','Lady Elizabeth Bowes-Lyon']" {
"'George VI'" [
fillcolor = "white:green"
label = "George VI"
]
"'Lady Elizabeth Bowes-Lyon'" [
fillcolor = "white:red"
label = "Lady Elizabeth Bowes-Lyon"
]
}
"'Rose Bowes-Lyon'" [
fillcolor = "white:red"
label = "Rose Bowes-Lyon"
]
}
subgraph "3" {
rank = "same"
rankdir = "LR"
"'Elizabeth II'" [
fillcolor = "white:red"
label = "Elizabeth II"
]
}
"['George V','Princess Mary of Teck']" [
shape = "point"
width = "0.1"
height = "0.1"
]
"['Cecilia Cavendish-Bentinck','Claude Bowes-Lyon']" [
shape = "point"
width = "0.1"
height = "0.1"
]
"['George VI','Lady Elizabeth Bowes-Lyon']" [
shape = "point"
width = "0.1"
height = "0.1"
]
"'George V'" -> "['George V','Princess Mary of Teck']" [
]
"'Princess Mary of Teck'" -> "['George V','Princess Mary of Teck']" [
]
"['George V','Princess Mary of Teck']" -> "'George VI'" [
]
"'Cecilia Cavendish-Bentinck'" -> "['Cecilia Cavendish-Bentinck','Claude Bowes-Lyon']" [
]
"'Claude Bowes-Lyon'" -> "['Cecilia Cavendish-Bentinck','Claude Bowes-Lyon']" [
]
"['Cecilia Cavendish-Bentinck','Claude Bowes-Lyon']" -> "'Lady Elizabeth Bowes-Lyon'" [
]
"['Cecilia Cavendish-Bentinck','Claude Bowes-Lyon']" -> "'Rose Bowes-Lyon'" [
]
"'George VI'" -> "['George VI','Lady Elizabeth Bowes-Lyon']" [
]
"'Lady Elizabeth Bowes-Lyon'" -> "['George VI','Lady Elizabeth Bowes-Lyon']" [
]
"['George VI','Lady Elizabeth Bowes-Lyon']" -> "'Elizabeth II'" [
]
}
that is, each layer goes into its own subgraph. I further used the subgraph to group pairs of parents.

GraphViz - How to have a subgraph be left-to-right when main graph is top-to-bottom?

I have a graph file like this:
digraph {
"Step1" -> "Step2" -> "Step3";
subgraph step2detail {
"Step2" -> "note1";
"Step2" -> "note2";
"Step2" -> "note3";
"Step2" -> "note4";
rankdir=TB
}
}
I want the subgraph step2detail to hang off to the right of 'Step2'.
Right now it looks like this:
I want Step1, Step2 and Step3 to all be vertically under each other and in 1 column.
The trick to get the graph you described is to use two subgraphs and link from one to the other. The invisible edges in "details" are what keep the notes aligned.
digraph {
rankdir="LR";
subgraph steps {
rank="same";
"Step1" -> "Step2" -> "Step3";
}
subgraph details {
rank="same";
edge[style="invisible",dir="none"];
"note1" -> "note2" -> "note3" -> "note4";
}
"Step2" -> "note1";
"Step2" -> "note2";
"Step2" -> "note3";
"Step2" -> "note4";
}
The result is:
Here's as simple as it gets - just use the group attribute to have graphviz prefer straight
edges:
digraph {
node[group=a, fontname="Arial", fontsize=14];
"Step1" -> "Step2" -> "Step3";
node[group=""];
"Step2" -> "note1";
"Step2" -> "note2";
"Step2" -> "note3";
"Step2" -> "note4";
}
By grouping the Step nodes into a clustered subgraph, the output is as follows:
digraph {
subgraph cluster_0 {
color=invis;
"Step1" -> "Step2" -> "Step3";
}
subgraph cluster_1 {
color=invis;
"Step2" -> "note4";
"Step2" -> "note3";
"Step2" -> "note2";
"Step2" -> "note1";
}
}
color=invis removes the border that would otherwise be drawn around the cluster
rankdir doesn't work directly in the subgraph, but if you add another set of curly braces - whatever that's called - rankdir works:
digraph {
"Step1" -> "Step2" -> "Step3";
subgraph step2detail {
{
"Step2" -> "note1";
"Step2" -> "note2";
"Step2" -> "note3";
"Step2" -> "note4";
rankdir=TB
rank=same
}
}
}
Use the command: rankdir=LR;
digraph {
rankdir=LR;
"Step1" -> "Step2" -> "Step3";
subgraph step2detail {
"Step2" -> "note1";
"Step2" -> "note2";
"Step2" -> "note3";
"Step2" -> "note4";
rankdir=TB
}
}

Resources