mirror of
https://github.com/red-data-tools/YouPlot.git
synced 2025-07-20 22:31:11 +08:00
count: if the values are the same, sort by name
This commit is contained in:
parent
f57090cc9b
commit
977d3beb2d
@ -14,11 +14,12 @@ module YouPlot
|
||||
# value_counts Enumerable::Statistics
|
||||
arr.value_counts(dropna: false)
|
||||
end
|
||||
.sort { |a, b| a[1] <=> b[1] }
|
||||
.reverse
|
||||
.sort do |a, b|
|
||||
r = b[1] <=> a[1] # compare values
|
||||
r = a[0] <=> b[0] if r == 0 # If the values are the same, compare by name
|
||||
r
|
||||
end
|
||||
.transpose
|
||||
# faster than `.sort_by{|a| a[1]}`, `.sort_by(a:last)`
|
||||
# `.sort{ |a, b| -a[1] <=> -b[1] }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
18
test/fixtures/simple-count.txt
vendored
18
test/fixtures/simple-count.txt
vendored
@ -1,12 +1,12 @@
|
||||
┌ ┐
|
||||
50 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1.0
|
||||
-50 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1.0
|
||||
40 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1.0
|
||||
-40 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1.0
|
||||
30 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1.0
|
||||
-30 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1.0
|
||||
20 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1.0
|
||||
-20 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1.0
|
||||
10 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1.0
|
||||
-10 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1.0
|
||||
-20 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1.0
|
||||
-30 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1.0
|
||||
-40 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1.0
|
||||
-50 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1.0
|
||||
10 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1.0
|
||||
20 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1.0
|
||||
30 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1.0
|
||||
40 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1.0
|
||||
50 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1.0
|
||||
└ ┘
|
||||
|
Loading…
Reference in New Issue
Block a user