Class: SmartChart::BaseChart
- Inherits:
-
Object
- Object
- SmartChart::BaseChart
- Defined in:
- lib/smart_chart/base_chart.rb
Overview
Method names are called attributes, data for URL are called parameters. Use attr_writers for all attributes, and wrte readers so they instantiate the correct object type.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#background ⇒ Object
chart background.
-
#data ⇒ Object
chart data.
-
#height ⇒ Object
dimensions of chart image, in pixels.
-
#legend ⇒ Object
legend properties.
-
#margins ⇒ Object
chart margins.
-
#orientation ⇒ Object
bar chart orientation – :vertical (default) or :horizontal pie chart orientation – degrees of rotation.
-
#style ⇒ Object
bar – :grouped (default) or :stacked pie – nil (2D, default), “3d”, or :concentric radar – nil (default) or :filled.
-
#width ⇒ Object
dimensions of chart image, in pixels.
-
#y_max ⇒ Object
writeonly
chart range.
-
#y_min ⇒ Object
writeonly
chart range.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ BaseChart
constructor
Accept attributes and attempt to assign each to an attribute.
-
#to_html(encode = true, validation = true, attributes = {}) ⇒ Object
Chart as an HTML tag.
-
#to_query_string(encode = true, validation = true) ⇒ Object
Get the chart URL query string.
-
#to_url(encode = true, validation = true) ⇒ Object
Get the full chart URL.
-
#valid? ⇒ Boolean
Does the chart pass all validations?.
-
#validate! ⇒ Object
Run validation (may raise exceptions).
Constructor Details
#initialize(options = {}) ⇒ BaseChart
Accept attributes and attempt to assign each to an attribute.
56 57 58 59 60 61 62 63 64 |
# File 'lib/smart_chart/base_chart.rb', line 56 def initialize( = {}) .each do |k,v| begin send("#{k}=", v) rescue NoMethodError raise NoAttributeError.new(self, k) end end end |
Instance Attribute Details
#background ⇒ Object
chart background
36 37 38 |
# File 'lib/smart_chart/base_chart.rb', line 36 def background @background end |
#data ⇒ Object
chart data
30 31 32 |
# File 'lib/smart_chart/base_chart.rb', line 30 def data @data end |
#height ⇒ Object
dimensions of chart image, in pixels
27 28 29 |
# File 'lib/smart_chart/base_chart.rb', line 27 def height @height end |
#legend ⇒ Object
legend properties
42 43 44 |
# File 'lib/smart_chart/base_chart.rb', line 42 def legend @legend end |
#margins ⇒ Object
chart margins
39 40 41 |
# File 'lib/smart_chart/base_chart.rb', line 39 def margins @margins end |
#orientation ⇒ Object
bar chart orientation – :vertical (default) or :horizontal pie chart orientation – degrees of rotation
46 47 48 |
# File 'lib/smart_chart/base_chart.rb', line 46 def orientation @orientation end |
#style ⇒ Object
bar – :grouped (default) or :stacked pie – nil (2D, default), “3d”, or :concentric radar – nil (default) or :filled
51 52 53 |
# File 'lib/smart_chart/base_chart.rb', line 51 def style @style end |
#width ⇒ Object
dimensions of chart image, in pixels
27 28 29 |
# File 'lib/smart_chart/base_chart.rb', line 27 def width @width end |
#y_max=(value) ⇒ Object
chart range
33 34 35 |
# File 'lib/smart_chart/base_chart.rb', line 33 def y_max=(value) @y_max = value end |
#y_min=(value) ⇒ Object
chart range
33 34 35 |
# File 'lib/smart_chart/base_chart.rb', line 33 def y_min=(value) @y_min = value end |
Instance Method Details
#to_html(encode = true, validation = true, attributes = {}) ⇒ Object
Chart as an HTML tag.
85 86 87 |
# File 'lib/smart_chart/base_chart.rb', line 85 def to_html(encode = true, validation = true, attributes = {}) '<img src="%s"%s />' % [to_url(encode, validation), tag_attributes(attributes)] end |
#to_query_string(encode = true, validation = true) ⇒ Object
Get the chart URL query string.
69 70 71 72 |
# File 'lib/smart_chart/base_chart.rb', line 69 def to_query_string(encode = true, validation = true) validate if validation query_string(encode) end |
#to_url(encode = true, validation = true) ⇒ Object
Get the full chart URL.
77 78 79 80 |
# File 'lib/smart_chart/base_chart.rb', line 77 def to_url(encode = true, validation = true) "http://chart.apis.google.com/chart?" + to_query_string(encode, validation) end |
#valid? ⇒ Boolean
Does the chart pass all validations?
99 100 101 102 103 104 105 106 |
# File 'lib/smart_chart/base_chart.rb', line 99 def valid? begin validate true rescue ValidationError false end end |
#validate! ⇒ Object
Run validation (may raise exceptions).
92 93 94 |
# File 'lib/smart_chart/base_chart.rb', line 92 def validate! validate end |