Skip to content

Commit c5d230d

Browse files
committed
Merge branch '2.9.6'
2 parents e71de33 + 2643a86 commit c5d230d

16 files changed

Lines changed: 328 additions & 243 deletions

d3.v2.js

Lines changed: 134 additions & 111 deletions
Large diffs are not rendered by default.

d3.v2.min.js

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "d3",
3-
"version": "2.9.5",
3+
"version": "2.9.6",
44
"description": "A small, free JavaScript library for manipulating documents based on data.",
55
"keywords": [
66
"dom",

src/core/core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
d3 = {version: "2.9.5"}; // semver
1+
d3 = {version: "2.9.6"}; // semver

src/core/interpolate.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ d3.interpolateHsl = function(a, b) {
171171
h1 = b.h - h0,
172172
s1 = b.s - s0,
173173
l1 = b.l - l0;
174+
if (h1 > 180) h1 -= 360; else if (h1 < -180) h1 += 360; // shortest path
174175
return function(t) {
175176
return d3_hsl_rgb(h0 + h1 * t, s0 + s1 * t, l0 + l1 * t).toString();
176177
};

src/geo/circle.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ d3.geo.circle = function() {
44
var origin = [0, 0],
55
degrees = 90 - 1e-2,
66
radians = degrees * d3_geo_radians,
7-
arc = d3.geo.greatArc().target(d3_identity);
7+
arc = d3.geo.greatArc().source(origin).target(d3_identity);
88

99
function circle() {
1010
// TODO render a circle as a Polygon
@@ -15,8 +15,8 @@ d3.geo.circle = function() {
1515
}
1616

1717
circle.clip = function(d) {
18-
arc.source(typeof origin === "function" ? origin.apply(this, arguments) : origin);
19-
return clipType(d);
18+
if (typeof origin === "function") arc.source(origin.apply(this, arguments));
19+
return clipType(d) || null;
2020
};
2121

2222
var clipType = d3_geo_type({
@@ -96,9 +96,11 @@ d3.geo.circle = function() {
9696
d0 = d1;
9797
}
9898

99-
if (p1 && clipped.length) {
100-
d1 = arc.distance(p2 = clipped[0]);
101-
clipped.push(d3_geo_greatArcInterpolate(p1, p2)((d0 - radians) / (d0 - d1)));
99+
// Close the clipped polygon if necessary.
100+
p0 = coordinates[0];
101+
p1 = clipped[0];
102+
if (p1 && p2[0] === p0[0] && p2[1] === p0[1] && !(p2[0] === p1[0] && p2[1] === p1[1])) {
103+
clipped.push(p1);
102104
}
103105

104106
return resample(clipped);
@@ -126,6 +128,7 @@ d3.geo.circle = function() {
126128
circle.origin = function(x) {
127129
if (!arguments.length) return origin;
128130
origin = x;
131+
if (typeof origin !== "function") arc.source(origin);
129132
return circle;
130133
};
131134

@@ -135,12 +138,5 @@ d3.geo.circle = function() {
135138
return circle;
136139
};
137140

138-
// Precision is specified in degrees.
139-
circle.precision = function(x) {
140-
if (!arguments.length) return arc.precision();
141-
arc.precision(x);
142-
return circle;
143-
};
144-
145-
return circle;
141+
return d3.rebind(circle, arc, "precision");
146142
}

src/geo/greatArc.js

Lines changed: 64 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,44 @@
11
d3.geo.greatArc = function() {
2-
var source = d3_geo_greatArcSource,
3-
target = d3_geo_greatArcTarget,
4-
precision = 6 * d3_geo_radians;
2+
var source = d3_geo_greatArcSource, p0,
3+
target = d3_geo_greatArcTarget, p1,
4+
precision = 6 * d3_geo_radians,
5+
interpolate = d3_geo_greatArcInterpolator();
56

67
function greatArc() {
7-
var a = typeof source === "function" ? source.apply(this, arguments) : source,
8-
b = typeof target === "function" ? target.apply(this, arguments) : target,
9-
i = d3_geo_greatArcInterpolate(a, b),
10-
dt = precision / i.d,
8+
var d = greatArc.distance.apply(this, arguments), // initializes the interpolator, too
119
t = 0,
12-
coordinates = [a];
13-
while ((t += dt) < 1) coordinates.push(i(t));
14-
coordinates.push(b);
15-
return {
16-
type: "LineString",
17-
coordinates: coordinates
18-
};
10+
dt = precision / d,
11+
coordinates = [p0];
12+
while ((t += dt) < 1) coordinates.push(interpolate(t));
13+
coordinates.push(p1);
14+
return {type: "LineString", coordinates: coordinates};
1915
}
2016

2117
// Length returned in radians; multiply by radius for distance.
2218
greatArc.distance = function() {
23-
var a = typeof source === "function" ? source.apply(this, arguments) : source,
24-
b = typeof target === "function" ? target.apply(this, arguments) : target;
25-
return d3_geo_greatArcInterpolate(a, b).d;
19+
if (typeof source === "function") interpolate.source(p0 = source.apply(this, arguments));
20+
if (typeof target === "function") interpolate.target(p1 = target.apply(this, arguments));
21+
return interpolate.distance();
2622
};
2723

28-
greatArc.source = function(x) {
24+
greatArc.source = function(_) {
2925
if (!arguments.length) return source;
30-
source = x;
26+
source = _;
27+
if (typeof source !== "function") interpolate.source(p0 = source);
3128
return greatArc;
3229
};
3330

34-
greatArc.target = function(x) {
31+
greatArc.target = function(_) {
3532
if (!arguments.length) return target;
36-
target = x;
33+
target = _;
34+
if (typeof target !== "function") interpolate.target(p1 = target);
3735
return greatArc;
3836
};
3937

4038
// Precision is specified in degrees.
41-
greatArc.precision = function(x) {
39+
greatArc.precision = function(_) {
4240
if (!arguments.length) return precision / d3_geo_radians;
43-
precision = x * d3_geo_radians;
41+
precision = _ * d3_geo_radians;
4442
return greatArc;
4543
};
4644

@@ -55,26 +53,56 @@ function d3_geo_greatArcTarget(d) {
5553
return d.target;
5654
}
5755

58-
function d3_geo_greatArcInterpolate(a, b) {
59-
var x0 = a[0] * d3_geo_radians, cx0 = Math.cos(x0), sx0 = Math.sin(x0),
60-
y0 = a[1] * d3_geo_radians, cy0 = Math.cos(y0), sy0 = Math.sin(y0),
61-
x1 = b[0] * d3_geo_radians, cx1 = Math.cos(x1), sx1 = Math.sin(x1),
62-
y1 = b[1] * d3_geo_radians, cy1 = Math.cos(y1), sy1 = Math.sin(y1),
63-
d = interpolate.d = Math.acos(Math.max(-1, Math.min(1, sy0 * sy1 + cy0 * cy1 * Math.cos(x1 - x0)))),
64-
sd = Math.sin(d);
56+
function d3_geo_greatArcInterpolator() {
57+
var x0, y0, cy0, sy0, kx0, ky0,
58+
x1, y1, cy1, sy1, kx1, ky1,
59+
d,
60+
k;
6561

66-
// From http://williams.best.vwh.net/avform.htm#Intermediate
6762
function interpolate(t) {
68-
var A = Math.sin(d - (t *= d)) / sd,
69-
B = Math.sin(t) / sd,
70-
x = A * cy0 * cx0 + B * cy1 * cx1,
71-
y = A * cy0 * sx0 + B * cy1 * sx1,
72-
z = A * sy0 + B * sy1;
63+
var B = Math.sin(t *= d) * k,
64+
A = Math.sin(d - t) * k,
65+
x = A * kx0 + B * kx1,
66+
y = A * ky0 + B * ky1,
67+
z = A * sy0 + B * sy1;
7368
return [
7469
Math.atan2(y, x) / d3_geo_radians,
7570
Math.atan2(z, Math.sqrt(x * x + y * y)) / d3_geo_radians
7671
];
7772
}
7873

74+
interpolate.distance = function() {
75+
if (d == null) k = 1 / Math.sin(d = Math.acos(Math.max(-1, Math.min(1, sy0 * sy1 + cy0 * cy1 * Math.cos(x1 - x0)))));
76+
return d;
77+
};
78+
79+
interpolate.source = function(_) {
80+
var cx0 = Math.cos(x0 = _[0] * d3_geo_radians),
81+
sx0 = Math.sin(x0);
82+
cy0 = Math.cos(y0 = _[1] * d3_geo_radians);
83+
sy0 = Math.sin(y0);
84+
kx0 = cy0 * cx0;
85+
ky0 = cy0 * sx0;
86+
d = null;
87+
return interpolate;
88+
};
89+
90+
interpolate.target = function(_) {
91+
var cx1 = Math.cos(x1 = _[0] * d3_geo_radians),
92+
sx1 = Math.sin(x1);
93+
cy1 = Math.cos(y1 = _[1] * d3_geo_radians);
94+
sy1 = Math.sin(y1);
95+
kx1 = cy1 * cx1;
96+
ky1 = cy1 * sx1;
97+
d = null;
98+
return interpolate;
99+
};
100+
79101
return interpolate;
80102
}
103+
104+
function d3_geo_greatArcInterpolate(a, b) {
105+
var i = d3_geo_greatArcInterpolator().source(a).target(b);
106+
i.distance();
107+
return i;
108+
}

src/geo/path.js

Lines changed: 31 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
d3.geo.path = function() {
99
var pointRadius = 4.5,
1010
pointCircle = d3_path_circle(pointRadius),
11-
projection = d3.geo.albersUsa();
11+
projection = d3.geo.albersUsa(),
12+
buffer = [];
1213

1314
function path(d, i) {
14-
if (typeof pointRadius === "function") {
15-
pointCircle = d3_path_circle(pointRadius.apply(this, arguments));
16-
}
17-
return pathType(d) || null;
15+
if (typeof pointRadius === "function") pointCircle = d3_path_circle(pointRadius.apply(this, arguments));
16+
pathType(d);
17+
var result = buffer.length ? buffer.join("") : null;
18+
buffer = [];
19+
return result;
1820
}
1921

2022
function project(coordinates) {
@@ -24,44 +26,38 @@ d3.geo.path = function() {
2426
var pathType = d3_geo_type({
2527

2628
FeatureCollection: function(o) {
27-
var path = [],
28-
features = o.features,
29+
var features = o.features,
2930
i = -1, // features.index
3031
n = features.length;
31-
while (++i < n) path.push(pathType(features[i].geometry));
32-
return path.join("");
32+
while (++i < n) buffer.push(pathType(features[i].geometry));
3333
},
3434

3535
Feature: function(o) {
36-
return pathType(o.geometry);
36+
pathType(o.geometry);
3737
},
3838

3939
Point: function(o) {
40-
return "M" + project(o.coordinates) + pointCircle;
40+
buffer.push("M", project(o.coordinates), pointCircle);
4141
},
4242

4343
MultiPoint: function(o) {
44-
var path = [],
45-
coordinates = o.coordinates,
44+
var coordinates = o.coordinates,
4645
i = -1, // coordinates.index
4746
n = coordinates.length;
48-
while (++i < n) path.push("M", project(coordinates[i]), pointCircle);
49-
return path.join("");
47+
while (++i < n) buffer.push("M", project(coordinates[i]), pointCircle);
5048
},
5149

5250
LineString: function(o) {
53-
var path = ["M"],
54-
coordinates = o.coordinates,
51+
var coordinates = o.coordinates,
5552
i = -1, // coordinates.index
5653
n = coordinates.length;
57-
while (++i < n) path.push(project(coordinates[i]), "L");
58-
path.pop();
59-
return path.join("");
54+
buffer.push("M");
55+
while (++i < n) buffer.push(project(coordinates[i]), "L");
56+
buffer.pop();
6057
},
6158

6259
MultiLineString: function(o) {
63-
var path = [],
64-
coordinates = o.coordinates,
60+
var coordinates = o.coordinates,
6561
i = -1, // coordinates.index
6662
n = coordinates.length,
6763
subcoordinates, // coordinates[i]
@@ -71,16 +67,14 @@ d3.geo.path = function() {
7167
subcoordinates = coordinates[i];
7268
j = -1;
7369
m = subcoordinates.length;
74-
path.push("M");
75-
while (++j < m) path.push(project(subcoordinates[j]), "L");
76-
path.pop();
70+
buffer.push("M");
71+
while (++j < m) buffer.push(project(subcoordinates[j]), "L");
72+
buffer.pop();
7773
}
78-
return path.join("");
7974
},
8075

8176
Polygon: function(o) {
82-
var path = [],
83-
coordinates = o.coordinates,
77+
var coordinates = o.coordinates,
8478
i = -1, // coordinates.index
8579
n = coordinates.length,
8680
subcoordinates, // coordinates[i]
@@ -90,17 +84,15 @@ d3.geo.path = function() {
9084
subcoordinates = coordinates[i];
9185
j = -1;
9286
if ((m = subcoordinates.length - 1) > 0) {
93-
path.push("M");
94-
while (++j < m) path.push(project(subcoordinates[j]), "L");
95-
path[path.length - 1] = "Z";
87+
buffer.push("M");
88+
while (++j < m) buffer.push(project(subcoordinates[j]), "L");
89+
buffer[buffer.length - 1] = "Z";
9690
}
9791
}
98-
return path.join("");
9992
},
10093

10194
MultiPolygon: function(o) {
102-
var path = [],
103-
coordinates = o.coordinates,
95+
var coordinates = o.coordinates,
10496
i = -1, // coordinates index
10597
n = coordinates.length,
10698
subcoordinates, // coordinates[i]
@@ -117,22 +109,19 @@ d3.geo.path = function() {
117109
subsubcoordinates = subcoordinates[j];
118110
k = -1;
119111
if ((p = subsubcoordinates.length - 1) > 0) {
120-
path.push("M");
121-
while (++k < p) path.push(project(subsubcoordinates[k]), "L");
122-
path[path.length - 1] = "Z";
112+
buffer.push("M");
113+
while (++k < p) buffer.push(project(subsubcoordinates[k]), "L");
114+
buffer[buffer.length - 1] = "Z";
123115
}
124116
}
125117
}
126-
return path.join("");
127118
},
128119

129120
GeometryCollection: function(o) {
130-
var path = [],
131-
geometries = o.geometries,
121+
var geometries = o.geometries,
132122
i = -1, // geometries index
133123
n = geometries.length;
134-
while (++i < n) path.push(pathType(geometries[i]));
135-
return path.join("");
124+
while (++i < n) buffer.push(pathType(geometries[i]));
136125
}
137126

138127
});

0 commit comments

Comments
 (0)