X-Git-Url: https://projects.mako.cc/source/selectricity-live/blobdiff_plain/1a62f78f4f3818ab697bddf51f80a1ba150ce9e7..131cab23209cb1dfa81930240b8cf722d2302131:/lib/gruff-0.2.8/lib/gruff/accumulator_bar.rb diff --git a/lib/gruff-0.2.8/lib/gruff/accumulator_bar.rb b/lib/gruff-0.2.8/lib/gruff/accumulator_bar.rb new file mode 100644 index 0000000..310e193 --- /dev/null +++ b/lib/gruff-0.2.8/lib/gruff/accumulator_bar.rb @@ -0,0 +1,27 @@ +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 + + accumulator_array = [] + index = 0 + + increment_array = @data.first[DATA_VALUES_INDEX].inject([]) {|memo, value| + memo << ((index > 0) ? (value + memo.max) : value) + accumulator_array << memo[index] - value + index += 1 + memo + } + data "Accumulator", accumulator_array + + super + end + +end