youplot 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 83145e216c0d124d537c8a01d63f9203730a74191fefcb9de5743b08e0e504bd
4
- data.tar.gz: a246eab22f11ab8c526cc838d9f2fbf7d249721b4782287087c08a5410f8647b
3
+ metadata.gz: 6db41d30d7f51a3209bd6c17e805c7dd6bcaf68db325ffb2d23b95850837d8d4
4
+ data.tar.gz: 1580e5501a9b635cc871c9d572549e4d33cc46e265ffe7befcd0a9d51285673a
5
5
  SHA512:
6
- metadata.gz: d9138c26fade36d7d0ca19100b47dcb8e65c8c884d13b74d258dcae9ea304ced2fc783b08e871d76607e57e394e6b861c81f1f5030caba53493b2f4740a05cd2
7
- data.tar.gz: f293d686791ba1481948877e534c9085e99c24ab9c36026979002ecaa9ee2ece6f12ad7193cda936c62e472e2f94008466cc666e9405157bfcc348c4c21c4579
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
- if tally && Enumerable.method_defined?(:tally)
12
- arr.tally
13
- else
14
- # value_counts Enumerable::Statistics
15
- arr.value_counts(dropna: false)
16
- end
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
- .transpose
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
@@ -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
@@ -14,7 +14,7 @@ module YouPlot
14
14
 
15
15
  # Remove blank lines
16
16
  arr.delete_if do |i|
17
- i == [] or i.all? nil
17
+ i == [] or i.all?(&:nil?)
18
18
  end
19
19
 
20
20
  # get header
@@ -11,8 +11,8 @@ module YouPlot
11
11
  :fmt,
12
12
  :progressive,
13
13
  :encoding,
14
- :color_names,
15
- :debug,
16
- keyword_init: true
14
+ :reverse, # count
15
+ :color_names, # color
16
+ :debug
17
17
  )
18
18
  end
@@ -15,16 +15,16 @@ module YouPlot
15
15
  @command = nil
16
16
 
17
17
  @options = Options.new(
18
- delimiter: "\t",
19
- transpose: false,
20
- headers: nil,
21
- pass: false,
22
- output: $stderr,
23
- fmt: 'xyy',
24
- progressive: false,
25
- encoding: nil,
26
- color_names: false,
27
- debug: false
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
- sub_parser.on_head('--canvas STR', String, 'type of canvas') do |v|
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', TrueClass) do |v|
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module YouPlot
4
- VERSION = '0.4.0'
4
+ VERSION = '0.4.1'
5
5
  end
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.0
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-05-30 00:00:00.000000000 Z
11
+ date: 2021-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: unicode_plot