Skip to content

Commit

Permalink
Define rangeBand in context of rangePoints.
Browse files Browse the repository at this point in the history
Previously, the rangeBand was zero when rangePoints was used. Now it returns the
size of the step between points. Fixes d3#584.
  • Loading branch information
mbostock committed May 20, 2013
1 parent d1d71e1 commit b7f5f30
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion d3.js
Original file line number Diff line number Diff line change
Expand Up @@ -6762,7 +6762,7 @@ d3 = function() {
if (arguments.length < 2) padding = 0;
var start = x[0], stop = x[1], step = (stop - start) / (Math.max(1, domain.length - 1) + padding);
range = steps(domain.length < 2 ? (start + stop) / 2 : start + step * padding / 2, step);
rangeBand = 0;
rangeBand = Math.abs(step);
ranger = {
t: "rangePoints",
a: arguments
Expand Down
8 changes: 4 additions & 4 deletions d3.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/scale/ordinal.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function d3_scale_ordinal(domain, ranger) {
stop = x[1],
step = (stop - start) / (Math.max(1, domain.length - 1) + padding);
range = steps(domain.length < 2 ? (start + stop) / 2 : start + step * padding / 2, step);
rangeBand = 0;
rangeBand = Math.abs(step);
ranger = {t: "rangePoints", a: arguments};
return scale;
};
Expand Down
18 changes: 9 additions & 9 deletions test/scale/ordinal-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,29 +109,29 @@ suite.addBatch({
"computes discrete points in a continuous range": function(ordinal) {
var x = ordinal().domain(["a", "b", "c"]).rangePoints([0, 120]);
assert.deepEqual(x.range(), [0, 60, 120]);
assert.equal(x.rangeBand(), 0);
assert.equal(x.rangeBand(), 60);
var x = ordinal().domain(["a", "b", "c"]).rangePoints([0, 120], 1);
assert.deepEqual(x.range(), [20, 60, 100]);
assert.equal(x.rangeBand(), 0);
assert.equal(x.rangeBand(), 40);
var x = ordinal().domain(["a", "b", "c"]).rangePoints([0, 120], 2);
assert.deepEqual(x.range(), [30, 60, 90]);
assert.equal(x.rangeBand(), 0);
assert.equal(x.rangeBand(), 30);
},
"correctly handles singleton domains": function(ordinal) {
var x = ordinal().domain(["a"]).rangePoints([0, 120]);
assert.deepEqual(x.range(), [60]);
assert.equal(x.rangeBand(), 0);
assert.equal(x.rangeBand(), 120);
},
"can be set to a descending range": function(ordinal) {
var x = ordinal().domain(["a", "b", "c"]).rangePoints([120, 0]);
assert.deepEqual(x.range(), [120, 60,0]);
assert.equal(x.rangeBand(), 0);
assert.equal(x.rangeBand(), 60);
var x = ordinal().domain(["a", "b", "c"]).rangePoints([120, 0], 1);
assert.deepEqual(x.range(), [100, 60, 20]);
assert.equal(x.rangeBand(), 0);
assert.equal(x.rangeBand(), 40);
var x = ordinal().domain(["a", "b", "c"]).rangePoints([120, 0], 2);
assert.deepEqual(x.range(), [90, 60, 30]);
assert.equal(x.rangeBand(), 0);
assert.equal(x.rangeBand(), 30);
}
},

Expand Down Expand Up @@ -244,14 +244,14 @@ suite.addBatch({
x.rangePoints([1, 2]);
assert.inDelta(x(0), 1, 1e-6);
assert.inDelta(x(1), 2, 1e-6);
assert.inDelta(x.rangeBand(), 0, 1e-6);
assert.inDelta(x.rangeBand(), 1, 1e-6);
assert.inDelta(y(0), 1/11, 1e-6);
assert.inDelta(y(1), 6/11, 1e-6);
assert.inDelta(y.rangeBand(), 4/11, 1e-6);
y.rangeBands([0, 1]);
assert.inDelta(x(0), 1, 1e-6);
assert.inDelta(x(1), 2, 1e-6);
assert.inDelta(x.rangeBand(), 0, 1e-6);
assert.inDelta(x.rangeBand(), 1, 1e-6);
assert.inDelta(y(0), 0, 1e-6);
assert.inDelta(y(1), 1/2, 1e-6);
assert.inDelta(y.rangeBand(), 1/2, 1e-6);
Expand Down

0 comments on commit b7f5f30

Please sign in to comment.