Sha256: 9bbb649078866877279a1f362e67e7f718312d6dcebc8bba82536e360ddee84c

Contents?: true

Size: 775 Bytes

Versions: 13

Compression:

Stored size: 775 Bytes

Contents

#!/usr/bin/ruby

# By Jonas Elfström - http://github.com/jonelf
$:.unshift( "../lib" )
require 'graphviz'

@min_level=1
@max_level=12
@max_depth=10
start_level=6

@g = GraphViz.new(:G, :type => "strict digraph")
# or @g = GraphViz.new(:G, :type => "digraph", :strict => true)
# or @g = GraphViz.digraph(:G, :strict => true)
# or @g = GraphViz.strict_digraph(:G)

def add_nodes(level, depth, parent)
  if depth<@max_depth
    current=[level, depth].join(",")

    sub=level<=>@min_level
    add=@max_level<=>level
    add_nodes(level-sub, depth+1, current)
    add_nodes(level+add, depth+1, current)

    @g.add_nodes(current).label=level.to_s
    @g.add_edges(parent, current) unless parent=="00"
  end
end

add_nodes(start_level, 0, "00")

@g.output( :png => "#{$0}.png" )

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
ruby-graphviz-1.2.2 examples/sample58.rb
ruby-graphviz-1.2.1 examples/sample58.rb
ruby-graphviz-1.2.0 examples/sample58.rb
ruby-graphviz-1.1.0 examples/sample58.rb
ruby-graphviz_c-1.1.1 examples/sample58.rb
ruby-graphviz_c-1.1.0 examples/sample58.rb
ruby-graphviz-1.0.9 examples/sample58.rb
ruby-graphviz-1.0.8 examples/sample58.rb
ruby-graphviz-1.0.7 examples/sample58.rb
ruby-graphviz-1.0.6 examples/sample58.rb
ruby-graphviz-1.0.5 examples/sample58.rb
ruby-graphviz-1.0.4 examples/sample58.rb
ruby-graphviz-1.0.3 examples/sample58.rb