Permalink
Browse files

Merge branch 'release'

  • Loading branch information...
mbostock committed Jun 17, 2011
2 parents e2119b8 + 27158fd commit 68424aeff4fd0436033d66b6cff17c913ff56e41
View
@@ -37,6 +37,7 @@ d3.core.js: \
src/core/descending.js \
src/core/min.js \
src/core/max.js \
+ src/core/sum.js \
src/core/zip.js \
src/core/bisect.js \
src/core/nest.js \
@@ -146,6 +147,8 @@ d3.time.js: \
src/start.js \
src/time/time.js \
src/time/format.js \
+ src/time/format-utc.js \
+ src/time/format-iso.js \
src/end.js
d3.geom.js: \
@@ -171,6 +174,7 @@ tests: \
tests/test-keys.test \
tests/test-max.test \
tests/test-min.test \
+ tests/test-sum.test \
tests/test-nest.test \
tests/test-permute.test \
tests/test-zip.test \
@@ -179,7 +183,11 @@ tests: \
tests/test-round.test \
tests/test-hsl.test \
tests/test-time-format.test \
+ tests/test-time-format-iso.test \
+ tests/test-time-format-utc.test \
tests/test-time-parse.test \
+ tests/test-time-parse-iso.test \
+ tests/test-time-parse-utc.test \
tests/test-transition.test \
tests/test-scale-linear.test \
tests/test-scale-polylinear.test \
View
16 d3.js
@@ -1,4 +1,4 @@
-(function(){d3 = {version: "1.20.3"}; // semver
+(function(){d3 = {version: "1.21.0"}; // semver
if (!Date.now) Date.now = function() {
return +new Date;
};
@@ -68,6 +68,20 @@ d3.max = function(array, f) {
}
return a;
};
+d3.sum = function(array, f) {
+ var s = 0,
+ n = array.length,
+ a,
+ i = -1;
+
+ if (arguments.length === 1) {
+ while (++i < n) if (!isNaN(a = +array[i])) s += a;
+ } else {
+ while (++i < n) if (!isNaN(a = +f.call(array, array[i], i))) s += a;
+ }
+
+ return s;
+};
d3.zip = function() {
if (!(n = arguments.length)) return [];
for (var i = -1, m = d3.min(arguments, d3_zipLength), zips = new Array(m); ++i < m;) {
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -1,4 +1,6 @@
(function(){d3.time = {};
+
+var d3_time = Date;
d3.time.format = function(template) {
var n = template.length;
@@ -22,7 +24,7 @@ d3.time.format = function(template) {
}
format.parse = function(string) {
- var date = new Date(1900, 0, 1),
+ var date = new d3_time(1900, 0, 1),
i = d3_time_parse(date, template, string, 0);
if (i != string.length) return null;
if (date.hour12) {
@@ -85,7 +87,7 @@ var d3_time_formats = {
W: d3_time_weekNumberMonday,
x: d3.time.format("%m/%d/%y"),
X: d3.time.format("%H:%M:%S"),
- y: function(d) { return d3_time_zfill2(d.getYear() % 100); },
+ y: function(d) { return d3_time_zfill2(d.getFullYear() % 100); },
Y: function(d) { return d3_time_zfill4(d.getFullYear() % 10000); },
Z: d3_time_zone,
"%": function(d) { return "%"; }
@@ -288,17 +290,21 @@ var d3_time_amPmLookup = {
pm: 1
};
+function d3_time_year(d) {
+ return new d3_time(d.getFullYear(), 0, 1);
+}
+
function d3_time_dayOfYear(d) {
- return d3_time_zfill3(1 + ~~((d - new Date(d.getFullYear(), 0, 1)) / 864e5));
+ return d3_time_zfill3(1 + ~~((d - d3_time_year(d)) / 864e5));
}
function d3_time_weekNumberSunday(d) {
- var d0 = new Date(d.getFullYear(), 0, 1);
+ var d0 = d3_time_year(d);
return d3_time_zfill2(~~(((d - d0) / 864e5 + d0.getDay()) / 7));
}
function d3_time_weekNumberMonday(d) {
- var d0 = new Date(d.getFullYear(), 0, 1);
+ var d0 = d3_time_year(d);
return d3_time_zfill2(~~(((d - d0) / 864e5 + (d0.getDay() + 6) % 7) / 7));
}
@@ -310,4 +316,53 @@ function d3_time_zone(d) {
zm = Math.abs(z) % 60;
return zs + d3_time_zfill2(zh) + d3_time_zfill2(zm);
}
+d3.time.format.utc = function(template) {
+ var local = d3.time.format(template);
+
+ function format(date) {
+ var utc = new d3_time_format_utc();
+ utc._ = date;
+ return local(utc);
+ }
+
+ format.parse = function(string) {
+ try {
+ d3_time = d3_time_format_utc;
+ var date = local.parse(string);
+ return date && date._;
+ } finally {
+ d3_time = Date;
+ }
+ };
+
+ format.toString = local.toString;
+
+ return format;
+};
+
+function d3_time_format_utc() {
+ this._ = new Date(Date.UTC.apply(this, arguments));
+}
+
+d3_time_format_utc.prototype = {
+ getDate: function() { return this._.getUTCDate(); },
+ getDay: function() { return this._.getUTCDay(); },
+ getFullYear: function() { return this._.getUTCFullYear(); },
+ getHours: function() { return this._.getUTCHours(); },
+ getMilliseconds: function() { return this._.getUTCMilliseconds(); },
+ getMinutes: function() { return this._.getUTCMinutes(); },
+ getMonth: function() { return this._.getUTCMonth(); },
+ getSeconds: function() { return this._.getUTCSeconds(); },
+ getTimezoneOffset: function() { return 0; },
+ valueOf: function() { return this._.getTime(); },
+ setDate: function(x) { this._.setUTCDate(x); },
+ setDay: function(x) { this._.setUTCDay(x); },
+ setFullYear: function(x) { this._.setUTCFullYear(x); },
+ setHours: function(x) { this._.setUTCHours(x); },
+ setMilliseconds: function(x) { this._.setUTCMilliseconds(x); },
+ setMinutes: function(x) { this._.setUTCMinutes(x); },
+ setMonth: function(x) { this._.setUTCMonth(x); },
+ setSeconds: function(x) { this._.setUTCSeconds(x); }
+};
+d3.time.format.iso = d3.time.format.utc("%Y-%m-%dT%H:%M:%SZ");
})();
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -1,6 +1,6 @@
var w = 960,
h = 500,
- mouse = [0, 0],
+ mouse = [null, null],
fill = d3.scale.linear().domain([0, 1e4]).range(["brown", "steelblue"]);
// Initialise boids.
@@ -16,6 +16,8 @@ var vertices = boids.map(function(boid) {
return boid(boids);
});
+d3.select(window).on("blur", nullGravity);
+
var svg = d3.select("#vis")
.append("svg:svg")
.attr("width", w)
@@ -25,7 +27,8 @@ var svg = d3.select("#vis")
var m = d3.svg.mouse(this);
mouse[0] = m[0];
mouse[1] = m[1];
- });
+ })
+ .on("mouseout", nullGravity);
svg.selectAll("path")
.data(d3.geom.voronoi(vertices))
@@ -56,3 +59,7 @@ d3.timer(function() {
.attr("d", function(d) { return "M" + d.join("L") + "Z"; })
.style("fill", function(d) { return fill((d3.geom.polygon(d).area())); });
});
+
+function nullGravity() {
+ mouse[0] = mouse[1] = null;
+}
View
@@ -1 +1 @@
-d3 = {version: "1.20.3"}; // semver
+d3 = {version: "1.21.0"}; // semver
View
@@ -0,0 +1,14 @@
+d3.sum = function(array, f) {
+ var s = 0,
+ n = array.length,
+ a,
+ i = -1;
+
+ if (arguments.length === 1) {
+ while (++i < n) if (!isNaN(a = +array[i])) s += a;
+ } else {
+ while (++i < n) if (!isNaN(a = +f.call(array, array[i], i))) s += a;
+ }
+
+ return s;
+};
View
@@ -0,0 +1 @@
+d3.time.format.iso = d3.time.format.utc("%Y-%m-%dT%H:%M:%SZ");
View
@@ -0,0 +1,48 @@
+d3.time.format.utc = function(template) {
+ var local = d3.time.format(template);
+
+ function format(date) {
+ var utc = new d3_time_format_utc();
+ utc._ = date;
+ return local(utc);
+ }
+
+ format.parse = function(string) {
+ try {
+ d3_time = d3_time_format_utc;
+ var date = local.parse(string);
+ return date && date._;
+ } finally {
+ d3_time = Date;
+ }
+ };
+
+ format.toString = local.toString;
+
+ return format;
+};
+
+function d3_time_format_utc() {
+ this._ = new Date(Date.UTC.apply(this, arguments));
+}
+
+d3_time_format_utc.prototype = {
+ getDate: function() { return this._.getUTCDate(); },
+ getDay: function() { return this._.getUTCDay(); },
+ getFullYear: function() { return this._.getUTCFullYear(); },
+ getHours: function() { return this._.getUTCHours(); },
+ getMilliseconds: function() { return this._.getUTCMilliseconds(); },
+ getMinutes: function() { return this._.getUTCMinutes(); },
+ getMonth: function() { return this._.getUTCMonth(); },
+ getSeconds: function() { return this._.getUTCSeconds(); },
+ getTimezoneOffset: function() { return 0; },
+ valueOf: function() { return this._.getTime(); },
+ setDate: function(x) { this._.setUTCDate(x); },
+ setDay: function(x) { this._.setUTCDay(x); },
+ setFullYear: function(x) { this._.setUTCFullYear(x); },
+ setHours: function(x) { this._.setUTCHours(x); },
+ setMilliseconds: function(x) { this._.setUTCMilliseconds(x); },
+ setMinutes: function(x) { this._.setUTCMinutes(x); },
+ setMonth: function(x) { this._.setUTCMonth(x); },
+ setSeconds: function(x) { this._.setUTCSeconds(x); }
+};
View
@@ -21,7 +21,7 @@ d3.time.format = function(template) {
}
format.parse = function(string) {
- var date = new Date(1900, 0, 1),
+ var date = new d3_time(1900, 0, 1),
i = d3_time_parse(date, template, string, 0);
if (i != string.length) return null;
if (date.hour12) {
@@ -84,7 +84,7 @@ var d3_time_formats = {
W: d3_time_weekNumberMonday,
x: d3.time.format("%m/%d/%y"),
X: d3.time.format("%H:%M:%S"),
- y: function(d) { return d3_time_zfill2(d.getYear() % 100); },
+ y: function(d) { return d3_time_zfill2(d.getFullYear() % 100); },
Y: function(d) { return d3_time_zfill4(d.getFullYear() % 10000); },
Z: d3_time_zone,
"%": function(d) { return "%"; }
@@ -287,17 +287,21 @@ var d3_time_amPmLookup = {
pm: 1
};
+function d3_time_year(d) {
+ return new d3_time(d.getFullYear(), 0, 1);
+}
+
function d3_time_dayOfYear(d) {
- return d3_time_zfill3(1 + ~~((d - new Date(d.getFullYear(), 0, 1)) / 864e5));
+ return d3_time_zfill3(1 + ~~((d - d3_time_year(d)) / 864e5));
}
function d3_time_weekNumberSunday(d) {
- var d0 = new Date(d.getFullYear(), 0, 1);
+ var d0 = d3_time_year(d);
return d3_time_zfill2(~~(((d - d0) / 864e5 + d0.getDay()) / 7));
}
function d3_time_weekNumberMonday(d) {
- var d0 = new Date(d.getFullYear(), 0, 1);
+ var d0 = d3_time_year(d);
return d3_time_zfill2(~~(((d - d0) / 864e5 + (d0.getDay() + 6) % 7) / 7));
}
View
@@ -1 +1,3 @@
d3.time = {};
+
+var d3_time = Date;
Oops, something went wrong.

0 comments on commit 68424ae

Please sign in to comment.