Class: Seer::PieChart

Inherits:
Object
  • Object
show all
Includes:
Chart
Defined in:
lib/seer/pie_chart.rb

Overview

USAGE

In your controller:

@data = Widgets.all # Must be an array of objects that respond to the specidied data method 
                    # (In this example, 'quantity'

In your view:

<div id="chart"></div>

<%= Seer::visualize(
      @data, 
      :as => :pie_chart,
      :series => {:series_label => 'name', :data_method => 'quantity'},
      :chart_options => { 
        :height => 300,
        :width => 300,
        :axis_font_size => 11,
        :title => "Widget Quantities",
        :point_size => 5,
        :is_3_d => true
      }
     )
 -%>

For details on the chart options, see the Google API docs at code.google.com/apis/visualization/documentation/gallery/piechart.html

Constant Summary

Constants included from Chart

Chart::DEFAULT_COLORS, Chart::DEFAULT_HEIGHT, Chart::DEFAULT_LEGEND_LOCATION, Chart::DEFAULT_WIDTH

Instance Attribute Summary collapse

Attributes included from Chart

#chart_element, #colors

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Chart

#data_columns, #formatted_colors, #in_element=, #options

Constructor Details

#initialize(args = {}) ⇒ PieChart

:nodoc:



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/seer/pie_chart.rb', line 42

def initialize(args={}) #:nodoc:

  # Standard options
  args.each{ |method,arg| self.send("#{method}=",arg) if self.respond_to?(method) }

  # Chart options
  args[:chart_options].each{ |method, arg| self.send("#{method}=",arg) if self.respond_to?(method) }

  # Handle defaults      
  @colors ||= args[:chart_options][:colors] || DEFAULT_COLORS
  @legend ||= args[:chart_options][:legend] || DEFAULT_LEGEND_LOCATION
  @height ||= args[:chart_options][:height] || DEFAULT_HEIGHT
  @width  ||= args[:chart_options][:width] || DEFAULT_WIDTH
  @is_3_d ||= args[:chart_options][:is_3_d]

  @data_table = []
  
end

Instance Attribute Details

#background_colorObject

Chart options accessors



37
38
39
# File 'lib/seer/pie_chart.rb', line 37

def background_color
  @background_color
end

#border_colorObject

Chart options accessors



37
38
39
# File 'lib/seer/pie_chart.rb', line 37

def border_color
  @border_color
end

#dataObject

Graph data



40
41
42
# File 'lib/seer/pie_chart.rb', line 40

def data
  @data
end

#data_methodObject

Graph data



40
41
42
# File 'lib/seer/pie_chart.rb', line 40

def data_method
  @data_method
end

#data_tableObject

:nodoc:



40
41
42
# File 'lib/seer/pie_chart.rb', line 40

def data_table
  @data_table
end

#enable_tooltipObject

Chart options accessors



37
38
39
# File 'lib/seer/pie_chart.rb', line 37

def enable_tooltip
  @enable_tooltip
end

#focus_border_colorObject

Chart options accessors



37
38
39
# File 'lib/seer/pie_chart.rb', line 37

def focus_border_color
  @focus_border_color
end

#heightObject

Chart options accessors



37
38
39
# File 'lib/seer/pie_chart.rb', line 37

def height
  @height
end

#is_3_dObject

:nodoc:



37
38
39
# File 'lib/seer/pie_chart.rb', line 37

def is_3_d
  @is_3_d
end

#label_methodObject

Graph data



40
41
42
# File 'lib/seer/pie_chart.rb', line 40

def label_method
  @label_method
end

#legendObject

Chart options accessors



37
38
39
# File 'lib/seer/pie_chart.rb', line 37

def legend
  @legend
end

#legend_background_colorObject

Chart options accessors



37
38
39
# File 'lib/seer/pie_chart.rb', line 37

def legend_background_color
  @legend_background_color
end

#legend_font_sizeObject

Chart options accessors



37
38
39
# File 'lib/seer/pie_chart.rb', line 37

def legend_font_size
  @legend_font_size
end

#legend_text_colorObject

Chart options accessors



37
38
39
# File 'lib/seer/pie_chart.rb', line 37

def legend_text_color
  @legend_text_color
end

#pie_join_angleObject

Chart options accessors



37
38
39
# File 'lib/seer/pie_chart.rb', line 37

def pie_join_angle
  @pie_join_angle
end

#pie_minimal_angleObject

Chart options accessors



37
38
39
# File 'lib/seer/pie_chart.rb', line 37

def pie_minimal_angle
  @pie_minimal_angle
end

#titleObject

Chart options accessors



37
38
39
# File 'lib/seer/pie_chart.rb', line 37

def title
  @title
end

#title_colorObject

Chart options accessors



37
38
39
# File 'lib/seer/pie_chart.rb', line 37

def title_color
  @title_color
end

#title_font_sizeObject

Chart options accessors



37
38
39
# File 'lib/seer/pie_chart.rb', line 37

def title_font_size
  @title_font_size
end

#title_xObject

Chart options accessors



37
38
39
# File 'lib/seer/pie_chart.rb', line 37

def title_x
  @title_x
end

#title_yObject

Chart options accessors



37
38
39
# File 'lib/seer/pie_chart.rb', line 37

def title_y
  @title_y
end

#tooltip_font_sizeObject

Chart options accessors



37
38
39
# File 'lib/seer/pie_chart.rb', line 37

def tooltip_font_size
  @tooltip_font_size
end

#tooltip_heightObject

Chart options accessors



37
38
39
# File 'lib/seer/pie_chart.rb', line 37

def tooltip_height
  @tooltip_height
end

#tooltip_widthObject

Chart options accessors



37
38
39
# File 'lib/seer/pie_chart.rb', line 37

def tooltip_width
  @tooltip_width
end

#widthObject

Chart options accessors



37
38
39
# File 'lib/seer/pie_chart.rb', line 37

def width
  @width
end

Class Method Details

.render(data, args) ⇒ Object

:nodoc:



103
104
105
106
107
108
109
110
111
112
# File 'lib/seer/pie_chart.rb', line 103

def self.render(data, args) #:nodoc:
  graph = Seer::PieChart.new(
    :data           => data,
    :label_method   => args[:series][:series_label],
    :data_method    => args[:series][:data_method],
    :chart_options  => args[:chart_options],
    :chart_element  => args[:in_element] || 'chart'
  )
  graph.to_js
end

Instance Method Details

#nonstring_optionsObject

:nodoc:



75
76
77
# File 'lib/seer/pie_chart.rb', line 75

def nonstring_options #:nodoc:
  [:colors, :enable_tooltip, :height, :is_3_d, :legend_font_size, :pie_join_angle, :pie_minimal_angle, :title_font_size, :tooltip_font_size, :tooltip_width, :width]
end

#string_optionsObject

:nodoc:



79
80
81
# File 'lib/seer/pie_chart.rb', line 79

def string_options #:nodoc:
  [:background_color, :border_color, :focus_border_color, :legend, :legend_background_color, :legend_text_color, :title, :title_color]
end

#to_jsObject

:nodoc:



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/seer/pie_chart.rb', line 83

def to_js #:nodoc:

  %{
    <script type="text/javascript">
      google.load('visualization', '1', {'packages':['piechart']});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = new google.visualization.DataTable();
#{data_columns}
#{data_table.join("\r")}
        var options = {};
#{options}
        var container = document.getElementById('#{self.chart_element}');
        var chart = new google.visualization.PieChart(container);
        chart.draw(data, options);
      }
    </script>
  }
end