Skip to content

Commit

Permalink
Decimal precision independant of tick count
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Vetter authored and svetter committed Feb 18, 2024
1 parent 9d83be0 commit 6b0cf33
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/datastore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl DataStore {
}

fn format_tick(&self, increment: f64, value: f64) -> String {
let precision: usize = increment.log10().abs().ceil().max(1.0) as usize;
let precision: usize = (-increment.log10().floor()).max(0.0) as usize;
format!("{:.precision$}", value)
}

Expand Down
4 changes: 2 additions & 2 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ pub fn draw_ui<T: tui::backend::Backend>(
([min, max], num_ticks)
};

let increment = (y_axis_bounds[1] - y_axis_bounds[0]) / (y_axis_num_ticks - 1) as f64;
let precision: usize = increment.log10().abs().ceil().max(1.0) as usize + 1;
let range_hundredth = (y_axis_bounds[1] - y_axis_bounds[0]) / 100.0;
let precision: usize = (-range_hundredth.log10().floor()).max(0.0) as usize;

// Top level layout
let chunks: Vec<tui::layout::Rect> = Layout::default()
Expand Down

0 comments on commit 6b0cf33

Please sign in to comment.