这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@Fil
Copy link
Member

@Fil Fil commented Mar 21, 2021

Added flatRollup and tests, then got carried away and added flatGroupSort, which implies we needed a lexicographic comparator for arrays. Maybe that's too much, but it's easy to trim down.

@Fil Fil requested a review from mbostock March 21, 2021 10:53
@Fil Fil changed the base branch from master to mbostock/flatGroup March 21, 2021 10:53
@mbostock
Copy link
Member

flatRollup seems fine, but not sure I understand the use case for flatGroupSort? That would require array equality to be useful, which JavaScript doesn’t support (even with InternMap).

@Fil
Copy link
Member Author

Fil commented Mar 22, 2021

With flatGroupSort(data, d => d.a, d => d.b) the idea is to be able to enumerate the keys in a rolled-up order, in particular to focus on the n most populated groups.

When I need to group on two dimensions I'll join them with a joined key: d => ${d.a} ${d.b}, then recoup my keys with (v => ({a: v[0].a, b: v[0].b, length})) in the reduce part of the rollup function. This is doable but not as comfortable with groupSort, which returns the joined keys as a string, which I then have to split (and be careful with spaces etc).

@mbostock
Copy link
Member

But you could sort the result of d3.flatGroup, no?

@Fil
Copy link
Member Author

Fil commented Mar 22, 2021

Sure! d3.flatGroupSort(data, v => v.length, d => d.island, d => d.sex) is the same as d3.sort(d3.flatGroup(data, d => d.island, d => d.sex), ([, , v]) => v.length).map(([key1, key2]) => [key1, key2]).
I think I wouldn't even call the last map, and keep the values as the last element of the array.

@mbostock
Copy link
Member

mbostock commented Jun 5, 2021

I am onboard with flatRollup but I would not like to ship flatGroupSort and lexicographic (at least not yet) since I’m not sure it’s a justified addition.

@mbostock mbostock changed the title flatGroup, flatRollup, flatGroupSort, lexicographic flatRollup Jun 5, 2021
@mbostock mbostock merged commit 33fb52b into mbostock/flatGroup Jun 5, 2021
@mbostock mbostock deleted the fil/flatGroup branch June 5, 2021 15:41
mbostock added a commit that referenced this pull request Jun 5, 2021
* lexicographic order

* flatGroup, flatRollup

* flatGroupSort

* exports

* remove flatGroupSort, lexicographic

Co-authored-by: Mike Bostock <mbostock@gmail.com>
mbostock added a commit that referenced this pull request Jun 5, 2021
* flatGroup

* flatRollup (#197)

* lexicographic order

* flatGroup, flatRollup

* flatGroupSort

* exports

* remove flatGroupSort, lexicographic

Co-authored-by: Mike Bostock <mbostock@gmail.com>

* extract tests

* Update README

Co-authored-by: Philippe Rivière <fil@rezo.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants