mood-bar.js

angular.module('homepage').
directive('moodBar', function () {
    return {
    	controller: 'moodBarController',
        restrict: 'E',
        replace: true,
        scope: {
        	data: '='
        },
        transclude: true,
        templateUrl: 'components/feature-components/mood/mood-bar.html'
    }
}).
controller('moodBarController', function ($scope) {
	function generateMoodSlots(level) {
		var slots = [];

		for(var i=3; i >= -3; i--) {
			// Add neutral slot
			if(i==0) {
				slots.push({type: 'neutral'});
			}
			// Build positive mood bar
			else if(level > 0) {
				if(level >= i && i > 0) {
					slots.push({type: 'positive'});
				}
				else {
					slots.push({type: 'invisible'});
				}
			}
			// Build negative mood bar
			else if(level < 0) {
				if(level <= i & i < 0) {
					slots.push({type: 'negative'});
				}
				else {
					slots.push({type: 'invisible'});
				}
			}
			else {
				slots.push({type: 'invisible'});
			}
		}

		return slots;
	}

	$scope.slots = generateMoodSlots($scope.data.level);
});