1 d3.json('/_files/nd_subscriptionstats.json', function(data) {
3 // collect debian and ubuntu releases we are dealing with to create
5 var debian_releases = new Array()
6 var ubuntu_releases = new Array()
8 data.forEach(function(d, i) {
9 if (d.key.indexOf("Ubuntu") > -1)
10 ubuntu_releases.push(d.key)
12 debian_releases.push(d.key);
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"])
22 releaseKeyColor = function(d, i) {
23 if (d.key.indexOf("Ubuntu") > -1)
24 return colors_ubuntu(ubuntu_releases.indexOf(d.key)+1)
26 return colors_debian(debian_releases.indexOf(d.key)+1);
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)
36 chart.stacked.style('stacked');
39 .tickFormat(function(d) {
40 return d3.time.format('%d %b %Y')(new Date(d)) });
43 .tickFormat(d3.format(',.2f'));
45 d3.select('#subscriptionchart')
47 .transition().duration(500).call(chart);
49 nv.utils.windowResize(chart.update);