Sha256: 77ce5831c0867d7b33dff38fec5fd27f753457d331573abd41a0f2567a312412

Contents?: true

Size: 1.69 KB

Versions: 16

Compression:

Stored size: 1.69 KB

Contents

$:.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" )

Version data entries

16 entries across 16 versions & 2 rubygems

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