Class: Kovid::AsciiCharts::Cartesian
- Defined in:
- lib/kovid/ascii_charts.rb
Constant Summary
Constants inherited from Chart
Kovid::AsciiCharts::Chart::DEFAULT_MAX_Y_VALS, Kovid::AsciiCharts::Chart::DEFAULT_MIN_Y_VALS, Kovid::AsciiCharts::Chart::STEPS
Instance Attribute Summary
Attributes inherited from Chart
Instance Method Summary collapse
Methods inherited from Chart
#all_ints, #draw, #from_step, #initialize, #max_xval_width, #max_yval, #max_yval_width, #min_yval, #nearest_step, #next_step_down, #next_step_up, #round_value, #rounded_data, #scan_data, #scan_y_range, #step_size, #to_step, #to_string, #y_range
Constructor Details
This class inherits a constructor from Kovid::AsciiCharts::Chart
Instance Method Details
#lines ⇒ Object
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'lib/kovid/ascii_charts.rb', line 226 def lines return [[' ', [:title], ' ', '|', '+-', ' ']] if data.empty? lines = [' '] = max_xval_width + 1 lines << (' ' * max_yval_width) + ' ' + rounded_data.map { |pair| pair[0].to_s.center() }.join('') y_range.each_with_index do |current_y, i| yval = current_y.to_s = if i == 0 '+' else '|' end current_line = [(' ' * (max_yval_width - yval.length)) + "#{current_y}#{}"] rounded_data.each do |pair| marker = if (i == 0) && [:hide_zero] '-' else '*' end filler = if i == 0 '-' else ' ' end comparison = if [:bar] current_y <= pair[1] else current_y == pair[1] end current_line << if comparison marker.center(, filler) else filler * end end lines << current_line.join('') current_y += step_size end lines << ' ' lines << [:title].center(lines[1].length) if [:title] lines << ' ' lines.reverse end |