Class: Scruffy::Components::DataMarkers
- Includes:
- Helpers::Marker
- Defined in:
- lib/scruffy/components/data_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 included from Helpers::Marker
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.
8 9 10 |
# File 'lib/scruffy/components/data_markers.rb', line 8 def markers @markers end |
Instance Method Details
#draw(svg, bounds, options = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/scruffy/components/data_markers.rb', line 10 def draw(svg, bounds, ={}) if [:calculate_markers] && ([:point_markers].nil? || [:point_markers].empty?) markers = ([:markers] || self.markers) || 5 [:point_markers] = [] each_marker(markers, [:min_key], [:max_key], bounds[:width], , :key_formatter) do |label, x| [:point_markers] << label end end unless [:point_markers].nil? # Updated to set the label in line with the point. point_distance = bounds[:width] / ([:point_markers].size).to_f (0...[:point_markers].size).map do |idx| x_coord = point_distance * idx + point_distance/2 if [:point_markers_ticks] svg.line(:x1 => x_coord, :y1 => 0, :x2 => x_coord, :y2 => -2, :style => "stroke:#{([:theme].marker || 'white').to_s}, stroke-width:1") end svg.text([:point_markers][idx], :x => 0, :y => 0, 'font-size' => [:theme].marker_font_size || relative(90), 'font-family' => [:theme].font_family, :transform => "translate(#{x_coord},#{bounds[:height]}) rotate(#{[:point_markers_rotation] || 0})", :fill => ([:theme].marker || 'white').to_s, 'text-anchor' => 'middle') unless [:point_markers][idx].nil? end end end |