//
// This work is licensed under the Creative Commons Attribution 2.5 License. To 
// view a copy of this license, visit
// http://creativecommons.org/licenses/by/2.5/
// or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San
// Francisco, California, 94105, USA.
//
// All copies and derivatives of this source must contain the license statement 
// above and the following attribution:
//
// Author: Kyle Scholz      http://kylescholz.com/
// Copyright: 2006
//

// override the functions that draw edges

  // render all edges
  GraphUI.prototype.drawEdges = function() {
    var ctx = document.getElementById('canvas').getContext("2d");
    ctx.clearRect(0,0,this['frame_width'],this['frame_height']);
	for( var i=0; i<graph.nodes.length; i++ ) {
	  if ( graph.originEdges[i] ) {
	    nodeI = graph.getNode(i);
	    nodeJ = graph.origin;
	    var distance = new Distance();
	    distance.calculate( nodeI.position, nodeJ.position );
	    this.drawEdge( nodeI, nodeJ, distance );
	  }
	  for( var j=0; j<graph.nodes.length; j++ ) {
	    if ( graph.edges[i] && graph.edges[i][j] ) {
	      nodeI = graph.getNode(i);
	      nodeJ = graph.getNode(j);
	      var distance = new Distance();
	      distance.calculate( nodeI.position, nodeJ.position );
	      this.drawEdge( nodeI, nodeJ, distance );
	    }
	  }
	}
  },
  
  // render an edge
  GraphUI.prototype.drawEdge = function ( nodeI, nodeJ, distance ) {
    var ctx = document.getElementById('canvas').getContext("2d");
    ctx.save();
    ctx.strokeStyle = "#666666";
    ctx.beginPath();
    ctx.lineWidth = .5;
    ctx.beginPath();
    ctx.moveTo( (nodeI['position']['x']+5),
                (nodeI['position']['y']+5) );
    ctx.lineTo( (nodeJ['position']['x']+5),
                (nodeJ['position']['y']+5) );
    ctx.stroke();
    ctx.restore();
  }
