Permalink
Browse files

Merge branch 'release'

  • Loading branch information...
2 parents 307016e + 639f802 commit 32907ec505b0adf63525a2a861dcc296b9cc7c4a @mbostock mbostock committed Oct 12, 2011
Showing with 93 additions and 22 deletions.
  1. +7 −4 d3.js
  2. +2 −2 d3.min.js
  3. +21 −1 d3.time.js
  4. +1 −1 d3.time.min.js
  5. +1 −1 package.json
  6. +1 −1 src/core/core.js
  7. +6 −3 src/scale/nice.js
  8. +13 −1 src/time/format-iso.js
  9. +8 −0 src/time/format.js
  10. +4 −0 test/scale/linear-test.js
  11. +4 −0 test/scale/log-test.js
  12. +4 −0 test/scale/pow-test.js
  13. +21 −8 test/time/format-test.js
View
11 d3.js
@@ -10,7 +10,7 @@ try {
d3_style_setProperty.call(this, name, value + "", priority);
};
}
-d3 = {version: "2.4.1"}; // semver
+d3 = {version: "2.4.2"}; // semver
var d3_array = d3_arraySlice; // conversion for NodeLists
function d3_arrayCopy(pseudoarray) {
@@ -2208,9 +2208,12 @@ function d3_scale_nice(domain, nice) {
dx = x0; x0 = x1; x1 = dx;
}
- nice = nice(x1 - x0);
- domain[i0] = nice.floor(x0);
- domain[i1] = nice.ceil(x1);
+ if (dx = x1 - x0) {
+ nice = nice(dx);
+ domain[i0] = nice.floor(x0);
+ domain[i1] = nice.ceil(x1);
+ }
+
return domain;
}
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -78,6 +78,7 @@ var d3_time_formats = {
H: function(d) { return d3_time_zfill2(d.getHours()); },
I: function(d) { return d3_time_zfill2(d.getHours() % 12 || 12); },
j: d3_time_dayOfYear,
+ L: function(d) { return d3_time_zfill3(d.getMilliseconds()); },
m: function(d) { return d3_time_zfill2(d.getMonth() + 1); },
M: function(d) { return d3_time_zfill2(d.getMinutes()); },
p: function(d) { return d.getHours() >= 12 ? "PM" : "AM"; },
@@ -104,6 +105,7 @@ var d3_time_parsers = {
H: d3_time_parseHour24,
I: d3_time_parseHour12,
// j: function(d, s, i) { /*TODO day of year [001,366] */ return i; },
+ L: d3_time_parseMilliseconds,
m: d3_time_parseMonthNumber,
M: d3_time_parseMinutes,
p: d3_time_parseAmPm,
@@ -277,6 +279,12 @@ function d3_time_parseSeconds(date, string, i) {
return n ? (date.setSeconds(+n[0]), i += n[0].length) : -1;
}
+function d3_time_parseMilliseconds(date, string, i) {
+ d3_time_numberRe.lastIndex = 0;
+ var n = d3_time_numberRe.exec(string.substring(i, i + 3));
+ return n ? (date.setMilliseconds(+n[0]), i += n[0].length) : -1;
+}
+
// Note: we don't look at the next directive.
var d3_time_numberRe = /\s*\d+/;
@@ -364,7 +372,19 @@ d3_time_format_utc.prototype = {
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");
+var d3_time_formatIso = d3.time.format.utc("%Y-%m-%dT%H:%M:%S.%LZ");
+
+d3.time.format.iso = Date.prototype.toISOString ? d3_time_formatIsoNative : d3_time_formatIso;
+
+function d3_time_formatIsoNative(date) {
+ return date.toISOString();
+}
+
+d3_time_formatIsoNative.parse = function(string) {
+ return new Date(string);
+};
+
+d3_time_formatIsoNative.toString = d3_time_formatIso.toString;
function d3_time_range(floor, step, number) {
return function(t0, t1, dt) {
var time = floor(t0), times = [];
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -1,6 +1,6 @@
{
"name": "d3",
- "version": "2.4.1",
+ "version": "2.4.2",
"description": "A small, free JavaScript library for manipulating documents based on data.",
"keywords": [
"dom",
View
@@ -1 +1 @@
-d3 = {version: "2.4.1"}; // semver
+d3 = {version: "2.4.2"}; // semver
View
@@ -10,9 +10,12 @@ function d3_scale_nice(domain, nice) {
dx = x0; x0 = x1; x1 = dx;
}
- nice = nice(x1 - x0);
- domain[i0] = nice.floor(x0);
- domain[i1] = nice.ceil(x1);
+ if (dx = x1 - x0) {
+ nice = nice(dx);
+ domain[i0] = nice.floor(x0);
+ domain[i1] = nice.ceil(x1);
+ }
+
return domain;
}
View
@@ -1 +1,13 @@
-d3.time.format.iso = d3.time.format.utc("%Y-%m-%dT%H:%M:%SZ");
+var d3_time_formatIso = d3.time.format.utc("%Y-%m-%dT%H:%M:%S.%LZ");
+
+d3.time.format.iso = Date.prototype.toISOString ? d3_time_formatIsoNative : d3_time_formatIso;
+
+function d3_time_formatIsoNative(date) {
+ return date.toISOString();
+}
+
+d3_time_formatIsoNative.parse = function(string) {
+ return new Date(string);
+};
+
+d3_time_formatIsoNative.toString = d3_time_formatIso.toString;
View
@@ -75,6 +75,7 @@ var d3_time_formats = {
H: function(d) { return d3_time_zfill2(d.getHours()); },
I: function(d) { return d3_time_zfill2(d.getHours() % 12 || 12); },
j: d3_time_dayOfYear,
+ L: function(d) { return d3_time_zfill3(d.getMilliseconds()); },
m: function(d) { return d3_time_zfill2(d.getMonth() + 1); },
M: function(d) { return d3_time_zfill2(d.getMinutes()); },
p: function(d) { return d.getHours() >= 12 ? "PM" : "AM"; },
@@ -101,6 +102,7 @@ var d3_time_parsers = {
H: d3_time_parseHour24,
I: d3_time_parseHour12,
// j: function(d, s, i) { /*TODO day of year [001,366] */ return i; },
+ L: d3_time_parseMilliseconds,
m: d3_time_parseMonthNumber,
M: d3_time_parseMinutes,
p: d3_time_parseAmPm,
@@ -274,6 +276,12 @@ function d3_time_parseSeconds(date, string, i) {
return n ? (date.setSeconds(+n[0]), i += n[0].length) : -1;
}
+function d3_time_parseMilliseconds(date, string, i) {
+ d3_time_numberRe.lastIndex = 0;
+ var n = d3_time_numberRe.exec(string.substring(i, i + 3));
+ return n ? (date.setMilliseconds(+n[0]), i += n[0].length) : -1;
+}
+
// Note: we don't look at the next directive.
var d3_time_numberRe = /\s*\d+/;
@@ -180,6 +180,10 @@ suite.addBatch({
assert.deepEqual(x.domain(), [130, 0]);
var x = linear().domain([0, .49]).nice();
assert.deepEqual(x.domain(), [0, .5]);
+ var x = linear().domain([0, 0]).nice();
+ assert.deepEqual(x.domain(), [0, 0]);
+ var x = linear().domain([.5, .5]).nice();
+ assert.deepEqual(x.domain(), [.5, .5]);
},
"nicing a polylinear domain only affects the extent": function(linear) {
var x = linear().domain([1.1, 1, 2, 3, 10.9]).nice();
View
@@ -194,6 +194,10 @@ suite.addBatch({
assert.deepEqual(x.domain(), [1000, 1]);
var x = log().domain([.01, .49]).nice();
assert.deepEqual(x.domain(), [.01, 1]);
+ var x = log().domain([0, 0]).nice();
+ assert.deepEqual(x.domain(), [0, 0]);
+ var x = log().domain([.5, .5]).nice();
+ assert.inDelta(x.domain(), [.5, .5], 1e-6);
},
"nicing a polylog domain only affects the extent": function(log) {
var x = log().domain([1.1, 1.5, 10.9]).nice();
View
@@ -187,6 +187,10 @@ suite.addBatch({
assert.deepEqual(x.domain(), [130, 0]);
var x = pow().domain([0, .49]).nice();
assert.deepEqual(x.domain(), [0, .5]);
+ var x = pow().domain([0, 0]).nice();
+ assert.deepEqual(x.domain(), [0, 0]);
+ var x = pow().domain([.5, .5]).nice();
+ assert.deepEqual(x.domain(), [.5, .5]);
},
"nicing a polypower domain only affects the extent": function(pow) {
var x = pow().domain([1.1, 1, 2, 3, 10.9]).nice();
View
@@ -94,6 +94,11 @@ suite.addBatch({
assert.equal(f(local(1990, 0, 1, 0, 0, 0)), "00");
assert.equal(f(local(1990, 0, 1, 0, 0, 32)), "32");
},
+ "formats zero-padded millisecond": function(format) {
+ var f = format("%L");
+ assert.equal(f(local(1990, 0, 1, 0, 0, 0, 0)), "000");
+ assert.equal(f(local(1990, 0, 1, 0, 0, 0, 432)), "432");
+ },
"formats zero-padded week number": function(format) {
var f = format("%U");
assert.equal(f(local(1990, 0, 1)), "00");
@@ -215,6 +220,11 @@ suite.addBatch({
assert.equal(f(utc(1990, 0, 1, 0, 0, 0)), "00");
assert.equal(f(utc(1990, 0, 1, 0, 0, 32)), "32");
},
+ "formats zero-padded millisecond": function(format) {
+ var f = format("%L");
+ assert.equal(f(utc(1990, 0, 1, 0, 0, 0, 0)), "000");
+ assert.equal(f(utc(1990, 0, 1, 0, 0, 0, 432)), "432");
+ },
"formats zero-padded week number": function(format) {
var f = format("%U");
assert.equal(f(utc(1990, 0, 1)), "00");
@@ -255,9 +265,12 @@ suite.addBatch({
topic: function(format) {
return format.iso;
},
+ "toString is %Y-%m-%dT%H:%M:%S.%LZ": function(format) {
+ assert.equal(format + "", "%Y-%m-%dT%H:%M:%S.%LZ");
+ },
"formats as ISO 8601": function(format) {
- assert.equal(format(utc(1990, 0, 1, 0, 0, 0)), "1990-01-01T00:00:00Z");
- assert.equal(format(utc(2011, 11, 31, 23, 59, 59)), "2011-12-31T23:59:59Z");
+ assert.equal(format(utc(1990, 0, 1, 0, 0, 0)), "1990-01-01T00:00:00.000Z");
+ assert.equal(format(utc(2011, 11, 31, 23, 59, 59)), "2011-12-31T23:59:59.000Z");
}
}
},
@@ -412,19 +425,19 @@ suite.addBatch({
},
"parses as ISO 8601": function(format) {
var p = format.parse;
- assert.deepEqual(p("1990-01-01T00:00:00Z"), utc(1990, 0, 1, 0, 0, 0));
- assert.deepEqual(p("2011-12-31T23:59:59Z"), utc(2011, 11, 31, 23, 59, 59));
+ assert.deepEqual(p("1990-01-01T00:00:00.000Z"), utc(1990, 0, 1, 0, 0, 0));
+ assert.deepEqual(p("2011-12-31T23:59:59.000Z"), utc(2011, 11, 31, 23, 59, 59));
}
}
}
});
-function local(year, month, day, hours, minutes, seconds) {
- return new Date(year, month, day, hours || 0, minutes || 0, seconds || 0);
+function local(year, month, day, hours, minutes, seconds, milliseconds) {
+ return new Date(year, month, day, hours || 0, minutes || 0, seconds || 0, milliseconds || 0);
}
-function utc(year, month, day, hours, minutes, seconds) {
- return new Date(Date.UTC(year, month, day, hours || 0, minutes || 0, seconds || 0));
+function utc(year, month, day, hours, minutes, seconds, milliseconds) {
+ return new Date(Date.UTC(year, month, day, hours || 0, minutes || 0, seconds || 0, milliseconds || 0));
}
suite.export(module);

0 comments on commit 32907ec

Please sign in to comment.