better handling of NANs
This commit is contained in:
parent
589ceb60a3
commit
4c18fad870
14
src/lib.rs
14
src/lib.rs
@ -123,6 +123,10 @@ impl ChartManager {
|
|||||||
let capped_data: Vec<(f32, f32)> = data
|
let capped_data: Vec<(f32, f32)> = data
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(x, y)| {
|
.map(|(x, y)| {
|
||||||
|
if y.is_nan() {
|
||||||
|
return (*x, 0.0);
|
||||||
|
}
|
||||||
|
|
||||||
let new_y: &f32 = if y > &self.max_y {
|
let new_y: &f32 = if y > &self.max_y {
|
||||||
&self.max_y
|
&self.max_y
|
||||||
} else if &self.min_y > y {
|
} else if &self.min_y > y {
|
||||||
@ -130,9 +134,11 @@ impl ChartManager {
|
|||||||
} else {
|
} else {
|
||||||
y
|
y
|
||||||
};
|
};
|
||||||
|
|
||||||
(*x, *new_y)
|
(*x, *new_y)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
log(&format!("{:?}", capped_data));
|
||||||
chart.draw_series(AreaSeries::new(capped_data, 0.0, &BLUE))?;
|
chart.draw_series(AreaSeries::new(capped_data, 0.0, &BLUE))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,13 +222,9 @@ impl ChartManager {
|
|||||||
false => tmp2,
|
false => tmp2,
|
||||||
};
|
};
|
||||||
|
|
||||||
if !y.is_nan() {
|
(x, x2, y)
|
||||||
(x, x2, y)
|
|
||||||
} else {
|
|
||||||
(f32::NAN, f32::NAN, f32::NAN)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.filter(|ele| ele != &(f32::NAN, f32::NAN, f32::NAN))
|
.filter(|(_, _, y)| !y.is_nan())
|
||||||
.collect();
|
.collect();
|
||||||
let area: f32 = data2.iter().map(|(_, _, y)| y * step).sum(); // sum of all rectangles' areas
|
let area: f32 = data2.iter().map(|(_, _, y)| y * step).sum(); // sum of all rectangles' areas
|
||||||
(data2, area)
|
(data2, area)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user