Skip to content

Commit 9caa88b

Browse files
committed
Aaccept non-Float64 arrays in y-only lineplot! and scatterplot!
1 parent d73446e commit 9caa88b

3 files changed

Lines changed: 20 additions & 6 deletions

File tree

spec/unicode_plot_spec.cr

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ describe UnicodePlot do
8181
p.series.should eq(prev_series + 1)
8282
end
8383

84+
it "accepts y-only numeric overload in lineplot!" do
85+
p = UnicodePlot.lineplot([1, 2, 3])
86+
prev_series = p.series
87+
UnicodePlot.lineplot!(p, [4, 5, 6])
88+
p.series.should eq(prev_series + 1)
89+
end
90+
8491
it "ignores extreme finite values without overflowing during rasterization" do
8592
p = UnicodePlot.lineplot([Float64::MAX, 0.5], [0.5, 0.5])
8693
p.to_s.should be_a(String)
@@ -126,6 +133,13 @@ describe UnicodePlot do
126133
UnicodePlot.scatterplot!(p, [1_i64, 2_i64, 3_i64], [2_i64, 3_i64, 4_i64])
127134
p.series.should eq(prev_series + 1)
128135
end
136+
137+
it "accepts y-only numeric overload in scatterplot!" do
138+
p = UnicodePlot.scatterplot([1, 2, 3])
139+
prev_series = p.series
140+
UnicodePlot.scatterplot!(p, [4, 5, 6])
141+
p.series.should eq(prev_series + 1)
142+
end
129143
end
130144

131145
describe "barplot" do

src/unicode_plot/interface/lineplot.cr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ module UnicodePlot
137137
lineplot!(plot, to_plot_f64(x), to_plot_f64(y), **kwargs)
138138
end
139139

140-
def lineplot!(plot : Plot, y : Array(Float64), **kwargs) : Plot
141-
x = (1..y.size).map(&.to_f)
142-
lineplot!(plot, x, y, **kwargs)
140+
def lineplot!(plot : Plot, y : Array(T), **kwargs) : Plot forall T
141+
x = (1..y.size).map(&.to_f64)
142+
lineplot!(plot, x, to_plot_f64(y), **kwargs)
143143
end
144144

145145
def lineplot!(plot : Plot, f : Float64 -> Float64, **kwargs) : Plot

src/unicode_plot/interface/scatterplot.cr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ module UnicodePlot
9898
scatterplot!(plot, to_plot_f64(x), to_plot_f64(y), **kwargs)
9999
end
100100

101-
def scatterplot!(plot : Plot, y : Array(Float64), **kwargs) : Plot
102-
x = (1..y.size).map(&.to_f)
103-
scatterplot!(plot, x, y, **kwargs)
101+
def scatterplot!(plot : Plot, y : Array(T), **kwargs) : Plot forall T
102+
x = (1..y.size).map(&.to_f64)
103+
scatterplot!(plot, x, to_plot_f64(y), **kwargs)
104104
end
105105
end

0 commit comments

Comments
 (0)