Skip to content
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

Cross operator (for data stack)? #20

Closed
mbostock opened this issue Nov 5, 2010 · 3 comments · May be fixed by Skitionek/d3#4
Closed

Cross operator (for data stack)? #20

mbostock opened this issue Nov 5, 2010 · 3 comments · May be fixed by Skitionek/d3#4
Milestone

Comments

@mbostock
Copy link
Member

mbostock commented Nov 5, 2010

The cross operator (as in the splom example) is very useful for recreating something like the Protovis data stack, where data from multiple levels in the hierarchy is available in the property functions.

The implementation is simple, if a bit confusing. Take an array a. To use this array as data, as the y attribute of each element, crossed with the enclosing parent's data as the x attribute:

function cross(a) {
  return function(d) {
    var c = [];
    for (var i = 0, n = a.length; i < n; i++) c.push({x: d, y: a[i]});
    return c;
  };
}

Another possibility might be to pull the parent data out of the current group in the property function (group.parentData). But, we don't currently expose the group index (j) or the group itself in the property function. We could pass these as two additional arguments to the property function, similar to Protovis but limited to the immediate enclosing parent, but I like the current simplicity. The extra arguments were a frequent source of confusion in Protovis.

Yet another possibility is for a parentData() method (or similarly a group() method that returns the current group, changing the node returned by node(), etc.), but that requires keeping state within the selection, which I don't like because of reentrancy issues.

So, I like the idea of the cross operator making the access of the parent data more explicit. But I'm not sure about the efficiency or the semantics.

@mbostock
Copy link
Member Author

mbostock commented Nov 5, 2010

The min and max operators should probably also be included with this module.

@mbostock
Copy link
Member Author

mbostock commented Feb 8, 2011

I've added the d3.nest operator. Still considering cross.

@mbostock
Copy link
Member Author

mbostock commented Mar 6, 2011

You can obviate the need for a cross operator by using recursive evaluation, via each. The nice thing is it allows access to parent data, as with Protovis, and avoids flattening (embedding) the parent data into child data. The downside is that it could make later updates more difficult, because if you reselect the children you'll be outside of the closure and so won't have access to the parent data…

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

Successfully merging a pull request may close this issue.

1 participant