D3.js d3-阳光分割。每个节点的大小不同

D3.js d3-阳光分割。每个节点的大小不同,d3.js,D3.js,我是d3库和javascript的新手。 我正在努力实现这样的目标 ,其中我有一个sunburst分区,但每个节点相对于径向中心的高度不同-但其父/子节点的填充保持不变。 我试着四处看看,找不到任何解决办法。 (尝试更改innerRadius/outerRadius参数似乎不起作用:() 这是我的密码: var vis = d3.select("#chart").append("svg") .style("margin", "auto") .style("position", "

我是d3库和javascript的新手。 我正在努力实现这样的目标 ,其中我有一个sunburst分区,但每个节点相对于径向中心的高度不同-但其父/子节点的填充保持不变。 我试着四处看看,找不到任何解决办法。 (尝试更改innerRadius/outerRadius参数似乎不起作用:()

这是我的密码:

var vis = d3.select("#chart").append("svg")
    .style("margin", "auto")
    .style("position", "relative")
    .attr("width", width)
    .attr("height", height)
    .append("svg:g")
    .attr("id", "container")
    .attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");

var partition = d3.layout.partition()
    .sort(function (a, b) { return d3.ascending(a.time, b.time); })
    .size([2 * Math.PI, radius * radius])
    .value(function(d) { return d.n_leaves+1; });

var arc = d3.svg.arc()
    .startAngle(function(d) { return d.x; })
    .endAngle(function(d) { return d.x + d.dx; })
    .innerRadius(function(d) { return Math.sqrt(d.y); })
    .outerRadius(function(d) { return Math.sqrt(d.y + d.dy); });

//read data from json file and visualize it
d3.text("5rrasx_out.json", function(text) {
    var data = JSON.parse(text);
    var json = buildHierarchy(data,'5rrasx');

    createVisualization(json);
});

// Main function to draw and set up the visualization, once we have the data.
function createVisualization(json) {

    // Bounding circle underneath the sunburst, to make it easier to detect
    // when the mouse leaves the parent g.
    vis.append("svg:circle")
        .attr("r", radius)
        .style("opacity", 0);

    // For efficiency, filter nodes to keep only those large enough to see.
    var nodes = partition.nodes(json);
    var dataSummary = [{label: 'pos', count: totalPos}, {label: 'neg', count: totalNeg}];

    //set title
    $("#title").text(json.title.replace(/\[.*\]/g,""));

    //set chart
    var path = vis.data([json]).selectAll("path")
        .data(nodes)
        .enter().append("path")
        .attr("class", "sunburst_node")
        .attr("display", function(d) { return d.depth ? null : "none"; })
        .attr("d", arc)
        .attr("fill-rule", "evenodd")
        .style("fill", function(d) { return (d.sentiment > 0) ? colors["pos"] : colors["neg"]; })
        .style("opacity", 1)
        .on("mouseover", mouseover)
        .on("click", click);
};
任何帮助都将不胜感激。
谢谢!

我知道这不是对上述问题的正确答案,但如果有人需要每个节点具有不同尺寸的sunburst,我将在这里发布如何使用ggsunburst包在R中实现这一点

# install ggsunburst
if (!require("ggplot2")) install.packages("ggplot2")
if (!require("rPython")) install.packages("rPython")
install.packages("http://genome.crg.es/~didac/ggsunburst/ggsunburst_0.0.10.tar.gz", repos=NULL, type="source")
library(ggsunburst)

# one possible input for ggsunburst is newick format
# consider the following newick "(((A,B),C),D,E);"
# you can define the distance in node A with "A:0.5"
# you can define size in node E with "E[&&NHX:size=5]"
# adding both attributes to the newick
nw <- '(((A:0.5,B),C:3),D[&&NHX:size=5],E[&&NHX:size=5]);'
sb <- sunburst_data(nw)
sunburst(sb, rects.fill.aes = "name") + scale_fill_discrete(guide=F)
#安装ggsunburst
如果(!require(“ggplot2”))安装.packages(“ggplot2”)
如果(!require(“rPython”))安装.packages(“rPython”)
安装程序包(“http://genome.crg.es/~didac/ggsunburst/ggsunburst_0.0.10.tar.gz“,repos=NULL,type=“source”)
图书馆(ggsunburst)
#ggsunburst的一个可能输入是newick格式
{考虑下面的纽克”(((a,b),c),d,e);
#可以使用“A:0.5”定义节点A中的距离
#您可以使用“E[&&NHX:size=5]”在节点E中定义大小
#将这两个属性添加到newick

nw我知道这不是对上述问题的正确答案,但如果有人需要每个节点具有不同维度的sunburst,我将在这里发布如何使用ggsunburst包在R中实现这一点

# install ggsunburst
if (!require("ggplot2")) install.packages("ggplot2")
if (!require("rPython")) install.packages("rPython")
install.packages("http://genome.crg.es/~didac/ggsunburst/ggsunburst_0.0.10.tar.gz", repos=NULL, type="source")
library(ggsunburst)

# one possible input for ggsunburst is newick format
# consider the following newick "(((A,B),C),D,E);"
# you can define the distance in node A with "A:0.5"
# you can define size in node E with "E[&&NHX:size=5]"
# adding both attributes to the newick
nw <- '(((A:0.5,B),C:3),D[&&NHX:size=5],E[&&NHX:size=5]);'
sb <- sunburst_data(nw)
sunburst(sb, rects.fill.aes = "name") + scale_fill_discrete(guide=F)
#安装ggsunburst
如果(!require(“ggplot2”))安装.packages(“ggplot2”)
如果(!require(“rPython”))安装.packages(“rPython”)
安装程序包(“http://genome.crg.es/~didac/ggsunburst/ggsunburst_0.0.10.tar.gz“,repos=NULL,type=“source”)
图书馆(ggsunburst)
#ggsunburst的一个可能输入是newick格式
{考虑下面的纽克”(((a,b),c),d,e);
#可以使用“A:0.5”定义节点A中的距离
#您可以使用“E[&&NHX:size=5]”在节点E中定义大小
#将这两个属性添加到newick

nw请提供一些代码。嗨@Seth,添加了我的代码。谢谢你的帮助!请提供一些代码。嗨@Seth,添加了我的代码。谢谢你的帮助!