Class: Dominikh::Graph
- Inherits:
-
DynamicIcon
- Object
- DynamicIcon
- Dominikh::Graph
- Defined in:
- lib/subtle/dominikh/graph.rb
Instance Attribute Summary collapse
-
#color_ranges ⇒ Object
Returns the value of attribute color_ranges.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#color ⇒ Subtlext::Color
Returns the color of the graph.
-
#initialize(*args) ⇒ Graph
constructor
A new instance of Graph.
-
#render ⇒ void
Draws the graph.
- #to_str ⇒ String (also: #to_s)
Constructor Details
#initialize(*args) ⇒ Graph
Returns a new instance of Graph.
8 9 10 11 12 13 |
# File 'lib/subtle/dominikh/graph.rb', line 8 def initialize(*args) super @color_ranges = {} @last_rendered_value = nil @value = 0 end |
Instance Attribute Details
#color_ranges ⇒ Object
Returns the value of attribute color_ranges.
5 6 7 |
# File 'lib/subtle/dominikh/graph.rb', line 5 def color_ranges @color_ranges end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
6 7 8 |
# File 'lib/subtle/dominikh/graph.rb', line 6 def value @value end |
Instance Method Details
#color ⇒ Subtlext::Color
Returns the color of the graph. If no suiting color can be found in @color_ranges, it will default to the color set by DynamicIcon#color=.
28 29 30 31 32 33 34 35 |
# File 'lib/subtle/dominikh/graph.rb', line 28 def color color = @color_ranges.find {|key, value| key.include?(self.value) } if color Subtlext::Color.new(color[1]) else @color end end |
#render ⇒ void
This method returns an undefined value.
Draws the graph. This method gets called automatically whenever the value of the graph changes. Extend this method in subclasses to define custom drawing routines.
42 43 44 45 |
# File 'lib/subtle/dominikh/graph.rb', line 42 def render super @last_rendered_value = value end |
#to_str ⇒ String Also known as: to_s
16 17 18 19 20 21 |
# File 'lib/subtle/dominikh/graph.rb', line 16 def to_str unless @last_rendered_value == value render end super end |