Module: IterationsHelper

Defined in:
lib/branston/app/helpers/iterations_helper.rb

Instance Method Summary collapse

Instance Method Details

#burndown_chart(iteration, data) ⇒ Object

TODO: Untested!



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/branston/app/helpers/iterations_helper.rb', line 5

def burndown_chart(iteration, data)

  total_points = iteration.velocity
  running_total = 0

  unless data.nil? or data.empty?
    points_data = data.map { |d|
      running_total += d.points.to_i
      total_points - running_total
    }


    points_data = [total_points] + points_data unless points_data.nil?

    work_days = [nil]
    (iteration.start_date.to_date..iteration.end_date.to_date).to_a.each do |date|
      work_days.push date.strftime('%d/%m') unless is_weekend(date)
    end

    # Keep adding the last value to flatline the chart
    while work_days.length > points_data.length
      points_data.push points_data.last
    end

    # Make some gradations for the y axis labels
    y_scale = [0]
    [4, 2, 1.5, 1.25, 1].each do |n|
      unit = (total_points / n).floor
      y_scale.push unit if unit > 0
    end

    image_tag Gchart.line(:size => '800x360',
      :title => "Iteration #{iteration.name} burndown",
      :data => points_data, :axis_with_labels => 'x,y',
      :axis_labels => [work_days, y_scale])

  end

end

#is_weekend(date) ⇒ Object



45
46
47
# File 'lib/branston/app/helpers/iterations_helper.rb', line 45

def is_weekend(date)
  date.wday == 0 or date.wday == 5 or date.wday == 6
end