Skip to content

Commit

Permalink
FLOE-437: refactor getSonificationUnits function
Browse files Browse the repository at this point in the history
  • Loading branch information
waharnum committed Nov 11, 2015
1 parent 7d28757 commit 8ad4006
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions src/js/chartAuthoring.js
Expand Up @@ -194,23 +194,21 @@ https://raw.githubusercontent.com/fluid-project/chartAuthoring/master/LICENSE.tx
return pieChartData;
};

// TODO: this needs to be better and configurable, but works for immediate purposes

floe.chartAuthoring.getSonificationUnits = function(value) {
var numberTens = Math.floor(value / 10);
var numberOnes = value % 10;
var tensArray =[];
var onesArray = [];
for(var i=0; i<numberTens; i++) {
tensArray.push(10);
// TODO: better implementation, but works for immediate purposes

floe.chartAuthoring.getSonificationUnits = function(value, unitDivisor) {
var numberDivisors = Math.floor(value / unitDivisor);
var numberRemainders = value % unitDivisor;
var divisorArray =[];
var remainderArray = [];
for(var i=0; i<numberDivisors; i++) {
divisorArray.push(unitDivisor);
}
for(i=0; i<numberOnes; i++) {
onesArray.push(1);
for(i=0; i<numberRemainders; i++) {
remainderArray.push(1);
}

var joinedArray = tensArray.concat(onesArray);
return joinedArray;

return divisorArray.concat(remainderArray);
};

// Given an object in the style of floe.chartAuthoring.dataEntryPanel.model.dataEntries,
Expand All @@ -225,7 +223,7 @@ https://raw.githubusercontent.com/fluid-project/chartAuthoring/master/LICENSE.tx
id: key,
label: item.label,
value: percentage,
units: floe.chartAuthoring.getSonificationUnits(percentage)
units: floe.chartAuthoring.getSonificationUnits(percentage, 10)
};
sonificationData.push(d);
}
Expand Down

0 comments on commit 8ad4006

Please sign in to comment.