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