package com.smartgwt.sample.client;

import java.util.Date;

import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.core.KeyIdentifier;
import com.smartgwt.client.types.ChartType;
import com.smartgwt.client.util.Page;
import com.smartgwt.client.util.PageKeyHandler;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.chart.FacetChart;
import com.smartgwt.client.widgets.cube.Facet;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class BuiltInDS implements EntryPoint {
    
    private FacetChart chart;
    
    /**
     * This is the entry point method.
     */
    public void onModuleLoad() {
        KeyIdentifier debugKey = new KeyIdentifier();
        debugKey.setCtrlKey(true);
        debugKey.setKeyName("D");

        Page.registerKey(debugKey, new PageKeyHandler() {
            public void execute(String keyName) {
                SC.showConsole();
            }
        });

        chart = new FacetChart();
		chart.setChartType(ChartType.COLUMN);
		//chart.setFacets(new Facet("date", i18nDictionary.get("receivingActivityLast7Days")),new Facet("type"));  
		chart.setFacets(new Facet("date", "Date"));
		chart.setValueProperty("count");
		chart.setBandedBackground(false);
		chart.setAutoRotateLabels(false);
		chart.setAxisStartValue(0.0);
		chart.setAxisEndValue(100.0);
		
		chart.setBackgroundColor("white");
        String[] dataColors = new String[1];
        dataColors[0] = "#008000";
        chart.setDataColors(dataColors);
        
		//chart.setDataColors("#7597E1");
		chart.setMaxBarThickness(100);  
        //chart.setStacked(Boolean.FALSE);
		chart.setValueTitle( "Receiving Number");
		chart.setTitle("");		
		chart.setShowValueOnHover(true);
		chart.setData(new ReceivingData[0]);
		this.LoadChartDataTest();
		chart.draw();
		
		
        
    }
    
    public void LoadChartDataTest(){
	       try {
	            
	            
	            ReceivingData rcv1 = null, rcv2 = null, rcv3 = null, rcv4 = null, rcv5 = null;
	            
	            Date dt = new Date();
	            int sec = dt.getSeconds();
	            //int mod = sec%6;
	            if (sec>= 0 && sec<10) {
	            	rcv1 = new ReceivingData("06/10/2016", "0");
		            rcv2 = new ReceivingData("05/10/2016", "0");
		            rcv3 = new ReceivingData("04/10/2016", "0");
		            rcv4 = new ReceivingData("03/10/2016", "0");
		            rcv5 = new ReceivingData("02/10/2016", "0");
	            } else if  (sec>= 10 && sec<20) {
	            	rcv1 = new ReceivingData("06/10/2016", "0");
		            rcv2 = new ReceivingData("05/10/2016", "0");
		            rcv3 = new ReceivingData("04/10/2016", "0");
		            rcv4 = new ReceivingData("03/10/2016", "0");
		            rcv5 = new ReceivingData("02/10/2016", "1");
	            } else if  (sec>= 20 && sec<30) {
	            	rcv1 = new ReceivingData("06/10/2016", "1");
		            rcv2 = new ReceivingData("05/10/2016", "0");
		            rcv3 = new ReceivingData("04/10/2016", "0");
		            rcv4 = new ReceivingData("03/10/2016", "0");
		            rcv5 = new ReceivingData("02/10/2016", "99");
	            } else if  (sec>= 30 && sec<40) {
	            	rcv1 = new ReceivingData("06/10/2016", "100");
		            rcv2 = new ReceivingData("05/10/2016", "100");
		            rcv3 = new ReceivingData("04/10/2016", "100");
		            rcv4 = new ReceivingData("03/10/2016", "100");
		            rcv5 = new ReceivingData("02/10/2016", "100");
	            } else if  (sec>= 40 && sec<50) {
	            	rcv1 = new ReceivingData("06/10/2016", "98");
		            rcv2 = new ReceivingData("05/10/2016", "97");
		            rcv3 = new ReceivingData("04/10/2016", "96");
		            rcv4 = new ReceivingData("03/10/2016", "95");
		            rcv5 = new ReceivingData("02/10/2016", "94");
	            } else if  (sec>= 50 && sec<60) {
	            	rcv1 = new ReceivingData("06/10/2016", "50");
		            rcv2 = new ReceivingData("05/10/2016", "55");
		            rcv3 = new ReceivingData("04/10/2016", "50");
		            rcv4 = new ReceivingData("03/10/2016", "55");
		            rcv5 = new ReceivingData("02/10/2016", "50");
	            }
	            
	            ReceivingData[] rcvData = {rcv1, rcv2, rcv3, rcv4, rcv5};
	            chart.setData(rcvData);
	       } catch (Exception e) {
	            SC.say("Error retrieving Receiving data. " + e);
//	            initialize();
	        }
		}

    
}
