File: sample37.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 (87 lines) | stat: -rw-r--r-- 1,733 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
$:.unshift( "../lib" )
require "graphviz"

# The goal is to set each planet to its own orbit + set some (earth+moon) to the same orbit

g = GraphViz::new( "Solarsys",
 :type => "digraph",
 :use => "twopi"
)

# the star
sun  = g.add_nodes(
 'Sun',
 :shape => "circle",
 :penwidth => 2,
 :fontsize => 12,
 :style => :filled,
 :fillcolor => "orange",
 :label => "Sun\n"
)

planets = Hash.new

# The Earth and the Moon - in the same subgraph\rank
g.subgraph { |c|
 c[:rank => 'same']
 planets['Moon']  = c.add_nodes(
   'Moon',
   :shape => "circle",
   :penwidth => 2,
   :fontsize => 12,
   :style => :filled,
   :fillcolor => "red",
   :label => "Moon\n"
 )
 planets['Earth']  = c.add_nodes(
   'Earth',
   :shape => "circle",
   :penwidth => 2,
   :fontsize => 12,
   :style => :filled,
   :fillcolor => "blue",
   :label => "Earth\n"
 )
 c.add_edges( planets['Moon'], planets['Earth'],
   :penwidth => 2,
   :labeltooltip => "distance",
   :color => "black"
 )


}

g.add_edges( sun, planets['Earth'],
  :penwidth => 2,
  :labeltooltip => "distance",
  :color => "black"
)

i = 0
# some more planets - each supposed having its own orbit - im trying to do it with rank
['Mercury','Venus','Mars','Jupiter','Saturn','Uranus','Neptune','Pluto'].each { |p|
  i = i + 1
 # set each to its own orbit
 # that doesnt seem to work ...
 g.subgraph { |c|
   c[:rank => "same"]
   planets[p] = c.add_nodes(
     p,
     :shape => "circle",
     :penwidth => 2,
     :fontsize => 12,
     :fillcolor => "green",
     :style => :filled,
     :label => "#{p}\n"
   )
   c.add_edges( sun, planets[p],
     :penwidth => 2,
     :label => "distance",
     :color => "black"
   )
 }

}

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