(words: WordItem[], limit: number, validMessages: number)
| 298 | } |
| 299 | |
| 300 | function renderWordCloud(words: WordItem[], limit: number, validMessages: number): Buffer { |
| 301 | ensureCjkFont(); |
| 302 | const canvas = createCanvas(WIDTH, HEIGHT); |
| 303 | const ctx = canvas.getContext("2d"); |
| 304 | ctx.fillStyle = "#ffffff"; |
| 305 | ctx.fillRect(0, 0, WIDTH, HEIGHT); |
| 306 | |
| 307 | const placed = layoutWords(ctx, words); |
| 308 | for (const item of placed) { |
| 309 | ctx.font = `700 ${item.size}px ${CJK_FONT_STACK}`; |
| 310 | ctx.fillStyle = item.color; |
| 311 | ctx.fillText(item.word, item.x || 0, item.y || 0); |
| 312 | } |
| 313 | |
| 314 | ctx.fillStyle = "#111827"; |
| 315 | ctx.font = `34px ${CJK_FONT_STACK}`; |
| 316 | ctx.fillText(`最近 ${limit} 条热词云 | ${validMessages} 条有效消息`, 42, HEIGHT - 34); |
| 317 | return canvas.toBuffer("image/png"); |
| 318 | } |
| 319 | |
| 320 | async function fetchRecentMessages(client: any, peer: any, limit: number): Promise<Api.Message[]> { |
| 321 | if (!peer || !client) return []; |
no test coverage detected