class Plasticine::Builder::Line

Attributes

lines[R]

Public Class Methods

new(id, options={}) click to toggle source
Calls superclass method Plasticine::Builder::Base::new
# File lib/plasticine/builder/line.rb, line 4
def initialize(id, options={})
  super

  @visual.merge! lines: [], nature: 'line', axis_x_format: :string, axis_y_format: :number, axis_y_tick_count: 10, chart_layout: 'line', max_y_ratio: 1, order: nil, quarter_start_month: 1
  @lines = {}
end

Public Instance Methods

add_dot(line_id, x, y) click to toggle source
# File lib/plasticine/builder/line.rb, line 44
def add_dot(line_id, x, y)
  @lines[line_id][:dots] << { x: x, y: y }
  @lines[line_id][:total_y] += y
end
add_line(id, label) click to toggle source
# File lib/plasticine/builder/line.rb, line 40
def add_line(id, label)
  @lines[id] = { label: label, dots: [], total_y: 0 } if not @lines[id]
end
axis_x_format=(format) click to toggle source
# File lib/plasticine/builder/line.rb, line 12
def axis_x_format=(format)
  @visual[:axis_x_format] = format
end
axis_y_format=(format) click to toggle source
# File lib/plasticine/builder/line.rb, line 16
def axis_y_format=(format)
  @visual[:axis_y_format] = format
end
axis_y_tick_count=(tick_count) click to toggle source
# File lib/plasticine/builder/line.rb, line 20
def axis_y_tick_count=(tick_count)
  @visual[:axis_y_tick_count] = tick_count
end
chart_layout=(clayout) click to toggle source
# File lib/plasticine/builder/line.rb, line 24
def chart_layout=(clayout)
  @visual[:chart_layout] = clayout
end
close_visual() click to toggle source
Calls superclass method Plasticine::Builder::Base#close_visual
# File lib/plasticine/builder/line.rb, line 49
def close_visual
  super

  #@chart[:legend] = (@chart[:lines].length > 1) if @chart[:legend].nil?
  set_max_y
  @visual[:lines] = @lines.each_value.map { |d| d }

  if @visual[:order]
    @visual[:lines] = @visual[:lines].sort_by{ |l| l[:total_y] }
    @visual[:lines].reverse! if @visual[:order] == 'asc'
  end

end
max_y_ratio=(max_y_ratio) click to toggle source
# File lib/plasticine/builder/line.rb, line 28
def max_y_ratio=(max_y_ratio)
  @visual[:max_y_ratio] = max_y_ratio
end
order=(direction) click to toggle source
# File lib/plasticine/builder/line.rb, line 36
def order=(direction)
  @visual[:order] = direction # asc or desc
end
quarter_start_month=(month) click to toggle source
# File lib/plasticine/builder/line.rb, line 32
def quarter_start_month=(month)
  @visual[:quarter_start_month] = month
end
set_max_y() click to toggle source
# File lib/plasticine/builder/line.rb, line 63
def set_max_y
  stacks = {}
  max_y = 0

  @lines.each_value do |line|
    line[:dots].each do |dot|
      key = dot[:x].to_s
      stacks[key] = 0 if not stacks[key]
      stacks[key] += dot[:y]
      max_y = dot[:y] if max_y < dot[:y]
    end
  end

  if max_y == 0
    @visual[:max_y_stack] = 0
    @visual[:max_y] = 0
  else
    @visual[:max_y_stack] = stacks.max_by{|k,v| v}[1] # Return the highest stacked value for a specific X
    @visual[:max_y] = max_y * @visual[:max_y_ratio]
  end
end