diff --git a/app/assets/javascripts/src/JIT.js b/app/assets/javascripts/src/JIT.js index 843f1fa8..bc3f23c3 100644 --- a/app/assets/javascripts/src/JIT.js +++ b/app/assets/javascripts/src/JIT.js @@ -2498,7 +2498,11 @@ Extras.Classes.Navigation = new Class({ if (!Metamaps.Mouse.boxStartCoordinates && (e.shiftKey || rightClick)) { Metamaps.Mouse.boxStartCoordinates = eventInfo.getPos(); } + Metamaps.Mouse.didPan = false; + + + // END METAMAPS CODE this.pos = eventInfo.getPos(); @@ -2570,6 +2574,8 @@ Extras.Classes.Navigation = new Class({ // START METAMAPS CODE if (Metamaps.Mouse.didPan) Metamaps.JIT.SmoothPanning(); + + // END METAMAPS CODE } @@ -7075,7 +7081,8 @@ Graph.Plot = { var l = Metamaps.Mouse.synapseStartCoordinates.length; for (var i = l - 1; i >= 0; i -= 1) { start = Metamaps.Mouse.synapseStartCoordinates[i]; - Metamaps.JIT.renderMidArrow(start, end, 13, false, canvas, 0.5, true); + Metamaps.JIT.renderMidArrow(start, end, 13, false, canvas, 0.3, true); + Metamaps.JIT.renderMidArrow(start, end, 13, false, canvas, 0.7, true); } ctx.restore(); } diff --git a/app/assets/javascripts/src/Metamaps.GlobalUI.js b/app/assets/javascripts/src/Metamaps.GlobalUI.js index fc8f46ea..a425d78f 100644 --- a/app/assets/javascripts/src/Metamaps.GlobalUI.js +++ b/app/assets/javascripts/src/Metamaps.GlobalUI.js @@ -366,6 +366,29 @@ Metamaps.GlobalUI.Search = { self.close(0, true); } break; + case 65: + case 97: + + if (e.ctrlKey){ + Metamaps.Control.deselectAllNodes(); + Metamaps.Control.deselectAllEdges(); + + e.preventDefault(); + Metamaps.Visualize.mGraph.graph.eachNode(function (n) { + Metamaps.Control.selectNode(n,e); + }); + + Metamaps.Visualize.mGraph.plot(); + } + + break; + case 69: + case 101: + if (e.ctrlKey){ + e.preventDefault(); + Metamaps.JIT.zoomExtents(); + } + break; default: break; //console.log(e.which); } diff --git a/app/assets/javascripts/src/Metamaps.JIT.js b/app/assets/javascripts/src/Metamaps.JIT.js index ee405736..3c5b79c9 100644 --- a/app/assets/javascripts/src/Metamaps.JIT.js +++ b/app/assets/javascripts/src/Metamaps.JIT.js @@ -20,6 +20,7 @@ Metamaps.JIT = { */ prepareVizData: function () { var self = Metamaps.JIT; + var synapsesToRemove = []; var topic; var mapping; var node; @@ -39,7 +40,12 @@ Metamaps.JIT = { Metamaps.Synapses.each(function (s) { edge = s.createEdge(); - if (nodes[edge.nodeFrom] && nodes[edge.nodeTo]) { + if(Metamaps.Topics.get(s.get('node1_id')) === undefined || Metamaps.Topics.get(s.get('node2_id')) === undefined) { + // this means it's an invalid synapse + synapsesToRemove.push(s); + } + else if (nodes[edge.nodeFrom] && nodes[edge.nodeTo]) { + existingEdge = _.findWhere(edges, { nodeFrom: edge.nodeFrom, nodeTo: edge.nodeTo @@ -53,15 +59,24 @@ Metamaps.JIT = { // for when you're dealing with multiple relationships between the same two topics if (Metamaps.Active.Map) { mapping = s.getMapping(); - existingEdge['$mappingIDs'].push(mapping.isNew() ? mapping.cid : mapping.id); + existingEdge.data['$mappingIDs'].push(mapping.id); } - existingEdge['$synapseIDs'].push(s.id); + existingEdge.data['$synapseIDs'].push(s.id); } else { // for when you're dealing with a topic that has relationships to many different nodes nodes[edge.nodeFrom].adjacencies.push(edge); + edges.push(edge); } } }); + + // clean up the synapses array in case of any faulty data + _.each(synapsesToRemove, function (synapse) { + mapping = synapse.getMapping(); + Metamaps.Synapses.remove(synapse); + Metamaps.Mappings.remove(mapping); + }); + _.each(nodes, function (node) { self.vizData.push(node); }); @@ -319,7 +334,7 @@ Metamaps.JIT = { if (Metamaps.Mouse.boxStartCoordinates) { Metamaps.Visualize.mGraph.busy = false; Metamaps.Mouse.boxEndCoordinates = eventInfo.getPos(); - Metamaps.JIT.selectWithBox(e); + Metamaps.JIT.zoomToBox(e); return; } @@ -672,8 +687,6 @@ Metamaps.JIT = { var scale = dist / lastDist; - console.log(scale); - if (8 >= Metamaps.Visualize.mGraph.canvas.scaleOffsetX * scale && Metamaps.Visualize.mGraph.canvas.scaleOffsetX * scale >= 1) { Metamaps.Visualize.mGraph.canvas.scale(scale, scale); } @@ -818,8 +831,8 @@ Metamaps.JIT = { } else if (tempInit && tempNode2 != null) { // this means you want to create a synapse between two existing topics Metamaps.Create.newTopic.addSynapse = false; - Metamaps.Create.newSynapse.topic1id = tempNode.id; - Metamaps.Create.newSynapse.topic2id = tempNode2.id; + Metamaps.Create.newSynapse.topic1id = tempNode.getData('topic').id; + Metamaps.Create.newSynapse.topic2id = tempNode2.getData('topic').id; tempNode2.setData('dim', 25, 'current'); Metamaps.Visualize.mGraph.plot(); midpoint.x = tempNode.pos.getc().x + (tempNode2.pos.getc().x - tempNode.pos.getc().x) / 2; @@ -940,7 +953,7 @@ Metamaps.JIT = { Metamaps.Control.deselectAllEdges(); } - //select all nodes, and their edges, that are within the box + //select all nodes that are within the box Metamaps.Visualize.mGraph.graph.eachNode(function (n) { var x = n.pos.x, y = n.pos.y; @@ -969,8 +982,8 @@ Metamaps.JIT = { var fromNodeY = -1 * synapse.get('edge').nodeFrom.pos.y; var toNodeX = synapse.get('edge').nodeTo.pos.x; var toNodeY = -1 * synapse.get('edge').nodeTo.pos.y; - - var maxX = fromNodeX; + + var maxX = fromNodeX; var maxY = fromNodeY; var minX = fromNodeX; var minY = fromNodeY; @@ -988,7 +1001,7 @@ Metamaps.JIT = { (eX > maxBoxX) ? (maxBoxX = eX):(minBoxX = eX); (eY > maxBoxY) ? (maxBoxY = eY):(minBoxY = eY); - //Fins the slopes from the synapse fromNode to the 4 corners of the selection box + //Find the slopes from the synapse fromNode to the 4 corners of the selection box var slopes = []; slopes.push( (sY - fromNodeY) / (sX - fromNodeX) ); slopes.push( (sY - fromNodeY) / (eX - fromNodeX) ); @@ -1005,40 +1018,44 @@ Metamaps.JIT = { //Find synapse-in-question's slope var synSlope = (toNodeY - fromNodeY) / (toNodeX - fromNodeX); var b = fromNodeY - synSlope * fromNodeX; + + //Use the selection box edges as test cases for synapse intersection + var testX = sX; + var testY = synSlope * testX + b; + + var selectTest; - var selectTest = false; - - //if the synapse slope is within a range that would intersect with the selection box - if (synSlope <= maxSlope && synSlope >= minSlope){ - var testX = sX; - var testY = synSlope * testX + b; - - if(testX >= minX && testX <= maxX && testY >= minY && testY <= maxY && testY >= minBoxY && testY <= maxBoxY){ - selectTest = true; - } - - testX = eX; - testY = synSlope * testX + b; - - if(testX >= minX && testX <= maxX && testY >= minY && testY <= maxY && testY >= minBoxY && testY <= maxBoxY){ - selectTest = true; - } - - testY = sY; - testX = (testY - b)/synSlope; - - if(testX >= minX && testX <= maxX && testY >= minY && testY <= maxY && testX >= minBoxX && testY <= maxBoxX){ - selectTest = true; - } - - testY = eY; - testX = (testY - b)/synSlope; - - if(testX >= minX && testX <= maxX && testY >= minY && testY <= maxY && testX >= minBoxX && testY <= maxBoxX){ - selectTest = true; - } + if(testX >= minX && testX <= maxX && testY >= minY && testY <= maxY && testY >= minBoxY && testY <= maxBoxY){ + selectTest = true; } - //The test synapse was selected! + + testX = eX; + testY = synSlope * testX + b; + + if(testX >= minX && testX <= maxX && testY >= minY && testY <= maxY && testY >= minBoxY && testY <= maxBoxY){ + selectTest = true; + } + + testY = sY; + testX = (testY - b)/synSlope; + + if(testX >= minX && testX <= maxX && testY >= minY && testY <= maxY && testX >= minBoxX && testX <= maxBoxX){ + selectTest = true; + } + + testY = eY; + testX = (testY - b)/synSlope; + + if(testX >= minX && testX <= maxX && testY >= minY && testY <= maxY && testX >= minBoxX && testX <= maxBoxX){ + selectTest = true; + } + + //Case where the synapse is wholly enclosed in the seldction box + if(fromNodeX >= minBoxX && fromNodeX <= maxBoxX && fromNodeY >= minBoxY && fromNodeY <= maxBoxY && toNodeX >= minBoxX && toNodeX <= maxBoxX && toNodeY >= minBoxY && toNodeY <= maxBoxY){ + selectTest = true; + } + + //The test synapse was selected! if(selectTest){ if(e.ctrlKey){ if(Metamaps.Selected.Edges.indexOf(synapse.get('edge')) != -1 ){ @@ -1102,15 +1119,23 @@ Metamaps.JIT = { // wait a certain length of time, then check again, then run this code setTimeout(function () { if (!Metamaps.JIT.nodeWasDoubleClicked()) { - if (!e.shiftKey) { + if (!e.shiftKey && !e.ctrlKey) { Metamaps.Control.deselectAllNodes(); Metamaps.Control.deselectAllEdges(); } - if (node.selected) { - Metamaps.Control.deselectNode(node); - } else { + if(e.ctrlKey || e.shiftKey){ + if (node.selected) { + Metamaps.Control.deselectNode(node); + } else { + Metamaps.Control.selectNode(node,e); + } + } + else{ + Metamaps.Control.deselectAllNodes(); + Metamaps.Control.deselectAllEdges(); Metamaps.Control.selectNode(node,e); } + //trigger animation to final styles Metamaps.Visualize.mGraph.fx.animate({ modes: ['edge-property:lineWidth:color:alpha'], @@ -1138,7 +1163,6 @@ Metamaps.JIT = { // create new menu for clicked on node var rightclickmenu = document.createElement("div"); rightclickmenu.className = "rightclickmenu"; - // add the proper options to the menu var menustring = '