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

Sort by year and age to make browsers behave alike

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