Sha256: d2cd28b8dc8fba18872379441942e7fa516a6a651b9ba7859bd31f14f12e01a9

Contents?: true

Size: 859 Bytes

Versions: 16

Compression:

Stored size: 859 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

16 entries across 16 versions & 1 rubygems

Version Path
aws_security_viz-0.2.5.pre.alpha.pre.26 lib/renderer/graphviz.rb
aws_security_viz-0.2.5.pre.alpha.pre.25 lib/renderer/graphviz.rb
aws_security_viz-0.2.5.pre.alpha.pre.24 lib/renderer/graphviz.rb
aws_security_viz-0.2.5.pre.alpha.pre.23 lib/renderer/graphviz.rb
aws_security_viz-0.2.5.pre.alpha.pre.22 lib/renderer/graphviz.rb
aws_security_viz-0.2.5.pre.alpha.pre.21 lib/renderer/graphviz.rb
aws_security_viz-0.2.4 lib/renderer/graphviz.rb
aws_security_viz-0.2.4.pre.alpha.pre.20 lib/renderer/graphviz.rb
aws_security_viz-0.2.4.pre.alpha.pre.19 lib/renderer/graphviz.rb
aws_security_viz-0.2.4.pre.alpha.pre.18 lib/renderer/graphviz.rb
aws_security_viz-0.2.4.pre.alpha.pre.15 lib/renderer/graphviz.rb
aws_security_viz-0.2.4.pre.alpha.pre.14 lib/renderer/graphviz.rb
aws_security_viz-0.2.4.pre.alpha.pre.13 lib/renderer/graphviz.rb
aws_security_viz-0.2.3 lib/renderer/graphviz.rb
aws_security_viz-0.2.3.pre.alpha.pre.12 lib/renderer/graphviz.rb
aws_security_viz-0.2.3.pre.alpha.pre.11 lib/renderer/graphviz.rb