Class: AgingWorkInProgressChart
- Includes:
- GroupableIssueChart
- Defined in:
- lib/jirametrics/aging_work_in_progress_chart.rb
Constant Summary
Constants inherited from ChartBase
ChartBase::LABEL_POSITIONS, ChartBase::OKABE_ITO_PALETTE
Instance Attribute Summary collapse
-
#board_columns ⇒ Object
readonly
Returns the value of attribute board_columns.
-
#board_id ⇒ Object
Returns the value of attribute board_id.
-
#possible_statuses ⇒ Object
Returns the value of attribute possible_statuses.
Attributes included from GroupableIssueChart
#group_by_block, #issue_hints, #issue_periods
Attributes inherited from ChartBase
#aggregated_project, #all_boards, #atlassian_document_format, #canvas_height, #canvas_width, #color_palette, #data_quality, #date_range, #file_system, #fix_versions, #holiday_dates, #issues, #settings, #time_range, #timezone_offset, #x_axis_title, #y_axis_title
Instance Method Summary collapse
- #adjust_chart_height ⇒ Object
- #adjust_visibility_of_unmapped_status_column(data_sets:) ⇒ Object
-
#aging_column_names(data_sets) ⇒ Object
The distinct column names that currently have aging items on the chart.
-
#aging_datapoints(issues) ⇒ Object
One column, y: age, title point per issue that's currently visible on the board.
- #aging_issue_on_board?(issue) ⇒ Boolean
-
#append_bar_data_sets(data_sets, calculator, column_indexes_to_remove) ⇒ Object
Each band is a floating bar running from the previous percentile's age up to its own, so it carries its own absolute position.
- #column_for(issue:) ⇒ Object
-
#column_trim_bounds(aging_columns:, age_data:, real_column_count:) ⇒ Object
The [left, right] column indexes to keep, combining columns with current aging items and columns with historical age data.
- #determine_board_columns ⇒ Object
-
#highest_plotted_age(data_sets) ⇒ Object
The y-axis ceiling is set a little above this so you can see that the tallest thing on the chart really does stop where it stops, rather than being clipped by the top of the plot.
- #indexes_of_leading_and_trailing_zeros(list) ⇒ Object
-
#initialize(block) ⇒ AgingWorkInProgressChart
constructor
A new instance of AgingWorkInProgressChart.
- #line_data_set(rules, issues) ⇒ Object
- #make_data_sets ⇒ Object
- #percentiles(percentile_color_hash) ⇒ Object
- #run ⇒ Object
-
#show_all_columns(show = true) ⇒ Object
Boolean positional is the config-block DSL's public API (show_all_columns false).
- #trim_board_columns(data_sets:, calculator:) ⇒ Object
Methods included from GroupableIssueChart
#accumulate_issue_for_group, #group_issues, #grouping_rules, #init_configuration_block, #reconcile_percentiles
Methods inherited from ChartBase
#aggregated_project?, #before_run, #call_before_run, #canvas, #canvas_responsive?, #collapsible_issues_panel, #color_block, #color_for, #comma_and, #completed_issues_in_range, #current_board, #cycletime, #cycletime_for_issue, #daily_chart_dataset, #date_annotation, #describe_non_working_days, #description_text, #expand_template, #expanded_header_text, #format_integer, #format_status, #header_text, #holidays, #html_directory, #icon_span, #link_to_issue, #next_id, #next_palette_color, #no_data_text, #non_working_day?, #normalize_annotation_datetime, #not_visible_icon, #not_visible_text, #ordinal, #percentile_of, #render, #render_axis_title, #render_binding, #render_header, #render_no_data, #render_top_text, #resolve_status, #stagger_label_positions, #status_category_color, #to_human_readable, #working_days_annotation, #wrap_and_render
Methods included from ChartFormat
Constructor Details
#initialize(block) ⇒ AgingWorkInProgressChart
Returns a new instance of AgingWorkInProgressChart.
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/jirametrics/aging_work_in_progress_chart.rb', line 13 def initialize block super() header_text 'Aging Work in Progress on board: <%= current_board.name %>' # div class="p" rather than <p>: the notes below are a ul, which is block level and not legal # inside a paragraph, so a browser closes the p early. Harmless while the list is the last # thing in the block, but it breaks the moment any text follows it. description_text <<-HTML <div class="p"> This chart shows only work items that have started but not completed, grouped by the column they're currently in. Hovering over a dot will show you the ID of that work item. </div> <div class="p"> The shaded areas indicate what percentage of the work has passed that column within that time. Notes: <ul> <li>It only shows columns that are considered "in progress". If you see a column that wouldn't normally be thought of that way, then likely issues were moving backwards or continued to progress after hitting that column.</li> <li>If you see a colour group that drops as it moves to the right, that generally indicates that a different number of data points is being included in each column. Probably because tickets moved backwards athough it could also indicate that a ticket jumped over columns as it moved to the right. </li> </ul> </div> <div style="border: 1px solid gray; padding: 0.2em"> <% @percentiles.keys.sort.reverse.each do |percent| %> <span style="padding-left: 0.5em; padding-right: 0.5em; vertical-align: middle;"><%= color_block @percentiles[percent] %> <%= percent %>%</span> <% end %> </div> HTML percentiles( 50 => '--aging-work-in-progress-chart-shading-50-color', 85 => '--aging-work-in-progress-chart-shading-85-color', 98 => '--aging-work-in-progress-chart-shading-98-color', 100 => '--aging-work-in-progress-chart-shading-100-color' ) show_all_columns false init_configuration_block(block) do grouping_rules do |issue, rule| rule.label = issue.type rule.color = color_for type: issue.type end end end |
Instance Attribute Details
#board_columns ⇒ Object (readonly)
Returns the value of attribute board_columns.
11 12 13 |
# File 'lib/jirametrics/aging_work_in_progress_chart.rb', line 11 def board_columns @board_columns end |
#board_id ⇒ Object
Returns the value of attribute board_id.
10 11 12 |
# File 'lib/jirametrics/aging_work_in_progress_chart.rb', line 10 def board_id @board_id end |
#possible_statuses ⇒ Object
Returns the value of attribute possible_statuses.
10 11 12 |
# File 'lib/jirametrics/aging_work_in_progress_chart.rb', line 10 def possible_statuses @possible_statuses end |
Instance Method Details
#adjust_chart_height ⇒ Object
249 250 251 252 253 254 |
# File 'lib/jirametrics/aging_work_in_progress_chart.rb', line 249 def adjust_chart_height min_height = @max_age * 5 @canvas_height = min_height if min_height > @canvas_height @canvas_height = 400 if min_height > 400 end |
#adjust_visibility_of_unmapped_status_column(data_sets:) ⇒ Object
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/jirametrics/aging_work_in_progress_chart.rb', line 226 def adjust_visibility_of_unmapped_status_column data_sets: column_name = @fake_column.name has_unmapped = data_sets.any? do |set| set['data'].any? do |data| data['x'] == column_name if data.is_a? Hash end end if has_unmapped && @description_text @description_text += "<div class=\"p\">The items shown in #{column_name.inspect} are not " \ 'visible on the board but are still active. Most likely everyone has forgotten about ' \ 'them.</div>' else # @column_headings.pop @board_columns.pop end end |
#aging_column_names(data_sets) ⇒ Object
The distinct column names that currently have aging items on the chart.
199 200 201 202 203 |
# File 'lib/jirametrics/aging_work_in_progress_chart.rb', line 199 def aging_column_names data_sets data_sets.flat_map do |set| set['data'].filter_map { |d| d['x'] if d.is_a? Hash } end.uniq end |
#aging_datapoints(issues) ⇒ Object
One column, y: age, title point per issue that's currently visible on the board.
130 131 132 133 134 135 136 137 138 |
# File 'lib/jirametrics/aging_work_in_progress_chart.rb', line 130 def aging_datapoints issues issues.filter_map do |issue| age = issue.board.cycletime.age(issue, today: date_range.end) column = column_for issue: issue next if column.nil? { 'y' => age, 'x' => column.name, 'title' => ["#{issue.key} : #{issue.summary} (#{label_days age})"] } end end |
#aging_issue_on_board?(issue) ⇒ Boolean
114 115 116 |
# File 'lib/jirametrics/aging_work_in_progress_chart.rb', line 114 def aging_issue_on_board? issue issue.board.id == @board_id && issue.board.cycletime.in_progress?(issue) end |
#append_bar_data_sets(data_sets, calculator, column_indexes_to_remove) ⇒ Object
Each band is a floating bar running from the previous percentile's age up to its own, so it carries its own absolute position. Asking Chart.js to stack the bands instead hands it the positioning of every dataset on the chart, and it will stack the aging dots right along with them.
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/jirametrics/aging_work_in_progress_chart.rb', line 143 def data_sets, calculator, column_indexes_to_remove previous_ages = [] @percentiles.keys.sort.each do |percentage| ages = calculator.age_data_for percentage: percentage column_indexes_to_remove.reverse_each { |index| ages.delete_at index } data_sets << { 'type' => 'bar', 'label' => "#{percentage}%", 'barPercentage' => 1.0, 'categoryPercentage' => 1.0, 'backgroundColor' => @percentiles[percentage], 'data' => ages.each_with_index.collect { |age, index| [previous_ages[index] || 0, age] } } previous_ages = ages end end |
#column_for(issue:) ⇒ Object
220 221 222 223 224 |
# File 'lib/jirametrics/aging_work_in_progress_chart.rb', line 220 def column_for issue: @board_columns.find do |board_column| board_column.status_ids.include? issue.status.id end end |
#column_trim_bounds(aging_columns:, age_data:, real_column_count:) ⇒ Object
The [left, right] column indexes to keep, combining columns with current aging items and columns
with historical age data. The last visible column is excluded from the right-boundary history search
because ages_of_issues_when_leaving_column inflates its age_data (it uses today as the end date
when there's no next column), so it's kept only when it has a current aging item.
209 210 211 212 213 214 215 216 217 218 |
# File 'lib/jirametrics/aging_work_in_progress_chart.rb', line 209 def column_trim_bounds aging_columns:, age_data:, real_column_count: in_current = ->(i) { aging_columns.include?(@board_columns[i].name) } first_aging = (0...real_column_count).find(&in_current) last_aging = (0...real_column_count).to_a.reverse.find(&in_current) first_data = (0...real_column_count).find { |i| !age_data[i].zero? } last_data = (0...(real_column_count - 1)).to_a.reverse.find { |i| !age_data[i].zero? } [[first_data, first_aging].compact.min, [last_data, last_aging].compact.max] end |
#determine_board_columns ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/jirametrics/aging_work_in_progress_chart.rb', line 75 def determine_board_columns unmapped_statuses = current_board.possible_statuses.collect(&:id) columns = current_board.visible_columns columns.each { |c| unmapped_statuses -= c.status_ids } @fake_column = BoardColumn.new({ 'name' => '[Unmapped Statuses]', 'statuses' => unmapped_statuses.collect { |id| { 'id' => id.to_s } }.uniq }) @board_columns = columns + [@fake_column] end |
#highest_plotted_age(data_sets) ⇒ Object
The y-axis ceiling is set a little above this so you can see that the tallest thing on the chart really does stop where it stops, rather than being clipped by the top of the plot. Bands count as much as dots do. Never shorter than 20 days. Called after the columns have been trimmed, so a column nobody can see can't push the ceiling up and leave unexplained space at the top.
107 108 109 110 111 112 |
# File 'lib/jirametrics/aging_work_in_progress_chart.rb', line 107 def highest_plotted_age data_sets data_sets.flat_map do |set| # A dot is {x:, y:, title:}. A band is a floating bar, [bottom, top]. set['data'].collect { |point| point.is_a?(Hash) ? point['y'] : point.last } end.push(20).max end |
#indexes_of_leading_and_trailing_zeros(list) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/jirametrics/aging_work_in_progress_chart.rb', line 159 def indexes_of_leading_and_trailing_zeros list result = [] 0.upto(list.size - 1) do |index| break unless list[index].zero? result << index end stop_at = result.empty? ? 0 : (result.last + 1) (list.size - 1).downto(stop_at).each do |index| break unless list[index].zero? result << index if list[index].zero? end result end |
#line_data_set(rules, issues) ⇒ Object
118 119 120 121 122 123 124 125 126 127 |
# File 'lib/jirametrics/aging_work_in_progress_chart.rb', line 118 def line_data_set rules, issues { 'type' => 'line', 'label' => rules.label, 'data' => aging_datapoints(issues), 'fill' => false, 'showLine' => false, 'backgroundColor' => rules.color } end |
#make_data_sets ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/jirametrics/aging_work_in_progress_chart.rb', line 88 def make_data_sets aging_issues = @issues.select { |issue| aging_issue_on_board? issue } rules_to_issues = group_issues aging_issues data_sets = rules_to_issues.keys.collect { |rules| line_data_set(rules, rules_to_issues[rules]) } calculator = BoardMovementCalculator.new board: @all_boards[@board_id], issues: issues, today: date_range.end column_indexes_to_remove = trim_board_columns data_sets: data_sets, calculator: calculator data_sets, calculator, column_indexes_to_remove @max_age = highest_plotted_age data_sets data_sets end |
#percentiles(percentile_color_hash) ⇒ Object
245 246 247 |
# File 'lib/jirametrics/aging_work_in_progress_chart.rb', line 245 def percentiles percentile_color_hash @percentiles = percentile_color_hash.transform_values { |value| CssVariable[value] } end |
#run ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/jirametrics/aging_work_in_progress_chart.rb', line 59 def run determine_board_columns data_sets = make_data_sets adjust_visibility_of_unmapped_status_column data_sets: data_sets adjust_chart_height wrap_and_render(binding, __FILE__) end |
#show_all_columns(show = true) ⇒ Object
Boolean positional is the config-block DSL's public API (show_all_columns false).
71 72 73 |
# File 'lib/jirametrics/aging_work_in_progress_chart.rb', line 71 def show_all_columns show = true # rubocop:disable Style/OptionalBooleanParameter @show_all_columns = show end |
#trim_board_columns(data_sets:, calculator:) ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/jirametrics/aging_work_in_progress_chart.rb', line 176 def trim_board_columns data_sets:, calculator: return [] if @show_all_columns # @fake_column is always the last element and is handled separately. real_column_count = @board_columns.size - 1 left_bound, right_bound = column_trim_bounds( aging_columns: aging_column_names(data_sets), age_data: calculator.age_data_for(percentage: 100), real_column_count: real_column_count ) indexes_to_remove = if left_bound && right_bound (0...left_bound).to_a + ((right_bound + 1)...real_column_count).to_a else (0...real_column_count).to_a end indexes_to_remove.reverse_each { |index| @board_columns.delete_at index } indexes_to_remove end |