Help with findObjectsIn

Hello everyone,

I have a diagram like “State Chart” with the function “addNodeAndLink” and I would like a kind of algorithm who calculate the location to avoid another rectangle. (without stacking) when I press the button “+”.
I think I should use “findObjectsIn” but I don’t see how…
Can I have an example please?

I apologize for my language because I’m french LOL


Here’s how you could implement that functionality.
In stateChart.html, replace this code in addNodeAndLink:
var p = fromNode.location;<br /> toData.loc = p.x + 200 + " " + p.y;Â // the "loc" property is a string, not a Point object
with:
var r = fromNode.actualBounds.copy();<br /> r.x = r.x + 200; // start looking off to the right of the original node<br /> while (diagram.findObjectsIn(r, // find all Nodes that intersect with this rect<br /> function(obj) { return obj.part; },<br /> function(obj) { return obj instanceof go.Node; },<br /> true).count > 0) {<br /> r.y += 10; // try searching farther down from there<br /> }<br /> toData.loc = go.Point.stringify(r.position); // the "loc" property is a string, not a Point object
Of course you may want to change where it looks to find a place for the new node.

And you never need to apologize about being French. Or of any other culture.



Oh oh oh !

It works very well !
THANK YOU FROM FRANCEWink