-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnyvisahalf.html
65 lines (56 loc) · 1.76 KB
/
nyvisahalf.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
<!DOCTYPE html>
<html>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="d3.layout.cloud.js"></script>
<head>
<title>Word Cloud Example</title>
</head>
<style>
body {
font-family:"Lucida Grande","Droid Sans",Arial,Helvetica,sans-serif;
}
.legend {
border: 1px solid #555555;
border-radius: 30px 30px 30px 30px;
font-size: 1em;
margin: 10px;
padding: 8px;
}
.bld {
font-weight: bold;
}
</style>
<body>
</body>
<script>
var frequency_list = [{"text":"year","size":39},{"text":"new","size":20},{"text":"change","size":34},{"text":"border","size":45},{"text":"govern","size":30},{"text":"worker","size":50},{"text":"student","size":11},{"text":"trump","size":48},{"text":"immigrant","size":17}];
var fill = d3.scale.category20();
var layout = d3.layout.cloud()
.size([1000, 900])
.words(frequency_list)
.padding(5)
.rotate(function() { return ~~(Math.random() * 2) * 90; })
.font("Impact")
.fontSize(function(d) { return d.size })
.on("end", draw);
layout.start();
function draw(words) {
d3.select("body").append("svg")
.attr("width", layout.size()[0])
.attr("height", layout.size()[1])
.append("g")
.attr("transform", "translate(" + layout.size()[0] / 2 + "," + layout.size()[1] / 2 + ")")
.selectAll("text")
.data(words)
.enter().append("text")
.style("font-size", function(d) { return d.size + "px"; })
.style("font-family", "Impact")
.style("fill", function(d, i) { return fill(i); })
.attr("text-anchor", "middle")
.attr("transform", function(d) {
return "translate(" + [d.x, d.y] + ")rotate(" + d.rotate + ")";
})
.text(function(d) { return d.text; });
}
</script>
</html>