Class: TimeBasedScatterplot
Constant Summary
Constants inherited
from ChartBase
ChartBase::LABEL_POSITIONS
Instance Attribute Summary
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
#group_issues, #grouping_rules, #init_configuration_block
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, #label_days, #label_hours, #label_issues, #label_minutes, #link_to_issue, #next_id, #normalize_annotation_datetime, #not_visible_text, #random_color, #render, #render_axis_title, #render_top_text, #seam_end, #seam_start, #stagger_label_positions, #status_category_color, #to_human_readable, #working_days_annotation, #wrap_and_render
Constructor Details
Returns a new instance of TimeBasedScatterplot.
8
9
10
11
12
13
|
# File 'lib/jirametrics/time_based_scatterplot.rb', line 8
def initialize
super
@percentage_lines = []
@highest_y_value = 0
end
|
Instance Method Details
#calculate_percent_line(items) ⇒ Object
100
101
102
103
104
105
106
|
# File 'lib/jirametrics/time_based_scatterplot.rb', line 100
def calculate_percent_line items
min = minimum_y_value
times = items.collect { |item| y_value(item) }
times.reject! { |y| min && y < min }
index = times.size * 85 / 100
times.sort[index]
end
|
#create_datasets(items) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/jirametrics/time_based_scatterplot.rb', line 26
def create_datasets items
data_sets = []
group_issues(items).each do |rules, items_by_type|
label = rules.label
color = rules.color
percent_line = calculate_percent_line items_by_type
data = items_by_type.filter_map { |item| data_for_item(item, rules: rules) }
data_sets << {
label: "#{label} (85% at #{label_days(percent_line)})",
data: data,
fill: false,
showLine: false,
backgroundColor: color
}
data_sets << trend_line_data_set(label: label, data: data, color: color)
@percentage_lines << [percent_line, color]
end
data_sets
end
|
#data_for_item(item, rules: nil) ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/jirametrics/time_based_scatterplot.rb', line 86
def data_for_item item, rules: nil
y = y_value(item)
min = minimum_y_value
return nil if min && y < min
@highest_y_value = y if @highest_y_value < y
{
y: y,
x: chart_format(x_value(item)),
title: [title_value(item, rules: rules)]
}
end
|
#minimum_y_value ⇒ Object
82
83
84
|
# File 'lib/jirametrics/time_based_scatterplot.rb', line 82
def minimum_y_value
nil
end
|
#run ⇒ Object
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/jirametrics/time_based_scatterplot.rb', line 15
def run
items = all_items
data_sets = create_datasets items
overall_percent_line = calculate_percent_line(items)
@percentage_lines << [overall_percent_line, CssVariable['--cycletime-scatterplot-overall-trendline-color']]
return "<h1 class='foldable'>#{@header_text}</h1><div>No data matched the selected criteria. Nothing to show.</div>" if data_sets.empty?
wrap_and_render(binding, __FILE__)
end
|
#show_trend_lines ⇒ Object
49
50
51
|
# File 'lib/jirametrics/time_based_scatterplot.rb', line 49
def show_trend_lines
@show_trend_lines = true
end
|
#trend_line_data_set(label:, data:, color:) ⇒ Object
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
|
# File 'lib/jirametrics/time_based_scatterplot.rb', line 53
def trend_line_data_set label:, data:, color:
points = data.collect do |hash|
[Time.parse(hash[:x]).to_i, hash[:y]]
end
calculator = TrendLineCalculator.new(points)
data_points = calculator.chart_datapoints(
range: time_range.begin.to_i..time_range.end.to_i,
max_y: @highest_y_value
)
data_points.each do |point_hash|
point_hash[:x] = chart_format Time.at(point_hash[:x])
end
{
type: 'line',
label: "#{label} Trendline",
data: data_points,
fill: false,
borderWidth: 1,
markerType: 'none',
borderColor: color,
borderDash: [6, 3],
pointStyle: 'dash',
hidden: !@show_trend_lines
}
end
|