As we saw earlier, this class stores a reference to the map, data, and the initial year. The election results of the latter will be reflected on the shape first, as shown in the following code snippet:
var Shape = function (map, data, currentYear) { this._map = map; this._data = data; this._updateParty(currentYear); }
A shape will be filled with the color of the political party that has won the elections on the London Assembly area represented by that shape. For this, we create an object instance variable (_party
) with the id
extracted from the votes
array.
_updateParty: function(year) { this._party = { id: this._data.votes[year] }; this._party.name = PARTIES[this._party.id]; }
The party's name is fetched from a constant array we define at the top of the file, below the line specifying the YEARS
array.
var PARTIES = ['Conservative', 'Labour'];
These are the only two parties that have controlled the London Assembly in the past four elections, so we add only them to the...