Skip to content

Commit 04001c1

Browse files
committed
Create edges via Graph
Refs graphp/graph#175
1 parent 5def620 commit 04001c1

File tree

8 files changed

+43
-41
lines changed

8 files changed

+43
-41
lines changed

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ $blue->setAttribute('graphviz.color', 'blue');
4040
$red = $graph->createVertex('red');
4141
$red->setAttribute('graphviz.color', 'red');
4242

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

4646
$graphviz = new Graphp\GraphViz\GraphViz();
@@ -92,7 +92,7 @@ $graph->setAttribute('graphviz.graph.rankdir', 'LR');
9292

9393
$hello = $graph->createVertex('hello');
9494
$world = $graph->createVertex('wörld');
95-
$hello->createEdgeTo($world);
95+
$graph->createEdgeDirected($hello, $world);
9696
```
9797

9898
![html graph example](examples/02-html.png)
@@ -164,7 +164,7 @@ $graph = new Graphp\Graph\Graph();
164164
$a = $graph->createVertex('a');
165165
$b = $graph->createVertex('b');
166166

167-
$blue = $a->createEdgeTo($b);
167+
$blue = $graph->createEdgeDirected($a, $b);
168168
$blue->setAttribute('graphviz.color', 'blue');
169169
```
170170

@@ -179,7 +179,7 @@ $graph->setAttribute('graphviz.edge.color', 'grey');
179179
$a = $graph->createVertex('a');
180180
$b = $graph->createVertex('b');
181181

182-
$grey = $a->createEdgeTo($b);
182+
$grey = $graph->createEdgeDirected($a, $b);
183183
```
184184

185185
These default attributes can be overriden on each edge instance by explicitly
@@ -192,7 +192,7 @@ $graph->setAttribute('graphviz.edge.color', 'grey');
192192
$a = $graph->createVertex('a');
193193
$b = $graph->createVertex('b');
194194

195-
$blue = $a->createEdgeTo($b);
195+
$blue = $graph->createEdgeDirected($a, $b);
196196
$blue->setAttribute('graphviz.color', 'blue');
197197
```
198198

@@ -244,7 +244,7 @@ $graph = new Graphp\Graph\Graph();
244244
$a = $graph->createVertex('a');
245245
$b = $graph->createVertex('b');
246246

247-
$edge = $a->createEdgeTo($b);
247+
$edge = $graph->createEdgeDirected($a, $b);
248248
```
249249

250250
If you assign an edge flow, capacity or weight, this library will automatically
@@ -257,7 +257,7 @@ $graph = new Graphp\Graph\Graph();
257257
$a = $graph->createVertex('a');
258258
$b = $graph->createVertex('b');
259259

260-
$edge = $a->createEdgeTo($b);
260+
$edge = $graph->createEdgeDirected($a, $b);
261261
$edge->setWeight(100);
262262
```
263263

@@ -270,7 +270,7 @@ $graph = new Graphp\Graph\Graph();
270270
$a = $graph->createVertex('a');
271271
$b = $graph->createVertex('b');
272272

273-
$edge = $a->createEdgeTo($b);
273+
$edge = $graph->createEdgeDirected($a, $b);
274274
$edge->setFlow(4);
275275
$edge->setCapacity(10);
276276
```
@@ -284,7 +284,7 @@ $graph = new Graphp\Graph\Graph();
284284
$a = $graph->createVertex('a');
285285
$b = $graph->createVertex('b');
286286

287-
$edge = $a->createEdgeTo($b);
287+
$edge = $graph->createEdgeDirected($a, $b);
288288
$edge->setFlow(4);
289289
$edge->setCapacity(null);
290290
$edge->setWeight(100);
@@ -300,7 +300,7 @@ $graph = new Graphp\Graph\Graph();
300300
$a = $graph->createVertex('a');
301301
$b = $graph->createVertex('b');
302302

303-
$edge = $a->createEdgeTo($b);
303+
$edge = $graph->createEdgeDirected($a, $b);
304304
$edge->setAttribute('graphviz.label', 'important');
305305
```
306306

