Sha256: 1a0d5628783fb4bd12ffe32d6a274bf3b40716c4e5b085d4d2fd219340ee97ff

Contents?: true

Size: 857 Bytes

Versions: 118

Compression:

Stored size: 857 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, opts)
      @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

118 entries across 118 versions & 1 rubygems

Version Path
aws_security_viz-0.2.3.pre.alpha.pre.10 lib/renderer/graphviz.rb
aws_security_viz-0.2.2 lib/renderer/graphviz.rb
aws_security_viz-0.2.2.pre.alpha.pre.421 lib/renderer/graphviz.rb
aws_security_viz-0.2.2.pre.alpha.pre.420 lib/renderer/graphviz.rb
aws_security_viz-0.2.2.pre.alpha.pre.419 lib/renderer/graphviz.rb
aws_security_viz-0.2.2.pre.alpha.pre.418 lib/renderer/graphviz.rb
aws_security_viz-0.2.2.pre.alpha.pre.417 lib/renderer/graphviz.rb
aws_security_viz-0.2.2.pre.alpha.pre.416 lib/renderer/graphviz.rb
aws_security_viz-0.2.2.pre.alpha.pre.415 lib/renderer/graphviz.rb
aws_security_viz-0.2.2.pre.alpha.pre.414 lib/renderer/graphviz.rb
aws_security_viz-0.2.2.pre.alpha.pre.413 lib/renderer/graphviz.rb
aws_security_viz-0.2.2.pre.alpha.pre.412 lib/renderer/graphviz.rb
aws_security_viz-0.2.2.pre.alpha.pre.411 lib/renderer/graphviz.rb
aws_security_viz-0.2.2.pre.alpha.pre.408 lib/renderer/graphviz.rb
aws_security_viz-0.2.2.pre.alpha.pre.407 lib/renderer/graphviz.rb
aws_security_viz-0.2.2.pre.alpha.pre.406 lib/renderer/graphviz.rb
aws_security_viz-0.2.2.pre.alpha.pre.405 lib/renderer/graphviz.rb
aws_security_viz-0.2.2.pre.alpha.pre.402 lib/renderer/graphviz.rb
aws_security_viz-0.2.2.pre.alpha.pre.401 lib/renderer/graphviz.rb
aws_security_viz-0.2.2.pre.alpha.pre.400 lib/renderer/graphviz.rb