Skip to content

Commit 6ca6d3e

Browse files
committed
Return undefined for empty buffers.
1 parent 342c1b8 commit 6ca6d3e

6 files changed

Lines changed: 91 additions & 85 deletions

File tree

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,6 @@ d3.layout.js: \
181181
d3.geo.js: \
182182
src/geo/geo.js \
183183
src/geo/stream.js \
184-
src/geo/stream-buffer.js \
185-
src/geo/stream-context.js \
186184
src/geo/stream-radians.js \
187185
src/geo/stream-rotate.js \
188186
src/geo/stream-transform.js \
@@ -208,6 +206,8 @@ d3.geo.js: \
208206
src/geo/mercator.js \
209207
src/geo/orthographic.js \
210208
src/geo/path.js \
209+
src/geo/path-buffer.js \
210+
src/geo/path-context.js \
211211
src/geo/path-area.js \
212212
src/geo/path-centroid.js \
213213
src/geo/area.js \

d3.js

Lines changed: 74 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -5397,72 +5397,6 @@
53975397
while (++i < n) d3_geo_streamLine(coordinates[i], listener);
53985398
listener.polygonEnd();
53995399
}
5400-
function d3_geo_streamBuffer(buffer, pointRadius) {
5401-
var stream = {
5402-
point: point,
5403-
lineStart: function() {
5404-
stream.point = pointLineStart;
5405-
},
5406-
lineEnd: lineEnd,
5407-
polygonStart: function() {
5408-
stream.lineEnd = lineEndPolygon;
5409-
},
5410-
polygonEnd: function() {
5411-
stream.lineEnd = lineEnd;
5412-
}
5413-
};
5414-
function point(x, y) {
5415-
buffer.push("M", x, ",", y, pointRadius);
5416-
}
5417-
function pointLineStart(x, y) {
5418-
buffer.push("M", x, ",", y);
5419-
stream.point = pointLine;
5420-
}
5421-
function pointLine(x, y) {
5422-
buffer.push("L", x, ",", y);
5423-
}
5424-
function lineEnd() {
5425-
stream.point = point;
5426-
}
5427-
function lineEndPolygon() {
5428-
buffer.push("Z");
5429-
}
5430-
pointRadius = d3_geo_pathCircle(4.5);
5431-
return stream;
5432-
}
5433-
function d3_geo_streamContext(context, pointRadius) {
5434-
var stream = {
5435-
point: point,
5436-
lineStart: function() {
5437-
stream.point = pointLineStart;
5438-
},
5439-
lineEnd: lineEnd,
5440-
polygonStart: function() {
5441-
stream.lineEnd = lineEndPolygon;
5442-
},
5443-
polygonEnd: function() {
5444-
stream.lineEnd = lineEnd;
5445-
}
5446-
};
5447-
function point(x, y) {
5448-
context.moveTo(x, y);
5449-
context.arc(x, y, pointRadius, 0, 2 * π);
5450-
}
5451-
function pointLineStart(x, y) {
5452-
context.moveTo(x, y);
5453-
stream.point = pointLine;
5454-
}
5455-
function pointLine(x, y) {
5456-
context.lineTo(x, y);
5457-
}
5458-
function lineEnd() {
5459-
stream.point = point;
5460-
}
5461-
function lineEndPolygon() {
5462-
context.closePath();
5463-
}
5464-
return stream;
5465-
}
54665400
function d3_geo_streamRadians(stream) {
54675401
return d3_geo_streamTransform(stream, function(x, y) {
54685402
stream.point(x * d3_radians, y * d3_radians);
@@ -6327,10 +6261,12 @@
63276261
var pointRadius = 4.5, pointCircle = d3_geo_pathCircle(pointRadius), projection = d3.geo.albersUsa(), context, buffer = [];
63286262
function path(object) {
63296263
var radius = typeof pointRadius === "function" ? pointRadius.apply(this, arguments) : pointRadius;
6330-
d3.geo.stream(object, projection.stream(context != null ? new d3_geo_streamContext(context, radius) : new d3_geo_streamBuffer(buffer, radius)));
6331-
var result = buffer.join("");
6332-
buffer = [];
6333-
return result;
6264+
d3.geo.stream(object, projection.stream(context == null ? new d3_geo_pathBuffer(buffer, radius) : new d3_geo_pathContext(context, radius)));
6265+
if (buffer.length) {
6266+
var result = buffer.join("");
6267+
buffer = [];
6268+
return result;
6269+
}
63346270
}
63356271
path.area = function(object) {
63366272
d3_geo_areaSum = 0;
@@ -6365,6 +6301,74 @@
63656301
function d3_geo_pathCircle(radius) {
63666302
return "m0," + radius + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius + "a" + radius + "," + radius + " 0 1,1 0," + +2 * radius + "z";
63676303
}
6304+
function d3_geo_pathBuffer(buffer, pointRadius) {
6305+
var stream = {
6306+
point: point,
6307+
lineStart: function() {
6308+
stream.point = pointLineStart;
6309+
},
6310+
lineEnd: lineEnd,
6311+
polygonStart: function() {
6312+
stream.lineEnd = lineEndPolygon;
6313+
},
6314+
polygonEnd: function() {
6315+
stream.lineEnd = lineEnd;
6316+
stream.point = point;
6317+
}
6318+
};
6319+
function point(x, y) {
6320+
buffer.push("M", x, ",", y, pointRadius);
6321+
}
6322+
function pointLineStart(x, y) {
6323+
buffer.push("M", x, ",", y);
6324+
stream.point = pointLine;
6325+
}
6326+
function pointLine(x, y) {
6327+
buffer.push("L", x, ",", y);
6328+
}
6329+
function lineEnd() {
6330+
stream.point = point;
6331+
}
6332+
function lineEndPolygon() {
6333+
buffer.push("Z");
6334+
}
6335+
pointRadius = d3_geo_pathCircle(4.5);
6336+
return stream;
6337+
}
6338+
function d3_geo_pathContext(context, pointRadius) {
6339+
var stream = {
6340+
point: point,
6341+
lineStart: function() {
6342+
stream.point = pointLineStart;
6343+
},
6344+
lineEnd: lineEnd,
6345+
polygonStart: function() {
6346+
stream.lineEnd = lineEndPolygon;
6347+
},
6348+
polygonEnd: function() {
6349+
stream.lineEnd = lineEnd;
6350+
stream.point = point;
6351+
}
6352+
};
6353+
function point(x, y) {
6354+
context.moveTo(x, y);
6355+
context.arc(x, y, pointRadius, 0, 2 * π);
6356+
}
6357+
function pointLineStart(x, y) {
6358+
context.moveTo(x, y);
6359+
stream.point = pointLine;
6360+
}
6361+
function pointLine(x, y) {
6362+
context.lineTo(x, y);
6363+
}
6364+
function lineEnd() {
6365+
stream.point = point;
6366+
}
6367+
function lineEndPolygon() {
6368+
context.closePath();
6369+
}
6370+
return stream;
6371+
}
63686372
var d3_geo_pathAreaScale, d3_geo_pathArea = {
63696373
point: d3_noop,
63706374
lineStart: d3_noop,

d3.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function d3_geo_streamBuffer(buffer, pointRadius) {
1+
function d3_geo_pathBuffer(buffer, pointRadius) {
22
var stream = {
33
point: point,
44

@@ -8,7 +8,7 @@ function d3_geo_streamBuffer(buffer, pointRadius) {
88

99
// While inside a polygon, override lineEnd to closePath.
1010
polygonStart: function() { stream.lineEnd = lineEndPolygon; },
11-
polygonEnd: function() { stream.lineEnd = lineEnd; }
11+
polygonEnd: function() { stream.lineEnd = lineEnd; stream.point = point; }
1212
};
1313

1414
function point(x, y) {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function d3_geo_streamContext(context, pointRadius) {
1+
function d3_geo_pathContext(context, pointRadius) {
22
var stream = {
33
point: point,
44

@@ -8,7 +8,7 @@ function d3_geo_streamContext(context, pointRadius) {
88

99
// While inside a polygon, override lineEnd to closePath.
1010
polygonStart: function() { stream.lineEnd = lineEndPolygon; },
11-
polygonEnd: function() { stream.lineEnd = lineEnd; }
11+
polygonEnd: function() { stream.lineEnd = lineEnd; stream.point = point; }
1212
};
1313

1414
function point(x, y) {

src/geo/path.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ d3.geo.path = function() {
99

1010
function path(object) {
1111
var radius = typeof pointRadius === "function" ? pointRadius.apply(this, arguments) : pointRadius;
12-
d3.geo.stream(object, projection.stream(context != null
13-
? new d3_geo_streamContext(context, radius)
14-
: new d3_geo_streamBuffer(buffer, radius)));
15-
var result = buffer.join("");
16-
buffer = [];
17-
return result;
12+
d3.geo.stream(object, projection.stream(context == null
13+
? new d3_geo_pathBuffer(buffer, radius)
14+
: new d3_geo_pathContext(context, radius)));
15+
if (buffer.length) {
16+
var result = buffer.join("");
17+
buffer = [];
18+
return result;
19+
}
1820
}
1921

2022
path.area = function(object) {

0 commit comments

Comments
 (0)