class SoPerf::Chart

Attributes

data_hash[RW]
duration[RW]
scale[RW]

Public Class Methods

new(data_hash) click to toggle source
# File lib/soperf/chart.rb, line 19
def initialize(data_hash)
  @data_hash = Hash[data_hash.sort_by do |_, arr| #sort the data by start time of first range
                      arr = [arr] unless arr.is_a?(Array)
                      arr.map { |range| range.first }.max
                    end]
  @chart     = {}
  set_up_rows
  @duration     = data_range(:round) #Find the full range of the data, rounded up
  @longest_name = data_hash.map { |k, _| k.to_s.length }.max #The longest name of the results
  @spacer       = Spacer.new(@longest_name)
  @text_info    = @data_hash.map { |k, v| "#{@chart[k].name(true)}: #{translate_time(v.first)}-#{translate_time(v.last)}" }
  @forced_width = nil
end

Public Instance Methods

data_range(round=:round) click to toggle source
# File lib/soperf/chart.rb, line 37
def data_range(round=:round)
  range = data_hash.map { |_, v| v.last }.max
  round==:round ? ((range/10.0).ceil*10) : range
end
ideal_scale() click to toggle source
# File lib/soperf/chart.rb, line 33
def ideal_scale
  (usable_space.to_f)/duration
end
print_text_info(render_job) click to toggle source
render(options_hash={}) click to toggle source
# File lib/soperf/chart.rb, line 47
def render(options_hash={})
  options_hash[:color] = true unless options_hash.has_key?(:color)
  @forced_width        = options_hash[:width] if options_hash.has_key?(:width)
  show_summary         = options_hash.has_key?(:summary) ? options_hash[:summary] : true
  @names               = @chart.map { |_, v| v.name(true) }
  options_hash.merge!({duration: data_range, longest_name: @longest_name,
                       spacer:   @spacer, names: @names})

  @render_job = RenderJob.new(options_hash)

  result = ''
  set_up_rows
  @chart.each_pair { |_, row| result << row.render(@render_job) + NEWLINE }
  contained = ChartContainer.new(@render_job).container(result)
  rendered  = "#{contained}\n#{(show_summary ? print_text_info(@render_job) : '')}"
  reset
  options_hash[:color] ? rendered : (rendered.uncolorize)
end
reset() click to toggle source
# File lib/soperf/chart.rb, line 84
def reset
  @scaled_tick_locations = nil
  @tick_locations        = nil
  @tick_freq             = nil
  @pretty_tick_values    = nil
  @forced_width          = nil
  @show_summary          = nil
end
scaled_tick_locations() click to toggle source
# File lib/soperf/chart.rb, line 66
def scaled_tick_locations
  @scaled_tick_locations ||= tick_locations.map { |val| val*scale }
end
set_up_rows() click to toggle source
# File lib/soperf/chart.rb, line 42
def set_up_rows
  ColorHelper.reset_color_index
  data_hash.each { |k, v| @chart[k] = Row.new(k, v) }
end