Positioning a drag-and-drop added node


I’m creating an interface that allows users to drag search results into a go.js diagram and have them appear as new nodes. Everything is working except accurate positioning of the new node elements. My attempt always appears some distance to the southeast of the intended spot. I’m guessing that given the mouse event object though, I should be able to express a generic line of code that places the node at the mouseup point, but I’m not sure what I’m missing. This is what I’m currently trying, where ‘e’ is the mouse event, and ‘pt’ should hold the loc value:

notifyDropTarget: function (ddSource, e, data) {

    var myDiagram = this.getGoMainCanvas().diagram,
        pt = myDiagram.transformViewToDoc(new go.Point(e.getXY()[0], e.getXY()[1])),
        locString = String(pt.x + ' ' + pt.y);

    var nodeData = {
        key: data.records[0].data.uri,
        title: data.records[0].data.label,
        type: "standard",
        category: "standard",
        percent: 22.60845450218767,
        color: "#00FFFF",
        description: data.records[0].data.preview,
        loc: locString



Big thanks in advance for any insight.


  • Ken

I think this sample demonstrates what you want: http://gojs.net/latest/samples/htmldragdrop.html

That uses jQuery drag-and-drop, but even if you aren't using jQuery, I hope it is instructive.

Fantastic - it certainly does! Thanks so much for the help, Walter