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,11 @@
|
|
1
|
+
# Interpolate Zoom
|
2
|
+
|
3
|
+
An interpolator for zooming and panning between two views of a two-dimensional plane, based on [“Smooth and efficient zooming and panning”](https://www.google.com/search?q=Smooth+and+efficient+zooming+and+panning) by Jarke J. van Wijk and Wim A.A. Nuij.
|
4
|
+
|
5
|
+
Demo: <http://bl.ocks.org/3828981>
|
6
|
+
|
7
|
+
<a name="interpolateZoom" href="#interpolateZoom">#</a> d3.**interpolateZoom**(*start*, *end*)
|
8
|
+
|
9
|
+
Returns an [interpolator](https://github.com/mbostock/d3/wiki/Transitions#wiki-_interpolate) between the two points *start* and *end*. Each point should be defined as an array of three numbers in world coordinates: *ux*, *uy* and *w*. The first two coordinates *ux*, *uy* are the center of the viewport. The last coordinate *w* is the size of the viewport.
|
10
|
+
|
11
|
+
The returned interpolator also has a *duration* property which encodes the recommended transition duration in milliseconds. This duration is based on the path length of the curved trajectory through *u,w* space. If you want to a slower or faster transition, feel free to multiply this by an arbitrary scale factor (*V* as described in the original paper).
|
@@ -0,0 +1,75 @@
|
|
1
|
+
(function() {
|
2
|
+
|
3
|
+
var ρ = Math.SQRT2,
|
4
|
+
ρ2 = 2,
|
5
|
+
ρ4 = 4;
|
6
|
+
|
7
|
+
// p0 = [ux0, uy0, w0]
|
8
|
+
// p1 = [ux1, uy1, w1]
|
9
|
+
d3.interpolateZoom = function(p0, p1) {
|
10
|
+
var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],
|
11
|
+
ux1 = p1[0], uy1 = p1[1], w1 = p1[2];
|
12
|
+
return ux0 === ux1 && uy0 === uy1
|
13
|
+
? interpolate1(ux0, uy0, w0, w1)
|
14
|
+
: interpolate2(ux0, uy0, ux1, uy1, w0, w1);
|
15
|
+
};
|
16
|
+
|
17
|
+
// Special case for u0 = u1.
|
18
|
+
function interpolate1(ux0, uy0, w0, w1) {
|
19
|
+
var S = Math.abs(Math.log(w1 / w0)) / ρ,
|
20
|
+
k = w1 < w0 ? -1 : 1;
|
21
|
+
|
22
|
+
function interpolate(t) {
|
23
|
+
var s = t * S;
|
24
|
+
return [
|
25
|
+
ux0,
|
26
|
+
uy0,
|
27
|
+
w0 * Math.exp(k * ρ * s)
|
28
|
+
];
|
29
|
+
}
|
30
|
+
|
31
|
+
interpolate.duration = S * 1000;
|
32
|
+
|
33
|
+
return interpolate;
|
34
|
+
};
|
35
|
+
|
36
|
+
// General case.
|
37
|
+
function interpolate2(ux0, uy0, ux1, uy1, w0, w1) {
|
38
|
+
var dx = ux1 - ux0,
|
39
|
+
dy = uy1 - uy0,
|
40
|
+
d2 = dx * dx + dy * dy,
|
41
|
+
d1 = Math.sqrt(d2),
|
42
|
+
b0 = (w1 * w1 - w0 * w0 + ρ4 * d2) / (2 * w0 * ρ2 * d1),
|
43
|
+
b1 = (w1 * w1 - w0 * w0 - ρ4 * d2) / (2 * w1 * ρ2 * d1),
|
44
|
+
r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),
|
45
|
+
r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1),
|
46
|
+
S = (r1 - r0) / ρ;
|
47
|
+
|
48
|
+
function interpolate(t) {
|
49
|
+
var s = t * S,
|
50
|
+
u = w0 / (ρ2 * d1) * (cosh(r0) * tanh(ρ * s + r0) - sinh(r0));
|
51
|
+
return [
|
52
|
+
ux0 + u * dx,
|
53
|
+
uy0 + u * dy,
|
54
|
+
w0 * cosh(r0) / cosh(ρ * s + r0)
|
55
|
+
];
|
56
|
+
};
|
57
|
+
|
58
|
+
interpolate.duration = S * 1000;
|
59
|
+
|
60
|
+
return interpolate;
|
61
|
+
};
|
62
|
+
|
63
|
+
function cosh(x) {
|
64
|
+
return (Math.exp(x) + Math.exp(-x)) / 2;
|
65
|
+
}
|
66
|
+
|
67
|
+
function sinh(x) {
|
68
|
+
return (Math.exp(x) - Math.exp(-x)) / 2;
|
69
|
+
}
|
70
|
+
|
71
|
+
function tanh(x) {
|
72
|
+
return sinh(x) / cosh(x);
|
73
|
+
}
|
74
|
+
|
75
|
+
})();
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# d3.jsonp
|
2
|
+
|
3
|
+
Demo: <http://bl.ocks.org/4494715>
|
4
|
+
|
5
|
+
A plugin for supporting the [JSONP](http://json-p.org/) technique of requesting
|
6
|
+
cross-domain JSON data. This plugin is unstable and in development.
|
7
|
+
|
8
|
+
Whenever possible, _use [CORS](http://en.wikipedia.org/wiki/Cross-origin_resource_sharing)
|
9
|
+
instead of JSONP_. CORS handles errors properly, has better security, and
|
10
|
+
supports formats besides JSON. See [enable-cors.org](http://enable-cors.org/) for more
|
11
|
+
information.
|
12
|
+
|
13
|
+
```js
|
14
|
+
// autogenerate a callback in the form d3.jsonp.foo
|
15
|
+
d3.jsonp('foo.jsonp?callback={callback}', function() {
|
16
|
+
console.log(arguments);
|
17
|
+
});
|
18
|
+
|
19
|
+
// specify a callback
|
20
|
+
d3.jsonp('foo.jsonp?callback=d3.jsonp.foo', function() {
|
21
|
+
console.log(arguments);
|
22
|
+
});
|
23
|
+
```
|
24
|
+
|
25
|
+
This plugin requires servers to accept callbacks with numeric and `.`
|
26
|
+
characters. Unlike `d3.xhr` functions, there is no error handling.
|
@@ -0,0 +1,25 @@
|
|
1
|
+
d3.jsonp = function (url, callback) {
|
2
|
+
function rand() {
|
3
|
+
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',
|
4
|
+
c = '', i = -1;
|
5
|
+
while (++i < 15) c += chars.charAt(Math.floor(Math.random() * 52));
|
6
|
+
return c;
|
7
|
+
}
|
8
|
+
|
9
|
+
function create(url) {
|
10
|
+
var e = url.match(/callback=d3.jsonp.(\w+)/),
|
11
|
+
c = e ? e[1] : rand();
|
12
|
+
d3.jsonp[c] = function(data) {
|
13
|
+
callback(data);
|
14
|
+
delete d3.jsonp[c];
|
15
|
+
script.remove();
|
16
|
+
};
|
17
|
+
return 'd3.jsonp.' + c;
|
18
|
+
}
|
19
|
+
|
20
|
+
var cb = create(url),
|
21
|
+
script = d3.select('head')
|
22
|
+
.append('script')
|
23
|
+
.attr('type', 'text/javascript')
|
24
|
+
.attr('src', url.replace(/(\{|%7B)callback(\{|%7D)/, cb));
|
25
|
+
};
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# keybinding
|
2
|
+
|
3
|
+
Keybindings for d3
|
4
|
+
|
5
|
+
Demo: <http://bl.ocks.org/4444952>
|
6
|
+
|
7
|
+
<a name="keybinding" href="#keybinding">#</a> d3.**keybinding**()
|
8
|
+
|
9
|
+
Returns a keybinding object that can be used with `.call` to provide
|
10
|
+
bindings on selections.
|
11
|
+
|
12
|
+
The keybinding object exposes `.on()` for common keycodes and dispatches events
|
13
|
+
with arguments `[d3.event, modifiers]` in which modifiers is a string which
|
14
|
+
can include `⇧`, `⌃`, `⌥`, `⌘'`.
|
15
|
+
|
16
|
+
Keystroke events on input areas (`<input>`, `<select>`, and `<textarea>`)
|
17
|
+
are not caught.
|
@@ -0,0 +1,120 @@
|
|
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
|
80
|
+
}
|
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
|
+
|
95
|
+
var pairs = d3.entries(_keys.keys),
|
96
|
+
event = d3.dispatch.apply(d3, d3.keys(_keys.keys));
|
97
|
+
|
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;
|
103
|
+
}
|
104
|
+
|
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
|
+
});
|
117
|
+
}
|
118
|
+
|
119
|
+
return d3.rebind(keys, event, 'on');
|
120
|
+
};
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# d3.longscroll
|
2
|
+
|
3
|
+
Scroll large numbers of rows using virtual rendering: <http://bl.ocks.org/3689677>
|
4
|
+
|
5
|
+
## Limitations
|
6
|
+
|
7
|
+
Currently, only up to around 1e7px of vertical space is supported in current
|
8
|
+
browsers. A fix for this is [in the works][1].
|
9
|
+
|
10
|
+
[1]: https://groups.google.com/d/msg/d3-js/vNOvn2YUcaI/mz7m1igScUUJ
|
@@ -0,0 +1,75 @@
|
|
1
|
+
(function() {
|
2
|
+
|
3
|
+
// Virtual rendering for rows taking up to 1e7px of vertical space.
|
4
|
+
// By Jason Davies, http://www.jasondavies.com/
|
5
|
+
d3.longscroll = function() {
|
6
|
+
var render = null,
|
7
|
+
size = 0,
|
8
|
+
position = 0,
|
9
|
+
rowHeight = 20;
|
10
|
+
|
11
|
+
function longscroll(g) {
|
12
|
+
g.selectAll("div.before").data([0]).enter().append("div").attr("class", "before");
|
13
|
+
var current = g.selectAll("div.current").data([0]);
|
14
|
+
current.enter().append("div").attr("class", "current");
|
15
|
+
g.selectAll("div.after").data([0]).enter().append("div").attr("class", "after");
|
16
|
+
|
17
|
+
g.on("scroll.longscroll", function() {
|
18
|
+
position = Math.floor(this.scrollTop / rowHeight);
|
19
|
+
scroll(this.scrollTop);
|
20
|
+
});
|
21
|
+
|
22
|
+
scroll(0);
|
23
|
+
current.each(function() {
|
24
|
+
this.scrollIntoView();
|
25
|
+
});
|
26
|
+
|
27
|
+
function scroll(scrollTop) {
|
28
|
+
g.each(function() {
|
29
|
+
this.scrollTop = scrollTop;
|
30
|
+
var g = d3.select(this),
|
31
|
+
rows = 1 + Math.ceil(this.clientHeight / rowHeight),
|
32
|
+
position0 = Math.max(0, Math.min(size - rows, position)),
|
33
|
+
position1 = position0 + rows;
|
34
|
+
|
35
|
+
g.select(".before").style("height", position0 * rowHeight + "px");
|
36
|
+
g.select(".after").style("height", (size - position1) * rowHeight + "px");
|
37
|
+
|
38
|
+
var div = g.select(".current").selectAll("div.row")
|
39
|
+
.data(d3.range(position0, Math.min(position1, size)), String);
|
40
|
+
div.enter().append("div")
|
41
|
+
.attr("class", "row");
|
42
|
+
div.exit().remove();
|
43
|
+
div.order().call(render);
|
44
|
+
});
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
longscroll.render = function(_) {
|
49
|
+
if (!arguments.length) return render;
|
50
|
+
render = _;
|
51
|
+
return longscroll;
|
52
|
+
};
|
53
|
+
|
54
|
+
longscroll.rowHeight = function(_) {
|
55
|
+
if (!arguments.length) return rowHeight;
|
56
|
+
rowHeight = +_;
|
57
|
+
return longscroll;
|
58
|
+
};
|
59
|
+
|
60
|
+
longscroll.position = function(_) {
|
61
|
+
if (!arguments.length) return position;
|
62
|
+
position = +_;
|
63
|
+
return longscroll;
|
64
|
+
};
|
65
|
+
|
66
|
+
longscroll.size = function(_) {
|
67
|
+
if (!arguments.length) return size;
|
68
|
+
size = +_;
|
69
|
+
return longscroll;
|
70
|
+
};
|
71
|
+
|
72
|
+
return longscroll;
|
73
|
+
};
|
74
|
+
|
75
|
+
})();
|
@@ -0,0 +1,20 @@
|
|
1
|
+
{
|
2
|
+
"name": "d3-plugins",
|
3
|
+
"version": "0.0.1",
|
4
|
+
"description": "Plugins for D3.js.",
|
5
|
+
"keywords": ["visualization"],
|
6
|
+
"homepage": "http://github.com/d3/d3-plugins",
|
7
|
+
"repository": {
|
8
|
+
"type": "git",
|
9
|
+
"url": "http://github.com/d3/d3-plugins.git"
|
10
|
+
},
|
11
|
+
"dependencies": {
|
12
|
+
"d3": "3.0.x"
|
13
|
+
},
|
14
|
+
"devDependencies": {
|
15
|
+
"vows": "0.6.x"
|
16
|
+
},
|
17
|
+
"scripts": {
|
18
|
+
"test": "./node_modules/vows/bin/vows `find . -name \"*-test.js\" \\! -path \"./node_modules/*\"`"
|
19
|
+
}
|
20
|
+
}
|
@@ -0,0 +1,249 @@
|
|
1
|
+
(function() {
|
2
|
+
|
3
|
+
// Based on http://vis.stanford.edu/protovis/ex/qqplot.html
|
4
|
+
d3.qq = function() {
|
5
|
+
var width = 1,
|
6
|
+
height = 1,
|
7
|
+
duration = 0,
|
8
|
+
domain = null,
|
9
|
+
tickFormat = null,
|
10
|
+
n = 100,
|
11
|
+
x = qqX,
|
12
|
+
y = qqY;
|
13
|
+
|
14
|
+
// For each small multiple…
|
15
|
+
function qq(g) {
|
16
|
+
g.each(function(d, i) {
|
17
|
+
var g = d3.select(this),
|
18
|
+
qx = qqQuantiles(n, x.call(this, d, i)),
|
19
|
+
qy = qqQuantiles(n, y.call(this, d, i)),
|
20
|
+
xd = domain && domain.call(this, d, i) || [d3.min(qx), d3.max(qx)], // new x-domain
|
21
|
+
yd = domain && domain.call(this, d, i) || [d3.min(qy), d3.max(qy)], // new y-domain
|
22
|
+
x0, // old x-scale
|
23
|
+
y0; // old y-scale
|
24
|
+
|
25
|
+
// Compute the new x-scale.
|
26
|
+
var x1 = d3.scale.linear()
|
27
|
+
.domain(xd)
|
28
|
+
.range([0, width]);
|
29
|
+
|
30
|
+
// Compute the new y-scale.
|
31
|
+
var y1 = d3.scale.linear()
|
32
|
+
.domain(yd)
|
33
|
+
.range([height, 0]);
|
34
|
+
|
35
|
+
// Retrieve the old scales, if this is an update.
|
36
|
+
if (this.__chart__) {
|
37
|
+
x0 = this.__chart__.x;
|
38
|
+
y0 = this.__chart__.y;
|
39
|
+
} else {
|
40
|
+
x0 = d3.scale.linear().domain([0, Infinity]).range(x1.range());
|
41
|
+
y0 = d3.scale.linear().domain([0, Infinity]).range(y1.range());
|
42
|
+
}
|
43
|
+
|
44
|
+
// Stash the new scales.
|
45
|
+
this.__chart__ = {x: x1, y: y1};
|
46
|
+
|
47
|
+
// Update diagonal line.
|
48
|
+
var diagonal = g.selectAll("line.diagonal")
|
49
|
+
.data([null]);
|
50
|
+
|
51
|
+
diagonal.enter().append("svg:line")
|
52
|
+
.attr("class", "diagonal")
|
53
|
+
.attr("x1", x1(yd[0]))
|
54
|
+
.attr("y1", y1(xd[0]))
|
55
|
+
.attr("x2", x1(yd[1]))
|
56
|
+
.attr("y2", y1(xd[1]));
|
57
|
+
|
58
|
+
diagonal.transition()
|
59
|
+
.duration(duration)
|
60
|
+
.attr("x1", x1(yd[0]))
|
61
|
+
.attr("y1", y1(xd[0]))
|
62
|
+
.attr("x2", x1(yd[1]))
|
63
|
+
.attr("y2", y1(xd[1]));
|
64
|
+
|
65
|
+
// Update quantile plots.
|
66
|
+
var circle = g.selectAll("circle")
|
67
|
+
.data(d3.range(n).map(function(i) {
|
68
|
+
return {x: qx[i], y: qy[i]};
|
69
|
+
}));
|
70
|
+
|
71
|
+
circle.enter().append("svg:circle")
|
72
|
+
.attr("class", "quantile")
|
73
|
+
.attr("r", 4.5)
|
74
|
+
.attr("cx", function(d) { return x0(d.x); })
|
75
|
+
.attr("cy", function(d) { return y0(d.y); })
|
76
|
+
.style("opacity", 1e-6)
|
77
|
+
.transition()
|
78
|
+
.duration(duration)
|
79
|
+
.attr("cx", function(d) { return x1(d.x); })
|
80
|
+
.attr("cy", function(d) { return y1(d.y); })
|
81
|
+
.style("opacity", 1);
|
82
|
+
|
83
|
+
circle.transition()
|
84
|
+
.duration(duration)
|
85
|
+
.attr("cx", function(d) { return x1(d.x); })
|
86
|
+
.attr("cy", function(d) { return y1(d.y); })
|
87
|
+
.style("opacity", 1);
|
88
|
+
|
89
|
+
circle.exit().transition()
|
90
|
+
.duration(duration)
|
91
|
+
.attr("cx", function(d) { return x1(d.x); })
|
92
|
+
.attr("cy", function(d) { return y1(d.y); })
|
93
|
+
.style("opacity", 1e-6)
|
94
|
+
.remove();
|
95
|
+
|
96
|
+
var xformat = tickFormat || x1.tickFormat(4),
|
97
|
+
yformat = tickFormat || y1.tickFormat(4),
|
98
|
+
tx = function(d) { return "translate(" + x1(d) + "," + height + ")"; },
|
99
|
+
ty = function(d) { return "translate(0," + y1(d) + ")"; };
|
100
|
+
|
101
|
+
// Update x-ticks.
|
102
|
+
var xtick = g.selectAll("g.x.tick")
|
103
|
+
.data(x1.ticks(4), function(d) {
|
104
|
+
return this.textContent || xformat(d);
|
105
|
+
});
|
106
|
+
|
107
|
+
var xtickEnter = xtick.enter().append("svg:g")
|
108
|
+
.attr("class", "x tick")
|
109
|
+
.attr("transform", function(d) { return "translate(" + x0(d) + "," + height + ")"; })
|
110
|
+
.style("opacity", 1e-6);
|
111
|
+
|
112
|
+
xtickEnter.append("svg:line")
|
113
|
+
.attr("y1", 0)
|
114
|
+
.attr("y2", -6);
|
115
|
+
|
116
|
+
xtickEnter.append("svg:text")
|
117
|
+
.attr("text-anchor", "middle")
|
118
|
+
.attr("dy", "1em")
|
119
|
+
.text(xformat);
|
120
|
+
|
121
|
+
// Transition the entering ticks to the new scale, x1.
|
122
|
+
xtickEnter.transition()
|
123
|
+
.duration(duration)
|
124
|
+
.attr("transform", tx)
|
125
|
+
.style("opacity", 1);
|
126
|
+
|
127
|
+
// Transition the updating ticks to the new scale, x1.
|
128
|
+
xtick.transition()
|
129
|
+
.duration(duration)
|
130
|
+
.attr("transform", tx)
|
131
|
+
.style("opacity", 1);
|
132
|
+
|
133
|
+
// Transition the exiting ticks to the new scale, x1.
|
134
|
+
xtick.exit().transition()
|
135
|
+
.duration(duration)
|
136
|
+
.attr("transform", tx)
|
137
|
+
.style("opacity", 1e-6)
|
138
|
+
.remove();
|
139
|
+
|
140
|
+
// Update ticks.
|
141
|
+
var ytick = g.selectAll("g.y.tick")
|
142
|
+
.data(y1.ticks(4), function(d) {
|
143
|
+
return this.textContent || yformat(d);
|
144
|
+
});
|
145
|
+
|
146
|
+
var ytickEnter = ytick.enter().append("svg:g")
|
147
|
+
.attr("class", "y tick")
|
148
|
+
.attr("transform", function(d) { return "translate(0," + y0(d) + ")"; })
|
149
|
+
.style("opacity", 1e-6);
|
150
|
+
|
151
|
+
ytickEnter.append("svg:line")
|
152
|
+
.attr("x1", 0)
|
153
|
+
.attr("x2", 6);
|
154
|
+
|
155
|
+
ytickEnter.append("svg:text")
|
156
|
+
.attr("text-anchor", "end")
|
157
|
+
.attr("dx", "-.5em")
|
158
|
+
.attr("dy", ".3em")
|
159
|
+
.text(yformat);
|
160
|
+
|
161
|
+
// Transition the entering ticks to the new scale, y1.
|
162
|
+
ytickEnter.transition()
|
163
|
+
.duration(duration)
|
164
|
+
.attr("transform", ty)
|
165
|
+
.style("opacity", 1);
|
166
|
+
|
167
|
+
// Transition the updating ticks to the new scale, y1.
|
168
|
+
ytick.transition()
|
169
|
+
.duration(duration)
|
170
|
+
.attr("transform", ty)
|
171
|
+
.style("opacity", 1);
|
172
|
+
|
173
|
+
// Transition the exiting ticks to the new scale, y1.
|
174
|
+
ytick.exit().transition()
|
175
|
+
.duration(duration)
|
176
|
+
.attr("transform", ty)
|
177
|
+
.style("opacity", 1e-6)
|
178
|
+
.remove();
|
179
|
+
});
|
180
|
+
}
|
181
|
+
|
182
|
+
qq.width = function(x) {
|
183
|
+
if (!arguments.length) return width;
|
184
|
+
width = x;
|
185
|
+
return qq;
|
186
|
+
};
|
187
|
+
|
188
|
+
qq.height = function(x) {
|
189
|
+
if (!arguments.length) return height;
|
190
|
+
height = x;
|
191
|
+
return qq;
|
192
|
+
};
|
193
|
+
|
194
|
+
qq.duration = function(x) {
|
195
|
+
if (!arguments.length) return duration;
|
196
|
+
duration = x;
|
197
|
+
return qq;
|
198
|
+
};
|
199
|
+
|
200
|
+
qq.domain = function(x) {
|
201
|
+
if (!arguments.length) return domain;
|
202
|
+
domain = x == null ? x : d3.functor(x);
|
203
|
+
return qq;
|
204
|
+
};
|
205
|
+
|
206
|
+
qq.count = function(z) {
|
207
|
+
if (!arguments.length) return n;
|
208
|
+
n = z;
|
209
|
+
return qq;
|
210
|
+
};
|
211
|
+
|
212
|
+
qq.x = function(z) {
|
213
|
+
if (!arguments.length) return x;
|
214
|
+
x = z;
|
215
|
+
return qq;
|
216
|
+
};
|
217
|
+
|
218
|
+
qq.y = function(z) {
|
219
|
+
if (!arguments.length) return y;
|
220
|
+
y = z;
|
221
|
+
return qq;
|
222
|
+
};
|
223
|
+
|
224
|
+
qq.tickFormat = function(x) {
|
225
|
+
if (!arguments.length) return tickFormat;
|
226
|
+
tickFormat = x;
|
227
|
+
return qq;
|
228
|
+
};
|
229
|
+
|
230
|
+
return qq;
|
231
|
+
};
|
232
|
+
|
233
|
+
function qqQuantiles(n, values) {
|
234
|
+
var m = values.length - 1;
|
235
|
+
values = values.slice().sort(d3.ascending);
|
236
|
+
return d3.range(n).map(function(i) {
|
237
|
+
return values[~~(i * m / n)];
|
238
|
+
});
|
239
|
+
}
|
240
|
+
|
241
|
+
function qqX(d) {
|
242
|
+
return d.x;
|
243
|
+
}
|
244
|
+
|
245
|
+
function qqY(d) {
|
246
|
+
return d.y;
|
247
|
+
}
|
248
|
+
|
249
|
+
})();
|