Skip to content
This repository has been archived by the owner on Nov 11, 2018. It is now read-only.

d3.nest retains node properties after rollup #23

Closed
DDDgfx opened this issue Apr 4, 2018 · 4 comments
Closed

d3.nest retains node properties after rollup #23

DDDgfx opened this issue Apr 4, 2018 · 4 comments

Comments

@DDDgfx
Copy link

DDDgfx commented Apr 4, 2018

Its difficult to understand why rollup should strip leaf node properties, when there are all kinds of reasons those properties might be desired for viz/labelling. etc once the nest is fed to d3.hierarchy. I understand that I can have rollup deliver back an object rather than a single value but 1) that is laborous and idiosyncratic to the data set and 2) d3.hierarchy then finds 0/undefined in the "value" property for non leaf nodes.
Maybe stratify handles this better, but in my environment its not feasible to ask my non-viz counterparts to keep a bunch of dead/non-functional rows in their data so stratify can find them.

Can there be a way to for rollup to retain leaf properties in the nest?

@DDDgfx
Copy link
Author

DDDgfx commented Apr 4, 2018

reference of my stratify comment: d3/d3-hierarchy#33

@DDDgfx
Copy link
Author

DDDgfx commented Apr 4, 2018

Furthur investigation indicates that that adding .sum() to my heirarchy also strips node properties. Why not a properties node? Consider how labels are created in the example linked above.

node.append("div")
      .attr("class", "node-label")
      .text(function(d) { return d.parent.parent.data.key + " to " + d.parent.data.key + "\n" + d.data.key; });

So in order to use something within a leaf, you'd either need to make sure its a key along the way, or do lookup from the OG data. Property portability might be more flexible.

@DDDgfx DDDgfx changed the title d3.nest retains leaf node properties after rollup d3.nest retains node properties after rollup Apr 4, 2018
@DDDgfx
Copy link
Author

DDDgfx commented Apr 18, 2018

Curious to know if this suggestion is reasonable.

@mbostock
Copy link
Member

Apologies for the delayed reply. This doesn’t seem to be an issue with d3.nest. nest.rollup doesn’t strip properties; if you specify a rollup function, you can do whatever you like with the passed-in array of values, and the returned value is what becomes the resulting entry.value.

Perhaps you meant to suggest a change to d3.hierarchy instead? That also doesn’t strip properties, but it does (intentionally) wrap the input data. You can access the original input as node.data.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants