koishi-plugin-chat-analyse 1.5.2 → 1.5.4
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 +9 -8
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1769,13 +1769,15 @@ var Renderer = class {
|
|
|
1769
1769
|
const wordsJson = JSON.stringify(words);
|
|
1770
1770
|
const weights = words.map((w) => w[1]);
|
|
1771
1771
|
const maxWeight = Math.max(...weights, 1);
|
|
1772
|
-
const minWeight = Math.min(...weights);
|
|
1772
|
+
const minWeight = Math.max(Math.min(...weights), 1);
|
|
1773
1773
|
const wordCount = words.length;
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
const
|
|
1774
|
+
let calculatedMaxFontSize = Math.round(1600 / Math.sqrt(wordCount));
|
|
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
|
+
const logMaxWeight = Math.log1p(maxWeight);
|
|
1779
|
+
const logMinWeight = Math.log1p(minWeight);
|
|
1780
|
+
const logWeightRange = logMaxWeight - logMinWeight <= 0 ? 1 : logMaxWeight - logMinWeight;
|
|
1779
1781
|
const cardHtml = `
|
|
1780
1782
|
<div class="container" style="width: 600px;">
|
|
1781
1783
|
<div class="header">
|
|
@@ -1794,7 +1796,7 @@ var Renderer = class {
|
|
|
1794
1796
|
fontFamily: ${JSON.stringify(config.fontFamily)},
|
|
1795
1797
|
weightFactor: (size) => {
|
|
1796
1798
|
if (${maxWeight} === ${minWeight}) return (${minFontSize} + ${maxFontSize}) / 2;
|
|
1797
|
-
const normalizedWeight = (size - ${
|
|
1799
|
+
const normalizedWeight = (Math.log1p(size) - ${logMinWeight}) / (${logWeightRange});
|
|
1798
1800
|
return ${minFontSize} + normalizedWeight * (${maxFontSize} - ${minFontSize});
|
|
1799
1801
|
},
|
|
1800
1802
|
color: ${JSON.stringify(config.color)},
|
|
@@ -1819,7 +1821,6 @@ var Renderer = class {
|
|
|
1819
1821
|
maskImage.onload = () => {
|
|
1820
1822
|
const ctx = canvas.getContext('2d');
|
|
1821
1823
|
ctx.drawImage(maskImage, 0, 0, canvas.width, canvas.height);
|
|
1822
|
-
options.clearCanvas = false; // Don't clear the mask image
|
|
1823
1824
|
WordCloud(canvas, options);
|
|
1824
1825
|
};
|
|
1825
1826
|
maskImage.src = maskImageUrl;
|