]> git.eli173.com Git - graphbyhand/commitdiff
some select stuff
authoreli173 <eli@eli173.com>
Sat, 29 Aug 2015 18:15:25 +0000 (13:15 -0500)
committereli173 <eli@eli173.com>
Sat, 29 Aug 2015 18:15:25 +0000 (13:15 -0500)
graph.js
index.html

index 7d99dac9f52484f5c0c867770ec856e6c8b2319f..00232efd444023b081cdf7e05d85a753d5f60286 100644 (file)
--- a/graph.js
+++ b/graph.js
@@ -16,7 +16,7 @@ curr_ed = null;
 
 evt = null;
 
-main = function() {
+var main = function() {
     var canvas = new fabric.Canvas("surface",{backgroundColor:'white'});
 
     canvas.on('mouse:down',function(o){mousedown(o,canvas)});
@@ -24,6 +24,13 @@ main = function() {
 }
 
 
+var setMode = function(ch) {
+    mode = ch;
+    if(mode!='s') {
+       document.getElementById("editor").style.display = "none";
+    }
+}
+
 var movement = function(options,canvas) {
     vert = options.target;
     edges = [];
@@ -75,6 +82,14 @@ var mousedown = function(options,canvas) {
        if(options.target && options.target.type == 'Vertex') {
            curr_ed = options.target;
            document.getElementById("label").value = curr_ed.label;
+           document.getElementById("elementid").innerHTML = curr_ed.id;
+           neighbors = getNeighbors(curr_ed,canvas);
+           nbrstrs = []
+           neighbors.map(function(e) {
+               nbrstrs.push("Label: "+e.label+", id:"+e.id+"<br/>");
+           });
+           nbstring = nbrstrs.join('\n');
+           document.getElementById("neighbors").innerHTML = nbstring;
            document.getElementById("editor").style.display = "block";
            
        }
@@ -147,6 +162,7 @@ var Vertex = fabric.util.createClass(fabric.Circle, {
        this.set({'edges':options.edges||[]});
        this.set({'hasControls':false});
        this.set({'hasBorders':false});
+       this.id = v_counter++;
     },
     toObject: function() {
        return fabric.util.object.extend(this.callSuper('toObject'), {
index 88dcb1867deb79cae2815e2cd9d518664bb2dbcf..4414c46fd71ea7ea88c5f00ad8062f4743191bad 100644 (file)
       <canvas id="surface" width="1000" height="300"></canvas>
     </div>
     <div id="buttons">
-      <button onclick="mode = 'v'">Place Vertices</button>
-      <button onclick="mode = 'e'">Place Edges</button>
-      <button onclick="mode = 's'">Select</button>
-      <button onclick="mode = 'd'">Remove</button>
+      <button onclick="setMode('v')">Place Vertices</button>
+      <button onclick="setMode('e')">Place Edges</button>
+      <button onclick="setMode('s')">Select</button>
+      <button onclick="setMode('d')">Remove</button>
     </div>
     <div id="editor" style="display: none">
       Label: <input id="label" type="text" value=""/>
-      Neighbors: <div id="neighbors"></div>
+      ID: <div style="display:inline-block" id="elementid"></div><br/>
+      Neighbors: <div id="neighbors"></div><br/>
       <input id="submitlabel" type="button" value="OK" onclick="submit()"/>
     </div>
   </body>