Graphvix
Graphviz in Elixir
Installation
If available in Hex, the package can be installed as:
-
Add
graphvixto your list of dependencies inmix.exs:
def deps do
[{:graphvix, "~> 0.4.0"}]
endUsage
See the wiki for examples.
Alias the included modules for ease of use
alias Graphvix.{Graph, Node, Edge, Cluster}Start up the graph state process. Currently only one graph can be active at a time. See
Graph.saveandGraph.loadbelow for information about working with multiple graphs.Graph.startAdd a single node
Node.new(label: "Start")Add an edge between two existing nodes
{node1_id, _node} = Node.new(label: "Start") {node2_id, _node} = Node.new(label: "End") {edge_id, _edge} = Edge.new(node1_id, node2_id, color: "blue")Add a cluster containing one or more nodes
{cluster_id, _cluster} = Cluster.new([node1_id, node2_id])Update settings to nodes and edges
Node.update(node1_id, color: "red") Edge.update(edge_id, label: "My connector")Show the internal structure of the graph
Graph.get %{ nodes: %{ ... }, edges: %{ ... }, clusters: %{ ... }, attrs: [ ... ] }Convert the graph to DOT format
Graph.write(graph) 'digraph G { node_1 [label="Start",color="red"]; node_2 [label="End"]; node_1 -> node_2 [color="blue",label="My connector"]; }'Save the graph to a .dot file, with an optional filename
Graph.save(:dot) #=> creates G.dot Graph.save(:dot, "my_graph") #=> creates my_graph.dotOr save the Elixir form of the graph to a .txt file
Graph.save(:txt) #=> creates G.txt Graph.save(:txt, "my_graph") #=> creates my_graph.txtCompile the graph to a PDF or PNG
Graph.compile #=> creates G.dot and G.pdf Graph.compile(:png) #=> creates G.dot and G.png Graph.compile("my_graph", :png) #=> creates my_graph.dot and my_graph.pngCompile and open the graph as a PDF/PNG from IEx
Graph.graph #=> creates G.dot and G.pdf; opens G.pdf Graph.graph("my_graph") #=> creates my_graph.dot and my_graph.pdf; opens my_graph.pdf Graph.graph("G2", :png) #=> creates G2.dot and G2.png; opens G2.pngReload a graph that had been saved as a .txt file. This updates the state of the graph process.
Graph.load("my_graph.txt")Reset the state of the graph process to an empty graph.
Graph.restart