Skip to content

Commit 854690a

Browse files
committed
Stop silent fallback when unknown canvas / colormap
1 parent edd5ad4 commit 854690a

3 files changed

Lines changed: 15 additions & 6 deletions

File tree

spec/unicode_plot_spec.cr

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ describe UnicodePlot do
4949
end
5050
end
5151

52+
it "raises on unknown canvas" do
53+
expect_raises(ArgumentError, /unknown canvas: mystery/) do
54+
UnicodePlot.lineplot([1.0, 2.0], [1.0, 4.0], canvas: :mystery)
55+
end
56+
end
57+
5258
it "accepts RGB tuple color" do
5359
p = UnicodePlot.lineplot([1.0, 2.0], [1.0, 2.0], color: {0, 0, 255})
5460
p.to_s.should be_a(String)
@@ -375,6 +381,12 @@ describe UnicodePlot do
375381
p = UnicodePlot.heatmap([[1_i128, 2_i128], [3_i128, 4_i128]])
376382
p.to_s.should be_a(String)
377383
end
384+
385+
it "raises on unknown colormap" do
386+
expect_raises(ArgumentError, /unknown colormap: mystery/) do
387+
UnicodePlot.heatmap([[1.0, 2.0], [3.0, 4.0]], colormap: :mystery)
388+
end
389+
end
378390
end
379391

380392
describe "stairs" do

src/unicode_plot/graphics/heatmap_graphics.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ module UnicodePlot
3333
}
3434

3535
def colormap_callback(name : Symbol) : Proc(Float64, Float64, Float64, UInt32)
36-
stops = COLORMAP_STOPS[name]? || COLORMAP_STOPS[:viridis]
36+
stops = COLORMAP_STOPS[name]? || raise ArgumentError.new("unknown colormap: #{name}")
3737
->(z : Float64, zmin : Float64, zmax : Float64) {
3838
return INVALID_COLOR unless z.finite?
3939
t = zmax > zmin ? ((z - zmin) / (zmax - zmin)).clamp(0.0, 1.0) : 0.5

src/unicode_plot/plot.cr

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,8 @@ module UnicodePlot
267267
yflip: yflip, xflip: xflip,
268268
yscale: yscale.is_a?(Symbol) ? yscale.as(Symbol) : yscale.as(Proc(Float64, Float64)),
269269
xscale: xscale.is_a?(Symbol) ? xscale.as(Symbol) : xscale.as(Proc(Float64, Float64)))
270-
else BrailleCanvas.new(h, w,
271-
origin_y: my, origin_x: mx,
272-
height: by - my, width: bx - mx,
273-
blend: blend, visible: (w >= 0),
274-
yflip: yflip, xflip: xflip)
270+
else
271+
raise ArgumentError.new("unknown canvas: #{canvas_type}")
275272
end
276273

277274
plot = Plot.new(can,

0 commit comments

Comments
 (0)