class Accessibility::Graph::Node

@todo Graphs could be nicer looking. That is, nodes could be much

more easily identifiable, by allowing different classes to tell
the node more about itself. A mixin module/protocol should
probably be created, just as with the inspector mixin, and added
to abstract base and overridden as needed in subclasses. In this
way, an object can be more specific about what shape it is, how
it is coloured, etc.
Reference: http://www.graphviz.org/doc/info/attrs.html

A node in the UI hierarchy. Used by {Accessibility::Graph} in order to build Graphviz DOT graphs.

Constants

BLACK

@private @return [String]

BOLD

@private @return [String]

BOX

@private @return [String]

EMPTY_STRING

@private @return [String]

FILLED

@private @return [String]

GREY

@private @return [String]

NAMESPACE

@private @return [String]

OCTAGON

@private @return [String]

OVAL

@private @return [String]

QUOTE

@private @return [String]

SOLID

@private @return [String]

Attributes

element[R]

@return [AX::Element]

id[R]

@return [String]

Public Class Methods

new(element) click to toggle source

@param element [AX::Element]

# File lib/accessibility/graph.rb, line 35
def initialize element
  @element = element
  @id      = "element_#{element.object_id}"
end

Public Instance Methods

to_dot() click to toggle source

@return [String]

# File lib/accessibility/graph.rb, line 41
def to_dot
  "#{@id} #{identifier} [shape=#{shape}] [style=#{style}] [color=#{colour}]"
end

Private Instance Methods

colour() click to toggle source
# File lib/accessibility/graph.rb, line 82
def colour
  if @element.attributes.include?(:enabled)
    return GREY unless @element.attribute(:enabled)
  end
  BLACK
end
identifier() click to toggle source
# File lib/accessibility/graph.rb, line 48
def identifier
  klass = @element.class.to_s.split(NAMESPACE).last
  ident = @element.pp_identifier.to_s.dup
  if ident.length > 12
    ident = "#{ident[0...12]}..."
  end
  ident << '"' if ident[1] == QUOTE && ident[-1] != QUOTE
  ident.gsub! /"/, '\"'
  ident.gsub! /\\/, '\\'
  "[label = \"#{klass}#{ident}\"]"
end
shape() click to toggle source
# File lib/accessibility/graph.rb, line 60
def shape
  if @element.attributes.include?(:focused) && @element.attribute(:focused)
    OCTAGON
  elsif @element.actions.empty?
    OVAL
  else
    BOX
  end
end
style() click to toggle source
# File lib/accessibility/graph.rb, line 70
def style
  # fill in the node if it is disabled (greyed out effect)
  if @element.attributes.include?(:enabled)
    return FILLED unless @element.attribute(:enabled)
  end
  # bold if focused and no children
  if @element.attributes.include?(:focused) && @element.attribute(:focused)
    return BOLD if @element.size_of(:children).zero?
  end
  SOLID
end