;(function () {
'use strict';
/**
* Draw simple pie bar chart.
* @namespace
*/
db.libs.peopleChart = (function($){
var name = 'peopleChart';
var update = function(id){
var $id = $(id);
var options = $id.data('options');
$id.find('li').each(function(i, li){
if(i < options.series[1]){
$(li).addClass('active');
} else {
$(li).removeClass('active');
}
});
return $id;
};
var series = function(id, data){
var $id = $(id);
var options = $id.data('options');
options.series = db.libs.chart.parse(data);
options.people = [];
for(var i = 0; i < options.series[0]; i++){
if(i < options.series[1]){
options.people.push(true);
} else {
options.people.push(false);
}
}
options.width = (100 / Math.ceil( options.series[0] / options.rows ));
options.type = db.templates['chart-people-'+options.type];
$id.data('options', options);
return $id;
};
var render = function(id){
var $id = $(id);
var options = $id.data('options');
$id.html( Mustache.render(db.templates['chart-people'], options) );
$id.get(0).dispatchEvent( new Event('rendered') );
return $id;
};
var init = function(id, options){
var $targets;
if(id !== undefined){
$targets = $(id);
} else {
$targets = $('.people[data-options]');
}
$targets.each(function(i, el){
if( !db.utils.isInitialized(el, name) ){
var $el = $(el);
var defaults = {
series: [],
type: 'men',
rows: 1,
};
if(id === undefined){
options = Foundation.utils.data_options($el);
}
options = $.extend({}, defaults, options);
$el.data('options', options);
series($el, options.series);
render($el);
db.utils.initialized(el, name);
}
});
return $targets;
};
return {
init: init,
reflow: function(){},
series: series,
update: update,
render: render
};
})(jQuery);
})();