class Graphdown::Node
Constants
- FONT_FAMILY
- FONT_SIZE
- MARGIN_BOTTOM
- MARGIN_RIGHT
- PADDING_LEFT
- PADDING_TOP
- WORD_HEIGHT
Attributes
child_edges[R]
label[R]
level[RW]
parent_edges[R]
x[RW]
y[RW]
Public Class Methods
new(label)
click to toggle source
# File lib/graphdown/node.rb, line 15 def initialize(label) @x = 0 @y = 0 @level = 0 @label = label @parent_edges = [] @child_edges = [] end
Public Instance Methods
ancestors()
click to toggle source
# File lib/graphdown/node.rb, line 52 def ancestors ancestors = [] ascend = ->(node) do ancestors << node node.parents.each { |parent| ascend.call(parent) } end parents.each { |parent| ascend.call(parent) } ancestors end
children()
click to toggle source
# File lib/graphdown/node.rb, line 62 def children child_edges.map(&:child) end
connect(child, direction = :forward)
click to toggle source
# File lib/graphdown/node.rb, line 33 def connect(child, direction = :forward) child.level = 1 # Prevent closed path direction = ancestors.include?(child) ? :backward : direction edge = Edge.new(self, child, direction) if direction == :backward self.parent_edges << edge child.child_edges << edge else self.child_edges << edge child.parent_edges << edge end end
descendants()
click to toggle source
# File lib/graphdown/node.rb, line 66 def descendants descendants = [] descend = ->(node) do descendants << node node.children.each { |child| descend.call(child) } end children.each { |child| descend.call(child) } descendants end
height()
click to toggle source
# File lib/graphdown/node.rb, line 29 def height WORD_HEIGHT + PADDING_TOP * 2 end
parents()
click to toggle source
# File lib/graphdown/node.rb, line 48 def parents parent_edges.map(&:parent) end
width()
click to toggle source
# File lib/graphdown/node.rb, line 24 def width text_width = 13 + (@label.length - 1) * 9 text_width + PADDING_LEFT * 2 end