diff --git a/src/modules/chart/index.ts b/src/modules/chart/index.ts index 2d0869a..8fe75c9 100644 --- a/src/modules/chart/index.ts +++ b/src/modules/chart/index.ts @@ -47,7 +47,7 @@ export default class extends Module { const data = await this.ai.api('charts/user/notes', { span: 'day', limit: 30, - userId: params.userId + userId: params.user.id }); chart = { @@ -59,6 +59,21 @@ export default class extends Module { data: data.diffs.renote }] }; + } else if (type === 'followers') { + const data = await this.ai.api('charts/user/following', { + span: 'day', + limit: 30, + userId: params.user.id + }); + + chart = { + title: `@${params.user.username}さんのフォロワー数`, + datasets: [{ + data: data.local.followers.total + }, { + data: data.remote.followers.total + }] + }; } else if (type === 'notes') { const data = await this.ai.api('charts/notes', { span: 'day', @@ -90,18 +105,24 @@ export default class extends Module { @autobind private async mentionHook(msg: Message) { - if (msg.includes(['チャート'])) { - this.log('Chart requested'); - const file = await this.genChart('userNotes', { - userId: msg.userId - }); - this.log('Replying...'); - msg.replyWithFile(serifs.chart.foryou, file); - return { - reaction: 'like' - }; - } else { + if (!msg.includes(['チャート'])) { return false; + } else { + this.log('Chart requested'); } + + let type = 'userNotes'; + if (msg.includes(['フォロワー'])) type = 'followers'; + + const file = await this.genChart(type, { + user: msg.user + }); + + this.log('Replying...'); + msg.replyWithFile(serifs.chart.foryou, file); + + return { + reaction: 'like' + }; } } diff --git a/src/modules/chart/render-chart.ts b/src/modules/chart/render-chart.ts index c9d1b56..c4ff1f6 100644 --- a/src/modules/chart/render-chart.ts +++ b/src/modules/chart/render-chart.ts @@ -46,6 +46,14 @@ export function renderChart(chart: Chart) { ctx.beginPath(); ctx.fillRect(0, 0, width, height); + // Draw title + if (chart.title) { + ctx.font = '35px CustomFont'; + const t = ctx.measureText(chart.title); + ctx.fillStyle = colors.text; + ctx.fillText(chart.title, (width / 2) - (t.width / 2), 128); + } + const xAxisCount = chart.datasets[0].data.length; const serieses = chart.datasets.length; @@ -153,6 +161,8 @@ export function renderChart(chart: Chart) { // https://github.com/apexcharts/apexcharts.js/blob/master/src/modules/Scales.js // This routine creates the Y axis values for a graph. function niceScale(lowerBound: number, upperBound: number, ticks: number): number[] { + if (lowerBound === 0 && upperBound === 0) return [0]; + // Calculate Min amd Max graphical labels and graph // increments. The number of ticks defaults to // 10 which is the SUGGESTED value. Any tick value