@@ -35,9 +35,9 @@ interface MappedMessage {
3535 nodeName: string ;
3636 };
3737 timeSent: string ;
38- level? : number ;
39- width? : number ;
40- XPos? : number ;
38+ level: number ;
39+ width: number ;
40+ XPos: number ;
4141}
4242
4343const nodeSpacingX = 300 ;
@@ -84,6 +84,9 @@ function mapMessage(message: Message): MappedMessage {
8484 type ,
8585 isError: message .status !== MessageStatus .Successful && message .status !== MessageStatus .ResolvedSuccessfully ,
8686 sagaName ,
87+ level: 0 ,
88+ width: 0 ,
89+ XPos: 0 ,
8790 link: {
8891 name: ` Link ${message .id } ` ,
8992 nodeName: message .id ,
@@ -92,12 +95,12 @@ function mapMessage(message: Message): MappedMessage {
9295 };
9396}
9497
95- function constructNodes(mappedMessages : MappedMessage []): Node [] {
98+ function constructNodes(mappedMessages : MappedMessage []): Node < MappedMessage > [] {
9699 return (
97100 mappedMessages
98101 // group by level
99102 .reduce ((groups : MappedMessage [][], message : MappedMessage ) => {
100- groups [message .level ! ] = [... (groups [message .level ! ] ?? []), message ];
103+ groups [message .level ] = [... (groups [message .level ] ?? []), message ];
101104 return groups ;
102105 }, [])
103106 // ensure each level has their items in the same "grouped" order as the level above
@@ -118,9 +121,9 @@ function constructNodes(mappedMessages: MappedMessage[]): Node[] {
118121 const parentMessage = previousLevel ?.find ((plMessage ) => message .parentId === plMessage .messageId && message .parentEndpoint === plMessage .receivingEndpoint .name ) ?? null ;
119122 // if the current parent node is the same as the previous parent node, then the current position needs to be to the right of siblings
120123 const currentParentWidth = previousParent === parentMessage ? currentWidth : 0 ;
121- const startX = parentMessage == null ? 0 : parentMessage .XPos ! - parentMessage .width ! / 2 ;
124+ const startX = parentMessage == null ? 0 : parentMessage .XPos - parentMessage .width / 2 ;
122125 // store the position of the node against the message, so child nodes can use it to determine their start position
123- message .XPos = startX + (currentParentWidth + message .width ! / 2 );
126+ message .XPos = startX + (currentParentWidth + message .width / 2 );
124127 return {
125128 result: [
126129 ... result ,
@@ -129,10 +132,10 @@ function constructNodes(mappedMessages: MappedMessage[]): Node[] {
129132 type: " message" ,
130133 data: message ,
131134 label: message .nodeName ,
132- position: { x: message .XPos * nodeSpacingX , y: message .level ! * nodeSpacingY },
135+ position: { x: message .XPos * nodeSpacingX , y: message .level * nodeSpacingY },
133136 },
134137 ],
135- currentWidth: currentParentWidth + message .width ! ,
138+ currentWidth: currentParentWidth + message .width ,
136139 previousParent: parentMessage ,
137140 };
138141 },
@@ -170,12 +173,17 @@ onMounted(async () => {
170173 message .width =
171174 children .length === 0
172175 ? 1 // leaf node
173- : children .map ((child ) => (child .width == null ? assignDescendantLevelsAndWidth (child , level + 1 ) : child )).reduce ((sum , { width }) => sum + width ! , 0 );
176+ : children .map ((child ) => (child .width === 0 ? assignDescendantLevelsAndWidth (child , level + 1 ) : child )).reduce ((sum , { width }) => sum + width , 0 );
174177 return message ;
175178 };
176- for (const root of mappedMessages .filter ((message ) => ! message .parentId )) assignDescendantLevelsAndWidth (root );
179+ for (const root of mappedMessages .filter ((message ) => ! message .parentId )) {
180+ assignDescendantLevelsAndWidth (root );
181+ }
182+
183+ const nodes = constructNodes (mappedMessages );
184+ const edges = constructEdges (nodes .map ((n ) => n .data as MappedMessage ));
177185
178- elements .value = [... constructNodes ( mappedMessages ) , ... constructEdges ( mappedMessages ) ];
186+ elements .value = [... nodes , ... edges ];
179187});
180188
181189function typeIcon(type : MessageType ) {
@@ -196,16 +204,17 @@ function toggleAddress() {
196204}
197205
198206const blackColor = hexToCSSFilter (" #000000" ).filter ;
207+ const greenColor = hexToCSSFilter (" #00c468" ).filter ;
199208 </script >
200209
201210<template >
202211 <div v-if =" store.conversationData.failed_to_load" class =" alert alert-info" >FlowDiagram data is unavailable.</div >
203212 <LoadingSpinner v-else-if =" store.conversationData.loading" />
204213 <div v-else id =" tree-container" >
205- <VueFlow v-model =" elements" :min-zoom =" 0.1" :fit-view-on-init =" true" >
214+ <VueFlow v-model =" elements" :min-zoom =" 0.1" :fit-view-on-init =" true" :only-render-visible-elements = " true " >
206215 <Controls position =" top-left" class =" controls" >
207- <ControlButton v-tippy =" `Show endpoints`" @click =" toggleAddress" >
208- <i class =" fa pa-flow-endpoint" :style =" { filter: blackColor }" ></i >
216+ <ControlButton v-tippy =" showAddress ? `Hide endpoints` : `Show endpoints`" @click =" toggleAddress" >
217+ <i class =" fa pa-flow-endpoint" :style =" { filter: showAddress ? greenColor : blackColor }" ></i >
209218 </ControlButton >
210219 </Controls >
211220 <template #node-message =" { data }: { data: MappedMessage } " >
0 commit comments