mirror of
https://github.com/red-data-tools/YouPlot.git
synced 2025-09-21 12:28:10 +08:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
c73da80de6 | ||
![]() |
2e8641ccea | ||
![]() |
1b43f7d48f | ||
![]() |
d8396fecf9 | ||
![]() |
4660c2ab02 | ||
![]() |
d7e49f048f |
@@ -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,
|
||||
|
@@ -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
|
||||
|
||||
|
@@ -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)
|
||||
|
@@ -1,5 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Uplot
|
||||
VERSION = '0.2.5'
|
||||
VERSION = '0.2.6'
|
||||
end
|
||||
|
Reference in New Issue
Block a user