d3_rails 3.1.6 → 3.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MzM3NDZhNmI3NmIzNTU2OTBjYWQ4ZGRlZjkwZTA2NDE0ZTUxNWVjZQ==
5
+ data.tar.gz: !binary |-
6
+ YmE4ZTc2MTIyNjcyZmEyNWIwNDM3ZGI4MGY5MWY3NWQzMDg1OWU0Ng==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MmE5MjU3MTU5NjVmNWE3NWIyZmQ4NTAxZTBhMWJlOGEzOTkyOTEzMGI5MWNl
10
+ M2YyZWExMjA3OTMyOWQ1NzY1YzQ1ZmVjMDQ5NzUyMDZmODA3NzhhYWM5YjQw
11
+ YmE4ZTA2MTg4Yzk0OTU2MmU2MDc4NzY5YjQ2MGI2MTVjZjAyNGE=
12
+ data.tar.gz: !binary |-
13
+ ZTZjZGUzMGUzNDEzZTg2N2ZmZGIzMDBjMmJkNDEwM2Y0NmEwZjAzMDk0MWRi
14
+ NzIzOTYyODE1MGIxZWJkZDE2YjQ5NjFjNDc4NzMwODRjZjYzM2RhZTc3ZTNi
15
+ ZGQ3YTg0YzY4NDgxYzg5ZDNlOWI1NDZmNjI5YTlkNjRlNDI2ODE=
data/MIT_LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ d3_rails License
2
+ (note that this license only really covers the ruby part
3
+ of the code, d3 has it's own license which is also included
4
+ in this gem, thank you Michael Bostocks for sharing
5
+ your framework).
6
+ ---------------------------
7
+
8
+ The MIT License (MIT)
9
+
10
+ Copyright (c) 2011-2013, Han Kang
11
+
12
+ Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ of this software and associated documentation files (the "Software"), to deal
14
+ in the Software without restriction, including without limitation the rights
15
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ copies of the Software, and to permit persons to whom the Software is
17
+ furnished to do so, subject to the following conditions:
18
+
19
+ The above copyright notice and this permission notice shall be included in
20
+ all copies or substantial portions of the Software.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # D3_Rails
2
+ ## Version 3.1.9 (of d3 in most current gem)
2
3
 
3
4
  **D3_Rails** is a small, lightweight gem which allows you to include any
4
5
  and all of D3 Javascripts into your 3.1 Rails application, merely by
@@ -12,11 +13,6 @@ handle interactivity, and incorporate smooth transitions and staged animations
12
13
  into your pages. You can use D3 as a visualization framework (like Protovis),
13
14
  or you can use it to build dynamic pages (like jQuery).
14
15
 
15
- # D3 Version
16
-
17
- The current release of this gem is using **D3 v=3.1.6**
18
- **Last Updated 5-9-2013**
19
-
20
16
  # Included Javascripts
21
17
 
22
18
  d3.js
@@ -1,3 +1,3 @@
1
1
  module D3Rails
