I'm using UserObject model to insert a vertex on mxGraph using drag n drop.


When a vertex is created with default parent (using graph.getDefaultParent() ), the position is where it is inserted is correct.


When inserted inside another vertex to form a parent-child relationship, the child cell location is shifted making the parent cell re-size itself. Is there a way to translate the point of insertion ?


I'm using graph.getPointForEvent method to get the drop location.



 var doc = mxUtils.createXmlDocument();\n var mxNode = doc.createElement("MyNode");\n mxNode.setAttribute('myId', 300);\n mxNode.setAttribute('name', "TestName");\n\n    var funct = function (graph, evt, target)\n    {\n        try\n        {\n            var cell = null;\n            var pt = graph.getPointForEvent(evt);\n\n            if (null == target)\n            {\n                target = graph.getDefaultParent();\n            }\n\n            graph.getModel().beginUpdate();\n            {\n                cell = graph.insertVertex(target, null, mxNode, pt.x, pt.y, width, height, style);\n            }\n            graph.getModel().endUpdate();\n\n            if (null != cell)\n            {\n                graph.setSelectionCells(cell);\n                graph.scrollCellToVisible(cell);\n            }\n        }\n        catch (e)\n        {\n            alert(e);\n        }\n    };\n

asked 18 Sep '11, 14:11

BlackCoffee's gravatar image

accept rate: 0%

Try this for pt:

var pt = graph.getPointForEvent(evt);  \nvar targetState = graph.getView().getState(target);\n\nif (targetState != null)\n{\n    var scale = graph.getView().scale;\n    pt.x -= targetState.origin.x * scale;\n    pt.y -= targetState.origin.y * scale;\n}\n

answered 19 Sep '11, 04:42

Gaudenz's gravatar image

accept rate: 39%

Thanks! that worked perfectly!

(19 Sep '11, 11:45) BlackCoffee
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 18 Sep '11, 14:11

Seen: 2,219 times

Last updated: 19 Sep '11, 11:45