PHP code example of graphp / graphviz
1. Go to this page and download the library: Download graphp/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/ */
graphp / graphviz example snippets
$graph = new Graphp\Graph\Graph();
$blue = $graph->createVertex();
$blue->setAttribute('id', 'blue');
$blue->setAttribute('graphviz.color', 'blue');
$red = $graph->createVertex();
$red->setAttribute('id', 'red');
$red->setAttribute('graphviz.color', 'red');
$edge = $graph->createEdgeDirected($blue, $red);
$edge->setAttribute('graphviz.color', 'grey');
$graphviz = new Graphp\GraphViz\GraphViz();
$graphviz->display($graph);
$graph = new Graphp\Graph\Graph();
$graph->setAttribute('graphviz.graph.bgcolor', 'transparent');
$graph = new Graphp\Graph\Graph();
$graph->setAttribute('graphviz.graph.rankdir', 'LR');
$hello = $graph->createVertex();
$hello->setAttribute('id', 'hello');
$world = $graph->createVertex();
$world->setAttribute('id', 'wörld');
$graph->createEdgeDirected($hello, $world);
$graph = new Graphp\Graph\Graph();
$graph->setAttribute('graphviz.name', 'G');
$graph->createVertex();
$graph = new Graphp\Graph\Graph();
$blue = $graph->createVertex();
$blue->setAttribute('graphviz.color', 'blue');
$graph = new Graphp\Graph\Graph();
$graph->setAttribute('graphviz.node.color', 'grey');
$grey = $graph->createVertex();
$graph = new Graphp\Graph\Graph();
$graph->setAttribute('graphviz.node.color', 'grey');
$blue = $graph->createVertex();
$blue->setAttribute('graphviz.color', 'blue');
$graph = new Graphp\Graph\Graph();
$a = $graph->createVertex();
$b = $graph->createVertex();
$blue = $graph->createEdgeDirected($a, $b);
$blue->setAttribute('graphviz.color', 'blue');
$graph = new Graphp\Graph\Graph();
$graph->setAttribute('graphviz.edge.color', 'grey');
$a = $graph->createVertex();
$b = $graph->createVertex();
$grey = $graph->createEdgeDirected($a, $b);
$graph = new Graphp\Graph\Graph();
$graph->setAttribute('graphviz.edge.color', 'grey');
$a = $graph->createVertex();
$b = $graph->createVertex();
$blue = $graph->createEdgeDirected($a, $b);
$blue->setAttribute('graphviz.color', 'blue');
$graph = new Graphp\Graph\Graph();
$v1 = $graph->createVertex();
$v2 = $graph->createVertex();
$graph = new Graphp\Graph\Graph();
$a = $graph->createVertex();
$a->setAttribute('id', 'blue');
$graph = new Graphp\Graph\Graph();
$blue = $graph->createVertex();
$blue->setAttribute('id', 'blue');
$blue->setAttribute('balance', 10);
$graph = new Graphp\Graph\Graph();
$blue = $graph->createVertex();
$blue->setAttribute('id', 'blue');
$blue->setAttribute('graphviz.label', 'Hello world!');
$graph = new Graphp\Graph\Graph();
$a = $graph->createVertex();
$b = $graph->createVertex();
$edge = $graph->createEdgeDirected($a, $b);
$graph = new Graphp\Graph\Graph();
$a = $graph->createVertex();
$b = $graph->createVertex();
$edge = $graph->createEdgeDirected($a, $b);
$edge->setAttribute('weight', 100);
$graph = new Graphp\Graph\Graph();
$a = $graph->createVertex();
$b = $graph->createVertex();
$edge = $graph->createEdgeDirected($a, $b);
$edge->setAttribute('flow', 4);
$edge->setAttribute('capacity', 10);
$graph = new Graphp\Graph\Graph();
$a = $graph->createVertex();
$b = $graph->createVertex();
$edge = $graph->createEdgeDirected($a, $b);
$edge->setAttribute('flow', 4);
$edge->setAttribute('capacity', null);
$edge->setAttribute('weight', 100);
$graph = new Graphp\Graph\Graph();
$a = $graph->createVertex();
$b = $graph->createVertex();
$edge = $graph->createEdgeDirected($a, $b);
$edge->setAttribute('graphviz.label', 'important');
$graph = new Graphp\Graph\Graph();
$a = $graph->createVertex();
$a->setAttribute('id', 'Entity');
$a->setAttribute('graphviz.shape', 'none');
$a->setAttribute('graphviz.label_html', '
<table cellspacing="0" border="0" cellborder="1">
<tr><td bgcolor="#eeeeee"><b>\N</b></td></tr>
<tr><td></td></tr>
<tr><td>+ touch()</td></tr>
</table>');
$b = $graph->createVertex();
$graph->createEdgeDirected($b, $a);
$b->setAttribute('id', 'Block');
$b->setAttribute('graphviz.shape', 'none');
$b->setAttribute('graphviz.label_html', '
<table cellspacing="0" border="0" cellborder="1">
<tr><td bgcolor="#eeeeee"><b>\N</b></td></tr>
<tr><td>- size:int</td></tr>
<tr><td>+ touch()</td></tr>
</table>');
$graph = new Graphp\Graph\Graph();
$a = $graph->createVertex();
$a->setAttribute('graphviz.shape', 'Mrecord');
$a->setAttribute('graphviz.label_record', '<f0> left |<middle> middle |<f2> right'));
$b = $graph->createVertex();
$b->setAttribute('graphviz.shape', 'Mrecord');
$b->setAttribute('graphviz.label_record', '<f0> left |<f1> middle |<right> right'));
// a:middle -> b:right
$edge = $graph->createEdgeDirected($a, $b);
$edge->setAttribute('graphviz.tailport', 'middle');
$edge->setAttribute('graphviz.headport', 'right');