~smagoun/whoopsie/whoopsie-lp1017637

« back to all changes in this revision

Viewing changes to backend/stats/static/js/d3/examples/stream/stream.js

  • Committer: Evan Dandrea
  • Date: 2012-05-09 05:53:45 UTC
  • Revision ID: evan.dandrea@canonical.com-20120509055345-z2j41tmcbf4as5uf
The backend now lives in lp:daisy and the website (errors.ubuntu.com) now lives in lp:errors.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
var 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
 
 
7
 
var 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
 
 
16
 
var 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
 
 
21
 
var vis = d3.select("#chart")
22
 
  .append("svg")
23
 
    .attr("width", w)
24
 
    .attr("height", h);
25
 
 
26
 
vis.selectAll("path")
27
 
    .data(data0)
28
 
  .enter().append("path")
29
 
    .style("fill", function() { return color(Math.random()); })
30
 
    .attr("d", area);
31
 
 
32
 
function 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
 
}