File: sample68.rb

package info (click to toggle)
ruby-graphviz 1.0.8-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,124 kB
  • ctags: 695
  • sloc: ruby: 7,656; xml: 26; makefile: 17
file content (27 lines) | stat: -rw-r--r-- 607 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$:.unshift("../lib")

require 'graphviz'
require 'graphviz/theory'
g = GraphViz.graph(:G)
g.add_nodes(["A", "B", "C", "D", "E", "F", "G"])
g.add_edges("A", ["B", "C", "E"])
g.add_edges("B", ["D", "F"])
g.add_edges("C", "G")
g.add_edges("F", "E")
g.output(:png => "#{$0}000.png")

t = GraphViz::Theory.new(g)
i = 1
t.dfs("A") { |node|
   name = sprintf("%s%03d.png", $0, i)
   node[:color => :lightblue, :style => :filled]
   g.output(:png => name)
   i = i + 1
}

t.bfs("A") { |node|
   name = sprintf("%s%03d.png", $0, i)
   node[:color => :red, :style => :filled]
   g.output(:png => name)
   i = i + 1
}