Class: DynamicReports::Chart

Inherits:
Object
  • Object
show all
Defined in:
lib/dynamic_reports/charts.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*chart_options) ⇒ Chart

Returns a new instance of Chart.



13
14
15
16
# File 'lib/dynamic_reports/charts.rb', line 13

def initialize(*chart_options)
  chart_options = chart_options.shift || {}
  options.merge!(chart_options)
end

Class Method Details

.configure(name, *chart_options, &block) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/dynamic_reports/charts.rb', line 5

def self.configure(name, *chart_options, &block)
  chart_options = chart_options.shift || {}
  chart = new(chart_options)
  chart.instance_eval(&block)
  chart.name name
  chart
end

Instance Method Details

#columns(*array) ⇒ Object

(Optional) Accessor for columns

Pass an array of symbols to define columns to chart. Columns MUST be numeric in value to chart.

Example:

columns :pageviews, :visits

You may leave this accessor blank to default to the report columns specified that are numeric.



102
103
104
105
106
107
108
109
110
111
112
# File 'lib/dynamic_reports/charts.rb', line 102

def columns(*array)
  unless array.empty?
    if (array.class == Array)
      options[:columns] = array
    else
      raise "Report columns must be specified."
    end
  else
    options[:columns]
  end
end

#height(value = nil) ⇒ Object

(Optional - Default = 175). Accessor used to set the height, in pixels, of the chart.

height "350"


77
78
79
# File 'lib/dynamic_reports/charts.rb', line 77

def height(value = nil)
  value ? options[:height] = value : (options[:height] || "175")
end

#label_column(value = nil) ⇒ Object

(Optional) Accessor used by bar and pie charts to determine the independent varible chart labels. Due to size constraints this is NOT used by column or line charts, but you can add labels to the X-axis for those charts via chart_options and passing Google Chart API calls.“

label_column should be a SINGLE column name from the dataset.

label_column "recorded_at"


49
50
51
# File 'lib/dynamic_reports/charts.rb', line 49

def label_column(value = nil)
  value ? options[:label_column] = value : options[:label_column]
end

#name(value = nil) ⇒ Object

Accessor used to set or get a specific report. Must be unique:

name "PV_Visits"


35
36
37
# File 'lib/dynamic_reports/charts.rb', line 35

def name(value = nil)
  value ? options[:name] = value.to_sym : options[:name]
end

#no_labels(value = nil) ⇒ Object

(Optional - Default = false). Accessor used to determine if axis labels should be shown. By default y-axis labels are shown.

no_labels true


86
87
88
# File 'lib/dynamic_reports/charts.rb', line 86

def no_labels(value = nil)
  value ? options[:no_labels] = value : options[:no_labels]
end

#optionsObject



18
19
20
# File 'lib/dynamic_reports/charts.rb', line 18

def options
  @options ||= {} ; @options
end

#title(value = nil) ⇒ Object

(Optional) Accessor used to set the chart title:

title "Pageviews versus Visits"

This is displayed above the chart



27
28
29
# File 'lib/dynamic_reports/charts.rb', line 27

def title(value = nil)
  value ? options[:title] = value : options[:title]
end

#type(value = nil) ⇒ Object

(Optional - Default = line). Accessor used to determine the type of chart to display. Valid options are line, column, bar or pie:

type "bar"


59
60
61
# File 'lib/dynamic_reports/charts.rb', line 59

def type(value = nil)
  value ? options[:type] = value : (options[:type] || :line)
end

#width(value = nil) ⇒ Object

(Optional - Default = 250). Accessor used to set the width, in pixels, of the chart.

width "400"


68
69
70
# File 'lib/dynamic_reports/charts.rb', line 68

def width(value = nil)
  value ? options[:width] = value : (options[:width] || "250")
end