とりあえず一旦これで自動修正

This commit is contained in:
hina
2020-06-06 18:01:56 +09:00
parent 334c810b8d
commit edd7a6f4c8
12 changed files with 295 additions and 268 deletions

View File

@@ -1,5 +1,5 @@
import * as CalHeatMap from 'cal-heatmap';
import {subMonths} from 'date-fns';
import { subMonths } from 'date-fns';
if (document.getElementById('cal-heatmap')) {
new CalHeatMap().init({
@@ -11,6 +11,6 @@ if (document.getElementById('cal-heatmap')) {
start: subMonths(new Date(), 9),
range: 10,
data: JSON.parse(document.getElementById('count-by-day')!.textContent as string),
legend: [1, 2, 3, 4]
legend: [1, 2, 3, 4],
});
}

View File

@@ -1,6 +1,6 @@
import * as CalHeatMap from 'cal-heatmap';
import * as Chart from 'chart.js';
import {addMonths, format} from 'date-fns';
import { addMonths, format } from 'date-fns';
const graphData = JSON.parse(document.getElementById('graph-data')!.textContent as string);
@@ -10,34 +10,38 @@ function createLineGraph(id: string, labels: string[], data: any) {
type: 'line',
data: {
labels: labels,
datasets: [{
data: data,
backgroundColor: 'rgba(255, 99, 132, 0.2)',
borderColor: 'rgba(255, 99, 132, 1)',
borderWidth: 1
}]
datasets: [
{
data: data,
backgroundColor: 'rgba(255, 99, 132, 0.2)',
borderColor: 'rgba(255, 99, 132, 1)',
borderWidth: 1,
},
],
},
options: {
legend: {
display: false
display: false,
},
elements: {
line: {
tension: 0
}
tension: 0,
},
},
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
yAxes: [
{
ticks: {
beginAtZero: true,
},
},
],
},
tooltips: {
mode: 'index',
intersect: false,
}
}
},
},
});
}
@@ -47,29 +51,33 @@ function createBarGraph(id: string, labels: string[], data: any) {
type: 'bar',
data: {
labels: labels,
datasets: [{
data: data,
backgroundColor: 'rgba(255, 99, 132, 0.2)',
borderColor: 'rgba(255, 99, 132, 1)',
borderWidth: 1
}]
datasets: [
{
data: data,
backgroundColor: 'rgba(255, 99, 132, 0.2)',
borderColor: 'rgba(255, 99, 132, 1)',
borderWidth: 1,
},
],
},
options: {
legend: {
display: false
display: false,
},
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
yAxes: [
{
ticks: {
beginAtZero: true,
},
},
],
},
tooltips: {
mode: 'index',
intersect: false,
}
}
},
},
});
}
@@ -84,7 +92,7 @@ function createMonthlyGraphData(from: Date) {
values.push(graphData.monthlySum[yearAndMonth] || 0);
}
return {keys, values};
return { keys, values };
}
function getCurrentYear(): number {
@@ -106,12 +114,14 @@ if (document.getElementById('cal-heatmap')) {
start: new Date(getCurrentYear(), 0, 1, 0, 0, 0, 0),
range: 12,
data: graphData.dailySum,
legend: [1, 2, 3, 4]
legend: [1, 2, 3, 4],
});
}
if (document.getElementById('monthly-graph')) {
const {keys: monthlyKey, values: monthlySum} = createMonthlyGraphData(new Date(getCurrentYear(), 0, 1, 0, 0, 0, 0));
const { keys: monthlyKey, values: monthlySum } = createMonthlyGraphData(
new Date(getCurrentYear(), 0, 1, 0, 0, 0, 0)
);
createLineGraph('monthly-graph', monthlyKey, monthlySum);
}
if (document.getElementById('yearly-graph')) {