google_visualr 0.0.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +25 -0
- data/MIT-LICENSE +15 -14
- data/README.rdoc +59 -48
- data/Rakefile +9 -30
- data/google_visualr.gemspec +24 -0
- data/lib/google_visualr.rb +39 -0
- data/lib/google_visualr/base_chart.rb +40 -0
- data/lib/google_visualr/data_table.rb +277 -0
- data/lib/google_visualr/formatters.rb +78 -0
- data/lib/google_visualr/image/spark_line.rb +13 -0
- data/lib/google_visualr/interactive/annotated_time_line.rb +11 -0
- data/lib/google_visualr/interactive/area_chart.rb +13 -0
- data/lib/google_visualr/interactive/bar_chart.rb +13 -0
- data/lib/google_visualr/interactive/candlestick_chart.rb +13 -0
- data/lib/google_visualr/interactive/column_chart.rb +13 -0
- data/lib/google_visualr/interactive/combo_chart.rb +13 -0
- data/lib/google_visualr/interactive/gauge.rb +11 -0
- data/lib/google_visualr/interactive/geo_chart.rb +11 -0
- data/lib/google_visualr/interactive/intensity_map.rb +11 -0
- data/lib/google_visualr/interactive/line_chart.rb +13 -0
- data/lib/google_visualr/interactive/map.rb +11 -0
- data/lib/google_visualr/interactive/motion_chart.rb +11 -0
- data/lib/google_visualr/interactive/org_chart.rb +11 -0
- data/lib/google_visualr/interactive/pie_chart.rb +13 -0
- data/lib/google_visualr/interactive/scatter_chart.rb +13 -0
- data/lib/google_visualr/interactive/table.rb +11 -0
- data/lib/google_visualr/interactive/treemap.rb +11 -0
- data/lib/google_visualr/packages.rb +30 -0
- data/lib/google_visualr/param_helpers.rb +50 -0
- data/lib/google_visualr/version.rb +3 -0
- data/spec/google_visualr/base_chart_spec.rb +55 -0
- data/spec/google_visualr/data_table_spec.rb +251 -0
- data/spec/google_visualr/formatters_spec.rb +104 -0
- data/spec/spec_helper.rb +8 -0
- data/test/google_visualr_spec.rb +7 -0
- data/test/helper.rb +18 -0
- metadata +73 -36
- data/VERSION +0 -1
- data/init.rb +0 -17
- data/install.rb +0 -1
- data/lib/annotated_time_line.rb +0 -50
- data/lib/area_chart.rb +0 -54
- data/lib/bar_chart.rb +0 -53
- data/lib/base_chart.rb +0 -285
- data/lib/column_chart.rb +0 -53
- data/lib/formatters.rb +0 -184
- data/lib/gauge.rb +0 -36
- data/lib/geo_map.rb +0 -32
- data/lib/image_spark_line.rb +0 -36
- data/lib/intensity_map.rb +0 -29
- data/lib/line_chart.rb +0 -54
- data/lib/map.rb +0 -31
- data/lib/motion_chart.rb +0 -36
- data/lib/org_chart.rb +0 -29
- data/lib/pie_chart.rb +0 -44
- data/lib/scatter_chart.rb +0 -52
- data/lib/table.rb +0 -39
- data/uninstall.rb +0 -1
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.6
|
data/init.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/lib/base_chart'
|
2
|
-
require File.dirname(__FILE__) + '/lib/annotated_time_line'
|
3
|
-
require File.dirname(__FILE__) + '/lib/area_chart'
|
4
|
-
require File.dirname(__FILE__) + '/lib/bar_chart'
|
5
|
-
require File.dirname(__FILE__) + '/lib/column_chart'
|
6
|
-
require File.dirname(__FILE__) + '/lib/gauge'
|
7
|
-
require File.dirname(__FILE__) + '/lib/geo_map'
|
8
|
-
require File.dirname(__FILE__) + '/lib/image_spark_line'
|
9
|
-
require File.dirname(__FILE__) + '/lib/intensity_map'
|
10
|
-
require File.dirname(__FILE__) + '/lib/line_chart'
|
11
|
-
require File.dirname(__FILE__) + '/lib/map'
|
12
|
-
require File.dirname(__FILE__) + '/lib/motion_chart'
|
13
|
-
require File.dirname(__FILE__) + '/lib/org_chart'
|
14
|
-
require File.dirname(__FILE__) + '/lib/pie_chart'
|
15
|
-
require File.dirname(__FILE__) + '/lib/scatter_chart'
|
16
|
-
require File.dirname(__FILE__) + '/lib/table'
|
17
|
-
require File.dirname(__FILE__) + '/lib/formatters'
|
data/install.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
# Install Hook
|
data/lib/annotated_time_line.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
module GoogleVisualr
|
2
|
-
|
3
|
-
# http://code.google.com/apis/visualization/documentation/gallery/annotatedtimeline.html
|
4
|
-
class AnnotatedTimeLine < BaseChart
|
5
|
-
|
6
|
-
attr_accessor :element_id
|
7
|
-
|
8
|
-
# http://code.google.com/apis/visualization/documentation/gallery/annotatedtimeline.html#Configuration_Options
|
9
|
-
attr_accessor :allowHtml
|
10
|
-
attr_accessor :allowRedraw
|
11
|
-
attr_accessor :allValuesSuffix
|
12
|
-
attr_accessor :annotationsWidth
|
13
|
-
attr_accessor :colors
|
14
|
-
attr_accessor :dateFormat
|
15
|
-
attr_accessor :displayAnnotations
|
16
|
-
attr_accessor :displayAnnotationsFilter
|
17
|
-
attr_accessor :displayDateBarSeparator
|
18
|
-
attr_accessor :displayExactValues
|
19
|
-
attr_accessor :displayLegendDots
|
20
|
-
attr_accessor :displayLegendValues
|
21
|
-
attr_accessor :displayRangeSelector
|
22
|
-
attr_accessor :displayZoomButtons
|
23
|
-
attr_accessor :fill
|
24
|
-
attr_accessor :highlightDot
|
25
|
-
attr_accessor :legendPosition
|
26
|
-
attr_accessor :max
|
27
|
-
attr_accessor :min
|
28
|
-
attr_accessor :numberFormats
|
29
|
-
attr_accessor :scaleColumns
|
30
|
-
attr_accessor :scaleType
|
31
|
-
attr_accessor :thickness
|
32
|
-
attr_accessor :wmode
|
33
|
-
attr_accessor :zoomEndTime
|
34
|
-
attr_accessor :zoomStartTime
|
35
|
-
|
36
|
-
def render (element_id)
|
37
|
-
|
38
|
-
options = Hash.new
|
39
|
-
|
40
|
-
options[:package] = self.class.to_s.split('::').last
|
41
|
-
options[:element_id] = element_id
|
42
|
-
options[:chart_style] = collect_parameters
|
43
|
-
|
44
|
-
super(options)
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
data/lib/area_chart.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
module GoogleVisualr
|
2
|
-
|
3
|
-
# http://code.google.com/apis/visualization/documentation/gallery/areachart.html
|
4
|
-
class AreaChart < BaseChart
|
5
|
-
|
6
|
-
attr_accessor :element_id
|
7
|
-
|
8
|
-
# http://code.google.com/apis/visualization/documentation/gallery/areachart.html#Configuration_Options
|
9
|
-
attr_accessor :axisColor
|
10
|
-
attr_accessor :axisBackgroundColor
|
11
|
-
attr_accessor :axisFontSize
|
12
|
-
attr_accessor :backgroundColor
|
13
|
-
attr_accessor :borderColor
|
14
|
-
attr_accessor :colors
|
15
|
-
attr_accessor :enableTooltip
|
16
|
-
attr_accessor :focusBorderColor
|
17
|
-
attr_accessor :height
|
18
|
-
attr_accessor :isStacked
|
19
|
-
attr_accessor :legend
|
20
|
-
attr_accessor :legendBackgroundColor
|
21
|
-
attr_accessor :legendFontSize
|
22
|
-
attr_accessor :legendTextColor
|
23
|
-
attr_accessor :lineSize
|
24
|
-
attr_accessor :logScale
|
25
|
-
attr_accessor :max
|
26
|
-
attr_accessor :min
|
27
|
-
attr_accessor :pointSize
|
28
|
-
attr_accessor :reverseAxis
|
29
|
-
attr_accessor :showCategories
|
30
|
-
attr_accessor :title
|
31
|
-
attr_accessor :titleX
|
32
|
-
attr_accessor :titleY
|
33
|
-
attr_accessor :titleColor
|
34
|
-
attr_accessor :titleFontSize
|
35
|
-
attr_accessor :tooltipFontSize
|
36
|
-
attr_accessor :tooltipHeight
|
37
|
-
attr_accessor :tooltipWidth
|
38
|
-
attr_accessor :width
|
39
|
-
|
40
|
-
def render (element_id)
|
41
|
-
|
42
|
-
options = Hash.new
|
43
|
-
|
44
|
-
options[:package] = self.class.to_s.split('::').last
|
45
|
-
options[:element_id] = element_id
|
46
|
-
options[:chart_style] = collect_parameters
|
47
|
-
|
48
|
-
super(options)
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
data/lib/bar_chart.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
module GoogleVisualr
|
2
|
-
|
3
|
-
# http://code.google.com/apis/visualization/documentation/gallery/barchart.html
|
4
|
-
class BarChart < BaseChart
|
5
|
-
|
6
|
-
attr_accessor :element_id
|
7
|
-
|
8
|
-
# http://code.google.com/apis/visualization/documentation/gallery/barchart.html#Configuration_Options
|
9
|
-
attr_accessor :axisColor
|
10
|
-
attr_accessor :axisBackgroundColor
|
11
|
-
attr_accessor :axisFontSize
|
12
|
-
attr_accessor :backgroundColor
|
13
|
-
attr_accessor :borderColor
|
14
|
-
attr_accessor :colors
|
15
|
-
attr_accessor :enableTooltip
|
16
|
-
attr_accessor :focusBorderColor
|
17
|
-
attr_accessor :height
|
18
|
-
attr_accessor :is3D
|
19
|
-
attr_accessor :isStacked
|
20
|
-
attr_accessor :legend
|
21
|
-
attr_accessor :legendBackgroundColor
|
22
|
-
attr_accessor :legendFontSize
|
23
|
-
attr_accessor :legendTextColor
|
24
|
-
attr_accessor :logScale
|
25
|
-
attr_accessor :max
|
26
|
-
attr_accessor :min
|
27
|
-
attr_accessor :reverseAxis
|
28
|
-
attr_accessor :showCategories
|
29
|
-
attr_accessor :title
|
30
|
-
attr_accessor :titleX
|
31
|
-
attr_accessor :titleY
|
32
|
-
attr_accessor :titleColor
|
33
|
-
attr_accessor :titleFontSize
|
34
|
-
attr_accessor :tooltipFontSize
|
35
|
-
attr_accessor :tooltipHeight
|
36
|
-
attr_accessor :tooltipWidth
|
37
|
-
attr_accessor :width
|
38
|
-
|
39
|
-
def render (element_id)
|
40
|
-
|
41
|
-
options = Hash.new
|
42
|
-
|
43
|
-
options[:package] = self.class.to_s.split('::').last
|
44
|
-
options[:element_id] = element_id
|
45
|
-
options[:chart_style] = collect_parameters
|
46
|
-
|
47
|
-
super(options)
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
data/lib/base_chart.rb
DELETED
@@ -1,285 +0,0 @@
|
|
1
|
-
module GoogleVisualr
|
2
|
-
|
3
|
-
class BaseChart
|
4
|
-
|
5
|
-
attr_accessor :chart_data
|
6
|
-
attr_accessor :formatters
|
7
|
-
|
8
|
-
##############################
|
9
|
-
# Constructors
|
10
|
-
##############################
|
11
|
-
#
|
12
|
-
# GoogleVisualr::visualization.new:
|
13
|
-
# Creates an empty visualization instance. Use add_columns, add_rows and set_value or set_cell methods to populate the visualization.
|
14
|
-
#
|
15
|
-
# GoogleVisualr::visualization.new(data object):
|
16
|
-
# reates a visualization by passing a JavaScript-string-literal like data object into the data parameter. This object can contain formatting options.
|
17
|
-
#
|
18
|
-
##############################
|
19
|
-
# Syntax Description of Data Object
|
20
|
-
##############################
|
21
|
-
#
|
22
|
-
# The data object consists of two required top-level properties, cols and rows.
|
23
|
-
#
|
24
|
-
# * cols property
|
25
|
-
#
|
26
|
-
# cols is an array of objects describing the ID and type of each column. Each property is an object with the following properties (case-sensitive):
|
27
|
-
#
|
28
|
-
# * type [Required] The data type of the data in the column. Supports the following string values:
|
29
|
-
# - 'string' : String value. Example values: v:'foo', :v:'bar'
|
30
|
-
# - 'number' : Number value. Example values: v:7, v:3.14, v:-55
|
31
|
-
# - 'boolean' : Boolean value ('true' or 'false'). Example values: v:true, v:false
|
32
|
-
# - 'date' : Date object, with the time truncated. Example value: v:Date.parse('2010-01-01')
|
33
|
-
# - 'datetime' : DateTime/Time object, time inclusive. Example value: v:DateTime.parse('2010-01-01 14:20:25')
|
34
|
-
# - 'timeofday' : Array of 3 numbers or 4 numbers, [Hour,Minute,Second,(Optional) Milliseconds]. Example value: v:[8, 15, 0]
|
35
|
-
# * label [Optional] A string value that some visualizations display for this column. Example: label:'Height'
|
36
|
-
# * id [Optional] A unique (basic alphanumeric) string ID of the column. Be careful not to choose a JavaScript keyword. Example: id:'col_1'
|
37
|
-
#
|
38
|
-
# * rows property
|
39
|
-
#
|
40
|
-
# The rows property holds an array of row objects. Each row object has one required property called c, which is an array of cells in that row.
|
41
|
-
#
|
42
|
-
# Each cell in the table is described by an object with the following properties:
|
43
|
-
#
|
44
|
-
# * v [Optional] The cell value. The data type should match the column data type.
|
45
|
-
# * f [Optional] A string version of the v value, formatted strictly for display only. If omitted, a string version of v will be used.
|
46
|
-
#
|
47
|
-
# Cells in the row array should be in the same order as their column descriptions in cols.
|
48
|
-
#
|
49
|
-
# To indicate a null cell, you can either specify null, or set empty string for a cell in an array, or omit trailing array members.
|
50
|
-
# So, to indicate a row with null for the first two cells, you could specify [ '', '', {cell_val}] or [null, null, {cell_val}].
|
51
|
-
def initialize(options={})
|
52
|
-
|
53
|
-
@chart_data = "var chart_data = new google.visualization.DataTable();"
|
54
|
-
|
55
|
-
if !options.empty?
|
56
|
-
|
57
|
-
cols = options[:cols]
|
58
|
-
add_columns(cols)
|
59
|
-
|
60
|
-
rows = options[:rows]
|
61
|
-
rows.each do |row|
|
62
|
-
add_row(row[:c])
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
68
|
-
|
69
|
-
# Adds a new column to the visualization.
|
70
|
-
#
|
71
|
-
# Parameters:
|
72
|
-
# * type [Required] The data type of the data in the column. Supports the following string values:
|
73
|
-
# - 'string' : String value. Example values: v:'hello'
|
74
|
-
# - 'number' : Number value. Example values: v:7 , v:3.14, v:-55
|
75
|
-
# - 'date' : Date object, with the time truncated. Example values: v:Date.parse('2010-01-01')
|
76
|
-
# - 'datetime' : Date object including the time. Example values: v:Date.parse('2010-01-01 14:20:25')
|
77
|
-
# - 'boolean' : Boolean value ('true' or 'false'). Example values: v: true
|
78
|
-
# * label [Optional] A string value that some visualizations display for this column. Example: label:'Height'
|
79
|
-
# * id [Optional] A unique (basic alphanumeric) string ID of the column. Be careful not to choose a JavaScript keyword. Example: id:'col_1'
|
80
|
-
def add_column (type, label="", id="")
|
81
|
-
@chart_data << "chart_data.addColumn('#{type}', '#{label}', '#{id}');"
|
82
|
-
end
|
83
|
-
|
84
|
-
# Adds multiple columns to the visualization.
|
85
|
-
#
|
86
|
-
# Parameters:
|
87
|
-
# * columns [Required] An array of column objects {:type, :label, :id}. Calls add_column for each column object.
|
88
|
-
def add_columns(columns)
|
89
|
-
|
90
|
-
columns.each do |column|
|
91
|
-
add_column(column[:type], column[:label], column[:id])
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|
95
|
-
|
96
|
-
# Adds a new row to the visualization.
|
97
|
-
# Call method without any parameters to add an empty row, otherwise, call method with a row object.
|
98
|
-
#
|
99
|
-
# Parameters:
|
100
|
-
# * row [Optional] An array of cell values specifying the data for the new row.
|
101
|
-
# - You can specify a value for a cell (e.g. 'hi') or specify a formatted value using cell objects (e.g. {v:55, f:'Fifty-five'}) as described in the constructor section.
|
102
|
-
# - You can mix simple values and cell objects in the same method call.
|
103
|
-
# - To create an empty cell, use nil or empty string.
|
104
|
-
def add_row(row)
|
105
|
-
|
106
|
-
if row.empty?
|
107
|
-
@chart_data << "chart_data.addRow();" # Empty Row
|
108
|
-
else
|
109
|
-
|
110
|
-
attributes = Array.new
|
111
|
-
row.each do |cell|
|
112
|
-
attributes << add_row_cell(cell)
|
113
|
-
end
|
114
|
-
|
115
|
-
@chart_data << "chart_data.addRow( [" + attributes.join(",") + "] );"
|
116
|
-
|
117
|
-
end
|
118
|
-
|
119
|
-
end
|
120
|
-
|
121
|
-
# Adds multiple rows to the visualization. You can call this method with data to populate a set of new rows or create new empty rows.
|
122
|
-
#
|
123
|
-
# Parameters:
|
124
|
-
# * array_or_num [Required] Either an array or a number.
|
125
|
-
# - Array: An array of row objects used to populate a set of new rows. Each row is an object as described in add_row().
|
126
|
-
# - Number: A number specifying the number of new empty rows to create.
|
127
|
-
def add_rows(array_or_num)
|
128
|
-
|
129
|
-
if array_or_num.is_a?(Array)
|
130
|
-
array_or_num.each do |row|
|
131
|
-
add_row(row)
|
132
|
-
end
|
133
|
-
else
|
134
|
-
@chart_data << "chart_data.addRows(#{array_or_num});"
|
135
|
-
end
|
136
|
-
|
137
|
-
end
|
138
|
-
|
139
|
-
# Sets the value and/or formatted value of a cell.
|
140
|
-
#
|
141
|
-
# Parameters:
|
142
|
-
# * row_index [Required] A number greater than or equal to zero, but smaller than the total number of rows.
|
143
|
-
# * column_index [Required] A number greater than or equal to zero, but smaller than the total number of columns.
|
144
|
-
# * value [Required] The cell value. The data type should match the column data type.
|
145
|
-
# * formatted_value [Optional] A string version of value, formatted strictly for display only. If omitted, a string version of value will be used.
|
146
|
-
def set_cell (row_index, column_index, value, formatted_value=nil, properties=nil)
|
147
|
-
|
148
|
-
@chart_data << "chart_data.setCell("
|
149
|
-
@chart_data << "#{row_index}, #{column_index}, #{typecast(value)}"
|
150
|
-
@chart_data << ", '#{formatted_value}'" unless formatted_value.blank?
|
151
|
-
@chart_data << ", '#{properties}'" unless properties.blank?
|
152
|
-
@chart_data << ");"
|
153
|
-
|
154
|
-
end
|
155
|
-
|
156
|
-
# Sets the value of a cell. Overwrites any existing cell value, and clear out any formatted value for the cell.
|
157
|
-
#
|
158
|
-
# Parameters:
|
159
|
-
# * row_index [Required] A number greater than or equal to zero, but smaller than the total number of rows.
|
160
|
-
# * column_index [Required] A number greater than or equal to zero, but smaller than the total number of columns.
|
161
|
-
# * value [Required] The cell value. The data type should match the column data type.
|
162
|
-
def set_value (row_index, column_index, value)
|
163
|
-
|
164
|
-
@chart_data << "chart_data.setCell(#{row_index}, #{column_index}, #{typecast(value)});"
|
165
|
-
|
166
|
-
end
|
167
|
-
|
168
|
-
# Applies one or more formatters to the visualization to format the columns as specified by the formatter/s.
|
169
|
-
#
|
170
|
-
# Parameters:
|
171
|
-
# * formatter/s [Required] One, or an array of formatters.
|
172
|
-
def format(*formatters)
|
173
|
-
|
174
|
-
@formatters ||= Array.new
|
175
|
-
@formatters += formatters
|
176
|
-
|
177
|
-
end
|
178
|
-
|
179
|
-
# Sets chart configuration options with a hash.
|
180
|
-
#
|
181
|
-
# Parameters:
|
182
|
-
# *options [Required] A hash of configuration options.
|
183
|
-
def set_options(options)
|
184
|
-
|
185
|
-
options.each_pair do | key, value |
|
186
|
-
send "#{key}=", value
|
187
|
-
end
|
188
|
-
|
189
|
-
end
|
190
|
-
|
191
|
-
# Generates JavaScript and renders the visualization in the final HTML output.
|
192
|
-
#
|
193
|
-
# Parameters:
|
194
|
-
# *div_id [Required] The ID of the DIV element that the visualization should be rendered in.
|
195
|
-
#
|
196
|
-
# Note: This is the super method.
|
197
|
-
def render(options)
|
198
|
-
|
199
|
-
script = "\n<script type='text/javascript'>"
|
200
|
-
script << "\n google.load('visualization','1', {packages: ['#{options[:package].downcase}'], callback: function() {"
|
201
|
-
script << "\n #{@chart_data}"
|
202
|
-
if @formatters
|
203
|
-
@formatters.each do |formatter|
|
204
|
-
script << formatter.script
|
205
|
-
end
|
206
|
-
end
|
207
|
-
script << "\n var chart = new google.visualization.#{options[:package]}(document.getElementById('#{options[:element_id]}'));"
|
208
|
-
script << "\n chart.draw(chart_data, #{options[:chart_style]});"
|
209
|
-
script << "\n }});"
|
210
|
-
script << "\n</script>"
|
211
|
-
|
212
|
-
return script
|
213
|
-
|
214
|
-
end
|
215
|
-
|
216
|
-
private
|
217
|
-
|
218
|
-
def add_row_cell(cell)
|
219
|
-
|
220
|
-
if cell.is_a?(Hash)
|
221
|
-
|
222
|
-
attributes = Array.new
|
223
|
-
cell.each_pair do |key, value|
|
224
|
-
attributes << "#{key}: #{typecast(value)}"
|
225
|
-
end
|
226
|
-
|
227
|
-
return "{" + attributes.join(",") + "}"
|
228
|
-
|
229
|
-
else
|
230
|
-
return "#{typecast(cell)}"
|
231
|
-
end
|
232
|
-
|
233
|
-
end
|
234
|
-
|
235
|
-
# If the column type is 'string' , the value should be a string.
|
236
|
-
# If the column type is 'number' , the value should be a number.
|
237
|
-
# If the column type is 'boolean' , the value should be a boolean.
|
238
|
-
# If the column type is 'date' , the value should be a Date object.
|
239
|
-
# If the column type is 'datetime' , the value should be a DateTime or Time object.
|
240
|
-
# If the column type is 'timeofday' , the value should be an array of three or four numbers: [hour, minute, second, optional milliseconds].
|
241
|
-
def typecast(value)
|
242
|
-
|
243
|
-
case
|
244
|
-
when value.is_a?(String)
|
245
|
-
return "'#{escape_single_quotes(value)}'"
|
246
|
-
when value.is_a?(Integer) || value.is_a?(Float)
|
247
|
-
return value
|
248
|
-
when value.is_a?(TrueClass) || value.is_a?(FalseClass)
|
249
|
-
return "#{value}"
|
250
|
-
when value.is_a?(Date)
|
251
|
-
return "new Date(#{value.year}, #{value.month-1}, #{value.day})"
|
252
|
-
when value.is_a?(DateTime) || value.is_a?(Time)
|
253
|
-
return "new Date(#{value.year}, #{value.month-1}, #{value.day}, #{value.hour}, #{value.min}, #{value.sec})"
|
254
|
-
when value.is_a?(Array)
|
255
|
-
return "[" + value.collect { |item| typecast(item) }.join(",") + "]"
|
256
|
-
else
|
257
|
-
return value
|
258
|
-
end
|
259
|
-
|
260
|
-
end
|
261
|
-
|
262
|
-
def collect_parameters
|
263
|
-
|
264
|
-
attributes = Array.new
|
265
|
-
instance_variable_names.each do |instance_variable|
|
266
|
-
next if instance_variable == "@chart_data" || instance_variable == "@formatters"
|
267
|
-
key = instance_variable.gsub("@", "")
|
268
|
-
value = instance_variable_get(instance_variable)
|
269
|
-
attribute = "#{key}:#{typecast(value)}"
|
270
|
-
attributes << attribute
|
271
|
-
end
|
272
|
-
|
273
|
-
return "{" + attributes.join(",") + "}"
|
274
|
-
|
275
|
-
end
|
276
|
-
|
277
|
-
def escape_single_quotes(str)
|
278
|
-
|
279
|
-
str.gsub(/[']/, '\\\\\'')
|
280
|
-
|
281
|
-
end
|
282
|
-
|
283
|
-
end
|
284
|
-
|
285
|
-
end
|