youplot 0.4.0 → 0.4.1
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/lib/youplot/backends/processing.rb +22 -14
- data/lib/youplot/backends/unicode_plot.rb +2 -2
- data/lib/youplot/command.rb +1 -1
- data/lib/youplot/dsv.rb +1 -1
- data/lib/youplot/options.rb +3 -3
- data/lib/youplot/parser.rb +16 -12
- 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: 6db41d30d7f51a3209bd6c17e805c7dd6bcaf68db325ffb2d23b95850837d8d4
|
4
|
+
data.tar.gz: 1580e5501a9b635cc871c9d572549e4d33cc46e265ffe7befcd0a9d51285673a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a60bbfd3edf64151c20a23bb3e13b7f528e7a313030d8e1134bb5cac7918aff2cc604fca301c2a86c3f8e8a8a6b411bb0e28fbb15b179ff4528559ded890cc7
|
7
|
+
data.tar.gz: b76603426970dc8d7c019bb394374d9c1e851a216a0d6607f5adcd9532649a25a6fd56113bce037d92a3eb66fdcab533f58391d8db93aa5091020c15c0043b16
|
@@ -6,22 +6,30 @@ module YouPlot
|
|
6
6
|
module Processing
|
7
7
|
module_function
|
8
8
|
|
9
|
-
def count_values(arr, tally: true)
|
9
|
+
def count_values(arr, tally: true, reverse: false)
|
10
10
|
# tally was added in Ruby 2.7
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
.sort do |a, b|
|
18
|
-
# compare values
|
19
|
-
r = b[1] <=> a[1]
|
20
|
-
# If the values are the same, compare by name
|
21
|
-
r = a[0] <=> b[0] if r == 0
|
22
|
-
r
|
11
|
+
result = \
|
12
|
+
if tally && Enumerable.method_defined?(:tally)
|
13
|
+
arr.tally
|
14
|
+
else
|
15
|
+
# value_counts Enumerable::Statistics
|
16
|
+
arr.value_counts(dropna: false)
|
23
17
|
end
|
24
|
-
|
18
|
+
|
19
|
+
# sorting
|
20
|
+
result = result.sort do |a, b|
|
21
|
+
# compare values
|
22
|
+
r = b[1] <=> a[1]
|
23
|
+
# If the values are the same, compare by name
|
24
|
+
r = a[0] <=> b[0] if r.zero?
|
25
|
+
r
|
26
|
+
end
|
27
|
+
|
28
|
+
# --reverse option
|
29
|
+
result.reverse! if reverse
|
30
|
+
|
31
|
+
# prepare for barplot
|
32
|
+
result.transpose
|
25
33
|
end
|
26
34
|
end
|
27
35
|
end
|
@@ -14,12 +14,12 @@ module YouPlot
|
|
14
14
|
|
15
15
|
module_function
|
16
16
|
|
17
|
-
def barplot(data, params, fmt = nil, count: false)
|
17
|
+
def barplot(data, params, fmt = nil, count: false, reverse: false)
|
18
18
|
headers = data.headers
|
19
19
|
series = data.series
|
20
20
|
# `uplot count`
|
21
21
|
if count
|
22
|
-
series = Processing.count_values(series[0])
|
22
|
+
series = Processing.count_values(series[0], reverse: reverse)
|
23
23
|
params.title = headers[0] if headers
|
24
24
|
end
|
25
25
|
if series.size == 1
|
data/lib/youplot/command.rb
CHANGED
@@ -146,7 +146,7 @@ module YouPlot
|
|
146
146
|
when :bar, :barplot
|
147
147
|
@backend.barplot(data, params, options[:fmt])
|
148
148
|
when :count, :c
|
149
|
-
@backend.barplot(data, params, count: true)
|
149
|
+
@backend.barplot(data, params, count: true, reverse: options[:reverse])
|
150
150
|
when :hist, :histogram
|
151
151
|
@backend.histogram(data, params)
|
152
152
|
when :line, :lineplot
|
data/lib/youplot/dsv.rb
CHANGED
data/lib/youplot/options.rb
CHANGED
data/lib/youplot/parser.rb
CHANGED
@@ -15,16 +15,16 @@ module YouPlot
|
|
15
15
|
@command = nil
|
16
16
|
|
17
17
|
@options = Options.new(
|
18
|
-
|
19
|
-
transpose:
|
20
|
-
headers:
|
21
|
-
pass:
|
22
|
-
|
23
|
-
|
24
|
-
progressive:
|
25
|
-
encoding:
|
26
|
-
color_names:
|
27
|
-
debug:
|
18
|
+
"\t", # elimiter:
|
19
|
+
false, # transpose:
|
20
|
+
nil, # headers:
|
21
|
+
false, # pass:
|
22
|
+
$stderr, # output:
|
23
|
+
'xyy', # fmt:
|
24
|
+
false, # progressive:
|
25
|
+
nil, # encoding:
|
26
|
+
false, # color_names:
|
27
|
+
false # debug:
|
28
28
|
)
|
29
29
|
|
30
30
|
@params = Parameters.new
|
@@ -163,7 +163,8 @@ module YouPlot
|
|
163
163
|
end
|
164
164
|
|
165
165
|
def sub_parser_add_canvas
|
166
|
-
|
166
|
+
canvas_types = UnicodePlot::Canvas::CANVAS_CLASS_MAP.keys.join(', ')
|
167
|
+
sub_parser.on_head('--canvas STR', String, 'type of canvas', "(#{canvas_types})") do |v|
|
167
168
|
params.canvas = v.to_sym
|
168
169
|
end
|
169
170
|
end
|
@@ -226,6 +227,9 @@ module YouPlot
|
|
226
227
|
sub_parser_add_xscale
|
227
228
|
|
228
229
|
when :count, :c
|
230
|
+
sub_parser.on_head('-r', '--reverse', TrueClass, 'reverse the result of comparisons') do |v|
|
231
|
+
options.reverse = v
|
232
|
+
end
|
229
233
|
sub_parser_add_symbol
|
230
234
|
sub_parser_add_xscale
|
231
235
|
|
@@ -270,7 +274,7 @@ module YouPlot
|
|
270
274
|
sub_parser_add_xlim
|
271
275
|
|
272
276
|
when :colors, :color, :colours, :colour
|
273
|
-
sub_parser.on_head('-n', '--names', 'show color names only'
|
277
|
+
sub_parser.on_head('-n', '--names', TrueClass, 'show color names only') do |v|
|
274
278
|
options[:color_names] = v
|
275
279
|
end
|
276
280
|
|
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.
|
4
|
+
version: 0.4.1
|
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-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: unicode_plot
|