Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
bonndan authored and Padam87 committed Jan 7, 2015
1 parent a1c7cd3 commit 665f575
Show file tree
Hide file tree
Showing 10 changed files with 729 additions and 284 deletions.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,40 @@ $sm->can('t34');

```


### Rendering State Machines as Graphs

You can render a state machine using Graphviz (see examples/rendered-graph.png).

To obtain the source code of a directed graph in dot simply initialize the graphviz renderer:

```php
use Finite\StateMachine\StateMachine;
use Finite\Visualisation\Graphviz;
use Finite\State\StateInterface;

$stateMachine = new StateMachine();
$renderer = new Graphviz();
$dotSource = $renderer->render($stateMachine);

```

To change how nodes are rendered, pass a configuration. The configuration accepts two parameters which control the generated output:

* An optional flag controlling whether the state properties shall be rendered within the label.
* The optional fill color (a dot color name or e.g. hex code) of init and end states.

```php
use Finite\StateMachine\StateMachine;
use Finite\Visualisation\Configuration;
use Finite\Visualisation\Graphviz;
use Finite\State\StateInterface;

$stateMachine = new StateMachine();
$config = new Configuration(true, 'red');
$renderer = new Graphviz($config);
$dotSource = $renderer->render($stateMachine);

```


5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
],
"require": {
"php": ">=5.3.3",
"symfony/options-resolver": "~2.1",
"symfony/options-resolver": "~2.1,<2.6",
"symfony/event-dispatcher": "~2.1",
"symfony/property-access": "~2.3"
},
Expand All @@ -28,7 +28,8 @@
"symfony/dependency-injection": "~2.1",
"symfony/framework-bundle": "~2.1",
"symfony/security": "~2.1",
"twig/twig": "~1.13"
"twig/twig": "~1.13",
"alom/graphviz": "v1.0.0"
},
"suggest": {
"pimple/pimple": "Needed for use with PimpleFactory",
Expand Down
Loading

0 comments on commit 665f575

Please sign in to comment.