Skip to content

d3.distinct() / d3.nest.distinct() #472

@mbostock

Description

@mbostock

It'd be nice to have a version of d3.nest for computing the number of distinct keys. Currently, you can do something like this:

var m = d3.nest().key(function(d) { return d.foo; }).entries(objects).length;

However, it would be faster to just compute the distinct count than to populate all the entries. That might look like this:

var m = d3.nest().key(function(d) { return d.foo; }).distinct(objects);

Alternatively, this could be provided as a d3.distinct(array[, f]) method. It's kind of nice that you can get the same functionality out of a nest operator, though. However, it's a bit weird since the nest operator allows multiple keys; do you want the number of distinct values for all keys? Or just the first key? Probably across all keys.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions