Skip to content

Commit

Permalink
Merge branch 'release'
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Jun 17, 2011
2 parents e2119b8 + 27158fd commit 68424ae
Show file tree
Hide file tree
Showing 26 changed files with 502 additions and 51 deletions.
8 changes: 8 additions & 0 deletions Makefile
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ d3.core.js: \
src/core/descending.js \ src/core/descending.js \
src/core/min.js \ src/core/min.js \
src/core/max.js \ src/core/max.js \
src/core/sum.js \
src/core/zip.js \ src/core/zip.js \
src/core/bisect.js \ src/core/bisect.js \
src/core/nest.js \ src/core/nest.js \
Expand Down Expand Up @@ -146,6 +147,8 @@ d3.time.js: \
src/start.js \ src/start.js \
src/time/time.js \ src/time/time.js \
src/time/format.js \ src/time/format.js \
src/time/format-utc.js \
src/time/format-iso.js \
src/end.js src/end.js


d3.geom.js: \ d3.geom.js: \
Expand All @@ -171,6 +174,7 @@ tests: \
tests/test-keys.test \ tests/test-keys.test \
tests/test-max.test \ tests/test-max.test \
tests/test-min.test \ tests/test-min.test \
tests/test-sum.test \
tests/test-nest.test \ tests/test-nest.test \
tests/test-permute.test \ tests/test-permute.test \
tests/test-zip.test \ tests/test-zip.test \
Expand All @@ -179,7 +183,11 @@ tests: \
tests/test-round.test \ tests/test-round.test \
tests/test-hsl.test \ tests/test-hsl.test \
tests/test-time-format.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.test \
tests/test-time-parse-iso.test \
tests/test-time-parse-utc.test \
tests/test-transition.test \ tests/test-transition.test \
tests/test-scale-linear.test \ tests/test-scale-linear.test \
tests/test-scale-polylinear.test \ tests/test-scale-polylinear.test \
Expand Down
16 changes: 15 additions & 1 deletion d3.js
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,4 @@
(function(){d3 = {version: "1.20.3"}; // semver (function(){d3 = {version: "1.21.0"}; // semver
if (!Date.now) Date.now = function() { if (!Date.now) Date.now = function() {
return +new Date; return +new Date;
}; };
Expand Down Expand Up @@ -68,6 +68,20 @@ d3.max = function(array, f) {
} }
return a; 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() { d3.zip = function() {
if (!(n = arguments.length)) return []; if (!(n = arguments.length)) return [];
for (var i = -1, m = d3.min(arguments, d3_zipLength), zips = new Array(m); ++i < m;) { for (var i = -1, m = d3.min(arguments, d3_zipLength), zips = new Array(m); ++i < m;) {
Expand Down
4 changes: 2 additions & 2 deletions d3.min.js

Large diffs are not rendered by default.

65 changes: 60 additions & 5 deletions d3.time.js
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,6 @@
(function(){d3.time = {}; (function(){d3.time = {};

var d3_time = Date;
d3.time.format = function(template) { d3.time.format = function(template) {
var n = template.length; var n = template.length;


Expand All @@ -22,7 +24,7 @@ d3.time.format = function(template) {
} }


format.parse = function(string) { 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); i = d3_time_parse(date, template, string, 0);
if (i != string.length) return null; if (i != string.length) return null;
if (date.hour12) { if (date.hour12) {
Expand Down Expand Up @@ -85,7 +87,7 @@ var d3_time_formats = {
W: d3_time_weekNumberMonday, W: d3_time_weekNumberMonday,
x: d3.time.format("%m/%d/%y"), x: d3.time.format("%m/%d/%y"),
X: d3.time.format("%H:%M:%S"), 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); }, Y: function(d) { return d3_time_zfill4(d.getFullYear() % 10000); },
Z: d3_time_zone, Z: d3_time_zone,
"%": function(d) { return "%"; } "%": function(d) { return "%"; }
Expand Down Expand Up @@ -288,17 +290,21 @@ var d3_time_amPmLookup = {
pm: 1 pm: 1
}; };


function d3_time_year(d) {
return new d3_time(d.getFullYear(), 0, 1);
}

function d3_time_dayOfYear(d) { 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) { 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)); return d3_time_zfill2(~~(((d - d0) / 864e5 + d0.getDay()) / 7));
} }


function d3_time_weekNumberMonday(d) { 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)); return d3_time_zfill2(~~(((d - d0) / 864e5 + (d0.getDay() + 6) % 7) / 7));
} }


Expand All @@ -310,4 +316,53 @@ function d3_time_zone(d) {
zm = Math.abs(z) % 60; zm = Math.abs(z) % 60;
return zs + d3_time_zfill2(zh) + d3_time_zfill2(zm); 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");
})(); })();
2 changes: 1 addition & 1 deletion d3.time.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions examples/voroboids/voroboids.js
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,6 @@
var w = 960, var w = 960,
h = 500, h = 500,
mouse = [0, 0], mouse = [null, null],
fill = d3.scale.linear().domain([0, 1e4]).range(["brown", "steelblue"]); fill = d3.scale.linear().domain([0, 1e4]).range(["brown", "steelblue"]);


// Initialise boids. // Initialise boids.
Expand All @@ -16,6 +16,8 @@ var vertices = boids.map(function(boid) {
return boid(boids); return boid(boids);
}); });


