Skip to content

Commit d043d11

Browse files
committed
setting ticks()/tickValues() sets the other one to null (mbostock)
1 parent 8c2204c commit d043d11

2 files changed

Lines changed: 46 additions & 4 deletions

File tree

src/svg/axis.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ d3.svg.axis = function() {
146146

147147
axis.ticks = function() {
148148
if (!arguments.length) return tickArguments_;
149+
tickValues = null;
149150
tickArguments_ = arguments;
150151
return axis;
151152
};
@@ -179,6 +180,7 @@ d3.svg.axis = function() {
179180

180181
axis.tickValues = function(x) {
181182
if (!arguments.length) return tickValues;
183+
tickArguments_ = null;
182184
tickValues = x;
183185
return axis;
184186
};

test/svg/axis-test.js

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,43 @@ suite.addBatch({
185185
text.each(function() {
186186
assert.equal(d3.select(this).attr("y"), 9);
187187
});
188+
},
189+
"passes any arguments to the scale's tickFormat function": function(axis) {
190+
var x = d3.scale.linear(),
191+
a = axis().scale(x).tickValues([1,2,3]),
192+
g = d3.select("body").html("").append("svg:g"),
193+
aa = [];
194+
195+
x.tickFormat = function() {
196+
aa.push(arguments);
197+
return String;
198+
};
199+
200+
g.call(a);
201+
assert.equal(aa.length, 1);
202+
assert.equal(aa[0].length, 3);
203+
assert.equal(aa[0][0], 1);
204+
assert.equal(aa[0][1], 2);
205+
assert.equal(aa[0][2], 3);
206+
}
207+
},
208+
209+
"tickValues": {
210+
"defaults to null": function(axis) {
211+
var a = axis().tickValues();
212+
assert.equal(a, null);
213+
},
214+
"can be given as array of positions": function(axis) {
215+
var l = [1, 2.5, 3], a = axis().tickValues(l), t = a.tickValues();
216+
assert.equal(t, l);
217+
assert.equal(t.length, 3);
218+
},
219+
"is reset by ticks()": function(axis) {
220+
var l = [1, 2.5, 3], a = axis().tickValues(l), t = a.tickValues();
221+
assert.equal(t, l);
222+
assert.equal(t.length, 3);
223+
a.ticks([10]);
224+
assert.equal(a.tickValues(), null);
188225
}
189226
},
190227

@@ -199,10 +236,13 @@ suite.addBatch({
199236
assert.equal(t[1], 42);
200237
assert.equal(t.length, 2);
201238
},
202-
"can be given as array of positions": function(axis) {
203-
var l = [1, 2.5, 3], a = axis().tickValues(l), t = a.tickValues();
204-
assert.equal(t, l);
205-
assert.equal(t.length, 3);
239+
"is set to null by tickValues()": function(axis) {
240+
var b = {}, a = axis().ticks(b, 42), t = a.ticks();
241+
assert.equal(t[0], b);
242+
assert.equal(t[1], 42);
243+
assert.equal(t.length, 2);
244+
a.tickValues([10]);
245+
assert.equal(a.ticks(), null);
206246
},
207247
"passes any arguments to the scale's ticks function": function(axis) {
208248
var x = d3.scale.linear(), b = {}, a = axis().ticks(b, 42).scale(x), aa = [],

0 commit comments

Comments
 (0)