Module: Analytica::Visualization::DataSet

Includes:
Strict
Included in:
DataSet
Defined in:
lib/visualization.rb

Instance Method Summary collapse

Instance Method Details

#datamaxObject



172
173
174
# File 'lib/visualization.rb', line 172

def datamax
(max > 0) ? (1.1*max) : 1
end

#to_bargraph(params = {}) ⇒ Object



267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
# File 'lib/visualization.rb', line 267

def to_bargraph(params={})
  enforce_map_defaults!({
    :title => {:text => ' ', :color => "000000", :size => 12},
    :orientation => :vertical,
    :color => '00bb00',
    :background_color => 'ffffff',
    :stacked => false,
    :width => 600,
    :height => 280,
    :stacked => false,
    :format => :image_tag,
    :bar_settings => {}}, params)

  enforce_map!({
    :title => :hash_map,
    :width => :natural_number,
    :height => :natural_number,
    :orientation => [:vertical, :horizontal],
    :stacked => :boolean,
    :background_color => :hex_color,
    :color => :hex_color,
    :format => [:url, :image_tag],
    :bar_settings => :hash_map}, params)
  
  set_title(params[:title])

  options = {}

  options.merge!({:format => 'image_tag'}) if params[:format] == :image_tag

  base = {
    :data => self,
    :max_value => datamax,
    :size => "#{params[:width]}x#{params[:height]}",
    :orientation => params[:orientation].to_s,
    :stacked => params[:stacked],
    :bar_width_and_spacing => bar_settings(params[:bar_settings])
  }

  options.merge!(base)

  color = {
    :bar_colors => params[:color],
    :background => params[:background_color],
    :chart_background => params[:background_color]
  }

  options.merge!(color)

  options.merge!(common_options)
  
  return Gchart.bar(options)
end

#to_linegraph(params = {}) ⇒ Object



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/visualization.rb', line 176

def to_linegraph(params={})
  enforce_map_defaults!({
    :title => {:text => ' ', :color => "000000", :size => 12},
    :color => 'ffffff',
    :background_color => '000000',
    :width => 600,
    :height => 280,
    :format => :image_tag,
    :bar_settings => {}}, params)

  enforce_map!({
    :title => :hash_map,
    :width => :natural_number,
    :height => :natural_number,
    :background_color => :hex_color,
    :format => [:url, :image_tag],
    :color => :hex_color}, params)

  set_title(params[:title])

  options = {}

  options.merge!({:format => 'image_tag'}) if params[:format] == :image_tag

  base = {
    :data => self,
    :max_value => datamax,
    :size => "#{params[:width]}x#{params[:height]}"
  }

  options.merge!(base)

  color = {
    :line_colors => params[:color],
    :background => params[:background_color],
    :chart_background => params[:background_color]
  }

  options.merge!(color)

  options.merge!(common_options)

  Gchart.line(options)
end

#to_sparkline(params = {}) ⇒ Object



221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/visualization.rb', line 221

def to_sparkline(params={})
  enforce_map_defaults!({
    :title => {:text => ' ', :color => "000000", :size => 12},
    :color => '0000ff',
    :background_color => 'ffffff',
    :width => 600,
    :height => 180,
    :format => :image_tag,
    :bar_settings => {}}, params)

  enforce_map!({
    :title => :hash_map,
    :width => :natural_number,
    :height => :natural_number,
    :background_color => :hex_color,
    :format => [:url, :image_tag],
    :color => :hex_color}, params)

  set_title(params[:title])

  options = {}

  options.merge!({:format => 'image_tag'}) if params[:format] == :image_tag

  base = {
    :data => self,
    :max_value => datamax,
    :size => "#{params[:width]}x#{params[:height]}"
  }

  options.merge!(base)

  color = {
    :line_colors => params[:color],
    :background => params[:background_color],
    :chart_background => params[:background_color]
  }

  options.merge!(color)

  options.merge!(common_options)

  Gchart.sparkline(options)
end