mirror of
https://github.com/red-data-tools/YouPlot.git
synced 2025-09-19 02:18:08 +08:00
Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
d6b6ae963d | ||
![]() |
3492f52df9 | ||
![]() |
21626122eb | ||
![]() |
38084c6db5 | ||
![]() |
59d200cae0 | ||
![]() |
cd8ee7f9d9 | ||
![]() |
9144207c85 | ||
![]() |
e0914beec8 | ||
![]() |
e146bc66f3 | ||
![]() |
bc0204af53 |
12
README.md
12
README.md
@@ -2,6 +2,8 @@
|
||||
|
||||
[](https://travis-ci.com/kojix2/uplot)
|
||||
[](https://badge.fury.io/rb/u-plot)
|
||||
[](https://rubydoc.info/gems/u-plot)
|
||||
[](LICENSE.txt)
|
||||
|
||||
Create ASCII charts on the terminal with data from standard streams in the pipeline.
|
||||
|
||||
@@ -17,7 +19,7 @@ gem install u-plot
|
||||
|
||||
## Usage
|
||||
|
||||
### histogram
|
||||
**histogram**
|
||||
|
||||
```sh
|
||||
ruby -r numo/narray -e "puts Numo::DFloat.new(1000).rand_norm.to_a" \
|
||||
@@ -46,6 +48,14 @@ ruby -r numo/narray -e "puts Numo::DFloat.new(1000).rand_norm.to_a" \
|
||||
Frequency
|
||||
```
|
||||
|
||||
**scatter**
|
||||
|
||||
```sh
|
||||
wget https://raw.githubusercontent.com/uiuc-cse/data-fa14/gh-pages/data/iris.csv -qO - \
|
||||
| cut -f1-4 -d, \
|
||||
| uplot scatter -H -d, -t IRIS -m 10
|
||||
```
|
||||
|
||||
## Development
|
||||
|
||||
## Contributing
|
||||
|
@@ -85,7 +85,7 @@ module Uplot
|
||||
params.padding = v
|
||||
end
|
||||
.on('-c', '--color VAL', String) do |v|
|
||||
params.color = v.to_sym
|
||||
params.color = v =~ /\A[0-9]+\z/ ? v.to_i : v.to_sym
|
||||
end
|
||||
.on('-x', '--xlabel VAL', String) do |v|
|
||||
params.xlabel = v
|
||||
@@ -259,9 +259,9 @@ module Uplot
|
||||
Plot.line(data, params)
|
||||
when :lines, :lineplots
|
||||
Plot.lines(data, params, fmt)
|
||||
when :scatter, :scatterplot
|
||||
when :scatter, :s
|
||||
Plot.scatter(data, params, fmt)
|
||||
when :density
|
||||
when :density, :d
|
||||
Plot.density(data, params, fmt)
|
||||
when :box, :boxplot
|
||||
Plot.boxplot(data, params)
|
||||
|
@@ -5,13 +5,32 @@ module Uplot
|
||||
module_function
|
||||
|
||||
def input(input, delimiter, headers, transpose)
|
||||
arr = read_csv(input, delimiter)
|
||||
arr = parse_as_csv(input, delimiter)
|
||||
headers = get_headers(arr, headers, transpose)
|
||||
series = get_series(arr, headers, transpose)
|
||||
Data.new(headers, series)
|
||||
if headers.nil?
|
||||
Data.new(headers, series)
|
||||
else
|
||||
if headers.include?(nil)
|
||||
warn "\e[35mHeaders contains nil in it.\e[0m"
|
||||
elsif headers.include? ''
|
||||
warn "\e[35mHeaders contains \"\" in it.\e[0m"
|
||||
end
|
||||
h_size = headers.size
|
||||
s_size = series.size
|
||||
if h_size == s_size
|
||||
Data.new(headers, series)
|
||||
elsif h_size > s_size
|
||||
warn "\e[35mThe number of headers is greater than the number of series.\e[0m"
|
||||
exit 1
|
||||
elsif h_size < s_size
|
||||
warn "\e[35mThe number of headers is less than the number of series.\e[0m"
|
||||
exit 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def read_csv(input, delimiter)
|
||||
def parse_as_csv(input, delimiter)
|
||||
CSV.parse(input, col_sep: delimiter)
|
||||
.delete_if do |i|
|
||||
i == [] or i.all? nil
|
||||
|
@@ -1,3 +1,3 @@
|
||||
module Uplot
|
||||
VERSION = '0.2.0'.freeze
|
||||
VERSION = '0.2.2'.freeze
|
||||
end
|
||||
|
@@ -1,4 +1,6 @@
|
||||
$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
|
||||
require 'simplecov'
|
||||
SimpleCov.start
|
||||
|
||||
require 'uplot'
|
||||
|
||||
require 'test/unit'
|
||||
|
4
test/uplot/command_test.rb
Normal file
4
test/uplot/command_test.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
require_relative '../test_helper.rb'
|
||||
|
||||
class UplotCommandTest < Test::Unit::TestCase
|
||||
end
|
4
test/uplot/plot_test.rb
Normal file
4
test/uplot/plot_test.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
require_relative '../test_helper.rb'
|
||||
|
||||
class UplotPlotTest < Test::Unit::TestCase
|
||||
end
|
130
test/uplot/preprocessing_test.rb
Normal file
130
test/uplot/preprocessing_test.rb
Normal file
@@ -0,0 +1,130 @@
|
||||
require_relative '../test_helper.rb'
|
||||
|
||||
class UplotPreprocessingTest < Test::Unit::TestCase
|
||||
def setup
|
||||
@m = Uplot::Preprocessing
|
||||
end
|
||||
|
||||
test :transpose2 do
|
||||
n = nil
|
||||
|
||||
assert_equal([[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
[7, 8, 9]], @m.transpose2([[1, 4, 7],
|
||||
[2, 5, 8],
|
||||
[3, 6, 9]]))
|
||||
assert_equal([[1, 2, 3],
|
||||
[4, 5, n],
|
||||
[6, n, n]], @m.transpose2([[1, 4, 6],
|
||||
[2, 5],
|
||||
[3]]))
|
||||
assert_equal([[1, 2, 3],
|
||||
[n, 4, 5],
|
||||
[n, n, 6]], @m.transpose2([[1],
|
||||
[2, 4],
|
||||
[3, 5, 6]]))
|
||||
end
|
||||
|
||||
test :get_headers do
|
||||
assert_equal([1, 4, 7], @m.get_headers([[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
[7, 8, 9]], true, true))
|
||||
|
||||
assert_equal([1, 2, 3], @m.get_headers([[1, 4, 6],
|
||||
[2, 5],
|
||||
[3]], true, true))
|
||||
|
||||
assert_equal([1, 2, 3], @m.get_headers([[1],
|
||||
[2, 4],
|
||||
[3, 5, 6]], true, true))
|
||||
|
||||
assert_equal([1, 2, 3], @m.get_headers([[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
[7, 8, 9]], true, false))
|
||||
|
||||
assert_equal([1, 4, 6], @m.get_headers([[1, 4, 6],
|
||||
[2, 5],
|
||||
[3]], true, false))
|
||||
|
||||
assert_equal([1], @m.get_headers([[1],
|
||||
[2, 4],
|
||||
[3, 5, 6]], true, false))
|
||||
|
||||
assert_equal(nil, @m.get_headers([[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
[7, 8, 9]], false, true))
|
||||
|
||||
assert_equal(nil, @m.get_headers([[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
[7, 8, 9]], false, false))
|
||||
end
|
||||
|
||||
test :get_series do
|
||||
n = nil
|
||||
|
||||
assert_equal([[2, 3], [5, 6], [8, 9]], @m.get_series([[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
[7, 8, 9]], true, true))
|
||||
|
||||
assert_equal([[4, 6], [5], []], @m.get_series([[1, 4, 6],
|
||||
[2, 5],
|
||||
[3]], true, true))
|
||||
|
||||
assert_equal([[], [4], [5, 6]], @m.get_series([[1],
|
||||
[2, 4],
|
||||
[3, 5, 6]], true, true))
|
||||
|
||||
assert_equal([[4, 7], [5, 8], [6, 9]], @m.get_series([[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
[7, 8, 9]], true, false))
|
||||
|
||||
assert_equal([[2, 3], [5, nil]], @m.get_series([[1, 4, 6],
|
||||
[2, 5],
|
||||
[3]], true, false))
|
||||
|
||||
assert_equal([[2, 3], [4, 5], [nil, 6]], @m.get_series([[1],
|
||||
[2, 4],
|
||||
[3, 5, 6]], true, false))
|
||||
|
||||
assert_equal([[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
[7, 8, 9]], @m.get_series([[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
[7, 8, 9]], false, true))
|
||||
|
||||
assert_equal([[1, 4, 6],
|
||||
[2, 5],
|
||||
[3]], @m.get_series([[1, 4, 6],
|
||||
[2, 5],
|
||||
[3]], false, true))
|
||||
|
||||
assert_equal([[1],
|
||||
[2, 4],
|
||||
[3, 5, 6]], @m.get_series([[1],
|
||||
[2, 4],
|
||||
[3, 5, 6]], false, true))
|
||||
|
||||
assert_equal([[1, 4, 7],
|
||||
[2, 5, 8],
|
||||
[3, 6, 9]], @m.get_series([[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
[7, 8, 9]], false, false))
|
||||
|
||||
assert_equal([[1, 2, 3],
|
||||
[4, 5, n],
|
||||
[6, n, n]], @m.get_series([[1, 4, 6],
|
||||
[2, 5],
|
||||
[3]], false, false))
|
||||
|
||||
assert_equal([[1, 2, 3],
|
||||
[n, 4, 5],
|
||||
[n, n, 6]], @m.get_series([[1],
|
||||
[2, 4],
|
||||
[3, 5, 6]], false, false))
|
||||
end
|
||||
|
||||
test :count do
|
||||
assert_equal([%i[a b c], [3, 2, 1]], @m.count(%i[a a a b b c]))
|
||||
assert_equal([%i[c b a], [3, 2, 1]], @m.count(%i[a b b c c c]))
|
||||
end
|
||||
end
|
@@ -24,5 +24,6 @@ Gem::Specification.new do |spec|
|
||||
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
|
||||
|
Reference in New Issue
Block a user