d3js-plugins-rails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +28 -0
- data/Rakefile +1 -0
- data/d3js-plugins-rails.gemspec +21 -0
- data/lib/d3js-plugins-rails/version.rb +7 -0
- data/lib/d3js-plugins-rails.rb +10 -0
- data/vendor/assets/javascripts/d3/plugins/.gitignore +1 -0
- data/vendor/assets/javascripts/d3/plugins/LICENSE +26 -0
- data/vendor/assets/javascripts/d3/plugins/Makefile +87 -0
- data/vendor/assets/javascripts/d3/plugins/README.md +19 -0
- data/vendor/assets/javascripts/d3/plugins/box/box.js +301 -0
- data/vendor/assets/javascripts/d3/plugins/bullet/README.md +14 -0
- data/vendor/assets/javascripts/d3/plugins/bullet/bullet.js +241 -0
- data/vendor/assets/javascripts/d3/plugins/chernoff/README.md +15 -0
- data/vendor/assets/javascripts/d3/plugins/chernoff/chernoff.js +176 -0
- data/vendor/assets/javascripts/d3/plugins/cie/README.md +54 -0
- data/vendor/assets/javascripts/d3/plugins/cie/cie.js +155 -0
- data/vendor/assets/javascripts/d3/plugins/fisheye/README.md +43 -0
- data/vendor/assets/javascripts/d3/plugins/fisheye/fisheye.js +85 -0
- data/vendor/assets/javascripts/d3/plugins/force_labels/README.md +29 -0
- data/vendor/assets/javascripts/d3/plugins/force_labels/force_labels.js +56 -0
- data/vendor/assets/javascripts/d3/plugins/geo/polyhedron/README.md +7 -0
- data/vendor/assets/javascripts/d3/plugins/geo/polyhedron/polyhedron.js +436 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/README.md +107 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/aitoff.js +40 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/armadillo.js +79 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/august.js +15 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/baker.js +28 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/berghaus.js +60 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/boggs.js +27 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/bonne.js +29 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/bromley.js +5 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/collignon.js +17 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/conic-conformal.js +29 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/conic-equidistant.js +27 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/craig.js +24 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/craster.js +18 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/cylindrical-equal-area.js +23 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/eckert1.js +18 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/eckert2.js +17 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/eckert3.js +17 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/eckert4.js +24 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/eckert5.js +17 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/eckert6.js +22 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/eisenlohr.js +16 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/end.js +1 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/gringorten.js +111 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/guyou.js +46 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/hammer-retroazimuthal.js +75 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/hammer.js +51 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/hatano.js +25 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/healpix.js +64 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/hill.js +64 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/homolosine.js +17 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/interrupt.js +111 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/kavrayskiy7.js +15 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/lagrange.js +27 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/larrivee.js +39 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/laskowski.js +31 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/littrow.js +21 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/loximuthal.js +29 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/miller.js +15 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/mollweide.js +35 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/mt-flat-polar-parabolic.js +21 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/mt-flat-polar-quartic.js +23 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/mt-flat-polar-sinusoidal.js +25 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/natural-earth.js +22 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/nell-hammer.js +20 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/parallel1.js +12 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/parallel2.js +13 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/peirce-quincuncial.js +14 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/polyconic.js +25 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/projection.js +29 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/robinson.js +83 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/satellite.js +68 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/sinu-mollweide.js +19 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/sinusoidal.js +15 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/start.js +1 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/test/aitoff-test.js +26 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/test/armadillo-test.js +28 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/test/baker-test.js +26 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/test/boggs-test.js +26 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/test/bonne-test.js +45 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/test/craig-test.js +25 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/test/craster-test.js +25 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/test/env.js +32 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/test/equirectangular-test.js +97 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/test/hammer-test.js +29 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/test/hatano-test.js +25 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/test/hill-test.js +26 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/test/larrivee-test.js +25 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/test/laskowski-test.js +26 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/test/littrow-test.js +24 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/test/loximuthal-test.js +25 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/test/mollweide-test.js +26 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/test/mt-flat-polar-parabolic-test.js +25 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/test/mt-flat-polar-quartic-test.js +25 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/test/mt-flat-polar-sinusoidal-test.js +25 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/test/natural-earth-test.js +26 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/test/quartic-authalic-test.js +0 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/test/robinson-test.js +26 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/test/wagner6-test.js +25 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/test/winkel3-test.js +26 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/van-der-grinten.js +41 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/van-der-grinten4.js +22 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/wagner4.js +9 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/wagner6.js +15 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/wagner7.js +22 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/wiechel.js +14 -0
- data/vendor/assets/javascripts/d3/plugins/geo/projection/winkel3.js +40 -0
- data/vendor/assets/javascripts/d3/plugins/geo/tile/README.md +6 -0
- data/vendor/assets/javascripts/d3/plugins/geo/tile/tile.js +53 -0
- data/vendor/assets/javascripts/d3/plugins/geodesic/README.md +3 -0
- data/vendor/assets/javascripts/d3/plugins/geodesic/geodesic.js +130 -0
- data/vendor/assets/javascripts/d3/plugins/geom/contour/README.md +5 -0
- data/vendor/assets/javascripts/d3/plugins/geom/contour/contour.js +72 -0
- data/vendor/assets/javascripts/d3/plugins/graph/README.md +148 -0
- data/vendor/assets/javascripts/d3/plugins/graph/data/cities-matrix.json +37 -0
- data/vendor/assets/javascripts/d3/plugins/graph/data/cities.csv +36 -0
- data/vendor/assets/javascripts/d3/plugins/graph/data/miserables.json +338 -0
- data/vendor/assets/javascripts/d3/plugins/graph/graph.js +161 -0
- data/vendor/assets/javascripts/d3/plugins/graph/index.html +37 -0
- data/vendor/assets/javascripts/d3/plugins/hexbin/README.md +58 -0
- data/vendor/assets/javascripts/d3/plugins/hexbin/hexbin.js +96 -0
- data/vendor/assets/javascripts/d3/plugins/hive/README.md +5 -0
- data/vendor/assets/javascripts/d3/plugins/hive/hive.js +80 -0
- data/vendor/assets/javascripts/d3/plugins/horizon/README.md +11 -0
- data/vendor/assets/javascripts/d3/plugins/horizon/horizon.js +192 -0
- data/vendor/assets/javascripts/d3/plugins/interpolate-zoom/README.md +11 -0
- data/vendor/assets/javascripts/d3/plugins/interpolate-zoom/interpolate-zoom.js +75 -0
- data/vendor/assets/javascripts/d3/plugins/jsonp/README.md +26 -0
- data/vendor/assets/javascripts/d3/plugins/jsonp/jsonp.js +25 -0
- data/vendor/assets/javascripts/d3/plugins/keybinding/README.md +17 -0
- data/vendor/assets/javascripts/d3/plugins/keybinding/keybinding.js +120 -0
- data/vendor/assets/javascripts/d3/plugins/longscroll/README.md +10 -0
- data/vendor/assets/javascripts/d3/plugins/longscroll/longscroll.js +75 -0
- data/vendor/assets/javascripts/d3/plugins/package.json +20 -0
- data/vendor/assets/javascripts/d3/plugins/qq/README.md +3 -0
- data/vendor/assets/javascripts/d3/plugins/qq/qq.js +249 -0
- data/vendor/assets/javascripts/d3/plugins/rollup/README.md +5 -0
- data/vendor/assets/javascripts/d3/plugins/rollup/rollup.js +131 -0
- data/vendor/assets/javascripts/d3/plugins/sankey/README.md +17 -0
- data/vendor/assets/javascripts/d3/plugins/sankey/sankey.js +292 -0
- data/vendor/assets/javascripts/d3/plugins/simplify/README.md +6 -0
- data/vendor/assets/javascripts/d3/plugins/simplify/simplify-test.js +193 -0
- data/vendor/assets/javascripts/d3/plugins/simplify/simplify.js +446 -0
- data/vendor/assets/javascripts/d3/plugins/superformula/superformula.js +98 -0
- data/vendor/assets/javascripts/d3/plugins/urlencode/urlencode-test.js +68 -0
- data/vendor/assets/javascripts/d3/plugins/urlencode/urlencode.js +37 -0
- metadata +218 -0
@@ -0,0 +1,14 @@
|
|
1
|
+
function wiechel(λ, φ) {
|
2
|
+
var cosφ = Math.cos(φ),
|
3
|
+
sinφ = Math.cos(λ) * cosφ,
|
4
|
+
sin1_φ = 1 - sinφ,
|
5
|
+
cosλ = Math.cos(λ = Math.atan2(Math.sin(λ) * cosφ, -Math.sin(φ))),
|
6
|
+
sinλ = Math.sin(λ);
|
7
|
+
cosφ = asqrt(1 - sinφ * sinφ);
|
8
|
+
return [
|
9
|
+
sinλ * cosφ - cosλ * sin1_φ,
|
10
|
+
-cosλ * cosφ - sinλ * sin1_φ
|
11
|
+
];
|
12
|
+
}
|
13
|
+
|
14
|
+
(d3.geo.wiechel = function() { return projection(wiechel); }).raw = wiechel;
|
@@ -0,0 +1,40 @@
|
|
1
|
+
// @import aitoff
|
2
|
+
|
3
|
+
function winkel3(λ, φ) {
|
4
|
+
var coordinates = aitoff(λ, φ);
|
5
|
+
return [
|
6
|
+
(coordinates[0] + λ * 2 / π) / 2,
|
7
|
+
(coordinates[1] + φ) / 2
|
8
|
+
];
|
9
|
+
}
|
10
|
+
|
11
|
+
winkel3.invert = function(x, y) {
|
12
|
+
var λ = x, φ = y, i = 25;
|
13
|
+
do {
|
14
|
+
var cosφ = Math.cos(φ),
|
15
|
+
sinφ = Math.sin(φ),
|
16
|
+
sin_2φ = Math.sin(2 * φ),
|
17
|
+
sin2φ = sinφ * sinφ,
|
18
|
+
cos2φ = cosφ * cosφ,
|
19
|
+
sinλ = Math.sin(λ),
|
20
|
+
cosλ_2 = Math.cos(λ / 2),
|
21
|
+
sinλ_2 = Math.sin(λ / 2),
|
22
|
+
sin2λ_2 = sinλ_2 * sinλ_2,
|
23
|
+
C = 1 - cos2φ * cosλ_2 * cosλ_2,
|
24
|
+
E = C ? acos(cosφ * cosλ_2) * Math.sqrt(F = 1 / C) : F = 0,
|
25
|
+
F,
|
26
|
+
fx = .5 * (2 * E * cosφ * sinλ_2 + λ * 2 / π) - x,
|
27
|
+
fy = .5 * (E * sinφ + φ) - y,
|
28
|
+
δxδλ = .5 * F * (cos2φ * sin2λ_2 + E * cosφ * cosλ_2 * sin2φ) + .5 * 2 / π,
|
29
|
+
δxδφ = F * (sinλ * sin_2φ / 4 - E * sinφ * sinλ_2),
|
30
|
+
δyδλ = .125 * F * (sin_2φ * sinλ_2 - E * sinφ * cos2φ * sinλ),
|
31
|
+
δyδφ = .5 * F * (sin2φ * cosλ_2 + E * sin2λ_2 * cosφ) + .5,
|
32
|
+
denominator = δxδφ * δyδλ - δyδφ * δxδλ,
|
33
|
+
δλ = (fy * δxδφ - fx * δyδφ) / denominator,
|
34
|
+
δφ = (fx * δyδλ - fy * δxδλ) / denominator;
|
35
|
+
λ -= δλ, φ -= δφ;
|
36
|
+
} while ((Math.abs(δλ) > ε || Math.abs(δφ) > ε) && --i > 0);
|
37
|
+
return [λ, φ];
|
38
|
+
};
|
39
|
+
|
40
|
+
(d3.geo.winkel3 = function() { return projection(winkel3); }).raw = winkel3;
|
@@ -0,0 +1,6 @@
|
|
1
|
+
# Zoomable Tiles
|
2
|
+
|
3
|
+
* Panning & Zooming Demo: <http://bl.ocks.org/4132797>
|
4
|
+
* Clipping Demo: <http://bl.ocks.org/4150951>
|
5
|
+
|
6
|
+
A layout for determining which 256x256 quadtree tiles to display in a rectangular viewport, based on a scale and translate. This layout can be used to create a simple slippy map, or render standard map tiles (e.g., MapBox, CloudMade) as a base layer behind a geographic projection.
|
@@ -0,0 +1,53 @@
|
|
1
|
+
d3.geo.tile = function() {
|
2
|
+
var size = [960, 500],
|
3
|
+
scale = 256,
|
4
|
+
translate = [size[0] / 2, size[1] / 2],
|
5
|
+
zoomDelta = 0;
|
6
|
+
|
7
|
+
function tile() {
|
8
|
+
var z = Math.max(Math.log(scale) / Math.LN2 - 8, 0),
|
9
|
+
z0 = Math.round(z + zoomDelta),
|
10
|
+
k = Math.pow(2, z - z0 + 8),
|
11
|
+
origin = [(translate[0] - scale / 2) / k, (translate[1] - scale / 2) / k],
|
12
|
+
tiles = [],
|
13
|
+
cols = d3.range(Math.max(0, Math.floor(-origin[0])), Math.max(0, Math.ceil(size[0] / k - origin[0]))),
|
14
|
+
rows = d3.range(Math.max(0, Math.floor(-origin[1])), Math.max(0, Math.ceil(size[1] / k - origin[1])));
|
15
|
+
|
16
|
+
rows.forEach(function(y) {
|
17
|
+
cols.forEach(function(x) {
|
18
|
+
tiles.push([x, y, z0]);
|
19
|
+
});
|
20
|
+
});
|
21
|
+
|
22
|
+
tiles.translate = origin;
|
23
|
+
tiles.scale = k;
|
24
|
+
|
25
|
+
return tiles;
|
26
|
+
}
|
27
|
+
|
28
|
+
tile.size = function(_) {
|
29
|
+
if (!arguments.length) return size;
|
30
|
+
size = _;
|
31
|
+
return tile;
|
32
|
+
};
|
33
|
+
|
34
|
+
tile.scale = function(_) {
|
35
|
+
if (!arguments.length) return scale;
|
36
|
+
scale = _;
|
37
|
+
return tile;
|
38
|
+
};
|
39
|
+
|
40
|
+
tile.translate = function(_) {
|
41
|
+
if (!arguments.length) return translate;
|
42
|
+
translate = _;
|
43
|
+
return tile;
|
44
|
+
};
|
45
|
+
|
46
|
+
tile.zoomDelta = function(_) {
|
47
|
+
if (!arguments.length) return zoomDelta;
|
48
|
+
zoomDelta = +_;
|
49
|
+
return tile;
|
50
|
+
};
|
51
|
+
|
52
|
+
return tile;
|
53
|
+
};
|
@@ -0,0 +1,130 @@
|
|
1
|
+
(function() {
|
2
|
+
var φ = 1.618033988749895,
|
3
|
+
ρ = 180 / Math.PI;
|
4
|
+
|
5
|
+
var vertices = [
|
6
|
+
[1,φ,0], [-1,φ,0], [1,-φ,0], [-1,-φ,0],
|
7
|
+
[0,1,φ], [0,-1,φ], [0,1,-φ], [0,-1,-φ],
|
8
|
+
[φ,0,1], [-φ,0,1], [φ,0,-1], [-φ,0,-1]
|
9
|
+
];
|
10
|
+
|
11
|
+
var faces = [
|
12
|
+
[0,1,4], [1,9,4], [4,9,5], [5,9,3], [2,3,7],
|
13
|
+
[3,2,5], [7,10,2], [0,8,10], [0,4,8], [8,2,10],
|
14
|
+
[8,4,5], [8,5,2], [1,0,6], [11,1,6], [3,9,11],
|
15
|
+
[6,10,7], [3,11,7], [11,6,7], [6,0,10], [9,1,11]
|
16
|
+
].map(function(face) {
|
17
|
+
return face.map(function(i) {
|
18
|
+
return vertices[i];
|
19
|
+
});
|
20
|
+
});
|
21
|
+
|
22
|
+
d3.geodesic = {
|
23
|
+
multipolygon: function(n) {
|
24
|
+
return {
|
25
|
+
type: "MultiPolygon",
|
26
|
+
coordinates: subdivideFaces(~~n).map(function(face) {
|
27
|
+
face = face.map(project);
|
28
|
+
face.push(face[0]);
|
29
|
+
return [face];
|
30
|
+
})
|
31
|
+
};
|
32
|
+
},
|
33
|
+
polygons: function(n) {
|
34
|
+
return d3.geodesic.multipolygon(~~n).coordinates.map(function(face) {
|
35
|
+
return {type: "Polygon", coordinates: face};
|
36
|
+
});
|
37
|
+
},
|
38
|
+
multilinestring: function(n) {
|
39
|
+
return {
|
40
|
+
type: "MultiLineString",
|
41
|
+
coordinates: subdivideEdges(~~n).map(function(edge) {
|
42
|
+
return edge.map(project);
|
43
|
+
})
|
44
|
+
};
|
45
|
+
}
|
46
|
+
};
|
47
|
+
|
48
|
+
function subdivideFaces(n) {
|
49
|
+
return d3.merge(faces.map(function(face) {
|
50
|
+
var i01 = interpolate(face[0], face[1]),
|
51
|
+
i02 = interpolate(face[0], face[2]),
|
52
|
+
faces = [];
|
53
|
+
|
54
|
+
faces.push([
|
55
|
+
face[0],
|
56
|
+
i01(1 / n),
|
57
|
+
i02(1 / n)
|
58
|
+
]);
|
59
|
+
|
60
|
+
for (var i = 1; i < n; ++i) {
|
61
|
+
var i1 = interpolate(i01(i / n), i02(i / n)),
|
62
|
+
i2 = interpolate(i01((i + 1) / n), i02((i + 1) / n));
|
63
|
+
for (var j = 0; j <= i; ++j) {
|
64
|
+
faces.push([
|
65
|
+
i1(j / i),
|
66
|
+
i2(j / (i + 1)),
|
67
|
+
i2((j + 1) / (i + 1))
|
68
|
+
]);
|
69
|
+
}
|
70
|
+
for (var j = 0; j < i; ++j) {
|
71
|
+
faces.push([
|
72
|
+
i1(j / i),
|
73
|
+
i1((j + 1) / i),
|
74
|
+
i2((j + 1) / (i + 1))
|
75
|
+
]);
|
76
|
+
}
|
77
|
+
}
|
78
|
+
|
79
|
+
return faces;
|
80
|
+
}));
|
81
|
+
}
|
82
|
+
|
83
|
+
function subdivideEdges(n) {
|
84
|
+
var edges = {};
|
85
|
+
|
86
|
+
subdivideFaces(n).forEach(function(face) {
|
87
|
+
add(face[0], face[1]);
|
88
|
+
add(face[1], face[2]);
|
89
|
+
add(face[2], face[0]);
|
90
|
+
});
|
91
|
+
|
92
|
+
function add(p0, p1) {
|
93
|
+
var t;
|
94
|
+
if (p0[0] < p1[0] || (p0[0] == p1[0] && (p0[1] < p1[1] || (p0[1] == p1[1] && p0[2] < p1[2])))) t = p0, p0 = p1, p1 = t;
|
95
|
+
edges[p0.map(round) + " " + p1.map(round)] = [p0, p1];
|
96
|
+
}
|
97
|
+
|
98
|
+
function round(d) {
|
99
|
+
return d3.round(d, 4);
|
100
|
+
}
|
101
|
+
|
102
|
+
return d3.values(edges);
|
103
|
+
}
|
104
|
+
|
105
|
+
function interpolate(p0, p1) {
|
106
|
+
var x0 = p0[0],
|
107
|
+
y0 = p0[1],
|
108
|
+
z0 = p0[2],
|
109
|
+
x1 = p1[0] - x0,
|
110
|
+
y1 = p1[1] - y0,
|
111
|
+
z1 = p1[2] - z0;
|
112
|
+
return function(t) {
|
113
|
+
return [
|
114
|
+
x0 + t * x1,
|
115
|
+
y0 + t * y1,
|
116
|
+
z0 + t * z1
|
117
|
+
];
|
118
|
+
};
|
119
|
+
}
|
120
|
+
|
121
|
+
function project(p) {
|
122
|
+
var x = p[0],
|
123
|
+
y = p[1],
|
124
|
+
z = p[2];
|
125
|
+
return [
|
126
|
+
Math.atan2(y, x) * ρ,
|
127
|
+
Math.acos(z / Math.sqrt(x * x + y * y + z * z)) * ρ - 90
|
128
|
+
];
|
129
|
+
}
|
130
|
+
})();
|
@@ -0,0 +1,5 @@
|
|
1
|
+
# Contour Plots
|
2
|
+
|
3
|
+
Demo: <http://bl.ocks.org/4241134>
|
4
|
+
|
5
|
+
Computes a contour for a given *grid function* using the [marching squares](http://en.wikipedia.org/wiki/Marching_squares) algorithm. Returns the contour polygon as an array of points. The grid function takes two arguments, *x* and *y*, and returns true if the specified point is inside the contour, and false for points outside the contour. The contour plugin can also take an optional starting point [x, y] on the grid.
|
@@ -0,0 +1,72 @@
|
|
1
|
+
(function() {
|
2
|
+
|
3
|
+
d3.geom.contour = function(grid, start) {
|
4
|
+
var s = start || d3_geom_contourStart(grid), // starting point
|
5
|
+
c = [], // contour polygon
|
6
|
+
x = s[0], // current x position
|
7
|
+
y = s[1], // current y position
|
8
|
+
dx = 0, // next x direction
|
9
|
+
dy = 0, // next y direction
|
10
|
+
pdx = NaN, // previous x direction
|
11
|
+
pdy = NaN, // previous y direction
|
12
|
+
i = 0;
|
13
|
+
|
14
|
+
do {
|
15
|
+
// determine marching squares index
|
16
|
+
i = 0;
|
17
|
+
if (grid(x-1, y-1)) i += 1;
|
18
|
+
if (grid(x, y-1)) i += 2;
|
19
|
+
if (grid(x-1, y )) i += 4;
|
20
|
+
if (grid(x, y )) i += 8;
|
21
|
+
|
22
|
+
// determine next direction
|
23
|
+
if (i === 6) {
|
24
|
+
dx = pdy === -1 ? -1 : 1;
|
25
|
+
dy = 0;
|
26
|
+
} else if (i === 9) {
|
27
|
+
dx = 0;
|
28
|
+
dy = pdx === 1 ? -1 : 1;
|
29
|
+
} else {
|
30
|
+
dx = d3_geom_contourDx[i];
|
31
|
+
dy = d3_geom_contourDy[i];
|
32
|
+
}
|
33
|
+
|
34
|
+
// update contour polygon
|
35
|
+
if (dx != pdx && dy != pdy) {
|
36
|
+
c.push([x, y]);
|
37
|
+
pdx = dx;
|
38
|
+
pdy = dy;
|
39
|
+
}
|
40
|
+
|
41
|
+
x += dx;
|
42
|
+
y += dy;
|
43
|
+
} while (s[0] != x || s[1] != y);
|
44
|
+
|
45
|
+
return c;
|
46
|
+
};
|
47
|
+
|
48
|
+
// lookup tables for marching directions
|
49
|
+
var d3_geom_contourDx = [1, 0, 1, 1,-1, 0,-1, 1,0, 0,0,0,-1, 0,-1,NaN],
|
50
|
+
d3_geom_contourDy = [0,-1, 0, 0, 0,-1, 0, 0,1,-1,1,1, 0,-1, 0,NaN];
|
51
|
+
|
52
|
+
function d3_geom_contourStart(grid) {
|
53
|
+
var x = 0,
|
54
|
+
y = 0;
|
55
|
+
|
56
|
+
// search for a starting point; begin at origin
|
57
|
+
// and proceed along outward-expanding diagonals
|
58
|
+
while (true) {
|
59
|
+
if (grid(x,y)) {
|
60
|
+
return [x,y];
|
61
|
+
}
|
62
|
+
if (x === 0) {
|
63
|
+
x = y + 1;
|
64
|
+
y = 0;
|
65
|
+
} else {
|
66
|
+
x = x - 1;
|
67
|
+
y = y + 1;
|
68
|
+
}
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
})();
|
@@ -0,0 +1,148 @@
|
|
1
|
+
# d3.graph
|
2
|
+
|
3
|
+
A plugin for manipulating [graph data structures](http://opendatastructures.org/ods-cpp/12_Graphs.html). This plugin is unstable and in development.
|
4
|
+
|
5
|
+
## Todo
|
6
|
+
|
7
|
+
* link nodes by name. see this [discussion on the force layout](https://groups.google.com/forum/?fromgroups#!topic/d3-js/LWuhBeEipz4)
|
8
|
+
|
9
|
+
* adjacency list
|
10
|
+
* graph traversal
|
11
|
+
* hypergraph
|
12
|
+
|
13
|
+
## Matrix
|
14
|
+
|
15
|
+
Create a matrix
|
16
|
+
|
17
|
+
```js
|
18
|
+
var matrix = d3.graph.matrix([
|
19
|
+
[1,1,0],
|
20
|
+
[0,0,0],
|
21
|
+
[2,1,1]
|
22
|
+
]);
|
23
|
+
```
|
24
|
+
|
25
|
+
Get an edge value
|
26
|
+
|
27
|
+
```js
|
28
|
+
matrix(i,j)
|
29
|
+
```
|
30
|
+
|
31
|
+
Check if edge exists (non-zero)
|
32
|
+
|
33
|
+
```js
|
34
|
+
matrix.has(i,j)
|
35
|
+
```
|
36
|
+
|
37
|
+
Set an edge value
|
38
|
+
|
39
|
+
```js
|
40
|
+
matrix.set(i,j,value)
|
41
|
+
```
|
42
|
+
|
43
|
+
Remove an edge
|
44
|
+
|
45
|
+
```js
|
46
|
+
matrix.remove(i,j)
|
47
|
+
```
|
48
|
+
|
49
|
+
Get outgoing edge indices
|
50
|
+
|
51
|
+
```js
|
52
|
+
matrix.outE(i)
|
53
|
+
```
|
54
|
+
|
55
|
+
Get incoming edge indices
|
56
|
+
|
57
|
+
```js
|
58
|
+
matrix.inE(i)
|
59
|
+
```
|
60
|
+
|
61
|
+
### todo
|
62
|
+
|
63
|
+
* documentation
|
64
|
+
* changing size
|
65
|
+
|
66
|
+
## Basics
|
67
|
+
|
68
|
+
Convert [matrix](http://en.wikipedia.org/wiki/Adjacency_matrix) to [list](http://opendatastructures.org/ods-cpp/12_2_Graph_as_Collection_Li.html)
|
69
|
+
|
70
|
+
```js
|
71
|
+
d3.graph.matrixToList([
|
72
|
+
[0,1,0],
|
73
|
+
[1,0,0],
|
74
|
+
[1,1,1]
|
75
|
+
])
|
76
|
+
/*
|
77
|
+
[
|
78
|
+
{"source":0,"target":0,"value":0},{"source":0,"target":1,"value":1},{"source":0,"target":2,"value":0},
|
79
|
+
{"source":1,"target":0,"value":1},{"source":1,"target":1,"value":0},{"source":1,"target":2,"value":0},
|
80
|
+
{"source":2,"target":0,"value":1},{"source":2,"target":1,"value":1},{"source":2,"target":2,"value":1}
|
81
|
+
]
|
82
|
+
*/
|
83
|
+
```
|
84
|
+
|
85
|
+
Convert list to matrix
|
86
|
+
|
87
|
+
```js
|
88
|
+
d3.graph.listToMatrix([
|
89
|
+
{"source":0,"target":1,"value":1},
|
90
|
+
{"source":1,"target":0,"value":1},
|
91
|
+
{"source":2,"target":0,"value":1},
|
92
|
+
{"source":2,"target":1,"value":1},
|
93
|
+
{"source":2,"target":2,"value":1}
|
94
|
+
])
|
95
|
+
/*
|
96
|
+
[0,1,0],
|
97
|
+
[1,0,0],
|
98
|
+
[1,1,1]
|
99
|
+
*/
|
100
|
+
```
|
101
|
+
|
102
|
+
## Stateful Use
|
103
|
+
|
104
|
+
```js
|
105
|
+
var graph = d3.graph();
|
106
|
+
```
|
107
|
+
|
108
|
+
Load a matrix
|
109
|
+
|
110
|
+
```js
|
111
|
+
graph.matrix([
|
112
|
+
[0,1,0],
|
113
|
+
[1,0,0],
|
114
|
+
[1,1,1]
|
115
|
+
]);
|
116
|
+
```
|
117
|
+
|
118
|
+
Get the graph as list of links
|
119
|
+
|
120
|
+
```js
|
121
|
+
graph.links();
|
122
|
+
```
|
123
|
+
|
124
|
+
Get the graph as matrix
|
125
|
+
|
126
|
+
```js
|
127
|
+
graph.matrix();
|
128
|
+
```
|
129
|
+
|
130
|
+
Nodes and links can be modified by passing in a value. This will overwrite existing data.
|
131
|
+
|
132
|
+
```js
|
133
|
+
graph.nodes(['red', 'purple', 'orange']);
|
134
|
+
graph.links([{"source":0,"target":0,"value":0},{"source":0,"target":1,"value":1},{"source":0,"target":2,"value":0}]);
|
135
|
+
```
|
136
|
+
|
137
|
+
Get a description of the graph
|
138
|
+
|
139
|
+
```js
|
140
|
+
graph.description();
|
141
|
+
// "d3.graph with 3 nodes and 9 links"
|
142
|
+
```
|
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
|
+
```
|