-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
69 lines (64 loc) · 2.12 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
<!DOCTYPE html>
<html>
<head>
<title>Reactive Extensions Click Stream</title>
<link rel="stylesheet" href="site.css">
<link href='https://fonts.googleapis.com/css?family=Droid+Sans' rel='stylesheet' type='text/css'>
</head>
<body>
<div id="container">
<h1>Click events grouped per second</h1>
<ul id="line">
</ul>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/4.0.7/rx.all.js"></script>
<script>
Rx.config.useNativeEvents = true;
//1 second = 30px;
var oneSecond = 30;
var colorCount = 4;
var clickCount = 0;
var startDate = Date.now();
var timeLine = document.getElementById("line");
var viewportHeight = window.innerHeight;
var container = document.getElementById("container");
var titleHeight = document.querySelector("h1").clientHeight;
function growBox() {
var diff = Date.now() - startDate;
var seconds = diff / 1000;
var newHeight = (seconds * oneSecond);
timeLine.style.height = newHeight + "px";
if (newHeight > viewportHeight - titleHeight) {
container.style.top = -(newHeight - viewportHeight + titleHeight ) + "px";
}
if (seconds < 180)
window.requestAnimationFrame(growBox);
};
window.requestAnimationFrame(growBox);
var clickStream = Rx.Observable.fromEvent(document, "click");
clickStream.map(function () {
clickCount++;
return "circle-" + (clickCount % colorCount + 1);
})
.bufferWithTime(1000)
.filter(function (clicks) {
return clicks.length;
})
.forEach(function (clicks) {
console.log(clicks.length);
var li = document.createElement("li");
li.classList.add("circles");
clicks.forEach(function (click) {
var span = document.createElement("span");
span.classList.add("circle");
span.classList.add(click);
li.appendChild(span);
});
var diff = Date.now() - startDate;
var seconds = diff / 1000;
li.style.top = (seconds * oneSecond - oneSecond / 2) + "px";
timeLine.appendChild(li);
})
</script>
</body>
</html>