Skip to content

Fix diverging scales with degenerate descending domains - #291

Open
Rajvira10 wants to merge 1 commit into
d3:mainfrom
Rajvira10:fix/descending-degenerate-diverging-domain
Open

Rajvira10 wants to merge 1 commit into
d3:mainfrom
Rajvira10:fix/descending-degenerate-diverging-domain

Conversation

@Rajvira10

@Rajvira10 Rajvira10 commented Oct 16, 2026 •

Copy link
Copy Markdown

With a descending domain whose first interval is collapsed, scaleDiverging().domain([1, 1, 0])(0) returns 0.5 instead of 1. Determine the direction from the transformed domain endpoints rather than the first interval, including when a power or symlog transform is reconfigured.

Fixes #256.

Regression coverage includes the reported inputs, clamping, copying, a collapsed last interval, power and symlog reconfiguration, and positive and negative logarithmic domains. All four new tests fail against the original source and pass with this change.

Validation on Node 26.8.1:

  • Full Mocha suite: 437 passing, using the runtime dependency versions from yarn.lock (d3-array 3.0.4, d3-format 3.0.1, d3-time 3.0.0).
  • ESLint across src and test: zero errors or warnings.
  • git diff --check: passed.

The installed Mocha 9 CLI's yargs dependency is incompatible with Node 26, so the suite was run through Mocha's programmatic API, with the same test glob and timezone as npm test:

TZ=America/Los_Angeles node --input-type=module -e 'import Mocha from "mocha"; import glob from "glob"; const mocha = new Mocha({reporter:"dot"}); for (const file of glob.sync("test/**/*-test.js")) mocha.addFile(file); await mocha.loadFilesAsync(); mocha.run(f => {process.exitCode = f ? 1 : 0;});'
node --input-type=module -e 'import eslint from "eslint"; const cli = new eslint.ESLint(); const results = await cli.lintFiles(["src", "test"]); console.log(await (await cli.loadFormatter("stylish")).format(results)); const errors=results.reduce((n,r) => n+r.errorCount+r.warningCount,0); process.exitCode=errors?1:0;'

The diff was independently reviewed and tested.

@Rajvira10
Rajvira10 marked this pull request as ready for review October 16, 2026 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

scaleDiverging for domain [1,1,0] produces wrong results

1 participant