2 Commits

Author SHA1 Message Date
kojix2
b8a187a1bf Remove needless space 2021-07-03 07:11:43 +09:00
kojix2
87bb24e236 Update README.md 2021-07-03 07:07:43 +09:00
11 changed files with 41 additions and 204 deletions

View File

@@ -6,12 +6,13 @@ jobs:
runs-on: ${{ matrix.os }}-latest
strategy:
matrix:
os: [ 'ubuntu', 'macos' ]
ruby: [ '2.4', '2.5', '2.6', '2.7', '3.0', '3.1', '3.2' ]
os: ['ubuntu', 'macos']
ruby: [ '2.4', '2.5', '2.6', '2.7', '3.0' ]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- run: gem install bundler
- run: bundle install
- run: bundle exec rake test

View File

@@ -1,23 +0,0 @@
name: doc
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: ruby
- name: Generate document
run: gem install -N yard && yard doc
- name: Publish Documentation on GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./doc

View File

@@ -4,9 +4,3 @@ source 'https://rubygems.org'
# Specify your gem's dependencies in youplot.gemspec
gemspec
group :test do
gem 'rake'
gem 'simplecov'
gem 'test-unit'
end

View File

@@ -211,14 +211,6 @@ The following sub-commands are available.
* Not yet supported.
### YouPlot Configuration (youplotrc)
You can specify default options in a configuration file in YAML format. For more information, enter the following command.
```
uplot --config
```
## Tools that are useful to use with YouPlot
* [csvtk](https://github.com/shenwei356/csvtk)
@@ -249,10 +241,6 @@ bundle exec rake install # Installation from source code
bundle exec exe/uplot # Run youplot (Try out the edited code)
```
Do you need commit rights to my repository?
Do you want to get admin rights and take over the project?
If so, please feel free to contact us.
### Acknowledgements
* [sampo grafiikka](https://jypg.net/sampo_grafiikka) - Project logo creation

View File

@@ -6,12 +6,6 @@ require_relative 'youplot/parameters'
require_relative 'youplot/command'
module YouPlot
# @run_as_executable = true / false
# YouPlot behaves slightly differently when run as a command line tool
# and when run as a script (e.g. for testing). In the event of an error,
# when run as a command line tool, YouPlot will display a short error message
# and exit abnormally. When run as a script, it will just raise an error.
@run_as_executable = false
class << self
attr_accessor :run_as_executable
@@ -19,4 +13,5 @@ module YouPlot
@run_as_executable
end
end
@run_as_executable = false
end

View File

@@ -127,10 +127,11 @@ module YouPlot
def plot_xyxy(data, method1, params)
headers = data.headers
series2 = data.series
.map { |s| s.map(&:to_f) }
.each_slice(2).to_a
series = data.series
method2 = get_method2(method1)
series.map! { |s| s.map(&:to_f) }
series2 = series.each_slice(2).to_a
series = nil
params.name ||= headers[0] if headers
params.xlim ||= series2.map(&:first).flatten.minmax # why need?
params.ylim ||= series2.map(&:last).flatten.minmax # why need?

View File

@@ -63,15 +63,9 @@ module YouPlot
# normal mode
else
# Sometimes the input file does not end with a newline code.
begin
begin
input = Kernel.gets(nil)
rescue Errno::ENOENT => e
warn e.message
next
end
while (input = Kernel.gets(nil))
main(input)
end until input
end
end
end
@@ -141,12 +135,7 @@ module YouPlot
rescue CSV::MalformedCSVError => e
warn 'Failed to parse the text. '
warn 'Please try to set the correct character encoding with --encoding option.'
warn e.backtrace.grep(/youplot/).first
exit 1
rescue ArgumentError => e
warn 'Failed to parse the text. '
warn e.backtrace.grep(/youplot/).first
exit 1
raise e
end
data
@@ -160,9 +149,9 @@ module YouPlot
@backend.barplot(data, params, count: true, reverse: options[:reverse])
when :hist, :histogram
@backend.histogram(data, params)
when :line, :lineplot, :l
when :line, :lineplot
@backend.line(data, params, options[:fmt])
when :lines, :lineplots, :ls
when :lines, :lineplots
@backend.lines(data, params, options[:fmt])
when :scatter, :s
@backend.scatter(data, params, options[:fmt])

View File

@@ -9,8 +9,7 @@ module YouPlot
class Error < StandardError; end
attr_reader :command, :options, :params,
:main_parser, :sub_parser,
:config_file, :config
:main_parser, :sub_parser
def initialize
@command = nil
@@ -31,61 +30,6 @@ module YouPlot
@params = Parameters.new
end
def apply_config_file
return if !config_file && find_config_file.nil?
read_config_file
configure
end
def config_file_candidate_paths
# keep the order of the paths
paths = []
paths << ENV['MYYOUPLOTRC'] if ENV['MYYOUPLOTRC']
paths << '.youplot.yml'
paths << '.youplotrc'
if ENV['HOME']
paths << File.join(ENV['HOME'], '.youplotrc')
paths << File.join(ENV['HOME'], '.youplot.yml')
paths << File.join(ENV['HOME'], '.config', 'youplot', 'youplotrc')
paths << File.join(ENV['HOME'], '.config', 'youplot', 'youplot.yml')
end
paths
end
def find_config_file
config_file_candidate_paths.each do |file|
path = File.expand_path(file)
next unless File.exist?(path)
@config_file = path
ENV['MYYOUPLOTRC'] = path
return @config_file
end
nil
end
def read_config_file
require 'yaml'
@config = YAML.load_file(config_file)
end
def configure
option_members = @options.members
param_members = @params.members
# It would be more useful to be able to configure by plot type
config.each do |k, v|
k = k.to_sym
if option_members.include?(k)
@options[k] ||= v
elsif param_members.include?(k)
@params[k] ||= v
else
raise Error, "Unknown option/param in config file: #{k}"
end
end
end
def create_base_parser
OptionParser.new do |parser|
parser.program_name = 'YouPlot'
@@ -151,7 +95,7 @@ module YouPlot
parser.on('-M', '--monochrome', TrueClass, 'no colouring even if writing to a tty') do |_v|
UnicodePlot::IOContext.define_method(:color?) { false } # FIXME
end
parser.on('--encoding STR', String, 'specify the input encoding') do |v|
parser.on('--encoding STR', String, 'Specify the input encoding') do |v|
options[:encoding] = v
end
# Optparse adds the help option, but it doesn't show up in usage.
@@ -160,9 +104,6 @@ module YouPlot
puts parser.help
exit if YouPlot.run_as_executable?
end
parser.on('--config FILE', 'specify a config file') do |v|
@config_file = v
end
parser.on('--debug', TrueClass, 'print preprocessed data') do |v|
options[:debug] = v
end
@@ -194,7 +135,6 @@ module YouPlot
colors color show the list of available colors
General options:
--config print config file info
--help print command specific help menu
--version print the version of YouPlot
MSG
@@ -202,36 +142,10 @@ module YouPlot
# Help for the main parser is simple.
# Simply show the banner above.
main_parser.on('--help', 'print sub-command help menu') do
show_main_help
puts main_parser.banner
puts
exit if YouPlot.run_as_executable?
end
main_parser.on('--config', 'show config file info') do
show_config_info
end
end
def show_main_help(out = $stdout)
out.puts main_parser.banner
out.puts
exit if YouPlot.run_as_executable?
end
def show_config_info
if ENV['MYYOUPLOTRC']
puts "config file : #{ENV['MYYOUPLOTRC']}"
puts config.inspect
else
puts <<~EOS
Configuration file not found.
It should be a YAML file, like this example:
width : 40
height : 20
By default, YouPlot will look for the configuration file in these locations:
#{config_file_candidate_paths.map { |s| ' ' + s }.join("\n")}
If you have the file elsewhere, you can specify its location with the `MYYOUPLOTRC` environment variable.
EOS
end
exit if YouPlot.run_as_executable?
end
def sub_parser_add_symbol
@@ -301,13 +215,10 @@ module YouPlot
case command
# If you type only `uplot` in the terminal.
# Output help to standard error output.
when nil
show_main_help($stderr)
# Output help to standard output.
when :help
show_main_help
warn main_parser.banner
warn "\n"
exit 1 if YouPlot.run_as_executable?
when :barplot, :bar
sub_parser_add_symbol
@@ -330,14 +241,14 @@ module YouPlot
params.nbins = v
end
when :lineplot, :line, :l
when :lineplot, :line
sub_parser_add_canvas
sub_parser_add_grid
sub_parser_add_fmt_yx
sub_parser_add_ylim
sub_parser_add_xlim
when :lineplots, :lines, :ls
when :lineplots, :lines
sub_parser_add_canvas
sub_parser_add_grid
sub_parser_add_fmt_xyxy
@@ -366,19 +277,14 @@ module YouPlot
options[:color_names] = v
end
# Currently it simply displays the configuration file,
# but in the future this may be changed to open a text editor like Vim
# to edit the configuration file.
when :config
show_config_info
else
error_message = "YouPlot: unrecognized command '#{command}'"
raise Error, error_message unless YouPlot.run_as_executable?
warn error_message
exit 1
error_message = "uplot: unrecognized command '#{command}'"
if YouPlot.run_as_executable?
warn error_message
exit 1
else
raise Error, error_message
end
end
end
@@ -386,7 +292,7 @@ module YouPlot
begin
create_main_parser.order!(argv)
rescue OptionParser::ParseError => e
warn "YouPlot: #{e.message}"
warn "uplot: #{e.message}"
exit 1 if YouPlot.run_as_executable?
end
@@ -395,14 +301,7 @@ module YouPlot
begin
create_sub_parser&.parse!(argv)
rescue OptionParser::ParseError => e
warn "YouPlot: #{e.message}"
exit 1 if YouPlot.run_as_executable?
end
begin
apply_config_file
rescue StandardError => e
warn "YouPlot: #{e.message}"
warn "uplot: #{e.message}"
exit 1 if YouPlot.run_as_executable?
end
end

View File

@@ -1,5 +1,5 @@
# frozen_string_literal: true
module YouPlot
VERSION = '0.4.5'
VERSION = '0.4.2'
end

View File

@@ -69,12 +69,6 @@ class YouPlotIRISTest < Test::Unit::TestCase
assert_equal fixture('iris-lineplot.txt'), @stderr_file.read
end
# l is an undocumented alias of lineplot.
test :l do
YouPlot::Command.new(['l', '-H', '-d,', '-t', 'IRIS-LINEPLOT']).run
assert_equal fixture('iris-lineplot.txt'), @stderr_file.read
end
test :lineplots do
YouPlot::Command.new(['lineplots', '-H', '-d,', '-t', 'IRIS-LINEPLOTS']).run
assert_equal fixture('iris-lineplots.txt'), @stderr_file.read
@@ -85,12 +79,6 @@ class YouPlotIRISTest < Test::Unit::TestCase
assert_equal fixture('iris-lineplots.txt'), @stderr_file.read
end
# ls is an undocumented alias of lineplots.
test :ls do
YouPlot::Command.new(['lines', '-H', '-d,', '-t', 'IRIS-LINEPLOTS']).run
assert_equal fixture('iris-lineplots.txt'), @stderr_file.read
end
test :scatter do
YouPlot::Command.new(['scatter', '-H', '-d,', '-t', 'IRIS-SCATTER']).run
assert_equal fixture('iris-scatter.txt'), @stderr_file.read

View File

@@ -19,5 +19,10 @@ Gem::Specification.new do |spec|
spec.executables = %w[uplot youplot]
spec.require_paths = ['lib']
spec.add_dependency 'unicode_plot', '>= 0.0.5'
spec.add_runtime_dependency 'unicode_plot'
spec.add_development_dependency 'bundler'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'rubocop'
spec.add_development_dependency 'simplecov'
spec.add_development_dependency 'test-unit'
end