Class: Quby::Compiler::DSL::ChartBuilder
- Inherits:
-
Object
- Object
- Quby::Compiler::DSL::ChartBuilder
show all
- Defined in:
- lib/quby/compiler/dsl/charting/chart_builder.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(questionnaire, key, **options) ⇒ ChartBuilder
Returns a new instance of ChartBuilder.
19
20
21
22
|
# File 'lib/quby/compiler/dsl/charting/chart_builder.rb', line 19
def initialize(questionnaire, key, **options)
@chart = self.class.chart_class.new(key, **options)
@questionnaire = questionnaire
end
|
Class Method Details
.chart_class ⇒ Object
rubocop:enable AccessorMethodName
15
16
17
|
# File 'lib/quby/compiler/dsl/charting/chart_builder.rb', line 15
def self.chart_class
@chart_class
end
|
.set_chart_class(chart_class) ⇒ Object
rubocop:disable AccessorMethodName
10
11
12
|
# File 'lib/quby/compiler/dsl/charting/chart_builder.rb', line 10
def self.set_chart_class(chart_class)
@chart_class = chart_class
end
|
Instance Method Details
#build(&block) ⇒ Object
66
67
68
69
70
|
# File 'lib/quby/compiler/dsl/charting/chart_builder.rb', line 66
def build(&block)
instance_eval(&block)
validate!
@chart
end
|
#chart_type(type) ⇒ Object
62
63
64
|
# File 'lib/quby/compiler/dsl/charting/chart_builder.rb', line 62
def chart_type(type)
@chart.chart_type = type
end
|
#plot(key, **options) ⇒ Object
52
53
54
55
56
57
58
59
60
|
# File 'lib/quby/compiler/dsl/charting/chart_builder.rb', line 52
def plot(key, **options)
unless plottable = @questionnaire.find_plottable(key)
fail "Questionnaire #{@questionnaire.key} chart #{@chart.key} references unknown score or question #{key}"
end
configure_options plottable, options
@chart.plottables << Entities::Charting::Plottable.new(plottable.key, options)
end
|
#plotband(from, to, color) ⇒ Object
44
45
46
|
# File 'lib/quby/compiler/dsl/charting/chart_builder.rb', line 44
def plotband(from, to, color)
@chart.plotbands << {from: from, to: to, color: color}
end
|
#plotline(value, color) ⇒ Object
48
49
50
|
# File 'lib/quby/compiler/dsl/charting/chart_builder.rb', line 48
def plotline(value, color)
@chart.plotlines << {value: value, color: color}
end
|
#range(range) ⇒ Object
28
29
30
|
# File 'lib/quby/compiler/dsl/charting/chart_builder.rb', line 28
def range(range)
@chart.y_range = range
end
|
#tick_interval(tick_interval) ⇒ Object
32
33
34
|
# File 'lib/quby/compiler/dsl/charting/chart_builder.rb', line 32
def tick_interval(tick_interval)
@chart.tick_interval = tick_interval
end
|
#title(title) ⇒ Object
24
25
26
|
# File 'lib/quby/compiler/dsl/charting/chart_builder.rb', line 24
def title(title)
@chart.title = title
end
|
#validate! ⇒ Object
72
73
74
75
76
77
78
79
|
# File 'lib/quby/compiler/dsl/charting/chart_builder.rb', line 72
def validate!
if @chart.y_categories.present? && @chart.y_range.present? &&
@chart.y_range != (0..(@chart.y_categories.count - 1))
fail ArgumentError, 'Y_categories size and range do not match'
end
true
end
|
#y_categories(y_categories) ⇒ Object
36
37
38
|
# File 'lib/quby/compiler/dsl/charting/chart_builder.rb', line 36
def y_categories(y_categories)
@chart.y_categories = y_categories
end
|
#y_range_categories(*y_range_categories) ⇒ Object
40
41
42
|
# File 'lib/quby/compiler/dsl/charting/chart_builder.rb', line 40
def y_range_categories(*y_range_categories)
@chart.y_range_categories = RangeCategories.new(*y_range_categories).as_range_hash
end
|