Class: Rubyplot::Area

Inherits:
Artist
  • Object
show all
Defined in:
lib/rubyplot/scripting/area/area.rb

Constant Summary

Constants inherited from Artist

Rubyplot::Artist::DATA_COLOR_INDEX, Rubyplot::Artist::DATA_LABEL_INDEX, Rubyplot::Artist::DATA_VALUES_INDEX, Rubyplot::Artist::DATA_VALUES_X_INDEX, Rubyplot::Artist::DEFAULT_MARGIN, Rubyplot::Artist::DEFAULT_TARGET_WIDTH, Rubyplot::Artist::LABEL_MARGIN, Rubyplot::Artist::LEGEND_MARGIN, Rubyplot::Artist::THOUSAND_SEPARATOR

Instance Attribute Summary

Attributes inherited from Artist

#base_image, #font, #font_color, #has_left_labels, #hide_legend, #hide_line_numbers, #labels, #legend_font_size, #legend_margin, #marker_color, #marker_count, #marker_shadow_color, #maximum_value, #minimum_value, #title, #title_margin, #x_axis_label, #y_axis_label

Instance Method Summary collapse

Methods inherited from Artist

#artist_draw, #calculate_caps_height, #calculate_spread, #calculate_width, #center, #clip_value_if_greater_than, #construct_colors_array, #data, #draw_axis_labels, #draw_label, #draw_legend, #draw_line_markers!, #draw_title, #get_colors_array, #initialize_variables, #normalize, #render_gradiated_background, #reset_themes, #scale, #scale_fontsize, #set_colors_array, #setup_drawing, #setup_graph_measurements, #significant, #sort_norm_data, #sum, #theme=, #write

Constructor Details

#initializeArea

Returns a new instance of Area


2
3
4
5
6
# File 'lib/rubyplot/scripting/area/area.rb', line 2

def initialize(*)
  super
  @sorted_drawing = true
  @all_colors_array = Magick.colors
end

Instance Method Details

#drawObject


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
# File 'lib/rubyplot/scripting/area/area.rb', line 8

def draw
  super
  return unless @geometry.has_data

  @x_increment = @graph_width / (@geometry.column_count - 1).to_f
  @d = @d.stroke 'transparent'

  @geometry.norm_data.each_with_index do |data_row, i|
    poly_points = []
    prev_x = prev_y = 0.0
    @d = @d.fill @plot_colors[i]

    data_row[DATA_VALUES_INDEX].each_with_index do |data_point, index|
      # Use incremented x and scaled y
      new_x = @graph_left + (@x_increment * index)
      new_y = @graph_top + (@graph_height - data_point * @graph_height)

      poly_points << new_x
      poly_points << new_y

      draw_label(new_x, index)

      prev_x = new_x
      prev_y = new_y
    end

    # Add closing points, draw polygon
    poly_points << @graph_right
    poly_points << @graph_bottom - 1
    poly_points << @graph_left
    poly_points << @graph_bottom - 1
    @d.fill_opacity(0.3)
    @d = @d.polyline(*poly_points)
  end

  @d.draw(@base_image)
end