1 d3.json('/_files/nd_subscriptionstats.json', function(data) {
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
6 // collect debian and ubuntu releases we are dealing with to create
8 // Will be Ubuntu for true
9 var releases = {false:[], true:[]}
11 data.forEach(function(d, i) {
12 releases[d.key.indexOf("Ubuntu") > -1].push(d.key)
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"])}
20 releaseKeyColor = function(d, i) {
21 var isubuntu = d.key.indexOf("Ubuntu") > -1
22 return colors[isubuntu](releases[isubuntu].indexOf(d.key)+1)
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)
32 chart.stacked.style('stacked');
35 .tickFormat(function(d) {
36 return d3.time.format('%d %b %Y')(new Date(d)) });
39 .tickFormat(d3.format(',.2f'));
41 d3.select('#subscriptionchart')
43 .transition().duration(500).call(chart);
45 nv.utils.windowResize(chart.update);