From a0c7de80ae7f45b907f341969aca8b76d278508e Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Tue, 21 May 2013 10:09:36 -0400 Subject: [PATCH] 1st version of 'coloring' subscription chart --- sphinx/_static/subscriptionchart.js | 30 ++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) 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) { -- 2.39.2