package it.unimi.di.laren.smartwash.View;

import com.jjoe64.graphview.BarGraphView;
import com.jjoe64.graphview.GraphView;
import com.jjoe64.graphview.GraphViewSeries;
import com.jjoe64.graphview.GraphView.GraphViewData;

import it.unimi.di.laren.smartwash.R;
import it.unimi.di.laren.smartwash.R.layout;
import it.unimi.di.laren.smartwash.R.menu;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Color;
import android.util.Log;
import android.view.Menu;
import android.widget.RelativeLayout;

public class GraphActivity extends Activity {
	String str = "";
	Double a, b, c, d, e, f, g, h, i, j;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_graph);
		Bundle extras = getIntent().getExtras();

		if (extras == null) {
			return;
		}
		else
		{
			str = extras.getString("RANGE");
		}
		 String[] temp;
		 
		  /* delimiter */
		  String delimiter = ",";
		  /* given string will be split by the argument delimiter provided. */
		  temp = str.split(delimiter);
		  /* print substrings */
		  for(int i =0; i < temp.length ; i++){
		    Log.i("temp:", " " + temp[i]);
		  }
		  a = Double.parseDouble(temp[0]);
		  b = Double.parseDouble(temp[1]);
		  c = Double.parseDouble(temp[2]);
		  d = Double.parseDouble(temp[3]);
		  e = Double.parseDouble(temp[4]);
		  f = Double.parseDouble(temp[5]);
		  g = Double.parseDouble(temp[6]);
		  h = Double.parseDouble(temp[7]);
		  i = Double.parseDouble(temp[8]);
		  j = Double.parseDouble(temp[9]);
		  Double somma = a+b+c+d+e+f+g+h+i+j;
		  a = (Double)((Double)a*100)/somma;
		  b = (Double)((Double)b*100)/somma;
		  c = (Double)((Double)c*100)/somma;
		  d = (Double)((Double)d*100)/somma;
		  e = (Double)((Double)e*100)/somma;
		  f = (Double)((Double)f*100)/somma;
		  g = (Double)((Double)g*100)/somma;
		  h = (Double)((Double)h*100)/somma;
		  i = (Double)((Double)i*100)/somma;
		  j = (Double)((Double)j*100)/somma;
		  Log.i("Somma", ": " + somma);
		  Log.i("percent:", " a " + a);
		  Log.i("percent:", " b " + b);
		  Log.i("percent:", " c " + c);
		  Log.i("percent:", " d " + d);
		  Log.i("percent:", " e " + e);
		  Log.i("percent:", " f " + f);
		  Log.i("percent:", " g " + g);
		  Log.i("percent:", " h " + h);
		  Log.i("percent:", " i " + i);
		  Log.i("percent:", " j " + j);
		GraphViewSeries exampleSeries = new GraphViewSeries(new GraphViewData[] {  
				new GraphViewData(0, a)
				, new GraphViewData(0.5, b)  
                , new GraphViewData(1, c)  
                , new GraphViewData(1.5, d)
                , new GraphViewData(2, e)
                , new GraphViewData(2.5, f)
                , new GraphViewData(3, g)
                , new GraphViewData(3.5, h)
                , new GraphViewData(4, i)
				, new GraphViewData(4.5, j)
      });  
          GraphView graphView = new BarGraphView(  
                this // context  
                , "" // heading  
          ); 
          graphView.getGraphViewStyle().setGridColor(Color.WHITE);  
          graphView.getGraphViewStyle().setHorizontalLabelsColor(Color.BLUE);  
          graphView.getGraphViewStyle().setVerticalLabelsColor(Color.BLUE);  
          graphView.getGraphViewStyle().setTextSize(13);  
          graphView.getGraphViewStyle().setNumVerticalLabels(20);
          graphView.getGraphViewStyle().setNumHorizontalLabels(13);
          graphView.setHorizontalLabels(new String[] {"0", "0.5", "1", "1.5", "2", "2.5", "3", "3.5", "4", "4.5", "5", "5.5", "6"});
          //graphView.setVerticalLabels(new String[] {"100", "95", "90", "85", "80", "75", "70", "65", "60", "55", "50", "45", "40", "35", "30", "25", "20", "15", "10", "5", "0"});
          graphView.addSeries(exampleSeries); // data  
          RelativeLayout layout = (RelativeLayout) findViewById(R.id.layout);  
          layout.addView(graphView);  
	}

	
}
