forked from tin0312/walk-more-than-you-scroll
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsummary.js
62 lines (58 loc) · 1.38 KB
/
summary.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* eslint-disable no-unused-vars */
/* global Chart, stats, pixelToMeter */
async function createSummary() {
// set example data
const weekData = await stats.getWeeklyStats();
const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
/** @type {Chart.ChartData} */
const data = {
labels: ['S', 'M', 'T', 'W', 'T', 'F', 'S'],
datasets: [
{
label: 'Daily summary',
backgroundColor: 'rgba(9, 132, 255, 0.7)',
borderColor: 'rgba(9, 132, 255, 0.9)',
borderWidth: 2,
hoverBackgroundColor: '#40F8FF',
data: weekData.map(({ distance }) => pixelToMeter(distance)),
},
],
};
/** @type {Chart.ChartOptions} */
const options = {
title: {
text: 'Summary',
},
plugins: {
tooltip: {
callbacks: {
title: (tooltipItem) => {
return days[tooltipItem[0].dataIndex];
},
label: (tooltipItem) => `${tooltipItem.formattedValue}m`,
},
},
},
maintainAspectRatio: true,
scales: {
y: {
stacked: true,
grid: {
display: true,
color: 'rgba(255,99,132,0.2)',
},
},
x: {
grid: {
display: false,
},
},
},
};
new Chart('scroll-summary', {
type: 'bar',
options: options,
data: data,
});
}
createSummary();