@@ -32,7 +32,7 @@ async function render(nodes, edges) {
3232 g . setDefaultEdgeLabel ( function ( ) { return { } ; } ) ;
3333
3434 for ( const node of nodes ) {
35- g . setNode ( node . id , { label : node . label , width : 1 , height : 1 , hasError : node . hasError , border : node . border , truncateIfNeeded : node . truncateIfNeeded , longLabel : originalNodes . find ( n => n . id === node . id ) . label , statistics : node . Statistics } ) ;
35+ g . setNode ( node . id , { label : node . label , width : 1 , height : 1 , hasError : node . hasError , border : node . border , truncateIfNeeded : node . truncateIfNeeded , longLabel : originalNodes . find ( n => n . id === node . id ) . label , statistics : node . Statistics , type : node . Type } ) ;
3636 }
3737
3838 for ( const edge of edges ) {
@@ -47,7 +47,7 @@ async function render(nodes, edges) {
4747 maxY = - Infinity ;
4848 longestLabel = 0 ;
4949 highestY = 0 ;
50- rows = { } ;
50+ const rows = { } ;
5151 for ( const node of g . nodes ( ) ) {
5252 const { x, y } = g . node ( node ) ;
5353 minX = Math . min ( minX , x ) ;
@@ -56,9 +56,9 @@ async function render(nodes, edges) {
5656 maxY = Math . max ( maxY , y ) ;
5757 longestLabel = Math . max ( longestLabel , g . node ( node ) . label . length ) ;
5858 highestY = Math . max ( highestY , y ) ;
59- rows [ y ] = 1 ;
59+ rows [ y ] = minX ;
6060 }
61-
61+
6262 width = Math . max ( maxX - minX , 1 ) ;
6363 height = Math . max ( maxY - minY , 1 ) ;
6464 screenWidth = process . stdout . columns - longestLabel ;
@@ -77,9 +77,9 @@ async function render(nodes, edges) {
7777 for ( let row = 0 ; row < screenHeight ; row ++ ) {
7878 const filteredNodes = g . nodes ( ) . filter ( p => g . node ( p ) . y === row ) ;
7979 const totalLabelLength = filteredNodes . reduce ( ( acc , p ) => acc + g . node ( p ) . label . length , 0 ) ;
80- const threshold = screenWidth - 2 * filteredNodes . length - 20 ;
80+ const threshold = screenWidth - 2 * filteredNodes . length - 130 ;
8181 if ( totalLabelLength > threshold ) {
82- const div = threshold / totalLabelLength ;
82+ const div = threshold / totalLabelLength / 1.75 ;
8383 for ( const node of filteredNodes ) {
8484 if ( g . node ( node ) . truncateIfNeeded ) {
8585 nodes . find ( p => p . id == node ) . label = g . node ( node ) . label . substring ( 0 , Math . floor ( g . node ( node ) . label . length * div ) ) ;
@@ -228,13 +228,17 @@ function addItem(node) {
228228}
229229function addBoxItem ( node , scrollIndex ) {
230230 const longLabel = node . longLabel ;
231- if ( longLabel . length > node . label . length ) {
232- let subLabel = longLabel . substring ( scrollIndex % longLabel . length , scrollIndex % longLabel . length + node . label . length ) ;
233- subLabel += "|" + longLabel . substring ( 0 , node . label . length - subLabel . length ) ;
231+ const length = getBoxWidth ( node ) ;
232+ if ( node . type !== "client" ) {
233+ writeAt ( node . x , node . y - 1 , node . type . padEnd ( length , " " ) , node . hasError ) ;
234+ }
235+ if ( longLabel . length > length ) {
236+ let subLabel = longLabel . substring ( scrollIndex % longLabel . length , scrollIndex % longLabel . length + length ) ;
237+ subLabel += "|" + longLabel . substring ( 0 , length - subLabel . length ) + " " ;
234238
235239 writeAt ( node . x , node . y , subLabel , node . hasError ) ;
236240 } else {
237- writeAt ( node . x , node . y , node . label , node . hasError ) ;
241+ writeAt ( node . x , node . y , longLabel . padEnd ( length , " " ) , node . hasError ) ;
238242 }
239243 if ( node . statistics ) {
240244 const str = Math . round ( node . statistics . TotalResponseTime * 1000 ) + "ms" ;
@@ -247,21 +251,27 @@ function addBoxItem(node, scrollIndex) {
247251 bottomBorder ( node ) ;
248252 }
249253}
254+ function getBoxWidth ( node ) {
255+ return Math . max ( node . type . length , node . label . length ) ;
256+ }
257+
250258function topBorder ( node ) {
251- writeAt ( node . x - 1 , node . y - 1 , "┏" . padEnd ( node . label . length + 1 , "━" ) + "┓" ) ;
259+ writeAt ( node . x - 1 , node . y - 2 , "┏" . padEnd ( getBoxWidth ( node ) + 1 , "━" ) + "┓" ) ;
252260}
253261function bottomBorder ( node ) {
254262 const yOffset = node . statistics ? 2 : 1 ;
255- writeAt ( node . x - 1 , node . y + yOffset , "┗" . padEnd ( node . label . length + 1 , "━" ) + "┛" ) ;
263+ writeAt ( node . x - 1 , node . y + yOffset , "┗" . padEnd ( getBoxWidth ( node ) + 1 , "━" ) + "┛" ) ;
256264}
257265function leftBorder ( node ) {
266+ writeAt ( node . x - 1 , node . y - 1 , "┃" ) ;
258267 writeAt ( node . x - 1 , node . y , "┃" ) ;
259268 if ( node . statistics ) {
260269 writeAt ( node . x - 1 , node . y + 1 , "┃" ) ;
261270 }
262271}
263272function rightBorder ( node ) {
264- const length = node . label . length ;
273+ const length = getBoxWidth ( node ) ;
274+ writeAt ( node . x + length , node . y - 1 , "┃" ) ;
265275 writeAt ( node . x + length , node . y , "┃" ) ;
266276 if ( node . statistics ) {
267277 writeAt ( node . x + length , node . y + 1 , "┃" ) ;
0 commit comments