pub enum ColorScheme {
Default,
Contrasting1,
Blue,
Green,
Cold1,
Black,
White,
}Variants§
Implementations§
Source§impl ColorScheme
impl ColorScheme
pub fn colors(&self) -> Vec<&'static str>
Sourcepub fn background_color(&self) -> &'static str
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
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
impl Clone for ColorScheme
Source§fn clone(&self) -> ColorScheme
fn clone(&self) -> ColorScheme
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ColorScheme
impl Debug for ColorScheme
Source§impl Default for ColorScheme
impl Default for ColorScheme
Source§fn default() -> ColorScheme
fn default() -> ColorScheme
Returns the “default value” for a type. Read more
impl Copy for ColorScheme
Auto Trait Implementations§
impl Freeze for ColorScheme
impl RefUnwindSafe for ColorScheme
impl Send for ColorScheme
impl Sync for ColorScheme
impl Unpin for ColorScheme
impl UnwindSafe for ColorScheme
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
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().