Sha256: 7f269ab448b90c8f61b854eddc48ad33cbbdf39f0dd003085a451dc192801f29

Contents?: true

Size: 768 Bytes

Versions: 6

Compression:

Stored size: 768 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_node(level, depth, parent)
  if depth<@max_depth
    current=[level, depth].join(",")

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

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

add_node(start_level, 0, "00")

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ruby-graphviz-1.0.2 examples/sample58.rb
ruby-graphviz-1.0.1 examples/sample58.rb
ruby-graphviz-1.0.0 examples/sample58.rb
ruby-graphviz-0.9.21 examples/sample58.rb
ruby-graphviz-0.9.20 examples/sample58.rb
ruby-graphviz-0.9.19 examples/sample58.rb