Urgent.News

What's breaking now, across thousands of outlets.

Tech

I made ER diagrams with the fewest line crossings, and proved it

I was modelling the ER diagram for a new project, and it got messy quickly once I had to share it with other people. Lines crossed everywhere, and nobody could follow which table pointed where. Auto-layout tools place the boxes sensibly, but the ones I have used don't count how many relationship lines cross, so nothing stops the mess. So I built erlayout to do that one thing: lay out an ER…

The author created an ER diagram layout tool called erlayout that minimizes line crossings and can prove the result is optimal. The tool takes SQL DDL, DBML or JSON input and determines how to arrange the tables in columns and rows to minimize crossings. It then demonstrates that no other layout within its model could have fewer crossings.

The Sakila sample database, with 15 tables and 22 foreign keys, goes from 8 crossings in the standard layered layout to 2 crossings in the erlayout optimized layout, which is proven to be optimal. The tool works by modeling tables in vertical columns, with foreign keys crossing gaps between columns, and counting the number of inverted pairs of edges spanning each gap to calculate crossings.

An optimization pass further shortens the lines after the initial layout is found. For larger schemas, erlayout breaks the schema into groups of tables that reference each other often and solves each group separately, arranging the diagrams in a grid. The resulting drawing can be exported to draw.io, Excalidraw or Mermaid diagrams.

The author invites contributions to improve the tool, such as drawing self-referential foreign keys as loops, adding adapters for Laravel migrations, and improving lower bounds for dense schemas.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Markdown Is Not HTML, But It Was Born to Become It

Markdown Is Not HTML, But It Was Born to Become It Every README, every GitHub issue, every docs page you have ever written in Markdown ends up as HTML. That is not an accident.

  • Markdown converts cleanly to HTML
  • Created by John Gruber in 2004
  • GitHub Flavored Markdown adds tables, task lists, autolinks

Let your computer read your draft back to you

I can reread a paragraph five times and still miss the word I typed twice. My eyes know what I meant to write, so they fill in the gaps. My ears are much less forgiving.

  • Computer text-to-speech reveals draft errors
  • Convert Markdown to plain text for reading
  • Automate reading process for consistent edits

More from Saturday 31 October →