Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"rank" tag example #10

Closed
alex263 opened this issue Mar 5, 2010 · 5 comments
Closed

"rank" tag example #10

alex263 opened this issue Mar 5, 2010 · 5 comments

Comments

@alex263
Copy link

alex263 commented Mar 5, 2010

Could you give a hint on how rank tag shall be used - Id like to declare equivalent to dot expression
{ rank = same; "node1"; "node2"; }

@glejeune
Copy link
Owner

glejeune commented Mar 5, 2010

You need to create a subgraph to do this. I'll add anonymous subgraphs support and "blocks" in the next version.

@glejeune
Copy link
Owner

glejeune commented Mar 9, 2010

OK, you can now create anonymous subgraph. For more information, see http://github.com/glejeune/Ruby-Graphviz/blob/master/examples/sample35.rb

@alex263
Copy link
Author

alex263 commented Mar 23, 2010

Originally I tried to play with twopi. Please, have a look -what may be wrong in this sample code I played with. Looks like "rank" has no any effect - all the "planets'" placement do not depend at all on rank

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_node(
  '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']  = g.add_node(
    'Moon',
    :shape => "circle",
    :penwidth => 2,
    :fontsize => 12,
    :style => :filled,
    :fillcolor => "red",
    :label => "Moon\n"
  )
  planets['Earth']  = g.add_node(
    'Earth',
    :shape => "circle",
    :penwidth => 2,
    :fontsize => 12,
    :style => :filled,
    :fillcolor => "blue",
    :label => "Earth\n"
  )
  g.add_edge( planets['Moon'], planets['Earth'],
    :penwidth => 2,
    :labeltooltip => "distance",
    :color => "black"
  )
  g.add_edge( sun, planets['Earth'],
    :penwidth => 2,
    :labeltooltip => "distance",
    :color => "black"
  )

}

# 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|
 
  # set each to its own orbit
  # that doesnt seem to work ...
  g.subgraph { |c|
    c[:rank => "same"]
    planets[p] = g.add_node(
      p,
      :shape => "circle",
      :penwidth => 2,
      :fontsize => 12,
      :fillcolor => "green",
      :style => :filled,
      :label => "#{p}\n"
    )
    g.add_edge( sun, planets[p],
      :penwidth => 2,
      :label => "distance",
      :color => "black"
    )
  }

}

g.output( :svg => "sample36.svg" )
g.output( :dot => "sample36.dot" )

@glejeune
Copy link
Owner

I'm not sure what you espect... But maybe this is better :

require 'rubygems'
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_node(
 '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_node(
   'Moon',
   :shape => "circle",
   :penwidth => 2,
   :fontsize => 12,
   :style => :filled,
   :fillcolor => "red",
   :label => "Moon\n"
 )
 planets['Earth']  = c.add_node(
   'Earth',
   :shape => "circle",
   :penwidth => 2,
   :fontsize => 12,
   :style => :filled,
   :fillcolor => "blue",
   :label => "Earth\n"
 )
 c.add_edge( planets['Moon'], planets['Earth'],
   :penwidth => 2,
   :labeltooltip => "distance",
   :color => "black"
 )
 c.add_edge( sun, planets['Earth'],
   :penwidth => 2,
   :labeltooltip => "distance",
   :color => "black"
 )
}


# 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|
 # set each to its own orbit
 # that doesnt seem to work ...
 g.subgraph { |c|
   c[:rank => "same"]
   planets[p] = c.add_node(
     p,
     :shape => "circle",
     :penwidth => 2,
     :fontsize => 12,
     :fillcolor => "green",
     :style => :filled,
     :label => "#{p}\n"
   )
   c.add_edge( sun, planets[p],
     :penwidth => 2,
     :label => "distance",
     :color => "black"
   )
 }
}
g.output( :svg => "sample36.svg" )
g.output( :dot => "sample36.dot" )

@xor256
Copy link

xor256 commented May 30, 2017

any sample without subgraph?

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants