Summary Chapter 7: Modeling tips and tricks 7. Introduction 7.15. Autoarrange objects over the canvas

7.15. Autoarrange objects over the canvas

The auto arrangement feature, which is not a trivial problem to solve, consists in a process that will sort tables and views in three different ways: hierarchical, scattered and grid. In order to trigger the auto arrangement feature you should click the icon on control toolbar and select the desired arragement mode. Note that this feature causes irreversible changes on the objects postioning. This process came as a way to help the user to visualize database models with lots of objetcs. Depending on the size of your model the process will take some time. After completing the result, for each mode, will be something like the image below.

The hierarchal arragement basically takes a table or a view with the major amount of relationships connected and uses it as the root of the hierarchy. The next step is to place aside the root all the tables and views that are directly linked to it. This routine is then repeated until all linked tables are arranged close to their parents or counterparts. If there are tables or views without relationships attached they will be placed at the bottom of the canvas. This rule is applied to text boxes that naturally are standalone objects being not possible to link them to any other object.

The scattered arragement basically places tables in random positions within their respective schemas and then scatters randomly the schemas themselves over the canvas area. Albeit being a random position generator the algorithm will try the most to avoid tables and schemas collisions or overlaps by detecting if the bounding rectangles of the mentioned objects intercept somehow. Once detected some collision the process will fix the colliding objects positions until no more intersections are detected. The method can be used, for instance, right after reverse engineering a database which contains several tables and schemas. Since the grid arrangement is the default when importing objects from a database, by using the scattered mode the user has a chance to sort the objects randomly and quickly without the need to move table per table to the desired location. Of course, the algorithm is not perfect and has its flaws. For instance, if the model is too big there'll be moments that constant overlaps or intersections will happen for the same set of objects thus pgModeler will stop to try repositioning these objects after a certain number of iterations avoiding the application hanging.

Lastly, the simplest mode is the grid arragement which places tables and views side-by-side forming a grid of 5 columns and 5 rows within every schema. This is the less "smart" procedure which is used as a starting point to use the other arrangement modes or even let the user manually organize the objects over the canvas as desired.

Sep 12, 2018 at 16:31