Strabon

changeset 1225:3536728b4877

Areacharts can now be selected to display the results of queries with more than two variables in projection. In this case, the first variable is a string and its values appear in the horizontal axis of the chart. The numeric values appear on the y-axis, and the names of the variables with numeric values appear in the legend.
author Konstantina Bereta <Konstantina.Bereta@di.uoa.gr>
date Wed Jul 17 13:26:54 2013 +0300 (2013-07-17)
parents c7a49858bfbc
children d41dcbd64b02
files endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java
line diff
     1.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java	Wed Jul 17 11:04:22 2013 +0300
     1.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java	Wed Jul 17 13:26:54 2013 +0300
     1.3 @@ -194,40 +194,77 @@
     1.4  		if(answerFormatStrabon.equalsIgnoreCase(Format.PIECHART.toString()) || answerFormatStrabon.equalsIgnoreCase( Format.AREACHART.toString())){
     1.5  			TupleQueryResult result = (TupleQueryResult) strabon.query(queryString, Format.fromString(answerFormatStrabon), strabon.getSailRepoConnection(), out);
     1.6  			List<String> bindingNames = result.getBindingNames();
     1.7 -			if(bindingNames.size() !=2 ){
     1.8 -				logger.error("Strabon endpoint: to display results in chart, exactly TWO variables must be projected");
     1.9 +			if(bindingNames.size() !=2 && answerFormatStrabon.equalsIgnoreCase(Format.PIECHART.toString())){
    1.10 +				logger.error("Strabon endpoint: to display results in a pie chart, exactly TWO variables must be projected");
    1.11  			}
    1.12  			else{
    1.13 -	
    1.14 -			ArrayList<String> arr = new ArrayList<String>(2);
    1.15 -			arr.add(0, bindingNames.get(0));
    1.16 -			arr.add(1, bindingNames.get(1));
    1.17 +				if(answerFormatStrabon.equalsIgnoreCase(Format.PIECHART.toString())){
    1.18 +					
    1.19 +					ArrayList<String> arr = new ArrayList<String>(2);
    1.20 +					arr.add(0, bindingNames.get(0));
    1.21 +					arr.add(1, bindingNames.get(1));
    1.22  
    1.23 -			
    1.24 -			gChartString = "data.addColumn('string',\'"+arr.get(0)+"');\n";
    1.25 -			gChartString += "data.addColumn('number',\'"+arr.get(1)+"');\n";
    1.26 -			
    1.27 -			int i=1;
    1.28 -			int index=0;
    1.29 -			while(result.hasNext()){
    1.30 -				BindingSet bindings = result.next();
    1.31 -				arr.add(0, bindings.getValue(bindingNames.get(0)).stringValue());
    1.32 -				arr.add(1, bindings.getValue(bindingNames.get(1)).stringValue());
    1.33 +					gChartString +="var data = new google.visualization.DataTable();";
    1.34 +					gChartString += "data.addColumn('string',\'"+arr.get(0)+"');\n";
    1.35 +					gChartString += "data.addColumn('number',\'"+arr.get(1)+"');\n";
    1.36 +					
    1.37 +					int i=1;
    1.38 +					int index=0;
    1.39 +					while(result.hasNext()){
    1.40 +						BindingSet bindings = result.next();
    1.41 +						arr.add(0, bindings.getValue(bindingNames.get(0)).stringValue());
    1.42 +						arr.add(1, bindings.getValue(bindingNames.get(1)).stringValue());
    1.43 +						
    1.44 +						gChartString += "data.addRow([\'"+withoutPrefix(arr.get(0))+"\', "+
    1.45 +								arr.get(1).replace("\"", "").replace("^^","").replace("<http://www.w3.org/2001/XMLSchema#integer>","")+"]);\n";
    1.46 +								i++;	
    1.47 +					}
    1.48 +					gChartString += "var options = {'title':'','width':1000, 'height':1000, is3D: true};\n";
    1.49 +					gChartString += "var chart = new google.visualization.PieChart(document.getElementById('chart_div'));\n";
    1.50 +		
    1.51 +						
    1.52 +				}
    1.53 +				else if(answerFormatStrabon.equalsIgnoreCase(Format.AREACHART.toString())){
    1.54 +					int varNum = bindingNames.size();
    1.55 +					ArrayList<String> arr = new ArrayList<String>(varNum);
    1.56 +
    1.57 +					gChartString += "var data = google.visualization.arrayToDataTable([[";
    1.58 +					for(int j=0; j<varNum; j++){
    1.59 +						String chartValue =bindingNames.get(j);
    1.60 +							gChartString += "'"+chartValue+"'";
    1.61 +					
    1.62 +						if(j != varNum-1){
    1.63 +							gChartString+=",";
    1.64 +						}
    1.65 +					}
    1.66 +					gChartString += "],";
    1.67 +					
    1.68 +					while(result.hasNext()){
    1.69 +						BindingSet bindings = result.next();
    1.70 +						gChartString += "[";
    1.71 +						for(int j=0; j<varNum; j++){
    1.72 +							
    1.73 +							String chartValue =bindings.getValue(bindingNames.get(j)).stringValue();
    1.74 +							if(j==0){ //the first variable is a string variable.
    1.75 +								gChartString += "'"+withoutPrefix(chartValue).replace("\"", "")+"'";
    1.76 +							}
    1.77 +							else{ //numeric value
    1.78 +								gChartString += withoutPrefix(chartValue).replace("\"", "");
    1.79 +							}
    1.80 +							if(j != varNum-1){
    1.81 +								gChartString+=",";
    1.82 +							}
    1.83 +						}
    1.84 +						gChartString += "],";
    1.85 +					}
    1.86 +					gChartString += "]);";
    1.87 +					gChartString += " var options = {title: '', hAxis: {title:'"+ bindingNames.get(0) +"',  titleTextStyle: {color: \'red\'}}};";
    1.88 +					gChartString += "var chart = new google.visualization.AreaChart(document.getElementById('chart_div')); \n";
    1.89  				
    1.90 -				gChartString += "data.addRow([\'"+withoutPrefix(arr.get(0))+"\', "+
    1.91 -						arr.get(1).replace("\"", "").replace("^^","").replace("<http://www.w3.org/2001/XMLSchema#integer>","")+"]);\n";
    1.92 -						i++;	
    1.93 -			}
    1.94 -			if(answerFormatStrabon.equals(Format.PIECHART.toString())){
    1.95 -
    1.96 -				gChartString += "var options = {'title':'','width':1000, 'height':1000, is3D: true};\n";
    1.97 -				gChartString += "var chart = new google.visualization.PieChart(document.getElementById('chart_div'));\n";
    1.98 -			}else{
    1.99 -				gChartString += " var options = {title: '', hAxis: {title:'"+ bindingNames.get(0) +"',  titleTextStyle: {color: \'red\'}}};";
   1.100 -				gChartString += "var chart = new google.visualization.AreaChart(document.getElementById('chart_div')); \n";
   1.101 -			}
   1.102 +				}
   1.103  				
   1.104 -		}}
   1.105 +				
   1.106 +			}}
   1.107  		else{
   1.108  			strabon.query(queryString, Format.fromString(answerFormatStrabon), strabon.getSailRepoConnection(), out);
   1.109  		}