Skip to content
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

fix: use domainMin and domainMax to set scale padding #3906

Merged
merged 4 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/vega-encode/src/Scale.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,6 @@ function configureDomain(scale, _, df) {

if (!domain) return 0;

// adjust continuous domain for minimum pixel padding
if (includePad(type) && _.padding && domain[0] !== peek(domain)) {
domain = padDomain(type, domain, _.range, _.padding, _.exponent, _.constant);
}

// adjust domain based on zero, min, max settings
if (zero || _.domainMin != null || _.domainMax != null || _.domainMid != null) {
n = ((domain = domain.slice()).length - 1) || 1;
Expand All @@ -159,6 +154,11 @@ function configureDomain(scale, _, df) {
}
}

// adjust continuous domain for minimum pixel padding
if (includePad(type) && _.padding && domain[0] !== peek(domain)) {
domain = padDomain(type, domain, _.range, _.padding, _.exponent, _.constant);
}

// set the scale domain
scale.domain(domainCheck(type, domain, df));

Expand Down
11 changes: 11 additions & 0 deletions packages/vega-encode/test/scale-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ tape('Scale respects domain padding', t => {
}).domain();
t.deepEqual(d, [0, 100]);

d = scale({
type: 'linear',
domain: [0, 100],
range: [0, 100],
padding: 5,
domainMin: 5,
domainMax: 95,
zero: false
}).domain();
t.deepEqual(d, [0, 100]);

// test log scale padding
d = scale({
type: 'log',
Expand Down