class Charty::Backends::UnicodePlot
Public Class Methods
prepare()
click to toggle source
# File lib/charty/backends/unicode_plot.rb, line 9 def prepare require 'unicode_plot' end
Public Instance Methods
bar(bar_pos, _group_names, values, colors, _orient, **kwargs)
click to toggle source
# File lib/charty/backends/unicode_plot.rb, line 19 def bar(bar_pos, _group_names, values, colors, _orient, **kwargs) @figure = { type: :bar, bar_pos: bar_pos, values: values, } end
begin_figure()
click to toggle source
# File lib/charty/backends/unicode_plot.rb, line 14 def begin_figure @figure = nil @layout = {} end
box_plot(plot_data, positions, orient:, **kwargs)
click to toggle source
# File lib/charty/backends/unicode_plot.rb, line 27 def box_plot(plot_data, positions, orient:, **kwargs) @figure = { type: :box, data: plot_data, orient: orient } end
disable_xaxis_grid()
click to toggle source
# File lib/charty/backends/unicode_plot.rb, line 51 def disable_xaxis_grid # do nothing end
render(**kwargs)
click to toggle source
# File lib/charty/backends/unicode_plot.rb, line 55 def render(**kwargs) plot = case @figure[:type] when :bar ::UnicodePlot.barplot(@layout[:xtick_labels], @figure[:values], xlabel: @layout[:xlabel]) when :box xlabel = if @figure[:orient] == :v @layout[:ylabel] else @layout[:xlabel] end ::UnicodePlot.boxplot(@layout[:xtick_labels], @figure[:data], xlabel: xlabel) end sio = StringIO.new class << sio def tty?; true; end end plot.render(sio) sio.string end
set_xlabel(label)
click to toggle source
# File lib/charty/backends/unicode_plot.rb, line 31 def set_xlabel(label) @layout[:xlabel] = label end
set_xlim(min, max)
click to toggle source
# File lib/charty/backends/unicode_plot.rb, line 47 def set_xlim(min, max) @layout[:xlim] = [min, max] end
set_xtick_labels(values)
click to toggle source
# File lib/charty/backends/unicode_plot.rb, line 43 def set_xtick_labels(values) @layout[:xtick_labels] = values end
set_xticks(values)
click to toggle source
# File lib/charty/backends/unicode_plot.rb, line 39 def set_xticks(values) @layout[:xticks] = values end
set_ylabel(label)
click to toggle source
# File lib/charty/backends/unicode_plot.rb, line 35 def set_ylabel(label) @layout[:ylabel] = label end
Private Instance Methods
show_bar(sio, figure, i)
click to toggle source
# File lib/charty/backends/unicode_plot.rb, line 77 def show_bar(sio, figure, i) end
show_box(sio, figure, i)
click to toggle source
# File lib/charty/backends/unicode_plot.rb, line 80 def show_box(sio, figure, i) end