ruby-graphviz 0.9.3 → 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/ChangeLog CHANGED
@@ -1,3 +1,8 @@
1
+ 0.9.4 :
2
+ * Escape nodes and edges attributs
3
+ * GraphViz::escape corrections (by Dave Burt)
4
+ * Add :errors option to set level of message suppression (default : suppress warning messages)
5
+
1
6
  0.9.3 :
2
7
  * Minor bug correction for Windows
3
8
  * Use Open3.popen3 if installed, else use IO.popen (by Dave Burt)
@@ -33,7 +33,7 @@ The same but with a block
33
33
  require 'graphviz'
34
34
 
35
35
  GraphViz::new( :G, :type => :digraph ) { |g|
36
- g.world( :label => "World" ) << g.hello( :label => Hello )
36
+ g.world( :label => "World" ) << g.hello( :label => "Hello" )
37
37
  }.output( :png => "hello_world.png" )
38
38
 
39
39
  Create a graph from a file
@@ -58,6 +58,8 @@ Create a graph from a file
58
58
 
59
59
  You also need to install GraphViz[http://www.graphviz.org] and Treetop[http://treetop.rubyforge.org/]
60
60
 
61
+ On *Windows* you also need to install win32-open3. This is not an absolute requirement.
62
+
61
63
  == LICENCE
62
64
 
63
65
  Ruby/GraphViz is freely distributable according to the terms of the
@@ -59,4 +59,4 @@ GraphViz::new( "TrafficLights", :type => :digraph ) { |g|
59
59
  g[:overlap] = :false
60
60
  g[:label] = 'PetriNet Model TrafficLights\nExtracted from ConceptBase and layed out by Graphviz'
61
61
  g[:fontsize] = 12;
62
- }.output( :png => "TrafficLights.png" )
62
+ }.output( :errors => 1, :png => "TrafficLights.png" )
@@ -1,32 +1,85 @@
1
1
  #!/bin/sh
2
2
 
3
- ruby shapes.rb $1
3
+ echo "arrowhead.rb"
4
4
  ruby arrowhead.rb $1
5
+ echo "HTML-Labels.rb"
6
+ ruby HTML-Labels.rb
7
+ echo "p2p.rb"
8
+ ruby p2p.rb $1
5
9
 
10
+ echo "sample01.rb"
6
11
  ruby sample01.rb $1
12
+ echo "sample02.rb"
7
13
  ruby sample02.rb $1
14
+ echo "sample03.rb"
8
15
  ruby sample03.rb $1
16
+ echo "sample04.rb"
9
17
  ruby sample04.rb $1
18
+ echo "sample05.rb"
10
19
  ruby sample05.rb $1
11
-
20
+ echo "sample06.rb"
21
+ ruby sample06.rb
22
+ echo "sample07.rb"
12
23
  ruby sample07.rb $1
24
+ echo "sample08.rb"
13
25
  ruby sample08.rb $1
26
+ echo "sample09.rb"
14
27
  ruby sample09.rb $1
28
+ echo "sample10.rb"
15
29
  ruby sample10.rb $1
30
+ echo "sample11.rb"
16
31
  ruby sample11.rb $1
32
+ echo "sample12.rb"
17
33
  ruby sample12.rb $1
34
+ echo "sample13.rb"
18
35
  ruby sample13.rb
36
+ echo "sample14.rb"
19
37
  ruby sample14.rb
38
+ echo "sample15.rb"
20
39
  ruby sample15.rb
40
+ echo "sample16.rb"
21
41
  ruby sample16.rb
42
+ echo "sample17.rb"
22
43
  ruby sample17.rb
44
+ echo "sample18.rb"
23
45
  ruby sample18.rb
46
+ echo "sample19.rb"
24
47
  ruby sample19.rb
48
+ echo "sample20.rb"
25
49
  ruby sample20.rb
50
+ echo "sample21.rb"
26
51
  ruby sample21.rb
52
+ echo "sample22.rb"
27
53
  ruby sample22.rb
54
+ echo "sample23.rb"
28
55
  ruby sample23.rb
56
+ echo "sample24.rb"
57
+ ruby sample24.rb
58
+ echo "sample25.rb"
59
+ ruby sample25.rb
29
60
 
61
+ echo "shapes.rb"
62
+ ruby shapes.rb $1
63
+ echo "testorder.rb"
30
64
  ruby testorder.rb $1
65
+ echo "testxml.rb"
31
66
  ruby testxml.rb $1
32
- ruby HTML-Labels.rb
67
+
68
+ cd dot
69
+ pwd
70
+ echo "dot/hello_test.rb"
71
+ ruby hello_test.rb
72
+ cd ..
73
+
74
+ cd graphviz.org
75
+ echo "graphviz.org/cluster.rb"
76
+ ruby cluster.rb
77
+ echo "graphviz.org/hello_world.rb"
78
+ ruby hello_world.rb
79
+ echo "graphviz.org/lion_share.rb"
80
+ ruby lion_share.rb
81
+ echo "graphviz.org/process.rb"
82
+ ruby process.rb
83
+ echo "graphviz.org/TrafficLights.rb"
84
+ ruby TrafficLights.rb
85
+ cd ..
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/ruby
2
+
3
+ $:.unshift( "../lib" );
4
+ require "graphviz"
5
+
6
+ GraphViz::new( "G" ) { |g|
7
+ g.hello << g.world
8
+ g.bonjour( :label => '"Bonjour"' ) - g.monde( :label => "Le\nmonde")
9
+ g.hola > g.mundo
10
+ g.holla >> g.welt
11
+ }.output( :path => "/usr/local/bin", :png => "#{$0}.png" )
@@ -41,6 +41,9 @@ class GraphViz
41
41
  ## Var: program path
42
42
  @@path = nil
43
43
  @path
44
+ ## Var: Error level
45
+ @@errors = 1
46
+ @errors
44
47
 
45
48
  ## Var: Graph name
46
49
  @name
@@ -62,8 +65,8 @@ class GraphViz
62
65
  # Create a new node
63
66
  #
64
67
  # In:
65
- # xNodeName : Name of the new node
66
- # *hOpt : Node attributs
68
+ # * xNodeName : Name of the new node
69
+ # * *hOpt : Node attributs
67
70
  #
68
71
  # Return the GraphViz::Node object created
69
72
  #
@@ -100,9 +103,9 @@ class GraphViz
100
103
  # Create a new edge
101
104
  #
102
105
  # In:
103
- # oNodeOne : First node (or node list)
104
- # oNodeTwo : Second Node (or node list)
105
- # *hOpt : Edge attributs
106
+ # * oNodeOne : First node (or node list)
107
+ # * oNodeTwo : Second Node (or node list)
108
+ # * *hOpt : Edge attributs
106
109
  #
107
110
  def add_edge( oNodeOne, oNodeTwo, *hOpt )
108
111
 
@@ -137,11 +140,11 @@ class GraphViz
137
140
  end
138
141
 
139
142
  #
140
- # Create à new graph
143
+ # Create a new graph
141
144
  #
142
145
  # In:
143
- # xGraphName : Graph name
144
- # *hOpt : Graph attributs
146
+ # * xGraphName : Graph name
147
+ # * *hOpt : Graph attributs
145
148
  #
146
149
  def add_graph( xGraphName, *hOpt )
147
150
  @hoGraphs[xGraphName] = GraphViz::new( xGraphName, :parent => self, :type => @oGraphType )
@@ -231,14 +234,18 @@ class GraphViz
231
234
  # Generate the graph
232
235
  #
233
236
  # Options :
