analytica 0.0.20 → 0.0.21

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.
Files changed (3) hide show
  1. data/lib/analytica.rb +7 -1
  2. data/lib/visualization.rb +66 -9
  3. metadata +3 -3
@@ -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.20'
7
+ VERSION = '0.0.21'
8
8
 
9
9
  include Strict
10
10
 
@@ -31,6 +31,9 @@ module Analytica
31
31
 
32
32
  def initialize(datapoints=[])
33
33
  enforce!(:numeric_array, datapoints)
34
+
35
+ @custom = ""
36
+ @custom_set = false
34
37
 
35
38
  @labels = {}
36
39
  @labels_set = false
@@ -63,6 +66,9 @@ module Analytica
63
66
  def initialize(datasets=[])
64
67
  enforce!(:dataset_array, datasets)
65
68
 
69
+ @custom = ""
70
+ @custom_set = false
71
+
66
72
  @labels = {}
67
73
  @labels_set = false
68
74
 
@@ -8,11 +8,13 @@ module Analytica
8
8
  def set_labels(params={})
9
9
  enforce_map_defaults!({
10
10
  :data => [],
11
- :type => :x_axis,
11
+ :type => :axis,
12
+ :style => :axis_tick,
12
13
  :prefix => ' ',
13
14
  :postfix => ' ',
14
15
  :decimal => 0,
15
16
  :color => '000000',
17
+ :tick_color => "333333",
16
18
  :size => 10}, params)
17
19
 
18
20
  enforce_primitive!(Array, params[:data])
@@ -22,18 +24,21 @@ module Analytica
22
24
  :prefix => :string,
23
25
  :decimal => :integer,
24
26
  :color => :hex_color,
27
+ :tick_color => :hex_color,
28
+ :style => [:axis_tick, :axis_only, :tick_only, :none],
25
29
  :size => :natural_number}, params)
26
30
 
27
31
  @labels_set = true
28
32
 
29
33
  @labels = {} if @labels.nil?
30
34
  @labels[params[:type]] = {}
31
-
32
35
  @labels[params[:type]][:prefix] = params[:prefix] == ' ' ? '' : params[:prefix]
33
36
  @labels[params[:type]][:postfix] = params[:postfix] == ' ' ? '' : params[:postfix]
34
37
  @labels[params[:type]][:decimal] = params[:decimal]
35
38
  @labels[params[:type]][:color] = params[:color]
36
39
  @labels[params[:type]][:size] = params[:size]
40
+ @labels[params[:type]][:style] = params[:style]
41
+ @labels[params[:type]][:tick_color] = params[:tick_color]
37
42
  @labels[params[:type]][:data] = params[:data]
38
43
  end
39
44
 
@@ -59,6 +64,14 @@ module Analytica
59
64
  bar_settings
60
65
  end
61
66
 
67
+ def add_custom(item)
68
+ enforce!(:string, item)
69
+
70
+ @custom_set = true
71
+ @custom += "&" if @custom.size > 0
72
+ @custom += item
73
+ end
74
+
62
75
  def generate_title
63
76
  options = {}
64
77
  if @title_set
@@ -71,11 +84,7 @@ module Analytica
71
84
  options = {}
72
85
  if @labels_set
73
86
  if @labels[:data]
74
- @labels[:data][:data].each {|element| data_string += ",#{element.to_f}"}
75
- data_labels = {
76
- :custom => "chm=N#{@labels[:data][:prefix]}*f#{@labels[:data][:decimal]}*#{@labels[:data][:postfix]},#{@labels[:data][:color]},0,-1,#{@labels[:data][:size]}&chds=0,#{datamax}"
77
- }
78
- options.merge!(data_labels)
87
+ add_custom("chm=N#{@labels[:data][:prefix]}*f#{@labels[:data][:decimal]}*#{@labels[:data][:postfix]},#{@labels[:data][:color]},0,-1,#{@labels[:data][:size]}&chds=0,#{datamax}")
79
88
  end
80
89
 
81
90
  if @labels[:axis]
@@ -83,28 +92,76 @@ module Analytica
83
92
  :axis_with_labels => ['x', 'y'],
