n-ary operators
Combine anonymous nodes with the same operator to simply graph
# File lib/mathviz.rb, line 634 def collapse(parentop = nil) @operands = @operands.flat_map {|x| x.collapse(@op)} if anonymous? && parentop == @op @operands else [self] end end
Graphviz node color; differentiates basic mathematical operators (+, -, *, /)
# File lib/mathviz.rb, line 587 def color case @op when :+; :green; when :-; :yellow; when :*; :blue; when :/; :cyan; else :red; end end
# File lib/mathviz.rb, line 625 def constant? @operands.all?(&:constant?) end
# File lib/mathviz.rb, line 629 def finite? @operands.all?(&:finite?) end
Draws edges, and ensure the from nodes is drawn
# File lib/mathviz.rb, line 598 def link_from(g, other, style, label) if label (g[other.to_s] >> g[node]) [:arrowhead => style, :headlabel => @op.to_s, :labeldistance => '2'] else (g[other.to_s] >> g[node]) [:arrowhead => style] end other.to_dot(g) unless other.generated? end
Debugging method; returns string of names and values
# File lib/mathviz.rb, line 572 def long n = @name && (@name + " = ") "(#{n}#{@op} #{@operands.join(',')} = #{to_value})" end
Graphviz node shape; differentiates comparison operators
# File lib/mathviz.rb, line 578 def shape if ([:>, :<, :>=, :<=, :&, :|, :==].include? @op) :ellipse else :box end end
Extend Graphviz g with a representation of this object, and incoming connections
# File lib/mathviz.rb, line 608 def to_dot(g) super link_from(g, @operands.first, :normal, false) @operands.slice(1..-1).each {|x| link_from(g, x, :onormal, true)} end
Generated with the Darkfish Rdoc Generator 2.