Skip to content
This repository has been archived by the owner on Nov 11, 2018. It is now read-only.

Why does d3.nest.map prepend a prefix? #28

Closed
dayvidwhy opened this issue Aug 28, 2018 · 4 comments
Closed

Why does d3.nest.map prepend a prefix? #28

dayvidwhy opened this issue Aug 28, 2018 · 4 comments

Comments

@dayvidwhy
Copy link

dayvidwhy commented Aug 28, 2018

Hi there 馃憢

We're long time users of d3 and recently looked at upgrading from d3 v3.5.8.

C3 have bumped their dependency on this project so we're wanting to make use of the latest d3 if we're going to update.

One thing I noticed right away is that since quite a while ago you introduced a prefix to keys when using d3.map;

https://github.com/d3/d3-collection/blame/5aad1d67f264c0b3b6a9f3e9833021497f03beeb/src/map.js#L1

Some very common code from us might look like the following;

let nestedData = d3.nest()
  .key((b) => b["Name"])
  .rollup((b) => {
    // return some aggregation on buckets of data by name
  })
  .map(data);

let names = Object.keys(nestedData);

So now in getting all of the unique "Name" elements we now get, for example ["$David", "$Jason"] if that makes sense, instead of ["David", "Jason"].

Now I'm not saying there's anything wrong with this, I imagine this update was part of a breaking change version bump, I'm just curious as to the reasoning?

Also I noticed that you export the prefix, did you have a snippet of code as an example of setting the prefix to nothing, if that's possible?

@dayvidwhy
Copy link
Author

@mbostock if you get a chance would you be able to reply to this?

@mbostock
Copy link
Member

http://2ality.com/2012/01/objects-as-maps.html

You should use ES Map instead of Object.

@dayvidwhy
Copy link
Author

dayvidwhy commented Sep 18, 2018

@mbostock correct me if I'm wrong, but you're asking me to just splice off the $ from the start of the keys?

edit:
I just saw this line;
https://github.com/d3/d3-collection/blame/5aad1d67f264c0b3b6a9f3e9833021497f03beeb/src/map.js#L26
Sorry I wasn't familiar with the new data structure, thanks for the information that's really interesting.

@mbostock
Copy link
Member

No, you shouldn鈥檛 be iterating over the properties on a d3.map instance, as those are private; you should be using map.keys.

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

No branches or pull requests

2 participants