mirror of
https://github.com/ratatui/ratatui.git
synced 2025-09-28 05:21:23 +00:00
fix(widgets/canvas): avoid panic on zero-width bounds
This commit is contained in:
parent
6204eddade
commit
fdbea9e2ee
@ -206,6 +206,9 @@ impl<'a, 'b> Painter<'a, 'b> {
|
||||
}
|
||||
let width = (self.context.x_bounds[1] - self.context.x_bounds[0]).abs();
|
||||
let height = (self.context.y_bounds[1] - self.context.y_bounds[0]).abs();
|
||||
if width == 0.0 || height == 0.0 {
|
||||
return None;
|
||||
}
|
||||
let x = ((x - left) * self.resolution.0 / width) as usize;
|
||||
let y = ((top - y) * self.resolution.1 / height) as usize;
|
||||
Some((x, y))
|
||||
|
@ -21,7 +21,7 @@ fn widgets_chart_can_have_axis_with_zero_length_bounds() {
|
||||
let chart = Chart::default()
|
||||
.block(Block::default().title("Plot").borders(Borders::ALL))
|
||||
.x_axis(Axis::default().bounds([0.0, 0.0]).labels(&["0.0", "1.0"]))
|
||||
.y_axis(Axis::default().bounds([0.0, 1.0]).labels(&["0.0", "1.0"]))
|
||||
.y_axis(Axis::default().bounds([0.0, 0.0]).labels(&["0.0", "1.0"]))
|
||||
.datasets(&datasets);
|
||||
f.render_widget(
|
||||
chart,
|
||||
|
Loading…
x
Reference in New Issue
Block a user