Graphviz calculates flexible graphs

Slashdot it! Delicious Share on Facebook Tweet! Digg!

Changing Appearance

You can change the appearance of a node with various attributes, including shape=box . Keep in mind that, with some forms, the text might bleed beyond the boundaries of the box – one of those unsolved problems of automation. You may have to tweak things by hand by resizing the box as needed.

You set the text color with color and the background color with fillcolor . The program allows color names, color values in HTML style (e.g., #F101FF ), and color numbers. The fillcolor only works, however, if you set the style to style=filled . You can find an overview of the color settings online [3].

The software normally determines the height and width of a node automatically, but you can set minimum height and width values.

If you set the fixedsize=true attribute for a node, the program interprets both values as set and doesn't exceed them. The entry is in inches. (An inch consists of 72 points – a measurement used in typography.)

The style attribute allows you to set the node's appearance (the type of frame). Graphviz knows filled, rounded-corner, dotted, dashed, bold, and other forms (Figure 3). With the peripheries=2 attribute, the software draws a double line; with style=invis , you can hide the node.

Figure 3: With the "style" attribute, you can change a node's appearance.

You set the text font for a label with the fontname attribute and the text size with fontsize . The fontpath defines the path to the font directory. Alternatively, you can use the environmental variables DOTFONTPATH or GDFONTPATH .

You label a node with its name or with the label attribute. You can also use the labelloc attribute, whereby the renderer positions the text. The value t sets the text at the top, and b sets it at the bottom. A labeljust value of r sets the text right-justified, and l makes it left-justified. By default, Graphviz centers the text.

Changing Edges

What works for text and boxes also works for lines: The style attribute also determines their appearance. As with node lines, you can make them solid, bold, dashed, dotted, or invisible (Figure 4). You can use the same values for line colors as for nodes. Line endings can have various styles. You can use the arrowhead attribute to set the tip, arrowtail to set the tail of the arrow, and arrowsize to change the size of the tip.

Figure 4: As with boxes, you can modify lines as desired.

The dir attribute sets the arrow direction, with both for both ends, forward for one direction, and back for the opposite direction. You would use none for a line without arrows. You'll find a comprehensive overview of arrow styles online [4]. With the attributes headclip=false and tailclip=false , you can set the line not to run to the edge of the node but to the middle. By default, the software creates a connection point at the edge of the node. To combine connecting lines, use the sametail or samehead attribute, depending on which end (see the sametail=groupB example in Figure 5).

Figure 5: You can combine connecting lines for a better appearance.

Graphviz provides three ways to label a connecting line. The label attribute puts the text in the middle of the line; headlabel puts it above the line. Placing a label at the top or bottom sometimes causes the text to come too close to the line or node. Here the labelangle and labeldistance attributes will help.

You can use all three types of line labels simultaneously. The decorate=true attribute underlines the text, and the labelfloat=true attribute allows overlapping labels, which can make the graph more compact.

Additionally, you can edit the text with the labelfontcolor , labelfontname , and labelfontsize attributes. The labelangle and labeldistance attributes determine where the text should be placed. Polar coordinates are used in this case. labelangle sets the angle in degrees, and labeldistance sets the distance from the node.

Buy this article as PDF

Express-Checkout as PDF

Pages: 5

Price $0.99
(incl. VAT)

Buy Ubuntu User

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content