Browse files

Add multiple outputs support

  • Loading branch information...
1 parent 831a0cd commit 61cd643ab56945cc0c012f9233e6973bdc9b54a3 greg committed Oct 10, 2009
View
2 ChangeLog
@@ -3,6 +3,8 @@
* Add the ability to create edge like that : node1 << node2 << node3 ...
* Complete README
* Add a DOT parser. This parser has a lot of limitations. So don't use it in a production context !
+* :output and :file options are deprecated, please use :<format> => :<file>
+* You can now specify multiple outputs via :<format> => :<file> (see sample 22).
0.9.0 :
* Add fdp example (sample 15)
View
2 examples/sample01.rb
@@ -29,4 +29,4 @@
g.add_edge( main, printf )
g.add_edge( execute, compare )
-g.output( :output => "png", :file => "#{$0}.png" )
+g.output( :png => "#{$0}.png" )
View
6 examples/sample02.rb
@@ -5,9 +5,9 @@
g = nil
if ARGV[0]
- g = GraphViz::new( "G", :output => "png", :path => ARGV[0] )
+ g = GraphViz::new( "G", :path => ARGV[0] )
else
- g = GraphViz::new( "G", :output => "png" )
+ g = GraphViz::new( "G" )
end
g.node[:shape] = "ellipse"
@@ -39,4 +39,4 @@
g.add_edge( main, printf, :color => "red", :style => "bold", :label => "100 times" )
g.add_edge( execute, compare, :color => "red" )
-g.output( :file => "#{$0}.png" )
+g.output( :png => "#{$0}.png" )
View
6 examples/sample03.rb
@@ -5,9 +5,9 @@
g = nil
if ARGV[0]
- g = GraphViz::new( "G", "output" => "png", "path" => ARGV[0] )
+ g = GraphViz::new( "G", "path" => ARGV[0] )
else
- g = GraphViz::new( "G", "output" => "png" )
+ g = GraphViz::new( "G" )
end
g.node["shape"] = "ellipse"
@@ -28,4 +28,4 @@
g.add_edge( b, c )
g.add_edge( b, d )
-g.output( :file => "#{$0}.png" )
+g.output( :png => "#{$0}.png" )
View
6 examples/sample04.rb
@@ -5,9 +5,9 @@
g = nil
if ARGV[0]
- g = GraphViz::new( "structs", "output" => "png", "path" => ARGV[0] )
+ g = GraphViz::new( "structs", "path" => ARGV[0] )
else
- g = GraphViz::new( "structs", "output" => "png" )
+ g = GraphViz::new( "structs" )
end
g.node["shape"] = "record"
@@ -19,4 +19,4 @@
g.add_edge( struct1, struct2 )
g.add_edge( struct1, struct3 )
-g.output( :file => "#{$0}.png" )
+g.output( :png => "#{$0}.png" )
View
2 examples/sample05.rb
@@ -29,4 +29,4 @@
g.add_edge( main, printf )
g.add_edge( execute, compare )
-g.output( "output" => "png", :file => "#{$0}.png" )
+g.output( :png => "#{$0}.png" )
View
4 examples/sample06.rb
@@ -1,7 +1,7 @@
$:.unshift( "../lib" );
require "graphviz"
-GraphViz::new( "G", :output => "png", :rankdir => "LR", :type => "graph" ) { |graph|
+GraphViz::new( "G", :rankdir => "LR", :type => "graph" ) { |graph|
graph.cluster0 { |cluster|
cluster[:label] = "Back Office"
@@ -43,4 +43,4 @@
graph.cluster0.grobil << graph.cluster1.dupond
graph.cluster1.dupont << graph.cluster2.door
graph.cluster1.dupond << graph.cluster2.door
-}.output( :path => '/usr/local/bin/', :file => "#{$0}.png" )
+}.output( :path => '/usr/local/bin/', :png => "#{$0}.png" )
View
4 examples/sample07.rb
@@ -3,7 +3,7 @@
$:.unshift( "../lib" );
require "graphviz"
-GraphViz::options( :output => "png", :use => "dot" )
+GraphViz::options( :use => "dot" )
if ARGV[0]
GraphViz::options( :path => ARGV[0] )
@@ -20,4 +20,4 @@
g.add_edge( "struct1:f1", "struct2:f0" )
g.add_edge( "struct1:f2", "struct3:here" )
-g.output( :file => "#{$0}.png" )
+g.output( :png => "#{$0}.png" )
View
6 examples/sample08.rb
@@ -5,9 +5,9 @@
g = nil
if ARGV[0]
- g = GraphViz::new( "G", "output" => "png", "nodesep" => ".05", "rankdir" => "LR", "path" => ARGV[0] )
+ g = GraphViz::new( "G" "nodesep" => ".05", "rankdir" => "LR", "path" => ARGV[0] )
else
- g = GraphViz::new( "G", "output" => "png", "nodesep" => ".05", "rankdir" => "LR" )
+ g = GraphViz::new( "G", "nodesep" => ".05", "rankdir" => "LR" )
end
g.node["shape"] = "record"
@@ -31,4 +31,4 @@
g.add_edge( "node2:p", "node6:n" )
g.add_edge( "node4:p", "node7:n" )
-g.output( :file => "#{$0}.png" )
+g.output( :png => "#{$0}.png" )
View
6 examples/sample09.rb
@@ -5,9 +5,9 @@
g = nil
if ARGV[0]
- g = GraphViz::new( "G", "output" => "png", "path" => ARGV[0] )
+ g = GraphViz::new( "G", "path" => ARGV[0] )
else
- g = GraphViz::new( "G", "output" => "png" )
+ g = GraphViz::new( "G" )
end
g.node["shape"] = "ellipse"
@@ -47,4 +47,4 @@
g.add_edge( a3, endn )
g.add_edge( b3, endn )
-g.output( :file => "#{$0}.png" )
+g.output( :png => "#{$0}.png" )
View
6 examples/sample10.rb
@@ -5,9 +5,9 @@
g = nil
if ARGV[0]
- g = GraphViz::new( "G", "output" => "png", "path" => ARGV[0] )
+ g = GraphViz::new( "G", "path" => ARGV[0] )
else
- g = GraphViz::new( "G", "output" => "png" )
+ g = GraphViz::new( "G" )
end
g.node["shape"] = "ellipse"
@@ -47,4 +47,4 @@
g.add_edge( a3, endn )
g.add_edge( b3, endn )
-g.output( :file => "#{$0}.png" )
+g.output( :png => "#{$0}.png" )
View
10 examples/sample22.rb
@@ -0,0 +1,10 @@
+#!/usr/bin/ruby
+
+$:.unshift( "../lib" );
+require "graphviz"
+
+GraphViz::new( "mainmap" ) { |graph|
+ graph[:URL] = "http://www.research.att.com/base.html"
+ graph.command( :URL => "http://www.research.att.com/command.html" )
+ (graph.command << graph._output( :label => "output" ))[:URL] = "colors.html"
+}.output( :canon => nil, :cmapx => "#{$0}.html", :png => "#{$0}.png" )
View
41 lib/graphviz.rb
@@ -29,10 +29,12 @@ class GraphViz
public
## Var: Output format (dot, png, jpeg, ...)
- @@format = "canon"
+ @@format = nil #"canon"
@format
## Var: Output file name
@filename
+ ## Var: Output format and file
+ @output
## Var: program to use (dot|twopi)
@@prog = "dot"
@prog
@@ -233,8 +235,9 @@ def []( xAttrName )
# :file : Output file name
# :use : Program to use (Constants::PROGRAMS)
# :path : Program PATH
+ # :<format> => :<file>
#
- def output( *hOpt )
+ def output( *hOpt )
xDOTScript = ""
xLastType = nil
xSeparator = ""
@@ -317,14 +320,16 @@ def output( *hOpt )
else
if hOpt.nil? == false and hOpt[0].nil? == false
hOpt[0].each do |xKey, xValue|
- xValue = xValue.to_s
+ xValue = xValue.to_s unless xValue.nil?
case xKey.to_s
when "output"
+ warn ":output option is deprecated, please use :<format> => :<file>"
if FORMATS.index( xValue ).nil? == true
raise ArgumentError, "output format '#{xValue}' invalid"
end
@format = xValue
when "file"
+ warn ":file option is deprecated, please use :<format> => :<file>"
@filename = xValue
when "use"
if PROGRAMS.index( xValue ).nil? == true
@@ -334,7 +339,10 @@ def output( *hOpt )
when "path"
@path = xValue
else
- raise ArgumentError, "option #{xKey.to_s} unknown"
+ if FORMATS.index( xKey.to_s ).nil? == true
+ raise ArgumentError, "output format '#{xValue}' invalid"
+ end
+ @output[xKey.to_s] = xValue
end
end
end
@@ -354,9 +362,24 @@ def output( *hOpt )
raise StandardError, "GraphViz not installed or #{@prog} not in PATH. Install GraphViz or use the 'path' option"
end
- xFile = ""
- xFile = "-o #{@filename}" if @filename.nil? == false
- xCmd = "#{cmd} -T#{@format} #{xFile} #{t.path}"
+ xOutputWithFile = ""
+ xOutputWithoutFile = ""
+ unless @format.nil?
+ if @filename.nil?
+ xOutputWithoutFile = "-T#{@format} "
+ else
+ xOutputWithFile = "-T#{@format} -o#{@filename} "
+ end
+ end
+ @output.each do |format, file|
+ if file.nil?
+ xOutputWithoutFile << "-T#{format} "
+ else
+ xOutputWithFile << "-T#{format} -o#{file} "
+ end
+ end
+
+ xCmd = "#{cmd} #{xOutputWithFile} #{xOutputWithoutFile} #{t.path}"
f = IO.popen( xCmd )
print f.readlines
@@ -428,6 +451,7 @@ def self.default( hOpts )
when "path"
@@path = v
when "output"
+ warn ":output option is deprecated!"
@@format = v
else
warn "Invalide option #{k}!"
@@ -489,6 +513,7 @@ def initialize( xGraphName, *hOpt, &block )
@format = @@format
@prog = @@prog
@path = @@path
+ @output = {}
@elements_order = Array::new()
@@ -507,6 +532,7 @@ def initialize( xGraphName, *hOpt, &block )
hOpt[0].each do |xKey, xValue|
case xKey.to_s
when "output"
+ warn ":output option is deprecated, please use :<format> => :<file>"
if FORMATS.index( xValue.to_s ).nil? == true
raise ArgumentError, "output format '#{xValue}' invalid"
end
@@ -517,6 +543,7 @@ def initialize( xGraphName, *hOpt, &block )
end
@prog = xValue.to_s
when "file"
+ warn ":file option is deprecated, please use :<format> => :<file>"
@filename = xValue.to_s
when "parent"
@oParentGraph = xValue

0 comments on commit 61cd643

Please sign in to comment.