This commit is contained in:
syuilo 2019-05-13 10:56:17 +09:00
parent 2d6f6dc7ae
commit cd46ed7eff
No known key found for this signature in database
GPG key ID: BDC4C49D06AB9D69
2 changed files with 11 additions and 6 deletions

View file

@ -51,6 +51,7 @@ export default class extends Module {
}); });
chart = { chart = {
title: `@${params.user.username}さんの投稿数`,
datasets: [{ datasets: [{
data: data.diffs.normal data: data.diffs.normal
}, { }, {

View file

@ -3,11 +3,7 @@ import { createCanvas, registerFont } from 'canvas';
const width = 1024 + 256; const width = 1024 + 256;
const height = 512 + 256; const height = 512 + 256;
const margin = 128; const margin = 128;
const titleTextSize = 35;
const chartAreaX = margin;
const chartAreaY = margin;
const chartAreaWidth = width - (margin * 2);
const chartAreaHeight = height - (margin * 2);
const lineWidth = 16; const lineWidth = 16;
const yAxisThickness = 2; const yAxisThickness = 2;
@ -46,12 +42,20 @@ export function renderChart(chart: Chart) {
ctx.beginPath(); ctx.beginPath();
ctx.fillRect(0, 0, width, height); ctx.fillRect(0, 0, width, height);
let chartAreaX = margin;
let chartAreaY = margin;
let chartAreaWidth = width - (margin * 2);
let chartAreaHeight = height - (margin * 2);
// Draw title // Draw title
if (chart.title) { if (chart.title) {
ctx.font = '35px CustomFont'; ctx.font = `${titleTextSize}px CustomFont`;
const t = ctx.measureText(chart.title); const t = ctx.measureText(chart.title);
ctx.fillStyle = colors.text; ctx.fillStyle = colors.text;
ctx.fillText(chart.title, (width / 2) - (t.width / 2), 128); ctx.fillText(chart.title, (width / 2) - (t.width / 2), 128);
chartAreaY += titleTextSize;
chartAreaHeight -= titleTextSize;
} }
const xAxisCount = chart.datasets[0].data.length; const xAxisCount = chart.datasets[0].data.length;