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.3.0"}]
end-
Ensure
graphvixis started before your application:
def application do
[applications: [:graphvix]]
endUsage
Alias the included modules for ease of use
iex> 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.iex> Graph.startAdd a single node
iex> Node.new(label: "Start")Add an edge between two existing nodes
iex> node1 = Node.new(label: "Start") iex> node2 = Node.new(label: "End") iex> edge = Edge.new(node1, node2, color: "blue")Update settings to nodes and edges
iex> Node.update(node1.id, color: "red") iex> Edge.update(edge.id, label: "My connector")Show the internal structure of the graph
iex> Graph.get %{ nodes: %{ ... }, edges: %{ ... }, clusters: %{ ... } }Convert the graph to DOT format
iex> 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
iex> Graph.save(:dot) #=> creates G.dot iex> Graph.save(:dot, "my_graph") #=> creates my_graph.dotOr save the Elixir form of the graph to a .txt file
iex> Graph.save(:txt) #=> creates G.txt iex> Graph.save(:txt, "my_graph") #=> creates my_graph.txtCompile the graph to a PDF or PNG
iex> Graph.compile #=> creates G.dot and G.pdf iex> Graph.compile(:png) #=> creates G.dot and G.png iex> Graph.compile("my_graph", :png) #=> creates my_graph.dot and my_graph.pngCompile and open the graph as a PDF/PNG from IEx
iex> Graph.graph #=> creates G.dot and G.pdf; opens G.pdf iex> Graph.graph("my_graph") #=> creates my_graph.dot and my_graph.pdf; opens my_graph.pdf iex> 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.
iex> Graph.load("my_graph.txt")Reset the state of the graph process to an empty graph.
iex> Graph.restart