mirror of
https://github.com/red-data-tools/YouPlot.git
synced 2025-09-19 02:18:08 +08:00
Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
5695bbe91f | ||
![]() |
0e2f8014fd | ||
![]() |
a6c054f596 | ||
![]() |
26050a2f87 | ||
![]() |
8eca14a70d | ||
![]() |
654dbfca62 | ||
![]() |
433c24e710 | ||
![]() |
b1baa4073c | ||
![]() |
27a84a4df1 | ||
![]() |
f8bd152a63 | ||
![]() |
f9ffca636f | ||
![]() |
83b1da9b96 | ||
![]() |
1f41e79952 | ||
![]() |
85ed440c52 | ||
![]() |
16525233f3 | ||
![]() |
4efdc79e30 |
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
@@ -7,9 +7,9 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os: [ 'ubuntu', 'macos' ]
|
os: [ 'ubuntu', 'macos' ]
|
||||||
ruby: [ '2.4', '2.5', '2.6', '2.7', '3.0', '3.1' ]
|
ruby: [ '2.4', '2.5', '2.6', '2.7', '3.0', '3.1', '3.2' ]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: ruby/setup-ruby@v1
|
- uses: ruby/setup-ruby@v1
|
||||||
with:
|
with:
|
||||||
ruby-version: ${{ matrix.ruby }}
|
ruby-version: ${{ matrix.ruby }}
|
||||||
|
2
.github/workflows/doc.yml
vendored
2
.github/workflows/doc.yml
vendored
@@ -13,7 +13,7 @@ jobs:
|
|||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: ruby/setup-ruby@v1
|
- uses: ruby/setup-ruby@v1
|
||||||
with:
|
with:
|
||||||
ruby-version: 3.1
|
ruby-version: ruby
|
||||||
- name: Generate document
|
- name: Generate document
|
||||||
run: gem install -N yard && yard doc
|
run: gem install -N yard && yard doc
|
||||||
- name: Publish Documentation on GitHub Pages
|
- name: Publish Documentation on GitHub Pages
|
||||||
|
@@ -211,6 +211,14 @@ The following sub-commands are available.
|
|||||||
|
|
||||||
* Not yet supported.
|
* 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
|
## Tools that are useful to use with YouPlot
|
||||||
|
|
||||||
* [csvtk](https://github.com/shenwei356/csvtk)
|
* [csvtk](https://github.com/shenwei356/csvtk)
|
||||||
|
@@ -40,24 +40,6 @@ module YouPlot
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
# config command
|
|
||||||
if @command == :config
|
|
||||||
if ENV['MYYOUPLOTRC']
|
|
||||||
puts "config file : #{ENV['MYYOUPLOTRC']}"
|
|
||||||
puts parser.config.inspect
|
|
||||||
else
|
|
||||||
puts <<~EOS
|
|
||||||
You don't have a config file. The default config file paths are:
|
|
||||||
./.youplot.yml, ./.youplotrc, ~/.youplot.yml, ~/.youplotrc
|
|
||||||
You can specify a config file with the environment variable MYYOUPLOTRC.
|
|
||||||
File format is YAML. For example:
|
|
||||||
width : 40
|
|
||||||
height : 20
|
|
||||||
EOS
|
|
||||||
end
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
# progressive mode
|
# progressive mode
|
||||||
if options[:progressive]
|
if options[:progressive]
|
||||||
stop = false
|
stop = false
|
||||||
@@ -178,9 +160,9 @@ module YouPlot
|
|||||||
@backend.barplot(data, params, count: true, reverse: options[:reverse])
|
@backend.barplot(data, params, count: true, reverse: options[:reverse])
|
||||||
when :hist, :histogram
|
when :hist, :histogram
|
||||||
@backend.histogram(data, params)
|
@backend.histogram(data, params)
|
||||||
when :line, :lineplot
|
when :line, :lineplot, :l
|
||||||
@backend.line(data, params, options[:fmt])
|
@backend.line(data, params, options[:fmt])
|
||||||
when :lines, :lineplots
|
when :lines, :lineplots, :ls
|
||||||
@backend.lines(data, params, options[:fmt])
|
@backend.lines(data, params, options[:fmt])
|
||||||
when :scatter, :s
|
when :scatter, :s
|
||||||
@backend.scatter(data, params, options[:fmt])
|
@backend.scatter(data, params, options[:fmt])
|
||||||
|
@@ -29,53 +29,59 @@ module YouPlot
|
|||||||
)
|
)
|
||||||
|
|
||||||
@params = Parameters.new
|
@params = Parameters.new
|
||||||
|
|
||||||
if @config_file = find_config_file
|
|
||||||
ENV['MYYOUPLOTRC'] = @config_file
|
|
||||||
@config = read_config_file(config_file)
|
|
||||||
configure(config)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def candidate_paths
|
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 = []
|
||||||
paths << ENV['MYYOUPLOTRC'] if ENV['MYYOUPLOTRC']
|
paths << ENV['MYYOUPLOTRC'] if ENV['MYYOUPLOTRC']
|
||||||
paths << '.youplot.yml'
|
paths << '.youplot.yml'
|
||||||
paths << '.youplotrc'
|
paths << '.youplotrc'
|
||||||
paths << File.join(ENV['HOME'], '.youplotrc') if ENV['HOME']
|
if ENV['HOME']
|
||||||
paths << File.join(ENV['HOME'], '.youplot.yml') 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
|
paths
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_config_file
|
def find_config_file
|
||||||
config_file_path = nil
|
config_file_candidate_paths.each do |file|
|
||||||
candidate_paths.each do |file|
|
|
||||||
path = File.expand_path(file)
|
path = File.expand_path(file)
|
||||||
if File.exist?(path)
|
next unless File.exist?(path)
|
||||||
config_file_path = path
|
|
||||||
break
|
@config_file = path
|
||||||
end
|
ENV['MYYOUPLOTRC'] = path
|
||||||
|
return @config_file
|
||||||
end
|
end
|
||||||
config_file_path
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_config_file(path)
|
def read_config_file
|
||||||
require 'yaml'
|
require 'yaml'
|
||||||
YAML.load_file(path)
|
@config = YAML.load_file(config_file)
|
||||||
end
|
end
|
||||||
|
|
||||||
def configure(config)
|
def configure
|
||||||
option_members = @options.members
|
option_members = @options.members
|
||||||
param_members = @params.members
|
param_members = @params.members
|
||||||
# It would be more useful to be able to configure by plot type
|
# It would be more useful to be able to configure by plot type
|
||||||
config.each do |k, v|
|
config.each do |k, v|
|
||||||
k = k.to_sym
|
k = k.to_sym
|
||||||
if option_members.include?(k)
|
if option_members.include?(k)
|
||||||
@options[k] = v
|
@options[k] ||= v
|
||||||
elsif param_members.include?(k)
|
elsif param_members.include?(k)
|
||||||
@params[k] = v
|
@params[k] ||= v
|
||||||
else
|
else
|
||||||
raise Error, "Unknown option/param: #{k}"
|
raise Error, "Unknown option/param in config file: #{k}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -154,6 +160,9 @@ module YouPlot
|
|||||||
puts parser.help
|
puts parser.help
|
||||||
exit if YouPlot.run_as_executable?
|
exit if YouPlot.run_as_executable?
|
||||||
end
|
end
|
||||||
|
parser.on('--config FILE', 'specify a config file') do |v|
|
||||||
|
@config_file = v
|
||||||
|
end
|
||||||
parser.on('--debug', TrueClass, 'print preprocessed data') do |v|
|
parser.on('--debug', TrueClass, 'print preprocessed data') do |v|
|
||||||
options[:debug] = v
|
options[:debug] = v
|
||||||
end
|
end
|
||||||
@@ -185,6 +194,7 @@ module YouPlot
|
|||||||
colors color show the list of available colors
|
colors color show the list of available colors
|
||||||
|
|
||||||
General options:
|
General options:
|
||||||
|
--config print config file info
|
||||||
--help print command specific help menu
|
--help print command specific help menu
|
||||||
--version print the version of YouPlot
|
--version print the version of YouPlot
|
||||||
MSG
|
MSG
|
||||||
@@ -192,10 +202,36 @@ module YouPlot
|
|||||||
# Help for the main parser is simple.
|
# Help for the main parser is simple.
|
||||||
# Simply show the banner above.
|
# Simply show the banner above.
|
||||||
main_parser.on('--help', 'print sub-command help menu') do
|
main_parser.on('--help', 'print sub-command help menu') do
|
||||||
puts main_parser.banner
|
show_main_help
|
||||||
puts
|
|
||||||
exit if YouPlot.run_as_executable?
|
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
def sub_parser_add_symbol
|
def sub_parser_add_symbol
|
||||||
@@ -265,10 +301,13 @@ module YouPlot
|
|||||||
case command
|
case command
|
||||||
|
|
||||||
# If you type only `uplot` in the terminal.
|
# If you type only `uplot` in the terminal.
|
||||||
|
# Output help to standard error output.
|
||||||
when nil
|
when nil
|
||||||
warn main_parser.banner
|
show_main_help($stderr)
|
||||||
warn "\n"
|
|
||||||
exit 1 if YouPlot.run_as_executable?
|
# Output help to standard output.
|
||||||
|
when :help
|
||||||
|
show_main_help
|
||||||
|
|
||||||
when :barplot, :bar
|
when :barplot, :bar
|
||||||
sub_parser_add_symbol
|
sub_parser_add_symbol
|
||||||
@@ -291,14 +330,14 @@ module YouPlot
|
|||||||
params.nbins = v
|
params.nbins = v
|
||||||
end
|
end
|
||||||
|
|
||||||
when :lineplot, :line
|
when :lineplot, :line, :l
|
||||||
sub_parser_add_canvas
|
sub_parser_add_canvas
|
||||||
sub_parser_add_grid
|
sub_parser_add_grid
|
||||||
sub_parser_add_fmt_yx
|
sub_parser_add_fmt_yx
|
||||||
sub_parser_add_ylim
|
sub_parser_add_ylim
|
||||||
sub_parser_add_xlim
|
sub_parser_add_xlim
|
||||||
|
|
||||||
when :lineplots, :lines
|
when :lineplots, :lines, :ls
|
||||||
sub_parser_add_canvas
|
sub_parser_add_canvas
|
||||||
sub_parser_add_grid
|
sub_parser_add_grid
|
||||||
sub_parser_add_fmt_xyxy
|
sub_parser_add_fmt_xyxy
|
||||||
@@ -327,16 +366,19 @@ module YouPlot
|
|||||||
options[:color_names] = v
|
options[:color_names] = v
|
||||||
end
|
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
|
when :config
|
||||||
|
show_config_info
|
||||||
|
|
||||||
else
|
else
|
||||||
error_message = "uplot: unrecognized command '#{command}'"
|
error_message = "YouPlot: unrecognized command '#{command}'"
|
||||||
if YouPlot.run_as_executable?
|
raise Error, error_message unless YouPlot.run_as_executable?
|
||||||
warn error_message
|
|
||||||
exit 1
|
warn error_message
|
||||||
else
|
exit 1
|
||||||
raise Error, error_message
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -344,7 +386,7 @@ module YouPlot
|
|||||||
begin
|
begin
|
||||||
create_main_parser.order!(argv)
|
create_main_parser.order!(argv)
|
||||||
rescue OptionParser::ParseError => e
|
rescue OptionParser::ParseError => e
|
||||||
warn "uplot: #{e.message}"
|
warn "YouPlot: #{e.message}"
|
||||||
exit 1 if YouPlot.run_as_executable?
|
exit 1 if YouPlot.run_as_executable?
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -353,7 +395,14 @@ module YouPlot
|
|||||||
begin
|
begin
|
||||||
create_sub_parser&.parse!(argv)
|
create_sub_parser&.parse!(argv)
|
||||||
rescue OptionParser::ParseError => e
|
rescue OptionParser::ParseError => e
|
||||||
warn "uplot: #{e.message}"
|
warn "YouPlot: #{e.message}"
|
||||||
|
exit 1 if YouPlot.run_as_executable?
|
||||||
|
end
|
||||||
|
|
||||||
|
begin
|
||||||
|
apply_config_file
|
||||||
|
rescue StandardError => e
|
||||||
|
warn "YouPlot: #{e.message}"
|
||||||
exit 1 if YouPlot.run_as_executable?
|
exit 1 if YouPlot.run_as_executable?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module YouPlot
|
module YouPlot
|
||||||
VERSION = '0.4.4'
|
VERSION = '0.4.5'
|
||||||
end
|
end
|
||||||
|
@@ -69,6 +69,12 @@ class YouPlotIRISTest < Test::Unit::TestCase
|
|||||||
assert_equal fixture('iris-lineplot.txt'), @stderr_file.read
|
assert_equal fixture('iris-lineplot.txt'), @stderr_file.read
|
||||||
end
|
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
|
test :lineplots do
|
||||||
YouPlot::Command.new(['lineplots', '-H', '-d,', '-t', 'IRIS-LINEPLOTS']).run
|
YouPlot::Command.new(['lineplots', '-H', '-d,', '-t', 'IRIS-LINEPLOTS']).run
|
||||||
assert_equal fixture('iris-lineplots.txt'), @stderr_file.read
|
assert_equal fixture('iris-lineplots.txt'), @stderr_file.read
|
||||||
@@ -79,6 +85,12 @@ class YouPlotIRISTest < Test::Unit::TestCase
|
|||||||
assert_equal fixture('iris-lineplots.txt'), @stderr_file.read
|
assert_equal fixture('iris-lineplots.txt'), @stderr_file.read
|
||||||
end
|
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
|
test :scatter do
|
||||||
YouPlot::Command.new(['scatter', '-H', '-d,', '-t', 'IRIS-SCATTER']).run
|
YouPlot::Command.new(['scatter', '-H', '-d,', '-t', 'IRIS-SCATTER']).run
|
||||||
assert_equal fixture('iris-scatter.txt'), @stderr_file.read
|
assert_equal fixture('iris-scatter.txt'), @stderr_file.read
|
||||||
|
Reference in New Issue
Block a user