evt = null;
-main = function() {
+var main = function() {
var canvas = new fabric.Canvas("surface",{backgroundColor:'white'});
canvas.on('mouse:down',function(o){mousedown(o,canvas)});
}
+var setMode = function(ch) {
+ mode = ch;
+ if(mode!='s') {
+ document.getElementById("editor").style.display = "none";
+ }
+}
+
var movement = function(options,canvas) {
vert = options.target;
edges = [];
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";
}
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'), {
<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>