koishi-plugin-chat-analyse 1.3.3 → 1.3.5
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 +29 -16
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1691,15 +1691,22 @@ var Renderer = class {
|
|
|
1691
1691
|
*/
|
|
1692
1692
|
async *renderLineChart(data) {
|
|
1693
1693
|
const { title, time, series, labels } = data;
|
|
1694
|
+
const seriesColors = series.map(() => {
|
|
1695
|
+
const randomPalette = this.COLOR_PALETTES[Math.floor(Math.random() * this.COLOR_PALETTES.length)];
|
|
1696
|
+
return randomPalette[Math.floor(Math.random() * randomPalette.length)];
|
|
1697
|
+
});
|
|
1694
1698
|
const width = 600, height = 320;
|
|
1695
|
-
const padding = { top: 20, right: 20, bottom:
|
|
1699
|
+
const padding = { top: 20, right: 20, bottom: 70, left: 20 };
|
|
1696
1700
|
const chartWidth = width - padding.left - padding.right;
|
|
1697
1701
|
const chartHeight = height - padding.top - padding.bottom;
|
|
1698
1702
|
const maxVal = Math.max(1, ...series.flatMap((s) => s.data));
|
|
1699
1703
|
const yTickCount = 5;
|
|
1700
1704
|
const yTickValue = Math.ceil(maxVal / yTickCount);
|
|
1701
1705
|
const yAxisMax = yTickValue * yTickCount;
|
|
1702
|
-
const getX = /* @__PURE__ */ __name((index) =>
|
|
1706
|
+
const getX = /* @__PURE__ */ __name((index) => {
|
|
1707
|
+
if (labels.length <= 1) return padding.left + chartWidth / 2;
|
|
1708
|
+
return padding.left + index / (labels.length - 1) * chartWidth;
|
|
1709
|
+
}, "getX");
|
|
1703
1710
|
const getY = /* @__PURE__ */ __name((value) => padding.top + chartHeight - value / yAxisMax * chartHeight, "getY");
|
|
1704
1711
|
let svgElements = "";
|
|
1705
1712
|
for (let i = 0; i <= yTickCount; i++) {
|
|
@@ -1709,25 +1716,31 @@ var Renderer = class {
|
|
|
1709
1716
|
svgElements += `<text x="${padding.left - 8}" y="${y + 4}" font-size="10" fill="var(--sub-text-color)" text-anchor="end">${value}</text>`;
|
|
1710
1717
|
}
|
|
1711
1718
|
labels.forEach((label, index) => {
|
|
1712
|
-
if (index % Math.ceil(labels.length /
|
|
1719
|
+
if (index % Math.ceil(labels.length / 12) === 0) {
|
|
1713
1720
|
const x = getX(index);
|
|
1714
|
-
svgElements += `<text x="${x}" y="${height - padding.bottom +
|
|
1721
|
+
svgElements += `<text x="${x}" y="${height - padding.bottom + 20}" font-size="10" fill="var(--sub-text-color)" text-anchor="middle">${label}</text>`;
|
|
1715
1722
|
}
|
|
1716
1723
|
});
|
|
1717
1724
|
series.forEach((s, seriesIndex) => {
|
|
1718
|
-
const color =
|
|
1725
|
+
const color = seriesColors[seriesIndex];
|
|
1719
1726
|
const points = s.data.map((value, index) => `${getX(index)},${getY(value)}`).join(" ");
|
|
1720
1727
|
svgElements += `<polyline points="${points}" fill="none" stroke="${color}" stroke-width="2"/>`;
|
|
1721
1728
|
});
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
const
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1729
|
+
if (series.length > 1) {
|
|
1730
|
+
const ITEMS_PER_ROW = 3;
|
|
1731
|
+
const ROW_HEIGHT = 20;
|
|
1732
|
+
const LEGEND_START_Y = height - padding.bottom + 45;
|
|
1733
|
+
const columnWidth = chartWidth / ITEMS_PER_ROW;
|
|
1734
|
+
series.forEach((s, seriesIndex) => {
|
|
1735
|
+
const rowIndex = Math.floor(seriesIndex / ITEMS_PER_ROW);
|
|
1736
|
+
const colIndex = seriesIndex % ITEMS_PER_ROW;
|
|
1737
|
+
const legendX = padding.left + colIndex * columnWidth;
|
|
1738
|
+
const legendY = LEGEND_START_Y + rowIndex * ROW_HEIGHT;
|
|
1739
|
+
const color = seriesColors[seriesIndex];
|
|
1740
|
+
svgElements += `<rect x="${legendX}" y="${legendY - 8}" width="12" height="8" fill="${color}" rx="2"/>`;
|
|
1741
|
+
svgElements += `<text x="${legendX + 18}" y="${legendY}" font-size="12" fill="var(--text-color)">${s.name}</text>`;
|
|
1742
|
+
});
|
|
1743
|
+
}
|
|
1731
1744
|
const totalMessages = series.reduce((sum, s) => sum + s.data.reduce((a, b) => a + b, 0), 0);
|
|
1732
1745
|
const cardHtml = `
|
|
1733
1746
|
<div class="container">
|
|
@@ -1951,7 +1964,7 @@ var Stat = class {
|
|
|
1951
1964
|
})()));
|
|
1952
1965
|
}
|
|
1953
1966
|
if (this.config.enableRankStat) {
|
|
1954
|
-
cmd.subcommand("rankstat", "发言排行").usage("查询发言排行,可指定查询范围,默认当前群组。").option("user", "-u <user:string> 指定用户").option("guild", "-g <guildId:string> 指定群组").option("type", "-t <type:string> 指定类型").option("duration", "-n <hours:number> 指定时长", { fallback: 24 }).option("offset", "-o <hours:number> 指定偏移").option("all", "-a 全局统计").action(({ session, options }) => handleAction(session, (async () => {
|
|
1967
|
+
cmd.subcommand("rankstat", "发言排行").usage("查询发言排行,可指定查询范围,默认当前群组。").option("user", "-u <user:string> 指定用户").option("guild", "-g <guildId:string> 指定群组").option("type", "-t <type:string> 指定类型").option("duration", "-n <hours:number> 指定时长", { fallback: 24 }).option("offset", "-o <hours:number> 指定偏移", { fallback: 0 }).option("all", "-a 全局统计").action(({ session, options }) => handleAction(session, (async () => {
|
|
1955
1968
|
const scope = await this.parseScope(session, options);
|
|
1956
1969
|
if (scope.error) return scope.error;
|
|
1957
1970
|
const until = new Date(Date.now() - options.offset * import_koishi3.Time.hour);
|
|
@@ -1994,7 +2007,7 @@ var Stat = class {
|
|
|
1994
2007
|
})()));
|
|
1995
2008
|
}
|
|
1996
2009
|
if (this.config.enableActivity) {
|
|
1997
|
-
cmd.subcommand("activity", "活跃统计").usage("查询活跃统计,可指定查询范围,默认当前群组。").option("user", "-u <user:string> 指定用户").option("guild", "-g <guildId:string> 指定群组").option("duration", "-n <units:number> 指定时长", { fallback: 24 }).option("offset", "-o <units:number> 指定偏移").option("days", "-d 以天为粒度").option("all", "-a 全局统计").action(({ session, options }) => handleAction(session, (async () => {
|
|
2010
|
+
cmd.subcommand("activity", "活跃统计").usage("查询活跃统计,可指定查询范围,默认当前群组。").option("user", "-u <user:string> 指定用户").option("guild", "-g <guildId:string> 指定群组").option("duration", "-n <units:number> 指定时长", { fallback: 24 }).option("offset", "-o <units:number> 指定偏移", { fallback: 0 }).option("days", "-d 以天为粒度").option("all", "-a 全局统计").action(({ session, options }) => handleAction(session, (async () => {
|
|
1998
2011
|
const scope = await this.parseScope(session, options);
|
|
1999
2012
|
if (scope.error) return scope.error;
|
|
2000
2013
|
const timeUnit = options.days ? import_koishi3.Time.day : import_koishi3.Time.hour;
|