Jason Davies D3文字云生成器的椭圆/圆形 [英] Oval/circular shape of the Jason Davies D3 Word Cloud generator

查看:284
本文介绍了Jason Davies D3文字云生成器的椭圆/圆形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Jason Davies的示例词云生成器代码来创建词云.我可以绘制它,但是我想要的单词云的形状是椭圆/圆形.我知道有人对Jason Davies的词云的圆形提出了疑问,但他们都在谈论对构建代码函数place()进行更改,并且也没有得到答案.我想知道是否有一种方法可以修改以下代码来实现椭圆/圆形:

I am using Jason Davies's sample word cloud generator code to create a word cloud. I am able to draw it but the shape of the word cloud I would like is oval/circular. I am aware that there have been questions regarding the circular shape of Jason Davies's word cloud but they all were talking about making changes in the build code function place() and were also unanswered. I am wondering if there is a way to achieve the oval/circular shape modifying the following code:

var fill = d3.scale.category20();

var layout = cloud()
    .size([500, 500])
    .words([
      "Hello", "world", "normally", "you", "want", "more", "words",
      "than", "this"].map(function(d) {
      return {text: d, size: 10 + 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")
      .style("fill", function(d, i) { return fill(i); })
      .attr("text-anchor", "middle")
      .attr("transform", function(d) {
        return "translate(" + [d.x, d.y] + ")rotate(" + d.rotate + ")";
      })
      .text(function(d) { return d.text; });
}

在Jason Davies的Github的自述文件中,提到了词定位的spiral,由于我是JavaScript的新手,所以我无法理解.有人有什么建议吗?非常感谢.

In the readme of Jason Davies's Github, there is a mention of spiralfor word positioning and I am unable to understand since I am very new to the JavaScript. Does anyone has any suggestions? Thanks a lot.

推荐答案

添加以下内容:.spiral("archimedean")

这篇关于Jason Davies D3文字云生成器的椭圆/圆形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