v1.0.0 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 of 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 must click the icon on the control toolbar and select the desired arrangement mode. Note that this feature causes irreversible changes in the objects' positioning. This process came as a way to help the user to visualize database models with lots of objects. 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 arrangement 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 of 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 arrangement 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 collisions, the process will fix the positions of the colliding objects until no more intersections are detected. The method can be used, for instance, right after reverse engineering a database that 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 when 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 arrangement 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.


Jun 27, 2023 at 09:39