Node Shapes (original) (raw)
There are three main types of shapes :polygon-based,record-based anduser-defined.
The record-based shape has largely been superseded and greatly generalized by HTML-like labels. That is, instead of using shape=record
, one might consider using shape=none
, margin=0
and an HTML-like label.
The geometry and style of all node shapes are affected by the node attributesfixedsize,fontname,fontsize,height,label,style andwidth.
Polygon-based Nodes
The possible polygon-based shapes are displayed below.
box
polygon
ellipse
oval
circle
point
egg
triangle
plaintext
plain
diamond
trapezium
parallelogram
house
pentagon
hexagon
septagon
octagon
doublecircle
doubleoctagon
tripleoctagon
invtriangle
invtrapezium
invhouse
Mdiamond
Msquare
Mcircle
rect
rectangle
square
star
none
underline
cylinder
note
tab
folder
box3d
component
promoter
cds
terminator
utr
primersite
restrictionsite
fivepoverhang
threepoverhang
noverhang
assembly
signature
insulator
ribosite
rnastab
proteasesite
proteinstab
rpromoter
rarrow
larrow
lpromoter
As the figures suggest, the shapes rect
and rectangle
are synonyms for box
, and none
is a synonym for plaintext
. The shape plain
is similar to these two, except that it also enforceswidth=0 height=0 margin=0
, which guarantees that the actual size of the node is entirely determined by the label. This is useful, for example, when using HTML-like labels. Also, unlike the rest, we have shown these three, as well as underline
, without style=filled
to indicate the normal use. If fill were turned on, the label text would appear in a filled rectangle.
The geometries of polygon-based shapes are also affected by the node attributesregular,peripheries andorientation. If shape="polygon"
, the attributessides,skew anddistortion are also used. If unset, they default to 4, 0.0 and 0.0, respectively. The point shape is special in that it is only affected by the peripheries,width andheight attributes.
Normally, the size of a node is determined by smallest width and height needed to contain its label and image, if any, with a margin specified by the margin attribute. The width and height must also be at least as large as the sizes specified by thewidth andheight attributes, which specify the minimum values for these parameters. See the fixedsize attribute for ways of restricting the node size. In particular, if fixedsize=shape
, the node's shape will be fixed by the width andheight attributes, and the shape is used for edge termination, but both the shape and label sizes are used preventing node overlap. For example, the following graph:
digraph G {
{
node [margin=0 fontcolor=blue fontsize=32 width=0.5 shape=circle style=filled]
b [fillcolor=yellow fixedsize=true label="a very long label"]
d [fixedsize=shape label="an even longer label"]
}
a -> {c d}
b -> {c d}
}
yields the figure:
Note that the label of the yellow node, with fixedsize=true
, overlaps the other node, where there is sufficient space for the gray node withfixedsize=shape
.
The shapes: note
, tab
, folder
,box3d
and component
were provided by Pander. The synthetic biology shapes:promoter
,cds
,terminator
,utr
,primersite
,restrictionsite
,fivepoverhang
,threepoverhang
,noverhang
,assembly
,signature
,insulator
,ribosite
,rnastab
,proteasesite
,proteinstab
,rpromoter
,rarrow
,larrow
andlpromoter
were contributed by Jenny Cheng.
Record-based Nodes
NOTE: Please see the note about record-based nodes. Also note that there are problems using non-trivial edges (edges with ports or labels) between adjacent nodes on the same rank if one or both nodes has a record shape.
These are specified by shape values of "record" and "Mrecord". The structure of a record-based node is determined by its label, which has the following schema:
rlabel | = | field ( '|' field )* |
---|---|---|
where field | = | fieldId or '{' rlabel '}' |
and fieldId | = | [ '<' _string_ '>'] [ string ] |
Braces, vertical bars and angle brackets must be escaped with a backslash character if you wish them to appear as a literal character. Spaces are interpreted as separators between tokens, so they must be escaped if you want spaces in the text.
The first string in fieldId assigns a portname to the field and can be combined with the node name to indicate where to attach an edge to the node. (See portPos.) The second string is used as the text for the field; it supports the usualescape sequences \n
, \l
and \r
.
Visually, a record is a box, with fields represented by alternating rows of horizontal or vertical subboxes. The Mrecord shape is identical to a record shape, except that the outermost box has rounded corners. Flipping between horizontal and vertical layouts is done by nesting fields in braces "{...}". The top-level orientation in a record is horizontal. Thus, a record with label "A | B | C | D" will have 4 fields oriented left to right, while "{A | B | C | D}" will have them from top to bottom and "A | { B | C } | D" will have "B" over "C", with "A" to the left and "D" to the right of "B" and "C".
The initial orientation of a record node depends on therankdir attribute. If this attribute is TB
(the default) or BT
, corresponding to vertical layouts, the top-level fields in a record are displayed horizontally. If, however, this attribute is LR
or RL
, corresponding to horizontal layouts, the top-level fields are displayed vertically.
As an example of a record node, the dot input:
digraph structs {
node [shape=record];
struct1 [label="<f0> left|<f1> mid\ dle|<f2> right"];
struct2 [label="<f0> one|<f1> two"];
struct3 [label="hello\nworld |{ b |{c|<here> d|e}| f}| g | h"];
struct1:f1 -> struct2:f0;
struct1:f2 -> struct3:here;
}
yields the figure:
If we add the line:
rankdir=LR
we get the layout:
If we change node struct1
to have shape Mrecord
, it then looks like:
Styles for Nodes
The styleattribute can be used to modify the appearance of a node. At present, there are 8 style values recognized:filled
, invisible
, diagonals
, rounded
.dashed
, dotted
, solid
and bold
. As usual, the value of the styleattribute can be a comma-separated list of any of these. If the style contains conflicts (e.g, style="dotted, solid"
), the last attribute wins.
filled
This value indicates that the node's interior should be filled. The color used is the node's fillcolor
or, if that's not defined, itscolor
. For unfilled nodes, the interior of the node is transparent to whatever color is the current graph or cluster background color. Note that point
shapes are always filled.
Thus, the code:
digraph G {
rankdir=LR
node [shape=box, color=blue]
node1 [style=filled]
node2 [style=filled, fillcolor=red]
node0 -> node1 -> node2
}
yields the figure:
invisible
Setting this style causes the node not to be displayed at all. Note that the node is still used in laying out the graph.
diagonals
The diagonals style causes small chords to be drawn near the vertices of the node's polygon or, in case of circles and ellipses, two chords near the top and the bottom of the shape. The special node shapesMsquare,Mcircle, andMdiamondare simply an ordinary square, circle and diamond with the diagonals style set.
rounded
The rounded style causes the polygonal corners to be smoothed. Note that this style also applies to record-based nodes. Indeed, the Mrecord
shape is simply shorthand for setting this style. Also, prior to 26 April 2005, the rounded and filled styles were mutually exclusive.
As an example of rounding, dot uses the graph:
digraph R {
rankdir=LR
node [style=rounded]
node1 [shape=box]
node2 [fillcolor=yellow, style="rounded,filled", shape=diamond]
node3 [shape=record, label="{ a | b | c }"]
node1 -> node2 -> node3
}
to produce the figure:
dashed
This style causes the node's border to be drawn as a dashed line.
dotted
This style causes the node's border to be drawn as a dotted line.
solid
This style causes the node's border to be drawn as a solid line, which is the default.
bold
This style causes the node's border to be drawn as a bold line. See also penwidth.
Additional styles may be available with a specific code generator.
HTML-Like Labels
NOTE: This feature is only available on versions of Graphviz that are newer than mid-November 2003. In particular, it is not part of release 1.10.
NOTE: The font markups for bold, italic, underlining, subscript and superscript (, , , and ) are only available in versions after 14 October 2011, and the markup for strike-through () requires versions later than 15 September 2013. In addition, all of these markups are currently only available via the cairo and svg renderers. The horizontal and vertical rules (
and ) are only available in versions later than 8 July 2011.
NOTE: For releases later than 9 September 2014, one can use shape=plain
so that the size of the node is totally determined by the label. Otherwise, the node's margin, width and height values may cause the node to be larger, so that edges are clipped away from the label. In effect, shape=plain
is shorthand for shape=none width=0 height=0 margin=0
.
If the value of a label attribute (label for nodes, edges, clusters, and graphs, and theheadlabel andtaillabelattributes of an edge) is given as anHTML string, that is, delimited by <...>
rather than "..."
, the label is interpreted as an HTML description. At their simplest, such labels can describe multiple lines of variously aligned text as provided by ordinarystring labels. More generally, the label can specify a table similar to those provided by HTML, with different graphical attributes at each level.
As HTML strings are processed like HTML input, any use of the "
, &
, <
, and >
characters in literal text or in attribute values need to be replaced by the corresponding escape sequence. For example, if you want to use &
in an href
value, this should be represented as &
.
NOTE: The features and syntax supported by these labels are modeled on HTML. However, there are many aspects that are relevant to Graphviz labels that are not in HTML and, conversely, HTML allows various constructs which are meaningless in Graphviz. We will generally refer to these labels as "HTML labels" rather than the cumbersome "HTML-like labels" but the reader is warned that these are not really HTML. The grammar below describes precisely what Graphviz will accept.
Although HTML labels are not, strictly speaking, a shape, they can be viewed as a generalization of the record shapes described above. In particular, if a node has set itsshapeattribute to none
or plaintext
, the HTML label will be the node's shape. On the other hand, if the node has any other shape (exceptpoint
), the HTML label will be embedded within the node the same way an ordinary label would be. Adding HTML labels to record-based shapes (record and Mrecord) is discouraged and may lead to unexpected behavior because of their conflicting label schemas and overlapping functionality.
The following is an abstract grammar for HTML labels. Terminals, corresponding to elements, are shown in bold font, and nonterminals in italics. Square brackets [
and ]
enclose optional items. Vertical bars |
separate alternatives. Note that, as in HTML, element and attribute names are case-insensitive. (cf. sections 3.2.1 and 3.2.2 of theHTML 4.01 specification).
label | : | text |
---|---|---|
| | fonttable | |
text | : | textitem |
| | text textitem | |
textitem | : | string |
| | ||
| | text | |
| | text | |
| | text | |
| | text | |
| | text | |
| | text | |
| | text | |
| | ||
fonttable | : | table |
| | table | |
| | table | |
| | table | |
| | table | |
| | table | |
table | : |
row
All non-printing characters such as tabs or newlines are ignored. Above, a string is any collection of printable characters, including spaces. For tables, outside of the body of a
< <U><TABLE><TR><TD>a</TD></TR></TABLE></U>>
is not legal. Removing either the space or the <U>...</U>
will fix this.
HTML comments are allowed within an HTML string. They can occur anywhere provided that, if they contain part of an HTML element, they must contain the entire element.
As is obvious from the above description, the interpretation of white space characters is one place where HTML-like labels is very different from standard HTML. In HTML, any sequence of white space characters is collapsed to a single space, If the user does not want this to happen, the input must use non-breaking spaces
. This makes sense in HTML, where text layout depends dynamically on the space available. In Graphviz, the layout is statically determined by the input, so it is reasonable to treat ordinary space characters as non-breaking. In addition, ignoring tabs and newlines allows the input text to be formatted for easier reading.
Each of the HTML elements has a set of optional attributes. Attribute values must appear in double quotes.
Table element
Font specification <FONT COLOR="color" FACE="fontname" POINT-SIZE="value" Line break <BR ALIGN="CENTER|LEFT|RIGHT" /> Image inclusion <IMG SCALE="FALSE|TRUE|WIDTH|HEIGHT|BOTH" SRC="_value_" /> Italic style <I Bold style <B Underline text <U Overline text <O Subscript text <SUB Superscript text <SUP Strike-through text <S Horizontal rule /> Vertical rule <VR /> ALIGN specifies horizontal placement. When an object is allocated more space than required, this value determines where the extra space is placed left and right of the object.
The contents of a cell are normally aligned as a block. In particular, lines of text are first aligned as a text block based on the width of the widest line and the corresponding BALIGN specifies the default alignment of BGCOLOR="color" sets the color of the background. This color can be overridden by a BGCOLOR attribute in descendents. The value can be a single color or two colors separated by a colon, the latter indicating a gradient fill. BORDER="value" specifies the width of the border around the object in points. A value of zero indicates no border. The default is 1. The maximum value is 255. If set in a table, and CELLBORDER is not set, this value is also used for all cells in the table. It can be overridden by a BORDER attribute in a cell. CELLBORDER="value" specifies the width of the border for all cells in a table. It can be overridden by a BORDER tag in a cell. The maximum value is 127. CELLPADDING="value" specifies the space, in points, between a cell's border and its content. The default is 2. The maximum value is 255. CELLSPACING="value" specifies the space, in points, between cells in a table and between a cell and the table's border. The default is 2. The maximum value is 127. COLOR="color" sets the color of the font within the scope of..., or the border color of the table or cell within the scope of | ... | . This color can be overridden by a COLOR attribute in descendents. By default, the font color is determined by thefontcolor attribute of the corresponding node, edge or graph, and the border color is determined by thecolor attribute of the corresponding node, edge or graph.