Commit 0f51cd4e authored by Kjetil Thuen's avatar Kjetil Thuen
Browse files

Made selected year more robust

parent c897ae86
......@@ -76,28 +76,25 @@ prepareMetadataDiv = (chartId, data, mapping) ->
_results.join ""
updateMetadata = (chartId, data) ->
updateMetadata = (chartId, currentYear, ageGroup) ->
# FIXME: Add a delay to reduce flicker
if not data
#FIXME: Whats needed here is the data for the current frame filtered on the
#selected year
# data = completeData[chartId].yearData[completeData[chartId].selectedYear]
data = d3.select(chartId + " svg.chart g.selected").data()[0]
data = lodash.filter completeData[chartId].yearData[currentYear],
{ 'birthyear': ageGroup }
d3.select chartId + " div.dataDetails"
.html prepareMetadataDiv chartId, data
.html prepareMetadataDiv chartId, data[0]
hoverBar = (chartId) ->
(data, index) ->
d3.selectAll chartId + " svg.chart g.valuepoint"
.filter (p) -> p.birthyear is data.birthyear
.classed "hovered", true
updateMetadata chartId, data
updateMetadata chartId, data.year, data.birthyear
unhoverBar = (chartId) ->
(data, index) ->
d3.selectAll chartId + " svg.chart g.valuepoint"
.classed "hovered", false
updateMetadata chartId
updateMetadata chartId, data.year, completeData[chartId].selectedYear
selectBar = (chartId) ->
(data, index) ->
......@@ -107,7 +104,7 @@ selectBar = (chartId) ->
.classed "selected", (d) ->
d.birthyear is completeData[chartId].selectedYear
updateMetadata chartId
updateMetadata chartId, "2015", data.birthyear
addBar = (newBar, chartId) ->
barGroup = newBar.append "g"
......@@ -192,7 +189,9 @@ updateChart = (chartId, frameNum) ->
.attr "height", 0
.remove()
updateMetadata chartId
updateMetadata chartId,
lodash.keys(completeData[chartId].yearData)[frameNum],
completeData[chartId].selectedYear
undefined
nextFrame = (chartId, frameNum) ->
......@@ -283,7 +282,8 @@ setupChart = (chartId, data, displayDetails) ->
completeData[chartId].displayDetails.rightsymbol +
"'></i>"
window.onresize = setupChart
nextFrame chartId, 0
window.onresize = -> setupChart chartId, data, displayDetails
displayPoster = (chartId, icon, header, message) ->
d3.select chartId
......
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