ColorScheme

Enum ColorScheme 

Source
pub enum ColorScheme {
    Default,
    Contrasting1,
    Blue,
    Green,
    Cold1,
    Black,
    White,
}

Variants§

§

Default

§

Contrasting1

§

Blue

§

Green

§

Cold1

§

Black

§

White

Implementations§

Source§

impl ColorScheme

Source

pub fn colors(&self) -> Vec<&'static str>

Source

pub fn background_color(&self) -> &'static str

Examples found in repository?
examples/mask_shape.rs (line 26)
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5    let output_path = "output_mask_heart.png";
6
7    let width = 800;
8    let height = 800;
9
10    println!("Generating words...");
11    let mut words = Vec::new();
12    for i in 0..300 {
13        words.push(WordInput::new("Love", 100.0));
14        words.push(WordInput::new("Rust", 80.0));
15        words.push(WordInput::new("Heart", 60.0 + (i as f32 % 40.0)));
16        words.push(WordInput::new("Mask", 40.0));
17    }
18
19    println!("Building word cloud...");
20
21    let scheme = ColorScheme::Default;
22    let wordcloud = WordCloudBuilder::new()
23        .size(width, height)
24        .mask_preset(MaskShape::Heart)
25        .color_scheme(scheme)
26        .background(scheme.background_color())
27        .padding(2)
28        .word_spacing(2.0)
29        .font_size_range(12.0, 80.0)
30        .build(&words)?;
31
32    println!("Saving to {}...", output_path);
33    fs::write(output_path, wordcloud.to_png(2.0)?)?;
34
35    println!("Done! Check {}", output_path);
36    Ok(())
37}
More examples
Hide additional examples
examples/chinese_dense.rs (line 37)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let mut words = generate_dense_chinese_data();
8    println!("Generated {} Chinese words.", words.len());
9
10    let start = Instant::now();
11
12    let width = 1600;
13    let height = 1100;
14
15    println!("Building word cloud ({}x{})...", width, height);
16
17    let count_len = words.len();
18    let dynamic_max_font_size = if count_len < 20 {
19        150.0
20    } else if count_len < 50 {
21        120.0
22    } else {
23        100.0
24    };
25
26    let max_weight = words.first().map(|w| w.weight).unwrap_or(100.0);
27    for word in &mut words {
28        if max_weight > 100.0 {
29            word.weight = word.weight.sqrt() * 10.0;
30        }
31    }
32
33    let scheme = ColorScheme::Default;
34    let wordcloud = WordCloudBuilder::new()
35        .size(width, height)
36        .color_scheme(scheme)
37        .background(scheme.background_color())
38        .padding(2)
39        .angles(vec![0.0, 90.0])
40        .word_spacing(2.0)
41        .font_size_range(14.0, dynamic_max_font_size)
42        .seed(2025)
43        .build(&words)?;
44
45    let output_path = "output_chinese_dense.png";
46    fs::write(output_path, wordcloud.to_png(2.0)?)?;
47
48    println!("Success! Time elapsed: {:?}", start.elapsed());
49    println!("Saved to {}", output_path);
50
51    Ok(())
52}

Trait Implementations§

Source§

impl Clone for ColorScheme

Source§

fn clone(&self) -> ColorScheme

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ColorScheme

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for ColorScheme

Source§

fn default() -> ColorScheme

Returns the “default value” for a type. Read more
Source§

impl Copy for ColorScheme

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> 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<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
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