Skip to content

Commit

Permalink
The default log tick format count is now 10.
Browse files Browse the repository at this point in the history
Previously if you didn’t specify a log tick format count, the ticks would not be
filtered. Now, for consistency with other scales, it defaults to ten. If you
want unfiltered ticks, you can specify a count of Infinity.

Fixes d3/d3-axis#3.
  • Loading branch information
mbostock committed Jan 27, 2016
1 parent fd07dd8 commit a30349f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ Like [*continuous*.ticks](#continuous_ticks), but customized for a log scale. If

<a name="log_tickFormat" href="#log_tickFormat">#</a> <i>log</i>.<b>tickFormat</b>([<i>count</i>[, <i>specifier</i>]])

Like [*continuous*.tickFormat](#continuous_tickFormat), but customized for a log scale. If a *count* is specified, then the formatter may return the empty string for some of the tick labels; this is useful if there is not enough room to fit all of the tick labels, but you still want to display the tick marks to show the log scale distortion. When specifying a count, you may also provide a format *specifier* or format function. For example, to get a tick formatter that will display 20 ticks of a currency, say `log.tickFormat(20, "$,f")`. If the specifier does not have a defined precision, the precision will be set automatically by the scale, returning the appropriate format. This provides a convenient, declarative way of specifying a format whose precision will be automatically set by the scale.
Like [*continuous*.tickFormat](#continuous_tickFormat), but customized for a log scale. The specified *count* typically has the same value as the count that is used to generate the [tick values](#continuous_ticks). If there are too many ticks, the formatter may return the empty string for some of the tick labels; however, note that the ticks are still shown. To disable filtering, specify a *count* of Infinity. When specifying a count, you may also provide a format *specifier* or format function. For example, to get a tick formatter that will display 20 ticks of a currency, say `log.tickFormat(20, "$,f")`. If the specifier does not have a defined precision, the precision will be set automatically by the scale, returning the appropriate format. This provides a convenient way of specifying a format whose precision will be automatically set by the scale.

<a name="log_nice" href="#log_nice">#</a> <i>log</i>.<b>nice</b>()

Expand Down Expand Up @@ -577,15 +577,15 @@ If *range* is specified, sets the scale’s range to the specified array of valu

<a name="quantize_ticks" href="#quantize_ticks">#</a> <i>quantize</i>.<b>ticks</b>([<i>count</i>])

Equivalent to [*linear*.ticks](#linear_ticks).
Equivalent to [*continuous*.ticks](#continuous_ticks).

<a name="quantize_tickFormat" href="#quantize_tickFormat">#</a> <i>quantize</i>.<b>tickFormat</b>([<i>count</i>[, <i>specifier</i>]])

Equivalent to [*linear*.tickFormat](#linear_tickFormat).
Equivalent to [*continuous*.tickFormat](#continuous_tickFormat).

<a name="quantize_nice" href="#quantize_nice">#</a> <i>quantize</i>.<b>nice</b>()

Equivalent to [*linear*.nice](#linear_nice).
Equivalent to [*continuous*.nice](#continuous_nice).

<a name="quantize_copy" href="#quantize_copy">#</a> <i>quantize</i>.<b>copy</b>()

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "d3-scale",
"version": "0.5.1",
"version": "0.5.2",
"description": "Encodings that map abstract data to visual representation.",
"keywords": [
"d3",
Expand Down
3 changes: 2 additions & 1 deletion src/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ export default function log() {
scale.tickFormat = function(count, specifier) {
if (specifier == null) specifier = base === 10 ? tickFormat10 : tickFormatOther;
else if (typeof specifier !== "function") specifier = format(specifier);
if (count == null) return specifier;
if (count === Infinity) return specifier;
if (count == null) count = 10;
var k = Math.max(1, base * count / scale.ticks().length); // TODO fast estimate?
return function(d) {
var i = d / pows(Math.round(logs(d)));
Expand Down
12 changes: 6 additions & 6 deletions test/log-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ tape("log.domain(…) coerces values to numbers", function(test) {

tape("log.domain(…) can take negative values", function(test) {
var x = scale.scaleLog().domain([-100, -1]);
test.deepEqual(x.ticks().map(x.tickFormat()), [
test.deepEqual(x.ticks().map(x.tickFormat(Infinity)), [
"-1e+2",
"-9e+1", "-8e+1", "-7e+1", "-6e+1", "-5e+1", "-4e+1", "-3e+1", "-2e+1", "-1e+1",
"-9e+0", "-8e+0", "-7e+0", "-6e+0", "-5e+0", "-4e+0", "-3e+0", "-2e+0", "-1e+0"
Expand Down Expand Up @@ -305,9 +305,9 @@ tape("log.base(base).ticks() generates the expected power-of-base ticks", functi
test.end();
});

tape("log.tickFormat() returns the \".0e\" format", function(test) {
tape("log.tickFormat() is equivalent to log.tickFormat(10)", function(test) {
var s = scale.scaleLog();
test.deepEqual(s.domain([1e-1, 1e1]).ticks().map(s.tickFormat()), ["1e-1", "2e-1", "3e-1", "4e-1", "5e-1", "6e-1", "7e-1", "8e-1", "9e-1", "1e+0", "2e+0", "3e+0", "4e+0", "5e+0", "6e+0", "7e+0", "8e+0", "9e+0", "1e+1"]);
test.deepEqual(s.domain([1e-1, 1e1]).ticks().map(s.tickFormat()), ["1e-1", "2e-1", "3e-1", "4e-1", "5e-1", "", "", "", "", "1e+0", "2e+0", "3e+0", "4e+0", "5e+0", "", "", "", "", "1e+1"]);
test.end();
});

Expand Down Expand Up @@ -342,18 +342,18 @@ tape("log.base(base).tickFormat(count) returns a filtered \",\" format", functio

tape("log.ticks() generates log ticks", function(test) {
var x = scale.scaleLog();
test.deepEqual(x.ticks().map(x.tickFormat()), [
test.deepEqual(x.ticks().map(x.tickFormat(Infinity)), [
"1e+0", "2e+0", "3e+0", "4e+0", "5e+0", "6e+0", "7e+0", "8e+0", "9e+0",
"1e+1"
]);
x.domain([100, 1]);
test.deepEqual(x.ticks().map(x.tickFormat()), [
test.deepEqual(x.ticks().map(x.tickFormat(Infinity)), [
"1e+2",
"9e+1", "8e+1", "7e+1", "6e+1", "5e+1", "4e+1", "3e+1", "2e+1", "1e+1",
"9e+0", "8e+0", "7e+0", "6e+0", "5e+0", "4e+0", "3e+0", "2e+0", "1e+0",
]);
x.domain([0.49999, 0.006029505943610648]);
test.deepEqual(x.ticks().map(x.tickFormat()), [
test.deepEqual(x.ticks().map(x.tickFormat(Infinity)), [
"4e-1", "3e-1", "2e-1", "1e-1",
"9e-2", "8e-2", "7e-2", "6e-2", "5e-2", "4e-2", "3e-2", "2e-2", "1e-2",
"9e-3", "8e-3", "7e-3"
Expand Down

0 comments on commit a30349f

Please sign in to comment.