   @legend = new ReactiveVar([])
   @loading = new ReactiveVar(false)
   @highlightedLocations = new Meteor.Collection(null)
+  @differentialIncidents = new ReactiveVar([])
 
 Template.eventResolvedIncidents.onRendered ->
   renderPlot = (differentials, locToSubintervals, locationTree, topLocations) =>

    Template.instance().loading.get()

  disableCases: ->
    'cases' not in Template.instance().data.selectedIncidentTypes.get()

  disableDeaths: ->
    'deaths' not in Template.instance().data.selectedIncidentTypes.get()

Template.eventResolvedIncidents.events
  "click .incident-type-selector .cases": (event, instance)->


  @autorun =>
    @incidents = EventIncidents.find(@data.filterQuery.get())
    incidentType = @incidentType.get()
    allIncidents = @incidents.fetch()
    allIncidents = allIncidents.filter (i)->
      i.locations.every (l)-> l.featureCode
    differentialIncidents = convertAllIncidentsToDifferentials(allIncidents)
    @differentialIncidents.set(differentialIncidents)

  @autorun =>
    @hoveredIntervalClickEvent = null
    incidentType = @incidentType.get()
    differentialIncidents = @differentialIncidents.get()
    # Toggle the incident type if there are no matching incidents
    console.log differentialIncidents
    if not _.findWhere(differentialIncidents, type: incidentType)
      if differentialIncidents.length >= 1
        if incidentType == 'cases'
          @incidentType.set('deaths')
        else
          @incidentType.set('cases')
        return
    @loading.set(true)
    @highlightedLocations.remove({})
    _.delay =>
      differentials = _.where(differentialIncidents, type: incidentType)
      subIntervals = differentailIncidentsToSubIntervals(differentials)
      extendSubIntervalsWithValues(differentials, subIntervals)
      for subInterval in subIntervals
