-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloud.js
More file actions
49 lines (45 loc) · 1.44 KB
/
Copy pathcloud.js
File metadata and controls
49 lines (45 loc) · 1.44 KB
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
var width = 960,
height = 500
var svg = d3.select("#place").append("svg")
.attr("width", width)
.attr("height", height);
d3.csv("worddata.csv", function (data) {
showCloud(data)
});
wordScale = d3.scale.linear().domain([0, 100]).range([0, 150]).clamp(true);
var svg = d3.select("svg")
.append("g")
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")")
function showCloud(data) {
d3.layout.cloud().size([960, 500])
.words(data)
.padding(5)
.rotate(function () { return 0; })
.font("Gowun Batang")
.fontSize(function (d) { return wordScale(d.frequency); })
.on("end", draw)
.start();
function draw(words) {
var cloud = svg.selectAll("text").data(words)
cloud.enter()
.append("text")
.style("font-family", "Gowun Batang")
.style("fill", function (d) {
return "#405275";
})
.style("fill-opacity", .5)
.attr("text-anchor", "middle")
.attr('font-size', 1)
.text(function (d) {
return d.text;
});
cloud
.style("font-size", function (d) {
return d.size + "px";
})
.attr("transform", function (d) {
return "translate(" + [d.x, d.y] + ")rotate(" + d.rotate + ")";
})
.style("fill-opacity", 1);
}
}