Module: LineChart
- Included in:
- Graph
- Defined in:
- lib/line_chart.rb
Instance Method Summary collapse
-
#draw_filled_line_graph(data, data_description, alpha = 100, around_zero = false) ⇒ Object
You can provide the alpha value used when merging all series layers.
-
#draw_line_graph(data, data_description, serie_name = "") ⇒ Object
This function will draw a line graph using all the registered series.
-
#draw_xy_graph(data, data_description, y_serie_name, x_serie_name, palette_id = 0) ⇒ Object
This function will draw a scatter line graph.
Instance Method Details
#draw_filled_line_graph(data, data_description, alpha = 100, around_zero = false) ⇒ Object
You can provide the alpha value used when merging all series layers. If around_zero is set to true, the area drawn will be between the 0 axis and the line graph value.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/line_chart.rb', line 50 def draw_filled_line_graph(data,data_description,alpha=100,around_zero=false) empty = -2147483647 data_description = self.validate_data_description("draw_filled_line_graph",data_description) self.validate_data("draw_filled_line_graph",data) layer_width = @g_area_x2-@g_area_x1 layer_height = @g_area_y2-@g_area_y1 graph_id = 0 id =0 color_id =0 data_description["values"].each do |col_name| data_description["description"].each do |key_i,value_i| if ( key_i == col_name ) color_id = id id = id+1 end end a_points = [] a_points << @g_area_x_offset a_points << layer_height @layers[0] = image_create_true_color(layer_width,layer_height) c_white = allocate_color(@layers[0],255,255,255) image_filled_rectangle(@layers[0],0,0,layer_width,layer_height,255,255,255) image_color_transparent(@layers[0],255,255,255) xpos = @g_area_x_offset xlast = -1 points_count = 2 y_zero = layer_height - ((0-@vmin) * @division_ratio) y_zero = layer_height if ( y_zero > layer_height ) ylast = empty data.each do |key| value = key[col_name] if key[col_name].is_a?(Numeric) ypos = layer_height - ((value-@vmin) * @division_ratio) else ypos = layer_height - ((0-@vmin) * @division_ratio) end # Save point into the image map if option activated */ if ( @build_map ) #self.add_to_image_map(xpos-3,ypos-3,xpos+3,ypos+3,data_description["description"][col_name],key[col_name].data_description["unit"]["Y"],"FLine") end if ( !(value.is_a?(Numeric))) points_count+=1 a_points << xlast a_points << layer_height ylast = empty else points_count+=1 if ( ylast != empty ) a_points << xpos a_points << ypos else points_count+=1 a_points << xpos a_points << layer_height a_points << xpos a_points << ypos end if (ylast !=empty && around_zero) points = [] points << xlast points << ylast points << xpos points << ypos points << xpos points << y_zero points << xlast points << y_zero c_graph = allocate_color(@layers[0],@palette[color_id]["r"],@palette[color_id]["g"],@palette[color_id]["b"]) image_filled_polygon(@layers[0],points,@palette[color_id]["r"],@palette[color_id]["g"],@palette[color_id]["b"],4) end ylast = ypos end xlast = xpos xpos = xpos + @division_width end a_points << layer_width - @g_area_x_offset a_points << layer_height if ( around_zero == false ) c_graph = allocate_color(@layers[0],@palette[color_id]["r"],@palette[color_id]["g"],@palette[color_id]["b"]) image_filled_polygon(@layers[0],a_points,@palette[color_id]["r"],@palette[color_id]["g"],@palette[color_id]["b"],points_count) end image_copy_merge(@layers[0],@picture,@g_area_x1,@g_area_y1,0,0,layer_width,layer_height,alpha) image_destroy(@layers[0]) graph_id+=1 draw_line_graph(data,data_description,col_name) end end |
#draw_line_graph(data, data_description, serie_name = "") ⇒ Object
This function will draw a line graph using all the registered series.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/line_chart.rb', line 3 def draw_line_graph(data,data_description,serie_name="") data_description = self.validate_data_description("draw_line_graph",data_description) self.validate_data("draw_line_graph",data) graph_id = 0 color_id =0 id =0 data_description["values"].each do |col_name| data_description["description"].each do |key_i,value_i| if ( key_i == col_name ) color_id = id id = id+1 end end if ( serie_name == "" || serie_name == col_name ) x_pos = @g_area_x1 + @g_area_x_offset x_last = -1 y_last = -1 data.each do |key| if(!key[col_name].nil?) value = key[col_name] if(value.is_a?(Numeric)) y_pos= @g_area_y2 - ((value-@vmin) * @division_ratio) else y_pos= @g_area_y2 - ((0-@vmin) * @division_ratio) end # /* Save point into the image map if option activated */ if ( @build_map ) #self.add_to_image_map(x_pos-3,y_pos-3,x_pos+3,y_pos+3,data_description["description"][col_name],data[key][col_name].data_description["unit"]["y"],"Line") end x_last = -1 if(!value.is_a?(Numeric)) if ( x_last != -1 ) self.draw_line(x_last,y_last,x_pos,y_pos,@palette[color_id]["r"],@palette[color_id]["g"],@palette[color_id]["b"],true) end x_last = x_pos y_last = y_pos x_last = -1 if(!value.is_a?(Numeric)) end x_pos = x_pos + @division_width end graph_id+=1 end end end |
#draw_xy_graph(data, data_description, y_serie_name, x_serie_name, palette_id = 0) ⇒ Object
This function will draw a scatter line graph. You must specify the x and y series that will be used. You can optionaly set the color index in the current palette.
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/line_chart.rb', line 147 def draw_xy_graph(data,data_description,y_serie_name,x_serie_name,palette_id=0) y_last = -1 x_last = -1 data.each do |key| if ( !key[y_serie_name].nil? && !key[x_serie_name].nil? ) x = key[x_serie_name] y = key[y_serie_name] y = @g_area_y2 - ((y-@vmin) * @division_ratio) x = @g_area_x1 + ((x-@v_x_min) * @x_division_ratio) if (x_last != -1 && y_last != -1) draw_line(x_last,y_last,x,y,@palette[palette_id]["r"],@palette[palette_id]["g"],@palette[palette_id]["b"],true) end x_last = x y_last = y end end end |