This commit is contained in:
Mike Bostock 2011-10-11 18:02:06 -07:00
Родитель 307016e843 639f802d22
Коммит 32907ec505
13 изменённых файлов: 93 добавлений и 22 удалений

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;
}

4
d3.min.js поставляемый

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -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 = [];

2
d3.time.min.js поставляемый

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -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",

Просмотреть файл

@ -1 +1 @@
d3 = {version: "2.4.1"}; // semver
d3 = {version: "2.4.2"}; // semver

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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;

Просмотреть файл

@ -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();

Просмотреть файл

@ -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();

Просмотреть файл

@ -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();

Просмотреть файл

@ -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);