@@ -329,7 +329,7 @@ $a->setAttribute('graphviz.label', GraphViz::raw('<
329329
</table>>'));
330330

331331
$b = $graph->createVertex('Block');
332-
$b->createEdgeTo($a);
332+
$graph->createEdgeDirected($b, $a);
333333
$b->setAttribute('graphviz.shape', 'none');
334334
$b->setAttribute('graphviz.label', GraphViz::raw('<
335335
<table cellspacing="0" border="0" cellborder="1">
@@ -368,7 +368,7 @@ $b->setAttribute('graphviz.shape', 'Mrecord');
368368
$b->setAttribute('graphviz.label', GraphViz::raw('"<f0> left |<f1> middle |<right> right"'));
369369

370370
// a:middle -> b:right
371-
$edge = $a->createEdgeTo($b);
371+
$edge = $graph->createEdgeDirected($a, $b);
372372
$edge->setAttribute('graphviz.tailport', 'middle');
373373
$edge->setAttribute('graphviz.headport', 'right');
374374
```

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-
"graphp/graph": "dev-master#9b4ff as 1.0.0"
13+
"graphp/graph": "dev-master#9ce805c as 1.0.0"
1414
},
1515
"require-dev": {
1616
"phpunit/phpunit": "^6.4 || ^5.7 || ^4.8.35"

examples/01-simple.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
$red = $graph->createVertex('red');
1111
$red->setAttribute('graphviz.color', 'red');
1212

13+
$edge = $graph->createEdgeDirected($blue, $red);
1314
$edge = $blue->createEdgeTo($red);
1415
$edge->setAttribute('graphviz.color', 'grey');
1516

examples/02-html.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
$hello = $graph->createVertex('hello');
1111
$world = $graph->createVertex('wörld');
12-
$hello->createEdgeTo($world);
12+
$graph->createEdgeDirected($hello, $world);
1313

1414
$graphviz = new Graphp\GraphViz\GraphViz();
1515
$graphviz->setFormat('svg');

examples/11-uml-html.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
</table>>'));
1717

1818
$b = $graph->createVertex('Block');
19-
$b->createEdgeTo($a);
19+
$graph->createEdgeDirected($b, $a);
2020
$b->setAttribute('graphviz.shape', 'none');
2121
$b->setAttribute('graphviz.label', GraphViz::raw('<
2222
<table cellspacing="0" border="0" cellborder="1">

examples/12-uml-records.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
$a->setAttribute('graphviz.label', GraphViz::raw('"{\N||+ touch()}"'));
1212

1313
$b = $graph->createVertex('Block');
14-
$b->createEdgeTo($a);
14+
$graph->createEdgeDirected($b, $a);
1515
$b->setAttribute('graphviz.shape', 'record');
1616
$b->setAttribute('graphviz.label', GraphViz::raw('"{\N|- size:int|+ touch()}"'));
1717

examples/13-record-ports.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
$b->setAttribute('graphviz.label', GraphViz::raw('"<f0> left |<f1> middle |<right> right"'));
1616

1717
// a:middle -> b:right
18-
$edge = $a->createEdgeTo($b);
18+
$edge = $graph->createEdgeDirected($a, $b);
1919
$edge->setAttribute('graphviz.tailport', 'middle');
2020
$edge->setAttribute('graphviz.headport', 'right');
2121

tests/GraphVizTest.php

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public function testGraphWithSimpleEdgeUsesGraphWithSimpleEdgeDefinition()
156156
{
157157
// a -- b
158158
$graph = new Graph();
159-
$graph->createVertex('a')->createEdge($graph->createVertex('b'));
159+
$graph->createEdgeUndirected($graph->createVertex('a'), $graph->createVertex('b'));
160160

161161
$expected = <<<VIZ
162162
graph {
@@ -174,8 +174,8 @@ public function testGraphWithLoopUsesGraphWithSimpleLoopDefinition()
174174
// | |
175175
// \--/
176176
$graph = new Graph();
177-
$graph->createVertex('a')->createEdge($graph->createVertex('b'));
178-
$graph->getVertex('b')->createEdge($graph->getVertex('b'));
177+
$graph->createEdgeUndirected($graph->createVertex('a'), $graph->createVertex('b'));
178+
$graph->createEdgeUndirected($graph->getVertex('b'), $graph->getVertex('b'));
179179

180180
$expected = <<<VIZ
181181
graph {
@@ -190,8 +190,9 @@ public function testGraphWithLoopUsesGraphWithSimpleLoopDefinition()
190190

191191
public function testGraphDirectedUsesDigraph()
192192
{
193+
// a -> b
193194
$graph = new Graph();
194-
$graph->createVertex('a')->createEdgeTo($graph->createVertex('b'));
195+
$graph->createEdgeDirected($graph->createVertex('a'), $graph->createVertex('b'));
195196

196197
$expected = <<<VIZ
197198
digraph {
@@ -209,8 +210,8 @@ public function testGraphDirectedWithLoopUsesDigraphWithSimpleLoopDefinition()
209210
// ^ |
210211
// \--/
211212
$graph = new Graph();
212-
$graph->createVertex('a')->createEdgeTo($graph->createVertex('b'));
213-
$graph->getVertex('b')->createEdgeTo($graph->getVertex('b'));
213+
$graph->createEdgeDirected($graph->createVertex('a'), $graph->createVertex('b'));
214+
$graph->createEdgeDirected($graph->getVertex('b'), $graph->getVertex('b'));
214215

215216
$expected = <<<VIZ
216217
digraph {
@@ -227,8 +228,8 @@ public function testGraphMixedUsesDigraphWithExplicitDirectionNoneForUndirectedE
227228
{
228229
// a -> b -- c
229230
$graph = new Graph();
230-
$graph->createVertex('a')->createEdgeTo($graph->createVertex('b'));
231-
$graph->createVertex('c')->createEdge($graph->getVertex('b'));
231+
$graph->createEdgeDirected($graph->createVertex('a'), $graph->createVertex('b'));
232+
$graph->createEdgeUndirected($graph->createVertex('c'), $graph->getVertex('b'));
232233

233234
$expected = <<<VIZ
234235
digraph {
@@ -247,8 +248,8 @@ public function testGraphMixedWithDirectedLoopUsesDigraphWithoutDirectionForDire
247248
// ^ |
248249
// \--/
249250
$graph = new Graph();
250-
$graph->createVertex('a')->createEdge($graph->createVertex('b'));
251-
$graph->getVertex('b')->createEdgeTo($graph->getVertex('b'));
251+
$graph->createEdgeUndirected($graph->createVertex('a'), $graph->createVertex('b'));
252+
$graph->createEdgeDirected($graph->getVertex('b'), $graph->getVertex('b'));
252253

253254
$expected = <<<VIZ
254255
digraph {
@@ -266,8 +267,8 @@ public function testGraphUndirectedWithIsolatedVerticesFirst()
266267
// a -- b -- c d
267268
$graph = new Graph();
268269
$graph->createVertices(array('a', 'b', 'c', 'd'));
269-
$graph->getVertex('a')->createEdge($graph->getVertex('b'));
270-
$graph->getVertex('b')->createEdge($graph->getVertex('c'));
270+
$graph->createEdgeUndirected($graph->getVertex('a'), $graph->getVertex('b'));
271+
$graph->createEdgeUndirected($graph->getVertex('b'), $graph->getVertex('c'));
271272

272273
$expected = <<<VIZ
273274
graph {
@@ -307,11 +308,11 @@ public function testVertexLabels()
307308
public function testEdgeLayoutAtributes()
308309
{
309310
$graph = new Graph();
310-
$graph->createVertex('1a')->createEdge($graph->createVertex('1b'));
311-
$graph->createVertex('2a')->createEdge($graph->createVertex('2b'))->setAttribute('graphviz.numeric', 20);
312-
$graph->createVertex('3a')->createEdge($graph->createVertex('3b'))->setAttribute('graphviz.textual', "forty");
313-
$graph->createVertex('4a')->createEdge($graph->createVertex('4b'))->getAttributeBag()->setAttributes(array('graphviz.1' => 1, 'graphviz.2' => 2));
314-
$graph->createVertex('5a')->createEdge($graph->createVertex('5b'))->getAttributeBag()->setAttributes(array('graphviz.a' => 'b', 'graphviz.c' => 'd'));
311+
$graph->createEdgeUndirected($graph->createVertex('1a'), $graph->createVertex('1b'));
312+
$graph->createEdgeUndirected($graph->createVertex('2a'), $graph->createVertex('2b'))->setAttribute('graphviz.numeric', 20);
313+
$graph->createEdgeUndirected($graph->createVertex('3a'), $graph->createVertex('3b'))->setAttribute('graphviz.textual', "forty");
314+
$graph->createEdgeUndirected($graph->createVertex('4a'), $graph->createVertex('4b'))->getAttributeBag()->setAttributes(array('graphviz.1' => 1, 'graphviz.2' => 2));
315+
$graph->createEdgeUndirected($graph->createVertex('5a'), $graph->createVertex('5b'))->getAttributeBag()->setAttributes(array('graphviz.a' => 'b', 'graphviz.c' => 'd'));
315316

316317
$expected = <<<VIZ
317318
graph {
@@ -330,13 +331,13 @@ public function testEdgeLayoutAtributes()
330331
public function testEdgeLabels()
331332
{
332333
$graph = new Graph();
333-
$graph->createVertex('1a')->createEdge($graph->createVertex('1b'));
334-
$graph->createVertex('2a')->createEdge($graph->createVertex('2b'))->setWeight(20);
335-
$graph->createVertex('3a')->createEdge($graph->createVertex('3b'))->setCapacity(30);
336-
$graph->createVertex('4a')->createEdge($graph->createVertex('4b'))->setFlow(40);
337-
$graph->createVertex('5a')->createEdge($graph->createVertex('5b'))->setFlow(50)->setCapacity(60);
338-
$graph->createVertex('6a')->createEdge($graph->createVertex('6b'))->setFlow(60)->setCapacity(70)->setWeight(80);
339-
$graph->createVertex('7a')->createEdge($graph->createVertex('7b'))->setFlow(70)->setAttribute('graphviz.label', 'prefixed');
334+
$graph->createEdgeUndirected($graph->createVertex('1a'), $graph->createVertex('1b'));
335+
$graph->createEdgeUndirected($graph->createVertex('2a'), $graph->createVertex('2b'))->setWeight(20);
336+
$graph->createEdgeUndirected($graph->createVertex('3a'), $graph->createVertex('3b'))->setCapacity(30);
337+
$graph->createEdgeUndirected($graph->createVertex('4a'), $graph->createVertex('4b'))->setFlow(40);
338+
$graph->createEdgeUndirected($graph->createVertex('5a'), $graph->createVertex('5b'))->setFlow(50)->setCapacity(60);
339+
$graph->createEdgeUndirected($graph->createVertex('6a'), $graph->createVertex('6b'))->setFlow(60)->setCapacity(70)->setWeight(80);
340+
$graph->createEdgeUndirected($graph->createVertex('7a'), $graph->createVertex('7b'))->setFlow(70)->setAttribute('graphviz.label', 'prefixed');
340341

341342
$expected = <<<VIZ
342343
graph {

0 commit comments

Comments
 (0)