Determining location for new table in Seating Chart

Hi,

I’m hacking the Seating Chart sample you have on your website and it’s going pretty well.

I have built a UI that allows the user to add a new table and this works fine. My only problem is determining a location on the main diagram to add the table at. I want it to be added at a location that doesn’t overlap with existing tables, so I presume some sort of collision detection is required.

Is there any built in functionality that can allow me to do this?

Many thanks,
John

Try calling http://gojs.net/latest/api/symbols/Diagram.html#findObjectsIn.

Of course you will need to decide where to look.

Hi Walter,

Thanks for your response. I think you mean that I should try guessing a location and using that method to see if it’s already used?

Do you have any suggestions on a strategy for guessing the first location, and subsequent location(s) should it already be occupied?

Thanks

Yes, you have to try and guess, or develop an algorithm to find the nearest suitable space that you would find adequate. There’s nothing built in to GoJS that does this.

A very simplistic approach would be to call findObjectsIn with a desired space, go through them all and find the largest value of node.actualBounds.right + 1, then try again using that value as the new x coordinate.

Thanks, this worked for me. Appreciate the help!