-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
41 lines (33 loc) · 1.05 KB
/
script.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
import data from './data.js';
const bars = document.querySelectorAll('.bar');
const weekdays = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'];
let max = 0;
const today = new Date().getDay() - 1;
if (today < 0) {
today = 6;
}
data.forEach((day, index) => {
const bar = bars[index];
bar.previousElementSibling.innerHTML = `$${day.amount}`;
if (day.amount > max) {
max = day.amount;
}
});
bars.forEach(bar => {
// Mouse enter/leave to show dollar amounts
bar.addEventListener('mouseenter', () => {
bar.previousElementSibling.classList.remove('hidden');
});
bar.addEventListener('mouseleave', () => {
bar.previousElementSibling.classList.add('hidden');
});
// Adjust bar height depending on dollar amount / max for the week
const graphHeight = bar.parentElement.parentElement.clientHeight;
const amt = +bar.previousElementSibling.innerHTML.slice(1);
const height = (graphHeight * amt)/max;
bar.style.height = `${height}px`;
// Assign blue color for today's weekday
if (bar.parentElement.id === weekdays[today]) {
bar.classList.add('today');
}
});