Skip to content

Commit 8c2204c

Browse files
committed
separate variable and accessor method for ticks (mbostock)
1 parent bc433a2 commit 8c2204c

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

src/svg/axis.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ d3.svg.axis = function() {
66
tickEndSize = 6,
77
tickPadding = 3,
88
tickArguments_ = [10],
9+
tickValues = null,
910
tickFormat_,
1011
tickSubdivide = 0;
1112

@@ -28,7 +29,7 @@ d3.svg.axis = function() {
2829
} : Object;
2930

3031
// Ticks, or domain values for ordinal scales.
31-
var ticks = tickArguments_.length == 1 && tickArguments_[0] instanceof Array ? tickArguments_[0] : (scale.ticks ? scale.ticks.apply(scale, tickArguments_) : scale.domain()),
32+
var ticks = tickValues == null ? (scale.ticks ? scale.ticks.apply(scale, tickArguments_) : scale.domain()) : tickValues,
3233
tickFormat = tickFormat_ == null ? (scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments_) : String) : tickFormat_;
3334

3435
// Minor ticks.
@@ -176,6 +177,12 @@ d3.svg.axis = function() {
176177
return axis;
177178
};
178179

180+
axis.tickValues = function(x) {
181+
if (!arguments.length) return tickValues;
182+
tickValues = x;
183+
return axis;
184+
};
185+
179186
return axis;
180187
};
181188

test/svg/axis-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,9 @@ suite.addBatch({
200200
assert.equal(t.length, 2);
201201
},
202202
"can be given as array of positions": function(axis) {
203-
var l = [1, 2.5, 3], a = axis().ticks(l), t = a.ticks();
204-
assert.equal(t[0], l);
205-
assert.equal(t.length, 1);
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);
206206
},
207207
"passes any arguments to the scale's ticks function": function(axis) {
208208
var x = d3.scale.linear(), b = {}, a = axis().ticks(b, 42).scale(x), aa = [],

0 commit comments

Comments
 (0)