This commit is contained in:
Mike Bostock 2013-10-02 21:04:00 -07:00
Родитель 5bc83c30ad
Коммит 4f51b3f37f
4 изменённых файлов: 45 добавлений и 27 удалений

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

@ -5114,8 +5114,7 @@ d3 = function() {
break; break;
} }
} }
d3_geom_voronoiClipEdges(bbox); if (bbox) d3_geom_voronoiClipEdges(bbox), d3_geom_voronoiCloseCells(bbox);
d3_geom_voronoiCloseCells(bbox);
var diagram = { var diagram = {
cells: d3_geom_voronoiCells, cells: d3_geom_voronoiCells,
edges: d3_geom_voronoiEdges edges: d3_geom_voronoiEdges
@ -5127,17 +5126,11 @@ d3 = function() {
return b.y - a.y || b.x - a.x; return b.y - a.y || b.x - a.x;
} }
d3.geom.voronoi = function(points) { d3.geom.voronoi = function(points) {
var x = d3_svg_lineX, y = d3_svg_lineY, clipExtent = d3_geom_voronoiClipExtent; var x = d3_svg_lineX, y = d3_svg_lineY, fx = x, fy = y, clipExtent = d3_geom_voronoiClipExtent;
if (points) return voronoi(points); if (points) return voronoi(points);
function voronoi(data) { function voronoi(data) {
var fx = d3_functor(x), fy = d3_functor(y), sites = data.map(function(d, i) { var polygons = [];
return { d3_geom_voronoi(sites(data), clipExtent).cells.forEach(function(cell, i) {
x: fx(d, i),
y: fy(d, i),
i: i
};
}), polygons = [];
d3_geom_voronoi(sites, clipExtent).cells.forEach(function(cell, i) {
(polygons[i] = cell.edges.length ? cell.edges.map(function(edge) { (polygons[i] = cell.edges.length ? cell.edges.map(function(edge) {
var start = edge.start(); var start = edge.start();
return [ start.x, start.y ]; return [ start.x, start.y ];
@ -5145,17 +5138,33 @@ d3 = function() {
}); });
return polygons; return polygons;
} }
function sites(data) {
return data.map(function(d, i) {
return {
x: fx(d, i),
y: fy(d, i),
i: i
};
});
}
voronoi.links = function(data) { voronoi.links = function(data) {
throw new Error("not yet implemented"); return d3_geom_voronoi(sites(data)).edges.filter(function(edge) {
return edge.l && edge.r;
}).map(function(edge) {
return {
source: data[edge.l.i],
target: data[edge.r.i]
};
});
}; };
voronoi.triangles = function(data) { voronoi.triangles = function(data) {
throw new Error("not yet implemented"); throw new Error("not yet implemented");
}; };
voronoi.x = function(_) { voronoi.x = function(_) {
return arguments.length ? (x = _, voronoi) : x; return arguments.length ? (fx = d3_functor(x = _), voronoi) : x;
}; };
voronoi.y = function(_) { voronoi.y = function(_) {
return arguments.length ? (y = _, voronoi) : y; return arguments.length ? (fy = d3_functor(y = _), voronoi) : y;
}; };
voronoi.clipExtent = function(_) { voronoi.clipExtent = function(_) {
if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent; if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent;

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

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

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

@ -6,18 +6,17 @@ import "geom";
d3.geom.voronoi = function(points) { d3.geom.voronoi = function(points) {
var x = d3_svg_lineX, var x = d3_svg_lineX,
y = d3_svg_lineY, y = d3_svg_lineY,
fx = x,
fy = y,
clipExtent = d3_geom_voronoiClipExtent; clipExtent = d3_geom_voronoiClipExtent;
// @deprecated; use voronoi(data) instead. // @deprecated; use voronoi(data) instead.
if (points) return voronoi(points); if (points) return voronoi(points);
function voronoi(data) { function voronoi(data) {
var fx = d3_functor(x), var polygons = [];
fy = d3_functor(y),
sites = data.map(function(d, i) { return {x: fx(d, i), y: fy(d, i), i: i}; }),
polygons = [];
d3_geom_voronoi(sites, clipExtent).cells.forEach(function(cell, i) { d3_geom_voronoi(sites(data), clipExtent).cells.forEach(function(cell, i) {
(polygons[i] = cell.edges.length ? cell.edges.map(function(edge) { (polygons[i] = cell.edges.length ? cell.edges.map(function(edge) {
var start = edge.start(); var start = edge.start();
return [start.x, start.y]; return [start.x, start.y];
@ -32,8 +31,19 @@ d3.geom.voronoi = function(points) {
return polygons; return polygons;
} }
function sites(data) {
return data.map(function(d, i) { return {x: fx(d, i), y: fy(d, i), i: i}; });
}
voronoi.links = function(data) { voronoi.links = function(data) {
throw new Error("not yet implemented"); return d3_geom_voronoi(sites(data)).edges.filter(function(edge) {
return edge.l && edge.r;
}).map(function(edge) {
return {
source: data[edge.l.i],
target: data[edge.r.i]
};
});
}; };
voronoi.triangles = function(data) { voronoi.triangles = function(data) {
@ -41,11 +51,11 @@ d3.geom.voronoi = function(points) {
}; };
voronoi.x = function(_) { voronoi.x = function(_) {
return arguments.length ? (x = _, voronoi) : x; return arguments.length ? (fx = d3_functor(x = _), voronoi) : x;
}; };
voronoi.y = function(_) { voronoi.y = function(_) {
return arguments.length ? (y = _, voronoi) : y; return arguments.length ? (fy = d3_functor(y = _), voronoi) : y;
}; };
voronoi.clipExtent = function(_) { voronoi.clipExtent = function(_) {

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

@ -42,8 +42,7 @@ function d3_geom_voronoi(sites, bbox) {
} }
} }
d3_geom_voronoiClipEdges(bbox); if (bbox) d3_geom_voronoiClipEdges(bbox), d3_geom_voronoiCloseCells(bbox);
d3_geom_voronoiCloseCells(bbox);
var diagram = {cells: d3_geom_voronoiCells, edges: d3_geom_voronoiEdges}; var diagram = {cells: d3_geom_voronoiCells, edges: d3_geom_voronoiEdges};