Commit 19ebd712 authored by igoshin's avatar igoshin Committed by Matija Obreza

#13778 Add Flot charts

parent c6ef5dbb
......@@ -603,7 +603,8 @@
<include>leaflet.min.js</include>
<include>leaflet.locationfilter.min.js</include>
<include>crophub.min.js</include>
<include>syronex-colorpicker.min.js</include>
<include>jquery.flot.min.js</include>
<include>jquery.flot.pie.min.js</include>
</includes>
</aggregation>
......
......@@ -53,6 +53,9 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> {
@Query(value = "select t.genus, count(a.id) from Accession a inner join a.taxonomy t where a.institute = ?1 group by t.genus order by count(a) desc", countQuery = "select count(distinct a.taxGenus) from Accession a where a.institute = ?1")
Page<Object[]> statisticsGenusInInstitute(FaoInstitute institute, Pageable pageable);
@Query(value = "select t.genus, count(a.id) from Accession a inner join a.taxonomy t where a.institute = ?1 group by t.genus order by count(a) desc", countQuery = "select count(distinct a.taxGenus) from Accession a where a.institute = ?1")
List<Object[]> statisticsGenusInInstitute(FaoInstitute institute);
@Query(value = "select a.taxSpecies, count(a) from Accession a where a.institute = ?1 group by a.taxSpecies order by count(a) desc", countQuery = "select count(distinct a.taxSpecies) from Accession a where a.institute = ?1")
Page<Object[]> statisticsSpeciesInInstitute(FaoInstitute institute, Pageable pageable);
......
......@@ -101,7 +101,9 @@ public interface GenesysService {
Page<Object[]> statisticsGenusByInstitute(FaoInstitute faoInstitute, Pageable pageable);
Page<Object[]> statisticsSpeciesByInstitute(FaoInstitute faoInstitute, Pageable pageable);
List<Object[]> statisticsGenusByInstitute(FaoInstitute institute);
Page<Object[]> statisticsSpeciesByInstitute(FaoInstitute faoInstitute, Pageable pageable);
// Page<Object[]> statisticsCropByInstitute(FaoInstitute faoInstitute,
// Pageable pageable);
......
......@@ -423,6 +423,11 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
return accessionRepository.statisticsGenusInInstitute(institute, pageable);
}
@Override
public List<Object[]> statisticsGenusByInstitute(FaoInstitute institute) {
return accessionRepository.statisticsGenusInInstitute(institute);
}
@Override
public Page<Object[]> statisticsSpeciesByInstitute(FaoInstitute institute, Pageable pageable) {
final Page<Object[]> page = accessionRepository.statisticsSpeciesInInstitute(institute, pageable);
......
......@@ -36,12 +36,10 @@ import org.springframework.context.annotation.Scope;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.*;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
......@@ -118,6 +116,16 @@ public class WiewsController extends BaseController {
return "/wiews/details";
}
@RequestMapping(value = "/statJson",produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Object getStatisticForFlot(@RequestParam("wiewsCode") String wiewsCode){
final FaoInstitute faoInstitute = instituteService.getInstitute(wiewsCode);
if (faoInstitute == null) {
throw new ResourceNotFoundException();
}
return genesysService.statisticsGenusByInstitute(faoInstitute);
}
@RequestMapping("/{wiewsCode}/datasets")
public String viewDatasets(ModelMap model, @PathVariable(value = "wiewsCode") String wiewsCode, @RequestParam(value = "page", defaultValue = "1") int page) {
_logger.debug("Viewing datasets for instCode=" + wiewsCode);
......
......@@ -52,6 +52,8 @@
<script type="text/javascript" src="<c:url value="/html/js/leaflet.locationfilter.min.js" />"></script>
<script type="text/javascript" src="<c:url value="/html/js/genesys.min.js" />"></script>
<script type="text/javascript" src="<c:url value="/html/js/syronex-colorpicker-min.js" />"></script>
<script type="text/javascript" src="<c:url value="/html/js/jquery.flot.min.js" />"></script>
<script type="text/javascript" src="<c:url value="/html/js/jquery.flot.pie.min.js" />"></script>
</c:when>
<c:when test="${requestContext.theme.name eq 'all'}">
<script type="text/javascript" src="<c:url value="/html/js/jquery.js" />"></script>
......@@ -61,7 +63,10 @@
<script type="text/javascript" src="<c:url value="/html/js/leaflet.locationfilter.js" />"></script>
<script type="text/javascript" src="<c:url value="/html/js/genesys.js" />"></script>
<script type="text/javascript" src="<c:url value="/html/js/syronex-colorpicker.js" />"></script>
</c:when>
<script type="text/javascript" src="<c:url value="/html/js/jquery.flot.js" />"></script>
<script type="text/javascript" src="<c:url value="/html/js/jquery.flot.pie.js" />"></script>
</c:when>
<c:otherwise>
<script type="text/javascript" src="<c:url value="/html/js/jquery.js" />"></script>
<script type="text/javascript" src="<c:url value="/html/js/jquery-ui.js" />"></script>
......@@ -71,6 +76,8 @@
<script type="text/javascript" src="<c:url value="/html/js/leaflet.locationfilter.js" />"></script>
<script type="text/javascript" src="<c:url value="/html/js/crophub.js" />"></script>
<script type="text/javascript" src="<c:url value="/html/js/syronex-colorpicker.js" />"></script>
<script type="text/javascript" src="<c:url value="/html/js/jquery.flot.js" />"></script>
<script type="text/javascript" src="<c:url value="/html/js/jquery.flot.pie.js" />"></script>
</c:otherwise>
</c:choose>
......
......@@ -111,7 +111,12 @@
<%-- <h3>
<spring:message code="faoInstitute.statistics" />
</h3> --%>
<div class="row">
<div id="flot" style="width:555px;height:300px"></div>
</div>
<div class="row" style="margin-top: 2em;">
<%-- <c:if test="${statisticsCrop ne null}">
......@@ -174,6 +179,84 @@
<%@include file="/WEB-INF/jsp/wiews/ga.jsp"%>
_pageDim = { institute: '${faoInstitute.code}' };
</script>
<script>
jQuery(document).ready(function() {
function makeDataForFlot(data){
var dataFlot = [];
var other = 0;
$.each(data, function (idx, statistic) {
if (idx < 9) {
dataFlot[idx] = {
label: statistic[0],
data: statistic[1]
}
} else {
other = statistic[1] + other;
dataFlot[9] = {
label: "Other",
data: other
}
}
});
return dataFlot;
}
$.ajax("/wiews/statJson", {
data: "wiewsCode=" + "${faoInstitute.code}",
success: function (data) {
var placeholder = $('#flot');
$("<div id='tooltip'></div>").css({
position: "absolute",
display: "none",
border: "1px solid #929292",
padding: "2px",
"background-color": "#929292",
opacity: 0.80
}).appendTo("body");
$.plot(placeholder, makeDataForFlot(data), {
series: {
pie: {
show: true
}
},
grid: {
hoverable: true,
clickable: true
},
legend: {
show: false
}
});
placeholder.bind("plothover", function (event, pos, obj) {
if (obj != null) {
var str = obj.series.label + " (" + obj.datapoint[1][0][1] + ")";
$("#hoverdata").text(str);
$("#tooltip").html(str)
.css({top: pos.pageY - 25, left: pos.pageX + 5})
.show();
}else{
$("#tooltip").hide();
}
});
placeholder.bind("plotclick", function (event, pos, obj) {
if (obj != null) {
window.location.replace(window.location.href + "/t/" + obj.series.label);
}
});
},
error: function (error) {
console.log(error);
}
});
});
</script>
</content>
</body>
</html>
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
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