     data = $.map(results, (request) -> request[0])
     showRankHistory data, fromYear, toYear
 
-window.loadRankHistory = (players) ->
+loadRankHistory = (players) ->
   $.when ($.map(players, (player) -> loadData player + "_rank_history"))...
 
-window.showRankHistory = (data, fromYear, toYear) ->
+showRankHistory = (data, fromYear, toYear) ->
   data = $.map(data, (e) ->
     hist = filterHistoryData(e.history, fromYear, toYear)
     key: e.first + " " + e.last

      .margin(left: 20, right: 40)
      .color(d3.scale.category10().range())
    chart.xAxis.rotateLabels(30)
      .tickValues( do -> $.map getYears(), (year) -> Date.parse "1/1/" + year)
      .tickFormat((d) -> d3.time.format("%x")(new Date(d)))

    chart.yAxis.tickValues([0, 10, 20, 30, 40, 45, 46, 47, 48, 49])


    d3.select("#rank-history svg").datum(data).transition().duration(500).call chart
    nv.utils.windowResize chart.update
    chart

filterHistoryData = (data, fromYear, toYear) ->
  fromTime = Date.parse(fromYear + "/1/1")
  toTime = Date.parse(parseInt(toYear) + 1 + "/1/1")
  $.map data, (item) ->
    time = Date.parse(item[0])
    [item]  if time >= fromTime and time < toTime

router.get '/rank-history/:players', (req) ->
  players  = req.params.players.split(',')
  fromYear = req.params.fromYear || FIRST_YEAR
  toYear   = req.params.toYear   || THIS_YEAR

  T('rank-history', fromYear, toYear).render inside: '.main'

  loadData "rankings", (rankings) ->
    updateGenerationTime rankings.generated_at

    T.each_with_index('player-field', rankings.data).render inside: '#players'

    for player in players
      $("[value=" + player + "]").attr('checked', 'checked')

    loadAndShowRankHistory players, fromYear, toYear