d3.select(window).on("blur", nullGravity);

var svg = d3.select("#vis") var svg = d3.select("#vis")
.append("svg:svg") .append("svg:svg")
.attr("width", w) .attr("width", w)
Expand All @@ -25,7 +27,8 @@ var svg = d3.select("#vis")
var m = d3.svg.mouse(this); var m = d3.svg.mouse(this);
mouse[0] = m[0]; mouse[0] = m[0];
mouse[1] = m[1]; mouse[1] = m[1];
}); })
.on("mouseout", nullGravity);


svg.selectAll("path") svg.selectAll("path")
.data(d3.geom.voronoi(vertices)) .data(d3.geom.voronoi(vertices))
Expand Down Expand Up @@ -56,3 +59,7 @@ d3.timer(function() {
.attr("d", function(d) { return "M" + d.join("L") + "Z"; }) .attr("d", function(d) { return "M" + d.join("L") + "Z"; })
.style("fill", function(d) { return fill((d3.geom.polygon(d).area())); }); .style("fill", function(d) { return fill((d3.geom.polygon(d).area())); });
}); });

function nullGravity() {
mouse[0] = mouse[1] = null;
}
2 changes: 1 addition & 1 deletion src/core/core.js
Original file line number Original file line Diff line number Diff line change
@@ -1 +1 @@
d3 = {version: "1.20.3"}; // semver d3 = {version: "1.21.0"}; // semver
14 changes: 14 additions & 0 deletions src/core/sum.js
Original file line number Original file line Diff line number Diff line change
@@ -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;
};
1 change: 1 addition & 0 deletions src/time/format-iso.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1 @@
d3.time.format.iso = d3.time.format.utc("%Y-%m-%dT%H:%M:%SZ");
48 changes: 48 additions & 0 deletions src/time/format-utc.js
Original file line number Original file line Diff line number Diff line change
@@ -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); }
};
14 changes: 9 additions & 5 deletions src/time/format.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ d3.time.format = function(template) {
} }


format.parse = function(string) { 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); i = d3_time_parse(date, template, string, 0);
if (i != string.length) return null; if (i != string.length) return null;
if (date.hour12) { if (date.hour12) {
Expand Down Expand Up @@ -84,7 +84,7 @@ var d3_time_formats = {
W: d3_time_weekNumberMonday, W: d3_time_weekNumberMonday,
x: d3.time.format("%m/%d/%y"), x: d3.time.format("%m/%d/%y"),
X: d3.time.format("%H:%M:%S"), 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); }, Y: function(d) { return d3_time_zfill4(d.getFullYear() % 10000); },
Z: d3_time_zone, Z: d3_time_zone,
"%": function(d) { return "%"; } "%": function(d) { return "%"; }
Expand Down Expand Up @@ -287,17 +287,21 @@ var d3_time_amPmLookup = {
pm: 1 pm: 1
}; };


function d3_time_year(d) {
return new d3_time(d.getFullYear(), 0, 1);
}

function d3_time_dayOfYear(d) { 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) { 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)); return d3_time_zfill2(~~(((d - d0) / 864e5 + d0.getDay()) / 7));
} }


function d3_time_weekNumberMonday(d) { 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)); return d3_time_zfill2(~~(((d - d0) / 864e5 + (d0.getDay() + 6) % 7) / 7));
} }


Expand Down
2 changes: 2 additions & 0 deletions src/time/time.js
Original file line number Original file line Diff line number Diff line change
@@ -1 +1,3 @@
d3.time = {}; d3.time = {};

var d3_time = Date;
Loading

0 comments on commit 68424ae

Please sign in to comment.