Skip to content

Commit

Permalink
Lazy circle for points.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed May 16, 2017
1 parent 917ba9a commit c316714
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/path/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ export default function PathString() {
}

PathString.prototype = {
_radius: 4.5,
_circle: circle(4.5),
pointRadius: function(_) {
return this._circle = circle(_), this;
if ((_ = +_) !== this._radius) this._radius = _, this._circle = null;
return this;
},
polygonStart: function() {
this._line = 0;
Expand All @@ -32,6 +34,7 @@ PathString.prototype = {
break;
}
default: {
if (this._circle == null) this._circle = circle(this._radius);
this._string.push("M", x, ",", y, this._circle);
break;
}
Expand Down
10 changes: 10 additions & 0 deletions test/path/string-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ tape("geoPath(Point) renders a point", function(test) {
test.end();
});

tape("geoPath.pointRadius(radius)(Point) renders a point of the given radius", function(test) {
test.pathEqual(d3_geo.geoPath()
.projection(equirectangular)
.pointRadius(10)({
type: "Point",
coordinates: [-63, 18]
}), "M165,160m0,10a10,10 0 1,1 0,-20a10,10 0 1,1 0,20z");
test.end();
});

tape("geoPath(MultiPoint) renders a point", function(test) {
test.pathEqual(testPath(equirectangular, {
type: "MultiPoint",
Expand Down

0 comments on commit c316714

Please sign in to comment.