diff --git a/web/epiphany-graph-viewer/src/lib/EpiphanyGraphViewer.tsx b/web/epiphany-graph-viewer/src/lib/EpiphanyGraphViewer.tsx index 76d56da..1a205b2 100644 --- a/web/epiphany-graph-viewer/src/lib/EpiphanyGraphViewer.tsx +++ b/web/epiphany-graph-viewer/src/lib/EpiphanyGraphViewer.tsx @@ -44,7 +44,11 @@ export function EpiphanyGraphViewer({ layoutAlgorithms, sidebar, sidebarWidth = 330, + showSidebar = true, overlayPanels = false, + focusSelection = false, + expandedNode, + onExpandedNodeClick, onSelectionChange, onCodeRefSelect, }: EpiphanyGraphViewerProps) { @@ -219,6 +223,41 @@ export function EpiphanyGraphViewer({ const linkedNodes = selectedNode ? findLinkedNodes(selectedNode.id, activeGraphKey, state) : []; + const expandedNodeMatches = + Boolean(expandedNode) && + Boolean(selectedNode) && + expandedNode?.graphKey === activeGraphKey && + expandedNode.nodeId === selectedNode?.id; + const expandedNodeMetrics = + expandedNodeMatches && selectedNode && viewportSize.width > 0 && viewportSize.height > 0 + ? expandedNodeViewportMetrics(selectedNode, activeTransform, viewportSize.width, viewportSize.height) + : null; + + useEffect(() => { + if (!focusSelection || !selectedNode || viewportSize.width <= 0 || viewportSize.height <= 0) { + return; + } + + const center = nodeCenter(selectedNode); + const targetScale = clamp(transforms[activeGraphKey].scale, 0.72, 1.08); + setTransforms((current) => ({ + ...current, + [activeGraphKey]: { + x: viewportSize.width / 2 - center.x * targetScale, + y: viewportSize.height / 2 - center.y * targetScale, + scale: targetScale, + userMoved: true, + }, + })); + }, [ + activeGraphKey, + focusSelection, + selectedNode?.id, + selectedNode?.x, + selectedNode?.y, + viewportSize.height, + viewportSize.width, + ]); return (
= 176 && node.height >= 72; + const showLinkCount = node.linkCount > 0 && node.width >= 150 && node.height >= 86; + const titleX = badgeX + badgeRadius + 14; + const titleY = node.height < 76 ? node.height / 2 + 4 : 26; return ( - {node.status?.trim() && node.width >= 112 && node.height >= 48 && activeTransform.scale > 0.66 && ( + {showStatus && activeTransform.scale > 0.66 && ( - {node.status.toUpperCase()} + {statusText.toUpperCase()} )} - {node.linkCount > 0 && node.width >= 72 && node.height >= 50 && ( - + {showLinkCount && ( + {node.linkCount} @@ -603,8 +647,8 @@ export function EpiphanyGraphViewer({ = 92 && node.height >= 40 ? fadeBetween(activeTransform.scale, 0.42, 0.72) : 0} pointerEvents="none"> {renderTextLines( copyLayout.titleLines, - 44, - 26, + titleX, + titleY, 15, { fill: "#f8fbff", @@ -656,10 +700,39 @@ export function EpiphanyGraphViewer({ )} + {expandedNodeMatches && expandedNodeMetrics && expandedNode && ( +
+ {expandedNode.content} +
+ )} -
- + + )} ); } @@ -1292,6 +1366,37 @@ function fitGraphToViewport(layout: GraphLayout, width: number, height: number): }; } +function nodeCenter(node: PositionedNode) { + return { + x: node.x + node.width / 2, + y: node.y + node.height / 2, + }; +} + +function expandedNodeViewportMetrics( + node: PositionedNode, + transform: ViewTransform, + viewportWidth: number, + viewportHeight: number, +) { + const center = nodeCenter(node); + const screenCenter = { + x: transform.x + center.x * transform.scale, + y: transform.y + center.y * transform.scale, + }; + const width = Math.min(Math.max(viewportWidth * 0.72, 560), viewportWidth - 56); + const height = Math.min(Math.max(viewportHeight * 0.74, 420), viewportHeight - 136); + const left = clamp(screenCenter.x - width / 2, 24, Math.max(24, viewportWidth - width - 24)); + const top = clamp(screenCenter.y - height / 2, 108, Math.max(108, viewportHeight - height - 24)); + + return { + left, + top, + width, + height, + }; +} + function handleNativeWheel( event: WheelEvent, viewportElement: HTMLElement, @@ -1452,15 +1557,20 @@ function fadeBetween(value: number, start: number, end: number) { } function buildNodeCopyLayout(node: PositionedNode) { + const compactHeight = node.height < 76; + const reservesStatusLane = node.status?.trim() && node.width >= 176 && node.height >= 72; + const reservesLinkLane = node.linkCount > 0 && node.width >= 150 && node.height >= 86; + const titleLeftInset = node.height < 40 ? 32 : 46; + const titleRightInset = reservesStatusLane ? 92 : reservesLinkLane ? 48 : 18; const titleWidth = Math.max( - 108, - node.width - (node.status?.trim() ? 154 : 92), + 28, + node.width - titleLeftInset - titleRightInset, ); - const bodyWidth = Math.max(148, node.width - 34); + const bodyWidth = Math.max(80, node.width - 34); const titleLines = wrapTextToLines( node.title, estimateCharacterCapacity(titleWidth, 7.4), - 2, + compactHeight ? 1 : 2, ); const purposeLines = wrapTextToLines( node.purpose, diff --git a/web/epiphany-graph-viewer/src/lib/types.ts b/web/epiphany-graph-viewer/src/lib/types.ts index 15eaf37..83d877a 100644 --- a/web/epiphany-graph-viewer/src/lib/types.ts +++ b/web/epiphany-graph-viewer/src/lib/types.ts @@ -1,4 +1,4 @@ -import type { CSSProperties, ReactNode } from "react"; +import type { CSSProperties, MouseEventHandler, ReactNode } from "react"; export type GraphKey = "architecture" | "dataflow"; @@ -81,7 +81,17 @@ export interface EpiphanyGraphViewerProps { layoutAlgorithms?: EpiphanyGraphLayoutAlgorithms; sidebar?: ReactNode; sidebarWidth?: CSSProperties["width"]; + showSidebar?: boolean; overlayPanels?: boolean; + focusSelection?: boolean; + expandedNode?: { + graphKey: GraphKey; + nodeId: string; + content: ReactNode; + className?: string; + ariaLabel?: string; + }; + onExpandedNodeClick?: MouseEventHandler; onSelectionChange?: (selection: ViewerSelection | null) => void; onCodeRefSelect?: ( codeRef: EpiphanyCodeRef,