Documentation

Graph
in package
Uses Attributes

Class representing a graph; this may be a main graph but also a subgraph.

In case of a subgraph: When the name of the subgraph is prefixed with cluster then the contents of this graph will be grouped and a border will be added. Otherwise it is used as logical container to place defaults in.

Table of Contents

$attributes  : array<string|int, Attribute>
$edges  : array<string|int, Edge>
$graphs  : array<string|int, Graph>
$name  : string
$nodes  : array<string|int, Node>
$path  : string
$strict  : bool
$type  : string
__call()  : Attribute|Graph|null
Magic method to provide a getter/setter to add attributes on the Graph.
__get()  : Node|null
Returns the requested node by its name.
__set()  : void
Sets a node using a custom name.
__toString()  : string
Generates a DOT file for use with GraphViz.
addGraph()  : self
Adds a subgraph to this graph; automatically changes the type to subgraph.
create()  : Graph
Factory method to instantiate a Graph so that you can use fluent coding to chain everything.
export()  : self
Exports this graph to a generated image.
findNode()  : Node|null
Finds a node in this graph or any of its subgraphs.
getAttribute()  : Attribute
getGraph()  : self
Returns the subgraph with a given name.
getName()  : string
Returns the name for this Graph.
getType()  : string
Returns the type of this Graph.
hasGraph()  : bool
Checks whether a graph with a certain name already exists.
isStrict()  : bool
link()  : self
Links two nodes to eachother and registers the Edge onto this graph.
setAttribute()  : self
setCenter()  :
setConcentrate()  :
setName()  : self
Sets the name for this graph.
setNode()  : self
Sets a node in the $nodes array; uses the name of the node as index.
setPath()  : self
Sets the path for the execution. Only needed if it is not in the PATH env.
setRank()  :
setRankDir()  :
setRankSep()  :
setSplines()  :
setStrict()  : self
Set if the Graph should be strict. If the graph is strict then multiple edges are not allowed between the same pairs of nodes
setType()  : self
Sets the type for this graph.

Properties

$edges

protected array<string|int, Edge> $edges = []

A list of edges / arrows for this Graph

$graphs

protected array<string|int, Graph> $graphs = []

A list of subgraphs for this Graph

$name

protected string $name = 'G'

Name of this graph

$nodes

protected array<string|int, Node> $nodes = []

A list of nodes for this Graph

$path

protected string $path = ''

The path to execute dot from

$strict

protected bool $strict = false

If the graph is strict then multiple edges are not allowed between the same pairs of nodes

$type

protected string $type = 'digraph'

Type of this graph; may be digraph, graph or subgraph

Methods

__call()

Magic method to provide a getter/setter to add attributes on the Graph.

public __call(string $name, array<string|int, mixed> $arguments) : Attribute|Graph|null

Using this method we make sure that we support any attribute without too much hassle. If the name for this method does not start with get or set we return null.

Set methods return this graph (fluent interface) whilst get methods return the attribute value.

Parameters
$name : string

Name of the method including get/set

$arguments : array<string|int, mixed>

The arguments, should be 1: the value

Tags
throws
AttributeNotFound
Return values
Attribute|Graph|null

__get()

Returns the requested node by its name.

public __get(string $name) : Node|null
Parameters
$name : string

The name of the node to retrieve.

Tags
see
Graph::setNode()
Return values
Node|null

__set()

Sets a node using a custom name.

public __set(string $name, Node $value) : void
Parameters
$name : string

Name of the node.

$value : Node

Node to set on the given name.

Tags
see
Graph::setNode()
Return values
void

__toString()

Generates a DOT file for use with GraphViz.

public __toString() : string

GraphViz is not used in this method; it is safe to call it even without GraphViz installed.

Return values
string

addGraph()

Adds a subgraph to this graph; automatically changes the type to subgraph.

public addGraph(Graph $graph) : self

Please note that an index is maintained using the name of the subgraph. Thus if you have 2 subgraphs with the same name that the first will be overwritten by the latter.

Parameters
$graph : Graph

The graph to add onto this graph as subgraph.

Tags
see
Graph::create()
Return values
self

create()

Factory method to instantiate a Graph so that you can use fluent coding to chain everything.

public static create([string $name = 'G' ][, bool $directional = true ]) : Graph
Parameters
$name : string = 'G'

The name for this graph.

$directional : bool = true

Whether this is a directed or undirected graph.

Return values
Graph

export()

Exports this graph to a generated image.

public export(string $type, string $filename) : self

This is the only method that actually requires GraphViz.

Parameters
$type : string

The type to export to; see the link above for a list of supported types.

$filename : string

The path to write to.

Tags
link
http://www.graphviz.org/content/output-formats
uses

GraphViz/dot

throws
Exception

If an error occurred in GraphViz.

Return values
self

findNode()

Finds a node in this graph or any of its subgraphs.

public findNode(string $name) : Node|null
Parameters
$name : string

Name of the node to find.

Return values
Node|null

getGraph()

Returns the subgraph with a given name.

public getGraph(string $name) : self
Parameters
$name : string

Name of the requested graph.

Return values
self

getName()

Returns the name for this Graph.

public getName() : string
Return values
string

getType()

Returns the type of this Graph.

public getType() : string
Return values
string

hasGraph()

Checks whether a graph with a certain name already exists.

public hasGraph(string $name) : bool
Parameters
$name : string

Name of the graph to find.

Return values
bool

isStrict()

public isStrict() : bool
Return values
bool

Links two nodes to eachother and registers the Edge onto this graph.

public link(Edge $edge) : self
Parameters
$edge : Edge

The link between two classes.

Tags
see
Edge::create()
Return values
self

setAttribute()

public setAttribute(string $name, string $value) : self
Parameters
$name : string
$value : string
Return values
self

setCenter()

public setCenter(string $center) :
Parameters
$center : string
Return values

setConcentrate()

public setConcentrate(string $concentrate) :
Parameters
$concentrate : string
Return values

setName()

Sets the name for this graph.

public setName(string $name) : self

If this is a subgraph you can prefix the name with cluster to group all contained nodes and add a border.

Parameters
$name : string

The new name for this graph.

Return values
self

setNode()

Sets a node in the $nodes array; uses the name of the node as index.

public setNode(Node $node) : self

Nodes can be retrieved by retrieving the property with the same name. Thus 'node1' can be retrieved by invoking: $graph->node1

Parameters
$node : Node

The node to set onto this Graph.

Tags
see
Node::create()
Return values
self

setPath()

Sets the path for the execution. Only needed if it is not in the PATH env.

public setPath(string $path) : self
Parameters
$path : string

The path to execute dot from

Return values
self

setRank()

public setRank(string $rank) :
Parameters
$rank : string
Return values

setRankDir()

public setRankDir(string $rankDir) :
Parameters
$rankDir : string
Return values

setRankSep()

public setRankSep(string $rankSep) :
Parameters
$rankSep : string
Return values

setSplines()

public setSplines(string $splines) :
Parameters
$splines : string
Return values

setStrict()

Set if the Graph should be strict. If the graph is strict then multiple edges are not allowed between the same pairs of nodes

public setStrict(bool $isStrict) : self
Parameters
$isStrict : bool
Return values
self

setType()

Sets the type for this graph.

public setType(string $type) : self
Parameters
$type : string

Must be either "digraph", "graph" or "subgraph".

Tags
throws
InvalidArgumentException

If $type is not "digraph", "graph" or "subgraph".

Return values
self

Search results