Skip to content

Commit faff3e1

Browse files
authored
Merge pull request #40 from clue-labs/deps
Update to graphp/graph
2 parents 5cc4466 + 8d85d84 commit faff3e1

File tree

11 files changed

+267
-172
lines changed

11 files changed

+267
-172
lines changed

README.md

Lines changed: 105 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,17 @@ the actual layouting of the graph is left up to the excelent [GraphViz](http://w
3232
Once [installed](#install), let's build and display a sample graph:
3333

3434
````php
35-
$graph = new Fhaculty\Graph\Graph();
35+
$graph = new Graphp\Graph\Graph();
3636

37-
$blue = $graph->createVertex('blue');
37+
$blue = $graph->createVertex();
38+
$blue->setAttribute('id', 'blue');
3839
$blue->setAttribute('graphviz.color', 'blue');
3940

40-
$red = $graph->createVertex('red');
41+
$red = $graph->createVertex();
42+
$red->setAttribute('id', 'red');
4143
$red->setAttribute('graphviz.color', 'red');
4244

43-
$edge = $blue->createEdgeTo($red);
45+
$edge = $graph->createEdgeDirected($blue, $red);
4446
$edge->setAttribute('graphviz.color', 'grey');
4547

4648
$graphviz = new Graphp\GraphViz\GraphViz();
@@ -75,7 +77,7 @@ these GraphViz attributes are supported by this library and have to be assigned
7577
on the graph instance with the `graphviz.graph.` prefix like this:
7678

7779
```php
78-
$graph = new Fhaculty\Graph\Graph();
80+
$graph = new Graphp\Graph\Graph();
7981
$graph->setAttribute('graphviz.graph.bgcolor', 'transparent');
8082
```
8183

@@ -87,12 +89,14 @@ For example, the `rankdir` attribute can be used to change the orientation to
8789
horizontal mode (left to right) like this:
8890

8991
```php
90-
$graph = new Fhaculty\Graph\Graph();
92+
$graph = new Graphp\Graph\Graph();
9193
$graph->setAttribute('graphviz.graph.rankdir', 'LR');
9294

93-
$hello = $graph->createVertex('hello');
94-
$world = $graph->createVertex('wörld');
95-
$hello->createEdgeTo($world);
95+
$hello = $graph->createVertex();
96+
$hello->setAttribute('id', 'hello');
97+
$world = $graph->createVertex();
98+
$world->setAttribute('id', 'wörld');
99+
$graph->createEdgeDirected($hello, $world);
96100
```
97101

98102
![html graph example](examples/02-html.png)
@@ -106,10 +110,10 @@ to assign a `G` here, but usually there should be no need to assign this. Among
106110
others, this may be used as the title or tooltip in SVG output.
107111

108112
```php
109-
$graph = new Fhaculty\Graph\Graph();
113+
$graph = new Graphp\Graph\Graph();
110114
$graph->setAttribute('graphviz.name', 'G');
111115

112-
$graph->createVertex('first');
116+
$graph->createVertex();
113117
```
114118

115119
### Vertex attributes
@@ -120,9 +124,9 @@ library and have to be assigned on the respective vertex instance with the
120124
`graphviz.` prefix like this:
121125

122126
```php
123-
$graph = new Fhaculty\Graph\Graph();
127+
$graph = new Graphp\Graph\Graph();
124128

125-
$blue = $graph->createVertex('blue');
129+
$blue = $graph->createVertex();
126130
$blue->setAttribute('graphviz.color', 'blue');
127131
```
128132

@@ -131,20 +135,20 @@ these GraphViz attributes are supported by this library and have to be assigned
131135
on the graph instance with the `graphviz.node.` prefix like this:
132136

133137
```php
134-
$graph = new Fhaculty\Graph\Graph();
138+
$graph = new Graphp\Graph\Graph();
135139
$graph->setAttribute('graphviz.node.color', 'grey');
136140

137-
$grey = $graph->createVertex('grey');
141+
$grey = $graph->createVertex();
138142
```
139143

140144
These default attributes can be overriden on each vertex instance by explicitly
141145
assigning the same attribute on the respective vertex instance like this:
142146

143147
```php
144-
$graph = new Fhaculty\Graph\Graph();
148+
$graph = new Graphp\Graph\Graph();
145149
$graph->setAttribute('graphviz.node.color', 'grey');
146150

147-
$blue = $graph->createVertex('blue');
151+
$blue = $graph->createVertex();
148152
$blue->setAttribute('graphviz.color', 'blue');
149153
```
150154

@@ -159,12 +163,12 @@ GraphViz attributes are supported by this library and have to be assigned on the
159163
respective edge instance with the `graphviz.` prefix like this:
160164

161165
```php
162-
$graph = new Fhaculty\Graph\Graph();
166+
$graph = new Graphp\Graph\Graph();
163167

164-
$a = $graph->createVertex('a');
165-
$b = $graph->createVertex('b');
168+
$a = $graph->createVertex();
169+
$b = $graph->createVertex();
166170

167-
$blue = $a->createEdgeTo($b);
171+
$blue = $graph->createEdgeDirected($a, $b);
168172
$blue->setAttribute('graphviz.color', 'blue');
169173
```
170174

@@ -173,134 +177,158 @@ these GraphViz attributes are supported by this library and have to be assigned
173177
on the graph instance with the `graphviz.edge.` prefix like this:
174178

175179
```php
176-
$graph = new Fhaculty\Graph\Graph();
180+
$graph = new Graphp\Graph\Graph();
177181
$graph->setAttribute('graphviz.edge.color', 'grey');
178182

179-
$a = $graph->createVertex('a');
180-
$b = $graph->createVertex('b');
183+
$a = $graph->createVertex();
184+
$b = $graph->createVertex();
181185

182-
$grey = $a->createEdgeTo($b);
186+
$grey = $graph->createEdgeDirected($a, $b);
183187
```
184188

185189
These default attributes can be overriden on each edge instance by explicitly
186190
assigning the same attribute on the respective edge instance like this:
187191

188192
```php
189-
$graph = new Fhaculty\Graph\Graph();
193+
$graph = new Graphp\Graph\Graph();
190194
$graph->setAttribute('graphviz.edge.color', 'grey');
191195

192-
$a = $graph->createVertex('a');
193-
$b = $graph->createVertex('b');
196+
$a = $graph->createVertex();
197+
$b = $graph->createVertex();
194198

195-
$blue = $a->createEdgeTo($b);
199+
$blue = $graph->createEdgeDirected($a, $b);
196200
$blue->setAttribute('graphviz.color', 'blue');
197201
```
198202

199203
## Labels
200204

201205
### Vertex labels
202206

203-
By default, GraphViz will always render the vertex ID as the label:
207+
By default, GraphViz will always render the vertex ID as the label.
208+
If you do not assign an explicit `id` attribute to a vertex, this library will
209+
automatically assign a vertex ID starting at `1` in the DOT output and GraphViz
210+
will automatically render this vertex ID as the label. The following example
211+
will automatically assign `1` and `2` as the label:
204212

205213
```php
206-
$graph = new Fhaculty\Graph\Graph();
214+
$graph = new Graphp\Graph\Graph();
207215

208-
$blue = $graph->createVertex('blue');
216+
$v1 = $graph->createVertex();
217+
$v2 = $graph->createVertex();
209218
```
210219

211-
If you assign a vertex balance, this library will automatically include a
212-
`label` attribute that includes the balance value. The following example will
213-
automatically assign `blue (+10)` as the label:
220+
If you assign an `id` attribute to a vertex, this library will automatically
221+
use it as the vertex ID in the DOT output and GraphViz will automatically render
222+
this vertex ID as the label. The following example will automatically assign
223+
`blue` as the label:
214224

215225
```php
216-
$graph = new Fhaculty\Graph\Graph();
226+
$graph = new Graphp\Graph\Graph();
217227

218-
$blue = $graph->createVertex('blue');
219-
$blue->setBalance(10);
228+
$a = $graph->createVertex();
229+
$a->setAttribute('id', 'blue');
230+
```
231+
232+
If you assign a `balance` attribute to a vertex, this library will automatically
233+
include a `label` attribute that appends the balance value in parenthesis. The
234+
following example will automatically assign `blue (+10)` as the label:
235+
236+
```php
237+
$graph = new Graphp\Graph\Graph();
238+
239+
$blue = $graph->createVertex();
240+
$blue->setAttribute('id', 'blue');
241+
$blue->setAttribute('balance', 10);
220242
```
221243

222244
You can use [vertex attributes](#vertex-attributes) to explicitly assign a
223245
custom `label` attribute. Note that any balance value will still be appended
224246
like in the previous example.
225247

226248
```php
227-
$graph = new Fhaculty\Graph\Graph();
249+
$graph = new Graphp\Graph\Graph();
228250

229-
$blue = $graph->createVertex('blue');
251+
$blue = $graph->createVertex();
252+
$blue->setAttribute('id', 'blue');
230253
$blue->setAttribute('graphviz.label', 'Hello world!');
231254
```
232255

233256
Note that all [attributes](#attributes) will be quoted and escaped by default,
234257
so a `>` will appear as-is and will not be interpreted as HTML. See also
235258
[HTML-like labels](#html-like-labels) below for more details.
236259

260+
Also note that you should either define *no* vertex IDs at all or *all* vertex
261+
IDs. If you only define *some* vertex IDs, the automatic numbering may yield a
262+
vertex ID that is already used explicitly and overwrite some of its settings.
263+
237264
### Edge labels
238265

239266
By default, GraphViz will not render any label on an edge:
240267

241268
```php
242-
$graph = new Fhaculty\Graph\Graph();
269+
$graph = new Graphp\Graph\Graph();
243270

244-
$a = $graph->createVertex('a');
245-
$b = $graph->createVertex('b');
271+
$a = $graph->createVertex();
272+
$b = $graph->createVertex();
246273

247-
$edge = $a->createEdgeTo($b);
274+
$edge = $graph->createEdgeDirected($a, $b);
248275
```
249276

250-
If you assign an edge flow, capacity or weight, this library will automatically
251-
include a `label` attribute that includes these values. The following example
252-
will automatically assign `100` as the label for the weighted edge:
277+
If you assign a `flow`, `capacity` or `weight` attribute to an edge, this library
278+
will automatically include a `label` attribute that includes these values. The
279+
following example will automatically assign `100` as the label for the weighted
280+
edge:
253281

254282
```php
255-
$graph = new Fhaculty\Graph\Graph();
283+
$graph = new Graphp\Graph\Graph();
256284

257-
$a = $graph->createVertex('a');
258-
$b = $graph->createVertex('b');
285+
$a = $graph->createVertex();
286+
$b = $graph->createVertex();
259287

260-
$edge = $a->createEdgeTo($b);
261-
$edge->setWeight(100);
288+
$edge = $graph->createEdgeDirected($a, $b);
289+
$edge->setAttribute('weight', 100);
262290
```
263291

264292
The following example will automatically assign `4/10` as the label for an edge
265293
with both flow and maximum capacity set:
266294

267295
```php
268-
$graph = new Fhaculty\Graph\Graph();
296+
$graph = new Graphp\Graph\Graph();
269297

270-
$a = $graph->createVertex('a');
271-
$b = $graph->createVertex('b');
298+
$a = $graph->createVertex();
299+
$b = $graph->createVertex();
272300

273-
$edge = $a->createEdgeTo($b);
274-
$edge->setFlow(4);
275-
$edge->setCapacity(10);
301+
$edge = $graph->createEdgeDirected($a, $b);
302+
$edge->setAttribute('flow', 4);
303+
$edge->setAttribute('capacity', 10);
276304
```
277305

278306
The following example will automatically assign `4/∞/100` as the label for a
279307
weighted edge with a flow and unlimited capacity:
280308

281309
```php
282-
$graph = new Fhaculty\Graph\Graph();
310+
$graph = new Graphp\Graph\Graph();
283311

284-
$a = $graph->createVertex('a');
285-
$b = $graph->createVertex('b');
312+
$a = $graph->createVertex();
313+
$b = $graph->createVertex();
286314

287-
$edge = $a->createEdgeTo($b);
288-
$edge->setFlow(4);
289-
$edge->setCapacity(null);
290-
$edge->setWeight(100);
315+
$edge = $graph->createEdgeDirected($a, $b);
316+
$edge->setAttribute('flow', 4);
317+
$edge->setAttribute('capacity', null);
318+
$edge->setAttribute('weight', 100);
291319
```
292320

293321
You can use [edge attributes](#edge-attributes) to explicitly assign any
294322
custom `label` attribute. Note that any flow, capacity or weight value will still
295323
be appended like in the previous examples.
296324

297325
```php
298-
$graph = new Fhaculty\Graph\Graph();
326+
$graph = new Graphp\Graph\Graph();
299327

300-
$a = $graph->createVertex('a');
301-
$b = $graph->createVertex('b');
328+
$a = $graph->createVertex();
329+
$b = $graph->createVertex();
302330

303-
$edge = $a->createEdgeTo($b);
331+
$edge = $graph->createEdgeDirected($a, $b);
304332
$edge->setAttribute('graphviz.label', 'important');
305333
```
306334

@@ -317,9 +345,10 @@ prevent automatic quoting and escaping, all attribute values have to be passed
317345
to the static `GraphViz::raw()` helper like this:
318346

319347
```php
320-
$graph = new Fhaculty\Graph\Graph();
348+
$graph = new Graphp\Graph\Graph();
321349

322-
$a = $graph->createVertex('Entity');
350+
$a = $graph->createVertex();
351+
$a->setAttribute('id', 'Entity');
323352
$a->setAttribute('graphviz.shape', 'none');
324353
$a->setAttribute('graphviz.label', GraphViz::raw('<
325354
<table cellspacing="0" border="0" cellborder="1">
@@ -328,8 +357,9 @@ $a->setAttribute('graphviz.label', GraphViz::raw('<
328357
<td>+ touch()</td></tr>
329358
</table>>'));
330359

331-
$b = $graph->createVertex('Block');
332-
$b->createEdgeTo($a);
360+
$b = $graph->createVertex();
361+
$graph->createEdgeDirected($b, $a);
362+
$b->setAttribute('id', 'Block');
333363
$b->setAttribute('graphviz.shape', 'none');
334364
$b->setAttribute('graphviz.label', GraphViz::raw('<
335365
<table cellspacing="0" border="0" cellborder="1">
@@ -357,7 +387,7 @@ automatic quoting and escaping, all attribute values have to be quoted manually
357387
and passed to the static `GraphViz::raw()` helper like this:
358388

359389
```php
360-
$graph = new Fhaculty\Graph\Graph();
390+
$graph = new Graphp\Graph\Graph();
361391

362392
$a = $graph->createVertex();
363393
$a->setAttribute('graphviz.shape', 'Mrecord');
@@ -368,7 +398,7 @@ $b->setAttribute('graphviz.shape', 'Mrecord');
368398
$b->setAttribute('graphviz.label', GraphViz::raw('"<f0> left |<f1> middle |<right> right"'));
369399

370400
// a:middle -> b:right
371-
$edge = $a->createEdgeTo($b);
401+
$edge = $graph->createEdgeDirected($a, $b);
372402
$edge->setAttribute('graphviz.tailport', 'middle');
373403
$edge->setAttribute('graphviz.headport', 'right');
374404
```

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"require": {
1212
"php": ">=5.3.0",
13-
"clue/graph": "~0.9.0|~0.8.0"
13+
"graphp/graph": "dev-master#81eef65 as 1.0.0"
1414
},
1515
"require-dev": {
1616
"phpunit/phpunit": "^6.4 || ^5.7 || ^4.8.35"

examples/01-simple.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22

33
require __DIR__ . '/../vendor/autoload.php';
44

5-
$graph = new Fhaculty\Graph\Graph();
5+
$graph = new Graphp\Graph\Graph();
66

7-
$blue = $graph->createVertex('blue');
7+
$blue = $graph->createVertex();
8+
$blue->setAttribute('id', 'blue');
89
$blue->setAttribute('graphviz.color', 'blue');
910

10-
$red = $graph->createVertex('red');
11+
$red = $graph->createVertex();
12+
$red->setAttribute('id', 'red');
1113
$red->setAttribute('graphviz.color', 'red');
1214

15+
$edge = $graph->createEdgeDirected($blue, $red);
1316
$edge = $blue->createEdgeTo($red);
1417
$edge->setAttribute('graphviz.color', 'grey');
1518

0 commit comments

Comments
 (0)