Skip to content
Browse files

Add attr_accessors for dot_radius and line_width on Line and Net grap…

…hs that override the calculated values.
  • Loading branch information...
1 parent deedb4f commit dbbd5efd87792587f11454dde5ac9b85f68b350e @jcoglan jcoglan committed Aug 15, 2009
Showing with 18 additions and 4 deletions.
  1. +8 −2 lib/gruff/line.rb
  2. +8 −2 lib/gruff/net.rb
  3. +2 −0 test/test_line.rb
View
10 lib/gruff/line.rb
@@ -19,6 +19,10 @@ class Gruff::Line < Gruff::Base
# Color of the baseline
attr_accessor :baseline_color
+
+ # Dimensions of lines and dots; calculated based on dataset size if left unspecified
+ attr_accessor :line_width
+ attr_accessor :dot_radius
# Hide parts of the graph to fit more datapoints, or for a different appearance.
attr_accessor :hide_dots, :hide_lines
@@ -81,10 +85,12 @@ def draw
@d = @d.stroke data_row[DATA_COLOR_INDEX]
@d = @d.fill data_row[DATA_COLOR_INDEX]
@d = @d.stroke_opacity 1.0
- @d = @d.stroke_width clip_value_if_greater_than(@columns / (@norm_data.first[DATA_VALUES_INDEX].size * 4), 5.0)
+ @d = @d.stroke_width line_width ||
+ clip_value_if_greater_than(@columns / (@norm_data.first[DATA_VALUES_INDEX].size * 4), 5.0)
- circle_radius = clip_value_if_greater_than(@columns / (@norm_data.first[DATA_VALUES_INDEX].size * 2.5), 5.0)
+ circle_radius = dot_radius ||
+ clip_value_if_greater_than(@columns / (@norm_data.first[DATA_VALUES_INDEX].size * 2.5), 5.0)
if !@hide_lines and !prev_x.nil? and !prev_y.nil? then
@d = @d.line(prev_x, prev_y, new_x, new_y)
View
10 lib/gruff/net.rb
@@ -6,6 +6,10 @@ class Gruff::Net < Gruff::Base
# Hide parts of the graph to fit more datapoints, or for a different appearance.
attr_accessor :hide_dots
+
+ # Dimensions of lines and dots; calculated based on dataset size if left unspecified
+ attr_accessor :line_width
+ attr_accessor :dot_radius
def initialize(*args)
super
@@ -25,10 +29,12 @@ def draw
@center_y = @graph_top + (@graph_height / 2.0) - 10 # Move graph up a bit
@x_increment = @graph_width / (@column_count - 1).to_f
- circle_radius = clip_value_if_greater_than(@columns / (@norm_data.first[DATA_VALUES_INDEX].size * 2.5), 5.0)
+ circle_radius = dot_radius ||
+ clip_value_if_greater_than(@columns / (@norm_data.first[DATA_VALUES_INDEX].size * 2.5), 5.0)
@d = @d.stroke_opacity 1.0
- @d = @d.stroke_width clip_value_if_greater_than(@columns / (@norm_data.first[DATA_VALUES_INDEX].size * 4), 5.0)
+ @d = @d.stroke_width line_width ||
+ clip_value_if_greater_than(@columns / (@norm_data.first[DATA_VALUES_INDEX].size * 4), 5.0)
if (defined?(@norm_baseline)) then
level = @graph_top + (@graph_height - @norm_baseline * @graph_height)
View
2 test/test_line.rb
@@ -132,6 +132,8 @@ def test_line_large_values
g.title = "Very Large Values Line Graph Test"
g.baseline_value = 50_000
g.baseline_color = 'green'
+ g.dot_radius = 15
+ g.line_width = 3
@datasets.each do |data|
g.data(data[0], data[1])
end

0 comments on commit dbbd5ef

Please sign in to comment.
Something went wrong with that request. Please try again.