-
Notifications
You must be signed in to change notification settings - Fork 1
/
consortsk55_clusters.html
251 lines (208 loc) · 8.09 KB
/
consortsk55_clusters.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<script type="text/javascript" src="../d3/d3.js"></script>
<script type="text/javascript" src="../d3/lib/colorbrewer/colorbrewer.js"></script>
<!-- <script type="text/javascript" src="../d3/d3.layout.js"></script> -->
<!-- <script type="text/javascript" src="packages.js"></script> -->
<!-- <link type="text/css" rel="stylesheet" href="style.css"/> -->
<!-- Bring in the stylesheets -->
<link type="text/css" rel="stylesheet" href="../d3/bostock_style.css"/>
<link type="text/css" rel="stylesheet" href="../d3/fredheim_style.css"/>
<link type="text/css" rel="stylesheet" href="layout.css"/>
<style type="text/css">
path.arc {
cursor: move;
fill: #fff;
}
.node circle {
/* fill: #fff; */
stroke: steelblue;
stroke-width: 1.5px;
}
.node {
font-size: 13px;
}
.link {
fill: none;
stroke: #777;
stroke-width: 1.5px;
}
</style>
</head>
<body>
<!-- Set up the page structure -->
<div id="title">
<h1>Hierarchical similarity of topics in Consortium dissertations</h1>
<h2>55 total topics, less 5 excluded topics</h2>
</div>
<div id="intro">
<p>Branches were produced by agglomerative clustering in R using cor() and hclust(), and the resulting tree cut to highlight major divisions. The central node (labeled '1of1') contains all topics; each subsequent branch point represents a point of convenience for considering groups of topics, with the first number being an arbitrary name and the second indicating the number of groups formed by that cut.</p>
<p>Five topics are excluded from this figure because they were especially non-content-bearing, e.g. topics comprised of non-words formed by unsuccessful character recognition during the scanning process.</p>
</div>
<div id="figure"></div>
<div id="details">Hover over any item for more details.</div>
<!-- Set up the figure -->
<script type="text/javascript">
var w = 700,
h = 700,
rx = (w / 2) - (h / 100),
ry = (h / 2) - (h / 100),
ryinit = (h / 2) + (h / 100),
m0,
rotate = 0;
var cluster = d3.layout.cluster()
.size([360, ry - 120])
.sort(null);
var diagonal = d3.svg.diagonal.radial()
.projection(function(d) { return [d.y, d.x / 180 * Math.PI]; });
var svg = d3.select("#figure").append("div")
.style("width", w + "px")
.style("height", w + "px");
var vis = svg.append("svg:svg")
.attr("width", w)
.attr("height", w)
.append("svg:g")
.attr("transform", "translate(" + rx + "," + ryinit + ")");
vis.append("svg:path")
.attr("class", "arc")
.attr("d", d3.svg.arc().innerRadius(ry - 120).outerRadius(ry).startAngle(0).endAngle(2 * Math.PI))
.on("mousedown", mousedown);
// Bring in the data and draw the figure
d3.json("consortsk55_clusters_nobads.json", function(json) {
var nodes = cluster.nodes(json);
// console.log(nodes);
var link = vis.selectAll("path.link")
.data(cluster.links(nodes))
.enter().append("svg:path")
.attr("class", "link")
.attr("d", diagonal);
var node = vis.selectAll("g.node")
.data(nodes)
.enter().append("svg:g")
.attr("class", "node")
.attr("transform", function(d) { return "rotate(" + (d.x - 90) + ")translate(" + d.y + ")"; })
var rScale = d3.scale.linear()
.domain([0, d3.max(nodes, function(d) { return d.size > 3 ? 3 : d.size ; })])
.range([3, 8]);
var colorScale = d3.scale.quantize()
.range(colorbrewer.Greens[7])
.domain([0, d3.max(nodes, function(d) { return d.children ? 0 : d.size; })]);
// console.log(colorScale.domain());
node.attr("id", function(d) { return d.name; });
node.append("svg:circle")
.attr("r", 4)
.attr("fill", function(d) { return (d.children) ? "#ffffff" : colorScale(d.scaledsize); })
node.append("svg:text")
.attr("dx", function(d) { return d.x < 180 ? 8 : -8; })
.attr("dy", ".31em")
.attr("text-anchor", function(d) {
if (d.children) { return "middle"; } else return d.x < 180 ? "start" : "end"; })
.attr("transform", function(d) {
if (d.children) {
if (d.children.children) { return (d.x < 90 || d.x > 270) ? "rotate(90)" : "rotate(-90)" ; }
else return d.x < 180 ? null : "rotate(180)";
} else { return d.x < 180 ? null : "rotate(180)"; }
})
.attr("opacity", function(d) {
if (!(d.children)) { return 1; } else return (d.parent && d.parent.children.length == 1) ? 0 : 0;
})
.text(function(d) { return d.name; })
.on("mouseover", mouseover);
});
d3.select(window)
.on("mousemove", mousemove)
.on("mouseup", mouseup);
function mouse(e) {
return [e.pageX - rx, e.pageY - ry];
}
function mousedown() {
m0 = mouse(d3.event);
d3.event.preventDefault();
}
function mousemove() {
if (m0) {
var m1 = mouse(d3.event),
dm = Math.atan2(cross(m0, m1), dot(m0, m1)) * 180 / Math.PI,
tx = "translate3d(0," + (ry - rx) + "px,0)rotate3d(0,0,0," + dm + "deg)translate3d(0," + (rx - ry) + "px,0)";
svg
.style("-moz-transform", tx)
.style("-ms-transform", tx)
.style("-webkit-transform", tx);
}
}
function mouseup() {
if (m0) {
var m1 = mouse(d3.event),
dm = Math.atan2(cross(m0, m1), dot(m0, m1)) * 180 / Math.PI,
tx = "rotate3d(0,0,0,0deg)";
rotate += dm;
if (rotate > 360) rotate -= 360;
else if (rotate < 0) rotate += 360;
m0 = null;
svg
.style("-moz-transform", tx)
.style("-ms-transform", tx)
.style("-webkit-transform", tx);
vis
.attr("transform", "translate(" + rx + "," + ryinit + ")rotate(" + rotate + ")")
.selectAll("g.node text")
.attr("dx", function(d) { return (d.x + rotate) % 360 < 180 ? 8 : -8; })
.attr("text-anchor", function(d) { if (d.children) { return "middle"; } else { return (d.x + rotate) % 360 < 180 ? "start" : "end"; } })
.attr("transform", function(d) {
if (d.children) {
if (d.children.children) { return (d.x + rotate < 90 || d.x + rotate > 270) ? "rotate(90)" : "rotate(-90)" ; }
else return (d.x + rotate) % 360 < 180 ? null : "rotate(180)";
} else { return (d.x + rotate) % 360 < 180 ? null : "rotate(180)"; }
})
.attr("opacity", function(d) {
if (!(d.children)) { return 1; } else return (d.parent && d.parent.children.length == 1) ? 0 : 1;
})
}
}
function cross(a, b) {
return a[0] * b[1] - a[1] * b[0];
}
function dot(a, b) {
return a[0] * b[0] + a[1] * b[1];
}
function mouseover(d) {
// console.log(d);
// console.log("scaledsize: " + d.scaledsize);
// console.log("topwords: " + d.topwords[0]);
var deets = document.getElementById("details");
if(d.children) {
deets.innerHTML = "<h2>Cluster " + d.name[0].replace(/of/g, ' of ') + "</h2>"
+ "<div id='size'>Percentage of corpus: " + (100*sum_children(d)).toFixed(2) + "</div>";
} else {
deets.innerHTML = "<h2>Topic " + d.topic + ": " + d.name[0].replace(/_/g, ' ') + "</h2>"
+ "<div id='size'>Percentage of corpus: " + (100*d.scaledsize[0]).toFixed(2) + "<br /><br /></div>"
+ "<div id='size'>Topic Rank: " + d.rank[0] + "<br /><br /></div>"
+ "<div id='topwords'>Top words: " + d.topwords[0].split(' ').join(', ') + "...</div>";
}
}
function sum_children(d, depth, sumsofar) {
if(!depth) { var depth = 0; } // set a default value if none is given
if(!sumsofar) { var sumsofar = 0; } // set a default value if none is given
// if(depth === 0) {
// console.log("Descendants of " + d.name + ": ");
// } else {
// console.log("At depth " + depth + ": " + d.name);
// }
if(d.children) { // proceed recursively through children
depth++;
d.children.forEach(function(x) {
// console.log(x);
sumsofar = sum_children(x, depth, sumsofar);
});
} else { // when we get to the bottom, increase sum and return
// console.log("Size: " + d.scaledsize[0]);
return(sumsofar + d.scaledsize[0]);
}
// console.log("I just looked at " + d.name + " and the sum is " + sumsofar);
return(sumsofar); // if we're not at bottom, just return sum as-is
}
</script>
</body>
</html>