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.2.0"}]
end
- Ensure
graphvixis started before your application:
def application do
[applications: [:graphvix]]
end
Usage
-
Start up a new process containing your graph
iex> graph = Graphvix.new -
Add a single node
iex> Graphvix.add_node(graph, label: "Start") -
Add an edge between two existing nodes
iex> node1 = Graphvix.add_node(graph, label: "Start")iex> node2 = Graphvix.add_node(graph, label: "End")iex> edge = Graphvix.add_edge(graph, node1, node2, color: "blue") -
Update settings to nodes and edges
iex> Graphvix.update(graph, node1.id, color: "red")iex> Graphvix.update(graph, edge.id, label: "My connector") -
Show the internal structure of the graph
iex> Graphvix.get(graph)%{nodes: %{ ... }edges: %{ ... }} -
Convert the graph to DOT format
iex> Graphvix.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> Graphvix.save(graph) #=> creates G.dotiex> Graphvix.save(graph, "my_graph") #=> creates my_graph.dot -
Compile the graph to a PDF or PNG
iex> Graphvix.compile(graph) #=> creates G.dot and G.pdfiex> Graphvix.compile(graph, :png) #=> creates G.dot and G.png -
Compile and open the graph as a PDF/PNG from IEx
iex> Graphvix.graph(graph) #=> creates G.dot and G.pdf; opens G.pdf