Skip to content

[Workflow] Made GraphvizDumper supports StateMachine #20497

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

Closed
wants to merge 1 commit into from

Conversation

HeahDude
Copy link
Contributor

Q A
Branch? master
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets ~
License MIT
Doc PR ~

Before:
dump

After:
dump4

@@ -126,21 +126,20 @@ private function addTransitions(array $transitions)
private function findEdges(Definition $definition)
{
$dotEdges = array();
$foundEdge = function ($from, $to, $direction) use (&$dotEdges) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$foundEdge is not really a good name for what the function is doing imo.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$addEdge?

@xabbuh
Copy link
Member

xabbuh commented Nov 12, 2016

Can we add a test to prevent regressions?

@stof
Copy link
Member

stof commented Nov 12, 2016

This indeed needs tests to be accepted

Status: needs work

@HeahDude
Copy link
Contributor Author

Fixed now, the problem came from the way transitions are configured for state machines.

Status: needs review

@HeahDude HeahDude changed the title [Workflow] Fixed duplicated edges in GraphvizDumper [Workflow] Made GraphvizDumper supports StateMachine Nov 14, 2016
@@ -84,7 +84,7 @@ private function findTransitions(Definition $definition)
$transitions = array();

foreach ($definition->getTransitions() as $transition) {
$transitions[] = array(
$transitions[$transition->getName()] = array(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks wrong to me. Transition names are not unique in the definition (the only requirement is that transition starting from a given node have unique names)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stof This is what this key is about, removing duplicated transition names, since they generate useless code in the dot file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If they have the same name, they have different from/to, so they should both be rendered on the graph separately (otherwise, the graph will lie).

Btw, for a finite state machine, we could change the graph to render transitions as edges directly (optionally, as rendering the graph in workflow mode is still useful), as they are known to have a single from and a single to

Copy link
Contributor Author

@HeahDude HeahDude Nov 14, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If they have the same name, they have different from/to, so they should both be rendered on the graph separately (otherwise, the graph will lie).

That not true for the way state machines have been implemented. It splits the transition that has many tos in many transitions with the same name.

See https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php#L416.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HeahDude But this class is also able to dump Workflow graph.

'to' => $transition->getName(),
'direction' => 'from',
);
$getEdge($from, $transition->getName(), 'from');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getEdge is a weird name, as it does not get anything. It adds something

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok l'll change it to addName, it seems you all agree with that :)

@@ -126,21 +126,20 @@ private function addTransitions(array $transitions)
private function findEdges(Definition $definition)
{
$dotEdges = array();
$getEdge = function ($from, $to, $direction) use (&$dotEdges) {
$dotEdges[$from.$to.$direction] = array(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind of "hash" could collide.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They should, this is the point of it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the thing is that your dumping of the StateMachine graph does not represent the workflow being defined by the state machine, as you represent a single transition with multiple input and output instead of several transitions (the fact that the DI config of the StateMachine allows to define these transitions in a shorted way by grouping them does not mean they are the same transition in the StateMachine)
Your dumping is lying about the actual workflow being run.
The bug in the GraphvizDumper currently is that it uses transition names to identify them in the dot file, while they are not unique identifiers anymore (they were at the time the dumper was written).

Btw, this is why I said we should have another dumper being tailored only at state machines, and dumping them into a graph being more readable. This graph would represent transitions as edges on the graph (which is not possible in generic workflows, as transitions can have multiple input and output). But I would make this another dumper, or an option in this dumper, because dumping the StateMachine as a generic workflow graph can be useful too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright! Thank you again for your explanation, I'll work on that soon!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, this is why I said we should have another dumper being tailored only at state machines, and dumping them into a graph being more readable

👍

@lyrixx
Copy link
Member

lyrixx commented Nov 21, 2016

@HeahDude I took care of this in #20583

@HeahDude
Copy link
Contributor Author

Awesome thanks! Closing then.

@HeahDude HeahDude closed this Nov 21, 2016
fabpot added a commit that referenced this pull request Nov 24, 2016
This PR was merged into the 3.3-dev branch.

Discussion
----------

[Workflow] Fixed graphviz dumper for state machine

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #20497
| License       | MIT
| Doc PR        | ~

---

Before:
![before](https://cloud.githubusercontent.com/assets/408368/20490801/77cc0abe-b00f-11e6-8094-f4d428d5acde.png)
After:
![after](https://cloud.githubusercontent.com/assets/408368/20490809/7d21a4b0-b00f-11e6-8de2-c5021fe2d4e0.png)

---

Script:
```php
<?php

require __DIR__.'/vendor/autoload.php';

use Symfony\Component\Workflow\Definition;
use Symfony\Component\Workflow\Dumper\StateMachineGraphvizDumper;
use Symfony\Component\Workflow\Marking;
use Symfony\Component\Workflow\StateMachine;
use Symfony\Component\Workflow\Transition;

$places = array('a', 'b', 'c', 'd');
$transitions[] = new Transition('t1', 'a', 'b');
$transitions[] = new Transition('t1', 'd', 'b');
$transitions[] = new Transition('t2', 'b', 'c');
$transitions[] = new Transition('t3', 'b', 'd');
$definition = new Definition($places, $transitions);

$marking = new Marking(['d' => 1]);

echo (new StateMachineGraphvizDumper())->dump($definition, $marking);
```

Commits
-------

1e92e02 [Workflow] Fixed graphviz dumper for state machine
fabpot added a commit that referenced this pull request Nov 24, 2016
This PR was submitted for the master branch but it was merged into the 3.2 branch instead (closes #20583).

Discussion
----------

[Workflow] Fixed graphviz dumper for state machine

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #20497
| License       | MIT
| Doc PR        | ~

---

Before:
![before](https://cloud.githubusercontent.com/assets/408368/20490801/77cc0abe-b00f-11e6-8094-f4d428d5acde.png)
After:
![after](https://cloud.githubusercontent.com/assets/408368/20490809/7d21a4b0-b00f-11e6-8de2-c5021fe2d4e0.png)

---

Script:
```php
<?php

require __DIR__.'/vendor/autoload.php';

use Symfony\Component\Workflow\Definition;
use Symfony\Component\Workflow\Dumper\StateMachineGraphvizDumper;
use Symfony\Component\Workflow\Marking;
use Symfony\Component\Workflow\StateMachine;
use Symfony\Component\Workflow\Transition;

$places = array('a', 'b', 'c', 'd');
$transitions[] = new Transition('t1', 'a', 'b');
$transitions[] = new Transition('t1', 'd', 'b');
$transitions[] = new Transition('t2', 'b', 'c');
$transitions[] = new Transition('t3', 'b', 'd');
$definition = new Definition($places, $transitions);

$marking = new Marking(['d' => 1]);

echo (new StateMachineGraphvizDumper())->dump($definition, $marking);
```

Commits
-------

330c069 [Workflow] Fixed graphviz dumper for state machine
@HeahDude HeahDude deleted the fix-workflow-dump branch November 26, 2016 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants