Skip to content

d3.bisectCenter? #138

Description

@mbostock

It’d be nice to have something that returned the closest datum to the specified value. I’m often doing something like this:

bisect = {
  const bisectDate = d3.bisector(d => d.date).left;
  return (data, date) => {
    const i = bisectDate(data, date, 1);
    const a = data[i - 1], b = data[i];
    return date - a.date > b.date - date ? b : a;
  };
}

It’d be nicer to say

bisect = d3.bisector(d => d.date).center

(Obviously, this would only work for quantitative values; ordinal values aren’t sufficient.)

Activity

  1. mbostock commented on Mar 14, 2020

    @mbostock
    MemberAuthor
  2. added a commit that references this issue on Jun 24, 2020
  3. Fil commented on Jun 24, 2020

    @Fil
    Member

    the (d) accessor / (d, x) comparator thing was a bit tricky, but I think #156 works as expected.

  4. added 3 commits that reference this issue on Aug 23, 2020
    107631b
    8aa9a13
    5b78836
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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