ruby-graphviz 0.9.19 → 0.9.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. data/AUTHORS +1 -0
  2. data/README.rdoc +6 -0
  3. data/examples/dot/so-sample001.gv +30 -0
  4. data/examples/dot/so-sample002.gv +33 -0
  5. data/examples/dot/so-sample003.gv +45 -0
  6. data/examples/graphml/cluster.graphml +4 -4
  7. data/examples/sample35.rb +1 -1
  8. data/examples/sample57.rb +2 -1
  9. data/lib/graphviz/attrs.rb +1 -1
  10. data/lib/graphviz/constants.rb +1 -1
  11. data/lib/graphviz/edge.rb +18 -2
  12. data/lib/graphviz/family_tree.rb +2 -0
  13. data/lib/graphviz/node.rb +16 -0
  14. data/lib/graphviz.rb +29 -5
  15. data/test/output/sample01.rb.png +0 -0
  16. data/test/output/sample02.rb.png +0 -0
  17. data/test/output/sample03.rb.png +0 -0
  18. data/test/output/sample04.rb.png +0 -0
  19. data/test/output/sample05.rb.png +0 -0
  20. data/test/output/sample06.rb.png +0 -0
  21. data/test/output/sample07.rb.png +0 -0
  22. data/test/output/sample08.rb.png +0 -0
  23. data/test/output/sample09.rb.png +0 -0
  24. data/test/output/sample10.rb.png +0 -0
  25. data/test/output/sample11.rb.png +0 -0
  26. data/test/output/sample12.rb.png +0 -0
  27. data/test/output/sample13.rb.png +0 -0
  28. data/test/output/sample14.rb.png +0 -0
  29. data/test/output/sample15.rb.png +0 -0
  30. data/test/output/sample16.rb.png +0 -0
  31. data/test/output/sample17.rb.png +0 -0
  32. data/test/output/sample18.rb.png +0 -0
  33. data/test/output/sample19.rb.png +0 -0
  34. data/test/output/sample20.rb.png +0 -0
  35. data/test/output/sample21.rb.html +3 -0
  36. data/test/output/sample21.rb.png +0 -0
  37. data/test/output/sample22.rb.html +5 -0
  38. data/test/output/sample22.rb.png +0 -0
  39. data/test/output/sample23.rb.png +0 -0
  40. data/test/output/sample24.rb.png +0 -0
  41. data/test/output/sample25.rb.png +0 -0
  42. data/test/output/sample26.rb.png +0 -0
  43. data/test/output/sample28.rb.png +0 -0
  44. data/test/output/sample29.rb.svg +21 -0
  45. data/test/output/sample30.rb.ps +923 -0
  46. data/test/output/sample31.rb.png +0 -0
  47. data/test/output/sample32.rb.png +0 -0
  48. data/test/output/sample35.rb.gv +24 -0
  49. data/test/output/sample35.rb.png +0 -0
  50. data/test/output/sample37.rb.dot +50 -0
  51. data/test/output/sample37.rb.png +0 -0
  52. data/test/output/sample38.rb.png +0 -0
  53. data/test/output/sample39.rb.png +0 -0
  54. data/test/output/sample40.rb.png +0 -0
  55. data/test/output/sample41.rb.svg +8 -0
  56. data/test/output/sample42.rb.png +0 -0
  57. data/test/output/sample43.rb.png +0 -0
  58. data/test/output/sample44.rb.png +0 -0
  59. data/test/output/sample45.rb.png +0 -0
  60. data/test/output/sample46.rb.png +0 -0
  61. data/test/output/sample47.rb.png +0 -0
  62. data/test/output/sample48.rb.png +0 -0
  63. data/test/output/sample49.rb.png +0 -0
  64. data/test/output/sample50.rb.png +0 -0
  65. data/test/output/sample51.rb.png +0 -0
  66. data/test/output/sample52.rb.png +0 -0
  67. data/test/output/sample53.rb.png +0 -0
  68. data/test/output/sample54.rb.png +0 -0
  69. data/test/output/sample55.rb.png +0 -0
  70. data/test/output/sample56.rb.svg +28 -0
  71. data/test/output/sample58.rb.png +0 -0
  72. data/test/output/sample99.rb.png +0 -0
  73. data/test/support.rb +7 -2
  74. data/test/test_examples.rb +4 -4
  75. data/test/test_init.rb +1 -1
  76. metadata +65 -4
data/AUTHORS CHANGED
@@ -11,6 +11,7 @@ Stefan Huber <http://github.com/MSNexploder>
11
11
  Nigel Thorne <http://github.com/NigelThorne>
12
12
  Rolf Timmermans <http://github.com/rolftimmermans>
13
13
  Jonas Elfström <http://github.com/jonelf>
14
+ oupo <http://github.com/oupo>
14
15
 
15
16
  Thanks to :
16
17
 
data/README.rdoc CHANGED
@@ -16,6 +16,12 @@ Interface to the GraphViz graphing tool
16
16
 
17
17
  == CHANGELOG
18
18
 
19
+ === 0.9.20 :
20
+ * Add GraphViz#each_attribut, Node#each_attribut and Edge#each_attribut
21
+ * Bugs corrections in tests (by oupo)
22
+ * Major bug correction in GraphViz#output for subgraphs
23
+ * Update GraphViz.escape
24
+
19
25
  === 0.9.19 :
20
26
  * Add strict digraph support (by Jonas Elfström) (see sample58.rb)
21
27
  g = GraphViz.new(:G, :type => "strict digraph")
@@ -0,0 +1,30 @@
1
+ digraph G {
2
+ layout="neato"
3
+ // scale things down for example
4
+ size="5,5"
5
+ rankdir=TD
6
+ ranksep=1
7
+ nodesep=1
8
+
9
+ node [shape=box]
10
+
11
+ top[pos="5,10!", width=5, height=2]
12
+
13
+ left1[pos="3.5,7!", width=2, height=2]
14
+ left2[pos="3.5,4!", width=2, height=2]
15
+
16
+ right[pos="6.5,5.5!", width=2, height=5]
17
+
18
+ bottom[pos="5,1!", width=5, height=2]
19
+
20
+
21
+ top->left1
22
+ top->right
23
+
24
+ left1->left2
25
+ left1->right
26
+ left2->right
27
+
28
+ left2->bottom
29
+ right->bottom
30
+ }
@@ -0,0 +1,33 @@
1
+
2
+ //{:category1 =>
3
+ // {:subcategory1 =>
4
+ // [
5
+ // {:article => "some article", :date => "2010-04-04"},
6
+ // ...
7
+ // ],
8
+ // :subc2 => [...]
9
+ // },
10
+ // :category2 => {...},
11
+ // ...
12
+ //}
13
+
14
+ graph G {
15
+ rankdir=LR
16
+ category1
17
+
18
+ subgraph clusterC {
19
+ node[shape="box"]
20
+ subcategory1
21
+ subc2
22
+
23
+ subgraph clusterS {
24
+ article -- "somme article"
25
+ date -- "2010-04-04"
26
+ }
27
+
28
+ subcategory1 -- clusterS
29
+ subc2 -- "..."
30
+ }
31
+
32
+ category1 -- clusterC
33
+ }
@@ -0,0 +1,45 @@
1
+
2
+ //{:category1 =>
3
+ // {:subcategory1 =>
4
+ // [
5
+ // {:article => "some article", :date => "2010-04-04"},
6
+ // ...
7
+ // ],
8
+ // :subc2 => [...]
9
+ // },
10
+ // :category2 => {...},
11
+ // ...
12
+ //}
13
+
14
+ graph G {
15
+ layout="fdp"
16
+
17
+ category1[label=":category1", shape="box"]
18
+
19
+ subgraph cluster_category1 {
20
+ subcategory1[label=":subcategory1", shape="box"]
21
+ subc2[label=":subc2", shape="box"]
22
+
23
+ subgraph cluster_subcategory1 {
24
+ subgraph cluster_subcategory1_Array0 {
25
+ article0[label=":article", shape="box"]
26
+ date0[label=":date", shape="box"]
27
+
28
+ article0 -- "somme article"
29
+ date0 -- "2010-04-04"
30
+ }
31
+ subgraph cluster_subcategory1_Array1 {
32
+ article1[label=":article", shape="box"]
33
+ date1[label=":date", shape="box"]
34
+
35
+ article1 -- "an other article"
36
+ date1 -- "2010-09-09"
37
+ }
38
+ }
39
+
40
+ subcategory1 -- cluster_subcategory1
41
+ subc2 -- "..."
42
+ }
43
+
44
+ category1 -- cluster_category1
45
+ }
@@ -15,19 +15,19 @@ xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdr
15
15
  <data key="label">process #1</data>
