mode = 'v'
curr_vert = null;
+curr_ed = null;
evt = null;
y:options.e.pageY});
canvas.add(vert);
canvas.bringToFront(vert);
- console.log(vert)
- console.log(options.e.pageY-v_radius)
}
break;
case 'e':
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:
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',
<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>