-
Notifications
You must be signed in to change notification settings - Fork 314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stratify could infer implied parent nodes? #33
Comments
An alternate basic example that solves the problem with |
Yes, you have to specify all parent nodes in the tabular data. There’s no way for d3.stratify to infer the implied parent nodes in the example you gave because it doesn’t understand the semantics of the id: the identifier is opaque. So, this is flat:
Just like this:
I couldn’t think of an elegant way to create the implied parent nodes. But maybe d3.stratify could have a mode where it creates implied parent nodes automatically if you opt-in… but you’d need another accessor function to either specify all parents of a particular node (flare.analytics.cluster.AgglomerativeCluster ↦ [flare, flare.analytics, flare.analytics.cluster]), or equivalently an accessor function to compute the parent of an implied parent (flare.analytics.cluster ↦ flare.analytics, flare.analytics ↦ flare, flare ↦ null). At any rate, you wouldn’t want to use d3.stratify with d3.nest because d3.nest already returns a hierarchical data structure; you want to use d3.hierarchy and pass a children accessor. I’ll cook up an example for that. |
Take a look at the In the tsv file that is the output of The particular use case I came across was a collection of organisms with partial taxonomy per organism. These are a few sample values from that column (a single column with comma-delimited strings in a TSV):
|
Looking at #34, it seems like creating implied parent nodes could be problematic with stratify if parents were to appear later in the dataset (like the output of |
This part in your example: data.forEach(function(row) {
row.taxonomy = row.file.split("/");
}); Is functionally equivalent to what I was suggesting here with d3.stratify:
|
Ordering shouldn’t be a problem. After a full pass of the input data, you’d have a set of missing parents. You’d then create nodes for each missing parent, and determine the next set of missing parents. When that set is empty, you’d be done. Three options:
|
If stratify.ancestorId is used, it’d be nice if we could automatically set a node.name, too. For example, if the id is Maybe I’m trying too hard to build this into d3.stratify, rather than creating something like d3.stratify that requires that the hierarchy structure be derived solely from delimiter-separated strings. And in that case, we can compute the implied parents and local names automatically. |
Would something like this hastily assembled I do understand though that the expected input structure is not sparse, and for this reason |
Eagerly looking forward to this solution. |
I think it can go both ways: provide a general |
In the existing d3.stratify examples, it seems parent nodes must be included in the original CSV.
Example: http://bl.ocks.org/mbostock/9d0899acb5d3b8d839d9d613a9e1fe04
It would be convenient if the first 3 rows in the above weren't required. In other words, this would be sufficient:
The nodes
flare
,flare.analytics
, andflare.analytics.cluster
would be created automatically in the resulting hierarchy. Currently running thestratify
function against the above CSV would throw an error like this:From this line of d3.stratify:
d3-hierarchy/src/stratify.js
Line 47 in 8b4c396
The text was updated successfully, but these errors were encountered: