Clean up custom plot axis demo

This commit is contained in:
Emil Ernerfeldt 2022-04-19 11:43:22 +02:00
parent e82ea0c4b4
commit 4231a5303b

View file

@ -382,7 +382,7 @@ impl Widget for &mut CustomAxisDemo {
x.rem_euclid(MINS_PER_H).floor() x.rem_euclid(MINS_PER_H).floor()
} }
fn get_percent(y: f64) -> f64 { fn get_percent(y: f64) -> f64 {
(100.0 * y).round() 100.0 * y
} }
let x_fmt = |x, _range: &RangeInclusive<f64>| { let x_fmt = |x, _range: &RangeInclusive<f64>| {
@ -401,7 +401,7 @@ impl Widget for &mut CustomAxisDemo {
let y_fmt = |y, _range: &RangeInclusive<f64>| { let y_fmt = |y, _range: &RangeInclusive<f64>| {
// Display only integer percentages // Display only integer percentages
if !is_approx_zero(y) && is_approx_integer(100.0 * y) { if !is_approx_zero(y) && is_approx_integer(100.0 * y) {
format!("{}%", get_percent(y)) format!("{:.0}%", get_percent(y))
} else { } else {
String::new() String::new()
} }
@ -409,7 +409,7 @@ impl Widget for &mut CustomAxisDemo {
let label_fmt = |_s: &str, val: &Value| { let label_fmt = |_s: &str, val: &Value| {
format!( format!(
"Day {d}, {h}:{m:02}\n{p}%", "Day {d}, {h}:{m:02}\n{p:.2}%",
d = get_day(val.x), d = get_day(val.x),
h = get_hour(val.x), h = get_hour(val.x),
m = get_minute(val.x), m = get_minute(val.x),
@ -417,6 +417,8 @@ impl Widget for &mut CustomAxisDemo {
) )
}; };
ui.label("Zoom in on the X-axis to see hours and minutes");
Plot::new("custom_axes") Plot::new("custom_axes")
.data_aspect(2.0 * MINS_PER_DAY as f32) .data_aspect(2.0 * MINS_PER_DAY as f32)
.x_axis_formatter(x_fmt) .x_axis_formatter(x_fmt)