Skip to main content

RGBAColor

Struct RGBAColor 

Source
pub struct RGBAColor {
    pub r: u8,
    pub g: u8,
    pub b: u8,
    pub a: f64,
}
Expand description

RGBA color representation.

Fields§

§r: u8§g: u8§b: u8§a: f64

Implementations§

Source§

impl RGBAColor

Source

pub fn new(r: u8, g: u8, b: u8) -> Self

Examples found in repository?
examples/continuous_color.rs (line 41)
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5    // Generate scatter data with a continuous variable for color
6    let x: Vec<f64> = (0..200)
7        .map(|i| {
8            let t = i as f64 * 0.05;
9            t.cos() * (1.0 + t * 0.3)
10        })
11        .collect();
12    let y: Vec<f64> = (0..200)
13        .map(|i| {
14            let t = i as f64 * 0.05;
15            t.sin() * (1.0 + t * 0.3)
16        })
17        .collect();
18    let z: Vec<f64> = (0..200).map(|i| i as f64 * 0.05).collect();
19
20    let df = df! {
21        "x" => &x,
22        "y" => &y,
23        "z" => &z,
24    }?;
25
26    // Default blue-to-red gradient
27    GGPlot::new(df.clone())
28        .aes(Aes::new().x("x").y("y").color("z"))
29        .geom_point()
30        .title("Continuous Color (default gradient)")
31        .xlab("X")
32        .ylab("Y")
33        .save("continuous_color.svg")?;
34
35    println!("Saved continuous_color.svg");
36
37    // Custom gradient: dark blue to yellow
38    GGPlot::new(df)
39        .aes(Aes::new().x("x").y("y").color("z"))
40        .geom_point()
41        .scale_color_gradient(RGBAColor::new(10, 30, 100), RGBAColor::new(255, 230, 50))
42        .title("Continuous Color (custom gradient)")
43        .xlab("X")
44        .ylab("Y")
45        .save("continuous_color_custom.svg")?;
46
47    println!("Saved continuous_color_custom.svg");
48    Ok(())
49}
More examples
Hide additional examples
examples/color_palettes.rs (line 63)
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5    // Generate grouped scatter data
6    let groups = ["Alpha", "Beta", "Gamma", "Delta", "Epsilon"];
7    let mut x_vals = Vec::new();
8    let mut y_vals = Vec::new();
9    let mut group_vals = Vec::new();
10
11    for (gi, &group) in groups.iter().enumerate() {
12        for j in 0..20 {
13            let base_x = gi as f64 * 2.0 + 1.0;
14            let base_y = (gi as f64 + 1.0) * 3.0;
15            let r = ((gi * 20 + j) * 7 + 13) % 17;
16            x_vals.push(base_x + (r as f64 / 17.0 - 0.5) * 2.0);
17            y_vals.push(base_y + ((r * 3 + 5) % 11) as f64 / 11.0 * 4.0 - 2.0);
18            group_vals.push(group);
19        }
20    }
21
22    let df = df! {
23        "x" => &x_vals,
24        "y" => &y_vals,
25        "group" => &group_vals,
26    }?;
27
28    // Viridis palette
29    GGPlot::new(df.clone())
30        .aes(Aes::new().x("x").y("y").color("group"))
31        .geom_point()
32        .scale_color_viridis()
33        .title("Viridis Palette")
34        .save("palette_viridis.svg")?;
35
36    println!("Saved palette_viridis.svg");
37
38    // Brewer Set1 palette
39    GGPlot::new(df.clone())
40        .aes(Aes::new().x("x").y("y").color("group"))
41        .geom_point()
42        .scale_color_brewer(PaletteName::Set1)
43        .title("Brewer Set1 Palette")
44        .save("palette_brewer_set1.svg")?;
45
46    println!("Saved palette_brewer_set1.svg");
47
48    // Brewer Dark2 palette
49    GGPlot::new(df.clone())
50        .aes(Aes::new().x("x").y("y").color("group"))
51        .geom_point()
52        .scale_color_brewer(PaletteName::Dark2)
53        .title("Brewer Dark2 Palette")
54        .save("palette_brewer_dark2.svg")?;
55
56    println!("Saved palette_brewer_dark2.svg");
57
58    // Manual colors
59    GGPlot::new(df)
60        .aes(Aes::new().x("x").y("y").color("group"))
61        .geom_point()
62        .scale_color_manual(vec![
63            ("Alpha", RGBAColor::new(255, 0, 0)),
64            ("Beta", RGBAColor::new(0, 180, 0)),
65            ("Gamma", RGBAColor::new(0, 0, 255)),
66            ("Delta", RGBAColor::new(255, 165, 0)),
67            ("Epsilon", RGBAColor::new(128, 0, 128)),
68        ])
69        .title("Manual Color Scale")
70        .save("palette_manual.svg")?;
71
72    println!("Saved palette_manual.svg");
73    Ok(())
74}
Source

pub fn with_alpha(self, a: f64) -> Self

Source

pub fn lerp(&self, other: &RGBAColor, t: f64) -> RGBAColor

Interpolate between two colors.

Trait Implementations§

Source§

impl Clone for RGBAColor

Source§

fn clone(&self) -> RGBAColor

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 Copy for RGBAColor

Source§

impl Debug for RGBAColor

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

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

Source§

fn vzip(self) -> V