How to make left aligned italic labels - graphviz

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)

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 find the root node on the basis of text of two attributes

I have a dynamic web table and I want to select the node on the basis of text value of two different text attributes.
//tr[.//td[contains(text(),'SATWIK GHANSIYAL')] and .//td[contains(text(),'07/07/2002')]]
HTML:
<html><head></head><body><table>
<tbody><tr style="background-color:White;height:24px;">
<td class="gridtext" align="center">
<span class="checkboxclass"><input id="ctl00_ContentPlaceHolder1_grdUsers_ctl02_chkSelect" type="checkbox" name="ctl00$ContentPlaceHolder1$grdUsers$ctl02$chkSelect" onclick="javascript:setTimeout('__doPostBack(\'ctl00$ContentPlaceHolder1$grdUsers$ctl02$chkSelect\',\'\')',
0)"></span>
</td><td class="gridtext" align="left" style="background-color:#FDE9D9;">SATWIK GHANSIYAL</td>
<td class="gridtext" align="left" style="background-color:#FDE9D9;" xpath="1">RAJESH GHANSIYAL</td>
<td class="gridtext" align="left" style="background-color:#FDE9D9;">SHELLY</td>
<td class="gridtext" align="left" style="background-color:#FDE9D9;">07/07/2002</td>
</tr>
</tbody></table>
</body></html>
I am getting the massage no element found
use this.
//tr[.//td[contains(.,'SATWIK GHANSIYAL')] and .//td[contains(.,'07/07/2002')]]
trying to evaluate this expression based on the given xml
//tr[.//td[contains(text(),'SATWIK GHANSIYAL')] and .//td[contains(text(),'07/07/2002')]]
text() is returning multiple sequence, thus giving me this error message.
Unable to perform XPath operation. A sequence of more than one item is not allowed as the first argument of contains() ("", "")

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:

give each wedge a different label in style=wedged in DOT 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:

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