source: Dev/branches/jQueryUI/client/d3/examples/stream/stream.js @ 249

Last change on this file since 249 was 249, checked in by hendrikvanantwerpen, 13 years ago

This one's for Subversion, because it's so close...

First widget (stripped down sequencer).
Seperated client and server code in two direcotry trees.

File size: 1.1 KB
Line 
1var n = 20, // number of layers
2    m = 200, // number of samples per layer
3    data0 = d3.layout.stack().offset("wiggle")(stream_layers(n, m)),
4    data1 = d3.layout.stack().offset("wiggle")(stream_layers(n, m)),
5    color = d3.interpolateRgb("#aad", "#556");
6
7var w = 960,
8    h = 500,
9    mx = m - 1,
10    my = d3.max(data0.concat(data1), function(d) {
11      return d3.max(d, function(d) {
12        return d.y0 + d.y;
13      });
14    });
15
16var area = d3.svg.area()
17    .x(function(d) { return d.x * w / mx; })
18    .y0(function(d) { return h - d.y0 * h / my; })
19    .y1(function(d) { return h - (d.y + d.y0) * h / my; });
20
21var vis = d3.select("#chart")
22  .append("svg:svg")
23    .attr("width", w)
24    .attr("height", h);
25
26vis.selectAll("path")
27    .data(data0)
28  .enter().append("svg:path")
29    .style("fill", function() { return color(Math.random()); })
30    .attr("d", area);
31
32function transition() {
33  d3.selectAll("path")
34      .data(function() {
35        var d = data1;
36        data1 = data0;
37        return data0 = d;
38      })
39    .transition()
40      .duration(2500)
41      .attr("d", area);
42}
Note: See TracBrowser for help on using the repository browser.