mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-07-23 13:45:12 +02:00
try alternate line algorithm
This commit is contained in:
parent
6510b36328
commit
a73e21d617
@ -104,7 +104,7 @@ impl TimeGraph<'_> {
|
||||
if self.hide_x_labels {
|
||||
Axis::default().bounds(adjusted_x_bounds)
|
||||
} else {
|
||||
let x_bound_left = ((-self.x_min) as u64 / 1000).to_string();
|
||||
let x_bound_left = ((-self.x_min) as u64).to_string();
|
||||
let x_bound_right = "0s";
|
||||
|
||||
let x_labels = vec![
|
||||
|
@ -33,14 +33,14 @@ pub trait Shape {
|
||||
|
||||
impl Shape for CanvasLine {
|
||||
fn draw(&self, painter: &mut Painter<'_, '_>) {
|
||||
let (x1, y1) = match painter.get_point(self.x1, self.y1) {
|
||||
Some(c) => c,
|
||||
None => return,
|
||||
let Some((x1, y1)) = painter.get_point(self.x1, self.y1) else {
|
||||
return;
|
||||
};
|
||||
let (x2, y2) = match painter.get_point(self.x2, self.y2) {
|
||||
Some(c) => c,
|
||||
None => return,
|
||||
|
||||
let Some((x2, y2)) = painter.get_point(self.x2, self.y2) else {
|
||||
return;
|
||||
};
|
||||
|
||||
let (dx, x_range) = if x2 >= x1 {
|
||||
(x2 - x1, x1..=x2)
|
||||
} else {
|
||||
@ -71,6 +71,39 @@ impl Shape for CanvasLine {
|
||||
} else {
|
||||
draw_line_high(painter, x1, y1, x2, y2, self.color);
|
||||
}
|
||||
|
||||
draw_line(painter, x1, y1, x2, y2, self.color);
|
||||
}
|
||||
}
|
||||
|
||||
/// Based on <https://github.com/gizak/termui/blob/master/drawille/drawille.go>
|
||||
fn draw_line(
|
||||
painter: &mut Painter<'_, '_>, x1: usize, y1: usize, x2: usize, y2: usize, colour: Color,
|
||||
) {
|
||||
let (left_point, right_point) = if x1 < x2 {
|
||||
((x1, y1), (x2, y2))
|
||||
} else {
|
||||
((x2, y2), (x1, y1))
|
||||
};
|
||||
|
||||
let dx = (left_point.0 as isize - right_point.0 as isize).abs();
|
||||
let dy = (left_point.1 as isize - right_point.1 as isize).abs();
|
||||
|
||||
let slope = dy as f64 / dx as f64;
|
||||
let slope_sign: isize = if left_point.1 < right_point.1 { 1 } else { -1 };
|
||||
|
||||
let mut target_y = left_point.1 as f64;
|
||||
let mut current_y = left_point.1 as isize;
|
||||
|
||||
for current_x in (left_point.0)..(right_point.0) {
|
||||
painter.paint(current_x, current_y as usize, colour);
|
||||
|
||||
target_y += slope * slope_sign as f64;
|
||||
|
||||
while current_y != target_y as isize && current_y >= 0 {
|
||||
painter.paint(current_x, current_y as usize, colour);
|
||||
current_y += slope_sign;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ impl TimeChart<'_> {
|
||||
.iter_along_base(times)
|
||||
.rev()
|
||||
.map(|(&time, &val)| {
|
||||
let from_start = current_time.duration_since(time).as_millis() as f64 * -1.0;
|
||||
let from_start = current_time.duration_since(time).as_secs_f64() * -1.0;
|
||||
|
||||
// XXX: Should this be generic over dataset.graph_type instead? That would allow us to move
|
||||
// transformations behind a type - however, that also means that there's some complexity added.
|
||||
|
@ -180,7 +180,7 @@ impl Painter {
|
||||
let data = app_state.data_store.get_data();
|
||||
|
||||
let border_style = self.get_border_style(widget_id, app_state.current_widget.widget_id);
|
||||
let x_min = -(cpu_widget_state.current_display_time as f64);
|
||||
let x_min = -(cpu_widget_state.current_display_time as f64) / 1000.0;
|
||||
let hide_x_labels = should_hide_x_label(
|
||||
app_state.app_config_fields.hide_time,
|
||||
app_state.app_config_fields.autohide_time,
|
||||
|
@ -62,7 +62,7 @@ impl Painter {
|
||||
|
||||
if let Some(mem_state) = app_state.states.mem_state.widget_states.get_mut(&widget_id) {
|
||||
let border_style = self.get_border_style(widget_id, app_state.current_widget.widget_id);
|
||||
let x_min = -(mem_state.current_display_time as f64);
|
||||
let x_min = -(mem_state.current_display_time as f64) / 1000.0;
|
||||
let hide_x_labels = should_hide_x_label(
|
||||
app_state.app_config_fields.hide_time,
|
||||
app_state.app_config_fields.autohide_time,
|
||||
|
@ -67,7 +67,7 @@ impl Painter {
|
||||
let rx_points = &(shared_data.timeseries_data.rx);
|
||||
let tx_points = &(shared_data.timeseries_data.tx);
|
||||
let time = &(shared_data.timeseries_data.time);
|
||||
let time_start = -(network_widget_state.current_display_time as f64);
|
||||
let time_start = -(network_widget_state.current_display_time as f64) / 1000.0;
|
||||
|
||||
let border_style = self.get_border_style(widget_id, app_state.current_widget.widget_id);
|
||||
let hide_x_labels = should_hide_x_label(
|
||||
|
Loading…
x
Reference in New Issue
Block a user