Sha256: 184bced79804260c4a78561be082a08f8bb5db5f095b7cb79bb1156b2199004d

Contents?: true

Size: 847 Bytes

Versions: 23

Compression:

Stored size: 847 Bytes

Contents

require 'graphviz'

module Renderer
  class GraphViz
    def initialize(file_name, config)
      @g = Graphviz::Graph.new('G', {
        overlap: false,
        splines: true,
        sep: 1,
        concentrate: true,
        rankdir: "LR"
      })
      @file_name = file_name
      @config = config
    end

    def add_node(name)
      @g.add_node(name, label: name)
    end

    def add_edge(from, to, opts)
      from_node = create_if_missing(from)
      to_node = create_if_missing(to)
      options =  ({style: 'bold'}).merge(opts)
      from_node.connect(to_node, options)
    end

    def create_if_missing(name)
      n = @g.get_node(name).first
      n.nil? ? add_node(name) : n
    end
    
    def output
      Graphviz::output(@g, path: @file_name, format: nil) #format: nil to force detection based on extension.
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
aws_security_viz-0.1.7.pre.alpha.pre.145 lib/renderer/graphviz.rb
aws_security_viz-0.1.7.pre.alpha.pre.138 lib/renderer/graphviz.rb
aws_security_viz-0.1.7.pre.alpha.pre.136 lib/renderer/graphviz.rb
aws_security_viz-0.1.6.pre.alpha.pre.134 lib/renderer/graphviz.rb
aws_security_viz-0.1.6 lib/renderer/graphviz.rb
aws_security_viz-0.1.5.pre.alpha.pre.133 lib/renderer/graphviz.rb
aws_security_viz-0.1.5.pre.alpha.pre.131 lib/renderer/graphviz.rb
aws_security_viz-0.1.5.pre.alpha.pre.130 lib/renderer/graphviz.rb
aws_security_viz-0.1.5.pre.alpha.pre.112 lib/renderer/graphviz.rb
aws_security_viz-0.1.5.pre.alpha.pre.111 lib/renderer/graphviz.rb
aws_security_viz-0.1.5.pre.alpha.pre.110 lib/renderer/graphviz.rb
aws_security_viz-0.1.5.pre.alpha.pre.109 lib/renderer/graphviz.rb
aws_security_viz-0.1.5.pre.alpha.pre.108 lib/renderer/graphviz.rb
aws_security_viz-0.1.5.pre.alpha.pre.107 lib/renderer/graphviz.rb
aws_security_viz-0.1.5.pre.alpha.pre.106 lib/renderer/graphviz.rb
aws_security_viz-0.1.5.pre.alpha.pre.103 lib/renderer/graphviz.rb
aws_security_viz-0.1.5.pre.alpha.pre.102 lib/renderer/graphviz.rb
aws_security_viz-0.1.5.pre.alpha.pre.101 lib/renderer/graphviz.rb
aws_security_viz-0.1.5.pre.alpha.pre.100 lib/renderer/graphviz.rb
aws_security_viz-0.1.5.pre.alpha.pre.99 lib/renderer/graphviz.rb