plot: Tooltip support multiple dots (#1030)

This commit is contained in:
Floyd Wang 2025-07-03 11:28:48 +08:00 committed by GitHub
parent b80d3a95b1
commit 32d0beff22
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -125,7 +125,7 @@ pub enum TooltipPosition {
pub struct TooltipState { pub struct TooltipState {
pub index: usize, pub index: usize,
pub cross_line: Point<Pixels>, pub cross_line: Point<Pixels>,
pub dot: Point<Pixels>, pub dots: Vec<Point<Pixels>>,
pub position: TooltipPosition, pub position: TooltipPosition,
} }
@ -133,13 +133,13 @@ impl TooltipState {
pub fn new( pub fn new(
index: usize, index: usize,
cross_line: Point<Pixels>, cross_line: Point<Pixels>,
dot: Point<Pixels>, dots: Vec<Point<Pixels>>,
position: TooltipPosition, position: TooltipPosition,
) -> Self { ) -> Self {
Self { Self {
index, index,
cross_line, cross_line,
dot, dots,
position, position,
} }
} }
@ -151,7 +151,7 @@ pub struct Tooltip {
position: Option<TooltipPosition>, position: Option<TooltipPosition>,
gap: Pixels, gap: Pixels,
cross_line: Option<CrossLine>, cross_line: Option<CrossLine>,
dot: Option<Dot>, dots: Option<Vec<Dot>>,
} }
impl Tooltip { impl Tooltip {
@ -162,7 +162,7 @@ impl Tooltip {
position: Default::default(), position: Default::default(),
gap: px(0.), gap: px(0.),
cross_line: None, cross_line: None,
dot: None, dots: None,
} }
} }
@ -181,8 +181,8 @@ impl Tooltip {
self self
} }
pub fn dot(mut self, dot: Dot) -> Self { pub fn dots(mut self, dots: impl IntoIterator<Item = Dot>) -> Self {
self.dot = Some(dot); self.dots = Some(dots.into_iter().collect());
self self
} }
} }
@ -224,6 +224,6 @@ impl RenderOnce for Tooltip {
} }
}), }),
) )
.when_some(self.dot, |this, dot| this.child(dot)) .when_some(self.dots, |this, dots| this.children(dots))
} }
} }