-
Notifications
You must be signed in to change notification settings - Fork 0
/
timeline.html
217 lines (193 loc) · 6.35 KB
/
timeline.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<!DOCTYPE html>
<html>
<head>
<style>
#details > div {
margin-top: 6px;
}
.tagline {
font-size: large;
font-weight: bold;
}
.tech-sticker {
margin: 4px;
background-color: cadetblue;
border-radius: 3px;
padding: 3px;
user-select: none;
}
.tech-sticker-list {
margin-top: 4px;
}
.extras {
font-size: small;
}
</style>
<script>
(function (i, s, o, g, r, a, m) {
i["GoogleAnalyticsObject"] = r;
(i[r] =
i[r] ||
function () {
(i[r].q = i[r].q || []).push(arguments);
}),
(i[r].l = 1 * new Date());
(a = s.createElement(o)), (m = s.getElementsByTagName(o)[0]);
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m);
})(
window,
document,
"script",
"https://www.google-analytics.com/analytics.js",
"ga"
);
ga("create", "UA-53641010-10", "auto");
ga("send", "pageview");
</script>
</head>
<body>
<script
type="text/javascript"
src="https://www.gstatic.com/charts/loader.js"
></script>
<div>Click the timeline to browse</div>
<div id="timeline" style="height: 300px"></div>
<div id="sums"></div>
<hr />
<div id="details"></div>
<script>
var A_MONTH = 1000 * 60 * 60 * 24 * 30.5;
var A_YEAR = 1000 * 60 * 60 * 24 * 365;
window.data = [];
google.charts.load("current", { packages: ["timeline"] });
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
fetch("./data/employment.json")
.then(
(result) => result.json(),
(err) => console.error(err)
)
.then(
(json) => {
var data = parse(json);
var container = document.getElementById("timeline");
var chart = new google.visualization.Timeline(container);
google.visualization.events.addListener(
chart,
"select",
selectHandler.bind(null, chart, data)
);
var dataTable = new google.visualization.DataTable();
dataTable.addColumn({ type: "string", id: "Category" });
dataTable.addColumn({ type: "string", id: "Name" });
dataTable.addColumn({ type: "date", id: "Start" });
dataTable.addColumn({ type: "date", id: "End" });
dataTable.addRows(data);
chart.draw(dataTable);
renderSums(data);
},
(err) => {
console.error(err);
}
);
}
function parse(jsonData) {
var dataSet = jsonData.map((x) => {
var row = [
x.category,
x.name,
new Date(x.from),
new Date(x.to || Date.now()),
];
row.id = x.id;
row.extras = x.extras;
row.category = x.category;
row.name = x.name;
row.from = new Date(x.from);
row.to = new Date(x.to || Date.now());
row.description = x.description;
row.position = x.position;
row.location = x.location;
return row;
});
return dataSet;
}
function renderSums(data) {
var schools = data.filter(
(x) =>
x.name.toLowerCase().indexOf("bsc") >= 0 ||
x.name.toLowerCase().indexOf("msc") >= 0
);
var work = data.filter((x) => x.category.toLowerCase() == "work");
var timeReducer = (total, next) => total + (next.to - next.from);
var totalSchoolTime = schools.reduce(timeReducer, 0);
var totalWorkTime = work.reduce(timeReducer, 0);
document.getElementById("sums").innerHTML = `
<div> Total university time: ~ ${asTime(totalSchoolTime)} </div>
<div> Total work experience: ~ ${asTime(totalWorkTime)} </div>
`;
}
function selectHandler(chart, data) {
var selectedObjects = chart.getSelection();
if (selectedObjects.length !== 1) {
clearDetails();
} else {
var obj = data[selectedObjects[0].row];
renderDetails(obj);
ga("send", "timeline", "select", obj.name, obj.id);
}
}
function asTime(timeSpan) {
var years = (timeSpan / A_YEAR) | 0;
var months = ((timeSpan % A_YEAR) / A_MONTH) | 0;
var pluralized = (timeUnit, count) =>
count == 0
? ""
: count == 1
? `1 ${timeUnit}`
: `${count} ${timeUnit}s`;
return `${pluralized("year", years)} ${pluralized("month", months)}`;
}
function renderDetails(obj) {
var tagline = "";
if (obj.category == "Work") {
tagline = `${obj.position} @ ${obj.name}, ${obj.location}`;
} else {
tagline = `Studying ${obj.name} @ ${obj.category}, ${obj.location}`;
}
var duration = `${obj.from.toLocaleDateString()} - ${obj.to.toLocaleDateString()} (~${asTime(
obj.to - obj.from
)})`;
var description = obj.description;
var extras = "";
var techAsStickerList = (x) =>
x.map((tech) => `<span class='tech-sticker'>${tech}</span>`).join("");
if (obj.extras.thesis) {
extras = `<div class="thesis">
<div class="tesis-title"> Thesis: ${
obj.extras.thesis.title
} </div>
<div> ${obj.extras.thesis.description} </div>
<div class='tech-sticker-list'> ${techAsStickerList(
obj.extras.thesis.technologies
)} </div>
</div>`;
} else if (obj.extras.technologies) {
extras = `<div class='tech-sticker-list'> ${techAsStickerList(
obj.extras.technologies
)} </div>`;
}
document.getElementById("details").innerHTML = `
<div class='tagline'> ${tagline}, <i class='duration'> ${duration} </i></div>
<div class='position-description'> ${description} </div>
<div class='extras'> ${extras} </div>
`;
}
function clearDetails() {
document.getElementById("details").innerHTML = "";
}
</script>
</body>
</html>