Repository navigation
refactor: extract graph layout from svg renderer - #26
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR extracts deterministic node measurement and placement from the database SVG renderer into a reusable @orbit/family-graph layout module, then updates the renderer to consume that shared layout output while keeping relationship routing renderer-local (per issue #8’s scope).
Changes:
- Added
layoutGraph()and associatedGraphLayout*contracts in@orbit/family-graph, with focused layout tests. - Migrated
@orbit/renderer-svgto build aGraphModelviadatabaseToGraphModel()and render usinglayoutGraph()results. - Expanded renderer regression assertions and committed a review SVG artifact.
Reviewed changes
Copilot reviewed 7 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/renderer.test.ts | Updates renderer regression fixture and adds assertions for emitted IDs and XML header. |
| tests/graph-layout.test.ts | Adds deterministic/non-overlapping layout tests and minimal-bounds coverage for layoutGraph(). |
| pnpm-lock.yaml | Adds workspace deps needed by @orbit/renderer-svg. |
| packages/renderer-svg/tsconfig.json | Adds project references to family-graph and validator. |
| packages/renderer-svg/src/renderer.ts | Replaces renderer-owned layout with databaseToGraphModel() + layoutGraph() consumption. |
| packages/renderer-svg/package.json | Adds dependencies on @orbit/family-graph and @orbit/validator. |
| packages/family-graph/src/layout.ts | Introduces shared graph layout contracts + deterministic placement implementation. |
| packages/family-graph/src/index.ts | Exports the new layout API from @orbit/family-graph. |
| artifacts/review/issue-8-customer-database.svg | Adds the intentional review SVG artifact generated by the CLI render path. |
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
6 tasks
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
Extract reusable Graph family node measurement and deterministic placement from the Database Schema SVG renderer. The existing renderer now converts the validated database model through
databaseToGraphModel(), callslayoutGraph(), and draws from the shared layout result.Closes #8
Architecture
Before:
ValidatedDatabaseModel → Database-specific renderer layout → SVGAfter:
ValidatedDatabaseModel → databaseToGraphModel() → layoutGraph() → existing SVG drawing/routing → SVGFiles and packages changed
packages/family-graph/src/layout.ts.@orbit/family-graph.@orbit/renderer-svgto depend on@orbit/family-graphand@orbit/validator.artifacts/review/issue-8-customer-database.svg.Layout contracts and algorithm
Added:
GraphLayoutGraphLayoutBoundsGraphLayoutNodeGraphLayoutRowGraphLayoutPortGraphLayoutOptionslayoutGraph(model, options)The algorithm is deterministic and stateless. It measures node width from titles, compartment titles, rows, and badges with a 300px compatibility minimum; calculates header/documentation/row heights; places primary nodes in a configurable fixed-column grid; optionally places secondary node kinds in a stable secondary column; exposes absolute row and port locations; and calculates total bounds.
The Database renderer identifies
database.enumas a secondary node kind to preserve the existing table-grid/enum placement.Renderer migration
renderDatabaseSvg(model)remains the public API. It now:databaseToGraphModel(model).layoutGraph(graph, { secondaryNodeKinds: ["database.enum"] }).GraphLayoutNodeandGraphLayoutRowcoordinates.Relationship routing itself remains renderer-local and unchanged in scope.
Removed obsolete code
Removed the renderer-private
Box/BoxRowcompatibility model,layout(),tableBox(),enumBox(), table/enum placement loops, duplicate width/height calculations, and duplicate layout constants. No second Database Schema layout path remains.Explicit non-goals
Validation
Passed:
corepack pnpm installcorepack pnpm buildcorepack pnpm typecheckcorepack pnpm test(7 files, 16 tests)corepack pnpm lintcorepack pnpm checkcorepack pnpm orbit validate docs/examples/customer-database.orbitcorepack pnpm orbit parse docs/examples/customer-database.orbit --jsoncorepack pnpm orbit render docs/examples/customer-database.orbit --output artifacts/review/issue-8-customer-database.svgcorepack pnpm format:checkstill reports pre-existing formatting issues indocs/architecture.mdanddocs/implementation-families.md; this PR does not modify those files.Review artifact
artifacts/review/issue-8-customer-database.svgThe committed review SVG was generated from the actual branch implementation through the CLI render path. It is valid, non-empty, and 3,280 bytes.
Visual comparison
Compared against a fresh render from
devbefore the extraction:780×434780×434users,orders,order_status)Copilot review
Copilot raised one valid edge case: secondary-only graphs with document documentation did not apply the document header offset. Commit
244c531applies the offset, adds a regression test, reruns all validation, and regenerates the unchanged review artifact. The thread was replied to and resolved; no unresolved conversations remain.Dead/obsolete code audit
Reviewed the complete diff and searched for the old layout helper names and geometry constants. No obsolete renderer layout implementation, unused imports, temporary debug code, or accidental generated output remains. The only committed generated file is the intentional review SVG.