Skip to content

Commit

Permalink
axis.tickValues accepts an iterable (#77)
Browse files Browse the repository at this point in the history
* axis.tickValues accepts an iterable

* Array.from

Co-authored-by: Mike Bostock <[email protected]>
  • Loading branch information
Fil and mbostock authored Jun 9, 2021
1 parent 8c091c1 commit 71298ac
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ See also [*axis*.ticks](#axis_ticks).

<a name="axis_tickValues" href="#axis_tickValues">#</a> <i>axis</i>.<b>tickValues</b>([<i>values</i>]) · [Source](https://github.com/d3/d3-axis/blob/master/src/axis.js)

If a *values* array is specified, the specified values are used for ticks rather than using the scale’s automatic tick generator. If *values* is null, clears any previously-set explicit tick values and reverts back to the scale’s tick generator. If *values* is not specified, returns the current tick values, which defaults to null. For example, to generate ticks at specific values:
If a *values* iterable is specified, the specified values are used for ticks rather than using the scale’s automatic tick generator. If *values* is null, clears any previously-set explicit tick values and reverts back to the scale’s tick generator. If *values* is not specified, returns the current tick values, which defaults to null. For example, to generate ticks at specific values:

```js
var xAxis = d3.axisBottom(x)
Expand Down
1 change: 0 additions & 1 deletion src/array.js

This file was deleted.

7 changes: 3 additions & 4 deletions src/axis.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {slice} from "./array.js";
import identity from "./identity.js";

var top = 1,
Expand Down Expand Up @@ -120,15 +119,15 @@ function axis(orient, scale) {
};

axis.ticks = function() {
return tickArguments = slice.call(arguments), axis;
return tickArguments = Array.from(arguments), axis;
};

axis.tickArguments = function(_) {
return arguments.length ? (tickArguments = _ == null ? [] : slice.call(_), axis) : tickArguments.slice();
return arguments.length ? (tickArguments = _ == null ? [] : Array.from(_), axis) : tickArguments.slice();
};

axis.tickValues = function(_) {
return arguments.length ? (tickValues = _ == null ? null : slice.call(_), axis) : tickValues && tickValues.slice();
return arguments.length ? (tickValues = _ == null ? null : Array.from(_), axis) : tickValues && tickValues.slice();
};

axis.tickFormat = function(_) {
Expand Down
1 change: 1 addition & 0 deletions test/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
},
"env": {
"browser": true,
"es6": true,
"node": true,
"mocha": true
}
Expand Down
5 changes: 5 additions & 0 deletions test/axis-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,8 @@ it("axis.tickValues() makes a defensive copy of the tick values", () => {
v.push(4);
assert.deepStrictEqual(a.tickValues(), [1, 2, 3]);
});

it("axis.tickValues(values) accepts an iterable", () => {
const a = axisLeft(scaleLinear()).tickValues(new Set([1, 2, 3]));
assert.deepStrictEqual(a.tickValues(), [1, 2, 3]);
});

0 comments on commit 71298ac

Please sign in to comment.