]> git.donarmstrong.com Git - neurodebian.git/blob - sphinx/_static/subscriptionchart.js
1st version of 'coloring' subscription chart
[neurodebian.git] / sphinx / _static / subscriptionchart.js
1 d3.json('/_files/nd_subscriptionstats.json', function(data) {
2
3   // collect debian and ubuntu releases we are dealing with to create
4   // proper color scales
5   var debian_releases = new Array()
6   var ubuntu_releases = new Array()
7
8         data.forEach(function(d, i) {
9         if (d.key.indexOf("Ubuntu") > -1)
10           ubuntu_releases.push(d.key)
11       else
12           debian_releases.push(d.key);
13   })
14
15   // yoh: can't find a sane way to use ordinal scale here
16   // so let's create linear scale for indices within known releases
17   var colors_debian = d3.scale.linear()
18         .domain([0, debian_releases.length]).range(["white", "#dd1155"])
19   var colors_ubuntu = d3.scale.linear()
20         .domain([0, ubuntu_releases.length]).range(["white", "#dd4814"])
21
22   releaseKeyColor = function(d, i) {
23         if (d.key.indexOf("Ubuntu") > -1)
24                 return colors_ubuntu(ubuntu_releases.indexOf(d.key)+1)
25         else
26                 return colors_debian(debian_releases.indexOf(d.key)+1);
27   }
28
29   nv.addGraph(function() {
30     chart = nv.models.stackedAreaChart()
31                   .x(function(d) { return d[0] })
32                   .y(function(d) { return d[1] })
33                   .color(releaseKeyColor)
34                   .clipEdge(true);
35
36     chart.stacked.style('stacked');
37
38     chart.xAxis
39         .tickFormat(function(d) {
40             return d3.time.format('%d %b %Y')(new Date(d)) });
41
42     chart.yAxis
43         .tickFormat(d3.format(',.2f'));
44
45     d3.select('#subscriptionchart')
46       .datum(data)
47         .transition().duration(500).call(chart);
48
49     nv.utils.windowResize(chart.update);
50
51     return chart;
52   });
53 })