@@ -29,7 +29,8 @@ It provides different trees implementations:
29
29
30
30
Exporters and importers:
31
31
* ** Ascii** : Export a tree into an ascii graphic, just for swag and visualisation fun.
32
- * ** Graph** : Export a tree into a graph using the [ graphp/graphp] ( https://github.com/graphp/graph ) library.
32
+ * ** Graph** : Export a tree into a Graph using the [ graphp/graphp] ( https://github.com/graphp/graph ) library.
33
+ * ** GraphViz** : Export a tree into a script in [ GraphViz] ( http://www.graphviz.org/ ) format.
33
34
* ** Text** : Export a tree into a simple string, easy for storing in a database.
34
35
35
36
Modifier:
@@ -51,8 +52,7 @@ Blog post: [https://not-a-number.io/2018/phptree-a-fast-tree-implementation](htt
51
52
52
53
## Optional packages
53
54
54
- * [ graphp/graphp] ( https://github.com/graphp/graph ) : To convert a tree into a graph.
55
- * [ graphp/graphviz] ( https://github.com/graphp/graphviz ) : To render a graph into dot format or an image.
55
+ * [ graphp/graphp] ( https://github.com/graphp/graph ) : To export a tree into a Graph.
56
56
57
57
## Usage
58
58
@@ -61,8 +61,7 @@ Blog post: [https://not-a-number.io/2018/phptree-a-fast-tree-implementation](htt
61
61
62
62
declare(strict_types = 1);
63
63
64
- use Graphp\GraphViz\GraphViz;
65
- use drupol\phptree\Exporter\Graph;
64
+ use drupol\phptree\Exporter\Gv;
66
65
use drupol\phptree\Node\ValueNode;
67
66
use drupol\phptree\Exporter\Text;
68
67
@@ -79,14 +78,15 @@ foreach (\range('A', 'Z') as $v) {
79
78
// Add children to the root node.
80
79
$tree->add(...$nodes);
81
80
82
- // Export to an image.
83
- $graphViz = new GraphViz();
84
- $graphExporter = new Graph();
85
- $graphViz->display($graphExporter->export($tree));
86
-
87
81
// Export to text.
88
82
$textExporter = new Text();
89
83
echo $textExporter->export($tree); // [root[A[C[G[O][P]][H[Q][R]]][D[I[S][T]][J[U][V]]]][B[E[K[W][X]][L[Y][Z]]][F[M][N]]]]⏎
84
+
85
+ // Export to a GraphViz script.
86
+ $exporter = new Gv();
87
+ $dotScript = $exporter->export($tree);
88
+ file_put_contents('graph.gv', $dotScript);
89
+ // Then do "dot -Tsvg graph.gv -o graph.svg" to export the script to SVG.
90
90
```
91
91
92
92
## Code quality, tests and benchmarks
0 commit comments