2021-05-28 08:36:08 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module YouPlot
|
|
|
|
# plotting functions.
|
|
|
|
module Backends
|
|
|
|
module Processing
|
|
|
|
module_function
|
|
|
|
|
|
|
|
def count_values(arr, tally: true)
|
|
|
|
# tally was added in Ruby 2.7
|
|
|
|
if tally && Enumerable.method_defined?(:tally)
|
|
|
|
arr.tally
|
|
|
|
else
|
2021-05-28 09:24:45 +08:00
|
|
|
# value_counts Enumerable::Statistics
|
|
|
|
arr.value_counts(dropna: false)
|
2021-05-28 08:36:08 +08:00
|
|
|
end
|
2021-05-28 09:24:45 +08:00
|
|
|
# faster than `.sort_by{|a| a[1]}`, `.sort_by(a:last)`
|
|
|
|
# `.sort{ |a, b| -a[1] <=> -b[1] }
|
2021-05-28 08:36:08 +08:00
|
|
|
.sort { |a, b| a[1] <=> b[1] }
|
|
|
|
.reverse
|
|
|
|
.transpose
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|