i
[chise/ruby.git] / chise / graphviz.rb
index 415c1c9..456ac66 100755 (executable)
@@ -4,11 +4,13 @@ class DotElement
   def initialize()
     @attr = Hash.new
   end
+
   def method_missing(mid, *args) #\8eQ\8dl:ostruct.rb
     mname = mid.id2name
     return @attr[mname] if args.length == 0
     @attr[mname.chop] = args[0] if mname =~ /=$/ #\91ã\93ü
   end
+
   def to_s
     str = "  #{mainstr()} "
     str << "[" + @attr.map {|k, v| %Q|#{k}="#{v}"| }.join(" ") + "]" if 0 < @attr.length
@@ -23,15 +25,19 @@ class DotPage < DotElement
     @nodes = []
     @edges = []
   end
+
   def mainstr() @name.to_s; end
+
   def add_node(node)
     return unless node.is_a? DotNode
     @nodes << node
   end
+
   def add_edge(edge)
     return unless edge.is_a? DotEdge
     @edges << edge
   end
+
   def to_s()
     str = "digraph G {\n"
 #    str << %Q|  size="6, 6"\n|
@@ -52,6 +58,7 @@ class DotNode < DotElement
     @name = name
     super()
   end
+
   def mainstr() @name.to_s; end
 end
 
@@ -60,6 +67,7 @@ class DotEdge < DotElement
     @from, @to = from, to
     super()
   end
+
   def mainstr() "#{@from.to_s} -> #{@to.to_s}"; end
 end
 
@@ -90,7 +98,9 @@ end
 class GraphvizCLI < Graphviz
 # COMMAND_DIR = "c:\Program Files\ATT\Graphviz\bin"
   COMMAND_DIR = "" #PATH\82ª\82Æ\82¨\82Á\82Ä\82È\82¢\82Æ\82¾\82ß\82Ý\82½\82¢\81B
-  NAMES = "dot twopi neato".split
+# NAMES = "dot twopi neato".split
+  NAMES = %w(dot twopi neato)
+
   def generate(debug=false)
     ar = []
     #ar << COMMAND_DIR + NAMES[@type] + ".exe"
@@ -111,12 +121,14 @@ end
 
 class GraphvizOLE < Graphviz
   #NAMES = "DOT TWOPI NEATO".split
+
   def generate(debug=false)
     require "win32ole"
     names = "DOT TWOPI NEATO".split
     @ole = WIN32OLE.new("Wingraphviz." + names[@type])
     @ole.codepage = cp if @codepage  #neato.codepage = 65001 #codepage: 65001 Unicode UTF-8 
     @instr = open(@in).read
+
     if @target =~ /svg/i
       result = @ole.toSVG(@instr)
       open(@out, "w"){|out| out.print result}
@@ -126,12 +138,14 @@ class GraphvizOLE < Graphviz
       result.save(@out)
     end
   end
+
   def nu_to_png(filename=nil)
     return "" unless @dot.is_a?(String)
     png = @ole.toPNG(@dot)
     png.save(filename) unless filename.nil?
     return png
   end
+
   #p neato.validate(str)
   #ps = neato.toPS(str)
   #open("test.ps", "w"){|out|  out.print ps  }