6 Commits

Author SHA1 Message Date
kojix2
c73da80de6 v0.2.6 2020-10-12 07:45:42 +09:00
kojix2
2e8641ccea Improved descs 2020-10-11 09:23:57 +09:00
kojix2
1b43f7d48f Add comment about pass 2020-10-11 08:29:02 +09:00
kojix2
d8396fecf9 Rubocop auto correct 2020-10-11 08:28:39 +09:00
kojix2
4660c2ab02 Extract case-branching by fmt into another method 2020-10-11 08:02:43 +09:00
kojix2
d7e49f048f Add a comment to params 2020-10-11 07:55:20 +09:00
4 changed files with 40 additions and 36 deletions

View File

@@ -2,6 +2,11 @@
module Uplot
class Command
# UnicodePlot parameters.
# * Normally in a Ruby program, you might use hash for the parameter object.
# * Here, I use Struct for 2 safety reason.
# * The keys are static in Struct.
# * Struct does not conflict with keyword arguments. Hash dose.
Params = Struct.new(
# Sort me!
:title,

View File

@@ -26,7 +26,8 @@ module Uplot
OptionParser.new do |opt|
opt.program_name = 'uplot'
opt.version = Uplot::VERSION
opt.on('-O', '--pass [VAL]', 'file to output standard input data to [stdout]') do |v|
opt.on('-O', '--pass [VAL]', 'file to output standard input data to [stdout]',
'for inserting uplot in the middle of Unix pipes') do |v|
@pass = v || $stdout
end
opt.on('-o', '--output VAL', 'file to output results to [stderr]') do |v|
@@ -87,7 +88,9 @@ module Uplot
main_parser.banner = \
<<~MSG
Program: uplot (Tools for plotting on the terminal)
Version: #{Uplot::VERSION} (using unicode_plot #{UnicodePlot::VERSION})
Version: #{Uplot::VERSION} (using UnicodePlot #{UnicodePlot::VERSION})
Author: kojix2 <2xijok@gmail.com>
Source: https://github.com/kojix2/uplot
Usage: uplot <command> [options]
@@ -118,37 +121,37 @@ module Uplot
exit 1
when :barplot, :bar
parser.on('--symbol VAL', String) do |v|
parser.on('--symbol VAL', String, 'character to be used to plot the bars') do |v|
params.symbol = v
end
parser.on('--xscale VAL', String) do |v|
parser.on('--xscale VAL', String, 'axis scaling') do |v|
params.xscale = v
end
when :count, :c
parser.on('--symbol VAL', String) do |v|
parser.on('--symbol VAL', String, 'character to be used to plot the bars') do |v|
params.symbol = v
end
when :histogram, :hist
parser.on('-n', '--nbins VAL', Numeric) do |v|
parser.on('-n', '--nbins VAL', Numeric, 'approximate number of bins') do |v|
params.nbins = v
end
parser.on('--closed VAL', String) do |v|
params.closed = v
end
parser.on('--symbol VAL', String) do |v|
parser.on('--symbol VAL', String, 'character to be used to plot the bars') do |v|
params.symbol = v
end
when :lineplot, :line
parser.on('--canvas VAL', String) do |v|
parser.on('--canvas VAL', String, 'type of canvas') do |v|
params.canvas = v
end
parser.on('--xlim VAL', Array) do |v|
parser.on('--xlim VAL', Array, 'plotting range for the x coordinate') do |v|
params.xlim = v.take(2)
end
parser.on('--ylim VAL', Array) do |v|
parser.on('--ylim VAL', Array, 'plotting range for the y coordinate') do |v|
params.ylim = v.take(2)
end
@@ -156,10 +159,10 @@ module Uplot
parser.on('--canvas VAL', String) do |v|
params.canvas = v
end
parser.on('--xlim VAL', Array) do |v|
parser.on('--xlim VAL', Array, 'plotting range for the x coordinate') do |v|
params.xlim = v.take(2)
end
parser.on('--ylim VAL', Array) do |v|
parser.on('--ylim VAL', Array, 'plotting range for the y coordinate') do |v|
params.ylim = v.take(2)
end
@@ -167,10 +170,10 @@ module Uplot
parser.on('--canvas VAL', String) do |v|
params.canvas = v
end
parser.on('--xlim VAL', Array) do |v|
parser.on('--xlim VAL', Array, 'plotting range for the x coordinate') do |v|
params.xlim = v.take(2)
end
parser.on('--ylim VAL', Array) do |v|
parser.on('--ylim VAL', Array, 'plotting range for the y coordinate') do |v|
params.ylim = v.take(2)
end
@@ -178,15 +181,15 @@ module Uplot
parser.on('--grid', TrueClass) do |v|
params.grid = v
end
parser.on('--xlim VAL', Array) do |v|
parser.on('--xlim VAL', Array, 'plotting range for the x coordinate') do |v|
params.xlim = v.take(2)
end
parser.on('--ylim VAL', Array) do |v|
parser.on('--ylim VAL', Array, 'plotting range for the y coordinate') do |v|
params.ylim = v.take(2)
end
when :boxplot, :box
parser.on('--xlim VAL', Array) do |v|
parser.on('--xlim VAL', Array, 'plotting range for the x coordinate') do |v|
params.xlim = v.take(2)
end

View File

@@ -53,7 +53,7 @@ module Uplot
(method1.to_s + '!').to_sym
end
def xyy_plot(data, method1, params)
def plot_xyy(data, method1, params)
headers = data.headers
series = data.series
method2 = get_method2(method1)
@@ -70,7 +70,7 @@ module Uplot
plot
end
def xyxy_plot(data, method1, params)
def plot_xyxy(data, method1, params)
headers = data.headers
series = data.series
method2 = get_method2(method1)
@@ -87,34 +87,30 @@ module Uplot
plot
end
def lines(data, params, fmt = 'xyy')
check_series_size(data, fmt)
def plot_fmt(data, fmt, method1, params)
case fmt
when 'xyy'
xyy_plot(data, :lineplot, params)
plot_xyy(data, method1, params)
when 'xyxy'
xyxy_plot(data, :lineplot, params)
plot_xyxy(data, method1, params)
else
raise "Unknown format: #{fmt}"
end
end
def lines(data, params, fmt = 'xyy')
check_series_size(data, fmt)
plot_fmt(data, fmt, :lineplot, params)
end
def scatter(data, params, fmt = 'xyy')
check_series_size(data, fmt)
case fmt
when 'xyy'
xyy_plot(data, :scatterplot, params)
when 'xyxy'
xyxy_plot(data, :scatterplot, params)
end
plot_fmt(data, fmt, :scatterplot, params)
end
def density(data, params, fmt = 'xyy')
check_series_size(data, fmt)
case fmt
when 'xyy'
xyy_plot(data, :densityplot, params)
when 'xyxy'
xyxy_plot(data, :densityplot, params)
end
plot_fmt(data, fmt, :densityplot, params)
end
def boxplot(data, params)

View File

@@ -1,5 +1,5 @@
# frozen_string_literal: true
module Uplot
VERSION = '0.2.5'
VERSION = '0.2.6'
end