rchart 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/rdata.rb ADDED
@@ -0,0 +1,239 @@
1
+ class Rdata
2
+ # This function create a new Rdata object.
3
+ # This object will be used during all the steps of the data population.
4
+ # Data will be extracted from this object using get_data and get_data_description
5
+ def initialize
6
+ @data = []
7
+ @data_description = {}
8
+ @data_description["position"] = "name"
9
+ @data_description["format"] = {"x"=>"number","y" => "number"}
10
+ @data_description["unit"] = {"x" => "","y"=>""}
11
+ @data_description["symbol"] = {}
12
+ end
13
+
14
+ # This function can be used to add one or multiple points to a data serie.
15
+ # By default points are added to Serie1.
16
+ # This will the value 25 as the last point of Serie1
17
+ # * chart_data.add_point(25)
18
+ # This will the value 2,4,9,5,1,0 as the last point of Serie1
19
+ # * chart_data.add_point([2,4,9,5,1,0])
20
+ # This will the value 12 as the last point of Serie2
21
+ # * chart_data.add_point(12,"Serie2")
22
+ # add the desciption "March" to the Serie2
23
+ # * chart_data.add_point(12,"Serie2","March")
24
+ def add_point(value,serie="Serie1",description="")
25
+ if ((value.is_a?(Array)) && value.count == 1)
26
+ value = value[0]
27
+ end
28
+ id = 0
29
+ @data.each_with_index do |v,index|
30
+ id = index+1 unless @data[index][serie].nil?
31
+ end
32
+ if value.is_a?(Numeric)
33
+ if @data[id].nil?
34
+ @data[id]={serie => value}
35
+ else
36
+ @data[id]= @data[id].merge(serie => value)
37
+ end
38
+ if description != ""
39
+ @data[id]["name"] = description;
40
+ elsif @data[id]["name"].nil?
41
+ @data[id]["name"] = id
42
+ end
43
+ else
44
+
45
+ value.each do |k|
46
+ if @data[id].nil?
47
+ @data[id] = {serie=>k}#TODO check k
48
+ else
49
+ @data[id] = @data[id].merge({serie=>k})
50
+ end
51
+
52
+ @data[id]["name"] = id if @data[id]["name"].nil?
53
+ id = id+1
54
+ end
55
+
56
+ end
57
+
58
+ end
59
+ # This function can be used to add a new data serie to the data_description.
60
+ # All the series declared in this object will be graphed when calling a chart function of the Rchart class.
61
+ # There is no change on Data, only the "Graphable" attribute is modified.
62
+ # Generate some data...
63
+ # * chart_data.add_point([2,4,9,5,1,0]),"Serie1")
64
+ # * chart_data.add_point([1,1,2,2,3,3]),"Serie2")
65
+ # * chart_data.add_point([4,2,4,2,4,2]),"Serie3")
66
+ # This will mark both Serie1 & Serie2 as "graphable" but not Serie3
67
+ # * chart_data.add_serie("Serie1")
68
+ # * chart_data.add_serie("Serie2")
69
+ def add_serie(serie_name="Serie1")
70
+
71
+ if (@data_description["values"].nil?)
72
+ @data_description["values"] = [serie_name]
73
+ else
74
+ found = false
75
+ @data_description["values"].each do |k|
76
+ found = true if ( k == serie_name ) #TODO check
77
+ end
78
+ @data_description["values"] << serie_name if (!found )
79
+ end
80
+
81
+ end
82
+ # This function can be used to set all data series as graphable.
83
+ # They'll all be graphed when calling a chart function of the Rchart class.
84
+ # There is no change on Data, only the "Graphable" attribute is modified
85
+ # Generate some data...
86
+ # * chart_data.add_point([2,4,9,5,1,0],"Serie1")
87
+ # * chart_data.add_point([(1,1,2,2,3,3],"Serie2")
88
+ # This will mark both Serie1 & Serie2 as "graphable"
89
+ # * chart_data.add_all_series
90
+
91
+ def add_all_series
92
+ @data_description["values"] = []
93
+ if(!@data[0].nil?)
94
+ @data[0].each do |k,v|
95
+ if (k != "name" )
96
+ @data_description["values"].push(k)
97
+ end
98
+ end
99
+ end
100
+ end
101
+ # This function can be used to remove a data series from the graphable ones.
102
+ # They'll all be graphed when calling a chart function of the Rchart class.
103
+ # There is no change on Data, only the "Graphable" attribute is modified.
104
+ # Generate some data...
105
+ # * chart_data.add_point([2,4,9,5,1,0],"Serie1")
106
+ # * chart_data.add_point([1,1,2,2,3,3],"Serie2")
107
+ # This will mark both Serie1 & Serie2 as "graphable"
108
+ # * chart_data.add_all_series
109
+ # This will remove the "graphable" status of Serie2
110
+ # * chart_data.remove_serie("Serie2")
111
+
112
+ def remove_serie(serie_name="Serie1")
113
+ if (!@data_description["values"].nil?)
114
+ found = false;
115
+ @data_description["values"].each do |v|
116
+ @data_description["values"].delete(v) if (v == serie_name )
117
+ end
118
+ end
119
+ end
120
+ # his function can be used to set which serie is used (if any) as abcisse value
121
+ # Generate some data...
122
+ # * chart_data.add_point(["Jan","Feb","Mar"),"Serie1")
123
+ # * chart_data.add_point([2,4,9),"Serie2")
124
+ # * chart_data.add_point([1,1,2),"Serie3")
125
+ # This will mark both Serie1 & Serie2 as "graphable"
126
+ # * chart_data.add_serie("Serie2")
127
+ # * chart_data.add_serie("Serie3")
128
+ # Set Serie as abcisse label
129
+ # * chart_data.set_abscise_label_serie("Serie1")
130
+ def set_abscise_label_serie(serie_name = "name")
131
+ @data_description["position"] = serie_name
132
+ end
133
+ # This function can be used to set the description of a serie.
134
+ # This description will be written on the graph when calling the draw_legend function
135
+ # Generate some data...
136
+ # * chart_data.add_point([2,4,9),"Serie1")
137
+ # * chart_data.add_point([1,1,2),"Serie2")
138
+ # This will set the name of Serie1 to "January"
139
+ # * chart_data.set_serie_name("January")
140
+ # This will set the name of Serie2 to "February"
141
+ # * chart_data.set_serie_name("February","Serie2")
142
+
143
+ def set_serie_name(name,serie_name="Serie1")
144
+ if @data_description["description"].nil?
145
+ @data_description["description"]={serie_name => name}
146
+ else
147
+ @data_description["description"] = @data_description["description"].merge(serie_name => name)
148
+ end
149
+ end
150
+
151
+ # This will give a name to the X axis, writting it horizontally behind the chart
152
+ # * chart_data.set_x_axis_name("Samples")
153
+ def set_x_axis_name(name="X Axis")
154
+ if @data_description["axis"].nil?
155
+ @data_description["axis"]={"x" => name}
156
+ else
157
+ @data_description["axis"]=@data_description["axis"].merge("x" => name)
158
+ end
159
+ end
160
+ # This will give a name to the Y axis, writting it horizontally behind the chart
161
+ # * chart_data.set_y_axis_name("Temperature")
162
+ def set_y_axis_name(name="Y Axis")
163
+ if @data_description["axis"].nil?
164
+ @data_description["axis"]= {"y" => name}
165
+ else
166
+ @data_description["axis"]=@data_description["axis"].merge("y" => name)
167
+ end
168
+ end
169
+
170
+ # With this function you can set the format of the X axis values. Todays formats are the following :
171
+ # * number used by defaults
172
+ # * metric number that will be displayed with k/m/g units
173
+
174
+ def set_x_axis_format(format="number")
175
+ @data_description["format"]["x"] = format
176
+ end
177
+ # With this function you can set the format of the Y axis values. Todays formats are the following :
178
+ # * number used by defaults
179
+ # * metric number that will be displayed with k/m/g units
180
+
181
+ def set_y_axis_format(format="number")
182
+ @data_description["format"]["y"] = format
183
+ end
184
+ # Set the axis unit. This will be appended to the axis value
185
+ # Give the "km" unit to the X axis
186
+ # * chart_data.set_x_axis_unit("km")
187
+ def set_x_axis_unit(unit="")
188
+ @data_description["unit"]["x"] = unit
189
+ end
190
+
191
+ # Set the axis unit. This will be appended to the axis value
192
+ # Give the "m/s" unit to the Y axis
193
+ # * chart_data.set_x_axis_unit("m/s")
194
+
195
+ def set_y_axis_unit(unit="")
196
+ @data_description["unit"]["y"] = unit
197
+ end
198
+
199
+ def set_serie_symbol(name,symbol)
200
+ @data_description["symbol"][name] = symbol
201
+ end
202
+ # This function can be used to remove the description of a serie.
203
+ # This description will be written on the graph when calling the drawLegend function.
204
+ # Removing it's name using this function can be usefull to hide previously used series
205
+ # Generate some data...
206
+ # * chart_data.add_point([2,4,9],"Serie1")
207
+ # * chart_data.add_point([1,1,2],"Serie2")
208
+ # This will set the name of Serie1 to "January"
209
+ # * chart_data.set_serie_name("January")
210
+ # This will set the name of Serie2 to "February"
211
+ # * chart_data.set_serie_name("February","Serie2")
212
+ # Ths will remove name of Serie1
213
+ # * chart_data.remove_serie_name("Serie1")
214
+ def remove_serie_name(serie_name)
215
+ if(!@data_description["description"][serie_name].nil?)
216
+ @data_description["description"].delete(serie_name)
217
+ end
218
+ end
219
+ # This function can be used to remove the description of a serie.
220
+ # This description will be written on the graph when calling the drawLegend function.
221
+ # Removing it's name using this function can be usefull to hide previously used series
222
+
223
+ def remove_all_series
224
+ @data_description["values"].each do |v|
225
+ @data_description["values"] = []
226
+ end
227
+ end
228
+
229
+ # This function is used everytime you want to retrieve the Data stored in the Rdata structure
230
+ def get_data
231
+ @data
232
+ end
233
+ # This function is used everytime you want to retrieve the Data description stored in the Rdata structure
234
+ def get_data_description
235
+ @data_description
236
+ end
237
+
238
+ end
239
+
data/lib/version.rb ADDED
@@ -0,0 +1,19 @@
1
+ require 'rubygems'
2
+ require 'ruby-debug'
3
+ class Version
4
+ MAJOR = 1
5
+ MINOR = 0
6
+ RELEASE = 0
7
+ def self.current
8
+ "#{MAJOR}.#{MINOR}.#{RELEASE}"
9
+ end
10
+ def self.font_path
11
+ Gem.path.each do |gem_path|
12
+ path= gem_path+"/gems/rchart-#{MAJOR}.#{MINOR}.#{RELEASE}/fonts"
13
+ if File.exists?(path+"/tahoma.ttf")
14
+ return path
15
+ break
16
+ end
17
+ end
18
+ end
19
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'rchart'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestRchart < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rchart
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - amardaxini
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-07-26 00:00:00 +05:30
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: ruby-gd
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.8.0
24
+ version:
25
+ description: Ruby port of the slick pChart charting library
26
+ email: amardaxini@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - LICENSE
38
+ - README.rdoc
39
+ - Rakefile
40
+ - VERSION
41
+ - examples/Point_Asterisk.png
42
+ - examples/Point_Cd.png
43
+ - examples/example1.rb
44
+ - examples/example10.rb
45
+ - examples/example11.rb
46
+ - examples/example12.rb
47
+ - examples/example13.rb
48
+ - examples/example14.rb
49
+ - examples/example15.rb
50
+ - examples/example16.rb
51
+ - examples/example17.rb
52
+ - examples/example18.rb
53
+ - examples/example19.rb
54
+ - examples/example2.rb
55
+ - examples/example20.rb
56
+ - examples/example21.rb
57
+ - examples/example3.rb
58
+ - examples/example4.rb
59
+ - examples/example5.rb
60
+ - examples/example6.rb
61
+ - examples/example7.rb
62
+ - examples/example8.rb
63
+ - examples/example9.rb
64
+ - examples/logo.png
65
+ - examples/softtones.txt
66
+ - fonts/GeosansLight.ttf
67
+ - fonts/MankSans.ttf
68
+ - fonts/Silkscreen.ttf
69
+ - fonts/pf_arma_five.ttf
70
+ - fonts/tahoma.ttf
71
+ - lib/rchart.rb
72
+ - lib/rdata.rb
73
+ - lib/version.rb
74
+ - test/helper.rb
75
+ - test/test_rchart.rb
76
+ has_rdoc: true
77
+ homepage: http://github.com/amardaxini/rchart
78
+ licenses: []
79
+
80
+ post_install_message:
81
+ rdoc_options:
82
+ - --charset=UTF-8
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: "0"
90
+ version:
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: "0"
96
+ version:
97
+ requirements:
98
+ - libgd-ruby, libpng-dev, libgd-dev package are required
99
+ rubyforge_project: rchart
100
+ rubygems_version: 1.3.5
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: Ruby port of the slick pChart charting library
104
+ test_files:
105
+ - test/test_rchart.rb
106
+ - test/helper.rb
107
+ - examples/example20.rb
108
+ - examples/example4.rb
109
+ - examples/example17.rb
110
+ - examples/example18.rb
111
+ - examples/example9.rb
112
+ - examples/example3.rb
113
+ - examples/example2.rb
114
+ - examples/example8.rb
115
+ - examples/example6.rb
116
+ - examples/example15.rb
117
+ - examples/example7.rb
118
+ - examples/example19.rb
119
+ - examples/example12.rb
120
+ - examples/example21.rb
121
+ - examples/example11.rb
122
+ - examples/example10.rb
123
+ - examples/example1.rb
124
+ - examples/example5.rb
125
+ - examples/example16.rb
126
+ - examples/example14.rb
127
+ - examples/example13.rb