PHP code example of badams / graphviz

1. Go to this page and download the library: Download badams/graphviz library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

badams / graphviz example snippets


$graph = new Alom\Graphviz\Digraph('G');
$graph
    ->subgraph('cluster_1')
        ->attr('node', array('style' => 'filled', 'fillcolor' => 'blue'))
        ->node('A')
        ->node('B')
        ->edge(array('b0', 'b1', 'b2', 'b3'))
    ->end()
    ->edge(array('A', 'B', 'C'))
;
echo $graph->render();

$graph = new Alom\Graphviz\Digraph('G');
$graph
    ->node('my_table', array(
        'label' => '<<table>...</table>>',
        '_escaped' => false
    ))

$graph = new Alom\Graphviz\Digraph('G');
$graph
    ->subgraph('cluster_1')
        ->node('A')
        ->node('B')
    ->end()
    ->subgraph('cluster_2')
        ->node('C')
        ->node('D')
    ->end()
    ->edge(array('C', 'D'))
;

$cluster = $graph->get('cluster_1');
$node = $graph->get('cluster_2')->get('D');

# read a value
echo $node->getAttribute('label', 'no label'); # second argument is default value

# write a value
$node->attribute('label', 'new label');

$graph = new Alom\Graphviz\Digraph('G');
$graph
    ->node('A', array('shape' => 'record', 'label' => '{ <1> Part 1 | <2> Part 2}'))
    ->node('B')
    ->edge(array('B', array('A', '1')))
;
bash
php samples/00-readme.php | dot -Tpdf -oout.pdf
xdg-open out.pdf