Rename UnicodePlotBackend -> Backend::UnicodePlot

This commit is contained in:
kojix2 2021-05-28 10:06:58 +09:00
parent 97d6c3e73f
commit 9e15c0ac2a
3 changed files with 19 additions and 19 deletions

View File

@ -6,7 +6,7 @@ require 'unicode_plot'
module YouPlot module YouPlot
# plotting functions. # plotting functions.
module Backends module Backends
module UnicodePlotBackend module UnicodePlot
class Error < StandardError; end class Error < StandardError; end
module_function module_function
@ -39,7 +39,7 @@ module YouPlot
labels = series[x_col] labels = series[x_col]
values = series[y_col].map(&:to_f) values = series[y_col].map(&:to_f)
end end
UnicodePlot.barplot(labels, values, **params.to_hc) ::UnicodePlot.barplot(labels, values, **params.to_hc)
end end
def histogram(data, params) def histogram(data, params)
@ -47,7 +47,7 @@ module YouPlot
series = data.series series = data.series
params.title ||= data.headers[0] if headers params.title ||= data.headers[0] if headers
values = series[0].map(&:to_f) values = series[0].map(&:to_f)
UnicodePlot.histogram(values, **params.to_hc) ::UnicodePlot.histogram(values, **params.to_hc)
end end
def line(data, params, fmt = nil) def line(data, params, fmt = nil)
@ -57,7 +57,7 @@ module YouPlot
# If there is only one series, it is assumed to be sequential data. # If there is only one series, it is assumed to be sequential data.
params.ylabel ||= headers[0] if headers params.ylabel ||= headers[0] if headers
y = series[0].map(&:to_f) y = series[0].map(&:to_f)
UnicodePlot.lineplot(y, **params.to_hc) ::UnicodePlot.lineplot(y, **params.to_hc)
else else
# If there are 2 or more series... # If there are 2 or more series...
if fmt == 'yx' if fmt == 'yx'
@ -75,7 +75,7 @@ module YouPlot
end end
x = series[x_col].map(&:to_f) x = series[x_col].map(&:to_f)
y = series[y_col].map(&:to_f) y = series[y_col].map(&:to_f)
UnicodePlot.lineplot(x, y, **params.to_hc) ::UnicodePlot.lineplot(x, y, **params.to_hc)
end end
end end
@ -94,9 +94,9 @@ module YouPlot
end end
params.xlim ||= series[0].flatten.minmax # why need? params.xlim ||= series[0].flatten.minmax # why need?
params.ylim ||= series[1..-1].flatten.minmax # why need? params.ylim ||= series[1..-1].flatten.minmax # why need?
plot = UnicodePlot.public_send(method1, series[0], series[1], **params.to_hc) plot = ::UnicodePlot.public_send(method1, series[0], series[1], **params.to_hc)
2.upto(series.size - 1) do |i| 2.upto(series.size - 1) do |i|
UnicodePlot.public_send(method2, plot, series[0], series[i], name: headers&.[](i)) ::UnicodePlot.public_send(method2, plot, series[0], series[i], name: headers&.[](i))
end end
plot plot
end end
@ -112,9 +112,9 @@ module YouPlot
params.xlim ||= series2.map(&:first).flatten.minmax # why need? params.xlim ||= series2.map(&:first).flatten.minmax # why need?
params.ylim ||= series2.map(&:last).flatten.minmax # why need? params.ylim ||= series2.map(&:last).flatten.minmax # why need?
x1, y1 = series2.shift x1, y1 = series2.shift
plot = UnicodePlot.public_send(method1, x1, y1, **params.to_hc) plot = ::UnicodePlot.public_send(method1, x1, y1, **params.to_hc)
series2.each_with_index do |(xi, yi), i| series2.each_with_index do |(xi, yi), i|
UnicodePlot.public_send(method2, plot, xi, yi, name: headers&.[]((i + 1) * 2)) ::UnicodePlot.public_send(method2, plot, xi, yi, name: headers&.[]((i + 1) * 2))
end end
plot plot
end end
@ -152,13 +152,13 @@ module YouPlot
series = data.series series = data.series
headers ||= (1..series.size).map(&:to_s) headers ||= (1..series.size).map(&:to_s)
series.map! { |s| s.map(&:to_f) } series.map! { |s| s.map(&:to_f) }
UnicodePlot.boxplot(headers, series, **params.to_hc) ::UnicodePlot.boxplot(headers, series, **params.to_hc)
end end
def colors(color_names = false) def colors(color_names = false)
# FIXME # FIXME
s = String.new s = String.new
UnicodePlot::StyledPrinter::TEXT_COLORS.each do |k, v| ::UnicodePlot::StyledPrinter::TEXT_COLORS.each do |k, v|
s << v s << v
s << k.to_s s << k.to_s
unless color_names unless color_names

View File

@ -4,7 +4,7 @@ require_relative 'dsv'
require_relative 'parser' require_relative 'parser'
# FIXME # FIXME
require_relative 'backends/unicode_plot_backend' require_relative 'backends/unicode_plot'
module YouPlot module YouPlot
Data = Struct.new(:headers, :series) Data = Struct.new(:headers, :series)
@ -19,7 +19,7 @@ module YouPlot
@command = nil @command = nil
@params = nil @params = nil
@options = nil @options = nil
@backend = YouPlot::Backends::UnicodePlotBackend @backend = YouPlot::Backends::UnicodePlot
end end
def run_as_executable def run_as_executable

View File

@ -67,37 +67,37 @@ class YouPlotSimpleTest < Test::Unit::TestCase
end end
test :lines do test :lines do
assert_raise(YouPlot::Backends::UnicodePlotBackend::Error) do assert_raise(YouPlot::Backends::UnicodePlot::Error) do
YouPlot::Command.new(['lines']).run YouPlot::Command.new(['lines']).run
end end
end end
test :lineplots do test :lineplots do
assert_raise(YouPlot::Backends::UnicodePlotBackend::Error) do assert_raise(YouPlot::Backends::UnicodePlot::Error) do
YouPlot::Command.new(['lineplots']).run YouPlot::Command.new(['lineplots']).run
end end
end end
test :s do test :s do
assert_raise(YouPlot::Backends::UnicodePlotBackend::Error) do assert_raise(YouPlot::Backends::UnicodePlot::Error) do
YouPlot::Command.new(['s']).run YouPlot::Command.new(['s']).run
end end
end end
test :scatter do test :scatter do
assert_raise(YouPlot::Backends::UnicodePlotBackend::Error) do assert_raise(YouPlot::Backends::UnicodePlot::Error) do
YouPlot::Command.new(['scatter']).run YouPlot::Command.new(['scatter']).run
end end
end end
test :d do test :d do
assert_raise(YouPlot::Backends::UnicodePlotBackend::Error) do assert_raise(YouPlot::Backends::UnicodePlot::Error) do
YouPlot::Command.new(['d']).run YouPlot::Command.new(['d']).run
end end
end end
test :density do test :density do
assert_raise(YouPlot::Backends::UnicodePlotBackend::Error) do assert_raise(YouPlot::Backends::UnicodePlot::Error) do
YouPlot::Command.new(['density']).run YouPlot::Command.new(['density']).run
end end
end end