Hello,
I am using go.js 2.3.5 from within react components, with chrome.
My question is about panning external objects from an external diagram into my diagram.
Specifically my wish is to be able to control the spacing between my objects as they are panned.
Currently my problem is that the panned objects overlap one another (in 10-20px) and enforce the user to separate them after they are dropped.
The requirement is that already during the panning and after they are dropped, they will be spaced.
However, I do not wish that spacing specification to impact other objects that are already part of my diagram. Their layout must stay intact as it was before the panning.
Already tried: diagram.model.addChangedListener
this responded in the proper timing, and I saw concrete values for: e.modelChange, e.change.name, e.model.nodeDataArray
however, when panned more than 1 component, it was triggered separately for each one of them.
In addition, accessing e.diagram
was a dead end (null)
Also tried: diagram.addDiagramListener('ExternalObjectsDropped', (e: go.DiagramEvent) => {
this responded but only after dropping the panned objects, which is a little bit late.
Also, it is unclear to me at this stage how to change the spacing between the objects.
So:
What is the correct way to control/enforce panning of new objects from outside into my diagram?
Based on your descriptions, I believe the term you intended to use is âdraggingâ, not âpanningâ. I have updated the title accordingly.
Are you just asking to make sure that when the user performs an external drag-and-drop into a diagram that the dropped nodes not overlap with the pre-existing nodes? Something like: Drag Unoccupied
No,
I donât mind about pre-existing nodes in the target diagram. (Overlapping with them is up to the user).
Itâs those âdropped nodesâ I care about. I donât want overlapping among themselves (During dragging and right after dropping), exactly as you can see in the attached screenshot which I hope is visible in the post.
I want to spare the user from the constant need of arranging those nodes after dropping them onto the diagram.
Normally the automatic location of nodes is the responsibility of a Layout, but I suspect you donât want that. I think you want to either implement an âExternalObjectsDroppedâ DiagramEvent listener to arrange the e.subject collection after having been dropped, or else override DraggingTool.computeEffectiveCollection in the source Diagram to call the super method first, arrange the results, and then return the collection.
Concerning your 2nd suggestion, can you please provide an example of how to do it?
I see a lot of example which use the following as part of calling the suprt method.
go.DraggingTool.prototype.computeEffectiveCollection.call(thisâŚ
but I cannot figure out why in my case I end up with âthisâ as null or undefined during runtime.