mode = 'v'
curr_vert = null;
+evt = null;
+
main = function() {
var canvas = new fabric.Canvas("surface",{backgroundColor:'white'});
// canvas.add(Edge({x1:44,y1:44,x2:88,y2:88,fill:'red',stroke:'red'}))
var mousedown = function(options,canvas) {
- console.log(options.target);
+ evt = options
switch(mode) {
case 'v':
if(!options.target) {
- var vert = new Vertex({x:options.e.clientX,
- y:options.e.clientY});
+ var vert = new Vertex({x:options.e.pageX,
+ y:options.e.pageY});
canvas.add(vert);
+ canvas.bringToFront(vert);
+ console.log(vert)
+ console.log(options.e.pageY-v_radius)
}
break;
case 'e':
if(options.target && options.target.type=='Vertex') {
- console.log(curr_vert)
if(curr_vert==null) {
curr_vert = options.target;
}
x2:options.target.left,
y2:options.target.top,
vertices:vertices});
- console.log(edge.x2)
+ canvas.add(new fabric.Rect({
+ left:Math.min(curr_vert.left,options.target.left),
+ top:Math.min(curr_vert.top,options.target.top),
+ width:Math.abs(curr_vert.left-options.target.left),
+ height:Math.abs(curr_vert.top-options.target.top),
+ fill:'green'
+ }));
curr_vert = null;
canvas.add(edge);
+ canvas.sendToBack(edge);
+ console.log(edge);
+ console.log(options.target.left)
}
}
break;
default:
break;
- }
+ };
canvas.renderAll();
};
options || (options = { });
this.callSuper('initialize',{radius:v_radius,fill:v_color,
originX:'center',originY:'center'});
- this.set('top',options.y || 0);
- this.set('left',options.x || 0);
- this.set('label',options.label||'');
- this.set('edges',options.edges||[]);
- this.set('hasControls',false);
- this.set('hasBorders',false);
+ this.set({'top':(options.y || 0)-v_radius});
+ this.set({'left':(options.x || 0)-v_radius});
+ this.set({'label':options.label||''});
+ this.set({'edges':options.edges||[]});
+ this.set({'hasControls':false});
+ this.set({'hasBorders':false});
},
toObject: function() {
return fabric.util.object.extend(this.callSuper('toObject'), {
type: 'Edge',
initialize: function(options) {
options || (options = { });
- this.callSuper('initialize',{x1:options.x1||0,y1:options.y1||0,
- x2:options.x2||0,y2:options.y2||0,
- stroke:e_color,
- strokeWidth:e_width});
- this.set('vertices',options.vertices||[]);
+ this.callSuper('initialize',
+ {stroke:e_color,strokeWidth:e_width,
+ selectable:false});
+ // this.set({'vertices':options.vertices||[]});
+ // this.set({'x1':options.x1||0});
+ // this.set({'x2':options.x2||0});
+ // this.set({'y1':options.y1||0});
+ // this.set({'y2':options.y2||0});
},
toObject: function() {
return fabric.util.object.extend(this.callSuper('toObject'), {