A computer science question

Peter Haworth pete at lcsql.com
Tue Feb 10 13:23:56 EST 2015


I've managed to get by for many years without the benefit of any formal
computer science training but I think I've finally run into a situation
which is probably solvable by a computer science algorithm.

I want to implement a database diagram feature in my SQLiteAdmin program
with a graphic to represent each table and lines connecting tables that
have a foreign key relationship.

The first challenge was to arrange the tables in a series of levels with
the tables that are not referenced in any foreign keys at the top the
second level with tables that reference the top level, and so on.  That I
have figured out with a nice recursive handler.

Now I'm faced with the issue of drawing the relationship lines.  Currently
the tables at each level are arranged in alphabetical order but that pretty
much guarantees that a table graphic will not be in the optimal position to
be connected to its parent table.

For example, I'm looking at a diagram where the table at the top left needs
a line drawn to the table at the bottom right.  Ideally the table at the
bottom right should be placed at the bottom left (or somewhere close) so
the connecting line can drawn from it to the table at the top left.

I'm guessing there is a computer science algorithm that will place the
table graphics in the optimal position for the connection lines to be
drawn.  Can anyone point me to that algorithm?

Pete
lcSQL Software <http://www.lcsql.com>
Home of lcStackBrowser <http://www.lcsql.com/lcstackbrowser.html> and
SQLiteAdmin <http://www.lcsql.com/sqliteadmin.html>



More information about the use-livecode mailing list