plot(shape): Add multi-label support for Bar (#1262)
## Breaking Change
```diff
- bar.label(move |_, point| Text::new("foo", point, "#red"));
+ bar.label(move |_, point| vec![Text::new("foo", point, "#red")]);
```
Add support for multiple labels on a single bar.
This commit is contained in:
parent
5e7a2cb37f
commit
c385da56c1
2 changed files with 4 additions and 5 deletions
|
|
@ -154,8 +154,7 @@ where
|
||||||
|
|
||||||
if let Some(label) = self.label.as_ref() {
|
if let Some(label) = self.label.as_ref() {
|
||||||
let label = label.clone();
|
let label = label.clone();
|
||||||
bar =
|
bar = bar.label(move |d, p| vec![Text::new(label(d), p, label_color)]);
|
||||||
bar.label(move |d, p| Text::new(label(d), p, label_color).align(TextAlign::Center));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bar.paint(&bounds, window, cx);
|
bar.paint(&bounds, window, cx);
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ pub struct Bar<T> {
|
||||||
y0: f32,
|
y0: f32,
|
||||||
y1: Box<dyn Fn(&T) -> Option<f32>>,
|
y1: Box<dyn Fn(&T) -> Option<f32>>,
|
||||||
fill: Box<dyn Fn(&T) -> Hsla>,
|
fill: Box<dyn Fn(&T) -> Hsla>,
|
||||||
label: Option<Box<dyn Fn(&T, Point<Pixels>) -> Text>>,
|
label: Option<Box<dyn Fn(&T, Point<Pixels>) -> Vec<Text>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Default for Bar<T> {
|
impl<T> Default for Bar<T> {
|
||||||
|
|
@ -87,7 +87,7 @@ impl<T> Bar<T> {
|
||||||
/// Set the label of the Bar.
|
/// Set the label of the Bar.
|
||||||
pub fn label<F>(mut self, label: F) -> Self
|
pub fn label<F>(mut self, label: F) -> Self
|
||||||
where
|
where
|
||||||
F: Fn(&T, Point<Pixels>) -> Text + 'static,
|
F: Fn(&T, Point<Pixels>) -> Vec<Text> + 'static,
|
||||||
{
|
{
|
||||||
self.label = Some(Box::new(label));
|
self.label = Some(Box::new(label));
|
||||||
self
|
self
|
||||||
|
|
@ -121,7 +121,7 @@ impl<T> Bar<T> {
|
||||||
graph.push(fill(Bounds::from_corners(p1, p2), color));
|
graph.push(fill(Bounds::from_corners(p1, p2), color));
|
||||||
|
|
||||||
if let Some(label) = &self.label {
|
if let Some(label) = &self.label {
|
||||||
labels.push(label(
|
labels.extend(label(
|
||||||
v,
|
v,
|
||||||
point(
|
point(
|
||||||
px(x_tick + self.band_width / 2.),
|
px(x_tick + self.band_width / 2.),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue