koishi-plugin-chat-analyse 1.4.5 → 1.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +10 -0
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1783,6 +1783,11 @@ var Renderer = class {
|
|
|
1783
1783
|
if (!words?.length) return;
|
|
1784
1784
|
const wordsJson = JSON.stringify(words);
|
|
1785
1785
|
const selectedPalette = this.COLOR_PALETTES[Math.floor(Math.random() * this.COLOR_PALETTES.length)];
|
|
1786
|
+
const weights = words.map((w) => w[1]);
|
|
1787
|
+
const maxWeight = Math.max(...weights, 1);
|
|
1788
|
+
const minWeight = Math.min(...weights);
|
|
1789
|
+
const MAX_FONT_SIZE = 64;
|
|
1790
|
+
const MIN_FONT_SIZE = 4;
|
|
1786
1791
|
const cardHtml = `
|
|
1787
1792
|
<div class="container">
|
|
1788
1793
|
<div class="header">
|
|
@@ -1796,6 +1801,11 @@ var Renderer = class {
|
|
|
1796
1801
|
const palette = ${JSON.stringify(selectedPalette)};
|
|
1797
1802
|
WordCloud(document.getElementById('wordcloud-container'), {
|
|
1798
1803
|
fontFamily: '"Noto Sans CJK SC", "Arial", sans-serif',
|
|
1804
|
+
weightFactor: (size) => {
|
|
1805
|
+
if (${maxWeight} === ${minWeight}) return (${MIN_FONT_SIZE} + ${MAX_FONT_SIZE}) / 2;
|
|
1806
|
+
const normalizedWeight = (size - ${minWeight}) / (${maxWeight} - ${minWeight});
|
|
1807
|
+
return ${MIN_FONT_SIZE} + normalizedWeight * (${MAX_FONT_SIZE} - ${MIN_FONT_SIZE});
|
|
1808
|
+
},
|
|
1799
1809
|
color: (word, weight, fontSize, distance, theta) => {
|
|
1800
1810
|
return palette[Math.floor(Math.random() * palette.length)];
|
|
1801
1811
|
},
|