-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweeks.html
145 lines (118 loc) · 4.3 KB
/
weeks.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
<html>
<head>
<title>My life in weeks</title>
<meta charset='UTF-8'/>
<style>
.week {
width: 10px;
height: 10px;
border: 1px solid black;
display: inline-block;
margin: 2px;
}
.birth {
background-color: red;
}
.death {
background-color: black;
}
.life-event {
background-color: violet;
}
.no-event {
background-color: lightgrey;
}
.enjoyment {
background-color: yellow;
}
.enjoyment-bad {
background-color: yellow;
}
.usefulness {
background-color: blue;
}
.usefulness-unhappy {
background-color: blue;
}
.ideal {
background-color: green;
}
.failure {
background-color: grey;
}
.year-label {
display: inline-block;
width: 4em;
margin-right: 4px;
text-align: right;
}
#container {
width: 920px;
text-align: center;
margin: auto;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>
<script src="https://unpkg.com/popper.js@1"></script>
<script src="https://unpkg.com/tippy.js@4"></script>
<script src="weeks.js"></script>
<script type="text/javascript">
const birthDate = moment("1982-05-26");
const deathDate = moment("2057-07-27")
const current = moment();
function mapEvents(events) {
const result = {};
for (dateStr in events) {
let ev = moment(dateStr);
if (!(ev.year() in result)) {
result[ev.year()] = {};
}
result[ev.year()][ev.week()] = events[dateStr];
}
return result;
}
function main() {
const cont = document.getElementById('container');
const eventMap = mapEvents(events);
const isInMyLife = function(year, week) {
return (year > birthDate.year() || week > birthDate.week())
&& (year < current.year() || (year == current.year() && week < current.week()));
}
const createYear = function(yearNo) {
const year = yearNo + birthDate.year();
const label = document.createElement('div');
label.className = 'year-label';
label.appendChild(document.createTextNode(year));
cont.appendChild(label)
for (let week = 0; week < 52; ++week) {
const weekElement = document.createElement('div');
weekElement.className = "week";
if (year == birthDate.year() && week == birthDate.week()) {
weekElement.className += ' birth';
tippy(weekElement, { 'content': 'Megszülettem' });
}
else if (year == deathDate.year() && week == deathDate.week()) {
weekElement.className += ' death';
tippy(weekElement, { 'content': 'Várható élettartam vége' });
} else if (year in eventMap && week in eventMap[year]) {
weekElement.className += ' ' + eventMap[year][week]['type'];
if (eventMap[year][week]['description']) {
tippy(weekElement, {'content': eventMap[year][week]['description'] })
}
} else if (isInMyLife(year, week)) {
weekElement.className += ' no-event'
}
cont.appendChild(weekElement);
}
cont.appendChild(document.createElement('br'));
};
for (let year = 0; year < 90; ++year) {
createYear(year);
}
}
window.addEventListener('load', main);
</script>
</head>
<body>
<div id='container'></div>
</body>