youplot 0.3.3 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +7 -1
- data/exe/uplot +1 -1
- data/exe/youplot +1 -1
- data/lib/youplot.rb +8 -0
- data/lib/youplot/backends/processing.rb +2 -2
- data/lib/youplot/backends/unicode_plot_backend.rb +24 -8
- data/lib/youplot/command.rb +11 -3
- data/lib/youplot/command/parser.rb +201 -190
- data/lib/youplot/dsv.rb +5 -7
- data/lib/youplot/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39029ea73cd1233a1ad890343381986b5fcf46e1e7619708cd0329269d07135c
|
4
|
+
data.tar.gz: '08662eaab8c28351e57727c69f2f5479e1950d3cbbad7d65ab61ec8994830fec'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f24fc609bf6501d9b9f6a6452db84d015cfbea7fe6c3a86f4d69ab31043c5a99d9907fe8dbf34f2672589fbfa99e51cde6cfab578c1ef570552e649a7ebfb10
|
7
|
+
data.tar.gz: 6fb46f5492480a385dec175d022e693442c43cdead3b5bd948dfdc0030a81d661ea5363cb386c9c9f7da5e25329cdc11c286d78985cc9383f7032a3a56a8435a
|
data/README.md
CHANGED
@@ -201,7 +201,7 @@ Usage: uplot histogram [options] <in.tsv>
|
|
201
201
|
|
202
202
|
Options for histogram:
|
203
203
|
--symbol VAL character to be used to plot the bars
|
204
|
-
--closed VAL
|
204
|
+
--closed VAL side of the intervals to be closed [left]
|
205
205
|
-n, --nbins VAL approximate number of bins
|
206
206
|
|
207
207
|
Options:
|
@@ -233,6 +233,12 @@ bundle exec rake test # Run the test
|
|
233
233
|
bundle exec rake install # Installation from source code
|
234
234
|
```
|
235
235
|
|
236
|
+
### Acknowledgements
|
237
|
+
|
238
|
+
* [Red Data Tools](https://github.com/red-data-tools) - Technical support
|
239
|
+
* [sampo grafiikka](https://jypg.net/sampo_grafiikka) - Project logo creation
|
240
|
+
* [yutaas](https://github.com/yutaas) - English proofreading
|
241
|
+
|
236
242
|
## License
|
237
243
|
|
238
244
|
[MIT License](https://opensource.org/licenses/MIT).
|
data/exe/uplot
CHANGED
data/exe/youplot
CHANGED
data/lib/youplot.rb
CHANGED
@@ -6,9 +6,9 @@ module YouPlot
|
|
6
6
|
module Processing
|
7
7
|
module_function
|
8
8
|
|
9
|
-
def count_values(arr)
|
9
|
+
def count_values(arr, tally: true)
|
10
10
|
# tally was added in Ruby 2.7
|
11
|
-
if Enumerable.method_defined?
|
11
|
+
if tally && Enumerable.method_defined?(:tally)
|
12
12
|
arr.tally
|
13
13
|
else
|
14
14
|
# https://github.com/marcandre/backports
|
@@ -7,6 +7,8 @@ module YouPlot
|
|
7
7
|
# plotting functions.
|
8
8
|
module Backends
|
9
9
|
module UnicodePlotBackend
|
10
|
+
class Error < StandardError; end
|
11
|
+
|
10
12
|
module_function
|
11
13
|
|
12
14
|
def barplot(data, params, fmt = nil, count: false)
|
@@ -37,7 +39,19 @@ module YouPlot
|
|
37
39
|
labels = series[x_col]
|
38
40
|
values = series[y_col].map(&:to_f)
|
39
41
|
end
|
40
|
-
|
42
|
+
begin
|
43
|
+
UnicodePlot.barplot(labels, values, **params.to_hc)
|
44
|
+
# UnicodePlot error:
|
45
|
+
# All values have to be positive. Negative bars are not supported.
|
46
|
+
rescue ArgumentError => e
|
47
|
+
if YouPlot.run_as_executable?
|
48
|
+
warn e.backtrace[0]
|
49
|
+
warn "\e[35m#{e}\e[0m"
|
50
|
+
exit 1
|
51
|
+
else
|
52
|
+
raise e
|
53
|
+
end
|
54
|
+
end
|
41
55
|
end
|
42
56
|
|
43
57
|
def histogram(data, params)
|
@@ -90,6 +104,7 @@ module YouPlot
|
|
90
104
|
params.name ||= headers[1]
|
91
105
|
params.xlabel ||= headers[0]
|
92
106
|
end
|
107
|
+
params.xlim ||= series[0].flatten.minmax # why need?
|
93
108
|
params.ylim ||= series[1..-1].flatten.minmax # why need?
|
94
109
|
plot = UnicodePlot.public_send(method1, series[0], series[1], **params.to_hc)
|
95
110
|
2.upto(series.size - 1) do |i|
|
@@ -103,13 +118,14 @@ module YouPlot
|
|
103
118
|
series = data.series
|
104
119
|
method2 = get_method2(method1)
|
105
120
|
series.map! { |s| s.map(&:to_f) }
|
106
|
-
|
121
|
+
series2 = series.each_slice(2).to_a
|
122
|
+
series = nil
|
107
123
|
params.name ||= headers[0] if headers
|
108
|
-
params.xlim
|
109
|
-
params.ylim
|
110
|
-
x1, y1 =
|
124
|
+
params.xlim ||= series2.map(&:first).flatten.minmax # why need?
|
125
|
+
params.ylim ||= series2.map(&:last).flatten.minmax # why need?
|
126
|
+
x1, y1 = series2.shift
|
111
127
|
plot = UnicodePlot.public_send(method1, x1, y1, **params.to_hc)
|
112
|
-
|
128
|
+
series2.each_with_index do |(xi, yi), i|
|
113
129
|
UnicodePlot.public_send(method2, plot, xi, yi, name: headers&.[]((i + 1) * 2))
|
114
130
|
end
|
115
131
|
plot
|
@@ -179,14 +195,14 @@ module YouPlot
|
|
179
195
|
warn " Headers: \e[35m#{data.headers.inspect}\e[0m"
|
180
196
|
warn " The first item is: \e[35m\"#{series[0][0]}\"\e[0m"
|
181
197
|
warn " The last item is : \e[35m\"#{series[0][-1]}\"\e[0m"
|
182
|
-
exit
|
198
|
+
YouPlot.run_as_executable ? exit(1) : raise(Error)
|
183
199
|
end
|
184
200
|
if fmt == 'xyxy' && series.size.odd?
|
185
201
|
warn 'YouPlot: In the xyxy format, the number of series must be even.'
|
186
202
|
warn ''
|
187
203
|
warn " Number of series: \e[35m#{series.size}\e[0m"
|
188
204
|
warn " Headers: \e[35m#{data.headers.inspect}\e[0m"
|
189
|
-
exit
|
205
|
+
YouPlot.run_as_executable ? exit(1) : raise(Error)
|
190
206
|
end
|
191
207
|
end
|
192
208
|
end
|
data/lib/youplot/command.rb
CHANGED
@@ -22,6 +22,11 @@ module YouPlot
|
|
22
22
|
@backend = YouPlot::Backends::UnicodePlotBackend
|
23
23
|
end
|
24
24
|
|
25
|
+
def run_as_executable
|
26
|
+
YouPlot.run_as_executable = true
|
27
|
+
run
|
28
|
+
end
|
29
|
+
|
25
30
|
def run
|
26
31
|
parser.parse_options(@argv)
|
27
32
|
@command ||= parser.command
|
@@ -34,11 +39,15 @@ module YouPlot
|
|
34
39
|
elsif options[:progressive]
|
35
40
|
stop = false
|
36
41
|
Signal.trap(:INT) { stop = true }
|
42
|
+
options[:output].print "\e[?25l" # make cursor invisible
|
37
43
|
while (input = Kernel.gets)
|
38
|
-
main_progressive(input)
|
44
|
+
n = main_progressive(input)
|
39
45
|
break if stop
|
46
|
+
|
47
|
+
options[:output].print "\e[#{n}F"
|
40
48
|
end
|
41
49
|
options[:output].print "\e[0J"
|
50
|
+
options[:output].print "\e[?25h" # make cursor visible
|
42
51
|
else
|
43
52
|
# Sometimes the input file does not end with a newline code.
|
44
53
|
while (input = Kernel.gets(nil))
|
@@ -154,8 +163,7 @@ module YouPlot
|
|
154
163
|
end
|
155
164
|
options[:output].print "\e[0J"
|
156
165
|
options[:output].flush
|
157
|
-
|
158
|
-
options[:output].print "\e[#{n}F"
|
166
|
+
out.string.lines.size
|
159
167
|
else
|
160
168
|
raise 'In progressive mode, output to a file is not possible.'
|
161
169
|
end
|
@@ -7,7 +7,10 @@ require_relative 'plot_params'
|
|
7
7
|
module YouPlot
|
8
8
|
class Command
|
9
9
|
class Parser
|
10
|
-
|
10
|
+
class Error < StandardError; end
|
11
|
+
|
12
|
+
attr_reader :command, :options, :params,
|
13
|
+
:main_parser, :sub_parser
|
11
14
|
|
12
15
|
def initialize
|
13
16
|
@command = nil
|
@@ -28,257 +31,265 @@ module YouPlot
|
|
28
31
|
end
|
29
32
|
|
30
33
|
def create_default_parser
|
31
|
-
OptionParser.new do |
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
34
|
+
OptionParser.new do |parser|
|
35
|
+
parser.program_name = 'YouPlot'
|
36
|
+
parser.version = YouPlot::VERSION
|
37
|
+
parser.summary_width = 24
|
38
|
+
parser.on_tail('') # Add a blank line at the end
|
39
|
+
parser.separator('')
|
40
|
+
parser.on('Common options:')
|
41
|
+
parser.on('-O', '--pass [FILE]', 'file to output input data to [stdout]',
|
42
|
+
'for inserting YouPlot in the middle of Unix pipes') do |v|
|
43
|
+
options[:pass] = v || $stdout
|
41
44
|
end
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
+
parser.on('-o', '--output [FILE]', 'file to output plots to [stdout]',
|
46
|
+
'If no option is specified, plot will print to stderr') do |v|
|
47
|
+
options[:output] = v || $stdout
|
45
48
|
end
|
46
|
-
|
47
|
-
|
49
|
+
parser.on('-d', '--delimiter DELIM', String, 'use DELIM instead of [TAB] for field delimiter') do |v|
|
50
|
+
options[:delimiter] = v
|
48
51
|
end
|
49
|
-
|
50
|
-
|
52
|
+
parser.on('-H', '--headers', TrueClass, 'specify that the input has header row') do |v|
|
53
|
+
options[:headers] = v
|
51
54
|
end
|
52
|
-
|
53
|
-
|
55
|
+
parser.on('-T', '--transpose', TrueClass, 'transpose the axes of the input data') do |v|
|
56
|
+
options[:transpose] = v
|
54
57
|
end
|
55
|
-
|
58
|
+
parser.on('-t', '--title STR', String, 'print string on the top of plot') do |v|
|
56
59
|
params.title = v
|
57
60
|
end
|
58
|
-
|
61
|
+
parser.on('-x', '--xlabel STR', String, 'print string on the bottom of the plot') do |v|
|
59
62
|
params.xlabel = v
|
60
63
|
end
|
61
|
-
|
64
|
+
parser.on('-y', '--ylabel STR', String, 'print string on the far left of the plot') do |v|
|
62
65
|
params.ylabel = v
|
63
66
|
end
|
64
|
-
|
67
|
+
parser.on('-w', '--width INT', Integer, 'number of characters per row') do |v|
|
65
68
|
params.width = v
|
66
69
|
end
|
67
|
-
|
70
|
+
parser.on('-h', '--height INT', Numeric, 'number of rows') do |v|
|
68
71
|
params.height = v
|
69
72
|
end
|
70
|
-
|
73
|
+
parser.on('-b', '--border STR', String, 'specify the style of the bounding box') do |v|
|
71
74
|
params.border = v.to_sym
|
72
75
|
end
|
73
|
-
|
76
|
+
parser.on('-m', '--margin INT', Numeric, 'number of spaces to the left of the plot') do |v|
|
74
77
|
params.margin = v
|
75
78
|
end
|
76
|
-
|
79
|
+
parser.on('--padding INT', Numeric, 'space of the left and right of the plot') do |v|
|
77
80
|
params.padding = v
|
78
81
|
end
|
79
|
-
|
82
|
+
parser.on('-c', '--color VAL', String, 'color of the drawing') do |v|
|
80
83
|
params.color = v =~ /\A[0-9]+\z/ ? v.to_i : v.to_sym
|
81
84
|
end
|
82
|
-
|
85
|
+
parser.on('--[no-]labels', TrueClass, 'hide the labels') do |v|
|
83
86
|
params.labels = v
|
84
87
|
end
|
85
|
-
|
86
|
-
|
88
|
+
parser.on('-p', '--progress', TrueClass, 'progressive mode [experimental]') do |v|
|
89
|
+
options[:progressive] = v
|
87
90
|
end
|
88
|
-
|
89
|
-
|
91
|
+
parser.on('--encoding STR', String, 'Specify the input encoding') do |v|
|
92
|
+
options[:encoding] = v
|
90
93
|
end
|
91
94
|
# Optparse adds the help option, but it doesn't show up in usage.
|
92
95
|
# This is why you need the code below.
|
93
|
-
|
94
|
-
puts
|
95
|
-
exit
|
96
|
+
parser.on('--help', 'print sub-command help menu') do
|
97
|
+
puts parser.help
|
98
|
+
exit if YouPlot.run_as_executable?
|
96
99
|
end
|
97
|
-
|
98
|
-
|
100
|
+
parser.on('--debug', TrueClass, 'print preprocessed data') do |v|
|
101
|
+
options[:debug] = v
|
99
102
|
end
|
100
|
-
yield opt if block_given?
|
103
|
+
# yield opt if block_given?
|
101
104
|
end
|
102
105
|
end
|
103
106
|
|
104
|
-
def
|
105
|
-
@main_parser
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
107
|
+
def create_main_parser
|
108
|
+
@main_parser = create_default_parser
|
109
|
+
main_parser.banner = \
|
110
|
+
<<~MSG
|
111
|
+
|
112
|
+
Program: YouPlot (Tools for plotting on the terminal)
|
113
|
+
Version: #{YouPlot::VERSION} (using UnicodePlot #{UnicodePlot::VERSION})
|
114
|
+
Source: https://github.com/kojix2/youplot
|
115
|
+
|
116
|
+
Usage: uplot <command> [options] <in.tsv>
|
117
|
+
|
118
|
+
Commands:
|
119
|
+
barplot bar draw a horizontal barplot
|
120
|
+
histogram hist draw a horizontal histogram
|
121
|
+
lineplot line draw a line chart
|
122
|
+
lineplots lines draw a line chart with multiple series
|
123
|
+
scatter s draw a scatter plot
|
124
|
+
density d draw a density plot
|
125
|
+
boxplot box draw a horizontal boxplot
|
126
|
+
colors color show the list of available colors
|
127
|
+
|
128
|
+
count c draw a baplot based on the number of
|
129
|
+
occurrences (slow)
|
130
|
+
|
131
|
+
General options:
|
132
|
+
--help print command specific help menu
|
133
|
+
--version print the version of YouPlot
|
134
|
+
MSG
|
135
|
+
|
136
|
+
# Help for the main parser is simple.
|
137
|
+
# Simply show the banner above.
|
138
|
+
main_parser.on('--help', 'print sub-command help menu') do
|
139
|
+
puts main_parser.banner
|
140
|
+
puts
|
141
|
+
exit if YouPlot.run_as_executable?
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def sub_parser_add_symbol
|
146
|
+
sub_parser.on_head('--symbol STR', String, 'character to be used to plot the bars') do |v|
|
147
|
+
params.symbol = v
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def sub_parser_add_xscale
|
152
|
+
xscale_options = UnicodePlot::ValueTransformer::PREDEFINED_TRANSFORM_FUNCTIONS.keys.join(', ')
|
153
|
+
sub_parser.on_head('--xscale STR', String, "axis scaling (#{xscale_options})") do |v|
|
154
|
+
params.xscale = v
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def sub_parser_add_canvas
|
159
|
+
sub_parser.on_head('--canvas STR', String, 'type of canvas') do |v|
|
160
|
+
params.canvas = v.to_sym
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
def sub_parser_add_xlim
|
165
|
+
sub_parser.on_head('--xlim FLOAT,FLOAT', Array, 'plotting range for the x coordinate') do |v|
|
166
|
+
params.xlim = v.take(2)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
def sub_parser_add_ylim
|
171
|
+
sub_parser.on_head('--ylim FLOAT,FLOAT', Array, 'plotting range for the y coordinate') do |v|
|
172
|
+
params.ylim = v.take(2)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
def sub_parser_add_grid
|
177
|
+
sub_parser.on_head('--[no-]grid', TrueClass, 'draws grid-lines at the origin') do |v|
|
178
|
+
params.grid = v
|
144
179
|
end
|
145
180
|
end
|
146
181
|
|
147
|
-
def
|
148
|
-
@sub_parser
|
149
|
-
|
182
|
+
def create_sub_parser
|
183
|
+
@sub_parser = create_default_parser
|
184
|
+
sub_parser.banner = \
|
185
|
+
<<~MSG
|
150
186
|
|
151
187
|
Usage: YouPlot #{command} [options] <in.tsv>
|
152
188
|
|
153
189
|
Options for #{command}:
|
154
190
|
MSG
|
155
191
|
|
156
|
-
|
192
|
+
case command
|
157
193
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
194
|
+
# If you type only `uplot` in the terminal.
|
195
|
+
when nil
|
196
|
+
warn main_parser.banner
|
197
|
+
warn "\n"
|
198
|
+
exit 1 if YouPlot.run_as_executable?
|
199
|
+
|
200
|
+
when :barplot, :bar
|
201
|
+
sub_parser_add_symbol
|
202
|
+
sub_parser.on_head('--fmt STR', String, 'xy : header is like x, y...', 'yx : header is like y, x...') do |v|
|
203
|
+
options[:fmt] = v
|
204
|
+
end
|
205
|
+
sub_parser_add_xscale
|
163
206
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
end
|
168
|
-
parser.on_head('--xscale VAL', String, 'axis scaling') do |v|
|
169
|
-
params.xscale = v
|
170
|
-
end
|
171
|
-
parser.on_head('--fmt VAL', String, 'xy : header is like x, y...', 'yx : header is like y, x...') do |v|
|
172
|
-
@options[:fmt] = v
|
173
|
-
end
|
174
|
-
|
175
|
-
when :count, :c
|
176
|
-
parser.on_head('--symbol VAL', String, 'character to be used to plot the bars') do |v|
|
177
|
-
params.symbol = v
|
178
|
-
end
|
179
|
-
|
180
|
-
when :histogram, :hist
|
181
|
-
parser.on_head('-n', '--nbins VAL', Numeric, 'approximate number of bins') do |v|
|
182
|
-
params.nbins = v
|
183
|
-
end
|
184
|
-
parser.on_head('--closed VAL', String) do |v|
|
185
|
-
params.closed = v
|
186
|
-
end
|
187
|
-
parser.on_head('--symbol VAL', String, 'character to be used to plot the bars') do |v|
|
188
|
-
params.symbol = v
|
189
|
-
end
|
190
|
-
|
191
|
-
when :lineplot, :line
|
192
|
-
parser.on_head('--canvas VAL', String, 'type of canvas') do |v|
|
193
|
-
params.canvas = v
|
194
|
-
end
|
195
|
-
parser.on_head('--xlim VAL', Array, 'plotting range for the x coordinate') do |v|
|
196
|
-
params.xlim = v.take(2)
|
197
|
-
end
|
198
|
-
parser.on_head('--ylim VAL', Array, 'plotting range for the y coordinate') do |v|
|
199
|
-
params.ylim = v.take(2)
|
200
|
-
end
|
201
|
-
parser.on_head('--fmt VAL', String, 'xy : header is like x, y...', 'yx : header is like y, x...') do |v|
|
202
|
-
@options[:fmt] = v
|
203
|
-
end
|
204
|
-
|
205
|
-
when :lineplots, :lines
|
206
|
-
parser.on_head('--canvas VAL', String) do |v|
|
207
|
-
params.canvas = v
|
208
|
-
end
|
209
|
-
parser.on_head('--xlim VAL', Array, 'plotting range for the x coordinate') do |v|
|
210
|
-
params.xlim = v.take(2)
|
211
|
-
end
|
212
|
-
parser.on_head('--ylim VAL', Array, 'plotting range for the y coordinate') do |v|
|
213
|
-
params.ylim = v.take(2)
|
214
|
-
end
|
215
|
-
parser.on_head('--fmt VAL', String, 'xyxy : header is like x1, y1, x2, y2, x3, y3...',
|
216
|
-
'xyy : header is like x, y1, y2, y2, y3...') do |v|
|
217
|
-
@options[:fmt] = v
|
218
|
-
end
|
219
|
-
|
220
|
-
when :scatter, :s
|
221
|
-
parser.on_head('--canvas VAL', String) do |v|
|
222
|
-
params.canvas = v
|
223
|
-
end
|
224
|
-
parser.on_head('--xlim VAL', Array, 'plotting range for the x coordinate') do |v|
|
225
|
-
params.xlim = v.take(2)
|
226
|
-
end
|
227
|
-
parser.on_head('--ylim VAL', Array, 'plotting range for the y coordinate') do |v|
|
228
|
-
params.ylim = v.take(2)
|
229
|
-
end
|
230
|
-
parser.on_head('--fmt VAL', String, 'xyxy : header is like x1, y1, x2, y2, x3, y3...',
|
231
|
-
'xyy : header is like x, y1, y2, y2, y3...') do |v|
|
232
|
-
@options[:fmt] = v
|
233
|
-
end
|
234
|
-
|
235
|
-
when :density, :d
|
236
|
-
parser.on_head('--grid', TrueClass) do |v|
|
237
|
-
params.grid = v
|
238
|
-
end
|
239
|
-
parser.on_head('--xlim VAL', Array, 'plotting range for the x coordinate') do |v|
|
240
|
-
params.xlim = v.take(2)
|
241
|
-
end
|
242
|
-
parser.on_head('--ylim VAL', Array, 'plotting range for the y coordinate') do |v|
|
243
|
-
params.ylim = v.take(2)
|
244
|
-
end
|
245
|
-
parser.on('--fmt VAL', String, 'xyxy : header is like x1, y1, x2, y2, x3, y3...',
|
246
|
-
'xyy : header is like x, y1, y2, y2, y3...') do |v|
|
247
|
-
@options[:fmt] = v
|
248
|
-
end
|
249
|
-
|
250
|
-
when :boxplot, :box
|
251
|
-
parser.on_head('--xlim VAL', Array, 'plotting range for the x coordinate') do |v|
|
252
|
-
params.xlim = v.take(2)
|
253
|
-
end
|
254
|
-
|
255
|
-
when :colors, :color, :colours, :colour
|
256
|
-
parser.on_head('-n', '--names', 'show color names only', TrueClass) do |v|
|
257
|
-
@options[:color_names] = v
|
258
|
-
end
|
207
|
+
when :count, :c
|
208
|
+
sub_parser_add_symbol
|
209
|
+
sub_parser_add_xscale
|
259
210
|
|
260
|
-
|
261
|
-
|
211
|
+
when :histogram, :hist
|
212
|
+
sub_parser_add_symbol
|
213
|
+
sub_parser.on_head('--closed STR', String, 'side of the intervals to be closed [left]') do |v|
|
214
|
+
params.closed = v
|
215
|
+
end
|
216
|
+
sub_parser.on_head('-n', '--nbins INT', Numeric, 'approximate number of bins') do |v|
|
217
|
+
params.nbins = v
|
218
|
+
end
|
219
|
+
|
220
|
+
when :lineplot, :line
|
221
|
+
sub_parser_add_canvas
|
222
|
+
sub_parser_add_grid
|
223
|
+
sub_parser.on_head('--fmt STR', String, 'xy : header is like x, y...', 'yx : header is like y, x...') do |v|
|
224
|
+
options[:fmt] = v
|
225
|
+
end
|
226
|
+
sub_parser_add_ylim
|
227
|
+
sub_parser_add_xlim
|
228
|
+
|
229
|
+
when :lineplots, :lines
|
230
|
+
sub_parser_add_canvas
|
231
|
+
sub_parser_add_grid
|
232
|
+
sub_parser.on_head('--fmt STR', String, 'xyxy : header is like x1, y1, x2, y2, x3, y3...',
|
233
|
+
'xyy : header is like x, y1, y2, y2, y3...') do |v|
|
234
|
+
options[:fmt] = v
|
235
|
+
end
|
236
|
+
sub_parser_add_ylim
|
237
|
+
sub_parser_add_xlim
|
238
|
+
|
239
|
+
when :scatter, :s
|
240
|
+
sub_parser_add_canvas
|
241
|
+
sub_parser_add_grid
|
242
|
+
sub_parser.on_head('--fmt STR', String, 'xyxy : header is like x1, y1, x2, y2, x3, y3...',
|
243
|
+
'xyy : header is like x, y1, y2, y2, y3...') do |v|
|
244
|
+
options[:fmt] = v
|
245
|
+
end
|
246
|
+
sub_parser_add_ylim
|
247
|
+
sub_parser_add_xlim
|
248
|
+
|
249
|
+
when :density, :d
|
250
|
+
sub_parser_add_canvas
|
251
|
+
sub_parser_add_grid
|
252
|
+
sub_parser.on('--fmt STR', String, 'xyxy : header is like x1, y1, x2, y2, x3, y3...',
|
253
|
+
'xyy : header is like x, y1, y2, y2, y3...') do |v|
|
254
|
+
options[:fmt] = v
|
255
|
+
end
|
256
|
+
sub_parser_add_ylim
|
257
|
+
sub_parser_add_xlim
|
258
|
+
|
259
|
+
when :boxplot, :box
|
260
|
+
sub_parser_add_xlim
|
261
|
+
|
262
|
+
when :colors, :color, :colours, :colour
|
263
|
+
sub_parser.on_head('-n', '--names', 'show color names only', TrueClass) do |v|
|
264
|
+
options[:color_names] = v
|
265
|
+
end
|
266
|
+
|
267
|
+
else
|
268
|
+
error_message = "uplot: unrecognized command '#{command}'"
|
269
|
+
if YouPlot.run_as_executable?
|
270
|
+
warn error_message
|
262
271
|
exit 1
|
272
|
+
else
|
273
|
+
raise Error, error_message
|
263
274
|
end
|
264
275
|
end
|
265
276
|
end
|
266
277
|
|
267
278
|
def parse_options(argv = ARGV)
|
268
279
|
begin
|
269
|
-
|
280
|
+
create_main_parser.order!(argv)
|
270
281
|
rescue OptionParser::ParseError => e
|
271
282
|
warn "uplot: #{e.message}"
|
272
|
-
exit 1
|
283
|
+
exit 1 if YouPlot.run_as_executable?
|
273
284
|
end
|
274
285
|
|
275
286
|
@command = argv.shift&.to_sym
|
276
287
|
|
277
288
|
begin
|
278
|
-
|
289
|
+
create_sub_parser&.parse!(argv)
|
279
290
|
rescue OptionParser::ParseError => e
|
280
291
|
warn "uplot: #{e.message}"
|
281
|
-
exit 1
|
292
|
+
exit 1 if YouPlot.run_as_executable?
|
282
293
|
end
|
283
294
|
end
|
284
295
|
end
|
data/lib/youplot/dsv.rb
CHANGED
@@ -25,10 +25,10 @@ module YouPlot
|
|
25
25
|
Data.new(headers, series)
|
26
26
|
elsif h_size > s_size
|
27
27
|
warn "\e[35mThe number of headers is greater than the number of series.\e[0m"
|
28
|
-
exit 1
|
28
|
+
exit 1 if YouPlot.run_as_executable?
|
29
29
|
elsif h_size < s_size
|
30
30
|
warn "\e[35mThe number of headers is less than the number of series.\e[0m"
|
31
|
-
exit 1
|
31
|
+
exit 1 if YouPlot.run_as_executable?
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -67,12 +67,10 @@ module YouPlot
|
|
67
67
|
else
|
68
68
|
Array.new(arr[0].size, [])
|
69
69
|
end
|
70
|
+
elsif transpose
|
71
|
+
arr
|
70
72
|
else
|
71
|
-
|
72
|
-
arr
|
73
|
-
else
|
74
|
-
transpose2(arr)
|
75
|
-
end
|
73
|
+
transpose2(arr)
|
76
74
|
end
|
77
75
|
end
|
78
76
|
end
|
data/lib/youplot/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: youplot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kojix2
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-01-
|
11
|
+
date: 2021-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: unicode_plot
|