Skip to content

Commit 546aa8d

Browse files
committed
Add generic y-only overload for stairs!
1 parent 998615a commit 546aa8d

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

spec/unicode_plot_spec.cr

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,13 @@ describe UnicodePlot do
390390
p.to_s.should be_a(String)
391391
end
392392

393+
it "accepts y-only numeric overload in stairs!" do
394+
p = UnicodePlot.stairs([1, 2, 3], [4, 5, 6])
395+
prev_series = p.series
396+
UnicodePlot.stairs!(p, [7, 8, 9])
397+
p.series.should eq(prev_series + 1)
398+
end
399+
393400
it "accepts UInt128 arrays via generic numeric overload" do
394401
p = UnicodePlot.stairs([1_u128, 2_u128, 3_u128], [4_u128, 5_u128, 6_u128])
395402
p.to_s.should be_a(String)

src/unicode_plot/interface/stairs.cr

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,14 @@ module UnicodePlot
105105
def stairs!(plot : Plot, x : Array(T), y : Array(U), **kwargs) : Plot forall T, U
106106
stairs!(plot, to_plot_f64(x), to_plot_f64(y), **kwargs)
107107
end
108+
109+
def stairs!(plot : Plot, y : Array(Float64), **kwargs) : Plot
110+
x = (1..y.size).map(&.to_f64)
111+
stairs!(plot, x, y, **kwargs)
112+
end
113+
114+
def stairs!(plot : Plot, y : Array(T), **kwargs) : Plot forall T
115+
x = (1..y.size).map(&.to_f64)
116+
stairs!(plot, x, to_plot_f64(y), **kwargs)
117+
end
108118
end

0 commit comments

Comments
 (0)