d3js-plugins-rails 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/lib/d3js-plugins-rails/version.rb +2 -1
  2. data/vendor/assets/javascripts/d3/plugins/Makefile +8 -0
  3. data/vendor/assets/javascripts/d3/plugins/geo/projection/README.md +8 -0
  4. data/vendor/assets/javascripts/d3/plugins/geo/projection/august.js +19 -1
  5. data/vendor/assets/javascripts/d3/plugins/geo/projection/berghaus.js +14 -0
  6. data/vendor/assets/javascripts/d3/plugins/geo/projection/bonne.js +1 -1
  7. data/vendor/assets/javascripts/d3/plugins/geo/projection/conic-conformal.js +11 -1
  8. data/vendor/assets/javascripts/d3/plugins/geo/projection/conic-equidistant.js +3 -1
  9. data/vendor/assets/javascripts/d3/plugins/geo/projection/craig.js +13 -7
  10. data/vendor/assets/javascripts/d3/plugins/geo/projection/eisenlohr.js +70 -9
  11. data/vendor/assets/javascripts/d3/plugins/geo/projection/elliptic.js +115 -0
  12. data/vendor/assets/javascripts/d3/plugins/geo/projection/fahey.js +19 -0
  13. data/vendor/assets/javascripts/d3/plugins/geo/projection/guyou.js +50 -36
  14. data/vendor/assets/javascripts/d3/plugins/geo/projection/hammer-retroazimuthal.js +40 -11
  15. data/vendor/assets/javascripts/d3/plugins/geo/projection/lagrange.js +19 -1
  16. data/vendor/assets/javascripts/d3/plugins/geo/projection/laskowski.js +3 -3
  17. data/vendor/assets/javascripts/d3/plugins/geo/projection/modified-stereographic.js +104 -0
  18. data/vendor/assets/javascripts/d3/plugins/geo/projection/peirce-quincuncial.js +41 -5
  19. data/vendor/assets/javascripts/d3/plugins/geo/projection/polyconic.js +10 -6
  20. data/vendor/assets/javascripts/d3/plugins/geo/projection/projection.js +21 -0
  21. data/vendor/assets/javascripts/d3/plugins/geo/projection/rectangular-polyconic.js +40 -0
  22. data/vendor/assets/javascripts/d3/plugins/geo/projection/test/august-test.js +27 -0
  23. data/vendor/assets/javascripts/d3/plugins/geo/projection/test/berghaus-test.js +26 -0
  24. data/vendor/assets/javascripts/d3/plugins/geo/projection/test/craig-test.js +26 -11
  25. data/vendor/assets/javascripts/d3/plugins/geo/projection/test/eisenlohr-test.js +34 -0
  26. data/vendor/assets/javascripts/d3/plugins/geo/projection/test/env.js +5 -4
  27. data/vendor/assets/javascripts/d3/plugins/geo/projection/test/fahey-test.js +25 -0
  28. data/vendor/assets/javascripts/d3/plugins/geo/projection/test/guyou-test.js +26 -0
  29. data/vendor/assets/javascripts/d3/plugins/geo/projection/test/hammer-retroazimuthal-test.js +39 -0
  30. data/vendor/assets/javascripts/d3/plugins/geo/projection/test/lagrange-test.js +59 -0
  31. data/vendor/assets/javascripts/d3/plugins/geo/projection/test/loximuthal-test.js +1 -1
  32. data/vendor/assets/javascripts/d3/plugins/geo/projection/test/modified-stereographic-test.js +24 -0
  33. data/vendor/assets/javascripts/d3/plugins/geo/projection/test/peirce-quincuncial-test.js +24 -0
  34. data/vendor/assets/javascripts/d3/plugins/geo/projection/test/polyconic-test.js +26 -0
  35. data/vendor/assets/javascripts/d3/plugins/geo/projection/test/rectangular-polyconic-test.js +48 -0
  36. data/vendor/assets/javascripts/d3/plugins/geo/projection/test/times-test.js +24 -0
  37. data/vendor/assets/javascripts/d3/plugins/geo/projection/test/two-point-azimuthal-test.js +22 -0
  38. data/vendor/assets/javascripts/d3/plugins/geo/projection/test/two-point-equidistant-test.js +24 -0
  39. data/vendor/assets/javascripts/d3/plugins/geo/projection/test/van-der-grinten2-test.js +24 -0
  40. data/vendor/assets/javascripts/d3/plugins/geo/projection/test/van-der-grinten3-test.js +24 -0
  41. data/vendor/assets/javascripts/d3/plugins/geo/projection/test/van-der-grinten4-test.js +28 -0
  42. data/vendor/assets/javascripts/d3/plugins/geo/projection/test/wiechel-test.js +24 -0
  43. data/vendor/assets/javascripts/d3/plugins/geo/projection/times.js +19 -0
  44. data/vendor/assets/javascripts/d3/plugins/geo/projection/two-point-azimuthal.js +46 -0
  45. data/vendor/assets/javascripts/d3/plugins/geo/projection/two-point-equidistant.js +23 -5
  46. data/vendor/assets/javascripts/d3/plugins/geo/projection/van-der-grinten2.js +28 -0
  47. data/vendor/assets/javascripts/d3/plugins/geo/projection/van-der-grinten3.js +24 -0
  48. data/vendor/assets/javascripts/d3/plugins/geo/projection/van-der-grinten4.js +37 -5
  49. data/vendor/assets/javascripts/d3/plugins/geo/projection/wiechel.js +12 -0
  50. data/vendor/assets/javascripts/d3/plugins/graph/README.md +6 -7
  51. data/vendor/assets/javascripts/d3/plugins/graph/graph.js +0 -33
  52. data/vendor/assets/javascripts/d3/plugins/graph/index.html +0 -1
  53. data/vendor/assets/javascripts/d3/plugins/keybinding/keybinding.js +189 -112
  54. data/vendor/assets/javascripts/d3/plugins/longscroll/longscroll.js +3 -2
  55. metadata +29 -3
