Graphviz generator for PHP - a rethinking of Image_GraphViz
GPL-3.0 License
Welcome to Grafizzi, a PHP wrapper for AT&T GraphViz.
$ composer require osinet/grafizzi
logger
key, and possibly other arguments likedirected
to specify if you want to build a directed graph.Graph
instance, passing it the container.Subgraph
, Node
and Edge
instances to the graph using theaddChild()
method. Each of these take the container and an array ofAttribute
instances in their constructor, or you can add them usingsetAttribute()
after construction. Attribute instances are reusable onbuild()
method on the graph instance to obtain a stringdot
, neato
or your Graphviz command of choice.Filter
instances to filter the result, for exampleDotFilter
), or "tee" it between aStringFilter
).You can take inspiration from the examples provided in the example/
directory:
example/hello_node.php
builds a minimal graph showing a lot of loggingexample/grafizzi.php
builds a graph for the Grafizzi hierarchy of Filter
The easiest way to get started is to clone the Git repository.
git clone https://github.com/fgm/grafizzi.git
Once you have a clone of the Grafizzi repository, you need to install its development dependencies, using the Composer package dependency manager.
Download Composer following the instructions on https://getcomposer.org/download/
Then run:
php composer.phar install
Note that Grafizzi is available for PHP ≥ 8.2.
Now make sure that your local system is properly configured for Grafizzi. To do this, execute:
php example/hello-node.php
You should see a detailed debug execution trace. On a POSIX system, you can get
just the resulting GraphViz source by redirecting stderr to /dev/null
:
php example/hello-node.php 2> /dev/null
You should see a very basic GraphViz source:
graph g {
rankdir="TB";
label="Some graph";
n1 [ label="Some node" ];
n2 [ label="Other node" ];
n1 -- n2;
} /* /graph g */
If you get any warnings or recommendations, or nothing at all, check your PHP error log, and fix these now before moving on.
If your system includes the make
command, after installing,
run:
make lint
You should get a green bar with zero warnings.
If your system includes the make
and `doxygen' commands, and GraphViz itself,
you can generate a fully indexed source documentation by running:
make docs
This will generate a HTML documentation with internal search engine in the
doxygen/ directory. Use it by browsing to doxygen/html/index.html
.
The documentation and search engine are even usable over file:///
URLs, so
you do not need a web server to access it.
If you want to make sure that Grafizzi runs fine on your system, run:
make test
Note that the Composer installation in dev mode will have installed PHPunit in
your vendor
folder.
You can remove php_error.log
, the generated doxygen docs directory, the
generated coverage reports, and many stray generated files by running:
make clean
This will not remove the vendor/
directory.
Have fun!
app/*
to example/*