-
Notifications
You must be signed in to change notification settings - Fork 19
/
index.html
158 lines (143 loc) · 5.45 KB
/
index.html
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<html lang="en">
<head>
<title>svelte-heatmap</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js" integrity="sha256-4iQZ6BVL4qNKlQ27TExEhBN1HFPvAvAMbFavKKosSWQ=" crossorigin="anonymous"></script>
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet">
</head>
<body>
<div class="max-w-4xl mx-auto p-6">
<div class="mb-12">
<h1 class="text-3xl">svelte-heatmap</h1>
<a class="hover:underline" href="https://github.com/scottbedard/svelte-heatmap">
https://github.com/scottbedard/svelte-heatmap
</a>
</div>
<div class="mb-12" id="weekly"></div>
<div class="mb-12" id="monthly"></div>
<!-- options -->
<div class="text-sm">
<label class="block mb-4">
Allow Overflow<br />
<input
class="mr-2"
checked="checked"
id="allowOverflow"
type="checkbox" />
</label>
<label class="block mb-4">
Cell Gap<br />
<input
id="cellGap"
max="5"
min="0"
step="0.001"
type="range"
value="3" />
</label>
<label class="block mb-4">
Cell Radius<br />
<input
id="cellRadius"
max="5"
min="0"
step="0.001"
type="range"
value="1" />
</label>
<button
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"
id="seed">
Seed
</button>
</div>
</div>
<script src="./dist/index.umd.js"></script>
<script>
/**
* Generate a random number.
* @param {number} min
* @param {number} max
* @return {number}
*/
function rand(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
/**
* Generate dummy data for a heatmap.
* @return {void}
*/
function generateFakeData() {
const data = [];
const date = moment().subtract(1, 'year');
const now = moment();
while (date.isBefore(now)) {
data.push({
date: date.toDate(),
value: rand(0, 4),
});
date.add(1, 'day');
}
return data;
}
/**
* Examples
*/
const fakeData = generateFakeData();
const cellGap = Number(document.querySelector('#cellGap').value);
const cellRadius = Number(document.querySelector('#cellRadius').value);
const weekly = new SvelteHeatmap({
props: {
allowOverflow: true,
cellGap: cellGap,
cellRadius: cellRadius,
data: fakeData,
endDate: moment().toDate(),
startDate: moment().subtract(1, 'year').toDate(),
view: 'weekly',
},
target: document.querySelector('#weekly'),
});
const monthly = new SvelteHeatmap({
props: {
allowOverflow: true,
cellGap: cellGap,
cellRadius: cellRadius,
colors: ['#a1dab4', '#42b6c4', '#2c7fb9', '#263494'],
data: fakeData,
emptyColor: '#ecedf0',
monthGap: 20,
startDate: moment().subtract(5, 'months').toDate(),
endDate: moment().toDate(),
view: 'monthly',
},
target: document.querySelector('#monthly'),
});
/**
* Options
*/
document.querySelector('#allowOverflow').addEventListener('change', (e) => {
const allowOverflow = e.target.checked;
monthly.$set({ allowOverflow });
weekly.$set({ allowOverflow });
});
document.querySelector('#cellGap').addEventListener('input', (e) => {
const cellGap = Number(e.target.value);
monthly.$set({ cellGap });
weekly.$set({ cellGap });
});
document.querySelector('#cellRadius').addEventListener('input', (e) => {
const cellRadius = Number(e.target.value);
monthly.$set({ cellRadius });
weekly.$set({ cellRadius });
});
/**
* Generate
*/
document.querySelector('#seed').addEventListener('click', () => {
const data = generateFakeData();
monthly.$set({ data });
weekly.$set({ data });
});
</script>
</body>
</html>