diff --git a/README.md b/README.md index 8d10606..c757535 100644 --- a/README.md +++ b/README.md @@ -313,7 +313,7 @@ Like [*continuous*.ticks](#continuous_ticks), but customized for a log scale. If # log.tickFormat([count[, specifier]]) -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. # log.nice() @@ -577,15 +577,15 @@ If *range* is specified, sets the scale’s range to the specified array of valu # quantize.ticks([count]) -Equivalent to [*linear*.ticks](#linear_ticks). +Equivalent to [*continuous*.ticks](#continuous_ticks). # quantize.tickFormat([count[, specifier]]) -Equivalent to [*linear*.tickFormat](#linear_tickFormat). +Equivalent to [*continuous*.tickFormat](#continuous_tickFormat). # quantize.nice() -Equivalent to [*linear*.nice](#linear_nice). +Equivalent to [*continuous*.nice](#continuous_nice). # quantize.copy() diff --git a/package.json b/package.json index 639d15a..3a45a96 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/log.js b/src/log.js index 6350bb0..b0778f7 100644 --- a/src/log.js +++ b/src/log.js @@ -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))); diff --git a/test/log-test.js b/test/log-test.js index 4898d42..d5f17ee 100644 --- a/test/log-test.js +++ b/test/log-test.js @@ -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" @@ -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(); }); @@ -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"