Module: Analytica::Visualization::DataSystem

Included in:
DataSystem
Defined in:
lib/visualization.rb

Instance Method Summary collapse

Instance Method Details

#datamaxObject



324
325
326
# File 'lib/visualization.rb', line 324

def datamax
  (self.map{|dset| dset.datamax}).max
end

#to_bargraph(params = {}) ⇒ Object



372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
# File 'lib/visualization.rb', line 372

def to_bargraph(params={})
  enforce_map_defaults!({
    :title => {:text => ' ', :color => "000000", :size => 12},
    :orientation => :vertical,
    :color => 'ffffff',
    :background_color => '000000',
    :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,
    :colors => :hex_color_array,
    :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[:colors],
    :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



328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
# File 'lib/visualization.rb', line 328

def to_linegraph(params={})
  enforce_map_defaults!({
    :title => {:text => ' ', :color => "000000", :size => 12},
    :color => 'ffffff',
    :width => 600,
    :height => 280,
    :format => :image_tag,
    :background_color => '000000'}, 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[:colors],
    :background => params[:background_color],
    :chart_background => params[:background_color]
  }

  options.merge!(color)

  options.merge!(common_options)

  Gchart.line(options)
end