Repository navigation
feat: ERD diagram support (erDiagram syntax, crow's foot notation) - #50
Merged
Merged
Conversation
Adds first-class entity-relationship diagram rendering via Mermaid- compatible erDiagram syntax. Entities render as table boxes with typed attribute rows and PK/FK/UK badges; relationships use crow's foot notation (exactly-one, zero-or-one, one-or-many, zero-or-many) with solid (identifying) or dashed (non-identifying) lines. New modules: - src/parser/erd.ts — line-by-line erDiagram parser - src/layout/erd.ts — dagre-based entity layout with attribute-aware sizing - src/renderer/erd.ts — DOM SVG renderer (entity boxes + crow's foot) - src/renderer/erd-string.ts — headless string renderer for Python/rehype Public API additions: parseERD, computeERDLayout, renderERDSVG, renderERDString, ERDLayoutResult, ERDCardinality, and related types. toLayout() now returns an optional erdLayout field for ERD inputs. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Move the zero-or-many circle from MARK_DIST1 (12) to MARK_DIST3 (36) so it sits beyond the crow-foot base instead of threading through the center prong. Switch attribute name column from percentage-based (w*0.44) to fixed offset (56px) and update layout width estimation per-column, giving consistent spacing between name and PK/FK/UK badges regardless of entity width. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replaces Comic Sans MS fallback with Bradley Hand / Segoe Print. Increases nodePadding x:30→46 to absorb Comic Neue's wider per-char width vs the 0.62 layout estimator, preventing label overflow. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Name-column start was fixed at 56px regardless of type text width. Now computed dynamically as max(NAME_COL_X, widest_type_estimate+14) in both layout (so the box widens) and renderers (so name text shifts right to match). Fixes overlap when types like varchar(255) are used. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Removes 8 duplicated constants (HEADER_HEIGHT, ATTR_ROW_HEIGHT, etc.) and normalize() that were copy-pasted verbatim across erd.ts and erd-string.ts. Also removes dead uid()/_nextId code from erd.ts. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
REL_TYPE used + quantifier, allowing mixed/repeated delimiters like --.. to parse silently with the wrong identifying flag. Changed to exact match (-- or ..) only. Multi-key priority comment claimed PK > FK > UK but k1 ?? k2 just took the first listed key. Now resolved correctly via find(). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…eparately
dagre.graphlib.Graph() is not a multigraph by default, so multiple
relationships between the same entity pair collapsed to one edge and
rendered as overlapping identical lines. Now uses { multigraph: true }
with per-relationship index as edge name, and for-loop with push
instead of .map() to preserve the index for edge retrieval.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… placeholder Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
erDiagramas a supported diagram type (previously listed as unsupported)type name PK), cardinality markers (||,|o,|{,o{), relationship labels,%%commentsrenderERDSVG) and headless string renderer (renderERDString) implemented — works with Python package and rehype pluginNew files
src/parser/erd.tssrc/layout/erd.tssrc/renderer/erd.tssrc/renderer/erd-string.tstests/parser/erd.test.tsAPI changes
toLayout()return type gains an optionalerdLayout?: ERDLayoutResultfield (populated for ERD inputs;layoutstays empty)parseERD,computeERDLayout,renderERDSVG,renderERDString, and all ERD types (ERDAST,ERDEntity,ERDRelationship,ERDAttribute,ERDCardinality,ERDLayoutResult,ERDLayoutEntity,ERDLayoutRelationship)DiagramASTupdated toFlowchartAST | ERDAST | UnsupportedDiagramASTTest plan
npm run test:run— 157 tests, all passnpm run lint— zero type errorsplayground.htmland paste an erDiagram to verify visual rendering (entity boxes, attribute rows, crow's foot marks, relationship labels, zoom/pan)||,|o,|{,o{🤖 Generated with Claude Code