From: martyntaylor <mtaylor(a)redhat.com>
---
lib/scruffy/components/value_markers.rb | 43 +++++++++++++++++++++----------
lib/scruffy/layers/multi_area.rb | 5 +---
2 files changed, 30 insertions(+), 18 deletions(-)
diff --git a/lib/scruffy/components/value_markers.rb
b/lib/scruffy/components/value_markers.rb
index 219dd1f..56a3c07 100644
--- a/lib/scruffy/components/value_markers.rb
+++ b/lib/scruffy/components/value_markers.rb
@@ -2,31 +2,46 @@ module Scruffy
module Components
class ValueMarkers < Base
attr_accessor :markers
-
+ attr_accessor :marker_values
+
def draw(svg, bounds, options={})
- markers = (options[:markers] || self.markers) || 5
- all_values = []
+ @marker_values = options[:marker_values] ? options[:marker_values] : nil
+ @markers = options[:markers] ? options[:markers] : 5
- (0...markers).each do |idx|
- marker = ((1 / (markers - 1).to_f) * idx) * bounds[:height]
- all_values << (options[:max_value] - options[:min_value]) * ((1 /
(markers - 1).to_f) * idx) + options[:min_value]
+ if @marker_values
+ draw_marker_values(@marker_values, bounds, svg, options)
+ else
+ all_values = []
+ inc = (options[:max_value] - options[:min_value]) / (@markers - 1)
+ for i in 0...@markers
+ all_values << (inc * i)
+ end
+ draw_marker_values(all_values, bounds, svg, options)
end
-
- (0...markers).each do |idx|
- marker = ((1 / (markers - 1).to_f) * idx) * bounds[:height]
- marker_value = (options[:max_value] - options[:min_value]) * ((1 / (markers -
1).to_f) * idx) + options[:min_value]
- marker_value = options[:value_formatter].route_format(marker_value, idx,
options.merge({:all_values => all_values})) if options[:value_formatter]
+ end
+
+ private
+ def draw_marker_values(marker_values, bounds, svg, options={})
+ count = 0
+ marker_values.each do |mv|
+ # The Y co-ordinate of this marker
+ y_coord_unit = bounds[:height] / (options[:max_value] - options[:min_value])
+ marker = y_coord_unit * mv
+
+ # The Value of the Marker
+ marker_value = mv
+ marker_value = options[:value_formatter].route_format(marker_value, count,
options.merge({:all_values => marker_values})) if options[:value_formatter]
+ count = count + 1
svg.text( marker_value.to_s,
:x => bounds[:width],
:y => (bounds[:height] - marker),
- 'font-size' => relative(8),
+ 'font-size' => relative(12),
'font-family' => options[:theme].font_family,
:fill => ((options.delete(:marker_color_override) ||
options[:theme].marker) || 'white').to_s,
'text-anchor' => 'end')
end
-
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/scruffy/layers/multi_area.rb b/lib/scruffy/layers/multi_area.rb
index 10f07e5..ec86b78 100644
--- a/lib/scruffy/layers/multi_area.rb
+++ b/lib/scruffy/layers/multi_area.rb
@@ -25,7 +25,6 @@ module Scruffy::Layers
area_color = @area_colors[0]
color_count = 1
else
- puts "Never Set Area Color"
area_color = color
end
@@ -35,13 +34,11 @@ module Scruffy::Layers
# Draw Lower Area Polygons
if @baselines
# Get the Color of this Area
- puts "Drawing Baselines"
@baselines.sort! {|x,y| y <=> x }
@baselines.each do |baseline|
if color_count
area_color = area_colors[color_count]
color_count = color_count + 1
- puts area_color.to_s
if color_count >= area_colors.size
color_count = 0
end
@@ -116,4 +113,4 @@ module Scruffy::Layers
return (height.to_f - (height.to_f * relative_percent))
end
end
-end
\ No newline at end of file
+end
--
1.7.1.1