fixup! plot: Fix the point scale cannot selecting the last point (#1143)
This commit is contained in:
parent
4c545165eb
commit
566f5b0d4d
1 changed files with 10 additions and 5 deletions
|
|
@ -9,6 +9,7 @@ use super::Scale;
|
|||
pub struct ScalePoint<T> {
|
||||
domain: Vec<T>,
|
||||
range_tick: f32,
|
||||
least_index_range_tick: f32,
|
||||
}
|
||||
|
||||
impl<T> ScalePoint<T>
|
||||
|
|
@ -17,8 +18,8 @@ where
|
|||
{
|
||||
pub fn new(domain: Vec<T>, range: Vec<f32>) -> Self {
|
||||
let len = domain.len();
|
||||
let range_tick = if len.is_zero() {
|
||||
0.
|
||||
let (range_tick, least_index_range_tick) = if len.is_zero() {
|
||||
(0., 0.)
|
||||
} else {
|
||||
let range_diff = range
|
||||
.iter()
|
||||
|
|
@ -26,10 +27,14 @@ where
|
|||
.into_option()
|
||||
.map_or(0., |(min, max)| max - min);
|
||||
|
||||
range_diff / (len as f32)
|
||||
(range_diff / (len - 1) as f32, range_diff / len as f32)
|
||||
};
|
||||
|
||||
Self { domain, range_tick }
|
||||
Self {
|
||||
domain,
|
||||
range_tick,
|
||||
least_index_range_tick,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -47,7 +52,7 @@ where
|
|||
return 0;
|
||||
}
|
||||
|
||||
let index = (tick / self.range_tick).round() as usize;
|
||||
let index = (tick / self.least_index_range_tick).round() as usize;
|
||||
index.min(self.domain.len().saturating_sub(1))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue