forked from TimeBandit/graph-sub
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraphSub.html
More file actions
95 lines (83 loc) · 2.55 KB
/
graphSub.html
File metadata and controls
95 lines (83 loc) · 2.55 KB
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
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<meta http-equiv="X-UA-COMPATIBLE" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>graphSub</title>
<link rel="stylesheet" href="css/base.css">
<style>
.node {
stroke: #fff;
stroke-width: 1.5px;
}
.link {
fill: none;
stroke: #bbb;
}
</style>
</head>
<body>
<div class="container">
<h2>graphSub</h2>
<section id="chart">
</section>
</div>
<script src="static/js/d3.js" charset="utf-8"></script>
<script src="static/js/underscore-min.js" charset="utf-8"></script>
<script src="static/js/graphSub.js" charset="utf-8"></script>
<script type="text/javascript">
var width = 960,
height = 500;
var color = d3.scale.category20();
var force = d3.layout.force()
.charge(-120)
.linkDistance(200)
.size([width, height]);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("data/fm.json", function(error, graph) {
force
.nodes(graph.nodes)
.links(graph.links)
.start();
var link = svg.selectAll(".link")
.data(graph.links)
.enter().append("line")
.attr("class", "link")
.style("stroke-width", function(d) { return Math.sqrt(d.value); });
// grouped nodes(gnodes)
var gnodes = svg.selectAll(".node")
.data(graph.nodes)
.enter()
.append('g')
function test(d, i){
console.log('node ', d, i);
//console.log(graph.nodes);
var n = 1;
// pass a deep copy, not the actualy dataset, else problems
var res = graphSub(d, "name", n, JSON.parse(JSON.stringify(graph.links)), JSON.parse(JSON.stringify(graph.nodes)));
};
var node = gnodes.append("circle")
.attr("class", "node")
.attr("r", 20)
.style("fill", function(d) { return color(d.group); })
.on('click', test)
.call(force.drag);
var labels = gnodes.append("text")
.text(function(d) { return d.name; });
force.on("tick", function() {
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; });
// Translate the groups
gnodes.attr("transform", function(d) {
return 'translate(' + [d.x, d.y] + ')';
});
});
});
</script>
</body>
</html>