Class: ReportEngine::GoogleChart

Inherits:
Object
  • Object
show all
Defined in:
lib/report_engine/google_chart.rb

Direct Known Subclasses

Html::GoogleChart, Pdf::GoogleChart

Instance Method Summary collapse

Constructor Details

#initialize(canvas, options) ⇒ GoogleChart

Returns a new instance of GoogleChart.



6
7
8
9
10
11
12
13
14
15
# File 'lib/report_engine/google_chart.rb', line 6

def initialize(canvas, options)
  @canvas       = canvas
  @data         = options[:data]
  @scale_labels = options[:scale_labels]
  @x_label      = options[:x_label]
  @y_label      = options[:y_label]
  @grouped      = options[:grouped].nil? ? true : options[:grouped]
  @colors       = options[:colors] || ['97172E','EE8C9E']
  @show_marker  = options[:show_marker]
end

Instance Method Details

#generate_urlObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/report_engine/google_chart.rb', line 17

def generate_url
  max = @data.max
  chart = ::GChart.bar do |g|
    g.grouped = @grouped
    g.data = @data #values.map{|v| v * 100.0 / max }
    g.colors = @colors
    g.width  = 520
    g.height = 140
    g.orientation = :vertical
    g.axis(:left) do |a|
      a.labels = [@y_label] #["%"]
      a.label_positions = [100]
      a.text_color = :black
    end
    g.axis(:bottom) do |a|
      a.labels = @scale_labels # ["0-10","10-20","20-30","30-40","40-50","50-60","60-70","70-80","80-90","90-100"]
      a.text_color = :black
    end
    g.axis(:bottom) do |a|
      a.labels = [@x_label] # ["Procentil"]
      a.label_positions = [100]
      a.text_color = :black
    end
    extra = {"chbh" => "a,5,10", "chds" => "0,#{max_value}"}
    extra.update("chbh" => "r,5,10") if @data.flatten.size < 3
    if @show_marker
      if @data.first.is_a? Array
        extra.update("chm" => @data.size.times.map{|i| "N,000000,#{i},-1,11" }.join('|'))
      else
        extra.update("chm" => "N,000000,0,-1,11")
      end
    end
    g.extras = extra
  end
  chart.to_url
end

#max_valueObject



54
55
56
# File 'lib/report_engine/google_chart.rb', line 54

def max_value
  @data.flatten.max
end