Nessuna descrizione

news-cloud.ftl 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <html>
  2. <!-- Body tag is where we will append our SVG and SVG objects-->
  3. <body>
  4. </body>
  5. <head>
  6. <title>블로그 검색어 Word Cloud</title>
  7. <script src="https://d3js.org/d3.v3.min.js"></script>
  8. <script src="https://rawgit.com/jasondavies/d3-cloud/master/build/d3.layout.cloud.js" type="text/JavaScript"></script>
  9. <script type="text/JavaScript">
  10. var datasToDraw = new Array();
  11. <#list message as i>
  12. var person = {}; //또는 var person = new Object();
  13. person.text = '${i.text}';
  14. person.size = ${i.size} * 5;
  15. datasToDraw.push(person);
  16. </#list>
  17. // Next you need to use the layout script to calculate the placement, rotation and size of each word:
  18. var width = 960;
  19. var height = 500;
  20. var fill = d3.scale.category20();
  21. var svg = d3.select("body").append("svg")
  22. .attr("width", width)
  23. .attr("height", height);
  24. var svg = d3.select("svg")
  25. .append("g")
  26. .attr("transform", "translate(" + width / 2 + "," + height / 2 + ")")
  27. var keywords = ["JavaScript", "Actionscript", "coffeescript"]
  28. function showCloud(words) {
  29. d3.layout.cloud()
  30. .size([width, height])
  31. .words(words)
  32. .rotate(function() {
  33. return ~~(Math.random() * 2) * 90;
  34. })
  35. .font("Impact")
  36. .fontSize(function(d) {
  37. return d.size;
  38. })
  39. .on("end", drawSkillCloud)
  40. .start();
  41. }
  42. showCloud(datasToDraw);
  43. // Finally implement `drawSkillCloud`, which performs the D3 drawing:
  44. // apply D3.js drawing API
  45. function drawSkillCloud(words) {
  46. var cloud = svg.selectAll("text").data(words)
  47. //Entering words
  48. cloud.enter()
  49. .append("text")
  50. .style("font-family", "overwatch")
  51. .style("fill", function(d) {
  52. return (keywords.indexOf(d.text) > -1 ? "#fbc280" : "#405275");
  53. })
  54. .style("fill-opacity", .5)
  55. .attr("text-anchor", "middle")
  56. .attr('font-size', 1)
  57. .text(function(d) {
  58. return d.text;
  59. });
  60. cloud
  61. .transition()
  62. .duration(600)
  63. .style("font-size", function(d) {
  64. return d.size + "px";
  65. })
  66. .attr("transform", function(d) {
  67. return "translate(" + [d.x, d.y] + ")rotate(" + d.rotate + ")";
  68. })
  69. .style("fill-opacity", 1);
  70. }
  71. // set the viewbox to content bounding box (zooming in on the content, effectively trimming whitespace)
  72. setInterval(function() {
  73. showCloud(datasToDraw);
  74. }, 2000)
  75. </script>
  76. </head>
  77. </html>