Line | |
---|
1 | /* Inspired by Lee Byron's test data generator. */ |
---|
2 | function stream_layers(n, m, o) { |
---|
3 | if (arguments.length < 3) o = 0; |
---|
4 | function bump(a) { |
---|
5 | var x = 1 / (.1 + Math.random()), |
---|
6 | y = 2 * Math.random() - .5, |
---|
7 | z = 10 / (.1 + Math.random()); |
---|
8 | for (var i = 0; i < m; i++) { |
---|
9 | var w = (i / m - y) * z; |
---|
10 | a[i] += x * Math.exp(-w * w); |
---|
11 | } |
---|
12 | } |
---|
13 | return d3.range(n).map(function() { |
---|
14 | var a = [], i; |
---|
15 | for (i = 0; i < m; i++) a[i] = o + o * Math.random(); |
---|
16 | for (i = 0; i < 5; i++) bump(a); |
---|
17 | return a.map(stream_index); |
---|
18 | }); |
---|
19 | } |
---|
20 | |
---|
21 | /* Another layer generator using gamma distributions. */ |
---|
22 | function stream_waves(n, m) { |
---|
23 | return d3.range(n).map(function(i) { |
---|
24 | return d3.range(m).map(function(j) { |
---|
25 | var x = 20 * j / m - i / 3; |
---|
26 | return 2 * x * Math.exp(-.5 * x); |
---|
27 | }).map(stream_index); |
---|
28 | }); |
---|
29 | } |
---|
30 | |
---|
31 | function stream_index(d, i) { |
---|
32 | return {x: i, y: Math.max(0, d)}; |
---|
33 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.