15 Commits

Author SHA1 Message Date
kojix2
4f17579846 v0.4.2 2021-06-10 11:35:35 +09:00
kojix2
81df12a033 Changed width option from Integer to Numeric
This is to keep consistency with other options
2021-06-10 11:33:46 +09:00
kojix2
a8073bc684 Convert xlim and ylim types to numbers
Fix (#18)
2021-06-10 11:19:35 +09:00
kojix2
23bb767afe Revert "Accept hyphens as an output option"
This reverts commit dfc027d972.

No need to change.
2021-06-08 17:44:53 +09:00
kojix2
dfc027d972 Accept hyphens as an output option 2021-06-07 23:51:46 +09:00
kojix2
7a1bacccbc Update README.md
Center the logo and badge
2021-06-04 00:20:54 +09:00
kojix2
92989eb582 🚀 Transferred YouPlot to RedDataTools 2021-06-03 12:01:07 +09:00
kojix2
33c68c0607 v0.4.1 2021-06-03 11:06:59 +09:00
kojix2
30b3b6e7d3 Rubocop auto correct 2021-06-03 11:03:49 +09:00
kojix2
d49a11bb7a Merge branch 'v0.4.1' 2021-06-03 11:01:20 +09:00
kojix2
c573d690bc Revert "Set the Gem Ruby version to 2.6 or higher"
I changed my mind, it better work on 2.4!

This reverts commit 2649959745.
2021-06-03 10:53:12 +09:00
kojix2
f823377c50 Make tests pass in Ruby 2.4 2021-06-03 10:48:47 +09:00
kojix2
d9777435a4 Add Test on ruby 2.4 2021-06-03 10:39:43 +09:00
kojix2
2649959745 Set the Gem Ruby version to 2.6 or higher 2021-06-03 10:32:20 +09:00
kojix2
4651c697d4 Add reverse to count 2021-05-31 22:50:11 +09:00
12 changed files with 124 additions and 63 deletions

View File

@@ -7,7 +7,7 @@ jobs:
strategy: strategy:
matrix: matrix:
os: ['ubuntu', 'macos'] os: ['ubuntu', 'macos']
ruby: [ '2.6', '2.7', '3.0' ] ruby: [ '2.4', '2.5', '2.6', '2.7', '3.0' ]
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1 - uses: ruby/setup-ruby@v1

View File

@@ -1,16 +1,19 @@
<p align="center"> <div align="center">
<img src="logo.svg" width="60%" height="60%" /> <img src="logo.svg" width="66%" height="66%" />
</p>
![Build Status](https://github.com/kojix2/youplot/workflows/test/badge.svg) <hr>
[![Gem Version](https://badge.fury.io/rb/youplot.svg)](https://badge.fury.io/rb/youplot)
[![Docs Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://rubydoc.info/gems/youplot)
[![The MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE.txt)
[![DOI](https://zenodo.org/badge/283230219.svg)](https://zenodo.org/badge/latestdoi/283230219)
YouPlot is a command line tool for Unicode Plotting working with data from standard stream. ![Build Status](https://github.com/red-data-tools/YouPlot/workflows/test/badge.svg)
[![Gem Version](https://badge.fury.io/rb/youplot.svg)](https://badge.fury.io/rb/youplot)
[![Docs Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://rubydoc.info/gems/youplot)
[![The MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE.txt)
[![DOI](https://zenodo.org/badge/283230219.svg)](https://zenodo.org/badge/latestdoi/283230219)
:bar_chart: Powered by [UnicodePlot](https://github.com/red-data-tools/unicode_plot.rb) YouPlot is a command line tool that draws plots in a terminal.
:bar_chart: Powered by [UnicodePlot](https://github.com/red-data-tools/unicode_plot.rb)
</div>
## Installation ## Installation
@@ -230,8 +233,8 @@ uplot colors
YouPlot is a library under development, so even small improvements like typofix are welcome! YouPlot is a library under development, so even small improvements like typofix are welcome!
Please feel free to send us your pull requests. Please feel free to send us your pull requests.
* [Report bugs](https://github.com/kojix2/youplot/issues) * [Report bugs](https://github.com/red-data-tools/YouPlot/issues)
* Fix bugs and [submit pull requests](https://github.com/kojix2/youplot/pulls) * Fix bugs and [submit pull requests](https://github.com/red-data-tools/YouPlot/pulls)
* Write, clarify, or fix documentation * Write, clarify, or fix documentation
* English corrections by native speakers are welcome. * English corrections by native speakers are welcome.
* Suggest or add new features * Suggest or add new features
@@ -249,7 +252,6 @@ bundle exec rake install # Installation from source code
### Acknowledgements ### Acknowledgements
* [Red Data Tools](https://github.com/red-data-tools) - Technical support
* [sampo grafiikka](https://jypg.net/sampo_grafiikka) - Project logo creation * [sampo grafiikka](https://jypg.net/sampo_grafiikka) - Project logo creation
* [yutaas](https://github.com/yutaas) - English proofreading * [yutaas](https://github.com/yutaas) - English proofreading

View File

@@ -6,22 +6,30 @@ module YouPlot
module Processing module Processing
module_function module_function
def count_values(arr, tally: true) def count_values(arr, tally: true, reverse: false)
# tally was added in Ruby 2.7 # tally was added in Ruby 2.7
if tally && Enumerable.method_defined?(:tally) result = \
arr.tally if tally && Enumerable.method_defined?(:tally)
else arr.tally
# value_counts Enumerable::Statistics else
arr.value_counts(dropna: false) # value_counts Enumerable::Statistics
end arr.value_counts(dropna: false)
.sort do |a, b|
# compare values
r = b[1] <=> a[1]
# If the values are the same, compare by name
r = a[0] <=> b[0] if r == 0
r
end end
.transpose
# sorting
result = result.sort do |a, b|
# compare values
r = b[1] <=> a[1]
# If the values are the same, compare by name
r = a[0] <=> b[0] if r.zero?
r
end
# --reverse option
result.reverse! if reverse
# prepare for barplot
result.transpose
end end
end end
end end

View File

@@ -14,12 +14,12 @@ module YouPlot
module_function module_function
def barplot(data, params, fmt = nil, count: false) def barplot(data, params, fmt = nil, count: false, reverse: false)
headers = data.headers headers = data.headers
series = data.series series = data.series
# `uplot count` # `uplot count`
if count if count
series = Processing.count_values(series[0]) series = Processing.count_values(series[0], reverse: reverse)
params.title = headers[0] if headers params.title = headers[0] if headers
end end
if series.size == 1 if series.size == 1

View File

@@ -146,7 +146,7 @@ module YouPlot
when :bar, :barplot when :bar, :barplot
@backend.barplot(data, params, options[:fmt]) @backend.barplot(data, params, options[:fmt])
when :count, :c when :count, :c
@backend.barplot(data, params, count: true) @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

View File

@@ -14,7 +14,7 @@ module YouPlot
# Remove blank lines # Remove blank lines
arr.delete_if do |i| arr.delete_if do |i|
i == [] or i.all? nil i == [] or i.all?(&:nil?)
end end
# get header # get header

View File

@@ -11,8 +11,8 @@ module YouPlot
:fmt, :fmt,
:progressive, :progressive,
:encoding, :encoding,
:color_names, :reverse, # count
:debug, :color_names, # color
keyword_init: true :debug
) )
end end

View File

@@ -15,16 +15,16 @@ module YouPlot
@command = nil @command = nil
@options = Options.new( @options = Options.new(
delimiter: "\t", "\t", # elimiter:
transpose: false, false, # transpose:
headers: nil, nil, # headers:
pass: false, false, # pass:
output: $stderr, $stderr, # output:
fmt: 'xyy', 'xyy', # fmt:
progressive: false, false, # progressive:
encoding: nil, nil, # encoding:
color_names: false, false, # color_names:
debug: false false # debug:
) )
@params = Parameters.new @params = Parameters.new
@@ -64,7 +64,7 @@ module YouPlot
parser.on('-y', '--ylabel STR', String, 'print string on the far left of the plot') do |v| parser.on('-y', '--ylabel STR', String, 'print string on the far left of the plot') do |v|
params.ylabel = v params.ylabel = v
end end
parser.on('-w', '--width INT', Integer, 'number of characters per row') do |v| parser.on('-w', '--width INT', Numeric, 'number of characters per row') do |v|
params.width = v params.width = v
end end
parser.on('-h', '--height INT', Numeric, 'number of rows') do |v| parser.on('-h', '--height INT', Numeric, 'number of rows') do |v|
@@ -118,7 +118,7 @@ module YouPlot
Program: YouPlot (Tools for plotting on the terminal) Program: YouPlot (Tools for plotting on the terminal)
Version: #{YouPlot::VERSION} (using UnicodePlot #{UnicodePlot::VERSION}) Version: #{YouPlot::VERSION} (using UnicodePlot #{UnicodePlot::VERSION})
Source: https://github.com/kojix2/youplot Source: https://github.com/red-data-tools/YouPlot
Usage: uplot <command> [options] <in.tsv> Usage: uplot <command> [options] <in.tsv>
@@ -163,20 +163,21 @@ module YouPlot
end end
def sub_parser_add_canvas def sub_parser_add_canvas
sub_parser.on_head('--canvas STR', String, 'type of canvas') do |v| canvas_types = UnicodePlot::Canvas::CANVAS_CLASS_MAP.keys.join(', ')
sub_parser.on_head('--canvas STR', String, 'type of canvas', "(#{canvas_types})") do |v|
params.canvas = v.to_sym params.canvas = v.to_sym
end end
end end
def sub_parser_add_xlim def sub_parser_add_xlim
sub_parser.on_head('--xlim FLOAT,FLOAT', Array, 'plotting range for the x coordinate') do |v| sub_parser.on_head('--xlim FLOAT,FLOAT', Array, 'plotting range for the x coordinate') do |v|
params.xlim = v params.xlim = v.map(&:to_f)
end end
end end
def sub_parser_add_ylim def sub_parser_add_ylim
sub_parser.on_head('--ylim FLOAT,FLOAT', Array, 'plotting range for the y coordinate') do |v| sub_parser.on_head('--ylim FLOAT,FLOAT', Array, 'plotting range for the y coordinate') do |v|
params.ylim = v params.ylim = v.map(&:to_f)
end end
end end
@@ -226,6 +227,9 @@ module YouPlot
sub_parser_add_xscale sub_parser_add_xscale
when :count, :c when :count, :c
sub_parser.on_head('-r', '--reverse', TrueClass, 'reverse the result of comparisons') do |v|
options.reverse = v
end
sub_parser_add_symbol sub_parser_add_symbol
sub_parser_add_xscale sub_parser_add_xscale
@@ -270,7 +274,7 @@ module YouPlot
sub_parser_add_xlim sub_parser_add_xlim
when :colors, :color, :colours, :colour when :colors, :color, :colours, :colour
sub_parser.on_head('-n', '--names', 'show color names only', TrueClass) do |v| sub_parser.on_head('-n', '--names', TrueClass, 'show color names only') do |v|
options[:color_names] = v options[:color_names] = v
end end

View File

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

38
test/fixtures/iris-count.txt vendored Normal file
View File

@@ -0,0 +1,38 @@
sepal_length
┌ ┐
5.0 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 10.0
5.1 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 9.0
6.3 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 9.0
5.7 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■ 8.0
6.7 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■ 8.0
5.5 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 7.0
5.8 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 7.0
6.4 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 7.0
4.9 ┤■■■■■■■■■■■■■■■■■■■■ 6.0
5.4 ┤■■■■■■■■■■■■■■■■■■■■ 6.0
5.6 ┤■■■■■■■■■■■■■■■■■■■■ 6.0
6.0 ┤■■■■■■■■■■■■■■■■■■■■ 6.0
6.1 ┤■■■■■■■■■■■■■■■■■■■■ 6.0
4.8 ┤■■■■■■■■■■■■■■■■■ 5.0
6.5 ┤■■■■■■■■■■■■■■■■■ 5.0
4.6 ┤■■■■■■■■■■■■■■ 4.0
5.2 ┤■■■■■■■■■■■■■■ 4.0
6.2 ┤■■■■■■■■■■■■■■ 4.0
6.9 ┤■■■■■■■■■■■■■■ 4.0
7.7 ┤■■■■■■■■■■■■■■ 4.0
4.4 ┤■■■■■■■■■■ 3.0
5.9 ┤■■■■■■■■■■ 3.0
6.8 ┤■■■■■■■■■■ 3.0
7.2 ┤■■■■■■■■■■ 3.0
4.7 ┤■■■■■■■ 2.0
6.6 ┤■■■■■■■ 2.0
4.3 ┤■■■ 1.0
4.5 ┤■■■ 1.0
5.3 ┤■■■ 1.0
7.0 ┤■■■ 1.0
7.1 ┤■■■ 1.0
7.3 ┤■■■ 1.0
7.4 ┤■■■ 1.0
7.6 ┤■■■ 1.0
7.9 ┤■■■ 1.0
└ ┘

View File

@@ -40,6 +40,8 @@ class YouPlotIRISTest < Test::Unit::TestCase
assert_equal fixture('iris-barplot.txt'), @stderr_file.read assert_equal fixture('iris-barplot.txt'), @stderr_file.read
end end
# barplot doesn't make sense, but just to make sure it works.
test :bar do test :bar do
YouPlot::Command.new(['bar', '-H', '-d,', '-t', 'IRIS-BARPLOT']).run YouPlot::Command.new(['bar', '-H', '-d,', '-t', 'IRIS-BARPLOT']).run
assert_equal fixture('iris-barplot.txt'), @stderr_file.read assert_equal fixture('iris-barplot.txt'), @stderr_file.read
@@ -55,6 +57,8 @@ class YouPlotIRISTest < Test::Unit::TestCase
assert_equal fixture('iris-histogram.txt'), @stderr_file.read assert_equal fixture('iris-histogram.txt'), @stderr_file.read
end end
# Yeah, lineplot/lineplots don't make sense too.
test :lineplot do test :lineplot do
YouPlot::Command.new(['lineplot', '-H', '-d,', '-t', 'IRIS-LINEPLOT']).run YouPlot::Command.new(['lineplot', '-H', '-d,', '-t', 'IRIS-LINEPLOT']).run
assert_equal fixture('iris-lineplot.txt'), @stderr_file.read assert_equal fixture('iris-lineplot.txt'), @stderr_file.read
@@ -105,15 +109,20 @@ class YouPlotIRISTest < Test::Unit::TestCase
assert_equal fixture('iris-boxplot.txt'), @stderr_file.read assert_equal fixture('iris-boxplot.txt'), @stderr_file.read
end end
# test :c do # Yeah, lineplot/lineplots don't make sense too.
# YouPlot::Command.new(['count', '-H', '-d,']).run # Just checking the behavior.
# assert_equal fixture('iris-count.txt'), @stderr_file.read
# end
# test :count do test :c do
# YouPlot::Command.new(['c', '-H', '-d,']).run YouPlot::Command.new(['count', '-H', '-d,']).run
# assert_equal fixture('iris-count.txt'), @stderr_file.read assert_equal fixture('iris-count.txt'), @stderr_file.read
# end end
test :count do
YouPlot::Command.new(['c', '-H', '-d,']).run
assert_equal fixture('iris-count.txt'), @stderr_file.read
end
# Output options.
test :plot_output_stdout do test :plot_output_stdout do
YouPlot::Command.new(['bar', '-o', '-H', '-d,', '-t', 'IRIS-BARPLOT']).run YouPlot::Command.new(['bar', '-o', '-H', '-d,', '-t', 'IRIS-BARPLOT']).run

View File

@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
spec.summary = 'A command line tool for Unicode Plotting' spec.summary = 'A command line tool for Unicode Plotting'
spec.description = 'A command line tool for Unicode Plotting' spec.description = 'A command line tool for Unicode Plotting'
spec.homepage = 'https://github.com/kojix2/youplot' spec.homepage = 'https://github.com/red-data-tools/YouPlot'
spec.license = 'MIT' spec.license = 'MIT'
spec.required_ruby_version = Gem::Requirement.new('>= 2.4.0') spec.required_ruby_version = Gem::Requirement.new('>= 2.4.0')