Class: Gruff::Bubble

Inherits:
Scatter show all
Defined in:
lib/gruff/bubble.rb

Overview

Here’s how to set up a Gruff::Bubble.

g = Gruff::Bubble.new
g.title = 'Bubble plot'
g.write('bubble.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 collapse

Attributes inherited from Scatter

#circle_radius, #maximum_x_value, #minimum_x_value, #show_vertical_markers, #stroke_width

Attributes inherited from Base

#bottom_margin, #colors, #hide_legend, #hide_line_markers, #hide_line_numbers, #hide_title, #label_margin, #label_max_size, #label_truncation_style, #left_margin, #legend_at_bottom, #legend_box_size, #legend_margin, #marker_color, #marker_shadow_color, #maximum_value, #minimum_value, #no_data_message, #right_margin, #sort, #sorted_drawing, #title_margin, #top_margin, #x_axis_increment, #x_axis_label_format, #y_axis_increment, #y_axis_label_format

Instance Method Summary collapse

Methods inherited from Scatter

#disable_significant_rounding_x_axis=, #enable_vertical_line_markers=, #use_vertical_x_labels=, #x_label_margin=

Methods inherited from Base

#add_color, #bold_title=, #draw, #font=, #font_color=, #initialize, #label_rotation=, #label_stagger_height=, #labels=, #legend_font_size=, #margins=, #marker_font_size=, #replace_colors, #theme=, #theme_37signals, #theme_greyscale, #theme_keynote, #theme_odeo, #theme_pastel, #theme_rails_keynote, #title=, #title_font=, #title_font_size=, #to_blob, #to_image, #transparent_background=, #write

Constructor Details

This class inherits a constructor from Gruff::Base

Instance Attribute Details

#fill_opacity=(value) ⇒ Object (writeonly)

Specifies the filling opacity in area graph. Default is 0.6.



12
13
14
# File 'lib/gruff/bubble.rb', line 12

def fill_opacity=(value)
  @fill_opacity = value
end

#stroke_width=(value) ⇒ Object (writeonly)

Specifies the stroke width in line. Default is 1.0.



15
16
17
# File 'lib/gruff/bubble.rb', line 15

def stroke_width=(value)
  @stroke_width = value
end

Instance Method Details

#data(name, x_data_points = [], y_data_points = [], point_sizes = [], color = nil) ⇒ Object

Note:

If you want to use a preset theme, you must set it before calling #data.

The first parameter is the name of the dataset. The next two are the x and y axis data points contain in their own array in that respective order. The 4th argument represents sizes of points. The final parameter is the color.

Can be called multiple times with different datasets for a multi-valued graph.

If the color argument is nil, the next color from the default theme will be used.

Examples:

g = Gruff::Bubble.new
g.title = "Bubble Graph"
g.data :A, [-1, 19, -4, -23], [-35, 21, 23, -4], [4.5, 1.0, 2.1, 0.9]

Parameters:

  • name (String, Symbol)

    containing the name of the dataset.

  • x_data_points (Array) (defaults to: [])

    An Array of x-axis data points.

  • y_data_points (Array) (defaults to: [])

    An Array of y-axis data points.

  • point_sizes (Array) (defaults to: [])

    An Array of sizes for points.

  • color (String) (defaults to: nil)

    The hex string for the color of the dataset. Defaults to nil.

Raises:

  • (ArgumentError)

    Data points contain nil values. This error will get raised if either the x or y axis data points array contains a nil value. The graph will not make an assumption as how to graph nil.

  • (ArgumentError)

    x_data_points is empty. This error is raised when the array for the x-axis points are empty

  • (ArgumentError)

    y_data_points is empty. This error is raised when the array for the y-axis points are empty.

  • (ArgumentError)

    point_sizes is empty. This error is raised when the array for the point_sizes are empty

  • (ArgumentError)

    x_data_points.length != y_data_points.length. Error means that the x and y axis point arrays do not match in length.

  • (ArgumentError)

    x_data_points.length != point_sizes.length. Error means that the x and point_sizes arrays do not match in length.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/gruff/bubble.rb', line 56

def data(name, x_data_points = [], y_data_points = [], point_sizes = [], color = nil)
  # make sure it's an array
  x_data_points = Array(x_data_points)
  y_data_points = Array(y_data_points)
  point_sizes   = Array(point_sizes)

  raise ArgumentError, 'Data Points contain nil Value!' if x_data_points.include?(nil) || y_data_points.include?(nil)
  raise ArgumentError, 'x_data_points is empty!' if x_data_points.empty?
  raise ArgumentError, 'y_data_points is empty!' if y_data_points.empty?
  raise ArgumentError, 'point_sizes is empty!'   if point_sizes.empty?
  raise ArgumentError, 'x_data_points.length != y_data_points.length!' if x_data_points.length != y_data_points.length
  raise ArgumentError, 'x_data_points.length != point_sizes.length!'   if x_data_points.length != point_sizes.length

  store.add(name, x_data_points, y_data_points, point_sizes, color)
end