graphvix v0.2.0 Graphvix
Use Graphvix to create a directed graph utilizing GenServer.
Graphvix allows:
- creating a new graph
graph = Graphvix.new
- adding/updating nodes and edges
node1 = Graphvix.add_node(graph, label: "Start")
node2 = Graphvix.add_node(graph, label: "End")
edge = Graphvix.add_edge(graph, node1, node2, color: "red")
Graphvix.update(graph, node1.id, color: "blue")
- saving to a DOT file
Graphvix.save(graph, "my_graph")
- compiling to PDF (also saves the graph as an intermediate step)
Graphvix.graph(graph)
Summary
Functions
Creates a new cluster with the listed nodes
Adds a new edge to the graph between node1 and node2 with the provided attrs
and a generated unique id
Adds a new node to the graph with the provided attrs and a generated unique id
Add one or more nodes to the cluster in the graph
Saves the graph and compiles to the provided filetype
Saves the graph and compiles to the provided filename and filetype
Returns the node or edge in the graph with the provided id
Returns the intetrnal structure of the graph, a map with nested maps for nodes and edges
Save the graph to a DOT file, compile it to the provided filetype, and open the file
Save the graph to a DOT file, compile it to PDF, and open the PDF file
Creates a new graph, and returns a PID pointing to the process managing the graph
Removes the node, edge, or cluster with the provided id from the graph
Remove one or more nodes from the cluster in the graph
Saves the graph to a DOT file with the provided filename (“G” by default)
Updates the attributes for the node or edge in the graph with the provided id
Returns a string representation in .dot format of the graph
Types
Functions
Creates a new cluster with the listed nodes.
Examples
iex> graph = Graphvix.new
iex> node1 = Graphvix.add_node(graph, label: "Start")
iex> node2 = Graphvix.add_node(graph, label: "End")
iex> cluster = Graphvix.add_cluster(graph, [node1, node2])
You can also pass node ids instead of nodes
iex> graph = Graphvix.new
iex> node1 = Graphvix.add_node(graph, label: "Start")
iex> node2 = Graphvix.add_node(graph, label: "End")
iex> cluster = Graphvix.add_cluster(graph, [node1.id, node2.id])
Adds a new edge to the graph between node1 and node2 with the provided attrs
and a generated unique id.
Returns the map containing the edge data
Examples
iex> graph = Graphvix.new
iex> node1 = Graphvix.add_node(graph, label: "Start")
iex> node2 = Graphvix.add_node(graph, label: "End")
iex> Graphvix.add_edge(graph, node1, node2)
%{ id: 3, start_node: 1, end_node: 2, attrs: [] }
You can also pass node ids instead of nodes as the 2nd and 3rd parameters.
iex> graph = Graphvix.new
iex> node1 = Graphvix.add_node(graph, label: "Start")
iex> node2 = Graphvix.add_node(graph, label: "End")
iex> Graphvix.add_edge(graph, node1.id, node2.id)
%{ id: 3, start_node: 1, end_node: 2, attrs: [] }
Adds a new node to the graph with the provided attrs and a generated unique id.
Returns the map containing the id and attributes for the new node.
Examples
iex> graph = Graphvix.new
iex> Graphvix.add_node(graph, label: "First Node", color: "red")
%{ id: 1, attrs: [label: "First Node", color: "red"] }
add_to_cluster(pid, pos_integer, [node_or_id] | node_or_id) :: map
Add one or more nodes to the cluster in the graph.
The third argument can be a single node id or a list of node ids.
Examples
iex> graph = Graphvix.new
iex> node1 = Graphvix.add_node(graph, label: "Start")
iex> node2 = Graphvix.add_node(graph, label: "End")
iex> node3 = Graphvix.add_node(graph, label: "Epilogue")
iex> cluster = Graphvix.add_cluster(graph, [node1, node2])
iex> Graphvix.add_to_cluster(graph, cluster.id, node3.id)
Saves the graph and compiles to the provided filetype.
Examples
iex> graph = Graphvix.new
iex> ...
iex> ...
iex> Graphvix.compile(graph)
Saves the graph and compiles to the provided filename and filetype.
Defaults are G.dot and :pdf
Examples
iex> graph = Graphvix.new
iex> ...
iex> ...
iex> Graphvix.compile(graph)
Returns the node or edge in the graph with the provided id.
Examples
iex> graph = Graphvix.new
iex> node1 = Graphvix.add_node(graph, label: "Start")
iex> Graphvix.find(graph, node1.id) == node1
true
Returns nil if no node or edge is found.
iex> graph = Graphvix.new
iex> Graphvix.find(graph, 3)
nil
Returns the intetrnal structure of the graph, a map with nested maps for nodes and edges.
Examples
iex> graph = Graphvix.new
iex> Graphvix.get(graph)
%{ nodes: %{}, edges: %{} }
Save the graph to a DOT file, compile it to the provided filetype, and open the file.
Examples
iex> graph = Graphvix.new
iex> ...
iex> ...
iex> Graphvix.graph(graph)
:ok
After running this, G.dot and G.pdf will exist in your working directory,
and G.pdf will open in your preferred PDF viewer.
Save the graph to a DOT file, compile it to PDF, and open the PDF file.
Examples
iex> graph = Graphvix.new
iex> ...
iex> ...
iex> Graphvix.graph(graph)
:ok
After running this, G.dot and G.pdf will exist in your working directory,
and G.pdf will open in your preferred PDF viewer.
Creates a new graph, and returns a PID pointing to the process managing the graph.
Examples
iex> graph = Graphvix.new
#PID<0.522.0>
Removes the node, edge, or cluster with the provided id from the graph
iex> graph = Graphvix.new
iex> node1 = Graphvix.add_node(graph, label: "Start")
iex> Graphvix.remove(graph, node1.id)
remove_from_cluster(pid, pos_integer, [node_or_id] | node_or_id) :: map
Remove one or more nodes from the cluster in the graph.
The third argument can be a single node id or a list of node ids.
Examples
iex> graph = Graphvix.new
iex> node1 = Graphvix.add_node(graph, label: "Start")
iex> node2 = Graphvix.add_node(graph, label: "End")
iex> node3 = Graphvix.add_node(graph, label: "Epilogue")
iex> cluster = Graphvix.add_cluster(graph, [node1, node2, node3])
iex> Graphvix.remove_from_cluster(graph, cluster.id, [node1.id, node3.id])
Saves the graph to a DOT file with the provided filename (“G” by default).
Examples
iex> graph = Graphvix.new
iex> ...
iex> ...
iex> Graphvix.save(graph)
:ok
After running this, G.dot will exist in your working directory.
Updates the attributes for the node or edge in the graph with the provided id.
Examples
iex> graph = Graphvix.new
iex> node1 = Graphvix.add_node(graph, label: "Start")
iex> Graphvix.update(graph, node1.id, color: "blue")
iex> Graphvix.find(graph, node1.id)
%{ id: 1, attrs: [label: "Start", color: "blue"] }