Base class for graphable objects. It also contain the operators, which return MathViz::Operation subclasses.
Define op as a binary operator
# File lib/mathviz.rb, line 347 def self.binop(op) define_method(op) do |c| MathViz::Operation.new(op, self, c) end end
Return a list of all MathViz::Terms accessible from a binding
# File lib/mathviz.rb, line 335 def self.list_terms(env) eval("local_variables", env).map { |var| value = eval(var.to_s, env) if (value.kind_of?(MathViz::Term)) value else nil end }.compact end
Assign names to named MathViz::Terms, so the name can be effiently looked up from the MathViz::Term object.
# File lib/mathviz.rb, line 325 def self.name_terms!(env) eval("local_variables", env).each do |var| value = eval(var.to_s, env) if value.respond_to? :name= value.name = var.to_s end end end
Only valid after names have been assigned, which means not during graph construction
# File lib/mathviz.rb, line 430 def anonymous? !@name end
Stub
# File lib/mathviz.rb, line 435 def collapse(parentop = nil) [self] end
Graphviz node color
# File lib/mathviz.rb, line 404 def color :black end
A string representation of the node’s data, typically calculated value with units.
# File lib/mathviz.rb, line 368 def data f = to_value if (f.kind_of?(TrueClass) || f.kind_of?(FalseClass)) f.to_s elsif (!f.respond_to? :finite?) f.to_s + with_units elsif (!f.finite?) MathViz::Infinity.to_s elsif (f.floor == f) f.to_i.to_s + with_units else f.to_s + with_units end end
Helper to avoid duplicate nodes
# File lib/mathviz.rb, line 425 def generated? !name.nil? end
Text label for graph nodes
# File lib/mathviz.rb, line 390 def label if (@name) [data, node].join("\n") else data end end
Graphviz node shape
# File lib/mathviz.rb, line 399 def shape :ellipse end
Graphviz node line style
# File lib/mathviz.rb, line 409 def style if anonymous? :dotted elsif constant? :solid else :dashed end end
Extend Graphviz g with a representation of this object
# File lib/mathviz.rb, line 420 def to_dot(g) g[node] [:label => label, :shape => shape, :color => color, :style => style] end
Generated with the Darkfish Rdoc Generator 2.