rchart 1.0.0

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/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 amardaxini
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,20 @@
1
+ = rchart
2
+
3
+ rchart is ruby port of the slick pChart charting library.
4
+
5
+ This gem requires ruby-gd 0.8.0 dependency.
6
+ * gem install ruby-gd
7
+ # ruby-gd requires mainly following dependencies
8
+ # libgd-ruby,libpng-dev,libgd-dev
9
+ # On Ubuntu you can install
10
+ * sudo apt-get install libgd-ruby
11
+ * sudo apt-get install libpng-dev
12
+ * sudo apt-get install libgd2-xpm-dev
13
+
14
+
15
+ == TODO
16
+ * Refactor code
17
+ * Use gd2 library instead of gd
18
+ == Copyright
19
+
20
+ Copyright (c) 2010 amardaxini. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,60 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "rchart"
8
+ gem.summary = %Q{Ruby port of the slick pChart charting library }
9
+ gem.description = %Q{Ruby port of the slick pChart charting library}
10
+ gem.email = "amardaxini@gmail.com"
11
+ gem.homepage = "http://github.com/amardaxini/rchart"
12
+ gem.authors = ["amardaxini"]
13
+ gem.rubyforge_project = "rchart"
14
+ # gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
15
+ gem.add_development_dependency "ruby-gd",">=0.8.0"
16
+ gem.files = [Dir['fonts/*'],Dir['examples/*'],".document", ".gitignore","LICENSE","README.rdoc","Rakefile","VERSION", "lib/rchart.rb","lib/rdata.rb","lib/version.rb","test/helper.rb","test/test_rchart.rb"]
17
+ gem.requirements << "libgd-ruby, libpng-dev, libgd-dev package are required"
18
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
19
+ end
20
+ Jeweler::GemcutterTasks.new
21
+ Jeweler::RubyforgeTasks.new do |rubyforge|
22
+ rubyforge.doc_task = "rdoc"
23
+ end
24
+ rescue LoadError
25
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
26
+ end
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ begin
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'test'
39
+ test.pattern = 'test/**/test_*.rb'
40
+ test.verbose = true
41
+ end
42
+ rescue LoadError
43
+ task :rcov do
44
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
45
+ end
46
+ end
47
+
48
+ task :test => :check_dependencies
49
+
50
+ task :default => :test
51
+
52
+ require 'rake/rdoctask'
53
+ Rake::RDocTask.new do |rdoc|
54
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
55
+
56
+ rdoc.rdoc_dir = 'rdoc'
57
+ rdoc.title = "rchart #{version}"
58
+ rdoc.rdoc_files.include('README*')
59
+ rdoc.rdoc_files.include('lib/**/*.rb')
60
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
Binary file
Binary file
@@ -0,0 +1,36 @@
1
+ # A cubic curve graph
2
+ require 'rubygems'
3
+ require 'rchart'
4
+ #Dataset definition
5
+ p = Rdata.new
6
+ p.add_point([1,4,3,4,3,3,2,1,0,7,4,3,2,3,3,5,1,0,7],"Serie1")
7
+ p.add_point([1,4,2,6,2,3,0,1,5,1,2,4,5,2,1,0,6,4,2],"Serie2")
8
+ p.add_all_series()
9
+ p.set_abscise_label_serie
10
+ p.set_serie_name("January","Serie1")
11
+ p.set_serie_name("February","Serie2")
12
+
13
+ #Initialise the graph
14
+ ch = Rchart.new(700,230)
15
+ ch.set_fixed_scale(-2,8)
16
+ ch.set_font_properties("tahoma.ttf",8)
17
+ ch.set_graph_area(50,30,585,200)
18
+ ch.draw_filled_rounded_rectangle(7,7,693,223,5,240,240,240)
19
+ ch.draw_rounded_rectangle(5,5,695,225,5,230,230,230)
20
+ ch.draw_graph_area(255,255,255,true)
21
+ ch.draw_scale(p.get_data,p.get_data_description,Rchart::SCALE_NORMAL,150,150,150,true,0,2)
22
+ ch.draw_grid(4,true,230,230,230,50)
23
+
24
+ #Draw the 0 line
25
+ ch.set_font_properties("tahoma.ttf",6)
26
+ ch.draw_treshold(0,143,55,72,true,true)
27
+
28
+ #Draw the cubic curve graph
29
+ ch.draw_cubic_curve(p.get_data,p.get_data_description)
30
+
31
+ #Finish the graph
32
+ ch.set_font_properties("tahoma.ttf",8)
33
+ ch.draw_legend(600,30,p.get_data_description,255,255,255)
34
+ ch.set_font_properties("tahoma.ttf",10)
35
+ ch.draw_title(50,22,"Example 1",50,50,50,585)
36
+ ch.render_png("example1")
@@ -0,0 +1,23 @@
1
+ #A 2D exploded pie graph
2
+ require 'rubygems'
3
+ require 'rchart'
4
+
5
+ p = Rdata.new
6
+ p.add_point([10,2,3,5,3],"Serie1")
7
+ p.add_point(["Jan","Feb","Mar","Apr","May"],"Serie2")
8
+ p.add_all_series
9
+ p.set_abscise_label_serie("Serie2")
10
+
11
+ ch = Rchart.new(300,200)
12
+ ch.set_font_properties("tahoma.ttf",8)
13
+ ch.draw_filled_rounded_rectangle(7,7,293,193,5,240,240,240)
14
+ ch.draw_rounded_rectangle(5,5,295,195,5,230,230,230)
15
+
16
+ # Draw the pie chart
17
+ ch.antialias_quality=0
18
+ ch.set_shadow_properties(2,2,200,200,200)
19
+ ch.draw_flat_pie_graph_with_shadow(p.get_data,p.get_data_description,120,100,60,Rchart::PIE_PERCENTAGE,8)
20
+ ch.clear_shadow
21
+ ch.draw_pie_legend(230,15,p.get_data,p.get_data_description,250,250,250)
22
+
23
+ ch.render_png("example10")
@@ -0,0 +1,22 @@
1
+ # A smooth flat pie graph
2
+ require 'rubygems'
3
+ require 'rchart'
4
+
5
+ p = Rdata.new
6
+ p.add_point([10,2,3,5,3],"Serie1")
7
+ p.add_point(["Jan","Feb","Mar","Apr","May"],"Serie2")
8
+ p.add_all_series
9
+ p.set_abscise_label_serie("Serie2")
10
+
11
+ ch = Rchart.new(300,200)
12
+ ch.draw_filled_rounded_rectangle(7,7,293,193,5,240,240,240)
13
+ ch.draw_rounded_rectangle(5,5,295,195,5,230,230,230)
14
+ #ch.load_color_palette_from_file("softtones.txt") #OR
15
+ ch.load_color_palette([[168,188,56],[188,208,76],[208,228,96],[228,245,116],[248,255,136]])
16
+ ch.draw_filled_circle(122,102,70,200,200,200)
17
+ ch.set_font_properties("tahoma.ttf",8)
18
+
19
+ ch.draw_basic_pie_graph(p.get_data,p.get_data_description,120,100,70,Rchart::PIE_PERCENTAGE,255,255,218)
20
+ ch.draw_pie_legend(230,15,p.get_data,p.get_data_description,250,250,250)
21
+
22
+ ch.render_png("example11")
@@ -0,0 +1,56 @@
1
+ # Playing with line style & pictures inclusion
2
+ require 'rubygems'
3
+ require 'rchart'
4
+
5
+ p = Rdata.new
6
+ p.add_point([10,9.4,7.7,5,1.7,-1.7,-5,-7.7,-9.4,-10,-9.4,-7.7,-5,-1.8,1.7],"Serie1")
7
+ p.add_point([0,3.4,6.4,8.7,9.8,9.8,8.7,6.4,3.4,0,-3.4,-6.4,-8.6,-9.8,-9.9],"Serie2")
8
+ p.add_point([7.1,9.1,10,9.7,8.2,5.7,2.6,-0.9,-4.2,-7.1,-9.1,-10,-9.7,-8.2,-5.8],"Serie3")
9
+ p.add_point(["Jan","Jan","Jan","Feb","Feb","Feb","Mar","Mar","Mar","Apr","Apr","Apr","May","May","May"],"Serie4")
10
+ p.add_all_series()
11
+ p.set_abscise_label_serie("Serie4")
12
+ p.set_serie_name("Max Average","Serie1")
13
+ p.set_serie_name("Min Average","Serie2")
14
+ p.set_serie_name("Temperature","Serie3")
15
+ p.set_serie_name("Temperature")
16
+ p.set_y_axis_name("Temperature")
17
+ p.set_x_axis_name("Month of the year")
18
+
19
+ ch = Rchart.new(700,230)
20
+ ch.set_fixed_scale(-12,12,5)
21
+ ch.set_font_properties("../fonts/tahoma.ttf",8)
22
+ ch.set_graph_area(65,30,570,185)
23
+ ch.draw_filled_rounded_rectangle(7,7,693,223,5,240,240,240)
24
+ ch.draw_rounded_rectangle(5,5,695,225,5,230,230,230)
25
+ ch.draw_graph_area(255,255,255,true)
26
+ ch.draw_scale(p.get_data,p.get_data_description,Rchart::SCALE_NORMAL,150,150,150,true,0,2,true,3)
27
+ ch.draw_grid(4,true,230,230,230,50)
28
+
29
+ #draw 0 line
30
+ ch.set_font_properties("tahoma.ttf",6)
31
+ ch.draw_treshold(0,143,55,72,true,true)
32
+
33
+ #draw area
34
+ p.remove_serie("Serie4")
35
+ ch.draw_area(p.get_data, "Serie1", "Serie2", 239,238,227,50)
36
+ p.remove_serie("Serie3")
37
+ ch.draw_line_graph(p.get_data,p.get_data_description)
38
+
39
+ #draw line graph
40
+ ch.set_line_style(1,6)
41
+ p.remove_all_series
42
+ p.add_serie("Serie3")
43
+ ch.draw_line_graph(p.get_data,p.get_data_description)
44
+ ch.draw_plot_graph(p.get_data,p.get_data_description,3,2,255,255,255)
45
+
46
+ #write values on serie3
47
+ ch.set_font_properties("tahoma.ttf",8)
48
+ ch.write_values(p.get_data,p.get_data_description, "Serie3")
49
+
50
+ #Finish the graph
51
+ ch.set_font_properties("tahoma.ttf",8)
52
+ ch.draw_legend(590,90,p.get_data_description,255,255,255)
53
+ ch.set_font_properties("tahoma.ttf",10)
54
+ ch.draw_title(60,22,"Example 15",50,50,50,585)
55
+ ch.draw_from_png("logo.png",584,35)
56
+ ch.render_png("example12")
@@ -0,0 +1,45 @@
1
+ #MISSING VALUES
2
+ require 'rubygems'
3
+ require 'rchart'
4
+
5
+ p = Rdata.new
6
+ p.add_point([2,5,7,"","",5,6,4,8,4,"",2,5,6,4,5,6,7,6],"Serie1")
7
+ p.add_point([-1,-3,-1,-2,-4,-1,"",-4,-5,-3,-2,-2,-3,-3,-5,-4,-3,-1,""],"Serie2")
8
+ p.add_all_series()
9
+ p.set_abscise_label_serie
10
+ p.set_serie_name("Raw #1","Serie1")
11
+ p.set_serie_name("Raw #2","Serie2")
12
+ p.set_y_axis_name("Response Time")
13
+ p.set_x_axis_name("Sample #ID")
14
+
15
+ ch = Rchart.new(700,230)
16
+ ch.set_font_properties("tahoma.ttf",8)
17
+ ch.set_graph_area(55,30,585,185)
18
+ ch.draw_filled_rounded_rectangle(7,7,693,223,5,240,240,240)
19
+ ch.draw_rounded_rectangle(5,5,695,225,5,230,230,230)
20
+ ch.draw_graph_area(255,255,255,true)
21
+ ch.draw_scale(p.get_data,p.get_data_description,Rchart::SCALE_NORMAL,150,150,150,true,0,2,true)
22
+ ch.draw_grid(4,true,230,230,230,50)
23
+
24
+ #draw 0 line
25
+ ch.set_font_properties("tahoma.ttf",6)
26
+ ch.draw_treshold(0,143,55,72,true,true)
27
+
28
+ #draw line graph
29
+ p.remove_serie("Serie2")
30
+ ch.draw_filled_line_graph(p.get_data,p.get_data_description,60,true)
31
+
32
+ #draw curve graph
33
+ p.remove_serie("Serie1")
34
+ p.add_serie("Serie2")
35
+ ch.set_shadow_properties(2,2,200,200,200,50)
36
+ ch.draw_cubic_curve(p.get_data, p.get_data_description)
37
+ ch.draw_plot_graph(p.get_data,p.get_data_description,3,2,255,255,255)
38
+ ch.clear_shadow
39
+
40
+ #Finish the graph
41
+ ch.set_font_properties("tahoma.ttf",8)
42
+ ch.draw_legend(600,30,p.get_data_description,255,255,255)
43
+ ch.set_font_properties("tahoma.ttf",10)
44
+ ch.draw_title(50,22,"Example 13",50,50,50,585)
45
+ ch.render_png("example13")
@@ -0,0 +1,37 @@
1
+ #Error reporting
2
+ require 'rubygems'
3
+ require 'rchart'
4
+
5
+ p = Rdata.new
6
+ p.add_point([10,4,3,2,3,3,2,1,0,7,4,3,2,3,3,5,1,0,7],"Serie1")
7
+ p.add_point([1,4,2,6,2,3,0,1,-5,1,2,4,5,2,1,0,6,4,30],"Serie2")
8
+ p.add_all_series()
9
+ p.set_abscise_label_serie
10
+ p.set_x_axis_name("Samples")
11
+ p.set_y_axis_name("Temprature")
12
+ p.set_serie_name("January","Serie1")
13
+
14
+ ch = Rchart.new(700,230)
15
+ ch.report_warnings("gd")
16
+ ch.set_font_properties("tahoma.ttf",8)
17
+ ch.set_graph_area(55,30,585,185)
18
+ ch.draw_filled_rounded_rectangle(7,7,693,223,5,240,240,240)
19
+ ch.draw_rounded_rectangle(5,5,695,225,5,230,230,230)
20
+ ch.draw_graph_area(255,255,255,true)
21
+ ch.draw_scale(p.get_data,p.get_data_description,Rchart::SCALE_NORMAL,150,150,150,true,0,2)
22
+ ch.draw_grid(4,true,230,230,230,50)
23
+
24
+ #draw 0 line
25
+ ch.set_font_properties("tahoma.ttf",6)
26
+ ch.draw_treshold(0,143,55,72,true,true)
27
+
28
+
29
+ #draw curve graph
30
+ ch.draw_cubic_curve(p.get_data, p.get_data_description)
31
+
32
+ #Finish the graph
33
+ ch.set_font_properties("tahoma.ttf",8)
34
+ ch.draw_legend(600,30,p.get_data_description,255,255,255)
35
+ ch.set_font_properties("tahoma.ttf",10)
36
+ ch.draw_title(50,22,"Example 14",50,50,50,585)
37
+ ch.render_png("example14")
@@ -0,0 +1,33 @@
1
+ #Stacked bar chart
2
+
3
+ require 'rubygems'
4
+ require 'rchart'
5
+
6
+ p = Rdata.new
7
+ p.add_point([1,4,-3,2,-3,3,2,1,0,7,4],"Serie1")
8
+ p.add_point([3,3,-4,1,-2,2,1,0,-1,6,3],"Serie2")
9
+ p.add_point([4,1,2,-1,-4,-2,3,2,1,2,2],"Serie3")
10
+ p.add_all_series()
11
+ p.set_abscise_label_serie
12
+ p.set_serie_name("January","Serie1")
13
+ p.set_serie_name("February","Serie2")
14
+ p.set_serie_name("March","Serie3")
15
+
16
+ ch = Rchart.new(700,230)
17
+ ch.set_font_properties("tahoma.ttf",8)
18
+ ch.set_graph_area(50,30,680,200)
19
+ ch.draw_filled_rounded_rectangle(7,7,693,223,5,240,240,240)
20
+ ch.draw_rounded_rectangle(5,5,695,225,5,230,230,230)
21
+ ch.draw_graph_area(255,255,255,true)
22
+ ch.draw_scale(p.get_data,p.get_data_description,2,150,150,150,true,0,2,true)
23
+ ch.draw_grid(4,true,230,230,230,50)
24
+ ch.set_font_properties("tahoma.ttf",6)
25
+ ch.draw_treshold(0,143,55,72,true,true)
26
+
27
+ ch.draw_stacked_bar_graph(p.get_data,p.get_data_description,100)
28
+
29
+ ch.set_font_properties("tahoma.ttf",8)
30
+ ch.draw_legend(596,150,p.get_data_description,255,255,255)
31
+ ch.set_font_properties("tahoma.ttf",10)
32
+ ch.draw_title(50,22,"Example 15",50,50,50,585)
33
+ ch.render_png("Example15")
@@ -0,0 +1,40 @@
1
+ # Playing with background
2
+
3
+ require 'rubygems'
4
+ require 'rchart'
5
+
6
+ p = Rdata.new
7
+ p.add_point([9,9,9,10,10,11,12,14,16,17,18,18,19,19,18,15,12,10,9],"Serie1")
8
+ p.add_point([10,11,11,12,12,13,14,15,17,19,22,24,23,23,22,20,18,16,14],"Serie2")
9
+ p.add_point([4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22],"Serie3")
10
+ p.add_all_series
11
+ p.remove_serie("Serie3")
12
+ p.set_abscise_label_serie("Serie3")
13
+ p.set_serie_name("January","Serie1")
14
+ p.set_serie_name("February","Serie2")
15
+ p.set_y_axis_name("Temperature")
16
+ p.set_y_axis_unit("°C")
17
+ p.set_x_axis_unit("h")
18
+
19
+ ch = Rchart.new(700,230)
20
+ ch.draw_graph_area_gradient(132,153,172,50,Rchart::TARGET_BACKGROUND)
21
+ ch.set_font_properties("tahoma.ttf",8)
22
+ ch.set_graph_area(60,20,585,180)
23
+ ch.draw_graph_area(213,217,221,false)
24
+ ch.draw_scale(p.get_data,p.get_data_description,Rchart::SCALE_NORMAL,213,217,221,true,0,2)
25
+ ch.draw_graph_area_gradient(162,183,202,50)
26
+ ch.draw_grid(4,true,230,230,230,20)
27
+
28
+ # Draw the line chart
29
+ ch.set_shadow_properties(3,3,0,0,0,30,4)
30
+ ch.draw_line_graph(p.get_data,p.get_data_description)
31
+ ch.clear_shadow
32
+ ch.draw_plot_graph(p.get_data,p.get_data_description,4,2,-1,-1,-1,true)
33
+
34
+ ch.set_font_properties("tahoma.ttf",8)
35
+ ch.draw_legend(605,142,p.get_data_description,236,238,240,52,58,82)
36
+ title= "Average Temperatures during the first months of 2008 "
37
+ ch.draw_text_box(0,210,700,230,title,0,255,255,255,Rchart::ALIGN_RIGHT,true,0,0,0,30)
38
+ ch.add_border(2)
39
+
40
+ ch.render_png("Example16")