Merge branch 'geo-bounds' of git://github.com/jasondavies/d3 into 3.0

Conflicts:
	src/geo/bounds.js
	src/geo/path.js
	src/geo/type.js
	test/geo/bounds-test.js
This commit is contained in:
Mike Bostock 2012-10-29 09:07:00 -07:00
Родитель 9828afda19 e3f4b90aa5
Коммит 9b1fefca81
4 изменённых файлов: 60 добавлений и 45 удалений

45
d3.js поставляемый
Просмотреть файл

@ -1921,6 +1921,26 @@
}; };
return albers; return albers;
} }
function d3_geo_bounds(projection) {
var x0, y0, x1, y1, bounds = d3_geo_type({
point: function(point) {
point = projection(point);
var x = point[0], y = point[1];
if (x < x0) x0 = x;
if (x > x1) x1 = x;
if (y < y0) y0 = y;
if (y > y1) y1 = y;
},
polygon: function(coordinates) {
this.line(coordinates[0]);
}
});
return function(feature) {
y1 = x1 = -(x0 = y0 = Infinity);
bounds.object(feature);
return [ [ x0, y0 ], [ x1, y1 ] ];
};
}
function d3_geo_circleClip(degrees, rotate) { function d3_geo_circleClip(degrees, rotate) {
function visible(point) { function visible(point) {
return Math.cos(point[1]) * Math.cos(point[0]) > cr; return Math.cos(point[1]) * Math.cos(point[0]) > cr;
@ -6473,24 +6493,7 @@
(d3.geo.azimuthalEquidistant = function() { (d3.geo.azimuthalEquidistant = function() {
return d3_geo_projection(d3_geo_azimuthalEquidistant); return d3_geo_projection(d3_geo_azimuthalEquidistant);
}).raw = d3_geo_azimuthalEquidistant; }).raw = d3_geo_azimuthalEquidistant;
d3.geo.bounds = function(feature) { d3.geo.bounds = d3_geo_bounds(d3_identity);
d3_geo_boundsTop = d3_geo_boundsRight = -(d3_geo_boundsLeft = d3_geo_boundsBottom = Infinity);
d3_geo_bounds.object(feature);
return [ [ d3_geo_boundsLeft, d3_geo_boundsBottom ], [ d3_geo_boundsRight, d3_geo_boundsTop ] ];
};
var d3_geo_boundsLeft, d3_geo_boundsBottom, d3_geo_boundsRight, d3_geo_boundsTop;
var d3_geo_bounds = d3_geo_type({
point: function(point) {
var x = point[0], y = point[1];
if (x < d3_geo_boundsLeft) d3_geo_boundsLeft = x;
if (x > d3_geo_boundsRight) d3_geo_boundsRight = x;
if (y < d3_geo_boundsBottom) d3_geo_boundsBottom = y;
if (y > d3_geo_boundsTop) d3_geo_boundsTop = y;
},
polygon: function(coordinates) {
this.line(coordinates[0]);
}
});
d3.geo.circle = function() { d3.geo.circle = function() {
function circle() {} function circle() {}
function bufferContext(lineStrings) { function bufferContext(lineStrings) {
@ -6775,7 +6778,7 @@
} }
return z ? [ x, y, 6 * z ] : null; return z ? [ x, y, 6 * z ] : null;
} }
var pointRadius = 4.5, pointCircle = d3_geo_pathCircle(pointRadius), projection = d3.geo.albersUsa(), buffer = []; var pointRadius = 4.5, pointCircle = d3_geo_pathCircle(pointRadius), projection = d3.geo.albersUsa(), bounds, buffer = [];
var bufferContext = { var bufferContext = {
point: function(x, y) { point: function(x, y) {
buffer.push("M", x, ",", y, pointCircle); buffer.push("M", x, ",", y, pointCircle);
@ -6855,12 +6858,16 @@
Point: singleCentroid(pointCentroid), Point: singleCentroid(pointCentroid),
Polygon: singleCentroid(polygonCentroid) Polygon: singleCentroid(polygonCentroid)
}); });
path.bounds = function(object) {
return (bounds || (bounds = d3_geo_bounds(projection)))(object);
};
path.centroid = function(object) { path.centroid = function(object) {
return centroidType.object(object); return centroidType.object(object);
}; };
path.projection = function(_) { path.projection = function(_) {
if (!arguments.length) return projection; if (!arguments.length) return projection;
projection = _; projection = _;
bounds = null;
return path; return path;
}; };
path.context = function(_) { path.context = function(_) {

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

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

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

@ -1,23 +1,23 @@
d3.geo.bounds = function(feature) { d3.geo.bounds = d3_geo_bounds(d3_identity);
d3_geo_boundsTop = d3_geo_boundsRight = -(d3_geo_boundsLeft = d3_geo_boundsBottom = Infinity);
d3_geo_bounds.object(feature);
return [[d3_geo_boundsLeft, d3_geo_boundsBottom], [d3_geo_boundsRight, d3_geo_boundsTop]];
};
var d3_geo_boundsLeft, function d3_geo_bounds(projection) {
d3_geo_boundsBottom, var x0, y0, x1, y1, bounds = d3_geo_type({
d3_geo_boundsRight, point: function(point) {
d3_geo_boundsTop; point = projection(point);
var x = point[0], y = point[1];
if (x < x0) x0 = x;
if (x > x1) x1 = x;
if (y < y0) y0 = y;
if (y > y1) y1 = y;
},
polygon: function(coordinates) {
this.line(coordinates[0]); // ignore holes
}
});
var d3_geo_bounds = d3_geo_type({ return function(feature) {
point: function(point) { y1 = x1 = -(x0 = y0 = Infinity);
var x = point[0], y = point[1]; bounds.object(feature);
if (x < d3_geo_boundsLeft) d3_geo_boundsLeft = x; return [[x0, y0], [x1, y1]];
if (x > d3_geo_boundsRight) d3_geo_boundsRight = x; };
if (y < d3_geo_boundsBottom) d3_geo_boundsBottom = y; }
if (y > d3_geo_boundsTop) d3_geo_boundsTop = y;
},
polygon: function(coordinates) {
this.line(coordinates[0]); // ignore holes
}
});

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

@ -4,6 +4,7 @@ d3.geo.path = function() {
var pointRadius = 4.5, var pointRadius = 4.5,
pointCircle = d3_geo_pathCircle(pointRadius), pointCircle = d3_geo_pathCircle(pointRadius),
projection = d3.geo.albersUsa(), projection = d3.geo.albersUsa(),
bounds,
buffer = []; buffer = [];
var bufferContext = { var bufferContext = {
@ -178,11 +179,18 @@ d3.geo.path = function() {
return z ? [x, y, 6 * z] : null; // weighted centroid return z ? [x, y, 6 * z] : null; // weighted centroid
} }
path.centroid = function(object) { return centroidType.object(object); }; path.bounds = function(object) {
return (bounds || (bounds = d3_geo_bounds(projection)))(object);
};
path.centroid = function(object) {
return centroidType.object(object);
};
path.projection = function(_) { path.projection = function(_) {
if (!arguments.length) return projection; if (!arguments.length) return projection;
projection = _; projection = _;
bounds = null;
return path; return path;
}; };