Module: Scruffy::Helpers::Marker

Included in:
Components::DataMarkers, Components::Grid, Components::VGrid, Components::ValueMarkers, Layers::Scatter
Defined in:
lib/scruffy/helpers/marker_helper.rb

Instance Method Summary collapse

Instance Method Details

#each_marker(markers, min, max, width, options, format_key) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/scruffy/helpers/marker_helper.rb', line 5

def each_marker(markers, min, max, width, options, format_key)
   all_values = []

  (0...markers).each do |idx|
    percent = idx.to_f / (markers-1)
    all_values << min + (max - min) * percent
  end

  all_values.size.times do |idx|
    dx = width/(markers - 1)
    
    location = idx.to_f * dx #+ dx/2
    marker_value = all_values[idx]
    marker_value = options[format_key].route_format(marker_value, idx, options.merge({:all_values => all_values})) if options[format_key]

    yield marker_value, location
  end  

end