Most real-world word clouds start from unstructured text — articles, survey responses,
commit messages, tweets. The engine expects { text, weight } pairs, so your app
tokenizes the source, counts frequencies, optionally filters stop words, then passes the
top N terms to layout().
Typical pipeline:
Map<string, number> of term → frequency.maxTerms.weight and call
layout(items, options).const STOP = new Set(["the", "and", "a", "to", "of", "in"]); export function textToItems(raw, { maxTerms = 500, minLen = 3 } = {}) { const counts = new Map(); const tokens = raw.toLowerCase().match(/[a-z0-9']+/g) ?? []; for (const t of tokens) { if (t.length < minLen || STOP.has(t)) continue; counts.set(t, (counts.get(t) ?? 0) + 1); } return [...counts.entries()] .sort((a, b) => b[1] - a[1]) .slice(0, maxTerms) .map(([text, weight]) => ({ text, weight })); }
Debounce input events (300–500 ms) so you don't re-pack on every keystroke. Show a
lightweight "laying out…" state while layout() runs — especially for longer
pasted documents.
Edit the sample paragraph or paste your own text. Click Generate cloud to tokenize, count, and lay out the top terms.
Open Fullscreen to lay out the cloud on the full viewport — useful for longer pasted documents with more unique terms.