-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVis_Circle_Interactions_HEB_CD.html
366 lines (292 loc) · 8.67 KB
/
Vis_Circle_Interactions_HEB_CD.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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
<!DOCTYPE html>
<meta charset="utf-8">
<style>
#left {
width : 49.48%;
float : left;
height : 765px;
border: 1px solid #000000;
position: relative;
text-align: center;
}
#right {
width : 49.48%;
float : right;
height : 765px;
}
#textual {
height : 160px;
margin-top: 5px;
border: 1px solid #000000;
}
#inner {
display: block;
height : 600px;
border: 1px solid #000000;
text-align: center;
position: relative;
}
.header{
text-align : center;
background: rgb(255, 150, 182);
margin-bottom: 5px;
}
div.tooltip {
position: absolute;
padding: 2px;
background: lightsteelblue;
border: 0px;
border-radius: 8px;
display: inline;
z-index : 2;
}
.cd-node circle {
fill: #fff;
stroke: black;
stroke-width: 1.5px;
}
.cd-node {
font: 10px sans-serif;
}
.cd-link {
fill: none;
stroke: #ccc;
stroke-width: 1.5px;
}
#close {
float:right;
display:inline-block;
padding:2px 5px;
background:#ccc;
}
.node {
font: 300 11px "Helvetica Neue", Helvetica, Arial, sans-serif;
fill: #bbb;
}
.node:hover {
fill: #000;
}
.link {
stroke: steelblue;
stroke-opacity: .4;
fill: none;
pointer-events: none;
}
.node:hover,
.node--source,
.node--target {
font-weight: 700;
}
.node--source {
fill: #2ca02c;
}
.node--target {
fill: #d62728;
}
.link--source,
.link--target {
stroke-opacity: 1;
stroke-width: 2px;
}
.link--source {
stroke: #d62728;
}
.link--target {
stroke: #d62728;
}
</style>
<body>
<div id="container">
<div id="left">
<div class="header"> Main Graph </div>
<div id="alert1" class="alert"> <text class="message"> Please click on any of the circle numbers to see the nodes in that circle </text> </div>
<div style="position:absolute;bottom:0;font-size:18px;">tension: <input id="scroll" style="position:relative;top:3px;" type="range" min="0" max="100" value="85"></div>
</div>
<div id="right">
<div id="inner">
<div class="header"> Sub Graph </div>
<div id="alert2" class="alert"> <text class="message"> Please hover on any of the nodes to see its connections to another nodes </text> </div>
</div>
<div id="textual"> <div class="header"> Description </div> </div>
</div>
</div>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
var diameter = 600,
radius = diameter / 2,
innerRadius = radius - 120;
var cluster = d3.layout.cluster()
.size([360, innerRadius])
.sort(null)
.value(function(d) { return d.size; });
var bundle = d3.layout.bundle();
var line = d3.svg.line.radial()
.interpolate("bundle")
.tension(.85)
.radius(function(d) { return d.y; })
.angle(function(d) { return d.x / 180 * Math.PI; });
var svg = d3.select("#left").append("svg")
.attr("width", diameter)
.attr("height", diameter)
.append("g")
.attr("transform", "translate(" + radius + "," + radius + ")");
var div = d3.select("#inner")
.append("div")
.attr("class", "tooltip")
.style("opacity", 0)
.attr("width", 1000)
.attr("height", 1000);
var link = svg.append("g").selectAll(".link"),
node = svg.append("g").selectAll(".node");
d3.json("./Data_Circle_Interactions_Hierarchicaledgebundling.json", function(error, classes) {
var nodes = cluster.nodes(packageHierarchy(classes)),
links = packageImports(nodes);
splines = bundle(links);
link = link
.data(bundle(links))
.enter().append("path")
.each(function(d) { d.source = d[0], d.target = d[d.length - 1]; })
.attr("class", "link")
.attr("d", line);
node = node
.data(nodes.filter(function(n) { return (!n.children && n.imports.length > 0); }))
.enter().append("text")
.attr("class", "node")
.attr("dy", ".31em")
.attr("transform", function(d) { return "rotate(" + (d.x - 90) + ")translate(" + (d.y + 8) + ",0)" + (d.x < 180 ? "" : "rotate(180)"); })
.style("text-anchor", function(d) { return d.x < 180 ? "start" : "end"; })
.text(function(d) { return d.key; })
.on("mouseover", mouseovered)
.on("mouseout", mouseouted)
.on("click",mouseclicked);
d3.select("input[id=scroll]").on("change", function() {
line.tension(this.value / 100);
link.attr("d", function(d, i) { return line(splines[i]); });
});
});
function mouseclicked(d){
var height = 500,
width = 500;
d3.select("#inner").selectAll("*:not(.header):not(#interaction):not(#innerscroll):not(.alert):not(.message)").remove();
d3.select("#textual").selectAll("*:not(.header)").remove();
d3.select("#textual")
.append("text")
.text("Selected circle is: Circle " + d.key)
.attr("style","display: block");
d3.select("#interaction")
.style("display", null);
d3.select("#alert1.alert")
.style("display","None");
d3.select("#alert2.alert")
.style("visibility","visible");
var cluster = d3.layout.cluster()
.size([height, width - 160]);
var diagonal = d3.svg.diagonal()
.projection(function(d1) { return [d1.y, d1.x]; });
var svg = d3.select("#inner").append("svg")
.attr("width", diameter)
.attr("height", diameter)
.attr("style","margin-top: 50px;")
.append("g")
.attr("transform", "translate(2,2)");
d3.json("Data_Clusterdendogram.json", function(error, root) {
var nodes = cluster.nodes(root.children[d.key]),
links = cluster.links(nodes);
var link = svg.selectAll("cd-link")
.data(links)
.enter().append("path")
.attr("class", "cd-link")
.attr("d", diagonal);
var node = svg.selectAll("cd-node")
.data(nodes)
.enter().append("g")
.attr("class", "cd-node")
.attr("transform", function(d) { return "translate(" + d.y + "," + d.x + ")"; })
node.append("circle")
.attr("r", 4.5);
node.append("text")
.attr("dx", function(d) { return d.children ? -8 : 8; })
.attr("dy", 3)
.style("text-anchor", function(d) { return d.children ? "end" : "start"; })
.text(function(d) { return d.name; });
d3.select("#textual")
.append("text")
.text("Number of nodes in the circle : " + (nodes.length))
.attr("style","display: block");
d3.select("#textual")
.append("text")
.text("Number of edges with in the circle : " + links.length)
.attr("style","display: block");
d3.select("#textual")
.append("a")
.html("Link for user evaluation survey")
.attr("href","form/evaluation_final.html")
.attr("target","_blank")
.attr("style","display: block; margin-top: 40px; text-align: left;");
});
d3.select(self.frameElement).style("height", height + "px");
div.transition()
.duration(200)
.style("opacity", .9)
.style("left", (d3.event.pageX) + "px")
.style("top", (d3.event.pageY - 28) + "px");
}
function mouseovered(d) {
node
.each(function(n) { n.target = n.source = false; });
link
.classed("link--target", function(l) { if (l.target === d) return l.source.source = true; })
.classed("link--source", function(l) { if (l.source === d) return l.target.target = true; })
.filter(function(l) { return l.target === d || l.source === d; })
.each(function() { this.parentNode.appendChild(this); });
node
.classed("node--target", function(n) { return n.target; })
.classed("node--source", function(n) { return n.source; });
}
function mouseouted(d) {
link
.classed("link--target", false)
.classed("link--source", false);
node
.classed("node--target", false)
.classed("node--source", false);
}
d3.select(self.frameElement).style("height", diameter + "px");
// Lazily construct the package hierarchy from class names.
function packageHierarchy(classes) {
var map = {};
function find(name, data) {
var node = map[name], i;
if (!node) {
node = map[name] = data || {name: name, children: []};
if (name.length) {
node.parent = find(name.substring(0, i = name.lastIndexOf(".")));
node.parent.children.push(node);
node.key = name.substring(i + 1);
}
}
return node;
}
classes.forEach(function(d) {
find(d.name, d);
});
return map[""];
}
// Return a list of imports for the given array of nodes.
function packageImports(nodes) {
var map = {},
imports = [];
// Compute a map from name to node.
nodes.forEach(function(d) {
map[d.name] = d;
});
// For each import, construct a link from the source to target node.
nodes.forEach(function(d) {
if (d.imports) d.imports.forEach(function(i) {
imports.push({source: map[d.name], target: map[i]});
});
});
return imports;
}
</script>