 
 class CanvasGraph
 
-  events:
-    'click button[name="unfavorite"]': 'onClickUnfavorite'
-    'click button[name="turn-page"]': 'onTurnPage'
-
-  elements:
-    'nav': 'navigation'
-    'button[name="turn-page"]': 'pageTurners'
+  DEBUG = false
 
   constructor: (@canvas, @data) ->
     @leftPadding = 60

    for xValue, idx in [@data.x...]
      @data.x[idx] = xValue - @smallestX

    # remove outliers and normalize
    @removeOutliers(nsigma=8)

    # update min/max values
    @smallestX = Math.min @data.x...

      @ctx.textAlign = 'left'
      @ctx.fillText( @toDataYCoord((-yClick+@canvas.height)).toFixed(4), 15, yClick+5 ) # don't forget to flip y-axis values
      
  processLightcurve: () ->
    @data.y = @removeOutliers(@data.y, nsigma=8) # NOTE: nsigma < 8 removes tutorial subject transits
    @data.y = @normalize(@data.y)

  normalize: (data) ->
    y_new = []
    mean = @mean(data)
    std = @std(data)

    for y, i in [ data... ]
      y_new[i] = (y-1)/(std)
      y_new[i] = y/(mean)
     
    return y_new

  removeOutliers: (data, nsigma) -> 
    y_new = []
    mean = @mean(data)
    std = @std(data)
    
    for y, i in [data...]
      if Math.sqrt( Math.pow( y - mean, 2 ) ) > nsigma * std
        console.log 'removed outlier' if DEBUG
        continue # skip (outlier)
      else
        y_new.push data[i]

    return y_new

  std: (data) ->
    mean = @mean(data)
