Class: Gruff::Bezier
Overview
Gruff::Bezier is a special line graph that have the bezier curve.
Here’s how to set up a Gruff::Bezier.
dataset = [
+0.00, +0.09, +0.19, +0.29, +0.38, +0.47, +0.56, +0.64, +0.71, +0.78,
+0.84, +0.89, +0.93, +0.96, +0.98, +0.99, +0.99, +0.99, +0.97, +0.94,
+0.90, +0.86, +0.80, +0.74, +0.67, +0.59, +0.51, +0.42, +0.33, +0.23,
+0.14, +0.04, -0.06, -0.16, -0.26, -0.36, -0.45, -0.53, -0.62, -0.69,
-0.76, -0.82, -0.88, -0.92, -0.96, -0.98, -1.00, -1.00, -1.00, -0.99,
-0.96, -0.93, -0.89, -0.84, -0.78, -0.71, -0.64, -0.56, -0.47, -0.38,
]
g = Gruff::Bezier.new
g.data 'sin', dataset
g.write('bezier.png')
Constant Summary
Constants inherited from Base
Gruff::Base::DEFAULT_MARGIN, Gruff::Base::DEFAULT_TARGET_WIDTH, Gruff::Base::LABEL_MARGIN, Gruff::Base::LEGEND_MARGIN
Instance Attribute Summary
Attributes inherited from Base
#bold_title, #bottom_margin, #center_labels_over_point, #colors, #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_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, #font=, #initialize, #margins=, #replace_colors, #theme=, #theme_37signals, #theme_greyscale, #theme_keynote, #theme_odeo, #theme_pastel, #theme_rails_keynote, #to_blob, #to_image, #write
Constructor Details
This class inherits a constructor from Gruff::Base
Instance Method Details
#draw ⇒ Object
22 23 24 25 26 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 |
# File 'lib/gruff/bezier.rb', line 22 def draw super return unless data_given? x_increment = @graph_width / (column_count - 1).to_f store.norm_data.each do |data_row| poly_points = [] data_row[1].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) if index == 0 && RUBY_PLATFORM != 'java' poly_points << new_x poly_points << new_y end poly_points << new_x poly_points << new_y draw_label(new_x, index) end stroke_width = clip_value_if_greater_than(@columns / (store.norm_data.first[1].size * 4), 5.0) if RUBY_PLATFORM == 'java' Gruff::Renderer::Polyline.new(color: data_row.color, width: stroke_width).render(poly_points) else Gruff::Renderer::Bezier.new(color: data_row.color, width: stroke_width).render(poly_points) end end end |