Strabon

changeset 1234:7728e6f633ca

Added another type of chart: columnchart. This type of chart is similar to AreaChart, so what was described in changeset #1225 applies in this case as well.
author Konstantina Bereta <Konstantina.Bereta@di.uoa.gr>
date Thu Jul 18 16:43:45 2013 +0300 (2013-07-18)
parents 6f23ffd29a1e
children 54eaaad0b72d
files 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/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java	Thu Jul 18 13:11:45 2013 +0300
     1.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java	Thu Jul 18 16:43:45 2013 +0300
     1.3 @@ -49,6 +49,7 @@
     1.4   * @author Manos Karpathiotakis <mk@di.uoa.gr>
     1.5   * @author Charalampos Nikolaou <charnik@di.uoa.gr>
     1.6   * @author Stella Giannakopoulou <sgian@di.uoa.gr>
     1.7 + * @author Konstantina Bereta <konstantina.bereta@di.uoa.gr>
     1.8   */
     1.9  public class QueryBean extends HttpServlet {
    1.10  
    1.11 @@ -139,14 +140,14 @@
    1.12  			// pass the other parameters as well
    1.13  			request.setAttribute("query", request.getParameter("query"));
    1.14  			if(request.getParameter("format").equalsIgnoreCase("PIECHART") || 
    1.15 -					request.getParameter("format").equalsIgnoreCase("AREACHART")){
    1.16 +					request.getParameter("format").equalsIgnoreCase("AREACHART")|| 
    1.17 +					request.getParameter("format").equalsIgnoreCase("COLUMNCHART")){
    1.18  				request.setAttribute("format", "CHART");
    1.19  			} else{
    1.20  				request.setAttribute("format", request.getParameter("format"));
    1.21  			}
    1.22  			request.setAttribute("handle", request.getParameter("handle"));
    1.23  			
    1.24 -			System.out.println("SET FORMAT: "+request.getAttribute("format"));
    1.25  			
    1.26  			// forward the request
    1.27  			dispatcher.forward(request, response);
    1.28 @@ -339,18 +340,16 @@
    1.29  					
    1.30  					try {
    1.31  						strabonWrapper.query(query, format, bos);
    1.32 -						//System.out.println("FORMAT: "+format);
    1.33  						if (format.equals(Common.getHTMLFormat())) {
    1.34  							request.setAttribute(RESPONSE, bos.toString());
    1.35  						} 
    1.36 -						else if(format.equals(Format.PIECHART.toString())){
    1.37 +						else if(format.equals(Format.PIECHART.toString())
    1.38 +								|| format.equals(Format.AREACHART.toString()) 
    1.39 +								|| format.equals(Format.COLUMNCHART.toString())){
    1.40  							request.setAttribute("format","CHART");
    1.41  							request.setAttribute(RESPONSE, strabonWrapper.getgChartString());
    1.42  						}
    1.43 -						else if(format.equals(Format.AREACHART.toString())){
    1.44 -							request.setAttribute("format","CHART");
    1.45 -							request.setAttribute(RESPONSE, strabonWrapper.getgChartString());
    1.46 -						}
    1.47 +	
    1.48  						else {
    1.49  							request.setAttribute(RESPONSE, StringEscapeUtils.escapeHtml(bos.toString()));
    1.50  						}
     2.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java	Thu Jul 18 13:11:45 2013 +0300
     2.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java	Thu Jul 18 16:43:45 2013 +0300
     2.3 @@ -191,7 +191,8 @@
     2.4  		if ((this.strabon == null) && (!init())) {
     2.5  			throw new RepositoryException("Could not connect to Strabon.");
     2.6  		} 
     2.7 -		if(answerFormatStrabon.equalsIgnoreCase(Format.PIECHART.toString()) || answerFormatStrabon.equalsIgnoreCase( Format.AREACHART.toString())){
     2.8 +		if(answerFormatStrabon.equalsIgnoreCase(Format.PIECHART.toString()) || answerFormatStrabon.equalsIgnoreCase( Format.AREACHART.toString())|| 
     2.9 +				answerFormatStrabon.equalsIgnoreCase( Format.COLUMNCHART.toString())){
    2.10  			TupleQueryResult result = (TupleQueryResult) strabon.query(queryString, Format.fromString(answerFormatStrabon), strabon.getSailRepoConnection(), out);
    2.11  			List<String> bindingNames = result.getBindingNames();
    2.12  			if(bindingNames.size() !=2 && answerFormatStrabon.equalsIgnoreCase(Format.PIECHART.toString())){
    2.13 @@ -224,7 +225,9 @@
    2.14  		
    2.15  						
    2.16  				}
    2.17 -				else if(answerFormatStrabon.equalsIgnoreCase(Format.AREACHART.toString())){
    2.18 +				else {
    2.19 +					
    2.20 +					String chartType;
    2.21  					int varNum = bindingNames.size();
    2.22  					ArrayList<String> arr = new ArrayList<String>(varNum);
    2.23  
    2.24 @@ -257,9 +260,14 @@
    2.25  						}
    2.26  						gChartString += "],";
    2.27  					}
    2.28 +					if(answerFormatStrabon.equalsIgnoreCase(Format.AREACHART.toString())){
    2.29 +						 chartType = "AreaChart";
    2.30 +					}else{
    2.31 +						 chartType = "ColumnChart";
    2.32 +					}
    2.33  					gChartString += "]);";
    2.34  					gChartString += " var options = {title: '', hAxis: {title:'"+ bindingNames.get(0) +"',  titleTextStyle: {color: \'red\'}}};";
    2.35 -					gChartString += "var chart = new google.visualization.AreaChart(document.getElementById('chart_div')); \n";
    2.36 +					gChartString += "var chart = new google.visualization."+chartType+"(document.getElementById('chart_div')); \n";
    2.37  				
    2.38  				}
    2.39  				
     3.1 --- a/resultio-spatial/api/src/main/java/org/openrdf/query/resultio/stSPARQLQueryResultFormat.java	Thu Jul 18 13:11:45 2013 +0300
     3.2 +++ b/resultio-spatial/api/src/main/java/org/openrdf/query/resultio/stSPARQLQueryResultFormat.java	Thu Jul 18 16:43:45 2013 +0300
     3.3 @@ -82,6 +82,9 @@
     3.4  	public static final stSPARQLQueryResultFormat AREACHART = new stSPARQLQueryResultFormat("AREACHART", 
     3.5  			Arrays.asList("text/plain"), Charset.forName("UTF-8"), Arrays.asList("areachart", "areachart"));
     3.6  	
     3.7 +	public static final stSPARQLQueryResultFormat COLUMNCHART = new stSPARQLQueryResultFormat("COLUMNCHART", 
     3.8 +			Arrays.asList("text/plain"), Charset.forName("UTF-8"), Arrays.asList("columnchart", "columnchart"));
     3.9 +	
    3.10  	/**
    3.11  	 * The available stSPARQLQuery Result Formats
    3.12  	 */
    3.13 @@ -97,6 +100,7 @@
    3.14  		register(HTML);
    3.15  		register(PIECHART);
    3.16  		register(AREACHART);
    3.17 +		register(COLUMNCHART);
    3.18  		
    3.19  	}
    3.20  	
     4.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Thu Jul 18 13:11:45 2013 +0300
     4.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Thu Jul 18 16:43:45 2013 +0300
     4.3 @@ -270,6 +270,9 @@
     4.4  				
     4.5  			case AREACHART:
     4.6  				return tupleQuery.evaluate();
     4.7 +
     4.8 +			case COLUMNCHART:
     4.9 +				return tupleQuery.evaluate();
    4.10  				
    4.11  			default:
    4.12  				// get the writer for the specified format
     5.1 --- a/runtime/src/main/java/eu/earthobservatory/utils/Format.java	Thu Jul 18 13:11:45 2013 +0300
     5.2 +++ b/runtime/src/main/java/eu/earthobservatory/utils/Format.java	Thu Jul 18 16:43:45 2013 +0300
     5.3 @@ -98,6 +98,8 @@
     5.4  	
     5.5  	PIECHART("PIECHART"),
     5.6  	
     5.7 +	COLUMNCHART("COLUMNCHART"),
     5.8 +	
     5.9  	AREACHART("AREACHART");
    5.10  	
    5.11  	/**