84
93
  :axis_labels => [@labels[:axis][:data], ["#{0}", "#{(datamax*0.5).to_i}", "#{datamax.to_i}"]]
85
94
  }
95
+
96
+ axis_style = case @labels[:axis][:style]
97
+ when :axis_tick
98
+ "lt"
99
+ when :axis_only
100
+ "l"
101
+ when :tick_only
102
+ "t"
103
+ when :none
104
+ "_"
105
+ end
106
+
107
+ add_custom("chxs=0N#{@labels[:axis][:prefix]}*f#{@labels[:axis][:decimal]}*#{@labels[:axis][:postfix]},#{@labels[:axis][:color]},#{@labels[:axis][:size]},#{axis_style},#{@labels[:axis][:tick_color]}|1N#{@labels[:axis][:prefix]}*f#{@labels[:axis][:decimal]}*#{@labels[:axis][:postfix]},#{@labels[:axis][:color]},#{@labels[:axis][:size]},#{axis_style},#{@labels[:axis][:tick_color]}") #http://code.google.com/apis/chart/docs/chart_params.html
86
108
  options.merge!(axis_labels)
109
+
87
110
  elsif @labels[:x_axis]
88
111
  x_axis_label = {
89
- :axis_with_labels => 'x',
112
+ :axis_with_labels => ['x'],
90
113
  :axis_labels => @labels[:x_axis][:data].size == 0 ? self.map{|n|"#{n}"} : @labels[:x_axis][:data]
91
114
  }
115
+
116
+ axis_style = case @labels[:x_axis][:style]
117
+ when :axis_tick
118
+ "lt"
119
+ when :axis_only
120
+ "l"
121
+ when :tick_only
122
+ "t"
123
+ when :none
124
+ "_"
125
+ end
126
+
127
+ add_custom("chxs=0N#{@labels[:x_axis][:prefix]}*f#{@labels[:x_axis][:decimal]}*#{@labels[:x_axis][:postfix]},#{@labels[:x_axis][:color]},#{@labels[:x_axis][:size]},#{axis_style},#{@labels[:x_axis][:tick_color]}") #http://code.google.com/apis/chart/docs/chart_params.html
92
128
  options.merge!(x_axis_label)
93
129
  elsif @labels[:y_axis]
94
130
  y_axis_label = {
95
- :axis_with_labels => 'y',
131
+ :axis_with_labels => ['y'],
96
132
  :axis_labels => @labels[:y_axis][:data].size == 0 ? ["#{0}", "#{(datamax*0.5).to_i}", "#{datamax.to_i}"] : @labels[:y_axis][:data]
97
133
  }
134
+ axis_style = case @labels[:y_axis][:style]
135
+ when :axis_tick
136
+ "lt"
137
+ when :axis_only
138
+ "l"
139
+ when :tick_only
140
+ "t"
141
+ when :none
142
+ "_"
143
+ end
144
+
145
+ add_custom("chxs=0N#{@labels[:y_axis][:prefix]}*f#{@labels[:y_axis][:decimal]}*#{@labels[:y_axis][:postfix]},#{@labels[:y_axis][:color]},#{@labels[:y_axis][:size]},#{axis_style},#{@labels[:y_axis][:tick_color]}") #http://code.google.com/apis/chart/docs/chart_params.html
98
146
  options.merge!(y_axis_label)
99
147
  end
100
148
  end
101
149
  options
102
150
  end
103
151
 
152
+ def generate_custom
153
+ options = {
154
+ :custom => @custom
155
+ }
156
+ @custom = ""
157
+ options
158
+ end
159
+
104
160
  def common_options
105
161
  options = {}
106
162
  options.merge!(generate_labels)
107
163
  options.merge!(generate_title)
164
+ options.merge!(generate_custom)
108
165
  options
109
166
  end
110
167
  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: 55
4
+ hash: 53
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 20
10
- version: 0.0.20
9
+ - 21
10
+ version: 0.0.21
11
11
  platform: ruby
12
12
  authors:
13
13
  - Raeez Lorgat