Skip to content

implicit zero #2332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/scales/quantitative.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ export function createScaleQ(
scale.interpolate(interpolate);
}

// If the zero option is not specified, then implicitly extend the domain to
// include zero if the minimum is less than 7% of the spread (and similarly
// for negative domains).
if (zero === undefined && type === "linear") {
const [min, max] = extent(domain);
zero = min > 0 ? min < 0.07 * (max - min) : max < 0 ? max > 0.07 * (min - max) : false;
}

// If a zero option is specified, we assume that the domain is numeric, and we
// want to ensure that the domain crosses zero. However, note that the domain
// may be reversed (descending) so we shouldn’t assume that the first value is
Expand Down
Loading