| layout | page |
|---|---|
| title | Tags |
' + tagContent + '
')).append($ul).slideDown('normal');
});
}
if (location.hash != '') {
showPosts(location.hash.substring(1));
}
function draw(words) {
d3.select('.cloud g')
.attr('transform', 'translate(' + [width / 2, height / 2] + ')')
.selectAll('text')
.data(words)
.enter()
.append('text')
.style('font-size', function(d) {
return d.size + 'px'
})
.style('fill', function(d, i) {
return fill(i);
})
.style('font-weight', function(d) {
return 'bold';
})
.style('font-family', 'Microsoft YaHei')
.style('cursor', 'pointer')
.text(function(d) {
return d.text;
})
.attr("text-anchor", "middle")
.attr("transform", function(d) {
return "translate(" + [d.x, d.y] + ")rotate(" + d.rotate + ")";
})
.on('mouseover', function(d) {
d3.select(this).style('opacity', '0.5');
})
.on('mouseout', function(d) {
d3.select(this).style('opacity', '1');
})
.on('click', function(d) {
showPosts(d.text);
});
}
var layout = d3.layout.cloud()
.size([width, height])
.words(tags.map(function(d) {
return {
text: d.tag,
size: scale(d.freq, minFreq, maxFreq, minSize, maxSize)
};
}).sort(function(a, b) {
return b.size - a.size;
}))
.padding(1)
.rotate(function() {
return ~~(Math.random() * 3 - 1) * 30;
})
.spiral('archimedean')
.font('Microsoft Yahei')
.fontSize(function(d) {
return d.size;
})
.on('end', draw);
layout.start();
</script>