| Class | Gruff::PhotoBar |
| In: |
lib/gruff/photo_bar.rb
|
| Parent: | Gruff::Base |
EXPERIMENTAL!
Doesn‘t work yet.
| theme | [R] | The name of a pre-packaged photo-based theme. |
def initialize(target_width=800)
super init_photo_bar_graphics()
end
# File lib/gruff/photo_bar.rb, line 26
26: def draw
27: super
28: return unless @has_data
29:
30: return # TODO Remove for further development
31:
32: init_photo_bar_graphics()
33:
34: #Draw#define_clip_path()
35: #Draw#clip_path(pathname)
36: #Draw#composite....with bar graph image OverCompositeOp
37: #
38: # See also
39: #
40: # Draw.pattern # define an image to tile as the filling of a draw object
41: #
42:
43: # Setup spacing.
44: #
45: # Columns sit side-by-side.
46: spacing_factor = 0.9
47: @bar_width = @norm_data[0][DATA_COLOR_INDEX].columns
48:
49: @norm_data.each_with_index do |data_row, row_index|
50:
51: data_row[DATA_VALUES_INDEX].each_with_index do |data_point, point_index|
52: data_point = 0 if data_point.nil?
53: # Use incremented x and scaled y
54: left_x = @graph_left + (@bar_width * (row_index + point_index + ((@data.length - 1) * point_index)))
55: left_y = @graph_top + (@graph_height - data_point * @graph_height) + 1
56: right_x = left_x + @bar_width * spacing_factor
57: right_y = @graph_top + @graph_height - 1
58:
59: bar_image_width = data_row[DATA_COLOR_INDEX].columns
60: bar_image_height = right_y.to_f - left_y.to_f
61:
62: # Crop to scale for data
63: bar_image = data_row[DATA_COLOR_INDEX].crop(0, 0, bar_image_width, bar_image_height)
64:
65: @d.gravity = NorthWestGravity
66: @d = @d.composite(left_x, left_y, bar_image_width, bar_image_height, bar_image)
67:
68: # Calculate center based on bar_width and current row
69: label_center = @graph_left + (@data.length * @bar_width * point_index) + (@data.length * @bar_width / 2.0)
70: draw_label(label_center, point_index)
71: end
72:
73: end
74:
75: @d.draw(@base_image)
76: end
Sets up colors with a list of images that will be used. Images should be 340px tall
# File lib/gruff/photo_bar.rb, line 88
88: def init_photo_bar_graphics
89: color_list = Array.new
90: theme_dir = File.dirname(__FILE__) + '/../../assets/' + theme
91:
92: Dir.open(theme_dir).each do |file|
93: next unless /\.png$/.match(file)
94: color_list << Image.read("#{theme_dir}/#{file}").first
95: end
96: @colors = color_list
97: end