Permalink
Browse files

Add strict digraph support

  • Loading branch information...
glejeune committed Oct 22, 2010
1 parent 4b30d59 commit b8d10d28e0c2a58e57bab4fe9c859b114e02e8a8
Showing with 79 additions and 2 deletions.
  1. +1 −0 AUTHORS
  2. +11 −0 README.rdoc
  3. +24 −0 examples/dot/this_crach_with_dot_2.20.dot
  4. +33 −0 examples/sample58.rb
  5. +8 −1 lib/graphviz.rb
  6. +2 −1 lib/graphviz/constants.rb
View
@@ -10,6 +10,7 @@ hipe <http://github.com/hipe>
Stefan Huber <http://github.com/MSNexploder>
Nigel Thorne <http://github.com/NigelThorne>
Rolf Timmermans <http://github.com/rolftimmermans>
+Jonas Elfström <http://github.com/jonelf>
Thanks to :
View
@@ -16,6 +16,17 @@ Interface to the GraphViz graphing tool
== CHANGELOG
+=== 0.9.19 :
+* Add strict digraph support (by Jonas Elfström) (see sample58.rb)
+ g = GraphViz.new(:G, :type => "strict digraph")
+ # or
+ g = GraphViz.new(:G, :type => "digraph", :strict => true)
+ # or
+ g = GraphViz.digraph(:G, :strict => true)
+ # or
+ g = GraphViz.strict_digraph(:G)
+
+
=== 0.9.18 :
* JRuby bug correction (by Nigel Thorne)
* Fix autoload problem for Rubinius (by Rolf Timmermans)
@@ -0,0 +1,24 @@
+graph A
+ {
+ graph [nodesep="0.10", size="7,5", bb="0,0,737,832"];
+ node [fontsize="12.00", shape=circle, height = 0.4 width = 0.4 fixedsize="true"];
+ 779 -- 780 [label = 6.5 style = "bold" ];
+ 522 -- 523 [label = 6.2 style = "bold" ];
+ 527 -- 528 [label = 6.0 style = "bold" ];
+ 752 -- 753 [label = 5.1 style = "solid"];
+ 576 -- 577 [label = 5.1 style = "solid"];
+ 578 -- 579 [label = 4.8 style = "dashed"];
+ 757 -- 758 [label = 4.6 style = "dashed"];
+ 696 -- 697 [label = 4.5 style = "dashed"];
+ 542 -- 543 [label = 4.4 style = "dashed"];
+ 723 -- 724 [label = 4.4 style = "dashed"];
+ 495 -- 496 [label = 4.4 style = "dashed"];
+ 459 -- 460 [label = 4.3 style = "dashed"];
+ 784 -- 785 [label = 4.2 style = "dashed"];
+ 518 -- 519 [label = 4.2 style = "dashed"];
+ 894 -- 895 [label = 4.1 style = "dashed"];
+ 435 -- 436 [label = 4.1 style = "dashed"];
+ 322 -- 323 [label = 4.1 style = "dashed"];
+ 545 -- 546 [label = 4.1 style = "dashed"];
+ 513 -- 514 [label = 4.0 style = "dashed"];
+ }
View
@@ -0,0 +1,33 @@
+#!/usr/bin/ruby
+
+# By Jonas Elfström - http://github.com/jonelf
+$:.unshift( "../lib" )
+require 'graphviz'
+
+@min_level=1
+@max_level=12
+@max_depth=10
+start_level=6
+
+@g = GraphViz.new(:G, :type => "strict digraph")
+# or @g = GraphViz.new(:G, :type => "digraph", :strict => true)
+# or @g = GraphViz.digraph(:G, :strict => true)
+# or @g = GraphViz.strict_digraph(:G)
+
+def add_node(level, depth, parent)
+ if depth<@max_depth
+ current=[level, depth].join(",")
+
+ sub=level<=>@min_level
+ add=@max_level<=>level
+ add_node(level-sub, depth+1, current)
+ add_node(level+add, depth+1, current)
+
+ @g.add_node(current).label=level.to_s
+ @g.add_edge(parent, current) unless parent=="00"
+ end
+end
+
+add_node(start_level, 0, "00")
+
+@g.output( :png => "#{$0}.png" )
View
@@ -479,7 +479,8 @@ def output( hOpts = {} )
@output = hOutput if hOutput.size > 0
- xDOTScript = ("#{@oGraphType} #{GraphViz.escape(@name)} {\n" << xDOTScript).gsub( "\0", "" )
+ xStict = ((@strict && @oGraphType == "digraph") ? "strict " : "")
+ xDOTScript = ("#{xStict}#{@oGraphType} #{GraphViz.escape(@name)} {\n" << xDOTScript).gsub( "\0", "" )
xOutputString = (@filename == String ||
@output.any? {|format, file| file == String })
@@ -705,6 +706,7 @@ def initialize( xGraphName, hOpts = {}, &block )
@extlibs = @@extlibs
@output = {}
@nothugly = false
+ @strict = false
@elements_order = GraphViz::Elements::new()
@@ -744,6 +746,8 @@ def initialize( xGraphName, hOpts = {}, &block )
@oGraphType = xValue.to_s
when "path"
@path = xValue.split( "," ).map{ |x| x.strip }
+ when "strict"
+ @strict = (xValue ? true : false)
when "errors"
@errors = xValue
when "extlibs"
@@ -762,6 +766,9 @@ def self.graph( xGraphName, hOpts = {}, &block )
def self.digraph( xGraphName, hOpts = {}, &block )
new( xGraphName, hOpts.symbolize_keys.merge( {:type => "digraph"} ), &block )
end
+ def self.strict_digraph( xGraphName, hOpts = {}, &block )
+ new( xGraphName, hOpts.symbolize_keys.merge( {:type => "digraph", :strict => true} ), &block )
+ end
#
# Escape a string to be acceptable as a node name in a graphviz input file
@@ -103,7 +103,8 @@ module Constants
## Const: graphs type
GRAPHTYPE = [
"digraph",
- "graph"
+ "graph",
+ "strict digraph"
]
def self.getAttrsFor( x )

0 comments on commit b8d10d2

Please sign in to comment.