class SoPerf::ChartContainer
Public Class Methods
new(render_job)
click to toggle source
# File lib/soperf/chart_container.rb, line 10 def initialize(render_job) @render_job = render_job @spacer = @render_job.spacer @scaled_tick_locations = render_job.scaled_tick_locations end
Public Instance Methods
add_names(rendered_string)
click to toggle source
# File lib/soperf/chart_container.rb, line 68 def add_names(rendered_string) lines = rendered_string.split("\n") result = '' @render_job.names.each_with_index do |name, i| result<< "#{@spacer.space(name.uncolorize)}#{name}:#{lines[i]}\n" end result end
container(rendered_string)
click to toggle source
# File lib/soperf/chart_container.rb, line 16 def container(rendered_string) plain_string = rendered_string.split("\n")[0].uncolorize width = ([plain_string.rindex(TICK_ON_LINE_END_CHAR)||0, (plain_string.rindex(LINE_CHAR)||0)].max)+1 top = [] width.times { top << TICK_CHAR } top[0] = TOP_LEFT_CORNER_CHAR top[-1] = TOP_RIGHT_CORNER_CHAR @render_job.scaled_tick_locations.each { |i| top[i] = TOP_ON_LINE_CHAR if top[i] == TICK_CHAR } bottom = top.dup.join top = top.join bottom[0], bottom[-1] = BOTTOM_LEFT_CORNER_CHAR, BOTTOM_RIGHT_CORNER_CHAR bottom.gsub!(TOP_ON_LINE_CHAR, BOTTOM_ON_LINE_CHAR) "#{@spacer.space(-1) + top}\n#{add_names(rendered_string)}#{@spacer.space(-1) + bottom}\n#{x_axis_legend}" end
fill_in_labels(arr)
click to toggle source
# File lib/soperf/chart_container.rb, line 49 def fill_in_labels(arr) result = '' leave_blank = 0 arr.each do |val| if val == ' ' && if leave_blank>0 result << '' leave_blank-=1 else result<<val end else leave_blank += (str = "#{val}").length-1 result<<str end end result end
x_axis_legend()
click to toggle source
# File lib/soperf/chart_container.rb, line 33 def x_axis_legend x_axis = Array.new(@render_job.width) { ' ' } odd_tick_locations = @scaled_tick_locations.values_at(*@scaled_tick_locations.each_index.select { |i| i.even? }) odd_ticks = @render_job.pretty_tick_values.values_at(*@render_job.pretty_tick_values.each_index.select { |i| i.even? }) odd_tick_locations.each_with_index do |l, i| x_axis[l]=odd_ticks[i].to_i end x_axis.map! do |val| val.is_a?(Integer) ? translate_time(val) : ' ' end @spacer.space('time')+"#{'time'}:#{fill_in_labels(x_axis)}" end