Skip to content

Commit

Permalink
Add the solution, based in check if the node names are valid, this is…
Browse files Browse the repository at this point in the history
… done at output process of the node and the edge. Since the problem just occurs when outputting, more especially in the generate dot file, with don't accept nodes with certain names. I did this way, so would have less impact in the rest of the code.
  • Loading branch information
Joao Guilherme Zeni committed Jun 6, 2014
1 parent 4add3ce commit f924858
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
7 changes: 7 additions & 0 deletions lib/graphviz.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ class GraphViz
attr_accessor :edge
alias_method :edge_attrs, :edge

## Restricted node names list
@reserved_node_names = []

@elements_order = nil

def add_node( xNodeName, hOpts = {} )
Expand All @@ -102,6 +105,9 @@ def add_nodes(node_name, options = {})
if node_name.kind_of? Array
node_name.each { |n| add_nodes(n, options.clone) }
else
puts node_name.class
#if node_name in @reserved_node_names
#end
node = @hoNodes[node_name]

if node.nil?
Expand Down Expand Up @@ -596,6 +602,7 @@ def output( hOpts = {} )
xOutputWithoutFile +
[tmpPath]

puts xCmd
xOutput << output_from_command( xCmd )
end

Expand Down
8 changes: 7 additions & 1 deletion lib/graphviz/edge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,13 @@ def output( oGraphType ) #:nodoc:
xLink = " -- "
end

xOut = self.node_one + xLink + self.node_two
# reserved words, they aren't accepted in dot as node name
reserved_names = ["node", "edge","graph", "digraph", "subgraph", "strict"]

xOut = reserved_names.include?(self.node_one) ? "" << "_" + self.node_one : "" << self.node_one
xOut = xOut << xLink
xOut = reserved_names.include?(self.node_two) ? xOut << "_" + self.node_two : xOut << self.node_two
#xOut = self.node_one + xLink + self.node_two
xAttr = ""
xSeparator = ""
@edge_attributes.data.each do |k, v|
Expand Down
7 changes: 6 additions & 1 deletion lib/graphviz/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,16 @@ def pg #:nodoc:
end

def output #:nodoc:
# reserved words, they aren't accepted in dot as node name
reserved_names = ["node", "edge","graph", "digraph", "subgraph", "strict"]
#node_id = @node_id.clone
#node_id = '"' << node_id << '"' if node_id.match( /^[a-zA-Z_]+[a-zA-Z0-9_\.]*$/ ).nil?
node_id = GraphViz.escape(@node_id)

xOut = "" << node_id
# add a check to see if the node names are valid
# if they aren't is added an _ before
# and the print staies the same, because of the label
xOut = reserved_names.include?(node_id) ? "" << "_" + node_id : "" << node_id
xAttr = ""
xSeparator = ""

Expand Down

0 comments on commit f924858

Please sign in to comment.