GoJS Sample for JSFIDDLE

Impressive software, just way too expensive in my opinion.

by Ryan Vice

HTML

<script src="http://www.gojs.net/latest/samples/goSamples.js"></script>
<script src="http://www.gojs.net/latest/release/go.js"></script>
<span>Go</span>
<div id="myDiagramDiv" style="border: solid 1px black; width:400px; height:400px"></div>
</div>

JavaScript

function LinkingDraggingTool() {
   go.DraggingTool.call(this);
   var $ = go.GraphObject.make;
   this._tempLink =
     $(go.Link, {
         layerName: "Tool"
       },
       $(go.Shape, {
         stroke: "blue",
         strokeWidth: 3
       }),
       $(go.Shape, {
         stroke: "blue",
         strokeWidth: 3,
         toArrow: "OpenTriangle"
       })
     );
   this._tempNode =
     $(go.Node, {
       layerName: "Tool"
     }, {
       fromLinkable: true
     });
 }

 go.Diagram.inherit(LinkingDraggingTool, go.DraggingTool);

 LinkingDraggingTool.prototype.doDeactivate = function() {
   go.DraggingTool.prototype.doDeactivate.call(this);
   this.diagram.remove(this._tempLink);
   this.diagram.remove(this._tempNode);
 }

 LinkingDraggingTool.prototype.findNearestNode = function(pt, draggednode) {
   var linkingTool = this.diagram.toolManager.linkingTool;
   var draggeds = this.draggedParts;
   var near = this.diagram.findObjectsNear(pt, 50,
     // only consider undragged Nodes for which a new link would be valid
     function(x) {
       var p = x.part;
       if (p instanceof go.Node &&
         !draggeds.contains(p) &&
         linkingTool.isValidLink(draggednode, draggednode.port, p, p.port)) {
         return p;
       }
       return null;
     });
   // find Node whose location is closest to PT
   var dist = Infinity;
   var nearest = null;
   near.each(function(n) {
     var d2 = n.location.distanceSquaredPoint(pt);
     if (d2 < dist) {
       dist = d2;
       nearest = n;
     }
   });
   return nearest;
 };

 LinkingDraggingTool.prototype.doDragOver = function(pt, over) {
   if (this.copiedParts !== null) return;
   var draggednode = this.draggedParts.first().key;
   var nearest = this.findNearestNode(pt, draggednode);
   if (nearest !== null && draggednode instanceof go.Node) {
     this._tempNode.location = nearest.actualBounds.center;
     this.diagram.add(this._tempNode);
     this._tempLink.fromNode = draggednode;
    ...