ruby-graphviz 1.0.7 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/CHANGELOG.rdoc +4 -0
  2. data/bin/dot2ruby +5 -5
  3. data/bin/gem2gv +18 -18
  4. data/bin/git2gv +20 -20
  5. data/bin/ruby2gv +26 -26
  6. data/bin/xml2gv +5 -5
  7. data/examples/sample06.rb +5 -5
  8. data/examples/sample12.rb +3 -3
  9. data/examples/sample13.rb +8 -8
  10. data/examples/sample14.rb +8 -8
  11. data/examples/sample15.rb +1 -1
  12. data/examples/sample17.rb +7 -7
  13. data/examples/sample19.rb +10 -10
  14. data/examples/sample20.rb +2 -2
  15. data/examples/sample21.rb +1 -1
  16. data/examples/sample28.rb +1 -1
  17. data/examples/sample31.rb +1 -1
  18. data/examples/sample33.rb +10 -10
  19. data/examples/sample34.rb +1 -1
  20. data/examples/sample35.rb +7 -7
  21. data/examples/sample36.rb +2 -2
  22. data/examples/sample40.rb +4 -4
  23. data/examples/sample44.rb +72 -72
  24. data/examples/sample45.rb +4 -4
  25. data/examples/sample48.rb +7 -7
  26. data/examples/sample50.rb +1 -1
  27. data/examples/sample52.rb +2 -2
  28. data/examples/sample53.rb +2 -2
  29. data/examples/sample54.rb +3 -3
  30. data/examples/sample60.rb +2 -2
  31. data/examples/sample61.rb +2 -2
  32. data/examples/sample62.rb +2 -2
  33. data/examples/sample99.rb +15 -15
  34. data/examples/theory/pert.rb +2 -2
  35. data/examples/theory/tests.rb +2 -2
  36. data/lib/graphviz.rb +140 -140
  37. data/lib/graphviz/attrs.rb +6 -11
  38. data/lib/graphviz/constants.rb +35 -35
  39. data/lib/graphviz/core_ext.rb +1 -1
  40. data/lib/graphviz/dot2ruby.rb +7 -7
  41. data/lib/graphviz/dsl.rb +5 -5
  42. data/lib/graphviz/edge.rb +13 -13
  43. data/lib/graphviz/elements.rb +5 -5
  44. data/lib/graphviz/ext.rb +1 -1
  45. data/lib/graphviz/family_tree.rb +15 -15
  46. data/lib/graphviz/family_tree/couple.rb +11 -11
  47. data/lib/graphviz/family_tree/generation.rb +6 -6
  48. data/lib/graphviz/family_tree/person.rb +13 -13
  49. data/lib/graphviz/graphml.rb +39 -39
  50. data/lib/graphviz/math/matrix.rb +23 -23
  51. data/lib/graphviz/node.rb +8 -8
  52. data/lib/graphviz/nothugly.rb +3 -3
  53. data/lib/graphviz/theory.rb +8 -8
  54. data/lib/graphviz/types.rb +3 -3
  55. data/lib/graphviz/types/arrow_type.rb +3 -3
  56. data/lib/graphviz/types/color.rb +2 -2
  57. data/lib/graphviz/types/color_list.rb +2 -2
  58. data/lib/graphviz/types/esc_string.rb +2 -2
  59. data/lib/graphviz/types/gv_bool.rb +3 -3
  60. data/lib/graphviz/types/gv_double.rb +3 -3
  61. data/lib/graphviz/types/html_string.rb +2 -2
  62. data/lib/graphviz/types/lbl_string.rb +2 -2
  63. data/lib/graphviz/types/rect.rb +2 -2
  64. data/lib/graphviz/types/spline_type.rb +9 -9
  65. data/lib/graphviz/utils.rb +13 -13
  66. data/lib/graphviz/utils/colors.rb +35 -35
  67. data/lib/graphviz/xml.rb +24 -24
  68. data/setup.rb +4 -4
  69. data/test/test_graph.rb +9 -9
  70. data/test/test_subgraph.rb +1 -1
  71. data/test/test_theory.rb +4 -4
  72. data/test/test_utils_colors.rb +4 -4
  73. metadata +2 -2
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,9 @@
1
1
  = CHANGELOG
2
2
 
3
+ == 1.0.8 :
4
+ * Cleanup format (by markus1189)
5
+ * Issue #49 : (undefined local variable or method `file' ) (by markus1189)
6
+
3
7
  == 1.0.7 :
4
8
  * Issue #48 : add_graph fails when passed a GraphViz object
