-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
310 lines (257 loc) · 10.3 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
309
310
<!DOCTYPE html>
<!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<html lang="en">
<head>
<meta charset="utf-8">
<title>MP's of Karnataka</title>
<script type="text/javascript" src="./d3/d3.v3.js"></script>
<script src="http://code.jquery.com/jquery-1.8.3.min.js" type="text/javascript" charset="utf-8"></script>
<script src="jquery.tipsy.js" type="text/javascript" charset="utf-8"></script>
<script src="crossfilter.js" type="text/javascript" charset="utf-8"></script>
<!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="jquery.better-autocomplete.js"></script> -->
<style type="text/css">
/* No style rules here yet */
.lower{
position: absolute;
left:100;
bottom:200;
}
.labelText{
padding-left: 20px;
}
#tooltip {
position: absolute;
width: 200px;
height: auto;
padding: 10px;
background-color: white;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
-webkit-box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.4);
-moz-box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.4);
box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.4);
pointer-events: none;
}
#tooltip.hidden {
display: none;
}
#tooltip p {
margin: 0;
font-family: sans-serif;
font-size: 16px;
line-height: 20px;
}
.tipsy { padding: 5px; font-size: 10px; position: absolute; z-index: 100000; }
.tipsy-inner { padding: 5px 8px 4px 8px; background-color: black; color: white; max-width: 200px; text-align: center; }
.tipsy-inner { border-radius: 3px; -moz-border-radius:3px; -webkit-border-radius:3px; }
.tipsy-arrow { position: absolute; background: url('images/tipsy.gif') no-repeat top left; width: 9px; height: 5px; }
.tipsy-n .tipsy-arrow { top: 0; left: 50%; margin-left: -4px; }
.tipsy-nw .tipsy-arrow { top: 0; left: 10px; }
.tipsy-ne .tipsy-arrow { top: 0; right: 10px; }
.tipsy-s .tipsy-arrow { bottom: 0; left: 50%; margin-left: -4px; background-position: bottom left; }
.tipsy-sw .tipsy-arrow { bottom: 0; left: 10px; background-position: bottom left; }
.tipsy-se .tipsy-arrow { bottom: 0; right: 10px; background-position: bottom left; }
.tipsy-e .tipsy-arrow { top: 50%; margin-top: -4px; right: 0; width: 5px; height: 9px; background-position: top right; }
.tipsy-w .tipsy-arrow { top: 50%; margin-top: -4px; left: 0; width: 5px; height: 9px; }
.tipsy { font-size:11px; margin-top:-10px;}
</style>
<link rel="stylesheet" href="css/normalize.css" />
<link rel="stylesheet" href="css/foundation.css" />
</head>
<body>
<!-- <div id="tooltip" class="hidden">
<p><strong>Important Label Heading</strong></p>
<p><span id="value">100</span>%</p>
</div> -->
<h1>MP's of Karnataka</h1>
<div style="float:left; padding-top:100px;">
<input id="one" type="checkbox" name = "party" value="bjp" class="lower" checked="checked">
<label for="bjp" class="labelText">BJP</label>
<br/><br/>
<input id="two" type="checkbox" name = "party" value="cong" class="lower" checked="checked">
<label for="cong" class="labelText">Congress</label>
<br/><br/>
<input id="three" type="checkbox" name = "party" value="jds" class="lower" checked="checked">
<label for="jds" class="labelText">JD(S)</label>
<br/><br/>
</div>
<!-- <input id="reset" class="lower">Reset</div> -->
<!-- <form id="search">
Legislator: <input type="text" />
<input type="submit" />
</form>
-->
<script type="text/javascript">
//Width and height
var w = 500;
var h = 300;
var padding = 20;
//Original data
var dataset;
d3.json("karnataka.json", function(data) {
dataset = data; //Once loaded, copy to dataset.
//console.log(data);
forced();
});
function forced(){
//Initialize a default force layout, using the nodes and edges in dataset
var force = d3.layout.force()
.nodes(dataset.nodes)
//.links(dataset.edges)
.size([w, h])
.linkDistance([5])
.charge([-20])
.start();
var colors = d3.scale.category10();
//Create SVG element
var svg = d3.select("body")
.append("svg")
.attr("width", w)
.attr("height", h);
/* var scaleY = d3.scale.linear()
.domain([d3.min(dataset, function(d) { return dataset.nodes[i]["ylat"]; }), d3.max(dataset, function(d) { return dataset.nodes[i]["ylat"]; })])
.range([1000- padding,padding]);
var scaleX = d3.scale.linear()
.domain([d3.min(dataset, function(d) { return dataset.nodes[i]["xlong"]; }),d3.max(dataset, function(d) { return dataset.nodes[i]["xlong"]; })])
.range([padding, 1000-padding]); */
//Create nodes as circles
var nodes = svg.selectAll("circle")
.data(dataset.nodes)
.enter()
//.append("g")
.append("circle")
//.attr("cx", function(d,i) { return dataset.nodes[i]["xlong"]; })
//.attr("cy", function(d,i) { return dataset.nodes[i]["ylat"]; })
.attr("r", 10)
.attr("class", "node")
.attr("style", "float:left")
.style("fill", function(d, i) {
//if(dataset.nodes)
//console.log(dataset.nodes[i]["Political party"]);
if (dataset.nodes[i]["Political party"] == "Indian National Congress") {
//console.log("Indian National Congress");
return colors(0);
}
else if (dataset.nodes[i]["Political party"] == "Bharatiya Janata Party") {
//console.log("Bharatiya Janata Party");
return colors(1);
}
else if (dataset.nodes[i]["Political party"] == "Janata Dal (Secular)") {
//console.log("Janata Dal (Secular)");
return colors(2);
}
})
/*.on("click", function(d,i){
d3.select("#tooltip")
//.style("left", xPosition + "px")
//.style("top", yPosition + "px")
.select("#value")
.text(dataset.nodes[i]["MP name"]);
//Show the tooltip
d3.select("#tooltip").classed("hidden", false);
})
//.on("mousemove", function(){return tooltip.style("top", (event.pageY-10)+"px").style("left",(event.pageX+10)+"px");})
.on("mouseout", function(){
d3.select("#tooltip").classed("hidden", true);}
)*/
.call(force.drag)
;
/* nodes.append("title")
.attr("id", "tooltip")
.attr("text-anchor", "middle")
.attr("font-family", "sans-serif")
.attr("font-size", "11px")
.attr("font-weight", "bold")
.attr("fill", "black")
.text(function(d,i) {
//console.log(dataset.nodes[i]["MP name"]);
//return "<div id='tooltip' class='hidden'><p>" + dataset.nodes[i]["MP name"] + "</p></div>";
return dataset.nodes[i]["MP name"];
});
*/
nodes.append("title")
.text(function(d,i) { return dataset.nodes[i]["MP name"]; });
$(".node").tipsy({ gravity: 's' });
/* d3.selectAll("#tooltip")
.on("click", function(d,i){
d3.select("#tooltip")
//.style("left", xPosition + "px")
//.style("top", yPosition + "px")
.select("#value")
.text(dataset.nodes[i]["MP name"]);
//Show the tooltip
d3.select("#tooltip").classed("hidden", false);
})
//.on("mousemove", function(){return tooltip.style("top", (event.pageY-10)+"px").style("left",(event.pageX+10)+"px");})
.on("mouseout", function(){
d3.select("#tooltip").classed("hidden", true);}
);*/
//Every time the simulation "ticks", this will be called
force.on("tick", function() {
nodes.attr("cx", function(d,i) { return d.x; })
.attr("cy", function(d,i) { return d.y; });
});
d3.selectAll("#one")
.on("change", function() {
//console.log("BJP");//Do something on click
svg.selectAll("circle").filter(function(d,i) {
//if(dataset.nodes[i]["Political party"] == "Bharatiya Janata Party"){
// { return nodes.data(dataset.nodes[i]["MP name"])}
return dataset.nodes[i]["Political party"] == "Bharatiya Janata Party";}
).style("display", this.checked ? null : "none");
});
d3.select("#two")
.on("change", function() {
svg.selectAll("circle").filter(function(d,i) {
return dataset.nodes[i]["Political party"] == "Indian National Congress";}
).style("display", this.checked ? null : "none");
});
d3.select("#three")
.on("change", function() {
svg.selectAll("circle").filter(function(d,i) {
return dataset.nodes[i]["Political party"] == "Janata Dal (Secular)";
}).style("display", this.checked ? null : "none");
});
d3.select("#four")
.on("change", function() {
svg.selectAll("circle").filter(function(d,i) {
return dataset.nodes[i]["Political party"] == "Janata Dal (Secular)";
}).style("display", this.checked ? null : "none");
});
/*
d3.select("#three")
.on("click", function() {
console.log("JDS");//Do something on click
nodes = nodes.filter(function(d,i) {
if(dataset.nodes[i]["Political party"] != "Janata Dal (Secular)")
{ return nodes.data(dataset.nodes[i]["MP name"])}
});
d3.select("#reset")
.on("click", function() {
console.log("reset");//Do something on click
nodes = nodes.filter(function(d) { return dataset.nodes;}
)});
*/
/* $('#search').submit(function() {
var searchTerm = $('input').val();
dataset.nodes = searchTerm;
console.log(dataset.nodes);
nodes.data(dataset.nodes);
//console.log(searchTerm);
var searchFilter = dataset.nodes.filter(function(d,i) {
console.log(dataset.nodes[i]["MP name"] === searchTerm);
return dataset.nodes[i]["MP name"] === searchTerm;
});
*/
/* var searchID = searchFilter[0].ID;
drawLinks(searchID)*/
/* return false;
});
*/
}
</script>
</body>
</html>