Skip to content

Commit da6351c

Browse files
committed
Format count value labels as integers
Related to #44 Fix #62 Reported by @forthrin Thanks!
1 parent 653e8b6 commit da6351c

3 files changed

Lines changed: 57 additions & 53 deletions

File tree

lib/youplot/backends/unicode_plot.rb

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ def barplot(data, params, fmt = nil, count: false, reverse: false)
6161
end
6262
params.title ||= headers[y_col] if headers
6363
labels = series[x_col]
64-
values = series[y_col].map(&:to_f)
64+
values = if count
65+
series[y_col].map(&:to_i)
66+
else
67+
series[y_col].map(&:to_f)
68+
end
6569
end
6670
::UnicodePlot.barplot(labels, values, **params.to_hc)
6771
end
@@ -215,14 +219,14 @@ def check_series_size(data, fmt)
215219
# if fmt == 'xyxy' && series.size is odd, the number of series is not even.
216220
return unless fmt == 'xyxy' && series.size.odd?
217221

218-
warn <<~EOS
219-
YouPlot: In the xyxy format, the number of series must be even.
222+
warn <<~EOS
223+
YouPlot: In the xyxy format, the number of series must be even.
220224
221-
Number of series: \e[35m#{series.size}\e[0m
222-
Headers: \e[35m#{data.headers.inspect}\e[0m
223-
EOS
224-
# NOTE: Error messages cannot be colored.
225-
YouPlot.run_as_executable ? exit(1) : raise(Error)
225+
Number of series: \e[35m#{series.size}\e[0m
226+
Headers: \e[35m#{data.headers.inspect}\e[0m
227+
EOS
228+
# NOTE: Error messages cannot be colored.
229+
YouPlot.run_as_executable ? exit(1) : raise(Error)
226230
end
227231
end
228232
end

test/fixtures/iris-count.txt

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
sepal_length
22
┌ ┐
3-
5.0 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 10.0
4-
5.1 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 9.0
5-
6.3 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 9.0
6-
5.7 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■ 8.0
7-
6.7 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■ 8.0
8-
5.5 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 7.0
9-
5.8 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 7.0
10-
6.4 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 7.0
11-
4.9 ┤■■■■■■■■■■■■■■■■■■■■ 6.0
12-
5.4 ┤■■■■■■■■■■■■■■■■■■■■ 6.0
13-
5.6 ┤■■■■■■■■■■■■■■■■■■■■ 6.0
14-
6.0 ┤■■■■■■■■■■■■■■■■■■■■ 6.0
15-
6.1 ┤■■■■■■■■■■■■■■■■■■■■ 6.0
16-
4.8 ┤■■■■■■■■■■■■■■■■■ 5.0
17-
6.5 ┤■■■■■■■■■■■■■■■■■ 5.0
18-
4.6 ┤■■■■■■■■■■■■■■ 4.0
19-
5.2 ┤■■■■■■■■■■■■■■ 4.0
20-
6.2 ┤■■■■■■■■■■■■■■ 4.0
21-
6.9 ┤■■■■■■■■■■■■■■ 4.0
22-
7.7 ┤■■■■■■■■■■■■■■ 4.0
23-
4.4 ┤■■■■■■■■■■ 3.0
24-
5.9 ┤■■■■■■■■■■ 3.0
25-
6.8 ┤■■■■■■■■■■ 3.0
26-
7.2 ┤■■■■■■■■■■ 3.0
27-
4.7 ┤■■■■■■■ 2.0
28-
6.6 ┤■■■■■■■ 2.0
29-
4.3 ┤■■■ 1.0
30-
4.5 ┤■■■ 1.0
31-
5.3 ┤■■■ 1.0
32-
7.0 ┤■■■ 1.0
33-
7.1 ┤■■■ 1.0
34-
7.3 ┤■■■ 1.0
35-
7.4 ┤■■■ 1.0
36-
7.6 ┤■■■ 1.0
37-
7.9 ┤■■■ 1.0
3+
5.0 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 10
4+
5.1 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 9
5+
6.3 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 9
6+
5.7 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 8
7+
6.7 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 8
8+
5.5 ┤■■■■■■■■■■■■■■■■■■■■■■■■■ 7
9+
5.8 ┤■■■■■■■■■■■■■■■■■■■■■■■■■ 7
10+
6.4 ┤■■■■■■■■■■■■■■■■■■■■■■■■■ 7
11+
4.9 ┤■■■■■■■■■■■■■■■■■■■■■■ 6
12+
5.4 ┤■■■■■■■■■■■■■■■■■■■■■■ 6
13+
5.6 ┤■■■■■■■■■■■■■■■■■■■■■■ 6
14+
6.0 ┤■■■■■■■■■■■■■■■■■■■■■■ 6
15+
6.1 ┤■■■■■■■■■■■■■■■■■■■■■■ 6
16+
4.8 ┤■■■■■■■■■■■■■■■■■■ 5
17+
6.5 ┤■■■■■■■■■■■■■■■■■■ 5
18+
4.6 ┤■■■■■■■■■■■■■■ 4
19+
5.2 ┤■■■■■■■■■■■■■■ 4
20+
6.2 ┤■■■■■■■■■■■■■■ 4
21+
6.9 ┤■■■■■■■■■■■■■■ 4
22+
7.7 ┤■■■■■■■■■■■■■■ 4
23+
4.4 ┤■■■■■■■■■■■ 3
24+
5.9 ┤■■■■■■■■■■■ 3
25+
6.8 ┤■■■■■■■■■■■ 3
26+
7.2 ┤■■■■■■■■■■■ 3
27+
4.7 ┤■■■■■■■ 2
28+
6.6 ┤■■■■■■■ 2
29+
4.3 ┤■■■■ 1
30+
4.5 ┤■■■■ 1
31+
5.3 ┤■■■■ 1
32+
7.0 ┤■■■■ 1
33+
7.1 ┤■■■■ 1
34+
7.3 ┤■■■■ 1
35+
7.4 ┤■■■■ 1
36+
7.6 ┤■■■■ 1
37+
7.9 ┤■■■■ 1
3838
└ ┘

test/fixtures/simple-count.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
┌ ┐
2-
-50 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1.0
3-
-40 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1.0
4-
-30 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1.0
5-
-20 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1.0
6-
-10 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1.0
7-
10 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1.0
8-
20 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1.0
9-
30 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1.0
10-
40 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1.0
11-
50 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1.0
2+
-50 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1
3+
-40 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1
4+
-30 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1
5+
-20 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1
6+
-10 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1
7+
10 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1
8+
20 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1
9+
30 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1
10+
40 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1
11+
50 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1
1212
└ ┘

0 commit comments

Comments
 (0)