MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / renderWordCloud

Function renderWordCloud

cy/cy.ts:300–318  ·  view source on GitHub ↗
(words: WordItem[], limit: number, validMessages: number)

Source from the content-addressed store, hash-verified

298}
299
300function 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
320async function fetchRecentMessages(client: any, peer: any, limit: number): Promise<Api.Message[]> {
321 if (!peer || !client) return [];

Callers 1

buildCloudImageFunction · 0.85

Calls 2

ensureCjkFontFunction · 0.85
layoutWordsFunction · 0.85

Tested by

no test coverage detected