Commit 49ba8afe authored by Mike Bostock's avatar Mike Bostock
Browse files

Merge branch '3.4.6'

parents 624f21c9 55dc3a20
{ {
"name": "d3", "name": "d3",
"version": "3.4.5", "version": "3.4.6",
"main": "d3.js", "main": "d3.js",
"scripts": [ "scripts": [
"d3.js" "d3.js"
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
"animation", "animation",
"canvas" "canvas"
], ],
"version": "3.4.5", "version": "3.4.6",
"main": "d3.js", "main": "d3.js",
"scripts": [ "scripts": [
"d3.js" "d3.js"
......
!function() { !function() {
var d3 = { var d3 = {
version: "3.4.5" version: "3.4.6"
}; };
if (!Date.now) Date.now = function() { if (!Date.now) Date.now = function() {
return +new Date(); return +new Date();
...@@ -91,13 +91,13 @@ ...@@ -91,13 +91,13 @@
return x != null && !isNaN(x); return x != null && !isNaN(x);
} }
d3.mean = function(array, f) { d3.mean = function(array, f) {
var n = array.length, a, m = 0, i = -1, j = 0; var s = 0, n = array.length, a, i = -1, j = n;
if (arguments.length === 1) { if (arguments.length === 1) {
while (++i < n) if (d3_number(a = array[i])) m += (a - m) / ++j; while (++i < n) if (d3_number(a = array[i])) s += a; else --j;
} else { } else {
while (++i < n) if (d3_number(a = f.call(array, array[i], i))) m += (a - m) / ++j; while (++i < n) if (d3_number(a = f.call(array, array[i], i))) s += a; else --j;
} }
return j ? m : undefined; return j ? s / j : undefined;
}; };
d3.quantile = function(values, p) { d3.quantile = function(values, p) {
var H = (values.length - 1) * p + 1, h = Math.floor(H), v = +values[h - 1], e = H - h; var H = (values.length - 1) * p + 1, h = Math.floor(H), v = +values[h - 1], e = H - h;
...@@ -2675,7 +2675,7 @@ ...@@ -2675,7 +2675,7 @@
return n ? (date.y = d3_time_expandYear(+n[0]), i + n[0].length) : -1; return n ? (date.y = d3_time_expandYear(+n[0]), i + n[0].length) : -1;
} }
function d3_time_parseZone(date, string, i) { function d3_time_parseZone(date, string, i) {
return /^[+-]\d{4}$/.test(string = string.substring(i, i + 5)) ? (date.Z = +string, return /^[+-]\d{4}$/.test(string = string.substring(i, i + 5)) ? (date.Z = -string,
i + 5) : -1; i + 5) : -1;
} }
function d3_time_expandYear(d) { function d3_time_expandYear(d) {
...@@ -7703,9 +7703,7 @@ ...@@ -7703,9 +7703,7 @@
} }
scale.domain = function(x) { scale.domain = function(x) {
if (!arguments.length) return domain; if (!arguments.length) return domain;
domain = x.filter(function(d) { domain = x.filter(d3_number).sort(d3_ascending);
return !isNaN(d);
}).sort(d3_ascending);
return rescale(); return rescale();
}; };
scale.range = function(x) { scale.range = function(x) {
......
This source diff could not be displayed because it is too large. You can view the blob instead.
{ {
"name": "d3", "name": "d3",
"version": "3.4.5", "version": "3.4.6",
"description": "A small, free JavaScript library for manipulating documents based on data.", "description": "A small, free JavaScript library for manipulating documents based on data.",
"keywords": [ "keywords": [
"dom", "dom",
......
import "../math/number"; import "../math/number";
d3.mean = function(array, f) { d3.mean = function(array, f) {
var n = array.length, var s = 0,
n = array.length,
a, a,
m = 0,
i = -1, i = -1,
j = 0; j = n;
if (arguments.length === 1) { if (arguments.length === 1) {
while (++i < n) if (d3_number(a = array[i])) m += (a - m) / ++j; while (++i < n) if (d3_number(a = array[i])) s += a; else --j;
} else { } else {
while (++i < n) if (d3_number(a = f.call(array, array[i], i))) m += (a - m) / ++j; while (++i < n) if (d3_number(a = f.call(array, array[i], i))) s += a; else --j;
} }
return j ? m : undefined; return j ? s / j : undefined;
}; };
...@@ -292,7 +292,7 @@ function d3_time_parseYear(date, string, i) { ...@@ -292,7 +292,7 @@ function d3_time_parseYear(date, string, i) {
function d3_time_parseZone(date, string, i) { function d3_time_parseZone(date, string, i) {
return /^[+-]\d{4}$/.test(string = string.substring(i, i + 5)) return /^[+-]\d{4}$/.test(string = string.substring(i, i + 5))
? (date.Z = +string, i + 5) ? (date.Z = -string, i + 5) // sign differs from getTimezoneOffset!
: -1; : -1;
} }
......
import "../arrays/ascending"; import "../arrays/ascending";
import "../arrays/bisect"; import "../arrays/bisect";
import "../arrays/quantile"; import "../arrays/quantile";
import "../math/number";
import "scale"; import "scale";
d3.scale.quantile = function() { d3.scale.quantile = function() {
...@@ -24,7 +25,7 @@ function d3_scale_quantile(domain, range) { ...@@ -24,7 +25,7 @@ function d3_scale_quantile(domain, range) {
scale.domain = function(x) { scale.domain = function(x) {
if (!arguments.length) return domain; if (!arguments.length) return domain;
domain = x.filter(function(d) { return !isNaN(d); }).sort(d3_ascending); domain = x.filter(d3_number).sort(d3_ascending);
return rescale(); return rescale();
}; };
......
!function(){ !function(){
var d3 = {version: "3.4.5"}; // semver var d3 = {version: "3.4.6"}; // semver
...@@ -18,10 +18,6 @@ suite.addBatch({ ...@@ -18,10 +18,6 @@ suite.addBatch({
assert.equal(mean([1, 2, 3, 4, 5, NaN]), 3); assert.equal(mean([1, 2, 3, 4, 5, NaN]), 3);
assert.equal(mean([10, null, 3, undefined, 5, NaN]), 6); assert.equal(mean([10, null, 3, undefined, 5, NaN]), 6);
}, },
"can handle large numbers without overflowing": function(mean) {
assert.equal(mean([Number.MAX_VALUE, Number.MAX_VALUE]), Number.MAX_VALUE);
assert.equal(mean([-Number.MAX_VALUE, -Number.MAX_VALUE]), -Number.MAX_VALUE);
},
"returns undefined for empty array": function(mean) { "returns undefined for empty array": function(mean) {
assert.isUndefined(mean([])); assert.isUndefined(mean([]));
assert.isUndefined(mean([null])); assert.isUndefined(mean([null]));
......
...@@ -30,7 +30,7 @@ suite.addBatch({ ...@@ -30,7 +30,7 @@ suite.addBatch({
assert.deepEqual(x.domain(), [3, 6, 7, 8, 8, 10, 13, 15, 16, 20]); assert.deepEqual(x.domain(), [3, 6, 7, 8, 8, 10, 13, 15, 16, 20]);
}, },
"non-numeric domain values are ignored": function(quantile) { "non-numeric domain values are ignored": function(quantile) {
var x = quantile().domain([6, 3, NaN, undefined, 7, 8, 8, 13, 20, 15, 16, 10, NaN]); var x = quantile().domain([6, 3, NaN, undefined, 7, 8, 8, 13, null, 20, 15, 16, 10, NaN]);
assert.deepEqual(x.domain(), [3, 6, 7, 8, 8, 10, 13, 15, 16, 20]); assert.deepEqual(x.domain(), [3, 6, 7, 8, 8, 10, 13, 15, 16, 20]);
}, },
"quantiles returns the inner thresholds": function(quantile) { "quantiles returns the inner thresholds": function(quantile) {
......
...@@ -328,8 +328,9 @@ suite.addBatch({ ...@@ -328,8 +328,9 @@ suite.addBatch({
"parses timezone offset": function(format) { "parses timezone offset": function(format) {
var p = format("%m/%d/%Y %Z").parse; var p = format("%m/%d/%Y %Z").parse;
assert.deepEqual(p("01/02/1990 +0000"), local(1990, 0, 1, 16)); assert.deepEqual(p("01/02/1990 +0000"), local(1990, 0, 1, 16));
assert.deepEqual(p("01/02/1990 +0100"), local(1990, 0, 1, 17)); assert.deepEqual(p("01/02/1990 +0100"), local(1990, 0, 1, 15));
assert.deepEqual(p("01/02/1990 -0100"), local(1990, 0, 1, 15)); assert.deepEqual(p("01/02/1990 -0100"), local(1990, 0, 1, 17));
assert.deepEqual(p("01/02/1990 -0800"), local(1990, 0, 2, 0));
}, },
"ignores optional padding modifier, skipping zeroes and spaces": function(format) { "ignores optional padding modifier, skipping zeroes and spaces": function(format) {
var p = format("%-m/%0d/%_Y").parse; var p = format("%-m/%0d/%_Y").parse;
......
...@@ -215,8 +215,9 @@ suite.addBatch({ ...@@ -215,8 +215,9 @@ suite.addBatch({
"parses timezone offset": function(format) { "parses timezone offset": function(format) {
var p = format("%m/%d/%Y %Z").parse; var p = format("%m/%d/%Y %Z").parse;
assert.deepEqual(p("01/02/1990 +0000"), utc(1990, 0, 2)); assert.deepEqual(p("01/02/1990 +0000"), utc(1990, 0, 2));
assert.deepEqual(p("01/02/1990 +0100"), utc(1990, 0, 2, 1)); assert.deepEqual(p("01/02/1990 +0100"), utc(1990, 0, 1, 23));
assert.deepEqual(p("01/02/1990 -0100"), utc(1990, 0, 1, 23)); assert.deepEqual(p("01/02/1990 -0100"), utc(1990, 0, 2, 1));
assert.deepEqual(p("01/02/1990 -0800"), time.local(1990, 0, 2));
} }
} }
} }
......
var offset = 0; var offset = 0;
exports.local = function(year, month, day, hours, minutes, seconds, milliseconds) { exports.local = function(year, month, day, hours, minutes, seconds, milliseconds) {
var date = new Date(); var date = new Date;
date.setFullYear(year, month, day); date.setFullYear(year, month, day);
date.setHours(hours || 0, offset + (minutes || 0), seconds || 0, milliseconds || 0); date.setHours(hours || 0, offset + (minutes || 0), seconds || 0, milliseconds || 0);
return date; return date;
}; };
exports.utc = function(year, month, day, hours, minutes, seconds, milliseconds) { exports.utc = function(year, month, day, hours, minutes, seconds, milliseconds) {
var date = new Date(); var date = new Date;
date.setUTCFullYear(year, month, day); date.setUTCFullYear(year, month, day);
date.setUTCHours(hours || 0, minutes || 0, seconds || 0, milliseconds || 0); date.setUTCHours(hours || 0, minutes || 0, seconds || 0, milliseconds || 0);
return date; return date;
......
Markdown is supported
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