Comments (3)
This seems too magical to be worth it, at least from the perspective of transitioning from version 3. There will be considerable confusion about hierarchy formats because of issues like d3/d3-collection#3
The d3.hierarchy API is useful to encounter and read about, so explicitly declaring it is good for now.
The automatic boxing probably can't work both with code that uses the existing d3.nest (key/values) and the flare.json (name/children) structures... or can it?
from d3-hierarchy.
I don’t think you’d want automatic boxing to allow the children to be defined using the values property by default. That would imply d3.hierarchy would allow either, as well, and that seems unnecessary and difficult to implement cleanly.
If we changed d3.nest according to d3/d3-collection#3, old code like this:
var entries = nest.entries(data);
var root = d3.hierarchy({values: entries}, function(d) { return d.values; });
root.sum(function(d) { return d.values; });
treemap(root);
Could be changed to this:
var entries = nest.entries(data);
var root = treemap({children: entries});
In other words:
- You don’t need to specify a children accessor to d3.hierarchy because the default one is now compatible with d3.nest.
- You don’t need to pass the result of nest.entries to d3.hierarchy because the hierarchy layout (treemap) automatically does that if the input isn’t a d3.hierarchy instance.
- You don’t need to call hierarchy.sum, either, because the hierarchy layout automatically does that if the input isn’t a d3.hierarchy instance.
- You don’t have the confusion of entry.values referring to either the children values or the rolled-up value because nest.rollup replaces the leaf entries with {key, value} objects.
Now, you could just take d3/d3-collection#3 by itself and not allow autoboxing, in which case you’d need to say this:
var entries = nest.entries(data);
var root = d3.hierarchy({children: entries});
root.sum(function(d) { return d.value; });
treemap(root);
That’s still an improvement in my view. If you just changed the behavior of nest.rollup, then it’d be:
var entries = nest.entries(data);
var root = d3.hierarchy({values: entries}, function(d) { return d.values; });
root.sum(function(d) { return d.value; });
treemap(root);
Which I guess is still slightly better because it avoids the entry.value vs. entry.values confusion, but I still think it’d be nice to use entry.children instead of entry.values.
You could also support autoboxing but reject d3/d3-collection#3, in which case the example here would remain unchanged since d3.nest wouldn’t be able to take advantage of autoboxing. But autoboxing would still help if you had hierarchical JSON data and you just wanted the default behavior in regards to sorting.
from d3-hierarchy.
Okay, I think I’m against autoboxing in that: it doesn’t introduce the d3.hierarchy API (and violates parsimony); it requires specifying default behavior in all hierarchy layouts; and it’s not useful in the case where you have tabular data and need to use d3.stratify.
from d3-hierarchy.
Related Issues (20)
- Treemap leaf nodes with rect height = 0 HOT 1
- How can I handle the ts error "Type 'number | undefined' is not assignable to type 'number'." ? HOT 1
- IE11 issue - Const must be initialized in each.js HOT 1
- the json result convert to d3-hierarchy can not generate the correct format without children HOT 1
- tree layout: Support transparent intermediary nodes to keep the tree tidy HOT 3
- Undesirable padding behaviour with disparately sized children HOT 3
- node.sum/count for non-numeric data
- New nodesAtDepth(depth) function HOT 3
- d3 partition: ability to choose different "value" size variable
- document d3.Node
- Seemingly non-weird ball collection throws an error in d3.packEnclose() HOT 1
- Suggestion: pack() layouts with deterministic outputs HOT 5
- Inner and outer padding for partition layout
- How can you add new attributes to d3.heirarchy() object? HOT 1
- why non-negative for node.sum
- Using @ant-design/plots and this error is popping up
- d3.stratify().path() doesn't bind data HOT 1
- Stratify nodes that are both a leaf (with value) and a parent
- d3__WEBPACK_IMPORTED_MODULE_0__.hierarchy is not a function HOT 3
- d3__WEBPACK_IMPORTED_MODULE_0__.hierarchy is not a function HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from d3-hierarchy.