Commit d6ca25e8 authored by Mike Bostock's avatar Mike Bostock
Browse files

Fix ordinal scales with singleton domains.

Fixes #1717. Turns out, -1 % 1 is 0!
parent f9e00b1d
......@@ -7615,7 +7615,7 @@
function d3_scale_ordinal(domain, ranger) {
var index, range, rangeBand;
function scale(x) {
return range[((index.get(x) || ranger.t === "range" && index.set(x, domain.push(x))) - 1) % range.length];
return range[((index.get(x) || (ranger.t === "range" ? index.set(x, domain.push(x)) : NaN)) - 1) % range.length];
}
function steps(start, step) {
return d3.range(domain.length).map(function(i) {
......
This diff is collapsed.
......@@ -12,7 +12,7 @@ function d3_scale_ordinal(domain, ranger) {
rangeBand;
function scale(x) {
return range[((index.get(x) || ranger.t === "range" && index.set(x, domain.push(x))) - 1) % range.length];
return range[((index.get(x) || (ranger.t === "range" ? index.set(x, domain.push(x)) : NaN)) - 1) % range.length];
}
function steps(start, step) {
......
......@@ -117,6 +117,8 @@ suite.addBatch({
"correctly handles singleton domains": function(ordinal) {
var x = ordinal().domain(["a"]).rangePoints([0, 120]);
assert.deepEqual(x.range(), [60]);
assert.isUndefined(x("b"));
assert.deepEqual(x.domain(), ["a"]);
},
"can be set to a descending range": function(ordinal) {
var x = ordinal().domain(["a", "b", "c"]).rangePoints([120, 0]);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment