Support optional projection.{line,polygon}.
This commit is contained in:
Родитель
6bba6a1868
Коммит
a7d5245f52
|
@ -2016,6 +2016,9 @@
|
||||||
function d3_path_circle(radius) {
|
function d3_path_circle(radius) {
|
||||||
return "m0," + radius + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius + "a" + radius + "," + radius + " 0 1,1 0," + +2 * radius + "z";
|
return "m0," + radius + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius + "a" + radius + "," + radius + " 0 1,1 0," + +2 * radius + "z";
|
||||||
}
|
}
|
||||||
|
function d3_geo_path_projectIdentity(d) {
|
||||||
|
return [ d ];
|
||||||
|
}
|
||||||
function d3_geo_projection(project) {
|
function d3_geo_projection(project) {
|
||||||
return d3_geo_projectionMutator(function() {
|
return d3_geo_projectionMutator(function() {
|
||||||
return project;
|
return project;
|
||||||
|
@ -6298,6 +6301,34 @@
|
||||||
buffer = [];
|
buffer = [];
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
function multiLineString(lineStrings) {
|
||||||
|
var lineString, j, m;
|
||||||
|
for (var i = 0, n = lineStrings.length; i < n; ++i) {
|
||||||
|
lineString = lineStrings[i];
|
||||||
|
j = -1;
|
||||||
|
m = lineString.length;
|
||||||
|
buffer.push("M");
|
||||||
|
while (++j < m) buffer.push(lineString[j], "L");
|
||||||
|
buffer.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function multiPolygon(polygons) {
|
||||||
|
var polygon, j, m, ring, k, p;
|
||||||
|
for (var i = 0, n = polygons.length; i < n; ++i) {
|
||||||
|
polygon = polygons[i];
|
||||||
|
j = -1;
|
||||||
|
m = polygon.length;
|
||||||
|
while (++j < m) {
|
||||||
|
ring = polygon[j];
|
||||||
|
k = -1;
|
||||||
|
if ((p = ring.length - 1) > 0) {
|
||||||
|
buffer.push("M");
|
||||||
|
while (++k < p) buffer.push(ring[k], "L");
|
||||||
|
buffer[buffer.length - 1] = "Z";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
function polygonArea(coordinates) {
|
function polygonArea(coordinates) {
|
||||||
var sum = area(coordinates[0]), i = 0, n = coordinates.length;
|
var sum = area(coordinates[0]), i = 0, n = coordinates.length;
|
||||||
while (++i < n) sum -= area(coordinates[i]);
|
while (++i < n) sum -= area(coordinates[i]);
|
||||||
|
@ -6318,7 +6349,7 @@
|
||||||
function area(coordinates) {
|
function area(coordinates) {
|
||||||
return Math.abs(d3.geom.polygon(coordinates.map(projection)).area());
|
return Math.abs(d3.geom.polygon(coordinates.map(projection)).area());
|
||||||
}
|
}
|
||||||
var pointRadius = 4.5, pointCircle = d3_path_circle(pointRadius), projection = d3.geo.albersUsa(), buffer = [];
|
var pointRadius = 4.5, pointCircle = d3_path_circle(pointRadius), projection = d3.geo.albersUsa(), projectLine = d3_geo_path_projectIdentity, projectPolygon = d3_geo_path_projectIdentity, buffer = [];
|
||||||
var pathType = d3_geo_type({
|
var pathType = d3_geo_type({
|
||||||
FeatureCollection: function(o) {
|
FeatureCollection: function(o) {
|
||||||
var features = o.features, i = -1, n = features.length;
|
var features = o.features, i = -1, n = features.length;
|
||||||
|
@ -6335,49 +6366,21 @@
|
||||||
while (++i < n) buffer.push("M", projection(coordinates[i]), pointCircle);
|
while (++i < n) buffer.push("M", projection(coordinates[i]), pointCircle);
|
||||||
},
|
},
|
||||||
LineString: function(o) {
|
LineString: function(o) {
|
||||||
var coordinates = o.coordinates, i = -1, n = coordinates.length;
|
multiLineString(projectLine(o.coordinates));
|
||||||
buffer.push("M");
|
|
||||||
while (++i < n) buffer.push(projection(coordinates[i]), "L");
|
|
||||||
buffer.pop();
|
|
||||||
},
|
},
|
||||||
MultiLineString: function(o) {
|
MultiLineString: function(o) {
|
||||||
var coordinates = o.coordinates, i = -1, n = coordinates.length, subcoordinates, j, m;
|
var lineStrings = o.coordinates;
|
||||||
while (++i < n) {
|
for (var i = 0, n = lineStrings.length; i < n; ++i) {
|
||||||
subcoordinates = coordinates[i];
|
multiLineString(projectLine(lineStrings[i]));
|
||||||
j = -1;
|
|
||||||
m = subcoordinates.length;
|
|
||||||
buffer.push("M");
|
|
||||||
while (++j < m) buffer.push(projection(subcoordinates[j]), "L");
|
|
||||||
buffer.pop();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Polygon: function(o) {
|
Polygon: function(o) {
|
||||||
var coordinates = o.coordinates, i = -1, n = coordinates.length, subcoordinates, j, m;
|
multiPolygon(projectPolygon(o.coordinates));
|
||||||
while (++i < n) {
|
|
||||||
subcoordinates = coordinates[i];
|
|
||||||
j = -1;
|
|
||||||
if ((m = subcoordinates.length - 1) > 0) {
|
|
||||||
buffer.push("M");
|
|
||||||
while (++j < m) buffer.push(projection(subcoordinates[j]), "L");
|
|
||||||
buffer[buffer.length - 1] = "Z";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
MultiPolygon: function(o) {
|
MultiPolygon: function(o) {
|
||||||
var coordinates = o.coordinates, i = -1, n = coordinates.length, subcoordinates, j, m, subsubcoordinates, k, p;
|
var polygons = o.coordinates;
|
||||||
while (++i < n) {
|
for (var i = 0, n = polygons.length; i < n; ++i) {
|
||||||
subcoordinates = coordinates[i];
|
multiPolygon(projectPolygon(polygons[i]));
|
||||||
j = -1;
|
|
||||||
m = subcoordinates.length;
|
|
||||||
while (++j < m) {
|
|
||||||
subsubcoordinates = subcoordinates[j];
|
|
||||||
k = -1;
|
|
||||||
if ((p = subsubcoordinates.length - 1) > 0) {
|
|
||||||
buffer.push("M");
|
|
||||||
while (++k < p) buffer.push(projection(subsubcoordinates[k]), "L");
|
|
||||||
buffer[buffer.length - 1] = "Z";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
GeometryCollection: function(o) {
|
GeometryCollection: function(o) {
|
||||||
|
@ -6430,6 +6433,8 @@
|
||||||
path.projection = function(_) {
|
path.projection = function(_) {
|
||||||
if (!arguments.length) return projection;
|
if (!arguments.length) return projection;
|
||||||
projection = _;
|
projection = _;
|
||||||
|
projectLine = projection.line || d3_geo_path_projectIdentity;
|
||||||
|
projectPolygon = projection.polygon || d3_geo_path_projectIdentity;
|
||||||
return path;
|
return path;
|
||||||
};
|
};
|
||||||
path.pointRadius = function(x) {
|
path.pointRadius = function(x) {
|
||||||
|
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
107
src/geo/path.js
107
src/geo/path.js
|
@ -9,6 +9,8 @@ d3.geo.path = function() {
|
||||||
var pointRadius = 4.5,
|
var pointRadius = 4.5,
|
||||||
pointCircle = d3_path_circle(pointRadius),
|
pointCircle = d3_path_circle(pointRadius),
|
||||||
projection = d3.geo.albersUsa(),
|
projection = d3.geo.albersUsa(),
|
||||||
|
projectLine = d3_geo_path_projectIdentity,
|
||||||
|
projectPolygon = d3_geo_path_projectIdentity,
|
||||||
buffer = [];
|
buffer = [];
|
||||||
|
|
||||||
function path(d, i) {
|
function path(d, i) {
|
||||||
|
@ -44,72 +46,24 @@ d3.geo.path = function() {
|
||||||
},
|
},
|
||||||
|
|
||||||
LineString: function(o) {
|
LineString: function(o) {
|
||||||
var coordinates = o.coordinates,
|
multiLineString(projectLine(o.coordinates));
|
||||||
i = -1, // coordinates.index
|
|
||||||
n = coordinates.length;
|
|
||||||
buffer.push("M");
|
|
||||||
while (++i < n) buffer.push(projection(coordinates[i]), "L");
|
|
||||||
buffer.pop();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
MultiLineString: function(o) {
|
MultiLineString: function(o) {
|
||||||
var coordinates = o.coordinates,
|
var lineStrings = o.coordinates;
|
||||||
i = -1, // coordinates.index
|
for (var i = 0, n = lineStrings.length; i < n; ++i) {
|
||||||
n = coordinates.length,
|
multiLineString(projectLine(lineStrings[i]));
|
||||||
subcoordinates, // coordinates[i]
|
|
||||||
j, // subcoordinates.index
|
|
||||||
m; // subcoordinates.length
|
|
||||||
while (++i < n) {
|
|
||||||
subcoordinates = coordinates[i];
|
|
||||||
j = -1;
|
|
||||||
m = subcoordinates.length;
|
|
||||||
buffer.push("M");
|
|
||||||
while (++j < m) buffer.push(projection(subcoordinates[j]), "L");
|
|
||||||
buffer.pop();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
Polygon: function(o) {
|
Polygon: function(o) {
|
||||||
var coordinates = o.coordinates,
|
multiPolygon(projectPolygon(o.coordinates));
|
||||||
i = -1, // coordinates.index
|
|
||||||
n = coordinates.length,
|
|
||||||
subcoordinates, // coordinates[i]
|
|
||||||
j, // subcoordinates.index
|
|
||||||
m; // subcoordinates.length
|
|
||||||
while (++i < n) {
|
|
||||||
subcoordinates = coordinates[i];
|
|
||||||
j = -1;
|
|
||||||
if ((m = subcoordinates.length - 1) > 0) {
|
|
||||||
buffer.push("M");
|
|
||||||
while (++j < m) buffer.push(projection(subcoordinates[j]), "L");
|
|
||||||
buffer[buffer.length - 1] = "Z";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
MultiPolygon: function(o) {
|
MultiPolygon: function(o) {
|
||||||
var coordinates = o.coordinates,
|
var polygons = o.coordinates;
|
||||||
i = -1, // coordinates index
|
for (var i = 0, n = polygons.length; i < n; ++i) {
|
||||||
n = coordinates.length,
|
multiPolygon(projectPolygon(polygons[i]));
|
||||||
subcoordinates, // coordinates[i]
|
|
||||||
j, // subcoordinates index
|
|
||||||
m, // subcoordinates.length
|
|
||||||
subsubcoordinates, // subcoordinates[j]
|
|
||||||
k, // subsubcoordinates index
|
|
||||||
p; // subsubcoordinates.length
|
|
||||||
while (++i < n) {
|
|
||||||
subcoordinates = coordinates[i];
|
|
||||||
j = -1;
|
|
||||||
m = subcoordinates.length;
|
|
||||||
while (++j < m) {
|
|
||||||
subsubcoordinates = subcoordinates[j];
|
|
||||||
k = -1;
|
|
||||||
if ((p = subsubcoordinates.length - 1) > 0) {
|
|
||||||
buffer.push("M");
|
|
||||||
while (++k < p) buffer.push(projection(subsubcoordinates[k]), "L");
|
|
||||||
buffer[buffer.length - 1] = "Z";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -161,6 +115,43 @@ d3.geo.path = function() {
|
||||||
|
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|
||||||
|
function multiLineString(lineStrings) {
|
||||||
|
var lineString,
|
||||||
|
j,
|
||||||
|
m;
|
||||||
|
for (var i = 0, n = lineStrings.length; i < n; ++i) {
|
||||||
|
lineString = lineStrings[i];
|
||||||
|
j = -1;
|
||||||
|
m = lineString.length;
|
||||||
|
buffer.push("M");
|
||||||
|
while (++j < m) buffer.push(lineString[j], "L");
|
||||||
|
buffer.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function multiPolygon(polygons) {
|
||||||
|
var polygon,
|
||||||
|
j,
|
||||||
|
m,
|
||||||
|
ring,
|
||||||
|
k,
|
||||||
|
p;
|
||||||
|
for (var i = 0, n = polygons.length; i < n; ++i) {
|
||||||
|
polygon = polygons[i];
|
||||||
|
j = -1;
|
||||||
|
m = polygon.length;
|
||||||
|
while (++j < m) {
|
||||||
|
ring = polygon[j];
|
||||||
|
k = -1;
|
||||||
|
if ((p = ring.length - 1) > 0) {
|
||||||
|
buffer.push("M");
|
||||||
|
while (++k < p) buffer.push(ring[k], "L");
|
||||||
|
buffer[buffer.length - 1] = "Z";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function polygonArea(coordinates) {
|
function polygonArea(coordinates) {
|
||||||
var sum = area(coordinates[0]), // exterior ring
|
var sum = area(coordinates[0]), // exterior ring
|
||||||
i = 0, // coordinates.index
|
i = 0, // coordinates.index
|
||||||
|
@ -234,6 +225,8 @@ d3.geo.path = function() {
|
||||||
path.projection = function(_) {
|
path.projection = function(_) {
|
||||||
if (!arguments.length) return projection;
|
if (!arguments.length) return projection;
|
||||||
projection = _;
|
projection = _;
|
||||||
|
projectLine = projection.line || d3_geo_path_projectIdentity;
|
||||||
|
projectPolygon = projection.polygon || d3_geo_path_projectIdentity;
|
||||||
return path;
|
return path;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -253,3 +246,5 @@ function d3_path_circle(radius) {
|
||||||
+ "a" + radius + "," + radius + " 0 1,1 0," + (+2 * radius)
|
+ "a" + radius + "," + radius + " 0 1,1 0," + (+2 * radius)
|
||||||
+ "z";
|
+ "z";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function d3_geo_path_projectIdentity(d) { return [d]; }
|
||||||
|
|
Загрузка…
Ссылка в новой задаче