Coverage Report

Created: 2026-02-14 06:16

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/plotters-0.3.7/src/chart/series.rs
Line
Count
Source
1
use super::ChartContext;
2
use crate::coord::CoordTranslate;
3
use crate::drawing::DrawingAreaErrorKind;
4
use crate::element::{DynElement, EmptyElement, IntoDynElement, MultiLineText, Rectangle};
5
use crate::style::{IntoFont, IntoTextStyle, ShapeStyle, SizeDesc, TextStyle, TRANSPARENT};
6
7
use plotters_backend::{BackendCoord, DrawingBackend, DrawingErrorKind};
8
9
type SeriesAnnoDrawFn<'a, DB> = dyn Fn(BackendCoord) -> DynElement<'a, DB, BackendCoord> + 'a;
10
11
/// The annotations (such as the label of the series, the legend element, etc)
12
/// When a series is drawn onto a drawing area, an series annotation object
13
/// is created and a mutable reference is returned.
14
pub struct SeriesAnno<'a, DB: DrawingBackend> {
15
    label: Option<String>,
16
    draw_func: Option<Box<SeriesAnnoDrawFn<'a, DB>>>,
17
}
18
19
impl<'a, DB: DrawingBackend> SeriesAnno<'a, DB> {
20
    #[allow(clippy::option_as_ref_deref)]
21
0
    pub(crate) fn get_label(&self) -> &str {
22
        // TODO: Change this when we bump the MSRV
23
0
        self.label.as_ref().map(|x| x.as_str()).unwrap_or("")
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::get_label::{closure#0}
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<_>>::get_label::{closure#0}
24
0
    }
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::get_label
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<_>>::get_label
25
26
0
    pub(crate) fn get_draw_func(&self) -> Option<&SeriesAnnoDrawFn<'a, DB>> {
27
0
        self.draw_func.as_ref().map(|x| x.as_ref())
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::get_draw_func::{closure#0}
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<_>>::get_draw_func::{closure#0}
28
0
    }
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::get_draw_func
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<_>>::get_draw_func
29
30
0
    pub(crate) fn new() -> Self {
31
0
        Self {
32
0
            label: None,
33
0
            draw_func: None,
34
0
        }
35
0
    }
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::new
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<_>>::new
36
37
    /**
38
    Sets the series label for the current series.
39
40
    See [`ChartContext::configure_series_labels()`] for more information and examples.
41
    */
42
0
    pub fn label<L: Into<String>>(&mut self, label: L) -> &mut Self {
43
0
        self.label = Some(label.into());
44
0
        self
45
0
    }
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::label::<&alloc::string::String>
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::label::<&str>
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<_>>::label::<_>
46
47
    /**
48
    Sets the legend element creator function.
49
50
    - `func`: The function use to create the element
51
52
    # Note
53
54
    The creation function uses a shifted pixel-based coordinate system, where the
55
    point (0,0) is defined to the mid-right point of the shape.
56
57
    # See also
58
59
    See [`ChartContext::configure_series_labels()`] for more information and examples.
60
    */
61
0
    pub fn legend<E: IntoDynElement<'a, DB, BackendCoord>, T: Fn(BackendCoord) -> E + 'a>(
62
0
        &mut self,
63
0
        func: T,
64
0
    ) -> &mut Self {
65
0
        self.draw_func = Some(Box::new(move |p| func(p).into_dyn()));
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::PathElement<(i32, i32)>, criterion::plot::plotters_backend::regression::regression_figure::{closure#3}>::{closure#0}
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::PathElement<(i32, i32)>, criterion::plot::plotters_backend::regression::regression_comparison_figure::{closure#2}>::{closure#0}
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::PathElement<(i32, i32)>, criterion::plot::plotters_backend::regression::regression_comparison_figure::{closure#1}>::{closure#0}
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::PathElement<(i32, i32)>, criterion::plot::plotters_backend::distributions::abs_distribution::{closure#6}>::{closure#0}
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::PathElement<(i32, i32)>, criterion::plot::plotters_backend::distributions::abs_distribution::{closure#9}>::{closure#0}
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::PathElement<(i32, i32)>, criterion::plot::plotters_backend::distributions::rel_distribution::{closure#6}>::{closure#0}
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::PathElement<(i32, i32)>, criterion::plot::plotters_backend::distributions::rel_distribution::{closure#9}>::{closure#0}
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::PathElement<(i32, i32)>, criterion::plot::plotters_backend::pdf::pdf_comparison_figure::{closure#6}>::{closure#0}
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::PathElement<(i32, i32)>, criterion::plot::plotters_backend::pdf::pdf_comparison_figure::{closure#7}>::{closure#0}
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::PathElement<(i32, i32)>, criterion::plot::plotters_backend::pdf::pdf::{closure#7}>::{closure#0}
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::PathElement<(i32, i32)>, criterion::plot::plotters_backend::t_test::t_test::{closure#2}>::{closure#0}
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::Circle<(i32, i32), u32>, criterion::plot::plotters_backend::pdf::pdf::{closure#8}::{closure#1}>::{closure#0}
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::Circle<(i32, i32), u32>, criterion::plot::plotters_backend::regression::regression_figure::{closure#2}>::{closure#0}
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::Circle<(i32, i32), u32>, criterion::plot::plotters_backend::iteration_times::iteration_times_figure::{closure#3}>::{closure#0}
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::Circle<(i32, i32), u32>, criterion::plot::plotters_backend::iteration_times::iteration_times_comparison_figure::{closure#3}>::{closure#0}
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::Circle<(i32, i32), u32>, criterion::plot::plotters_backend::iteration_times::iteration_times_comparison_figure::{closure#5}>::{closure#0}
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::Rectangle<(i32, i32)>, criterion::plot::plotters_backend::summary::draw_line_comarision_figure<core::ops::range::Range<f64>, core::ops::range::Range<f64>>::{closure#0}>::{closure#0}
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::Rectangle<(i32, i32)>, criterion::plot::plotters_backend::summary::draw_line_comarision_figure<plotters::coord::ranged1d::combinators::logarithmic::LogRangeExt<f64>, plotters::coord::ranged1d::combinators::logarithmic::LogRangeExt<f64>>::{closure#0}>::{closure#0}
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::Rectangle<(i32, i32)>, criterion::plot::plotters_backend::regression::regression_figure::{closure#4}>::{closure#0}
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::Rectangle<(i32, i32)>, criterion::plot::plotters_backend::distributions::abs_distribution::{closure#8}>::{closure#0}
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::Rectangle<(i32, i32)>, criterion::plot::plotters_backend::distributions::rel_distribution::{closure#8}>::{closure#0}
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::Rectangle<(i32, i32)>, criterion::plot::plotters_backend::distributions::rel_distribution::{closure#10}>::{closure#0}
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::Rectangle<(i32, i32)>, criterion::plot::plotters_backend::pdf::pdf_comparison_figure::{closure#3}>::{closure#0}
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::Rectangle<(i32, i32)>, criterion::plot::plotters_backend::pdf::pdf_comparison_figure::{closure#5}>::{closure#0}
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::Rectangle<(i32, i32)>, criterion::plot::plotters_backend::pdf::pdf::{closure#6}>::{closure#0}
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::Rectangle<(i32, i32)>, criterion::plot::plotters_backend::t_test::t_test::{closure#1}>::{closure#0}
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<_>>::legend::<_, _>::{closure#0}
66
0
        self
67
0
    }
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::PathElement<(i32, i32)>, criterion::plot::plotters_backend::regression::regression_figure::{closure#3}>
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::PathElement<(i32, i32)>, criterion::plot::plotters_backend::regression::regression_comparison_figure::{closure#2}>
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::PathElement<(i32, i32)>, criterion::plot::plotters_backend::regression::regression_comparison_figure::{closure#1}>
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::PathElement<(i32, i32)>, criterion::plot::plotters_backend::distributions::abs_distribution::{closure#6}>
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::PathElement<(i32, i32)>, criterion::plot::plotters_backend::distributions::abs_distribution::{closure#9}>
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::PathElement<(i32, i32)>, criterion::plot::plotters_backend::distributions::rel_distribution::{closure#6}>
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::PathElement<(i32, i32)>, criterion::plot::plotters_backend::distributions::rel_distribution::{closure#9}>
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::PathElement<(i32, i32)>, criterion::plot::plotters_backend::pdf::pdf_comparison_figure::{closure#6}>
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::PathElement<(i32, i32)>, criterion::plot::plotters_backend::pdf::pdf_comparison_figure::{closure#7}>
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::PathElement<(i32, i32)>, criterion::plot::plotters_backend::pdf::pdf::{closure#7}>
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::PathElement<(i32, i32)>, criterion::plot::plotters_backend::t_test::t_test::{closure#2}>
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::Circle<(i32, i32), u32>, criterion::plot::plotters_backend::pdf::pdf::{closure#8}::{closure#1}>
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::Circle<(i32, i32), u32>, criterion::plot::plotters_backend::regression::regression_figure::{closure#2}>
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::Circle<(i32, i32), u32>, criterion::plot::plotters_backend::iteration_times::iteration_times_figure::{closure#3}>
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::Circle<(i32, i32), u32>, criterion::plot::plotters_backend::iteration_times::iteration_times_comparison_figure::{closure#3}>
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::Circle<(i32, i32), u32>, criterion::plot::plotters_backend::iteration_times::iteration_times_comparison_figure::{closure#5}>
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::Rectangle<(i32, i32)>, criterion::plot::plotters_backend::summary::draw_line_comarision_figure<core::ops::range::Range<f64>, core::ops::range::Range<f64>>::{closure#0}>
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::Rectangle<(i32, i32)>, criterion::plot::plotters_backend::summary::draw_line_comarision_figure<plotters::coord::ranged1d::combinators::logarithmic::LogRangeExt<f64>, plotters::coord::ranged1d::combinators::logarithmic::LogRangeExt<f64>>::{closure#0}>
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::Rectangle<(i32, i32)>, criterion::plot::plotters_backend::regression::regression_figure::{closure#4}>
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::Rectangle<(i32, i32)>, criterion::plot::plotters_backend::distributions::abs_distribution::{closure#8}>
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::Rectangle<(i32, i32)>, criterion::plot::plotters_backend::distributions::rel_distribution::{closure#8}>
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::Rectangle<(i32, i32)>, criterion::plot::plotters_backend::distributions::rel_distribution::{closure#10}>
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::Rectangle<(i32, i32)>, criterion::plot::plotters_backend::pdf::pdf_comparison_figure::{closure#3}>
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::Rectangle<(i32, i32)>, criterion::plot::plotters_backend::pdf::pdf_comparison_figure::{closure#5}>
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::Rectangle<(i32, i32)>, criterion::plot::plotters_backend::pdf::pdf::{closure#6}>
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<plotters_svg::svg::SVGBackend>>::legend::<plotters::element::basic_shapes::Rectangle<(i32, i32)>, criterion::plot::plotters_backend::t_test::t_test::{closure#1}>
Unexecuted instantiation: <plotters::chart::series::SeriesAnno<_>>::legend::<_, _>
68
}
69
70
/**
71
Useful to specify the position of the series label.
72
73
See [`ChartContext::configure_series_labels()`] for more information and examples.
74
*/
75
#[derive(Debug, Clone, PartialEq)]
76
pub enum SeriesLabelPosition {
77
    /// Places the series label at the upper left
78
    UpperLeft,
79
    /// Places the series label at the middle left
80
    MiddleLeft,
81
    /// Places the series label at the lower left
82
    LowerLeft,
83
    /// Places the series label at the upper middle
84
    UpperMiddle,
85
    /// Places the series label at the middle middle
86
    MiddleMiddle,
87
    /// Places the series label at the lower middle
88
    LowerMiddle,
89
    /// Places the series label at the upper right
90
    UpperRight,
91
    /// Places the series label at the middle right
92
    MiddleRight,
93
    /// Places the series label at the lower right
94
    LowerRight,
95
    /// Places the series label at the specific location in backend coordinates
96
    Coordinate(i32, i32),
97
}
98
99
impl SeriesLabelPosition {
100
0
    fn layout_label_area(&self, label_dim: (i32, i32), area_dim: (u32, u32)) -> (i32, i32) {
101
        use SeriesLabelPosition::*;
102
        (
103
0
            match self {
104
0
                UpperLeft | MiddleLeft | LowerLeft => 5,
105
0
                UpperMiddle | MiddleMiddle | LowerMiddle => (area_dim.0 as i32 - label_dim.0) / 2,
106
0
                UpperRight | MiddleRight | LowerRight => area_dim.0 as i32 - label_dim.0 - 5,
107
0
                Coordinate(x, _) => *x,
108
            },
109
0
            match self {
110
0
                UpperLeft | UpperMiddle | UpperRight => 5,
111
0
                MiddleLeft | MiddleMiddle | MiddleRight => (area_dim.1 as i32 - label_dim.1) / 2,
112
0
                LowerLeft | LowerMiddle | LowerRight => area_dim.1 as i32 - label_dim.1 - 5,
113
0
                Coordinate(_, y) => *y,
114
            },
115
        )
116
0
    }
117
}
118
119
/// The struct to specify the series label of a target chart context
120
pub struct SeriesLabelStyle<'a, 'b, DB: DrawingBackend, CT: CoordTranslate> {
121
    target: &'b mut ChartContext<'a, DB, CT>,
122
    position: SeriesLabelPosition,
123
    legend_area_size: u32,
124
    border_style: ShapeStyle,
125
    background: ShapeStyle,
126
    label_font: Option<TextStyle<'b>>,
127
    margin: u32,
128
}
129
130
impl<'a, 'b, DB: DrawingBackend + 'a, CT: CoordTranslate> SeriesLabelStyle<'a, 'b, DB, CT> {
131
0
    pub(super) fn new(target: &'b mut ChartContext<'a, DB, CT>) -> Self {
132
0
        Self {
133
0
            target,
134
0
            position: SeriesLabelPosition::MiddleRight,
135
0
            legend_area_size: 30,
136
0
            border_style: (&TRANSPARENT).into(),
137
0
            background: (&TRANSPARENT).into(),
138
0
            label_font: None,
139
0
            margin: 10,
140
0
        }
141
0
    }
Unexecuted instantiation: <plotters::chart::series::SeriesLabelStyle<plotters_svg::svg::SVGBackend, plotters::coord::ranged2d::cartesian::Cartesian2d<plotters::coord::ranged1d::combinators::logarithmic::LogCoord<f64>, plotters::coord::ranged1d::combinators::logarithmic::LogCoord<f64>>>>::new
Unexecuted instantiation: <plotters::chart::series::SeriesLabelStyle<plotters_svg::svg::SVGBackend, plotters::coord::ranged2d::cartesian::Cartesian2d<plotters::coord::ranged1d::types::numeric::RangedCoordf64, plotters::coord::ranged1d::types::numeric::RangedCoordf64>>>::new
Unexecuted instantiation: <plotters::chart::series::SeriesLabelStyle<_, _>>::new
142
143
    /**
144
    Sets the series label positioning style
145
146
    `pos` - The positioning style
147
148
    See [`ChartContext::configure_series_labels()`] for more information and examples.
149
    */
150
0
    pub fn position(&mut self, pos: SeriesLabelPosition) -> &mut Self {
151
0
        self.position = pos;
152
0
        self
153
0
    }
Unexecuted instantiation: <plotters::chart::series::SeriesLabelStyle<plotters_svg::svg::SVGBackend, plotters::coord::ranged2d::cartesian::Cartesian2d<plotters::coord::ranged1d::combinators::logarithmic::LogCoord<f64>, plotters::coord::ranged1d::combinators::logarithmic::LogCoord<f64>>>>::position
Unexecuted instantiation: <plotters::chart::series::SeriesLabelStyle<plotters_svg::svg::SVGBackend, plotters::coord::ranged2d::cartesian::Cartesian2d<plotters::coord::ranged1d::types::numeric::RangedCoordf64, plotters::coord::ranged1d::types::numeric::RangedCoordf64>>>::position
Unexecuted instantiation: <plotters::chart::series::SeriesLabelStyle<_, _>>::position
154
155
    /**
156
    Sets the margin of the series label drawing area.
157
158
    - `value`: The size specification in backend units (pixels)
159
160
    See [`ChartContext::configure_series_labels()`] for more information and examples.
161
    */
162
0
    pub fn margin<S: SizeDesc>(&mut self, value: S) -> &mut Self {
163
0
        self.margin = value
164
0
            .in_pixels(&self.target.plotting_area().dim_in_pixel())
165
0
            .max(0) as u32;
166
0
        self
167
0
    }
168
169
    /**
170
    Sets the size of the legend area.
171
172
    `size` - The size of legend area in backend units (pixels)
173
174
    See [`ChartContext::configure_series_labels()`] for more information and examples.
175
    */
176
0
    pub fn legend_area_size<S: SizeDesc>(&mut self, size: S) -> &mut Self {
177
0
        let size = size
178
0
            .in_pixels(&self.target.plotting_area().dim_in_pixel())
179
0
            .max(0) as u32;
180
0
        self.legend_area_size = size;
181
0
        self
182
0
    }
183
184
    /**
185
    Sets the style of the label series area.
186
187
    `style` - The style of the border
188
189
    See [`ChartContext::configure_series_labels()`] for more information and examples.
190
    */
191
0
    pub fn border_style<S: Into<ShapeStyle>>(&mut self, style: S) -> &mut Self {
192
0
        self.border_style = style.into();
193
0
        self
194
0
    }
195
196
    /**
197
    Sets the background style of the label series area.
198
199
    `style` - The style of the border
200
201
    See [`ChartContext::configure_series_labels()`] for more information and examples.
202
    */
203
0
    pub fn background_style<S: Into<ShapeStyle>>(&mut self, style: S) -> &mut Self {
204
0
        self.background = style.into();
205
0
        self
206
0
    }
207
208
    /**
209
    Sets the font for series labels.
210
211
    `font` - Desired font
212
213
    See [`ChartContext::configure_series_labels()`] for more information and examples.
214
    */
215
0
    pub fn label_font<F: IntoTextStyle<'b>>(&mut self, font: F) -> &mut Self {
216
0
        self.label_font = Some(font.into_text_style(&self.target.plotting_area().dim_in_pixel()));
217
0
        self
218
0
    }
219
220
    /**
221
    Draws the series label area.
222
223
    See [`ChartContext::configure_series_labels()`] for more information and examples.
224
    */
225
0
    pub fn draw(&mut self) -> Result<(), DrawingAreaErrorKind<DB::ErrorType>> {
226
0
        let drawing_area = self.target.plotting_area().strip_coord_spec();
227
228
        // TODO: Issue #68 Currently generic font family doesn't load on OSX, change this after the issue
229
        // resolved
230
0
        let default_font = ("sans-serif", 12).into_font();
231
0
        let default_style: TextStyle = default_font.into();
232
233
0
        let font = {
234
0
            let mut temp = None;
235
0
            std::mem::swap(&mut self.label_font, &mut temp);
236
0
            temp.unwrap_or(default_style)
237
        };
238
239
0
        let mut label_element = MultiLineText::<_, &str>::new((0, 0), &font);
240
0
        let mut funcs = vec![];
241
242
0
        for anno in self.target.series_anno.iter() {
243
0
            let label_text = anno.get_label();
244
0
            let draw_func = anno.get_draw_func();
245
246
0
            if label_text.is_empty() && draw_func.is_none() {
247
0
                continue;
248
0
            }
249
250
0
            funcs.push(draw_func.unwrap_or(&|p: BackendCoord| EmptyElement::at(p).into_dyn()));
Unexecuted instantiation: <plotters::chart::series::SeriesLabelStyle<plotters_svg::svg::SVGBackend, plotters::coord::ranged2d::cartesian::Cartesian2d<plotters::coord::ranged1d::combinators::logarithmic::LogCoord<f64>, plotters::coord::ranged1d::combinators::logarithmic::LogCoord<f64>>>>::draw::{closure#0}
Unexecuted instantiation: <plotters::chart::series::SeriesLabelStyle<plotters_svg::svg::SVGBackend, plotters::coord::ranged2d::cartesian::Cartesian2d<plotters::coord::ranged1d::types::numeric::RangedCoordf64, plotters::coord::ranged1d::types::numeric::RangedCoordf64>>>::draw::{closure#0}
Unexecuted instantiation: <plotters::chart::series::SeriesLabelStyle<_, _>>::draw::{closure#0}
251
0
            label_element.push_line(label_text);
252
        }
253
254
0
        let (mut w, mut h) = label_element.estimate_dimension().map_err(|e| {
255
0
            DrawingAreaErrorKind::BackendError(DrawingErrorKind::FontError(Box::new(e)))
256
0
        })?;
Unexecuted instantiation: <plotters::chart::series::SeriesLabelStyle<plotters_svg::svg::SVGBackend, plotters::coord::ranged2d::cartesian::Cartesian2d<plotters::coord::ranged1d::combinators::logarithmic::LogCoord<f64>, plotters::coord::ranged1d::combinators::logarithmic::LogCoord<f64>>>>::draw::{closure#1}
Unexecuted instantiation: <plotters::chart::series::SeriesLabelStyle<plotters_svg::svg::SVGBackend, plotters::coord::ranged2d::cartesian::Cartesian2d<plotters::coord::ranged1d::types::numeric::RangedCoordf64, plotters::coord::ranged1d::types::numeric::RangedCoordf64>>>::draw::{closure#1}
Unexecuted instantiation: <plotters::chart::series::SeriesLabelStyle<_, _>>::draw::{closure#1}
257
258
0
        let margin = self.margin as i32;
259
260
0
        w += self.legend_area_size as i32 + margin * 2;
261
0
        h += margin * 2;
262
263
0
        let (area_w, area_h) = drawing_area.dim_in_pixel();
264
265
0
        let (label_x, label_y) = self.position.layout_label_area((w, h), (area_w, area_h));
266
267
0
        label_element.relocate((
268
0
            label_x + self.legend_area_size as i32 + margin,
269
0
            label_y + margin,
270
0
        ));
271
272
0
        drawing_area.draw(&Rectangle::new(
273
0
            [(label_x, label_y), (label_x + w, label_y + h)],
274
0
            self.background.filled(),
275
0
        ))?;
276
0
        drawing_area.draw(&Rectangle::new(
277
0
            [(label_x, label_y), (label_x + w, label_y + h)],
278
0
            self.border_style,
279
0
        ))?;
280
0
        drawing_area.draw(&label_element)?;
281
282
0
        for (((_, y0), (_, y1)), make_elem) in label_element
283
0
            .compute_line_layout()
284
0
            .map_err(|e| {
285
0
                DrawingAreaErrorKind::BackendError(DrawingErrorKind::FontError(Box::new(e)))
286
0
            })?
Unexecuted instantiation: <plotters::chart::series::SeriesLabelStyle<plotters_svg::svg::SVGBackend, plotters::coord::ranged2d::cartesian::Cartesian2d<plotters::coord::ranged1d::combinators::logarithmic::LogCoord<f64>, plotters::coord::ranged1d::combinators::logarithmic::LogCoord<f64>>>>::draw::{closure#2}
Unexecuted instantiation: <plotters::chart::series::SeriesLabelStyle<plotters_svg::svg::SVGBackend, plotters::coord::ranged2d::cartesian::Cartesian2d<plotters::coord::ranged1d::types::numeric::RangedCoordf64, plotters::coord::ranged1d::types::numeric::RangedCoordf64>>>::draw::{closure#2}
Unexecuted instantiation: <plotters::chart::series::SeriesLabelStyle<_, _>>::draw::{closure#2}
287
0
            .into_iter()
288
0
            .zip(funcs.into_iter())
289
        {
290
0
            let legend_element = make_elem((label_x + margin, (y0 + y1) / 2));
291
0
            drawing_area.draw(&legend_element)?;
292
        }
293
294
0
        Ok(())
295
0
    }
Unexecuted instantiation: <plotters::chart::series::SeriesLabelStyle<plotters_svg::svg::SVGBackend, plotters::coord::ranged2d::cartesian::Cartesian2d<plotters::coord::ranged1d::combinators::logarithmic::LogCoord<f64>, plotters::coord::ranged1d::combinators::logarithmic::LogCoord<f64>>>>::draw
Unexecuted instantiation: <plotters::chart::series::SeriesLabelStyle<plotters_svg::svg::SVGBackend, plotters::coord::ranged2d::cartesian::Cartesian2d<plotters::coord::ranged1d::types::numeric::RangedCoordf64, plotters::coord::ranged1d::types::numeric::RangedCoordf64>>>::draw
Unexecuted instantiation: <plotters::chart::series::SeriesLabelStyle<_, _>>::draw
296
}