Class: Gchart

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#grid_linesObject

Returns the value of attribute grid_lines.



4
5
6
# File 'lib/gchart_mod.rb', line 4

def grid_lines
  @grid_lines
end

#shape_markersObject

Returns the value of attribute shape_markers.



4
5
6
# File 'lib/gchart_mod.rb', line 4

def shape_markers
  @shape_markers
end

Instance Method Details

#query_builder(options = "") ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/gchart_mod.rb', line 50

def query_builder(options="")
  dataset 
  query_params = instance_variables.map do |var|
    case var
    when '@data'
      set_data unless @data == []  
    # Set the graph size  
    when '@width'
      set_size unless @width.nil? || @height.nil?
    when '@type'
      set_type
    when '@title'
      set_title unless @title.nil?
    when '@legend'
      set_legend unless @legend.nil?
    when '@bg_color'
      set_colors
    when '@chart_color'
      set_colors if @bg_color.nil?
    when '@bar_colors'
      set_bar_colors
    when '@bar_width_and_spacing'
      set_bar_width_and_spacing
    when '@axis_with_labels'
      set_axis_with_labels
    when '@axis_range'
      set_axis_range if dataset
    when '@axis_labels'
      set_axis_labels
    when '@range_markers'
      set_range_markers
    when '@geographical_area'
      set_geographical_area
    when '@country_codes'
      set_country_codes
    when '@grid_lines'
      set_grid_lines
    when '@shape_markers'
      set_shape_markers
    when '@custom'
      @custom
    end
  end.compact
  
  # Use ampersand as default delimiter
  unless options == :html
    delimiter = '&'
  # Escape ampersand for html image tags
  else
    delimiter = '&'
  end
  
  jstize(@@url + query_params.join(delimiter))
end

#set_grid_linesObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/gchart_mod.rb', line 30

def set_grid_lines
    grid_lines_values = case @grid_lines
    when String
        @grid_lines
    when Array
        @grid_lines.join(",")
    when Hash
        x_step = @grid_lines[:x_step]
        y_step = @grid_lines[:y_step]
        line_length = @grid_lines[:line_length]
        blank_length = @grid_lines[:blank_length]
        x_offset = @grid_lines[:x_offset]
        y_offset = @grid_lines[:y_offset]
        [x_step,y_step,line_length,blank_length,x_offset,y_offset].join(",")
    else
        @grid_lines.to_s
    end
    "chg=#{grid_lines_values}"
end

#set_shape_markersObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gchart_mod.rb', line 6

def set_shape_markers
    shape_markers_values = case @shape_markers
    when String
        @shape_markers
    when Array
        if @shape_markers[0].is_a?(Array)
            @shape_markers.map{|sm|sm.join(",")}.join("|")
        else
            @shape_markers.join("|")
        end
    when Hash
        marker_type = @shape_markers[:marker_type]
        color = @shape_markers[:color]
        data_set_index = @shape_markers[:data_set_index]
        data_point = @shape_markers[:data_point]
        size = @shape_markers[:size]
        priority = @shape_markers[:priority]
        [marker_type,color,data_set_index,data_point,size,priority].join(",")
    else
        @shape_makers.to_s
    end
    "chm=#{shape_markers_values}"
end