ruby-graphviz 1.0.7 → 1.0.8
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.rdoc +4 -0
- data/bin/dot2ruby +5 -5
- data/bin/gem2gv +18 -18
- data/bin/git2gv +20 -20
- data/bin/ruby2gv +26 -26
- data/bin/xml2gv +5 -5
- data/examples/sample06.rb +5 -5
- data/examples/sample12.rb +3 -3
- data/examples/sample13.rb +8 -8
- data/examples/sample14.rb +8 -8
- data/examples/sample15.rb +1 -1
- data/examples/sample17.rb +7 -7
- data/examples/sample19.rb +10 -10
- data/examples/sample20.rb +2 -2
- data/examples/sample21.rb +1 -1
- data/examples/sample28.rb +1 -1
- data/examples/sample31.rb +1 -1
- data/examples/sample33.rb +10 -10
- data/examples/sample34.rb +1 -1
- data/examples/sample35.rb +7 -7
- data/examples/sample36.rb +2 -2
- data/examples/sample40.rb +4 -4
- data/examples/sample44.rb +72 -72
- data/examples/sample45.rb +4 -4
- data/examples/sample48.rb +7 -7
- data/examples/sample50.rb +1 -1
- data/examples/sample52.rb +2 -2
- data/examples/sample53.rb +2 -2
- data/examples/sample54.rb +3 -3
- data/examples/sample60.rb +2 -2
- data/examples/sample61.rb +2 -2
- data/examples/sample62.rb +2 -2
- data/examples/sample99.rb +15 -15
- data/examples/theory/pert.rb +2 -2
- data/examples/theory/tests.rb +2 -2
- data/lib/graphviz.rb +140 -140
- data/lib/graphviz/attrs.rb +6 -11
- data/lib/graphviz/constants.rb +35 -35
- data/lib/graphviz/core_ext.rb +1 -1
- data/lib/graphviz/dot2ruby.rb +7 -7
- data/lib/graphviz/dsl.rb +5 -5
- data/lib/graphviz/edge.rb +13 -13
- data/lib/graphviz/elements.rb +5 -5
- data/lib/graphviz/ext.rb +1 -1
- data/lib/graphviz/family_tree.rb +15 -15
- data/lib/graphviz/family_tree/couple.rb +11 -11
- data/lib/graphviz/family_tree/generation.rb +6 -6
- data/lib/graphviz/family_tree/person.rb +13 -13
- data/lib/graphviz/graphml.rb +39 -39
- data/lib/graphviz/math/matrix.rb +23 -23
- data/lib/graphviz/node.rb +8 -8
- data/lib/graphviz/nothugly.rb +3 -3
- data/lib/graphviz/theory.rb +8 -8
- data/lib/graphviz/types.rb +3 -3
- data/lib/graphviz/types/arrow_type.rb +3 -3
- data/lib/graphviz/types/color.rb +2 -2
- data/lib/graphviz/types/color_list.rb +2 -2
- data/lib/graphviz/types/esc_string.rb +2 -2
- data/lib/graphviz/types/gv_bool.rb +3 -3
- data/lib/graphviz/types/gv_double.rb +3 -3
- data/lib/graphviz/types/html_string.rb +2 -2
- data/lib/graphviz/types/lbl_string.rb +2 -2
- data/lib/graphviz/types/rect.rb +2 -2
- data/lib/graphviz/types/spline_type.rb +9 -9
- data/lib/graphviz/utils.rb +13 -13
- data/lib/graphviz/utils/colors.rb +35 -35
- data/lib/graphviz/xml.rb +24 -24
- data/setup.rb +4 -4
- data/test/test_graph.rb +9 -9
- data/test/test_subgraph.rb +1 -1
- data/test/test_theory.rb +4 -4
- data/test/test_utils_colors.rb +4 -4
- metadata +2 -2
data/lib/graphviz/node.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Copyright (C) 2004 - 2011 Gregoire Lejeune <gregoire.lejeune@free.fr>
|
2
|
-
#
|
2
|
+
#
|
3
3
|
# This program is free software; you can redistribute it and/or modify
|
4
4
|
# it under the terms of the GNU General Public License as published by
|
5
5
|
# the Free Software Foundation; either version 2 of the License, or
|
6
6
|
# (at your option) any later version.
|
7
|
-
#
|
7
|
+
#
|
8
8
|
# This program is distributed in the hope that it will be useful,
|
9
9
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
10
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
11
|
# GNU General Public License for more details.
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# You should have received a copy of the GNU General Public License
|
14
14
|
# along with this program; if not, write to the Free Software
|
15
15
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
@@ -27,9 +27,9 @@ class GraphViz
|
|
27
27
|
attr_reader :incidents
|
28
28
|
|
29
29
|
# Create a new node
|
30
|
-
#
|
30
|
+
#
|
31
31
|
# * node_id : ID of the node
|
32
|
-
# * parent_graph : Graph
|
32
|
+
# * parent_graph : Graph
|
33
33
|
def initialize( node_id, parent_graph )
|
34
34
|
@neighbors = []
|
35
35
|
@incidents = []
|
@@ -75,7 +75,7 @@ class GraphViz
|
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
|
-
# Calls block once for each attribute of the node, passing the name and value to the
|
78
|
+
# Calls block once for each attribute of the node, passing the name and value to the
|
79
79
|
# block as a two-element array.
|
80
80
|
#
|
81
81
|
# If global is set to false, the block does not receive the attributes set globally
|
@@ -95,7 +95,7 @@ class GraphViz
|
|
95
95
|
|
96
96
|
# Create an edge between the current node and the node +node+
|
97
97
|
def <<( node )
|
98
|
-
if( node.class == Array )
|
98
|
+
if( node.class == Array )
|
99
99
|
node.each do |no|
|
100
100
|
self << no
|
101
101
|
end
|
@@ -116,7 +116,7 @@ class GraphViz
|
|
116
116
|
# _n.color = "blue"
|
117
117
|
# _n.fontcolor = "red"
|
118
118
|
# }
|
119
|
-
#
|
119
|
+
#
|
120
120
|
def set( &b )
|
121
121
|
yield( self )
|
122
122
|
end
|
data/lib/graphviz/nothugly.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# This file use notugly.xsl: An XSL transform to pretty up the SVG output from Graphviz
|
2
|
-
#
|
2
|
+
#
|
3
3
|
# See: http://www.hokstad.com/making-graphviz-output-pretty-with-xsl.html
|
4
4
|
# And: http://www.hokstad.com/making-graphviz-output-pretty-with-xsl-updated.html
|
5
|
-
#
|
5
|
+
#
|
6
6
|
# By Vidar Hokstad and Ryan Shea; Contributions by Jonas Tingborn,
|
7
7
|
# Earl Cummings, Michael Kennedy (Graphviz 2.20.2 compatibility, bug fixes,
|
8
8
|
# testing, lots of gradients)
|
@@ -33,7 +33,7 @@ class GraphViz
|
|
33
33
|
def self.nothugly( file, save = true )
|
34
34
|
xsl = File.join( File.dirname(File.expand_path(__FILE__)), "nothugly", "nothugly.xsl" )
|
35
35
|
out = self.send(XSLT_METHOD, file, xsl)
|
36
|
-
|
36
|
+
|
37
37
|
if save
|
38
38
|
fname = File.join( File.dirname(File.expand_path(file)), File.basename(file))
|
39
39
|
File.open( fname, "w" ) { |io|
|
data/lib/graphviz/theory.rb
CHANGED
@@ -42,7 +42,7 @@ class GraphViz
|
|
42
42
|
# Return the degree of the given node
|
43
43
|
def degree( node )
|
44
44
|
degree = 0
|
45
|
-
name = node
|
45
|
+
name = node
|
46
46
|
if node.kind_of?(GraphViz::Node)
|
47
47
|
name = node.id
|
48
48
|
end
|
@@ -59,7 +59,7 @@ class GraphViz
|
|
59
59
|
return degree_matrix - adjancy_matrix
|
60
60
|
end
|
61
61
|
|
62
|
-
# Return <tt>true</tt> if the graph if symmetric, <tt>false</tt> otherwise
|
62
|
+
# Return <tt>true</tt> if the graph if symmetric, <tt>false</tt> otherwise
|
63
63
|
def symmetric?
|
64
64
|
adjancy_matrix == adjancy_matrix.transpose
|
65
65
|
end
|
@@ -124,7 +124,7 @@ class GraphViz
|
|
124
124
|
if d[arv.index].to_f.infinite?
|
125
125
|
return nil
|
126
126
|
else
|
127
|
-
return( {
|
127
|
+
return( {
|
128
128
|
:path => ch,
|
129
129
|
:distance => d[arv.index]
|
130
130
|
} )
|
@@ -187,7 +187,7 @@ class GraphViz
|
|
187
187
|
return pagerank
|
188
188
|
end
|
189
189
|
|
190
|
-
# Return the list of nodes that are directly accessible from given node
|
190
|
+
# Return the list of nodes that are directly accessible from given node
|
191
191
|
def neighbors(node)
|
192
192
|
if node.class == String
|
193
193
|
@graph.get_node(node).neighbors
|
@@ -231,9 +231,9 @@ class GraphViz
|
|
231
231
|
recursive_dfs(node, visited_nodes, &b)
|
232
232
|
end
|
233
233
|
|
234
|
-
private
|
234
|
+
private
|
235
235
|
def recursive_dfs(node, visited_nodes, &b)
|
236
|
-
node = @graph.get_node(node) if node.kind_of? String
|
236
|
+
node = @graph.get_node(node) if node.kind_of? String
|
237
237
|
b.call(node)
|
238
238
|
visited_nodes << node
|
239
239
|
neighbors(node).each do |n|
|
@@ -256,7 +256,7 @@ class GraphViz
|
|
256
256
|
}
|
257
257
|
|
258
258
|
return matrix
|
259
|
-
end
|
259
|
+
end
|
260
260
|
|
261
261
|
def degree_matrix
|
262
262
|
matrix = GraphViz::Math::Matrix.new( @graph.node_count, @graph.node_count )
|
@@ -312,7 +312,7 @@ class GraphViz
|
|
312
312
|
capth = critical_path_recursion( d, a, [cpath], result, level+1 )
|
313
313
|
else
|
314
314
|
result << cpath
|
315
|
-
end
|
315
|
+
end
|
316
316
|
end
|
317
317
|
end
|
318
318
|
return result
|
data/lib/graphviz/types.rb
CHANGED
@@ -4,16 +4,16 @@ class GraphViz
|
|
4
4
|
def initialize( data )
|
5
5
|
@data = check(data)
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
def output
|
9
9
|
return @data
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def source
|
13
13
|
return @data
|
14
14
|
end
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
Dir.glob( File.dirname( File.expand_path(__FILE__) )+"/types/*.rb" ).each do |f|
|
18
18
|
autoload File.basename(f).gsub(File.extname(f), "").split( "_" ).map{|n| n.capitalize }.join.to_sym, f
|
19
19
|
end
|
@@ -4,7 +4,7 @@
|
|
4
4
|
# "hello\n\t\l\"world\""
|
5
5
|
#
|
6
6
|
# OR
|
7
|
-
#
|
7
|
+
#
|
8
8
|
# >> x = 'hello\n\t\l"world"'
|
9
9
|
# => "hello\\n\\t\\l\"world\""
|
10
10
|
# >> puts x.inspect.gsub( "\\\\", "\\" )
|
@@ -16,11 +16,11 @@ class GraphViz
|
|
16
16
|
def check(data)
|
17
17
|
return data
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
def output
|
21
21
|
return @data.to_s.inspect.gsub( "\\\\", "\\" )
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
alias :to_gv :output
|
25
25
|
alias :to_s :output
|
26
26
|
|
data/lib/graphviz/types/color.rb
CHANGED
@@ -8,11 +8,11 @@ class GraphViz
|
|
8
8
|
@to_ruby = data.split(/\s*:\s*/).map { |c| GraphViz::Types::Color.new(c).to_ruby }
|
9
9
|
return data
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def output
|
13
13
|
return @data.to_s.inspect.gsub( "\\\\", "\\" )
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
alias :to_gv :output
|
17
17
|
alias :to_s :output
|
18
18
|
|
@@ -3,11 +3,11 @@ end
|
|
3
3
|
|
4
4
|
# bool
|
5
5
|
#
|
6
|
-
# For the bool type,
|
6
|
+
# For the bool type,
|
7
7
|
# - TRUE values are represented by "true" or "yes" (case-insensitive), true and any non-zero integer
|
8
8
|
# - FALSE values by "false", "no" or empty string (case-insensitive), false and zero.
|
9
9
|
#
|
10
|
-
# Example
|
10
|
+
# Example
|
11
11
|
#
|
12
12
|
# graph[:center] = "true"
|
13
13
|
# or
|
@@ -25,7 +25,7 @@ class GraphViz
|
|
25
25
|
@to_ruby = true
|
26
26
|
return data
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
if false == data or (data.is_a?(Integer) and data == 0) or (data.is_a?(String) and BOOL_FALSE.include?(data.downcase))
|
30
30
|
@to_ruby = false
|
31
31
|
return data
|
@@ -15,15 +15,15 @@ class GraphViz
|
|
15
15
|
|
16
16
|
raise DoubleException, "Invalid double value for `#{data}`"
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def output
|
20
20
|
return @data.to_s.inspect.gsub( "\\\\", "\\" )
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def to_f
|
24
24
|
@data.to_f
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
alias :to_gv :output
|
28
28
|
alias :to_s :output
|
29
29
|
alias :to_ruby :to_f
|
@@ -4,7 +4,7 @@ class GraphViz
|
|
4
4
|
def check(data)
|
5
5
|
return data
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
def output
|
9
9
|
html = /^<([<|(^<)*<].*)>$/m.match(@data)
|
10
10
|
if html != nil
|
@@ -13,7 +13,7 @@ class GraphViz
|
|
13
13
|
@data.to_s.inspect.gsub( "\\\\", "\\" )
|
14
14
|
end
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
alias :to_gv :output
|
18
18
|
alias :to_s :output
|
19
19
|
alias :to_ruby :output
|
data/lib/graphviz/types/rect.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
class SplineTypeException < RuntimeError
|
2
2
|
end
|
3
3
|
|
4
|
-
# spliteType or point
|
4
|
+
# spliteType or point
|
5
5
|
#
|
6
6
|
# spline ( ';' spline )*
|
7
7
|
# where spline = (endp)? (startp)? point (triple)+
|
@@ -9,16 +9,16 @@ end
|
|
9
9
|
# and endp = "e,%f,%f"
|
10
10
|
# and startp = "s,%f,%f"
|
11
11
|
#
|
12
|
-
# If a spline has points p1 p2 p3 ... pn, (n = 1 (mod 3)), the points correspond
|
13
|
-
# to the control points of a B-spline from p1 to pn. If startp is given, it touches
|
14
|
-
# one node of the edge, and the arrowhead goes from p1 to startp. If startp is not
|
15
|
-
# given, p1 touches a node. Similarly for pn and endp.
|
12
|
+
# If a spline has points p1 p2 p3 ... pn, (n = 1 (mod 3)), the points correspond
|
13
|
+
# to the control points of a B-spline from p1 to pn. If startp is given, it touches
|
14
|
+
# one node of the edge, and the arrowhead goes from p1 to startp. If startp is not
|
15
|
+
# given, p1 touches a node. Similarly for pn and endp.
|
16
16
|
class GraphViz
|
17
17
|
class Types
|
18
18
|
class SplineType < Common
|
19
19
|
FLOAT_MASK = /[-+]?(?:[0-9]*\.[0-9]+|[0-9]+)/
|
20
20
|
ENDP_MASK = /e\s*,\s*#{FLOAT_MASK}\s*,\s*#{FLOAT_MASK}/
|
21
|
-
STARTP_MASK = /s\s*,\s*#{FLOAT_MASK}\s*,\s*#{FLOAT_MASK}/
|
21
|
+
STARTP_MASK = /s\s*,\s*#{FLOAT_MASK}\s*,\s*#{FLOAT_MASK}/
|
22
22
|
POINT_MASK = /#{FLOAT_MASK}\s*,\s*#{FLOAT_MASK}(?:\s*,\s*#{FLOAT_MASK})?!?/
|
23
23
|
TRIPLE_MASK = /#{POINT_MASK}\s+#{POINT_MASK}\s+#{POINT_MASK}/
|
24
24
|
SPLINE_MASK = /(?:#{ENDP_MASK}\s+)?(?:#{STARTP_MASK}\s+)?#{POINT_MASK}(?:\s*#{TRIPLE_MASK})+/
|
@@ -39,11 +39,11 @@ class GraphViz
|
|
39
39
|
|
40
40
|
raise SplineTypeException, "Invalid spline type value"
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
def output
|
44
44
|
return @data.to_s.inspect.gsub( "\\\\", "\\" )
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
alias :to_gv :output
|
48
48
|
alias :to_s :output
|
49
49
|
|
@@ -64,7 +64,7 @@ class GraphViz
|
|
64
64
|
def triples
|
65
65
|
end
|
66
66
|
|
67
|
-
private
|
67
|
+
private
|
68
68
|
def point?
|
69
69
|
not @is_spline
|
70
70
|
end
|
data/lib/graphviz/utils.rb
CHANGED
@@ -5,16 +5,16 @@ module GVUtils
|
|
5
5
|
# (http://copiousfreetime.rubyforge.org/launchy/Launchy/Application.html)
|
6
6
|
# it follow is licence :
|
7
7
|
#
|
8
|
-
# Permission to use, copy, modify, and/or distribute this software for any
|
9
|
-
# purpose with or without fee is hereby granted, provided that the above
|
8
|
+
# Permission to use, copy, modify, and/or distribute this software for any
|
9
|
+
# purpose with or without fee is hereby granted, provided that the above
|
10
10
|
# copyright notice and this permission notice appear in all copies.
|
11
11
|
#
|
12
|
-
# THE SOFTWARE IS PROVIDED AS IS AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
13
|
-
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
14
|
-
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
15
|
-
# SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
16
|
-
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
17
|
-
# OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
12
|
+
# THE SOFTWARE IS PROVIDED AS IS AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
13
|
+
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
14
|
+
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
15
|
+
# SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
16
|
+
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
17
|
+
# OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
18
18
|
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
19
19
|
def find_executable(bin, custom_paths) #:nodoc:
|
20
20
|
system_path = ENV['PATH']
|
@@ -26,13 +26,13 @@ module GVUtils
|
|
26
26
|
return file_path if File.executable?(file_path) and File.file?(file_path)
|
27
27
|
|
28
28
|
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ # WAS: elsif RUBY_PLATFORM =~ /mswin|mingw/
|
29
|
-
found_ext = (ENV['PATHEXT'] || '.exe;.bat;.com').split(";").find {|ext| File.executable?(
|
30
|
-
return
|
29
|
+
found_ext = (ENV['PATHEXT'] || '.exe;.bat;.com').split(";").find {|ext| File.executable?(file_path + ext) }
|
30
|
+
return file_path + found_ext if found_ext
|
31
31
|
end
|
32
32
|
end
|
33
33
|
return nil
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
def escape_path_containing_blanks(path) #:nodoc:
|
37
37
|
path.gsub!(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
|
38
38
|
path_elements = path.split(File::SEPARATOR)
|
@@ -45,7 +45,7 @@ module GVUtils
|
|
45
45
|
end
|
46
46
|
path_elements.join(File::SEPARATOR)
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
def output_and_errors_from_command(cmd) #:nodoc:
|
50
50
|
unless defined? Open3
|
51
51
|
begin
|
@@ -76,5 +76,5 @@ module GVUtils
|
|
76
76
|
raise "Error from #{cmd}:\n#{errors}"
|
77
77
|
end
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
end
|
@@ -2,17 +2,17 @@ require 'graphviz/core_ext'
|
|
2
2
|
|
3
3
|
class GraphViz
|
4
4
|
class Utils
|
5
|
-
class Colors
|
5
|
+
class Colors
|
6
6
|
HEX_FOR_COLOR = /[0-9a-fA-F]{2}/
|
7
7
|
RGBA = /^(#{HEX_FOR_COLOR})(#{HEX_FOR_COLOR})(#{HEX_FOR_COLOR})(#{HEX_FOR_COLOR})?$/
|
8
|
-
|
8
|
+
|
9
9
|
attr_reader :r, :g, :b, :a
|
10
10
|
attr_reader :h, :s, :v
|
11
|
-
|
11
|
+
|
12
12
|
def initialize
|
13
13
|
@r, @g, @b, @a, @h, @s, @v, @color = nil, nil, nil, nil, nil, nil, nil, nil
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def rgb(r, g, b, a = nil)
|
17
17
|
if r.is_a?(Fixnum)
|
18
18
|
r = r.to_s.convert_base(10, 16)
|
@@ -20,64 +20,64 @@ class GraphViz
|
|
20
20
|
unless r.is_a?(String) and HEX_FOR_COLOR.match(r)
|
21
21
|
raise ColorException, "Bad red value"
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
if g.is_a?(Fixnum)
|
25
25
|
g = g.to_s.convert_base(10, 16)
|
26
26
|
end
|
27
27
|
unless g.is_a?(String) and HEX_FOR_COLOR.match(g)
|
28
28
|
raise ColorException, "Bad green value"
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
if b.is_a?(Fixnum)
|
32
32
|
b = b.to_s.convert_base(10, 16)
|
33
33
|
end
|
34
34
|
unless b.is_a?(String) and HEX_FOR_COLOR.match(b)
|
35
35
|
raise ColorException, "Bad blue value"
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
if a.is_a?(Fixnum)
|
39
39
|
a = a.to_s.convert_base(10, 16)
|
40
40
|
end
|
41
41
|
unless a.nil? or (a.is_a?(String) and HEX_FOR_COLOR.match(a))
|
42
42
|
raise ColorException, "Bad alpha value"
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
@r = r
|
46
46
|
@g = g
|
47
47
|
@b = b
|
48
48
|
@a = a
|
49
|
-
|
49
|
+
|
50
50
|
@color = COLORS.key(rgba_string.downcase)
|
51
|
-
|
51
|
+
|
52
52
|
@h, @s, @v = rgb_to_hsv(@r, @g, @b)
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
def hsv(h, s, v)
|
56
56
|
unless h.is_a?(Float) and s.is_a?(Float) and v.is_a?(Float)
|
57
57
|
raise ColorException, "Bas HSV value"
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
@h = h
|
61
61
|
@s = s
|
62
62
|
@v = v
|
63
|
-
|
63
|
+
|
64
64
|
@r, @g, @b = hsv_to_rgb(@h, @s, @v)
|
65
|
-
|
65
|
+
|
66
66
|
@color = COLORS.key(rgba_string.downcase);
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
def name(c = nil)
|
70
70
|
return @color if c.nil?
|
71
71
|
|
72
72
|
@color = c
|
73
|
-
|
73
|
+
|
74
74
|
rgb = COLORS[c]
|
75
75
|
unless rgb.nil?
|
76
76
|
m = RGBA.match(rgb)
|
77
77
|
@r = m[1]
|
78
78
|
@g = m[2]
|
79
79
|
@b = m[3]
|
80
|
-
|
80
|
+
|
81
81
|
@h, @s, @v = rgb_to_hsv(@r, @g, @b)
|
82
82
|
end
|
83
83
|
end
|
@@ -89,7 +89,7 @@ class GraphViz
|
|
89
89
|
nil
|
90
90
|
end
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
def hsv_string(s = ", ")
|
94
94
|
unless @h.nil?
|
95
95
|
"#{@h}#{s}#{@s}#{s}#{@v}"
|
@@ -105,45 +105,45 @@ class GraphViz
|
|
105
105
|
def hsv_to_rgb(h, s, v)
|
106
106
|
Colors.hsv_to_rgb(h, s, v)
|
107
107
|
end
|
108
|
-
|
108
|
+
|
109
109
|
class <<self
|
110
110
|
def rgb(r, g, b, a = nil)
|
111
111
|
color = Colors.new
|
112
112
|
color.rgb(r, g, b, a)
|
113
113
|
color
|
114
114
|
end
|
115
|
-
|
115
|
+
|
116
116
|
def hsv(h, s, v)
|
117
117
|
color = Colors.new
|
118
118
|
color.hsv(h, s, v)
|
119
119
|
color
|
120
120
|
end
|
121
|
-
|
121
|
+
|
122
122
|
def name(c)
|
123
123
|
color = Colors.new
|
124
124
|
color.name(c)
|
125
125
|
color
|
126
126
|
end
|
127
|
-
|
127
|
+
|
128
128
|
def rgb_to_hsv(r, g, b)
|
129
129
|
h, s, v = 0.0, 0.0, 0.0
|
130
|
-
|
130
|
+
|
131
131
|
_r = r.convert_base(16, 10).to_f / 255.0
|
132
132
|
_g = g.convert_base(16, 10).to_f / 255.0
|
133
133
|
_b = b.convert_base(16, 10).to_f / 255.0
|
134
134
|
rgb = [ _r, _g, _b ]
|
135
|
-
|
135
|
+
|
136
136
|
min = rgb.min
|
137
137
|
max = rgb.max
|
138
138
|
v = max
|
139
|
-
|
139
|
+
|
140
140
|
delta = max - min
|
141
141
|
if max != 0.0
|
142
142
|
s = delta / max
|
143
143
|
else
|
144
144
|
return [-1, 0, v]
|
145
145
|
end
|
146
|
-
|
146
|
+
|
147
147
|
if _r == max
|
148
148
|
h = ( _g - _b ) / delta
|
149
149
|
elsif( _g == max )
|
@@ -151,29 +151,29 @@ class GraphViz
|
|
151
151
|
else
|
152
152
|
h = 4 + ( _r - _g ) / delta
|
153
153
|
end
|
154
|
-
|
154
|
+
|
155
155
|
h = h * 60
|
156
156
|
h = h + 360 if h < 0
|
157
157
|
h = h / 360.0
|
158
|
-
|
158
|
+
|
159
159
|
[h, s, v]
|
160
160
|
end
|
161
|
-
|
161
|
+
|
162
162
|
def hsv_to_rgb(h, s, v)
|
163
163
|
_h, _s, _v = h.to_f * 360.0, s.to_f, v.to_f
|
164
|
-
|
165
|
-
if _s == 0.0
|
164
|
+
|
165
|
+
if _s == 0.0
|
166
166
|
r = (_v * 255 ).to_i.to_s.convert_base(10,16)
|
167
167
|
return [r, r, r]
|
168
168
|
end
|
169
|
-
|
169
|
+
|
170
170
|
_h = _h / 60.0
|
171
171
|
i = _h.floor
|
172
172
|
f = _h - i
|
173
173
|
p = _v * ( 1.0 - _s )
|
174
174
|
q = _v * ( 1.0 - _s * f )
|
175
175
|
t = _v * ( 1.0 - _s * ( 1 - f ) )
|
176
|
-
case i
|
176
|
+
case i
|
177
177
|
when 0
|
178
178
|
r = _v
|
179
179
|
g = t
|
@@ -199,7 +199,7 @@ class GraphViz
|
|
199
199
|
g = p
|
200
200
|
b = q
|
201
201
|
end
|
202
|
-
|
202
|
+
|
203
203
|
[
|
204
204
|
(r * 255).to_i.to_s.convert_base(10, 16),
|
205
205
|
(g * 255).to_i.to_s.convert_base(10, 16),
|
@@ -207,7 +207,7 @@ class GraphViz
|
|
207
207
|
]
|
208
208
|
end
|
209
209
|
end
|
210
|
-
|
210
|
+
|
211
211
|
COLORS = {
|
212
212
|
"aliceblue" => "f0f8ff",
|
213
213
|
"antiquewhite" => "faebd7",
|