Skip to content

refactor(erd): ErdViewport and ErdCanvas out of _ErdViewState, saved-view rules into the controller (#1690) - #1724

Merged
ZhuchkaTriplesix merged 2 commits into
devfrom
refactor/erd-canvas
Oct 18, 2026
Merged

ZhuchkaTriplesix merged 2 commits into
devfrom
refactor/erd-canvas

Conversation

@ZhuchkaTriplesix

Copy link
Copy Markdown
Member

Refs #1690 (second PR: the canvas)

erd_view.dart: 1482 -> 1285 lines (1844 before #1723). Behaviour and look unchanged.

  • ErdViewport (erd_viewport.dart): zoom and pan with the TransformationController, the viewport box key, the zoom floor, and the maths: zoomTo about a point, zoomBy, fit (returns whether the floor moved), centreOn, centre, toCanvas / toScreen. It replaces _scale, _viewportSize, _setScale, _viewCentre and the matrix code in the view.
  • ErdCanvas (widgets/erd_canvas.dart): the shortcuts and focus, the InteractiveViewer over the sheet, and the layers in order (hover layer, group frames, edges, cards, notes), then the edge label, the search panel and the zoom controls in screen space. The view builds the layers and hands them in.
  • Controller: snapshot, capture, toStore, stateOfView and addViewFromCurrent hold the rules of saving and switching views (which layout goes to the active view or to All tables, which tables a view keeps, that a new view from All tables leaves it showing every table); the view only supplies positions and viewport.

Tests: erd_viewport_test.dart (zoom about a point keeps it still, clamping to the floor and maximum, conversions, fit without enlarging, fit of a diagram bigger than the floor, centring), six more controller tests for saving and views. The 140 existing ERD tests pass unchanged, and so do workspace, core/erd and e2e (663 locally). Bench: erd_open_200 build p90 19.1 ms, erd_hover 0.1 ms, erd_drag 0.2 ms.

Where the issue's ~900 lines stands: not reached. What is left in _ErdViewState is the glue that needs the layout, the schema and the viewport together (loading, routing and card drag, group and note drag, the export source for ErdExporter, the dialogs). Splitting it further would mean one more object that owns the layout and the routes; I'd rather leave that decision to you than move it for the number. The issue stays open for that.

@github-actions github-actions Bot added the enhancement New feature or request label Oct 18, 2026
@ZhuchkaTriplesix
ZhuchkaTriplesix merged commit 4eb96f5 into dev Oct 18, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant