From abea5e44097c31c8cc5b1b5e64c6086a862c6ca3 Mon Sep 17 00:00:00 2001 From: hikarupsp Date: Wed, 16 Apr 2014 02:03:03 +0900 Subject: [PATCH] =?utf8?q?=E3=83=8E=E3=83=BC=E3=83=89=E8=AD=98=E5=88=A5?= =?utf8?q?=E5=AD=90=E3=81=AE=E5=A4=89=E6=9B=B4=E3=81=8C=E3=81=A7=E3=81=8D?= =?utf8?q?=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E3=81=AA=E3=81=A3=E3=81=9F?= =?utf8?q?=E3=80=82=20=E3=81=BE=E3=81=9F=E3=80=81=E8=A1=A8=E7=A4=BA?= =?utf8?q?=E3=82=92=E4=B8=80=E6=99=82=E5=81=9C=E6=AD=A2=E3=81=99=E3=82=8B?= =?utf8?q?=E3=81=93=E3=81=A8=E3=81=8C=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88?= =?utf8?q?=E3=81=86=E3=81=AB=E3=81=AA=E3=81=A3=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- mgcanvas/index.html | 3 ++ mgcanvas/mgcanvas.js | 87 +++++++++++++++++++++++++++++++++------------------- 2 files changed, 59 insertions(+), 31 deletions(-) diff --git a/mgcanvas/index.html b/mgcanvas/index.html index 06a4e65..cec60f6 100755 --- a/mgcanvas/index.html +++ b/mgcanvas/index.html @@ -137,11 +137,14 @@ onload = function() {
+ + + \ No newline at end of file diff --git a/mgcanvas/mgcanvas.js b/mgcanvas/mgcanvas.js index 4e43a43..9f4fc3a 100755 --- a/mgcanvas/mgcanvas.js +++ b/mgcanvas/mgcanvas.js @@ -10,8 +10,10 @@ function MGCanvas(canvasDOMObj){ this.tickPerSecond = 30; this.tickCount = 0; this.tickTimer = window.setInterval(function(){ that.tick(); }, 1000 / this.tickPerSecond); + this.isFrozen = false; this.nodeList = new Array(); this.edgeList = new Array(); + this.selectedEdge = null; var that = this; window.addEventListener('keydown', function(event){ @@ -51,11 +53,9 @@ function MGCanvas(canvasDOMObj){ that.lastMousePosition = that.getMousePositionOnElement(e); that.mouseDownPosition = that.lastMousePosition; var p = that.convertPointToGraphLayerFromCanvasLayerP(that.lastMousePosition); - console.log(p.x + "," + p.y); + //console.log(p.x + "," + p.y); var node = that.getNodeAtPointP(p); - if(node){ - node.isSelected = true; - } + that.selectNode(node); that.isMouseDown = true; }; this.canvas.onmouseup = function (e){ @@ -147,33 +147,35 @@ MGCanvas.prototype = { ); } - // - // Check - // - - p = this.nodeList; - for(var i = 0, iLen = p.length; i < iLen; i++){ - nTemp = this.getVectorLength(p[i].vector); - if(nMax < nTemp){ - n = p[i]; - nMax = nTemp; + if(!this.isFrozen){ + // + // Check + // + + p = this.nodeList; + for(var i = 0, iLen = p.length; i < iLen; i++){ + nTemp = this.getVectorLength(p[i].vector); + if(nMax < nTemp){ + n = p[i]; + nMax = nTemp; + } + } + if(n){ + n.ignoreEdgeRepulsion = 10; + } + + + // + // Move + // + p = this.nodeList; + for(var i = 0, iLen = p.length; i < iLen; i++){ + this.nodeList[i].tick(); + } + p = this.edgeList; + for(var i = 0, iLen = p.length; i < iLen; i++){ + this.edgeList[i].tick(); } - } - if(n){ - n.ignoreEdgeRepulsion = 10; - } - - - // - // Move - // - p = this.nodeList; - for(var i = 0, iLen = p.length; i < iLen; i++){ - this.nodeList[i].tick(); - } - p = this.edgeList; - for(var i = 0, iLen = p.length; i < iLen; i++){ - this.edgeList[i].tick(); } // @@ -366,7 +368,21 @@ MGCanvas.prototype = { } } return null; - } + }, + selectNode: function(node){ + if(this.selectedNode){ + this.selectedNode.isSelected = false; + } + if(node){ + node.isSelected = true; + } + this.selectedNode = node; + }, + setIdentifierForSelectedNode: function(str){ + if(this.selectedNode){ + this.selectedNode.identifier = str; + } + }, } function MGNode(env, identifier){ @@ -380,6 +396,7 @@ function MGNode(env, identifier){ this.repulsionLengthNode = 90; this.repulsionLengthEdge = 90; this.ignoreEdgeRepulsion = 0; + // this.strokeStyle = "rgba(0, 0, 0, 1)"; this.isSelected = false; } @@ -455,9 +472,17 @@ function MGEdge(env, identifier, node0, node1){ this.node0 = node0; this.node1 = node1; this.freeLength = 250; + // + this.strokeStyle = "rgba(0, 0, 0, 1)"; + this.isSelected = false; } MGEdge.prototype = { draw: function(){ + if(this.isSelected){ + this.env.context.strokeStyle = "rgba(255, 0, 0, 1)"; + } else{ + this.env.context.strokeStyle = this.strokeStyle; + } if(this.node0 && this.node1){ this.env.drawLineP(this.node0.position, this.node1.position); } -- 2.11.0