diff --git a/Kieker.WebGUI/src/main/webapp/js/flowEditor.js b/Kieker.WebGUI/src/main/webapp/js/flowEditor.js index 96fef984ae4f3f92dc9cb79bf5fe1c0d4a9516ca..74707d94d45558054cf2f6f6e3005a43e4f298da 100644 --- a/Kieker.WebGUI/src/main/webapp/js/flowEditor.js +++ b/Kieker.WebGUI/src/main/webapp/js/flowEditor.js @@ -152,6 +152,62 @@ function GraphFlow(){ // FUNCTIONS // ///////////////////////////////////////////// + /** + Concatenates nodefamily 'id's and their x- and y-position + to a string, separating each element with a space. + TODO: save bend points of edges + @return - the resulting string + */ + this.saveNodePositions = function(){ + var positions = ""; + var node; + + for(var n = 0, l = jsonCapacity.occupied; n < l; n++){ + node = json[n]; + positions += node.id + " " + node.data.$xPos + " " + node.data.$yPos + " "; + } + + return positions; + } + + /** + Reads nodefamily positions out of a string, which was created with + the saveNodePositions() function and moves all nodes to the respective + positions. + @param positions - the string which contains node ids and positions + @param smoothTransition - no functionality at the moment + */ + this.loadNodePositions = function(positions, smoothTransition){ + var pos = positions.split(" "); + var node, x, y; + + for(var i = 0, l = pos.length; i < l; i+=3){ + // look for the node + node = fd.graph.getNode(pos[i]); + + // if node exists, set positions + if(node){ + x = parseFloat(pos[i+1]); + y = parseFloat(pos[i+2]); + + prepareNodeMove(node); + moveNode(x,y); + saveNodeMove(); + } + } + + //TODO: smooth animation + if(false){ + fd.animate({ + modes: ['linear'], + transition: $jit.Trans.Cubic.easeInOut, + duration: 1000 + }); + } + else{ + fd.plot(); + } + } /** Returns a XML-String, representing the graph as KGraph diff --git a/Kieker.WebGUI/src/main/webapp/js/jit.js b/Kieker.WebGUI/src/main/webapp/js/jit.js index 15130dccc5618b77dd912ece0d4ddc93971f8358..5ae2778749232f17a3a975324ac36e78a6db7374 100644 --- a/Kieker.WebGUI/src/main/webapp/js/jit.js +++ b/Kieker.WebGUI/src/main/webapp/js/jit.js @@ -6498,35 +6498,52 @@ var EdgeHelper = { EdgeHelper.flowarrow.contains({ x: 10, y: 30 }, { x: 15, y: 35 }, { x: 15, y: 35 }, 30); (end code) */ - 'contains': function(posFrom, posTo, pos, epsilon) { + 'contains': function(posFrom, posTo, pos, dim) { // is mouse pos within line bounds ? { - var minX = Math.min(posFrom.x, posTo.x), - minY = Math.min(posFrom.y, posTo.y), - maxX = Math.max(posFrom.x, posTo.x), - maxY = Math.max(posFrom.y, posTo.y); - if(pos.x < minX || pos.x > maxX || pos.y < minY || pos.y > maxY){ + var temp, + minX = posFrom.x, + maxX = posTo.x; + if(minX > maxX){ + temp = maxX; + maxX = minX; + minX = temp; + } + + temp = pos.x; + if(temp < minX-dim || temp > maxX+dim){ + return false; + } + + var minY = posFrom.y, + maxY = posTo.y; + if(minY > maxY){ + temp = maxY; + maxY = minY; + minY = temp; + } + + temp = pos.y; + if(temp < minY-dim || temp > maxY+dim){ return false; } } - var sizeModifier = 6; - if(typeof(vertexLabelSize) != 'undefined'){ - sizeModifier = vertexLabelSize/2; - } - // calculate normal vector of edge var n = {"x" : (posTo.y - posFrom.y), "y": (posFrom.x - posTo.x)}, nAbs = Math.sqrt(n.x * n.x + n.y * n.y); - n.x /= nAbs; - n.y /= nAbs; + + if(nAbs != 0){ + n.x /= nAbs; + n.y /= nAbs; + } // use Hesse-Normal-Form for calculating the distance between edge and mouse pos var d = (pos.x-posFrom.x)*n.x + (pos.y-posFrom.y)*n.y; - + // is mouse pos close to line ? - if( Math.abs(d) <= sizeModifier){ + if( Math.abs(d) <= dim){ return true; } @@ -18208,12 +18225,12 @@ $jit.FlowGraph.$extend = true; if(bend){ for(var b = 0, l = bend.length; b < l; b++){ toBend = bend[b]; - contains |= this.edgeHelper.flowarrow.contains(from, toBend, pos, this.edge.epsilon); + contains |= this.edgeHelper.flowarrow.contains(from, toBend, pos, dim); from = bend[b]; } } - return contains || this.edgeHelper.flowarrow.contains(from, to, pos, this.edge.epsilon); + return contains || this.edgeHelper.flowarrow.contains(from, to, pos, dim); } },