sunburst-chart
sunburst-chart copied to clipboard
Node size is not showing correctly according to the size value
Describe the bug All node size now generate different size. But size respect ordering is ok.
To Reproduce Steps to reproduce the behavior:
- see the screenshot. then you can understand.
Expected behavior Node size will be showing correctly according to the size value
Screenshots
Without seeing your raw data, it could be that any element that has children should NOT have a size property. If parent elements have a size property, their node size will calculate incorrectly. It would be great if the sunburst could automatically discard a "size" property if a node has children.
I used this code to disregard the size attribute if a node has children. Sunburst() .data(data3) .size(function(d) { if (d.children) { return null; } else { return d.size; } })
So how would I go at it, if I wanted to divide my four root-segments into four equal parts?
I suppose it would be even better if the size attribute was directly calculated against its parent irregardless of child nodes, but it seems that this tool does it the other way. So the issue request here should go something like this:
Describe the bug: Node sizes don't calculate in ways that support a hierarchical visualization.
To reproduce: Create a JSON file where all nodes have size attributes, choose an element that has children and give it a large size value. The children will not cover the parent node - there will be gaps in the visualization. The following workaround code is used to prevent this behavior: Sunburst() .data(data3) .size(function(d) { if (d.children) { return null; } else { return d.size; } })
Hoped for behavior: Root node should (obviously) always be 100%, each child element from there down should use the size attribute to calculate against its parent node. If no size is given then each element should be spread equally (if there are two children they are each 50%, 4 would get 25%, etc.) across its parent node. If a child element has children with sizes that don't calculate to 100%, then the children should be automatically spread proportionately to get to 100% of the parent.
I can't foresee a use case where a parent element should be larger than the combined size value of the children.
Hi ! Here is my dataset:
{
name: "root",
children: [
{
name: "mineral",
value: 180,
},
{
name: "animal",
value: 90,
children: [
{
name: "animal/mammal",
value: 40,
children: [
{
name: "animal/mammal/quadrupede",
value: 70,
},
{
name: "animal/mammal/cetacean",
value: 30,
},
],
},
{
name: "animal/fish",
value: 20,
},
],
},
{
name: "vegetal",
value: 90,
children: [
{
name: "vegetal/tree",
value: 150,
},
{
name: "vegetal/lichen",
value: 50,
},
],
},
],
}
```
The "mineral" sector should make 50% of the total and the "animal" and "plant" sectors should each make 25%, without taking into account the value of their children.
Here is what I get:
