Class: TimeBasedChart

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

Overview

Common base for every cycle-time chart. It owns the cycletime unit system -- which unit the value axis is expressed in and how a raw value is labelled -- because that concern is core to any chart that plots a cycle time, not a cross-cutting add-on. The scatter/histo split lives one level down (in TimeBasedScatterplot / TimeBasedHistogram, which supply the value_axis_title= hook so this class doesn't need to know which axis carries the value); the PR-vs-issue split lives one level below that.

Direct Known Subclasses

TimeBasedHistogram, TimeBasedScatterplot

Constant Summary collapse

VALUE_AXIS_LABELS =

The cycletime units we support, mapped to how each reads in an axis title. :days counts calendar days; :hours24 counts elapsed 24-hour clock periods (the two differ for anything that crosses midnight).

{
  minutes: 'minutes',
  hours: 'hours',
  days: 'days',
  hours24: '24-hour periods'
}.freeze

Constants inherited from ChartBase

ChartBase::LABEL_POSITIONS, ChartBase::OKABE_ITO_PALETTE

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

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

#initializeTimeBasedChart

Returns a new instance of TimeBasedChart.



23
24
25
26
27
# File 'lib/jirametrics/time_based_chart.rb', line 23

def initialize
  super

  @cycletime_unit = :days
end

Instance Method Details

#cycletime_unit(unit) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/jirametrics/time_based_chart.rb', line 29

def cycletime_unit unit
  axis_label = VALUE_AXIS_LABELS[unit]
  unless axis_label
    raise ArgumentError,
      "cycletime_unit must be one of #{VALUE_AXIS_LABELS.keys.map(&:inspect).join(', ')}, got #{unit.inspect}"
  end

  @cycletime_unit = unit
  self.value_axis_title = "Cycle time in #{axis_label}"
end

#duration_in_unit(from, to) ⇒ Object

Converts the span between two Times into the selected cycletime unit.

:days is deliberately different from the other units: it counts calendar days inclusively in the configured timezone (opened and closed on the same day is 1 day, crossing one midnight is 2), matching the working-days cycletime engine. The elapsed units (:hours, :minutes) divide the wall-clock span and round up -- a partial unit still counts as one, so a 20-minute PR is 1 hour, never 0.



56
57
58
59
60
61
62
63
64
# File 'lib/jirametrics/time_based_chart.rb', line 56

def duration_in_unit from, to
  if @cycletime_unit == :days
    tz = timezone_offset || '+00:00'
    (to.getlocal(tz).to_date - from.getlocal(tz).to_date).to_i + 1
  else
    seconds_per_unit = { minutes: 60, hours: 3600, hours24: 86_400 }[@cycletime_unit]
    ((to - from) / seconds_per_unit).ceil
  end
end

#label_cycletime(value) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/jirametrics/time_based_chart.rb', line 40

def label_cycletime value
  case @cycletime_unit
  when :minutes then label_minutes(value)
  when :hours then label_hours(value)
  when :days then label_days(value)
  when :hours24 then "#{value}x 24h periods"
  end
end