Skip to content

Commit 7eae80e

Browse files
committed
When doing move or resize of title/statbox, limit it by pad boundaries
git-svn-id: https://subversion.gsi.de/dabc/trunk/plugins/root/js@2695 bcbf6573-9a26-0410-9ebc-ce4ab7aade96
1 parent cd2d268 commit 7eae80e

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

scripts/JSRootPainter.js

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,11 +1078,17 @@
10781078
y -= rect_height();
10791079
return y;
10801080
}
1081+
1082+
var acc_x = 0, acc_y = 0, pad_w = 1, pad_h = 1;
10811083

10821084
var drag_move = d3.behavior.drag().origin(Object)
10831085
.on("dragstart", function() {
10841086
d3.event.sourceEvent.preventDefault();
10851087

1088+
acc_x = 0; acc_y = 0;
1089+
pad_w = Number(pthis.svg_pad(true).attr("width")) - rect_width();
1090+
pad_h = Number(pthis.svg_pad(true).attr("height")) - rect_height();
1091+
10861092
pthis[drag_rect_name] =
10871093
pthis.svg_pad(true)
10881094
.append("rect")
@@ -1095,12 +1101,23 @@
10951101
.style("cursor", "move");
10961102
}).on("drag", function() {
10971103
d3.event.sourceEvent.preventDefault();
1098-
pthis[drag_rect_name].attr("x", Number(pthis[drag_rect_name].attr("x")) + d3.event.dx);
1099-
pthis[drag_rect_name].attr("y", Number(pthis[drag_rect_name].attr("y")) + d3.event.dy);
1104+
1105+
var x = Number(pthis[drag_rect_name].attr("x"));
1106+
var y = Number(pthis[drag_rect_name].attr("y"));
1107+
var dx = d3.event.dx, dy = d3.event.dy;
1108+
1109+
if (((acc_x<0) && (dx>0)) || ((acc_x>0) && (dx<0))) { acc_x += dx; dx = 0; }
1110+
if (((acc_y<0) && (dy>0)) || ((acc_y>0) && (dy<0))) { acc_y += dy; dy = 0; }
1111+
1112+
if ((x + dx < 0) || (x +dx > pad_w)) acc_x += dx; else x+=dx;
1113+
if ((y+dy < 0) || (y+dy > pad_h)) acc_y += dy; else y += dy;
1114+
1115+
pthis[drag_rect_name].attr("x", x);
1116+
pthis[drag_rect_name].attr("y", y);
11001117
d3.event.sourceEvent.stopPropagation();
11011118
}).on("dragend", function() {
11021119
d3.event.sourceEvent.preventDefault();
1103-
1120+
11041121
pthis[drag_rect_name].style("cursor", "auto");
11051122

11061123
var x = Number(pthis[drag_rect_name].attr("x"));
@@ -1133,6 +1150,9 @@
11331150
var drag_resize = d3.behavior.drag().origin(Object)
11341151
.on( "dragstart", function() {
11351152
d3.event.sourceEvent.preventDefault();
1153+
acc_x = 0; acc_y = 0;
1154+
pad_w = Number(pthis.svg_pad(true).attr("width")) - rect_x();
1155+
pad_h = Number(pthis.svg_pad(true).attr("height")) - rect_y();
11361156
pthis[drag_rect_name] =
11371157
pthis.svg_pad(true)
11381158
.append("rect")
@@ -1146,8 +1166,16 @@
11461166
// main_rect.style("cursor", "move");
11471167
}).on("drag", function() {
11481168
d3.event.sourceEvent.preventDefault();
1149-
pthis[drag_rect_name].attr("width", Number(pthis[drag_rect_name].attr("width")) + d3.event.dx);
1150-
pthis[drag_rect_name].attr("height", Number(pthis[drag_rect_name].attr("height")) + d3.event.dy);
1169+
1170+
var w = Number(pthis[drag_rect_name].attr("width"));
1171+
var h = Number(pthis[drag_rect_name].attr("height"));
1172+
var dx = d3.event.dx, dy = d3.event.dy;
1173+
if ((acc_x>0) && (dx<0)) { acc_x += dx; dx = 0; }
1174+
if ((acc_y>0) && (dy<0)) { acc_y += dy; dy = 0; }
1175+
if (w+dx > pad_w) acc_x += dx; else w+=dx;
1176+
if (h+dy > pad_h) acc_y += dy; else h+=dy;
1177+
pthis[drag_rect_name].attr("width", w);
1178+
pthis[drag_rect_name].attr("height", h);
11511179
d3.event.sourceEvent.stopPropagation();
11521180
}).on( "dragend", function() {
11531181
d3.event.sourceEvent.preventDefault();

0 commit comments

Comments
 (0)