forked from mkane2/allonepeople
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex-simple.html
168 lines (147 loc) · 5.23 KB
/
index-simple.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<!DOCTYPE html>
<meta charset="utf-8">
<title>All One People | Maeve Kane</title>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/intro.js/2.9.3/intro.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3-legend/2.25.6/d3-legend.js"></script>
<script src="barclay-simple.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/intro.js/2.9.3/introjs.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
</head>
<body>
<div id="viz-1" style="width: 800px; height: 1200px"></div>
<script>
var width = $('#viz-1').width()
var height = $('#viz-1').height()
var svg
var simulation
var div
var node
var link
var text
function showChart(networkChart) {
$("#viz-1").empty();
svg = null;
simulation = null;
div = null;
node = null;
link = null;
text = null;
buildNetwork(forceData.responseJSON);
// build the svg for the viz
svg = d3.select("#viz-1")
.append("svg")
.attr("preserveAspectRatio", "xMinYMin meet")
.attr("viewBox", "0 0 " + width + " " + height)
.call(d3.zoom().on("zoom", function() {
svg.attr("transform", d3.event.transform)
}))
.on("dblclick.zoom", null)
.append("g");
simulation = d3.forceSimulation()
.force("link", d3.forceLink().id(function(d) {
return d.name;
}).strength(1))
.force("charge", d3.forceManyBody())
.force("center", d3.forceCenter(width / 2, height / 2))
.force('collision', d3.forceCollide().radius(function(d) {
return (d.betweenesscentrality_1745 * 150 + d.degree_1745) / 2 + 15
}));
// Define the div for the tooltip
div = d3.select("body").append("div")
.attr("class", "tooltip-1");
toggle = 0;
link = svg.append("g")
.attr("class", "links")
.selectAll("line")
.data(networkChart.links)
.enter().append("line");
//.attr("stroke-width", function(d) { return Math.sqrt(d.value); });
node = svg.selectAll("circle")
.data(networkChart.nodes)
.enter().append("circle")
.attr("id", function(d) {
return d.name + "-1"
})
.attr("r", function(d) {
return d.betweenesscentrality_1745 * 150 + 8;
})
.attr("fill", function(d) {
return color(d[networkChart.colorFillCategory]);
})
.on("mouseover", function(d) {
div.html("<h6>" + d.name + "</h6><strong>Race:</strong> " + d.race + "</br><strong>Gender:</strong> " + d.gender + "</br><strong>Clan:</strong> " + d.clan + "</br><strong>First appeared as:</strong> " + d.role +
"</br><strong>Subcommunity:</strong> " + d.modularity_class)
.style("left", (d3.event.pageX) + "px")
.style("top", (d3.event.pageY - 28) + "px")
.style("opacity", 1);
})
.on("mouseout", function(d) {
div.transition()
.duration(50) // duration is critical for mouse over.. if a user is moving the mouse fast the tooltip is not responsive
.style("opacity", 0);
})
.call(d3.drag()
.on("start", dragstarted)
.on("drag", dragged)
.on("end", dragended))
.on('dblclick', connectedNodes);
text = svg.selectAll("text")
.data(node)
.enter()
.append("text");
labels = text
.attr("x", function(d) {
return d.cx
})
.attr("y", function(d) {
return d.cy
})
.text(function(d) {
return "( " + d.cx + ", " + d.cy + " )"
})
simulation
.nodes(networkChart.nodes)
.on("tick", ticked);
simulation.force("link")
.links(networkChart.links);
linkedByIndex = {};
for (i = 0; i < networkChart.nodes.length; i++) {
linkedByIndex[i + "," + i] = 1;
};
// Loop over each "link" and determine if they are connectioned
networkChart.links.forEach(function(d) {
linkedByIndex[d.source.index + "," + d.target.index] = 1;
});
};
function ticked() {
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("cx", function(d) {
return d.x;
})
.attr("cy", function(d) {
return d.y;
});
}
$(document).ready(
showChart(networkChart)
)
</script>
</body>