Improved error messages.

This commit is contained in:
kojix2 2020-08-16 13:20:52 +09:00
parent a09a703c33
commit 9d58b1aaf9
2 changed files with 15 additions and 0 deletions

View File

@ -247,6 +247,7 @@ module Uplot
input.freeze input.freeze
@raw_inputs << input @raw_inputs << input
@data = Preprocessing.input(input, @delimiter, @headers, @transpose) @data = Preprocessing.input(input, @delimiter, @headers, @transpose)
pp @data if @debug
case plot_type case plot_type
when :bar, :barplot when :bar, :barplot
Plot.barplot(data, params, @count) Plot.barplot(data, params, @count)

View File

@ -86,6 +86,7 @@ module Uplot
end end
def lines(data, params, fmt = 'xyy') def lines(data, params, fmt = 'xyy')
check_series_size(data, fmt)
case fmt case fmt
when 'xyy' when 'xyy'
xyy_plot(data, :lineplot, params) xyy_plot(data, :lineplot, params)
@ -95,6 +96,7 @@ module Uplot
end end
def scatter(data, params, fmt = 'xyy') def scatter(data, params, fmt = 'xyy')
check_series_size(data, fmt)
case fmt case fmt
when 'xyy' when 'xyy'
xyy_plot(data, :scatterplot, params) xyy_plot(data, :scatterplot, params)
@ -104,6 +106,7 @@ module Uplot
end end
def density(data, params, fmt = 'xyy') def density(data, params, fmt = 'xyy')
check_series_size(data, fmt)
case fmt case fmt
when 'xyy' when 'xyy'
xyy_plot(data, :densityplot, params) xyy_plot(data, :densityplot, params)
@ -119,5 +122,16 @@ module Uplot
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 check_series_size(data, fmt)
series = data.series
if series.size == 1
warn "uplot: There is only one series of input data. Please check the delimiter."
warn ""
warn " The first item is: \e[35m\"#{series[0][0]}\"\e[0m"
warn " The last item is : \e[35m\"#{series[0][-1]}\"\e[0m"
exit 1
end
end
end end
end end