analytica 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/analytica.rb +40 -2
- data/lib/visualization.rb +268 -54
- metadata +4 -4
data/lib/analytica.rb
CHANGED
@@ -4,17 +4,27 @@ require File.join(File.dirname(__FILE__), 'computation')
|
|
4
4
|
require File.join(File.dirname(__FILE__), 'visualization')
|
5
5
|
|
6
6
|
module Analytica
|
7
|
-
VERSION = '0.0.
|
7
|
+
VERSION = '0.0.8'
|
8
8
|
|
9
9
|
include Strict
|
10
10
|
|
11
|
+
dataset_array_handler = proc do |data, context|
|
12
|
+
enforce_primitive!(Array, data, context)
|
13
|
+
data.each {|item| enforce_primitive!(DataSet, item, context)}
|
14
|
+
end
|
15
|
+
|
16
|
+
register_supertype(:dataset_array, dataset_array_handler)
|
17
|
+
|
11
18
|
class DataSet < Array
|
12
19
|
include Analytica::Computation
|
13
|
-
include Analytica::Visualization
|
20
|
+
include Analytica::Visualization::DataSet
|
14
21
|
|
15
22
|
def initialize(datapoints=[])
|
16
23
|
enforce!(:numeric_array, datapoints)
|
17
24
|
|
25
|
+
@labels = []
|
26
|
+
@labels_set = false
|
27
|
+
|
18
28
|
super datapoints
|
19
29
|
end
|
20
30
|
|
@@ -33,4 +43,32 @@ module Analytica
|
|
33
43
|
super other
|
34
44
|
end
|
35
45
|
end
|
46
|
+
|
47
|
+
class DataSystem < Array
|
48
|
+
include Analytica::Visualization::DataSystem
|
49
|
+
|
50
|
+
def initialize(datasets=[])
|
51
|
+
enforce!(:dataset_array, datasets)
|
52
|
+
|
53
|
+
super datasets
|
54
|
+
end
|
55
|
+
|
56
|
+
def <<(object)
|
57
|
+
enforce_primitive!(DataSet, object)
|
58
|
+
|
59
|
+
super object
|
60
|
+
end
|
61
|
+
|
62
|
+
def concat(other)
|
63
|
+
enforce!(:dataset_array, other)
|
64
|
+
|
65
|
+
super datasets
|
66
|
+
end
|
67
|
+
|
68
|
+
def +(other)
|
69
|
+
enforce!(:dataset_array, other)
|
70
|
+
|
71
|
+
super other
|
72
|
+
end
|
73
|
+
end
|
36
74
|
end
|
data/lib/visualization.rb
CHANGED
@@ -1,67 +1,281 @@
|
|
1
1
|
require 'typestrict'
|
2
|
-
require '
|
3
|
-
|
4
|
-
class GChart::Base
|
5
|
-
def to_html
|
6
|
-
"<img src=\"#{self.to_url}\" />"
|
7
|
-
end
|
8
|
-
end
|
2
|
+
require 'googlecharts'
|
9
3
|
|
10
4
|
module Analytica
|
11
5
|
module Visualization
|
12
|
-
|
6
|
+
def default_bar_settings
|
7
|
+
{:width => 25, :spacing => 10, :group_spacing => 12}
|
8
|
+
end
|
13
9
|
|
14
|
-
|
15
|
-
|
10
|
+
module DataSet
|
11
|
+
include Strict
|
16
12
|
|
17
|
-
|
18
|
-
|
13
|
+
def set_labels(labels)
|
14
|
+
enforce!(:string_array, labels)
|
15
|
+
|
16
|
+
@labels = labels
|
17
|
+
@labels_set = true
|
18
|
+
end
|
19
|
+
|
20
|
+
def datamax
|
21
|
+
(max > 0) ? (1.25*max) : 1
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_linegraph(params)
|
25
|
+
enforce_map!({
|
26
|
+
:width => :natural_number,
|
27
|
+
:height => :natural_number,
|
28
|
+
:background_color => :hex_color,
|
29
|
+
:color => :hex_color}, params)
|
30
|
+
|
31
|
+
params[:title] = '' unless params.has_key? :title
|
32
|
+
params[:title_size] = 12 unless params.has_key? :title_size
|
33
|
+
params[:title_color] = '000000' unless params.has_key? :title_color
|
34
|
+
|
35
|
+
|
36
|
+
options = {}
|
37
|
+
|
38
|
+
base = {
|
39
|
+
:data => self,
|
40
|
+
:max_value => datamax,
|
41
|
+
:size => "#{params[:width]}x#{params[:height]}",
|
42
|
+
:format => 'image_tag'
|
43
|
+
}
|
44
|
+
|
45
|
+
options.merge!(base)
|
46
|
+
|
47
|
+
title = {
|
48
|
+
:title => params[:title],
|
49
|
+
:title_color => params[:title_color],
|
50
|
+
:title_size => params[:title_size]
|
51
|
+
}
|
52
|
+
|
53
|
+
#options.merge!(title)
|
54
|
+
|
55
|
+
color = {
|
56
|
+
:line_colors => params[:color],
|
57
|
+
:background => params[:background_color],
|
58
|
+
:chart_background => params[:background_color]
|
59
|
+
}
|
60
|
+
|
61
|
+
options.merge!(color)
|
62
|
+
|
63
|
+
label = {
|
64
|
+
:legend => ['x', 'y'], # TODO number of datasets
|
65
|
+
:axis_with_labels => ['x','r'], #TODO number of datasets
|
66
|
+
:axis_labels => [[],[]] # TODO
|
67
|
+
}
|
68
|
+
|
69
|
+
|
70
|
+
#options.merge!(label)
|
71
|
+
|
72
|
+
Gchart.line(options)
|
73
|
+
end
|
74
|
+
|
75
|
+
def to_sparkline(params)
|
76
|
+
enforce_map!({
|
77
|
+
:width => :natural_number,
|
78
|
+
:height => :natural_number,
|
79
|
+
:background_color => :hex_color,
|
80
|
+
:color => :hex_color}, params)
|
81
|
+
|
82
|
+
params[:title] = '' unless params.has_key? :title
|
83
|
+
params[:title_size] = 12 unless params.has_key? :title_size
|
84
|
+
params[:title_color] = '000000' unless params.has_key? :title_color
|
85
|
+
|
86
|
+
|
87
|
+
options = {}
|
88
|
+
|
89
|
+
base = {
|
90
|
+
:data => self,
|
91
|
+
:max_value => datamax,
|
92
|
+
:size => "#{params[:width]}x#{params[:height]}",
|
93
|
+
:format => 'image_tag'
|
94
|
+
}
|
95
|
+
|
96
|
+
options.merge!(base)
|
97
|
+
|
98
|
+
title = {
|
99
|
+
:title => params[:title],
|
100
|
+
:title_color => params[:title_color],
|
101
|
+
:title_size => params[:title_size]
|
102
|
+
}
|
103
|
+
|
104
|
+
#options.merge!(title)
|
105
|
+
|
106
|
+
color = {
|
107
|
+
:line_colors => params[:color],
|
108
|
+
:background => params[:background_color],
|
109
|
+
:chart_background => params[:background_color]
|
110
|
+
}
|
111
|
+
|
112
|
+
options.merge!(color)
|
113
|
+
|
114
|
+
label = {
|
115
|
+
:legend => ['x', 'y'], # TODO number of datasets
|
116
|
+
:axis_with_labels => ['x','r'], #TODO number of datasets
|
117
|
+
:axis_labels => [[],[]] # TODO
|
118
|
+
}
|
119
|
+
|
120
|
+
#options.merge!(label)
|
121
|
+
|
122
|
+
Gchart.sparkline(options)
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
def to_bargraph(params)
|
127
|
+
enforce_map!({
|
128
|
+
:width => :natural_number,
|
129
|
+
:height => :natural_number,
|
130
|
+
:orientation => [:vertical, :horizontal],
|
131
|
+
:background_color => :hex_color,
|
132
|
+
:color => :hex_color}, params)
|
133
|
+
|
134
|
+
options = {}
|
135
|
+
|
136
|
+
base = {
|
137
|
+
:data => self,
|
138
|
+
:max_value => datamax,
|
139
|
+
:size => "#{params[:width]}x#{params[:height]}",
|
140
|
+
:orientation => params[:orientation].to_s,
|
141
|
+
:stacked => params[:stacked],
|
142
|
+
:bar_width_and_spacing => Analytica::Visualization::default_bar_settings,
|
143
|
+
:format => 'image_tag'
|
144
|
+
}
|
145
|
+
|
146
|
+
options.merge!(base)
|
147
|
+
|
148
|
+
title = {
|
149
|
+
:title => params[:title],
|
150
|
+
:title_color => params[:title_color],
|
151
|
+
:title_size => params[:title_size]
|
152
|
+
}
|
153
|
+
|
154
|
+
#options.merge!(title)
|
155
|
+
|
156
|
+
color = {
|
157
|
+
:bar_colors => params[:color],
|
158
|
+
:background => params[:background_color],
|
159
|
+
:chart_background => params[:background_color]
|
160
|
+
}
|
161
|
+
|
162
|
+
options.merge!(color)
|
163
|
+
|
164
|
+
label = {
|
165
|
+
:legend => ['x', 'y'], # TODO number of datasets
|
166
|
+
:axis_with_labels => ['x','r'], #TODO number of datasets
|
167
|
+
:axis_labels => [[],[]] # TODO
|
168
|
+
}
|
169
|
+
|
170
|
+
#options.merge!(label)
|
19
171
|
|
20
|
-
def datamax
|
21
|
-
(max > 0) ? max : 1
|
22
|
-
end
|
23
172
|
|
24
|
-
|
25
|
-
|
26
|
-
:width => :natural_number,
|
27
|
-
:height => :natural_number,
|
28
|
-
:background_color => :hex_color,
|
29
|
-
:color => :hex_color}, params)
|
30
|
-
|
31
|
-
GChart.line do |g|
|
32
|
-
g.data = self
|
33
|
-
g.extras = {
|
34
|
-
'chm' => 'N*cUSD0*,000000,0,-1,11',
|
35
|
-
'chbh' => '18,38',
|
36
|
-
'chds' => "0,#{datamax}"
|
37
|
-
}
|
38
|
-
g.size = "#{(params[:width]).to_i}x#{(params[:height]).to_i}"
|
39
|
-
g.entire_background = params[:background_color].to_s
|
40
|
-
g.colors = params[:color].to_s
|
41
|
-
g.axis(:bottom) {|a| a.labels = @labels}
|
42
|
-
end
|
173
|
+
return Gchart.bar(options)
|
174
|
+
end
|
43
175
|
end
|
44
176
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
177
|
+
module DataSystem
|
178
|
+
def datamax
|
179
|
+
(self.map{|dset| dset.datamax}).max
|
180
|
+
end
|
181
|
+
|
182
|
+
def to_linegraph(params)
|
183
|
+
enforce_map!({
|
184
|
+
:width => :natural_number,
|
185
|
+
:height => :natural_number,
|
186
|
+
:background_color => :hex_color,
|
187
|
+
:colors => :hex_color_array}, params)
|
188
|
+
|
189
|
+
params[:title] = '' unless params.has_key? :title
|
190
|
+
params[:title_size] = 12 unless params.has_key? :title_size
|
191
|
+
params[:title_color] = '000000' unless params.has_key? :title_color
|
192
|
+
|
193
|
+
|
194
|
+
options = {}
|
195
|
+
|
196
|
+
base = {
|
197
|
+
:data => self,
|
198
|
+
:max_value => datamax,
|
199
|
+
:size => "#{params[:width]}x#{params[:height]}",
|
200
|
+
:format => 'image_tag'
|
201
|
+
}
|
202
|
+
|
203
|
+
options.merge!(base)
|
204
|
+
|
205
|
+
title = {
|
206
|
+
:title => params[:title],
|
207
|
+
:title_color => params[:title_color],
|
208
|
+
:title_size => params[:title_size]
|
209
|
+
}
|
210
|
+
|
211
|
+
#options.merge!(title)
|
212
|
+
|
213
|
+
color = {
|
214
|
+
:line_colors => params[:colors],
|
215
|
+
:background => params[:background_color],
|
216
|
+
:chart_background => params[:background_color]
|
217
|
+
}
|
218
|
+
|
219
|
+
options.merge!(color)
|
220
|
+
|
221
|
+
label = {
|
222
|
+
:legend => ['x', 'y'], # TODO number of datasets
|
223
|
+
:axis_with_labels => ['x','r'], #TODO number of datasets
|
224
|
+
:axis_labels => [[],[]] # TODO
|
225
|
+
}
|
226
|
+
|
227
|
+
Gchart.line(options)
|
228
|
+
end
|
229
|
+
|
230
|
+
def to_bargraph(params)
|
231
|
+
enforce_map!({
|
232
|
+
:width => :natural_number,
|
233
|
+
:height => :natural_number,
|
234
|
+
:orientation => [:vertical, :horizontal],
|
235
|
+
:stacked => :boolean,
|
236
|
+
:background_color => :hex_color,
|
237
|
+
:colors => :hex_color_array}, params)
|
238
|
+
|
239
|
+
options = {}
|
240
|
+
|
241
|
+
base = {
|
242
|
+
:data => self,
|
243
|
+
:max_value => datamax,
|
244
|
+
:size => "#{params[:width]}x#{params[:height]}",
|
245
|
+
:orientation => params[:orientation].to_s,
|
246
|
+
:stacked => params[:stacked],
|
247
|
+
:bar_width_and_spacing => Analytica::Visualization::default_bar_settings,
|
248
|
+
:format => 'image_tag'
|
249
|
+
}
|
250
|
+
|
251
|
+
options.merge!(base)
|
252
|
+
|
253
|
+
title = {
|
254
|
+
:title => params[:title],
|
255
|
+
:title_color => params[:title_color],
|
256
|
+
:title_size => params[:title_size]
|
257
|
+
}
|
258
|
+
|
259
|
+
#options.merge!(title)
|
260
|
+
|
261
|
+
color = {
|
262
|
+
:bar_colors => params[:colors],
|
263
|
+
:background => params[:background_color],
|
264
|
+
:chart_background => params[:background_color]
|
265
|
+
}
|
266
|
+
|
267
|
+
options.merge!(color)
|
268
|
+
|
269
|
+
label = {
|
270
|
+
:legend => ['x', 'y'], # TODO number of datasets
|
271
|
+
:axis_with_labels => ['x','r'], #TODO number of datasets
|
272
|
+
:axis_labels => [[],[]] # TODO
|
273
|
+
}
|
274
|
+
|
275
|
+
#options.merge!(label)
|
276
|
+
|
277
|
+
|
278
|
+
return Gchart.bar(options)
|
65
279
|
end
|
66
280
|
end
|
67
281
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: analytica
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 8
|
10
|
+
version: 0.0.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Raeez Lorgat
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-12 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|