Skip to content

Commit 8defa96

Browse files
committed
Slightly improve stability by using smaller values
1 parent a73e21d commit 8defa96

File tree

2 files changed

+2
-35
lines changed

2 files changed

+2
-35
lines changed

src/canvas/components/time_graph.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ mod test {
230230
fn create_time_graph() -> TimeGraph<'static> {
231231
TimeGraph {
232232
title: " Network ".into(),
233-
x_min: -15000.0,
233+
x_min: -15.0,
234234
hide_x_labels: false,
235235
y_bounds: AxisBound::Max(100.5),
236236
y_labels: &Y_LABELS,
@@ -254,7 +254,7 @@ mod test {
254254
let x_axis = tg.generate_x_axis();
255255

256256
let actual = Axis::default()
257-
.bounds(AxisBound::Min(-15000.0))
257+
.bounds(AxisBound::Min(-15.0))
258258
.labels(vec![Span::styled("15s", style), Span::styled("0s", style)])
259259
.style(style);
260260
assert_eq!(x_axis.bounds, actual.bounds);

src/canvas/components/time_graph/time_chart/canvas.rs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -71,39 +71,6 @@ impl Shape for CanvasLine {
7171
} else {
7272
draw_line_high(painter, x1, y1, x2, y2, self.color);
7373
}
74-
75-
draw_line(painter, x1, y1, x2, y2, self.color);
76-
}
77-
}
78-
79-
/// Based on <https://github.com/gizak/termui/blob/master/drawille/drawille.go>
80-
fn draw_line(
81-
painter: &mut Painter<'_, '_>, x1: usize, y1: usize, x2: usize, y2: usize, colour: Color,
82-
) {
83-
let (left_point, right_point) = if x1 < x2 {
84-
((x1, y1), (x2, y2))
85-
} else {
86-
((x2, y2), (x1, y1))
87-
};
88-
89-
let dx = (left_point.0 as isize - right_point.0 as isize).abs();
90-
let dy = (left_point.1 as isize - right_point.1 as isize).abs();
91-
92-
let slope = dy as f64 / dx as f64;
93-
let slope_sign: isize = if left_point.1 < right_point.1 { 1 } else { -1 };
94-
95-
let mut target_y = left_point.1 as f64;
96-
let mut current_y = left_point.1 as isize;
97-
98-
for current_x in (left_point.0)..(right_point.0) {
99-
painter.paint(current_x, current_y as usize, colour);
100-
101-
target_y += slope * slope_sign as f64;
102-
103-
while current_y != target_y as isize && current_y >= 0 {
104-
painter.paint(current_x, current_y as usize, colour);
105-
current_y += slope_sign;
106-
}
10774
}
10875
}
10976

0 commit comments

Comments
 (0)