-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
89 lines (73 loc) · 2.77 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>FDEB Example</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="https://d3js.org/d3.v3.min.js" charset="utf-8"></script>
</head>
<body>
<div id="svg">
</div>
<script>
$(function () {
d3.xml("brazil-outline.svg", function (brazilMap) {
let marginTop = 150;
var svg = d3.select("#svg").append("svg")
.attr("width", 1050)
.attr("height", 1250);
svg = svg.append('g');
svg.append('rect').attr({ 'fill': '#FFFFFF', 'width': 1050, 'height': 1250 });
svg.attr('transform', 'translate(0, 0)');
var importedNode = document.importNode(brazilMap.documentElement, true);
svg.each(function() {
this.appendChild(importedNode)
})
d3.json("result.json", function (results) {
let edges = results.edges;
let nodes = results.nodes;
let linearGradient = svg.append('defs').append("linearGradient")
.attr("id", "linearGradient");
linearGradient.append("stop")
.attr("offset", "0%")
.attr("stop-color", "#ff2222");
linearGradient.append("stop")
.attr("offset", "70%")
.attr("stop-color", "#ff2222");
linearGradient.append("stop")
.attr("offset", "80%")
.attr("stop-color", "#0000FF");
linearGradient.append("stop")
.attr("offset", "100%")
.attr("stop-color", "#0000FF");
var d3line = d3.svg.line()
.x(function (d) { return d.x; })
.y(function (d) { return d.y; })
.interpolate("linear");
//plot the data
for (var i = 0; i < edges.length; i++) {
svg.append("path")
.attr("d", d3line(edges[i]))
.attr('transform', 'translate(0, '+marginTop+')')
.style("stroke-width", 0.1)
.style("stroke", "url(#linearGradient)")
.style("fill", "none")
.style('stroke-opacity', 0.4);
}
//draw nodes
svg.selectAll('.node')
.data(d3.entries(nodes))
.enter()
.append('circle')
.attr('transform', 'translate(0, '+marginTop+')')
.attr('opacity', '0.7')
.classed('node', true)
.attr({ 'r': 0.5, 'fill': '#00DDEE' })
.attr('cx', function (d) { return d.value.x; })
.attr('cy', function (d) { return d.value.y; });
})
});
})
</script>
</body>
</html>