d3.nice(start, stop, 1) returns [-1e308, 1e308] when the interval contains zero, so d3.bin gives NaN bin bounds

未关闭 适合新手
#292 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@awais-ur-rehman 已经在做这个了。

开始于 2026年11月7日。

  • #293 来自 @awais-ur-rehman —— 未关闭
  • #299 来自 @Fil —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
领域
data

调研方向

从 src/nice.js 开始。issue指出了反复扩大区间的循环,请追踪计数为 1 且跨越零时,其刻度步长如何变化。使用 node 重现示例,并检查 nice 和 bin 的现有测试。完成的标准是:d3.nice 返回一个覆盖输入的有限区间,且报告的 bin 边界均为有限值。

由索引模型根据 Issue 内容生成。

描述

With count 1 and start < 0 < stop, d3.nice keeps widening the interval until the step overflows. d3.bin hits this through thresholds(1) or when thresholdScott / thresholdFreedmanDiaconis return 1, and the bins get NaN bounds.

import * as d3 from "d3-array";

console.log(d3.nice(-1, 5, 1));
console.log(d3.nice(-0.1, 0.2, 1));
console.log(d3.thresholdScott([-1, 5], -1, 5));
console.log(d3.bin().thresholds(d3.thresholdScott)([-1, 5]));
console.log(d3.bin().thresholds(1)([-1.4, 5.6]));

node t.mjs

Actual:

[ -1e+308, 1e+308 ]
[ -1e+308, 1e+308 ]
1
[ [ -1, 5, x0: -1e+308, x1: NaN ], [ x0: NaN, x1: 1e+308 ] ]
[ [ -1.4, 5.6, x0: -1e+308, x1: NaN ], [ x0: NaN, x1: 1e+308 ] ]

Expected: a finite nice interval covering the input (for example [-10, 10] for d3.nice(-1, 5, 1)), and bins with finite x0 and x1.

Tested with d3-array 3.2.5 from npm and main at 24c015e, Node.js 26.13.0.

The loop in src/nice.js stops only when tickIncrement returns the previous step (or a non-finite one). With count 1 across zero, rounding both ends outward always gives an interval of at least two steps, so every iteration picks the next larger step ([-1, 5] to [-5, 5] to [-10, 10] ...). Stopping when the step grows past the previous one, or capping the iterations as d3-scale's linear.nice does, would end it.

Credit: https://ucsbplse.github.io/

主要语言
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 摘要。