16
16
  <node id="a0">
17
17
  <data key="style">filled</data>
18
- <data key="style">white</data>
18
+ <data key="color">white</data>
19
19
  </node>
20
20
  <node id="a1">
21
21
  <data key="style">filled</data>
22
- <data key="style">white</data>
22
+ <data key="color">white</data>
23
23
  </node>
24
24
  <node id="a2">
25
25
  <data key="style">filled</data>
26
- <data key="style">white</data>
26
+ <data key="color">white</data>
27
27
  </node>
28
28
  <node id="a3">
29
29
  <data key="style">filled</data>
30
- <data key="style">white</data>
30
+ <data key="color">white</data>
31
31
  </node>
32
32
  <edge id="e0" source="a0" target="a1"/>
33
33
  <edge id="e1" source="a1" target="a2"/>
data/examples/sample35.rb CHANGED
@@ -40,4 +40,4 @@ GraphViz.digraph( :G ) { |g|
40
40
  (c2.mysite << c2.dotgraph)[:color => "blue"]
41
41
  (c1.image << c2.dotgraph)[:color => "red"]
42
42
  (c2.mysite << g.cluster_0.zeimage)[:color => "red"]
43
- }.output( :png => "#{$0}.png" )
43
+ }.output( :png => "#{$0}.png", :none => "#{$0}.gv" )
data/examples/sample57.rb CHANGED
@@ -2,6 +2,7 @@ $:.unshift( "../lib" )
2
2
 
3
3
  require 'graphviz/graphml'
4
4
 
5
- graphml = File.join( File.dirname( File.expand_path( __FILE__ ) ), "graphml", "cluster.graphml" )
5
+ graphml = File.join( File.dirname( File.expand_path( __FILE__ ) ), "graphml", "port.graphml" )
6
6
  g = GraphViz::GraphML.new( graphml )
7
7
  g.graph.output( :png => "#{$0}.png" )
8
+ puts g.graph.output( :none => String )
@@ -52,7 +52,7 @@ class GraphViz
52
52
  @data[xKey.to_s]
53
53
  end
54
54
  end
55
-
55
+
56
56
  def []=( xKey, xValue )
57
57
  unless @attributs.keys.include?( xKey.to_s )
58
58
  raise ArgumentError, "#{@name} attribut '#{xKey.to_s}' invalid"
@@ -40,7 +40,7 @@
40
40
  # C => cluster
41
41
  #
42
42
  module Constants
43
- RGV_VERSION = "0.9.19"
43
+ RGV_VERSION = "0.9.20"
44
44
 
45
45
  ## Const: Output formats
