mirror of
https://github.com/red-data-tools/YouPlot.git
synced 2025-07-22 23:41:12 +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
|
# value_counts Enumerable::Statistics
|
||||||
arr.value_counts(dropna: false)
|
arr.value_counts(dropna: false)
|
||||||
end
|
end
|
||||||
.sort { |a, b| a[1] <=> b[1] }
|
.sort do |a, b|
|
||||||
.reverse
|
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
|
.transpose
|
||||||
# faster than `.sort_by{|a| a[1]}`, `.sort_by(a:last)`
|
|
||||||
# `.sort{ |a, b| -a[1] <=> -b[1] }
|
|
||||||
end
|
end
|
||||||
end
|
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
|
-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