give each wedge a different label in style=wedged in DOT graphviz - graphviz

I could not figure out looking at the Graphviz docs if there is a way to specify different labels for each wedge in a circle with style=wedged. e.g. below node draws a circle divided into 3 wedges with three colors.
nodepie [shape = "circle" style = "wedged" fillcolor = "green:red:yellow"];
I want to put different numbers on each wedge.
Could anybody help?
Thanks for your help.

Sorry, but I don't think this is possible; I've tried before. Even using weird combinations of html labels I wasn't able to get a satisfactory result. There's nothing in the label documentation that even hints at a method for achieving this.
Sorry I don't have a more positive answer for you, but in the case I think it's "no." As you can see, alignment is a mess; it might be feasible if the pie had four wedges and the html label could be superimposed on top, two rows and two columns. But with three it's hard to imagine a layout that would delight:
digraph x{
nodepie [shape = "circle" style = "wedged" fillcolor = "green:red:yellow"
label=< <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0"> <TR><TD PORT="f0">one</TD><TD>two</TD></TR> </TABLE>>];
}

Workaround for three wedgets (of approximately same size);
digraph x{
nodepie [shape = "circle" style = "wedged" fillcolor = "green:red:yellow"
label=<
<TABLE BORDER="0" CELLBORDER="0" CELLSPACING="0">
<TR>
<TD PORT="f0" ROWSPAN="2">one</TD>
<TD ROWSPAN="2"> </TD>
<TD>two</TD>
</TR>
<TR>
<TD PORT="f0">tree</TD>
</TR>
</TABLE>
>];
}

If you create a html-table with elements using the same colors as the WEDGE, you can have your labels next to the pie.
digraph structs {
p01 [shape = none
label = <<table border="0" cellspacing="0">
<tr><td bgcolor="blue">P01</td></tr>
<tr><td bgcolor="red">P02</td></tr>
<tr><td bgcolor="yellow">P03</td></tr>
<tr><td bgcolor="green">P04</td></tr>
</table>>]
node [shape=circle]
pie [label="wedged"
style=wedged
color=none
fillcolor="blue;0.4:red;0.1:yellow;0.2:green"
fontcolor=pink]
}
Result:

Related

Create node in graphviz using polygon as icon and text label

Is there any way to create a node in Graphviz that looks like the below?
(Placing a hexagon and text side by side inside the node instead of just placing text inside box)
You can't easily embed nodes within other nodes, but you can insert images into nodes. Create an image (or images) with the polygon shape(s) and insert them into an HTML-style node (record-style would probably also work).
Like so:
digraph i{
{rank=same
n1 [shape=plaintext,label=<
<TABLE CELLSPACING="0" CELLPADDING="0" BORDER="1" cellborder="0">
<TR><TD FIXEDSIZE="true" height="20" width="20"><IMG SRC="cow.png" scale="true"/></TD><TD>some text</TD></TR>
</TABLE>
>
]
n2 [shape=plaintext,label=<
<TABLE CELLSPACING="0" CELLPADDING="0" BORDER="1" cellborder="0" >
<TR><TD colspan="2" bgcolor="green1">Step</TD></TR>
<TR><TD FIXEDSIZE="true" height="20" width="20"><IMG SRC="cow.png" scale="true"/></TD><TD>some text</TD></TR>
</TABLE>
>
]
n1 -> n2
}
}
Giving:

How to make left aligned italic labels

I know there's \l for left aligned line breaks and also <I></I> for italic text in HTML labels, but how would I make left aligned italic labels?
Those escape strings for alignment seem to work only in regular labels. However, when using HTML-based strings for node labels, you may use the align attribute.
The following example shows the use of align for table cells td and within the text of a table cell using line breaks br:
digraph G {
n[shape=rect, label=<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
<TR><TD colspan="3">Very very wide text in the first line</TD></TR>
<TR>
<TD width="1" align="left"><i>one</i></TD>
<TD width="1" align="center">two</TD>
<TD width="1" align="right">three</TD>
</TR>
<TR><TD colspan="3">More wide text without meaning
<br/>
<i>four</i>
<br align="right" />
<i>five</i>
<br align="left" />
</TD>
</TR>
</TABLE>
>]
}
In case you're looking for a simple solution and aren't into HTML-like labels, and the entire label has to be italic, then you may also use an italic font:
graph {
n[width=2, label="left\l", fontname="times-italic"]
}
Your fontname may vary, depending on your system (see also fontname)

How to layout Graphviz / dot layout and order question

I'm trying to use dot notation and set the order of the items. in the example below I would like FLIP/FLOPA to be on top and FLIP/FLOPB on the bottom. It would also be good to line everything up.
I'm a bit confused how invisible edges might work?
this is where im at:
digraph G {
graph [pad ="1", rankdir = LR, splines=ortho];
size = "16.66,8.33!"; // 1200x600 at 72px/in, "!" to force
ratio = "fill";
node[shape=record];
flipa[label="FLIPA", height=3];
flopa[label="FLOPA", height=3];
flipb[label="FLIPB", height=3];
flopb[label="FLOPB", height=3];
source1[shape=rarrow];
source2[shape=rarrow];
sink1[shape=rarrow];
sink2[shape=rarrow];
source1 -> flipa;
flipa -> flopa [label="red" color=red,penwidth=3.0];
flipa -> flopa [label="blue" color=blue,penwidth=3.0];
flopa -> sink1;
source2 -> flipb;
flipb -> flopb [label="red" color=red,penwidth=3.0];
flipb -> flopb [label="blue" color=blue,penwidth=3.0];
flopb -> sink2;
label="Graph";
labelloc=top;
labeljust=left;
}
Thanks in advance
Neil
The order in which you mention nodes in layout is important.
If you have horizontal layout (rankdir=LR), the nodes appear in your layout from bottom to top, look at this, for example:
digraph {
rankdir=LR
node1
node2
node3
}
This results in:
Now if we reverse the order:
digraph {
rankdir=LR
node3
node2
node1
}
We get this:
PS: I don't recommend using ortho splines, they may cause all sorts of artifacts, including very poor handling of edge labels. You problems with lining up may be caused by them. Even though when I compile your code on my machine, the nodes are lined up correctly.
To answer your question in the comments:
How to implement parallel edges without splines=ortho
But let me warn you, it is very ugly.
In graphviz you can use HTML-like syntax to define some structures, most important of them being tables. Any old enough frontender will tell you that you can design almost anything using tables. I use them a lot when work with graphviz.
What you can do in your situation: instead of your plain rectangular nodes place a table with three rows. Top row and bottom row are going to be empty. The middle one will contain your label: FLIPA or FLOPA.
Next you assign port attribute to all cells. This way you will be able to connect specific rows of tables together using the headport and tailport (or their synonims, the colon-syntax, which I used in example below).
Here's the example:
digraph G {
graph [pad ="1", rankdir = LR];
size = "16.66,8.33!"; // 1200x600 at 72px/in, "!" to force
ratio = "fill";
node[shape=record];
flipb[
shape=plain
label=<
<table border="1" cellspacing="0" cellborder="0">
<tr>
<td height="80" port="upper"> </td>
</tr>
<tr>
<td height="80" port="middle">FLIPB</td>
</tr>
<tr>
<td height="80" port="bottom"> </td>
</tr>
</table>
>
];
flopb[
shape=plain
label=<
<table border="1" cellspacing="0" cellborder="0">
<tr>
<td height="80" port="upper"> </td>
</tr>
<tr>
<td height="80" port="middle">FLOPB</td>
</tr>
<tr>
<td height="80" port="bottom"> </td>
</tr>
</table>
>
];
flipa[
shape=plain
label=<
<table border="1" cellspacing="0" cellborder="0">
<tr>
<td height="80" port="upper"> </td>
</tr>
<tr>
<td height="80" port="middle">FLIPA</td>
</tr>
<tr>
<td height="80" port="bottom"> </td>
</tr>
</table>
>
];
flopa[
shape=plain
label=<
<table border="1" cellspacing="0" cellborder="0">
<tr>
<td height="80" port="upper"> </td>
</tr>
<tr>
<td height="80" port="middle">FLOPA</td>
</tr>
<tr>
<td height="80" port="bottom"> </td>
</tr>
</table>
>
];
source1[shape=rarrow];
source2[shape=rarrow];
sink1[shape=rarrow];
sink2[shape=rarrow];
source1 -> flipa;
flipa:upper -> flopa:upper [label="red" color=red,penwidth=3.0];
flipa:bottom -> flopa:bottom [label="blue" color=blue,penwidth=3.0];
flopa -> sink1;
source2 -> flipb;
flipb:upper -> flopb:upper [label="red" color=red,penwidth=3.0];
flipb:bottom -> flopb:bottom [label="blue" color=blue,penwidth=3.0];
flopb -> sink2;
label="Graph";
labelloc=top;
labeljust=left;
}
Result:

Graphviz dot: How to change the colour of one record in multi-record shape

I have the following dot sample. I would like to give the first section in each record (the table name) a different background and foreground colour. I can't find any examples of how to do this for a record. Basically I want the table name in the sql query schema diagram to stand out. Can anyone help?
digraph G {
rankdir=LR;
node [shape=record];
corpus_language [label="corpus_language|<id> id\len\l|<name> name\lEnglist\l|<sentence_count> sentence_count\l1027686\l"];
corpus_sentence [label="corpus_sentence|<id> id\l1241798\l|<text> text\lBaseball is a sport\l|<creator_id> creator_id\l10859\l|<created_on> created_on\l2006-11-14 17:58:09.303128\l|<language_id> language_id\len\l|<activity_id> activity_id\l11\l|<score> score\l124\l"];
corpus_language:id -> corpus_sentence:language_id [arrowhead=normal label=language_id];
}
I'm pretty sure that it's not possible. Instead you should use HTML-style labels, that are a more developped form of record nodes. You can define your node using the <table> tag, and set the color using bgcolor="your_color". A list of available colors is available here: http://www.graphviz.org/doc/info/colors.html (you also have a RGBA way of doing it, as described here: http://www.graphviz.org/doc/info/attrs.html#k:color)
With HTML labels, your example becomes as follows:
digraph G
{
rankdir = LR;
node1
[
shape = none
label = <<table border="0" cellspacing="0">
<tr><td port="port1" border="1" bgcolor="red">corpus_language</td></tr>
<tr><td port="port2" border="1">id: en</td></tr>
<tr><td port="port3" border="1">name: Englist</td></tr>
<tr><td port="port4" border="1">sentence_count: 1027686</td></tr>
</table>>
]
node2
[
shape = none
label = <<table border="0" cellspacing="0">
<tr><td port="port1" border="1" bgcolor="blue">corpus_sentence</td></tr>
<tr><td port="port2" border="1">id: 1241798</td></tr>
<tr><td port="port3" border="1">text: Baseball is a sport</td></tr>
<tr><td port="port4" border="1">creator_id: 10859</td></tr>
<tr><td port="port5" border="1">created_on: 2006-11-14 17:58:09.303128</td></tr>
<tr><td port="port6" border="1">language_id: en</td></tr>
<tr><td port="port7" border="1">activity_id: 11</td></tr>
<tr><td port="port8" border="1">score: 124</td></tr>
</table>>
]
node1:port2 -> node2:port6 [label="language_id"]
}
Here is the result:

Graphviz: How can I make the style of an HTML table cell bold?

I'd expect the following dot code to make the title bold but the <b> tag doesn't seem to be working in this context for some reason.
digraph G {
node [shape=plaintext]
a [label=<<table border="0" cellborder="1" cellspacing="0">
<tr><td><b>title</b></td></tr>
<tr><td>row 1</td></tr>
<tr><td>row 2</td></tr>
</table>>];
}
Any working alternatives?
This exact graph actually does work. You'll most certainly need to update graphviz.
Here's the output with 2.28:

Resources