regression: in d3.bin, values next to a threshold go into the wrong bin

未关闭
#295 0 条评论 1 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 1 天内回复

@Fil 已经在做这个了。

开始于 2026年11月9日。

  • #296 来自 @Fil —— 未关闭

评估

这个 Issue 还没有评估数据。

描述

d3.bin().domain([0, 1]).thresholds(10)([0.3 * 3]) // 0.3 * 3 is 0.8999999999999999

puts the value in the bin [0.9, 1] instead of [0.8, 0.9]. With the same thresholds passed explicitly, d3.bin().domain([0, 1]).thresholds(d3.ticks(0, 1, 10).slice(1, -1)), it goes into [0.8, 0.9].

The same happens with an integer step: d3.bin().domain([-10, 10]).thresholds(10)([1.9999999999999998]) puts the value in [2, 4] instead of [0, 2].

Since 3.1.3 (#220), when the domain is aligned with the thresholds, bin computes the index of a value's bin as Math.floor((x - x0) / step) (or Math.floor((x0 - x) * step) for a fractional step). This division or multiplication can round across an integer. Only the underestimate is corrected, and only for fractional steps. 3.1.2 put these values in the correct bins.

主要语言
JavaScript
星标
465
派生
193
平均合并
5 小时 46 分钟
30 天内合并 PR
1

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

d3/d3-array 的其他 Issue

查看 d3/d3-array 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。