Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example command to render graph as PNG #137

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions docs/visualization.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
It can be very helpful to visualize your state machine as a directed graph. This is possible
with the open source [GraphViz](http://www.graphviz.org/) library if we convert from our
state machine configuration to the `.dot` language expected by GraphViz using the
`visualize` method:
`visualize` method.

A `main.js` file defining the following FSM:

```javascript
var visualize = require('javascript-state-machine/lib/visualize');
Expand All @@ -16,7 +18,7 @@ state machine configuration to the `.dot` language expected by GraphViz using th
]
});

visualize(fsm)
console.log(visualize(fsm));
```

Generates the following .dot syntax:
Expand All @@ -32,6 +34,10 @@ Generates the following .dot syntax:

Which GraphViz displays as:

```bash
node main.js | dot -Tpng -o graph.png && open graph.png
```

![door](../examples/vertical_door.png)

## Enhanced Visualization
Expand All @@ -47,7 +53,7 @@ You can customize the generated `.dot` output - and hence the graphviz visualiza
{ name: 'close', from: 'open', to: 'closed', dot: { color: 'red', headport: 's', tailport: 's' } }
]
});
visualize(fsm, { name: 'door', orientation: 'horizontal' });
console.log(visualize(fsm, { name: 'door', orientation: 'horizontal' }));
```

Generates the following (enhanced) `.dot` syntax:
Expand Down Expand Up @@ -81,7 +87,7 @@ You can use the same `visualize` method to generate `.dot` output for a state ma
]
});

visualize(Matter, { name: 'matter', orientation: 'horizontal' })
console.log(visualize(Matter, { name: 'matter', orientation: 'horizontal' }));
```

Generates the following .dot syntax:
Expand Down Expand Up @@ -116,7 +122,7 @@ Which GraphViz displays as:
]
});

visualize(Wizard, { orientation: 'horizontal' })
console.log(visualize(Wizard, { orientation: 'horizontal' }));
```

Generates:
Expand Down Expand Up @@ -167,7 +173,7 @@ Displays:
]
})

visualize(ATM)
console.log(visualize(ATM));
```

Generates:
Expand Down