234
- # :output : Output format (Constants::FORMATS)
235
- # :file : Output file name
236
- # :use : Program to use (Constants::PROGRAMS)
237
- # :path : Program PATH
238
- # :<format> => <file> : <file> can be
239
- # * a file name
240
- # * nil, then the output will be printed to STDOUT
241
- # * String, then the output will be returned as a String
237
+ # * :output : Output format (Constants::FORMATS)
238
+ # * :file : Output file name
239
+ # * :use : Program to use (Constants::PROGRAMS)
240
+ # * :path : Program PATH
241
+ # * :<format> => <file> : <file> can be
242
+ # * a file name
243
+ # * nil, then the output will be printed to STDOUT
244
+ # * String, then the output will be returned as a String
245
+ # * :errors : DOT error level (default 1)
246
+ # * 0 = Error + Warning
247
+ # * 1 = Error
248
+ # * 2 = none
242
249
  #
243
250
  def output( *hOpt )
244
251
  xDOTScript = ""
@@ -341,6 +348,8 @@ class GraphViz
341
348
  @prog = xValue
342
349
  when "path"
343
350
  @path = xValue
351
+ when "errors"
352
+ @errors = xValue
344
353
  else
345
354
  if FORMATS.index( xKey.to_s ).nil? == true
346
355
  raise ArgumentError, "output format '#{xValue}' invalid"
@@ -393,7 +402,7 @@ class GraphViz
393
402
 
394
403
  #xCmd = "#{cmd} #{xOutputWithFile} #{xOutputWithoutFile} #{t.path}"
395
404
  #if /Windows/.match( ENV['OS'] )
396
- xCmd = "\"#{cmd}\" #{xOutputWithFile} #{xOutputWithoutFile} #{t.path}"
405
+ xCmd = "\"#{cmd}\" -q#{@errors} #{xOutputWithFile} #{xOutputWithoutFile} #{t.path}"
397
406
  #end
398
407
 
399
408
  output_from_command( xCmd )
@@ -492,7 +501,7 @@ class GraphViz
492
501
  ## ----------------------------------------------------------------------------
493
502
 
494
503
  #
495
- # Change default options (:use, :path and :output)
504
+ # Change default options (:use, :path, :errors and :output)
496
505
  #
497
506
  def self.default( hOpts )
498
507
  hOpts.each do |k, v|
@@ -501,6 +510,8 @@ class GraphViz
501
510
  @@prog = v
502
511
  when "path"
503
512
  @@path = v
513
+ when "errors"
514
+ @@errors = v
504
515
  when "output"
505
516
  warn ":output option is deprecated!"
506
517
  @@format = v
@@ -520,12 +531,12 @@ class GraphViz
520
531
  # Create a new graph from a GraphViz File
521
532
  #
522
533
  # Options :
523
- # :output : Output format (Constants::FORMATS) (default : dot)
524
- # :file : Output file name (default : none)
525
- # :use : Program to use (Constants::PROGRAMS) (default : dot)
526
- # :path : Program PATH
527
- # :parent : Parent graph (default : none)
528
- # :type : Graph type (Constants::GRAPHTYPE) (default : digraph)
534
+ # * :output : Output format (Constants::FORMATS) (default : dot)
535
+ # * :file : Output file name (default : none)
536
+ # * :use : Program to use (Constants::PROGRAMS) (default : dot)
537
+ # * :path : Program PATH
538
+ # * :parent : Parent graph (default : none)
539
+ # * :type : Graph type (Constants::GRAPHTYPE) (default : digraph)
529
540
  #
530
541
  def self.parse( xFile, *hOpts, &block )
531
542
  g = GraphViz::Parser.parse( xFile, hOpts[0], &block )
@@ -551,12 +562,16 @@ class GraphViz
551
562
  # Create a new graph object
552
563
  #
553
564
  # Options :
554
- # :output : Output format (Constants::FORMATS) (default : dot)
555
- # :file : Output file name (default : none)
556
- # :use : Program to use (Constants::PROGRAMS) (default : dot)
557
- # :path : Program PATH
558
- # :parent : Parent graph (default : none)
559
- # :type : Graph type (Constants::GRAPHTYPE) (default : digraph)
565
+ # * :output : Output format (Constants::FORMATS) (default : dot)
566
+ # * :file : Output file name (default : none)
567
+ # * :use : Program to use (Constants::PROGRAMS) (default : dot)
568
+ # * :path : Program PATH
569
+ # * :parent : Parent graph (default : none)
570
+ # * :type : Graph type (Constants::GRAPHTYPE) (default : digraph)
571
+ # * :errors : DOT error level (default 1)
572
+ # * 0 = Error + Warning
573
+ # * 1 = Error
574
+ # * 2 = none
560
575
  #
561
576
  def initialize( xGraphName, *hOpt, &block )
562
577
  @filename = nil
@@ -564,6 +579,7 @@ class GraphViz
564
579
  @format = @@format
565
580
  @prog = @@prog
566
581
  @path = @@path
582
+ @errors = @@errors
567
583
  @output = {}
568
584
 
569
585
  @elements_order = Array::new()
@@ -605,6 +621,8 @@ class GraphViz
605
621
  @oGraphType = xValue.to_s
606
622
  when "path"
607
623
  @path = xValue.to_s
624
+ when "errors"
625
+ @errors = xValue
608
626
  else
609
627
  self[xKey.to_s] = xValue.to_s
610
628
  end
@@ -617,8 +635,8 @@ class GraphViz
617
635
  #
618
636
  # Escape a string to be acceptable as a node name in a graphviz input file
619
637
  #
620
- def self.escape(str) #:nodoc:
621
- if str.match( /^[a-zA-Z_]+[a-zA-Z0-9_:\.]*$/ ).nil?
638
+ def self.escape(str, force = false) #:nodoc:
639
+ if force or str.match( /\A[a-zA-Z_]+[a-zA-Z0-9_:\.]*\Z/ ).nil?
622
640
  '"' + str.gsub('"', '\\"').gsub("\n", '\\\\n') + '"'
623
641
  else
624
642
  str
@@ -15,7 +15,7 @@
15
15
  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
16
 
17
17
  module Constants
18
- RGV_VERSION = "0.9.3"
18
+ RGV_VERSION = "0.9.4"
19
19
 
20
20
  ## Const: Output formats