5
9
  * Issue #47 : Find executable (by markus1189)
data/bin/dot2ruby CHANGED
@@ -1,16 +1,16 @@
1
1
  #!/usr/bin/env ruby
2
2
  # Copyright (C) 2010 Gregoire Lejeune <gregoire.lejeune@free.fr>
3
- #
3
+ #
4
4
  # This program is free software; you can redistribute it and/or modify
5
5
  # it under the terms of the GNU General Public License as published by
6
6
  # the Free Software Foundation; either version 2 of the License, or
7
7
  # (at your option) any later version.
8
- #
8
+ #
9
9
  # This program is distributed in the hope that it will be useful,
10
10
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
11
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
12
  # GNU General Public License for more details.
13
- #
13
+ #
14
14
  # You should have received a copy of the GNU General Public License
15
15
  # along with this program; if not, write to the Free Software
16
16
  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@@ -20,7 +20,7 @@ require 'graphviz/constants'
20
20
  require 'graphviz/dot2ruby'
21
21
  require 'getoptlong'
22
22
 
23
- def usage
23
+ def usage
24
24
  puts "usage: dot2ruby [-ofile] [-Tformat] [-h] [-V] script"
25
25
  puts "-o, --output-file file Output file"
26
26
  puts "-T, --output-format format Output format (default: nil)"
@@ -83,7 +83,7 @@ end
83
83
 
84
84
  xFile = ARGV[0]
85
85
 
86
- if xFile.nil? == true
86
+ if xFile.nil?
87
87
  usage( )
88
88
  exit
89
89
  end
data/bin/gem2gv CHANGED
@@ -1,16 +1,16 @@
1
1
  #!/usr/bin/env ruby
2
2
  # Copyright (C) 2010 Gregoire Lejeune <gregoire.lejeune@free.fr>
3
- #
3
+ #
4
4
  # This program is free software; you can redistribute it and/or modify
5
5
  # it under the terms of the GNU General Public License as published by
6
6
  # the Free Software Foundation; either version 2 of the License, or
7
7
  # (at your option) any later version.
8
- #
8
+ #
9
9
  # This program is distributed in the hope that it will be useful,
10
10
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
11
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
12
  # GNU General Public License for more details.
13
- #
13
+ #
14
14
  # You should have received a copy of the GNU General Public License
15
15
  # along with this program; if not, write to the Free Software
16
16
  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@@ -22,24 +22,24 @@ require 'getoptlong'
22
22
  class Gem2Gv
23
23
  def initialize( xGVPath, xUse )
24
24
  @oGraph = GraphViz::new( :G, :path => xGVPath, :use => xUse )
25
-
25
+
26
26
  @nodes = []
27
27
  @name = 'gem2gv'
28
28
  end
29
-
29
+
30
30
  def out( xFormat = "dot", xFile = nil )
31
- if xFile.nil? == true
31
+ if xFile.nil?
32
32
  @oGraph.output( xFormat => String )
33
33
  else
34
34
  @oGraph.output( xFormat => xFile )
35
35
  end
36
36
  end
37
-
37
+
38
38
  def go( gemName, version = ">0" )
39
39
  nodes = getDependency(gemName, version)
40
-
40
+
41
41
  createEdges( gemName, version, nodes )
42
-
42
+
43
43
  nodes.each do |node|
44
44
  unless @nodes.include?(node)
45
45
  @nodes << node
@@ -50,22 +50,22 @@ class Gem2Gv
50
50
 
51
51
  def getDependency( gemName, version = ">0" )
52
52
  nodes = []
53
-
53
+
54
54
  dependency = Gem::Dependency.new( gemName, version )
55
55
  fetcher = Gem::SpecFetcher.fetcher
56
-
56
+
57
57
  fetcher.find_matching(dependency).each do |spec_tuple, source_uri|
58
58
  spec = fetcher.fetch_spec spec_tuple, URI.parse(source_uri)
59
-
59
+
60
60
  spec.dependencies.each do |dep|
61
61
  #nodes << { :name => dep.name, :version => dep.version_requirements.to_s} unless nodes.include?({ :name => dep.name, :version => dep.version_requirements.to_s})
62
62
  nodes << { :name => dep.name, :version => ">0" } unless nodes.include?({ :name => dep.name, :version => ">0" })
63
63
  end
64
64
  end
65
-
65
+
66
66
  return nodes
67
67
  end
68
-
68
+
69
69
  def getNode( name, version )
70
70
  #nodeName = "#{name}#{version}"
