(counts: Map<string, number>)
| 226 | } |
| 227 | } |
| 228 | |
| 229 | function buildWordItems(counts: Map<string, number>): WordItem[] { |
| 230 | const entries = pruneOverlappingWords([...counts.entries()]) |
| 231 | .filter(([, count]) => count >= 2) |
| 232 | .sort((a, b) => b[1] - a[1]) |
| 233 | .slice(0, 220); |
| 234 | if (!entries.length) return []; |
| 235 | const max = entries[0][1]; |
| 236 | const min = entries[entries.length - 1][1]; |
| 237 | const spread = Math.max(1, max - min); |
| 238 | return entries.map(([word, count], index) => { |
| 239 | const ratio = (count - min) / spread; |
| 240 | const size = Math.round(12 + Math.pow(ratio, 0.7) * 68); |
| 241 | return { |
| 242 | word, |
| 243 | count, |
| 244 | size, |
| 245 | color: PALETTE[index % PALETTE.length], |
| 246 | }; |
| 247 | }); |
| 248 | } |
| 249 | |
| 250 | function overlaps(a: WordItem, placed: WordItem[]): boolean { |
no test coverage detected