Skip to content

Commit

Permalink
Revert "Define rangeBand in context of rangePoints."
Browse files Browse the repository at this point in the history
This reverts commit b7f5f30, which broke the
behavior of the axis component for ordinal scales by changing the meaning of
rangeBand.
  • Loading branch information
mbostock committed May 20, 2013
1 parent cf4c17a commit eb38418
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion component.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "d3",
"version": "3.1.8",
"version": "3.1.9",
"main": "index-browserify.js",
"scripts": [
"index-browserify.js",
Expand Down
4 changes: 2 additions & 2 deletions d3.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
d3 = function() {
var d3 = {
version: "3.1.8"
version: "3.1.9"
};
if (!Date.now) Date.now = function() {
return +new Date();
Expand Down Expand Up @@ -6790,7 +6790,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 = Math.abs(step);
rangeBand = 0;
ranger = {
t: "rangePoints",
a: arguments
Expand Down
2 changes: 1 addition & 1 deletion d3.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "d3",
"version": "3.1.8",
"version": "3.1.9",
"description": "A small, free JavaScript library for manipulating documents based on data.",
"keywords": [
"dom",
Expand Down
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 = Math.abs(step);
rangeBand = 0;
ranger = {t: "rangePoints", a: arguments};
return scale;
};
Expand Down
2 changes: 1 addition & 1 deletion src/start.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
d3 = (function(){
var d3 = {version: "3.1.8"}; // semver
var d3 = {version: "3.1.9"}; // semver
27 changes: 18 additions & 9 deletions test/scale/ordinal-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,29 +109,38 @@ 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(), 60);
var x = ordinal().domain(["a", "b", "c"]).rangePoints([0, 120], 1);
assert.deepEqual(x.range(), [20, 60, 100]);
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(), 30);
},
"correctly handles singleton domains": function(ordinal) {
var x = ordinal().domain(["a"]).rangePoints([0, 120]);
assert.deepEqual(x.range(), [60]);
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(), 60);
var x = ordinal().domain(["a", "b", "c"]).rangePoints([120, 0], 1);
assert.deepEqual(x.range(), [100, 60, 20]);
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(), 30);
},
"has a rangeBand of zero": function(ordinal) {
var x = ordinal().domain(["a", "b", "c"]).rangePoints([0, 120]);
assert.equal(x.rangeBand(), 0);
var x = ordinal().domain(["a", "b", "c"]).rangePoints([0, 120], 1);
assert.equal(x.rangeBand(), 0);
var x = ordinal().domain(["a", "b", "c"]).rangePoints([0, 120], 2);
assert.equal(x.rangeBand(), 0);
var x = ordinal().domain(["a"]).rangePoints([0, 120]);
assert.equal(x.rangeBand(), 0);
var x = ordinal().domain(["a", "b", "c"]).rangePoints([120, 0]);
assert.equal(x.rangeBand(), 0);
var x = ordinal().domain(["a", "b", "c"]).rangePoints([120, 0], 1);
assert.equal(x.rangeBand(), 0);
var x = ordinal().domain(["a", "b", "c"]).rangePoints([120, 0], 2);
assert.equal(x.rangeBand(), 0);
}
},

Expand Down Expand Up @@ -244,14 +253,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(), 1, 1e-6);
assert.inDelta(x.rangeBand(), 0, 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(), 1, 1e-6);
assert.inDelta(x.rangeBand(), 0, 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 eb38418

Please sign in to comment.