| Crates.io | araea-wordcloud |
| lib.rs | araea-wordcloud |
| version | 0.1.11 |
| created_at | 2025-11-28 14:22:23.271834+00 |
| updated_at | 2025-12-07 16:02:46.305437+00 |
| description | High-performance word cloud visualization library supporting SVG/PNG output, custom masks, and color schemes. |
| homepage | |
| repository | https://github.com/araea/araea-wordcloud |
| max_upload_size | |
| id | 1955401 |
| size | 2,155,425 |
A high-performance word cloud visualization library implemented in pure Rust. Supports mask shapes, SVG/PNG dual output, custom fonts, vertical writing, and accurate pixel-perfect collision detection.
[dependencies]
araea-wordcloud = "0.1"
use araea_wordcloud::generate;
use std::fs;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Define words and weights
let words = vec![
("Rust", 100.0),
("Fast", 80.0),
("Safe", 60.0),
("WordCloud", 40.0),
];
// Generate with default settings
let wordcloud = generate(&words)?;
// Save as PNG (scale 2.0 for higher resolution)
fs::write("output.png", wordcloud.to_png(2.0)?)?;
// Or save as SVG
fs::write("output.svg", wordcloud.to_svg())?;
Ok(())
}
use araea_wordcloud::{WordCloudBuilder, WordInput, ColorScheme, MaskShape};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let words = vec![
WordInput::new("Love", 100.0),
WordInput::new("Rust", 80.0),
WordInput::new("Design", 60.0),
WordInput::new("Code", 50.0),
];
let wordcloud = WordCloudBuilder::new()
.size(800, 800)
// Use a built-in color scheme or custom colors
.color_scheme(ColorScheme::Blue)
// Use a built-in mask shape
.mask_preset(MaskShape::Heart)
// Adjust font sizes
.font_size_range(20.0, 100.0)
// Set rotation angles (e.g., -45, 0, 45 degrees)
.angles(vec![-45.0, 0.0, 45.0])
// Adjust spacing between words
.padding(10)
.build(&words)?;
std::fs::write("heart_cloud.png", wordcloud.to_png(2.0)?)?;
Ok(())
}
To enable vertical writing (ideal for Chinese/Japanese), set vertical_writing(true) and include 90.0 or -90.0 in your angles. Characters will be stacked vertically but remain upright, rather than the whole word being rotated sideways.
let wordcloud = WordCloudBuilder::new()
.size(800, 800)
// Allow words to be placed vertically (90 degrees)
.angles(vec![0.0, 90.0])
// Enable vertical writing mode:
// Words placed at 90/-90 degrees will have characters stacked vertically
.vertical_writing(true)
.build(&words)?;


Run the examples:
cargo run --example simple - Basic usagecargo run --example mask_shape - Heart-shaped word cloudcargo run --example chinese_dense - High-density Chinese word cloudcargo run --example advanced - Custom colors and layout| Scheme | Description | Background |
|---|---|---|
Default |
Classic dark green, red, and gold tones | White |
Contrasting1 |
Vibrant orange, cyan, and beige | Black |
Blue |
Deep ocean blues and orange accents | White |
Green |
Natural forest greens and earth tones | White |
Cold1 |
Dark slate, grey, and bronze | Black |
Black |
Pure black text | White |
White |
Pure white text | Black |
| Shape | Description |
|---|---|
Circle |
Standard circular layout (default) |
Cloud |
Cloud shape |
Heart |
Heart shape |
Skull |
Skull shape |
Star |
Star shape |
Triangle |
Triangle shape |
| Method | Description | Default |
|---|---|---|
.size(w, h) |
Canvas dimensions | 800x600 |
.background(hex) |
Custom background color | #FFFFFF (or based on scheme) |
.colors(vec![...]) |
Custom list of hex colors | Default Scheme |
.color_scheme(enum) |
Use a preset color scheme | ColorScheme::Default |
.font(bytes) |
Custom font file data (TTF/OTF) | HarmonyOS Sans SC Bold |
.mask(bytes) |
Custom mask image (SVG/PNG) | None |
.padding(px) |
Collision padding between words | 5 |
.angles(vec![...]) |
Allowed rotation angles (degrees) | vec![0.0] (Horizontal) |
.vertical_writing(bool) |
Enable upright vertical text flow (for CJK) when angle is ±90° | false |
.seed(u64) |
Random seed for reproducible layout | Random |
Thanks to wordcloud.online for inspiration and reference. The word cloud rendering approach is inspired by this website, achieving efficient and visually appealing results using canvas-style pixel collision detection.