d3-rails 3.3.6 → 3.3.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 283868840a9eb84574c433d39690ad8085113e64
4
+ data.tar.gz: bce54a9f1d4be4406cf54aae4727ede1e6ab7301
5
+ SHA512:
6
+ metadata.gz: 03446d88adb4f4c25eb649ba647ea4728ed63d35d4fdb07a5e64d214865d370ace6a241cb4a768d345a138498c09e4ef2051a357ba61791fd5c0a8cd68038680
7
+ data.tar.gz: 489da15673b8098400925ec07ee19f3db600ba632e8a55afb51d887e9d9ba16cf7d1addec16fb569f6327d611ce2db4daf7fa8f946aadbc4fd163e6ee4608ca3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 3.3.7 (11 October 2013)
2
+
3
+ * Upgrade D3 to 3.3.7
4
+
1
5
  ## 3.3.6 (29 September 2013)
2
6
 
3
7
  * Upgrade D3 to 3.3.6
data/README.md CHANGED
@@ -6,7 +6,7 @@ d3-rails provides D3 for Rails 3.1 and higher.
6
6
 
7
7
  ## Version
8
8
 
9
- d3-rails comes with version 3.3.6 of D3.js. and will track the always
9
+ d3-rails comes with version 3.3.7 of D3.js. and will track the always
10
10
  mirror the version of D3 it comes with.
11
11
 
12
12
 
