class ActiveCharts::XYChart

Constants

OFFSET

Attributes

section_height[R]
section_width[R]
x_label_y[R]
x_labels[R]
x_max[R]
x_min[R]
x_ticks[R]
y_label_x[R]
y_labels[R]
y_max[R]
y_min[R]
y_ticks[R]

Public Class Methods

new(collection, options = {}) click to toggle source
Calls superclass method ActiveCharts::RectangularChart::new
# File lib/active_charts/xy_chart.rb, line 5
def initialize(collection, options = {})
  super
  
  section_calcs
  tick_calcs
end

Public Instance Methods

bottom_label_text_tags() click to toggle source
# File lib/active_charts/xy_chart.rb, line 23
def bottom_label_text_tags
  x_labels.map.with_index do |label, index| 
    label = formatted_val(label, data_formatters[0])
    classes = 'ac-x-label'
    classes += ' anchor_start' if index.zero?
  
    tag.text(label, x: x_tick_x(index), y: x_label_y, class: classes)
  end.join
end
side_label_text_tags() click to toggle source
# File lib/active_charts/xy_chart.rb, line 15
def side_label_text_tags
  y_labels.map.with_index do |label, index| 
    label = formatted_val(label, data_formatters[1])
    
    tag.text(label, x: y_label_x, y: y_tick_y(index), class: 'ac-y-label')
  end.join
end

Private Instance Methods

height_calcs(values) click to toggle source
# File lib/active_charts/xy_chart.rb, line 51
def height_calcs(values)
  @grid_height = svg_height - label_height * 2
  @y_min, @y_max, y_step = Util.scale(values.min, values.max)
  @y_labels = (y_min..y_max).step(y_step)
end
label_classes() click to toggle source
# File lib/active_charts/xy_chart.rb, line 87
def label_classes
  [css_class + '-label', 'ac-toggleable'].join(' ')
end
prereq_calcs() click to toggle source
# File lib/active_charts/xy_chart.rb, line 35
def prereq_calcs
  @collection = collection.map do |row| 
    row.map { |x, y| [Util.safe_to_dec(x), Util.safe_to_dec(y)] } 
  end
end
section_calcs() click to toggle source
# File lib/active_charts/xy_chart.rb, line 57
def section_calcs
  @section_width = grid_width.to_d / (x_labels.count - 1)
  @section_height = grid_height.to_d / (y_labels.count - 1)
end
tick_calcs() click to toggle source
# File lib/active_charts/xy_chart.rb, line 62
def tick_calcs
  @x_label_y = x_axis_y
  @y_label_x = y_axis_x
  @x_ticks = (1..x_labels.size - 2).map { |i| x_tick_x(i) }
  @y_ticks = (1..y_labels.size - 2).map { |i| y_tick_y(i) }
end
values_calcs() click to toggle source
# File lib/active_charts/xy_chart.rb, line 41
def values_calcs
  @collection.flatten(1)
end
width_calcs(values) click to toggle source
# File lib/active_charts/xy_chart.rb, line 45
def width_calcs(values)
  @grid_width = svg_width - MARGIN * 4
  @x_min, @x_max, x_step = Util.scale(values.min, values.max)
  @x_labels = (x_min..x_max).step(x_step)
end
x_axis_y() click to toggle source
# File lib/active_charts/xy_chart.rb, line 69
def x_axis_y
  grid_height + label_height * 1.5
end
x_tick_x(index) click to toggle source
# File lib/active_charts/xy_chart.rb, line 77
def x_tick_x(index)
  section_width * index
end
y_axis_x() click to toggle source
# File lib/active_charts/xy_chart.rb, line 73
def y_axis_x
  grid_width + OFFSET
end
y_tick_y(index) click to toggle source
# File lib/active_charts/xy_chart.rb, line 81
def y_tick_y(index)
  return label_height + TOP_LEFT_OFFSET if index.eql?(y_labels.count - 1)
  
  (section_height * (y_labels.count - 1 - index)).round(6)
end