mirror of
https://github.com/red-data-tools/YouPlot.git
synced 2025-09-19 19:08:07 +08:00
Compare commits
18 Commits
kojix2-rea
...
v0.4.4
Author | SHA1 | Date | |
---|---|---|---|
![]() |
19f05e57ac | ||
![]() |
f11fd6babb | ||
![]() |
9d69c4322c | ||
![]() |
41c0d37a13 | ||
![]() |
a1dcc532ea | ||
![]() |
523700348c | ||
![]() |
e34ab2b097 | ||
![]() |
f8fe010d27 | ||
![]() |
e76d4f279e | ||
![]() |
3a1a29424d | ||
![]() |
b78da2388a | ||
![]() |
a7bb75e87d | ||
![]() |
ca9f97a7dc | ||
![]() |
f67a5ce913 | ||
![]() |
dbbfd366be | ||
![]() |
42cadee553 | ||
![]() |
e689c69838 | ||
![]() |
c53169e9ee |
7
.github/workflows/ci.yml
vendored
7
.github/workflows/ci.yml
vendored
@@ -6,13 +6,12 @@ jobs:
|
|||||||
runs-on: ${{ matrix.os }}-latest
|
runs-on: ${{ matrix.os }}-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os: ['ubuntu', 'macos']
|
os: [ 'ubuntu', 'macos' ]
|
||||||
ruby: [ '2.4', '2.5', '2.6', '2.7', '3.0' ]
|
ruby: [ '2.4', '2.5', '2.6', '2.7', '3.0', '3.1' ]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- uses: ruby/setup-ruby@v1
|
- uses: ruby/setup-ruby@v1
|
||||||
with:
|
with:
|
||||||
ruby-version: ${{ matrix.ruby }}
|
ruby-version: ${{ matrix.ruby }}
|
||||||
- run: gem install bundler
|
bundler-cache: true
|
||||||
- run: bundle install
|
|
||||||
- run: bundle exec rake test
|
- run: bundle exec rake test
|
||||||
|
23
.github/workflows/doc.yml
vendored
Normal file
23
.github/workflows/doc.yml
vendored
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
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: 3.1
|
||||||
|
- 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
|
6
Gemfile
6
Gemfile
@@ -4,3 +4,9 @@ source 'https://rubygems.org'
|
|||||||
|
|
||||||
# Specify your gem's dependencies in youplot.gemspec
|
# Specify your gem's dependencies in youplot.gemspec
|
||||||
gemspec
|
gemspec
|
||||||
|
|
||||||
|
group :test do
|
||||||
|
gem 'rake'
|
||||||
|
gem 'simplecov'
|
||||||
|
gem 'test-unit'
|
||||||
|
end
|
||||||
|
10
README.md
10
README.md
@@ -7,7 +7,7 @@
|
|||||||
<a href="https://rubydoc.info/gems/youplot/"><img alt="Docs Stable" src="https://img.shields.io/badge/docs-stable-blue.svg"></a>
|
<a href="https://rubydoc.info/gems/youplot/"><img alt="Docs Stable" src="https://img.shields.io/badge/docs-stable-blue.svg"></a>
|
||||||
<a href="LICENSE.txt"><img alt="The MIT License" src="https://img.shields.io/badge/license-MIT-blue.svg"></a>
|
<a href="LICENSE.txt"><img alt="The MIT License" src="https://img.shields.io/badge/license-MIT-blue.svg"></a>
|
||||||
|
|
||||||
YouPlot is a command line tool that draws plots in the terminal.
|
YouPlot is a command line tool that draws plots on the terminal.
|
||||||
|
|
||||||
:bar_chart: Powered by [UnicodePlot](https://github.com/red-data-tools/unicode_plot.rb)
|
:bar_chart: Powered by [UnicodePlot](https://github.com/red-data-tools/unicode_plot.rb)
|
||||||
</div>
|
</div>
|
||||||
@@ -189,7 +189,7 @@ The following sub-commands are available.
|
|||||||
* The `--help` option will show more detailed options for each subcommand.
|
* The `--help` option will show more detailed options for each subcommand.
|
||||||
* `uplot hist --help`
|
* `uplot hist --help`
|
||||||
|
|
||||||
### Set columns as x-axis or y-axis?
|
### Set columns as x-axis or y-axis
|
||||||
|
|
||||||
* YouPlot treats the first column as the X axis and the second column as the Y axis. When working with multiple series, the first column is the X axis, the second column is series Y1, the third column is series Y2, and so on.
|
* YouPlot treats the first column as the X axis and the second column as the Y axis. When working with multiple series, the first column is the X axis, the second column is series Y1, the third column is series Y2, and so on.
|
||||||
* If you pass only one column of data for `line` and `bar`, YouPlot will automatically use a sequential number starting from 1 as the X-axis.
|
* If you pass only one column of data for `line` and `bar`, YouPlot will automatically use a sequential number starting from 1 as the X-axis.
|
||||||
@@ -203,7 +203,7 @@ The following sub-commands are available.
|
|||||||
|
|
||||||
### Categorical data
|
### Categorical data
|
||||||
|
|
||||||
* With gne datamash, you can manage to handle categorized data.
|
* With GNU datamash, you can manage to handle categorized data.
|
||||||
* `cat test/fixtures/iris.csv | sed '/^$/d' | datamash --header-in --output-delimiter=: -t, -g5 collapse 3,4 | cut -f2-3 -d: | sed 's/:/\n/g' | uplot s -d, -T --fmt xyxy`
|
* `cat test/fixtures/iris.csv | sed '/^$/d' | datamash --header-in --output-delimiter=: -t, -g5 collapse 3,4 | cut -f2-3 -d: | sed 's/:/\n/g' | uplot s -d, -T --fmt xyxy`
|
||||||
* This is not so easy...
|
* This is not so easy...
|
||||||
|
|
||||||
@@ -241,6 +241,10 @@ bundle exec rake install # Installation from source code
|
|||||||
bundle exec exe/uplot # Run youplot (Try out the edited 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
|
### Acknowledgements
|
||||||
|
|
||||||
* [sampo grafiikka](https://jypg.net/sampo_grafiikka) - Project logo creation
|
* [sampo grafiikka](https://jypg.net/sampo_grafiikka) - Project logo creation
|
||||||
|
@@ -6,6 +6,12 @@ require_relative 'youplot/parameters'
|
|||||||
require_relative 'youplot/command'
|
require_relative 'youplot/command'
|
||||||
|
|
||||||
module YouPlot
|
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
|
class << self
|
||||||
attr_accessor :run_as_executable
|
attr_accessor :run_as_executable
|
||||||
|
|
||||||
@@ -13,5 +19,4 @@ module YouPlot
|
|||||||
@run_as_executable
|
@run_as_executable
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@run_as_executable = false
|
|
||||||
end
|
end
|
||||||
|
@@ -127,11 +127,10 @@ module YouPlot
|
|||||||
|
|
||||||
def plot_xyxy(data, method1, params)
|
def plot_xyxy(data, method1, params)
|
||||||
headers = data.headers
|
headers = data.headers
|
||||||
series = data.series
|
series2 = data.series
|
||||||
|
.map { |s| s.map(&:to_f) }
|
||||||
|
.each_slice(2).to_a
|
||||||
method2 = get_method2(method1)
|
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.name ||= headers[0] if headers
|
||||||
params.xlim ||= series2.map(&:first).flatten.minmax # why need?
|
params.xlim ||= series2.map(&:first).flatten.minmax # why need?
|
||||||
params.ylim ||= series2.map(&:last).flatten.minmax # why need?
|
params.ylim ||= series2.map(&:last).flatten.minmax # why need?
|
||||||
|
@@ -40,6 +40,24 @@ 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
|
||||||
@@ -63,9 +81,15 @@ module YouPlot
|
|||||||
# normal mode
|
# normal mode
|
||||||
else
|
else
|
||||||
# Sometimes the input file does not end with a newline code.
|
# Sometimes the input file does not end with a newline code.
|
||||||
while (input = Kernel.gets(nil))
|
begin
|
||||||
|
begin
|
||||||
|
input = Kernel.gets(nil)
|
||||||
|
rescue Errno::ENOENT => e
|
||||||
|
warn e.message
|
||||||
|
next
|
||||||
|
end
|
||||||
main(input)
|
main(input)
|
||||||
end
|
end until input
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -135,7 +159,12 @@ module YouPlot
|
|||||||
rescue CSV::MalformedCSVError => e
|
rescue CSV::MalformedCSVError => e
|
||||||
warn 'Failed to parse the text. '
|
warn 'Failed to parse the text. '
|
||||||
warn 'Please try to set the correct character encoding with --encoding option.'
|
warn 'Please try to set the correct character encoding with --encoding option.'
|
||||||
raise e
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
data
|
data
|
||||||
|
@@ -9,7 +9,8 @@ module YouPlot
|
|||||||
class Error < StandardError; end
|
class Error < StandardError; end
|
||||||
|
|
||||||
attr_reader :command, :options, :params,
|
attr_reader :command, :options, :params,
|
||||||
:main_parser, :sub_parser
|
:main_parser, :sub_parser,
|
||||||
|
:config_file, :config
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@command = nil
|
@command = nil
|
||||||
@@ -28,6 +29,55 @@ 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
|
||||||
|
|
||||||
|
def candidate_paths
|
||||||
|
paths = []
|
||||||
|
paths << ENV['MYYOUPLOTRC'] if ENV['MYYOUPLOTRC']
|
||||||
|
paths << '.youplot.yml'
|
||||||
|
paths << '.youplotrc'
|
||||||
|
paths << File.join(ENV['HOME'], '.youplotrc') if ENV['HOME']
|
||||||
|
paths << File.join(ENV['HOME'], '.youplot.yml') if ENV['HOME']
|
||||||
|
paths
|
||||||
|
end
|
||||||
|
|
||||||
|
def find_config_file
|
||||||
|
config_file_path = nil
|
||||||
|
candidate_paths.each do |file|
|
||||||
|
path = File.expand_path(file)
|
||||||
|
if File.exist?(path)
|
||||||
|
config_file_path = path
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
config_file_path
|
||||||
|
end
|
||||||
|
|
||||||
|
def read_config_file(path)
|
||||||
|
require 'yaml'
|
||||||
|
YAML.load_file(path)
|
||||||
|
end
|
||||||
|
|
||||||
|
def configure(config)
|
||||||
|
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: #{k}"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_base_parser
|
def create_base_parser
|
||||||
@@ -95,7 +145,7 @@ module YouPlot
|
|||||||
parser.on('-M', '--monochrome', TrueClass, 'no colouring even if writing to a tty') do |_v|
|
parser.on('-M', '--monochrome', TrueClass, 'no colouring even if writing to a tty') do |_v|
|
||||||
UnicodePlot::IOContext.define_method(:color?) { false } # FIXME
|
UnicodePlot::IOContext.define_method(:color?) { false } # FIXME
|
||||||
end
|
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
|
options[:encoding] = v
|
||||||
end
|
end
|
||||||
# Optparse adds the help option, but it doesn't show up in usage.
|
# Optparse adds the help option, but it doesn't show up in usage.
|
||||||
@@ -277,6 +327,8 @@ module YouPlot
|
|||||||
options[:color_names] = v
|
options[:color_names] = v
|
||||||
end
|
end
|
||||||
|
|
||||||
|
when :config
|
||||||
|
|
||||||
else
|
else
|
||||||
error_message = "uplot: unrecognized command '#{command}'"
|
error_message = "uplot: unrecognized command '#{command}'"
|
||||||
if YouPlot.run_as_executable?
|
if YouPlot.run_as_executable?
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module YouPlot
|
module YouPlot
|
||||||
VERSION = '0.4.2'
|
VERSION = '0.4.4'
|
||||||
end
|
end
|
||||||
|
@@ -19,10 +19,5 @@ Gem::Specification.new do |spec|
|
|||||||
spec.executables = %w[uplot youplot]
|
spec.executables = %w[uplot youplot]
|
||||||
spec.require_paths = ['lib']
|
spec.require_paths = ['lib']
|
||||||
|
|
||||||
spec.add_runtime_dependency 'unicode_plot'
|
spec.add_dependency 'unicode_plot', '>= 0.0.5'
|
||||||
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
|
end
|
||||||
|
Reference in New Issue
Block a user