]> git.eli173.com Git - graphbyhand/commitdiff
got naming, deletion good
authoreli173 <eli@eli173.com>
Sat, 29 Aug 2015 17:24:44 +0000 (12:24 -0500)
committereli173 <eli@eli173.com>
Sat, 29 Aug 2015 17:24:44 +0000 (12:24 -0500)
graph.js
index.html

index 1d6ef5ceafc0a989fedfbd64d3539003c9bb042a..7d99dac9f52484f5c0c867770ec856e6c8b2319f 100644 (file)
--- a/graph.js
+++ b/graph.js
@@ -12,6 +12,7 @@ e_counter = 0;
 
 mode = 'v'
 curr_vert = null;
+curr_ed = null;
 
 evt = null;
 
@@ -48,8 +49,6 @@ var mousedown = function(options,canvas) {
                                   y:options.e.pageY});
            canvas.add(vert);
            canvas.bringToFront(vert);
-           console.log(vert)
-           console.log(options.e.pageY-v_radius)
        }
        break;
     case 'e':
@@ -69,21 +68,24 @@ var mousedown = function(options,canvas) {
                curr_vert = null;
                canvas.add(edge);
                canvas.sendToBack(edge);
-               console.log(edge);
-               console.log(options.target.left)
            }
        }
        break;
     case 's':
+       if(options.target && options.target.type == 'Vertex') {
+           curr_ed = options.target;
+           document.getElementById("label").value = curr_ed.label;
+           document.getElementById("editor").style.display = "block";
+           
+       }
        break;
     case 'd':
        if(options.target) {
-           if(options.target.type=='Edge') {
-               canvas.remove(options.target);
-           }
-           else { // it's a vertex...
-               edges = []
+           if(options.target.type=='Vertex') {
+               edges = getEdges(options.target,canvas);
+               edges.map(function(e){canvas.remove(e);});
            }
+           canvas.remove(options.target);
        }
        break;
     default:
@@ -93,10 +95,45 @@ var mousedown = function(options,canvas) {
     canvas.renderAll();
 };
 
+var submit = function() {
+    var label = document.getElementById('label').value;
+    labelVertex(curr_ed,label);
+}
+
 var labelVertex = function(vert,label) {
     vert.set({'label':label});
 }
 
+var getEdges = function(vert,canvas) {
+    edges = [];
+    canvas.forEachObject(function(o) {
+       if(o.type == 'Edge' && o.vertices != []) {
+           if(o.vertices[0]==vert) {
+               edges.push(o);
+           }
+           else if(o.vertices[1]==vert) {
+               edges.push(o);
+           }
+       }
+    });
+    return edges;//here too
+}
+
+var getNeighbors = function(vert,canvas) {
+    neighbors = [];
+    canvas.forEachObject(function(o) {
+       // here
+       if(o.type == 'Edge' && o.vertices!=[]) {
+           if(o.vertices[0]==vert) {
+               neighbors.push(o.vertices[1]);
+           }
+           else if(o.vertices[1]==vert) {
+               neighbors.push(o.vertices[0]);
+           }
+       }
+    });
+    return neighbors;
+}
 
 var Vertex = fabric.util.createClass(fabric.Circle, {
     type: 'Vertex',
index 00b8e1035d9ebda8646a80da3504041c65dfa913..88dcb1867deb79cae2815e2cd9d518664bb2dbcf 100644 (file)
       <button onclick="mode = 's'">Select</button>
       <button onclick="mode = 'd'">Remove</button>
     </div>
+    <div id="editor" style="display: none">
+      Label: <input id="label" type="text" value=""/>
+      Neighbors: <div id="neighbors"></div>
+      <input id="submitlabel" type="button" value="OK" onclick="submit()"/>
+    </div>
   </body>
 </html>