Is it possible to have graphviz/dot render a node as a circle that is split in the middle horizontally, with a top and bottom text content? Something like a record, but the final shape should be a circle. Currently I'm using Mrecord, but that's only a rounded rectangle, not a circle shape.
I searched for ways to increase the border radius of Mrecord (to make it a quasi-circle) but that did not work. I also tried Mcircle, which is not what I was looking for.
Not directly, but you can create a circle-shaped node, divided in half with the wedged attribute and in the HTML-like label write a HTML <TABLE> without borders which will place text on top of the node.
Script:
digraph {
nodepie [shape = "circle"
style = "wedged"
fillcolor="white;0.5:white"
label=<<TABLE BORDER="0" CELLBORDER="0" CELLSPACING="0">
<TR>
<TD>one</TD>
</TR>
<TR>
<TD>two</TD>
</TR>
</TABLE>>];
}
Result:
Not directly, but you can create an image (svg, png, ...) that looks exactly like you want, using any drawing program, & then include that image in your Graphviz graph.
Related
I am wanting to change the background color of an edge label in Graphviz. At the moment the only way I can see of doing this is using an HTML table.
Eg,
edge [len=3,fontcolor=red];
DeviceA -- DeviceB [headlabel=<
<table border="0" cellborder="0">
<tr>
<td bgcolor="white">Head Label</td>
</tr>
</table>>
,taillabel="Tail Label"];
What I would like to be able to do is something shorter/cleaner:
edge [len=3,fontcolor=red,bgcolour=white];
DeviceA -- DeviceB [headlabel="Head Label",taillabel="Tail Label"];
Is their an option for this in graphviz?
The reason I am trying to do this is because end labels end up written over edges, which makes the label difficult to read, a background color the same color as the canvas, artificially creates a break in the edge.
Thanks
In GraphViz there is no way to change the Background Colour of an Edge Label. However you can achieve the same by using a HTML Table:
Eg:
edge [len=3,fontcolor=red];
DeviceA -- DeviceB [headlabel=<
<table border="0" cellborder="0">
<tr>
<td bgcolor="white">Head Label</td>
</tr>
</table>>
,taillabel="Tail Label"];
I have a very simple graph:
digraph {
node [shape=rect];
rankdir=LR;
A -> B
}
It outputs as I expect:
However, I need to place unique numbers in each corner of both A and B. I am currently only aware of xlabel, but from what I gather can only be used once and cannot be specified in a particular region. So how can I accomplish writing numbers in each corner?
Newest versions of Graphviz support HTML styling of nodes, including tables ("newer than mid-November 2003", that is). So you can make a 3x3 table like this:
Source:
digraph {
node [shape=rect];
rankdir=LR;
A [shape=none label=<
<TABLE BORDER="0" CELLBORDER="0">
<TR><TD>1</TD><TD></TD><TD>2</TD></TR>
<TR><TD COLSPAN="3" BORDER="1">A</TD></TR>
<TR><TD>3</TD><TD></TD><TD>4</TD></TR>
</TABLE>
>];
A -> B
}
Tested with http://sandbox.kidstrythisathome.com/erdos/; it also works with my local installed version (2.38.0).
See Graphviz: Node Shapes for the full set of supported HTML, and examples.
I want to use graphviz for my use-cases, is there an easy way of getting a horizontal line in an ellipse shape?
image for reference:
(source: highscore.de)
if I use
digraph G {
Case [
label = "{Use-Case C | Extension points \l blablabla}"
shape = "record"
]
}
I get a square with the horizontal line, but as soon as I change from record to ellipse the label has the text "{Use-Case C | Extension points \l blablabla}"
Actually, ellipse and record are different types of nodes. Vertical bar in record is used as a horizontal line just by convention. It is impossible to draw it in ellipse like that.
But there is a workaround here.
According to another question about horizontal lines you can try HTML labels while using tables. They won't give you exactly what you want. Still, it is possible to draw label like that:
digraph structs {
node [shape=ellipse]
A [label=<
<TABLE BORDER="0" CELLSPACING="0">
<TR><TD>top</TD></TR>
<HR/>
<TR><TD>bottom</TD></TR>
</TABLE>
>];
B [label="Hello, Graphviz"];
A -> B;
}
Whereas the result looks like:
Ultimately, you may try creating your custom shape
I want to assign multiple color to a node in graphViz. the optimal solution would be a circular node with a pie chart format.
I know one way which is to use HTML tag. the following is a simple example:
graph G{
1--2;
1[shape=none,margin=0,label=<
<table BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">
<tr>
<td bgcolor="red"></td>
<td bgcolor="blue"></td>
</tr>
</table> >];
2[shape=circle,style=filled,fillcolor=yellow];
3[shape=circle,style=filled,fillcolor=yellow];
}
However, there are some problems:
the node 1 has no label (I want it to have label "1" )
the edge connecting the node 1 to node 2 is not completely attached to node 1. In other words, there is a space between node 1 and the edge connecting it to node 2.
node 1 is rectangular. how can I have a circular node?
If there is no way to overcome these problems, would you please suggest any other graph visualization software?
You can achieve this by
graph G{
1--2;
1[shape=circle,style=wedged,fillcolor="red:blue"];
2[shape=circle,style=filled,fillcolor=yellow];
3[shape=circle,style=filled,fillcolor=yellow];
}
The advantage of the approach is that you can use more than 2 colors in a node.
For your 1st problem, it really depends on your implementation for the two-color nodes. You have multiple solutions described in this post: Two colours in one node with graphviz's dot? With your current code, the easiest way to add a label is to write it inside ot the <td></td> tags, like in the following code:
graph G{
1--2;
1[shape=none,margin=0,label=<
<table BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">
<tr>
<td bgcolor="red">1</td>
<td bgcolor="blue"></td>
</tr>
</table> >];
2[shape=circle,style=filled,fillcolor=yellow];
3[shape=circle,style=filled,fillcolor=yellow];
}
However, it won't be centered, and I think a gradient node is preferrable.
For your second problem, you need to declare a port on the cells of your array, and use them to anchor your edges when drawing edges:
graph G{
1[shape=none, label=<
<table MARGIN="0" BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">
<tr>
<td bgcolor="red" port="L">1</td>
<td bgcolor="blue" port="R"></td>
</tr>
</table> >];
2[shape=circle,style=filled,fillcolor=yellow];
3[shape=circle,style=filled,fillcolor=yellow];
1:L--2;
}
For your 3rd problem, according to http://www.graphviz.org/doc/info/shapes.html, you have the possibility to create custom shapes. I don't know any way to create such rounded arrays, so you should look in this direction I think.
I try to find out in Graphviz, how to make a label "1" colored and at the same time a hyperlink. Is this possible? Please see the example below.
F
<graphviz>
digraph vvv
{
rankdir=LR
a2 [href="http://www.apple.com"]
{
a0->a1[href="http://www.uk.com"] [label="1"] [color =red];
a1->a2
}
a2[style=filled,color=yellow]
a0[style=filled,color=lightgrey]
</graphviz>
Yes it's possible.
I'm assuming you are generating SVG output.
If by make a label "1" colored you mean the font color of the label text, it's as simple as specifying it in the edge attributes:
a0->a1[href="http://www.uk.com", fontcolor=yellow, color=red label="1"];
fontcolor refers to the color of the label's text, whereas color is the color of the edge itself.
If you want to have an edge label with a colored background, fillcolor is supposed to work. However, it doesn't (may depend on the version of graphviz). Therefore you may use HTML-like labels and specify the BGCOLOR:
a0->a1[href="http://www.uk.com", fontcolor=red, label=<
<TABLE CELLBORDER="0" CELLPADDING="0" CELLSPACING="0" BORDER="0">
<TR><TD BGCOLOR="yellow">1KMK</TD></TR>
</TABLE>
>, color =red];