Skip to content

Commit 7458d1c

Browse files
committed
Output vertex and edge attributes
1 parent ab482c6 commit 7458d1c

File tree

1 file changed

+43
-4
lines changed

1 file changed

+43
-4
lines changed

src/TrivialGraphFormat.php

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,52 @@ public function getOutput(Graph $graph)
5454

5555
protected function getVertexLabel(Vertex $vertex)
5656
{
57-
// TODO: dump additional vertex attributes, such as group, balance, etc.
58-
return $vertex->getId();
57+
// label defaults to the vertex ID
58+
$label = $vertex->getId();
59+
60+
// add balance to label if set
61+
$balance = $vertex->getBalance();
62+
if($balance !== NULL){
63+
if($balance > 0){
64+
$balance = '+' . $balance;
65+
}
66+
$label.= ' (' . $balance . ')';
67+
}
68+
69+
// add group to label if set
70+
// TODO: what does 'if set' mean? groups should not be shown when vertex never had any group assigned (but it defaults to 0)
71+
// $group = $vertex->getGroup();
72+
// if ($group !== 0) {
73+
// $label .= ' [' . $group .']';
74+
// }
75+
76+
return $label;
5977
}
6078

6179
protected function getEdgeLabel(Edge $edge)
6280
{
63-
// TODO: dump additional edge attributes, such as flow, capacity, weight, etc.
64-
return '';
81+
$label = '';
82+
83+
$flow = $edge->getFlow();
84+
$capacity = $edge->getCapacity();
85+
// flow is set
86+
if ($flow !== NULL) {
87+
// NULL capacity = infinite capacity
88+
$label = $flow . '/' . ($capacity === NULL ? '' : $capacity);
89+
// capacity set, but not flow (assume zero flow)
90+
} elseif ($capacity !== NULL) {
91+
$label = '0/' . $capacity;
92+
}
93+
94+
$weight = $edge->getWeight();
95+
// weight is set
96+
if ($weight !== NULL) {
97+
if ($label === '') {
98+
$label = $weight;
99+
} else {
100+
$label .= '/' . $weight;
101+
}
102+
}
103+
return $label;
65104
}
66105
}

0 commit comments

Comments
 (0)