From 4f5ae140a2a309d94c424dbf34d3b66ec9a7c5a6 Mon Sep 17 00:00:00 2001
From: Patrick Simianer
Date: Fri, 18 Sep 2015 11:45:35 +0200
Subject: fixed mixing up of boxes on fast dragging
---
edit.html | 2 +-
edit.js | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--------
2 files changed, 91 insertions(+), 13 deletions(-)
diff --git a/edit.html b/edit.html
index 476fa30..2772e32 100644
--- a/edit.html
+++ b/edit.html
@@ -17,7 +17,7 @@
-
+ DEBUG:
Instructions
diff --git a/edit.js b/edit.js
index 1198636..61af8c9 100644
--- a/edit.js
+++ b/edit.js
@@ -30,7 +30,9 @@ var shapes_by_id = {},
shape_att = { fill: "#eee", stroke: "#000", "fill-opacity": 0, "stroke-width": 1 }
source = ["Das", "ist ein", "kleines", "Haus", "gewesen", "."], // data
target = ["This", "has been", "a", "small", "house", "."], // ^
- align = [0, 1, 3, 4, 1, 5]; // ^
+ align = [0, 1, 3, 4, 1, 5],
+ new_pos = -1,
+ old_pos = -1;
/*
* connection
@@ -106,6 +108,7 @@ var dragger = function ()
{
if (edit_mode) return;
curDrag = this;
+ old_pos = curDrag["grid_"];
if (this.type == "text")
curDrag = this.pair;
curDrag.toFront();
@@ -138,6 +141,9 @@ move = function (dx, dy)
*/
var collide = function collide(obj)
{
+ if (!obj["id_"])
+ return;
+ debug();
if (obj.type != 'rect') {
return;
}
@@ -145,31 +151,56 @@ var collide = function collide(obj)
curDrag["delete_me_"] = true;
return;
}
- if (curDrag["grid_"] > obj["grid_"]) {
- if (curDrag.getBBox().width < obj.getBBox().width &&
+ if (curDrag["grid_tmp_"] > obj["grid_tmp_"]) { // right -> left
+ /*if (curDrag.getBBox().width < obj.getBBox().width &&
curDrag.getBBox().x > (obj.getBBox().x+obj.getBBox().width/3)) {
return;
- }
+ }*/
att = { x: obj.attr("x")+curDrag.getBBox().width+(margin-2*padding) };
obj.attr(att);
att = { x: obj.pair.attr("x")+curDrag.getBBox().width+(margin-2*padding) };
obj.pair.attr(att);
- } else {
- if (curDrag.getBBox().width < obj.getBBox().width &&
+ } else { // left -> right
+ /*if (curDrag.getBBox().width < obj.getBBox().width &&
curDrag.getBBox().x < (obj.getBBox().x+obj.getBBox().width/3)) {
return;
- }
+ }*/
att = { x: obj.attr("x")-(curDrag.getBBox().width+(margin-2*padding)) };
obj.attr(att);
att = { x: obj.pair.attr("x")-(curDrag.getBBox().width+(margin-2*padding)) };
obj.pair.attr(att);
}
// switch grid pos
- var tmpx = curDrag["grid_"];
- curDrag["grid_"] = obj["grid_"];
- obj["grid_"] = tmpx;
+ new_pos = obj["grid_tmp_"];
+ var tmpx = curDrag["grid_tmp_"];
+ curDrag["grid_tmp_"] = obj["grid_tmp_"];
+ obj["grid_tmp_"] = tmpx;
+ //snap_to_grid(true,true);
},
+debug = function () {
+ var s = "";
+ for (var i=0; iold_pos)) {
+ target_shapes[i]["grid_"] += 1;
+ } else if (b && new_pos old_pos) {
+ for (var i=0; i < target_shapes.length; i++) {
+ pos = target_shapes[i]["grid_"];
+ id = target_shapes[i]["id_"];
+ if (id == cur_id)
+ continue;
+ if (pos >= old_pos && pos <= new_pos) {
+ target_shapes[i]["grid_"] -= 1;
+ } else {
+ continue;
+ }
+ }
+ } else if (new_pos < old_pos) {
+ for (var i=0; i < target_shapes.length; i++) {
+ pos = target_shapes[i]["grid_"];
+ id = target_shapes[i]["id_"];
+ if (id == cur_id)
+ continue;
+ if (pos >= new_pos && pos <= old_pos) {
+ target_shapes[i]["grid_"] += 1;
+ } else {
+ continue;
+ }
+ }
+ }
+ debug1();
+ target_shapes.sort(function(a, b) {
+ return a["grid_"]-b["grid_"];
+ });
for (var i = 0; i < target_shapes.length; i++) {
var obj = target_shapes[i];
if (!obj || !obj.attrs) { // removed
@@ -272,6 +349,7 @@ var make_obj = function(x, text, type)
sh.attr({ cursor: "move" });
tx.drag(move, dragger, up);
sh["grid_"] = id;
+ sh["grid_tmp_"] = id;
sh.click(function() {
if (connect_mode) {
if (connections[conn_str(connect_mode_shape,this)]) {
@@ -352,7 +430,7 @@ add_obj = function()
}
}
if (!shapes[max_idx]) {
- make_obj(xbegin+padding, "NEW", "target", 0);
+ make_obj(xbegin+padding, "X", "target", 0);
} else {
make_obj(shapes[max_idx].getBBox().x2+(margin-padding),
"NEW",
--
cgit v1.2.3