Class: Dominikh::Graph

Inherits:
DynamicIcon
  • Object
show all
Defined in:
lib/subtle/dominikh/graph.rb

Direct Known Subclasses

Bar, Chart

Instance Attribute Summary collapse

Instance Method Summary collapse

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_rangesObject

Returns the value of attribute color_ranges.



5
6
7
# File 'lib/subtle/dominikh/graph.rb', line 5

def color_ranges
  @color_ranges
end

#valueObject (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

#colorSubtlext::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=.

Returns:

  • (Subtlext::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

#rendervoid

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_strString Also known as: to_s

Returns:

  • (String)


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