mirror of
https://github.com/red-data-tools/YouPlot.git
synced 2025-09-20 11:48:07 +08:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
0fa1e37da7 | ||
![]() |
3c6a4b46b1 | ||
![]() |
1f713d2a7b | ||
![]() |
749ac8a091 |
3
Gemfile
3
Gemfile
@@ -2,6 +2,3 @@ source 'https://rubygems.org'
|
||||
|
||||
# Specify your gem's dependencies in uplot.gemspec
|
||||
gemspec
|
||||
|
||||
gem 'minitest', '~> 5.0'
|
||||
gem 'rake', '~> 12.0'
|
||||
|
@@ -19,7 +19,7 @@ module Uplot
|
||||
|
||||
def create_parser
|
||||
OptionParser.new
|
||||
.on('-o', '--output', TrueClass) { |v| @output = v }
|
||||
.on('-o', '--output', TrueClass) { |v| @output = v }
|
||||
.on('-d', '--delimiter VAL', String) { |v| @delimiter = v }
|
||||
.on('-H', '--headers', TrueClass) { |v| @headers = v }
|
||||
.on('-T', '--transpose', TrueClass) { |v| @transpose = v }
|
||||
@@ -30,6 +30,8 @@ module Uplot
|
||||
.on('-m', '--margin VAL', Numeric) { |v| @params[:margin] = v }
|
||||
.on('-p', '--padding VAL', Numeric) { |v| @params[:padding] = v }
|
||||
.on('-c', '--color VAL', String) { |v| @params[:color] = v.to_sym }
|
||||
.on('-x', '--xlabel VAL', String) { |v| @params[:xlabel] = v }
|
||||
.on('-y', '--ylabel VAL', String) { |v| @params[:ylabel] = v }
|
||||
.on('-l', '--labels', TrueClass) { |v| @params[:labels] = v }
|
||||
.on('--fmt VAL', String) { |v| @fmt = v }
|
||||
.on('--debug', TrueClass) { |v| @debug = v }
|
||||
@@ -41,7 +43,6 @@ module Uplot
|
||||
parsers['barplot'] = parsers['bar']
|
||||
.on('--symbol VAL', String) { |v| @params[:symbol] = v }
|
||||
.on('--xscale VAL', String) { |v| @params[:xscale] = v }
|
||||
.on('--xlabel VAL', String) { |v| @params[:xlabel] = v }
|
||||
.on('--count', TrueClass) { |v| @count = v }
|
||||
parsers['count'] = parsers['c'] # barplot -c
|
||||
.on('--symbol VAL', String) { |v| @params[:symbol] = v }
|
||||
@@ -70,24 +71,41 @@ module Uplot
|
||||
parsers.default = nil
|
||||
|
||||
main_parser.banner = <<~MSG
|
||||
Program: Uplot (Tools for plotting on the terminal)
|
||||
Program: uplot (Tools for plotting on the terminal)
|
||||
Version: #{Uplot::VERSION} (using unicode_plot #{UnicodePlot::VERSION})
|
||||
|
||||
Usage: uplot <command> [options]
|
||||
|
||||
Command: #{parsers.keys.join(' ')}
|
||||
|
||||
Options:
|
||||
MSG
|
||||
main_parser.order!(argv)
|
||||
|
||||
begin
|
||||
main_parser.order!(argv)
|
||||
rescue OptionParser::ParseError => e
|
||||
warn "uplot: #{e.message}"
|
||||
exit 1
|
||||
end
|
||||
|
||||
@ptype = argv.shift
|
||||
|
||||
unless parsers.has_key?(@ptype)
|
||||
puts main_parser.help
|
||||
warn "unrecognized command '#{@ptype}'"
|
||||
if @ptype.nil?
|
||||
warn main_parser.help
|
||||
else
|
||||
warn "uplot: unrecognized command '#{@ptype}'"
|
||||
end
|
||||
exit 1
|
||||
end
|
||||
parser = parsers[@ptype]
|
||||
parser.parse!(argv) unless argv.empty?
|
||||
|
||||
begin
|
||||
parser.parse!(argv) unless argv.empty?
|
||||
rescue OptionParser::ParseError => e
|
||||
warn "uplot: #{e.message}"
|
||||
exit 1
|
||||
end
|
||||
end
|
||||
|
||||
def run
|
||||
@@ -172,17 +190,15 @@ module Uplot
|
||||
def line(data, headers)
|
||||
if data.size == 1
|
||||
@params[:ylabel] ||= headers[0] if headers
|
||||
y = data[0]
|
||||
x = (1..y.size).to_a
|
||||
y = data[0].map(&:to_f)
|
||||
UnicodePlot.lineplot(y, **@params.compact)
|
||||
else
|
||||
@params[:xlabel] ||= headers[0] if headers
|
||||
@params[:ylabel] ||= headers[1] if headers
|
||||
x = data[0]
|
||||
y = data[1]
|
||||
x = data[0].map(&:to_f)
|
||||
y = data[1].map(&:to_f)
|
||||
UnicodePlot.lineplot(x, y, **@params.compact)
|
||||
end
|
||||
x = x.map(&:to_f)
|
||||
y = y.map(&:to_f)
|
||||
UnicodePlot.lineplot(x, y, **@params.compact)
|
||||
end
|
||||
|
||||
def get_method2(method1)
|
||||
|
@@ -1,3 +1,3 @@
|
||||
module Uplot
|
||||
VERSION = '0.1.3'.freeze
|
||||
VERSION = '0.1.4'.freeze
|
||||
end
|
||||
|
Reference in New Issue
Block a user