This commit is contained in:
Joshua Widmann 2015-02-08 18:47:41 +01:00
commit 0d984bb2ed

View file

@ -66,8 +66,7 @@ class Visualization {
this._$categoryList.on('click', 'a', e => {
$(e.target).parent().toggleClass('active')
var categories = this.getActiveCategories()
var incidents = filter.byCategories(this.data, categories)
var incidents = this.filterAll()
this.displayMarkers(incidents)
e.preventDefault()
@ -78,6 +77,14 @@ class Visualization {
return this
}
/**
* Get currently active year
* @return {String}
*/
getCurrentYear () {
return this._$yearList.children('.active').find('a').data().showYear
}
/**
* Creates the year list which optionally already holds a button for "all"
* @param {jQuery.Selector} selector The container holding
@ -110,9 +117,7 @@ class Visualization {
$target.parent().siblings().removeClass('active')
$target.parent().addClass('active')
var year = $target.data().showYear
var incidents = (year) ? filter.byYear(this.data, year) : this.data
var incidents = this.filterAll()
this.displayMarkers(incidents)
e.preventDefault()
@ -123,6 +128,14 @@ class Visualization {
return this
}
filterAll () {
var year = this.getCurrentYear()
var categories = this.getActiveCategories()
var byYear = (year) ? filter.byYear(this.data, year) : this.data
return filter.byCategories(byYear, categories)
}
/**
* Sets up all markers for the first time so afterwards they only need to be
* faded in and out