koishi-plugin-chat-analyse 1.5.9 → 1.6.1
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 +23 -15
- package/package.json +1 -1
- package/readme.md +1 -0
package/lib/index.js
CHANGED
|
@@ -1766,18 +1766,30 @@ var Renderer = class {
|
|
|
1766
1766
|
async *renderWordCloud(data, config) {
|
|
1767
1767
|
const { title, time, words } = data;
|
|
1768
1768
|
if (!words?.length) return;
|
|
1769
|
-
const wordsJson = JSON.stringify(words);
|
|
1770
1769
|
const weights = words.map((w) => w[1]);
|
|
1771
1770
|
const maxWeight = Math.max(...weights, 1);
|
|
1772
1771
|
const minWeight = Math.max(Math.min(...weights), 1);
|
|
1773
|
-
const wordCount = words.length;
|
|
1774
|
-
let calculatedMaxFontSize = Math.round(2560 / Math.pow(wordCount, 0.66));
|
|
1775
|
-
let calculatedMinFontSize = Math.round(calculatedMaxFontSize / 6);
|
|
1776
|
-
const maxFontSize = Math.max(4, Math.min(128, calculatedMaxFontSize));
|
|
1777
|
-
const minFontSize = Math.max(4, Math.min(maxFontSize, calculatedMinFontSize));
|
|
1778
1772
|
const logMaxWeight = Math.log1p(maxWeight);
|
|
1779
1773
|
const logMinWeight = Math.log1p(minWeight);
|
|
1780
|
-
const logWeightRange = logMaxWeight - logMinWeight
|
|
1774
|
+
const logWeightRange = logMaxWeight - logMinWeight;
|
|
1775
|
+
const getRelativeFontSize = /* @__PURE__ */ __name((size) => {
|
|
1776
|
+
if (logWeightRange <= 0) return 1;
|
|
1777
|
+
const normalizedWeight = (Math.log1p(size) - logMinWeight) / logWeightRange;
|
|
1778
|
+
return 0.05 + 0.95 * normalizedWeight;
|
|
1779
|
+
}, "getRelativeFontSize");
|
|
1780
|
+
let estimatedCurrentArea = 0;
|
|
1781
|
+
const relativeFontSizes = words.map((word) => getRelativeFontSize(word[1]));
|
|
1782
|
+
for (let i = 0; i < words.length; i++) {
|
|
1783
|
+
const wordText = words[i][0];
|
|
1784
|
+
const relativeSize = relativeFontSizes[i];
|
|
1785
|
+
estimatedCurrentArea += Math.pow(relativeSize, 2) * wordText.length * 0.6;
|
|
1786
|
+
}
|
|
1787
|
+
const scalingFactor = Math.sqrt(600 * 600 / Math.max(1, estimatedCurrentArea));
|
|
1788
|
+
const wordList = words.map((word, i) => {
|
|
1789
|
+
let finalSize = relativeFontSizes[i] * scalingFactor;
|
|
1790
|
+
finalSize = Math.max(4, Math.min(128, finalSize));
|
|
1791
|
+
return [word[0], finalSize];
|
|
1792
|
+
});
|
|
1781
1793
|
const cardHtml = `
|
|
1782
1794
|
<div class="container" style="width: 600px;">
|
|
1783
1795
|
<div class="header">
|
|
@@ -1792,19 +1804,15 @@ var Renderer = class {
|
|
|
1792
1804
|
<script>
|
|
1793
1805
|
const canvas = document.getElementById('wordcloud-container');
|
|
1794
1806
|
const options = {
|
|
1795
|
-
list: ${wordsJson},
|
|
1796
1807
|
fontFamily: ${JSON.stringify(config.fontFamily)},
|
|
1797
|
-
weightFactor: (size) => {
|
|
1798
|
-
if (${maxWeight} === ${minWeight}) return (${minFontSize} + ${maxFontSize}) / 2;
|
|
1799
|
-
const normalizedWeight = (Math.log1p(size) - ${logMinWeight}) / (${logWeightRange});
|
|
1800
|
-
return ${minFontSize} + normalizedWeight * (${maxFontSize} - ${minFontSize});
|
|
1801
|
-
},
|
|
1802
1808
|
color: ${JSON.stringify(config.color)},
|
|
1803
1809
|
shape: ${JSON.stringify(config.shape)},
|
|
1810
|
+
rotationSteps: ${config.rotationSteps},
|
|
1804
1811
|
ellipticity: ${config.ellipticity},
|
|
1805
1812
|
minRotation: ${config.minRotation},
|
|
1806
1813
|
maxRotation: ${config.maxRotation},
|
|
1807
|
-
|
|
1814
|
+
list: ${JSON.stringify(wordList)},
|
|
1815
|
+
weightFactor: (size) => size,
|
|
1808
1816
|
backgroundColor: 'transparent',
|
|
1809
1817
|
drawOutOfBound: true,
|
|
1810
1818
|
clearCanvas: false,
|
|
@@ -2541,7 +2549,7 @@ var Config3 = import_koishi7.Schema.intersect([
|
|
|
2541
2549
|
enableSimilarActivity: import_koishi7.Schema.boolean().default(true).description("启用相似活跃分析")
|
|
2542
2550
|
}).description("高级分析配置"),
|
|
2543
2551
|
import_koishi7.Schema.object({
|
|
2544
|
-
MaxWords: import_koishi7.Schema.number().min(0).default(
|
|
2552
|
+
MaxWords: import_koishi7.Schema.number().min(0).default(256).description("最大词量"),
|
|
2545
2553
|
ellipticity: import_koishi7.Schema.number().min(0).max(1).default(1).description("长宽比"),
|
|
2546
2554
|
rotationSteps: import_koishi7.Schema.number().min(0).default(3).description("旋转步数"),
|
|
2547
2555
|
minRotation: import_koishi7.Schema.number().min(-Math.PI).max(Math.PI).default(-Math.PI / 2).description("最小旋转角"),
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -168,6 +168,7 @@
|
|
|
168
168
|
| `minRotation` | **最小旋转角**:单词随机旋转的最小角度(弧度)。 | `-1.570796` (-π/2) |
|
|
169
169
|
| `maxRotation` | **最大旋转角**:单词随机旋转的最大角度(弧度)。 | `1.570796` (π/2) |
|
|
170
170
|
| `rotationSteps`| **旋转步数**:旋转角度的选择方式。0表示随机,2表示只在最小/最大角度中二选一。 | `3` |
|
|
171
|
+
| `MaxWords`| **最大词量**:词云显示的最多词汇数量。 | `256` |
|
|
171
172
|
|
|
172
173
|
## 📌 注意事项
|
|
173
174
|
|