Rework sampling to avoid 0 case and always include min and max

This commit is contained in:
Ross McFarland 2016-05-18 09:50:30 -07:00
parent 73ac76bfe5
commit 773db64ffc
1 changed files with 11 additions and 4 deletions

View File

@ -117,11 +117,18 @@ Ember.Handlebars.helper('tomographyGraph', function(tomography, size) {
' <circle class="border" r="' + insetSize + '"/>' +
' </g>' +
' <g class="lines">';
var sampling = 360 / tomography.n;
distances = tomography.distances.filter(function () {
return Math.random() < sampling
});
var distances = tomography.distances;
var n = distances.length;
if (tomography.n > 360) {
// We have more nodes than we want to show, take a random sampling to keep
// the number around 360.
var sampling = 360 / tomography.n;
distances = distances.filter(function (_, i) {
return i == 0 || i == n - 1 || Math.random() < sampling
});
// Re-set n to the filtered size
n = distances.length;
}
distances.forEach(function (distance, i) {
buf += ' <line transform="rotate(' + (i * 360 / n) + ')" y2="' + (-insetSize * (distance / max)) + '"></line>';
});