PlotDirector/Docs/Relationships/MainWorkspaceEnhancement-20261126.md

7.9 KiB

Main Relationships enhancement — investigation and isolation contract

Scope: main RelationshipMap/Index only; Development deployment only. Context and Character Details are protected.

The main view uses its own _GraphScripts Cytoscape renderer and relationship-workspace.js. No other view includes that graph partial. Context and Character Details use their existing SVG components (context-relationship-layout.js and their own renderers). Those scripts, views, styles, controllers and default settings will remain unchanged. Before/after comparisons use the same synthetic data, focus, theme, scene and dimensions, plus existing protected interaction regressions.

Reuse: canonical RelationshipMap service/state resolver and editor; author-reference family definitions from ContextRelationshipLenses.Family; unchanged family layout algorithm via an explicit main-page include; canonical CharacterAttributes Directory/Assign/Undo endpoints and shared definitions; application context menus, toast actions, Scene Explorer and workspace dividers. New behaviour and storage stay under #rwApp / main-workspace scripts. No new graph library, AI calls, database store or shared rendering default.

Existing main state: local v1 project/book layout, manual extra/removed nodes, focus/zoom/pan, 250ms debounce; Cytoscape circle/COSE; three importance palettes, right Details, legend, Scene Explorer, Map/List, PWA ribbon and maximise. Current gaps include Ctrl-wheel centre zoom, single-network layouts, hidden-but-not-removed membership, no pin/layout undo/presets, and no importance assignment between groups. Existing two-sided workspace dividers are already available and will be reused with author/project scoping and no scene-resolution calls on resize.

Plan/checkpoints: A baseline/isolation; B scoped interaction/menus; C membership/pins/layout undo; D shared importance assignment; E clustered/radial/family/importance layouts; F routing; G presets/history stability; H persistence/dividers; I build/full regression, rendered browser/PWA, all themes, protected comparisons, performance, documentation and Development smoke/deployment. Do not deploy an incomplete checkpoint. Preserve unrelated investigation files and existing author data.

Acceptance evidence and measured results will be appended after implementation. The user attachment remains the authoritative checklist, including every section 21 criterion and requested screenshots. Any unverified or incomplete requirement must be labelled explicitly in the final matrix.

Implemented boundary and architecture

The main page explicitly loads relationship-main.js, relationship-main-layout.js and one dedicated calculation worker. _GraphScripts remains main-only. No Context or Character Details renderer, layout, stylesheet, controller, focus contract or default has changed. The only shared-surface change is an opt-in author/project/book preference-key suffix; unscoped callers retain their original key and behaviour.

The main adapter retains the existing canonical editor, historical State resolver, Scene Explorer, Details, full-width shell, palette responsive drawer, Map/List and maximise. It diffs edges and updates affected cast records rather than remounting Cytoscape. Family-only/reference layouts lazily retrieve an explicitly authorised author-reference projection from the existing relationship repository. Family classification and deterministic family geometry reuse the existing Context family predicate/algorithm without changing them. History ordering reuses StoryStateService.OrderScenes. The family projection is a read model, not another relationship store.

Importance uses CharacterQuickAttributes presentation definitions and the existing Directory/Assign/Undo endpoints, row versions, antiforgery, project permissions, protected undo tokens and shared actionable toast service. It performs no optimistic reclassification. Equal values are client/server no-ops. Relationship saves publish lightweight existing ContextWorkspaceNotifications; receiving views continue authenticated data retrieval. The main page subscribes once to the existing presence connection, coalesces hints and never constructs a SignalR connection. No new SQL or migrations are needed. No AI or author-data classification is involved.

Geometry and interaction

Cluster placement uses recorded connected components, deterministic greedy modularity communities inside each component, bounded local/community force placement and actual rectangular collision clearance. Isolated members are compactly parked. Radial uses breadth-first recorded relationship distance, a chosen centre and bounded depth. Importance uses wrapped tiers with community/degree/barycentre ordering. Family uses existing canonical parent/child/partner/sibling roles and shared junction routes, including adoption/step styles; it never infers a partnership from shared children. Circle remains available. Pinned positions are exact; conflicting pins warn rather than moving an author's pin.

Layout and route batches run in a single main-page worker with request generations; stale results are discarded. If unavailable, the same pure engine supplies the fallback and route work yields in batches. Node movement recalculates incident routes while dragging and a complete batch on release. Zoom updates labels without route recalculation or network calls. Straight links have distinct boundary endpoints; curves use bounded obstacle-aware candidates; orthogonal links use doglegs and bounded obstacle detours, including parallel lane offsets. Dense labels concentrate on selection/hover/focus with an explicit Show all option. Crossings remain possible in dense networks.

Pointer-anchored ordinary wheel zoom and captured middle-button pan are confined to the main canvas. Node selection preserves viewport position; explicit palette/centre actions centre it. Native pointer context menus reuse the shared service via its existing queued registration pattern; geometry APIs are selected by connector style. Shift+F10/Context Menu key, Diagram menu and selected Character actions provide keyboard/touch alternatives. Delete is guarded to a canvas character selection, leaving text editing alone. Double-click uses the existing Character Details route.

Membership and local preferences

Version 2 preferences are keyed by author/project/book and migrate existing main v1 positions, removed/extra nodes, focus and viewport. They contain membership, positions, pins, preset, arrangement, connector, depth, label preference, Map/List, palette collapse and zoom/pan. The custom snapshot survives a preset excursion. A separate bounded diagram Undo stack restores diagram state; importance Undo continues server-side concurrency checks. Clear/remove are purely diagram operations, never archive/delete operations. Two independent divider widths use the existing workspace-surface storage with the same opt-in scope. Preferences are local browser data and do not synchronise across devices; no canonical records are used as a preference store.

Family pin choices are explicit Keep/Rearrange/Cancel. After a manual family-card move, independent orthogonal routing is used until the next explicit family arrangement rebuilds shared junction paths. General routing is best effort, not a guarantee of a planar graph. Very large arrangements begin at readable zoom; Fit provides an overview and pointer zoom/pan exposes individual regions. Forced conflicting pins are the only permitted card-overlap exception.

Verification and delivery

See the accompanying acceptance report for the per-criterion matrix, exact before/after protected comparisons, measured timings, screenshots, commit IDs and Development receipt. Baseline comparisons were captured before implementation. Synthetic fixtures exercise 20, 75, 100 and 200 characters, sparse/dense networks, connected subgroups, isolated members and canonical multi-generation family definitions. Existing author records are not demonstration fixtures. Production is outside this release.