71
71
  #nodeLabel = "#{name}\n#{version}"
@@ -73,10 +73,10 @@ class Gem2Gv
73
73
  nodeLabel = "#{name}"
74
74
  return @oGraph.get_node(nodeName) || @oGraph.add_nodes( nodeName, "label" => nodeLabel )
75
75
  end
76
-
76
+
77
77
  def createEdges( gemName, version, nodes )
78
78
  nodeA = getNode( gemName, version )
79
-
79
+
80
80
  nodes.each do |node|
81
81
  nodeB = getNode( node[:name], node[:version] )
82
82
  @oGraph.add_edges( nodeA, nodeB )
@@ -84,7 +84,7 @@ class Gem2Gv
84
84
  end
85
85
  end
86
86
 
87
- def usage
87
+ def usage
88
88
  puts "usage: gem2gv [-Tformat] [-ofile] [-h] [-V] gemname"
89
89
  puts "-T, --output-format format Output format (default: PNG)"
90
90
  puts "-o, --output-file file Output file (default: STDOUT)"
@@ -154,7 +154,7 @@ end
154
154
 
155
155
  xGem = ARGV[0]
156
156
 
157
- if xGem.nil? == true
157
+ if xGem.nil?
158
158
  usage( )
159
159
  exit
160
160
  end
data/bin/git2gv CHANGED
@@ -1,16 +1,16 @@
1
1
  #!/usr/bin/env ruby
2
2
  # Copyright (C) 2010 Gregoire Lejeune <gregoire.lejeune@free.fr>
3
- #
3
+ #
4
4
  # This program is free software; you can redistribute it and/or modify
5
5
  # it under the terms of the GNU General Public License as published by
6
6
  # the Free Software Foundation; either version 2 of the License, or
7
7
  # (at your option) any later version.
8
- #
8
+ #
9
9
  # This program is distributed in the hope that it will be useful,
10
10
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
11
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
12
  # GNU General Public License for more details.
13
- #
13
+ #
14
14
  # You should have received a copy of the GNU General Public License
15
15
  # along with this program; if not, write to the Free Software
16
16
  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@@ -23,41 +23,41 @@ class Git2Gv
23
23
  def initialize( xGVPath, xOutFile, xOutFormat, bNothugly )
24
24
  @xGVPath, @xOutFile, @xOutFormat, @bNothugly = xGVPath, xOutFile, xOutFormat.to_sym, bNothugly
25
25
  end
26
-
26
+
27
27
  def run
28
28
  git = GraphViz.new( :G, :path => @xGVPath )
29
-
29
+
30
30
  git.node[:shape => "record"]
31
-
31
+
32
32
  branches.each do |branch|
33
33
  git.add_nodes( branch, :style => "filled", :fillcolor => :lightgrey )
34
34
  end
35
-
35
+
36
36
  commits.each do |commit|
