mirror of
https://github.com/red-data-tools/YouPlot.git
synced 2025-05-06 15:11:12 +08:00
Add preprocess_count
This commit is contained in:
parent
76f88eb55a
commit
6a00314fc4
@ -120,8 +120,12 @@ module Uplot
|
|||||||
[data, headers]
|
[data, headers]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def preprocess_count(data)
|
||||||
|
data[0].tally.sort { |a, b| a[1] <=> b[1] }.reverse.transpose
|
||||||
|
end
|
||||||
|
|
||||||
def barplot(data, headers)
|
def barplot(data, headers)
|
||||||
data = data[0].tally.sort { |a, b| a[1] <=> b[1] }.reverse.transpose if @count
|
data = preprocess_count(data) if @count
|
||||||
@params[:title] ||= headers[1] if headers
|
@params[:title] ||= headers[1] if headers
|
||||||
UnicodePlot.barplot(data[0], data[1].map(&:to_f), **@params)
|
UnicodePlot.barplot(data[0], data[1].map(&:to_f), **@params)
|
||||||
end
|
end
|
||||||
@ -159,7 +163,6 @@ module Uplot
|
|||||||
@params[:ylim] ||= data[1..-1].flatten.minmax
|
@params[:ylim] ||= data[1..-1].flatten.minmax
|
||||||
plot = UnicodePlot.lineplot(data[0], data[1], **@params.compact)
|
plot = UnicodePlot.lineplot(data[0], data[1], **@params.compact)
|
||||||
2.upto(data.size - 1) do |i|
|
2.upto(data.size - 1) do |i|
|
||||||
p data[i]
|
|
||||||
UnicodePlot.lineplot!(plot, data[0], data[i], name: headers[i])
|
UnicodePlot.lineplot!(plot, data[0], data[i], name: headers[i])
|
||||||
end
|
end
|
||||||
plot
|
plot
|
||||||
|
Loading…
Reference in New Issue
Block a user