I am Trying to tweak this example http://raphaeljs.com/graffle.html to restrict the drag to within the container svg.
Somewhat like http://bl.ocks.org/1557377 or http://jqueryui.com/demos/draggable/#constrain-movement Basically I want to restrict objects moving out from the bounding box while dragging.
Here is the tweaked code added to move function ( http://jsfiddle.net/f4mFQ/1/ )
if(thisBox.x < 0){
ddx = 0;
}else if(thisBox.x>width-thisBox.width ){
ddx = width-thisBox.width;
}else {
ddx = this.ox + dx;
}
if(thisBox.y < 0){
ddy = 0;
}else if(thisBox.y>height-thisBox.height ){
ddy = height-thisBox.height;
}else{
ddy = this.oy + dy;
}
This partially works, when rectangle is moved beyond boundary it kind of dances on the edge! while the circle and ellipse get stuck to the edge.
So how to restrict element drag with constrained movement within parent bounding box in this case svg