analytica 0.0.14 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/analytica.rb +1 -1
- data/lib/visualization.rb +93 -19
- data/test/test_analytica.rb +2 -1
- metadata +4 -4
data/lib/analytica.rb
CHANGED
data/lib/visualization.rb
CHANGED
@@ -3,10 +3,6 @@ require 'typestrict'
|
|
3
3
|
|
4
4
|
module Analytica
|
5
5
|
module Visualization
|
6
|
-
def self.default_bar_settings
|
7
|
-
{:width => 25, :spacing => 10, :group_spacing => 12}
|
8
|
-
end
|
9
|
-
|
10
6
|
module Common
|
11
7
|
def set_title(params)
|
12
8
|
enforce_map!({
|
@@ -48,21 +44,38 @@ module Analytica
|
|
48
44
|
@labels_set = true
|
49
45
|
end
|
50
46
|
|
47
|
+
def bar_settings(bar_settings)
|
48
|
+
enforce_map_optional!({
|
49
|
+
:width => :natural_number,
|
50
|
+
:spacing => :natural_number,
|
51
|
+
:group_spacing => :natural_number}, bar_settings)
|
52
|
+
bar_settings
|
53
|
+
end
|
54
|
+
|
51
55
|
def datamax
|
52
56
|
(max > 0) ? (1.25*max) : 1
|
53
57
|
end
|
54
58
|
|
55
59
|
def to_linegraph(params={})
|
60
|
+
enforce_map_defaults!({
|
61
|
+
:title => ' ',
|
62
|
+
:title_size => 12,
|
63
|
+
:title_color => '000000',
|
64
|
+
:color => 'ffffff',
|
65
|
+
:background_color => '000000',
|
66
|
+
:width => 600,
|
67
|
+
:height => 280,
|
68
|
+
:bar_settings => {}}, params)
|
69
|
+
|
56
70
|
enforce_map!({
|
71
|
+
:title => :string,
|
72
|
+
:title_size => :natural_number,
|
73
|
+
:title_color => :hex_color,
|
57
74
|
:width => :natural_number,
|
58
75
|
:height => :natural_number,
|
59
76
|
:background_color => :hex_color,
|
60
77
|
:color => :hex_color}, params)
|
61
78
|
|
62
|
-
params[:title] = '' unless params.has_key? :title
|
63
|
-
params[:title_size] = 12 unless params.has_key? :title_size
|
64
|
-
params[:title_color] = '000000' unless params.has_key? :title_color
|
65
|
-
|
66
79
|
|
67
80
|
options = {}
|
68
81
|
|
@@ -89,7 +102,20 @@ module Analytica
|
|
89
102
|
end
|
90
103
|
|
91
104
|
def to_sparkline(params={})
|
105
|
+
enforce_map_defaults!({
|
106
|
+
:title => ' ',
|
107
|
+
:title_size => 12,
|
108
|
+
:title_color => '000000',
|
109
|
+
:color => '0000ff',
|
110
|
+
:background_color => 'ffffff',
|
111
|
+
:width => 600,
|
112
|
+
:height => 280,
|
113
|
+
:bar_settings => {}}, params)
|
114
|
+
|
92
115
|
enforce_map!({
|
116
|
+
:title => :string,
|
117
|
+
:title_size => :natural_number,
|
118
|
+
:title_color => :hex_color,
|
93
119
|
:width => :natural_number,
|
94
120
|
:height => :natural_number,
|
95
121
|
:background_color => :hex_color,
|
@@ -126,12 +152,29 @@ module Analytica
|
|
126
152
|
|
127
153
|
|
128
154
|
def to_bargraph(params={})
|
155
|
+
enforce_map_defaults!({
|
156
|
+
:title => ' ',
|
157
|
+
:title_size => 12,
|
158
|
+
:title_color => '000000',
|
159
|
+
:orientation => :vertical,
|
160
|
+
:color => 'ffffff',
|
161
|
+
:background_color => '000000',
|
162
|
+
:stacked => false,
|
163
|
+
:width => 600,
|
164
|
+
:height => 280,
|
165
|
+
:bar_settings => {}}, params)
|
166
|
+
|
129
167
|
enforce_map!({
|
168
|
+
:title => :string,
|
169
|
+
:title_size => :natural_number,
|
170
|
+
:title_color => :hex_color,
|
130
171
|
:width => :natural_number,
|
131
172
|
:height => :natural_number,
|
132
173
|
:orientation => [:vertical, :horizontal],
|
174
|
+
:stacked => :boolean,
|
133
175
|
:background_color => :hex_color,
|
134
|
-
:color => :hex_color
|
176
|
+
:color => :hex_color,
|
177
|
+
:bar_settings => :hash_map}, params)
|
135
178
|
|
136
179
|
options = {}
|
137
180
|
|
@@ -141,7 +184,7 @@ module Analytica
|
|
141
184
|
:size => "#{params[:width]}x#{params[:height]}",
|
142
185
|
:orientation => params[:orientation].to_s,
|
143
186
|
:stacked => params[:stacked],
|
144
|
-
:bar_width_and_spacing =>
|
187
|
+
:bar_width_and_spacing => bar_settings(params[:bar_settings]),
|
145
188
|
:format => 'image_tag'
|
146
189
|
}
|
147
190
|
|
@@ -156,13 +199,21 @@ module Analytica
|
|
156
199
|
options.merge!(color)
|
157
200
|
|
158
201
|
options.merge!(common_options)
|
159
|
-
|
202
|
+
|
160
203
|
return Gchart.bar(options)
|
161
204
|
end
|
162
205
|
end
|
163
206
|
|
164
207
|
module DataSystem
|
165
208
|
|
209
|
+
def bar_settings(bar_settings)
|
210
|
+
enforce_map_optional!({
|
211
|
+
:width => :natural_number,
|
212
|
+
:spacing => :natural_number,
|
213
|
+
:group_spacing => :natural_number}, bar_settings)
|
214
|
+
bar_settings
|
215
|
+
end
|
216
|
+
|
166
217
|
def set_labels(labels)
|
167
218
|
enforce!(:string_array, labels)
|
168
219
|
|
@@ -175,16 +226,24 @@ module Analytica
|
|
175
226
|
end
|
176
227
|
|
177
228
|
def to_linegraph(params={})
|
229
|
+
enforce_map_defaults!({
|
230
|
+
:title => ' ',
|
231
|
+
:title_size => 12,
|
232
|
+
:title_color => '000000',
|
233
|
+
:color => 'ffffff',
|
234
|
+
:width => 600,
|
235
|
+
:height => 280,
|
236
|
+
:background_color => '000000'}, params)
|
237
|
+
|
238
|
+
|
178
239
|
enforce_map!({
|
240
|
+
:title => :string,
|
241
|
+
:title_size => :natural_number,
|
242
|
+
:title_color => :hex_color,
|
179
243
|
:width => :natural_number,
|
180
244
|
:height => :natural_number,
|
181
245
|
:background_color => :hex_color,
|
182
|
-
:
|
183
|
-
|
184
|
-
params[:title] = '' unless params.has_key? :title
|
185
|
-
params[:title_size] = 12 unless params.has_key? :title_size
|
186
|
-
params[:title_color] = '000000' unless params.has_key? :title_color
|
187
|
-
|
246
|
+
:color => :hex_color}, params)
|
188
247
|
|
189
248
|
options = {}
|
190
249
|
|
@@ -211,13 +270,28 @@ module Analytica
|
|
211
270
|
end
|
212
271
|
|
213
272
|
def to_bargraph(params={})
|
273
|
+
enforce_map_defaults!({
|
274
|
+
:title => ' ',
|
275
|
+
:title_size => 12,
|
276
|
+
:title_color => '000000',
|
277
|
+
:orientation => :vertical,
|
278
|
+
:color => 'ffffff',
|
279
|
+
:background_color => '000000',
|
280
|
+
:width => 600,
|
281
|
+
:height => 280,
|
282
|
+
:bar_settings => {}}, params)
|
283
|
+
|
214
284
|
enforce_map!({
|
285
|
+
:title => :string,
|
286
|
+
:title_size => :natural_number,
|
287
|
+
:title_color => :hex_color,
|
215
288
|
:width => :natural_number,
|
216
289
|
:height => :natural_number,
|
217
290
|
:orientation => [:vertical, :horizontal],
|
218
291
|
:stacked => :boolean,
|
219
292
|
:background_color => :hex_color,
|
220
|
-
:colors => :hex_color_array
|
293
|
+
:colors => :hex_color_array,
|
294
|
+
:bar_settings => :hash_map}, params)
|
221
295
|
|
222
296
|
options = {}
|
223
297
|
|
@@ -227,7 +301,7 @@ module Analytica
|
|
227
301
|
:size => "#{params[:width]}x#{params[:height]}",
|
228
302
|
:orientation => params[:orientation].to_s,
|
229
303
|
:stacked => params[:stacked],
|
230
|
-
:bar_width_and_spacing =>
|
304
|
+
:bar_width_and_spacing => bar_settings(params[:bar_settings]),
|
231
305
|
:format => 'image_tag'
|
232
306
|
}
|
233
307
|
|
data/test/test_analytica.rb
CHANGED
@@ -3,6 +3,7 @@ require "analytica"
|
|
3
3
|
|
4
4
|
class TestAnalytica < Test::Unit::TestCase
|
5
5
|
def test_sanity
|
6
|
-
|
6
|
+
a = Analytica::DataSet.new([3, 8, 3, 9, 2, 7])
|
7
|
+
puts a.to_bargraph(:width => 500, :height => 230, :color => 'ffffff', :background_color => '000000', :orientation => :vertical).gsub("\"", "'").inspect
|
7
8
|
end
|
8
9
|
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: 1
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 15
|
10
|
+
version: 0.0.15
|
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-20 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|