@@ -13,6 +13,10 @@ class StackGraph {
1313 static distx = 15 ;
1414 static disty = 15 ;
1515
16+ static arrow_stem_w = 2 ;
17+ static arrow_head_w = 16 ;
18+ static arrow_head_h = 8 ;
19+
1620 constructor ( container , graph , paths , metadata ) {
1721 this . metadata = metadata ;
1822
@@ -280,27 +284,27 @@ class StackGraph {
280284 this . render_scope ( g ) ;
281285 break ;
282286 case "pop_symbol" :
283- this . render_symbol_node ( g , "↑" + node . symbol ) ;
287+ this . render_symbol_node ( g , node . symbol , null , "pop" ) ;
284288 if ( node . is_definition ) {
285289 g . classed ( 'definition' , true ) ;
286290 }
287291 break ;
288292 case "pop_scoped_symbol" :
289293 let pop_scope = { class : "pop_scope" } ;
290- this . render_symbol_node ( g , "↑" + node . symbol , pop_scope ) ;
294+ this . render_symbol_node ( g , node . symbol , pop_scope , "pop" ) ;
291295 if ( node . is_definition ) {
292296 g . classed ( 'definition' , true ) ;
293297 }
294298 break ;
295299 case "push_symbol" :
296- this . render_symbol_node ( g , "↓" + node . symbol ) ;
300+ this . render_symbol_node ( g , node . symbol , null , "push" ) ;
297301 if ( node . is_reference ) {
298302 g . classed ( 'reference' , true ) ;
299303 }
300304 break ;
301305 case "push_scoped_symbol" :
302306 let push_scope = { class : "push_scope" } ;
303- this . render_symbol_node ( g , "↓" + node . symbol , push_scope ) ;
307+ this . render_symbol_node ( g , node . symbol , push_scope , "push" ) ;
304308 if ( node . is_reference ) {
305309 g . classed ( 'reference' , true ) ;
306310 }
@@ -331,12 +335,11 @@ class StackGraph {
331335 break ;
332336 }
333337 }
334-
335- render_symbol_node ( g , text , scope ) {
338+ render_symbol_node ( g , text , scope , shape ) {
336339 let content = g . append ( "g" ) ;
337340 content . append ( 'text' ) . text ( text ) ;
338341 let text_bbox = content . node ( ) . getBBox ( ) ;
339- if ( scope !== undefined ) {
342+ if ( scope !== undefined && scope !== null ) {
340343 content . append ( "circle" )
341344 . attr ( "class" , scope . class )
342345 . attr ( "transform" , `translate(${ text_bbox . width + StackGraph . margin } , ${ 6 - text_bbox . height / 2 } )` ) ;
@@ -345,18 +348,71 @@ class StackGraph {
345348 . attr ( "transform" , `translate(${ text_bbox . width + StackGraph . margin } , ${ 6 - text_bbox . height / 2 } )` ) ;
346349 }
347350 let bbox = content . node ( ) . getBBox ( ) ;
348- g . append ( 'rect' ) . lower ( )
351+ let l = bbox . x - StackGraph . margin ,
352+ r = bbox . x + bbox . width + StackGraph . margin ,
353+ t = bbox . y - StackGraph . margin ,
354+ b = bbox . y + bbox . height + StackGraph . margin ;
355+ var box_points ;
356+ var arrow_points = null ;
357+ switch ( shape ) {
358+ case "pop" :
359+ box_points = `
360+ ${ l } ,${ t }
361+ ${ r } ,${ t }
362+ ${ r } ,${ b }
363+ ${ l - StackGraph . arrow_stem_w } ,${ b }
364+ ${ l - StackGraph . arrow_stem_w } ,${ t + StackGraph . arrow_head_h }
365+ ${ l - StackGraph . arrow_head_w / 2 } ,${ t + StackGraph . arrow_head_h }
366+ ` ;
367+ arrow_points = `
368+ ${ l } ,${ t }
369+ ${ l + StackGraph . arrow_head_w / 2 } ,${ t + StackGraph . arrow_head_h }
370+ ${ l + StackGraph . arrow_stem_w } ,${ t + StackGraph . arrow_head_h }
371+ ${ l + StackGraph . arrow_stem_w } ,${ b }
372+ ${ l - StackGraph . arrow_stem_w } ,${ b }
373+ ${ l - StackGraph . arrow_stem_w } ,${ t + StackGraph . arrow_head_h }
374+ ${ l - StackGraph . arrow_head_w / 2 } ,${ t + StackGraph . arrow_head_h }
375+ ` ;
376+ break ;
377+ case "push" :
378+ box_points = `
379+ ${ l - StackGraph . arrow_stem_w } ,${ t }
380+ ${ r } ,${ t }
381+ ${ r } ,${ b }
382+ ${ l } ,${ b }
383+ ${ l - StackGraph . arrow_head_w / 2 } ,${ b - StackGraph . arrow_head_h }
384+ ${ l - StackGraph . arrow_stem_w } ,${ b - StackGraph . arrow_head_h }
385+ ` ;
386+ arrow_points = `
387+ ${ l - StackGraph . arrow_stem_w } ,${ t }
388+ ${ l + StackGraph . arrow_stem_w } ,${ t }
389+ ${ l + StackGraph . arrow_stem_w } ,${ b - StackGraph . arrow_head_h }
390+ ${ l + StackGraph . arrow_head_w / 2 } ,${ b - StackGraph . arrow_head_h }
391+ ${ l } ,${ b }
392+ ${ l - StackGraph . arrow_head_w / 2 } ,${ b - StackGraph . arrow_head_h }
393+ ${ l - StackGraph . arrow_stem_w } ,${ b - StackGraph . arrow_head_h }
394+ ` ;
395+ break ;
396+ default :
397+ box_points = `
398+ ${ l } ,${ t }
399+ ${ r } ,${ t }
400+ ${ r } ,${ b }
401+ ${ l } ,${ b }
402+ ` ;
403+ break ;
404+ }
405+ if ( arrow_points !== null ) {
406+ g . append ( 'polygon' ) . lower ( )
407+ . attr ( "class" , "arrow" )
408+ . attr ( 'points' , arrow_points ) ;
409+ }
410+ g . append ( 'polygon' ) . lower ( )
349411 . attr ( "class" , "background" )
350- . attr ( 'x' , bbox . x - StackGraph . margin )
351- . attr ( 'y' , bbox . y - StackGraph . margin )
352- . attr ( 'width' , bbox . width + 2 * StackGraph . margin )
353- . attr ( 'height' , bbox . height + 2 * StackGraph . margin ) ;
354- g . append ( 'rect' ) . lower ( ) . lower ( )
412+ . attr ( 'points' , box_points ) ;
413+ g . append ( 'polygon' ) . lower ( )
355414 . attr ( "class" , "border" )
356- . attr ( 'x' , bbox . x - StackGraph . margin )
357- . attr ( 'y' , bbox . y - StackGraph . margin )
358- . attr ( 'width' , bbox . width + 2 * StackGraph . margin )
359- . attr ( 'height' , bbox . height + 2 * StackGraph . margin ) ;
415+ . attr ( 'points' , box_points ) ;
360416 }
361417
362418 render_scope ( g ) {
0 commit comments