]> git.donarmstrong.com Git - neurodebian.git/blobdiff - sphinx/_static/subscriptionchart.js
ENH: make JS a bit more compact for coloring subscriptions chart
[neurodebian.git] / sphinx / _static / subscriptionchart.js
index 5320f0a86ba50284be8002b1840c6aa671f177e9..b3eba1d2343f8fc9f3d56f1b9f2fc315f4bb47d1 100644 (file)
@@ -1,11 +1,35 @@
 d3.json('/_files/nd_subscriptionstats.json', function(data) {
+
+  // yoh: can't find a sane way to use ordinal scale here
+  // so let's create linear scale for indices within known releases
+
+  // collect debian and ubuntu releases we are dealing with to create
+  // proper color scales
+  // Will be Ubuntu for true
+  var releases = {false:[], true:[]}
+
+  data.forEach(function(d, i) {
+         releases[d.key.indexOf("Ubuntu") > -1].push(d.key)
+  })
+
+ var colors = {false: d3.scale.linear()
+                              .domain([0, releases[false].length]).range(["white", "#dd1155"]),
+                true:  d3.scale.linear()
+                       .domain([0, releases[true].length]).range(["white", "#dd4814"])}
+
+  releaseKeyColor = function(d, i) {
+       var isubuntu = d.key.indexOf("Ubuntu") > -1
+    return colors[isubuntu](releases[isubuntu].indexOf(d.key)+1)
+  }
+
   nv.addGraph(function() {
     chart = nv.models.stackedAreaChart()
                   .x(function(d) { return d[0] })
                   .y(function(d) { return d[1] })
+                  .color(releaseKeyColor)
                   .clipEdge(true);
 
-    chart.stacked.style('expand');
+    chart.stacked.style('stacked');
 
     chart.xAxis
         .tickFormat(function(d) {