koishi-plugin-chat-analyse 1.3.3 → 1.3.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.
Files changed (2) hide show
  1. package/lib/index.js +29 -16
  2. 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: 60, left: 40 };
1699
+ const padding = { top: 20, right: 30, bottom: 80, left: 40 };
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) => padding.left + index / (labels.length - 1) * chartWidth, "getX");
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 / 10) === 0) {
1719
+ if (index % Math.ceil(labels.length / 12) === 0) {
1713
1720
  const x = getX(index);
1714
- svgElements += `<text x="${x}" y="${height - padding.bottom + 15}" font-size="10" fill="var(--sub-text-color)" text-anchor="middle">${label}</text>`;
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 = this.COLOR_PALETTES[0][seriesIndex % this.COLOR_PALETTES[0].length];
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
- let legendX = padding.left;
1723
- const legendY = height - padding.bottom + 40;
1724
- series.forEach((s, seriesIndex) => {
1725
- const color = this.COLOR_PALETTES[0][seriesIndex % this.COLOR_PALETTES[0].length];
1726
- svgElements += `<rect x="${legendX}" y="${legendY - 8}" width="12" height="8" fill="${color}" rx="2"/>`;
1727
- const textElement = `<text x="${legendX + 18}" y="${legendY}" font-size="12" fill="var(--text-color)">${s.name}</text>`;
1728
- svgElements += textElement;
1729
- legendX += 25 + s.name.length * 8;
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;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-chat-analyse",
3
3
  "description": "强大而全面的聊天数据分析,支持统计命令,发言,消息类型,活跃度,支持发言排行和生成词云",
4
- "version": "1.3.3",
4
+ "version": "1.3.4",
5
5
  "contributors": [
6
6
  "Yis_Rime <yis_rime@outlook.com>"
7
7
  ],