youplot 0.3.3 → 0.4.2
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 +53 -31
- data/exe/uplot +1 -1
- data/exe/youplot +1 -1
- data/lib/youplot.rb +12 -4
- data/lib/youplot/backends/processing.rb +22 -10
- data/lib/youplot/backends/{unicode_plot_backend.rb → unicode_plot.rb} +42 -29
- data/lib/youplot/command.rb +70 -17
- data/lib/youplot/dsv.rb +58 -50
- data/lib/youplot/options.rb +18 -0
- data/lib/youplot/parameters.rb +34 -0
- data/lib/youplot/parser.rb +310 -0
- data/lib/youplot/version.rb +1 -1
- metadata +8 -8
- data/lib/youplot/command/options.rb +0 -19
- data/lib/youplot/command/parser.rb +0 -286
- data/lib/youplot/command/plot_params.rb +0 -37
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.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kojix2
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: unicode_plot
|
@@ -109,14 +109,14 @@ files:
|
|
109
109
|
- exe/youplot
|
110
110
|
- lib/youplot.rb
|
111
111
|
- lib/youplot/backends/processing.rb
|
112
|
-
- lib/youplot/backends/
|
112
|
+
- lib/youplot/backends/unicode_plot.rb
|
113
113
|
- lib/youplot/command.rb
|
114
|
-
- lib/youplot/command/options.rb
|
115
|
-
- lib/youplot/command/parser.rb
|
116
|
-
- lib/youplot/command/plot_params.rb
|
117
114
|
- lib/youplot/dsv.rb
|
115
|
+
- lib/youplot/options.rb
|
116
|
+
- lib/youplot/parameters.rb
|
117
|
+
- lib/youplot/parser.rb
|
118
118
|
- lib/youplot/version.rb
|
119
|
-
homepage: https://github.com/
|
119
|
+
homepage: https://github.com/red-data-tools/YouPlot
|
120
120
|
licenses:
|
121
121
|
- MIT
|
122
122
|
metadata: {}
|
@@ -135,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
135
|
- !ruby/object:Gem::Version
|
136
136
|
version: '0'
|
137
137
|
requirements: []
|
138
|
-
rubygems_version: 3.2.
|
138
|
+
rubygems_version: 3.2.15
|
139
139
|
signing_key:
|
140
140
|
specification_version: 4
|
141
141
|
summary: A command line tool for Unicode Plotting
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module YouPlot
|
4
|
-
class Command
|
5
|
-
Options = Struct.new(
|
6
|
-
:delimiter,
|
7
|
-
:transpose,
|
8
|
-
:headers,
|
9
|
-
:pass,
|
10
|
-
:progressive,
|
11
|
-
:output,
|
12
|
-
:fmt,
|
13
|
-
:encoding,
|
14
|
-
:color_names,
|
15
|
-
:debug,
|
16
|
-
keyword_init: true
|
17
|
-
)
|
18
|
-
end
|
19
|
-
end
|
@@ -1,286 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'optparse'
|
4
|
-
require_relative 'options'
|
5
|
-
require_relative 'plot_params'
|
6
|
-
|
7
|
-
module YouPlot
|
8
|
-
class Command
|
9
|
-
class Parser
|
10
|
-
attr_reader :command, :options, :params
|
11
|
-
|
12
|
-
def initialize
|
13
|
-
@command = nil
|
14
|
-
|
15
|
-
@options = Options.new(
|
16
|
-
delimiter: "\t",
|
17
|
-
transpose: false,
|
18
|
-
headers: nil,
|
19
|
-
pass: false,
|
20
|
-
output: $stderr,
|
21
|
-
fmt: 'xyy',
|
22
|
-
encoding: nil,
|
23
|
-
color_names: false,
|
24
|
-
debug: false
|
25
|
-
)
|
26
|
-
|
27
|
-
@params = PlotParams.new
|
28
|
-
end
|
29
|
-
|
30
|
-
def create_default_parser
|
31
|
-
OptionParser.new do |opt|
|
32
|
-
opt.program_name = 'YouPlot'
|
33
|
-
opt.version = YouPlot::VERSION
|
34
|
-
opt.summary_width = 24
|
35
|
-
opt.on_tail('') # Add a blank line at the end
|
36
|
-
opt.separator('')
|
37
|
-
opt.on('Common options:')
|
38
|
-
opt.on('-O', '--pass [FILE]', 'file to output input data to [stdout]',
|
39
|
-
'for inserting YouPlot in the middle of Unix pipes') do |v|
|
40
|
-
@options[:pass] = v || $stdout
|
41
|
-
end
|
42
|
-
opt.on('-o', '--output [FILE]', 'file to output plots to [stdout]',
|
43
|
-
'If no option is specified, plot will print to stderr') do |v|
|
44
|
-
@options[:output] = v || $stdout
|
45
|
-
end
|
46
|
-
opt.on('-d', '--delimiter VAL', String, 'use DELIM instead of TAB for field delimiter') do |v|
|
47
|
-
@options[:delimiter] = v
|
48
|
-
end
|
49
|
-
opt.on('-H', '--headers', TrueClass, 'specify that the input has header row') do |v|
|
50
|
-
@options[:headers] = v
|
51
|
-
end
|
52
|
-
opt.on('-T', '--transpose', TrueClass, 'transpose the axes of the input data') do |v|
|
53
|
-
@options[:transpose] = v
|
54
|
-
end
|
55
|
-
opt.on('-t', '--title VAL', String, 'print string on the top of plot') do |v|
|
56
|
-
params.title = v
|
57
|
-
end
|
58
|
-
opt.on('-x', '--xlabel VAL', String, 'print string on the bottom of the plot') do |v|
|
59
|
-
params.xlabel = v
|
60
|
-
end
|
61
|
-
opt.on('-y', '--ylabel VAL', String, 'print string on the far left of the plot') do |v|
|
62
|
-
params.ylabel = v
|
63
|
-
end
|
64
|
-
opt.on('-w', '--width VAL', Integer, 'number of characters per row') do |v|
|
65
|
-
params.width = v
|
66
|
-
end
|
67
|
-
opt.on('-h', '--height VAL', Numeric, 'number of rows') do |v|
|
68
|
-
params.height = v
|
69
|
-
end
|
70
|
-
opt.on('-b', '--border VAL', String, 'specify the style of the bounding box') do |v|
|
71
|
-
params.border = v.to_sym
|
72
|
-
end
|
73
|
-
opt.on('-m', '--margin VAL', Numeric, 'number of spaces to the left of the plot') do |v|
|
74
|
-
params.margin = v
|
75
|
-
end
|
76
|
-
opt.on('-p', '--padding VAL', Numeric, 'space of the left and right of the plot') do |v|
|
77
|
-
params.padding = v
|
78
|
-
end
|
79
|
-
opt.on('-c', '--color VAL', String, 'color of the drawing') do |v|
|
80
|
-
params.color = v =~ /\A[0-9]+\z/ ? v.to_i : v.to_sym
|
81
|
-
end
|
82
|
-
opt.on('--[no-]labels', TrueClass, 'hide the labels') do |v|
|
83
|
-
params.labels = v
|
84
|
-
end
|
85
|
-
opt.on('--progress', TrueClass, 'progressive mode [experimental]') do |v|
|
86
|
-
@options[:progressive] = v
|
87
|
-
end
|
88
|
-
opt.on('--encoding VAL', String, 'Specify the input encoding') do |v|
|
89
|
-
@options[:encoding] = v
|
90
|
-
end
|
91
|
-
# Optparse adds the help option, but it doesn't show up in usage.
|
92
|
-
# This is why you need the code below.
|
93
|
-
opt.on('--help', 'print sub-command help menu') do
|
94
|
-
puts opt.help
|
95
|
-
exit
|
96
|
-
end
|
97
|
-
opt.on('--debug', TrueClass, 'print preprocessed data') do |v|
|
98
|
-
@options[:debug] = v
|
99
|
-
end
|
100
|
-
yield opt if block_given?
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
def main_parser
|
105
|
-
@main_parser ||= create_default_parser do |main_parser|
|
106
|
-
# Here, help message is stored in the banner.
|
107
|
-
# Because help of main_parser may be referred by `sub_parser`.
|
108
|
-
|
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
|
-
# Actually, main_parser can take common optional arguments.
|
137
|
-
# However, these options dose not be shown in the help menu.
|
138
|
-
# I think the main help should be simple.
|
139
|
-
main_parser.on('--help', 'print sub-command help menu') do
|
140
|
-
puts main_parser.banner
|
141
|
-
puts
|
142
|
-
exit
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
def sub_parser
|
148
|
-
@sub_parser ||= create_default_parser do |parser|
|
149
|
-
parser.banner = <<~MSG
|
150
|
-
|
151
|
-
Usage: YouPlot #{command} [options] <in.tsv>
|
152
|
-
|
153
|
-
Options for #{command}:
|
154
|
-
MSG
|
155
|
-
|
156
|
-
case command
|
157
|
-
|
158
|
-
# If you type only `uplot` in the terminal.
|
159
|
-
when nil
|
160
|
-
warn main_parser.banner
|
161
|
-
warn "\n"
|
162
|
-
exit 1
|
163
|
-
|
164
|
-
when :barplot, :bar
|
165
|
-
parser.on_head('--symbol VAL', String, 'character to be used to plot the bars') do |v|
|
166
|
-
params.symbol = v
|
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
|
259
|
-
|
260
|
-
else
|
261
|
-
warn "uplot: unrecognized command '#{command}'"
|
262
|
-
exit 1
|
263
|
-
end
|
264
|
-
end
|
265
|
-
end
|
266
|
-
|
267
|
-
def parse_options(argv = ARGV)
|
268
|
-
begin
|
269
|
-
main_parser.order!(argv)
|
270
|
-
rescue OptionParser::ParseError => e
|
271
|
-
warn "uplot: #{e.message}"
|
272
|
-
exit 1
|
273
|
-
end
|
274
|
-
|
275
|
-
@command = argv.shift&.to_sym
|
276
|
-
|
277
|
-
begin
|
278
|
-
sub_parser.parse!(argv)
|
279
|
-
rescue OptionParser::ParseError => e
|
280
|
-
warn "uplot: #{e.message}"
|
281
|
-
exit 1
|
282
|
-
end
|
283
|
-
end
|
284
|
-
end
|
285
|
-
end
|
286
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module YouPlot
|
4
|
-
class Command
|
5
|
-
# UnicodePlot parameters.
|
6
|
-
# * Normally in a Ruby program, you might use hash for the parameter object.
|
7
|
-
# * Here, I use Struct for 2 safety reason.
|
8
|
-
# * The keys are static in Struct.
|
9
|
-
# * Struct does not conflict with keyword arguments. Hash dose.
|
10
|
-
PlotParams = Struct.new(
|
11
|
-
# Sort me!
|
12
|
-
:title,
|
13
|
-
:width,
|
14
|
-
:height,
|
15
|
-
:border,
|
16
|
-
:margin,
|
17
|
-
:padding,
|
18
|
-
:color,
|
19
|
-
:xlabel,
|
20
|
-
:ylabel,
|
21
|
-
:labels,
|
22
|
-
:symbol,
|
23
|
-
:xscale,
|
24
|
-
:nbins,
|
25
|
-
:closed,
|
26
|
-
:canvas,
|
27
|
-
:xlim,
|
28
|
-
:ylim,
|
29
|
-
:grid,
|
30
|
-
:name
|
31
|
-
) do
|
32
|
-
def to_hc
|
33
|
-
to_h.compact
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|