Commit 95bc9f41 authored by Mike Bostock's avatar Mike Bostock
Browse files

Fix log.nice.

parent f281e7c2
{
"name": "d3",
"version": "3.2.5",
"version": "3.2.6",
"main": "d3.js",
"scripts": [
"d3.js"
......
......@@ -10,7 +10,7 @@
"animation",
"canvas"
],
"version": "3.2.5",
"version": "3.2.6",
"main": "index-browserify.js",
"scripts": [
"d3.js",
......
d3 = function() {
var d3 = {
version: "3.2.5"
version: "3.2.6"
};
if (!Date.now) Date.now = function() {
return +new Date();
......@@ -6836,10 +6836,13 @@ d3 = function() {
scale.base = function(_) {
if (!arguments.length) return base;
base = +_;
return scale.domain(domain);
linear.domain(domain.map(log));
return scale;
};
scale.nice = function() {
domain = d3_scale_nice(linear.domain(), positive ? Math : d3_scale_logNiceNegative).map(pow);
var niced = d3_scale_nice(domain.map(log), positive ? Math : d3_scale_logNiceNegative);
linear.domain(niced);
domain = niced.map(pow);
return scale;
};
scale.ticks = function() {
......
This diff is collapsed.
{
"name": "d3",
"version": "3.2.5",
"version": "3.2.6",
"description": "A small, free JavaScript library for manipulating documents based on data.",
"keywords": [
"dom",
......
......@@ -35,11 +35,14 @@ function d3_scale_log(linear, base, positive, domain) {
scale.base = function(_) {
if (!arguments.length) return base;
base = +_;
return scale.domain(domain);
linear.domain(domain.map(log));
return scale;
};
scale.nice = function() {
domain = d3_scale_nice(linear.domain(), positive ? Math : d3_scale_logNiceNegative).map(pow);
var niced = d3_scale_nice(domain.map(log), positive ? Math : d3_scale_logNiceNegative);
linear.domain(niced); // do not modify the linear scale’s domain in-place!
domain = niced.map(pow);
return scale;
};
......
d3 = (function(){
var d3 = {version: "3.2.5"}; // semver
var d3 = {version: "3.2.6"}; // semver
......@@ -306,6 +306,12 @@ suite.addBatch({
assert.inDelta(x.domain(), [1, 1.5, 100], 1e-6);
var x = d3.scale.log().domain([-123.1, -1.5, -.5]).nice();
assert.inDelta(x.domain(), [-1000, -1.5, -.1], 1e-6);
},
"the niced domain is subsequently used by the scale": function(d3) {
var x = d3.scale.log().domain([1.5, 50]).nice();
assert.inDelta(x.domain(), [1, 100], 1e-6);
assert.inDelta(x(1), 0, 1e-6);
assert.inDelta(x(100), 1, 1e-6);
}
},
......@@ -351,6 +357,19 @@ suite.addBatch({
assert.inDelta(x(20), 1.30103, 1e-6);
assert.inDelta(y(20), 1.30103, 1e-6);
assert.isFalse(x.clamp());
},
"changes to nicing are isolated": function(d3) {
var x = d3.scale.log().domain([1.5, 50]), y = x.copy().nice();
assert.inDelta(x.domain(), [1.5, 50], 1e-6);
assert.inDelta(x(1.5), 0, 1e-6);
assert.inDelta(x(50), 1, 1e-6);
assert.inDelta(x.invert(0), 1.5, 1e-6);
assert.inDelta(x.invert(1), 50, 1e-6);
assert.inDelta(y.domain(), [1, 100], 1e-6);
assert.inDelta(y(1), 0, 1e-6);
assert.inDelta(y(100), 1, 1e-6);
assert.inDelta(y.invert(0), 1, 1e-6);
assert.inDelta(y.invert(1), 100, 1e-6);
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment