Skip to main content

ChartPainter

Struct ChartPainter 

Source
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

Source

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.

Source

pub fn with_label_chars(self, chars: u16) -> Self

The painter with room for y labels of chars characters.

Source

pub fn palette(&self) -> &ChartPalette

The colors this painter draws with.

Source

pub fn set_palette(&mut self, palette: ChartPalette)

Draws with palette from now on.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for ChartPainter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.