   if segment_length is 1
     result.push previous
   result
+
+simplifyPoints = (minDistance, values) ->
+  previous = null
+  result = []
+
+  _.each values, (v) ->
+    if previous?
+      if previous.y? != v.y? # discontinuity
+        result.push v
+        if v.y?
+          previous = v
+      else if v.y?
+        deltaX = Math.abs v.x - previous.x
+        deltaY = Math.abs v.y - previous.y
+        if Math.sqrt(deltaX * deltaX + deltaY * deltaY) > minDistance
+          previous = v
+          result.push v
+    else
+      previous = v
+      result.push v
+
+  result

        value_max = Math.max value, value_max
        {value, time: time, x: x(time), 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'

          d.y0 = y0
          d.value = y)

    if params.simplify
      simplify = _.partial simplifyPoints, params.simplify
    else
      simplify = _.identity

    if params.drawNullAsZero
      transform_value = (v) -> v ? 0
      filter_scatter_values = simplify
      expand_line_values = simplify
    else
      # TODO this won't work well with stack
      transform_value = (v) -> v
      filter_scatter_values = (values) ->
        simplify _.filter values, (d) -> d.value?
      expand_line_values = _.compose simplify, expandIsolatedValuesToLineSegments

    value_min = null
    value_max = null
