-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
308 lines (232 loc) · 7.2 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
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<style>
body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
svg {fill:black; float:left}
.graph .axis {
stroke-width: 1;
}
.graph .axis .tick line {
stroke: black;
}
.graph .axis .tick text {
fill: black;
font-size: 0.7em;
}
.graph .axis .domain {
fill: none;
stroke: black;
}
.graph .group {
fill: none;
stroke: black;
stroke-width: 1.5;
}
/* CSS Document */
body {
font:12px arial;
color: #222;
text-align:center;
padding:35px; }
form, p, span {
margin:0;
padding:0; }
input { font:12px arial; }
a {
color:#0000FF;
text-decoration:none; }
a:hover { text-decoration:underline; }
#wrapper, #loginform {
margin:0 auto;
padding-bottom:25px;
background:#EBF4FB;
width:504px;
border:1px solid #ACD8F0; }
#loginform { padding-top:18px; }
#loginform p { margin: 5px; }
#chatbox {
text-align:left;
margin:0 auto;
margin-bottom:25px;
padding:10px;
background:#fff;
height:270px;
width:430px;
border:1px solid #ACD8F0;
overflow:auto; }
#usermsg {
width:395px;
border:1px solid #ACD8F0; }
#submit { width: 60px; }
.error { color: #ff0000; }
#menu { padding:12.5px 25px 12.5px 25px; }
.welcome { float:left; }
.logout { float:right; }
.msgln { margin:0 0 2px 0; }
</style>
</head>
<body>
<h2>Twitter Sentiment</h2><h3>Bitcoin</h3>
<div class="tweets">Tweets</div>
<div class="graphPolar"></div>
<div class="graphPolar"></div>
<div id="wrapper">
<div id="menu">
<p class="welcome">Welcome, <b></b></p>
<div style="clear:both"></div>
</div>
<div id="chatbox"></div>
</form>
</div>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script>
// jQuery Document
$(document).ready(function(){
});
var milliseconds = 300
setInterval(getData, milliseconds);
//getData();
//setInterval (loadLog, 2500);
//window.setTimeout(getData(), milliseconds);
//getData();
function getData(){
d3.json("http://169.226.135.210:3000/", function(error, data){
if(error){
console.log(error)
}
console.log(data)
//d3.select("body").text(data.response)
var tweets = data;
//auto scrolling
function loadLog(){
var oldscrollHeight = $("#chatbox").attr("scrollHeight") - 20; //Scroll height before the request
$.ajax({
url: "http://localhost:8888/",
cache: false,
success: function(html){
$("#chatbox").html(html); //Insert chat log into the #chatbox div
//Auto-scroll
var newscrollHeight = $("#chatbox").attr("scrollHeight") - 20; //Scroll height after the request
if(newscrollHeight > oldscrollHeight){
$("#chatbox").animate({ scrollTop: newscrollHeight }, 'normal'); //Autoscroll to bottom of div
}
},
});
}
//send data to the page in tweet form
$('.tweets').text(data[1]);
$('#chatbox').text(data);
//for(var tweet=0; tweet<data.length; tweet++){
// console.log(data[tweet])
// $('#chatbox').text(data[tweet]);
// $('#chatbox').text(data[tweet]);
//}
makePolarityGraphs(tweets);
//makeSubjectivityGraphs(tweets);
})
}
function makePolarityGraphs(tweets){
//tweets = getData()
d3.select("svg").remove()
var svg = d3.select("body").append('svg').attr('width',960).attr('height',500),
margin = {top: 20, right: 20, bottom: 30, left: 50},
width = 900//+svg.attr("width") - margin.left - margin.right,
height = 450//+svg.attr("height") - margin.top - margin.bottom,
//d3.select svg .remove -makes it so only one at a time
//g = d3.select(svg.remove())
//d3.select( svg ).remove()
//clear svg before reloading
g = svg.append("g").attr("transform", "translate(" + margin.left + "," + margin.top + ")");
// var parseTime = d3.timeParse("%Y-%m-%dT %H:%M:%S");
var x = d3.scaleTime()
.rangeRound([0, width]);
var y = d3.scaleLinear()
.rangeRound([height, 0]);
var line = d3.line()
.x(function(d) { return x(d.time); })
.y(function(d) { return y(d.polarity); });
tweets = tweets.map(d => {
return {id: d[0] , time: new Date(d[1]), tweet:d[2], polarity:+d[3], subjectivity:+d[4]}
})
console.log('tweets',tweets)
x.domain(d3.extent(tweets, function(d) { return d.time; }));
console.log(d3.extent(tweets, function(d) { return d.time; }))
y.domain([-1,1]);
g.append("g")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(x))
.select(".domain")
.remove();
g.append("g")
.call(d3.axisLeft(y))
.append("text")
.attr("fill", "#000")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", "0.71em")
.attr("text-anchor", "end")
.text("Price ($)");
g.append("path")
.datum(tweets)
.attr("fill", "none")
.attr("stroke", "steelblue")
.attr("stroke-linejoin", "round")
.attr("stroke-linecap", "round")
.attr("stroke-width", 1.5)
.attr("d", line);
// })
}
function makeSubjectivityGraphs(tweets){
//tweets = getData()
var svg = d3.select("body").append('svg').attr('width',960).attr('height',500),
margin = {top: 20, right: 20, bottom: 30, left: 50},
width = 900//+svg.attr("width") - margin.left - margin.right,
height = 450//+svg.attr("height") - margin.top - margin.bottom,
g = svg.append("g").attr("transform", "translate(" + margin.left + "," + margin.top + ")");
// var parseTime = d3.timeParse("%Y-%m-%dT %H:%M:%S");
var x = d3.scaleTime()
.rangeRound([0, width]);
var y = d3.scaleLinear()
.rangeRound([height, 0]);
var line = d3.line()
.x(function(d) { return x(d.time); })
.y(function(d) { return y(d.subjectivity); });
tweets = tweets.map(d => {
return {id: d[0] , time: new Date(d[1]), tweet:d[2], polarity:+d[3], subjectivity:+d[4]}
})
console.log('tweets',tweets)
x.domain(d3.extent(tweets, function(d) { return d.time; }));
console.log(d3.extent(tweets, function(d) { return d.time; }))
y.domain([0,1]);
g.append("g")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(x))
.select(".domain")
.remove();
g.append("g")
.call(d3.axisLeft(y))
.append("text")
.attr("fill", "#000")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", "0.71em")
.attr("text-anchor", "end")
.text("Price ($)");
g.append("path")
.datum(tweets)
.attr("fill", "none")
.attr("stroke", "steelblue")
.attr("stroke-linejoin", "round")
.attr("stroke-linecap", "round")
.attr("stroke-width", 1.5)
.attr("d", line);
// })
}
</script>
</body>
</html>