forked from h2oai/h2o-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
209 lines (184 loc) · 7.31 KB
/
index.html
File metadata and controls
209 lines (184 loc) · 7.31 KB
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
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Storm Demo Live</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js" type="text/javascript"></script>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script>
// use to randomly place rain drops along the cloud
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
</script>
<style>
#demo {
width: 100%;
height: 100%;
position: relative;
}
#cloud,
#woof,
#predict,
#meow {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
}
#cloud {
z-index: 10;
}
#predict { z-index: 5; }
#cur {
position: relative;
top:45px;
left:10%;
width: 400px;
height:200px;
z-index:900;
}
#cat_cnt {
position: absolute;
top: 15px;
left: 50%;
z-index:900;
}
#ccnt {
position: absolute;
top: 15px;
left: 100%;
z-index:900;
font-size: 90px;
}
#dcnt {
position: absolute;
top: 15px;
left: 200%;
z-index:900;
font-size: 90px;
}
#dog_cnt {
position: absolute;
top: 10px;
left: 160%;
z-index:900;
}
</style>
</head>
<body>
<div id = "demo">
<div id="cloud"><img src="./cloud.png" style="width:100%;height:228px"></div>
<div id="meow"></div>
<div id="woof"></div>
<div id="predict"></div>
<div id="cur_val" style="display:none;">cat</div>
<div id="old" style="display:none;"></div>
</div>
<div id="cur">
<img id="cur_pic" src="./cat.png" style="display:none;">
<img id="cat_cnt" src="./cat.png">
<div id="ccnt" style="color: #ffffff;">0</div>
<img id="dog_cnt" src="./dog.png">
<div id="dcnt" style="color: #ffffff;">0</div>
</div>
<script>
var w = innerWidth;
var h = innerHeight;
// simple method to GET the latest predictions from Storm
function gogogo() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
var txt = xmlhttp.responseText;
txt = txt.split(',');
var predict = txt[1];
if (predict === undefined) return;
var isCat = predict == "cat";
var dogObs = isCat ? 0 : 1;
var catObs = isCat ? 1 : 0;
$('#dcnt').text(function(i, txt) { return parseInt($("#dcnt").text(), 10) + dogObs});
$('#ccnt').text(function(i, txt) { return parseInt($("#ccnt").text(), 10) + catObs});
$('#cur_val').text(predict);
document.getElementById("cur_pic").src="./".concat(predict).concat(".png");
}
};
xmlhttp.open("GET", "./out", true);
xmlhttp.send();
}
function rain() {
// data for each vis
var data = Array.apply(null, new Array(50)).map(Number.prototype.valueOf,0).map(function() { return getRandomInt(30, window.innerWidth - 100)} );
var data2= Array.apply(null, new Array(50)).map(Number.prototype.valueOf,0).map(function() { return getRandomInt(30, window.innerWidth - 100)} );
var data3= [60,innerWidth/5,innerWidth*2/5,3*innerWidth/5, 4*innerWidth/5, innerWidth];
// visualization references
var vis = d3.select("#meow").append("svg").attr("width", w+100).attr("height",innerHeight+100).style("display", "inline");
var vis2 =d3.select("#woof").append("svg").attr("width", w+100).attr("height",innerHeight+100).style("display", "inline");
var vis3 = d3.select("#predict").append("svg").attr("width", w+100).attr("height",innerHeight+100).style("display", "inline").attr("id", "pred");
// set of objects in each visualization
var ones = vis.selectAll("rect").data(data);
var zeros=vis2.selectAll("circle").data(data2);
var imgs = vis3.selectAll("image").data(data3);
// loop!
setInterval(function() {
// get the most recent prediction...
gogogo();
// drop the 'cat.png' or 'dog.png' based on the $("#cur_val").text() value
imgs.enter()
.append("svg:image")
.attr("xlink:href", function() { return "./".concat($("#cur_val").text()).concat(".png") })
.attr("x", function(d) { return d; })
.attr("y", "0")
.attr("width", "300")
.attr("height", "150")
.transition()
.delay(function () {
return getRandomInt(0, 1000);
})
.each("end", function () {
d3.select(this).transition().duration(1500).attr("y", innerHeight+200);
d3.select(this).transition().delay(2000).duration(1).style("opacity", 0).ease("exp").remove();
});
// build the straight line drops of rain
ones.enter().append("rect")
.attr("x", function (d) {
return d;
})
.attr("y", 50)
.attr("width", 2)
.attr("height", 10)
.style("border", "1px solid black")
.transition()
.delay(function () {
return getRandomInt(0, 1000);
})
.each("end", function () {
d3.select(this).transition().duration(1500).attr("y", innerHeight+200);
d3.select(this).transition().delay(2000).duration(1).style("opacity", 0).ease("exp").remove();
});
// build the circle drops of rain
zeros.enter().append("circle")
.attr("cx", function(d) { return d; })
.attr("cy", 200)
.attr("r", 5)
.attr("width", 2)
.attr("height", 25)
.attr("fill", "white")
.attr("stroke", "black")
.style("border", "1px solid black")
.transition()
.delay(function () {
return getRandomInt(500, 2000);
})
.each("end", function () {
d3.select(this).transition().duration(2000).attr("cy", innerHeight+200);
d3.select(this).transition().delay(2000).duration(1).style("opacity", 0).ease("exp").remove();
});
}, 1000);
}
// launch the whole thing...
$(document).ready(function() {rain();});
</script>
</body>
</html>