Comments (9)
Perhaps nest.entries should create {key, children} by default, too. Then it would be default-compatible with d3.hierarchy.
from d3-collection.
I think it's best to keep the behavior of d3.nest as it is-- at least key/values for the internal node keys. It's a simple, successful function with many examples and tutorials out there.
The referenced issue could resolved with a new convenience function in d3-hierarchy that has an API similar d3.nest but returns a hierarchy object. The new function would be a sibling to stratify
.
from d3-collection.
I don’t want to introduce a new operator; that’s a pretty big addition to the API when there’s already a reasonable way to turn the result of nest.entries into a d3.hierarchy. We’re just talking about turning this:
var root = d3.hierarchy({values: nest.entries(data)}, function(d) { return d.values; })
.sum(function(d) { return d.values; });
Into this:
var root = d3.hierarchy({children: nest.entries(data)})
.sum(function(d) { return d.value; });
Or, if we just change the behavior of nest.rollup and don’t adopt entry.children:
var root = d3.hierarchy({values: nest.entries(data)}, function(d) { return d.values; })
.sum(function(d) { return d.value; });
Name changes are the most trivial of incompatibilities. We shouldn’t needlessly rename things, but if changing entry.values to entry.children makes things easier, it might be worth it. Certainly there are a lot of other API changes in D3 4.0 that I believe are worth it; we shouldn’t needlessly bind ourselves to past API decisions if we’ve learned something since.
It is interesting to consider whether d3.nest should return a d3.hierarchy instance directly. That would suggest moving d3.nest to the d3-hierarchy module, or perhaps better, moving d3.hierarchy and d3.stratify into d3-collection (since these are just operations on data and not hierarchical layouts). That would offer some nice improvements, like addressing #4 because d3.hierarchy provides visit methods, but you also lose something because nests are specialized hierarchies where each child is uniquely identified by a string key. It’s sometimes convenient to represent them as nested maps.
So, I feel like it’s worth considering renaming entry.values to entry.children (and having nest.rollup replace entry.children with entry.value), but I’m not currently in favor of more substantial changes.
from d3-collection.
I’ve implemented both approaches in #6 and #7. I guess I’m leaning towards #6 to be conservative now.
from d3-collection.
Merged #6.
from d3-collection.
I'm having problems with d3.nest. Sometimes rollup returns key/value and sometimes key/values. It appears that the first time it is invoked it results in key/values then key/value. This means that the program works correctly the first time but then it returns key/value and fails.
from d3-collection.
@PatriciaW43 nest.rollup always produces leaf entries with entry.value rather than entry.values. Please see my guide on reporting an issue.
from d3-collection.
I wasn't sure how to report an issue so I created a Gist at gist:fe81b673a90a3cd5f32b7aceca9559c0
from d3-collection.
For me nest.rollup is also producing entry.values on leaf entries.
See this example, which is linked from d3-collection's readme: http://bl.ocks.org/phoebebright/raw/3176159/
var nested_data = d3.nest()
.key(function(d) { return d.status; })
.key(function(d) { return d.priority; })
.rollup(function(leaves) { return leaves.length; })
.entries(csv_data);
Returns:
[
{
"key": "Complete",
"values": [
{
"key": "MUST",
"values": 5
},
{
"key": "SHOULD",
"values": 5
},
{
"key": "COULD",
"values": 1
}
]
},
{
"key": "In Progress",
"values": [
{
"key": "MUST",
"values": 6
},
{
"key": "SHOULD",
"values": 1
},
{
"key": "WISH",
"values": 1
}
]
},
{
"key": "Not Started",
"values": [
{
"key": "MUST",
"values": 9
},
{
"key": "SHOULD",
"values": 3
},
{
"key": "COULD",
"values": 3
},
{
"key": "WISH",
"values": 1
}
]
}
]
from d3-collection.
Related Issues (19)
- Fix prototype.constructor.
- d3.map could take an optional value accessor function? HOT 1
- ES6 Collections. HOT 2
- d3.group convenience function? HOT 3
- Support natural sorting of keys. HOT 5
- sortValues after rollup HOT 2
- Feature request HOT 1
- value/values on rollup function HOT 2
- d3.nest reformats a Date object to a string HOT 1
- Nest: individual key sorting HOT 1
- es6 import syntax example? HOT 4
- d3.nest retains node properties after rollup HOT 4
- Feature Request - same level nesting by multiple key HOT 1
- Custom key, values field names for the nest() HOT 5
- Why does d3.nest.map prepend a prefix? HOT 4
- Add nest.count or nest.visit? HOT 1
- Mutable nests? HOT 1
- Support string as accessor? HOT 1
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-collection.