-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtesting2.html
222 lines (186 loc) · 6.24 KB
/
testing2.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
<!DOCTYPE html>
<head>
<title>StockEr</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js" charset="utf-8"></script>
<link rel="stylesheet" type="text/css" href="css/main.css">
<link rel="stylesheet" href="css/materialize.css">
<link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="shortcut icon" href="../favicon.ico">
<link rel="stylesheet" type="text/css" href="css/normalize.css" />
<link rel="stylesheet" type="text/css" href="fonts/font-awesome-4.2.0/css/font-awesome.min.css" />
<link rel="stylesheet" type="text/css" href="css/demo.css" />
<link rel="stylesheet" type="text/css" href="css/set2.css" />
<!-- Compiled and minified JavaScript -->
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.2/js/materialize.min.js"></script>
<script type="text/javascript" src="js/main.js"></script>
<script src="js/classie.js"></script>
<script src="js/stockjson.js"></script>
<script type="text/javascript" src="js/jquery.transit.js"></script>
</head>
<body>
<div id="twoThirds">
<div class="container">
<div class="row" id="title">
<h2><img src="StockAssist.png" width="5%"> StockAssist</h2>
</div>
<div class="row" id="input">
<form>
<span class="input input--fumi">
<input class="input__field input__field--fumi" type="text" id="input-23" />
<label class="input__label input__label--fumi" for="input-23">
<i class="fa fa-fw fa fa-search icon icon--fumi"></i>
<span class="input__label-content input__label-content--fumi">Stock Name</span>
</label>
</span>
</form>
</div>
<div class="row" id="click_row">
<div class="col s12"><a class="waves-effect waves-light btn center" id="click" href = "#hi">Lookup</a></div>
</div>
</div>
</div>
</body>
<script>
//all the json data
var jsonLines = [
{ "x1": 50, "y1": 50, "x2": 50, "y2": 350, "id": ""},
{ "x1": 50, "y1": 350, "x2": 350, "y2": 350, "id": ""},
{ "x1": 900, "y1": 550, "x2": 900, "y2": 750, "id": ""},
{ "x1": 900, "y1": 750, "x2": 1200, "y2": 750, "id": ""},
{ "x1": 50, "y1": 350, "x2": 110, "y2": 350, "id": "graph"},
{ "x1": 110, "y1": 350, "x2": 170, "y2": 350, "id": "graph"},
{ "x1": 170, "y1": 350, "x2": 230, "y2": 350, "id": "graph"},
{ "x1": 230, "y1": 350, "x2": 290, "y2": 350, "id": "graph"},
{ "x1": 290, "y1": 350, "x2": 350, "y2": 350, "id": "graph"},
{ "x1": 625, "y1": 500, "x2": 500, "y2": 300, "id": "needle"}];
var jsonRect = [
{ "x": 920, "y": 750, "width": 30, "height": 0, "color" : "red" },
{ "x": 1020, "y": 750, "width": 30, "height": 0, "color" : "red" },
{ "x": 1120, "y": 750, "width": 30, "height": 0, "color" : "red" }];
var jsonText = [
{ "x": 100, "y": 400, "text": "Stock History"},
{ "x": 920, "y": 780, "text": "Good"},
{ "x": 1020, "y": 780, "text": "Neutral"},
{ "x": 1120, "y": 780, "text": "Bad"},
{ "x": 500, "y": 500, "text": "Buy"},
{ "x": 700, "y": 500, "text": "Sell"},
{ "x": 900, "y": 100, "text": "Good Words"},
{ "x": 200, "y": 500, "text": "Bad Words"}];
var jsonCircles = [
{ "x_axis": 615, "y_axis": 420, "radius": 150}];
//creating the svg and binding everything to it
var data;
var svgContainer = d3.select("body").append("svg")
.attr("width", 1300)
.attr("height", 800)
.attr("id","hi");
var lines = svgContainer.selectAll("line")
.data(jsonLines)
.enter()
.append("line");
var rects = svgContainer.selectAll("rect")
.data(jsonRect)
.enter()
.append("rect");
var texts = svgContainer.selectAll("text")
.data(jsonText)
.enter()
.append("text");
var circles = svgContainer.selectAll("circle")
.data(jsonCircles)
.enter()
.append("circle");
//loading all the attributes to the objects
var lineAttributes = lines
.attr("x1", function (d) { return d.x1; })
.attr("y1", function (d) { return d.y1; })
.attr("x2", function (d) { return d.x2; })
.attr("y2", function (d) { return d.y2; })
.attr("stroke-width", 2)
.attr("stroke", "black");
var rectAttributes = rects
.attr("x", function (d) { return d.x; })
.attr("y", function (d) { return d.y; })
.attr("width", function (d) { return d.width; })
.attr("height", function (d) { return d.height; })
.attr("fill", function (d) { return d.color; });
var textLabels = texts
.attr("x", function(d) { return d.x; })
.attr("y", function(d) { return d.y; })
.text( function (d) { return d.text; })
.attr("font-family", "sans-serif")
.attr("font-size", "20px")
.attr("fill", "black");
var circleAttributes = circles
.attr("cx", function (d) { return d.x_axis; })
.attr("cy", function (d) { return d.y_axis; })
.attr("r", function (d) { return d.radius; })
.attr("fill-opacity", 0)
.attr("stroke-width", 2)
.attr("stroke", "black");
var words = ["hello", "there", "you"];
//what happens when you click the lookup button
$("#click").click(function(event) {
console.log("hello");
//getting the json request, putting it in data
d3.json("http://stockassist.azurewebsites.net/twitter?q="+$("#stock").val(), function(error, json) {
if (error) return console.warn(error);
data = json;
console.log(data);
visualizeit();
});
//doing transitions for the charts
d3.selectAll("rect").transition()
.delay(400)
.duration(600)
.attr("height",function(d,i){return (i+1)*50;})
.attr("y", function(d,i){return d.y-((i+1)*50);});
d3.selectAll("line").transition()
.delay(400)
.duration(600)
.attr("x2", function(d,i){
if(d.id == "needle"){
return d.x2 + 150;
}else{
return d.x2;
}
})
.attr("y1", function(d,i){
if(d.id == "graph"){
if(i%2){
return d.y1 - 50;
}else{
return d.y1 - 80;
}
}else{
return d.y1;
}
})
.attr("y2", function(d,i){
if(d.id == "graph"){
if(i%2){
return d.y2 - 80;
}else{
return d.y2 - 50;
}
}else{
return d.y2;
}
});
//trying to put words here
var texts2 = svgContainer.selectAll("text")
.data(words)
.enter()
.append("text")
.attr("x", 900)
.attr("y", function(d,i) { return 100+(i*100); })
.text( function (d) { return d; })
.attr("font-family", "sans-serif")
.attr("font-size", "20px")
.attr("fill", "black");
});
</script>