Strabon

changeset 1220:29b9763c5db4

added Areachart to the available chart formats & did some beautifications in the code
author Konstantina Bereta <Konstantina.Bereta@di.uoa.gr>
date Mon Jul 15 14:27:49 2013 +0300 (2013-07-15)
parents faf2ee0185df
children bf3cb3f5ebe5
files endpoint/WebContent/query.jsp endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java resultio-spatial/api/src/main/java/org/openrdf/query/resultio/stSPARQLQueryResultFormat.java runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java runtime/src/main/java/eu/earthobservatory/utils/Format.java
line diff
     1.1 --- a/endpoint/WebContent/query.jsp	Tue Jul 09 19:13:01 2013 +0300
     1.2 +++ b/endpoint/WebContent/query.jsp	Mon Jul 15 14:27:49 2013 +0300
     1.3 @@ -226,15 +226,12 @@
     1.4        
     1.5          // Create the data table.
     1.6          var data = new google.visualization.DataTable();
     1.7 -        <% if (request.getParameter("format")!=null && request.getAttribute("response") != null) {
     1.8 -        	if (request.getParameter("format").equals("CHART")) {
     1.9 +        <% if (request.getAttribute("format")!=null && request.getAttribute("response") != null) {
    1.10 +        	if (request.getAttribute("format").equals("CHART")) {
    1.11          		out.println(request.getAttribute("response"));	  
    1.12          		 %>
    1.13        
    1.14 -        var options = {'title':'Displaying results in chart','width':1000, 'height':1000};
    1.15 -
    1.16 -      
    1.17 -        var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
    1.18 + 
    1.19          chart.draw(data, options);
    1.20          
    1.21          <%}}%>
    1.22 @@ -377,8 +374,8 @@
    1.23  <div id="divResultsStart"></div>
    1.24  	<!-- Response -->
    1.25  <% 
    1.26 -if (request.getAttribute("response") != null && !request.getParameter("format").equals("CHART")) {
    1.27 -	if (!Common.getHTMLFormat().equals(request.getParameter("format"))) {%>
    1.28 +if (request.getAttribute("response") != null && !request.getAttribute("format").equals("CHART")) {
    1.29 +	if (!Common.getHTMLFormat().equals(request.getAttribute("format"))) {%>
    1.30  		<%=request.getAttribute("response")%>
    1.31  	<%} else {
    1.32  		%>
     2.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java	Tue Jul 09 19:13:01 2013 +0300
     2.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java	Mon Jul 15 14:27:49 2013 +0300
     2.3 @@ -138,9 +138,16 @@
     2.4  			
     2.5  			// pass the other parameters as well
     2.6  			request.setAttribute("query", request.getParameter("query"));
     2.7 -			request.setAttribute("format", request.getParameter("format"));
     2.8 +			if(request.getParameter("format").equalsIgnoreCase("PIECHART") || 
     2.9 +					request.getParameter("format").equalsIgnoreCase("AREACHART")){
    2.10 +				request.setAttribute("format", "CHART");
    2.11 +			} else{
    2.12 +				request.setAttribute("format", request.getParameter("format"));
    2.13 +			}
    2.14  			request.setAttribute("handle", request.getParameter("handle"));
    2.15  			
    2.16 +			System.out.println("SET FORMAT: "+request.getAttribute("format"));
    2.17 +			
    2.18  			// forward the request
    2.19  			dispatcher.forward(request, response);
    2.20  			
    2.21 @@ -336,7 +343,13 @@
    2.22  						if (format.equals(Common.getHTMLFormat())) {
    2.23  							request.setAttribute(RESPONSE, bos.toString());
    2.24  						} 
    2.25 -						else if(format.equals(Format.CHART.toString())){
    2.26 +						else if(format.equals(Format.PIECHART.toString())){
    2.27 +							request.setAttribute("format","CHART");
    2.28 +							System.out.println("Format set= "+ request.getAttribute("format"));
    2.29 +							request.setAttribute(RESPONSE, strabonWrapper.getgChartString());
    2.30 +						}
    2.31 +						else if(format.equals(Format.AREACHART.toString())){
    2.32 +							request.setAttribute("format","CHART");
    2.33  							request.setAttribute(RESPONSE, strabonWrapper.getgChartString());
    2.34  						}
    2.35  						else {
     3.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java	Tue Jul 09 19:13:01 2013 +0300
     3.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java	Mon Jul 15 14:27:49 2013 +0300
     3.3 @@ -191,7 +191,7 @@
     3.4  		if ((this.strabon == null) && (!init())) {
     3.5  			throw new RepositoryException("Could not connect to Strabon.");
     3.6  		} 
     3.7 -		if(answerFormatStrabon.equalsIgnoreCase(Format.CHART.toString())){
     3.8 +		if(answerFormatStrabon.equalsIgnoreCase(Format.PIECHART.toString()) || answerFormatStrabon.equalsIgnoreCase( Format.AREACHART.toString())){
     3.9  			TupleQueryResult result = (TupleQueryResult) strabon.query(queryString, Format.fromString(answerFormatStrabon), strabon.getSailRepoConnection(), out);
    3.10  			List<String> bindingNames = result.getBindingNames();
    3.11  			if(bindingNames.size() !=2 ){
    3.12 @@ -213,33 +213,23 @@
    3.13  				BindingSet bindings = result.next();
    3.14  				arr.add(0, bindings.getValue(bindingNames.get(0)).stringValue());
    3.15  				arr.add(1, bindings.getValue(bindingNames.get(1)).stringValue());
    3.16 -//.replace("<http://www.w3.org/2001/XMLSchema#integer>","")
    3.17 -				if(!arr.get(0).contains("http") ){ //plain literal case- no prefixes to remove
    3.18 -					gChartString += "data.addRow([\'"+arr.get(0)+"\', "+
    3.19 -							arr.get(1).replace("\"", "").replace("^^","")+"]);\n";
    3.20 -							i++;	
    3.21 -				}
    3.22 -				else{ //URI case
    3.23 -					//removing prefixes so that they will not be displayed in the chart
    3.24 -					if(arr.get(0).lastIndexOf('#') > arr.get(0).lastIndexOf('/')){
    3.25 -						index = arr.get(0).lastIndexOf('#')+1;
    3.26 -					}
    3.27 -					else{
    3.28 -						index = arr.get(0).lastIndexOf("/")+1;
    3.29 -					}
    3.30 -					
    3.31 -					int endIndex= arr.get(0).length();
    3.32 -					gChartString += "data.addRow([\'"+arr.get(0).subSequence(index, endIndex )+"\', "+
    3.33 -					arr.get(1).replace("\"", "").replace("^^","").replace("<http://www.w3.org/2001/XMLSchema#integer>","")+"]);\n";
    3.34 -					i++;	
    3.35 -				}
    3.36  				
    3.37 +				gChartString += "data.addRow([\'"+withoutPrefix(arr.get(0))+"\', "+
    3.38 +						arr.get(1).replace("\"", "").replace("^^","").replace("<http://www.w3.org/2001/XMLSchema#integer>","")+"]);\n";
    3.39 +						i++;	
    3.40  			}
    3.41 -			 /* gChartString += "var options = {'title':'Displaying results in chart','width':400, 'height':300};";
    3.42 -			  gChartString += "var chart = new google.visualization.PieChart(document.getElementById('chart_div'));";
    3.43 -			  gChartString += "chart.draw(data, options);";*/
    3.44 -			//System.out.println(gChartString);
    3.45 +			if(answerFormatStrabon.equals(Format.PIECHART.toString())){
    3.46  
    3.47 +				gChartString += "var options = {'title':'','width':1000, 'height':1000, is3D: true};\n";
    3.48 +				gChartString += "var chart = new google.visualization.PieChart(document.getElementById('chart_div'));\n";
    3.49 +			}else{
    3.50 +				gChartString += " var options = {title: '', hAxis: {title:'"+ bindingNames.get(0) +"',  titleTextStyle: {color: \'red\'}}};";
    3.51 +				gChartString += "var chart = new google.visualization.AreaChart(document.getElementById('chart_div')); \n";
    3.52 +			}
    3.53 +
    3.54 +				System.out.println(gChartString);
    3.55 +
    3.56 +				
    3.57  		}}
    3.58  		else{
    3.59  			strabon.query(queryString, Format.fromString(answerFormatStrabon), strabon.getSailRepoConnection(), out);
    3.60 @@ -446,6 +436,25 @@
    3.61  	}
    3.62  	
    3.63  	
    3.64 +	public String withoutPrefix(String inputURI){
    3.65 +		int index;
    3.66 +	
    3.67 +		if(!inputURI.contains("http") ){ //plain literal case- no prefixes to remove
    3.68 +			return inputURI;
    3.69 +		}
    3.70 +		else{ //URI case
    3.71 +			//removing prefixes so that they will not be displayed in the chart
    3.72 +			if(inputURI.lastIndexOf('#') > inputURI.lastIndexOf('/')){
    3.73 +				index = inputURI.lastIndexOf('#')+1;
    3.74 +			}
    3.75 +			else{
    3.76 +				index = inputURI.lastIndexOf("/")+1;
    3.77 +			}
    3.78 +			
    3.79 +			int endIndex= inputURI.length();
    3.80 +			return  inputURI.substring(index, endIndex );
    3.81  
    3.82 +	}
    3.83 +	}
    3.84  }
    3.85  
     4.1 --- a/resultio-spatial/api/src/main/java/org/openrdf/query/resultio/stSPARQLQueryResultFormat.java	Tue Jul 09 19:13:01 2013 +0300
     4.2 +++ b/resultio-spatial/api/src/main/java/org/openrdf/query/resultio/stSPARQLQueryResultFormat.java	Mon Jul 15 14:27:49 2013 +0300
     4.3 @@ -76,8 +76,11 @@
     4.4  	/**
     4.5  	 * CHART format (so that results can be displayed using google charts)  
     4.6  	 */
     4.7 -	public static final stSPARQLQueryResultFormat CHART = new stSPARQLQueryResultFormat("CHART", 
     4.8 -			Arrays.asList("text/plain"), Charset.forName("UTF-8"), Arrays.asList("chart", "chart"));
     4.9 +	public static final stSPARQLQueryResultFormat PIECHART = new stSPARQLQueryResultFormat("PIECHART", 
    4.10 +			Arrays.asList("text/plain"), Charset.forName("UTF-8"), Arrays.asList("piechart", "piechart"));
    4.11 +	
    4.12 +	public static final stSPARQLQueryResultFormat AREACHART = new stSPARQLQueryResultFormat("AREACHART", 
    4.13 +			Arrays.asList("text/plain"), Charset.forName("UTF-8"), Arrays.asList("areachart", "areachart"));
    4.14  	
    4.15  	/**
    4.16  	 * The available stSPARQLQuery Result Formats
    4.17 @@ -92,8 +95,9 @@
    4.18  		register(GEOJSON);
    4.19  		register(TSV);
    4.20  		register(HTML);
    4.21 -		register(CHART);
    4.22 -
    4.23 +		register(PIECHART);
    4.24 +		register(AREACHART);
    4.25 +		
    4.26  	}
    4.27  	
    4.28  	/**
     5.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Tue Jul 09 19:13:01 2013 +0300
     5.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Mon Jul 15 14:27:49 2013 +0300
     5.3 @@ -265,7 +265,10 @@
     5.4  				
     5.5  				return tupleQuery;
     5.6  //				break;	
     5.7 -			case CHART:
     5.8 +			case PIECHART:
     5.9 +				return tupleQuery.evaluate();
    5.10 +				
    5.11 +			case AREACHART:
    5.12  				return tupleQuery.evaluate();
    5.13  				
    5.14  			default:
     6.1 --- a/runtime/src/main/java/eu/earthobservatory/utils/Format.java	Tue Jul 09 19:13:01 2013 +0300
     6.2 +++ b/runtime/src/main/java/eu/earthobservatory/utils/Format.java	Mon Jul 15 14:27:49 2013 +0300
     6.3 @@ -96,7 +96,9 @@
     6.4  	 */
     6.5  	INVALID("INVALID"),
     6.6  	
     6.7 -	CHART("CHART");
     6.8 +	PIECHART("PIECHART"),
     6.9 +	
    6.10 +	AREACHART("AREACHART");
    6.11  	
    6.12  	/**
    6.13  	 * The string representation of this format