 
   toCanvasXPoint: (e) -> e.pageX-@canvas.getBoundingClientRect().left - window.scrollX
 
+  elementXOffset: (e) -> e.offsetX || e.clientX - e.target.offsetLeft + window.pageXOffset
+
+  elementYOffset: (e) -> e.offsetY || e.clientY - e.target.offsetTop + window.pageYOffset
+
 
 module?.exports = CanvasGraph: CanvasGraph, Marks: Marks, Mark: Mark

    @element.addEventListener 'mouseover', (e) => @hovering = true
    @element.addEventListener 'mouseout', (e) => @hovering = false
    @element.addEventListener 'mousedown', (e) => @onMouseDown(e)
    @element.addEventListener 'click', (e) => @canvasGraph.marks.remove(@) if e.layerY < 15
    window.addEventListener 'mousemove', (e) => @onMouseMove(e)
    window.addEventListener 'mouseup', (e) => @onMouseUp(e)


    @dataXMax = @canvasGraph.toDataXCoord(@canvasXMax)

  updateCursor: (e) ->
    if @elementYOffset(e) < 15
      @element.style.cursor = "pointer"
    else if ((Math.abs @elementXOffset(e) - (@canvasXMax-@canvasXMin)) < 10) || @elementXOffset(e) < 10
      @element.style.cursor = "ew-resize"
    else
      @element.style.cursor = "move"
