rchart 1.2.2 → 2.0.1
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/Rakefile +3 -3
- data/VERSION +1 -1
- data/lib/bar_chart.rb +166 -0
- data/lib/color_palette.rb +56 -0
- data/lib/cubic_chart.rb +271 -0
- data/lib/gd2_helper.rb +161 -0
- data/lib/graph.rb +24 -0
- data/lib/graph_helper.rb +414 -0
- data/lib/layout.rb +247 -0
- data/lib/legend.rb +243 -0
- data/lib/line_chart.rb +164 -0
- data/lib/pie_chart.rb +479 -0
- data/lib/plot_chart.rb +192 -0
- data/lib/rchart.rb +13 -3189
- data/lib/rchart_helper.rb +265 -0
- data/lib/rdata.rb +15 -14
- data/lib/scale.rb +538 -0
- metadata +49 -16
data/lib/gd2_helper.rb
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'gd2-ffij'
|
3
|
+
|
4
|
+
module GD2
|
5
|
+
def image_create_true_color(width,height)
|
6
|
+
# Image::IndexedColor.new(width,height)
|
7
|
+
Image::TrueColor.new(width,height)
|
8
|
+
end
|
9
|
+
|
10
|
+
def add_point(x,y)
|
11
|
+
Canvas::Point.new(x,y)
|
12
|
+
end
|
13
|
+
|
14
|
+
def image_color_allocate(picture,r,g,b)
|
15
|
+
Color.new(r,g,b) # returns an integer value
|
16
|
+
end
|
17
|
+
|
18
|
+
def image_ttf_text(picture,font_size,angle,x_pos,y_pos,fg_color,font_name,string,options={})
|
19
|
+
angle = deg2rad(angle)
|
20
|
+
font = Font::TrueType.new(font_name, font_size,options)
|
21
|
+
point= add_point(x_pos,y_pos)
|
22
|
+
text = Canvas::Text.new(font,point,angle,string)
|
23
|
+
text.draw(picture,fg_color.rgba)
|
24
|
+
end
|
25
|
+
|
26
|
+
# color helper
|
27
|
+
def image_ftb_box(font_size,angle,font_name,string,x=0,y=0,options={})
|
28
|
+
angle = deg2rad(angle)
|
29
|
+
font = Font::TrueType.new(font_name, font_size,options)
|
30
|
+
position = font.bounding_rectangle(string,angle)
|
31
|
+
[position[:lower_left][0],position[:lower_left][1],position[:lower_right][0],position[:lower_right][1],position[:upper_right][0],position[:upper_right][1],position[:upper_left][0],position[:upper_left][1]]
|
32
|
+
end #Compute and draw the scale
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
def image_set_pixel(picture,x,y,r,g,b)
|
37
|
+
color= image_color_allocate(picture,r,g,b)
|
38
|
+
picture.set_pixel(x,y,color.rgba.to_i)
|
39
|
+
end
|
40
|
+
|
41
|
+
def image_color_at(picture,x,y)
|
42
|
+
pixel = picture.get_pixel(x, y)
|
43
|
+
# rgb_color(picture, pixel)
|
44
|
+
end
|
45
|
+
def image_line(picture,x1,y1,x2,y2,r,g,b)
|
46
|
+
color = allocate_color(picture,r,g,b)
|
47
|
+
point1 = add_point(x1,y1)
|
48
|
+
point2 = add_point(x2,y2)
|
49
|
+
line = Canvas::Line.new(point1,point2)
|
50
|
+
line.draw(picture,color)
|
51
|
+
end
|
52
|
+
|
53
|
+
def image_filled_rectangle(picture,x1,y1,x2,y2,r,g,b)
|
54
|
+
color = allocate_color(picture, r, g, b)
|
55
|
+
point1 = add_point(x1,y1)
|
56
|
+
point2 = add_point(x2,y2)
|
57
|
+
filled_rectangle = Canvas::FilledRectangle.new(point1,point2)
|
58
|
+
filled_rectangle.draw(picture,color.rgba)
|
59
|
+
end
|
60
|
+
def image_copy_merge(src_pic,dest_pic, dst_x, dst_y, src_x, src_y, dst_w, dst_h, pct, gray = false)
|
61
|
+
dest_pic.merge_from(src_pic, dst_x, dst_y, src_x, src_y, dst_w, dst_h,pct/100.0)
|
62
|
+
end
|
63
|
+
|
64
|
+
def image_copy(src_pic,dest_pic,dest_x, dest_y, self_x, self_y, width, height)
|
65
|
+
dest_pic.copy_from(src_pic,dest_x, dest_y, self_x, self_y, width, height)
|
66
|
+
end
|
67
|
+
|
68
|
+
def image_color_transparent(im,r,g,b)
|
69
|
+
color = allocate_color(im, r, g, b)
|
70
|
+
# im.save_alpha =true
|
71
|
+
im.transparent = color
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
def image_destroy(image)
|
76
|
+
GD2FFI.gdImageDestroy(image.image_ptr)
|
77
|
+
end
|
78
|
+
|
79
|
+
def image_create_from_png(file_name)
|
80
|
+
Image.import(file_name)
|
81
|
+
end
|
82
|
+
def image_create_from_jpeg(file_name)
|
83
|
+
Image.import(file_name)
|
84
|
+
end
|
85
|
+
def image_create_from_gif(file_name)
|
86
|
+
Image.import(file_name)
|
87
|
+
end
|
88
|
+
def get_image_size(image)
|
89
|
+
[image.width,image.height]
|
90
|
+
end
|
91
|
+
|
92
|
+
def image_filled_polygon(picture,points,r,g,b,points_count=0)
|
93
|
+
color = allocate_color(picture,r,g,b)
|
94
|
+
polygon_points = []
|
95
|
+
i=0
|
96
|
+
if points_count == 0
|
97
|
+
num_points = (points.length+1)
|
98
|
+
else
|
99
|
+
num_points = points_count+points_count
|
100
|
+
end
|
101
|
+
while(i<=num_points)
|
102
|
+
j =i
|
103
|
+
polygon_points << Canvas::Point.new(points[j],points[j+1]) if(!points[j+1].nil?)
|
104
|
+
i = i+2
|
105
|
+
end
|
106
|
+
polygon=Canvas::FilledPolygon.new(polygon_points)
|
107
|
+
polygon.draw(picture,color.to_i)
|
108
|
+
end
|
109
|
+
|
110
|
+
def rgb_color(picture,pixel)
|
111
|
+
color = picture.pixel2color(pixel)
|
112
|
+
[color.r,color.g,color.b]
|
113
|
+
end
|
114
|
+
# render Graph as png format
|
115
|
+
def render_png(file_name,level=9)
|
116
|
+
print_errors(@error_interface) if ( @error_reporting )
|
117
|
+
file = File.new(file_name,"wb")
|
118
|
+
file.write @picture.png(level)
|
119
|
+
file.close
|
120
|
+
end
|
121
|
+
|
122
|
+
def export_image(file_name,options={})
|
123
|
+
@picture.export(file_name,options)
|
124
|
+
end
|
125
|
+
|
126
|
+
#Outputs the image in PNG format as String object.
|
127
|
+
#This method will be especially useful when you want to transmit an image directly to an user(i.e, without first writing it to a file)
|
128
|
+
|
129
|
+
def render_png_str(level=9,img=self.picture)
|
130
|
+
img.png(level)
|
131
|
+
end
|
132
|
+
|
133
|
+
def render_jepeg_str(level=9,img=self.picture)
|
134
|
+
img.png(level)
|
135
|
+
end
|
136
|
+
def render_gif_str(img=self.picture)
|
137
|
+
img.gif
|
138
|
+
end
|
139
|
+
|
140
|
+
def render_wbmp_str(fgcolor,img=self.picture)
|
141
|
+
img.wbmp(fgcolor)
|
142
|
+
end
|
143
|
+
|
144
|
+
def render_gd_str(img=self.picture)
|
145
|
+
img.gd(fgcolor)
|
146
|
+
end
|
147
|
+
# Format flags for Image#gd2
|
148
|
+
# GD2::FMT_RAW
|
149
|
+
# GD2::FMT_COMPRESSED
|
150
|
+
def gd2(fmt= GD2::FMT_RAW,img=self.picture)
|
151
|
+
img.gd2(fmt)
|
152
|
+
end
|
153
|
+
|
154
|
+
# render Graph as jpeg format
|
155
|
+
def render_jpeg(file_name,quality=0)
|
156
|
+
print_errors(@error_interface) if ( @error_reporting )
|
157
|
+
file = File.new(file_name,"wb")
|
158
|
+
file.write @picture.jpeg(quality)
|
159
|
+
file.close
|
160
|
+
end
|
161
|
+
end
|
data/lib/graph.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'cubic_chart'
|
2
|
+
require 'bar_chart'
|
3
|
+
require 'line_chart'
|
4
|
+
require 'plot_chart'
|
5
|
+
require 'pie_chart'
|
6
|
+
require 'rchart_helper'
|
7
|
+
require 'graph_helper'
|
8
|
+
require 'layout'
|
9
|
+
require 'legend'
|
10
|
+
require 'scale'
|
11
|
+
require 'color_palette'
|
12
|
+
module Graph
|
13
|
+
include CubicChart
|
14
|
+
include BarChart
|
15
|
+
include LineChart
|
16
|
+
include PlotChart
|
17
|
+
include PieChart
|
18
|
+
include RchartHelper
|
19
|
+
include GraphHelper
|
20
|
+
include Layout
|
21
|
+
include Legend
|
22
|
+
include Scale
|
23
|
+
include ColorPalette
|
24
|
+
end
|
data/lib/graph_helper.rb
ADDED
@@ -0,0 +1,414 @@
|
|
1
|
+
module GraphHelper
|
2
|
+
# This function can be used to set the background color.
|
3
|
+
# The default graph background color is set to white.
|
4
|
+
def draw_background(r,g,b)
|
5
|
+
b,g,r= validate_color(b, g, r)
|
6
|
+
image_filled_rectangle(@picture,0,0,@x_size,@y_size,r,g,b)
|
7
|
+
end
|
8
|
+
|
9
|
+
# You can use this function to fill the background of the picture or of the graph area with a color gradient pattern.
|
10
|
+
# You must specify the starting color with its r,g,b values, the number of shades to apply with the decay parameter and optionnaly the target that can be :
|
11
|
+
# * Rchart:: TARGET_GRAPHAREA The currently defined graph area
|
12
|
+
# * Rchart:: TARGET_BACKGROUND The whole picture background
|
13
|
+
def draw_graph_area_gradient(r,g,b,decay,target=Rchart::TARGET_GRAPHAREA)
|
14
|
+
b, g, r = validate_color(b, g, r)
|
15
|
+
x1,y1,x2,y2 = 0,0,0,0
|
16
|
+
if ( target == Rchart::TARGET_GRAPHAREA )
|
17
|
+
x1 = @g_area_x1+1
|
18
|
+
x2 = @g_area_x2-1
|
19
|
+
y1 = @g_area_y1+1
|
20
|
+
y2 = @g_area_y2
|
21
|
+
end
|
22
|
+
|
23
|
+
if ( target == Rchart::TARGET_BACKGROUND )
|
24
|
+
x1 = 0
|
25
|
+
x2 = @x_size
|
26
|
+
y1 = 0
|
27
|
+
y2 = @y_size
|
28
|
+
end
|
29
|
+
#Positive gradient
|
30
|
+
if ( decay > 0 )
|
31
|
+
y_step = (y2 - y1 - 2) / decay
|
32
|
+
i=0
|
33
|
+
while i<=decay
|
34
|
+
r-=1
|
35
|
+
g-=1
|
36
|
+
b-=1
|
37
|
+
yi1 = y1 + ( i * y_step )
|
38
|
+
yi2 = ( yi1 + ( i * y_step ) + y_step ).ceil
|
39
|
+
yi2 = y2-1 if ( yi2 >= yi2 )
|
40
|
+
image_filled_rectangle(@picture,x1,yi1,x2,yi2,r,g,b)
|
41
|
+
i=i+1
|
42
|
+
end
|
43
|
+
end
|
44
|
+
# Negative gradient
|
45
|
+
if ( decay < 0 )
|
46
|
+
y_step = (y2 - y1 - 2) / -decay
|
47
|
+
yi1 = y1
|
48
|
+
yi2 = y1+y_step
|
49
|
+
i= -decay
|
50
|
+
while i>=0
|
51
|
+
r+=1
|
52
|
+
g+=1
|
53
|
+
b+=1
|
54
|
+
image_filled_rectangle(@picture,x1,yi1,x2,yi2,r,g,b)
|
55
|
+
yi1+= y_step
|
56
|
+
yi2+= y_step
|
57
|
+
yi2 = y2-1 if ( yi2 >= yi2 )
|
58
|
+
i= i-1
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# This function draw an aliased rectangle
|
65
|
+
# The upper left and bottom right border positions are used as first 4 arguments.
|
66
|
+
# The last 3 parameters are used to set the border color
|
67
|
+
def draw_rectangle(x1, y1, x2, y2, r, g, b)
|
68
|
+
b, g, r = validate_color(b, g, r)
|
69
|
+
c_rectangle = allocate_color(@picture,r, g, b)
|
70
|
+
x1=x1-0.2
|
71
|
+
y1=y1-0.2
|
72
|
+
x2=x2+0.2
|
73
|
+
y2=y2+0.2
|
74
|
+
draw_line(x1,y1,x2,y1,r,g,b)
|
75
|
+
draw_line(x2,y1,x2,y2,r,g,b)
|
76
|
+
draw_line(x2,y2,x1,y2,r,g,b)
|
77
|
+
draw_line(x1,y2,x1,y1,r,g,b)
|
78
|
+
end
|
79
|
+
|
80
|
+
# This function draw an aliased filled rectangle
|
81
|
+
# The upper left and bottom right border positions are used as first 4 arguments. The last R,G,B parameters are used to set the border color.
|
82
|
+
# You can specify if the aliased border will be drawn and the transparency.
|
83
|
+
def draw_filled_rectangle(x1, y1, x2, y2, r, g, b, draw_border=true, alpha=100,no_fall_back=false)
|
84
|
+
x1, x2 = x2, x1 if x2.to_f < x1.to_f
|
85
|
+
y1, y2 = y2, y1 if y2.to_f < y1.to_f
|
86
|
+
b,g,r=validate_color(b, g, r)
|
87
|
+
|
88
|
+
if(alpha == 100)
|
89
|
+
#Process shadows
|
90
|
+
if(@shadow_active && no_fall_back)
|
91
|
+
draw_filled_rectangle(x1+@shadow_x_distance,y1+@shadow_y_distance,x2+@shadow_x_distance,y2+@shadow_y_distance,@shadow_r_color,@shadow_g_color,@shadow_b_color,false,@shadow_alpha,true)
|
92
|
+
if(@shadow_blur != 0)
|
93
|
+
alpha_decay = (@shadow_alpha/ @shadow_blur)
|
94
|
+
i =1
|
95
|
+
while i<=@shadow_blur
|
96
|
+
draw_filled_rectangle(x1+@shadow_x_distance-i/2,y1+@shadow_y_distance-i/2,x2+@shadow_x_distance-i/2,y2+@shadow_y_distance-i/2,@shadow_r_color,@shadow_g_color,@shadow_b_color,false,@shadow_alpha-alpha_decay*i,true)
|
97
|
+
i = i+1
|
98
|
+
end
|
99
|
+
i = 1
|
100
|
+
while i<=@shadow_blur
|
101
|
+
draw_filled_rectangle(x1+@shadow_x_distance+i/2,y1+@shadow_y_distance+i/2,x2+@shadow_x_distance+i/2,y2+@shadow_y_distance+i/2,@shadow_r_color,@shadow_g_color,@shadow_b_color,false,@shadow_alpha-alpha_decay*i,true)
|
102
|
+
i = i+1
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
image_filled_rectangle(@picture,x1.to_f.round,y1.to_f.round,x2.to_f.round,y2.to_f.round,r,g,b)
|
107
|
+
else
|
108
|
+
layer_width = (x2-x1).abs+2
|
109
|
+
layer_height = (y2-y1).abs+2
|
110
|
+
@layers[0] = image_create_true_color(layer_width,layer_height)
|
111
|
+
c_white = allocate_color(@layers[0],255,255,255)
|
112
|
+
image_filled_rectangle(@layers[0],0,0,layer_width,layer_height,255,255,255)
|
113
|
+
image_color_transparent(@layers[0],255,255,255)
|
114
|
+
image_filled_rectangle(@layers[0],1.round,1.round,(layer_width-1).round,(layer_height-1).round,r,g,b)
|
115
|
+
image_copy_merge(@layers[0],@picture,([x1,x2].min-1).round,([y1,y2].min-1).round,0,0,layer_width,layer_height,alpha)
|
116
|
+
#TODO Find out equivalent method
|
117
|
+
image_destroy(@layers[0])
|
118
|
+
end
|
119
|
+
if (draw_border )
|
120
|
+
shadow_settings = @shadow_active
|
121
|
+
@shadow_active = false
|
122
|
+
draw_rectangle(x1,y1,x2,y2,r,g,b)
|
123
|
+
@shadow_active = shadow_settings
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
# This function draw an aliased rectangle with rounded corners
|
128
|
+
# The upper left and bottom right border positions are used as first 4 arguments.
|
129
|
+
# Argument #5 represents the radius of the rounded corner.
|
130
|
+
# The last 3 parameters are used to set the border color.
|
131
|
+
def draw_rounded_rectangle(x1, y1, x2, y2, radius,r, g, b)
|
132
|
+
b, g, r = validate_color(b, g, r)
|
133
|
+
|
134
|
+
c_rectangle = allocate_color(@picture,r,g,b)
|
135
|
+
|
136
|
+
step = 90 / ((3.1418 * radius)/2)
|
137
|
+
i=0
|
138
|
+
while i<=90
|
139
|
+
x = Math.cos((i+180)*3.1418/180) * radius + x1 + radius
|
140
|
+
y = Math.sin((i+180)*3.1418/180) * radius + y1 + radius
|
141
|
+
draw_antialias_pixel(x,y,r,g,b)
|
142
|
+
|
143
|
+
x = Math.cos((i-90)*3.1418/180) * radius + x2 - radius
|
144
|
+
y = Math.sin((i-90)*3.1418/180) * radius + y1 + radius
|
145
|
+
draw_antialias_pixel(x,y,r,g,b)
|
146
|
+
|
147
|
+
x = Math.cos((i)*3.1418/180) * radius + x2 - radius
|
148
|
+
y = Math.sin((i)*3.1418/180) * radius + y2 - radius
|
149
|
+
draw_antialias_pixel(x,y,r,g,b)
|
150
|
+
|
151
|
+
x = Math.cos((i+90)*3.1418/180) * radius + x1 + radius
|
152
|
+
y = Math.sin((i+90)*3.1418/180) * radius + y2 - radius
|
153
|
+
draw_antialias_pixel(x,y,r,g,b)
|
154
|
+
i=i+step
|
155
|
+
end
|
156
|
+
|
157
|
+
x1=x1-0.2
|
158
|
+
y1=y1-0.2
|
159
|
+
x2=x2+0.2
|
160
|
+
y2=y2+0.2
|
161
|
+
draw_line(x1+radius,y1,x2-radius,y1,r,g,b)
|
162
|
+
draw_line(x2,y1+radius,x2,y2-radius,r,g,b)
|
163
|
+
draw_line(x2-radius,y2,x1+radius,y2,r,g,b)
|
164
|
+
draw_line(x1,y2-radius,x1,y1+radius,r,g,b)
|
165
|
+
end
|
166
|
+
# This function draw an aliased filled rectangle with rounded corners
|
167
|
+
# The upper left and bottom right border positions are used as first 4 arguments.
|
168
|
+
# Argument #5 represents the radius of the rounded corner.
|
169
|
+
# The last 3 parameters are used to set the border color.
|
170
|
+
def draw_filled_rounded_rectangle(x1, y1, x2, y2, radius,r, g, b, draw_border=true, alpha=100)
|
171
|
+
b, g, r = validate_color(b, g, r)
|
172
|
+
c_rectangle = allocate_color(@picture,r,g,b)
|
173
|
+
|
174
|
+
step = 90 / ((3.1418 * radius)/2)
|
175
|
+
i=0
|
176
|
+
while i<=90
|
177
|
+
xi1 = Math.cos((i+180)*3.1418/180) * radius + x1 + radius
|
178
|
+
yi1 = Math.sin((i+180)*3.1418/180) * radius + y1 + radius
|
179
|
+
|
180
|
+
xi2 = Math.cos((i-90)*3.1418/180) * radius + x2 - radius
|
181
|
+
yi2 = Math.sin((i-90)*3.1418/180) * radius + y1 + radius
|
182
|
+
|
183
|
+
xi3 = Math.cos((i)*3.1418/180) * radius + x2 - radius
|
184
|
+
yi3 = Math.sin((i)*3.1418/180) * radius + y2 - radius
|
185
|
+
|
186
|
+
xi4 = Math.cos((i+90)*3.1418/180) * radius + x1 + radius
|
187
|
+
yi4 = Math.sin((i+90)*3.1418/180) * radius + y2 - radius
|
188
|
+
|
189
|
+
image_line(@picture,xi1,yi1,x1+radius,yi1,r,g,b)
|
190
|
+
image_line(@picture,x2-radius,yi2,xi2,yi2,r,g,b)
|
191
|
+
image_line(@picture,x2-radius,yi3,xi3,yi3,r,g,b)
|
192
|
+
image_line(@picture,xi4,yi4,x1+radius,yi4,r,g,b)
|
193
|
+
|
194
|
+
draw_antialias_pixel(xi1,yi1,r,g,b)
|
195
|
+
draw_antialias_pixel(xi2,yi2,r,g,b)
|
196
|
+
draw_antialias_pixel(xi3,yi3,r,g,b)
|
197
|
+
draw_antialias_pixel(xi4,yi4,r,g,b)
|
198
|
+
i=i+step
|
199
|
+
end
|
200
|
+
image_filled_rectangle(@picture,x1,y1+radius,x2,y2-radius,r,g,b)
|
201
|
+
image_filled_rectangle(@picture,x1+radius,y1,x2-radius,y2,r,g,b)
|
202
|
+
|
203
|
+
x1=x1-0.2
|
204
|
+
y1=y1-0.2
|
205
|
+
x2=x2+0.2
|
206
|
+
y2=y2+0.2
|
207
|
+
draw_line(x1+radius,y1,x2-radius,y1,r,g,b)
|
208
|
+
draw_line(x2,y1+radius,x2,y2-radius,r,g,b)
|
209
|
+
draw_line(x2-radius,y2,x1+radius,y2,r,g,b)
|
210
|
+
draw_line(x1,y2-radius,x1,y1+radius,r,g,b)
|
211
|
+
end
|
212
|
+
# This function draw an aliased circle at position (xc,yc) with the specified radius.
|
213
|
+
# The last 3 parameters are used to set the border color.
|
214
|
+
# Width is used to draw ellipses.
|
215
|
+
def draw_circle(xc,yc,height,r,g,b,width=0)
|
216
|
+
width = height if ( width == 0 )
|
217
|
+
b, g, r = validate_color(b, g, r)
|
218
|
+
|
219
|
+
c_circle = allocate_color(@picture,r,g,b)
|
220
|
+
step = 360 / (2 * 3.1418 * [width,height].max)
|
221
|
+
i =0
|
222
|
+
while(i<=360)
|
223
|
+
x= Math.cos(i*3.1418/180) * height + xc
|
224
|
+
y = Math.sin(i*3.1418/180) * width + yc
|
225
|
+
draw_antialias_pixel(x,y,r,g,b)
|
226
|
+
i = i+step
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
# This function draw a filled aliased circle at position (xc,yc) with the specified radius.
|
231
|
+
# The last 3 parameters are used to set the border and filling color.
|
232
|
+
# Width is used to draw ellipses.
|
233
|
+
def draw_filled_circle(xc,yc,height,r,g,b,width=0)
|
234
|
+
width = height if ( width == 0 )
|
235
|
+
b, g, r = validate_color(b, g, r)
|
236
|
+
step = 360 / (2 * 3.1418 * [width,height].max)
|
237
|
+
i =90
|
238
|
+
while i<=270
|
239
|
+
x1 = Math.cos(i*3.1418/180) * height + xc
|
240
|
+
y1 = Math.sin(i*3.1418/180) * width + yc
|
241
|
+
x2 = Math.cos((180-i)*3.1418/180) * height + xc
|
242
|
+
y2 = Math.sin((180-i)*3.1418/180) * width + yc
|
243
|
+
draw_antialias_pixel(x1-1,y1-1,r,g,b)
|
244
|
+
draw_antialias_pixel(x2-1,y2-1,r,g,b)
|
245
|
+
image_line(@picture,x1,y1-1,x2-1,y2-1,r,g,b) if ( (y1-1) > yc - [width,height].max )
|
246
|
+
i= i+step
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
# This function draw an aliased ellipse at position (xc,yc) with the specified height and width.
|
251
|
+
# The last 3 parameters are used to set the border color.
|
252
|
+
def draw_ellipse(xc,yc,height,width,r,g,b)
|
253
|
+
draw_circle(xc,yc,height,r,g,b,width)
|
254
|
+
end
|
255
|
+
|
256
|
+
|
257
|
+
# This function draw a filled aliased ellipse at position (xc,yc) with the specified height and width.
|
258
|
+
# The last 3 parameters are used to set the border and filling color.
|
259
|
+
def draw_filled_ellipse(xc,yc,height,width,r,g,b)
|
260
|
+
draw_filled_circle(xc,yc,height,r,g,b,width)
|
261
|
+
end
|
262
|
+
|
263
|
+
# This function will draw an aliased line between points (x1,y1) and (x2,y2).
|
264
|
+
# The last 3 parameters are used to set the line color.
|
265
|
+
# The last optional parameter is used for internal calls made by graphing function.If set to true, only portions of line inside the graph area will be drawn.
|
266
|
+
|
267
|
+
def draw_line(x1,y1,x2,y2,r,g,b,graph_function=false)
|
268
|
+
if ( @line_dot_size > 1 )
|
269
|
+
draw_dotted_line(x1,y1,x2,y2,@line_dot_size,r,g,b,graph_function)
|
270
|
+
else
|
271
|
+
b, g, r = validate_color(b, g, r)
|
272
|
+
distance = Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)) rescue 0
|
273
|
+
if ( distance == 0 )
|
274
|
+
return -1
|
275
|
+
else
|
276
|
+
x_step = (x2-x1) / distance
|
277
|
+
y_step = (y2-y1) / distance
|
278
|
+
i =0
|
279
|
+
while i<=distance
|
280
|
+
x = i * x_step + x1
|
281
|
+
y = i * y_step + y1
|
282
|
+
if((x >= @g_area_x1.to_f && x <= @g_area_x2.to_f && y >= @g_area_y1.to_f && y <= @g_area_y2.to_f) || !graph_function )
|
283
|
+
if ( @line_width == 1 )
|
284
|
+
draw_antialias_pixel(x,y,r,g,b)
|
285
|
+
else
|
286
|
+
start_offset = -(@line_width/2)
|
287
|
+
end_offset = (@line_width/2)
|
288
|
+
j = start_offset
|
289
|
+
|
290
|
+
while j<=end_offset
|
291
|
+
draw_antialias_pixel(x+j,y+j,r,g,b)
|
292
|
+
j+=1
|
293
|
+
end
|
294
|
+
end
|
295
|
+
end
|
296
|
+
i =i+1
|
297
|
+
end
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end
|
301
|
+
# This function will draw an alpha pixel at position (x,y).
|
302
|
+
# alpha is used to specify the transparency factor ( between 0 and 100 )
|
303
|
+
# The last 3 parameters are used to set the pixel color.
|
304
|
+
def draw_alpha_pixel(x,y,alpha,r,g,b)
|
305
|
+
b, g, r = validate_color(b, g, r)
|
306
|
+
if ( x < 0 || y < 0 || x >= @x_size || y >= @y_size )
|
307
|
+
#eturn(-1)
|
308
|
+
#TODO check image_color_at method is right?
|
309
|
+
else
|
310
|
+
rgb2= image_color_at(@picture, x, y)
|
311
|
+
r2 = (rgb2 >> 16) & 0xFF
|
312
|
+
g2 = (rgb2 >> 8) & 0xFF
|
313
|
+
b2 = rgb2 & 0xFF
|
314
|
+
i_alpha = (100 - alpha)/100
|
315
|
+
alpha = alpha / 100
|
316
|
+
ra = (r*alpha+r2*i_alpha).floor
|
317
|
+
ga = (g*alpha+g2*i_alpha).floor
|
318
|
+
ba = (b*alpha+b2*i_alpha).floor
|
319
|
+
image_set_pixel(@picture,x,y,ra,ga,ba)
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
# This function will draw an aliased dotted line between points (x1,y1) and (x2,y2).
|
324
|
+
# Parameter #5 is used to specify the dot size ( 2 will draw 1 point every 2 points )
|
325
|
+
# The last 3 parameters are used to set the line color.
|
326
|
+
def draw_dotted_line(x1,y1,x2,y2,dot_size,r,g,b,graph_function=false)
|
327
|
+
b, g, r = validate_color(b, g, r)
|
328
|
+
distance = Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))
|
329
|
+
x_step = (x2-x1) / distance
|
330
|
+
y_step = (y2-y1) / distance
|
331
|
+
dot_index = 0
|
332
|
+
i = 0
|
333
|
+
start_offset = 0
|
334
|
+
|
335
|
+
while(i<=distance)
|
336
|
+
x = i * x_step + x1
|
337
|
+
y = i * y_step + y1
|
338
|
+
if ( dot_index <= dot_size)
|
339
|
+
if ( (x >= @g_area_x1 && x <= @g_area_x2 && y >= @g_area_y1 && y <= @g_area_y2) || !graph_function )
|
340
|
+
if (@line_width == 1 )
|
341
|
+
draw_antialias_pixel(x,y,r,g,b)
|
342
|
+
else
|
343
|
+
start_offset = start_offset -(@line_width/2)
|
344
|
+
end_offset = (@line_width/2)
|
345
|
+
j = start_offset
|
346
|
+
while(j<= end_offset)
|
347
|
+
draw_antialias_pixel(x+j,y+j,r,g,b)
|
348
|
+
j= j+1
|
349
|
+
end
|
350
|
+
end
|
351
|
+
end
|
352
|
+
end
|
353
|
+
dot_index = dot_index+1
|
354
|
+
dot_index = 0 if (dot_index == dot_size * 2)
|
355
|
+
i= i+1
|
356
|
+
end
|
357
|
+
|
358
|
+
end
|
359
|
+
# Private functions for internal processing Internal function.
|
360
|
+
def draw_antialias_pixel(x,y,r,g,b,alpha=100,no_fall_back=false)
|
361
|
+
#Process shadows
|
362
|
+
if(@shadow_active && !no_fall_back)
|
363
|
+
draw_antialias_pixel(x+@shadow_x_distance,y+@shadow_y_distance,@shadow_r_color,@shadow_g_color,@shadow_b_color,@shadow_alpha,true)
|
364
|
+
if(@shadow_blur != 0)
|
365
|
+
alpha_decay = (@shadow_alpha*1.0 / @shadow_blur)
|
366
|
+
i=1
|
367
|
+
while i<=@shadow_blur
|
368
|
+
draw_antialias_pixel(x+@shadow_x_distance-i/2,y+@shadow_y_distance-i/2,@shadow_r_color,@shadow_g_color,@shadow_b_color,@shadow_alpha-alpha_decay*i,true)
|
369
|
+
i = i+1
|
370
|
+
end
|
371
|
+
i =1
|
372
|
+
while i<=@shadow_blur
|
373
|
+
draw_antialias_pixel(x+@shadow_x_distance+i/2,y+@shadow_y_distance+i/2,@shadow_r_color,@shadow_g_color,@shadow_b_color,@shadow_alpha-alpha_decay*i,true)
|
374
|
+
i = i+1
|
375
|
+
end
|
376
|
+
end
|
377
|
+
end
|
378
|
+
b, g, r = validate_color(b, g, r)
|
379
|
+
plot = ""
|
380
|
+
xi = x.floor rescue 0
|
381
|
+
yi = y.floor rescue 0
|
382
|
+
if ( xi == x && yi == y)
|
383
|
+
if ( alpha == 100 )
|
384
|
+
image_set_pixel(@picture,x,y,r,g,b)
|
385
|
+
else
|
386
|
+
draw_alpha_pixel(x,y,alpha,r,g,b)
|
387
|
+
end
|
388
|
+
else
|
389
|
+
if xi > 0 || yi > 0 #soe error occures therefor added condtion
|
390
|
+
alpha1 = (((1 - (x - x.floor)) * (1 - (y - y.floor)) * 100) / 100) * alpha
|
391
|
+
draw_alpha_pixel(xi,yi,alpha1,r,g,b) if alpha1 > @anti_alias_quality
|
392
|
+
alpha2 = (((x - x.floor) * (1 - (y - y.floor)) * 100) / 100) * alpha
|
393
|
+
draw_alpha_pixel(xi+1,yi,alpha2,r,g,b) if alpha2 > @anti_alias_quality
|
394
|
+
alpha3 = (((1 - (x - x.floor)) * (y - y.floor) * 100) / 100) * alpha
|
395
|
+
draw_alpha_pixel(xi,yi+1,alpha3,r,g,b) if alpha3 > @anti_alias_quality
|
396
|
+
alpha4 = (((x - x.floor) * (y - y.floor) * 100) / 100) * alpha
|
397
|
+
draw_alpha_pixel(xi+1,yi+1,alpha4,r,g,b) if alpha4 > @anti_alias_quality
|
398
|
+
end
|
399
|
+
end
|
400
|
+
end
|
401
|
+
|
402
|
+
# Activate the image map creation process Internal function
|
403
|
+
def set_image_map(mode=true,graph_id="MyGraph")
|
404
|
+
@build_map = mode
|
405
|
+
@map_id = graph_id
|
406
|
+
end
|
407
|
+
# Add a box into the image map Internal function
|
408
|
+
def add_to_image_map(x1,y1,x2,y2,serie_name,value,caller_function)
|
409
|
+
if ( @map_function == nil || @map_function == caller_function )
|
410
|
+
@image_map << (x1.round).to_s+","+(y1.round).to_s+","+(x2.round).to_s+","+(y2.round).to_s+","+serie_name+","+value.to_s
|
411
|
+
@map_function = caller_function
|
412
|
+
end
|
413
|
+
end
|
414
|
+
end
|