How to Draw State Machine Diagrams in Dia

Dia Diagram Editor is a free, open-source project by the GNOME community. This site is an independent community resource — we are not affiliated with the GNOME Dia project.

State machine diagrams (UML statecharts) show how an object behaves: which states it can be in, and which events move it between them. Embedded developers, game programmers, and anyone modeling order-processing or device firmware will use these constantly. Dia’s UML sheet has every object you need, and this guide — part of our UML in Dia series — builds a traffic-light controller as the example.

The objects you’ll use

Dia UML objectLooks likeMeaning
Initial/End stateFilled circle / bullseyeWhere the lifecycle starts and ends
StateRounded rectangleA condition the object can be in (“Red”, “Green”)
TransitionArrow between statesAn event that moves the object to another state

Enable the UML sheet via File → Sheets and Objects if you don’t see these.

Step-by-step: traffic light controller

1. Place the initial state

Drag the Initial/End state object onto the canvas — the small filled circle marks where the controller starts when powered on.

2. Add the states

Drag three State rounded rectangles and label them Red, Green, Yellow. Double-click a state to edit its name. Arrange them left to right in cycle order.

3. Draw the transitions

Use Transition arrows: Initial → Red, Red → Green, Green → Yellow, Yellow → Red. Label each arrow with its trigger using the standard event[guard]/action format, e.g. timer_expired[30s]/switch_lights. Connection points turn red when the arrow is properly attached.

4. Add the end state (if any)

A traffic light never terminates, so there’s no end state here — that’s fine and normal. For something like an order (“Pending → Shipped → Delivered”), you’d end with the bullseye End state.

5. Composite states for complex behavior

When a state has its own sub-behavior (e.g. “Green” contains “Flashing Green” for pedestrian crossings), draw a larger State box around the sub-states. Dia doesn’t enforce nesting semantics — the grouping is visual — so add a note explaining the hierarchy.

Tip: Every transition needs a label. An unlabeled arrow in a state diagram is a bug report waiting to happen — the reader can’t tell what triggers the change.

Real-world patterns

  • Order processing: Pending → Paid → Shipped → Delivered, with a Cancelled end state reachable from Pending/Paid.
  • Device firmware: Boot → Idle → Measuring → Transmitting → Sleep, with timeout transitions back to Sleep.
  • Game AI: Patrol → Chase → Attack → Flee, driven by distance/visibility events.

FAQ

Can Dia validate my state machine?

No — Dia is a drawing tool, not a modeling tool. It won’t check that every state is reachable or that transitions are complete. Review the logic yourself (or pair the diagram with a truth table).

How do I show guards and actions on transitions?

Double-click the transition arrow and type the label in event[guard]/action form, e.g. coin_inserted[amount >= price]/dispense.

What’s the difference between state and activity diagrams?

State diagrams show an object’s lifecycle (states + events). Activity diagrams show a workflow’s steps. Same system, different viewpoint.

Can I generate code from a Dia state diagram?

Not directly — Dia has no code generator for statecharts. Some developers redraw the logic in tools like PlantUML or state-machine libraries once the design is settled in Dia.

How do I export for documentation?

File → Export to SVG for wikis or PDF for specs. See our export guide.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *