Commit 0b5688a3 authored by stef's avatar stef

[fix] map for country filtered list

parent aff839f0
......@@ -226,8 +226,13 @@ def filter_violations(request, country, operator=None):
violations = Violation.objects.filter(activationid='', country=country, operator=operator)
if not request.GET.get('all'):
violations = violations.exclude(state__in=['duplicate', 'closed'])
countries=sorted([(i['total'],i['country'])
for i in Violation.objects.values('country').filter(activationid='',country=country).exclude(state__in=['duplicate', 'closed']).annotate(total=Count('country'))],
reverse=True)
countryweights=json.dumps([{'iso2': y, 'w': x} for x, y in countries])
return render_to_response('list.html',
{ "violations": violations,
"country": country,
"status": STATUS },
context_instance=RequestContext(request))
......
......@@ -6,20 +6,52 @@ $script.ready('kartograph', function() {
window.map = $K.map('#map');
map.loadMap('/site_media/eu.svg', function(map) {
map
.addLayer('eu', 'bgback')
.addLayer('eu', 'bg')
.addLayer('eu', 'bgstroke')
.addLayer({'id': 'eu',
'className': 'bgback',
filter: function(d) {
if(country.length==2) {
return d.iso2 == country;
}
return true;
}
})
.addLayer({'id': 'eu',
'className': 'bg',
filter: function(d) {
if(country.length==2) {
return d.iso2 == country;
}
return true;
}
})
.addLayer({'id': 'eu',
'className': 'bgstroke',
filter: function(d) {
if(country.length==2) {
return d.iso2 == country;
}
return true;
}
})
.addLayer({'id': 'countries', 'className': 'context'})
.addLayer('graticule')
.addLayer({'id': 'eu',
'className': 'fg',
filter: function(d) {
if(country.length==2) {
return d.iso2 == country;
}
return true;
},
'tooltip': {
content: function(obj,foo) {
var count=0;
for(var i=0;i<data.length;i++) {
if(data[i].iso2==foo.data.iso2) {
count=data[i].w;
break;
if(data) {
for(var i=0;i<data.length;i++) {
if(data[i].iso2==foo.data.iso2) {
count=data[i].w;
break;
}
}
}
if(count>0) {
......@@ -45,16 +77,18 @@ $script.ready('kartograph', function() {
limits: chroma.limits(data, 'q', 6, 'w')
});
map.choropleth({
data: data,
layer: 'fg',
key: 'iso2',
colors: function(d) {
if (d == null) return '#fff';
return colorscale.getColor(d['w']);
},
duration: 0
});
if(data) {
map.choropleth({
data: data,
layer: 'fg',
key: 'iso2',
colors: function(d) {
if (d == null) return '#fff';
return colorscale.getColor(d['w']);
},
duration: 0
});
}
});
});
});
......@@ -18,9 +18,8 @@
$script(['{{ MEDIA_URL }}/js/raphael.min.js', '{{ MEDIA_URL }}/js/kartograph.min.js', '{{ MEDIA_URL }}/js/chroma.min.js', '{{ MEDIA_URL }}/js/qtip.min.js'], 'kartograph');
</script>
<script type="text/javascript">
{% if countryweights %}
var data={{countryweights|safe}};
{% endif %}
var data={% if countryweights %}{{countryweights|safe}}{%else%}null{% endif %};
var country="{{country}}";
$script.ready(['jquery','tables'], function() {
$(document).ready(function() {
$.tablesorter.addParser({
......
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