forked from macc704/kf6apijs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
result.html
94 lines (79 loc) · 2.46 KB
/
result.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
<html>
<head>
<style>
.link {
stroke: #ccc;
}
.node text {
pointer-events: none;
font: 10px sans-serif;
}
</style>
<script src="jquery.js"></script>
<script src="bower_components/d3/d3.min.js"></script>
<script>
window.onload = function() {
if (window.opener) {
window.opener.notify(window);
} else {
console.log('local');
$('#graph').html('');
var elem = document.getElementById("json-data");
var data = JSON.parse(elem.textContent);
graphinit(data);
}
}
function graphinit(json) {
var sJson = JSON.stringify(json);
$('#json-data').html(sJson);
var width = 960,
height = 500
var svg = d3.select("#graph").append("svg")
.attr("width", width)
.attr("height", height);
var force = d3.layout.force()
.gravity(0.05)
.distance(100)
.charge(-100)
.size([width, height]);
force
.nodes(json.nodes)
.links(json.links)
.start();
var link = svg.selectAll(".link")
.data(json.links)
.enter().append("line")
.attr("class", "link")
.style("stroke-width", function(d) { return Math.sqrt(d.weight); });
var node = svg.selectAll(".node")
.data(json.nodes)
.enter().append("g")
.attr("class", "node")
.call(force.drag);
node.append("circle")
// .attr("xlink:href", "https://github.com/favicon.ico")
.attr("r", 7)
.attr("fill", "gray");
// .attr("x", -8)
// .attr("y", -8)
node.append("text")
.attr("dx", 12)
.attr("dy", ".35em")
.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; });
node.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; });
});
}
</script>
</head>
<body>
<script type="application/json" id="json-data"></script>
<h1>Graph:</h1>
<div id="graph">
</div>
</body>
</html>