• R/O
  • HTTP
  • SSH
  • HTTPS

AI004: コミット

サブプロジェクトAI004


コミットメタ情報

リビジョンabea5e44097c31c8cc5b1b5e64c6086a862c6ca3 (tree)
日時2014-04-16 02:03:03
作者hikarupsp <hikarupsp@user...>
コミッターhikarupsp

ログメッセージ

ノード識別子の変更ができるようになった。
また、表示を一時停止することができるようになった。

変更サマリ

差分

--- a/mgcanvas/index.html
+++ b/mgcanvas/index.html
@@ -137,11 +137,14 @@ onload = function() {
137137 <canvas id="mainCanvas" width="1024" height="768" style="border:1px solid #000000;"></canvas>
138138 <br />
139139 <button onclick="mgmain.bringToCenter();">Center</button>
140+<button onclick="mgmain.isFrozen = !mgmain.isFrozen;">Freeze</button>
140141 <button onclick="mgmain.zoomIn();">+</button>
141142 <button onclick="mgmain.zoomOut();">-</button>
142143 <button onclick="mgmain.moveViewRelative(0, -10);">↑</button>
143144 <button onclick="mgmain.moveViewRelative(0, 10);">↓</button>
144145 <button onclick="mgmain.moveViewRelative(-10, 0);">←</button>
145146 <button onclick="mgmain.moveViewRelative(10, 0);">→</button>
147+<input id="identBox" type="text">
148+<button onclick="mgmain.setIdentifierForSelectedNode(getElementById('identBox').value);">set</button>
146149 </body>
147150 </html>
\ No newline at end of file
--- a/mgcanvas/mgcanvas.js
+++ b/mgcanvas/mgcanvas.js
@@ -10,8 +10,10 @@ function MGCanvas(canvasDOMObj){
1010 this.tickPerSecond = 30;
1111 this.tickCount = 0;
1212 this.tickTimer = window.setInterval(function(){ that.tick(); }, 1000 / this.tickPerSecond);
13+ this.isFrozen = false;
1314 this.nodeList = new Array();
1415 this.edgeList = new Array();
16+ this.selectedEdge = null;
1517
1618 var that = this;
1719 window.addEventListener('keydown', function(event){
@@ -51,11 +53,9 @@ function MGCanvas(canvasDOMObj){
5153 that.lastMousePosition = that.getMousePositionOnElement(e);
5254 that.mouseDownPosition = that.lastMousePosition;
5355 var p = that.convertPointToGraphLayerFromCanvasLayerP(that.lastMousePosition);
54- console.log(p.x + "," + p.y);
56+ //console.log(p.x + "," + p.y);
5557 var node = that.getNodeAtPointP(p);
56- if(node){
57- node.isSelected = true;
58- }
58+ that.selectNode(node);
5959 that.isMouseDown = true;
6060 };
6161 this.canvas.onmouseup = function (e){
@@ -147,33 +147,35 @@ MGCanvas.prototype = {
147147 );
148148 }
149149
150- //
151- // Check
152- //
153-
154- p = this.nodeList;
155- for(var i = 0, iLen = p.length; i < iLen; i++){
156- nTemp = this.getVectorLength(p[i].vector);
157- if(nMax < nTemp){
158- n = p[i];
159- nMax = nTemp;
150+ if(!this.isFrozen){
151+ //
152+ // Check
153+ //
154+
155+ p = this.nodeList;
156+ for(var i = 0, iLen = p.length; i < iLen; i++){
157+ nTemp = this.getVectorLength(p[i].vector);
158+ if(nMax < nTemp){
159+ n = p[i];
160+ nMax = nTemp;
161+ }
162+ }
163+ if(n){
164+ n.ignoreEdgeRepulsion = 10;
165+ }
166+
167+
168+ //
169+ // Move
170+ //
171+ p = this.nodeList;
172+ for(var i = 0, iLen = p.length; i < iLen; i++){
173+ this.nodeList[i].tick();
174+ }
175+ p = this.edgeList;
176+ for(var i = 0, iLen = p.length; i < iLen; i++){
177+ this.edgeList[i].tick();
160178 }
161- }
162- if(n){
163- n.ignoreEdgeRepulsion = 10;
164- }
165-
166-
167- //
168- // Move
169- //
170- p = this.nodeList;
171- for(var i = 0, iLen = p.length; i < iLen; i++){
172- this.nodeList[i].tick();
173- }
174- p = this.edgeList;
175- for(var i = 0, iLen = p.length; i < iLen; i++){
176- this.edgeList[i].tick();
177179 }
178180
179181 //
@@ -366,7 +368,21 @@ MGCanvas.prototype = {
366368 }
367369 }
368370 return null;
369- }
371+ },
372+ selectNode: function(node){
373+ if(this.selectedNode){
374+ this.selectedNode.isSelected = false;
375+ }
376+ if(node){
377+ node.isSelected = true;
378+ }
379+ this.selectedNode = node;
380+ },
381+ setIdentifierForSelectedNode: function(str){
382+ if(this.selectedNode){
383+ this.selectedNode.identifier = str;
384+ }
385+ },
370386 }
371387
372388 function MGNode(env, identifier){
@@ -380,6 +396,7 @@ function MGNode(env, identifier){
380396 this.repulsionLengthNode = 90;
381397 this.repulsionLengthEdge = 90;
382398 this.ignoreEdgeRepulsion = 0;
399+ //
383400 this.strokeStyle = "rgba(0, 0, 0, 1)";
384401 this.isSelected = false;
385402 }
@@ -455,9 +472,17 @@ function MGEdge(env, identifier, node0, node1){
455472 this.node0 = node0;
456473 this.node1 = node1;
457474 this.freeLength = 250;
475+ //
476+ this.strokeStyle = "rgba(0, 0, 0, 1)";
477+ this.isSelected = false;
458478 }
459479 MGEdge.prototype = {
460480 draw: function(){
481+ if(this.isSelected){
482+ this.env.context.strokeStyle = "rgba(255, 0, 0, 1)";
483+ } else{
484+ this.env.context.strokeStyle = this.strokeStyle;
485+ }
461486 if(this.node0 && this.node1){
462487 this.env.drawLineP(this.node0.position, this.node1.position);
463488 }
旧リポジトリブラウザで表示