-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
100 lines (87 loc) · 2.83 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
<!DOCTYPE html>
<html>
<head>
<title>CMUCC Network Map</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="network.css"/>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/d3/3.4.3/d3.js"></script>
</head>
<body>
<script>
var width = $(window).width()//1280,
height = $(window).height()//800;
var color = d3.scale.category20();
var force = d3.layout.force()
.size([width, height])
.charge(-400)
.linkDistance(30)
.on("tick", tick);
var drag = force.drag()
.on("dragstart", dragstart)
.on("dragend", dragend);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
//.append('g')
//.call(d3.behavior.zoom().on("zoom", redraw))
//.append('g');
//svg.append('rect')
//.attr('width', width)
//.attr('height', height)
//.attr('fill', 'gray');
var link = svg.selectAll(".link"),
node = svg.selectAll(".node");
d3.json("graph.json", function(error, graph) {
force
.nodes(graph.nodes)
.links(graph.links)
.start();
link = link.data(graph.links)
.enter().append("line")
.attr("class", "link");
node = node.data(graph.nodes)
.data(graph.nodes)
.enter().append("g")
.attr("class", "node")
.on("dblclick", dblclick)
.call(drag);
node.append("circle")
.attr("r", 5)
.style("fill", function(d) { return color(d.group); })
node.append("text")
.attr("dx", 12)
.attr("dy", ".35em")
.text(function(d) { return d.name });
});
var isDragging=false
function redraw() {
//if (isDragging){
// return false
//}
console.log(d3.event.translate)
svg.attr("transform",
"translate(" + d3.event.translate + ")"
+ " scale(" + d3.event.scale + ")");
}
function tick() {
link.attr("x1", function(d) { return d.source.x; })
.attr("y1", function(d) { return d.source.y; })
.attr("x2", function(d) { return d.target.x; })
.attr("y2", function(d) { return d.target.y; });
node.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; });
}
function dblclick(d) {
d3.select(this).classed("fixed", d.fixed = false);
}
function dragend(d) {
isDragging=false
d3.event.translate
}
function dragstart(d) {
isDragging=true
d3.select(this).classed("fixed", d.fixed = true);
}
</script>
</body>
</html>