﻿package com.controller
{
	
	/**
	 * ...
	 * @author Vivek Kumar
	 */
	
	
	import com.comp.chartDataGrid;
	import flash.display.MovieClip;
	
	public class ChartController
	{
		static private var instance:ChartController;
		public var c_xmlCaptivateParams:XML;
		public var c_xmlConfigParams:XML;
		public var c_chartDataGridObj:chartDataGrid;
		public var c_objRootRef;
		private var xTipPos:Number;
		private var yTipPos:Number;
		
		public function ChartController()
		{
			
		}
		
		public static function getInstance():ChartController
		{
			if(instance == null){
				instance =  new ChartController();
			}
			return instance;
		}
		
		public function execCommand(arg:String, data)
		{
			if (arg == "parseXML")
			{
				setData(data);
			}
			else if (arg == "parseConfig")
			{
				setConfig(data);
			}
			else if (arg == "createGrid")
			{
				if (c_chartDataGridObj == null)
				{
					c_chartDataGridObj = new chartDataGrid();
				}
				c_chartDataGridObj.drawGrid();
			}
			else if (arg == "setRootRef")
			{
				c_objRootRef = data;
			}
			else if (arg == "generateChart")
			{
				if (c_chartDataGridObj == null){
					c_chartDataGridObj = new chartDataGrid();
				}
				c_chartDataGridObj.move(xTipPos, yTipPos)
				c_chartDataGridObj.generateChart();
			}
		}
		
		private function setConfig(strConfigXML:String):void
		{
			c_xmlConfigParams = new XML(strConfigXML);			
		}
		
		/**
		* This function sets the XML data according to which the table is to be drawn.
		* If there is empty string passed, that means a default table is to be drawn.
		* @param strCaptivateXML Description This is xml in the form of string and carries all the parameters last set by the user. The data for each cell and modification done to the table resides in this xml only.
		*/
		private function setData(strCaptivateXML:String):void
		{
			c_xmlCaptivateParams = new XML(strCaptivateXML);
		}
		
		/**
		* This function always returns the latest XML whenever called.
		*/
		public function getModifiedXML():String
		{
			//trace("Data Object ::: "+inObjData);
			XML.prettyIndent = 0;
			XML.prettyPrinting = false;
			return c_chartDataGridObj.objectToString();
		}
		
		public function move(x:Number, y:Number):void
		{
			xTipPos = x;
			yTipPos = y;
		}
		
	}
	
}