Last active
May 20, 2019 02:01
-
-
Save mariotacke/e652c124902edd41250085e6f96e8cf2 to your computer and use it in GitHub Desktop.
Revisions
-
mariotacke revised this gist
May 20, 2019 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,7 +14,8 @@ async function init () { layout.start(); function draw (words) { d3.select("body") .append("svg") .attr("width", layout.size()[0]) .attr("height", layout.size()[1]) .append("g") -
mariotacke renamed this gist
May 20, 2019 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
mariotacke created this gist
May 20, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ async function init () { const cloud = await getCloud(); const highestScore = Math.max(...cloud.map((x) => x.size)); var layout = d3.layout.cloud() .size([500, 500]) .words(cloud) .rotate(function () { return ~~(Math.random() * 2) * 90; }) .font("Impact") .fontSize(function (d) { return d.size / highestScore * 90 }) .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") .attr("transform", function (d) { return "translate(" + [d.x, d.y] + ")rotate(" + d.rotate + ")"; }) .text(function (d) { return d.text; }); } }