dataviz::figure::canvas::pixelcanvas

Struct PixelCanvas

source
pub struct PixelCanvas {
    pub width: u32,
    pub height: u32,
    pub background_color: [u8; 3],
    pub buffer: Vec<u8>,
    pub margin: u32,
}
Expand description

A structure representing a pixel-based drawing canvas.

Fields§

§width: u32

Width of the canvas in pixels.

§height: u32

Height of the canvas in pixels.

§background_color: [u8; 3]

Background color of the canvas (RGB format).

§buffer: Vec<u8>

Buffer storing pixel data as a linear array.

§margin: u32

Margin around the canvas (in pixels).

Implementations§

source§

impl PixelCanvas

source

pub fn new( width: u32, height: u32, background_color: [u8; 3], margin: u32, ) -> Self

Creates a new PixelCanvas with the specified dimensions, background color, and margin.

§Parameters
  • width: The width of the canvas in pixels.
  • height: The height of the canvas in pixels.
  • background_color: The RGB color of the canvas background.
  • margin: Margin size in pixels.
§Returns

A new PixelCanvas instance.

source

pub fn clear(&mut self)

Clears the canvas by filling it with the background color.

source

pub fn draw_pixel(&mut self, x: u32, y: u32, color: [u8; 3])

Draws a single pixel at the specified coordinates with the given color.

§Parameters
  • x: The x-coordinate of the pixel.
  • y: The y-coordinate of the pixel.
  • color: The RGB color of the pixel.
source

pub fn blend_pixel(&mut self, x: u32, y: u32, color: [u8; 3], alpha: f64)

Blends a pixel with the specified color and alpha value.

§Parameters
  • x: The x-coordinate of the pixel.
  • y: The y-coordinate of the pixel.
  • color: The RGB color to blend.
  • alpha: The transparency value (0.0 to 1.0).
source

pub fn draw_horizontal_line(&mut self, y: u32, color: [u8; 3])

Draws a horizontal line at the specified y-coordinate.

§Parameters
  • y: The y-coordinate of the line.
  • color: The RGB color of the line.
source

pub fn draw_vertical_line(&mut self, x: u32, color: [u8; 3])

Draws a vertical line at the specified x-coordinate.

§Parameters
  • x: The x-coordinate of the line.
  • color: The RGB color of the line.
source

pub fn draw_grid(&mut self, grid_size: &[usize; 2], color: [u8; 3])

Draws a grid on the canvas.

§Parameters
  • grid_size: An array specifying the spacing of grid lines in the x and y directions.
  • color: The RGB color of the grid lines.
source

pub fn draw_text_vertical( &mut self, x: u32, y: u32, text: &str, color: [u8; 3], font: &FontRef<'_>, scale: PxScale, )

Draws text vertically at the specified position.

§Parameters
  • x: The x-coordinate for the text.
  • y: The y-coordinate for the text.
  • text: The text content.
  • color: The RGB color of the text.
  • font: The font reference for rendering text.
  • scale: The scaling factor for the font size.
source

pub fn draw_text( &mut self, x: u32, y: u32, text: &str, color: [u8; 3], font: &FontRef<'_>, scale: PxScale, )

Draws text at the specified position.

§Parameters
  • x: The x-coordinate for the text.
  • y: The y-coordinate for the text.
  • text: The text content.
  • color: The RGB color of the text.
  • font: The font reference for rendering text.
  • scale: The scaling factor for the font size.
source

pub fn draw_line( &mut self, x1: i32, y1: i32, x2: i32, y2: i32, color: [u8; 3], line_type: LineType, )

Draws a line with the specified type (solid, dashed, or dotted).

§Parameters
  • x1, y1: Coordinates of the start point.
  • x2, y2: Coordinates of the end point.
  • color: The RGB color of the line.
  • line_type: The type of line to draw (LineType).
source

pub fn save_as_image(&self, file_path: &str)

Saves the current canvas as an image file.

§Parameters
  • file_path: The path to save the image file.
§Panics

Panics if the image cannot be saved.

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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V