class Scruffy::Components::ValueMarkers
Attributes
markers[RW]
Public Instance Methods
draw(svg, bounds, options={})
click to toggle source
# File lib/scruffy/components/value_markers.rb, line 6 def draw(svg, bounds, options={}) markers = (options[:markers] || self.markers) || 5 all_values = [] (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] 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] svg.text( marker_value.to_s, :x => bounds[:width], :y => (bounds[:height] - marker), 'font-size' => relative(8), 'font-family' => options[:theme].font_family, :fill => ((options.delete(:marker_color_override) || options[:theme].marker) || 'white').to_s, 'text-anchor' => 'end') end end