@@ -0,0 +1,24 @@
1
+ require("./env");
2
+
3
+ var vows = require("vows"),
4
+ assert = require("assert");
5
+
6
+ var suite = vows.describe("d3.geo.vanDerGrinten3");
7
+
8
+ suite.addBatch({
9
+ "vanDerGrinten3": {
10
+ topic: d3.geo.vanDerGrinten3,
11
+ "projections and inverse projections": function(vanDerGrinten3) {
12
+ assert.equalInverse(vanDerGrinten3, [ 0, 0], [480, 250]);
13
+ assert.equalInverse(vanDerGrinten3, [ 0, -45], [480, 376.268082]);
14
+ assert.equalInverse(vanDerGrinten3, [ 0, 45], [480, 123.731917]);
15
+ assert.equalInverse(vanDerGrinten3, [-90, 0], [244.380550, 250]);
16
+ assert.equalInverse(vanDerGrinten3, [ 90, 0], [715.619449, 250]);
17
+ assert.equalInverse(vanDerGrinten3, [-80, 15], [271.793387, 210.453529]);
18
+ assert.equalInverse(vanDerGrinten3, [ 1, 1], [482.617913, 247.381925]);
19
+ assert.equalInverse(vanDerGrinten3, [ 15, 45], [516.468521, 123.731917]);
20
+ }
21
+ }
22
+ });
23
+
24
+ suite.export(module);
@@ -0,0 +1,28 @@
1
+ require("./env");
2
+
3
+ var vows = require("vows"),
4
+ assert = require("assert");
5
+
6
+ var suite = vows.describe("d3.geo.vanDerGrinten4");
7
+
8
+ suite.addBatch({
9
+ "vanDerGrinten4": {
10
+ topic: d3.geo.vanDerGrinten4,
11
+ "doesn't generate NaN": function(vanDerGrinten4) {
12
+ assert.inDelta(vanDerGrinten4([20, 1e-7]), [532.359877, 250], 1e-6);
13
+ },
14
+ "projections and inverse projections": function(vanDerGrinten4) {
15
+ assert.equalInverse(vanDerGrinten4, [ 0, 0], [480, 250]);
16
+ assert.equalInverse(vanDerGrinten4, [ 0, -45], [480, 367.809724]);
17
+ assert.equalInverse(vanDerGrinten4, [ 0, 45], [480, 132.190275]);
18
+ assert.equalInverse(vanDerGrinten4, [-90, 0], [244.380550, 250]);
19
+ assert.equalInverse(vanDerGrinten4, [ 90, 0], [715.619449, 250]);
20
+ assert.equalInverse(vanDerGrinten4, [-80, 15], [274.023642, 209.610498]);
21
+ assert.equalInverse(vanDerGrinten4, [ 1, 1], [482.617670, 247.382005]);
22
+ assert.equalInverse(vanDerGrinten4, [ 15, 45], [509.605158, 131.892658]);
23
+ assert.equalInverse(vanDerGrinten4, [-180, 15], [ 12.226093, 204.955105]);
24
+ }
25
+ }
26
+ });
27
+
28
+ suite.export(module);
@@ -0,0 +1,24 @@
1
+ require("./env");
2
+
3
+ var vows = require("vows"),
4
+ assert = require("assert");
5
+
6
+ var suite = vows.describe("d3.geo.wiechel");
7
+
8
+ suite.addBatch({
9
+ "wiechel": {
10
+ topic: d3.geo.wiechel,
11
+ "projections and inverse projections": function(wiechel) {
12
+ assert.equalInverse(wiechel, [ 0, 0], [480, 250]);
13
+ assert.equalInverse(wiechel, [ 0, -45], [436.066017, 356.066017]);
14
+ assert.equalInverse(wiechel, [ 0, 45], [523.933982, 143.933982]);
15
+ assert.equalInverse(wiechel, [-90, 0], [330, 100]);
16
+ assert.equalInverse(wiechel, [ 90, 0], [630, 400]);
17
+ assert.equalInverse(wiechel, [-80, 15], [370.087700, 90.716040]);
18
+ assert.equalInverse(wiechel, [ 1, 1], [482.649770, 247.414442]);
19
+ assert.equalInverse(wiechel, [ 15, 45], [553.483232, 155.847766]);
20
+ }
21
+ }
22
+ });
23
+
24
+ suite.export(module);
@@ -0,0 +1,19 @@
1
+ function times(λ, φ) {
2
+ var t = Math.tan(φ / 2),
3
+ s = Math.sin(π / 4 * t);
4
+ return [
5
+ λ * (.74482 - .34588 * s * s),
6
+ 1.70711 * t
7
+ ];
8
+ }
9
+
10
+ times.invert = function(x, y) {
11
+ var t = y / 1.70711,
12
+ s = Math.sin(π / 4 * t);
13
+ return [
14
+ x / (.74482 - .34588 * s * s),
15
+ 2 * Math.atan(t)
16
+ ];
17
+ };
18
+
19
+ (d3.geo.times = function() { return projection(times); }).raw = times;
@@ -0,0 +1,46 @@
1
+ // @import two-point-equidistant
2
+
3
+ function twoPointAzimuthal(d) {
4
+ var cosd = Math.cos(d);
5
+
6
+ function forward(λ, φ) {
7
+ var coordinates = d3.geo.gnomonic.raw(λ, φ);
8
+ coordinates[0] *= cosd;
9
+ return coordinates;
10
+ }
11
+
12
+ forward.invert = function(x, y) {
13
+ return d3.geo.gnomonic.raw.invert(x / cosd, y);
14
+ };
15
+
16
+ return forward;
17
+ }
18
+
19
+ function twoPointAzimuthalProjection() {
20
+ var points = [[0, 0], [0, 0]],
21
+ m = projectionMutator(twoPointAzimuthal),
22
+ p = m(0),
23
+ rotate = p.rotate;
24
+
25
+ delete p.rotate;
26
+
27
+ p.points = function(_) {
28
+ if (!arguments.length) return points;
29
+ points = _;
30
+
31
+ var interpolate = d3.geo.interpolate(_[0], _[1]),
32
+ origin = interpolate(.5),
33
+ p = twoPointEquidistant_rotate(-origin[0] * radians, -origin[1] * radians, _[0][0] * radians, _[0][1] * radians),
34
+ b = interpolate.distance * .5, // |[0, 0] - p|
35
+ c = (p[0] < 0 ? -1 : +1) * p[1], // |[p[0], 0] - p|
36
+ γ = asin(Math.sin(c) / Math.sin(b));
37
+
38
+ rotate.call(p, [-origin[0], -origin[1], -γ * degrees]);
39
+
40
+ return m(b);
41
+ };
42
+
43
+ return p;
44
+ }
45
+
46
+ (d3.geo.twoPointAzimuthal = twoPointAzimuthalProjection).raw = twoPointAzimuthal;
@@ -5,8 +5,11 @@ function twoPointEquidistant(z0) {
5
5
  if (!z0) return d3.geo.azimuthalEquidistant.raw;
6
6
  var λa = -z0 / 2,
7
7
  λb = -λa,
8
- z02 = z0 * z0;
9
- return function(λ, φ) {
8
+ z02 = z0 * z0,
9
+ tanλ0 = Math.tan(λb),
10
+ S = .5 / Math.sin(λb);
11
+
12
+ function forward(λ, φ) {
10
13
  var za = acos(Math.cos(φ) * Math.cos(λ - λa)),
11
14
  zb = acos(Math.cos(φ) * Math.cos(λ - λb)),
12
15
  ys = φ < 0 ? -1 : 1;
@@ -15,7 +18,21 @@ function twoPointEquidistant(z0) {
15
18
  (za - zb) / (2 * z0),
16
19
  ys * asqrt(4 * z02 * zb - (z02 - za + zb) * (z02 - za + zb)) / (2 * z0)
17
20
  ];
21
+ }
22
+
23
+ forward.invert = function(x, y) {
24
+ var y2 = y * y,
25
+ cosza = Math.cos(Math.sqrt(y2 + (t = x + λa) * t)),
26
+ coszb = Math.cos(Math.sqrt(y2 + (t = x + λb) * t)),
27
+ t,
28
+ d;
29
+ return [
30
+ Math.atan2(d = cosza - coszb, t = (cosza + coszb) * tanλ0),
31
+ (y < 0 ? -1 : 1) * acos(Math.sqrt(t * t + d * d) * S)
32
+ ];
18
33
  };
34
+
35
+ return forward;
19
36
  }
20
37
 
21
38
  function twoPointEquidistantProjection() {
@@ -33,9 +50,10 @@ function twoPointEquidistantProjection() {
33
50
  // Compute the origin as the midpoint of the two reference points.
34
51
  // Rotate one of the reference points by the origin.
35
52
  // Apply the spherical law of sines to compute γ rotation.
36
- var origin = d3.geo.interpolate(_[0], _[1])(.5),
53
+ var interpolate = d3.geo.interpolate(_[0], _[1]),
54
+ origin = interpolate(.5),
37
55
  p = twoPointEquidistant_rotate(-origin[0] * radians, -origin[1] * radians, _[0][0] * radians, _[0][1] * radians),
38
- b = acos(Math.cos(p[1]) * Math.cos(p[0])), // |[0, 0] - p|
56
+ b = interpolate.distance * .5, // |[0, 0] - p|
39
57
  c = (p[0] < 0 ? -1 : +1) * p[1], // |[p[0], 0] - p|
40
58
  γ = asin(Math.sin(c) / Math.sin(b));
41
59
 
@@ -44,7 +62,7 @@ function twoPointEquidistantProjection() {
44
62
  return m(b * 2);
45
63
  };
46
64
 
47
- return p
65
+ return p;
48
66
  }
49
67
 
50
68
  function twoPointEquidistant_rotate(δλ, δφ, λ, φ) {
@@ -0,0 +1,28 @@
1
+ function vanDerGrinten2(λ, φ) {
2
+ if (Math.abs(φ) < ε) return [λ, 0];
3
+ var sinθ = Math.abs(2 * φ / π),
4
+ θ = asin(sinθ);
5
+ if (Math.abs(λ) < ε || Math.abs(Math.abs(φ) - π / 2) < ε) return [0, sgn(φ) * π * Math.tan(θ / 2)];
6
+ var cosθ = Math.cos(θ),
7
+ A = Math.abs(π / λ - λ / π) / 2,
8
+ A2 = A * A,
9
+ x1 = cosθ * (Math.sqrt(1 + A2) - A * cosθ) / (1 + A2 * sinθ * sinθ);
10
+ return [
11
+ sgn(λ) * π * x1,
12
+ sgn(φ) * π * asqrt(1 - x1 * (2 * A + x1))
13
+ ];
14
+ }
15
+
16
+ vanDerGrinten2.invert = function(x, y) {
17
+ if (!x) return [0, π / 2 * Math.sin(2 * Math.atan(y / π))];
18
+ var x1 = Math.abs(x / π),
19
+ A = (1 - x1 * x1 - (y /= π) * y) / (2 * x1),
20
+ A2 = A * A,
21
+ B = Math.sqrt(A2 + 1);
22
+ return [
23
+ sgn(x) * π * (B - A),
24
+ sgn(y) * π / 2 * Math.sin(2 * Math.atan2(Math.sqrt((1 - 2 * A * x1) * (A + B) - x1), Math.sqrt(B + A + x1)))
25
+ ];
26
+ };
27
+
28
+ (d3.geo.vanDerGrinten2 = function() { return projection(vanDerGrinten2); }).raw = vanDerGrinten2;
@@ -0,0 +1,24 @@
1
+ function vanDerGrinten3(λ, φ) {
2
+ if (Math.abs(φ) < ε) return [λ, 0];
3
+ var sinθ = 2 * φ / π,
4
+ θ = asin(sinθ);
5
+ if (Math.abs(λ) < ε || Math.abs(Math.abs(φ) - π / 2) < ε) return [0, π * Math.tan(θ / 2)];
6
+ var A = (π / λ - λ / π) / 2,
7
+ y1 = sinθ / (1 + Math.cos(θ));
8
+ return [
9
+ π * (sgn(λ) * asqrt(A * A + 1 - y1 * y1) - A),
10
+ π * y1
11
+ ];
12
+ }
13
+
14
+ vanDerGrinten3.invert = function(x, y) {
15
+ if (!y) return [x, 0];
16
+ var y1 = y / π,
17
+ A = (π * π * (1 - y1 * y1) - x * x) / (2 * π * x);
18
+ return [
19
+ x ? π * (sgn(x) * Math.sqrt(A * A + 1) - A) : 0,
20
+ π / 2 * Math.sin(2 * Math.atan(y1))
21
+ ];
22
+ };
23
+
24
+ (d3.geo.vanDerGrinten3 = function() { return projection(vanDerGrinten3); }).raw = vanDerGrinten3;
@@ -2,21 +2,53 @@ function vanDerGrinten4(λ, φ) {
2
2
  if (!φ) return [λ, 0];
3
3
  var φ0 = Math.abs(φ);
4
4
  if (!λ || φ0 === π / 2) return [0, φ];
5
- var t,
6
- B = 2 * φ0 / π,
5
+ var B = 2 * φ0 / π,
7
6
  B2 = B * B,
8
7
  C = (8 * B - B2 * (B2 + 2) - 5) / (2 * B2 * (B - 1)),
9
8
  C2 = C * C,
10
9
  BC = B * C,
11
10
  B_C2 = B2 + C2 + 2 * BC,
12
- D = sgn(Math.abs(λ) - π / 2) * Math.sqrt((t = (t = 2 * λ / π) + 1 / t) * t - 4),
11
+ B_3C = B + 3 * C,
12
+ λ0 = 2 * λ / π,
13
+ λ1 = λ0 + 1 / λ0,
14
+ D = sgn(Math.abs(λ) - π / 2) * Math.sqrt(λ1 * λ1 - 4),
13
15
  D2 = D * D,
14
- F = B_C2 * (B2 + C2 * D2 - 1) + (1 - B2) * (B2 * ((t = B + 3 * C) * t + 4 * C2) + 12 * BC * C2 + 4 * C2 * C2),
16
+ F = B_C2 * (B2 + C2 * D2 - 1) + (1 - B2) * (B2 * (B_3C * B_3C + 4 * C2) + 12 * BC * C2 + 4 * C2 * C2),
15
17
  x1 = (D * (B_C2 + C2 - 1) + 2 * Math.sqrt(F)) / (4 * B_C2 + D2);
16
18
  return [
17
19
  sgn(λ) * π * x1 / 2,
18
- sgn(φ) * π / 2 * Math.sqrt(1 + D * Math.abs(x1) - x1 * x1)
20
+ sgn(φ) * π / 2 * asqrt(1 + D * Math.abs(x1) - x1 * x1)
19
21
  ];
20
22
  }
21
23
 
24
+ vanDerGrinten4.invert = function(x, y) {
25
+ if (!x || !y) return [x, y];
26
+ y /= π;
27
+ var x1 = sgn(x) * x * 2 / π,
28
+ D = (x1 * x1 - 1 + 4 * y * y) / Math.abs(x1),
29
+ D2 = D * D,
30
+ B = 2 * y,
31
+ i = 50;
32
+ do {
33
+ var B2 = B * B,
34
+ C = (8 * B - B2 * (B2 + 2) - 5) / (2 * B2 * (B - 1)),
35
+ C_ = (3 * B - B2 * B - 10) / (2 * B2 * B),
36
+ C2 = C * C,
37
+ BC = B * C,
38
+ B_C = B + C,
39
+ B_C2 = B_C * B_C,
40
+ B_3C = B + 3 * C,
41
+ F = B_C2 * (B2 + C2 * D2 - 1) + (1 - B2) * (B2 * (B_3C * B_3C + 4 * C2) + C2 * (12 * BC + 4 * C2)),
42
+ F_ = -2 * B_C * (4 * BC * C2 + (1 - 4 * B2 + 3 * B2 * B2) * (1 + C_) + C2 * (-6 + 14 * B2 - D2 + (-8 + 8 * B2 - 2 * D2) * C_) + BC * (-8 + 12 * B2 + (-10 + 10 * B2 - D2) * C_)),
43
+ sqrtF = Math.sqrt(F),
44
+ f = D * (B_C2 + C2 - 1) + 2 * sqrtF - x1 * (4 * B_C2 + D2),
45
+ f_ = D * (2 * C * C_ + 2 * B_C * (1 + C_)) + F_ / sqrtF - 8 * B_C * (D * (-1 + C2 + B_C2) + 2 * sqrtF) * (1 + C_) / (D2 + 4 * B_C2);
46
+ B -= δ = f / f_;
47
+ } while (δ > ε && --i > 0);
48
+ return [
49
+ sgn(x) * (Math.sqrt(D * D + 4) + D) * π / 4,
50
+ π / 2 * B
51
+ ];
52
+ };
53
+
22
54
  (d3.geo.vanDerGrinten4 = function() { return projection(vanDerGrinten4); }).raw = vanDerGrinten4;
@@ -11,4 +11,16 @@ function wiechel(λ, φ) {
11
11
  ];
12
12
  }
13
13
 
14
+ wiechel.invert = function(x, y) {
15
+ var w = -.5 * (x * x + y * y),
16
+ k = Math.sqrt(-w * (2 + w)),
17
+ b = y * w + x * k,
18
+ a = x * w - y * k,
19
+ D = Math.sqrt(a * a + b * b);
20
+ return [
21
+ Math.atan2(k * b, D * (1 + w)),
22
+ D ? -asin(k * a / D) : 0
23
+ ];
24
+ };
25
+
14
26
  (d3.geo.wiechel = function() { return projection(wiechel); }).raw = wiechel;
@@ -1,6 +1,11 @@
1
1
  # d3.graph
2
2
 
3
- A plugin for manipulating [graph data structures](http://opendatastructures.org/ods-cpp/12_Graphs.html). This plugin is unstable and in development.
3
+ This plugin is not currently in active development.
4
+
5
+ For a more complete set of graph analysis tools, see the work of [Elijah Meeks and Maya Krishnan](http://dhs.stanford.edu/dh/networks/).
6
+
7
+ A plugin for manipulating [graph data structures](http://opendatastructures.org/ods-cpp/12_Graphs.html).
8
+
4
9
 
5
10
  ## Todo
6
11
 
@@ -140,9 +145,3 @@ Get a description of the graph
140
145
  graph.description();
141
146
  // "d3.graph with 3 nodes and 9 links"
142
147
  ```
143
-
144
- Basic node filters. These currently filter the original node set, so subsequent filters won't stack. See [Gremlin](https://github.com/tinkerpop/gremlin/wiki/Basic-Graph-Traversals).
145
-
146
- ```js
147
- graph.traverse().filter(function(d) { return d.indexOf('urp') > -1 }).value();
148
- ```
@@ -27,39 +27,6 @@
27
27
  return this;
28
28
  };
29
29
 
30
- graph.traverse = function() {
31
- var traversal = {},
32
- selected = {}, // selected entities
33
- selected_type;
34
-
35
- traversal.filter = function(f) {
36
- // only works on nodes
37
- if (!arguments.length) return this;
38
- selected = nodes.filter(f);
39
- return this;
40
- };
41
-
42
- traversal.value = function(x) {
43
- if (!arguments.length) {
44
- // reset selection
45
- var result = selected;
46
- selected_type = false;
47
- selected = {};
48
- return result;
49
- }
50
- selected = x;
51
- return this;
52
- };
53
-
54
- traversal.selected_type = function(x) {
55
- if (!arguments.length) return selected_type;
56
- selected_type = x;
57
- return this;
58
- };
59
-
60
- return traversal;
61
- };
62
-
63
30
  return graph;
64
31
  };
65
32
 
@@ -27,7 +27,6 @@
27
27
  console.log('nodes', g.nodes() );
28
28
  console.log('links', g.links() );
29
29
  console.log('matrix', g.matrix() );
30
- console.log('traversal', g.traverse().filter(function(d) { return d.indexOf('urp') > -1 }).value());
31
30
 
32
31
  var m = d3.graph.matrix([
33
32
  [1,1,0],
@@ -1,120 +1,197 @@
1
- d3.keybinding = function() {
2
- // via https://github.com/keithamus/jwerty/
3
- // and https://github.com/madrobby/keymaster
4
- var _keys = {
5
- // MOD aka toggleable keys
6
- mods: {
7
- // Shift key,
8
- '⇧': 16,
9
- // CTRL key, on Mac: ⌃
10
- '⌃': 17,
11
- // ALT key, on Mac: ⌥ (Alt)
12
- '⌥': 18,
13
- // META, on Mac: ⌘ (CMD), on Windows (Win), on Linux (Super)
14
- '⌘': 91
15
- },
16
- // Normal keys
17
- keys: {
18
- // Backspace key, on Mac: ⌫ (Backspace)
19
- '⌫': 8, backspace: 8,
20
- // Tab Key, on Mac: ⇥ (Tab), on Windows ⇥⇥
21
- '⇥': 9, '⇆': 9, tab: 9,
22
- // Return key, ↩
23
- '↩': 13, 'return': 13, enter: 13, '⌅': 13,
24
- // Pause/Break key
25
- 'pause': 19, 'pause-break': 19,
26
- // Caps Lock key, ⇪
27
- '⇪': 20, caps: 20, 'caps-lock': 20,
28
- // Escape key, on Mac: ⎋, on Windows: Esc
29
- '⎋': 27, escape: 27, esc: 27,
30
- // Space key
31
- space: 32,
32
- // Page-Up key, or pgup, on Mac: ↖
33
- '↖': 33, pgup: 33, 'page-up': 33,
34
- // Page-Down key, or pgdown, on Mac: ↘
35
- '↘': 34, pgdown: 34, 'page-down': 34,
36
- // END key, on Mac: ⇟
37
- '⇟': 35, end: 35,
38
- // HOME key, on Mac: ⇞
39
- '⇞': 36, home: 36,
40
- // Insert key, or ins
41
- ins: 45, insert: 45,
42
- // Delete key, on Mac: ⌦ (Delete)
43
- '⌦': 46, del: 46, 'delete': 46,
44
- // Left Arrow Key, or ←
45
- '←': 37, left: 37, 'arrow-left': 37,
46
- // Up Arrow Key, or ↑
47
- '↑': 38, up: 38, 'arrow-up': 38,
48
- // Right Arrow Key, or →
49
- '→': 39, right: 39, 'arrow-right': 39,
50
- // Up Arrow Key, or ↓
51
- '↓': 40, down: 40, 'arrow-down': 40,
52
- // odities, printing characters that come out wrong:
53
- // Num-Multiply, or *
54
- '*': 106, star: 106, asterisk: 106, multiply: 106,
55
- // Num-Plus or +
56
- '+': 107, 'plus': 107,
57
- // Num-Subtract, or -
58
- '-': 109, subtract: 109,
59
- // Semicolon
60
- ';': 186, semicolon:186,
61
- // = or equals
62
- '=': 187, 'equals': 187,
63
- // Comma, or ,
64
- ',': 188, comma: 188,
65
- //'-': 189, //???
66
- // Period, or ., or full-stop
67
- '.': 190, period: 190, 'full-stop': 190,
68
- // Slash, or /, or forward-slash
69
- '/': 191, slash: 191, 'forward-slash': 191,
70
- // Tick, or `, or back-quote
71
- '`': 192, tick: 192, 'back-quote': 192,
72
- // Open bracket, or [
73
- '[': 219, 'open-bracket': 219,
74
- // Back slash, or \
75
- '\\': 220, 'back-slash': 220,
76
- // Close backet, or ]
77
- ']': 221, 'close-bracket': 221,
78
- // Apostraphe, or Quote, or '
79
- '\'': 222, quote: 222, apostraphe: 222
1
+ /*
2
+ * This code is licensed under the MIT license.
3
+ *
4
+ * Copyright © 2013, iD authors.
5
+ *
6
+ * Portions copyright © 2011, Keith Cirkel
7
+ * See https://github.com/keithamus/jwerty
8
+ *
9
+ */
10
+ d3.keybinding = function(namespace) {
11
+ var bindings = [];
12
+
13
+ function matches(binding, event) {
14
+ for (var p in binding.event) {
15
+ if (event[p] != binding.event[p])
16
+ return false;
80
17
  }
81
- };
82
- // To minimise code bloat, add all of the NUMPAD 0-9 keys in a loop
83
- var i = 95, n = 0;
84
- while (++i < 106) _keys.keys['num-' + n] = i; ++n;
85
- // To minimise code bloat, add all of the top row 0-9 keys in a loop
86
- i = 47, n = 0;
87
- while (++i < 58) _keys.keys[n] = i; ++n;
88
- // To minimise code bloat, add all of the F1-F25 keys in a loop
89
- i = 111, n = 1;
90
- while (++i < 136) _keys.keys['f' + n] = i; ++n;
91
- // To minimise code bloat, add all of the letters of the alphabet in a loop
92
- i = 64;
93
- while(++i < 91) _keys.keys[String.fromCharCode(i).toLowerCase()] = i;
94
18
 
95
- var pairs = d3.entries(_keys.keys),
96
- event = d3.dispatch.apply(d3, d3.keys(_keys.keys));
19
+ return (!binding.capture) === (event.eventPhase !== Event.CAPTURING_PHASE);
20
+ }
97
21
 
98
- function keys(selection) {
99
- selection.on('keydown', function () {
100
- var tagName = d3.select(d3.event.target).node().tagName;
101
- if (tagName == 'INPUT' || tagName == 'SELECT' || tagName == 'TEXTAREA') {
102
- return;
22
+ function capture() {
23
+ for (var i = 0; i < bindings.length; i++) {
24
+ var binding = bindings[i];
25
+ if (matches(binding, d3.event)) {
26
+ binding.callback();
103
27
  }
28
+ }
29
+ }
30
+
31
+ function bubble() {
32
+ var tagName = d3.select(d3.event.target).node().tagName;
33
+ if (tagName == 'INPUT' || tagName == 'SELECT' || tagName == 'TEXTAREA') {
34
+ return;
35
+ }
36
+ capture();
37
+ }
104
38
 
105
- var modifiers = '';
106
- if (d3.event.shiftKey) modifiers += '⇧';
107
- if (d3.event.ctrlKey) modifiers += '⌃';
108
- if (d3.event.altKey) modifiers += '⌥';
109
- if (d3.event.metaKey) modifiers += '⌘';
110
-
111
- pairs.filter(function(d) {
112
- return d.value === d3.event.keyCode;
113
- }).forEach(function(d) {
114
- event[d.key](d3.event, modifiers);
115
- });
116
- });
39
+ function keybinding(selection) {
40
+ selection = selection || d3.select(document);
41
+ selection.on('keydown.capture' + namespace, capture, true);
42
+ selection.on('keydown.bubble' + namespace, bubble, false);
43
+ return keybinding;
117
44
  }
118
45
 
119
- return d3.rebind(keys, event, 'on');
46
+ keybinding.off = function(selection) {
47
+ selection = selection || d3.select(document);
48
+ selection.on('keydown.capture' + namespace, null);
49
+ selection.on('keydown.bubble' + namespace, null);
50
+ return keybinding;
51
+ };
52
+
53
+ keybinding.on = function(code, callback, capture) {
54
+ var binding = {
55
+ event: {
56
+ keyCode: 0,
57
+ shiftKey: false,
58
+ ctrlKey: false,
59
+ altKey: false,
60
+ metaKey: false
61
+ },
62
+ capture: capture,
63
+ callback: callback
64
+ };
65
+
66
+ code = code.toLowerCase().match(/(?:(?:[^+])+|\+\+|^\+$)/g);
67
+
68
+ for (var i = 0; i < code.length; i++) {
69
+ // Normalise matching errors
70
+ if (code[i] === '++') code[i] = '+';
71
+
72
+ if (code[i] in d3.keybinding.modifierCodes) {
73
+ binding.event[d3.keybinding.modifierProperties[d3.keybinding.modifierCodes[code[i]]]] = true;
74
+ } else if (code[i] in d3.keybinding.keyCodes) {
75
+ binding.event.keyCode = d3.keybinding.keyCodes[code[i]];
76
+ }
77
+ }
78
+
79
+ bindings.push(binding);
80
+
81
+ return keybinding;
82
+ };
83
+
84
+ return keybinding;
120
85
  };
86
+
87
+ (function () {
88
+ d3.keybinding.modifierCodes = {
89
+ // Shift key, ⇧
90
+ '⇧': 16, shift: 16,
91
+ // CTRL key, on Mac: ⌃
92
+ '⌃': 17, ctrl: 17,
93
+ // ALT key, on Mac: ⌥ (Alt)
94
+ '⌥': 18, alt: 18, option: 18,
95
+ // META, on Mac: ⌘ (CMD), on Windows (Win), on Linux (Super)
96
+ '⌘': 91, meta: 91, cmd: 91, 'super': 91, win: 91
97
+ };
98
+
99
+ d3.keybinding.modifierProperties = {
100
+ 16: 'shiftKey',
101
+ 17: 'ctrlKey',
102
+ 18: 'altKey',
103
+ 91: 'metaKey'
104
+ };
105
+
106
+ d3.keybinding.keyCodes = {
107
+ // Backspace key, on Mac: ⌫ (Backspace)
108
+ '⌫': 8, backspace: 8,
109
+ // Tab Key, on Mac: ⇥ (Tab), on Windows ⇥⇥
110
+ '⇥': 9, '⇆': 9, tab: 9,
111
+ // Return key, ↩
112
+ '↩': 13, 'return': 13, enter: 13, '⌅': 13,
113
+ // Pause/Break key
114
+ 'pause': 19, 'pause-break': 19,
115
+ // Caps Lock key, ⇪
116
+ '⇪': 20, caps: 20, 'caps-lock': 20,
117
+ // Escape key, on Mac: ⎋, on Windows: Esc
118
+ '⎋': 27, escape: 27, esc: 27,
119
+ // Space key
120
+ space: 32,
121
+ // Page-Up key, or pgup, on Mac: ↖
122
+ '↖': 33, pgup: 33, 'page-up': 33,
123
+ // Page-Down key, or pgdown, on Mac: ↘
124
+ '↘': 34, pgdown: 34, 'page-down': 34,
125
+ // END key, on Mac: ⇟
126
+ '⇟': 35, end: 35,
127
+ // HOME key, on Mac: ⇞
128
+ '⇞': 36, home: 36,
129
+ // Insert key, or ins
130
+ ins: 45, insert: 45,
131
+ // Delete key, on Mac: ⌦ (Delete)
132
+ '⌦': 46, del: 46, 'delete': 46,
133
+ // Left Arrow Key, or ←
134
+ '←': 37, left: 37, 'arrow-left': 37,
135
+ // Up Arrow Key, or ↑
136
+ '↑': 38, up: 38, 'arrow-up': 38,
137
+ // Right Arrow Key, or →
138
+ '→': 39, right: 39, 'arrow-right': 39,
139
+ // Up Arrow Key, or ↓
140
+ '↓': 40, down: 40, 'arrow-down': 40,
141
+ // odities, printing characters that come out wrong:
142
+ // Num-Multiply, or *
143
+ '*': 106, star: 106, asterisk: 106, multiply: 106,
144
+ // Num-Plus or +
145
+ '+': 107, 'plus': 107,
146
+ // Num-Subtract, or -
147
+ '-': 109, subtract: 109,
148
+ // Semicolon
149
+ ';': 186, semicolon:186,
150
+ // = or equals
151
+ '=': 187, 'equals': 187,
152
+ // Comma, or ,
153
+ ',': 188, comma: 188,
154
+ //'-': 189, //???
155
+ // Period, or ., or full-stop
156
+ '.': 190, period: 190, 'full-stop': 190,
157
+ // Slash, or /, or forward-slash
158
+ '/': 191, slash: 191, 'forward-slash': 191,
159
+ // Tick, or `, or back-quote
160
+ '`': 192, tick: 192, 'back-quote': 192,
161
+ // Open bracket, or [
162
+ '[': 219, 'open-bracket': 219,
163
+ // Back slash, or \
164
+ '\\': 220, 'back-slash': 220,
165
+ // Close backet, or ]
166
+ ']': 221, 'close-bracket': 221,
167
+ // Apostrophe, or Quote, or '
168
+ '\'': 222, quote: 222, apostrophe: 222
169
+ };
170
+
171
+ // NUMPAD 0-9
172
+ var i = 95, n = 0;
173
+ while (++i < 106) {
174
+ d3.keybinding.keyCodes['num-' + n] = i;
175
+ ++n;
176
+ }
177
+
178
+ // 0-9
179
+ i = 47; n = 0;
180
+ while (++i < 58) {
181
+ d3.keybinding.keyCodes[n] = i;
182
+ ++n;
183
+ }
184
+
185
+ // F1-F25
186
+ i = 111; n = 1;
187
+ while (++i < 136) {
188
+ d3.keybinding.keyCodes['f' + n] = i;
189
+ ++n;
190
+ }
191
+
192
+ // a-z
193
+ i = 64;
194
+ while (++i < 91) {
195
+ d3.keybinding.keyCodes[String.fromCharCode(i).toLowerCase()] = i;
196
+ }
197
+ })();