Skip to content

Commit

Permalink
Allow unlimited outer padding.
Browse files Browse the repository at this point in the history
Also clarify the documentation for outer padding.

Fixes #101.
Fixes #102.
Fixes #132.
  • Loading branch information
mbostock committed Jan 26, 2019
1 parent 5d767cb commit fb5f0b3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -858,19 +858,19 @@ If *round* is specified, enables or disables rounding accordingly. If rounding i

<a name="band_paddingInner" href="#band_paddingInner">#</a> <i>band</i>.<b>paddingInner</b>([<i>padding</i>]) [<>](https://github.com/d3/d3-scale/blob/master/src/band.js "Source")

If *padding* is specified, sets the inner padding to the specified value which must be in the range [0, 1]. If *padding* is not specified, returns the current inner padding which defaults to 0. The inner padding determines the ratio of the range that is reserved for blank space between bands.
If *padding* is specified, sets the inner padding to the specified number which must be less than or equal to 1. If *padding* is not specified, returns the current inner padding which defaults to 0. The inner padding specifies the proportion of the range that is reserved for blank space between bands; a value of 0 means no blank space between bands, and a value of 1 means a [bandwidth](#band_bandwidth) of zero.

<a name="band_paddingOuter" href="#band_paddingOuter">#</a> <i>band</i>.<b>paddingOuter</b>([<i>padding</i>]) [<>](https://github.com/d3/d3-scale/blob/master/src/band.js "Source")

If *padding* is specified, sets the outer padding to the specified value which must be in the range [0, 1]. If *padding* is not specified, returns the current outer padding which defaults to 0. The outer padding determines the ratio of the range that is reserved for blank space before the first band and after the last band.
If *padding* is specified, sets the outer padding to the specified number which is typically in the range [0, 1]. If *padding* is not specified, returns the current outer padding which defaults to 0. The outer padding specifies the amount of blank space, in terms of multiples of the [step](#band_step), to reserve before the first band and after the last band.

<a name="band_padding" href="#band_padding">#</a> <i>band</i>.<b>padding</b>([<i>padding</i>]) [<>](https://github.com/d3/d3-scale/blob/master/src/band.js "Source")

A convenience method for setting the [inner](#band_paddingInner) and [outer](#band_paddingOuter) padding to the same *padding* value. If *padding* is not specified, returns the inner padding.

<a name="band_align" href="#band_align">#</a> <i>band</i>.<b>align</b>([<i>align</i>]) [<>](https://github.com/d3/d3-scale/blob/master/src/band.js "Source")

If *align* is specified, sets the alignment to the specified value which must be in the range [0, 1]. If *align* is not specified, returns the current alignment which defaults to 0.5. The alignment determines how any leftover unused space in the range is distributed. A value of 0.5 indicates that the leftover space should be equally distributed before the first band and after the last band; *i.e.*, the bands should be centered within the range. A value of 0 or 1 may be used to shift the bands to one side, say to position them adjacent to an axis.
If *align* is specified, sets the alignment to the specified value which must be in the range [0, 1]. If *align* is not specified, returns the current alignment which defaults to 0.5. The alignment specifies how any leftover unused space in the range is distributed. A value of 0.5 indicates that the leftover space should be equally distributed before the first band and after the last band; *i.e.*, the bands should be centered within the range. A value of 0 or 1 may be used to shift the bands to one side, say to position them adjacent to an axis.

<a name="band_bandwidth" href="#band_bandwidth">#</a> <i>band</i>.<b>bandwidth</b>() [<>](https://github.com/d3/d3-scale/blob/master/src/band.js "Source")

Expand Down Expand Up @@ -924,11 +924,11 @@ If *round* is specified, enables or disables rounding accordingly. If rounding i

<a name="point_padding" href="#point_padding">#</a> <i>point</i>.<b>padding</b>([<i>padding</i>]) [<>](https://github.com/d3/d3-scale/blob/master/src/band.js "Source")

If *padding* is specified, sets the outer padding to the specified value which must be in the range [0, 1]. If *padding* is not specified, returns the current outer padding which defaults to 0. The outer padding determines the ratio of the range that is reserved for blank space before the first point and after the last point. Equivalent to [*band*.paddingOuter](#band_paddingOuter).
If *padding* is specified, sets the outer padding to the specified value which must be in the range [0, 1]. If *padding* is not specified, returns the current outer padding which defaults to 0. The outer padding specifies the proportion of the range that is reserved for blank space before the first point and after the last point. Equivalent to [*band*.paddingOuter](#band_paddingOuter).

<a name="point_align" href="#point_align">#</a> <i>point</i>.<b>align</b>([<i>align</i>]) [<>](https://github.com/d3/d3-scale/blob/master/src/band.js "Source")

If *align* is specified, sets the alignment to the specified value which must be in the range [0, 1]. If *align* is not specified, returns the current alignment which defaults to 0.5. The alignment determines how any leftover unused space in the range is distributed. A value of 0.5 indicates that the leftover space should be equally distributed before the first point and after the last point; *i.e.*, the points should be centered within the range. A value of 0 or 1 may be used to shift the points to one side, say to position them adjacent to an axis.
If *align* is specified, sets the alignment to the specified value which must be in the range [0, 1]. If *align* is not specified, returns the current alignment which defaults to 0.5. The alignment specifies how any leftover unused space in the range is distributed. A value of 0.5 indicates that the leftover space should be equally distributed before the first point and after the last point; *i.e.*, the points should be centered within the range. A value of 0 or 1 may be used to shift the points to one side, say to position them adjacent to an axis.

<a name="point_bandwidth" href="#point_bandwidth">#</a> <i>point</i>.<b>bandwidth</b>() [<>](https://github.com/d3/d3-scale/blob/master/src/band.js "Source")

Expand Down
6 changes: 3 additions & 3 deletions src/band.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ export default function band() {
};

scale.padding = function(_) {
return arguments.length ? (paddingInner = paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
return arguments.length ? (paddingInner = Math.min(1, paddingOuter = +_), rescale()) : paddingInner;
};

scale.paddingInner = function(_) {
return arguments.length ? (paddingInner = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
return arguments.length ? (paddingInner = Math.min(1, _), rescale()) : paddingInner;
};

scale.paddingOuter = function(_) {
return arguments.length ? (paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingOuter;
return arguments.length ? (paddingOuter = +_, rescale()) : paddingOuter;
};

scale.align = function(_) {
Expand Down
10 changes: 5 additions & 5 deletions test/band-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ tape("band.paddingInner(p) specifies the inner padding p", function(test) {
test.end();
});

tape("band.paddingInner(p) coerces p to a number in [0, 1]", function(test) {
tape("band.paddingInner(p) coerces p to a number <= 1", function(test) {
var s = scale.scaleBand();
test.equal(s.paddingInner("1.0").paddingInner(), 1);
test.equal(s.paddingInner("-1.0").paddingInner(), 0);
test.equal(s.paddingInner("-1.0").paddingInner(), -1);
test.equal(s.paddingInner("2.0").paddingInner(), 1);
test.ok(Number.isNaN(s.paddingInner(NaN).paddingInner()));
test.end();
Expand All @@ -187,11 +187,11 @@ tape("band.paddingOuter(p) specifies the outer padding p", function(test) {
test.end();
});

tape("band.paddingOuter(p) coerces p to a number in [0, 1]", function(test) {
tape("band.paddingOuter(p) coerces p to a number", function(test) {
var s = scale.scaleBand();
test.equal(s.paddingOuter("1.0").paddingOuter(), 1);
test.equal(s.paddingOuter("-1.0").paddingOuter(), 0);
test.equal(s.paddingOuter("2.0").paddingOuter(), 1);
test.equal(s.paddingOuter("-1.0").paddingOuter(), -1);
test.equal(s.paddingOuter("2.0").paddingOuter(), 2);
test.ok(Number.isNaN(s.paddingOuter(NaN).paddingOuter()));
test.end();
});
Expand Down

0 comments on commit fb5f0b3

Please sign in to comment.