Skip to main content

BarArtist

Struct BarArtist 

Source
pub struct BarArtist {
    pub categories: Categories,
    pub heights: Series,
    pub color: Color,
    pub label: Option<String>,
    pub alpha: f64,
    pub horizontal: bool,
    pub bar_width: f64,
}
Expand description

A bar chart rendering vertical or horizontal bars over categorical data.

Categories are placed at integer positions 0, 1, 2, ... on the category axis, with each bar centered on its position. The bar_width field controls the fraction of the inter-category spacing that the bar occupies (1.0 = bars touching, 0.5 = half-width with gaps).

Fields§

§categories: Categories

Category labels for the bar axis.

§heights: Series

Bar heights (or lengths, for horizontal bars).

§color: Color

Fill color of the bars.

§label: Option<String>

Optional legend label. When Some, the bar series appears in the legend.

§alpha: f64

Opacity from 0.0 (fully transparent) to 1.0 (fully opaque).

§horizontal: bool

When true, bars extend horizontally (categories on the y-axis).

§bar_width: f64

Bar width as a fraction of the category spacing (0.0, 1.0].

Implementations§

Source§

impl BarArtist

Source

pub fn data_bounds(&self) -> (f64, f64, f64, f64)

Computes the data-space bounding box (xmin, xmax, ymin, ymax).

For vertical bars, the x-axis spans from -0.5 to n - 0.5 (where n is the number of categories) so that bars are centered on integer positions. The y-axis spans from 0.0 to the tallest bar, with a fallback of (0.0, 1.0) when the heights series is empty.

For horizontal bars the axes are transposed: the y-axis holds the category positions and the x-axis holds the bar lengths.

Source§

impl BarArtist

Source

pub fn color(&mut self, color: Color) -> &mut Self

Sets the bar color.

Applies the given Color to every bar rendered by this artist.

§Arguments
  • color - The Color to fill each bar with.
Source

pub fn label(&mut self, label: &str) -> &mut Self

Sets the legend label.

When a legend is displayed on the figure, this label will appear next to the color swatch for this bar series. Passing a new value overwrites any previously set label.

§Arguments
  • label - A string slice that will be stored as the legend entry.
Source

pub fn alpha(&mut self, alpha: f64) -> &mut Self

Sets the opacity.

The value is clamped to the range [0.0, 1.0], where 0.0 is fully transparent and 1.0 is fully opaque.

§Arguments
  • alpha - The desired opacity level.
Source

pub fn bar_width(&mut self, width: f64) -> &mut Self

Sets the bar width as a fraction of the category spacing (0.0 to 1.0).

Smaller values produce thinner bars with more whitespace between them, while larger values make the bars wider. The value is clamped to the range [0.1, 1.0] so that bars are never invisibly thin nor overlap their neighbours.

§Arguments
  • width - The fraction of available category space each bar should occupy.

Trait Implementations§

Source§

impl Clone for BarArtist

Source§

fn clone(&self) -> BarArtist

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BarArtist

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.