Class: QueryReport::Chart::ChartBase
- Inherits:
-
Object
- Object
- QueryReport::Chart::ChartBase
- Defined in:
- lib/query_report/chart/chart_base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
- #add(column_title, &block) ⇒ Object
-
#initialize(title, query, options = {}) ⇒ ChartBase
constructor
A new instance of ChartBase.
- #prepare_visualr(type) ⇒ Object
- #to_blob(type) ⇒ Object
Constructor Details
#initialize(title, query, options = {}) ⇒ ChartBase
Returns a new instance of ChartBase.
9 10 11 12 13 |
# File 'lib/query_report/chart/chart_base.rb', line 9 def initialize(title, query, ={}) @title = title @query = query @options = {:width => 500, :height => 240}.merge() end |
Instance Attribute Details
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
7 8 9 |
# File 'lib/query_report/chart/chart_base.rb', line 7 def columns @columns end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
7 8 9 |
# File 'lib/query_report/chart/chart_base.rb', line 7 def data @data end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/query_report/chart/chart_base.rb', line 7 def @options end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
7 8 9 |
# File 'lib/query_report/chart/chart_base.rb', line 7 def title @title end |
Instance Method Details
#add(column_title, &block) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/query_report/chart/chart_base.rb', line 15 def add(column_title, &block) val = block.call(@query) @columns ||= [] @columns << QueryReport::Chart::Column.new(column_title, val.kind_of?(String) ? :string : :number) @data ||= [] @data << val end |
#prepare_visualr(type) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/query_report/chart/chart_base.rb', line 23 def prepare_visualr(type) @data_table = GoogleVisualr::DataTable.new ##### Adding column header ##### @data_table.new_column('string', '') if type == :column @columns.each do |col| @data_table.new_column(col.type.to_s, col.title) end ##### Adding column header ##### ##### Adding value ##### chart_row_data = type == :column ? [''] + @data : @data @data_table.add_row(chart_row_data) ##### Adding value ##### = {:title => title, backgroundColor: 'transparent'}.merge(@options) chart_type = "#{type}_chart".classify chart_type = "GoogleVisualr::Interactive::#{chart_type}".constantize ap @data_table.as_json chart_type.new(@data_table, ) end |
#to_blob(type) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/query_report/chart/chart_base.rb', line 45 def to_blob(type) chart_type = type.to_s.classify chart_type = "Gruff::#{chart_type}".constantize @gruff = chart_type.new(@options[:width]) @gruff.title = title @gruff.theme = QueryReport::Chart::Themes::GOOGLE_CHART @data.each_with_index do |value, i| @gruff.data(@columns[i].title, value) end @gruff.to_blob end |