   ###
   # HANDLERS
   ###
-  # FIXME:
-  # fix drag -> click behavior
-  #
   
   _onMapClick: (e) =>
-    e.stopPropagation()
-    return unless @interactive
     this.deselectAll() unless e.ctrlKey
+  _onMapDrag: (dx, dy, x, y, e) =>
+    @transformations.dx = dx
+    @transformations.dy = dy
+    this._applyTransformations()
+  _onMapDragStart: (x, y, e) =>
+  _onMapDragEnd: (e) =>
+    @transformations.x += @transformations.dx
+    @transformations.y += @transformations.dy
+    @transformations.dx = 0
+    @transformations.dy = 0
   _onNodeClick: (e) =>
-    e.stopPropagation()
-    return unless @interactive
     node = this.fetchNode(e.target.node_id)
     if e.target.node_id in this.getSelectedIds()
       this.deselect(node)
     else
       this.select(node, e.ctrlKey)
-    this._freeze()
   _onNodeDragStart: (x, y, e) =>
-    node = this.fetchNode(e.target.node_id)
-    this.select(node)
   _onNodeDrag: (dx, dy, x, y, e) =>
-    @selection[0].move(x+dx, y+dy)
+    return if dx*dy = 0
+    return unless node = @selection[0]
+    x = e.clientX - @bbox.x - @transformations.x
+    y = e.clientY - @bbox.y - @transformations.y
+    node.move(x, y)
   _onNodeDragEnd: (e) =>
-    this._freeze()
-  _onMapDrag: (dx, dy, x, y, e) =>
-    e.stopPropagation()
-    return unless dx*dy > 0
-    @transformations.dx = dx
-    @transformations.dy = dy
-    this._applyTransformations()
-    this._freeze()
-  _onMapDragStart: (x, y, e) =>
-    e.stopPropagation()
-  _onMapDragEnd: (e) =>
-    e.stopPropagation()
-    @transformations.x = @transformations.dx
-    @transformations.y = @transformations.dy
-    @transformations.dx = 0
-    @transformations.dy = 0
-    this._freeze()
   _onScroll: (e) =>
     factor = e.deltaY * 0.05
     @transformations.zoom += factor

window.SvgNodes = {}

class SvgNodes.Map
  
  this._eventNameToHandlerName = (en) ->
    en.replace ':', '_'
  constructor: (parent = null, params = {} )->
    @w = params.w
    @h = params.h


  highlight: =>
    @highlighted = true
    #@svg.transform(Snap.matrix().scale(1.1, 1.1, @x, @y))
    @label.attr(fontWeight: 'bold')

  dim: =>
    @highlighted = false
    #@svg.transform(Snap.matrix())
    @label.attr(fontWeight: 'normal')

  _moveEdges: =>
