Commit 992c1429 authored by Matija Obreza's avatar Matija Obreza
Browse files

Charts and Maps

parent 85027c17
......@@ -32,7 +32,7 @@ public interface CountryRepository extends JpaRepository<Country, Long> {
// @Query("from Country c where c.code3= ?1 and c.current=true")
Country findByCode3(String code3);
Country findByCode2(String code2);
Country findByCode2AndCurrent(String code2, boolean current);
// List<Country> findByRegion(Region region);
......
......@@ -113,7 +113,11 @@ public class GeoServiceImpl implements GeoService {
if (isoCode.length() == 3) {
country = countryRepository.findByCode3(isoCode);
} else if (isoCode.length() == 2) {
country = countryRepository.findByCode2(isoCode);
// RO = ROU and ROM
country = countryRepository.findByCode2AndCurrent(isoCode, true);
if (country == null) {
country = countryRepository.findByCode2AndCurrent(isoCode, false);
}
}
return country;
......@@ -272,8 +276,8 @@ public class GeoServiceImpl implements GeoService {
* (country.getCode2().equals(countryInfo.getIso()) &&
* country.getCodeNum() != null &&
* country.getCodeNum().equals(countryInfo.getIsoNum())) { if
* (country.isCurrent() != countryInfo.isActive()) {
* LOG.warn("Country " + country + " is listed as active=" +
* (country.isCurrent() != countryInfo.isActive()) { LOG.warn(
* "Country " + country + " is listed as active=" +
* countryInfo.isActive() + " on remote site");
* country.setCurrent(countryInfo.isActive());
* countryRepository.save(country); } }
......@@ -287,7 +291,7 @@ public class GeoServiceImpl implements GeoService {
LOG.warn("geonames.org contry source not available");
return;
}
final List<CountryInfo> countries = geoNamesCountrySource.fetchCountryData();
if (LOG.isDebugEnabled()) {
......
/**
* Copyright 2015 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package org.genesys2.server.servlet.controller;
import java.io.IOException;
......@@ -6,16 +23,19 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.genesys2.server.model.filters.GenesysFilter;
import org.genesys2.server.service.ElasticService;
import org.genesys2.server.service.FilterConstants;
import org.genesys2.server.service.GeoService;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
import org.genesys2.server.service.impl.FilterHandler;
import org.genesys2.server.service.impl.SearchException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.facet.result.Term;
import org.springframework.data.elasticsearch.core.facet.result.TermResult;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
......@@ -26,8 +46,8 @@ import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
@Controller
@RequestMapping("/charts")
public class AccessionsWorldMapController extends BaseController {
@RequestMapping("/explore/0/charts")
public class ChartsController extends BaseController {
@Autowired
private ElasticService elasticService;
......@@ -35,15 +55,30 @@ public class AccessionsWorldMapController extends BaseController {
@Autowired
private GeoService geoService;
@Autowired
private FilterHandler filterHandler;
@Autowired
private ObjectMapper mapper;
@RequestMapping("/collections")
public String chartsCollection() {
return "/charts/collection";
@RequestMapping("/map")
public String chartsCollection(ModelMap model, @RequestParam(value = "filter", required = false, defaultValue = "{}") String jsonFilter) throws JsonParseException, JsonMappingException, IOException {
AppliedFilters appliedFilters = mapper.readValue(jsonFilter, AppliedFilters.class);
String[] selectedFilters = appliedFilters.getFilterNames();
final List<GenesysFilter> currentFilters = filterHandler.selectFilters(selectedFilters);
model.addAttribute("appliedFilters", appliedFilters);
model.addAttribute("currentFilters", currentFilters);
// JSP works with JsonObject
final Map<?, ?> filters = mapper.readValue(appliedFilters.toString(), Map.class);
model.addAttribute("filters", filters);
model.addAttribute("jsonFilter", appliedFilters.toString());
return "/charts/map";
}
@RequestMapping(value = "/collections/data", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE })
@RequestMapping(value = "data/country-collection-size", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE })
@ResponseBody
public List<Map<String, Object>> accessionsCollection(@RequestParam(value = "filter", required = false, defaultValue = "{}") String jsonFilter)
throws JsonParseException, JsonMappingException, IOException, SearchException {
......
......@@ -693,6 +693,8 @@ see-also.country=More about PGR conservation in {0}
help.page.intro=Visit the tutorials section to learn how to use Genesys.
chart.collections.title=Accessions in genebanks around the world
chart.attribution-text=www.genesys-pgr.org &copy;
charts=Charts and Maps
charts.intro=Here you'll find some useful charts and maps for your next presentation!
chart.collections.title=Size of genebank collections
chart.attribution-text=www.genesys-pgr.org
chart.collections.series=Number of accessions in genebanks
......@@ -13,7 +13,7 @@
<div class="main-col-header clearfix">
<div class="row">
<div class="col-xs-9 pull-right text-right">
<a class="btn btn-default" href="<c:url value="/explore"><c:param name="filter" value="${jsonFilter}" /></c:url>"><span class="glyphicon glyphicon-eye-open"></span><span style="margin-left: 0.5em;"><spring:message code="view.accessions" /></span></a>
<a class="btn btn-default" href="<c:url value="/explore"><c:param name="filter" value="${jsonFilter}" /></c:url>"><span class="glyphicon glyphicon-list"></span><span style="margin-left: 0.5em;"><spring:message code="view.accessions" /></span></a>
<a class="btn btn-default" href="<c:url value="/explore/map"><c:param name="filter" value="${jsonFilter}" /></c:url>"><span class="glyphicon glyphicon-globe"></span><span style="margin-left: 0.5em;"><spring:message code="maps.view-map" /></span></a>
</div>
<div class="col-xs-3 results">
......
<%@include file="/WEB-INF/jsp/init.jsp" %>
<html>
<head>
<title></title>
</head>
<body>
<div id="container" style="height: 500px; min-width: 310px; max-width: 800px; margin: 0 auto"></div>
<content tag="javascript">
<script type="text/javascript" src="<c:url value="/html/js/genesyshighcharts.min.js" />"></script>
<script type="text/javascript">
$(function () {
'use strict';
$.getJSON('/${pageContext.response.locale}/charts/collections/data', function (data) {
var mapData = Highcharts.geojson(Highcharts.maps['custom/world']);
$('#container').highcharts('Map', {
chart: {
borderWidth: 1
},
title: {
text: '<spring:message code="chart.collections.title" />'
},
subtitle: {
text: '<spring:message code="chart.attribution-text" />'
},
legend: {
enabled: false
},
mapNavigation: {
enabled: true,
buttonOptions: {
verticalAlign: 'top'
}
},
series: [{
name: 'Accessions',
mapData: mapData,
color: '#88ba42',
enableMouseTracking: false
}, {
type: 'mapbubble',
mapData: mapData,
name: '<spring:message code="chart.collections.series" />',
joinBy: ['iso-a2', 'code'],
data: data,
color: '#88ba42',
minSize: 20,
maxSize: '12%',
tooltip: {
pointFormat: '{point.country}: {point.z}'
}
}]
});
});
});
</script>
</content>
</body>
</html>
<%@include file="/WEB-INF/jsp/init.jsp" %>
<html>
<head>
<title></title>
</head>
<body>
<cms:informative-h1 title="charts" fancy="true" info="charts.intro" />
<div class="main-col-header clearfix">
<div class="row">
<div class="col-xs-9 pull-right text-right">
<a class="btn btn-default" href="<c:url value="/explore"><c:param name="filter" value="${jsonFilter}" /></c:url>"><span class="glyphicon glyphicon-list"></span><span style="margin-left: 0.5em;"><spring:message code="view.accessions" /></span></a>
<a class="btn btn-default" href="<c:url value="/explore/overview"><c:param name="filter">${jsonFilter}</c:param></c:url>"><span class="glyphicon glyphicon-eye-open"></span><span><spring:message code="data-overview.short" /></span></a>
<a class="btn btn-default" href="<c:url value="/explore/map"><c:param name="filter" value="${jsonFilter}" /></c:url>"><span class="glyphicon glyphicon-globe"></span><span style="margin-left: 0.5em;"><spring:message code="maps.view-map" /></span></a>
</div>
<div class="col-xs-3 results">
<a class="btn btn-default" href="javascript: window.history.go(-1);"><spring:message code="navigate.back" /></a>
</div>
</div>
</div>
<c:if test="${fn:length(currentFilters) gt 0}">
<div id="allfilters" class="disabled applied-filters">
<%-- Only render currently present filters --%>
<c:forEach items="${currentFilters}" var="filter">
<c:set var="normalizedKey" value="${filter.key.replace('.', '-').replace(':', '_')}"/>
<c:set var="appliedFilter" value="${appliedFilters.get(filter.key)}" />
<div class="clearfix filter-block" id="<c:out value="${normalizedKey}" />_filter" norm-key="<c:out value="${normalizedKey}" />" i-key="<c:out value="${filter.key}" />">
<div class="col-lg-3 edit-fil">
<c:if test="${not filter.core}">
<c:out value="${filter.title}" />
<%-- <a href="<c:url value="/descriptors/${filter.key}" />"> --%>
</c:if>
<c:if test="${filter.core}">
<spring:message code="filter.${filter.key}" />
</c:if>
</div>
<div class="col-lg-9">
<div class="filter-values" id="<c:out value="${normalizedKey}" />_value">
<c:if test="${appliedFilter.inverse}">
<spring:message code="filter.inverse" />
</c:if>
<c:forEach items="${filters[appliedFilter.key]}" var="value">
<c:set var="string" value="${value}"/>
<c:if test="${fn:contains(value, 'range')}">
<c:set var="string" value="${fn:replace(value,'{range=[','Between ')}"/>
<c:set var="string" value="${fn:replace(string,',',' and ')}"/>
<c:set var="string" value="${fn:replace(string,']}','')}"/>
<c:set var="value" value="${fn:replace(value,'{','{\"')}"/>
<c:set var="value" value="${fn:replace(value,'=','\":')}"/>
</c:if>
<c:if test="${fn:contains(value, 'min')}">
<c:set var="string" value="${fn:replace(value,'{min=','More than ')}"/>
<c:set var="string" value="${fn:replace(string,'}','')}"/>
<c:set var="value" value="${fn:replace(value,'{','{\"')}"/>
<c:set var="value" value="${fn:replace(value,'=','\":')}"/>
</c:if>
<c:if test="${fn:contains(value, 'max')}">
<c:set var="string" value="${fn:replace(value,'{max=','Less than ')}"/>
<c:set var="string" value="${fn:replace(string,'}','')}"/>
<c:set var="value" value="${fn:replace(value,'{','{\"')}"/>
<c:set var="value" value="${fn:replace(value,'=','\":')}"/>
</c:if>
<c:if test="${fn:contains(value, 'like')}">
<c:set var="string" value="${fn:replace(value,'{like=','Like ')}"/>
<c:set var="string" value="${fn:replace(string,'}','')}"/>
<c:set var="value" value="${fn:replace(value,'{','{\"')}"/>
<c:set var="value" value="${fn:replace(value,'=','\":\"')}"/>
<c:set var="value" value="${fn:replace(value,'}','\"}')}"/>
</c:if>
<c:if test="${string==null}">
<c:set var="string" value="null" />
<c:set var="value" value="null" />
</c:if>
<div class="filtval complex" x-key="<c:out value="${normalizedKey}" /><c:out value="${value}"/>" i-key="<c:out value="${filter.key}" />"><c:out value="${string}" /></div>
<c:remove var="string" />
</c:forEach>
</div>
</div>
</div>
</c:forEach>
</div>
</c:if>
<div id="container" style="min-height: 500px; min-width: 310px; margin: 0 auto"></div>
<content tag="javascript">
<script type="text/javascript" src="<c:url value="/html/js/genesyshighcharts.min.js" />"></script>
<script type="text/javascript">
$(function () {
'use strict';
$.getJSON('/${pageContext.response.locale}/explore/0/charts/data/country-collection-size' + window.location.search, function (data) {
var mapData = Highcharts.geojson(Highcharts.maps['custom/world']);
$('#container').highcharts('Map', {
chart: {
borderWidth: 1
},
title: {
text: '<spring:message code="chart.collections.title" />'
},
<%--
subtitle: {
text: '<spring:message code="chart.attribution-text" />'
},
--%>
legend: {
enabled: false
},
mapNavigation: {
enabled: true,
buttonOptions: {
verticalAlign: 'top'
}
},
series: [{
name: 'World',
mapData: mapData,
color: '#88ba42',
enableMouseTracking: false
}, {
type: 'mapbubble',
mapData: mapData,
name: '<spring:message code="chart.collections.series" />',
joinBy: ['iso-a2', 'code'],
data: data,
color: '#88ba42',
minSize: 20,
maxSize: '12%',
tooltip: {
pointFormat: '{point.country}: {point.z}'
}
}]
});
});
});
</script>
</content>
</body>
</html>
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