46
46
  FORMATS = [
data/lib/graphviz/edge.rb CHANGED
@@ -61,7 +61,7 @@ class GraphViz
61
61
  if @xNodeOnePort.nil? or with_port == false
62
62
  GraphViz.escape(@xNodeOne)
63
63
  else
64
- GraphViz.escape(@xNodeOne, true) + ":#{@xNodeOnePort}"
64
+ GraphViz.escape(@xNodeOne, :force => true) + ":#{@xNodeOnePort}"
65
65
  end
66
66
  end
67
67
  alias :tail_node :node_one
@@ -71,7 +71,7 @@ class GraphViz
71
71
  if @xNodeTwoPort.nil? or with_port == false
72
72
  GraphViz.escape(@xNodeTwo)
73
73
  else
74
- GraphViz.escape(@xNodeTwo, true) + ":#{@xNodeTwoPort}"
74
+ GraphViz.escape(@xNodeTwo, :force => true) + ":#{@xNodeTwoPort}"
75
75
  end
76
76
  end
77
77
  alias :head_node :node_two
@@ -112,6 +112,22 @@ class GraphViz
112
112
  end
113
113
  end
114
114
 
115
+ #
116
+ # Calls block once for each attribut of the edge, passing the name and value to the
117
+ # block as a two-element array.
118
+ #
119
+ # If global is set to false, the block does not receive the attributs set globally
120
+ #
121
+ def each_attribut(global = true, &b)
122
+ attrs = @oAttrEdge.to_h
123
+ if global
124
+ attrs = pg.edge.to_h.merge attrs
125
+ end
126
+ attrs.each do |k,v|
127
+ yield(k,v)
128
+ end
129
+ end
130
+
115
131
  def <<( oNode ) #:nodoc:
116
132
  n = @oGParrent.get_node(@xNodeTwo)
117
133
 
@@ -1,3 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  require 'rubygems'
2
4
  require 'graphviz'
3
5
  require 'graphviz/family_tree/generation'
data/lib/graphviz/node.rb CHANGED
@@ -91,6 +91,22 @@ class GraphViz
91
91
  end
92
92
  end
93
93
 
94
+ #
95
+ # Calls block once for each attribut of the node, passing the name and value to the
96
+ # block as a two-element array.
97
+ #
98
+ # If global is set to false, the block does not receive the attributs set globally
99
+ #
100
+ def each_attribut(global = true, &b)
101
+ attrs = @oAttrNode.to_h
102
+ if global
103
+ attrs = pg.node.to_h.merge attrs
104
+ end
105
+ attrs.each do |k,v|
106
+ yield(k,v)
107
+ end
108
+ end
109
+
94
110
  #
95
111
  # Create an edge between the current node and the node +oNode+
96
112
  #
data/lib/graphviz.rb CHANGED
@@ -230,7 +230,7 @@ class GraphViz
230
230
  hOpts = xGraphName
231
231
  xGraphName = nil
232
232
  end
233
-
233
+
234
234
  if xGraphName.nil?
235
235
  xGraphID = String.random(11)
236
236
  xGraphName = ""
@@ -337,6 +337,16 @@ class GraphViz
337
337
  end
338
338
  end
339
339
 
340
+ #
341
+ # Calls block once for each attribut of the graph, passing the name and value to the
342
+ # block as a two-element array.
343
+ #
344
+ def each_attribut(&b)
345
+ @graph.each do |k,v|
346
+ yield(k,v)
347
+ end
348
+ end
349
+
340
350
  #
341
351
  # Generate the graph
342
352
  #
@@ -432,7 +442,7 @@ class GraphViz
432
442
  xDOTScript << "}"
433
443
 
434
444
  if @oParentGraph.nil? == false
435
- xDOTScript = "subgraph #{GraphViz.escape(@name)} {\n" << xDOTScript
445
+ xDOTScript = "subgraph #{GraphViz.escape(@name, :unquote_empty => true)} {\n" << xDOTScript
436
446
 
437
447
  return( xDOTScript )
438
448
  else
@@ -480,7 +490,7 @@ class GraphViz
480
490
  @output = hOutput if hOutput.size > 0
481
491
 
482
492
  xStict = ((@strict && @oGraphType == "digraph") ? "strict " : "")
483
- xDOTScript = ("#{xStict}#{@oGraphType} #{GraphViz.escape(@name)} {\n" << xDOTScript).gsub( "\0", "" )
493
+ xDOTScript = ("#{xStict}#{@oGraphType} #{GraphViz.escape(@name, :unquote_empty => true)} {\n" << xDOTScript).gsub( "\0", "" )
484
494
 
485
495
  xOutputString = (@filename == String ||
486
496
  @output.any? {|format, file| file == String })
@@ -797,8 +807,13 @@ class GraphViz
797
807
  #
798
808
  # Escape a string to be acceptable as a node name in a graphviz input file
799
809
  #
800
- def self.escape(str, force = false ) #:nodoc:
801
- if force or str.match( /\A[a-zA-Z_]+[a-zA-Z0-9_]*\Z/ ).nil?
810
+ def self.escape(str, opts = {} ) #:nodoc:
811
+ options = {
812
+ :force => false,
813
+ :unquote_empty => false,
814
+ }.merge(opts)
815
+
816
+ if (options[:force] or str.match( /\A[a-zA-Z_]+[a-zA-Z0-9_]*\Z/ ).nil?) and options[:unquote_empty] == false
802
817
  '"' + str.gsub('"', '\\"').gsub("\n", '\\\\n').gsub(".","\\.") + '"'
803
818
  ## MAYBE WE NEED TO USE THIS ONE ## str.inspect.gsub(".","\\.").gsub( "\\\\", "\\" )
804
819
  else
@@ -806,4 +821,13 @@ class GraphViz
806
821
  end
807
822
  end
808
823
 
824
+ #def self.escape(str, force = false ) #:nodoc:
825
+ # if force or str.match( /\A[a-zA-Z_]+[a-zA-Z0-9_]*\Z/ ).nil?
826
+ # '"' + str.gsub('"', '\\"').gsub("\n", '\\\\n').gsub(".","\\.") + '"'
827
+ # ## MAYBE WE NEED TO USE THIS ONE ## str.inspect.gsub(".","\\.").gsub( "\\\\", "\\" )
828
+ # else
829
+ # str
830
+ # end
831
+ #end
832
+
809
833
  end
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,3 @@
1
+ base referer
2
+ poly http://www.research.att.com/base.html 133,29 130,22 121,15 107,10 89,7 69,5 50,7 32,10 17,15 8,22 5,29 8,37 17,43 32,49 50,52 69,53 89,52 107,49 121,43 130,37
3
+ poly colors.html 114,125 112,118 106,111 96,106 83,103 69,101 55,103 43,106 33,111 26,118 24,125 26,133 33,139 43,145 55,148 69,149 83,148 96,145 106,139 112,133
Binary file
@@ -0,0 +1,5 @@
1
+ <map id="mainmap" name="mainmap">
2
+ <area shape="poly" id="node1" href="http://www.research.att.com/command.html" title="command" alt="" coords="133,29 130,22 121,15 107,10 89,7 69,5 50,7 32,10 17,15 8,22 5,29 8,37 17,43 32,49 50,52 69,53 89,52 107,49 121,43 130,37"/>
3
+ <area shape="poly" id="edge2" href="colors.html" alt="" coords="72,54 72,87 67,87 67,54"/>
4
+ <area shape="rect" id="graph1" href="http://www.research.att.com/base.html" alt="" coords="0,0,139,155"/>
5
+ </map>
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,21 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
3
+ "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4
+ <!-- Generated by graphviz version 2.27.20100802.0445 (20100802.0445)
5
+ -->
6
+ <!-- Title: G Pages: 1 -->
7
+ <svg width="150pt" height="62pt"
8
+ viewBox="0.00 0.00 150.00 62.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
9
+ <g id="graph1" class="graph" transform="scale(1 1) rotate(0) translate(4 58)">
10
+ <title>G</title>
11
+ <polygon fill="white" stroke="white" points="-4,5 -4,-58 147,-58 147,5 -4,5"/>
12
+ <!-- &quot;Hello\.&quot;\nHow are you ? -->
13
+ <g id="node1" class="node"><title>&quot;Hello\.&quot;\nHow are you ?</title>
14
+ <a xlink:href="http://www.website.com" xlink:title="&quot;Hello.&quot;\nHow are you ?">
15
+ <ellipse fill="none" stroke="#ff0000" cx="71" cy="-27" rx="70.9184" ry="26.8701"/>
16
+ <text text-anchor="middle" x="71" y="-29.4" font-family="Times,serif" font-size="14.00">&quot;Hello.&quot;</text>
17
+ <text text-anchor="middle" x="71" y="-14.4" font-family="Times,serif" font-size="14.00">How are you ?</text>
18
+ </a>
19
+ </g>
20
+ </g>
21
+ </svg>