From 0e5621a24677e4b286131effd81035a59261eca0 Mon Sep 17 00:00:00 2001 From: hikarupsp Date: Sat, 26 Apr 2014 10:51:52 +0900 Subject: [PATCH] =?utf8?q?=E8=87=AA=E5=8B=95=E8=BF=BD=E5=B0=BE=E3=82=92?= =?utf8?q?=E5=86=8D=E5=AE=9F=E8=A3=85=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- mgcanvas/index.html | 6 +++--- mgcanvas/mgcanvas.js | 36 ++++++++++++++++++++++++++---------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/mgcanvas/index.html b/mgcanvas/index.html index 8aa5545..8ea27ea 100755 --- a/mgcanvas/index.html +++ b/mgcanvas/index.html @@ -23,7 +23,7 @@ onload = function() { var c = document.getElementById("mainCanvas"); mgmain = new MGCanvas(c); - + /* mgmain.setGraph([[ "A","B","C","D","E","F", ],[ @@ -35,7 +35,7 @@ onload = function() { ["A", "E"], ["A", "B"], ]]); - + */ /* mgmain.setGraph([[ "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P", @@ -137,7 +137,7 @@ onload = function() {
- + diff --git a/mgcanvas/mgcanvas.js b/mgcanvas/mgcanvas.js index 72fa1ea..74f4038 100755 --- a/mgcanvas/mgcanvas.js +++ b/mgcanvas/mgcanvas.js @@ -1,7 +1,3 @@ -//文字列をキーとする。 - -//まず、最も多数のエッジを持つノードを探す。 -//それを起点にして、エッジをたどる。 function MGCanvas(canvasDOMObj){ var that = this; @@ -10,7 +6,8 @@ function MGCanvas(canvasDOMObj){ this.tickPerSecond = 30; this.tickCount = 0; this.tickTimer = window.setInterval(function(){ that.tick(); }, 1000 / this.tickPerSecond); - this.isFrozen = false; + this.isPaused = false; + this.isEnabledAutomaticTracking = true; this.nodeList = new Array(); this.edgeList = new Array(); this.selectedNode = null; @@ -60,6 +57,7 @@ function MGCanvas(canvasDOMObj){ var edge = that.getEdgeAtPointP(p); that.selectEdge(edge); that.isMouseDown = true; + that.isEnabledAutomaticTracking = false; }; this.canvas.onmouseup = function (e){ that.isMouseDown = false; @@ -81,6 +79,12 @@ MGCanvas.prototype = { this.edgeList.push(new MGEdge(this, p[i][2], n(p[i][0]), n(p[i][1]))); } }, + addNode: function(identifier, uuid){ + + }, + addEdge: function(identifier, uuid, nodeid){ + + }, bringToCenter: function(){ // 重心を求めて、それを表示オフセットに設定する var g = new Point2D(0, 0); @@ -95,6 +99,8 @@ MGCanvas.prototype = { this.positionOffset.x = -g.x; this.positionOffset.y = -g.y; + + this.isEnabledAutomaticTracking = true; }, zoomIn: function(){ this.context.scale(2, 2); @@ -108,10 +114,10 @@ MGCanvas.prototype = { this.positionOffset.x += -x; this.positionOffset.y += -y; }, - /* bringInScreen: function(){ //大きく外れていないときには動かさない var g = new Point2D(0, 0); + var f = new Point2D(0, 0); var p; p = this.nodeList; for(var i = 0, iLen = p.length; i < iLen; i++){ @@ -120,16 +126,17 @@ MGCanvas.prototype = { } g.x /= p.length; g.y /= p.length; + g.x += this.positionOffset.x; + g.y += this.positionOffset.y; if( g.x < this.displayRect.origin.x / 2 || g.x > -this.displayRect.origin.x / 2 || g.y < this.displayRect.origin.y / 2 || g.y > -this.displayRect.origin.x / 2){ - this.positionOffset.x = -g.x; - this.positionOffset.y = -g.y; + this.positionOffset.x += -g.x; + this.positionOffset.y += -g.y; } }, - */ tick: function(){ var p; var t; @@ -141,6 +148,15 @@ MGCanvas.prototype = { this.tickCount++; // + // AutomaticTracking + // + + if(this.isEnabledAutomaticTracking && (this.tickCount % 30 == 0)){ + this.bringInScreen(); + } + + + // // View moving with mouse // if(this.isMouseDown){ @@ -150,7 +166,7 @@ MGCanvas.prototype = { ); } - if(!this.isFrozen){ + if(!this.isPaused){ // // Check // -- 2.11.0