@@ -144,7 +144,20 @@ const graphModule = (function() {
144144
145145 d3 . select ( self . frameElement ) . style ( "height" , "700px" ) ;
146146 }
147-
147+ function truncateEllipsis ( d ) {
148+ let dstr = d . name . split ( ":" ) [ 0 ] ;
149+ if ( dstr . length > 20 ) {
150+ let truncated = dstr . substring ( 0 , 18 ) ;
151+ if ( / \s + $ / . test ( truncated ) || / ^ \s / . test ( dstr [ 18 ] ) ) {
152+ /* If it ends with spaces remove all spaces and the last
153+ non-space character to show the word has been truncated */
154+ truncated = truncated . replace ( / \s + $ / , "" ) ;
155+ truncated = truncated . slice ( 0 , - 1 ) ;
156+ }
157+ dstr = truncated + "..." ;
158+ }
159+ return dstr ;
160+ }
148161 function update ( source ) {
149162 var i = 0
150163 var nodes = tree . nodes ( root ) . reverse ( )
@@ -198,14 +211,19 @@ const graphModule = (function() {
198211 . attr ( "dy" , ".35em" )
199212 . attr ( "class" , function ( d ) {
200213 var fclass = d . name . split ( ":" ) . shift ( ) . toLowerCase ( ) ;
214+ fclass = fclass . replace ( / ^ [ ^ a - z A - Z _ - ] / , 'C' ) ;
215+ fclass = fclass . replace ( / [ ^ a - z A - Z 0 - 9 _ - ] / g, '_' ) ;
201216 if ( ! ( 'children' in d ) )
202- return "gvisible prechk-" + fclass + " finale" ;
217+ return "gvisible prechk-" + fclass + " finale" ;
203218 return "gvisible prechk-" + fclass ; } )
204- . text ( function ( d ) { return d . name . split ( ":" ) [ 0 ] ; } )
219+ . attr ( "data-fullname" , function ( d ) {
220+ return d . name . split ( ":" ) . shift ( ) ;
221+ } )
222+ . text ( truncateEllipsis )
205223 . style ( "font-size" , font )
206224 . style ( "fill" , function ( d ) {
207- var t = d . name . split ( ":" ) . shift ( ) ;
208- var x ;
225+ const t = d . name . split ( ":" ) . shift ( ) ;
226+ let x ;
209227 if ( t in lcolors )
210228 x = lcolors [ t ] ;
211229 return x ;
@@ -368,13 +386,18 @@ const graphModule = (function() {
368386 var yoffset = - 10
369387 if ( showFullTree )
370388 yoffset = - 6
371- d3 . select ( "g#x" + id ) . append ( "text" ) . attr ( "dx" , - 6 ) . attr ( "dy" , yoffset ) . attr ( "class" , "gtext" )
389+ d3 . select ( "g#x" + id )
390+ . append ( "text" ) . attr ( "dx" , - 6 )
391+ . attr ( "dy" , yoffset ) . attr ( "class" , "gtext" )
372392 . append ( "textPath" ) . attr ( "href" , "#f" + id ) . attr ( "class" , xclass )
373393 . attr ( "text-anchor" , "middle" )
374394 . attr ( "id" , "t" + id )
375395 . attr ( "csid" , csid )
376396 . attr ( "parentname" , pname )
377- . text ( text ) . attr ( "startOffset" , doffset + "%" )
397+ . attr ( "data-fullname" , text )
398+ . text ( truncateEllipsis ( { name :text } ) )
399+ . attr ( "fill" , "#777" )
400+ . attr ( "startOffset" , doffset + "%" )
378401 . on ( "click" , pathclick )
379402 . on ( "mouseover" , showdiv )
380403 . on ( "mouseout" , hidediv ) ;
0 commit comments