Skip to content

Commit 3f9cebb

Browse files
committed
Cache projection stream.
1 parent 61c67b9 commit 3f9cebb

4 files changed

Lines changed: 34 additions & 25 deletions

File tree

d3.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3482,7 +3482,7 @@ d3 = function() {
34823482
if (y > d3_geo_pathBoundsY1) d3_geo_pathBoundsY1 = y;
34833483
}
34843484
function d3_geo_pathBuffer() {
3485-
var pointCircle = d3_geo_pathCircle(4.5), buffer = [];
3485+
var pointCircle = d3_geo_pathBufferCircle(4.5), buffer = [];
34863486
var stream = {
34873487
point: point,
34883488
lineStart: function() {
@@ -3497,7 +3497,7 @@ d3 = function() {
34973497
stream.point = point;
34983498
},
34993499
pointRadius: function(_) {
3500-
pointCircle = d3_geo_pathCircle(_);
3500+
pointCircle = d3_geo_pathBufferCircle(_);
35013501
return stream;
35023502
},
35033503
result: function() {
@@ -3526,6 +3526,9 @@ d3 = function() {
35263526
}
35273527
return stream;
35283528
}
3529+
function d3_geo_pathBufferCircle(radius) {
3530+
return "m0," + radius + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius + "z";
3531+
}
35293532
var d3_geo_pathCentroid = {
35303533
point: d3_geo_pathCentroidPoint,
35313534
lineStart: d3_geo_pathCentroidLineStart,
@@ -3630,9 +3633,12 @@ d3 = function() {
36303633
return stream;
36313634
}
36323635
d3.geo.path = function() {
3633-
var pointRadius = 4.5, projection, context, projectStream, contextStream;
3636+
var pointRadius = 4.5, projection, context, projectStream, contextStream, objectStream;
36343637
function path(object) {
3635-
if (object) d3.geo.stream(object, projectStream(contextStream.pointRadius(typeof pointRadius === "function" ? +pointRadius.apply(this, arguments) : pointRadius)));
3638+
if (object) {
3639+
if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
3640+
d3.geo.stream(object, objectStream);
3641+
}
36363642
return contextStream.result();
36373643
}
36383644
path.area = function(object) {
@@ -3653,23 +3659,23 @@ d3 = function() {
36533659
path.projection = function(_) {
36543660
if (!arguments.length) return projection;
36553661
projectStream = (projection = _) ? _.stream || d3_geo_pathProjectStream(_) : d3_identity;
3662+
objectStream = projectStream(contextStream);
36563663
return path;
36573664
};
36583665
path.context = function(_) {
36593666
if (!arguments.length) return context;
36603667
contextStream = (context = _) == null ? new d3_geo_pathBuffer() : new d3_geo_pathContext(_);
3668+
objectStream = projectStream(contextStream);
36613669
return path;
36623670
};
36633671
path.pointRadius = function(_) {
36643672
if (!arguments.length) return pointRadius;
3665-
pointRadius = typeof _ === "function" ? _ : +_;
3673+
pointRadius = typeof _ === "function" ? _ : (_ = +_, contextStream.pointRadius(_),
3674+
_);
36663675
return path;
36673676
};
36683677
return path.projection(d3.geo.albersUsa()).context(null);
36693678
};
3670-
function d3_geo_pathCircle(radius) {
3671-
return "m0," + radius + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius + "a" + radius + "," + radius + " 0 1,1 0," + +2 * radius + "z";
3672-
}
36733679
function d3_geo_pathProjectStream(project) {
36743680
var resample = d3_geo_resample(function(λ, φ) {
36753681
return project([ λ * d3_degrees, φ * d3_degrees ]);

d3.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/geo/path-buffer.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function d3_geo_pathBuffer() {
2-
var pointCircle = d3_geo_pathCircle(4.5),
2+
var pointCircle = d3_geo_pathBufferCircle(4.5),
33
buffer = [];
44

55
var stream = {
@@ -14,7 +14,7 @@ function d3_geo_pathBuffer() {
1414
polygonEnd: function() { stream.lineEnd = lineEnd; stream.point = point; },
1515

1616
pointRadius: function(_) {
17-
pointCircle = d3_geo_pathCircle(_);
17+
pointCircle = d3_geo_pathBufferCircle(_);
1818
return stream;
1919
},
2020

@@ -50,3 +50,10 @@ function d3_geo_pathBuffer() {
5050

5151
return stream;
5252
}
53+
54+
function d3_geo_pathBufferCircle(radius) {
55+
return "m0," + radius
56+
+ "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius
57+
+ "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius
58+
+ "z";
59+
}

src/geo/path.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ d3.geo.path = function() {
1919
projection,
2020
context,
2121
projectStream,
22-
contextStream;
22+
contextStream,
23+
objectStream;
2324

2425
function path(object) {
25-
if (object) d3.geo.stream(object, projectStream(
26-
contextStream.pointRadius(typeof pointRadius === "function"
27-
? +pointRadius.apply(this, arguments)
28-
: pointRadius)));
26+
if (object) {
27+
if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
28+
d3.geo.stream(object, objectStream);
29+
}
2930
return contextStream.result();
3031
}
3132

@@ -50,31 +51,26 @@ d3.geo.path = function() {
5051
path.projection = function(_) {
5152
if (!arguments.length) return projection;
5253
projectStream = (projection = _) ? _.stream || d3_geo_pathProjectStream(_) : d3_identity;
54+
objectStream = projectStream(contextStream);
5355
return path;
5456
};
5557

5658
path.context = function(_) {
5759
if (!arguments.length) return context;
5860
contextStream = (context = _) == null ? new d3_geo_pathBuffer : new d3_geo_pathContext(_);
61+
objectStream = projectStream(contextStream);
5962
return path;
6063
};
6164

6265
path.pointRadius = function(_) {
6366
if (!arguments.length) return pointRadius;
64-
pointRadius = typeof _ === "function" ? _ : +_;
67+
pointRadius = typeof _ === "function" ? _ : (_ = +_, contextStream.pointRadius(_), _);
6568
return path;
6669
};
6770

6871
return path.projection(d3.geo.albersUsa()).context(null);
6972
};
7073

71-
function d3_geo_pathCircle(radius) {
72-
return "m0," + radius
73-
+ "a" + radius + "," + radius + " 0 1,1 0," + (-2 * radius)
74-
+ "a" + radius + "," + radius + " 0 1,1 0," + (+2 * radius)
75-
+ "z";
76-
}
77-
7874
function d3_geo_pathProjectStream(project) {
7975
var resample = d3_geo_resample(function(λ, φ) { return project([λ * d3_degrees, φ * d3_degrees]); });
8076
return function(stream) {

0 commit comments

Comments
 (0)