mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* CR stripped.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7137 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
61edd31bf6
commit
6b8e5b303f
1 changed files with 25 additions and 25 deletions
|
@ -1,15 +1,15 @@
|
||||||
module DOT
|
module DOT
|
||||||
|
|
||||||
# these glogal vars are used to make nice graph source
|
# these glogal vars are used to make nice graph source
|
||||||
$tab = ' '
|
$tab = ' '
|
||||||
$tab2 = $tab * 2
|
$tab2 = $tab * 2
|
||||||
|
|
||||||
# if we don't like 4 spaces, we can change it any time
|
# if we don't like 4 spaces, we can change it any time
|
||||||
def change_tab( t )
|
def change_tab( t )
|
||||||
$tab = t
|
$tab = t
|
||||||
$tab2 = t * 2
|
$tab2 = t * 2
|
||||||
end
|
end
|
||||||
|
|
||||||
# options for node declaration
|
# options for node declaration
|
||||||
NODE_OPTS = [
|
NODE_OPTS = [
|
||||||
'bgcolor',
|
'bgcolor',
|
||||||
|
@ -27,7 +27,7 @@ module DOT
|
||||||
'style',
|
'style',
|
||||||
'URL',
|
'URL',
|
||||||
]
|
]
|
||||||
|
|
||||||
# options for edge declaration
|
# options for edge declaration
|
||||||
EDGE_OPTS = [
|
EDGE_OPTS = [
|
||||||
'color',
|
'color',
|
||||||
|
@ -45,7 +45,7 @@ module DOT
|
||||||
'style',
|
'style',
|
||||||
'weight'
|
'weight'
|
||||||
]
|
]
|
||||||
|
|
||||||
# options for graph declaration
|
# options for graph declaration
|
||||||
GRAPH_OPTS = [
|
GRAPH_OPTS = [
|
||||||
'bgcolor',
|
'bgcolor',
|
||||||
|
@ -75,7 +75,7 @@ module DOT
|
||||||
'style',
|
'style',
|
||||||
'URL'
|
'URL'
|
||||||
]
|
]
|
||||||
|
|
||||||
# a root class for any element in dot notation
|
# a root class for any element in dot notation
|
||||||
class DOTSimpleElement
|
class DOTSimpleElement
|
||||||
attr_accessor :name
|
attr_accessor :name
|
||||||
|
@ -88,7 +88,7 @@ module DOT
|
||||||
@name
|
@name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# an element that has options ( node, edge or graph )
|
# an element that has options ( node, edge or graph )
|
||||||
class DOTElement < DOTSimpleElement
|
class DOTElement < DOTSimpleElement
|
||||||
#attr_reader :parent
|
#attr_reader :parent
|
||||||
|
@ -96,7 +96,7 @@ module DOT
|
||||||
|
|
||||||
def initialize( params = {}, option_list = [] )
|
def initialize( params = {}, option_list = [] )
|
||||||
super( params )
|
super( params )
|
||||||
@name = params['name'] ? params['name'] : nil
|
@name = params['name'] ? params['name'] : nil
|
||||||
@parent = params['parent'] ? params['parent'] : nil
|
@parent = params['parent'] ? params['parent'] : nil
|
||||||
@options = {}
|
@options = {}
|
||||||
option_list.each{ |i|
|
option_list.each{ |i|
|
||||||
|
@ -104,7 +104,7 @@ module DOT
|
||||||
}
|
}
|
||||||
@options['label'] ||= @name if @name != 'node'
|
@options['label'] ||= @name if @name != 'node'
|
||||||
end
|
end
|
||||||
|
|
||||||
def each_option
|
def each_option
|
||||||
@options.each{ |i| yield i }
|
@options.each{ |i| yield i }
|
||||||
end
|
end
|
||||||
|
@ -118,13 +118,13 @@ module DOT
|
||||||
# @parent = thing
|
# @parent = thing
|
||||||
#end
|
#end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# this is used when we build nodes that have shape=record
|
# this is used when we build nodes that have shape=record
|
||||||
# ports don't have options :)
|
# ports don't have options :)
|
||||||
class DOTPort < DOTSimpleElement
|
class DOTPort < DOTSimpleElement
|
||||||
attr_accessor :label
|
attr_accessor :label
|
||||||
|
|
||||||
def initialize( params = {} )
|
def initialize( params = {} )
|
||||||
super( params )
|
super( params )
|
||||||
@name = params['label'] ? params['label'] : ''
|
@name = params['label'] ? params['label'] : ''
|
||||||
|
@ -133,7 +133,7 @@ module DOT
|
||||||
( @name && @name != "" ? "<#{@name}>" : "" ) + "#{@label}"
|
( @name && @name != "" ? "<#{@name}>" : "" ) + "#{@label}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# node element
|
# node element
|
||||||
class DOTNode < DOTElement
|
class DOTNode < DOTElement
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ module DOT
|
||||||
def to_s( t = '' )
|
def to_s( t = '' )
|
||||||
|
|
||||||
label = @options['shape'] != 'record' && @ports.length == 0 ?
|
label = @options['shape'] != 'record' && @ports.length == 0 ?
|
||||||
@options['label'] ?
|
@options['label'] ?
|
||||||
t + $tab + "label = \"#{@options['label']}\"\n" :
|
t + $tab + "label = \"#{@options['label']}\"\n" :
|
||||||
'' :
|
'' :
|
||||||
t + $tab + 'label = "' + " \\\n" +
|
t + $tab + 'label = "' + " \\\n" +
|
||||||
|
@ -170,14 +170,14 @@ module DOT
|
||||||
t + $tab2 + i.to_s
|
t + $tab2 + i.to_s
|
||||||
}.join( "| \\\n" ) + " \\\n" +
|
}.join( "| \\\n" ) + " \\\n" +
|
||||||
t + $tab + '"' + "\n"
|
t + $tab + '"' + "\n"
|
||||||
|
|
||||||
t + "#{@name} [\n" +
|
t + "#{@name} [\n" +
|
||||||
@options.to_a.collect{ |i|
|
@options.to_a.collect{ |i|
|
||||||
i[1] && i[0] != 'label' ?
|
i[1] && i[0] != 'label' ?
|
||||||
t + $tab + "#{i[0]} = #{i[1]}" : nil
|
t + $tab + "#{i[0]} = #{i[1]}" : nil
|
||||||
}.compact.join( ",\n" ) + ( label != '' ? ",\n" : "\n" ) +
|
}.compact.join( ",\n" ) + ( label != '' ? ",\n" : "\n" ) +
|
||||||
label +
|
label +
|
||||||
t + "]\n"
|
t + "]\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -198,7 +198,7 @@ module DOT
|
||||||
def << ( thing )
|
def << ( thing )
|
||||||
@nodes << thing
|
@nodes << thing
|
||||||
end
|
end
|
||||||
|
|
||||||
def push( thing )
|
def push( thing )
|
||||||
@nodes.push( thing )
|
@nodes.push( thing )
|
||||||
end
|
end
|
||||||
|
@ -211,14 +211,14 @@ module DOT
|
||||||
hdr = t + "#{@dot_string} #{@name} {\n"
|
hdr = t + "#{@dot_string} #{@name} {\n"
|
||||||
|
|
||||||
options = @options.to_a.collect{ |name, val|
|
options = @options.to_a.collect{ |name, val|
|
||||||
val && name != 'label' ?
|
val && name != 'label' ?
|
||||||
t + $tab + "#{name} = #{val}" :
|
t + $tab + "#{name} = #{val}" :
|
||||||
name ? t + $tab + "#{name} = \"#{val}\"" : nil
|
name ? t + $tab + "#{name} = \"#{val}\"" : nil
|
||||||
}.compact.join( "\n" ) + "\n"
|
}.compact.join( "\n" ) + "\n"
|
||||||
|
|
||||||
nodes = @nodes.collect{ |i|
|
nodes = @nodes.collect{ |i|
|
||||||
i.to_s( t + $tab )
|
i.to_s( t + $tab )
|
||||||
}.join( "\n" ) + "\n"
|
}.join( "\n" ) + "\n"
|
||||||
hdr + options + nodes + t + "}\n"
|
hdr + options + nodes + t + "}\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -239,12 +239,12 @@ module DOT
|
||||||
@from = params['from'] ? params['from'] : nil
|
@from = params['from'] ? params['from'] : nil
|
||||||
@to = params['to'] ? params['to'] : nil
|
@to = params['to'] ? params['to'] : nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s( t = '' )
|
def to_s( t = '' )
|
||||||
t + "#{@from} -> #{to} [\n" +
|
t + "#{@from} -> #{to} [\n" +
|
||||||
@options.to_a.collect{ |i|
|
@options.to_a.collect{ |i|
|
||||||
i[1] && i[0] != 'label' ?
|
i[1] && i[0] != 'label' ?
|
||||||
t + $tab + "#{i[0]} = #{i[1]}" :
|
t + $tab + "#{i[0]} = #{i[1]}" :
|
||||||
i[1] ? t + $tab + "#{i[0]} = \"#{i[1]}\"" : nil
|
i[1] ? t + $tab + "#{i[0]} = \"#{i[1]}\"" : nil
|
||||||
}.compact.join( "\n" ) + "\n" + t + "]\n"
|
}.compact.join( "\n" ) + "\n" + t + "]\n"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue