Class: GraphViz
- Inherits:
-
Object
- Object
- GraphViz
- Includes:
- Constants, Utils
- Defined in:
- lib/graphviz/constants.rb,
lib/graphviz.rb,
lib/graphviz/ext.rb,
lib/graphviz/xml.rb,
lib/graphviz/node.rb,
lib/graphviz/edge.rb,
lib/graphviz/types.rb,
lib/graphviz/attrs.rb,
lib/graphviz/utils.rb,
lib/graphviz/theory.rb,
lib/graphviz/graphml.rb,
lib/graphviz/nothugly.rb,
lib/graphviz/elements.rb,
lib/graphviz/dot_script.rb,
lib/graphviz/types/rect.rb,
lib/graphviz/types/color.rb,
lib/graphviz/math/matrix.rb,
lib/graphviz/family_tree.rb,
lib/graphviz/utils/colors.rb,
lib/graphviz/types/gv_bool.rb,
lib/graphviz/types/gv_double.rb,
lib/graphviz/types/esc_string.rb,
lib/graphviz/types/arrow_type.rb,
lib/graphviz/types/color_list.rb,
lib/graphviz/types/lbl_string.rb,
lib/graphviz/types/spline_type.rb,
lib/graphviz/types/html_string.rb,
lib/graphviz/family_tree/couple.rb,
lib/graphviz/family_tree/person.rb,
lib/graphviz/family_tree/sibling.rb,
lib/graphviz/family_tree/generation.rb
Overview
TODO: Remove
Defined Under Namespace
Modules: Constants, Utils Classes: Attrs, DOTScript, DOTScriptData, DSL, Edge, Elements, Ext, FamilyTree, GraphML, GraphMLError, Math, Node, Theory, Types, XML
Constant Summary
- @@format =
Var: Output format (dot, png, jpeg, …)
nil- @@prog =
Var: program to use (dot|twopi)
"dot"- @@path =
Var: program path
[]
- @@errors =
Var: Error level
1- @@extlibs =
Var: External libraries
[]
Constants included from Constants
Constants::EDGESATTRS, Constants::FORMATS, Constants::GENCS_ATTRS, Constants::GRAPHSATTRS, Constants::GRAPHTYPE, Constants::NODESATTRS, Constants::PROGRAMS, Constants::RGV_VERSION
Instance Attribute Summary (collapse)
-
- (Object) edge
(also: #edge_attrs)
This accessor allow you to set global edges attributes.
-
- (Object) graph
This accessor allow you to set global graph attributes.
-
- (Object) node
(also: #node_attrs)
This accessor allow you to set global nodes attributes.
Class Method Summary (collapse)
-
+ (Object) commonGraph(o1, o2)
:nodoc:.
-
+ (Object) default(hOpts)
Change default options (:use, :path, :errors and :output).
- + (Object) libxslt_transform(xml, xsl)
-
+ (Object) nothugly(file, save = true)
Transform to pretty up the SVG output.
- + (Object) options(hOpts)
-
+ (Object) parse(xFile, hOpts = {}) {|graph| ... }
Create a new graph from a GraphViz File.
-
+ (Object) parse_string(str, hOpts = {}) {|graph| ... }
Create a new graph from a GraphViz File.
- + (Object) xml_xslt_transform(xml, xsl)
Instance Method Summary (collapse)
-
- (Object) <<(oNode)
(also: #>, #-, #>>)
Create an edge between the current cluster and the node or cluster oNode.
-
- (Object) [](xAttrName)
Get the value of the graph attribute xAttrName.
-
- (Object) []=(xAttrName, xValue)
Set value xValue to the graph attribute xAttrName.
-
- (Object) add(h)
Add nodes and edges defined by a Hash.
- - (Object) add_edge(oNodeOne, oNodeTwo, hOpts = {})
-
- (Object) add_edges(node_one, node_two, options = {})
Create a new edge.
-
- (Object) add_graph(xGraphName = nil, hOpts = {}, &block)
(also: #subgraph)
Create a new graph.
- - (Object) add_node(xNodeName, hOpts = {})
-
- (Object) add_nodes(node_name, options = {})
Create a new node.
- - (Object) append_attributes_and_types(script)
-
- (Object) complete
Return a new completed graph.
-
- (Object) complete!
Complete the current graph.
-
- (Boolean) directed?
Return true if the graph is directed.
- - (Object) each_attribut(&b)
-
- (Object) each_attribute(&b)
Calls block once for each attribute of the graph, passing the name and value to the block as a two-element array.
-
- (Object) each_edge(&block)
Allow you to traverse edges.
-
- (Object) each_graph(&block)
Allow you to traverse graphs.
-
- (Object) each_node(&block)
Allow you to traverse nodes.
-
- (Object) edge_count
Get the number of edges.
-
- (Object) find_node(name)
Returns the first node found in the entire graph, starting from the root graph.
-
- (Object) get_edge_at_index(index)
Return the edge object for the given index.
-
- (Object) get_graph(xGraphName) {|graph| ... }
Return the graph object for the given name (or nil).
-
- (Object) get_node(xNodeName) {|node| ... }
Return the node object for the given name (or nil) in the current graph.
-
- (Object) get_node_at_index(index)
Return the node object for the given index.
-
- (Object) graph_attrs
This accessor allow you to set global graph attributes.
-
- (Object) graph_count
Get the number of graphs.
- - (Boolean) has_parent_graph?
-
- (Object) method_missing(idName, *args, &block)
:nodoc:.
-
- (Object) name
(also: #id)
Get the graph name.
-
- (Object) node_count
Get the number of nodes.
-
- (Object) output(hOpts = {})
(also: #save)
Generate the graph.
-
- (Object) pg
:nodoc:.
-
- (Object) pg=(x)
:nodoc:.
-
- (Object) root_graph
Return the root graph.
-
- (Object) search_node(name)
Return the first node found in the current graph, and it subgraphs.
-
- (Object) set_position(xType, xKey, xValue)
:nodoc:.
-
- (Object) to_graph
Create a new graph from the current subgraph.
- - (Object) to_s
-
- (Object) type
Return the graph type (graph digraph).
-
- (Object) type=(x)
:nodoc:.
Methods included from Utils
#escape_path_containing_blanks, #find_executable, #output_and_errors_from_command, #output_from_command
Methods included from Constants
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
- (Object) method_missing(idName, *args, &block)
:nodoc:
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 |
# File 'lib/graphviz.rb', line 350 def method_missing( idName, *args, &block ) #:nodoc: xName = idName.id2name rCod = nil if block # Creating a cluster named '#{xName}' rCod = add_graph( xName, args[0]||{} ) yield( rCod ) else # Create a node named '#{xName}' or search for a node, edge or cluster if @hoNodes.keys.include?( xName ) if( args[0] ) return { xName => args[0] } else return( @hoNodes[xName] ) end end return( @hoGraphs[xName] ) if @hoGraphs.keys.include?( xName ) rCod = add_nodes( xName, args[0]||{} ) end return rCod end |
Instance Attribute Details
- (Object) edge Also known as: edge_attrs
This accessor allow you to set global edges attributes
82 83 84 |
# File 'lib/graphviz.rb', line 82 def edge @edge end |
- (Object) graph
This accessor allow you to set global graph attributes
74 75 76 |
# File 'lib/graphviz.rb', line 74 def graph @graph end |
- (Object) node Also known as: node_attrs
This accessor allow you to set global nodes attributes
78 79 80 |
# File 'lib/graphviz.rb', line 78 def node @node end |
Class Method Details
+ (Object) commonGraph(o1, o2)
:nodoc:
690 691 692 693 694 695 696 697 698 699 700 |
# File 'lib/graphviz.rb', line 690 def self.commonGraph( o1, o2 ) #:nodoc: g1 = o1.pg g2 = o2.pg return o1 if g1.nil? return o2 if g2.nil? return g1 if g1.object_id == g2.object_id return GraphViz::commonGraph( g1, g2 ) end |
+ (Object) default(hOpts)
Change default options (:use, :path, :errors and :output)
715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 |
# File 'lib/graphviz.rb', line 715 def self.default( hOpts ) hOpts.each do |k, v| case k.to_s when "use" @@prog = v when "path" @@path = v.split( "," ).map{ |x| x.strip } when "errors" @@errors = v when "extlibs" @@extlibs = v.split( "," ).map{ |x| x.strip } else warn "Invalid option #{k}!" end end end |
+ (Object) libxslt_transform(xml, xsl)
54 55 56 57 58 59 60 61 62 |
# File 'lib/graphviz/nothugly.rb', line 54 def self.libxslt_transform(xml, xsl) LibXML::XML.default_load_external_dtd = false LibXML::XML.default_substitute_entities = false stylesheet_doc = LibXML::XML::Document.file(xsl) stylesheet = LibXSLT::XSLT::Stylesheet.new(stylesheet_doc) xml_doc = LibXML::XML::Document.file(xml) stylesheet.apply(xml_doc).to_s end |
+ (Object) nothugly(file, save = true)
Transform to pretty up the SVG output
For more information, see www.hokstad.com/making-graphviz-output-pretty-with-xsl.html and www.hokstad.com/making-graphviz-output-pretty-with-xsl-updated.html
You can use the :nothugly option to GraphViz#output :
graph.output( :svg => "myGraph.svg", :nothugly => true )
Or directly on an SVG output graph :
GraphViz.nothugly( "myGraph.svg" )
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/graphviz/nothugly.rb', line 33 def self.nothugly( file, save = true ) xsl = File.join( File.dirname(File.(__FILE__)), "nothugly", "nothugly.xsl" ) out = self.send(XSLT_METHOD, file, xsl) if save fname = File.join( File.dirname(File.(file)), File.basename(file)) File.open( fname, "w" ) { |io| io.print out } else return out end end |
+ (Object) options(hOpts)
732 733 734 |
# File 'lib/graphviz.rb', line 732 def self.( hOpts ) GraphViz::default( hOpts ) end |
+ (Object) parse(xFile, hOpts = {}) {|graph| ... }
Create a new graph from a GraphViz File
Options :
-
:output : Output format (GraphViz::Constants::FORMATS) (default : dot)
-
:file : Output file name (default : none)
-
:use : Program to use (GraphViz::Constants::PROGRAMS) (default : dot)
-
:path : Program PATH
746 747 748 749 750 |
# File 'lib/graphviz.rb', line 746 def self.parse( xFile, hOpts = {}, &block ) graph = Dot2Ruby::new( hOpts[:path], nil, nil ).eval( xFile ) yield( graph ) if( block and graph ) return graph end |
+ (Object) parse_string(str, hOpts = {}) {|graph| ... }
Create a new graph from a GraphViz File
Options :
-
:output : Output format (GraphViz::Constants::FORMATS) (default : dot)
-
:file : Output file name (default : none)
-
:use : Program to use (GraphViz::Constants::PROGRAMS) (default : dot)
-
:path : Program PATH
760 761 762 763 764 |
# File 'lib/graphviz.rb', line 760 def self.parse_string( str, hOpts = {}, &block ) graph = Dot2Ruby::new( hOpts[:path], nil, nil ).eval_string( str ) yield( graph ) if( block and graph ) return graph end |
+ (Object) xml_xslt_transform(xml, xsl)
47 48 49 50 51 52 |
# File 'lib/graphviz/nothugly.rb', line 47 def self.xml_xslt_transform(xml, xsl) xslt = XML::XSLT.new() xslt.xml = xml xslt.xsl = xsl xslt.serve() end |
Instance Method Details
- (Object) <<(oNode) Also known as: >, -, >>
Create an edge between the current cluster and the node or cluster oNode
661 662 663 664 665 666 667 668 669 670 671 |
# File 'lib/graphviz.rb', line 661 def <<( oNode ) raise( ArgumentError, "Edge between root graph and node or cluster not allowed!" ) if self.pg.nil? if( oNode.class == Array ) oNode.each do |no| self << no end else return GraphViz::commonGraph( oNode, self ).add_edges( self, oNode ) end end |
- (Object) [](xAttrName)
Get the value of the graph attribute xAttrName
387 388 389 390 391 392 393 394 395 |
# File 'lib/graphviz.rb', line 387 def []( xAttrName ) if Hash === xAttrName xAttrName.each do |key, value| self[key] = value end else return( @graph[xAttrName].clone ) end end |
- (Object) []=(xAttrName, xValue)
Set value xValue to the graph attribute xAttrName
379 380 381 382 |
# File 'lib/graphviz.rb', line 379 def []=( xAttrName, xValue ) xValue = xValue.to_s if xValue.class == Symbol @graph[xAttrName] = xValue end |
- (Object) add(h)
Add nodes and edges defined by a Hash
325 326 327 328 329 330 331 |
# File 'lib/graphviz.rb', line 325 def add(h) if h.kind_of? Hash h.each do |node, data| add_hash_edge(node, data) end end end |
- (Object) add_edge(oNodeOne, oNodeTwo, hOpts = {})
184 185 186 187 188 189 |
# File 'lib/graphviz.rb', line 184 def add_edge( oNodeOne, oNodeTwo, hOpts = {} ) if oNodeTwo.kind_of? Array or oNodeOne.kind_of? Array raise ArgumentError, "use `add_edges' to add several edges at the same time" end add_edges(oNodeOne, oNodeTwo, hOpts) end |
- (Object) add_edges(node_one, node_two, options = {})
Create a new edge
In:
-
node_one : First node (or node list)
-
node_two : Second Node (or node list)
-
options : Edge attributes
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/graphviz.rb', line 197 def add_edges( node_one, node_two, = {} ) if( node_one.class == Array ) node_one.each do |no| add_edges( no, node_two, ) end else if( node_two.class == Array ) node_two.each do |nt| add_edges( node_one, nt, ) end else edge = GraphViz::Edge::new( node_one, node_two, self ) edge.index = @elements_order.size_of( "edge" ) .each do |xKey, xValue| edge[xKey.to_s] = xValue end @elements_order.push( { "type" => "edge", "value" => edge } ) @loEdges.push( edge ) return( edge ) end end end |
- (Object) add_graph(xGraphName = nil, hOpts = {}, &block) Also known as: subgraph
Create a new graph
In:
-
xGraphName : Graph name
-
hOpts : Graph attributes
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
# File 'lib/graphviz.rb', line 262 def add_graph( xGraphName = nil, hOpts = {}, &block ) if xGraphName.kind_of?(GraphViz) xGraphID = xGraphName.id @hoGraphs[xGraphID] = xGraphName.clone @hoGraphs[xGraphID].type = @oGraphType @hoGraphs[xGraphID].pg = self xGraphName = xGraphID else if xGraphName.kind_of?(Hash) hOpts = xGraphName xGraphName = nil end if xGraphName.nil? xGraphID = String.random(11) xGraphName = "" else xGraphID = xGraphName end @hoGraphs[xGraphID] = GraphViz::new( xGraphName, {:parent => self, :type => @oGraphType}, &block ) hOpts.each do |xKey, xValue| @hoGraphs[xGraphID][xKey.to_s] = xValue end end @elements_order.push( { "type" => "graph", "name" => xGraphName, "value" => @hoGraphs[xGraphID] } ) return( @hoGraphs[xGraphID] ) end |
- (Object) add_node(xNodeName, hOpts = {})
87 88 89 90 91 92 |
# File 'lib/graphviz.rb', line 87 def add_node( xNodeName, hOpts = {} ) if xNodeName.kind_of? Array raise ArgumentError, "use `add_nodes' to add several nodes at the same time" end return add_nodes(xNodeName, hOpts) end |
- (Object) add_nodes(node_name, options = {})
Create a new node
In:
-
xNodeName : Name of the new node
-
hOpts : Node attributes
Return the GraphViz::Node object created
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/graphviz.rb', line 101 def add_nodes(node_name, = {}) if node_name.kind_of? Array node_name.each { |n| add_nodes(n, .clone) } else node = @hoNodes[node_name] if node.nil? @hoNodes[node_name] = GraphViz::Node::new( node_name, self ) @hoNodes[node_name].index = @elements_order.size_of( "node" ) unless .keys.include?(:label) or .keys.include?("label") [:label] = node_name end @elements_order.push( { "type" => "node", "name" => node_name, "value" => @hoNodes[node_name] } ) node = @hoNodes[node_name] end .each do |xKey, xValue| @hoNodes[node_name][xKey.to_s] = xValue end return node end end |
- (Object) append_attributes_and_types(script)
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 |
# File 'lib/graphviz.rb', line 617 def append_attributes_and_types(script) script_data = DOTScriptData.new @elements_order.each { |kElement| p kElement["type"] is_new_type = script_data.type != kElement["type"] if is_new_type script << script_data unless script_data.type.nil? or script_data.empty? script_data = DOTScriptData.new(kElement["type"]) end # Modified by Brandon Coleman verify value is NOT NULL kElement["value"] or raise ArgumentError, "#{kElement["name"]} is nil!" case kElement["type"] when "graph_attr", "node_attr", "edge_attr" script_data.add_attribute(kElement["name"], kElement["value"].to_gv) when "node", "graph" script << kElement["value"].output() when "edge" script << " " + kElement["value"].output( @oGraphType ) else raise ArgumentError, "Don't know what to do with element type '#{kElement['type']}'" end } script << script_data unless script_data.type.nil? or script_data.empty? end |
- (Object) complete
Return a new completed graph
767 768 769 |
# File 'lib/graphviz.rb', line 767 def complete GraphViz.parse_string( root_graph.output( :dot => String ) ) end |
- (Object) complete!
Complete the current graph
772 773 774 775 |
# File 'lib/graphviz.rb', line 772 def complete! # TODO: Keep options complete end |
- (Boolean) directed?
Return true if the graph is directed.
778 779 780 |
# File 'lib/graphviz.rb', line 778 def directed? not((/digraph/ =~ "bla digraph bla").nil?) end |
- (Object) each_attribut(&b)
406 407 408 409 |
# File 'lib/graphviz.rb', line 406 def each_attribut(&b) warn "`GraphViz#each_attribut` is deprecated, please use `GraphViz#each_attribute`" each_attribute(&b) end |
- (Object) each_attribute(&b)
Calls block once for each attribute of the graph, passing the name and value to the block as a two-element array.
401 402 403 404 405 |
# File 'lib/graphviz.rb', line 401 def each_attribute(&b) @graph.each do |k,v| yield(k,v) end end |
- (Object) each_edge(&block)
Allow you to traverse edges
230 231 232 233 234 235 236 237 238 |
# File 'lib/graphviz.rb', line 230 def each_edge( &block ) if block_given? @loEdges.each do |edge| yield(edge) end else return @loEdges end end |
- (Object) each_graph(&block)
Allow you to traverse graphs
312 313 314 315 316 317 318 319 320 |
# File 'lib/graphviz.rb', line 312 def each_graph( &block ) if block_given? @hoGraphs.each do |name, graph| yield( name, graph ) end else return @hoGraphs end end |
- (Object) each_node(&block)
Allow you to traverse nodes
169 170 171 172 173 174 175 176 177 |
# File 'lib/graphviz.rb', line 169 def each_node( &block ) if block_given? @hoNodes.each do |name, node| yield( name, node ) end else return( @hoNodes ) end end |
- (Object) edge_count
Get the number of edges
243 244 245 |
# File 'lib/graphviz.rb', line 243 def edge_count @loEdges.size end |
- (Object) find_node(name)
Returns the first node found in the entire graph, starting from the root graph
142 143 144 145 |
# File 'lib/graphviz.rb', line 142 def find_node(name) root = root_graph return root.search_node(name) end |
- (Object) get_edge_at_index(index)
Return the edge object for the given index
250 251 252 253 |
# File 'lib/graphviz.rb', line 250 def get_edge_at_index( index ) element = @elements_order[index, "edge"] (element.nil?) ? nil : element["value"] end |
- (Object) get_graph(xGraphName) {|graph| ... }
Return the graph object for the given name (or nil)
301 302 303 304 305 306 307 |
# File 'lib/graphviz.rb', line 301 def get_graph( xGraphName, &block ) graph = @hoGraphs[xGraphName] || nil yield( graph ) if( block and graph ) return graph end |
- (Object) get_node(xNodeName) {|node| ... }
Return the node object for the given name (or nil) in the current graph
133 134 135 136 137 138 139 |
# File 'lib/graphviz.rb', line 133 def get_node( xNodeName, &block ) node = @hoNodes[xNodeName] || nil yield( node ) if( block and node ) return node end |
- (Object) get_node_at_index(index)
Return the node object for the given index
161 162 163 164 |
# File 'lib/graphviz.rb', line 161 def get_node_at_index( index ) element = @elements_order[index, "node"] (element.nil?) ? nil : element["value"] end |
- (Object) graph_attrs
This accessor allow you to set global graph attributes
75 76 77 |
# File 'lib/graphviz.rb', line 75 def graph @graph end |
- (Object) graph_count
Get the number of graphs
346 347 348 |
# File 'lib/graphviz.rb', line 346 def graph_count @hoGraphs.size end |
- (Boolean) has_parent_graph?
782 783 784 |
# File 'lib/graphviz.rb', line 782 def has_parent_graph? not @oParentGraph.nil? end |
- (Object) name Also known as: id
Get the graph name
653 654 655 |
# File 'lib/graphviz.rb', line 653 def name @name.clone end |
- (Object) node_count
Get the number of nodes
180 181 182 |
# File 'lib/graphviz.rb', line 180 def node_count @hoNodes.size end |
- (Object) output(hOpts = {}) Also known as: save
Generate the graph
Options :
-
:output : Output format (GraphViz::Constants::FORMATS)
-
:file : Output file name
-
:use : Program to use (GraphViz::Constants::PROGRAMS)
-
:path : Program PATH
-
:<format> => <file> : <file> can be
-
a file name
-
nil, then the output will be printed to STDOUT
-
String, then the output will be returned as a String
-
-
:errors : DOT error level (default 1)
-
0 = Error + Warning
-
1 = Error
-
2 = none
-
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 |
# File 'lib/graphviz.rb', line 435 def output( hOpts = {} ) xDOTScript = DOTScript.new lNotHugly = [] append_attributes_and_types(xDOTScript) xDOTScript << "}" if has_parent_graph? xDOTScript.make_subgraph("#{GraphViz.escape(@name, :unquote_empty => true)}") else hOutput = {} hOpts.each do |xKey, xValue| xValue = xValue.to_s unless xValue.nil? or [Class, TrueClass, FalseClass].include?(xValue.class) case xKey.to_s when "use" if PROGRAMS.index( xValue ).nil? raise ArgumentError, "can't use '#{xValue}'" end @prog = xValue when "path" @path = xValue && xValue.split( "," ).map{ |x| x.strip } when "errors" @errors = xValue when "extlib" @extlibs = xValue.split( "," ).map{ |x| x.strip } when "scale" # Scale input by 'v' (=72) @scale = xValue when "inverty" # Invert y coordinate in output @inverty = xValue when "no_layout" # No layout mode 'v' (=1) @no_layout = xValue when "reduce" # Reduce graph @reduce_graph = xValue when "Lg" # Don't use grid @Lg = xValue when "LO" # Use old attractive force @LO = xValue when "Ln" # Set number of iterations to i @Ln = xValue when "LU" # Set unscaled factor to i @LU = xValue when "LC" # Set overlap expansion factor to v @LC = xValue when "LT" # Set temperature (temperature factor) to v @LT = xValue when "nothugly" begin require 'graphviz/nothugly' @nothugly = true rescue LoadError warn "You must install ruby-xslt or libxslt-ruby to use nothugly option!" @nothugly = false end else if FORMATS.index( xKey.to_s ).nil? raise ArgumentError, "output format '#{xValue}' invalid" end hOutput[xKey.to_s] = xValue end end @output = hOutput if hOutput.size > 0 xStict = ((@strict && @oGraphType == "digraph") ? "strict " : "") xDOTScript.prepend( "#{xStict}#{@oGraphType} #{GraphViz.escape(@name, :unquote_empty => true)} {" ) xOutputString = (@filename == String || @output.any? {|format, file| file == String }) xOutput = "" if @format.to_s == "none" or @output.any? {|fmt, fn| fmt.to_s == "none"} if xOutputString xOutput << xDOTScript else xFileName = @output["none"] || @filename open( xFileName, "w" ) do |h| h.puts xDOTScript end end end if (@format.to_s != "none" and not @format.nil?) or (@output.any? {|format, file| format != "none" } and @output.size > 0) ## Act: Save script and send it to dot t = Tempfile::open( File.basename(__FILE__) ) t.print( xDOTScript ) t.close cmd = find_executable( @prog, @path ) if cmd == nil raise StandardError, "GraphViz not installed or #{@prog} not in PATH. Install GraphViz or use the 'path' option" end cmd = escape_path_containing_blanks(cmd) if IS_JRUBY xOutputWithFile = "" xOutputWithoutFile = "" unless @format.nil? or @format == "none" lNotHugly << @filename if @format.to_s == "svg" and @nothugly if @filename.nil? or @filename == String xOutputWithoutFile = "-T#{@format} " else xOutputWithFile = "-T#{@format} -o#{@filename} " end end @output.each_except( :key => ["none"] ) do |format, file| lNotHugly << file if format.to_s == "svg" and @nothugly if file.nil? or file == String xOutputWithoutFile << "-T#{format} " else xOutputWithFile << "-T#{format} -o#{file} " end end xExternalLibraries = "" @extlibs.each do |lib| xExternalLibraries << "-l#{lib} " end xOtherOptions = "" xOtherOptions += " -s#{@scale}" unless @scale.nil? xOtherOptions += " -y" if @inverty unless @no_layout.nil? xOtherOptions += " -n" xOtherOptions += "2" if @no_layout.to_i == 2 end xOtherOptions += " -x" if @reduce_graph xOtherOptions += " -Lg" if @Lg xOtherOptions += " -LO" if @LO xOtherOptions += " -Ln#{@Ln}" unless @Ln.nil? xOtherOptions += " -LU#{@LU}" unless @LU.nil? xOtherOptions += " -LC#{@LC}" unless @LC.nil? xOtherOptions += " -LT#{@LT}" unless @LT.nil? if IS_JRUBY xCmd = "#{cmd} -q#{@errors} #{xExternalLibraries} #{xOtherOptions} #{xOutputWithFile} #{xOutputWithoutFile} #{t.path}" elsif IS_CYGWIN tmpPath = t.path begin tmpPath = "'" + `cygpath -w #{t.path}`.chomp + "'" rescue warn "cygpath is not installed!" end xCmd = "\"#{cmd}\" -q#{@errors} #{xExternalLibraries} #{xOtherOptions} #{xOutputWithFile} #{xOutputWithoutFile} #{tmpPath}" else xCmd = "\"#{cmd}\" -q#{@errors} #{xExternalLibraries} #{xOtherOptions} #{xOutputWithFile} #{xOutputWithoutFile} #{t.path}" end xOutput << output_from_command( xCmd ) end # Not Hugly lNotHugly.each do |f| if f.nil? or f == String xOutput = GraphViz.nothugly( xOutput, false ) else GraphViz.nothugly( f, true ) end end if xOutputString xOutput else print xOutput end end end |
- (Object) pg
:nodoc:
676 677 678 |
# File 'lib/graphviz.rb', line 676 def pg #:nodoc: @oParentGraph end |
- (Object) pg=(x)
:nodoc:
679 680 681 |
# File 'lib/graphviz.rb', line 679 def pg=(x) #:nodoc: @oParentGraph = x end |
- (Object) root_graph
Return the root graph
686 687 688 |
# File 'lib/graphviz.rb', line 686 def root_graph return( (self.pg.nil?) ? self : self.pg.root_graph ) end |
- (Object) search_node(name)
Return the first node found in the current graph, and it subgraphs
148 149 150 151 152 153 154 155 156 |
# File 'lib/graphviz.rb', line 148 def search_node(name) n = get_node(name) return n unless n.nil? each_graph { |_, g| n = g.search_node(name) return n unless n.nil? } return nil end |
- (Object) set_position(xType, xKey, xValue)
:nodoc:
702 703 704 705 706 707 708 |
# File 'lib/graphviz.rb', line 702 def set_position( xType, xKey, xValue ) #:nodoc: @elements_order.push( { "type" => "#{xType}_attr", "name" => xKey, "value" => xValue } ) end |
- (Object) to_graph
Create a new graph from the current subgraph
412 413 414 415 416 |
# File 'lib/graphviz.rb', line 412 def to_graph graph = self.clone graph.pg = nil return graph end |
- (Object) to_s
646 647 648 |
# File 'lib/graphviz.rb', line 646 def to_s self.output(:none => String) end |
- (Object) type
Return the graph type (graph digraph)
336 337 338 |
# File 'lib/graphviz.rb', line 336 def type @oGraphType end |
- (Object) type=(x)
:nodoc:
339 340 341 |
# File 'lib/graphviz.rb', line 339 def type=(x) #:nodoc: @oGraphType = x end |