Commit 7441fb42 authored by Kjetil Thuen's avatar Kjetil Thuen

Sort by year and age to make browsers behave alike

parent 431ac8ca
......@@ -39,20 +39,28 @@ prepareFuncFactory = (successCallback, errorCallback) ->
parseInt(cell.tid) - parseInt(cell.alder)
flattenedValuesByYearAndBirthYear =
lodash.mapValues valuesByYearAndBirthYear, (years) ->
lodash.filter lodash.map(years, (birthYear) ->
{
birthyear: parseInt(birthYear[0].tid) -
parseInt(birthYear[0].alder)
year: parseInt birthYear[0].tid
age: parseInt birthYear[0].alder
label: parseInt birthYear[0].alder
rvalue: birthYear[0].value
lvalue: birthYear[1].value
}
), (cell) ->
#Ages < 100 are really age groups. Eeeeewww!
cell.age < 100
lodash.chain lodash.values(valuesByYearAndBirthYear)
.map (year) ->
lodash.map lodash.values(year), (birthYear) ->
{
birthyear: parseInt(birthYear[0].tid) -
parseInt(birthYear[0].alder)
year: parseInt birthYear[0].tid
age: parseInt birthYear[0].alder
label: parseInt birthYear[0].alder
rvalue: birthYear[0].value
lvalue: birthYear[1].value
}
.flatten true
#Ages < 100 are really age groups. Eeeeewww!
.filter (cell) -> cell.age < 100
#Explicit ordering to work around browser strangeness
.sortBy 'year'
.reverse true
.sortBy 'age'
.reverse true
.groupBy 'year'
.value()
successCallback flattenedValuesByYearAndBirthYear
else
......
......@@ -407,9 +407,9 @@ displayPoster = (chartId, icon, header, message) ->
#Constructor.
#
#The data parameter should be an object with named years. Each year member
#should be an array with at least two members (male and female, further members
#are ignored), each element in these arrays should contain an object that has
#the value property.
#should be an array with at least two members (agegroups), each element in
#these arrays should contain an object that contains lvalue, rvalue, year,
#birthyear, age and label properties.
#
#The chartId is the id attribute of a div within wich the graph should
#be built. There can be several simultanious graphs
......
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