require 'graphviz'

module Renderer
  class GraphViz
    def initialize(file_name, config)
      @g = ::GraphViz::new('G', :type => 'strict digraph') { |g|
        g[:overlap] = :false
        g[:splines] = :true
        g[:sep] = 1
        g[:concentrate] = :true
      }
      @file_name = file_name
      @config = config
    end

    def add_node(name)
      @g.add_node(name)
    end

    def add_edge(from, to, opts)
      @g.add_edge(from, to, ({style: 'bold'}).merge(opts))
    end

    def output
      extension = File.extname(@file_name)
      opts = {extension[1..-1].to_sym => @file_name, :use => @config.format}
      @g.output(opts)
    end
  end
end
require 'graphviz'

module Renderer
  class GraphViz
    def initialize(file_name, config)
      @g = ::GraphViz::new('G', :type => 'strict digraph') { |g|
        g[:overlap] = :false
        g[:splines] = :true
        g[:sep] = 1
        g[:concentrate] = :true
        g[:rankdir] = "LR"
      }
      @file_name = file_name
      @config = config
    end

    def add_node(name)
      @g.add_node(name)
    end

    def add_edge(from, to, opts)
      @g.add_edge(from, to, ({style: 'bold'}).merge(opts))
    end

    def output
      extension = File.extname(@file_name)
      opts = {extension[1..-1].to_sym => @file_name, :use => @config.format}
      @g.output(opts)
    end
  end
end

Use add rankdir option to improve the look
Use add rankdir option to improve the look

Right now all networks are source nodes and this way have a rank of 0
means they are all placed on top, side by side. In a network with a lot
of subnets the picture becomes wider which makes it hard to read and
complicated to scroll.

With this change, the graph direction switches from top to down to left
to right and this way subnets will belisted on the left side.
Pictures now become higher instead of wider and become a bit easier to
navigate, since nodes also becomes closer since they take way less
space.

Signed-off-by: Sheogorath <1c2647ce2ee8a4ec8e5c8b1b245ca38f94844bab@shivering-isles.com>
