Skip to content

Commit

Permalink
Ok, maybe it was too much
Browse files Browse the repository at this point in the history
  • Loading branch information
glejeune committed Jan 14, 2010
1 parent c5b11e1 commit 3fa77d5
Show file tree
Hide file tree
Showing 42 changed files with 186 additions and 621 deletions.
9 changes: 8 additions & 1 deletion examples/HTML-Labels.rb
Expand Up @@ -7,7 +7,14 @@

g.add_node( "HTML" )

g.add_node( "struct1", "html" => '<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0"> <TR><TD>left</TD><TD PORT="f1">mid dle</TD><TD PORT="f2">right</TD></TR> </TABLE>>]; struct2 [label=< <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0"> <TR><TD PORT="f0">one</TD><TD>two</TD></TR> </TABLE>')
g.add_node( "struct1", "html" => '
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
<TR>
<TD>left</TD>
<TD PORT="f1">mid dle</TD>
<TD PORT="f2">right</TD>
</TR>
</TABLE>' )

g.add_node( "struct2", "html" => '<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0"> <TR><TD PORT="f0">one</TD><TD>two</TD></TR> </TABLE>' )
g.add_node( "struct3", "html" => '<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4"> <TR> <TD ROWSPAN="3">hello<BR/>world</TD> <TD COLSPAN="3">b</TD> <TD ROWSPAN="3">g</TD> <TD ROWSPAN="3">h</TD> </TR> <TR> <TD>c</TD><TD PORT="here">d</TD><TD>e</TD> </TR> <TR> <TD COLSPAN="3">f</TD> </TR> </TABLE>' )
Expand Down
2 changes: 1 addition & 1 deletion examples/dot/hello_test.rb
Expand Up @@ -10,5 +10,5 @@
g.get_node("World") { |n|
n.label = "Le Monde"
}
}.output(:png => "sample.png")
}.output(:png => "#{$0}.png")

2 changes: 1 addition & 1 deletion examples/sample29.rb
Expand Up @@ -5,4 +5,4 @@

GraphViz.new(:G){ |g|
g.add_node("\"Hello.\"\nHow are you ?", :href => "http://www.website.com", :tooltip => "\"Hello.\"\nHow are you ?", :shape => "ellipse", :color => "#FF0000")
}.save( :svg => "#{$0}.svg" )
}.save( :canon => "#{$0}.gv" )
2 changes: 1 addition & 1 deletion examples/testxml.rb
Expand Up @@ -4,4 +4,4 @@
require 'graphviz/xml'

gvxml = GraphViz::XML::new( "test.xml", :text => true, :attrs => true )
gvxml.output( :png => "#{$0}.png", :use => "dot", :path => ARGV[0] )
gvxml.output( :png => "#{$0}.png", :use => "dot" )
27 changes: 14 additions & 13 deletions lib/graphviz.rb
Expand Up @@ -47,7 +47,7 @@ class GraphViz
@@prog = "dot"
@prog
## Var: program path
@@path = nil
@@path = []
@path
## Var: Error level
@@errors = 1
Expand Down Expand Up @@ -298,15 +298,15 @@ def output( *hOpt )

case kElement["type"]
when "graph_attr"
xData << xSeparator + kElement["name"] + " = \"" + kElement["value"] + "\""
xData << xSeparator + kElement["name"] + " = " + kElement["value"].to_gv
xSeparator = "; "

when "node_attr"
xData << xSeparator + kElement["name"] + " = \"" + kElement["value"] + "\""
xData << xSeparator + kElement["name"] + " = " + kElement["value"].to_gv
xSeparator = ", "

when "edge_attr"
xData << xSeparator + kElement["name"] + " = \"" + kElement["value"] + "\""
xData << xSeparator + kElement["name"] + " = " + kElement["value"].to_gv
xSeparator = ", "

when "node"
Expand Down Expand Up @@ -361,7 +361,7 @@ def output( *hOpt )
end
@prog = xValue
when "path"
@path = xValue
@path = xValue.split( "," )
when "errors"
@errors = xValue
else
Expand Down Expand Up @@ -521,7 +521,7 @@ def self.default( hOpts )
when "use"
@@prog = v
when "path"
@@path = v
@@path = v.split( "," )
when "errors"
@@errors = v
when "output"
Expand Down Expand Up @@ -632,7 +632,7 @@ def initialize( xGraphName, *hOpt, &block )
end
@oGraphType = xValue.to_s
when "path"
@path = xValue.to_s
@path = xValue.split( "," )
when "errors"
@errors = xValue
else
Expand All @@ -648,10 +648,10 @@ def initialize( xGraphName, *hOpt, &block )
# Escape a string to be acceptable as a node name in a graphviz input file
#
def self.escape(str, force = false ) #:nodoc:
#if force or str.match( /\A[a-zA-Z_]+[a-zA-Z0-9_:]*\Z/ ).nil?
# '"' + str.gsub('"', '\\"').gsub("\n", '\\\\n').gsub(".","\\.") + '"'
if force or str.match( /\A[a-zA-Z_]+[a-zA-Z0-9_:\.]*\Z/ ).nil?
'"' + str.gsub('"', '\\"').gsub("\n", '\\\\n') + '"'
if force or str.match( /\A[a-zA-Z_]+[a-zA-Z0-9_:]*\Z/ ).nil?
'"' + str.gsub('"', '\\"').gsub("\n", '\\\\n').gsub(".","\\.") + '"'
#if force or str.match( /\A[a-zA-Z_]+[a-zA-Z0-9_:\.]*\Z/ ).nil?
# '"' + str.gsub('"', '\\"').gsub("\n", '\\\\n') + '"'
else
str
end
Expand All @@ -672,8 +672,9 @@ def self.escape(str, force = false ) #:nodoc:
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
# OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
def find_executable(bin = @prog, *paths) #:nodoc:
paths = ENV['PATH'].split(File::PATH_SEPARATOR) if paths.empty?
def find_executable(bin, paths) #:nodoc:
paths = ENV['PATH'].split(File::PATH_SEPARATOR) if paths.nil? or paths.empty?

paths.each do |path|
file = (path.nil?)?bin:File.join(path,bin)
if File.executable?(file) then
Expand Down
17 changes: 2 additions & 15 deletions lib/graphviz/attrs.rb
Expand Up @@ -42,23 +42,10 @@ def []=( xKey, xValue )
raise ArgumentError, "#{@name} attribut '#{xKey.to_s}' invalid"
end

value = ArgumentError
@attributs[xKey.to_s].each do |type|
begin
value = GraphViz::Types.const_get(type).new( xValue )
break
rescue ArgumentError
nil
end
end

if value == ArgumentError
raise ArgumentError, "Value `#{xValue}' not allowed for attribut #{xKey}, type #{@attributs[xKey.to_s].join(" or ")}!"
end
@data[xKey.to_s] = value
@data[xKey.to_s] = GraphViz::Types.const_get(@attributs[xKey.to_s]).new( xValue )

if @graphviz.nil? == false
@graphviz.set_position( @name, xKey.to_s, value )
@graphviz.set_position( @name, xKey.to_s, @data[xKey.to_s] )
end
end
end
Expand Down

0 comments on commit 3fa77d5

Please sign in to comment.