Class: Tplot::BarChart

Inherits:
LineChart show all
Defined in:
lib/tplot/bar_chart.rb

Constant Summary

Constants inherited from LineChart

LineChart::COLORS

Instance Attribute Summary

Attributes inherited from LineChart

#labels, #limit

Instance Method Summary collapse

Methods inherited from LineChart

#add, #calc_position, #draw, #draw_frame_post, #draw_frame_pre, #init_colors, #initialize, #pre_draw, #update

Constructor Details

This class inherits a constructor from Tplot::LineChart

Instance Method Details

#draw_lineObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/tplot/bar_chart.rb', line 3

def draw_line
  tmp_data = @datas.dup
  (-@width..0).map(&:abs).each do |col|
    data = tmp_data.pop
    break unless data

    data_with_idx = []
    data.each_with_index do |value, idx|
      data_with_idx.push [value, idx]
    end
    data_with_idx.sort{|l, r| r.first.abs <=> l.first.abs }.each do |array|
      value, idx = array.first, array.last
      min = calc_position(0)
      max = calc_position(value)
      min, max = max, min if min > max
      (min..max).each do |line|
        setpos(line, col)
        attron(color_pair(COLORS[idx % COLORS.size])|A_NORMAL) do
          addstr("*")
        end
      end
    end
  end
end