Class: DailyWipChart
Constant Summary
Constants inherited
from ChartBase
ChartBase::LABEL_POSITIONS, ChartBase::OKABE_ITO_PALETTE
Instance Attribute Summary collapse
Attributes inherited from ChartBase
#aggregated_project, #all_boards, #atlassian_document_format, #board_id, #canvas_height, #canvas_width, #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
-
#active_dates_for(issue) ⇒ Object
The range of dates an issue is "active" on the chart: from when it started - or its creation, if it stopped without a recorded start - through when it stopped, or the end of the range if still open.
-
#add_trend_line(group_labels:, line_color:) ⇒ Object
-
#background_color_for(grouping_rule) ⇒ Object
-
#build_data_sets(possible_rules, issue_rules_by_active_date) ⇒ Object
-
#configure_rule(issue:, date:) ⇒ Object
-
#conflicting_labels(possible_rules) ⇒ Object
Labels that appear both highlighted and un-highlighted; the highlighted variant gets a '*' suffix so the two are distinguishable in the legend.
-
#daily_wip_totals(data, group_labels) ⇒ Object
Sums the daily WIP across every dataset whose label is in group_labels, giving { date => total_wip }.
-
#datapoint_for(date:, issue_rules:, grouping_rule:, display_label:, positive:) ⇒ Object
One y, title point: the issues active on this date that belong to this rule's group, with a title listing them.
-
#default_description_text ⇒ Object
-
#default_grouping_rules(issue:, rules:) ⇒ Object
-
#default_header_text ⇒ Object
-
#group_issues_by_active_dates ⇒ Object
-
#grouping_rules(&block) ⇒ Object
-
#initialize(block) ⇒ DailyWipChart
constructor
A new instance of DailyWipChart.
-
#issue_strings_for(issue_rules, grouping_rule) ⇒ Object
-
#make_data_set(grouping_rule:, issue_rules_by_active_date:, label_suffix: '') ⇒ Object
-
#prepend_trend_lines(data_sets) ⇒ Object
-
#run ⇒ Object
-
#select_possible_rules(issue_rules_by_active_date) ⇒ Object
-
#trend_line_data_set(data:, group_labels:, color:) ⇒ Object
Methods inherited from ChartBase
#aggregated_project?, #before_run, #call_before_run, #canvas, #canvas_responsive?, #chart_format, #collapsible_issues_panel, #color_block, #color_for, #completed_issues_in_range, #current_board, #cycletime, #cycletime_for_issue, #daily_chart_dataset, #date_annotation, #describe_non_working_days, #description_text, #format_integer, #format_status, #header_text, #holidays, #html_directory, #icon_span, #link_to_issue, #next_id, #non_working_day?, #normalize_annotation_datetime, #not_visible_icon, #not_visible_text, #random_color, #render, #render_axis_title, #render_top_text, #resolve_status, #stagger_label_positions, #status_category_color, #to_human_readable, #working_days_annotation, #wrap_and_render
Constructor Details
Returns a new instance of DailyWipChart.
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/jirametrics/daily_wip_chart.rb', line 21
def initialize block
super()
description_text default_description_text
@x_axis_title = nil
@y_axis_title = 'Count of items'
instance_eval(&block) if block
return if @group_by_block
grouping_rules do |issue, rules|
default_grouping_rules issue: issue, rules: rules
end
end
|
Instance Attribute Details
#possible_statuses ⇒ Object
Returns the value of attribute possible_statuses.
19
20
21
|
# File 'lib/jirametrics/daily_wip_chart.rb', line 19
def possible_statuses
@possible_statuses
end
|
Instance Method Details
#active_dates_for(issue) ⇒ Object
The range of dates an issue is "active" on the chart: from when it started - or its creation, if it
stopped without a recorded start - through when it stopped, or the end of the range if still open.
Returns nil when the issue neither started nor stopped.
104
105
106
107
108
109
110
111
112
|
# File 'lib/jirametrics/daily_wip_chart.rb', line 104
def active_dates_for issue
start, stop = cycletime_for_issue(issue).started_stopped_dates(issue)
return nil if start.nil? && stop.nil?
start = issue.created.to_date if start.nil?
start = @date_range.begin if start < @date_range.begin
start..(stop || @date_range.end)
end
|
#add_trend_line(group_labels:, line_color:) ⇒ Object
172
173
174
|
# File 'lib/jirametrics/daily_wip_chart.rb', line 172
def add_trend_line group_labels:, line_color:
(@trend_lines ||= []) << [group_labels, line_color]
end
|
#background_color_for(grouping_rule) ⇒ Object
152
153
154
155
156
157
|
# File 'lib/jirametrics/daily_wip_chart.rb', line 152
def background_color_for grouping_rule
color = grouping_rule.color || random_color
return color unless grouping_rule.highlight
RawJavascript.new("createDiagonalPattern(#{color.to_json})")
end
|
#build_data_sets(possible_rules, issue_rules_by_active_date) ⇒ Object
48
49
50
51
52
53
54
55
|
# File 'lib/jirametrics/daily_wip_chart.rb', line 48
def build_data_sets possible_rules, issue_rules_by_active_date
labels = conflicting_labels(possible_rules)
possible_rules.collect do |grouping_rule|
suffix = labels.include?(grouping_rule.label) && grouping_rule.highlight ? '*' : ''
make_data_set grouping_rule: grouping_rule, issue_rules_by_active_date: issue_rules_by_active_date,
label_suffix: suffix
end
end
|
159
160
161
162
163
164
165
166
|
# File 'lib/jirametrics/daily_wip_chart.rb', line 159
def configure_rule issue:, date:
raise "#{self.class}: grouping_rules must be set" if @group_by_block.nil?
rules = DailyGroupingRules.new
rules.current_date = date
@group_by_block.call issue, rules
rules
end
|
#conflicting_labels(possible_rules) ⇒ Object
Labels that appear both highlighted and un-highlighted; the highlighted variant gets a '*' suffix so
the two are distinguishable in the legend.
59
60
61
62
63
64
|
# File 'lib/jirametrics/daily_wip_chart.rb', line 59
def conflicting_labels possible_rules
possible_rules
.group_by(&:label)
.select { |_label, rules| rules.any?(&:highlight) && rules.any? { |rule| !rule.highlight } }
.keys
end
|
#daily_wip_totals(data, group_labels) ⇒ Object
Sums the daily WIP across every dataset whose label is in group_labels, giving { date => total_wip }.
177
178
179
180
181
182
183
184
185
186
187
188
|
# File 'lib/jirametrics/daily_wip_chart.rb', line 177
def daily_wip_totals data, group_labels
day_wip_hash = {}
data.each do |top_level|
next unless group_labels.include? top_level[:label]
top_level[:data].each do |datapoint|
date = datapoint[:x]
day_wip_hash[date] = (day_wip_hash[date] || 0) + datapoint[:y]
end
end
day_wip_hash
end
|
#datapoint_for(date:, issue_rules:, grouping_rule:, display_label:, positive:) ⇒ Object
One y, title point: the issues active on this date that belong to this rule's group, with a
title listing them. y is negated for negative-priority groups so they render below the axis.
137
138
139
140
141
142
143
|
# File 'lib/jirametrics/daily_wip_chart.rb', line 137
def datapoint_for date:, issue_rules:, grouping_rule:, display_label:, positive:
issue_strings = issue_strings_for issue_rules, grouping_rule
title_label = grouping_rule.label_hint || display_label
title = ["#{title_label} (#{label_issues issue_strings.size})"] + issue_strings
{ x: date, y: positive ? issue_strings.size : -issue_strings.size, title: title }
end
|
#default_description_text ⇒ Object
73
|
# File 'lib/jirametrics/daily_wip_chart.rb', line 73
def default_description_text = ''
|
#default_grouping_rules(issue:, rules:) ⇒ Object
75
76
77
|
# File 'lib/jirametrics/daily_wip_chart.rb', line 75
def default_grouping_rules issue:, rules:
raise 'If you use this class directly then you must provide grouping_rules'
end
|
72
|
# File 'lib/jirametrics/daily_wip_chart.rb', line 72
def = 'Daily WIP'
|
#group_issues_by_active_dates ⇒ Object
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/jirametrics/daily_wip_chart.rb', line 90
def group_issues_by_active_dates
hash = {}
@issues.each do |issue|
active_dates_for(issue)&.each do |date|
rule = configure_rule issue: issue, date: date
(hash[date] ||= []) << [issue, rule] unless rule.ignored?
end
end
hash
end
|
#grouping_rules(&block) ⇒ Object
168
169
170
|
# File 'lib/jirametrics/daily_wip_chart.rb', line 168
def grouping_rules &block
@group_by_block = block
end
|
#issue_strings_for(issue_rules, grouping_rule) ⇒ Object
145
146
147
148
149
150
|
# File 'lib/jirametrics/daily_wip_chart.rb', line 145
def issue_strings_for issue_rules, grouping_rule
issue_rules
.select { |_issue, rules| rules.group == grouping_rule.group }
.sort_by { |issue, _rules| issue.key_as_i }
.collect { |issue, rules| "#{issue.key} : #{issue.summary.strip} #{rules.issue_hint}" }
end
|
#make_data_set(grouping_rule:, issue_rules_by_active_date:, label_suffix: '') ⇒ Object
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/jirametrics/daily_wip_chart.rb', line 114
def make_data_set grouping_rule:, issue_rules_by_active_date:, label_suffix: ''
positive = grouping_rule.group_priority >= 0
display_label = "#{grouping_rule.label}#{label_suffix}"
data = issue_rules_by_active_date.collect do |date, issue_rules|
datapoint_for date: date, issue_rules: issue_rules, grouping_rule: grouping_rule,
display_label: display_label, positive: positive
end
{
type: 'bar',
label: display_label,
label_hint: grouping_rule.label_hint,
data: data,
backgroundColor: background_color_for(grouping_rule),
borderColor: CssVariable['--wip-chart-border-color'],
borderWidth: grouping_rule.color.to_s == 'var(--body-background)' ? 1 : 0,
borderRadius: positive ? 0 : 5
}
end
|
#prepend_trend_lines(data_sets) ⇒ Object
66
67
68
69
70
|
# File 'lib/jirametrics/daily_wip_chart.rb', line 66
def prepend_trend_lines data_sets
@trend_lines.filter_map do |group_labels, line_color|
trend_line_data_set(data: data_sets, group_labels: group_labels, color: line_color)
end + data_sets
end
|
#run ⇒ Object
38
39
40
41
42
43
44
45
46
|
# File 'lib/jirametrics/daily_wip_chart.rb', line 38
def run
issue_rules_by_active_date = group_issues_by_active_dates
possible_rules = select_possible_rules issue_rules_by_active_date
data_sets = build_data_sets(possible_rules, issue_rules_by_active_date)
data_sets = prepend_trend_lines(data_sets) if @trend_lines
wrap_and_render(binding, __FILE__)
end
|
#select_possible_rules(issue_rules_by_active_date) ⇒ Object
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/jirametrics/daily_wip_chart.rb', line 79
def select_possible_rules issue_rules_by_active_date
possible_rules = []
issue_rules_by_active_date.each_pair do |_date, issues_rules_list|
issues_rules_list.each do |_issue, rules| possible_rules << rules unless possible_rules.any? { |r| r.group == rules.group }
end
end
possible_rules.sort_by!(&:group_priority)
end
|
#trend_line_data_set(data:, group_labels:, color:) ⇒ Object
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
|
# File 'lib/jirametrics/daily_wip_chart.rb', line 190
def trend_line_data_set data:, group_labels:, color:
points = daily_wip_totals(data, group_labels)
.collect { |date, wip| [date.jd, wip] }
.sort_by(&:first)
calculator = TrendLineCalculator.new(points)
return nil unless calculator.valid?
data_points = calculator.chart_datapoints(
range: date_range.begin.jd..date_range.end.jd,
max_y: points.collect { |_date, wip| wip }.max
)
data_points.each do |point_hash|
point_hash[:x] = chart_format Date.jd(point_hash[:x])
end
{
type: 'line',
label: 'Trendline',
data: data_points,
fill: false,
borderWidth: 1,
markerType: 'none',
borderColor: CssVariable[color],
borderDash: [6, 3],
pointStyle: 'dash',
hidden: false
}
end
|