2
- VERSION = "3.1.6"
2
+ VERSION = "3.1.9"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  d3 = function() {
2
2
  var d3 = {
3
- version: "3.1.6"
3
+ version: "3.1.9"
4
4
  };
5
5
  if (!Date.now) Date.now = function() {
6
6
  return +new Date();
@@ -2076,7 +2076,7 @@ d3 = function() {
2076
2076
  d3.geo.stream(object, d3_geo_area);
2077
2077
  return d3_geo_areaSum;
2078
2078
  };
2079
- var d3_geo_areaSum, d3_geo_areaRingU, d3_geo_areaRingV;
2079
+ var d3_geo_areaSum, d3_geo_areaRingSum;
2080
2080
  var d3_geo_area = {
2081
2081
  sphere: function() {
2082
2082
  d3_geo_areaSum += 4 * π;
@@ -2085,11 +2085,11 @@ d3 = function() {
2085
2085
  lineStart: d3_noop,
2086
2086
  lineEnd: d3_noop,
2087
2087
  polygonStart: function() {
2088
- d3_geo_areaRingU = 1, d3_geo_areaRingV = 0;
2088
+ d3_geo_areaRingSum = 0;
2089
2089
  d3_geo_area.lineStart = d3_geo_areaRingStart;
2090
2090
  },
2091
2091
  polygonEnd: function() {
2092
- var area = 2 * Math.atan2(d3_geo_areaRingV, d3_geo_areaRingU);
2092
+ var area = 2 * d3_geo_areaRingSum;
2093
2093
  d3_geo_areaSum += area < 0 ? 4 * π + area : area;
2094
2094
  d3_geo_area.lineStart = d3_geo_area.lineEnd = d3_geo_area.point = d3_noop;
2095
2095
  }
@@ -2104,44 +2104,169 @@ d3 = function() {
2104
2104
  function nextPoint(λ, φ) {
2105
2105
  λ *= d3_radians;
2106
2106
  φ = φ * d3_radians / 2 + π / 4;
2107
- var dλ = λ - λ0, cosφ = Math.cos(φ), sinφ = Math.sin(φ), k = sinφ0 * sinφ, u0 = d3_geo_areaRingU, v0 = d3_geo_areaRingV, u = cosφ0 * cosφ + k * Math.cos(dλ), v = k * Math.sin(dλ);
2108
- d3_geo_areaRingU = u0 * u - v0 * v;
2109
- d3_geo_areaRingV = v0 * u + u0 * v;
2107
+ var dλ = λ - λ0, cosφ = Math.cos(φ), sinφ = Math.sin(φ), k = sinφ0 * sinφ, u = cosφ0 * cosφ + k * Math.cos(dλ), v = k * Math.sin(dλ);
2108
+ d3_geo_areaRingSum += Math.atan2(v, u);
2110
2109
  λ0 = λ, cosφ0 = cosφ, sinφ0 = sinφ;
2111
2110
  }
2112
2111
  d3_geo_area.lineEnd = function() {
2113
2112
  nextPoint(λ00, φ00);
2114
2113
  };
2115
2114
  }
2116
- d3.geo.bounds = d3_geo_bounds(d3_identity);
2117
- function d3_geo_bounds(projectStream) {
2118
- var x0, y0, x1, y1;
2115
+ function d3_geo_cartesian(spherical) {
2116
+ var λ = spherical[0], φ = spherical[1], cosφ = Math.cos(φ);
2117
+ return [ cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ) ];
2118
+ }
2119
+ function d3_geo_cartesianDot(a, b) {
2120
+ return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
2121
+ }
2122
+ function d3_geo_cartesianCross(a, b) {
2123
+ return [ a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0] ];
2124
+ }
2125
+ function d3_geo_cartesianAdd(a, b) {
2126
+ a[0] += b[0];
2127
+ a[1] += b[1];
2128
+ a[2] += b[2];
2129
+ }
2130
+ function d3_geo_cartesianScale(vector, k) {
2131
+ return [ vector[0] * k, vector[1] * k, vector[2] * k ];
2132
+ }
2133
+ function d3_geo_cartesianNormalize(d) {
2134
+ var l = Math.sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
2135
+ d[0] /= l;
2136
+ d[1] /= l;
2137
+ d[2] /= l;
2138
+ }
2139
+ function d3_geo_spherical(cartesian) {
2140
+ return [ Math.atan2(cartesian[1], cartesian[0]), Math.asin(Math.max(-1, Math.min(1, cartesian[2]))) ];
2141
+ }
2142
+ function d3_geo_sphericalEqual(a, b) {
2143
+ return Math.abs(a[0] - b[0]) < ε && Math.abs(a[1] - b[1]) < ε;
2144
+ }
2145
+ d3.geo.bounds = function() {
2146
+ var λ0, φ0, λ1, φ1, λ_, λ__, φ__, p0, dλSum, ranges, range;
2119
2147
  var bound = {
2120
- point: boundPoint,
2121
- lineStart: d3_noop,
2122
- lineEnd: d3_noop,
2148
+ point: point,
2149
+ lineStart: lineStart,
2150
+ lineEnd: lineEnd,
2123
2151
  polygonStart: function() {
2124
- bound.lineEnd = boundPolygonLineEnd;
2152
+ bound.point = ringPoint;
2153
+ bound.lineStart = ringStart;
2154
+ bound.lineEnd = ringEnd;
2155
+ dλSum = 0;
2156
+ d3_geo_area.polygonStart();
2125
2157
  },
2126
2158
  polygonEnd: function() {
2127
- bound.point = boundPoint;
2159
+ d3_geo_area.polygonEnd();
2160
+ bound.point = point;
2161
+ bound.lineStart = lineStart;
2162
+ bound.lineEnd = lineEnd;
2163
+ if (d3_geo_areaRingSum < 0) λ0 = -(λ1 = 180), φ0 = -(φ1 = 90); else if (dλSum > ε) φ1 = 90; else if (dλSum < -ε) φ0 = -90;
2164
+ range[0] = λ0, range[1] = λ1;
2165
+ }
2166
+ };
2167
+ function point(λ, φ) {
2168
+ ranges.push(range = [ λ0 = λ, λ1 = λ ]);
2169
+ if (φ < φ0) φ0 = φ;
2170
+ if (φ > φ1) φ1 = φ;
2171
+ }
2172
+ function linePoint(λ, φ) {
2173
+ var p = d3_geo_cartesian([ λ * d3_radians, φ * d3_radians ]);
2174
+ if (p0) {
2175
+ var normal = d3_geo_cartesianCross(p0, p), equatorial = [ normal[1], -normal[0], 0 ], inflection = d3_geo_cartesianCross(equatorial, normal);
2176
+ d3_geo_cartesianNormalize(inflection);
2177
+ inflection = d3_geo_spherical(inflection);
2178
+ var dλ = λ - λ_, s = dλ > 0 ? 1 : -1, λi = inflection[0] * d3_degrees * s, antimeridian = Math.abs(dλ) > 180;
2179
+ if (antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
2180
+ var φi = inflection[1] * d3_degrees;
2181
+ if (φi > φ1) φ1 = φi;
2182
+ } else if (λi = (λi + 360) % 360 - 180, antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
2183
+ var φi = -inflection[1] * d3_degrees;
2184
+ if (φi < φ0) φ0 = φi;
2185
+ } else {
2186
+ if (φ < φ0) φ0 = φ;
2187
+ if (φ > φ1) φ1 = φ;
2188
+ }
2189
+ if (antimeridian) {
2190
+ if (λ < λ_) {
2191
+ if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
2192
+ } else {
2193
+ if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
2194
+ }
2195
+ } else {
2196
+ if (λ1 >= λ0) {
2197
+ if (λ < λ0) λ0 = λ;
2198
+ if (λ > λ1) λ1 = λ;
2199
+ } else {
2200
+ if (λ > λ_) {
2201
+ if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
2202
+ } else {
2203
+ if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
2204
+ }
2205
+ }
2206
+ }
2207
+ } else {
2208
+ point(λ, φ);
2128
2209
  }
2129
- };
2130
- function boundPoint(x, y) {
2131
- if (x < x0) x0 = x;
2132
- if (x > x1) x1 = x;
2133
- if (y < y0) y0 = y;
2134
- if (y > y1) y1 = y;
2210
+ p0 = p, λ_ = λ;
2211
+ }
2212
+ function lineStart() {
2213
+ bound.point = linePoint;
2135
2214
  }
2136
- function boundPolygonLineEnd() {
2137
- bound.point = bound.lineEnd = d3_noop;
2215
+ function lineEnd() {
2216
+ range[0] = λ0, range[1] = λ1;
2217
+ bound.point = point;
2218
+ p0 = null;
2219
+ }
2220
+ function ringPoint(λ, φ) {
2221
+ if (p0) {
2222
+ var dλ = λ - λ_;
2223
+ dλSum += Math.abs(dλ) > 180 ? dλ + (dλ > 0 ? 360 : -360) : dλ;
2224
+ } else λ__ = λ, φ__ = φ;
2225
+ d3_geo_area.point(λ, φ);
2226
+ linePoint(λ, φ);
2227
+ }
2228
+ function ringStart() {
2229
+ d3_geo_area.lineStart();
2230
+ }
2231
+ function ringEnd() {
2232
+ ringPoint(λ__, φ__);
2233
+ d3_geo_area.lineEnd();
2234
+ if (Math.abs(dλSum) > ε) λ0 = -(λ1 = 180);
2235
+ range[0] = λ0, range[1] = λ1;
2236
+ p0 = null;
2237
+ }
2238
+ function angle(λ0, λ1) {
2239
+ return (λ1 -= λ0) < 0 ? λ1 + 360 : λ1;
2240
+ }
2241
+ function compareRanges(a, b) {
2242
+ return a[0] - b[0];
2243
+ }
2244
+ function withinRange(x, range) {
2245
+ return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
2138
2246
  }
2139
2247
  return function(feature) {
2140
- y1 = x1 = -(x0 = y0 = Infinity);
2141
- d3.geo.stream(feature, projectStream(bound));
2142
- return [ [ x0, y0 ], [ x1, y1 ] ];
2248
+ φ1 = λ1 = -(λ0 = φ0 = Infinity);
2249
+ ranges = [];
2250
+ d3.geo.stream(feature, bound);
2251
+ ranges.sort(compareRanges);
2252
+ for (var i = 1, n = ranges.length, a = ranges[0], b, merged = [ a ]; i < n; ++i) {
2253
+ b = ranges[i];
2254
+ if (withinRange(b[0], a) || withinRange(b[1], a)) {
2255
+ if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
2256
+ if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
2257
+ } else {
2258
+ merged.push(a = b);
2259
+ }
2260
+ }
2261
+ var best = -Infinity, dλ;
2262
+ for (var n = merged.length - 1, i = 0, a = merged[n], b; i <= n; a = b, ++i) {
2263
+ b = merged[i];
2264
+ if ((dλ = angle(a[1], b[0])) > best) best = dλ, λ0 = b[0], λ1 = a[1];
2265
+ }
2266
+ ranges = range = null;
2267
+ return [ [ λ0, φ0 ], [ λ1, φ1 ] ];
2143
2268
  };
2144
- }
2269
+ }();
2145
2270
  d3.geo.centroid = function(object) {
2146
2271
  d3_geo_centroidDimension = d3_geo_centroidW = d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0;
2147
2272
  d3.geo.stream(object, d3_geo_centroid);
@@ -2223,39 +2348,9 @@ d3 = function() {
2223
2348
  function d3_geo_centroidLineEnd() {
2224
2349
  d3_geo_centroid.point = d3_geo_centroidPoint;
2225
2350
  }
2226
- function d3_geo_cartesian(spherical) {
2227
- var λ = spherical[0], φ = spherical[1], cosφ = Math.cos(φ);
2228
- return [ cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ) ];
2229
- }
2230
- function d3_geo_cartesianDot(a, b) {
2231
- return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
2232
- }
2233
- function d3_geo_cartesianCross(a, b) {
2234
- return [ a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0] ];
2235
- }
2236
- function d3_geo_cartesianAdd(a, b) {
2237
- a[0] += b[0];
2238
- a[1] += b[1];
2239
- a[2] += b[2];
2240
- }
2241
- function d3_geo_cartesianScale(vector, k) {
2242
- return [ vector[0] * k, vector[1] * k, vector[2] * k ];
2243
- }
2244
- function d3_geo_cartesianNormalize(d) {
2245
- var l = Math.sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
2246
- d[0] /= l;
2247
- d[1] /= l;
2248
- d[2] /= l;
2249
- }
2250
2351
  function d3_true() {
2251
2352
  return true;
2252
2353
  }
2253
- function d3_geo_spherical(cartesian) {
2254
- return [ Math.atan2(cartesian[1], cartesian[0]), Math.asin(Math.max(-1, Math.min(1, cartesian[2]))) ];
2255
- }
2256
- function d3_geo_sphericalEqual(a, b) {
2257
- return Math.abs(a[0] - b[0]) < ε && Math.abs(a[1] - b[1]) < ε;
2258
- }
2259
2354
  function d3_geo_clipPolygon(segments, compare, inside, interpolate, listener) {
2260
2355
  var subject = [], clip = [];
2261
2356
  segments.forEach(function(segment) {
@@ -2752,7 +2847,7 @@ d3 = function() {
2752
2847
  }
2753
2848
  listener.point(b[0], b[1]);
2754
2849
  if (!v) listener.lineEnd();
2755
- } else {
2850
+ } else if (v) {
2756
2851
  listener.lineStart();
2757
2852
  listener.point(x, y);
2758
2853
  }
@@ -3257,63 +3352,94 @@ d3 = function() {
3257
3352
  }
3258
3353
  forward.invert = function(x, y) {
3259
3354
  var ρ0_y = ρ0 - y;
3260
- return [ Math.atan2(x, ρ0_y) / n, Math.asin((C - (x * x + ρ0_y * ρ0_y) * n * n) / (2 * n)) ];
3355
+ return [ Math.atan2(x, ρ0_y) / n, d3_asin((C - (x * x + ρ0_y * ρ0_y) * n * n) / (2 * n)) ];
3261
3356
  };
3262
3357
  return forward;
3263
3358
  }
3264
3359
  (d3.geo.conicEqualArea = function() {
3265
3360
  return d3_geo_conic(d3_geo_conicEqualArea);
3266
3361
  }).raw = d3_geo_conicEqualArea;
3362
+ d3.geo.albers = function() {
3363
+ return d3.geo.conicEqualArea().rotate([ 96, 0 ]).center([ -.6, 38.7 ]).parallels([ 29.5, 45.5 ]).scale(1070);
3364
+ };
3267
3365
  d3.geo.albersUsa = function() {
3268
- var lower48 = d3.geo.conicEqualArea().rotate([ 98, 0 ]).center([ 0, 38 ]).parallels([ 29.5, 45.5 ]);
3269
- var alaska = d3.geo.conicEqualArea().rotate([ 160, 0 ]).center([ 0, 60 ]).parallels([ 55, 65 ]);
3270
- var hawaii = d3.geo.conicEqualArea().rotate([ 160, 0 ]).center([ 0, 20 ]).parallels([ 8, 18 ]);
3271
- var puertoRico = d3.geo.conicEqualArea().rotate([ 60, 0 ]).center([ 0, 10 ]).parallels([ 8, 18 ]);
3272
- var alaskaInvert, hawaiiInvert, puertoRicoInvert;
3366
+ var lower48 = d3.geo.albers();
3367
+ var alaska = d3.geo.conicEqualArea().rotate([ 154, 0 ]).center([ -2, 58.5 ]).parallels([ 55, 65 ]);
3368
+ var hawaii = d3.geo.conicEqualArea().rotate([ 157, 0 ]).center([ -3, 19.9 ]).parallels([ 8, 18 ]);
3369
+ var point, pointStream = {
3370
+ point: function(x, y) {
3371
+ point = [ x, y ];
3372
+ }
3373
+ }, lower48Point, alaskaPoint, hawaiiPoint;
3273
3374
  function albersUsa(coordinates) {
3274
- return projection(coordinates)(coordinates);
3275
- }
3276
- function projection(point) {
3277
- var lon = point[0], lat = point[1];
3278
- return lat > 50 ? alaska : lon < -140 ? hawaii : lat < 21 ? puertoRico : lower48;
3375
+ var x = coordinates[0], y = coordinates[1];
3376
+ point = null;
3377
+ (lower48Point(x, y), point) || (alaskaPoint(x, y), point) || hawaiiPoint(x, y);
3378
+ return point;
3279
3379
  }
3280
3380
  albersUsa.invert = function(coordinates) {
3281
- return alaskaInvert(coordinates) || hawaiiInvert(coordinates) || puertoRicoInvert(coordinates) || lower48.invert(coordinates);
3381
+ var k = lower48.scale(), t = lower48.translate(), x = (coordinates[0] - t[0]) / k, y = (coordinates[1] - t[1]) / k;
3382
+ return (y >= .12 && y < .234 && x >= -.425 && x < -.214 ? alaska : y >= .166 && y < .234 && x >= -.214 && x < -.115 ? hawaii : lower48).invert(coordinates);
3282
3383
  };
3283
- albersUsa.scale = function(x) {
3384
+ albersUsa.stream = function(stream) {
3385
+ var lower48Stream = lower48.stream(stream), alaskaStream = alaska.stream(stream), hawaiiStream = hawaii.stream(stream);
3386
+ return {
3387
+ point: function(x, y) {
3388
+ lower48Stream.point(x, y);
3389
+ alaskaStream.point(x, y);
3390
+ hawaiiStream.point(x, y);
3391
+ },
3392
+ sphere: function() {
3393
+ lower48Stream.sphere();
3394
+ alaskaStream.sphere();
3395
+ hawaiiStream.sphere();
3396
+ },
3397
+ lineStart: function() {
3398
+ lower48Stream.lineStart();
3399
+ alaskaStream.lineStart();
3400
+ hawaiiStream.lineStart();
3401
+ },
3402
+ lineEnd: function() {
3403
+ lower48Stream.lineEnd();
3404
+ alaskaStream.lineEnd();
3405
+ hawaiiStream.lineEnd();
3406
+ },
3407
+ polygonStart: function() {
3408
+ lower48Stream.polygonStart();
3409
+ alaskaStream.polygonStart();
3410
+ hawaiiStream.polygonStart();
3411
+ },
3412
+ polygonEnd: function() {
3413
+ lower48Stream.polygonEnd();
3414
+ alaskaStream.polygonEnd();
3415
+ hawaiiStream.polygonEnd();
3416
+ }
3417
+ };
3418
+ };
3419
+ albersUsa.precision = function(_) {
3420
+ if (!arguments.length) return lower48.precision();
3421
+ lower48.precision(_);
3422
+ alaska.precision(_);
3423
+ hawaii.precision(_);
3424
+ return albersUsa;
3425
+ };
3426
+ albersUsa.scale = function(_) {
3284
3427
  if (!arguments.length) return lower48.scale();
3285
- lower48.scale(x);
3286
- alaska.scale(x * .6);
3287
- hawaii.scale(x);
3288
- puertoRico.scale(x * 1.5);
3428
+ lower48.scale(_);
3429
+ alaska.scale(_ * .35);
3430
+ hawaii.scale(_);
3289
3431
  return albersUsa.translate(lower48.translate());
3290
3432
  };
3291
- albersUsa.translate = function(x) {
3433
+ albersUsa.translate = function(_) {
3292
3434
  if (!arguments.length) return lower48.translate();
3293
- var dz = lower48.scale(), dx = x[0], dy = x[1];
3294
- lower48.translate(x);
3295
- alaska.translate([ dx - .4 * dz, dy + .17 * dz ]);
3296
- hawaii.translate([ dx - .19 * dz, dy + .2 * dz ]);
3297
- puertoRico.translate([ dx + .58 * dz, dy + .43 * dz ]);
3298
- alaskaInvert = d3_geo_albersUsaInvert(alaska, [ [ -180, 50 ], [ -130, 72 ] ]);
3299
- hawaiiInvert = d3_geo_albersUsaInvert(hawaii, [ [ -164, 18 ], [ -154, 24 ] ]);
3300
- puertoRicoInvert = d3_geo_albersUsaInvert(puertoRico, [ [ -67.5, 17.5 ], [ -65, 19 ] ]);
3435
+ var k = lower48.scale(), x = +_[0], y = +_[1];
3436
+ lower48Point = lower48.translate(_).clipExtent([ [ x - .455 * k, y - .238 * k ], [ x + .455 * k, y + .238 * k ] ]).stream(pointStream).point;
3437
+ alaskaPoint = alaska.translate([ x - .307 * k, y + .201 * k ]).clipExtent([ [ x - .425 * k + ε, y + .12 * k + ε ], [ x - .214 * k - ε, y + .234 * k - ε ] ]).stream(pointStream).point;
3438
+ hawaiiPoint = hawaii.translate([ x - .205 * k, y + .212 * k ]).clipExtent([ [ x - .214 * k + ε, y + .166 * k + ε ], [ x - .115 * k - ε, y + .234 * k - ε ] ]).stream(pointStream).point;
3301
3439
  return albersUsa;
3302
3440
  };
3303
- return albersUsa.scale(1e3);
3441
+ return albersUsa.scale(1070);
3304
3442
  };
3305
- function d3_geo_albersUsaInvert(projection, extent) {
3306
- var a = projection(extent[0]), b = projection([ .5 * (extent[0][0] + extent[1][0]), extent[0][1] ]), c = projection([ extent[1][0], extent[0][1] ]), d = projection(extent[1]);
3307
- var dya = b[1] - a[1], dxa = b[0] - a[0], dyb = c[1] - b[1], dxb = c[0] - b[0];
3308
- var ma = dya / dxa, mb = dyb / dxb;
3309
- var cx = .5 * (ma * mb * (a[1] - c[1]) + mb * (a[0] + b[0]) - ma * (b[0] + c[0])) / (mb - ma), cy = (.5 * (a[0] + b[0]) - cx) / ma + .5 * (a[1] + b[1]);
3310
- var dx0 = d[0] - cx, dy0 = d[1] - cy, dx1 = a[0] - cx, dy1 = a[1] - cy, r0 = dx0 * dx0 + dy0 * dy0, r1 = dx1 * dx1 + dy1 * dy1;
3311
- var a0 = Math.atan2(dy0, dx0), a1 = Math.atan2(dy1, dx1);
3312
- return function(coordinates) {
3313
- var dx = coordinates[0] - cx, dy = coordinates[1] - cy, r = dx * dx + dy * dy, a = Math.atan2(dy, dx);
3314
- if (r0 < r && r < r1 && a0 < a && a < a1) return projection.invert(coordinates);
3315
- };
3316
- }
3317
3443
  var d3_geo_pathAreaSum, d3_geo_pathAreaPolygon, d3_geo_pathArea = {
3318
3444
  point: d3_noop,
3319
3445
  lineStart: d3_noop,
@@ -3341,8 +3467,22 @@ d3 = function() {
3341
3467
  nextPoint(x00, y00);
3342
3468
  };
3343
3469
  }
3470
+ var d3_geo_pathBoundsX0, d3_geo_pathBoundsY0, d3_geo_pathBoundsX1, d3_geo_pathBoundsY1;
3471
+ var d3_geo_pathBounds = {
3472
+ point: d3_geo_pathBoundsPoint,
3473
+ lineStart: d3_noop,
3474
+ lineEnd: d3_noop,
3475
+ polygonStart: d3_noop,
3476
+ polygonEnd: d3_noop
3477
+ };
3478
+ function d3_geo_pathBoundsPoint(x, y) {
3479
+ if (x < d3_geo_pathBoundsX0) d3_geo_pathBoundsX0 = x;
3480
+ if (x > d3_geo_pathBoundsX1) d3_geo_pathBoundsX1 = x;
3481
+ if (y < d3_geo_pathBoundsY0) d3_geo_pathBoundsY0 = y;
3482
+ if (y > d3_geo_pathBoundsY1) d3_geo_pathBoundsY1 = y;
3483
+ }
3344
3484
  function d3_geo_pathBuffer() {
3345
- var pointCircle = d3_geo_pathCircle(4.5), buffer = [];
3485
+ var pointCircle = d3_geo_pathBufferCircle(4.5), buffer = [];
3346
3486
  var stream = {
3347
3487
  point: point,
3348
3488
  lineStart: function() {
@@ -3357,7 +3497,7 @@ d3 = function() {
3357
3497
  stream.point = point;
3358
3498
  },
3359
3499
  pointRadius: function(_) {
3360
- pointCircle = d3_geo_pathCircle(_);
3500
+ pointCircle = d3_geo_pathBufferCircle(_);
3361
3501
  return stream;
3362
3502
  },
3363
3503
  result: function() {
@@ -3386,6 +3526,9 @@ d3 = function() {
3386
3526
  }
3387
3527
  return stream;
3388
3528
  }
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
+ }
3389
3532
  var d3_geo_pathCentroid = {
3390
3533
  point: d3_geo_pathCentroidPoint,
3391
3534
  lineStart: d3_geo_pathCentroidLineStart,
@@ -3506,7 +3649,9 @@ d3 = function() {
3506
3649
  return d3_geo_centroidZ ? [ d3_geo_centroidX / d3_geo_centroidZ, d3_geo_centroidY / d3_geo_centroidZ ] : undefined;
3507
3650
  };
3508
3651
  path.bounds = function(object) {
3509
- return d3_geo_bounds(projectStream)(object);
3652
+ d3_geo_pathBoundsX1 = d3_geo_pathBoundsY1 = -(d3_geo_pathBoundsX0 = d3_geo_pathBoundsY0 = Infinity);
3653
+ d3.geo.stream(object, projectStream(d3_geo_pathBounds));
3654
+ return [ [ d3_geo_pathBoundsX0, d3_geo_pathBoundsY0 ], [ d3_geo_pathBoundsX1, d3_geo_pathBoundsY1 ] ];
3510
3655
  };
3511
3656
  path.projection = function(_) {
3512
3657
  if (!arguments.length) return projection;
@@ -3525,9 +3670,6 @@ d3 = function() {
3525
3670
  };
3526
3671
  return path.projection(d3.geo.albersUsa()).context(null);
3527
3672
  };
3528
- function d3_geo_pathCircle(radius) {
3529
- return "m0," + radius + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius + "a" + radius + "," + radius + " 0 1,1 0," + +2 * radius + "z";
3530
- }
3531
3673
  function d3_geo_pathProjectStream(project) {
3532
3674
  var resample = d3_geo_resample(function(λ, φ) {
3533
3675
  return project([ λ * d3_degrees, φ * d3_degrees ]);
@@ -3556,9 +3698,6 @@ d3 = function() {
3556
3698
  };
3557
3699
  };
3558
3700
  }
3559
- d3.geo.albers = function() {
3560
- return d3.geo.conicEqualArea().parallels([ 29.5, 45.5 ]).rotate([ 98, 0 ]).center([ 0, 38 ]).scale(1e3);
3561
- };
3562
3701
  function d3_geo_azimuthal(scale, angle) {
3563
3702
  function azimuthal(λ, φ) {
3564
3703
  var cosλ = Math.cos(λ), cosφ = Math.cos(φ), k = scale(cosλ * cosφ);
@@ -4633,8 +4772,10 @@ d3 = function() {
4633
4772
  d3.transform = function(string) {
4634
4773
  var g = d3_document.createElementNS(d3.ns.prefix.svg, "g");
4635
4774
  return (d3.transform = function(string) {
4636
- g.setAttribute("transform", string);
4637
- var t = g.transform.baseVal.consolidate();
4775
+ if (string != null) {
4776
+ g.setAttribute("transform", string);
4777
+ var t = g.transform.baseVal.consolidate();
4778
+ }
4638
4779
  return new d3_transform(t ? t.matrix : d3_transformIdentity);
4639
4780
  })(string);
4640
4781
  };
@@ -4813,7 +4954,9 @@ d3 = function() {
4813
4954
  n--;
4814
4955
  }
4815
4956
  if (s.length === 1) {
4816
- return s[0] == null ? q[0].x : function() {
4957
+ return s[0] == null ? (o = q[0].x, function(t) {
4958
+ return o(t) + "";
4959
+ }) : function() {
4817
4960
  return b;
4818
4961
  };
4819
4962
  }
@@ -4834,7 +4977,7 @@ d3 = function() {
4834
4977
  }
4835
4978
  d3.interpolators = [ function(a, b) {
4836
4979
  var t = typeof b;
4837
- return (t === "string" || t !== typeof a ? d3_rgb_names.has(b) || /^(#|rgb\(|hsl\()/.test(b) ? d3_interpolateRgb : d3_interpolateString : b instanceof d3_Color ? d3_interpolateRgb : t === "object" ? Array.isArray(b) ? d3_interpolateArray : d3_interpolateObject : d3_interpolateNumber)(a, b);
4980
+ return (t === "string" ? d3_rgb_names.has(b) || /^(#|rgb\(|hsl\()/.test(b) ? d3_interpolateRgb : d3_interpolateString : b instanceof d3_Color ? d3_interpolateRgb : t === "object" ? Array.isArray(b) ? d3_interpolateArray : d3_interpolateObject : d3_interpolateNumber)(a, b);
4838
4981
  } ];
4839
4982
  d3.interpolateArray = d3_interpolateArray;
4840
4983
  function d3_interpolateArray(a, b) {
@@ -6476,9 +6619,9 @@ d3 = function() {
6476
6619
  }) : ",." + precision + "f");
6477
6620
  }
6478
6621
  d3.scale.log = function() {
6479
- return d3_scale_log(d3.scale.linear().domain([ 0, Math.LN10 ]), 10, d3_scale_logp, d3_scale_powp);
6622
+ return d3_scale_log(d3.scale.linear().domain([ 0, Math.LN10 ]), 10, d3_scale_logp, d3_scale_powp, [ 1, 10 ]);
6480
6623
  };
6481
- function d3_scale_log(linear, base, log, pow) {
6624
+ function d3_scale_log(linear, base, log, pow, domain) {
6482
6625
  function scale(x) {
6483
6626
  return linear(log(x));
6484
6627
  }
@@ -6486,10 +6629,10 @@ d3 = function() {
6486
6629
  return pow(linear.invert(x));
6487
6630
  };
6488
6631
  scale.domain = function(x) {
6489
- if (!arguments.length) return linear.domain().map(pow);
6632
+ if (!arguments.length) return domain;
6490
6633
  if (x[0] < 0) log = d3_scale_logn, pow = d3_scale_pown; else log = d3_scale_logp,
6491
6634
  pow = d3_scale_powp;
6492
- linear.domain(x.map(log));
6635
+ linear.domain((domain = x.map(Number)).map(log));
6493
6636
  return scale;
6494
6637
  };
6495
6638
  scale.base = function(_) {
@@ -6498,7 +6641,7 @@ d3 = function() {
6498
6641
  return scale;
6499
6642
  };
6500
6643
  scale.nice = function() {
6501
- linear.domain(d3_scale_nice(linear.domain(), d3_scale_logNice(base)));
6644
+ linear.domain(d3_scale_nice(domain, nice).map(log));
6502
6645
  return scale;
6503
6646
  };
6504
6647
  scale.ticks = function() {
@@ -6528,8 +6671,27 @@ d3 = function() {
6528
6671
  };
6529
6672
  };
6530
6673
  scale.copy = function() {
6531
- return d3_scale_log(linear.copy(), base, log, pow);
6532
- };
6674
+ return d3_scale_log(linear.copy(), base, log, pow, domain);
6675
+ };
6676
+ function nice() {
6677
+ return log === d3_scale_logp ? {
6678
+ floor: floor,
6679
+ ceil: ceil
6680
+ } : {
6681
+ floor: function(x) {
6682
+ return -ceil(-x);
6683
+ },
6684
+ ceil: function(x) {
6685
+ return -floor(-x);
6686
+ }
6687
+ };
6688
+ }
6689
+ function floor(x) {
6690
+ return Math.pow(base, Math.floor(Math.log(x) / Math.log(base)));
6691
+ }
6692
+ function ceil(x) {
6693
+ return Math.pow(base, Math.ceil(Math.log(x) / Math.log(base)));
6694
+ }
6533
6695
  return d3_scale_linearRebind(scale, linear);
6534
6696
  }
6535
6697
  var d3_scale_logFormat = d3.format(".0e");
@@ -6545,24 +6707,10 @@ d3 = function() {
6545
6707
  function d3_scale_pown(x) {
6546
6708
  return -Math.exp(-x);
6547
6709
  }
6548
- function d3_scale_logNice(base) {
6549
- base = Math.log(base);
6550
- var nice = {
6551
- floor: function(x) {
6552
- return Math.floor(x / base) * base;
6553
- },
6554
- ceil: function(x) {
6555
- return Math.ceil(x / base) * base;
6556
- }
6557
- };
6558
- return function() {
6559
- return nice;
6560
- };
6561
- }
6562
6710
  d3.scale.pow = function() {
6563
- return d3_scale_pow(d3.scale.linear(), 1);
6711
+ return d3_scale_pow(d3.scale.linear(), 1, [ 0, 1 ]);
6564
6712
  };
6565
- function d3_scale_pow(linear, exponent) {
6713
+ function d3_scale_pow(linear, exponent, domain) {
6566
6714
  var powp = d3_scale_powPow(exponent), powb = d3_scale_powPow(1 / exponent);
6567
6715
  function scale(x) {
6568
6716
  return linear(powp(x));
@@ -6571,28 +6719,28 @@ d3 = function() {
6571
6719
  return powb(linear.invert(x));
6572
6720
  };
6573
6721
  scale.domain = function(x) {
6574
- if (!arguments.length) return linear.domain().map(powb);
6575
- linear.domain(x.map(powp));
6722
+ if (!arguments.length) return domain;
6723
+ linear.domain((domain = x.map(Number)).map(powp));
6576
6724
  return scale;
6577
6725
  };
6578
6726
  scale.ticks = function(m) {
6579
- return d3_scale_linearTicks(scale.domain(), m);
6727
+ return d3_scale_linearTicks(domain, m);
6580
6728
  };
6581
6729
  scale.tickFormat = function(m, format) {
6582
- return d3_scale_linearTickFormat(scale.domain(), m, format);
6730
+ return d3_scale_linearTickFormat(domain, m, format);
6583
6731
  };
6584
6732
  scale.nice = function() {
6585
- return scale.domain(d3_scale_nice(scale.domain(), d3_scale_linearNice));
6733
+ return scale.domain(d3_scale_nice(domain, d3_scale_linearNice));
6586
6734
  };
6587
6735
  scale.exponent = function(x) {
6588
6736
  if (!arguments.length) return exponent;
6589
- var domain = scale.domain();
6590
6737
  powp = d3_scale_powPow(exponent = x);
6591
6738
  powb = d3_scale_powPow(1 / exponent);
6592
- return scale.domain(domain);
6739
+ linear.domain(domain.map(powp));
6740
+ return scale;
6593
6741
  };
6594
6742
  scale.copy = function() {
6595
- return d3_scale_pow(linear.copy(), exponent);
6743
+ return d3_scale_pow(linear.copy(), exponent, domain);
6596
6744
  };
6597
6745
  return d3_scale_linearRebind(scale, linear);
6598
6746
  }