mirror of
https://github.com/syuilo/ai.git
synced 2024-11-25 06:01:07 +00:00
chart
This commit is contained in:
parent
2c74b27097
commit
2d6f6dc7ae
|
@ -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(['チャート'])) {
|
||||
if (!msg.includes(['チャート'])) {
|
||||
return false;
|
||||
} else {
|
||||
this.log('Chart requested');
|
||||
const file = await this.genChart('userNotes', {
|
||||
userId: msg.userId
|
||||
}
|
||||
|
||||
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'
|
||||
};
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue