mirror of
https://github.com/red-data-tools/YouPlot.git
synced 2025-09-19 19:08:07 +08:00
Compare commits
20 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
eb317e2bb5 | ||
![]() |
edd081562e | ||
![]() |
cc076d5cfe | ||
![]() |
6f5b73887d | ||
![]() |
e18344cc13 | ||
![]() |
ae1e7ba44e | ||
![]() |
4f78920915 | ||
![]() |
115ff6623d | ||
![]() |
1b666038bb | ||
![]() |
b368dc44b4 | ||
![]() |
9581cf730a | ||
![]() |
566cee883a | ||
![]() |
0aa6de0de5 | ||
![]() |
5d1a4fdf3c | ||
![]() |
a5cdc94bb0 | ||
![]() |
f2b7b94a09 | ||
![]() |
1d92ab8e2d | ||
![]() |
98e294fae9 | ||
![]() |
0af084916e | ||
![]() |
dee53a003c |
185
README.md
185
README.md
@@ -1,11 +1,12 @@
|
|||||||
# YouPlot
|

|
||||||
|
|
||||||

|

|
||||||
[](https://badge.fury.io/rb/youplot)
|
[](https://badge.fury.io/rb/youplot)
|
||||||
[](https://rubydoc.info/gems/youplot)
|
[](https://rubydoc.info/gems/youplot)
|
||||||
[](LICENSE.txt)
|
[](LICENSE.txt)
|
||||||
|
[](https://zenodo.org/badge/latestdoi/283230219)
|
||||||
|
|
||||||
Create ASCII charts on the terminal with data from standard streams in the pipeline.
|
YouPlot is a command line tool for Unicode Plotting working with data from standard stream.
|
||||||
|
|
||||||
: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)
|
||||||
|
|
||||||
@@ -15,16 +16,22 @@ Create ASCII charts on the terminal with data from standard streams in the pipel
|
|||||||
gem install youplot
|
gem install youplot
|
||||||
```
|
```
|
||||||
|
|
||||||
## Screenshots
|
## Quick Start
|
||||||
|
|
||||||
**histogram**
|
`cat data.tsv | uplot <command> [options]`
|
||||||
|
|
||||||
|
### barplot
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
ruby -r numo/narray -e "puts Numo::DFloat.new(1000).rand_norm.to_a" \
|
curl -sL https://git.io/ISLANDScsv \
|
||||||
| uplot hist --nbins 15
|
| sort -nk2 -t, \
|
||||||
|
| tail -n15 \
|
||||||
|
| uplot bar -d, -t "Areas of the World's Major Landmasses"
|
||||||
```
|
```
|
||||||
|
|
||||||
<img src="https://i.imgur.com/wpsoGJq.png" width="75%" height="75%">
|

|
||||||
|
|
||||||
|
### histogram
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
echo -e "from numpy import random;" \
|
echo -e "from numpy import random;" \
|
||||||
@@ -33,91 +40,119 @@ echo -e "from numpy import random;" \
|
|||||||
| python \
|
| python \
|
||||||
| uplot hist --nbins 20
|
| uplot hist --nbins 20
|
||||||
```
|
```
|
||||||
|

|
||||||
|
|
||||||
<img src="https://i.imgur.com/97R2MQx.png" width="75%" height="75%">
|
### lineplot
|
||||||
|
|
||||||
**scatter**
|
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
curl -s https://raw.githubusercontent.com/uiuc-cse/data-fa14/gh-pages/data/iris.csv \
|
curl -sL https://git.io/AirPassengers \
|
||||||
| cut -f1-4 -d, \
|
| cut -f2,3 -d, \
|
||||||
| uplot scatter -H -d, -t IRIS
|
| uplot line -d, -w 50 -h 15 -t AirPassengers --xlim 1950,1960 --ylim 0,600
|
||||||
```
|
```
|
||||||
|
|
||||||
<img src="https://i.imgur.com/STX7bFT.png" width="75%" height="75%">
|

|
||||||
|
|
||||||
**line**
|
### scatter
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
curl -s https://www.mhlw.go.jp/content/pcr_positive_daily.csv \
|
curl -sL https://git.io/IRIStsv \
|
||||||
| cut -f2 -d, \
|
| cut -f1-4 \
|
||||||
| uplot line -w 50 -h 15 -t 'PCR positive tests' --xlabel Date --ylabel number
|
| uplot scatter -H -t IRIS
|
||||||
```
|
```
|
||||||
|
|
||||||
<img src="https://i.imgur.com/PVl5dsa.png" width="75%" height="75%">
|

|
||||||
|
|
||||||
**box**
|
### density
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
curl -s https://raw.githubusercontent.com/uiuc-cse/data-fa14/gh-pages/data/iris.csv \
|
curl -sL https://git.io/IRIStsv \
|
||||||
| cut -f1-4 -d, \
|
| cut -f1-4 \
|
||||||
| uplot box -H -d, -t IRIS
|
| uplot density -H -t IRIS
|
||||||
```
|
```
|
||||||
|
|
||||||
<img src="https://i.imgur.com/sNI4SmN.png" width="75%" height="75%">
|

|
||||||
|
|
||||||
**colors**
|
### boxplot
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
uplot colors
|
curl -sL https://git.io/IRIStsv \
|
||||||
|
| cut -f1-4 \
|
||||||
|
| uplot boxplot -H -t IRIS
|
||||||
```
|
```
|
||||||
|
|
||||||
<img src="https://i.imgur.com/LxyHQsz.png">
|

|
||||||
|
|
||||||
|
### count
|
||||||
|
|
||||||
|
In this example, YouPlot counts the number of chromosomes where the gene is located from the human gene annotation file and create a bar chart. The human gene annotation file can be downloaded from the following website.
|
||||||
|
|
||||||
|
* https://www.gencodegenes.org/human/
|
||||||
|
|
||||||
|
```sh
|
||||||
|
cat gencode.v35.annotation.gff3 \
|
||||||
|
| grep -v '#' | grep 'gene' | cut -f1 | \
|
||||||
|
uplot count -t "The number of human gene annotations per chromosome" -c blue
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Note: `count` is not very fast because it runs in a Ruby script.
|
||||||
|
This is fine if the data is small, that is, in most cases. However, if you want to visualize huge data, it is faster to use a combination of common Unix commands as shown below.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
cat gencode.v35.annotation.gff3 | grep -v '#' | grep 'gene' | cut -f1 \
|
||||||
|
|sort | uniq -c | sort -nrk2 | awk '{print $2,$1}' \
|
||||||
|
| uplot bar -d ' ' -t "The number of human gene annotations per chromosome" -c blue
|
||||||
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
`uplot --help`
|
### Why YouPlot?
|
||||||
|
|
||||||
```
|
Wouldn't it be a bit of pain to have to run R, Python, Julia, gnuplot or whatever REPL just to check your data?
|
||||||
Program: YouPlot (Tools for plotting on the terminal)
|
YouPlot is a command line tool for this purpose. With YouPlot, you can continue working without leaving your terminal and shell.
|
||||||
Version: 0.2.7 (using UnicodePlot 0.0.4)
|
|
||||||
Source: https://github.com/kojix2/youplot
|
|
||||||
|
|
||||||
Usage: uplot <command> [options] <in.tsv>
|
### how to use YouPlot?
|
||||||
|
|
||||||
Commands:
|
`uplot` is the shortened form of `youplot`. You can use either.
|
||||||
barplot bar
|
|
||||||
histogram hist
|
|
||||||
lineplot line
|
|
||||||
lineplots lines
|
|
||||||
scatter s
|
|
||||||
density d
|
|
||||||
boxplot box
|
|
||||||
colors show the list of available colors
|
|
||||||
|
|
||||||
count c baplot based on the number of occurrences
|
| | |
|
||||||
(slower than `sort | uniq -c | sort -n -k1`)
|
|-----------------------------------|------------------------------------------------|
|
||||||
|
| Reads data from standard input | `cat data.tsv \| uplot <command> [options]` |
|
||||||
|
| Reads data from files | `uplot <command> [options] data.tsv ...` |
|
||||||
|
| Outputs data from stdin to stdout | `pipeline1 \| uplot <command> -O \| pipeline2` |
|
||||||
|
|
||||||
Options:
|
### Where to output the plot?
|
||||||
-O, --pass [VAL] file to output standard input data to [stdout]
|
|
||||||
for inserting YouPlot in the middle of Unix pipes
|
By default, the plot is output to *standard error output*.
|
||||||
-o, --output VAL file to output results to [stderr]
|
The output file or stream for the plot can be specified with the `-o` option.
|
||||||
-d, --delimiter VAL use DELIM instead of TAB for field delimiter
|
|
||||||
-H, --headers specify that the input has header row
|
### Where to output the input data?
|
||||||
-T, --transpose transpose the axes of the input data
|
|
||||||
-t, --title VAL print string on the top of plot
|
By default, the input data is not output anywhere.
|
||||||
-x, --xlabel VAL print string on the bottom of the plot
|
The `-O` option, with no arguments, outputs the input data directly to the standard output. This is useful when passing data to a subsequent pipeline.
|
||||||
-y, --ylabel VAL print string on the far left of the plot
|
|
||||||
-w, --width VAL number of characters per row
|
### What types of plots are available?
|
||||||
-h, --height VAL number of rows
|
|
||||||
-b, --border VAL specify the style of the bounding box
|
The following sub-commands are available
|
||||||
-m, --margin VAL number of spaces to the left of the plot
|
|
||||||
-p, --padding VAL space of the left and right of the plot
|
| command | short | how it works |
|
||||||
-c, --color VAL color of the drawing
|
|-----------|-------|----------------------------------------|
|
||||||
--[no-]labels hide the labels
|
| barplot | bar | draw a horizontal barplot |
|
||||||
--fmt VAL xyxy : header is like x1, y1, x2, y2, x3, y3...
|
| histogram | hist | draw a horizontal histogram |
|
||||||
xyy : header is like x, y1, y2, y2, y3...
|
| lineplot | line | draw a line chart |
|
||||||
```
|
| lineplots | lines | draw a line chart with multiple series |
|
||||||
|
| scatter | s | draw a scatter plot |
|
||||||
|
| density | d | draw a density plot |
|
||||||
|
| boxplot | box | draw a horizontal boxplot |
|
||||||
|
|
||||||
|
See Quick Start for `count`.
|
||||||
|
|
||||||
|
| command | short | how it works |
|
||||||
|
|-----------|-------|----------------------------------------------------------|
|
||||||
|
| count | c | draw a baplot based on the number of occurrences (slow) |
|
||||||
|
|
||||||
|
### How to view detailed command line options
|
||||||
|
|
||||||
Use `--help` to print command-specific options.
|
Use `--help` to print command-specific options.
|
||||||
|
|
||||||
@@ -135,13 +170,29 @@ Options:
|
|||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
## Development
|
### How to view the list of available colors?
|
||||||
|
|
||||||
Let's keep it simple.
|
```sh
|
||||||
|
uplot colors
|
||||||
|
```
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
Bug reports and pull requests are welcome on GitHub at [https://github.com/kojix2/youplot](https://github.com/kojix2/youplot).
|
* [Report bugs](https://github.com/kojix2/youplot/issues)
|
||||||
|
* Fix bugs and [submit pull requests](https://github.com/kojix2/youplot/pulls)
|
||||||
|
* Write, clarify, or fix documentation
|
||||||
|
* Suggest or add new features
|
||||||
|
|
||||||
|
|
||||||
|
### Development
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git clone https://github.com/your_name/GR.rb # Clone the Git repo
|
||||||
|
cd GR.rb
|
||||||
|
bundle install # Install the gem dependencies
|
||||||
|
bundle exec rake test # Run the test
|
||||||
|
bundle exec rake install # Installation from source code
|
||||||
|
```
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
@@ -152,17 +152,23 @@ module YouPlot
|
|||||||
end
|
end
|
||||||
|
|
||||||
def colors(color_names = false)
|
def colors(color_names = false)
|
||||||
|
# FIXME
|
||||||
|
s = String.new
|
||||||
UnicodePlot::StyledPrinter::TEXT_COLORS.each do |k, v|
|
UnicodePlot::StyledPrinter::TEXT_COLORS.each do |k, v|
|
||||||
print v
|
s << v
|
||||||
print k
|
s << k.to_s
|
||||||
unless color_names
|
unless color_names
|
||||||
print "\t"
|
s << "\t"
|
||||||
print ' ●'
|
s << ' ●'
|
||||||
end
|
end
|
||||||
print "\033[0m"
|
s << "\033[0m"
|
||||||
print "\t"
|
s << "\t"
|
||||||
end
|
end
|
||||||
puts
|
s << "\n"
|
||||||
|
def s.render(obj)
|
||||||
|
obj.print(self)
|
||||||
|
end
|
||||||
|
s
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_series_size(data, fmt)
|
def check_series_size(data, fmt)
|
||||||
|
@@ -10,89 +10,101 @@ module YouPlot
|
|||||||
Data = Struct.new(:headers, :series)
|
Data = Struct.new(:headers, :series)
|
||||||
|
|
||||||
class Command
|
class Command
|
||||||
attr_accessor :params
|
attr_accessor :command, :params, :options
|
||||||
attr_reader :data, :fmt, :parser
|
attr_reader :data, :parser
|
||||||
|
|
||||||
def initialize(argv = ARGV)
|
def initialize(argv = ARGV)
|
||||||
@argv = argv
|
@argv = argv
|
||||||
@params = Params.new
|
|
||||||
@parser = Parser.new
|
@parser = Parser.new
|
||||||
|
@command = nil
|
||||||
|
@params = nil
|
||||||
|
@options = nil
|
||||||
@backend = YouPlot::Backends::UnicodePlotBackend
|
@backend = YouPlot::Backends::UnicodePlotBackend
|
||||||
end
|
end
|
||||||
|
|
||||||
def run
|
def run
|
||||||
parser.parse_options(@argv)
|
parser.parse_options(@argv)
|
||||||
command = parser.command
|
@command ||= parser.command
|
||||||
params = parser.params
|
@options ||= parser.options
|
||||||
delimiter = parser.delimiter
|
@params ||= parser.params
|
||||||
transpose = parser.transpose
|
|
||||||
headers = parser.headers
|
|
||||||
pass = parser.pass
|
|
||||||
output = parser.output
|
|
||||||
fmt = parser.fmt
|
|
||||||
@encoding = parser.encoding
|
|
||||||
@debug = parser.debug
|
|
||||||
|
|
||||||
if command == :colors
|
|
||||||
@backend.colors(parser.color_names)
|
|
||||||
exit
|
|
||||||
end
|
|
||||||
|
|
||||||
|
if %i[colors color colours colour].include? @command
|
||||||
|
plot = create_plot
|
||||||
|
output_plot(plot)
|
||||||
|
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))
|
while (input = Kernel.gets(nil))
|
||||||
|
main(input)
|
||||||
# Pass the input to subsequent pipelines
|
|
||||||
case pass
|
|
||||||
when IO
|
|
||||||
pass.print(input)
|
|
||||||
else
|
|
||||||
if pass
|
|
||||||
File.open(pass, 'w') do |f|
|
|
||||||
f.print(input)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@data = if @encoding
|
private
|
||||||
input2 = input.dup.force_encoding(@encoding).encode('utf-8')
|
|
||||||
DSVReader.input(input2, delimiter, headers, transpose)
|
def main(input)
|
||||||
else
|
output_data(input)
|
||||||
DSVReader.input(input, delimiter, headers, transpose)
|
|
||||||
|
@data = read_dsv(input)
|
||||||
|
|
||||||
|
pp @data if options[:debug]
|
||||||
|
|
||||||
|
plot = create_plot
|
||||||
|
output_plot(plot)
|
||||||
end
|
end
|
||||||
|
|
||||||
pp @data if @debug
|
def read_dsv(input)
|
||||||
|
input = input.dup.force_encoding(options[:encoding]).encode('utf-8') if options[:encoding]
|
||||||
|
DSVReader.input(input, options[:delimiter], options[:headers], options[:transpose])
|
||||||
|
end
|
||||||
|
|
||||||
plot = case command
|
def create_plot
|
||||||
|
case command
|
||||||
when :bar, :barplot
|
when :bar, :barplot
|
||||||
@backend.barplot(data, params, 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)
|
||||||
when :hist, :histogram
|
when :hist, :histogram
|
||||||
@backend.histogram(data, params)
|
@backend.histogram(data, params)
|
||||||
when :line, :lineplot
|
when :line, :lineplot
|
||||||
@backend.line(data, params, fmt)
|
@backend.line(data, params, options[:fmt])
|
||||||
when :lines, :lineplots
|
when :lines, :lineplots
|
||||||
@backend.lines(data, params, fmt)
|
@backend.lines(data, params, options[:fmt])
|
||||||
when :scatter, :s
|
when :scatter, :s
|
||||||
@backend.scatter(data, params, fmt)
|
@backend.scatter(data, params, options[:fmt])
|
||||||
when :density, :d
|
when :density, :d
|
||||||
@backend.density(data, params, fmt)
|
@backend.density(data, params, options[:fmt])
|
||||||
when :box, :boxplot
|
when :box, :boxplot
|
||||||
@backend.boxplot(data, params)
|
@backend.boxplot(data, params)
|
||||||
|
when :colors, :color, :colours, :colour
|
||||||
|
@backend.colors(options[:color_names])
|
||||||
else
|
else
|
||||||
raise "unrecognized plot_type: #{command}"
|
raise "unrecognized plot_type: #{command}"
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
case output
|
def output_data(input)
|
||||||
|
# Pass the input to subsequent pipelines
|
||||||
|
case options[:pass]
|
||||||
when IO
|
when IO
|
||||||
plot.render(output)
|
options[:pass].print(input)
|
||||||
else
|
else
|
||||||
File.open(output, 'w') do |f|
|
if options[:pass]
|
||||||
|
File.open(options[:pass], 'w') do |f|
|
||||||
|
f.print(input)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def output_plot(plot)
|
||||||
|
case options[:output]
|
||||||
|
when IO
|
||||||
|
plot.render(options[:output])
|
||||||
|
else
|
||||||
|
File.open(options[:output], 'w') do |f|
|
||||||
plot.render(f)
|
plot.render(f)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
18
lib/youplot/command/cmd_options.rb
Normal file
18
lib/youplot/command/cmd_options.rb
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module YouPlot
|
||||||
|
class Command
|
||||||
|
CmdOptions = Struct.new(
|
||||||
|
:delimiter,
|
||||||
|
:transpose,
|
||||||
|
:headers,
|
||||||
|
:pass,
|
||||||
|
:output,
|
||||||
|
:fmt,
|
||||||
|
:encoding,
|
||||||
|
:color_names,
|
||||||
|
:debug,
|
||||||
|
keyword_init: true
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
@@ -1,28 +1,30 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'optparse'
|
require 'optparse'
|
||||||
require_relative 'params'
|
require_relative 'cmd_options'
|
||||||
|
require_relative 'plot_params'
|
||||||
|
|
||||||
module YouPlot
|
module YouPlot
|
||||||
class Command
|
class Command
|
||||||
class Parser
|
class Parser
|
||||||
attr_reader :command, :params,
|
attr_reader :command, :options, :params
|
||||||
:delimiter, :transpose, :headers, :pass, :output, :fmt,
|
|
||||||
:color_names, :encoding, :debug
|
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@command = nil
|
@command = nil
|
||||||
@params = Params.new
|
|
||||||
|
|
||||||
@delimiter = "\t"
|
@options = CmdOptions.new(
|
||||||
@transpose = false
|
delimiter: "\t",
|
||||||
@headers = nil
|
transpose: false,
|
||||||
@pass = false
|
headers: nil,
|
||||||
@output = $stderr
|
pass: false,
|
||||||
@fmt = 'xyy'
|
output: $stderr,
|
||||||
@encoding = nil
|
fmt: 'xyy',
|
||||||
@debug = false
|
encoding: nil,
|
||||||
@color_names = false
|
color_names: false,
|
||||||
|
debug: false
|
||||||
|
)
|
||||||
|
|
||||||
|
@params = PlotParams.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_default_parser
|
def create_default_parser
|
||||||
@@ -33,21 +35,22 @@ module YouPlot
|
|||||||
opt.on_tail('') # Add a blank line at the end
|
opt.on_tail('') # Add a blank line at the end
|
||||||
opt.separator('')
|
opt.separator('')
|
||||||
opt.on('Common options:')
|
opt.on('Common options:')
|
||||||
opt.on('-O', '--pass [VAL]', 'file to output standard input data to [stdout]',
|
opt.on('-O', '--pass [FILE]', 'file to output input data to [stdout]',
|
||||||
'for inserting YouPlot in the middle of Unix pipes') do |v|
|
'for inserting YouPlot in the middle of Unix pipes') do |v|
|
||||||
@pass = v || $stdout
|
@options[:pass] = v || $stdout
|
||||||
end
|
end
|
||||||
opt.on('-o', '--output VAL', 'file to output results to [stderr]') do |v|
|
opt.on('-o', '--output [FILE]', 'file to output plots to [stdout]',
|
||||||
@output = v
|
'If no option is specified, plot will print to stderr') do |v|
|
||||||
|
@options[:output] = v || $stdout
|
||||||
end
|
end
|
||||||
opt.on('-d', '--delimiter VAL', String, 'use DELIM instead of TAB for field delimiter') do |v|
|
opt.on('-d', '--delimiter VAL', String, 'use DELIM instead of TAB for field delimiter') do |v|
|
||||||
@delimiter = v
|
@options[:delimiter] = v
|
||||||
end
|
end
|
||||||
opt.on('-H', '--headers', TrueClass, 'specify that the input has header row') do |v|
|
opt.on('-H', '--headers', TrueClass, 'specify that the input has header row') do |v|
|
||||||
@headers = v
|
@options[:headers] = v
|
||||||
end
|
end
|
||||||
opt.on('-T', '--transpose', TrueClass, 'transpose the axes of the input data') do |v|
|
opt.on('-T', '--transpose', TrueClass, 'transpose the axes of the input data') do |v|
|
||||||
@transpose = v
|
@options[:transpose] = v
|
||||||
end
|
end
|
||||||
opt.on('-t', '--title VAL', String, 'print string on the top of plot') do |v|
|
opt.on('-t', '--title VAL', String, 'print string on the top of plot') do |v|
|
||||||
params.title = v
|
params.title = v
|
||||||
@@ -79,8 +82,11 @@ module YouPlot
|
|||||||
opt.on('--[no-]labels', TrueClass, 'hide the labels') do |v|
|
opt.on('--[no-]labels', TrueClass, 'hide the labels') do |v|
|
||||||
params.labels = v
|
params.labels = v
|
||||||
end
|
end
|
||||||
|
opt.on('--progress', TrueClass, 'progressive') do |v|
|
||||||
|
@options[:progressive] = v
|
||||||
|
end
|
||||||
opt.on('--encoding VAL', String, 'Specify the input encoding') do |v|
|
opt.on('--encoding VAL', String, 'Specify the input encoding') do |v|
|
||||||
@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.
|
||||||
# This is why you need the code below.
|
# This is why you need the code below.
|
||||||
@@ -89,7 +95,7 @@ module YouPlot
|
|||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
opt.on('--debug', TrueClass, 'print preprocessed data') do |v|
|
opt.on('--debug', TrueClass, 'print preprocessed data') do |v|
|
||||||
@debug = v
|
@options[:debug] = v
|
||||||
end
|
end
|
||||||
yield opt if block_given?
|
yield opt if block_given?
|
||||||
end
|
end
|
||||||
@@ -117,7 +123,7 @@ module YouPlot
|
|||||||
scatter s draw a scatter plot
|
scatter s draw a scatter plot
|
||||||
density d draw a density plot
|
density d draw a density plot
|
||||||
boxplot box draw a horizontal boxplot
|
boxplot box draw a horizontal boxplot
|
||||||
colors show the list of available colors
|
colors color show the list of available colors
|
||||||
|
|
||||||
count c draw a baplot based on the number of
|
count c draw a baplot based on the number of
|
||||||
occurrences (slow)
|
occurrences (slow)
|
||||||
@@ -163,7 +169,7 @@ module YouPlot
|
|||||||
params.xscale = v
|
params.xscale = v
|
||||||
end
|
end
|
||||||
parser.on_head('--fmt VAL', String, 'xy : header is like x, y...', 'yx : header is like y, x...') do |v|
|
parser.on_head('--fmt VAL', String, 'xy : header is like x, y...', 'yx : header is like y, x...') do |v|
|
||||||
@fmt = v
|
@options[:fmt] = v
|
||||||
end
|
end
|
||||||
|
|
||||||
when :count, :c
|
when :count, :c
|
||||||
@@ -193,7 +199,7 @@ module YouPlot
|
|||||||
params.ylim = v.take(2)
|
params.ylim = v.take(2)
|
||||||
end
|
end
|
||||||
parser.on_head('--fmt VAL', String, 'xy : header is like x, y...', 'yx : header is like y, x...') do |v|
|
parser.on_head('--fmt VAL', String, 'xy : header is like x, y...', 'yx : header is like y, x...') do |v|
|
||||||
@fmt = v
|
@options[:fmt] = v
|
||||||
end
|
end
|
||||||
|
|
||||||
when :lineplots, :lines
|
when :lineplots, :lines
|
||||||
@@ -206,8 +212,9 @@ module YouPlot
|
|||||||
parser.on_head('--ylim VAL', Array, 'plotting range for the y coordinate') do |v|
|
parser.on_head('--ylim VAL', Array, 'plotting range for the y coordinate') do |v|
|
||||||
params.ylim = v.take(2)
|
params.ylim = v.take(2)
|
||||||
end
|
end
|
||||||
parser.on_head('--fmt VAL', String, 'xyxy : header is like x1, y1, x2, y2, x3, y3...', 'xyy : header is like x, y1, y2, y2, y3...') do |v|
|
parser.on_head('--fmt VAL', String, 'xyxy : header is like x1, y1, x2, y2, x3, y3...',
|
||||||
@fmt = v
|
'xyy : header is like x, y1, y2, y2, y3...') do |v|
|
||||||
|
@options[:fmt] = v
|
||||||
end
|
end
|
||||||
|
|
||||||
when :scatter, :s
|
when :scatter, :s
|
||||||
@@ -220,8 +227,9 @@ module YouPlot
|
|||||||
parser.on_head('--ylim VAL', Array, 'plotting range for the y coordinate') do |v|
|
parser.on_head('--ylim VAL', Array, 'plotting range for the y coordinate') do |v|
|
||||||
params.ylim = v.take(2)
|
params.ylim = v.take(2)
|
||||||
end
|
end
|
||||||
parser.on_head('--fmt VAL', String, 'xyxy : header is like x1, y1, x2, y2, x3, y3...', 'xyy : header is like x, y1, y2, y2, y3...') do |v|
|
parser.on_head('--fmt VAL', String, 'xyxy : header is like x1, y1, x2, y2, x3, y3...',
|
||||||
@fmt = v
|
'xyy : header is like x, y1, y2, y2, y3...') do |v|
|
||||||
|
@options[:fmt] = v
|
||||||
end
|
end
|
||||||
|
|
||||||
when :density, :d
|
when :density, :d
|
||||||
@@ -234,8 +242,9 @@ module YouPlot
|
|||||||
parser.on_head('--ylim VAL', Array, 'plotting range for the y coordinate') do |v|
|
parser.on_head('--ylim VAL', Array, 'plotting range for the y coordinate') do |v|
|
||||||
params.ylim = v.take(2)
|
params.ylim = v.take(2)
|
||||||
end
|
end
|
||||||
parser.on('--fmt VAL', String, 'xyxy : header is like x1, y1, x2, y2, x3, y3...', 'xyy : header is like x, y1, y2, y2, y3...') do |v|
|
parser.on('--fmt VAL', String, 'xyxy : header is like x1, y1, x2, y2, x3, y3...',
|
||||||
@fmt = v
|
'xyy : header is like x, y1, y2, y2, y3...') do |v|
|
||||||
|
@options[:fmt] = v
|
||||||
end
|
end
|
||||||
|
|
||||||
when :boxplot, :box
|
when :boxplot, :box
|
||||||
@@ -243,9 +252,9 @@ module YouPlot
|
|||||||
params.xlim = v.take(2)
|
params.xlim = v.take(2)
|
||||||
end
|
end
|
||||||
|
|
||||||
when :colors
|
when :colors, :color, :colours, :colour
|
||||||
parser.on_head('-n', '--names', 'show color names only', TrueClass) do |v|
|
parser.on_head('-n', '--names', 'show color names only', TrueClass) do |v|
|
||||||
@color_names = v
|
@options[:color_names] = v
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
|
@@ -7,7 +7,7 @@ module YouPlot
|
|||||||
# * Here, I use Struct for 2 safety reason.
|
# * Here, I use Struct for 2 safety reason.
|
||||||
# * The keys are static in Struct.
|
# * The keys are static in Struct.
|
||||||
# * Struct does not conflict with keyword arguments. Hash dose.
|
# * Struct does not conflict with keyword arguments. Hash dose.
|
||||||
Params = Struct.new(
|
PlotParams = Struct.new(
|
||||||
# Sort me!
|
# Sort me!
|
||||||
:title,
|
:title,
|
||||||
:width,
|
:width,
|
@@ -1,5 +1,5 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module YouPlot
|
module YouPlot
|
||||||
VERSION = '0.3.1'
|
VERSION = '0.3.2'
|
||||||
end
|
end
|
||||||
|
151
test/fixtures/IRIStsv.tsv
vendored
Normal file
151
test/fixtures/IRIStsv.tsv
vendored
Normal file
@@ -0,0 +1,151 @@
|
|||||||
|
sepal_length sepal_width petal_length petal_width species
|
||||||
|
5.1 3.5 1.4 0.2 Iris-setosa
|
||||||
|
4.9 3 1.4 0.2 Iris-setosa
|
||||||
|
4.7 3.2 1.3 0.2 Iris-setosa
|
||||||
|
4.6 3.1 1.5 0.2 Iris-setosa
|
||||||
|
5 3.6 1.4 0.2 Iris-setosa
|
||||||
|
5.4 3.9 1.7 0.4 Iris-setosa
|
||||||
|
4.6 3.4 1.4 0.3 Iris-setosa
|
||||||
|
5 3.4 1.5 0.2 Iris-setosa
|
||||||
|
4.4 2.9 1.4 0.2 Iris-setosa
|
||||||
|
4.9 3.1 1.5 0.1 Iris-setosa
|
||||||
|
5.4 3.7 1.5 0.2 Iris-setosa
|
||||||
|
4.8 3.4 1.6 0.2 Iris-setosa
|
||||||
|
4.8 3 1.4 0.1 Iris-setosa
|
||||||
|
4.3 3 1.1 0.1 Iris-setosa
|
||||||
|
5.8 4 1.2 0.2 Iris-setosa
|
||||||
|
5.7 4.4 1.5 0.4 Iris-setosa
|
||||||
|
5.4 3.9 1.3 0.4 Iris-setosa
|
||||||
|
5.1 3.5 1.4 0.3 Iris-setosa
|
||||||
|
5.7 3.8 1.7 0.3 Iris-setosa
|
||||||
|
5.1 3.8 1.5 0.3 Iris-setosa
|
||||||
|
5.4 3.4 1.7 0.2 Iris-setosa
|
||||||
|
5.1 3.7 1.5 0.4 Iris-setosa
|
||||||
|
4.6 3.6 1 0.2 Iris-setosa
|
||||||
|
5.1 3.3 1.7 0.5 Iris-setosa
|
||||||
|
4.8 3.4 1.9 0.2 Iris-setosa
|
||||||
|
5 3 1.6 0.2 Iris-setosa
|
||||||
|
5 3.4 1.6 0.4 Iris-setosa
|
||||||
|
5.2 3.5 1.5 0.2 Iris-setosa
|
||||||
|
5.2 3.4 1.4 0.2 Iris-setosa
|
||||||
|
4.7 3.2 1.6 0.2 Iris-setosa
|
||||||
|
4.8 3.1 1.6 0.2 Iris-setosa
|
||||||
|
5.4 3.4 1.5 0.4 Iris-setosa
|
||||||
|
5.2 4.1 1.5 0.1 Iris-setosa
|
||||||
|
5.5 4.2 1.4 0.2 Iris-setosa
|
||||||
|
4.9 3.1 1.5 0.1 Iris-setosa
|
||||||
|
5 3.2 1.2 0.2 Iris-setosa
|
||||||
|
5.5 3.5 1.3 0.2 Iris-setosa
|
||||||
|
4.9 3.1 1.5 0.1 Iris-setosa
|
||||||
|
4.4 3 1.3 0.2 Iris-setosa
|
||||||
|
5.1 3.4 1.5 0.2 Iris-setosa
|
||||||
|
5 3.5 1.3 0.3 Iris-setosa
|
||||||
|
4.5 2.3 1.3 0.3 Iris-setosa
|
||||||
|
4.4 3.2 1.3 0.2 Iris-setosa
|
||||||
|
5 3.5 1.6 0.6 Iris-setosa
|
||||||
|
5.1 3.8 1.9 0.4 Iris-setosa
|
||||||
|
4.8 3 1.4 0.3 Iris-setosa
|
||||||
|
5.1 3.8 1.6 0.2 Iris-setosa
|
||||||
|
4.6 3.2 1.4 0.2 Iris-setosa
|
||||||
|
5.3 3.7 1.5 0.2 Iris-setosa
|
||||||
|
5 3.3 1.4 0.2 Iris-setosa
|
||||||
|
7 3.2 4.7 1.4 Iris-versicolor
|
||||||
|
6.4 3.2 4.5 1.5 Iris-versicolor
|
||||||
|
6.9 3.1 4.9 1.5 Iris-versicolor
|
||||||
|
5.5 2.3 4 1.3 Iris-versicolor
|
||||||
|
6.5 2.8 4.6 1.5 Iris-versicolor
|
||||||
|
5.7 2.8 4.5 1.3 Iris-versicolor
|
||||||
|
6.3 3.3 4.7 1.6 Iris-versicolor
|
||||||
|
4.9 2.4 3.3 1 Iris-versicolor
|
||||||
|
6.6 2.9 4.6 1.3 Iris-versicolor
|
||||||
|
5.2 2.7 3.9 1.4 Iris-versicolor
|
||||||
|
5 2 3.5 1 Iris-versicolor
|
||||||
|
5.9 3 4.2 1.5 Iris-versicolor
|
||||||
|
6 2.2 4 1 Iris-versicolor
|
||||||
|
6.1 2.9 4.7 1.4 Iris-versicolor
|
||||||
|
5.6 2.9 3.6 1.3 Iris-versicolor
|
||||||
|
6.7 3.1 4.4 1.4 Iris-versicolor
|
||||||
|
5.6 3 4.5 1.5 Iris-versicolor
|
||||||
|
5.8 2.7 4.1 1 Iris-versicolor
|
||||||
|
6.2 2.2 4.5 1.5 Iris-versicolor
|
||||||
|
5.6 2.5 3.9 1.1 Iris-versicolor
|
||||||
|
5.9 3.2 4.8 1.8 Iris-versicolor
|
||||||
|
6.1 2.8 4 1.3 Iris-versicolor
|
||||||
|
6.3 2.5 4.9 1.5 Iris-versicolor
|
||||||
|
6.1 2.8 4.7 1.2 Iris-versicolor
|
||||||
|
6.4 2.9 4.3 1.3 Iris-versicolor
|
||||||
|
6.6 3 4.4 1.4 Iris-versicolor
|
||||||
|
6.8 2.8 4.8 1.4 Iris-versicolor
|
||||||
|
6.7 3 5 1.7 Iris-versicolor
|
||||||
|
6 2.9 4.5 1.5 Iris-versicolor
|
||||||
|
5.7 2.6 3.5 1 Iris-versicolor
|
||||||
|
5.5 2.4 3.8 1.1 Iris-versicolor
|
||||||
|
5.5 2.4 3.7 1 Iris-versicolor
|
||||||
|
5.8 2.7 3.9 1.2 Iris-versicolor
|
||||||
|
6 2.7 5.1 1.6 Iris-versicolor
|
||||||
|
5.4 3 4.5 1.5 Iris-versicolor
|
||||||
|
6 3.4 4.5 1.6 Iris-versicolor
|
||||||
|
6.7 3.1 4.7 1.5 Iris-versicolor
|
||||||
|
6.3 2.3 4.4 1.3 Iris-versicolor
|
||||||
|
5.6 3 4.1 1.3 Iris-versicolor
|
||||||
|
5.5 2.5 4 1.3 Iris-versicolor
|
||||||
|
5.5 2.6 4.4 1.2 Iris-versicolor
|
||||||
|
6.1 3 4.6 1.4 Iris-versicolor
|
||||||
|
5.8 2.6 4 1.2 Iris-versicolor
|
||||||
|
5 2.3 3.3 1 Iris-versicolor
|
||||||
|
5.6 2.7 4.2 1.3 Iris-versicolor
|
||||||
|
5.7 3 4.2 1.2 Iris-versicolor
|
||||||
|
5.7 2.9 4.2 1.3 Iris-versicolor
|
||||||
|
6.2 2.9 4.3 1.3 Iris-versicolor
|
||||||
|
5.1 2.5 3 1.1 Iris-versicolor
|
||||||
|
5.7 2.8 4.1 1.3 Iris-versicolor
|
||||||
|
6.3 3.3 6 2.5 Iris-virginica
|
||||||
|
5.8 2.7 5.1 1.9 Iris-virginica
|
||||||
|
7.1 3 5.9 2.1 Iris-virginica
|
||||||
|
6.3 2.9 5.6 1.8 Iris-virginica
|
||||||
|
6.5 3 5.8 2.2 Iris-virginica
|
||||||
|
7.6 3 6.6 2.1 Iris-virginica
|
||||||
|
4.9 2.5 4.5 1.7 Iris-virginica
|
||||||
|
7.3 2.9 6.3 1.8 Iris-virginica
|
||||||
|
6.7 2.5 5.8 1.8 Iris-virginica
|
||||||
|
7.2 3.6 6.1 2.5 Iris-virginica
|
||||||
|
6.5 3.2 5.1 2 Iris-virginica
|
||||||
|
6.4 2.7 5.3 1.9 Iris-virginica
|
||||||
|
6.8 3 5.5 2.1 Iris-virginica
|
||||||
|
5.7 2.5 5 2 Iris-virginica
|
||||||
|
5.8 2.8 5.1 2.4 Iris-virginica
|
||||||
|
6.4 3.2 5.3 2.3 Iris-virginica
|
||||||
|
6.5 3 5.5 1.8 Iris-virginica
|
||||||
|
7.7 3.8 6.7 2.2 Iris-virginica
|
||||||
|
7.7 2.6 6.9 2.3 Iris-virginica
|
||||||
|
6 2.2 5 1.5 Iris-virginica
|
||||||
|
6.9 3.2 5.7 2.3 Iris-virginica
|
||||||
|
5.6 2.8 4.9 2 Iris-virginica
|
||||||
|
7.7 2.8 6.7 2 Iris-virginica
|
||||||
|
6.3 2.7 4.9 1.8 Iris-virginica
|
||||||
|
6.7 3.3 5.7 2.1 Iris-virginica
|
||||||
|
7.2 3.2 6 1.8 Iris-virginica
|
||||||
|
6.2 2.8 4.8 1.8 Iris-virginica
|
||||||
|
6.1 3 4.9 1.8 Iris-virginica
|
||||||
|
6.4 2.8 5.6 2.1 Iris-virginica
|
||||||
|
7.2 3 5.8 1.6 Iris-virginica
|
||||||
|
7.4 2.8 6.1 1.9 Iris-virginica
|
||||||
|
7.9 3.8 6.4 2 Iris-virginica
|
||||||
|
6.4 2.8 5.6 2.2 Iris-virginica
|
||||||
|
6.3 2.8 5.1 1.5 Iris-virginica
|
||||||
|
6.1 2.6 5.6 1.4 Iris-virginica
|
||||||
|
7.7 3 6.1 2.3 Iris-virginica
|
||||||
|
6.3 3.4 5.6 2.4 Iris-virginica
|
||||||
|
6.4 3.1 5.5 1.8 Iris-virginica
|
||||||
|
6 3 4.8 1.8 Iris-virginica
|
||||||
|
6.9 3.1 5.4 2.1 Iris-virginica
|
||||||
|
6.7 3.1 5.6 2.4 Iris-virginica
|
||||||
|
6.9 3.1 5.1 2.3 Iris-virginica
|
||||||
|
5.8 2.7 5.1 1.9 Iris-virginica
|
||||||
|
6.8 3.2 5.9 2.3 Iris-virginica
|
||||||
|
6.7 3.3 5.7 2.5 Iris-virginica
|
||||||
|
6.7 3 5.2 2.3 Iris-virginica
|
||||||
|
6.3 2.5 5 1.9 Iris-virginica
|
||||||
|
6.5 3 5.2 2 Iris-virginica
|
||||||
|
6.2 3.4 5.4 2.3 Iris-virginica
|
||||||
|
5.9 3 5.1 1.8 Iris-virginica
|
|
@@ -7,23 +7,27 @@ class YouPlotCommandTest < Test::Unit::TestCase
|
|||||||
class << self
|
class << self
|
||||||
def startup
|
def startup
|
||||||
@stdin = $stdin.dup
|
@stdin = $stdin.dup
|
||||||
|
@stdout = $stdout.dup
|
||||||
@stderr = $stderr.dup
|
@stderr = $stderr.dup
|
||||||
end
|
end
|
||||||
|
|
||||||
def shutdown
|
def shutdown
|
||||||
$stdin = @stdin
|
$stdin = @stdin
|
||||||
|
$stdout = @stdout
|
||||||
$stderr = @stderr
|
$stderr = @stderr
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
$stdin = File.open(File.expand_path('../fixtures/iris.csv', __dir__), 'r')
|
$stdin = File.open(File.expand_path('../fixtures/iris.csv', __dir__), 'r')
|
||||||
@tmp_file = Tempfile.new
|
@stderr_file = Tempfile.new
|
||||||
$stderr = @tmp_file
|
@stdout_file = Tempfile.new
|
||||||
|
$stderr = @stderr_file
|
||||||
|
$stdout = @stdout_file
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
@tmp_file.close
|
@stderr_file.close
|
||||||
end
|
end
|
||||||
|
|
||||||
def fixture(fname)
|
def fixture(fname)
|
||||||
@@ -32,71 +36,96 @@ class YouPlotCommandTest < Test::Unit::TestCase
|
|||||||
|
|
||||||
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'), @tmp_file.read
|
assert_equal fixture('iris-barplot.txt'), @stderr_file.read
|
||||||
end
|
end
|
||||||
|
|
||||||
test :barplot do
|
test :barplot do
|
||||||
YouPlot::Command.new(['barplot', '-H', '-d,', '-t', 'IRIS-BARPLOT']).run
|
YouPlot::Command.new(['barplot', '-H', '-d,', '-t', 'IRIS-BARPLOT']).run
|
||||||
assert_equal fixture('iris-barplot.txt'), @tmp_file.read
|
assert_equal fixture('iris-barplot.txt'), @stderr_file.read
|
||||||
end
|
end
|
||||||
|
|
||||||
test :hist do
|
test :hist do
|
||||||
YouPlot::Command.new(['hist', '-H', '-d,', '-t', 'IRIS-HISTOGRAM']).run
|
YouPlot::Command.new(['hist', '-H', '-d,', '-t', 'IRIS-HISTOGRAM']).run
|
||||||
assert_equal fixture('iris-histogram.txt'), @tmp_file.read
|
assert_equal fixture('iris-histogram.txt'), @stderr_file.read
|
||||||
end
|
end
|
||||||
|
|
||||||
test :histogram do
|
test :histogram do
|
||||||
YouPlot::Command.new(['histogram', '-H', '-d,', '-t', 'IRIS-HISTOGRAM']).run
|
YouPlot::Command.new(['histogram', '-H', '-d,', '-t', 'IRIS-HISTOGRAM']).run
|
||||||
assert_equal fixture('iris-histogram.txt'), @tmp_file.read
|
assert_equal fixture('iris-histogram.txt'), @stderr_file.read
|
||||||
end
|
end
|
||||||
|
|
||||||
test :line do
|
test :line do
|
||||||
YouPlot::Command.new(['line', '-H', '-d,', '-t', 'IRIS-LINEPLOT']).run
|
YouPlot::Command.new(['line', '-H', '-d,', '-t', 'IRIS-LINEPLOT']).run
|
||||||
assert_equal fixture('iris-lineplot.txt'), @tmp_file.read
|
assert_equal fixture('iris-lineplot.txt'), @stderr_file.read
|
||||||
end
|
end
|
||||||
|
|
||||||
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'), @tmp_file.read
|
assert_equal fixture('iris-lineplot.txt'), @stderr_file.read
|
||||||
end
|
end
|
||||||
|
|
||||||
test :lines do
|
test :lines do
|
||||||
YouPlot::Command.new(['lines', '-H', '-d,', '-t', 'IRIS-LINEPLOTS']).run
|
YouPlot::Command.new(['lines', '-H', '-d,', '-t', 'IRIS-LINEPLOTS']).run
|
||||||
assert_equal fixture('iris-lineplots.txt'), @tmp_file.read
|
assert_equal fixture('iris-lineplots.txt'), @stderr_file.read
|
||||||
end
|
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'), @tmp_file.read
|
assert_equal fixture('iris-lineplots.txt'), @stderr_file.read
|
||||||
end
|
end
|
||||||
|
|
||||||
test :s do
|
test :s do
|
||||||
YouPlot::Command.new(['s', '-H', '-d,', '-t', 'IRIS-SCATTER']).run
|
YouPlot::Command.new(['s', '-H', '-d,', '-t', 'IRIS-SCATTER']).run
|
||||||
assert_equal fixture('iris-scatter.txt'), @tmp_file.read
|
assert_equal fixture('iris-scatter.txt'), @stderr_file.read
|
||||||
end
|
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'), @tmp_file.read
|
assert_equal fixture('iris-scatter.txt'), @stderr_file.read
|
||||||
end
|
end
|
||||||
|
|
||||||
test :d do
|
test :d do
|
||||||
YouPlot::Command.new(['d', '-H', '-d,', '-t', 'IRIS-DENSITY']).run
|
YouPlot::Command.new(['d', '-H', '-d,', '-t', 'IRIS-DENSITY']).run
|
||||||
assert_equal fixture('iris-density.txt'), @tmp_file.read
|
assert_equal fixture('iris-density.txt'), @stderr_file.read
|
||||||
end
|
end
|
||||||
|
|
||||||
test :density do
|
test :density do
|
||||||
YouPlot::Command.new(['density', '-H', '-d,', '-t', 'IRIS-DENSITY']).run
|
YouPlot::Command.new(['density', '-H', '-d,', '-t', 'IRIS-DENSITY']).run
|
||||||
assert_equal fixture('iris-density.txt'), @tmp_file.read
|
assert_equal fixture('iris-density.txt'), @stderr_file.read
|
||||||
end
|
end
|
||||||
|
|
||||||
test :box do
|
test :box do
|
||||||
YouPlot::Command.new(['box', '-H', '-d,', '-t', 'IRIS-BOXPLOT']).run
|
YouPlot::Command.new(['box', '-H', '-d,', '-t', 'IRIS-BOXPLOT']).run
|
||||||
assert_equal fixture('iris-boxplot.txt'), @tmp_file.read
|
assert_equal fixture('iris-boxplot.txt'), @stderr_file.read
|
||||||
end
|
end
|
||||||
|
|
||||||
test :boxplot do
|
test :boxplot do
|
||||||
YouPlot::Command.new(['boxplot', '-H', '-d,', '-t', 'IRIS-BOXPLOT']).run
|
YouPlot::Command.new(['boxplot', '-H', '-d,', '-t', 'IRIS-BOXPLOT']).run
|
||||||
assert_equal fixture('iris-boxplot.txt'), @tmp_file.read
|
assert_equal fixture('iris-boxplot.txt'), @stderr_file.read
|
||||||
|
end
|
||||||
|
|
||||||
|
test :plot_output_stdout do
|
||||||
|
YouPlot::Command.new(['bar', '-o', '-H', '-d,', '-t', 'IRIS-BARPLOT']).run
|
||||||
|
assert_equal '', @stderr_file.read
|
||||||
|
end
|
||||||
|
|
||||||
|
test :data_output_stdout do
|
||||||
|
YouPlot::Command.new(['bar', '-O', '-H', '-d,', '-t', 'IRIS-BARPLOT']).run
|
||||||
|
assert_equal fixture('iris-barplot.txt'), @stderr_file.read
|
||||||
|
assert_equal File.read(File.expand_path('../fixtures/iris.csv', __dir__)), @stdout_file.read
|
||||||
|
end
|
||||||
|
|
||||||
|
%i[colors color colours colour].each do |cmd_name|
|
||||||
|
test cmd_name do
|
||||||
|
YouPlot::Command.new([cmd_name.to_s]).run
|
||||||
|
assert_equal fixture('colors.txt'), @stderr_file.read
|
||||||
|
assert_equal '', @stdout_file.read
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test :colors_output_stdout do
|
||||||
|
YouPlot::Command.new(['colors', '-o']).run
|
||||||
|
assert_equal '', @stderr_file.read
|
||||||
|
assert_equal fixture('colors.txt'), @stdout_file.read
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user