Class: Gruff::PhotoBar

Inherits:
Base
  • Object
show all
Defined in:
lib/gruff/photo_bar.rb

Overview

EXPERIMENTAL!

Doesn’t work yet.

Constant Summary

Constants inherited from Base

Base::DEFAULT_MARGIN, Base::DEFAULT_TARGET_WIDTH, Base::LABEL_MARGIN, Base::LEGEND_MARGIN

Instance Attribute Summary collapse

Attributes inherited from Base

#bold_title, #bottom_margin, #center_labels_over_point, #colors, #font, #font_color, #has_left_labels, #hide_legend, #hide_line_markers, #hide_line_numbers, #hide_title, #label_max_size, #label_stagger_height, #label_truncation_style, #labels, #left_margin, #legend_at_bottom, #legend_box_size, #legend_font_size, #legend_margin, #marker_color, #marker_count, #marker_font_size, #marker_shadow_color, #maximum_value, #minimum_value, #no_data_message, #right_margin, #sort, #sorted_drawing, #title, #title_font, #title_font_size, #title_margin, #top_margin, #use_data_label, #x_axis_increment, #x_axis_label, #y_axis_increment, #y_axis_label

Instance Method Summary collapse

Methods inherited from Base

#add_color, #data, #initialize, #margins=, #replace_colors, #theme=, #theme_37signals, #theme_greyscale, #theme_keynote, #theme_odeo, #theme_pastel, #theme_rails_keynote, #to_blob, #write

Constructor Details

This class inherits a constructor from Gruff::Base

Instance Attribute Details

#themeObject (readonly)

Return the chosen theme or the default



20
21
22
# File 'lib/gruff/photo_bar.rb', line 20

def theme
  @theme
end

Instance Method Details

#drawObject

def initialize(target_width=800)

  super
  init_photo_bar_graphics()
end


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
# File 'lib/gruff/photo_bar.rb', line 27

def draw
  super
  return unless data_given?

  return # TODO: Remove for further development

  init_photo_bar_graphics

  #Draw#define_clip_path()
  #Draw#clip_path(pathname)
  #Draw#composite....with bar graph image OverCompositeOp
  #
  # See also
  #
  # Draw.pattern # define an image to tile as the filling of a draw object
  #

  # Setup spacing.
  #
  # Columns sit side-by-side.
  spacing_factor = 0.9
  bar_width = store.norm_data[0].color.columns

  store.norm_data.each_with_index do |data_row, row_index|
    data_row.points.each_with_index do |data_point, point_index|
      data_point = 0 if data_point.nil?
      # Use incremented x and scaled y
      left_x = @graph_left + (bar_width * (row_index + point_index + ((store.length - 1) * point_index)))
      left_y = @graph_top + (@graph_height - data_point * @graph_height) + 1
      right_x = left_x + bar_width * spacing_factor
      right_y = @graph_top + @graph_height - 1

      bar_image_width = data_row.color.columns
      bar_image_height = right_y.to_f - left_y.to_f

      # Crop to scale for data
      bar_image = data_row.color.crop(0, 0, bar_image_width, bar_image_height)

      @d.gravity = Magick::NorthWestGravity
      @d.composite(left_x, left_y, bar_image_width, bar_image_height, bar_image)

      # Calculate center based on bar_width and current row
      label_center = @graph_left + (store.length * bar_width * point_index) + (store.length * bar_width / 2.0)
      draw_label(label_center, point_index)
    end
  end

  Gruff::Renderer.finish
end