37
- git.add_nodes(
38
- commit[:short],
37
+ git.add_nodes(
38
+ commit[:short],
39
39
  :style => "filled",
40
40
  :fillcolor => :lightblue,
41
- :label => "{ #{commit[:long]} |{ #{commit[:comment].gsub(/\{/, "\\{").gsub(/\}/, "\\}").gsub(/\|/, "\\|").gsub(/</, "\\<").gsub(/>/, "\\>")}}| { #{commit[:commiter]} | #{commit[:date]} } }"
41
+ :label => "{ #{commit[:long]} |{ #{commit[:comment].gsub(/\{/, "\\{").gsub(/\}/, "\\}").gsub(/\|/, "\\|").gsub(/</, "\\<").gsub(/>/, "\\>")}}| { #{commit[:commiter]} | #{commit[:date]} } }"
42
42
  )
43
43
  end
44
-
44
+
45
45
  refs.each do |from, to|
46
46
  git.add_edges( from, to )
47
47
  end
48
-
48
+
49
49
  relations.each do |from, to|
50
50
  git.add_edges( to, from, :dir => "back" )
51
51
  end
52
-
52
+
53
53
  git.output( @xOutFormat => @xOutFile, :nothugly => @bNothugly )
54
54
  end
55
-
55
+
56
56
  # private
57
57
  def cmd(c, &blk)
58
58
  `#{c}`.split($/).map(&blk || proc {|a| a })
59
59
  end
60
-
60
+
61
61
  def commits
62
62
  @commits ||= begin
63
63
  data = []
@@ -74,30 +74,30 @@ class Git2Gv
74
74
  data
75
75
  end
76
76
  end
77
-
77
+
78
78
  def relations
79
79
  @rels ||= cmd("git log --pretty=format:\"%h %p\"") { |l|
80
80
  c, *parents = l.split
81
81
  parents.map {|p| [p, c] }
82
82
  }.flatten(1)
83
83
  end
84
-
84
+
85
85
  def branches
86
86
  @branches ||= cmd("git branch") {|b| b[2..-1] }
87
87
  end
88
-
88
+
89
89
  def refs
90
90
  branches.inject({}) {|h,b|
91
91
  h.tap { h[b] = `git log -1 #{b} --pretty=format:"%h"` }
92
92
  }
93
93
  end
94
-
94
+
95
95
  def current_branch
96
96
  cmd("git branch").select {|l| l =~ /^\*/ }.first.strip[2..-1]
97
97
  end
98
98
  end
99
99
 
100
- def usage
100
+ def usage
101
101
  puts "usage: git2gv [-Tformat] [-ofile] [-h] [-V]"
102
102
  puts "-T, --output-format format Output format (default: png)"
103
103
  puts " --nothugly Use nothugly if SVG output"
data/bin/ruby2gv CHANGED
@@ -1,16 +1,16 @@
1
1
  #!/usr/bin/env ruby
2
2
  # Copyright (C) 2005 - 2012 Gregoire Lejeune <gregoire.lejeune@free.fr>
3
- #
3
+ #
4
4
  # This program is free software; you can redistribute it and/or modify
5
5
  # it under the terms of the GNU General Public License as published by
6
6
  # the Free Software Foundation; either version 2 of the License, or
7
7
  # (at your option) any later version.
8
- #
8
+ #
9
9
  # This program is distributed in the hope that it will be useful,
10
10
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
11
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
12
  # GNU General Public License for more details.
13
- #
13
+ #
14
14
  # You should have received a copy of the GNU General Public License
15
15
  # along with this program; if not, write to the Free Software
16
16
  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@@ -34,7 +34,7 @@ class Rb2Gv
34
34
  @hxEdge = Array::new( )
35
35
  @lxStops = xStops
36
36
  end
37
-
37
+
38
38
  public
39
39
  def parse( xFile )
40
40
  @hxNodes[xFile] = gv_newNode( xFile, "box", "forestgreen" )
@@ -44,38 +44,38 @@ class Rb2Gv
44
44
  end
45
45
 
46
46
  def out( xFormat = "dot", xFile = nil )
47
- if xFile.nil? == true
47
+ if xFile.nil?
48
48
  @oGraph.output( xFormat => String )
49
49
  else
50
50
  @oGraph.output( xFormat => xFile )
51
51
  end
52
52
  end
53
-
53
+
54
54
  private
55
- def gv_newNode( xNode, xShape = "box", xColor = nil )
55
+ def gv_newNode( xNode, xShape = "box", xColor = nil )
56
56
  xNodeName = xNode.gsub( /[^a-zA-Z0-9]/, "_" )
57
- if xColor.nil? == true
57
+ if xColor.nil?
58
58
  @oGraph.add_nodes( xNodeName, "label" => xNode, "shape" => xShape )
59
59
  else
60
60
  @oGraph.add_nodes( xNodeName, "label" => xNode, "shape" => xShape, "style" => "filled", "color" => xColor )
61
61
  end
62
62
  end
63
-
63
+
64
64
  def getLibraryPath( xLib, xExt = ["rb"] )
65
-
65
+
66
66
  xPath = [ "libexecdir", "libdir", "sitedir", "rubylibdir", "sitelibdir", "archdir", "sitedir", "sitearchdir" ]
67
67
  xRbLib = with_config( xLib+'lib', xLib)
68
-
68
+
69
69
  if /\.(rb|so|bundle|dll)$/.match( xRbLib )
70
70
  match = /^(.*)\.([^\.]*)$/.match(xRbLib)
71
71
  xRbFile, xExt = match[1], [match[2]]
72
72
  else
73
73
  xRbFile = xRbLib
74
74
  end
75
-
75
+
76
76
  xExt.each do |e|
77
77
  xRbFileWithExt = xRbFile + "." + e
78
-
78
+
79
79
  # Search in "standard" paths
80
80
  xPath.each do |xDir|
81
81
  xCurrentPath = Config::expand( Config::CONFIG[xDir] )
@@ -84,7 +84,7 @@ class Rb2Gv
84
84
  return xFileFound
85
85
  end
86
86
  end
87
-
87
+
88
88
  # Search in "rubygems" :: This is not utile but...
89
89
  spec = Gem.searcher.find(xLib)
90
90
  unless spec.nil?
@@ -103,10 +103,10 @@ class Rb2Gv
103
103
 
104
104
  return nil
105
105
  end
106
-
106
+
107
107
  def parseFile( xFile, xFromFile = nil, xLib = nil )
108
-
109
- if xFromFile.nil? == false
108
+
109
+ if xFromFile
110
110
  puts "Parse #{xFile} required in #{xFromFile} :" if DEBUG
111
111
  else
112
112
  puts "Parse #{xFile} :" if DEBUG
@@ -115,18 +115,18 @@ class Rb2Gv
115
115
  fp = open( xFile, 'r' )
116
116
  xData = fp.read()
117
117
  fp.close
118
-
118
+
119
119
  xData.each do |xLine|
120
120
  if lxLineMatch = REQUIRE.match( xLine )
121
121
  xRequiredLib = lxLineMatch[2].gsub( /\.(rb|so)$/, "" )
122
-
123
- if @hxNodes.has_key?( xRequiredLib ) == false
122
+
123
+ if not @hxNodes.has_key?( xRequiredLib )
124
124
  puts " + Node #{xRequiredLib}" if DEBUG
125
125
 
126
126
  xRequiredFile = getLibraryPath( xRequiredLib )
127
- if xRequiredFile.nil? == false
127
+ if xRequiredFile
128
128
  unless @lxStops.include?(xRequiredLib)
129
- @hxNodes[xRequiredLib] = gv_newNode( xRequiredLib )
129
+ @hxNodes[xRequiredLib] = gv_newNode( xRequiredLib )
130
130
  parseFile( xRequiredFile, xFile, xRequiredLib )
131
131
  else
132
132
  @hxNodes[xRequiredLib] = gv_newNode( xRequiredLib, "invhouse", "deepskyblue" )
@@ -140,7 +140,7 @@ class Rb2Gv
140
140
  end
141
141
 
142
142
  end
143
-
143
+
144
144
  puts " + Edge #{xLib} -> #{xRequiredLib}" if DEBUG
145
145
  unless @hxEdge.include?( "#{@hxNodes[xLib].id}-#{@hxNodes[xRequiredLib].id}" )
146
146
  @oGraph.add_edges( @hxNodes[xLib], @hxNodes[xRequiredLib] )
@@ -148,12 +148,12 @@ class Rb2Gv
148
148
  end
149
149
  end
150
150
  end
151
-
151
+
152
152
  end
153
153
 
154
154
  end
155
155
 
156
- def usage
156
+ def usage
157
157
  puts "usage: ruby2gv [-Tformat] [-ofile] [-h] [-V] script"
158
158
  puts "-T, --output-format format Output format (default: PNG)"
159
159
  puts "-o, --output-file file Output file (default: STDOUT)"
@@ -226,7 +226,7 @@ end
226
226
 
227
227
  xFile = ARGV[0]
228
228
 
229
- if xFile.nil? == true
229
+ if xFile.nil?
230
230
  usage( )
231
231
  exit
232
232
  end
data/bin/xml2gv CHANGED
@@ -1,16 +1,16 @@
1
1
  #!/usr/bin/env ruby
2
2
  # Copyright (C) 2005 - 2012 Gregoire Lejeune <gregoire.lejeune@free.fr>
3
- #
3
+ #
4
4
  # This program is free software; you can redistribute it and/or modify
5
5
  # it under the terms of the GNU General Public License as published by
6
6
  # the Free Software Foundation; either version 2 of the License, or
7
7
  # (at your option) any later version.
8
- #
8
+ #
9
9
  # This program is distributed in the hope that it will be useful,
10
10
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
11
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
12
  # GNU General Public License for more details.
13
- #
13
+ #
14
14
  # You should have received a copy of the GNU General Public License
15
15
  # along with this program; if not, write to the Free Software
16
16
  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@@ -19,7 +19,7 @@ require 'rubygems'
19
19
  require 'getoptlong'
20
20
  require 'graphviz/xml'
21
21
 
22
- def usage
22
+ def usage
23
23
  puts "usage: xml2gv [-Tformat] [-ofile] [-h] [-V] script"
24
24
  puts "-T, --output-format format Output format (default: PNG)"
25
25
  puts "-o, --output-file file Output file (default: STDOUT)"
@@ -87,7 +87,7 @@ end
87
87
 
88
88
  xFile = ARGV[0]
89
89
 
90
- if xFile.nil? == true
90
+ if xFile.nil?
91
91
  usage( )
92
92
  exit
93
93
  end