From 5f4defa2e6557bc0972f1e14e56f6cff94bebb55 Mon Sep 17 00:00:00 2001 From: eli173 Date: Sat, 29 Aug 2015 12:24:44 -0500 Subject: [PATCH] got naming, deletion good --- graph.js | 55 +++++++++++++++++++++++++++++++++++++++++++++--------- index.html | 5 +++++ 2 files changed, 51 insertions(+), 9 deletions(-) diff --git a/graph.js b/graph.js index 1d6ef5c..7d99dac 100644 --- 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', diff --git a/index.html b/index.html index 00b8e10..88dcb18 100644 --- a/index.html +++ b/index.html @@ -18,5 +18,10 @@ + -- 2.39.2