@@ -1,6 +1,6 @@
1
1
  d3 = function() {
2
2
  var d3 = {
3
- version: "3.3.6"
3
+ version: "3.3.7"
4
4
  };
5
5
  if (!Date.now) Date.now = function() {
6
6
  return +new Date();
@@ -186,8 +186,19 @@ d3 = function() {
186
186
  return entries;
187
187
  };
188
188
  d3.merge = function(arrays) {
189
- return Array.prototype.concat.apply([], arrays);
189
+ var n = arrays.length, m, i = -1, j = 0, merged, array;
190
+ while (++i < n) j += arrays[i].length;
191
+ merged = new Array(j);
192
+ while (--n >= 0) {
193
+ array = arrays[n];
194
+ m = array.length;
195
+ while (--m >= 0) {
196
+ merged[--j] = array[m];
197
+ }
198
+ }
199
+ return merged;
190
200
  };
201
+ var abs = Math.abs;
191
202
  d3.range = function(start, stop, step) {
192
203
  if (arguments.length < 3) {
193
204
  step = 1;
@@ -197,7 +208,7 @@ d3 = function() {
197
208
  }
198
209
  }
199
210
  if ((stop - start) / step === Infinity) throw new Error("infinite range");
200
- var range = [], k = d3_range_integerScale(Math.abs(step)), i = -1, j;
211
+ var range = [], k = d3_range_integerScale(abs(step)), i = -1, j;
201
212
  start *= k, stop *= k, step *= k;
202
213
  if (step < 0) while ((j = start + step * ++i) > stop) range.push(j / k); else while ((j = start + step * ++i) < stop) range.push(j / k);
203
214
  return range;
@@ -714,16 +725,16 @@ d3 = function() {
714
725
  };
715
726
  function d3_selection_creator(name) {
716
727
  return typeof name === "function" ? name : (name = d3.ns.qualify(name)).local ? function() {
717
- return d3_document.createElementNS(name.space, name.local);
728
+ return this.ownerDocument.createElementNS(name.space, name.local);
718
729
  } : function() {
719
- return d3_document.createElementNS(this.namespaceURI, name);
730
+ return this.ownerDocument.createElementNS(this.namespaceURI, name);
720
731
  };
721
732
  }
722
733
  d3_selectionPrototype.insert = function(name, before) {
723
734
  name = d3_selection_creator(name);
724
735
  before = d3_selection_selector(before);
725
736
  return this.select(function() {
726
- return this.insertBefore(name.apply(this, arguments), before.apply(this, arguments));
737
+ return this.insertBefore(name.apply(this, arguments), before.apply(this, arguments) || null);
727
738
  });
728
739
  };
729
740
  d3_selectionPrototype.remove = function() {
@@ -2031,11 +2042,12 @@ d3 = function() {
2031
2042
  if (n < 2) delay = 0;
2032
2043
  if (n < 3) then = Date.now();
2033
2044
  var time = then + delay, timer = {
2034
- callback: callback,
2035
- time: time,
2036
- next: null
2045
+ c: callback,
2046
+ t: time,
2047
+ f: false,
2048
+ n: null
2037
2049
  };
2038
- if (d3_timer_queueTail) d3_timer_queueTail.next = timer; else d3_timer_queueHead = timer;
2050
+ if (d3_timer_queueTail) d3_timer_queueTail.n = timer; else d3_timer_queueHead = timer;
2039
2051
  d3_timer_queueTail = timer;
2040
2052
  if (!d3_timer_interval) {
2041
2053
  d3_timer_timeout = clearTimeout(d3_timer_timeout);
@@ -2060,30 +2072,23 @@ d3 = function() {
2060
2072
  d3_timer_mark();
2061
2073
  d3_timer_sweep();
2062
2074
  };
2063
- function d3_timer_replace(callback, delay, then) {
2064
- var n = arguments.length;
2065
- if (n < 2) delay = 0;
2066
- if (n < 3) then = Date.now();
2067
- d3_timer_active.callback = callback;
2068
- d3_timer_active.time = then + delay;
2069
- }
2070
2075
  function d3_timer_mark() {
2071
2076
  var now = Date.now();
2072
2077
  d3_timer_active = d3_timer_queueHead;
2073
2078
  while (d3_timer_active) {
2074
- if (now >= d3_timer_active.time) d3_timer_active.flush = d3_timer_active.callback(now - d3_timer_active.time);
2075
- d3_timer_active = d3_timer_active.next;
2079
+ if (now >= d3_timer_active.t) d3_timer_active.f = d3_timer_active.c(now - d3_timer_active.t);
2080
+ d3_timer_active = d3_timer_active.n;
2076
2081
  }
2077
2082
  return now;
2078
2083
  }
2079
2084
  function d3_timer_sweep() {
2080
2085
  var t0, t1 = d3_timer_queueHead, time = Infinity;
2081
2086
  while (t1) {
2082
- if (t1.flush) {
2083
- t1 = t0 ? t0.next = t1.next : d3_timer_queueHead = t1.next;
2087
+ if (t1.f) {
2088
+ t1 = t0 ? t0.n = t1.n : d3_timer_queueHead = t1.n;
2084
2089
  } else {
2085
- if (t1.time < time) time = t1.time;
2086
- t1 = (t0 = t1).next;
2090
+ if (t1.t < time) time = t1.t;
2091
+ t1 = (t0 = t1).n;
2087
2092
  }
2088
2093
  }
2089
2094
  d3_timer_queueTail = t0;
@@ -2102,7 +2107,7 @@ d3 = function() {
2102
2107
  return d3_formatPrefixes[8 + i / 3];
2103
2108
  };
2104
2109
  function d3_formatPrefix(d, i) {
2105
- var k = Math.pow(10, Math.abs(8 - i) * 3);
2110
+ var k = Math.pow(10, abs(8 - i) * 3);
2106
2111
  return {
2107
2112
  scale: i > 8 ? function(d) {
2108
2113
  return d / k;
@@ -2388,7 +2393,7 @@ d3 = function() {
2388
2393
  return [ Math.atan2(cartesian[1], cartesian[0]), d3_asin(cartesian[2]) ];
2389
2394
  }
2390
2395
  function d3_geo_sphericalEqual(a, b) {
2391
- return Math.abs(a[0] - b[0]) < ε && Math.abs(a[1] - b[1]) < ε;
2396
+ return abs(a[0] - b[0]) < ε && abs(a[1] - b[1]) < ε;
2392
2397
  }
2393
2398
  d3.geo.bounds = function() {
2394
2399
  var λ0, φ0, λ1, φ1, λ_, λ__, φ__, p0, dλSum, ranges, range;
@@ -2423,7 +2428,7 @@ d3 = function() {
2423
2428
  var normal = d3_geo_cartesianCross(p0, p), equatorial = [ normal[1], -normal[0], 0 ], inflection = d3_geo_cartesianCross(equatorial, normal);
2424
2429
  d3_geo_cartesianNormalize(inflection);
2425
2430
  inflection = d3_geo_spherical(inflection);
2426
- var dλ = λ - λ_, s = dλ > 0 ? 1 : -1, λi = inflection[0] * d3_degrees * s, antimeridian = Math.abs(dλ) > 180;
2431
+ var dλ = λ - λ_, s = dλ > 0 ? 1 : -1, λi = inflection[0] * d3_degrees * s, antimeridian = abs(dλ) > 180;
2427
2432
  if (antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
2428
2433
  var φi = inflection[1] * d3_degrees;
2429
2434
  if (φi > φ1) φ1 = φi;
@@ -2468,7 +2473,7 @@ d3 = function() {
2468
2473
  function ringPoint(λ, φ) {
2469
2474
  if (p0) {
2470
2475
  var dλ = λ - λ_;
2471
- dλSum += Math.abs(dλ) > 180 ? dλ + (dλ > 0 ? 360 : -360) : dλ;
2476
+ dλSum += abs(dλ) > 180 ? dλ + (dλ > 0 ? 360 : -360) : dλ;
2472
2477
  } else λ__ = λ, φ__ = φ;
2473
2478
  d3_geo_area.point(λ, φ);
2474
2479
  linePoint(λ, φ);
@@ -2479,7 +2484,7 @@ d3 = function() {
2479
2484
  function ringEnd() {
2480
2485
  ringPoint(λ__, φ__);
2481
2486
  d3_geo_area.lineEnd();
2482
- if (Math.abs(dλSum) > ε) λ0 = -(λ1 = 180);
2487
+ if (abs(dλSum) > ε) λ0 = -(λ1 = 180);
2483
2488
  range[0] = λ0, range[1] = λ1;
2484
2489
  p0 = null;
2485
2490
  }
@@ -2622,41 +2627,13 @@ d3 = function() {
2622
2627
  listener.lineEnd();
2623
2628
  return;
2624
2629
  }
2625
- var a = {
2626
- point: p0,
2627
- points: segment,
2628
- other: null,
2629
- visited: false,
2630
- entry: true,
2631
- subject: true
2632
- }, b = {
2633
- point: p0,
2634
- points: [ p0 ],
2635
- other: a,
2636
- visited: false,
2637
- entry: false,
2638
- subject: false
2639
- };
2640
- a.other = b;
2630
+ var a = new d3_geo_clipPolygonIntersection(p0, segment, null, true), b = new d3_geo_clipPolygonIntersection(p0, null, a, false);
2631
+ a.o = b;
2641
2632
  subject.push(a);
2642
2633
  clip.push(b);
2643
- a = {
2644
- point: p1,
2645
- points: [ p1 ],
2646
- other: null,
2647
- visited: false,
2648
- entry: false,
2649
- subject: true
2650
- };
2651
- b = {
2652
- point: p1,
2653
- points: [ p1 ],
2654
- other: a,
2655
- visited: false,
2656
- entry: true,
2657
- subject: false
2658
- };
2659
- a.other = b;
2634
+ a = new d3_geo_clipPolygonIntersection(p1, segment, null, false);
2635
+ b = new d3_geo_clipPolygonIntersection(p1, null, a, true);
2636
+ a.o = b;
2660
2637
  subject.push(a);
2661
2638
  clip.push(b);
2662
2639
  });
@@ -2665,35 +2642,36 @@ d3 = function() {
2665
2642
  d3_geo_clipPolygonLinkCircular(clip);
2666
2643
  if (!subject.length) return;
2667
2644
  for (var i = 0, entry = clipStartInside, n = clip.length; i < n; ++i) {
2668
- clip[i].entry = entry = !entry;
2645
+ clip[i].e = entry = !entry;
2669
2646
  }
2670
- var start = subject[0], current, points, point;
2647
+ var start = subject[0], points, point;
2671
2648
  while (1) {
2672
- current = start;
2673
- while (current.visited) if ((current = current.next) === start) return;
2674
- points = current.points;
2649
+ var current = start, isSubject = true;
2650
+ while (current.v) if ((current = current.n) === start) return;
2651
+ points = current.z;
2675
2652
  listener.lineStart();
2676
2653
  do {
2677
- current.visited = current.other.visited = true;
2678
- if (current.entry) {
2679
- if (current.subject) {
2680
- for (var i = 0; i < points.length; i++) listener.point((point = points[i])[0], point[1]);
2654
+ current.v = current.o.v = true;
2655
+ if (current.e) {
2656
+ if (isSubject) {
2657
+ for (var i = 0, n = points.length; i < n; ++i) listener.point((point = points[i])[0], point[1]);
2681
2658
  } else {
2682
- interpolate(current.point, current.next.point, 1, listener);
2659
+ interpolate(current.x, current.n.x, 1, listener);
2683
2660
  }
2684
- current = current.next;
2661
+ current = current.n;
2685
2662
  } else {
2686
- if (current.subject) {
2687
- points = current.prev.points;
2688
- for (var i = points.length; --i >= 0; ) listener.point((point = points[i])[0], point[1]);
2663
+ if (isSubject) {
2664
+ points = current.p.z;
2665
+ for (var i = points.length - 1; i >= 0; --i) listener.point((point = points[i])[0], point[1]);
2689
2666
  } else {
2690
- interpolate(current.point, current.prev.point, -1, listener);
2667
+ interpolate(current.x, current.p.x, -1, listener);
2691
2668
  }
2692
- current = current.prev;
2669
+ current = current.p;
2693
2670
  }
2694
- current = current.other;
2695
- points = current.points;
2696
- } while (!current.visited);
2671
+ current = current.o;
2672
+ points = current.z;
2673
+ isSubject = !isSubject;
2674
+ } while (!current.v);
2697
2675
  listener.lineEnd();
2698
2676
  }
2699
2677
  }
@@ -2701,12 +2679,20 @@ d3 = function() {
2701
2679
  if (!(n = array.length)) return;
2702
2680
  var n, i = 0, a = array[0], b;
2703
2681
  while (++i < n) {
2704
- a.next = b = array[i];
2705
- b.prev = a;
2682
+ a.n = b = array[i];
2683
+ b.p = a;
2706
2684
  a = b;
2707
2685
  }
2708
- a.next = b = array[0];
2709
- b.prev = a;
2686
+ a.n = b = array[0];
2687
+ b.p = a;
2688
+ }
2689
+ function d3_geo_clipPolygonIntersection(point, points, other, entry) {
2690
+ this.x = point;
2691
+ this.z = points;
2692
+ this.o = other;
2693
+ this.e = entry;
2694
+ this.v = false;
2695
+ this.n = this.p = null;
2710
2696
  }
2711
2697
  function d3_geo_clip(pointVisible, clipLine, interpolate, clipStart) {
2712
2698
  return function(rotate, listener) {
@@ -2821,7 +2807,7 @@ d3 = function() {
2821
2807
  };
2822
2808
  }
2823
2809
  function d3_geo_clipSort(a, b) {
2824
- return ((a = a.point)[0] < 0 ? a[1] - halfπ - ε : halfπ - a[1]) - ((b = b.point)[0] < 0 ? b[1] - halfπ - ε : halfπ - b[1]);
2810
+ return ((a = a.x)[0] < 0 ? a[1] - halfπ - ε : halfπ - a[1]) - ((b = b.x)[0] < 0 ? b[1] - halfπ - ε : halfπ - b[1]);
2825
2811
  }
2826
2812
  function d3_geo_pointInPolygon(point, polygon) {
2827
2813
  var meridian = point[0], parallel = point[1], meridianNormal = [ Math.sin(meridian), -Math.cos(meridian), 0 ], polarAngle = 0, winding = 0;
@@ -2833,9 +2819,9 @@ d3 = function() {
2833
2819
  while (true) {
2834
2820
  if (j === m) j = 0;
2835
2821
  point = ring[j];
2836
- var λ = point[0], φ = point[1] / 2 + π / 4, sinφ = Math.sin(φ), cosφ = Math.cos(φ), dλ = λ - λ0, antimeridian = Math.abs(dλ) > π, k = sinφ0 * sinφ;
2822
+ var λ = point[0], φ = point[1] / 2 + π / 4, sinφ = Math.sin(φ), cosφ = Math.cos(φ), dλ = λ - λ0, antimeridian = abs(dλ) > π, k = sinφ0 * sinφ;
2837
2823
  d3_geo_areaRingSum.add(Math.atan2(k * Math.sin(dλ), cosφ0 * cosφ + k * Math.cos(dλ)));
2838
- polarAngle += antimeridian ? dλ + (dλ >= 0 ? 2 : -2) * π : dλ;
2824
+ polarAngle += antimeridian ? dλ + (dλ >= 0 ? τ : ) : dλ;
2839
2825
  if (antimeridian ^ λ0 >= meridian ^ λ >= meridian) {
2840
2826
  var arc = d3_geo_cartesianCross(d3_geo_cartesian(point0), d3_geo_cartesian(point));
2841
2827
  d3_geo_cartesianNormalize(arc);
@@ -2861,8 +2847,8 @@ d3 = function() {
2861
2847
  clean = 1;
2862
2848
  },
2863
2849
  point: function(λ1, φ1) {
2864
- var sλ1 = λ1 > 0 ? π : -π, dλ = Math.abs(λ1 - λ0);
2865
- if (Math.abs(dλ - π) < ε) {
2850
+ var sλ1 = λ1 > 0 ? π : -π, dλ = abs(λ1 - λ0);
2851
+ if (abs(dλ - π) < ε) {
2866
2852
  listener.point(λ0, φ0 = (φ0 + φ1) / 2 > 0 ? halfπ : -halfπ);
2867
2853
  listener.point(sλ0, φ0);
2868
2854
  listener.lineEnd();
@@ -2871,8 +2857,8 @@ d3 = function() {
2871
2857
  listener.point(λ1, φ0);
2872
2858
  clean = 0;
2873
2859
  } else if (sλ0 !== sλ1 && dλ >= π) {
2874
- if (Math.abs(λ0 - sλ0) < ε) λ0 -= sλ0 * ε;
2875
- if (Math.abs(λ1 - sλ1) < ε) λ1 -= sλ1 * ε;
2860
+ if (abs(λ0 - sλ0) < ε) λ0 -= sλ0 * ε;
2861
+ if (abs(λ1 - sλ1) < ε) λ1 -= sλ1 * ε;
2876
2862
  φ0 = d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1);
2877
2863
  listener.point(sλ0, φ0);
2878
2864
  listener.lineEnd();
@@ -2894,7 +2880,7 @@ d3 = function() {
2894
2880
  }
2895
2881
  function d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1) {
2896
2882
  var cosφ0, cosφ1, sinλ0_λ1 = Math.sin(λ0 - λ1);
2897
- return Math.abs(sinλ0_λ1) > ε ? Math.atan((Math.sin(φ0) * (cosφ1 = Math.cos(φ1)) * Math.sin(λ1) - Math.sin(φ1) * (cosφ0 = Math.cos(φ0)) * Math.sin(λ0)) / (cosφ0 * cosφ1 * sinλ0_λ1)) : (φ0 + φ1) / 2;
2883
+ return abs(sinλ0_λ1) > ε ? Math.atan((Math.sin(φ0) * (cosφ1 = Math.cos(φ1)) * Math.sin(λ1) - Math.sin(φ1) * (cosφ0 = Math.cos(φ0)) * Math.sin(λ0)) / (cosφ0 * cosφ1 * sinλ0_λ1)) : (φ0 + φ1) / 2;
2898
2884
  }
2899
2885
  function d3_geo_clipAntimeridianInterpolate(from, to, direction, listener) {
2900
2886
  var φ;
@@ -2909,8 +2895,8 @@ d3 = function() {
2909
2895
  listener.point(-π, -φ);
2910
2896
  listener.point(-π, 0);
2911
2897
  listener.point(-π, φ);
2912
- } else if (Math.abs(from[0] - to[0]) > ε) {
2913
- var s = (from[0] < to[0] ? 1 : -1) * π;
2898
+ } else if (abs(from[0] - to[0]) > ε) {
2899
+ var s = from[0] < to[0] ? π : -π;
2914
2900
  φ = direction * s / 2;
2915
2901
  listener.point(-s, φ);
2916
2902
  listener.point(0, φ);
@@ -2920,7 +2906,7 @@ d3 = function() {
2920
2906
  }
2921
2907
  }
2922
2908
  function d3_geo_clipCircle(radius) {
2923
- var cr = Math.cos(radius), smallRadius = cr > 0, notHemisphere = Math.abs(cr) > ε, interpolate = d3_geo_circleInterpolate(radius, 6 * d3_radians);
2909
+ var cr = Math.cos(radius), smallRadius = cr > 0, notHemisphere = abs(cr) > ε, interpolate = d3_geo_circleInterpolate(radius, 6 * d3_radians);
2924
2910
  return d3_geo_clip(visible, clipLine, interpolate, smallRadius ? [ 0, -radius ] : [ -π, radius - π ]);
2925
2911
  function visible(λ, φ) {
2926
2912
  return Math.cos(λ) * Math.cos(φ) > cr;
@@ -3000,9 +2986,9 @@ d3 = function() {
3000
2986
  if (!two) return q;
3001
2987
  var λ0 = a[0], λ1 = b[0], φ0 = a[1], φ1 = b[1], z;
3002
2988
  if (λ1 < λ0) z = λ0, λ0 = λ1, λ1 = z;
3003
- var δλ = λ1 - λ0, polar = Math.abs(δλ - π) < ε, meridian = polar || δλ < ε;
2989
+ var δλ = λ1 - λ0, polar = abs(δλ - π) < ε, meridian = polar || δλ < ε;
3004
2990
  if (!polar && φ1 < φ0) z = φ0, φ0 = φ1, φ1 = z;
3005
- if (meridian ? polar ? φ0 + φ1 > 0 ^ q[1] < (Math.abs(q[0] - λ0) < ε ? φ0 : φ1) : φ0 <= q[1] && q[1] <= φ1 : δλ > π ^ (λ0 <= q[0] && q[0] <= λ1)) {
2991
+ if (meridian ? polar ? φ0 + φ1 > 0 ^ q[1] < (abs(q[0] - λ0) < ε ? φ0 : φ1) : φ0 <= q[1] && q[1] <= φ1 : δλ > π ^ (λ0 <= q[0] && q[0] <= λ1)) {
3006
2992
  var q1 = d3_geo_cartesianScale(u, (-w + t) / uu);
3007
2993
  d3_geo_cartesianAdd(q1, A);
3008
2994
  return [ q, d3_geo_spherical(q1) ];
@@ -3015,6 +3001,60 @@ d3 = function() {
3015
3001
  return code;
3016
3002
  }
3017
3003
  }
3004
+ function d3_geom_clipLine(x0, y0, x1, y1) {
3005
+ return function(line) {
3006
+ var a = line.a, b = line.b, ax = a.x, ay = a.y, bx = b.x, by = b.y, t0 = 0, t1 = 1, dx = bx - ax, dy = by - ay, r;
3007
+ r = x0 - ax;
3008
+ if (!dx && r > 0) return;
3009
+ r /= dx;
3010
+ if (dx < 0) {
3011
+ if (r < t0) return;
3012
+ if (r < t1) t1 = r;
3013
+ } else if (dx > 0) {
3014
+ if (r > t1) return;
3015
+ if (r > t0) t0 = r;
3016
+ }
3017
+ r = x1 - ax;
3018
+ if (!dx && r < 0) return;
3019
+ r /= dx;
3020
+ if (dx < 0) {
3021
+ if (r > t1) return;
3022
+ if (r > t0) t0 = r;
3023
+ } else if (dx > 0) {
3024
+ if (r < t0) return;
3025
+ if (r < t1) t1 = r;
3026
+ }
3027
+ r = y0 - ay;
3028
+ if (!dy && r > 0) return;
3029
+ r /= dy;
3030
+ if (dy < 0) {
3031
+ if (r < t0) return;
3032
+ if (r < t1) t1 = r;
3033
+ } else if (dy > 0) {
3034
+ if (r > t1) return;
3035
+ if (r > t0) t0 = r;
3036
+ }
3037
+ r = y1 - ay;
3038
+ if (!dy && r < 0) return;
3039
+ r /= dy;
3040
+ if (dy < 0) {
3041
+ if (r > t1) return;
3042
+ if (r > t0) t0 = r;
3043
+ } else if (dy > 0) {
3044
+ if (r < t0) return;
3045
+ if (r < t1) t1 = r;
3046
+ }
3047
+ if (t0 > 0) line.a = {
3048
+ x: ax + t0 * dx,
3049
+ y: ay + t0 * dy
3050
+ };
3051
+ if (t1 < 1) line.b = {
3052
+ x: ax + t1 * dx,
3053
+ y: ay + t1 * dy
3054
+ };
3055
+ return line;
3056
+ };
3057
+ }
3018
3058
  var d3_geo_clipExtentMAX = 1e9;
3019
3059
  d3.geo.clipExtent = function() {
3020
3060
  var x0, y0, x1, y1, stream, clip, clipExtent = {
@@ -3035,7 +3075,7 @@ d3 = function() {
3035
3075
  };
3036
3076
  function d3_geo_clipExtent(x0, y0, x1, y1) {
3037
3077
  return function(listener) {
3038
- var listener_ = listener, bufferListener = d3_geo_clipBufferListener(), segments, polygon, ring;
3078
+ var listener_ = listener, bufferListener = d3_geo_clipBufferListener(), clipLine = d3_geom_clipLine(x0, y0, x1, y1), segments, polygon, ring;
3039
3079
  var clip = {
3040
3080
  point: point,
3041
3081
  lineStart: lineStart,
@@ -3130,13 +3170,22 @@ d3 = function() {
3130
3170
  }
3131
3171
  } else {
3132
3172
  if (v && v_) listener.point(x, y); else {
3133
- var a = [ x_, y_ ], b = [ x, y ];
3134
- if (clipLine(a, b)) {
3173
+ var l = {
3174
+ a: {
3175
+ x: x_,
3176
+ y: y_
3177
+ },
3178
+ b: {
3179
+ x: x,
3180
+ y: y
3181
+ }
3182
+ };
3183
+ if (clipLine(l)) {
3135
3184
  if (!v_) {
3136
3185
  listener.lineStart();
3137
- listener.point(a[0], a[1]);
3186
+ listener.point(l.a.x, l.a.y);
3138
3187
  }
3139
- listener.point(b[0], b[1]);
3188
+ listener.point(l.b.x, l.b.y);
3140
3189
  if (!v) listener.lineEnd();
3141
3190
  clean = false;
3142
3191
  } else if (v) {
@@ -3151,43 +3200,15 @@ d3 = function() {
3151
3200
  return clip;
3152
3201
  };
3153
3202
  function corner(p, direction) {
3154
- return Math.abs(p[0] - x0) < ε ? direction > 0 ? 0 : 3 : Math.abs(p[0] - x1) < ε ? direction > 0 ? 2 : 1 : Math.abs(p[1] - y0) < ε ? direction > 0 ? 1 : 0 : direction > 0 ? 3 : 2;
3203
+ return abs(p[0] - x0) < ε ? direction > 0 ? 0 : 3 : abs(p[0] - x1) < ε ? direction > 0 ? 2 : 1 : abs(p[1] - y0) < ε ? direction > 0 ? 1 : 0 : direction > 0 ? 3 : 2;
3155
3204
  }
3156
3205
  function compare(a, b) {
3157
- return comparePoints(a.point, b.point);
3206
+ return comparePoints(a.x, b.x);
3158
3207
  }
3159
3208
  function comparePoints(a, b) {
3160
3209
  var ca = corner(a, 1), cb = corner(b, 1);
3161
3210
  return ca !== cb ? ca - cb : ca === 0 ? b[1] - a[1] : ca === 1 ? a[0] - b[0] : ca === 2 ? a[1] - b[1] : b[0] - a[0];
3162
3211
  }
3163
- function clipLine(a, b) {
3164
- var dx = b[0] - a[0], dy = b[1] - a[1], t = [ 0, 1 ];
3165
- if (Math.abs(dx) < ε && Math.abs(dy) < ε) return x0 <= a[0] && a[0] <= x1 && y0 <= a[1] && a[1] <= y1;
3166
- if (d3_geo_clipExtentT(x0 - a[0], dx, t) && d3_geo_clipExtentT(a[0] - x1, -dx, t) && d3_geo_clipExtentT(y0 - a[1], dy, t) && d3_geo_clipExtentT(a[1] - y1, -dy, t)) {
3167
- if (t[1] < 1) {
3168
- b[0] = a[0] + t[1] * dx;
3169
- b[1] = a[1] + t[1] * dy;
3170
- }
3171
- if (t[0] > 0) {
3172
- a[0] += t[0] * dx;
3173
- a[1] += t[0] * dy;
3174
- }
3175
- return true;
3176
- }
3177
- return false;
3178
- }
3179
- }
3180
- function d3_geo_clipExtentT(num, denominator, t) {
3181
- if (Math.abs(denominator) < ε) return num <= 0;
3182
- var u = num / denominator;
3183
- if (denominator > 0) {
3184
- if (u > t[1]) return false;
3185
- if (u > t[0]) t[0] = u;
3186
- } else {
3187
- if (u < t[0]) return false;
3188
- if (u < t[1]) t[1] = u;
3189
- }
3190
- return true;
3191
3212
  }
3192
3213
  function d3_geo_compose(a, b) {
3193
3214
  function compose(x, y) {
@@ -3312,7 +3333,7 @@ d3 = function() {
3312
3333
  },
3313
3334
  polygonEnd: function() {
3314
3335
  d3_geo_pathArea.lineStart = d3_geo_pathArea.lineEnd = d3_geo_pathArea.point = d3_noop;
3315
- d3_geo_pathAreaSum += Math.abs(d3_geo_pathAreaPolygon / 2);
3336
+ d3_geo_pathAreaSum += abs(d3_geo_pathAreaPolygon / 2);
3316
3337
  }
3317
3338
  };
3318
3339
  function d3_geo_pathAreaRingStart() {
@@ -3541,8 +3562,8 @@ d3 = function() {
3541
3562
  function resampleLineTo(x0, y0, λ0, a0, b0, c0, x1, y1, λ1, a1, b1, c1, depth, stream) {
3542
3563
  var dx = x1 - x0, dy = y1 - y0, d2 = dx * dx + dy * dy;
3543
3564
  if (d2 > 4 * δ2 && depth--) {
3544
- var a = a0 + a1, b = b0 + b1, c = c0 + c1, m = Math.sqrt(a * a + b * b + c * c), φ2 = Math.asin(c /= m), λ2 = Math.abs(Math.abs(c) - 1) < ε ? (λ0 + λ1) / 2 : Math.atan2(b, a), p = project(λ2, φ2), x2 = p[0], y2 = p[1], dx2 = x2 - x0, dy2 = y2 - y0, dz = dy * dx2 - dx * dy2;
3545
- if (dz * dz / d2 > δ2 || Math.abs((dx * dx2 + dy * dy2) / d2 - .5) > .3 || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) {
3565
+ var a = a0 + a1, b = b0 + b1, c = c0 + c1, m = Math.sqrt(a * a + b * b + c * c), φ2 = Math.asin(c /= m), λ2 = abs(abs(c) - 1) < ε ? (λ0 + λ1) / 2 : Math.atan2(b, a), p = project(λ2, φ2), x2 = p[0], y2 = p[1], dx2 = x2 - x0, dy2 = y2 - y0, dz = dy * dx2 - dx * dy2;
3566
+ if (dz * dz / d2 > δ2 || abs((dx * dx2 + dy * dy2) / d2 - .5) > .3 || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) {
3546
3567
  resampleLineTo(x0, y0, λ0, a0, b0, c0, x2, y2, λ2, a /= m, b /= m, c, depth, stream);
3547
3568
  stream.point(x2, y2);
3548
3569
  resampleLineTo(x2, y2, λ2, a, b, c, x1, y1, λ1, a1, b1, c1, depth, stream);
@@ -3850,9 +3871,9 @@ d3 = function() {
3850
3871
  }
3851
3872
  function lines() {
3852
3873
  return d3.range(Math.ceil(X0 / DX) * DX, X1, DX).map(X).concat(d3.range(Math.ceil(Y0 / DY) * DY, Y1, DY).map(Y)).concat(d3.range(Math.ceil(x0 / dx) * dx, x1, dx).filter(function(x) {
3853
- return Math.abs(x % DX) > ε;
3874
+ return abs(x % DX) > ε;
3854
3875
  }).map(x)).concat(d3.range(Math.ceil(y0 / dy) * dy, y1, dy).filter(function(y) {
3855
- return Math.abs(y % DY) > ε;
3876
+ return abs(y % DY) > ε;
3856
3877
  }).map(y));
3857
3878
  }
3858
3879
  graticule.lines = function() {
@@ -4000,7 +4021,7 @@ d3 = function() {
4000
4021
  d3_geo_length.point = d3_geo_length.lineEnd = d3_noop;
4001
4022
  };
4002
4023
  function nextPoint(λ, φ) {
4003
- var sinφ = Math.sin(φ *= d3_radians), cosφ = Math.cos(φ), t = Math.abs((λ *= d3_radians) - λ0), cosΔλ = Math.cos(t);
4024
+ var sinφ = Math.sin(φ *= d3_radians), cosφ = Math.cos(φ), t = abs((λ *= d3_radians) - λ0), cosΔλ = Math.cos(t);
4004
4025
  d3_geo_lengthSum += Math.atan2(Math.sqrt((t = cosφ * Math.sin(t)) * t + (t = cosφ0 * sinφ - sinφ0 * cosφ * cosΔλ) * t), sinφ0 * sinφ + cosφ0 * cosφ * cosΔλ);
4005
4026
  λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ;
4006
4027
  }
@@ -4037,7 +4058,7 @@ d3 = function() {
4037
4058
  }, n = φ0 === φ1 ? Math.sin(φ0) : Math.log(cosφ0 / Math.cos(φ1)) / Math.log(t(φ1) / t(φ0)), F = cosφ0 * Math.pow(t(φ0), n) / n;
4038
4059
  if (!n) return d3_geo_mercator;
4039
4060
  function forward(λ, φ) {
4040
- var ρ = Math.abs(Math.abs(φ) - halfπ) < ε ? 0 : F / Math.pow(t(φ), n);
4061
+ var ρ = abs(abs(φ) - halfπ) < ε ? 0 : F / Math.pow(t(φ), n);
4041
4062
  return [ ρ * Math.sin(n * λ), F - ρ * Math.cos(n * λ) ];
4042
4063
  }
4043
4064
  forward.invert = function(x, y) {
@@ -4051,7 +4072,7 @@ d3 = function() {
4051
4072
  }).raw = d3_geo_conicConformal;
4052
4073
  function d3_geo_conicEquidistant(φ0, φ1) {
4053
4074
  var cosφ0 = Math.cos(φ0), n = φ0 === φ1 ? Math.sin(φ0) : (cosφ0 - Math.cos(φ1)) / (φ1 - φ0), G = cosφ0 / n + φ0;
4054
- if (Math.abs(n) < ε) return d3_geo_equirectangular;
4075
+ if (abs(n) < ε) return d3_geo_equirectangular;
4055
4076
  function forward(λ, φ) {
4056
4077
  var ρ = G - φ;
4057
4078
  return [ ρ * Math.sin(n * λ), G - ρ * Math.cos(n * λ) ];
@@ -4362,7 +4383,7 @@ d3 = function() {
4362
4383
  var tangents = [], d, a, b, s, m = d3_svg_lineFiniteDifferences(points), i = -1, j = points.length - 1;
4363
4384
  while (++i < j) {
4364
4385
  d = d3_svg_lineSlope(points[i], points[i + 1]);
4365
- if (Math.abs(d) < ε) {
4386
+ if (abs(d) < ε) {
4366
4387
  m[i] = m[i + 1] = 0;
4367
4388
  } else {
4368
4389
  a = m[i] / d;
@@ -4533,424 +4554,653 @@ d3 = function() {
4533
4554
  var a = coordinates[0], b = coordinates[coordinates.length - 1];
4534
4555
  return !(a[0] - b[0] || a[1] - b[1]);
4535
4556
  }
4536
- d3.geom.delaunay = function(vertices) {
4537
- var edges = vertices.map(function() {
4538
- return [];
4539
- }), triangles = [];
4540
- d3_geom_voronoiTessellate(vertices, function(e) {
4541
- edges[e.region.l.index].push(vertices[e.region.r.index]);
4542
- });
4543
- edges.forEach(function(edge, i) {
4544
- var v = vertices[i], cx = v[0], cy = v[1];
4545
- edge.forEach(function(v) {
4546
- v.angle = Math.atan2(v[0] - cx, v[1] - cy);
4547
- });
4548
- edge.sort(function(a, b) {
4549
- return a.angle - b.angle;
4550
- });
4551
- for (var j = 0, m = edge.length - 1; j < m; j++) {
4552
- triangles.push([ v, edge[j], edge[j + 1] ]);
4553
- }
4554
- });
4555
- return triangles;
4556
- };
4557
- d3.geom.voronoi = function(points) {
4558
- var x = d3_svg_lineX, y = d3_svg_lineY, clipPolygon = null;
4559
- if (arguments.length) return voronoi(points);
4560
- function voronoi(data) {
4561
- var points, polygons = data.map(function() {
4562
- return [];
4563
- }), fx = d3_functor(x), fy = d3_functor(y), d, i, n = data.length, Z = 1e6;
4564
- if (fx === d3_svg_lineX && fy === d3_svg_lineY) points = data; else for (points = new Array(n),
4565
- i = 0; i < n; ++i) {
4566
- points[i] = [ +fx.call(this, d = data[i], i), +fy.call(this, d, i) ];
4567
- }
4568
- d3_geom_voronoiTessellate(points, function(e) {
4569
- var s1, s2, x1, x2, y1, y2;
4570
- if (e.a === 1 && e.b >= 0) {
4571
- s1 = e.ep.r;
4572
- s2 = e.ep.l;
4573
- } else {
4574
- s1 = e.ep.l;
4575
- s2 = e.ep.r;
4576
- }
4577
- if (e.a === 1) {
4578
- y1 = s1 ? s1.y : -Z;
4579
- x1 = e.c - e.b * y1;
4580
- y2 = s2 ? s2.y : Z;
4581
- x2 = e.c - e.b * y2;
4582
- } else {
4583
- x1 = s1 ? s1.x : -Z;
4584
- y1 = e.c - e.a * x1;
4585
- x2 = s2 ? s2.x : Z;
4586
- y2 = e.c - e.a * x2;
4587
- }
4588
- var v1 = [ x1, y1 ], v2 = [ x2, y2 ];
4589
- polygons[e.region.l.index].push(v1, v2);
4590
- polygons[e.region.r.index].push(v1, v2);
4591
- });
4592
- polygons = polygons.map(function(polygon, i) {
4593
- var cx = points[i][0], cy = points[i][1], angle = polygon.map(function(v) {
4594
- return Math.atan2(v[0] - cx, v[1] - cy);
4595
- }), order = d3.range(polygon.length).sort(function(a, b) {
4596
- return angle[a] - angle[b];
4597
- });
4598
- return order.filter(function(d, i) {
4599
- return !i || angle[d] - angle[order[i - 1]] > ε;
4600
- }).map(function(d) {
4601
- return polygon[d];
4602
- });
4603
- });
4604
- polygons.forEach(function(polygon, i) {
4605
- var n = polygon.length;
4606
- if (!n) return polygon.push([ -Z, -Z ], [ -Z, Z ], [ Z, Z ], [ Z, -Z ]);
4607
- if (n > 2) return;
4608
- var p0 = points[i], p1 = polygon[0], p2 = polygon[1], x0 = p0[0], y0 = p0[1], x1 = p1[0], y1 = p1[1], x2 = p2[0], y2 = p2[1], dx = Math.abs(x2 - x1), dy = y2 - y1;
4609
- if (Math.abs(dy) < ε) {
4610
- var y = y0 < y1 ? -Z : Z;
4611
- polygon.push([ -Z, y ], [ Z, y ]);
4612
- } else if (dx < ε) {
4613
- var x = x0 < x1 ? -Z : Z;
4614
- polygon.push([ x, -Z ], [ x, Z ]);
4557
+ var d3_geom_voronoiEdges, d3_geom_voronoiCells, d3_geom_voronoiBeaches, d3_geom_voronoiBeachPool = [], d3_geom_voronoiFirstCircle, d3_geom_voronoiCircles, d3_geom_voronoiCirclePool = [];
4558
+ function d3_geom_voronoiBeach() {
4559
+ d3_geom_voronoiRedBlackNode(this);
4560
+ this.edge = this.site = this.circle = null;
4561
+ }
4562
+ function d3_geom_voronoiCreateBeach(site) {
4563
+ var beach = d3_geom_voronoiBeachPool.pop() || new d3_geom_voronoiBeach();
4564
+ beach.site = site;
4565
+ return beach;
4566
+ }
4567
+ function d3_geom_voronoiDetachBeach(beach) {
4568
+ d3_geom_voronoiDetachCircle(beach);
4569
+ d3_geom_voronoiBeaches.remove(beach);
4570
+ d3_geom_voronoiBeachPool.push(beach);
4571
+ d3_geom_voronoiRedBlackNode(beach);
4572
+ }
4573
+ function d3_geom_voronoiRemoveBeach(beach) {
4574
+ var circle = beach.circle, x = circle.x, y = circle.cy, vertex = {
4575
+ x: x,
4576
+ y: y
4577
+ }, previous = beach.P, next = beach.N, disappearing = [ beach ];
4578
+ d3_geom_voronoiDetachBeach(beach);
4579
+ var lArc = previous;
4580
+ while (lArc.circle && abs(x - lArc.circle.x) < ε && abs(y - lArc.circle.cy) < ε) {
4581
+ previous = lArc.P;
4582
+ disappearing.unshift(lArc);
4583
+ d3_geom_voronoiDetachBeach(lArc);
4584
+ lArc = previous;
4585
+ }
4586
+ disappearing.unshift(lArc);
4587
+ d3_geom_voronoiDetachCircle(lArc);
4588
+ var rArc = next;
4589
+ while (rArc.circle && abs(x - rArc.circle.x) < ε && abs(y - rArc.circle.cy) < ε) {
4590
+ next = rArc.N;
4591
+ disappearing.push(rArc);
4592
+ d3_geom_voronoiDetachBeach(rArc);
4593
+ rArc = next;
4594
+ }
4595
+ disappearing.push(rArc);
4596
+ d3_geom_voronoiDetachCircle(rArc);
4597
+ var nArcs = disappearing.length, iArc;
4598
+ for (iArc = 1; iArc < nArcs; ++iArc) {
4599
+ rArc = disappearing[iArc];
4600
+ lArc = disappearing[iArc - 1];
4601
+ d3_geom_voronoiSetEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
4602
+ }
4603
+ lArc = disappearing[0];
4604
+ rArc = disappearing[nArcs - 1];
4605
+ rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, rArc.site, null, vertex);
4606
+ d3_geom_voronoiAttachCircle(lArc);
4607
+ d3_geom_voronoiAttachCircle(rArc);
4608
+ }
4609
+ function d3_geom_voronoiAddBeach(site) {
4610
+ var x = site.x, directrix = site.y, lArc, rArc, dxl, dxr, node = d3_geom_voronoiBeaches._;
4611
+ while (node) {
4612
+ dxl = d3_geom_voronoiLeftBreakPoint(node, directrix) - x;
4613
+ if (dxl > ε) node = node.L; else {
4614
+ dxr = x - d3_geom_voronoiRightBreakPoint(node, directrix);
4615
+ if (dxr > ε) {
4616
+ if (!node.R) {
4617
+ lArc = node;
4618
+ break;
4619
+ }
4620
+ node = node.R;
4615
4621
  } else {
4616
- var y = (x2 - x1) * (y1 - y0) < (x1 - x0) * (y2 - y1) ? Z : -Z, z = Math.abs(dy) - dx;
4617
- if (Math.abs(z) < ε) {
4618
- polygon.push([ dy < 0 ? y : -y, y ]);
4622
+ if (dxl > ) {
4623
+ lArc = node.P;
4624
+ rArc = node;
4625
+ } else if (dxr > -ε) {
4626
+ lArc = node;
4627
+ rArc = node.N;
4619
4628
  } else {
4620
- if (z > 0) y *= -1;
4621
- polygon.push([ -Z, y ], [ Z, y ]);
4629
+ lArc = rArc = node;
4622
4630
  }
4631
+ break;
4632
+ }
4633
+ }
4634
+ }
4635
+ var newArc = d3_geom_voronoiCreateBeach(site);
4636
+ d3_geom_voronoiBeaches.insert(lArc, newArc);
4637
+ if (!lArc && !rArc) return;
4638
+ if (lArc === rArc) {
4639
+ d3_geom_voronoiDetachCircle(lArc);
4640
+ rArc = d3_geom_voronoiCreateBeach(lArc.site);
4641
+ d3_geom_voronoiBeaches.insert(newArc, rArc);
4642
+ newArc.edge = rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
4643
+ d3_geom_voronoiAttachCircle(lArc);
4644
+ d3_geom_voronoiAttachCircle(rArc);
4645
+ return;
4646
+ }
4647
+ if (!rArc) {
4648
+ newArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
4649
+ return;
4650
+ }
4651
+ d3_geom_voronoiDetachCircle(lArc);
4652
+ d3_geom_voronoiDetachCircle(rArc);
4653
+ var lSite = lArc.site, ax = lSite.x, ay = lSite.y, bx = site.x - ax, by = site.y - ay, rSite = rArc.site, cx = rSite.x - ax, cy = rSite.y - ay, d = 2 * (bx * cy - by * cx), hb = bx * bx + by * by, hc = cx * cx + cy * cy, vertex = {
4654
+ x: (cy * hb - by * hc) / d + ax,
4655
+ y: (bx * hc - cx * hb) / d + ay
4656
+ };
4657
+ d3_geom_voronoiSetEdgeEnd(rArc.edge, lSite, rSite, vertex);
4658
+ newArc.edge = d3_geom_voronoiCreateEdge(lSite, site, null, vertex);
4659
+ rArc.edge = d3_geom_voronoiCreateEdge(site, rSite, null, vertex);
4660
+ d3_geom_voronoiAttachCircle(lArc);
4661
+ d3_geom_voronoiAttachCircle(rArc);
4662
+ }
4663
+ function d3_geom_voronoiLeftBreakPoint(arc, directrix) {
4664
+ var site = arc.site, rfocx = site.x, rfocy = site.y, pby2 = rfocy - directrix;
4665
+ if (!pby2) return rfocx;
4666
+ var lArc = arc.P;
4667
+ if (!lArc) return -Infinity;
4668
+ site = lArc.site;
4669
+ var lfocx = site.x, lfocy = site.y, plby2 = lfocy - directrix;
4670
+ if (!plby2) return lfocx;
4671
+ var hl = lfocx - rfocx, aby2 = 1 / pby2 - 1 / plby2, b = hl / plby2;
4672
+ if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
4673
+ return (rfocx + lfocx) / 2;
4674
+ }
4675
+ function d3_geom_voronoiRightBreakPoint(arc, directrix) {
4676
+ var rArc = arc.N;
4677
+ if (rArc) return d3_geom_voronoiLeftBreakPoint(rArc, directrix);
4678
+ var site = arc.site;
4679
+ return site.y === directrix ? site.x : Infinity;
4680
+ }
4681
+ function d3_geom_voronoiCell(site) {
4682
+ this.site = site;
4683
+ this.edges = [];
4684
+ }
4685
+ d3_geom_voronoiCell.prototype.prepare = function() {
4686
+ var halfEdges = this.edges, iHalfEdge = halfEdges.length, edge;
4687
+ while (iHalfEdge--) {
4688
+ edge = halfEdges[iHalfEdge].edge;
4689
+ if (!edge.b || !edge.a) halfEdges.splice(iHalfEdge, 1);
4690
+ }
4691
+ halfEdges.sort(d3_geom_voronoiHalfEdgeOrder);
4692
+ return halfEdges.length;
4693
+ };
4694
+ function d3_geom_voronoiCloseCells(extent) {
4695
+ var x0 = extent[0][0], x1 = extent[1][0], y0 = extent[0][1], y1 = extent[1][1], x2, y2, x3, y3, cells = d3_geom_voronoiCells, iCell = cells.length, cell, iHalfEdge, halfEdges, nHalfEdges, start, end;
4696
+ while (iCell--) {
4697
+ cell = cells[iCell];
4698
+ if (!cell || !cell.prepare()) continue;
4699
+ halfEdges = cell.edges;
4700
+ nHalfEdges = halfEdges.length;
4701
+ iHalfEdge = 0;
4702
+ while (iHalfEdge < nHalfEdges) {
4703
+ end = halfEdges[iHalfEdge].end(), x3 = end.x, y3 = end.y;
4704
+ start = halfEdges[++iHalfEdge % nHalfEdges].start(), x2 = start.x, y2 = start.y;
4705
+ if (abs(x3 - x2) > ε || abs(y3 - y2) > ε) {
4706
+ halfEdges.splice(iHalfEdge, 0, new d3_geom_voronoiHalfEdge(d3_geom_voronoiCreateBorderEdge(cell.site, end, abs(x3 - x0) < ε && y1 - y3 > ε ? {
4707
+ x: x0,
4708
+ y: abs(x2 - x0) < ε ? y2 : y1
4709
+ } : abs(y3 - y1) < ε && x1 - x3 > ε ? {
4710
+ x: abs(y2 - y1) < ε ? x2 : x1,
4711
+ y: y1
4712
+ } : abs(x3 - x1) < ε && y3 - y0 > ε ? {
4713
+ x: x1,
4714
+ y: abs(x2 - x1) < ε ? y2 : y0
4715
+ } : abs(y3 - y0) < ε && x3 - x0 > ε ? {
4716
+ x: abs(y2 - y0) < ε ? x2 : x0,
4717
+ y: y0
4718
+ } : null), cell.site, null));
4719
+ ++nHalfEdges;
4720
+ }
4721
+ }
4722
+ }
4723
+ }
4724
+ function d3_geom_voronoiHalfEdgeOrder(a, b) {
4725
+ return b.angle - a.angle;
4726
+ }
4727
+ function d3_geom_voronoiCircle() {
4728
+ d3_geom_voronoiRedBlackNode(this);
4729
+ this.x = this.y = this.arc = this.site = this.cy = null;
4730
+ }
4731
+ function d3_geom_voronoiAttachCircle(arc) {
4732
+ var lArc = arc.P, rArc = arc.N;
4733
+ if (!lArc || !rArc) return;
4734
+ var lSite = lArc.site, cSite = arc.site, rSite = rArc.site;
4735
+ if (lSite === rSite) return;
4736
+ var bx = cSite.x, by = cSite.y, ax = lSite.x - bx, ay = lSite.y - by, cx = rSite.x - bx, cy = rSite.y - by;
4737
+ var d = 2 * (ax * cy - ay * cx);
4738
+ if (d >= -ε2) return;
4739
+ var ha = ax * ax + ay * ay, hc = cx * cx + cy * cy, x = (cy * ha - ay * hc) / d, y = (ax * hc - cx * ha) / d, cy = y + by;
4740
+ var circle = d3_geom_voronoiCirclePool.pop() || new d3_geom_voronoiCircle();
4741
+ circle.arc = arc;
4742
+ circle.site = cSite;
4743
+ circle.x = x + bx;
4744
+ circle.y = cy + Math.sqrt(x * x + y * y);
4745
+ circle.cy = cy;
4746
+ arc.circle = circle;
4747
+ var before = null, node = d3_geom_voronoiCircles._;
4748
+ while (node) {
4749
+ if (circle.y < node.y || circle.y === node.y && circle.x <= node.x) {
4750
+ if (node.L) node = node.L; else {
4751
+ before = node.P;
4752
+ break;
4623
4753
  }
4624
- });
4625
- if (clipPolygon) for (i = 0; i < n; ++i) clipPolygon.clip(polygons[i]);
4626
- for (i = 0; i < n; ++i) polygons[i].point = data[i];
4627
- return polygons;
4628
- }
4629
- voronoi.x = function(_) {
4630
- return arguments.length ? (x = _, voronoi) : x;
4631
- };
4632
- voronoi.y = function(_) {
4633
- return arguments.length ? (y = _, voronoi) : y;
4634
- };
4635
- voronoi.clipExtent = function(_) {
4636
- if (!arguments.length) return clipPolygon && [ clipPolygon[0], clipPolygon[2] ];
4637
- if (_ == null) clipPolygon = null; else {
4638
- var x1 = +_[0][0], y1 = +_[0][1], x2 = +_[1][0], y2 = +_[1][1];
4639
- clipPolygon = d3.geom.polygon([ [ x1, y1 ], [ x1, y2 ], [ x2, y2 ], [ x2, y1 ] ]);
4640
- }
4641
- return voronoi;
4642
- };
4643
- voronoi.size = function(_) {
4644
- if (!arguments.length) return clipPolygon && clipPolygon[2];
4645
- return voronoi.clipExtent(_ && [ [ 0, 0 ], _ ]);
4646
- };
4647
- voronoi.links = function(data) {
4648
- var points, graph = data.map(function() {
4649
- return [];
4650
- }), links = [], fx = d3_functor(x), fy = d3_functor(y), d, i, n = data.length;
4651
- if (fx === d3_svg_lineX && fy === d3_svg_lineY) points = data; else for (points = new Array(n),
4652
- i = 0; i < n; ++i) {
4653
- points[i] = [ +fx.call(this, d = data[i], i), +fy.call(this, d, i) ];
4654
- }
4655
- d3_geom_voronoiTessellate(points, function(e) {
4656
- var l = e.region.l.index, r = e.region.r.index;
4657
- if (graph[l][r]) return;
4658
- graph[l][r] = graph[r][l] = true;
4659
- links.push({
4660
- source: data[l],
4661
- target: data[r]
4662
- });
4663
- });
4664
- return links;
4665
- };
4666
- voronoi.triangles = function(data) {
4667
- if (x === d3_svg_lineX && y === d3_svg_lineY) return d3.geom.delaunay(data);
4668
- var points = new Array(n), fx = d3_functor(x), fy = d3_functor(y), d, i = -1, n = data.length;
4669
- while (++i < n) {
4670
- (points[i] = [ +fx.call(this, d = data[i], i), +fy.call(this, d, i) ]).data = d;
4671
- }
4672
- return d3.geom.delaunay(points).map(function(triangle) {
4673
- return triangle.map(function(point) {
4674
- return point.data;
4675
- });
4676
- });
4677
- };
4678
- return voronoi;
4679
- };
4680
- var d3_geom_voronoiOpposite = {
4681
- l: "r",
4682
- r: "l"
4683
- };
4684
- function d3_geom_voronoiTessellate(points, callback) {
4685
- var Sites = {
4686
- list: points.map(function(v, i) {
4687
- return {
4688
- index: i,
4689
- x: v[0],
4690
- y: v[1]
4691
- };
4692
- }).sort(function(a, b) {
4693
- return a.y < b.y ? -1 : a.y > b.y ? 1 : a.x < b.x ? -1 : a.x > b.x ? 1 : 0;
4694
- }),
4695
- bottomSite: null
4696
- };
4697
- var EdgeList = {
4698
- list: [],
4699
- leftEnd: null,
4700
- rightEnd: null,
4701
- init: function() {
4702
- EdgeList.leftEnd = EdgeList.createHalfEdge(null, "l");
4703
- EdgeList.rightEnd = EdgeList.createHalfEdge(null, "l");
4704
- EdgeList.leftEnd.r = EdgeList.rightEnd;
4705
- EdgeList.rightEnd.l = EdgeList.leftEnd;
4706
- EdgeList.list.unshift(EdgeList.leftEnd, EdgeList.rightEnd);
4707
- },
4708
- createHalfEdge: function(edge, side) {
4709
- return {
4710
- edge: edge,
4711
- side: side,
4712
- vertex: null,
4713
- l: null,
4714
- r: null
4754
+ } else {
4755
+ if (node.R) node = node.R; else {
4756
+ before = node;
4757
+ break;
4758
+ }
4759
+ }
4760
+ }
4761
+ d3_geom_voronoiCircles.insert(before, circle);
4762
+ if (!before) d3_geom_voronoiFirstCircle = circle;
4763
+ }
4764
+ function d3_geom_voronoiDetachCircle(arc) {
4765
+ var circle = arc.circle;
4766
+ if (circle) {
4767
+ if (!circle.P) d3_geom_voronoiFirstCircle = circle.N;
4768
+ d3_geom_voronoiCircles.remove(circle);
4769
+ d3_geom_voronoiCirclePool.push(circle);
4770
+ d3_geom_voronoiRedBlackNode(circle);
4771
+ arc.circle = null;
4772
+ }
4773
+ }
4774
+ function d3_geom_voronoiClipEdges(extent) {
4775
+ var edges = d3_geom_voronoiEdges, clip = d3_geom_clipLine(extent[0][0], extent[0][1], extent[1][0], extent[1][1]), i = edges.length, e;
4776
+ while (i--) {
4777
+ e = edges[i];
4778
+ if (!d3_geom_voronoiConnectEdge(e, extent) || !clip(e) || abs(e.a.x - e.b.x) < ε && abs(e.a.y - e.b.y) < ε) {
4779
+ e.a = e.b = null;
4780
+ edges.splice(i, 1);
4781
+ }
4782
+ }
4783
+ }
4784
+ function d3_geom_voronoiConnectEdge(edge, extent) {
4785
+ var vb = edge.b;
4786
+ if (vb) return true;
4787
+ var va = edge.a, x0 = extent[0][0], x1 = extent[1][0], y0 = extent[0][1], y1 = extent[1][1], lSite = edge.l, rSite = edge.r, lx = lSite.x, ly = lSite.y, rx = rSite.x, ry = rSite.y, fx = (lx + rx) / 2, fy = (ly + ry) / 2, fm, fb;
4788
+ if (ry === ly) {
4789
+ if (fx < x0 || fx >= x1) return;
4790
+ if (lx > rx) {
4791
+ if (!va) va = {
4792
+ x: fx,
4793
+ y: y0
4794
+ }; else if (va.y >= y1) return;
4795
+ vb = {
4796
+ x: fx,
4797
+ y: y1
4715
4798
  };
4716
- },
4717
- insert: function(lb, he) {
4718
- he.l = lb;
4719
- he.r = lb.r;
4720
- lb.r.l = he;
4721
- lb.r = he;
4722
- },
4723
- leftBound: function(p) {
4724
- var he = EdgeList.leftEnd;
4725
- do {
4726
- he = he.r;
4727
- } while (he != EdgeList.rightEnd && Geom.rightOf(he, p));
4728
- he = he.l;
4729
- return he;
4730
- },
4731
- del: function(he) {
4732
- he.l.r = he.r;
4733
- he.r.l = he.l;
4734
- he.edge = null;
4735
- },
4736
- right: function(he) {
4737
- return he.r;
4738
- },
4739
- left: function(he) {
4740
- return he.l;
4741
- },
4742
- leftRegion: function(he) {
4743
- return he.edge == null ? Sites.bottomSite : he.edge.region[he.side];
4744
- },
4745
- rightRegion: function(he) {
4746
- return he.edge == null ? Sites.bottomSite : he.edge.region[d3_geom_voronoiOpposite[he.side]];
4747
- }
4748
- };
4749
- var Geom = {
4750
- bisect: function(s1, s2) {
4751
- var newEdge = {
4752
- region: {
4753
- l: s1,
4754
- r: s2
4755
- },
4756
- ep: {
4757
- l: null,
4758
- r: null
4759
- }
4799
+ } else {
4800
+ if (!va) va = {
4801
+ x: fx,
4802
+ y: y1
4803
+ }; else if (va.y < y0) return;
4804
+ vb = {
4805
+ x: fx,
4806
+ y: y0
4760
4807
  };
4761
- var dx = s2.x - s1.x, dy = s2.y - s1.y, adx = dx > 0 ? dx : -dx, ady = dy > 0 ? dy : -dy;
4762
- newEdge.c = s1.x * dx + s1.y * dy + (dx * dx + dy * dy) * .5;
4763
- if (adx > ady) {
4764
- newEdge.a = 1;
4765
- newEdge.b = dy / dx;
4766
- newEdge.c /= dx;
4808
+ }
4809
+ } else {
4810
+ fm = (lx - rx) / (ry - ly);
4811
+ fb = fy - fm * fx;
4812
+ if (fm < -1 || fm > 1) {
4813
+ if (lx > rx) {
4814
+ if (!va) va = {
4815
+ x: (y0 - fb) / fm,
4816
+ y: y0
4817
+ }; else if (va.y >= y1) return;
4818
+ vb = {
4819
+ x: (y1 - fb) / fm,
4820
+ y: y1
4821
+ };
4767
4822
  } else {
4768
- newEdge.b = 1;
4769
- newEdge.a = dx / dy;
4770
- newEdge.c /= dy;
4823
+ if (!va) va = {
4824
+ x: (y1 - fb) / fm,
4825
+ y: y1
4826
+ }; else if (va.y < y0) return;
4827
+ vb = {
4828
+ x: (y0 - fb) / fm,
4829
+ y: y0
4830
+ };
4771
4831
  }
4772
- return newEdge;
4773
- },
4774
- intersect: function(el1, el2) {
4775
- var e1 = el1.edge, e2 = el2.edge;
4776
- if (!e1 || !e2 || e1.region.r == e2.region.r) {
4777
- return null;
4778
- }
4779
- var d = e1.a * e2.b - e1.b * e2.a;
4780
- if (Math.abs(d) < 1e-10) {
4781
- return null;
4782
- }
4783
- var xint = (e1.c * e2.b - e2.c * e1.b) / d, yint = (e2.c * e1.a - e1.c * e2.a) / d, e1r = e1.region.r, e2r = e2.region.r, el, e;
4784
- if (e1r.y < e2r.y || e1r.y == e2r.y && e1r.x < e2r.x) {
4785
- el = el1;
4786
- e = e1;
4832
+ } else {
4833
+ if (ly < ry) {
4834
+ if (!va) va = {
4835
+ x: x0,
4836
+ y: fm * x0 + fb
4837
+ }; else if (va.x >= x1) return;
4838
+ vb = {
4839
+ x: x1,
4840
+ y: fm * x1 + fb
4841
+ };
4787
4842
  } else {
4788
- el = el2;
4789
- e = e2;
4790
- }
4791
- var rightOfSite = xint >= e.region.r.x;
4792
- if (rightOfSite && el.side === "l" || !rightOfSite && el.side === "r") {
4793
- return null;
4794
- }
4795
- return {
4796
- x: xint,
4797
- y: yint
4798
- };
4799
- },
4800
- rightOf: function(he, p) {
4801
- var e = he.edge, topsite = e.region.r, rightOfSite = p.x > topsite.x;
4802
- if (rightOfSite && he.side === "l") {
4803
- return 1;
4804
- }
4805
- if (!rightOfSite && he.side === "r") {
4806
- return 0;
4843
+ if (!va) va = {
4844
+ x: x1,
4845
+ y: fm * x1 + fb
4846
+ }; else if (va.x < x0) return;
4847
+ vb = {
4848
+ x: x0,
4849
+ y: fm * x0 + fb
4850
+ };
4807
4851
  }
4808
- if (e.a === 1) {
4809
- var dyp = p.y - topsite.y, dxp = p.x - topsite.x, fast = 0, above = 0;
4810
- if (!rightOfSite && e.b < 0 || rightOfSite && e.b >= 0) {
4811
- above = fast = dyp >= e.b * dxp;
4852
+ }
4853
+ }
4854
+ edge.a = va;
4855
+ edge.b = vb;
4856
+ return true;
4857
+ }
4858
+ function d3_geom_voronoiEdge(lSite, rSite) {
4859
+ this.l = lSite;
4860
+ this.r = rSite;
4861
+ this.a = this.b = null;
4862
+ }
4863
+ function d3_geom_voronoiCreateEdge(lSite, rSite, va, vb) {
4864
+ var edge = new d3_geom_voronoiEdge(lSite, rSite);
4865
+ d3_geom_voronoiEdges.push(edge);
4866
+ if (va) d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, va);
4867
+ if (vb) d3_geom_voronoiSetEdgeEnd(edge, rSite, lSite, vb);
4868
+ d3_geom_voronoiCells[lSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, lSite, rSite));
4869
+ d3_geom_voronoiCells[rSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, rSite, lSite));
4870
+ return edge;
4871
+ }
4872
+ function d3_geom_voronoiCreateBorderEdge(lSite, va, vb) {
4873
+ var edge = new d3_geom_voronoiEdge(lSite, null);
4874
+ edge.a = va;
4875
+ edge.b = vb;
4876
+ d3_geom_voronoiEdges.push(edge);
4877
+ return edge;
4878
+ }
4879
+ function d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, vertex) {
4880
+ if (!edge.a && !edge.b) {
4881
+ edge.a = vertex;
4882
+ edge.l = lSite;
4883
+ edge.r = rSite;
4884
+ } else if (edge.l === rSite) {
4885
+ edge.b = vertex;
4886
+ } else {
4887
+ edge.a = vertex;
4888
+ }
4889
+ }
4890
+ function d3_geom_voronoiHalfEdge(edge, lSite, rSite) {
4891
+ var va = edge.a, vb = edge.b;
4892
+ this.edge = edge;
4893
+ this.site = lSite;
4894
+ this.angle = rSite ? Math.atan2(rSite.y - lSite.y, rSite.x - lSite.x) : edge.l === lSite ? Math.atan2(vb.x - va.x, va.y - vb.y) : Math.atan2(va.x - vb.x, vb.y - va.y);
4895
+ }
4896
+ d3_geom_voronoiHalfEdge.prototype = {
4897
+ start: function() {
4898
+ return this.edge.l === this.site ? this.edge.a : this.edge.b;
4899
+ },
4900
+ end: function() {
4901
+ return this.edge.l === this.site ? this.edge.b : this.edge.a;
4902
+ }
4903
+ };
4904
+ function d3_geom_voronoiRedBlackTree() {
4905
+ this._ = null;
4906
+ }
4907
+ function d3_geom_voronoiRedBlackNode(node) {
4908
+ node.U = node.C = node.L = node.R = node.P = node.N = null;
4909
+ }
4910
+ d3_geom_voronoiRedBlackTree.prototype = {
4911
+ insert: function(after, node) {
4912
+ var parent, grandpa, uncle;
4913
+ if (after) {
4914
+ node.P = after;
4915
+ node.N = after.N;
4916
+ if (after.N) after.N.P = node;
4917
+ after.N = node;
4918
+ if (after.R) {
4919
+ after = after.R;
4920
+ while (after.L) after = after.L;
4921
+ after.L = node;
4922
+ } else {
4923
+ after.R = node;
4924
+ }
4925
+ parent = after;
4926
+ } else if (this._) {
4927
+ after = d3_geom_voronoiRedBlackFirst(this._);
4928
+ node.P = null;
4929
+ node.N = after;
4930
+ after.P = after.L = node;
4931
+ parent = after;
4932
+ } else {
4933
+ node.P = node.N = null;
4934
+ this._ = node;
4935
+ parent = null;
4936
+ }
4937
+ node.L = node.R = null;
4938
+ node.U = parent;
4939
+ node.C = true;
4940
+ after = node;
4941
+ while (parent && parent.C) {
4942
+ grandpa = parent.U;
4943
+ if (parent === grandpa.L) {
4944
+ uncle = grandpa.R;
4945
+ if (uncle && uncle.C) {
4946
+ parent.C = uncle.C = false;
4947
+ grandpa.C = true;
4948
+ after = grandpa;
4812
4949
  } else {
4813
- above = p.x + p.y * e.b > e.c;
4814
- if (e.b < 0) {
4815
- above = !above;
4816
- }
4817
- if (!above) {
4818
- fast = 1;
4950
+ if (after === parent.R) {
4951
+ d3_geom_voronoiRedBlackRotateLeft(this, parent);
4952
+ after = parent;
4953
+ parent = after.U;
4819
4954
  }
4955
+ parent.C = false;
4956
+ grandpa.C = true;
4957
+ d3_geom_voronoiRedBlackRotateRight(this, grandpa);
4820
4958
  }
4821
- if (!fast) {
4822
- var dxs = topsite.x - e.region.l.x;
4823
- above = e.b * (dxp * dxp - dyp * dyp) < dxs * dyp * (1 + 2 * dxp / dxs + e.b * e.b);
4824
- if (e.b < 0) {
4825
- above = !above;
4959
+ } else {
4960
+ uncle = grandpa.L;
4961
+ if (uncle && uncle.C) {
4962
+ parent.C = uncle.C = false;
4963
+ grandpa.C = true;
4964
+ after = grandpa;
4965
+ } else {
4966
+ if (after === parent.L) {
4967
+ d3_geom_voronoiRedBlackRotateRight(this, parent);
4968
+ after = parent;
4969
+ parent = after.U;
4826
4970
  }
4971
+ parent.C = false;
4972
+ grandpa.C = true;
4973
+ d3_geom_voronoiRedBlackRotateLeft(this, grandpa);
4827
4974
  }
4975
+ }
4976
+ parent = after.U;
4977
+ }
4978
+ this._.C = false;
4979
+ },
4980
+ remove: function(node) {
4981
+ if (node.N) node.N.P = node.P;
4982
+ if (node.P) node.P.N = node.N;
4983
+ node.N = node.P = null;
4984
+ var parent = node.U, sibling, left = node.L, right = node.R, next, red;
4985
+ if (!left) next = right; else if (!right) next = left; else next = d3_geom_voronoiRedBlackFirst(right);
4986
+ if (parent) {
4987
+ if (parent.L === node) parent.L = next; else parent.R = next;
4988
+ } else {
4989
+ this._ = next;
4990
+ }
4991
+ if (left && right) {
4992
+ red = next.C;
4993
+ next.C = node.C;
4994
+ next.L = left;
4995
+ left.U = next;
4996
+ if (next !== right) {
4997
+ parent = next.U;
4998
+ next.U = node.U;
4999
+ node = next.R;
5000
+ parent.L = node;
5001
+ next.R = right;
5002
+ right.U = next;
4828
5003
  } else {
4829
- var yl = e.c - e.a * p.x, t1 = p.y - yl, t2 = p.x - topsite.x, t3 = yl - topsite.y;
4830
- above = t1 * t1 > t2 * t2 + t3 * t3;
5004
+ next.U = parent;
5005
+ parent = next;
5006
+ node = next.R;
4831
5007
  }
4832
- return he.side === "l" ? above : !above;
4833
- },
4834
- endPoint: function(edge, side, site) {
4835
- edge.ep[side] = site;
4836
- if (!edge.ep[d3_geom_voronoiOpposite[side]]) return;
4837
- callback(edge);
4838
- },
4839
- distance: function(s, t) {
4840
- var dx = s.x - t.x, dy = s.y - t.y;
4841
- return Math.sqrt(dx * dx + dy * dy);
4842
- }
4843
- };
4844
- var EventQueue = {
4845
- list: [],
4846
- insert: function(he, site, offset) {
4847
- he.vertex = site;
4848
- he.ystar = site.y + offset;
4849
- for (var i = 0, list = EventQueue.list, l = list.length; i < l; i++) {
4850
- var next = list[i];
4851
- if (he.ystar > next.ystar || he.ystar == next.ystar && site.x > next.vertex.x) {
4852
- continue;
4853
- } else {
5008
+ } else {
5009
+ red = node.C;
5010
+ node = next;
5011
+ }
5012
+ if (node) node.U = parent;
5013
+ if (red) return;
5014
+ if (node && node.C) {
5015
+ node.C = false;
5016
+ return;
5017
+ }
5018
+ do {
5019
+ if (node === this._) break;
5020
+ if (node === parent.L) {
5021
+ sibling = parent.R;
5022
+ if (sibling.C) {
5023
+ sibling.C = false;
5024
+ parent.C = true;
5025
+ d3_geom_voronoiRedBlackRotateLeft(this, parent);
5026
+ sibling = parent.R;
5027
+ }
5028
+ if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
5029
+ if (!sibling.R || !sibling.R.C) {
5030
+ sibling.L.C = false;
5031
+ sibling.C = true;
5032
+ d3_geom_voronoiRedBlackRotateRight(this, sibling);
5033
+ sibling = parent.R;
5034
+ }
5035
+ sibling.C = parent.C;
5036
+ parent.C = sibling.R.C = false;
5037
+ d3_geom_voronoiRedBlackRotateLeft(this, parent);
5038
+ node = this._;
5039
+ break;
5040
+ }
5041
+ } else {
5042
+ sibling = parent.L;
5043
+ if (sibling.C) {
5044
+ sibling.C = false;
5045
+ parent.C = true;
5046
+ d3_geom_voronoiRedBlackRotateRight(this, parent);
5047
+ sibling = parent.L;
5048
+ }
5049
+ if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
5050
+ if (!sibling.L || !sibling.L.C) {
5051
+ sibling.R.C = false;
5052
+ sibling.C = true;
5053
+ d3_geom_voronoiRedBlackRotateLeft(this, sibling);
5054
+ sibling = parent.L;
5055
+ }
5056
+ sibling.C = parent.C;
5057
+ parent.C = sibling.L.C = false;
5058
+ d3_geom_voronoiRedBlackRotateRight(this, parent);
5059
+ node = this._;
4854
5060
  break;
4855
5061
  }
4856
5062
  }
4857
- list.splice(i, 0, he);
4858
- },
4859
- del: function(he) {
4860
- for (var i = 0, ls = EventQueue.list, l = ls.length; i < l && ls[i] != he; ++i) {}
4861
- ls.splice(i, 1);
4862
- },
4863
- empty: function() {
4864
- return EventQueue.list.length === 0;
4865
- },
4866
- nextEvent: function(he) {
4867
- for (var i = 0, ls = EventQueue.list, l = ls.length; i < l; ++i) {
4868
- if (ls[i] == he) return ls[i + 1];
4869
- }
4870
- return null;
4871
- },
4872
- min: function() {
4873
- var elem = EventQueue.list[0];
4874
- return {
4875
- x: elem.vertex.x,
4876
- y: elem.ystar
4877
- };
4878
- },
4879
- extractMin: function() {
4880
- return EventQueue.list.shift();
4881
- }
4882
- };
4883
- EdgeList.init();
4884
- Sites.bottomSite = Sites.list.shift();
4885
- var newSite = Sites.list.shift(), newIntStar;
4886
- var lbnd, rbnd, llbnd, rrbnd, bisector;
4887
- var bot, top, temp, p, v;
4888
- var e, pm;
5063
+ sibling.C = true;
5064
+ node = parent;
5065
+ parent = parent.U;
5066
+ } while (!node.C);
5067
+ if (node) node.C = false;
5068
+ }
5069
+ };
5070
+ function d3_geom_voronoiRedBlackRotateLeft(tree, node) {
5071
+ var p = node, q = node.R, parent = p.U;
5072
+ if (parent) {
5073
+ if (parent.L === p) parent.L = q; else parent.R = q;
5074
+ } else {
5075
+ tree._ = q;
5076
+ }
5077
+ q.U = parent;
5078
+ p.U = q;
5079
+ p.R = q.L;
5080
+ if (p.R) p.R.U = p;
5081
+ q.L = p;
5082
+ }
5083
+ function d3_geom_voronoiRedBlackRotateRight(tree, node) {
5084
+ var p = node, q = node.L, parent = p.U;
5085
+ if (parent) {
5086
+ if (parent.L === p) parent.L = q; else parent.R = q;
5087
+ } else {
5088
+ tree._ = q;
5089
+ }
5090
+ q.U = parent;
5091
+ p.U = q;
5092
+ p.L = q.R;
5093
+ if (p.L) p.L.U = p;
5094
+ q.R = p;
5095
+ }
5096
+ function d3_geom_voronoiRedBlackFirst(node) {
5097
+ while (node.L) node = node.L;
5098
+ return node;
5099
+ }
5100
+ function d3_geom_voronoi(sites, bbox) {
5101
+ var site = sites.sort(d3_geom_voronoiVertexOrder).pop(), x0, y0, circle;
5102
+ d3_geom_voronoiEdges = [];
5103
+ d3_geom_voronoiCells = new Array(sites.length);
5104
+ d3_geom_voronoiBeaches = new d3_geom_voronoiRedBlackTree();
5105
+ d3_geom_voronoiCircles = new d3_geom_voronoiRedBlackTree();
4889
5106
  while (true) {
4890
- if (!EventQueue.empty()) {
4891
- newIntStar = EventQueue.min();
4892
- }
4893
- if (newSite && (EventQueue.empty() || newSite.y < newIntStar.y || newSite.y == newIntStar.y && newSite.x < newIntStar.x)) {
4894
- lbnd = EdgeList.leftBound(newSite);
4895
- rbnd = EdgeList.right(lbnd);
4896
- bot = EdgeList.rightRegion(lbnd);
4897
- e = Geom.bisect(bot, newSite);
4898
- bisector = EdgeList.createHalfEdge(e, "l");
4899
- EdgeList.insert(lbnd, bisector);
4900
- p = Geom.intersect(lbnd, bisector);
4901
- if (p) {
4902
- EventQueue.del(lbnd);
4903
- EventQueue.insert(lbnd, p, Geom.distance(p, newSite));
4904
- }
4905
- lbnd = bisector;
4906
- bisector = EdgeList.createHalfEdge(e, "r");
4907
- EdgeList.insert(lbnd, bisector);
4908
- p = Geom.intersect(bisector, rbnd);
4909
- if (p) {
4910
- EventQueue.insert(bisector, p, Geom.distance(p, newSite));
4911
- }
4912
- newSite = Sites.list.shift();
4913
- } else if (!EventQueue.empty()) {
4914
- lbnd = EventQueue.extractMin();
4915
- llbnd = EdgeList.left(lbnd);
4916
- rbnd = EdgeList.right(lbnd);
4917
- rrbnd = EdgeList.right(rbnd);
4918
- bot = EdgeList.leftRegion(lbnd);
4919
- top = EdgeList.rightRegion(rbnd);
4920
- v = lbnd.vertex;
4921
- Geom.endPoint(lbnd.edge, lbnd.side, v);
4922
- Geom.endPoint(rbnd.edge, rbnd.side, v);
4923
- EdgeList.del(lbnd);
4924
- EventQueue.del(rbnd);
4925
- EdgeList.del(rbnd);
4926
- pm = "l";
4927
- if (bot.y > top.y) {
4928
- temp = bot;
4929
- bot = top;
4930
- top = temp;
4931
- pm = "r";
4932
- }
4933
- e = Geom.bisect(bot, top);
4934
- bisector = EdgeList.createHalfEdge(e, pm);
4935
- EdgeList.insert(llbnd, bisector);
4936
- Geom.endPoint(e, d3_geom_voronoiOpposite[pm], v);
4937
- p = Geom.intersect(llbnd, bisector);
4938
- if (p) {
4939
- EventQueue.del(llbnd);
4940
- EventQueue.insert(llbnd, p, Geom.distance(p, bot));
4941
- }
4942
- p = Geom.intersect(bisector, rrbnd);
4943
- if (p) {
4944
- EventQueue.insert(bisector, p, Geom.distance(p, bot));
4945
- }
5107
+ circle = d3_geom_voronoiFirstCircle;
5108
+ if (site && (!circle || site.y < circle.y || site.y === circle.y && site.x < circle.x)) {
5109
+ if (site.x !== x0 || site.y !== y0) {
5110
+ d3_geom_voronoiCells[site.i] = new d3_geom_voronoiCell(site);
5111
+ d3_geom_voronoiAddBeach(site);
5112
+ x0 = site.x, y0 = site.y;
5113
+ }
5114
+ site = sites.pop();
5115
+ } else if (circle) {
5116
+ d3_geom_voronoiRemoveBeach(circle.arc);
4946
5117
  } else {
4947
5118
  break;
4948
5119
  }
4949
5120
  }
4950
- for (lbnd = EdgeList.right(EdgeList.leftEnd); lbnd != EdgeList.rightEnd; lbnd = EdgeList.right(lbnd)) {
4951
- callback(lbnd.edge);
5121
+ if (bbox) d3_geom_voronoiClipEdges(bbox), d3_geom_voronoiCloseCells(bbox);
5122
+ var diagram = {
5123
+ cells: d3_geom_voronoiCells,
5124
+ edges: d3_geom_voronoiEdges
5125
+ };
5126
+ d3_geom_voronoiBeaches = d3_geom_voronoiCircles = d3_geom_voronoiEdges = d3_geom_voronoiCells = null;
5127
+ return diagram;
5128
+ }
5129
+ function d3_geom_voronoiVertexOrder(a, b) {
5130
+ return b.y - a.y || b.x - a.x;
5131
+ }
5132
+ d3.geom.voronoi = function(points) {
5133
+ var x = d3_svg_lineX, y = d3_svg_lineY, fx = x, fy = y, clipExtent = d3_geom_voronoiClipExtent;
5134
+ if (points) return voronoi(points);
5135
+ function voronoi(data) {
5136
+ var polygons = [];
5137
+ d3_geom_voronoi(sites(data), clipExtent).cells.forEach(function(cell, i) {
5138
+ (polygons[i] = cell.edges.length ? cell.edges.map(function(edge) {
5139
+ var start = edge.start();
5140
+ return [ start.x, start.y ];
5141
+ }) : [ [ clipExtent[0][0], clipExtent[1][1] ], [ clipExtent[1][0], clipExtent[1][1] ], [ clipExtent[1][0], clipExtent[0][1] ], [ clipExtent[0][0], clipExtent[0][1] ] ]).point = data[i];
5142
+ });
5143
+ return polygons;
5144
+ }
5145
+ function sites(data) {
5146
+ return data.map(function(d, i) {
5147
+ return {
5148
+ x: fx(d, i),
5149
+ y: fy(d, i),
5150
+ i: i
5151
+ };
5152
+ });
4952
5153
  }
5154
+ voronoi.links = function(data) {
5155
+ return d3_geom_voronoi(sites(data)).edges.filter(function(edge) {
5156
+ return edge.l && edge.r;
5157
+ }).map(function(edge) {
5158
+ return {
5159
+ source: data[edge.l.i],
5160
+ target: data[edge.r.i]
5161
+ };
5162
+ });
5163
+ };
5164
+ voronoi.triangles = function(data) {
5165
+ var triangles = [];
5166
+ d3_geom_voronoi(sites(data)).cells.forEach(function(cell, i) {
5167
+ var site = cell.site, edges = cell.edges.sort(d3_geom_voronoiHalfEdgeOrder), j = -1, m = edges.length, e0, s0, e1 = edges[m - 1].edge, s1 = e1.l === site ? e1.r : e1.l;
5168
+ while (++j < m) {
5169
+ e0 = e1;
5170
+ s0 = s1;
5171
+ e1 = edges[j].edge;
5172
+ s1 = e1.l === site ? e1.r : e1.l;
5173
+ if (i < s0.i && i < s1.i && d3_geom_voronoiTriangleArea(site, s0, s1) < 0) {
5174
+ triangles.push([ data[i], data[s0.i], data[s1.i] ]);
5175
+ }
5176
+ }
5177
+ });
5178
+ return triangles;
5179
+ };
5180
+ voronoi.x = function(_) {
5181
+ return arguments.length ? (fx = d3_functor(x = _), voronoi) : x;
5182
+ };
5183
+ voronoi.y = function(_) {
5184
+ return arguments.length ? (fy = d3_functor(y = _), voronoi) : y;
5185
+ };
5186
+ voronoi.clipExtent = function(_) {
5187
+ if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent;
5188
+ clipExtent = _ == null ? d3_geom_voronoiClipExtent : _;
5189
+ return voronoi;
5190
+ };
5191
+ voronoi.size = function(_) {
5192
+ if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent && clipExtent[1];
5193
+ return voronoi.clipExtent(_ && [ [ 0, 0 ], _ ]);
5194
+ };
5195
+ return voronoi;
5196
+ };
5197
+ var d3_geom_voronoiClipExtent = [ [ -1e6, -1e6 ], [ 1e6, 1e6 ] ];
5198
+ function d3_geom_voronoiTriangleArea(a, b, c) {
5199
+ return (a.x - c.x) * (b.y - a.y) - (a.x - b.x) * (c.y - a.y);
4953
5200
  }
5201
+ d3.geom.delaunay = function(vertices) {
5202
+ return d3.geom.voronoi().triangles(vertices);
5203
+ };
4954
5204
  d3.geom.quadtree = function(points, x1, y1, x2, y2) {
4955
5205
  var x = d3_svg_lineX, y = d3_svg_lineY, compat;
4956
5206
  if (compat = arguments.length) {
@@ -4996,7 +5246,7 @@ d3 = function() {
4996
5246
  if (n.leaf) {
4997
5247
  var nx = n.x, ny = n.y;
4998
5248
  if (nx != null) {
4999
- if (Math.abs(nx - x) + Math.abs(ny - y) < .01) {
5249
+ if (abs(nx - x) + abs(ny - y) < .01) {
5000
5250
  insertChild(n, d, x, y, x1, y1, x2, y2);
5001
5251
  } else {
5002
5252
  var nPoint = n.point;
@@ -5242,7 +5492,7 @@ d3 = function() {
5242
5492
  var i = name.indexOf("-"), t = i >= 0 ? name.substring(0, i) : name, m = i >= 0 ? name.substring(i + 1) : "in";
5243
5493
  t = d3_ease.get(t) || d3_ease_default;
5244
5494
  m = d3_ease_mode.get(m) || d3_identity;
5245
- return d3_ease_clamp(m(t.apply(null, Array.prototype.slice.call(arguments, 1))));
5495
+ return d3_ease_clamp(m(t.apply(null, d3_arraySlice.call(arguments, 1))));
5246
5496
  };
5247
5497
  function d3_ease_clamp(f) {
5248
5498
  return function(t) {
@@ -5751,7 +6001,7 @@ d3 = function() {
5751
6001
  return force;
5752
6002
  };
5753
6003
  force.start = function() {
5754
- var i, j, n = nodes.length, m = links.length, w = size[0], h = size[1], neighbors, o;
6004
+ var i, n = nodes.length, m = links.length, w = size[0], h = size[1], neighbors, o;
5755
6005
  for (i = 0; i < n; ++i) {
5756
6006
  (o = nodes[i]).index = i;
5757
6007
  o.weight = 0;
@@ -5777,13 +6027,8 @@ d3 = function() {
5777
6027
  charges = [];
5778
6028
  if (typeof charge === "function") for (i = 0; i < n; ++i) charges[i] = +charge.call(this, nodes[i], i); else for (i = 0; i < n; ++i) charges[i] = charge;
5779
6029
  function position(dimension, size) {
5780
- var neighbors = neighbor(i), j = -1, m = neighbors.length, x;
5781
- while (++j < m) if (!isNaN(x = neighbors[j][dimension])) return x;
5782
- return Math.random() * size;
5783
- }
5784
- function neighbor() {
5785
6030
  if (!neighbors) {
5786
- neighbors = [];
6031
+ neighbors = new Array(n);
5787
6032
  for (j = 0; j < n; ++j) {
5788
6033
  neighbors[j] = [];
5789
6034
  }
@@ -5793,7 +6038,9 @@ d3 = function() {
5793
6038
  neighbors[o.target.index].push(o.source);
5794
6039
  }
5795
6040
  }
5796
- return neighbors[i];
6041
+ var candidates = neighbors[i], j = -1, m = candidates.length, x;
6042
+ while (++j < m) if (!isNaN(x = candidates[j][dimension])) return x;
6043
+ return Math.random() * size;
5797
6044
  }
5798
6045
  return force.resume();
5799
6046
  };
@@ -7848,9 +8095,10 @@ d3 = function() {
7848
8095
  };
7849
8096
  ++lock.count;
7850
8097
  d3.timer(function(elapsed) {
7851
- var d = node.__data__, ease = transition.ease, delay = transition.delay, duration = transition.duration, tweened = [];
8098
+ var d = node.__data__, ease = transition.ease, delay = transition.delay, duration = transition.duration, timer = d3_timer_active, tweened = [];
8099
+ timer.t = delay + time;
7852
8100
  if (delay <= elapsed) return start(elapsed - delay);
7853
- d3_timer_replace(start, delay, time);
8101
+ timer.c = start;
7854
8102
  function start(elapsed) {
7855
8103
  if (lock.active > id) return stop();
7856
8104
  lock.active = id;
@@ -7860,8 +8108,10 @@ d3 = function() {
7860
8108
  tweened.push(value);
7861
8109
  }
7862
8110
  });
7863
- if (tick(elapsed || 1)) return 1;
7864
- d3_timer_replace(tick, delay, time);
8111
+ d3.timer(function() {
8112
+ timer.c = tick(elapsed || 1) ? d3_true : tick;
8113
+ return 1;
8114
+ }, 0, time);
7865
8115
  }
7866
8116
  function tick(elapsed) {
7867
8117
  if (lock.active !== id) return stop();
@@ -8765,7 +9015,7 @@ d3 = function() {
8765
9015
  pm: 1
8766
9016
  });
8767
9017
  function d3_time_zone(d) {
8768
- var z = d.getTimezoneOffset(), zs = z > 0 ? "-" : "+", zh = ~~(Math.abs(z) / 60), zm = Math.abs(z) % 60;
9018
+ var z = d.getTimezoneOffset(), zs = z > 0 ? "-" : "+", zh = ~~(abs(z) / 60), zm = abs(z) % 60;
8769
9019
  return zs + d3_time_formatPad(zh, "0", 2) + d3_time_formatPad(zm, "0", 2);
8770
9020
  }
8771
9021
  function d3_time_parseLiteralPercent(date, string, i) {