From: eli173 Date: Sat, 29 Aug 2015 00:05:40 +0000 (-0500) Subject: FINALLY edges work ok X-Git-Url: https://git.eli173.com/?a=commitdiff_plain;h=a8174c51ce4336f9e133bad6ce854bde4cc2c9d9;p=graphbyhand FINALLY edges work ok --- diff --git a/graph.js b/graph.js index 587b7f4..8211b13 100644 --- a/graph.js +++ b/graph.js @@ -13,7 +13,7 @@ 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'})) + canvas.on('mouse:down',function(o){mousedown(o,canvas)}); } @@ -43,13 +43,6 @@ var mousedown = function(options,canvas) { x2:options.target.left, y2:options.target.top, vertices:vertices}); - 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); @@ -94,14 +87,16 @@ var Edge = fabric.util.createClass(fabric.Line, { type: 'Edge', initialize: function(options) { options || (options = { }); - this.callSuper('initialize', + y1 = options.y1||0; + x1 = options.x1||0; + y2 = options.y2||0; + x2 = options.x2||0; + arr = [x1,y1,x2,y2]; + this.callSuper('initialize',arr, {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}); + selectable:false, + originX:'center', + originY:'center'}); }, toObject: function() { return fabric.util.object.extend(this.callSuper('toObject'), {