YouPlot/lib/youplot/backends/processing.rb

29 lines
663 B
Ruby
Raw Normal View History

# 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
# value_counts Enumerable::Statistics
arr.value_counts(dropna: false)
end
.sort do |a, b|
2021-05-29 08:45:29 +08:00
# compare values
r = b[1] <=> a[1]
# If the values are the same, compare by name
2021-06-03 09:48:47 +08:00
r = a[0] <=> b[0] if r.zero?
r
end
.transpose
end
end
end
end