From: Yaroslav Halchenko <debian@onerussian.com>
Date: Tue, 21 May 2013 14:09:36 +0000 (-0400)
Subject: 1st version of 'coloring' subscription chart
X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=a0c7de80ae7f45b907f341969aca8b76d278508e;p=neurodebian.git

1st version of 'coloring' subscription chart
---

diff --git a/sphinx/_static/subscriptionchart.js b/sphinx/_static/subscriptionchart.js
index 5320f0a..37b98a2 100644
--- a/sphinx/_static/subscriptionchart.js
+++ b/sphinx/_static/subscriptionchart.js
@@ -1,11 +1,39 @@
 d3.json('/_files/nd_subscriptionstats.json', function(data) {
+
+  // collect debian and ubuntu releases we are dealing with to create
+  // proper color scales
+  var debian_releases = new Array()
+  var ubuntu_releases = new Array()
+
+	data.forEach(function(d, i) {
+  	if (d.key.indexOf("Ubuntu") > -1)
+          ubuntu_releases.push(d.key)
+      else
+          debian_releases.push(d.key);
+  })
+
+  // yoh: can't find a sane way to use ordinal scale here
+  // so let's create linear scale for indices within known releases
+  var colors_debian = d3.scale.linear()
+	.domain([0, debian_releases.length]).range(["white", "#dd1155"])
+  var colors_ubuntu = d3.scale.linear()
+	.domain([0, ubuntu_releases.length]).range(["white", "#dd4814"])
+
+  releaseKeyColor = function(d, i) {
+	if (d.key.indexOf("Ubuntu") > -1)
+		return colors_ubuntu(ubuntu_releases.indexOf(d.key)+1)
+	else
+		return colors_debian(debian_releases.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) {