2 # Graphiviz wrapper by eto 2003-0227
3 # $Id: graphviz.rb,v 1.1 2003-11-10 08:31:26 eto Exp $
4 # Copyright (C) 2002-2003 Kouichirou Eto, All rights reserved.
5 # This is free software with ABSOLUTELY NO WARRANTY.
6 # You can redistribute it and/or modify it under the terms of the GNU GPL2.
8 class DotElement #======================================================================
12 def method_missing(mid, *args) #
\8eQ
\8dl:ostruct.rb
14 return @attr[mname] if args.length == 0
15 @attr[mname.chop] = args[0] if mname =~ /=$/ #
\91ã
\93ü
18 str = " #{mainstr()} "
19 str << "[" + @attr.map {|k, v| %Q|#{k}="#{v}"| }.join(" ") + "]" if 0 < @attr.length
25 class DotPage < DotElement #======================================================================
31 def mainstr() @name.to_s; end
33 return unless node.is_a? DotNode
37 return unless edge.is_a? DotEdge
42 # str << %Q| size="6, 6"\n|
43 str << @attr.map {|k, v| %Q| #{k}="#{v}"\n| }.join("")
55 class DotNode < DotElement #======================================================================
60 def mainstr() @name.to_s; end
63 class DotEdge < DotElement #======================================================================
64 def initialize(from, to)
68 def mainstr() "#{@from.to_s} -> #{@to.to_s}"; end
71 class Graphviz #======================================================================
\92\8a\8fÛ
\83N
\83\89\83X
75 def initialize(type=DOT)
82 attr_accessor :type, :codepage, :target, :in, :out
83 def post_process() #
\93¯
\82¶
\83t
\83@
\83C
\83\8b\82É
\8fã
\8f\91\82«
\82É
\82·
\82é
\81B
85 str.gsub!(/&#x/, '&#x')
86 #str.gsub!(/font-family:MS Gothic;/, '')
87 #str.gsub!(/font-family:MS Gothic;/, 'font-family:MS-Mincho;')
88 str.gsub!(/font-family:Times New Roman;/, '')
89 open(@out, "w"){|out| out.print str}
93 class GraphvizCLI < Graphviz #====================================================================== Command Line Interface
94 # COMMAND_DIR = "c:\Program Files\ATT\Graphviz\bin"
95 COMMAND_DIR = "" #PATH
\82ª
\82Æ
\82¨
\82Á
\82Ä
\82È
\82¢
\82Æ
\82¾
\82ß
\82Ý
\82½
\82¢
\81B
96 NAMES = "dot twopi neato".split
97 def generate(debug=false)
99 #ar << COMMAND_DIR + NAMES[@type] + ".exe"
100 ar << COMMAND_DIR + NAMES[@type]
115 class GraphvizOLE < Graphviz #====================================================================== Object Linking & Embedding
116 #NAMES = "DOT TWOPI NEATO".split
117 def generate(debug=false)
118 require 'win32ole' #
\82±
\82ñ
\82È
\82Æ
\82±
\82É
\8e\9d\82Á
\82Ä
\82«
\82½
\81B
119 names = "DOT TWOPI NEATO".split
120 @ole = WIN32OLE.new("Wingraphviz." + names[@type])
121 @ole.codepage = cp if @codepage #neato.codepage = 65001 #codepage: 65001 Unicode UTF-8
122 @instr = open(@in).read
124 result = @ole.toSVG(@instr)
125 open(@out, "w"){|out| out.print result}
127 elsif @target =~ /svg/i
128 result = @ole.toPNG(@dot)
132 def nu_to_png(filename=nil)
133 return "" unless @dot.is_a?(String)
134 png = @ole.toPNG(@dot)
135 png.save(filename) unless filename.nil?
138 #p neato.validate(str)
139 #ps = neato.toPS(str)
140 #open("test.ps", "w"){|out| out.print ps }
143 #----------------------------------------------------------------------end.