a_la_chart 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/README.rdoc +62 -1
- data/lib/a_la_chart/a_la_chart.rb +27 -3
- data/lib/a_la_chart.rb +1 -1
- metadata +1 -1
data/History.txt
CHANGED
data/README.rdoc
CHANGED
@@ -113,7 +113,7 @@ The corresponding index.html.haml (or index.html.erb, or whatever) will look som
|
|
113
113
|
|
114
114
|
Except for chart_tag, it's pretty normal. In the first chart we pass in the minimum required fields for chart_tag: the chart implementation (:google, :fusion, :raphael are the first to be supported, more to come), and the chart type (dependent on the implementation, see a_la_chart/configs/*/config.yml for the lists). The second pie chart is populated with the :gender pie data. ":case" is how we can support several styles of data for a single type of chart.
|
115
115
|
|
116
|
-
|
116
|
+
=== Multiple Chart Support
|
117
117
|
|
118
118
|
What if we want to display the city data as a :bar chart? There are two options. The first option, we can move the city data to a separate chart block. You can have as many chart blocks in a single controller as supported types. While we're at it, let's rename the query select names to be 'label' and 'value', to avoid the extra typing of remapping the data.
|
119
119
|
|
@@ -160,6 +160,67 @@ The above example shows the minimum configs required. However, certain configs a
|
|
160
160
|
|
161
161
|
More to come...
|
162
162
|
|
163
|
+
== CONFIGURATION
|
164
|
+
|
165
|
+
=== Overriding Config
|
166
|
+
|
167
|
+
Internal configs can be overridden in rails environment configs (eg. environment.rb). For example, to use a custom :inline ERB template (paths are based on RAILS_ROOT):
|
168
|
+
|
169
|
+
ALaChart::Config[:fusion][:v3_1][:pie][:data] = 'app/views/a_la_charts/custom_inline.html.erb'
|
170
|
+
|
171
|
+
Then just copy the original template from the gem config dir, and make the desired changes.
|
172
|
+
|
173
|
+
NOTE: Creating custom templates can be complex and tie your project closely to a particular version of ALC. In short, caveat emptor, pal.
|
174
|
+
|
175
|
+
=== Custom Templates
|
176
|
+
|
177
|
+
Creating custom configs is done just like overriding configs - be sure you do not over write any existing chart configs.
|
178
|
+
|
179
|
+
For example, suppose you want the Fusion Stacked Column chart to contain an HTML legend table to of your own design, but you do not want to overwrite the existing Stacked Column chart. You can create a new chart like this (similar to the YAML stacked_column config):
|
180
|
+
|
181
|
+
ALaChart::Config[:fusion][:v3_1][:legend_stacked_column] = {
|
182
|
+
:chart_type => 'StackedColumn2D',
|
183
|
+
:inline => 'app/views/a_la_charts/legend_stacked_column.html.erb'
|
184
|
+
}
|
185
|
+
|
186
|
+
Next, copy the inline template from the a la chart config directory, place it in the path denoted by your :inline configuration, and paste your custom legend table at the end (or whatever changes you want), for example:
|
187
|
+
|
188
|
+
<table class="legend">
|
189
|
+
<tr>
|
190
|
+
<th colspan="2">Category</th>
|
191
|
+
<th>Total</th>
|
192
|
+
</tr>
|
193
|
+
<% color_palette_clear(:fusion, :stacked_column) %>
|
194
|
+
<% @totals.each do |total| %>
|
195
|
+
<tr>
|
196
|
+
<td style="background-color:#<%= color_palette_next(:fusion, :stacked_column) %>"> </td>
|
197
|
+
<td><%= total[:category] %></td>
|
198
|
+
<td><%= total[:quantity] %></td>
|
199
|
+
</tr>
|
200
|
+
<% end %>
|
201
|
+
</table>
|
202
|
+
|
203
|
+
'color_palette_clear' and 'color_palette_next' are a built-in functions to reset and pop color values from the color_palette stack. They are two of several built in helpers. View them all in a_la_chart_helper.rb. But note, since they are still considered internal, they are subject to change from version to version. Again, caveat emptor.
|
204
|
+
|
205
|
+
== THEMING
|
206
|
+
|
207
|
+
By default a la chart comes with no themes, and allows each framework to declare its own defaults. However, you probably want your charts to have a certain global look. The problem being that different frameworks have different configurations. For now, ALC does not attempt to replace the theming with any sort of universal mechanism (if you want a red pie chart for Fusion and Google, you must create two themes). This may change in subsequent versions.
|
208
|
+
|
209
|
+
For example, Fusion Charts have rich customizability, which must be configured with the chart data. Fusion can be given a custom color palette (the ordered list of colors to be 'popped' for each data segment), and a set of default chart options (values that will appear in the xml data 'chart' tag).
|
210
|
+
|
211
|
+
ALaChart::Config[:fusion][:theme] = :my_theme
|
212
|
+
ALaChart::Config[:fusion][:themes][:my_theme] = {
|
213
|
+
:color_palette => [ '7BB465', 'B2B4B6', 'FEC35A', '65A4B5', '9E65B5', 'B57765', 'F7DF65' ],
|
214
|
+
:default_options => {
|
215
|
+
:useRoundEdges => '0',
|
216
|
+
:alpha => '100',
|
217
|
+
:bgColor => 'ffffff'
|
218
|
+
}
|
219
|
+
}
|
220
|
+
|
221
|
+
|
222
|
+
More to come...
|
223
|
+
|
163
224
|
== LICENSE:
|
164
225
|
|
165
226
|
Copyright (c) 2009 Mobi, released under the MIT license
|
@@ -100,8 +100,8 @@ module ALaChart
|
|
100
100
|
|
101
101
|
self.before_filter(:provide_chart_data, :only => [:index, :show])
|
102
102
|
|
103
|
-
# Namespace this stuff??
|
104
|
-
[:data, :fields, :meta, :value, :set_chart].each do |method|
|
103
|
+
# TODO: Namespace this stuff??
|
104
|
+
[:before, :data, :fields, :meta, :value, :set_chart].each do |method|
|
105
105
|
master_helper_module.module_eval <<-end_eval
|
106
106
|
def #{method}(*args, &block) # def current_user(*args, &block)
|
107
107
|
controller.send(%(#{method}), *args, &block) # controller.send(%(current_user), *args, &block)
|
@@ -140,6 +140,7 @@ module ALaChart
|
|
140
140
|
|
141
141
|
if cases.blank?
|
142
142
|
define_method("get_data") do
|
143
|
+
do_before_data if defined?(do_before_data)
|
143
144
|
# note: instance_eval binds scope variables, call does not
|
144
145
|
instance_eval(&block) || []
|
145
146
|
# block.call(binding)
|
@@ -152,6 +153,11 @@ module ALaChart
|
|
152
153
|
else
|
153
154
|
cases.each { |caze|
|
154
155
|
define_method("get_data_#{caze}") do
|
156
|
+
if respond_to?("do_before_data_#{caze}")
|
157
|
+
return [] unless send("do_before_data_#{caze}")
|
158
|
+
elsif defined?(do_before_data)
|
159
|
+
return [] unless do_before_data
|
160
|
+
end
|
155
161
|
# note: instance_eval binds scope variables, call does not
|
156
162
|
instance_eval(&block) || []
|
157
163
|
# block.call(binding)
|
@@ -162,7 +168,25 @@ module ALaChart
|
|
162
168
|
}
|
163
169
|
end
|
164
170
|
end
|
165
|
-
|
171
|
+
|
172
|
+
def before(*cases, &block)
|
173
|
+
if cases.blank?
|
174
|
+
define_method("do_before_data") do
|
175
|
+
# note: instance_eval binds scope variables, call does not
|
176
|
+
instance_eval(&block)
|
177
|
+
# block.call(binding)
|
178
|
+
end
|
179
|
+
else
|
180
|
+
cases.each { |caze|
|
181
|
+
define_method("do_before_data_#{caze}") do
|
182
|
+
# note: instance_eval binds scope variables, call does not
|
183
|
+
instance_eval(&block)
|
184
|
+
# block.call(binding)
|
185
|
+
end
|
186
|
+
}
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
166
190
|
def meta(*attrs)
|
167
191
|
if attrs.size == 1
|
168
192
|
attrs = attrs[0]
|
data/lib/a_la_chart.rb
CHANGED