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

Generating a Graphviz dot file from WorkflowDefinition #83

Open
tatupesonen opened this issue Aug 7, 2023 · 0 comments
Open

Generating a Graphviz dot file from WorkflowDefinition #83

tatupesonen opened this issue Aug 7, 2023 · 0 comments

Comments

@tatupesonen
Copy link

tatupesonen commented Aug 7, 2023

Hi!

I've built some functionality outside of the library that allows you to generate a Graphviz dot file directly from the WorkflowDefinition. Is this something you'd be interested in upstreaming to your package?

Currently I've manually made the $id, $dependents and $instance fields of Node of the library public because it's needed for my custom extension to work, but if it's integrated into the library the API would largely stay the same.

Here's the source code I currently use for it:

    public function handle()
    {
        $workflow = new ExampleWorkflow();
        $graph = $workflow->definition()->graph();
        echo 'digraph G {' . PHP_EOL;
        echo '    rankdir="LR";' . PHP_EOL;
        echo '    graph [pad="0.5", nodesep="1", ranksep="2"]' . PHP_EOL;
        array_walk($graph->graph, function ($n) use (&$buf) {
            $this->getDot($n, $buf);
        });
    }

    public function getDot(Node $node, &$dot, &$visited = [])
    {
        $visited[$node->id] = true;
        if ($node->dependents) {
            foreach ($node->dependents as $dep) {
                echo '    "' . $node->id . '" -> { "' . $dep->id . '" }' . PHP_EOL;
                if (!$visited[$node->id]) {
                    $this->getDot($dep, $dot, $visited);
                }
            }
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant