Dia straights (and curves and network diagrams)

268
Are you designing a new program and need to put a process into a flowchart? Do you need an entity relationship diagram for a database?
Do you need to document the management structure for a new department?
If so, try Dia, a useful and usable open source diagramming application available for both Linux and Windows.

If you’re familiar with Microsoft Visio then you will understand Dia’s general concept, though Dia is not a Visio clone.

To try Dia, download the appropriate source or binary and follow the
installation instructions. Within a few minutes you should be able to
run the application.

The main window and the workspace

Dia presents two windows — a main window on the left, and a workspace area on the right.

The main window holds the program’s controls. From here you can open
a new or existing diagram, save one that you have edited, print, or
view help documentation. The help is rather limited, but since Dia is
easy to use this is not a problem.

Below the menu is a section which gives you a set of simple shapes
and lines, and below that is perhaps the most useful part of the main
window: a drop-down box allowing you access to the different groups (or
sheets) of diagram objects. The default is Assorted, but you can scroll
down to select the the one that you require. For instance, if you are
designing a database, you may wish to select ER, which displays entity
relationship diagram shapes.

The next section of the screen gives you the ability to change the
colours of shapes. You can also change the thickness of the lines used
to draw shapes and lines. By default, lines are set to be fairly thick.

Figure 1: The Dia Screens – click to enlarge

At the bottom of the main screen you can change the shape of a line start, the shape of its end, and the style of a line.

On the right of the screen, the workspace comprises a menu bar, and
below it an area for drawing the diagram. By default Dia opens an A4
sheet to work with (although you can change this by using Preferences
from the File menu on the Main window). You create diagrams by adding
objects (shapes and lines) from the main window.

Building a diagram

To begin building a diagram, add an object by clicking on it in the
main window, and then clicking on the workspace at the point where you
want the object to be displayed. Once you have a couple of shape
objects in the workspace, add a line; click on the line in the main
window and then click on the workspace. A line has a green square at
each end — these are its connection points, used to fix the line to
other objects.

The connection point feature is particularly useful. Select one end
of a line by clicking on it and holding down the left mouse button,
then drag the line end to one of the connection points on one of the
other objects (denoted by a blue cross). The object will be highlighted
in red when the connection points are aligned. When you let go of the
mouse button the object and line become joined together.

Once you link two of shapes using a line, Dia maintains the
connections wherever you move any of the objects. In other words,
moving shapes will not break any connections — the lines just redraw
themselves. This becomes useful as the diagram increases in complexity.
It means that you can rearrange objects (perhaps to improve clarity or
to emphasize a particular aspect) without worrying about having to
reconnect elements.

Customizing Dia

Dia’s bundled components are suitable for most diagrams, but if you do need a new shape, it’s easy to create your own.

More ways to diagram
Dia is not the only open source diagram drawing package. XFig
is comparable to Dia, and like Dia it is available for both Windows and
Linux. It also provides some additional output formats. KDE lovers
should have a look at Karbon14.

First, add a new diagram object group or sheet. Move to the sheet
directory (typically it is /etc/dia/sheets, but you can use the shell
command find / -name "*.sheet" to locate the folder). To
create the sheet file, either copy one of the existing files (e.g.
flowchart.sheet) or create a new one and add your own details in XML
format. For example, the file MAB.Sheet could contain:

<?xml version="1.0" encoding="UTF-8"?>
<sheet xmlns="http://www.lysator.liu.se/~alla/dia/dia-she   et-ns">
<name>Mark's Objects</name>
<description>Objects for Dr. Mark Alexander Bain</description>
<contents>
<object name="MAB -- Document">
<description>Mark's Document</description>
</object>
</contents>
</sheet>

The name parameter contains the information that will appear in the drop-down list on the main window. The contents list the objects
to be displayed in the pane. The objects contained in the contents can
be either existing ones from other lists (so that you can create your
own grouping) or new objects.

Create a new subdirectory under the Dia directory called shapes.
Store any new shapes in this folder. (The directories do not affect the
operation of Dia, but do make for easier file management.) For
instance, the file dia/shapes/MAB/mab_document.sheet could contain:

Figure 2: Example diagram with a custom object – click to enlarge

<shape xmlns="http://www.daa.com.au/~james/dia-shape-ns" xmlns:svg="http://www.w3.org/2000/svg">
<name>MAB -- Document</name>
<description>Document</description>
<icon>mab_document.png</icon>
<connections>
<point x="0" y="0"/>
<point x="0" y="5"/>
<point x="10" y="0"/>
<point x="10" y="5"/>
<point x="10" y="2.5"/>
<point x="0" y="2.5"/>
<point x="5" y="5"/>
<point x="5" y="2.5"/>
</connections>
<textbox x1="0" y1="0" x2="10" y2="5"/>
<svg:svg width="10" height="5">
<svg:path d="m0,0 h1 l4,3 l4,-3 h1 v5 h-10 z"
style="fill: default"/>
</svg:svg>
</shape>

Like the sheets file, the shapes file is written in XML and contains certain key elements. The icon
parameter stores a reference to be image to be displayed in the main
window. It should be stored in the same directory as the shape file.
Another important element is connections, which is used
to store the coordinates of each connection point for the object
(x=0,y=0 is the top right of the shape). Finally, the shape of the
object is defined in Scalable Vector Graphics (SVG), and uses the path parameter to define the outline of the shape. The example above means:

  • m0,0 — move to (0,0) — the top left corner of the shape
  • h1 — draw a horizontal line from the current point to one which is 1 unit right (default unit is 1px)
  • l4,3 — draw a line from the current point to another right 4 and down 3
  • l4,-3 — draw a line from the current point to another right 4 and up 3
  • v5 — draw a vertical line from the current point to another 5 down
  • h-10 — draw a horizontal line left 10
  • z — draw a line back to the starting point

You can see the finished diagram in figure 2.

Dia doesn’t pretend to be anything that it’s not — it’s just there to help you to put together clear and professional diagrams. There are plans for the application to put its files into the OpenOffice.org XML file format. However, even without that, Dia’s stability and its ease of use make it worth looking at. The vast array of diagram types available make it useful enough for anyone, and the fact that you can extend it easily make it a powerful desktop tool.