ntrepid8 / graphvix

Graphviz for Elixir

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Graphvix

Build Status

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.5.0"}]
end

Usage

See the wiki for examples.

  1. Alias the included modules for ease of use

     alias Graphvix.{Graph, Node, Edge, Cluster}
  2. Create a new graph.

    Graph.new(:first_graph)
  3. Add a single node

     Node.new(label: "Start")
  4. 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")
  5. Add a cluster containing one or more nodes

     {cluster_id, _cluster} = Cluster.new([node1_id, node2_id])
  6. Update settings to nodes and edges

     Node.update(node1_id, color: "red")
     Edge.update(edge_id, label: "My connector")
  7. Show the internal structure of the graph

     Graph.get
    %{
       nodes: %{ ... },
       edges: %{ ... },
       clusters: %{ ... },
       attrs: [ ... ]
    }
  8. Convert the graph to DOT format

     Graph.write
    """
    digraph G {
      node_1 [label="Start",color="red"];
      node_2 [label="End"];
    
      node_1 -> node_2 [color="blue",label="My connector"];
    }
    """
  9. Save the graph to a .dot file, with an optional filename

     Graph.save #=> creates "first_graph.dot"
  10. Compile the graph to a PDF or PNG

     Graph.compile #=> creates first_graph.dot and first_graph.pdf
     Graph.compile(:png) #=> creates first_graph.dot and first_graph.png
  11. Compile and open the graph as a PDF/PNG from IEx

     Graph.graph #=> creates first_graph.dot and first_graph.pdf; opens first_graph.pdf
     Graph.graph(:png) #=> creates first_graph.dot and first_graph.png; opens first_graph.png
  12. Load a previously created graph.

     Graph.switch(:old_graph)

About

Graphviz for Elixir

License:MIT License


Languages

Language:Elixir 100.0%