koishi-plugin-chat-analyse 1.2.1 → 1.2.2
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 +12 -11
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1730,17 +1730,14 @@ var Renderer = class {
|
|
|
1730
1730
|
*/
|
|
1731
1731
|
async *renderWordCloud(data) {
|
|
1732
1732
|
const { title, time, words } = data;
|
|
1733
|
-
if (!words?.length) return
|
|
1733
|
+
if (!words?.length) return;
|
|
1734
1734
|
const wordsJson = JSON.stringify(words);
|
|
1735
1735
|
const selectedPalette = this.COLOR_PALETTES[Math.floor(Math.random() * this.COLOR_PALETTES.length)];
|
|
1736
|
-
const
|
|
1737
|
-
const
|
|
1738
|
-
const
|
|
1739
|
-
const
|
|
1740
|
-
const
|
|
1741
|
-
const progress = (count - minWords) / (maxWords - minWords);
|
|
1742
|
-
const clampedProgress = Math.max(0, Math.min(1, progress));
|
|
1743
|
-
const dynamicWeightFactor = maxWeight - (maxWeight - minWeight) * clampedProgress;
|
|
1736
|
+
const weights = words.map((w) => w[1]);
|
|
1737
|
+
const maxWeight = Math.max(...weights, 1);
|
|
1738
|
+
const minWeight = Math.min(...weights);
|
|
1739
|
+
const MAX_FONT_SIZE = 64;
|
|
1740
|
+
const MIN_FONT_SIZE = 4;
|
|
1744
1741
|
const cardHtml = `
|
|
1745
1742
|
<div class="container">
|
|
1746
1743
|
<div class="header">
|
|
@@ -1755,14 +1752,18 @@ var Renderer = class {
|
|
|
1755
1752
|
WordCloud(document.getElementById('wordcloud-container'), {
|
|
1756
1753
|
list: ${wordsJson},
|
|
1757
1754
|
fontFamily: '"Noto Sans CJK SC", "Arial", sans-serif',
|
|
1758
|
-
weightFactor: (size) =>
|
|
1755
|
+
weightFactor: (size) => {
|
|
1756
|
+
if (${maxWeight} === ${minWeight}) return (${MIN_FONT_SIZE} + ${MAX_FONT_SIZE}) / 2;
|
|
1757
|
+
const normalizedWeight = (size - ${minWeight}) / (${maxWeight} - ${minWeight});
|
|
1758
|
+
return ${MIN_FONT_SIZE} + normalizedWeight * (${MAX_FONT_SIZE} - ${MIN_FONT_SIZE});
|
|
1759
|
+
},
|
|
1759
1760
|
color: (word, weight, fontSize, distance, theta) => {
|
|
1760
1761
|
return palette[Math.floor(Math.random() * palette.length)];
|
|
1761
1762
|
},
|
|
1762
1763
|
backgroundColor: 'transparent',
|
|
1763
1764
|
shape: 'square',
|
|
1764
1765
|
ellipticity: 0.6,
|
|
1765
|
-
gridSize:
|
|
1766
|
+
gridSize: 1,
|
|
1766
1767
|
rotateRatio: 1,
|
|
1767
1768
|
minRotation: -Math.PI / 4,
|
|
1768
1769
|
maxRotation: Math.PI / 4,
|