From: Yaroslav Halchenko Date: Tue, 21 May 2013 14:10:01 +0000 (-0400) Subject: ENH: make JS a bit more compact for coloring subscriptions chart X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=d350815cb81d7fe5167713e19c9298e1e8dc1304;p=neurodebian.git ENH: make JS a bit more compact for coloring subscriptions chart --- diff --git a/sphinx/_static/subscriptionchart.js b/sphinx/_static/subscriptionchart.js index 37b98a2..b3eba1d 100644 --- a/sphinx/_static/subscriptionchart.js +++ b/sphinx/_static/subscriptionchart.js @@ -1,29 +1,25 @@ 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 - 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); + // Will be Ubuntu for true + var releases = {false:[], true:[]} + + data.forEach(function(d, i) { + releases[d.key.indexOf("Ubuntu") > -1].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"]) + 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) { - 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); + var isubuntu = d.key.indexOf("Ubuntu") > -1 + return colors[isubuntu](releases[isubuntu].indexOf(d.key)+1) } nv.addGraph(function() {