Class: AgingWorkBarChart

Inherits:
ChartBase show all
Defined in:
lib/jirametrics/aging_work_bar_chart.rb

Constant Summary collapse

@@next_id =
0

Instance Attribute Summary

Attributes inherited from ChartBase

#aggregated_project, #all_boards, #board_id, #canvas_height, #canvas_width, #data_quality, #date_range, #holiday_dates, #issues, #settings, #time_range, #timezone_offset

Instance Method Summary collapse

Methods inherited from ChartBase

#aggregated_project?, #canvas, #canvas_responsive?, #chart_format, #collapsible_issues_panel, #color_for, #completed_issues_in_range, #current_board, #daily_chart_dataset, #description_text, #filter_issues, #format_integer, #format_status, #header_text, #holidays, #label_days, #label_issues, #link_to_issue, #next_id, #random_color, #render, #sprints_in_time_range, #status_category_color, #wrap_and_render

Constructor Details

#initialize(block = nil) ⇒ AgingWorkBarChart

Returns a new instance of AgingWorkBarChart.



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
# File 'lib/jirametrics/aging_work_bar_chart.rb', line 8

def initialize block = nil
  super()

  header_text 'Aging Work Bar Chart'
  description_text <<-HTML
    <p>
      This chart shows all active (started but not completed) work, ordered from oldest at the top to
      newest at the bottom.
    </p>
    <p>
      There are potentially three bars for each issue, although a bar may be missing if the issue has no
      information relevant to that. Hovering over any of the bars will provide more details.
      <ol><li>The top bar tells you what status the issue is in at any time. Any statuses in the status
      category of "To Do" will be in blue. Any in the category of "In Progress" will be in a
      yellow and any in "Done" will be green.</li>
      <li>The middle bar indicates blocked and stalled states. A lighter orange is stalled and a darker,
      reddish colour is blocked.</li>
      <li>The bottom bar indicated an expedited state.</li></ol>
    </p>
    <p>
      The gray backgrounds indicate weekends and the red vertical line indicates the 85% point for all
      items in this time period. Anything that started to the left of that is now an outlier.
    </p>
  HTML

  # Because this one will size itself as needed, we start with a smaller default size
  @canvas_height = 80

  instance_eval(&block) if block
end

Instance Method Details

#blocked_data_sets(issue:, issue_label:, issue_start_time:, stack:) ⇒ Object



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/jirametrics/aging_work_bar_chart.rb', line 166

def blocked_data_sets issue:, issue_label:, issue_start_time:, stack:
  data_sets = []
  starting_change = nil

  issue.blocked_stalled_changes(end_time: time_range.end).each do |change|
    if starting_change.nil? || starting_change.active?
      starting_change = change
      next
    end

    if change.time >= issue_start_time
      data_sets << one_block_change_data_set(
        starting_change: starting_change, ending_time: change.time,
        issue_label: issue_label, stack: stack, issue_start_time: issue_start_time
      )
    end

    starting_change = change
  end

  data_sets
end

#calculate_percent_line(percentage: 85) ⇒ Object



229
230
231
232
233
234
# File 'lib/jirametrics/aging_work_bar_chart.rb', line 229

def calculate_percent_line percentage: 85
  days = completed_issues_in_range.collect { |issue| issue.board.cycletime.cycletime(issue) }.compact.sort
  return nil if days.empty?

  days[days.length * percentage / 100]
end

#data_set_by_block(issue:, issue_label:, title_label:, stack:, color:, start_date:, end_date: date_range.end, &block) ⇒ Object



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/jirametrics/aging_work_bar_chart.rb', line 189

def data_set_by_block(
  issue:, issue_label:, title_label:, stack:, color:, start_date:, end_date: date_range.end, &block
)
  started = nil
  ended = nil
  data = []

  (start_date..end_date).each do |day|
    if block.call(day)
      started = day if started.nil?
      ended = day
    elsif ended
      data << {
        x: [chart_format(started), chart_format(ended)],
        y: issue_label,
        title: "#{issue.type} : #{title_label} #{label_days (ended - started).to_i + 1}"
      }

      started = nil
      ended = nil
    end
  end

  if started
    data << {
      x: [chart_format(started), chart_format(ended)],
      y: issue_label,
      title: "#{issue.type} : #{title_label} #{label_days (end_date - started).to_i + 1}"
    }
  end

  {
    type: 'bar',
    data: data,
    backgroundColor: color,
    stacked: true,
    stack: stack
  }
