Class: Scruffy::Components::ValueMarkers
- Defined in:
- lib/scruffy/components/value_markers.rb
Instance Attribute Summary collapse
-
#markers ⇒ Object
Returns the value of attribute markers.
Attributes inherited from Base
#id, #options, #position, #size, #visible
Instance Method Summary collapse
Methods inherited from Base
#initialize, #process, #render
Constructor Details
This class inherits a constructor from Scruffy::Components::Base
Instance Attribute Details
#markers ⇒ Object
Returns the value of attribute markers.
4 5 6 |
# File 'lib/scruffy/components/value_markers.rb', line 4 def markers @markers end |
Instance Method Details
#draw(svg, bounds, options = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/scruffy/components/value_markers.rb', line 6 def draw(svg, bounds, ={}) markers = ([:markers] || self.markers) || 5 all_values = [] (0...markers).each do |idx| marker = ((1 / (markers - 1).to_f) * idx) * bounds[:height] all_values << ([:max_value] - [:min_value]) * ((1 / (markers - 1).to_f) * idx) + [:min_value] end (0...markers).each do |idx| marker = ((1 / (markers - 1).to_f) * idx) * bounds[:height] marker_value = ([:max_value] - [:min_value]) * ((1 / (markers - 1).to_f) * idx) + [:min_value] marker_value = [:value_formatter].route_format(marker_value, idx, .merge({:all_values => all_values})) if [:value_formatter] svg.text( marker_value.to_s, :x => bounds[:width], :y => (bounds[:height] - marker), 'font-size' => relative(8), 'font-family' => [:theme].font_family, :fill => ((.delete(:marker_color_override) || [:theme].marker) || 'white').to_s, 'text-anchor' => 'end') end end |