Class: Quby::Questionnaires::DSL::LineChartBuilder

Inherits:
ChartBuilder
  • Object
show all
Defined in:
lib/quby/questionnaires/dsl/charting/line_chart_builder.rb

Instance Method Summary collapse

Methods inherited from ChartBuilder

#build, chart_class, #chart_type, #initialize, #plot, #plotband, #range, set_chart_class, #tick_interval, #title, #y_categories, #y_range_categories

Constructor Details

This class inherits a constructor from Quby::Questionnaires::DSL::ChartBuilder

Instance Method Details

#baseline(value = nil, &block) ⇒ Object

value - Number or a hash ‘=> {female: 5, default: 4, .., default: { default: 3 }}` block - deprecated.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/quby/questionnaires/dsl/charting/line_chart_builder.rb', line 22

def baseline(value = nil, &block)
  unless value.nil? ^ block.nil?
    fail ArgumentError, "Must give either value or a block"
  end

  if value && value.is_a?(Hash)
    @chart.baseline = ->(age, gender) {
      age_match = value.find { |age_range, _v| age && age_range === age }
      hash_by_gender = (age_match&.last || value.stringify_keys["default"])

      gender_match = hash_by_gender.find {|gender_key, _v| gender && gender_key.to_s == gender.to_s }
      gender_match&.last || hash_by_gender.stringify_keys['default']
    }
  elsif value
    @chart.baseline = ->(age, gender) { value }
  end

  if block
    if block.arity != 2
      fail ArgumentError, "Given block must take two arguments"
    end
    @chart.baseline = block
  end
end

#clinically_relevant_change(value) ⇒ Object



47
48
49
# File 'lib/quby/questionnaires/dsl/charting/line_chart_builder.rb', line 47

def clinically_relevant_change(value)
  @chart.clinically_relevant_change = value
end

#tonality(value) ⇒ Object



16
17
18
# File 'lib/quby/questionnaires/dsl/charting/line_chart_builder.rb', line 16

def tonality(value)
  @chart.tonality = value
end

#validate!Object



51
52
53
# File 'lib/quby/questionnaires/dsl/charting/line_chart_builder.rb', line 51

def validate!
  fail "Chart #{@chart.key} has no range specified" unless @chart.y_range
end

#y_axis_label(label) ⇒ Object



12
13
14
# File 'lib/quby/questionnaires/dsl/charting/line_chart_builder.rb', line 12

def y_axis_label(label)
  @chart.y_label = label
end