Class: Quby::Compiler::Entities::Charting::Chart

Inherits:
Object
  • Object
show all
Defined in:
lib/quby/compiler/entities/charting/chart.rb

Direct Known Subclasses

BarChart, LineChart, OverviewChart, RadarChart

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, title: nil, plottables: nil, y_categories: nil, y_range_categories: nil, chart_type: nil, y_range: nil, tick_interval: nil, plotbands: nil, plotlines: nil) ⇒ Chart

Returns a new instance of Chart.



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/quby/compiler/entities/charting/chart.rb', line 66

def initialize(key, title: nil, plottables: nil, y_categories: nil, y_range_categories: nil, chart_type: nil, y_range: nil, tick_interval: nil, plotbands: nil, plotlines: nil)
  self.key = key.to_sym
  self.title = title
  self.plottables = plottables || []
  self.y_categories = y_categories
  self.y_range_categories = y_range_categories
  self.chart_type = chart_type
  self.y_range = y_range
  self.tick_interval = tick_interval
  self.plotbands = plotbands || []
  self.plotlines = plotlines || []
end

Instance Attribute Details

#chart_typeSymbol

Returns:

  • (Symbol)


52
53
54
# File 'lib/quby/compiler/entities/charting/chart.rb', line 52

def chart_type
  @chart_type
end

#keySymbol

Returns:

  • (Symbol)


9
10
11
# File 'lib/quby/compiler/entities/charting/chart.rb', line 9

def key
  @key
end

#plotbandsArray

Returns:

  • (Array)


61
62
63
# File 'lib/quby/compiler/entities/charting/chart.rb', line 61

def plotbands
  @plotbands
end

#plotlinesArray

Returns:

  • (Array)


64
65
66
# File 'lib/quby/compiler/entities/charting/chart.rb', line 64

def plotlines
  @plotlines
end

#plottablesArray

Returns:

  • (Array)


15
16
17
# File 'lib/quby/compiler/entities/charting/chart.rb', line 15

def plottables
  @plottables
end

#tick_intervalFloat

Returns:

  • (Float)


58
59
60
# File 'lib/quby/compiler/entities/charting/chart.rb', line 58

def tick_interval
  @tick_interval
end

#titleString

Returns:

  • (String)


12
13
14
# File 'lib/quby/compiler/entities/charting/chart.rb', line 12

def title
  @title
end

#y_categoriesArray

If y_categories are defined, plottable values should correspond to values from this array and the graph will be plotted with corresponding y axis categories example (icl_r):

["Zeer laag", "Laag", "Gemiddeld", "Hoog", "Zeer Hoog"]

(caution, capitalization oddity)

NB: only implemented for bar charts on the roqua side

Returns:

  • (Array)


28
29
30
# File 'lib/quby/compiler/entities/charting/chart.rb', line 28

def y_categories
  @y_categories
end

#y_rangeObject



83
84
85
# File 'lib/quby/compiler/entities/charting/chart.rb', line 83

def y_range
  @y_range || @y_range = default_y_range
end

#y_range_categoriesHash<Range, String>

If y_range_categories are defined, plottable values should fall in the ranges that compose the keys of this hash. The chart will label these ranges of y_values with the corresponding value in the hash on the y axis. For example:

{
  (0.0...30.0) => "Zeer laag",
  (30.0...40.0) => "Laag",
  (40.0...60.0) => "Gemiddeld",
  (60.0...70.0) => "Hoog",
  (70.0..100.0) => "Zeer hoog"
}

NB: .. is inclusive the last value in the range, … is exclusive.

ChartBuilder#y_range_categories massages its parameters into this format. Only implemented for line charts on the RoQua side.

Returns:

  • (Hash<Range, String>)


49
50
51
# File 'lib/quby/compiler/entities/charting/chart.rb', line 49

def y_range_categories
  @y_range_categories
end

Instance Method Details

#default_y_rangeObject



91
92
93
94
95
96
# File 'lib/quby/compiler/entities/charting/chart.rb', line 91

def default_y_range
  # when there are y_categories, the y_range should match the
  # number of categories (validated in chart_builder#validate!)
  (0..(y_categories.count - 1)) if y_categories.present?
  # otherwise, nil is allowed as a y_range
end

#typeObject



79
80
81
# File 'lib/quby/compiler/entities/charting/chart.rb', line 79

def type
  self.class.name.to_s.demodulize.underscore
end