1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 21:30:03 -04:00

egui_plot: Improve default formatter of tick-marks (#4738)

The default `Plot` formatter now picks precision intelligently based on
zoom level. The width of the Y axis are is now much smaller by default,
and expands as needed.

Also deprecates `Plot::y_axis_with`; replaced with `y_axis_min_width`.
This commit is contained in:
Emil Ernerfeldt
2024-06-30 14:20:41 +02:00
committed by GitHub
parent 17fd305967
commit b6fd1cfc99
6 changed files with 121 additions and 67 deletions

View File

@@ -190,6 +190,9 @@ pub fn format_with_minimum_decimals(value: f64, decimals: usize) -> String {
format_with_decimals_in_range(value, decimals..=6)
}
/// Use as few decimals as possible to show the value accurately, but within the given range.
///
/// Decimals are counted after the decimal point.
pub fn format_with_decimals_in_range(value: f64, decimal_range: RangeInclusive<usize>) -> String {
let min_decimals = *decimal_range.start();
let max_decimals = *decimal_range.end();
@@ -198,7 +201,7 @@ pub fn format_with_decimals_in_range(value: f64, decimal_range: RangeInclusive<u
let max_decimals = max_decimals.min(16);
let min_decimals = min_decimals.min(max_decimals);
if min_decimals != max_decimals {
if min_decimals < max_decimals {
// Ugly/slow way of doing this. TODO(emilk): clean up precision.
for decimals in min_decimals..max_decimals {
let text = format!("{value:.decimals$}");