This commit is contained in:
syuilo 2019-05-13 10:43:29 +09:00
parent 2c74b27097
commit 2d6f6dc7ae
No known key found for this signature in database
GPG key ID: BDC4C49D06AB9D69
2 changed files with 43 additions and 12 deletions

View file

@ -47,7 +47,7 @@ export default class extends Module {
const data = await this.ai.api('charts/user/notes', { const data = await this.ai.api('charts/user/notes', {
span: 'day', span: 'day',
limit: 30, limit: 30,
userId: params.userId userId: params.user.id
}); });
chart = { chart = {
@ -59,6 +59,21 @@ export default class extends Module {
data: data.diffs.renote 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') { } else if (type === 'notes') {
const data = await this.ai.api('charts/notes', { const data = await this.ai.api('charts/notes', {
span: 'day', span: 'day',
@ -90,18 +105,24 @@ export default class extends Module {
@autobind @autobind
private async mentionHook(msg: Message) { private async mentionHook(msg: Message) {
if (msg.includes(['チャート'])) { 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 {
return false; 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'
};
} }
} }

View file

@ -46,6 +46,14 @@ export function renderChart(chart: Chart) {
ctx.beginPath(); ctx.beginPath();
ctx.fillRect(0, 0, width, height); 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 xAxisCount = chart.datasets[0].data.length;
const serieses = chart.datasets.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 // https://github.com/apexcharts/apexcharts.js/blob/master/src/modules/Scales.js
// This routine creates the Y axis values for a graph. // This routine creates the Y axis values for a graph.
function niceScale(lowerBound: number, upperBound: number, ticks: number): number[] { function niceScale(lowerBound: number, upperBound: number, ticks: number): number[] {
if (lowerBound === 0 && upperBound === 0) return [0];
// Calculate Min amd Max graphical labels and graph // Calculate Min amd Max graphical labels and graph
// increments. The number of ticks defaults to // increments. The number of ticks defaults to
// 10 which is the SUGGESTED value. Any tick value // 10 which is the SUGGESTED value. Any tick value