File: accumulator_bar.rb

package info (click to toggle)
ruby-gruff 0.6.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 852 kB
  • sloc: ruby: 4,929; makefile: 3
file content (18 lines) | stat: -rw-r--r-- 550 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
require File.dirname(__FILE__) + '/base'

##
# A special bar graph that shows a single dataset as a set of
# stacked bars. The bottom bar shows the running total and 
# the top bar shows the new value being added to the array.

class Gruff::AccumulatorBar < Gruff::StackedBar
  def draw
    raise(Gruff::IncorrectNumberOfDatasetsException) unless @data.length == 1

    accum_array = @data.first[DATA_VALUES_INDEX][0..-2].inject([0]) { |a, v| a << a.last + v}
    data 'Accumulator', accum_array
    set_colors
    @data.reverse!
    super
  end
end