Class: TimeBasedScatterplot
- Inherits:
-
TimeBasedChart
- Object
- ChartBase
- TimeBasedChart
- TimeBasedScatterplot
- Includes:
- GroupableIssueChart
- Defined in:
- lib/jirametrics/time_based_scatterplot.rb
Direct Known Subclasses
Constant Summary
Constants inherited from TimeBasedChart
TimeBasedChart::VALUE_AXIS_LABELS
Constants inherited from ChartBase
ChartBase::LABEL_POSITIONS, ChartBase::OKABE_ITO_PALETTE
Instance Attribute Summary
Attributes included from GroupableIssueChart
#group_by_block, #issue_hints, #issue_periods
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
- #calculate_percent_line(items) ⇒ Object
- #create_datasets(items) ⇒ Object
- #data_for_item(item, rules: nil) ⇒ Object
-
#initialize ⇒ TimeBasedScatterplot
constructor
A new instance of TimeBasedScatterplot.
- #minimum_y_value ⇒ Object
- #run ⇒ Object
- #show_trend_lines ⇒ Object
- #trend_line_data_set(label:, data:, color:) ⇒ Object
-
#value_axis_title=(title) ⇒ Object
On a scatterplot the cycle time is plotted up the y-axis.
Methods included from GroupableIssueChart
#group_issues, #grouping_rules, #init_configuration_block
Methods inherited from TimeBasedChart
#cycletime_unit, #duration_in_unit, #label_cycletime
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
#initialize ⇒ TimeBasedScatterplot
Returns a new instance of TimeBasedScatterplot.
9 10 11 12 13 14 |
# File 'lib/jirametrics/time_based_scatterplot.rb', line 9 def initialize super @percentage_lines = [] @highest_y_value = 0 end |
Instance Method Details
#calculate_percent_line(items) ⇒ Object
109 110 111 112 113 114 115 |
# File 'lib/jirametrics/time_based_scatterplot.rb', line 109 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
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/jirametrics/time_based_scatterplot.rb', line 35 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
95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/jirametrics/time_based_scatterplot.rb', line 95 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
91 92 93 |
# File 'lib/jirametrics/time_based_scatterplot.rb', line 91 def minimum_y_value nil end |
#run ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/jirametrics/time_based_scatterplot.rb', line 21 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']] if data_sets.empty? return "<h1 class='foldable'>#{@header_text}</h1>" \ '<div>No data matched the selected criteria. Nothing to show.</div>' end wrap_and_render(binding, __FILE__) end |
#show_trend_lines ⇒ Object
58 59 60 |
# File 'lib/jirametrics/time_based_scatterplot.rb', line 58 def show_trend_lines @show_trend_lines = true end |
#trend_line_data_set(label:, data:, color:) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/jirametrics/time_based_scatterplot.rb', line 62 def trend_line_data_set label:, data:, color: points = data.collect do |hash| [Time.parse(hash[:x]).to_i, hash[:y]] end # The trend calculation works with numbers only so convert Time to an int and back 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 |
#value_axis_title=(title) ⇒ Object
On a scatterplot the cycle time is plotted up the y-axis.
17 18 19 |
# File 'lib/jirametrics/time_based_scatterplot.rb', line 17 def value_axis_title= title @y_axis_title = title end |