pub struct ChartPainter { /* private fields */ }Expand description
Draws what is around a chart’s series: gridlines at the ticks, the axis edges and the
tick labels, right of the plot for y and under it for x, and a crosshair over it.
Owns the label font’s character map; glyphs come from the canvas’s shared cache.
Painting allocates nothing once the label characters are cached (see
prewarm); the characters of category names are cached the first time
they are drawn.
Implementations§
Source§impl ChartPainter
impl ChartPainter
Sourcepub fn new(font: Font, px: f32, palette: ChartPalette) -> Self
pub fn new(font: Font, px: f32, palette: ChartPalette) -> Self
A painter writing labels in font at px pixels per em, with room for y labels
of 8 characters.
Sourcepub fn with_label_chars(self, chars: u16) -> Self
pub fn with_label_chars(self, chars: u16) -> Self
The painter with room for y labels of chars characters.
Sourcepub fn palette(&self) -> &ChartPalette
pub fn palette(&self) -> &ChartPalette
The colors this painter draws with.
Sourcepub fn set_palette(&mut self, palette: ChartPalette)
pub fn set_palette(&mut self, palette: ChartPalette)
Draws with palette from now on.
Sourcepub fn prewarm(&mut self, cache: &mut GlyphCache) -> usize
pub fn prewarm(&mut self, cache: &mut GlyphCache) -> usize
Rasterizes every character a label can use into cache at every subpixel position
now, so frames never rasterize (or allocate) for labels. Returns how many glyphs could
not be cached.
Sourcepub fn plot_area(&mut self, bounds: Rect, x_labels: bool) -> Rect
pub fn plot_area(&mut self, bounds: Rect, x_labels: bool) -> Rect
The area of bounds left for the plot once the y labels (right) and, if
x_labels, the x labels (below) have their room; edges on whole pixels. Charts
stacked on one time axis label x under the lowest only.
Sourcepub fn paint_axes(
&mut self,
canvas: &mut Canvas<'_>,
plot: &Plot,
x_labels: bool,
)
pub fn paint_axes( &mut self, canvas: &mut Canvas<'_>, plot: &Plot, x_labels: bool, )
Draws the gridlines, the axis edges and the y labels of plot, and its x labels
if x_labels. Call it before the series so they draw over the grid. A
Category axis gets no x labels here: see
paint_axes_named.
Sourcepub fn paint_axes_named<'n>(
&mut self,
canvas: &mut Canvas<'_>,
plot: &Plot,
x_labels: bool,
names: &dyn Fn(usize) -> Option<&'n str>,
)
pub fn paint_axes_named<'n>( &mut self, canvas: &mut Canvas<'_>, plot: &Plot, x_labels: bool, names: &dyn Fn(usize) -> Option<&'n str>, )
paint_axes, with the places of a
Category x axis labelled by names (None: no label
there). A name longer than the room between two labels is cut, ending in …. Other
axes ignore names.
Sourcepub fn paint_crosshair(
&mut self,
canvas: &mut Canvas<'_>,
plot: &Plot,
at: Point,
x_label: bool,
)
pub fn paint_crosshair( &mut self, canvas: &mut Canvas<'_>, plot: &Plot, at: Point, x_label: bool, )
Draws a crosshair at at over plot: a line down the plot through at, and, if
at is within the plot, a line across it with the y there in a box right of the
plot; with x_label, the x there in a box under the plot. The values are written
finer than the tick labels. For stacked plots, give each one the same at and label
x under the lowest. A Category axis gets no x value
here: see paint_crosshair_named.
Sourcepub fn paint_crosshair_named<'n>(
&mut self,
canvas: &mut Canvas<'_>,
plot: &Plot,
at: Point,
x_label: bool,
names: &dyn Fn(usize) -> Option<&'n str>,
)
pub fn paint_crosshair_named<'n>( &mut self, canvas: &mut Canvas<'_>, plot: &Plot, at: Point, x_label: bool, names: &dyn Fn(usize) -> Option<&'n str>, )
paint_crosshair, with the x of a
Category axis written as the name names gives the nearest
place (None: nothing written). Other axes ignore names.
Sourcepub fn title_height(&self) -> f32
pub fn title_height(&self) -> f32
The height of the line a title takes above a plot: leave it out of the bounds given
to plot_area for a plot with a title.
Sourcepub fn paint_title(&mut self, canvas: &mut Canvas<'_>, plot: &Plot, title: &str)
pub fn paint_title(&mut self, canvas: &mut Canvas<'_>, plot: &Plot, title: &str)
Writes title on the line of title_height above plot,
from its left edge, cut off where the plot ends: above the plot, it hides none of
it. An empty title draws nothing.