ruby-graphviz 1.0.8 → 1.0.9
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.
- checksums.yaml +7 -0
- data/AUTHORS.rdoc +1 -0
- data/CHANGELOG.rdoc +12 -0
- data/README.rdoc +2 -0
- data/Rakefile +13 -6
- data/bin/dot2ruby +2 -2
- data/bin/gem2gv +2 -3
- data/bin/git2gv +2 -4
- data/bin/ruby2gv +16 -19
- data/bin/xml2gv +2 -2
- data/examples/sample38.rb +5 -5
- data/lib/graphviz.rb +82 -116
- data/lib/graphviz/attrs.rb +1 -1
- data/lib/graphviz/constants.rb +247 -240
- data/lib/graphviz/core_ext.rb +1 -1
- data/lib/graphviz/dot2ruby.rb +1 -1
- data/lib/graphviz/dot_script.rb +109 -0
- data/lib/graphviz/edge.rb +4 -4
- data/lib/graphviz/node.rb +1 -1
- data/lib/graphviz/theory.rb +3 -3
- data/lib/graphviz/types.rb +2 -1
- data/lib/graphviz/types/lbl_string.rb +1 -1
- data/lib/graphviz/utils.rb +70 -67
- data/lib/graphviz/utils/colors.rb +1 -1
- data/man/dot2ruby.1 +66 -0
- data/man/dot2ruby.1.ronn +55 -0
- data/man/gem2gv.1 +60 -0
- data/man/gem2gv.1.ronn +47 -0
- data/man/git2gv.1 +48 -0
- data/man/git2gv.1.ronn +40 -0
- data/man/ruby2gv.1 +60 -0
- data/man/ruby2gv.1.ronn +47 -0
- data/man/xml2gv.1 +48 -0
- data/man/xml2gv.1.ronn +39 -0
- data/ruby-graphviz.gemspec +4 -1
- data/test/test_dot_script.rb +43 -0
- data/test/test_graph.rb +9 -0
- data/test/test_subgraph.rb +1 -1
- metadata +70 -23
data/lib/graphviz/core_ext.rb
CHANGED
data/lib/graphviz/dot2ruby.rb
CHANGED
@@ -0,0 +1,109 @@
|
|
1
|
+
require "forwardable"
|
2
|
+
class GraphViz
|
3
|
+
|
4
|
+
class DOTScriptData
|
5
|
+
attr_accessor :type
|
6
|
+
def initialize(type = nil)
|
7
|
+
@data = []
|
8
|
+
@separator = ""
|
9
|
+
@type = type
|
10
|
+
end
|
11
|
+
|
12
|
+
def append(data)
|
13
|
+
@data << data
|
14
|
+
end
|
15
|
+
alias :<< :append
|
16
|
+
|
17
|
+
def add_attribute(name, value)
|
18
|
+
@data << @separator << name << " = " << value
|
19
|
+
@separator = determine_separator
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_str
|
23
|
+
case @type
|
24
|
+
when "graph_attr" then "#{@data.join}#{@separator}"
|
25
|
+
when "node_attr" then "node[#{@data.join(' ')}];"
|
26
|
+
when "edge_attr" then "edge[#{@data.join(' ')}];"
|
27
|
+
else raise ArgumentError, "Wrong type: #{@type}."
|
28
|
+
end
|
29
|
+
end
|
30
|
+
alias :to_s :to_str
|
31
|
+
|
32
|
+
def empty?
|
33
|
+
@data.empty?
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def determine_separator
|
39
|
+
case @type
|
40
|
+
when "graph_attr" then ";\n"
|
41
|
+
when "node_attr", "edge_attr" then ","
|
42
|
+
else raise ArgumentError, "Wrong type: #{@type}."
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
class DOTScript
|
49
|
+
extend Forwardable
|
50
|
+
|
51
|
+
def_delegators :@script, :end_with?
|
52
|
+
|
53
|
+
def initialize
|
54
|
+
@script = ''
|
55
|
+
end
|
56
|
+
|
57
|
+
def append(line)
|
58
|
+
@script << assure_ends_with(line.to_s,"\n")
|
59
|
+
|
60
|
+
self
|
61
|
+
end
|
62
|
+
alias :<< :append
|
63
|
+
|
64
|
+
def prepend(line)
|
65
|
+
@script = assure_ends_with(line.to_s,"\n") + @script
|
66
|
+
|
67
|
+
self
|
68
|
+
end
|
69
|
+
|
70
|
+
def make_subgraph(name)
|
71
|
+
prepend(assure_ends_with("subgraph #{name}"," {"))
|
72
|
+
end
|
73
|
+
|
74
|
+
def add_type(type, data)
|
75
|
+
return self if data.empty?
|
76
|
+
|
77
|
+
case type
|
78
|
+
when "graph_attr"
|
79
|
+
append_statement(" " + data)
|
80
|
+
when "node_attr"
|
81
|
+
append_statement(" node [" + data + "]")
|
82
|
+
when "edge_attr"
|
83
|
+
append_statement(" edge [" + data + "]")
|
84
|
+
else
|
85
|
+
raise ArgumentError,
|
86
|
+
"Unknown type: #{type}." <<
|
87
|
+
"Possible: 'graph_attr','node_attr','edge_attr'"
|
88
|
+
end
|
89
|
+
|
90
|
+
self
|
91
|
+
end
|
92
|
+
|
93
|
+
def to_str
|
94
|
+
@script
|
95
|
+
end
|
96
|
+
alias :to_s :to_str
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
def assure_ends_with(str,ending="\n")
|
101
|
+
str.to_s.end_with?("\n") ? str : str + ending
|
102
|
+
end
|
103
|
+
|
104
|
+
def append_statement(statement)
|
105
|
+
append(assure_ends_with(statement, ";\n"))
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
end
|
data/lib/graphviz/edge.rb
CHANGED
@@ -19,7 +19,7 @@ require 'graphviz/constants'
|
|
19
19
|
|
20
20
|
class GraphViz
|
21
21
|
class Edge
|
22
|
-
include Constants
|
22
|
+
include GraphViz::Constants
|
23
23
|
|
24
24
|
# Create a new edge
|
25
25
|
#
|
@@ -45,7 +45,7 @@ class GraphViz
|
|
45
45
|
|
46
46
|
# Return the node one as string (so with port if any)
|
47
47
|
def node_one( with_port = true )
|
48
|
-
if not
|
48
|
+
if not(@node_one_port and with_port)
|
49
49
|
GraphViz.escape(@node_one_id)
|
50
50
|
else
|
51
51
|
GraphViz.escape(@node_one_id, :force => true) + ":#{@node_one_port}"
|
@@ -55,7 +55,7 @@ class GraphViz
|
|
55
55
|
|
56
56
|
# Return the node two as string (so with port if any)
|
57
57
|
def node_two( with_port = true )
|
58
|
-
if not
|
58
|
+
if not(@node_two_port and with_port)
|
59
59
|
GraphViz.escape(@node_two_id)
|
60
60
|
else
|
61
61
|
GraphViz.escape(@node_two_id, :force => true) + ":#{@node_two_port}"
|
@@ -172,7 +172,7 @@ class GraphViz
|
|
172
172
|
if xAttr.length > 0
|
173
173
|
xOut << " [" + xAttr + "]"
|
174
174
|
end
|
175
|
-
xOut
|
175
|
+
xOut << ";"
|
176
176
|
|
177
177
|
return( xOut )
|
178
178
|
end
|
data/lib/graphviz/node.rb
CHANGED
data/lib/graphviz/theory.rb
CHANGED
@@ -150,8 +150,8 @@ class GraphViz
|
|
150
150
|
return nil if range.include?(nil) or @graph.type != "digraph"
|
151
151
|
r = [ [0, [1]] ]
|
152
152
|
|
153
|
-
critical_path_recursion( distance_matrix, adjancy_matrix, r, [], 0 ).inject( {:distance => 0, :path => []} ) { |
|
154
|
-
(
|
153
|
+
critical_path_recursion( distance_matrix, adjancy_matrix, r, [], 0 ).inject( {:distance => 0, :path => []} ) { |_r, item|
|
154
|
+
(_r[:distance] < item[0]) ? { :distance => item[0], :path => item[1] } : _r
|
155
155
|
}
|
156
156
|
end
|
157
157
|
|
@@ -309,7 +309,7 @@ class GraphViz
|
|
309
309
|
cpath = [ (p[0] + d[node,succ]), (p[1].clone << succ) ]
|
310
310
|
|
311
311
|
if index_of_item( a.line(succ), 1 ).size > 0
|
312
|
-
|
312
|
+
critical_path_recursion( d, a, [cpath], result, level+1 )
|
313
313
|
else
|
314
314
|
result << cpath
|
315
315
|
end
|
data/lib/graphviz/types.rb
CHANGED
@@ -15,7 +15,8 @@ class GraphViz
|
|
15
15
|
end
|
16
16
|
|
17
17
|
Dir.glob( File.dirname( File.expand_path(__FILE__) )+"/types/*.rb" ).each do |f|
|
18
|
-
autoload File.basename(f).gsub(File.extname(f), "").split( "_" ).map{|n| n.capitalize }.join.to_sym, f
|
18
|
+
#autoload File.basename(f).gsub(File.extname(f), "").split( "_" ).map{|n| n.capitalize }.join.to_sym, f
|
19
|
+
require f
|
19
20
|
end
|
20
21
|
end
|
21
22
|
end
|
data/lib/graphviz/utils.rb
CHANGED
@@ -1,80 +1,83 @@
|
|
1
1
|
require 'rbconfig'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
3
|
+
class GraphViz
|
4
|
+
module Utils
|
5
|
+
# Since this code is an adaptation of Launchy::Application#find_executable
|
6
|
+
# (http://copiousfreetime.rubyforge.org/launchy/Launchy/Application.html)
|
7
|
+
# it follow is licence :
|
8
|
+
#
|
9
|
+
# Permission to use, copy, modify, and/or distribute this software for any
|
10
|
+
# purpose with or without fee is hereby granted, provided that the above
|
11
|
+
# copyright notice and this permission notice appear in all copies.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED AS IS AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
14
|
+
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
15
|
+
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
16
|
+
# SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
17
|
+
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
18
|
+
# OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
19
|
+
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
20
|
+
def find_executable(bin, custom_paths) #:nodoc:
|
21
|
+
system_path = ENV['PATH']
|
22
|
+
user_given_path = Array(custom_paths).join(File::PATH_SEPARATOR)
|
23
|
+
search_path = system_path + File::PATH_SEPARATOR + user_given_path
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
search_path.split(File::PATH_SEPARATOR).each do |path|
|
26
|
+
file_path = File.join(path,bin)
|
27
|
+
return file_path if File.executable?(file_path) and File.file?(file_path)
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ # WAS: elsif RUBY_PLATFORM =~ /mswin|mingw/
|
30
|
+
found_ext = (ENV['PATHEXT'] || '.exe;.bat;.com').split(";").find {|ext| File.executable?(file_path + ext) }
|
31
|
+
return file_path + found_ext if found_ext
|
32
|
+
end
|
31
33
|
end
|
34
|
+
return nil
|
32
35
|
end
|
33
|
-
return nil
|
34
|
-
end
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
37
|
+
def escape_path_containing_blanks(path) #:nodoc:
|
38
|
+
path.gsub!(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
|
39
|
+
path_elements = path.split(File::SEPARATOR)
|
40
|
+
path_elements.map! do |element|
|
41
|
+
if element.include?(' ')
|
42
|
+
"\"#{element}\""
|
43
|
+
else
|
44
|
+
element
|
45
|
+
end
|
44
46
|
end
|
47
|
+
path_elements.join(File::SEPARATOR)
|
45
48
|
end
|
46
|
-
path_elements.join(File::SEPARATOR)
|
47
|
-
end
|
48
49
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
50
|
+
def output_and_errors_from_command(cmd) #:nodoc:
|
51
|
+
unless defined? Open3
|
52
|
+
begin
|
53
|
+
require 'open3'
|
54
|
+
require 'win32/open3'
|
55
|
+
rescue LoadError
|
56
|
+
end
|
57
|
+
end
|
58
|
+
begin
|
59
|
+
Open3.popen3( cmd ) do |stdin, stdout, stderr|
|
60
|
+
stdin.close
|
61
|
+
stdout.binmode
|
62
|
+
[stdout.read, stderr.read]
|
63
|
+
end
|
64
|
+
rescue NotImplementedError, NoMethodError
|
65
|
+
IO.popen( cmd ) do |stdout|
|
66
|
+
stdout.binmode
|
67
|
+
[stdout.read, nil]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
70
71
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
72
|
+
def output_from_command(cmd) #:nodoc:
|
73
|
+
output, errors = output_and_errors_from_command(cmd)
|
74
|
+
if errors.nil? || errors.strip.empty?
|
75
|
+
output
|
76
|
+
else
|
77
|
+
raise "Error from #{cmd}:\n#{errors}"
|
78
|
+
end
|
79
|
+
end
|
79
80
|
|
81
|
+
end
|
80
82
|
end
|
83
|
+
|
data/man/dot2ruby.1
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
.\" generated with Ronn/v0.7.3
|
2
|
+
.\" http://github.com/rtomayko/ronn/tree/0.7.3
|
3
|
+
.
|
4
|
+
.TH "DOT2RUBY" "1" "April 2013" "" ""
|
5
|
+
.
|
6
|
+
.SH "NAME"
|
7
|
+
\fBdot2ruby\fR \- create a ruby script from a graphviz script
|
8
|
+
.
|
9
|
+
.SH "SYNOPSIS"
|
10
|
+
\fBdot2ruby\fR [\fB\-o\fR\fIfile\fR] [\fB\-T\fR\fIformat\fR] [\fB\-h\fR] [\fB\-V\fR] \fIscript\fR
|
11
|
+
.
|
12
|
+
.SH "DESCRIPTION"
|
13
|
+
\fBdot2ruby\fR is a tool that allows you to create a ruby script from a graphviz script\.
|
14
|
+
.
|
15
|
+
.P
|
16
|
+
See </usr/share/doc/ruby\-graphviz/> for more details\.
|
17
|
+
.
|
18
|
+
.SH "OPTIONS"
|
19
|
+
.
|
20
|
+
.TP
|
21
|
+
\fB\-o\fR, \fB\-\-output\-file\fR [\fIfile\fR]
|
22
|
+
Path to output image file (default STDOUT)
|
23
|
+
.
|
24
|
+
.TP
|
25
|
+
\fB\-T\fR, \fB\-\-output\-format\fR [\fIformat\fR]
|
26
|
+
Output format (default: png)
|
27
|
+
.
|
28
|
+
.TP
|
29
|
+
\fB\-p\fR, \fB\-\-path\fR
|
30
|
+
Graphviz path
|
31
|
+
.
|
32
|
+
.TP
|
33
|
+
\fB\-V\fR, \fB\-\-version\fR
|
34
|
+
Show version
|
35
|
+
.
|
36
|
+
.TP
|
37
|
+
\fB\-h\fR, \fB\-\-help\fR
|
38
|
+
Show this usage message
|
39
|
+
.
|
40
|
+
.SH "EXAMPLE"
|
41
|
+
.
|
42
|
+
.nf
|
43
|
+
|
44
|
+
$ cat hello\.dot
|
45
|
+
digraph G {Hello\->World;}
|
46
|
+
|
47
|
+
$ dot2ruby hello\.dot
|
48
|
+
# This code was generated by dot2ruby\.g
|
49
|
+
|
50
|
+
require \'rubygems\'
|
51
|
+
require \'graphviz\'
|
52
|
+
graph_g = GraphViz\.digraph( "G" ) { |graph_g|
|
53
|
+
graph_g[:bb] = \'0,0,70,108\'
|
54
|
+
node_hello = graph_g\.add_nodes( "Hello", :height => \'0\.5\', :label => \'\eN\', :pos => \'35,90\', :width => \'0\.88889\' )
|
55
|
+
graph_g\.add_edges( "Hello", "World", :pos => \'e,35,36\.413 35,71\.831 35,64\.131 35,54\.974 35,46\.417\' )
|
56
|
+
node_world = graph_g\.add_nodes( "World", :height => \'0\.5\', :label => \'\eN\', :pos => \'35,18\', :width => \'0\.97222\' )
|
57
|
+
}
|
58
|
+
puts graph_g\.output( :canon => String )
|
59
|
+
.
|
60
|
+
.fi
|
61
|
+
.
|
62
|
+
.SH "AUTHOR"
|
63
|
+
Copyright 2004\-2013 Gregoire Lejeune
|
64
|
+
.
|
65
|
+
.P
|
66
|
+
This manual page is written by Praveen Arimbrathodiyl \fIpraveen@debian\.org\fR for Debian GNU System (GNU/Linux, GNU/kFreeBSD, GNU/Hurd)\.
|
data/man/dot2ruby.1.ronn
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
dot2ruby(1) - create a ruby script from a graphviz script
|
2
|
+
=========================================================
|
3
|
+
|
4
|
+
## SYNOPSIS
|
5
|
+
|
6
|
+
`dot2ruby` [`-o`<file>] [`-T`<format>] [`-h`] [`-V`] _script_
|
7
|
+
|
8
|
+
## DESCRIPTION
|
9
|
+
|
10
|
+
**dot2ruby** is a tool that allows you to create a ruby script from
|
11
|
+
a graphviz script.
|
12
|
+
|
13
|
+
See </usr/share/doc/ruby-graphviz/> for more details.
|
14
|
+
|
15
|
+
## OPTIONS
|
16
|
+
|
17
|
+
* `-o`, `--output-file` [<file>]:
|
18
|
+
Path to output image file (default STDOUT)
|
19
|
+
|
20
|
+
* `-T`, `--output-format` [<format>]:
|
21
|
+
Output format (default: png)
|
22
|
+
|
23
|
+
* `-p`, `--path`:
|
24
|
+
Graphviz path
|
25
|
+
|
26
|
+
* `-V`, `--version`:
|
27
|
+
Show version
|
28
|
+
|
29
|
+
* `-h`, `--help`:
|
30
|
+
Show this usage message
|
31
|
+
|
32
|
+
## EXAMPLE
|
33
|
+
|
34
|
+
$ cat hello.dot
|
35
|
+
digraph G {Hello->World;}
|
36
|
+
|
37
|
+
$ dot2ruby hello.dot
|
38
|
+
# This code was generated by dot2ruby.g
|
39
|
+
|
40
|
+
require 'rubygems'
|
41
|
+
require 'graphviz'
|
42
|
+
graph_g = GraphViz.digraph( "G" ) { |graph_g|
|
43
|
+
graph_g[:bb] = '0,0,70,108'
|
44
|
+
node_hello = graph_g.add_nodes( "Hello", :height => '0.5', :label => '\N', :pos => '35,90', :width => '0.88889' )
|
45
|
+
graph_g.add_edges( "Hello", "World", :pos => 'e,35,36.413 35,71.831 35,64.131 35,54.974 35,46.417' )
|
46
|
+
node_world = graph_g.add_nodes( "World", :height => '0.5', :label => '\N', :pos => '35,18', :width => '0.97222' )
|
47
|
+
}
|
48
|
+
puts graph_g.output( :canon => String )
|
49
|
+
|
50
|
+
## AUTHOR
|
51
|
+
|
52
|
+
Copyright 2004-2013 Gregoire Lejeune
|
53
|
+
|
54
|
+
This manual page is written by Praveen Arimbrathodiyl <praveen@debian.org> for
|
55
|
+
Debian GNU System (GNU/Linux, GNU/kFreeBSD, GNU/Hurd).
|