change color computation to a score system

This commit is contained in:
Gwenhael Le Moine 2014-08-19 17:08:58 +02:00
parent 8094fc839c
commit af98d41e59

View file

@ -38,26 +38,64 @@ app.controller( 'BalanceCtrl',
}; };
}; };
// compute an account's score: from 0 (good) to 9 (bad)
var score_account = function( account ) {
if ( account.match( /^Income:salaire$/ ) ) {
return 0;
} else if ( account.match( /^Income:Gift$/ ) ) {
return 5;
} else if ( account.match( /^Expenses:(courses|Hang)$/ ) ) {
return 0;
} else if ( account.match( /^Expenses:Home/ ) ) {
return 0;
} else if ( account.match( /^Expenses:Health/ ) ) {
return 0;
} else if ( account.match( /^Expenses:Car/ ) ) {
return 3;
} else if ( account.match( /^Expenses:(Food|Transport)/ ) ) {
return 6;
} else if ( account.match( /^Expenses:(Shopping|Gadgets|Entertainement)/ ) ) {
return 8;
} else {
return 5;
}
};
$scope.color = function() { $scope.color = function() {
return function( d, i ) { return function( d, i ) {
if ( d.data.account.match( /^Income:salaire$/ ) ) { var score = score_account( d.data.account );
switch( score ) {
case 0:
return '#0f0'; return '#0f0';
} else if ( d.data.account.match( /^Income:Gift$/ ) ) { break;
return '#ef0'; case 1:
} else if ( d.data.account.match( /^Expenses:Home/ ) ) { return '#3f0';
return '#00f'; break;
} else if ( d.data.account.match( /^Expenses:Health/ ) ) { case 2:
return '#0cf'; return '#6f0';
} else if ( d.data.account.match( /^Expenses:(courses|Hang)$/ ) ) { break;
return '#0b6'; case 3:
} else if ( d.data.account.match( /^Expenses:Car/ ) ) { return '#9f0';
return '#111'; break;
} else if ( d.data.account.match( /^Expenses:(Food|Transport)/ ) ) { case 4:
return '#b60'; return '#cf0';
} else if ( d.data.account.match( /^Expenses:(Shopping|Gadgets|Entertainement)/ ) ) { break;
case 5:
return '#fc0';
break;
case 6:
return '#f90';
break;
case 7:
return '#f60';
break;
case 8:
return '#f30';
break;
case 9:
return '#f00'; return '#f00';
} else { break;
return '#ddd'; default:
return '#fff';
} }
}; };
}; };