/**
 * StatData is a class to represent and provide easy access to sets of statistical data
 *
 * @since Tue Jun 12 2007
 * @author Ron Rademaker
 **/
var StatData = Class.create();

StatData.prototype = {
	/**
	 * initialize
	 *
	 * Initialize a new StatData
	 *
	 * @access public
	 * @since Tue Jun 12 2007
	 * @return void
	 **/
	initialize: function() {
		this.empty = true;
		this.fields = {};
		this.colors = {};
	},

	/**
	 * setValue
	 *
	 * Sets the value of field to value
	 *
	 * @access public
	 * @since Tue Jun 12 2007
	 * @param string field
	 * @param integer value
	 * @param string color
	 * @return void
	 **/
	setValue: function(field, value, color) {
		this.empty = false;
		this.fields[field] = value;
		this.colors[field] = color;
	},

	/**
	 * getValue
	 *
	 * Gets the value of field 
	 *
	 * @access public
	 * @since Tue Jun 12 2007
	 * @param string field
	 * @return integer
	 **/
	getValue: function(field) {
		return this.fields[field];
	},

	/**
	 * getTotal
	 *
	 * Gets the sum of all fields (no, not the movie ;) )
	 *
	 * @access public
	 * @since Tue Jun 12 2007
	 * @return integer
	 **/
	getTotal: function() {
		var total = 0;
		for (var i in this.fields) {
			total += this.fields[i];
		}
		return total;
	},

	/**
	 * getPortion
	 *
	 * Gets the fraction of scale for field (for example, use scale 100 to get percentage or 2PI to get the radial angle for a pie chart)
	 *
	 * @access public
	 * @since Tue Jun 12 2007
	 * @param string field
	 * @param float scale
	 * @return float
	 **/
	getPortion: function(field, scale) {
		var total = this.getTotal();
		var value = this.getValue(field);

		return scale * (value / total);		
	},

	/**
	 * getColor
	 *
	 * Gets a color for the field
	 *
	 * @access public
	 * @since Tue Jun 12 2007
	 * @param string field
	 * @return string
	 **/
	getColor: function(field) {
		return this.colors[field];
	},

	/**
	 * getFields
	 *
	 * Returns an array of all defined fields
	 *
	 * @access public
	 * @since Tue Jun 12 2007
	 * @return array
	 **/
	getFields: function() {
		var fields = new Array();
		for (var i in this.fields) {
			fields.push(i);
		}
		return fields;
	}
}

