-
Notifications
You must be signed in to change notification settings - Fork 185
stacks #177
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
stacks #177
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two outstanding questions:
There are a number of places that call array.indexOf (the sort option, rank = sum, rank = appearance, rank = insideOut, and rank = array of values). This probably means quadratic performance. Can we implement these so they are more efficient?
Do we need the sort option? There aren’t any examples that use it yet. That would eliminate one of the uses of array.indexOf, too.
The sort option is used only in the case of the wiggle offset, which tries to minimize the differences from one location to the next. We could ignore it, with a caveat that the wiggle offset needs data sorted on x to get the correct result. And in any case, the option is passed up to areaY. |
The sort option is a subset of the transform composition problem we were discussing in the other thread. I think it’s best to remove the option for now and instead implement a more general solution such as an array of transforms. Also, while the sort option is passed through to the next mark, it will be ignored because Plot.stack defines the transform option which takes priority over the sort option; the sort option is just shorthand for a transform, but is ignored if a transform is explicitly specified. Yes, I think we should use a Map or similar instead of indexOf. Are you able to do that this morning, or should I? |
This comment has been minimized.
This comment has been minimized.
Okay, a few last (?) things:
|
Oh, and |
Almost there. Question: should rank be renamed to order to match D3’s stack.order? I know they are not exactly the same, but I don’t totally grok whether “rank” is a more expressive term than “order” here, or if it’s different just for the sake of being different. Related #179. |
I realized I misunderstood the behavior of the order (formerly rank) option: when an array of values, it’s effectively an ordinal domain for the z dimension; it’s a partial ordering of series rather than a complete ordering of data as suggested in #179. This also means that the array interpretation is different than the function and field variants, as the latter produce complete orderings. I’m going to break things for a bit as I think through this design some more. |
…and "reverse" symbols. - "key" can easily be obtained by passing a sorted array of keys - "none" and "reverse" are obtained by null and by {reverse: true} - "ascending" and "descending" are obtained by "sum" (with {reverse: true} for "descending")
This reverts commit 5156052.
src/transforms/stack.js
Outdated
} | ||
} | ||
return positions(Z, order); | ||
return positions(Z, Kn.reverse().concat(Kp)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naïve Q: I don't understand what this optimizes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
array.unshift is an O(N) operation on an array of length N, so if it’s done O(N) times the total is O(N²). Where as array.push is O(1) and array.reverse and array.concat are O(N), so the total is O(N). It won’t matter much in practice since N is typically very low here (the number of distinct values in z), but it’s not hard to do efficiently either, so I did.
(this is #132, rebased on #176)
changes wrt #132:
See API documentation at https://observablehq.com/@data-workflows/plot-stack-options
Test plots:
supersedes #110
supersedes #132
closes #109
closes #22
closes #113