@@ -94,17 +94,13 @@ function Dot({ label, color }: { label?: ReactNode; color?: string }) {
9494
9595export type TreeGraphProps = {
9696 tree ?: TreeWorkerReturnType ;
97- onExit ?: ( ) => void ;
9897} & SharedGraphProps ;
9998
10099export type NodeType = { x : number ; y : number ; label : string ; size : number } ;
101100export type EdgeType = { label : string } ;
102101
103102export function TreeGraph ( props : TreeGraphProps ) {
104- const { trace, tree, layer : key , onExit } = props ;
105-
106- const acrylic = useAcrylic ( ) ;
107- const theme = useTheme ( ) ;
103+ const { trace, tree, layer : key } = props ;
108104
109105 const [ orientation , setOrientation ] =
110106 useState < keyof typeof orientationOptions > ( "vertical" ) ;
@@ -122,6 +118,29 @@ export function TreeGraph(props: TreeGraphProps) {
122118
123119 const isHighlightingEnabled = ! isEmpty ( highlightEdges ) ;
124120
121+ return (
122+ < >
123+ < TreeControls
124+ layer = { key }
125+ isHighlightingEnabled = { isHighlightingEnabled }
126+ setOrientation = { setOrientation }
127+ orientation = { orientation }
128+ />
129+ < FocusedView { ...props } />
130+ </ >
131+ ) ;
132+ }
133+
134+ export function FocusedView ( props : SharedGraphProps ) {
135+ const { trace, layer : key , onExit } = props ;
136+
137+ const acrylic = useAcrylic ( ) ;
138+ const theme = useTheme ( ) ;
139+
140+ const highlightEdges = useHighlighting ( key ) ;
141+
142+ const isHighlightingEnabled = ! isEmpty ( highlightEdges ) ;
143+
125144 const bg = getShade (
126145 highlightNodesOptions . find (
127146 ( highlight ) => highlight . type === highlightEdges ?. type ,
@@ -134,76 +153,68 @@ export function TreeGraph(props: TreeGraphProps) {
134153 const event = trace ?. events ?. [ highlightEdges ?. step ?? 0 ] ;
135154
136155 return (
137- < >
138- < TreeControls
139- layer = { key }
140- isHighlightingEnabled = { isHighlightingEnabled }
141- setOrientation = { setOrientation }
142- orientation = { orientation }
143- />
156+ < Stack
157+ sx = { {
158+ width : "100%" ,
159+ height : "100%" ,
160+ position : "absolute" ,
161+ top : 0 ,
162+ left : 0 ,
163+ pt : 6 ,
164+ pointerEvents : "none" ,
165+ } }
166+ >
144167 < Stack
145168 sx = { {
146169 width : "100%" ,
147170 height : "100%" ,
148- position : "absolute" ,
149- top : 0 ,
150- left : 0 ,
151- pt : 6 ,
152- pointerEvents : "none" ,
171+ border : isHighlightingEnabled ? `2px solid ${ bg } ` : "none" ,
172+ // The top bar has a 0.5px border, so the top border of the graph needs to be 0.5 pixels thicker
173+ borderTopWidth : "2.5px" ,
174+ transition : ( t ) => t . transitions . create ( "box-shadow" ) ,
153175 } }
154176 >
155- < Stack
156- sx = { {
157- width : "100%" ,
158- height : "100%" ,
159- border : isHighlightingEnabled ? `2px solid ${ bg } ` : "none" ,
160- // The top bar has a 0.5px border, so the top border of the graph needs to be 0.5 pixels thicker
161- borderTopWidth : "2.5px" ,
162- transition : ( t ) => t . transitions . create ( "box-shadow" ) ,
163- } }
164- >
165- { isHighlightingEnabled && (
166- < Scroll x style = { { height : theme . spacing ( 5 ) } } >
167- < Box
177+ { isHighlightingEnabled && (
178+ < Scroll x style = { { height : theme . spacing ( 5 ) } } >
179+ < Box
180+ sx = { {
181+ ...pick ( acrylic , "backdropFilter" ) ,
182+ transition : ( t ) => t . transitions . create ( "background-color" ) ,
183+ pointerEvents : "all" ,
184+ alignItems : "center" ,
185+ p : 2 ,
186+ height : "100%" ,
187+ bgcolor : alpha ( bg , 0.05 ) || "info.main" ,
188+ display : "flex" ,
189+ justifyContent : "space-between" ,
190+ minWidth : "max-content" ,
191+ gap : 2 ,
192+ } }
193+ >
194+ < Typography variant = "overline" >
195+ { startCase ( highlightEdges ?. type ) } { " " }
196+ < Box sx = { { opacity : 0.7 } } component = "span" >
197+ < Dot color = { getColorHex ( event ?. type ) } /> { " " }
198+ { startCase ( event ?. type ) } { event ?. id }
199+ { ", " }
200+ Step { highlightEdges ?. step } { " " }
201+ </ Box >
202+ </ Typography >
203+ < Button
204+ onClick = { onExit }
205+ variant = "outlined"
168206 sx = { {
169- ...pick ( acrylic , "backdropFilter" ) ,
170- transition : ( t ) => t . transitions . create ( "background-color" ) ,
171- pointerEvents : "all" ,
172- alignItems : "center" ,
173- p : 2 ,
174- height : "100%" ,
175- bgcolor : alpha ( bg , 0.05 ) || "info.main" ,
176- display : "flex" ,
177- justifyContent : "space-between" ,
178- minWidth : "max-content" ,
179- gap : 2 ,
207+ mr : - 1 ,
208+ height : theme . spacing ( 4 ) ,
180209 } }
181210 >
182- < Typography variant = "overline" >
183- { startCase ( highlightEdges ?. type ) } { " " }
184- < Box sx = { { opacity : 0.7 } } component = "span" >
185- < Dot color = { getColorHex ( event ?. type ) } /> { " " }
186- { startCase ( event ?. type ) } { event ?. id }
187- { ", " }
188- Step { highlightEdges ?. step } { " " }
189- </ Box >
190- </ Typography >
191- < Button
192- onClick = { onExit }
193- variant = "outlined"
194- sx = { {
195- mr : - 1 ,
196- height : theme . spacing ( 4 ) ,
197- } }
198- >
199- Exit focused view
200- </ Button >
201- </ Box >
202- </ Scroll >
203- ) }
204- </ Stack >
211+ Exit focused view
212+ </ Button >
213+ </ Box >
214+ </ Scroll >
215+ ) }
205216 </ Stack >
206- </ >
217+ </ Stack >
207218 ) ;
208219}
209220
0 commit comments