pgadmin4 icon indicating copy to clipboard operation
pgadmin4 copied to clipboard

ERD: Improve auto layout

Open adityatoshniwal opened this issue 2 years ago • 17 comments

Describe the solution you'd like Currently, the auto layout in ERD places the nodes correctly but links are:

  1. Not always right angled.
  2. Goes behind the nodes.
  3. Does not switch sides to get best link route.

This can be improved by using a better algorithm.

adityatoshniwal avatar Jul 20 '23 05:07 adityatoshniwal

Screenshot_20230825_164341 An example of the lines not going anywhere very sensible. I'd personally call this a bugfix rather than a feature, though it's an aesthetic bug rather than a functional one.

HTH

wayland avatar Aug 25 '23 06:08 wayland

May also be related to https://github.com/pgadmin-org/pgadmin4/issues/5199

wayland avatar Oct 18 '23 21:10 wayland

seeing identical behavior on pgadmin 7.8 on Mac - after generating an ERD for an existing database, not only do the relationship lines look pretty wild, but they also have anchor points that don't reset and aren't movable/editable.

Note that this seems to be the only issue preventing an autogenerated ERD from being useful - everything else looks pretty good!

morrissimo avatar Nov 09 '23 22:11 morrissimo

Any progress on this or can someone point me in the direction where i can start working on it?

raprocks avatar Nov 20 '23 16:11 raprocks

Hi @raprocks, Right now, we're failing to find a relevant layout algorithm. Basically, a layout algo will help in getting the positions of nodes and links. We're using dagre currently https://www.npmjs.com/package/dagre

adityatoshniwal avatar Nov 21 '23 05:11 adityatoshniwal

For comparison, I'm attaching an auto-generated er diagram of the same (very simple) db done with pgAdmin4 v7.8 and a proprietary software (Navicat Data Modeler 3).

image

Diagram

I'm no expert, but maybe a first step in the right direction could be switching to RightAngleLinks as per @projectstorm/react-diagrams demo.

(I'm with @wayland in that this looks more like a bugfix than a feature-request. I do recognize that automatic laying-out is very complex to get right, and will probably require many iterations).

carlo-salinari avatar Dec 06 '23 13:12 carlo-salinari

@carlo-salinari The major difference between pgAdmin ERD and the ERD which you shared is - The links in pgAdmin start from the actual column used, and not just randomly sticking the link anywhere. If we're OK to sacrifice this then a solution can be worked on.

adityatoshniwal avatar Dec 06 '23 13:12 adityatoshniwal

@adityatoshniwal I believe from the end-user perspective the major difference is in terms of clarity, so to speak.

And that seems to come from the routing around (and not behind) the tables, better use of spacing and grouping, predictability of the links, overall less graphical noise from the background and better color contrast.

The direct connection to the column certainly complicates routing a bit, but it could probably be maintained. It would be interesting to find comparisons.

carlo-salinari avatar Dec 06 '23 13:12 carlo-salinari

@carlo-salinari I had tried to find a suitable algorithm to keep links on column and auto layout. But unfortunately didn't find anything concrete. I think at some point we'll have to let it go in favour of better clarity. In future if we find a suitable algo then we can link back to columns as an improvement.

adityatoshniwal avatar Dec 07 '23 05:12 adityatoshniwal

@adityatoshniwal You mean let go of the link-to-key constraint? That's something to experiment with, but I don't think that's the crux of the problem here.

Automatic graph layout is a notoriously hard problem: there is no clearly understood metric to evaluate the results and the complexity varies wildly with graph input size and constraints number.

These two aspects will keep coming up while looking for a solution (even a partial one).

It's unlikely that we'll be able to find a ready-made robust algorithm able to handle arbitrarily sized schemas right away, even removing the link-to-key constraint.

A more pragmatic approach would be to work step-wise, i.e.:

  1. establish thresholds (small, medium, large schemas) and gather sample schemas
  2. work towards making automatic layout of small/medium schemas mostly work right out of the box (experiment with and fine-tune some classic force directed/network flow algorithm)
  3. make fixing schemas by hand as painless as possible (right now it's a pretty frustrating experience)

This seems more or less the approach currently followed by all other similar applications.

And eventually some magic machine-learning solution will materialize, capturing all the aesthetic requirements :)

carlo-salinari avatar Dec 07 '23 13:12 carlo-salinari

This is a sample of an auto-generated erd graph with maintained link-to-key constraints (https://www.softwareideas.net/en/erd-auto-generator).

erd-auto-generator

  • layout is orthogonal
  • links route around tables
  • bends variance appear uniform
  • crossings are marked graphically
  • not much in the way of compaction

carlo-salinari avatar Dec 11 '23 22:12 carlo-salinari

Only javascript library I could find tackling erd diagrams decently: https://gojs.net/latest/samples/entityRelationship.html

image

Unfortunately, I don't think their license is compatible with pgAdmin's.

carlo-salinari avatar Dec 11 '23 22:12 carlo-salinari

Other people (eg. DataWharf) seem to be using maxGraph (basically mxGraph, but gets updates). They're under an Apache-style license; no idea about compatibility.

https://github.com/maxGraph/maxGraph

HTH,

wayland avatar Dec 12 '23 23:12 wayland

It would be very helpful to add a feature to manually move the nodes of the lines manually by clicking and dragging. That way it would be a lot easier to tidy up an auto generated ERD. The ability to manually insert and delete nodes on a line segment would also come in handy.

javinosearas avatar Feb 13 '24 09:02 javinosearas

This is an interesting example where the lines are made from column to column and everything looks quite great. It's DrawSQL, a commercial website. image

RieBi avatar Jul 24 '24 06:07 RieBi

It seems like orthogonal lines is the way

RieBi avatar Jul 24 '24 06:07 RieBi

@RieBi ERD tool lines works fine when building from scratch. The issue is with auto layout. I will go through all the suggestions and see how we can fix it.

adityatoshniwal avatar Jul 24 '24 06:07 adityatoshniwal

This is clearly a 'bug' not a 'feature' from end user perspective. Also this issue should get a better priority imo.

vishnupeas avatar Oct 28 '24 09:10 vishnupeas

This is clearly a 'bug' not a 'feature' from end user perspective. Also this issue should get a better priority imo.

Feel free to raise a PR if you have a solution. I've spend a lot of time in past, may be there is one available today.

adityatoshniwal avatar Oct 28 '24 09:10 adityatoshniwal

Point no.1 and 3 will be fixed with my PR here - https://github.com/pgadmin-org/pgadmin4/pull/8167. For point no. 2, I spent a lot of time to find a apt. path finding algorithm. I tried A-star but it becomes very very slow for large diagrams - and produces links with lot of turns. If anybody happens to know a good path finding lib then we can use that. Intention is not to get the best optimal path but to get a path with least turns without going below nodes.

adityatoshniwal avatar Nov 22 '24 10:11 adityatoshniwal

Point no. 1 and 2 has been fixed and verified in snapshot build.

For point no. 2 we will create a new issue.

pravesh-sharma avatar Dec 02 '24 05:12 pravesh-sharma

For point no. 2 we will create a new issue.

Opened https://github.com/pgadmin-org/pgadmin4/issues/8212

adityatoshniwal avatar Dec 02 '24 06:12 adityatoshniwal