mirror of
https://github.com/red-data-tools/YouPlot.git
synced 2025-05-06 07:10:10 +08:00
Try to refactor
This commit is contained in:
parent
eadafa6307
commit
1dec36641b
@ -158,40 +158,34 @@ module Uplot
|
||||
UnicodePlot.lineplot(x, y, **@params.compact)
|
||||
end
|
||||
|
||||
def lines(data, headers)
|
||||
def x1_y1_y2_style(data, headers, call1, call2) # Fix method name
|
||||
data.map! { |series| series.map(&:to_f) }
|
||||
@params[:name] ||= headers[1] if headers
|
||||
@params[:xlabel] ||= headers[0] if headers
|
||||
@params[:ylim] ||= data[1..-1].flatten.minmax
|
||||
plot = UnicodePlot.lineplot(data[0], data[1], **@params.compact)
|
||||
plot = UnicodePlot.public_send(call1, data[0], data[1], **@params.compact)
|
||||
2.upto(data.size - 1) do |i|
|
||||
UnicodePlot.lineplot!(plot, data[0], data[i], name: headers[i])
|
||||
UnicodePlot.public_send(call2, plot, data[0], data[i], name: headers[i])
|
||||
end
|
||||
plot
|
||||
end
|
||||
|
||||
def lines(data, headers)
|
||||
if true # x1_y1_y2_style
|
||||
x1_y1_y2_style(data, headers, :lineplot, :lineplot!)
|
||||
end
|
||||
end
|
||||
|
||||
def scatter(data, headers)
|
||||
data.map! { |series| series.map(&:to_f) }
|
||||
@params[:name] ||= headers[1] if headers
|
||||
@params[:xlabel] ||= headers[0] if headers
|
||||
@params[:ylim] ||= data[1..-1].flatten.minmax
|
||||
plot = UnicodePlot.scatterplot(data[0], data[1], **@params.compact)
|
||||
2.upto(data.size - 1) do |i|
|
||||
UnicodePlot.scatterplot!(plot, data[0], data[i], name: headers[i])
|
||||
if true # x1_y1_y2_style
|
||||
x1_y1_y2_style(data, headers, :scatterplot, :scatterplot!)
|
||||
end
|
||||
plot
|
||||
end
|
||||
|
||||
def density(data, headers)
|
||||
data.map! { |series| series.map(&:to_f) }
|
||||
@params[:name] ||= headers[1] if headers
|
||||
@params[:xlabel] ||= headers[0] if headers
|
||||
@params[:ylim] ||= data[1..-1].flatten.minmax
|
||||
plot = UnicodePlot.densityplot(data[0], data[1], **@params.compact)
|
||||
2.upto(data.size - 1) do |i|
|
||||
UnicodePlot.densityplot!(plot, data[0], data[i], name: headers[i])
|
||||
if true # x1_y1_y2_style
|
||||
x1_y1_y2_style(data, headers, :densityplot, :densityplot!)
|
||||
end
|
||||
plot
|
||||
end
|
||||
|
||||
def boxplot(data, headers)
|
||||
|
Loading…
Reference in New Issue
Block a user