### Install PHP Graphviz with Composer
Source: https://github.com/alexandresalome/graphviz/blob/2.1-dev/docs/getting-started.md
Installs the PHP Graphviz library as a project dependency using Composer.
```shell
composer require alom/graphviz
```
--------------------------------
### Render a Directed Graph with PHP Graphviz
Source: https://github.com/alexandresalome/graphviz/blob/2.1-dev/docs/getting-started.md
Demonstrates how to create a directed graph using the PHP Graphviz library, including subgraphs and edges, and render it in DOT language.
```php
subgraph('cluster_1')
->attr('node', ['style' => 'filled', 'fillcolor' => 'blue'])
->node('A')
->node('B')
->end()
->edge(array('A', 'B', 'C'))
;
echo $graph->render();
```
--------------------------------
### Convert Graphviz DOT to PNG Image
Source: https://github.com/alexandresalome/graphviz/blob/2.1-dev/docs/getting-started.md
Shows how to pipe the DOT language output from a PHP script to the Graphviz 'dot' command-line tool to generate a PNG image.
```shell
php test-graphviz.php | dot -Tpng > test-graphviz.png
```
--------------------------------
### Basic Graphviz Digraph Creation
Source: https://github.com/alexandresalome/graphviz/blob/2.1-dev/docs/examples/basic.md
This snippet demonstrates how to create a directed graph using the Graphviz library. It includes creating subgraphs, setting attributes for nodes and subgraphs, and defining edges. The code utilizes a fluent interface for building the graph structure.
```php
$graph = new Graphviz\Digraph();
$graph
->subgraph('cluster_0')
->set('style', 'filled')
->set('color', 'lightgrey')
->attr('node', ['style' => 'filled', 'color' => 'white'])
->edge(['a0', 'a1', 'a2', 'a3'])
->set('label', 'process #1')
->end()
->subgraph('cluster_1')
->attr('node', ['style' => 'filled'])
->edge(['b0', 'b1', 'b2', 'b3'])
->set('label', 'process #2')
->set('color', 'blue')
->end()
->edge(['start', 'a0'])
->edge(['start', 'b0'])
->edge(['a1', 'b3'])
->edge(['b2', 'a3'])
->edge(['a3', 'a0'])
->edge(['a3', 'end'])
->edge(['b3', 'end'])
;
```
--------------------------------
### Create Clustered Subgraphs
Source: https://github.com/alexandresalome/graphviz/blob/2.1-dev/docs/examples/subgraph.md
Demonstrates how to create clustered subgraphs with custom attributes like background color and labels. This involves instantiating a Digraph, defining nodes, and then creating subgraphs using the `subgraph` method.
```php
$graph = new Graphviz\Digraph();
$graph
->nodes(['A', 'B', 'C'])
->subgraph('cluster_A')
->set('bgcolor', '#ffcc00')
->set('label', 'Title of the cluster A')
->nodes(['D', 'E'])
->end()
->subgraph('cluster_B')
->nodes(['F', 'G'])
->end()
->edge(['A', 'C'])
->edge(['B', 'D', 'F'])
->edge(['D', 'E'])
->edge(['B', 'G'])
;
```
--------------------------------
### Create Nested Subgraphs
Source: https://github.com/alexandresalome/graphviz/blob/2.1-dev/docs/examples/subgraph.md
Illustrates the creation of nested subgraphs, where a subgraph can contain other subgraphs. This example shows a chain of nested clusters, each containing a node and an edge.
```php
$graph = new Graphviz\Digraph();
$graph->node('A')->edge(['A', 'B']);
$sub1 = $graph
->subgraph('cluster_1')
->node('B')
->edge(['B', 'C'])
;
$sub2 = $sub1->subgraph('cluster_2')
->node('C')
->edge(['C', 'D'])
;
$sub3 = $sub2->subgraph('cluster_3')
->node('D')
;
```
--------------------------------
### PHP Graphviz Table Node Creation
Source: https://github.com/alexandresalome/graphviz/blob/2.1-dev/docs/examples/table.md
This snippet shows how to create a Graphviz Digraph and add nodes with HTML-like table labels. It demonstrates the use of `RawText` to ensure that the HTML content within the table is not escaped by Graphviz.
```php
$graph = new Graphviz\Digraph();
$graph
->node('escaped', [
'label' => '<
>',
])
->node('unescaped', [
'label' => new Graphviz\RawText('<>'),
])
;
```
--------------------------------
### Access Existing Node
Source: https://github.com/alexandresalome/graphviz/blob/2.1-dev/docs/usage/nodes.md
Shows how to retrieve an existing `Node` object from the graph using its identifier with the `get()` method and modify its attributes.
```php
$graph = new Graphviz\Digraph();
$graph->node('foo');
$foo = $graph->get('foo');
$foo->attribute('shape', 'record');
```
--------------------------------
### Instantiate Graphviz Graph
Source: https://github.com/alexandresalome/graphviz/blob/2.1-dev/docs/usage/creation.md
Demonstrates how to create both directed (Digraph) and undirected (Graph) graph objects using the Graphviz library.
```php
$graph = new Graphviz\Digraph();
```
```php
$graph = new Graphviz\Graph();
```
--------------------------------
### Create Node with Attributes
Source: https://github.com/alexandresalome/graphviz/blob/2.1-dev/docs/usage/nodes.md
Illustrates how to create a node and assign attributes to it by passing an associative array of attributes.
```php
$graph = new Graphviz\Digraph();
$graph->node('foo', [
'shape' => 'record',
'label' => 'This is the label of the node'
]);
```
--------------------------------
### Configure and Add Edges to an Undirected Graph
Source: https://github.com/alexandresalome/graphviz/blob/2.1-dev/docs/usage/creation.md
Illustrates setting graph attributes and adding edges to an undirected graph using the Graphviz\Graph class.
```php
$graph = new Graphviz\Graph();
$graph->set('rankdir', 'LR');
$graph->edge(['Alice', 'Bob', 'Charlie']);
$graph->edge(['Alice', 'Charlie']);
```
--------------------------------
### Configure and Add Edges to a Directed Graph
Source: https://github.com/alexandresalome/graphviz/blob/2.1-dev/docs/usage/creation.md
Shows how to set graph attributes like 'rankdir' and add edges to a directed graph using the Graphviz\Digraph class.
```php
$graph = new Graphviz\Digraph();
$graph->set('rankdir', 'LR');
$graph->edge(['Alice', 'Bob', 'Charlie']);
$graph->edge(['Alice', 'Charlie']);
```
--------------------------------
### Create Multiple Nodes
Source: https://github.com/alexandresalome/graphviz/blob/2.1-dev/docs/usage/nodes.md
Shows how to create multiple nodes at once using the `nodes()` method with an array of node identifiers.
```php
$graph = new Graphviz\Digraph();
$graph->nodes(['foo', 'bar', 'baz']);
```
--------------------------------
### Create and Use Subgraphs in Digraph
Source: https://github.com/alexandresalome/graphviz/blob/2.1-dev/docs/graphviz/subgraph.md
Demonstrates how to create a directed graph and add nodes to different subgraphs. Subgraphs themselves do not provide visual grouping.
```php
$graph = new Graphviz\Digraph();
$graph
->nodes(['A', 'B', 'C'])
->subgraph('1')
->nodes(['D', 'E'])
->end()
->subgraph('2')
->nodes(['F', 'G'])
->end()
->edge(['A', 'C'])
->edge(['B', 'D', 'F'])
->edge(['D', 'E'])
->edge(['B', 'G'])
;
```
--------------------------------
### Create Graphviz Edge
Source: https://github.com/alexandresalome/graphviz/blob/2.1-dev/docs/usage/edges.md
Demonstrates the basic creation of an edge between multiple nodes using the `edge` method in PHP. This is the fundamental way to define connections in a graph.
```php
$graph = new Graphviz\Digraph();
$graph->set('rankdir', 'LR');
$graph->edge(['foo', 'bar', 'baz']);
```
--------------------------------
### Create and Use Cluster Subgraphs in Digraph
Source: https://github.com/alexandresalome/graphviz/blob/2.1-dev/docs/graphviz/subgraph.md
Illustrates creating a directed graph with cluster subgraphs. Subgraphs prefixed with 'cluster_' are rendered with a visual bounding box.
```php
$graph = new Graphviz\Digraph();
$graph
->nodes(['A', 'B', 'C'])
->subgraph('cluster_A')
->nodes(['D', 'E'])
->end()
->subgraph('cluster_B')
->nodes(['F', 'G'])
->end()
->edge(['A', 'C'])
->edge(['B', 'D', 'F'])
->edge(['D', 'E'])
->edge(['B', 'G'])
;
```
--------------------------------
### Create Multiple Nodes with Attributes
Source: https://github.com/alexandresalome/graphviz/blob/2.1-dev/docs/usage/nodes.md
Demonstrates creating multiple nodes, some with specific attributes, using an associative array in the `nodes()` method.
```php
$graph = new Graphviz\Digraph();
$graph->nodes([
'foo',
'bar' => ['shape' => 'record'],
'baz',
]);
```
--------------------------------
### Create Single Node
Source: https://github.com/alexandresalome/graphviz/blob/2.1-dev/docs/usage/nodes.md
Demonstrates how to create a single node in a Graphviz digraph using the `node()` method.
```php
$graph = new Graphviz\Digraph();
$graph->node('foo');
```
--------------------------------
### Style Graphviz Edge with Attributes
Source: https://github.com/alexandresalome/graphviz/blob/2.1-dev/docs/usage/edges.md
Shows how to apply visual attributes, such as 'style' and 'color', to an edge by passing an associative array as the second argument to the `edge` method. This allows for customization of edge appearance.
```php
$graph = new Graphviz\Digraph();
$graph->edge(['foo', 'bar'], [
'style' => 'dashed',
'color' => 'red',
]);
```
--------------------------------
### Render Graph to DOT Format
Source: https://github.com/alexandresalome/graphviz/blob/2.1-dev/docs/usage/rendering.md
Renders a graph object into the DOT language format. This is the primary method for outputting the graph's structure.
```php
$graph = new Graphviz\Digraph();
$graph->edge(['Alice', 'Bob']);
echo $graph->render();
```
```dot
digraph G {
Alice -> Bob;
}
```
--------------------------------
### Customize Graph Indentation
Source: https://github.com/alexandresalome/graphviz/blob/2.1-dev/docs/usage/rendering.md
Allows explicit control over the indentation used in the generated DOT output by specifying a custom indentation string.
```php
$renderer = new Graphviz\Output\DotRenderer(' ');
echo $renderer->render($graph);
```
```dot
digraph G {
Alice -> Bob;
}
```
--------------------------------
### Set Graph Attribute
Source: https://github.com/alexandresalome/graphviz/blob/2.1-dev/docs/usage/attributes.md
Demonstrates how to set a global attribute for a directed graph using the 'set' method in PHP. This is useful for defining properties like background color.
```php
# Directed graph
$graph = new Graphviz\Digraph();
$graph->set('bgcolor', 'red');
$graph->nodes(['foo', 'bar']);
```
--------------------------------
### Manipulate Node Object
Source: https://github.com/alexandresalome/graphviz/blob/2.1-dev/docs/usage/nodes.md
Explains how to obtain a `Node` object using `beginNode()` and then manipulate its attributes using the `attribute()` method.
```php
$graph = new Graphviz\Digraph();
$node = $graph->beginNode('foo');
# Set a value
$node->attribute('shape', 'record');
$node->attribute('label', 'This is the label');
# Get a value
$value = $node->getAttribute('shape');
```
--------------------------------
### Target Graphviz Port Identifier in Edge
Source: https://github.com/alexandresalome/graphviz/blob/2.1-dev/docs/usage/edges.md
Illustrates how to create an edge that targets a specific port identifier within a node. This is achieved by providing an array containing the node identifier and the port identifier to the `edge` method, enabling more precise connections.
```php
$graph = new Graphviz\Digraph();
$graph->node('week', [
'shape' => 'record',
'label' => 'Monday|Tuesday| Wednesday|Thursday|Friday',
]);
$graph->node('people', [
'shape' => 'record',
'label' => 'Alice| Bob|Charlie',
]);
$graph->edge([
['week', 'wed'],
['people', 'bob'],
]);
```
--------------------------------
### Set Node, Edge, and Subgraph Attributes
Source: https://github.com/alexandresalome/graphviz/blob/2.1-dev/docs/usage/attributes.md
Illustrates setting attributes for nodes, edges, and subgraphs within a directed graph using the 'attr' method in PHP. This allows for fine-grained styling of different graph elements.
```php
# Directed graph
$graph = new Graphviz\Digraph();
$graph
->attr('node', ['style' => 'filled', 'fillcolor' => 'yellow'])
->attr('edge', ['color' => 'blue'])
->nodes(['foo', 'bar'])
->subgraph('cluster_baz')
->attr('graph', ['bgcolor' => 'green'])
->nodes(['A', 'B', 'C'])
->end()
->edge(['foo', 'B'])
->edge(['bar', 'C'])
;
```
--------------------------------
### Generate Contributor List
Source: https://github.com/alexandresalome/graphviz/blob/2.1-dev/docs/contributors.md
This bash command extracts and formats contributor names from Git log history. It reverses the log, formats author names, replaces specific names, and then filters out duplicate entries to provide a unique list of contributors in order of appearance.
```bash
git log --reverse --format="%aN" \
| sed "s/alexandresalome/Alexandre Salomé/g" \
| perl -ne 'if (!defined $x{$_}) { print $_; $x{$_} = 1; }'
```
--------------------------------
### Add Single Line Comment - Graphviz PHP
Source: https://github.com/alexandresalome/graphviz/blob/2.1-dev/docs/usage/comment.md
Adds a single line comment to a Graphviz graph. Supports custom prefixes and C++ style comments. The commentLine method takes the comment string, an optional boolean to remove leading spaces, and an optional boolean to use C++ style comments.
```php
$graph = new Graphviz\Digraph();
$graph->commentLine('Empty graph');
echo $graph->render();
```
```php
$graph = new Graphviz\Digraph();
$graph->commentLine("Line 1\nLine 2");
echo $graph->render();
```
```php
$graph = new Graphviz\Digraph();
$graph->commentLine('-- ASCII MASTER --//', false);
echo $graph->render();
```
```php
$graph = new Graphviz\Digraph();
$graph->commentLine('C++ style', true, false);
echo $graph->render();
```
--------------------------------
### Add Block Comment - Graphviz PHP
Source: https://github.com/alexandresalome/graphviz/blob/2.1-dev/docs/usage/comment.md
Adds a block comment to a Graphviz graph. Supports multi-line comments and options to disable new lines and spacing. The commentBlock method takes the comment string and an optional boolean to control formatting.
```php
$graph = new Graphviz\Digraph();
$graph->commentBlock('My block comment');
echo $graph->render();
```
```php
$graph = new Graphviz\Digraph();
$graph->commentBlock("My block comment\non multiple lines");
echo $graph->render();
```
```php
$graph = new Graphviz\Digraph();
$graph->commentBlock("** ASCII fan\nNew line\n**", false);
echo $graph->render();
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.