def draw_data
minvalue = min_value
fieldheight = (@graph_height.to_f - font_size*2*top_font) /
(get_y_labels.max - get_y_labels.min)
fieldwidth = field_width
line = @data.length
prev_sum = Array.new(@config[:fields].length).fill(0)
cum_sum = Array.new(@config[:fields].length).fill(-minvalue)
for data in @data.reverse
lpath = ""
apath = ""
if not stacked then cum_sum.fill(-minvalue) end
data[:data].each_index do |i|
cum_sum[i] += data[:data][i]
c = calc_coords(i, cum_sum[i], fieldwidth, fieldheight)
lpath << "#{c[:x]} #{c[:y]} "
end
if area_fill
if stacked then
(prev_sum.length - 1).downto 0 do |i|
c = calc_coords(i, prev_sum[i], fieldwidth, fieldheight)
apath << "#{c[:x]} #{c[:y]} "
end
c = calc_coords(0, prev_sum[0], fieldwidth, fieldheight)
else
apath = "V#@graph_height"
c = calc_coords(0, 0, fieldwidth, fieldheight)
end
@graph.add_element("path", {
"d" => "M#{c[:x]} #{c[:y]} L" + lpath + apath + "Z",
"class" => "fill#{line}"
})
end
@graph.add_element("path", {
"d" => "M0 #@graph_height L" + lpath,
"class" => "line#{line}"
})
if show_data_points || show_data_values
cum_sum.each_index do |i|
if show_data_points
@graph.add_element( "circle", {
"cx" => (fieldwidth * i).to_s,
"cy" => (@graph_height - cum_sum[i] * fieldheight).to_s,
"r" => "2.5",
"class" => "dataPoint#{line}"
})
end
make_datapoint_text(
fieldwidth * i,
@graph_height - cum_sum[i] * fieldheight - 6,
cum_sum[i] + minvalue
)
end
end
prev_sum = cum_sum.dup
line -= 1
end
end