Commit a6d4b9b4 authored by Matija Obreza's avatar Matija Obreza

Updates and reverts to charts

parent f106889c
......@@ -28,15 +28,15 @@ import javax.persistence.PrePersist;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import org.apache.commons.lang3.StringUtils;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.genesys2.server.model.GlobalVersionedAuditedModel;
import org.genesys2.server.model.impl.CropTaxonomy;
import org.hibernate.annotations.Type;
import org.hibernate.search.annotations.Indexed;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@Entity
// Add index on all fields
@Table(name = "taxonomy2", uniqueConstraints = { @UniqueConstraint(columnNames = { "genus", "species", "spAuthor", "subtaxa", "subtAuthor" }) })
......
......@@ -19,6 +19,7 @@ package org.genesys2.server.servlet.controller;
import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
......@@ -118,7 +119,7 @@ public class WiewsController extends BaseController {
@RequestMapping(value = "/{wiewsCode}/stat-genus",produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Object getGenusStats(@PathVariable(value = "wiewsCode") String wiewsCode){
public List<Object[]> getGenusStats(@PathVariable(value = "wiewsCode") String wiewsCode){
final FaoInstitute faoInstitute = instituteService.getInstitute(wiewsCode);
if (faoInstitute == null) {
throw new ResourceNotFoundException();
......@@ -128,12 +129,12 @@ public class WiewsController extends BaseController {
@RequestMapping(value = "/{wiewsCode}/stat-species",produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Object getSpeciesStats(@PathVariable(value = "wiewsCode") String wiewsCode){
public List<Object[]> getSpeciesStats(@PathVariable(value = "wiewsCode") String wiewsCode){
final FaoInstitute faoInstitute = instituteService.getInstitute(wiewsCode);
if (faoInstitute == null) {
throw new ResourceNotFoundException();
}
return genesysService.statisticsSpeciesByInstitute(faoInstitute, new PageRequest(0, 10)).getContent();
return genesysService.statisticsSpeciesByInstitute(faoInstitute, new PageRequest(0, 20)).getContent();
}
@RequestMapping("/{wiewsCode}/datasets")
......
......@@ -16,7 +16,10 @@
package org.genesys2.spring.config;
import java.util.*;
import java.util.HashSet;
import java.util.Locale;
import java.util.Properties;
import java.util.Set;
import org.genesys2.spring.AddStuffInterceptor;
import org.genesys2.spring.BetterSessionLocaleResolver;
......@@ -30,8 +33,6 @@ import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Scope;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
import org.springframework.validation.Validator;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
......@@ -63,17 +64,6 @@ public class SpringServletConfig extends WebMvcConfigurerAdapter {
registry.addResourceHandler("/html/**").addResourceLocations("/html/");
}
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(converter());
}
@Bean
public MappingJacksonHttpMessageConverter converter() {
MappingJacksonHttpMessageConverter converter = new MappingJacksonHttpMessageConverter();
return converter;
}
@Bean
public ViewResolver viewResolver() {
final org.springframework.web.servlet.view.InternalResourceViewResolver resolver = new org.springframework.web.servlet.view.InternalResourceViewResolver();
......
......@@ -128,7 +128,9 @@
<div class="col-sm-6">
<h4><spring:message code="faoInstitute.stat-by-genus" arguments="${statisticsGenus.numberOfElements}" /></h4>
<div id="chartStatsByGenus" style="height:300px"></div>
<div class="chart chart-pie">
<div id="chartStatsByGenus" style="height:300px;"></div>
</div>
<ul class="funny-list statistics">
<c:forEach items="${statisticsGenus.content}" var="stat" varStatus="status">
......@@ -140,7 +142,9 @@
<div class="col-sm-6">
<h4><spring:message code="faoInstitute.stat-by-species" arguments="${statisticsTaxonomy.numberOfElements}" /></h4>
<div id="chartStatsBySpecies" style="height:300px"></div>
<div class="chart chart-pie">
<div id="chartStatsBySpecies" style="height:300px"></div>
</div>
<ul class="funny-list statistics">
<c:forEach items="${statisticsTaxonomy.content}" var="stat" varStatus="status">
......@@ -171,7 +175,12 @@
minZoom: 4,
maxZoom: 6, /* WIEWS does not provide enough detail */
center: new GenesysMaps.LatLng(${faoInstitute.latitude}, ${faoInstitute.longitude}),
markerTitle: "<spring:escapeBody javaScriptEscape="true">${faoInstitute.fullName}</spring:escapeBody>"
markerTitle: "<spring:escapeBody javaScriptEscape="true">${faoInstitute.fullName}</spring:escapeBody>",
scrollWheelZoom: false,
touchZoom: false,
dragging: false,
doubleClickZoom: false,
boxZoom: false
});
});
</script>
......@@ -182,8 +191,8 @@
</script>
<script>
jQuery(document).ready(function () {
GenesysChart.chart("#chartStatsByGenus", "/wiews/${faoInstitute.code}/stat-genus", null);
GenesysChart.chart("#chartStatsBySpecies", "/wiews/${faoInstitute.code}/stat-species", null);
GenesysChart.chart("#chartStatsByGenus", "/wiews/${faoInstitute.code}/stat-genus", null, null, function(genus) { window.location=window.location.pathname + "/t/" + genus; });
GenesysChart.chart("#chartStatsBySpecies", "/wiews/${faoInstitute.code}/stat-species", null, function(taxonomy) { return taxonomy.taxonName; }, function(taxonomy) { window.location=window.location.pathname + "/t/" + taxonomy.genus + "/" + taxonomy.species; });
});
</script>
</content>
......
......@@ -1959,3 +1959,6 @@ html[dir="rtl"] ul.statistics .stats-number {
padding: 0px 8px;
}
.chart.chart-pie {
padding: 10px;
}
\ No newline at end of file
......@@ -97,7 +97,7 @@ GenesysMaps.BoundingBox.prototype.getBounds = function() {
};
GenesysChart = {
chart: function (placeholder, url, options) {
chart: function (placeholder, url, options, labelCallback, clickCallback) {
var defaultOptions = {
series: {
......@@ -117,14 +117,12 @@ GenesysChart = {
}
};
if(options!=null){
defaultOptions=options;
}
var opts=$.extend(true, defaultOptions, options);
$.ajax(url, {
success: function (data) {
$.plot($(placeholder), GenesysChart.makeDataForFlot(data), defaultOptions);
$.plot($(placeholder), GenesysChart.makeDataForFlot(data, labelCallback), opts);
$("<div class='tooltip-chart'></div>").css({
position: "absolute",
......@@ -159,15 +157,8 @@ GenesysChart = {
});
$(placeholder).bind("plotclick", function (event, pos, obj) {
if (obj != null) {
var params = obj.series.label.split(" ");
if (typeof params[1] != "undefined") {
window.location.replace(window.location.href + "/t/" + params[0] + "/" + params[1]);
} else {
window.location.replace(window.location.href + "/t/" + params[0]);
}
if (obj != null && obj.series.labelSource != null && clickCallback != null) {
return clickCallback(obj.series.labelSource);
}
});
},
......@@ -177,19 +168,19 @@ GenesysChart = {
});
},
makeDataForFlot: function (data) {
makeDataForFlot: function (data, labelCallback) {
var dataFlot = [];
$.each(data, function (idx, statistic) {
var label;
if(typeof statistic[0]=="object"){
label=statistic[0]["taxonName"];
}else if(typeof statistic[0]=="string"){
label=statistic[0];
}
if (statistic[0]!=null && labelCallback != null) {
label = labelCallback(statistic[0]);
} else if (typeof statistic[0]=="string") {
label = statistic[0];
}
dataFlot[idx] = {
labelSource: statistic[0],
label: label,
data: statistic[1]
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment