<canvas id="mainCanvas" width="1024" height="768" style="border:1px solid #000000;"></canvas>
<br />
<button onclick="mgmain.bringToCenter();">Center</button>
+<button onclick="mgmain.isFrozen = !mgmain.isFrozen;">Freeze</button>
<button onclick="mgmain.zoomIn();">+</button>
<button onclick="mgmain.zoomOut();">-</button>
<button onclick="mgmain.moveViewRelative(0, -10);">↑</button>
<button onclick="mgmain.moveViewRelative(0, 10);">↓</button>
<button onclick="mgmain.moveViewRelative(-10, 0);">←</button>
<button onclick="mgmain.moveViewRelative(10, 0);">→</button>
+<input id="identBox" type="text">
+<button onclick="mgmain.setIdentifierForSelectedNode(getElementById('identBox').value);">set</button>
</body>
</html>
\ No newline at end of file
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){
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){
);
}
- //
- // 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();
}
//
}
}
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){
this.repulsionLengthNode = 90;
this.repulsionLengthEdge = 90;
this.ignoreEdgeRepulsion = 0;
+ //
this.strokeStyle = "rgba(0, 0, 0, 1)";
this.isSelected = false;
}
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);
}