end

#grow_chart_height_if_too_many_issues(aging_issue_count) ⇒ Object



84
85
86
87
88
89
# File 'lib/jirametrics/aging_work_bar_chart.rb', line 84

def grow_chart_height_if_too_many_issues aging_issue_count
  px_per_bar = 8
  bars_per_issue = 3
  preferred_height = aging_issue_count * px_per_bar * bars_per_issue
  @canvas_height = preferred_height if @canvas_height.nil? || @canvas_height < preferred_height
end

#one_block_change_data_set(starting_change:, ending_time:, issue_label:, stack:, issue_start_time:) ⇒ Object



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/jirametrics/aging_work_bar_chart.rb', line 148

def one_block_change_data_set starting_change:, ending_time:, issue_label:, stack:, issue_start_time:
  color = settings['colors']['blocked']
  color = settings['colors']['stalled'] if starting_change.stalled?
  {
    backgroundColor: color,
    data: [
      {
        title: starting_change.reasons,
        x: [chart_format([issue_start_time, starting_change.time].max), chart_format(ending_time)],
        y: issue_label
      }
    ],
    stack: stack,
    stacked: true,
    type: 'bar'
  }
end

#runObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/jirametrics/aging_work_bar_chart.rb', line 39

def run
  aging_issues = @issues.select do |issue|
    cycletime = issue.board.cycletime
    cycletime.started_time(issue) && cycletime.stopped_time(issue).nil?
  end

  grow_chart_height_if_too_many_issues aging_issues.size

  today = date_range.end
  aging_issues.sort! do |a, b|
    a.board.cycletime.age(b, today: today) <=> b.board.cycletime.age(a, today: today)
  end
  data_sets = []
  aging_issues.each do |issue|
    cycletime = issue.board.cycletime
    issue_start_time = cycletime.started_time(issue)
    issue_start_date = issue_start_time.to_date
    issue_label = "[#{label_days cycletime.age(issue, today: today)}] #{issue.key}: #{issue.summary}"[0..60]
    [
      status_data_sets(issue: issue, label: issue_label, today: today),
      blocked_data_sets(
        issue: issue,
        issue_label: issue_label,
        stack: 'blocked',
        issue_start_time: issue_start_time
      ),
      data_set_by_block(
        issue: issue,
        issue_label: issue_label,
        title_label: 'Expedited',
        stack: 'expedited',
        color: 'red',
        start_date: issue_start_date
      ) { |day| issue.expedited_on_date?(day) }
    ].compact.flatten.each do |data|
      data_sets << data
    end
  end

  percentage = calculate_percent_line
  percentage_line_x = date_range.end - calculate_percent_line if percentage

  wrap_and_render(binding, __FILE__)
end

#status_data_sets(issue:, label:, today:) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/jirametrics/aging_work_bar_chart.rb', line 91

def status_data_sets issue:, label:, today:
  cycletime = issue.board.cycletime

  issue_started_time = cycletime.started_time(issue)

  previous_start = nil
  previous_status = nil

  data_sets = []
  issue.changes.each do |change|
    next unless change.status?

    status = issue.find_status_by_name change.value

    unless previous_start.nil? || previous_start < issue_started_time
      hash = {
        type: 'bar',
        data: [{
          x: [chart_format(previous_start), chart_format(change.time)],
          y: label,
          title: "#{issue.type} : #{change.value}"
        }],
        backgroundColor: status_category_color(status),
        borderColor: 'white',
        borderWidth: {
           top: 0,
           right: 1,
           bottom: 0,
           left: 0
        },
        stacked: true,
        stack: 'status'
      }
      data_sets << hash if date_range.include?(change.time.to_date)
    end

    previous_start = change.time
    previous_status = status
  end

  if previous_start
    data_sets << {
      type: 'bar',
      data: [{
        x: [chart_format(previous_start), chart_format("#{today}T00:00:00#{@timezone_offset}")],
        y: label,
        title: "#{issue.type} : #{previous_status.name}"
      }],
      backgroundColor: status_category_color(previous_status),
      stacked: true,
      stack: 'status'
    }
  end

  data_sets
end