/** * get label for given $vertex * * @param Vertex $vertex * @return string */ protected function getVertexLabel(Vertex $vertex) { // label defaults to the vertex ID $label = $vertex->getId(); // add balance to label if set $balance = $vertex->getBalance(); if ($balance !== NULL) { if ($balance > 0) { $balance = '+' . $balance; } $label .= ' (' . $balance . ')'; } // add group to label if set // TODO: what does 'if set' mean? groups should not be shown when vertex never had any group assigned (but it defaults to 0) // $group = $vertex->getGroup(); // if ($group !== 0) { // $label .= ' [' . $group .']'; // } return $label; }
private function addBalance(Vertex $vertex, $balance) { $vertex->setBalance($vertex->getBalance() + $balance); }
/** * create a new Vertex in this Graph from the given input Vertex of another graph * * @param Vertex $originalVertex * @return Vertex new vertex in this graph * @throws RuntimeException if vertex with this ID already exists */ public function createVertexClone(Vertex $originalVertex) { $id = $originalVertex->getId(); if ($this->vertices->hasVertexId($id)) { throw new RuntimeException('Id of cloned vertex already exists'); } $newVertex = new Vertex($this, $id); // TODO: properly set attributes of vertex $newVertex->getAttributeBag()->setAttributes($originalVertex->getAttributeBag()->getAttributes()); $newVertex->setBalance($originalVertex->getBalance()); $newVertex->setGroup($originalVertex->getGroup()); return $newVertex; }
protected function getLayoutVertex(Vertex $vertex) { $layout = $vertex->getLayout(); $balance = $vertex->getBalance(); if ($balance !== NULL) { if ($balance > 0) { $balance = '+' . $balance; } if (!isset($layout['label'])) { $layout['label'] = $vertex->getId(); } $layout['label'] .= ' (' . $balance . ')'; } return $layout; }
protected function getLayoutVertex(Vertex $vertex) { $bag = new AttributeBagNamespaced($vertex, 'graphviz.'); $layout = $bag->getAttributes(); $balance = $vertex->getBalance(); if ($balance !== NULL) { if ($balance > 0) { $balance = '+' . $balance; } if (!isset($layout['label'])) { $layout['label'] = $vertex->getId(); } $layout['label'] .= ' (' . $balance . ')'; } return $layout; }