-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwordclouddemo.html
44 lines (40 loc) · 1.59 KB
/
wordclouddemo.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
<!DOCTYPE html>
<meta charset="utf-8">
<body>
<script src="https://d3js.org/d3.v5.min.js"></script>
<script src="JS/wordcloud.js"></script>
<script>
var cloud = d3.layout.cloud;
var fill = d3.scaleOrdinal(d3.schemeGreens[9])
var layout = cloud()
.size([500, 500])
.words(['NLP','Deep Learning', 'Statistics', 'Topic Modeling', 'Semantic Analysis',
'Classification & Clustering', ' Volatility', 'Information Visualization',
'Consulting', 'Business Analytics', 'Software Engineering'].map(function(d) {
return {text: d, size: 5 + Math.random() * 90, test: "haha"};
}))
.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")
.attr("text-anchor", "middle")
.style("fill", function(d, i) {return fill(i)})
.attr("transform", function(d) {
return "translate(" + [d.x, d.y] + ")rotate(" + d.rotate + ")";
})
.text(function(d) { return d.text; });
}
</script>