Graphvix

Graphviz in Elixir

Installation

If available in Hex, the package can be installed as:

  1. Add graphvix to your list of dependencies in mix.exs:
def deps do
[{:graphvix, "~> 0.2.0"}]
end
  1. Ensure graphvix is started before your application:
def application do
[applications: [:graphvix]]
end

Usage

  1. Start up a new process containing your graph

    iex> graph = Graphvix.new
  2. Add a single node

    iex> Graphvix.add_node(graph, label: "Start")
  3. 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")
  4. Update settings to nodes and edges

    iex> Graphvix.update(graph, node1.id, color: "red")
    iex> Graphvix.update(graph, edge.id, label: "My connector")
  5. Show the internal structure of the graph

    iex> Graphvix.get(graph)
    %{
    nodes: %{ ... }
    edges: %{ ... }
    }
  6. 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"];
    }'
  7. Save the graph to a .dot file, with an optional filename

    iex> Graphvix.save(graph) #=> creates G.dot
    iex> Graphvix.save(graph, "my_graph") #=> creates my_graph.dot
  8. Compile the graph to a PDF or PNG

    iex> Graphvix.compile(graph) #=> creates G.dot and G.pdf
    iex> Graphvix.compile(graph, :png) #=> creates G.dot and G.png
  9. Compile and open the graph as a PDF/PNG from IEx

    iex> Graphvix.graph(graph) #=> creates G.dot and G.pdf; opens G.pdf