Class: AsciiCharts::Cartesian
Constant Summary
Constants inherited from Chart
AsciiCharts::Chart::DEFAULT_MAX_Y_VALS, AsciiCharts::Chart::DEFAULT_MIN_Y_VALS, 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 AsciiCharts::Chart
Instance Method Details
#lines ⇒ Object
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 274 275 276 277 278 |
# File 'lib/ascii_charts.rb', line 227 def lines if self.data.size == 0 return [[' ', self.[:title], ' ', '|', '+-', ' ']] end lines = [' '] = self.max_xval_width + 1 lines << (' ' * self.max_yval_width) + ' ' + self.rounded_data.map{|pair| pair[0].to_s.center()}.join('') self.y_range.each_with_index do |current_y, i| yval = current_y.to_s = if 0 == i '+' else '|' end current_line = [(' ' * (self.max_yval_width - yval.length) ) + "#{current_y}#{}"] self.rounded_data.each do |pair| marker = if (0 == i) && [:hide_zero] '-' else '*' end filler = if 0 == i '-' else ' ' end comparison = if self.[:bar] current_y <= pair[1] else current_y == pair[1] end if comparison current_line << marker.center(, filler) else current_line << filler * end end lines << current_line.join('') current_y = current_y + self.step_size end lines << ' ' if self.[:title] lines << self.[:title].center(lines[1].length) end lines << ' ' lines.reverse end |