File public/js/graph.js changed (mode: 100644) (index 0fbceb2..8956ed5) |
1 |
|
$(function() {
|
|
2 |
|
|
|
3 |
|
var width = 720,
|
|
4 |
|
height = 720
|
|
5 |
|
|
|
6 |
|
var svg = d3.select("#graph").append("svg").attr("width", width).attr("height", height)
|
|
7 |
|
|
|
8 |
|
var fisheye = d3.fisheye.circular()
|
|
9 |
|
.radius(120);
|
|
10 |
|
|
|
11 |
|
d3.json("/node/"+node_id+"/neighbors.json", function(error, json) {
|
|
12 |
|
if (error) return console.warn(error);
|
|
13 |
|
|
|
14 |
|
var n = json.nodes.length;
|
|
15 |
|
|
|
16 |
|
json.nodes.forEach(function(d,i) {
|
|
17 |
|
if(i==0){
|
|
18 |
|
d.x = Math.floor(width / 2);
|
|
19 |
|
d.y = Math.floor(height / 2);
|
|
20 |
|
} else {
|
|
21 |
|
d.x = 60 + Math.floor(Math.random()*(width - 120));
|
|
22 |
|
d.y = 60 + Math.floor(Math.random()*(height - 120));
|
|
23 |
|
}
|
|
24 |
|
|
|
25 |
|
});
|
|
26 |
|
|
|
27 |
|
json.links.forEach(function(d) {
|
|
28 |
|
d.source_node = json.nodes[d.source]
|
|
29 |
|
d.target_node = json.nodes[d.target]
|
|
30 |
|
});
|
|
31 |
|
|
|
32 |
|
var link = svg.selectAll(".link")
|
|
33 |
|
.data(json.links)
|
|
34 |
|
.enter().append("line")
|
|
35 |
|
.attr("class", "link")
|
|
36 |
|
.attr("x1", function(d) { return d.source_node.x; })
|
|
37 |
|
.attr("y1", function(d) { return d.source_node.y; })
|
|
38 |
|
.attr("x2", function(d) { return d.target_node.x; })
|
|
39 |
|
.attr("y2", function(d) { return d.target_node.y; })
|
|
40 |
|
.style("stroke-width", 1);
|
|
41 |
|
|
|
42 |
|
|
|
43 |
|
var node = svg.selectAll(".node")
|
|
44 |
|
.data(json.nodes)
|
|
45 |
|
.enter().append("g")
|
|
46 |
|
.attr("class", "node")
|
|
47 |
|
.append("svg:a")
|
|
48 |
|
.attr("xlink:href", function(d){return '/node/'+d.name+'/';})
|
|
49 |
|
.append("circle")
|
|
50 |
|
.attr("cx", function(d) { return d.x; })
|
|
51 |
|
.attr("cy", function(d) { return d.y; })
|
|
52 |
|
.attr("r", 4)
|
|
53 |
|
.attr("fill", "#2a9fd6")
|
|
54 |
|
.attr("stroke", function(d) {return d.color_code;})
|
|
55 |
|
.attr("stroke-width",3);
|
|
56 |
|
|
|
57 |
|
node.append("text")
|
|
58 |
|
.attr("dx", "-0.35em")
|
|
59 |
|
.attr("dy", "0.35em")
|
|
60 |
|
.text(function(d) { return d.name });
|
|
61 |
|
|
|
62 |
|
|
|
63 |
|
var center_node = svg.select(".node")
|
|
64 |
|
.select("circle")
|
|
65 |
|
.attr("fill", "#93c");
|
|
66 |
|
|
|
67 |
|
|
|
68 |
|
|
|
69 |
|
svg.on("mousemove", function() {
|
|
70 |
|
fisheye.focus(d3.mouse(this));
|
|
71 |
|
|
|
72 |
|
node.each(function(d) { d.fisheye = fisheye(d); })
|
|
73 |
|
.attr("cx", function(d) { return d.fisheye.x; })
|
|
74 |
|
.attr("cy", function(d) { return d.fisheye.y; })
|
|
75 |
|
.attr("r", function(d) { return d.fisheye.z * 4.5; });
|
|
76 |
|
|
|
77 |
|
link.attr("x1", function(d) { return d.source_node.fisheye.x; })
|
|
78 |
|
.attr("y1", function(d) { return d.source_node.fisheye.y; })
|
|
79 |
|
.attr("x2", function(d) { return d.target_node.fisheye.x; })
|
|
80 |
|
.attr("y2", function(d) { return d.target_node.fisheye.y; });
|
|
81 |
|
});
|
|
82 |
|
|
|
83 |
|
});
|
|
84 |
|
|
|
85 |
|
});
|
|
|
1 |
|
$(function() { |
|
2 |
|
|
|
3 |
|
var width = 720, |
|
4 |
|
height = 720 |
|
5 |
|
|
|
6 |
|
var svg = d3.select("#graph").append("svg").attr("width", width).attr("height", height) |
|
7 |
|
|
|
8 |
|
var fisheye = d3.fisheye.circular() |
|
9 |
|
.radius(120); |
|
10 |
|
|
|
11 |
|
d3.json("/node/"+node_id+"/neighbors.json", function(error, json) { |
|
12 |
|
if (error) return console.warn(error); |
|
13 |
|
|
|
14 |
|
var n = json.nodes.length; |
|
15 |
|
|
|
16 |
|
json.nodes.forEach(function(d,i) { |
|
17 |
|
if(i==0){ |
|
18 |
|
d.x = Math.floor(width / 2); |
|
19 |
|
d.y = Math.floor(height / 2); |
|
20 |
|
} else { |
|
21 |
|
d.x = 60 + Math.floor(Math.random()*(width - 120)); |
|
22 |
|
d.y = 60 + Math.floor(Math.random()*(height - 120)); |
|
23 |
|
} |
|
24 |
|
|
|
25 |
|
}); |
|
26 |
|
|
|
27 |
|
json.links.forEach(function(d) { |
|
28 |
|
d.source_node = json.nodes[d.source] |
|
29 |
|
d.target_node = json.nodes[d.target] |
|
30 |
|
}); |
|
31 |
|
|
|
32 |
|
var link = svg.selectAll(".link") |
|
33 |
|
.data(json.links) |
|
34 |
|
.enter().append("line") |
|
35 |
|
.attr("class", "link") |
|
36 |
|
.attr("x1", function(d) { return d.source_node.x; }) |
|
37 |
|
.attr("y1", function(d) { return d.source_node.y; }) |
|
38 |
|
.attr("x2", function(d) { return d.target_node.x; }) |
|
39 |
|
.attr("y2", function(d) { return d.target_node.y; }) |
|
40 |
|
.style("stroke-width", 1); |
|
41 |
|
|
|
42 |
|
|
|
43 |
|
var node = svg.selectAll(".node") |
|
44 |
|
.data(json.nodes) |
|
45 |
|
.enter().append("g") |
|
46 |
|
.attr("class", "node") |
|
47 |
|
.append("svg:a") |
|
48 |
|
.attr("xlink:href", function(d){return '/node/'+d.name+'/';}) |
|
49 |
|
.append("circle") |
|
50 |
|
.attr("cx", function(d) { return d.x; }) |
|
51 |
|
.attr("cy", function(d) { return d.y; }) |
|
52 |
|
.attr("r", 4) |
|
53 |
|
.attr("fill", "#2a9fd6") |
|
54 |
|
.attr("stroke", function(d) {return d.color_code;}) |
|
55 |
|
.attr("stroke-width",3); |
|
56 |
|
|
|
57 |
|
node.append("text") |
|
58 |
|
.attr("dx", "-0.35em") |
|
59 |
|
.attr("dy", "0.35em") |
|
60 |
|
.text(function(d) { return d.name }); |
|
61 |
|
|
|
62 |
|
|
|
63 |
|
var center_node = svg.select(".node") |
|
64 |
|
.select("circle") |
|
65 |
|
.attr("fill", "#93c"); |
|
66 |
|
|
|
67 |
|
|
|
68 |
|
|
|
69 |
|
svg.on("mousemove", function() { |
|
70 |
|
fisheye.focus(d3.mouse(this)); |
|
71 |
|
|
|
72 |
|
node.each(function(d) { d.fisheye = fisheye(d); }) |
|
73 |
|
.attr("cx", function(d) { return d.fisheye.x; }) |
|
74 |
|
.attr("cy", function(d) { return d.fisheye.y; }) |
|
75 |
|
.attr("r", function(d) { return d.fisheye.z * 4.5; }); |
|
76 |
|
|
|
77 |
|
link.attr("x1", function(d) { return d.source_node.fisheye.x; }) |
|
78 |
|
.attr("y1", function(d) { return d.source_node.fisheye.y; }) |
|
79 |
|
.attr("x2", function(d) { return d.target_node.fisheye.x; }) |
|
80 |
|
.attr("y2", function(d) { return d.target_node.fisheye.y; }); |
|
81 |
|
}); |
|
82 |
|
|
|
83 |
|
}); |
|
84 |
|
|
|
85 |
|
}); |