21
21
  FORMATS = [
@@ -29,9 +29,9 @@ class GraphViz
29
29
  # Create a new edge
30
30
  #
31
31
  # In:
32
- # vNodeOne : First node
33
- # vNodeTwo : Second node
34
- # oGParrent : Graph
32
+ # * vNodeOne : First node
33
+ # * vNodeTwo : Second node
34
+ # * oGParrent : Graph
35
35
  #
36
36
  def initialize( vNodeOne, vNodeTwo, oGParrent = nil )
37
37
  if vNodeOne.class == String
@@ -71,9 +71,9 @@ class GraphViz
71
71
 
72
72
  GraphViz::commonGraph( oNode, n ).add_edge( n, oNode )
73
73
  end
74
- alias :> :<<
75
- alias :- :<<
76
- alias :>> :<<
74
+ alias :> :<< #:nodoc:
75
+ alias :- :<< #:nodoc:
76
+ alias :>> :<< #:nodoc:
77
77
 
78
78
  #
79
79
  # Set edge attributs
@@ -116,7 +116,7 @@ class GraphViz
116
116
  xAttr = ""
117
117
  xSeparator = ""
118
118
  @oAttrEdge.data.each do |k, v|
119
- xAttr << xSeparator + k + " = \"" + v + "\""
119
+ xAttr << xSeparator + k + " = " + GraphViz.escape(v, true)
120
120
  xSeparator = ", "
121
121
  end
122
122
  if xAttr.length > 0
@@ -28,8 +28,8 @@ class GraphViz
28
28
  # Create a new node
29
29
  #
30
30
  # In:
31
- # xNodeName : Name of the node
32
- # oGParrent : Graph
31
+ # * xNodeName : Name of the node
32
+ # * oGParrent : Graph
33
33
  #
34
34
  def initialize( xNodeName, oGParrent = nil )
35
35
  @xNodeName = xNodeName
@@ -114,7 +114,7 @@ class GraphViz
114
114
  if k == "html"
115
115
  xAttr << xSeparator + "label = <" + v + ">"
116
116
  else
117
- xAttr << xSeparator + k + " = \"" + v + "\""
117
+ xAttr << xSeparator + k + " = " + GraphViz.escape(v, true)
118
118
  end
119
119
  xSeparator = ", "
120
120
  end
@@ -44,8 +44,8 @@ class GraphViz
44
44
 
45
45
  class Graph < Treetop::Runtime::SyntaxNode
46
46
  def eval( context, hOpts )
47
- puts "GRAPH TYPE = #{type.text_value}"
48
- puts "GRAPH NAME = #{name.text_value}"
47
+ # puts "GRAPH TYPE = #{type.text_value}"
48
+ # puts "GRAPH NAME = #{name.text_value}"
49
49
 
50
50
  hOpts = hOpts[0].merge( {:type => type.text_value} )
51
51
 
@@ -69,15 +69,15 @@ class GraphViz
69
69
 
70
70
  class GraphPreference < Treetop::Runtime::SyntaxNode
71
71
  def eval( context )
72
- puts "GRAPH PREFERENCE : "
73
- puts " #{key.text_value} = #{value.text_value.gsub(/"/, "")}"
72
+ # puts "GRAPH PREFERENCE : "
73
+ # puts " #{key.text_value} = #{value.text_value.gsub(/"/, "")}"
74
74
  context.graph[key.text_value] = value.text_value.gsub(/"/, "")
75
75
  end
76
76
  end
77
77
 
78
78
  class NamedGraphPreference < Treetop::Runtime::SyntaxNode
79
79
  def eval( context )
80
- puts "GRAPH PREFERENCES :"
80
+ # puts "GRAPH PREFERENCES :"
81
81
  options.eval().each do |k,v|
82
82
  context.graph[k] = v
83
83
  end
@@ -86,14 +86,14 @@ class GraphViz
86
86
 
87
87
  class NodePreference < Treetop::Runtime::SyntaxNode
88
88
  def eval( context )
89
- puts "NODE PREFERENCES :"
89
+ # puts "NODE PREFERENCES :"
90
90
  context.options[:node] = context.options[:node].merge( options.eval() )
91
91
  end
92
92
  end
93
93
 
94
94
  class EdgePreference < Treetop::Runtime::SyntaxNode
95
95
  def eval( context )
96
- puts "EDGE PREFERENCES :"
96
+ # puts "EDGE PREFERENCES :"
97
97
  context.options[:edge] = context.options[:edge].merge( options.eval() )
98
98
  end
99
99
  end
@@ -101,8 +101,8 @@ class GraphViz
101
101
  class Node < Treetop::Runtime::SyntaxNode
102
102
  def eval( context )
103
103
  node_name = name.text_value.gsub( /"/, "" )
104
- puts "NODE NAME = #{node_name}"
105
- puts "OPTIONS = "
104
+ # puts "NODE NAME = #{node_name}"
105
+ # puts "OPTIONS = "
106
106
 
107
107
  # Create node
108
108
  node = context.nodes[node_name] || context.graph.add_node( node_name )
@@ -126,7 +126,7 @@ class GraphViz
126
126
 
127
127
  class Edge < Treetop::Runtime::SyntaxNode
128
128
  def create_node( name, context )
129
- puts " NEED TO CREATE NODE : #{name}"
129
+ # puts " NEED TO CREATE NODE : #{name}"
130
130
  # Create the node
131
131
  node = context.graph.add_node( name )
132
132
 
@@ -160,10 +160,10 @@ class GraphViz
160
160
  def eval( context )
161
161
  one_name = node_one.text_value.gsub( /"/, "" )
162
162
  two_name = node_two.text_value.gsub( /"/, "" )
163
- puts "EDGE"
164
- puts "NODE ONE = #{one_name}"
165
- puts "NODE TWO = #{two_name}"
166
- puts "OPTIONS = "
163
+ # puts "EDGE"
164
+ # puts "NODE ONE = #{one_name}"
165
+ # puts "NODE TWO = #{two_name}"
166
+ # puts "OPTIONS = "
167
167
 
168
168
  # Get or create node one
169
169
  one = context.nodes[one_name] || create_node( one_name, context )
@@ -181,7 +181,7 @@ class GraphViz
181
181
  last_node = two
182
182
  other_nodes.elements.each do |e|
183
183
  new_node_name = e.next_node.text_value.gsub( /"/, "" )
184
- puts "OTHER NODE : #{new_node_name}"
184
+ # puts "OTHER NODE : #{new_node_name}"
185
185
 
186
186
  new_node = context.nodes[new_node_name] || create_node( new_node_name, context )
187
187
  create_edge( last_node, new_node, edge_options, context )
@@ -193,7 +193,7 @@ class GraphViz
193
193
 
194
194
  class Subgraph < Treetop::Runtime::SyntaxNode
195
195
  def eval( context )
196
- puts "CREATE SUBGRAPH : #{name.text_value}"
196
+ # puts "CREATE SUBGRAPH : #{name.text_value}"
197
197
 
198
198
  # Save options
199
199
  saved_options = context.options.clone
@@ -220,10 +220,10 @@ class GraphViz
220
220
  def eval
221
221
  options = {}
222
222
  elements[2].elements.each do |e|
223
- puts " #{e.elements[0].text_value} = #{e.elements[4].text_value}"
223
+ # puts " #{e.elements[0].text_value} = #{e.elements[4].text_value}"
224
224
  options[e.elements[0].text_value] = e.elements[4].text_value.gsub( /"/, "" )
225
225
  end
226
- puts " #{elements[3].text_value} = #{elements[7].text_value}"
226
+ # puts " #{elements[3].text_value} = #{elements[7].text_value}"
227
227
  options[elements[3].text_value] = elements[7].text_value.gsub( /"/, "" )
228
228
 
229
229
  return options
@@ -30,10 +30,18 @@ class GraphViz
30
30
  # Generate the graph
31
31
  #
32
32
  # Options :
33
- # :output : Output format (Constants::FORMATS)
34
- # :file : Output file name
35
- # :use : Program to use (Constants::PROGRAMS)
36
- # :path : Program PATH
33
+ # * :output : Output format (Constants::FORMATS)
34
+ # * :file : Output file name
35
+ # * :use : Program to use (Constants::PROGRAMS)
36
+ # * :path : Program PATH
37
+ # * :<format> => <file> : <file> can be
38
+ # * a file name
39
+ # * nil, then the output will be printed to STDOUT
40
+ # * String, then the output will be returned as a String
41
+ # * :errors : DOT error level (default 1)
42
+ # * 0 = Error + Warning
43
+ # * 1 = Error
44
+ # * 2 = none
37
45
  #
38
46
  def output( *hOpt )
39
47
  @oGraph.output( *hOpt )
@@ -45,8 +53,8 @@ class GraphViz
45
53
  # Create a graph from a XML file
46
54
  #
47
55
  # In:
48
- # xFile : XML File
49
- # *hOpt : Graph options
56
+ # * xFile : XML File
57
+ # * *hOpt : Graph options
50
58
  #
51
59
  def initialize( xFile, *hOpt )
52
60
  @xNodeName = "00000"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-graphviz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregoire Lejeune
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-19 00:00:00 +02:00
12
+ date: 2009-10-21 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -85,7 +85,7 @@ files:
85
85
  - examples/sample22.rb
86
86
  - examples/sample23.rb
87
87
  - examples/sample24.rb
88
- - examples/sample24.rb.png
88
+ - examples/sample25.rb
89
89
  - examples/shapes.rb
90
90
  - examples/test.xml
91
91
  - examples/testorder.rb
Binary file