analytica 0.0.16 → 0.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/analytica.rb +4 -2
- data/lib/visualization.rb +58 -72
- metadata +3 -3
data/lib/analytica.rb
CHANGED
@@ -4,7 +4,7 @@ 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.17'
|
8
8
|
|
9
9
|
include Strict
|
10
10
|
|
@@ -58,10 +58,12 @@ module Analytica
|
|
58
58
|
include Analytica::Visualization::Common
|
59
59
|
include Analytica::Visualization::DataSystem
|
60
60
|
|
61
|
+
attr_accessor :labels
|
62
|
+
|
61
63
|
def initialize(datasets=[])
|
62
64
|
enforce!(:dataset_array, datasets)
|
63
65
|
|
64
|
-
@labels =
|
66
|
+
@labels = {}
|
65
67
|
@labels_set = false
|
66
68
|
|
67
69
|
super datasets
|
data/lib/visualization.rb
CHANGED
@@ -3,40 +3,8 @@ require 'typestrict'
|
|
3
3
|
|
4
4
|
module Analytica
|
5
5
|
module Visualization
|
6
|
-
module Common
|
7
|
-
def set_title(params)
|
8
|
-
enforce_map!({
|
9
|
-
:title => :string,
|
10
|
-
:title_size => :natural_number,
|
11
|
-
:title_color => :hex_color}, params)
|
12
|
-
|
13
|
-
@title = params
|
14
|
-
@title_set = true
|
15
|
-
end
|
16
|
-
|
17
|
-
def common_options
|
18
|
-
options = {}
|
19
|
-
|
20
|
-
if @labels_set
|
21
|
-
label = {
|
22
|
-
:axis_with_labels => ['x', 'y'],
|
23
|
-
:axis_labels => [@labels[:axis][:data], ["#{0}", "#{(datamax*0.5).to_i}", "#{datamax.to_i}"]]
|
24
|
-
}
|
25
|
-
|
26
|
-
options.merge!(label)
|
27
|
-
end
|
28
|
-
|
29
|
-
if @title_set
|
30
|
-
options.merge!(@title)
|
31
|
-
end
|
32
|
-
|
33
|
-
options
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
module DataSet
|
38
|
-
include Strict
|
39
6
|
|
7
|
+
module Common
|
40
8
|
def set_labels(data, params={})
|
41
9
|
enforce_map_defaults!({
|
42
10
|
:type => :axis,
|
@@ -66,6 +34,16 @@ module Analytica
|
|
66
34
|
@labels[params[:type]][:data] = data
|
67
35
|
end
|
68
36
|
|
37
|
+
def set_title(params)
|
38
|
+
enforce_map!({
|
39
|
+
:title => :string,
|
40
|
+
:title_size => :natural_number,
|
41
|
+
:title_color => :hex_color}, params)
|
42
|
+
|
43
|
+
@title = params
|
44
|
+
@title_set = true
|
45
|
+
end
|
46
|
+
|
69
47
|
def bar_settings(bar_settings)
|
70
48
|
enforce_map_optional!({
|
71
49
|
:width => :natural_number,
|
@@ -74,6 +52,48 @@ module Analytica
|
|
74
52
|
bar_settings
|
75
53
|
end
|
76
54
|
|
55
|
+
def generate_title
|
56
|
+
options = {}
|
57
|
+
if @title_set
|
58
|
+
options.merge!(@title)
|
59
|
+
end
|
60
|
+
options
|
61
|
+
end
|
62
|
+
|
63
|
+
def generate_labels
|
64
|
+
options = {}
|
65
|
+
if @labels_set
|
66
|
+
if @labels[:data]
|
67
|
+
@labels[:data][:data].each {|element| data_string += ",#{element.to_f}"}
|
68
|
+
data_labels = {
|
69
|
+
:custom => "chm=N#{@labels[:data][:prefix]}*f#{@labels[:data][:decimal]}*#{@labels[:data][:postfix]},#{@labels[:data][:color]},0,-1,#{@labels[:data][:size]}&chds=0,#{datamax}"
|
70
|
+
}
|
71
|
+
options.merge!(data_labels)
|
72
|
+
end
|
73
|
+
|
74
|
+
if @labels[:axis]
|
75
|
+
axis_labels = {
|
76
|
+
:axis_with_labels => ['x', 'y'],
|
77
|
+
:axis_labels => [@labels[:axis][:data], ["#{0}", "#{(datamax*0.5).to_i}", "#{datamax.to_i}"]]
|
78
|
+
}
|
79
|
+
options.merge!(axis_labels)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
puts "ended with label settings => #{options.inspect}"
|
83
|
+
options
|
84
|
+
end
|
85
|
+
|
86
|
+
def common_options
|
87
|
+
options = {}
|
88
|
+
options.merge!(generate_labels)
|
89
|
+
options.merge!(generate_title)
|
90
|
+
options
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
module DataSet
|
95
|
+
include Strict
|
96
|
+
|
77
97
|
def datamax
|
78
98
|
(max > 0) ? (1.25*max) : 1
|
79
99
|
end
|
@@ -131,7 +151,7 @@ module Analytica
|
|
131
151
|
:color => '0000ff',
|
132
152
|
:background_color => 'ffffff',
|
133
153
|
:width => 600,
|
134
|
-
:height =>
|
154
|
+
:height => 180,
|
135
155
|
:bar_settings => {}}, params)
|
136
156
|
|
137
157
|
enforce_map!({
|
@@ -184,6 +204,7 @@ module Analytica
|
|
184
204
|
:stacked => false,
|
185
205
|
:width => 600,
|
186
206
|
:height => 280,
|
207
|
+
:stacked => false,
|
187
208
|
:bar_settings => {}}, params)
|
188
209
|
|
189
210
|
enforce_map!({
|
@@ -219,51 +240,15 @@ module Analytica
|
|
219
240
|
}
|
220
241
|
|
221
242
|
options.merge!(color)
|
222
|
-
|
223
|
-
if @labels_set
|
224
243
|
|
225
|
-
|
226
|
-
|
227
|
-
@labels[:data][:data].each {|element| data_string += ",#{element.to_f}"}
|
228
|
-
data_string = data_string[1..data_string.size]
|
229
|
-
data_labels = {
|
230
|
-
:custom => "chm=N#{@labels[:data][:prefix]}*f#{@labels[:data][:decimal]}*#{@labels[:data][:postfix]},#{@labels[:data][:color]},0,-1,#{@labels[:data][:size]}&chds=0,#{datamax}"
|
231
|
-
}
|
232
|
-
options.merge!(data_labels)
|
233
|
-
end
|
234
|
-
|
235
|
-
if @labels[:axis]
|
236
|
-
puts "doing the axis labels thing #{@labels[:axis][:data]}"
|
237
|
-
axis_labels = {
|
238
|
-
:axis_with_labels => ['x', 'y'],
|
239
|
-
:axis_labels => [@labels[:axis][:data], ["#{0}", "#{(datamax*0.5).to_i}", "#{datamax.to_i}"]]
|
240
|
-
}
|
241
|
-
|
242
|
-
options.merge!(axis_labels)
|
243
|
-
end
|
244
|
-
end
|
245
|
-
|
246
|
-
if @title_set
|
247
|
-
options.merge!(@title)
|
248
|
-
end
|
244
|
+
options.merge!(common_options)
|
245
|
+
|
249
246
|
return Gchart.bar(options)
|
250
247
|
end
|
251
248
|
end
|
252
249
|
|
253
250
|
module DataSystem
|
254
251
|
|
255
|
-
def bar_settings(bar_settings)
|
256
|
-
enforce_map_optional!({
|
257
|
-
:width => :natural_number,
|
258
|
-
:spacing => :natural_number,
|
259
|
-
:group_spacing => :natural_number}, bar_settings)
|
260
|
-
bar_settings
|
261
|
-
end
|
262
|
-
|
263
|
-
def set_labels(data, params={})
|
264
|
-
# TODO implement
|
265
|
-
end
|
266
|
-
|
267
252
|
def datamax
|
268
253
|
(self.map{|dset| dset.datamax}).max
|
269
254
|
end
|
@@ -322,6 +307,7 @@ module Analytica
|
|
322
307
|
:background_color => '000000',
|
323
308
|
:width => 600,
|
324
309
|
:height => 280,
|
310
|
+
:stacked => false,
|
325
311
|
:bar_settings => {}}, params)
|
326
312
|
|
327
313
|
enforce_map!({
|
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: 61
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 17
|
10
|
+
version: 0.0.17
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Raeez Lorgat
|