20: def draw_bars
21:
22:
23:
24: spacing_factor = 0.9
25: @bar_width = @graph_width / (@column_count * @data.length).to_f
26:
27: @d = @d.stroke_opacity 0.0
28:
29:
30: conversion = Gruff::BarConversion.new()
31: conversion.graph_height = @graph_height
32: conversion.graph_top = @graph_top
33:
34:
35: if @minimum_value >= 0 then
36:
37: conversion.mode = 1
38: else
39:
40: if @maximum_value <= 0 then
41: conversion.mode = 2
42: else
43:
44: conversion.mode = 3
45: conversion.spread = @spread
46: conversion.minimum_value = @minimum_value
47: conversion.zero = -@minimum_value/@spread
48: end
49: end
50:
51:
52: @norm_data.each_with_index do |data_row, row_index|
53:
54: data_row[DATA_VALUES_INDEX].each_with_index do |data_point, point_index|
55:
56:
57: left_x = @graph_left + (@bar_width * (row_index + point_index + ((@data.length - 1) * point_index)))
58: right_x = left_x + @bar_width * spacing_factor
59:
60: conv = []
61: conversion.getLeftYRightYscaled( data_point, conv )
62:
63:
64: @d = @d.fill data_row[DATA_COLOR_INDEX]
65: @d = @d.rectangle(left_x, conv[0], right_x, conv[1])
66:
67:
68: label_center = @graph_left +
69: (@data.length * @bar_width * point_index) +
70: (@data.length * @bar_width / 2.0)
71:
72: draw_label(label_center - (@center_labels_over_point ? @bar_width / 2.0 : 0.0), point_index)
73: end
74:
75: end
76:
77:
78: draw_label(@graph_right, @column_count) if @center_labels_over_point
79:
80: @d.draw(@base_image)
81: end