           d.y0 = y0
           d.value = y)
 
-      line_fn = (d, i) ->
-        mode = line_mode d, i
-        if mode is 'line'
-          line
-        else
-          area
-
     if params.drawNullAsZero
       transform_value = (v) -> v ? 0
       filter_scatter_values = _.identity
       expand_line_values = _.identity
     else
+      # TODO this won't work well with stack
       transform_value = (v) -> v
       filter_scatter_values = (values) ->
         _.filter values, (d) -> d.value?
-      expand_line_values = (values) ->
-        result = []
-        segment_length = 0
-        previous = null
-        _.each values, (v, i) ->
-          if v.value?
-            segment_length++
-            previous = v
-          else
-            if segment_length is 1
-              result.push previous
-            segment_length = 0
-
-          result.push v
-
-        if segment_length is 1
-          result.push previous
-        result
+      expand_line_values = expandIsolatedValuesToLineSegments
 
     time_min = null
     time_max = null
     value_min = null
     value_max = null
-    targets = for s in data
+    targets = for s, targetIndex in data
       values = for datapoint, i in s.datapoints
         value = get_value datapoint, i
         timestamp = get_timestamp datapoint, i

        .attr('class', 'crosshair-time')
        .attr('y', -6)

    clearExtent = (v) -> _.extend {}, v, {extent: null}
    setBrushing = (v) -> _.extend {}, v, {brushing: true}
    setNotBrushing = (v) -> _.extend {}, v, {brushing: false}
    brushed = ->
      brushBus.push if brush.empty() then clearExtent else (v) -> _.extend {}, v, {extent: brush.extent()}
    brushstart = -> brushBus.push setBrushing

        value_max = Math.max value, value_max
        {value, time: moment(timestamp * 1000), original: datapoint}
      bisector = d3.bisector (d) -> d.time
      lineValues = expand_line_values values
      scatterValues = filter_scatter_values values
      lineMode =
        if params.areaMode is 'all' or params.areaMode is 'stacked'
          'area'
        else if params.areaMode is 'first' and targetIndex is 0
          'area'
        else
          'line'

      lineFn = if lineMode is 'line'
        line
      else
        area
      targetColor = color targetIndex
      {values, bisector, name: s.target, lineValues, scatterValues, lineMode, lineFn, color: targetColor}

    if params.areaMode is 'stacked'
      stack targets
