Sha256: 59c116952914a185f072319a7d735aecaa5926f65f4de95b5924bcf605a18151

Contents?: true

Size: 754 Bytes

Versions: 4

Compression:

Stored size: 754 Bytes

Contents

# frozen_string_literal: true

#
# Gruff::AccumulatorBar is 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.
#
# Here's how to set up a Gruff::AccumulatorBar.
#
#   g = Gruff::AccumulatorBar.new
#   g.title = 'Your Savings'
#   g.data 'First', [1, 1, 1]
#   g.write('accumulator_bar.png')
#
class Gruff::AccumulatorBar < Gruff::StackedBar
private

  def setup_data
    raise(Gruff::IncorrectNumberOfDatasetsException) unless store.length == 1

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gruff-0.15.0-java lib/gruff/accumulator_bar.rb
gruff-0.15.0 lib/gruff/accumulator_bar.rb
gruff-0.14.0 lib/gruff/accumulator_bar.rb
gruff-0.14.0-java lib/gruff/accumulator_bar.rb