@@ -10,8 +10,16 @@ export class Title extends Component {
10
10
* Truncates title creating ellipses and attaching tooltip for exposing full title.
11
11
*/
12
12
truncateTitle ( ) {
13
- const containerWidth = DOMUtils . getSVGElementSize ( this . parent ) . width ;
14
- const title = DOMUtils . appendOrSelect ( this . parent , "text.title" ) ;
13
+ // get a reference to the title elements to calculate the size the title can be
14
+ const containerBounds = DOMUtils . getSVGElementSize ( this . parent , { useAttr : true } ) ;
15
+ // need to check if the width is 0, and try to use the parent attribute (getSVGElement wont validate if height: 0)
16
+ const containerWidth = containerBounds . width ? containerBounds . width : this . parent . node ( ) . getAttribute ( "width" ) ;
17
+ const title = DOMUtils . appendOrSelect ( this . parent , "text.title" ) ;
18
+
19
+ // sanity check to prevent stack overflow on binary search
20
+ if ( containerWidth <= 0 ) {
21
+ return ;
22
+ }
15
23
16
24
// check if the title is too big for the containing svg
17
25
if ( title . node ( ) . getComputedTextLength ( ) > containerWidth ) {
@@ -35,17 +43,17 @@ export class Title extends Component {
35
43
36
44
// add events for displaying the tooltip with the title
37
45
const self = this ;
38
- title . on ( "mouseenter" , function ( ) {
46
+ title . on ( "mouseenter" , function ( ) {
39
47
self . services . events . dispatchEvent ( "show-tooltip" , {
40
48
hoveredElement : title ,
41
49
type : TooltipTypes . TITLE
42
50
} ) ;
43
51
} )
44
- . on ( "mouseout" , function ( ) {
45
- self . services . events . dispatchEvent ( "hide-tooltip" , {
46
- hoveredElement : title ,
52
+ . on ( "mouseout" , function ( ) {
53
+ self . services . events . dispatchEvent ( "hide-tooltip" , {
54
+ hoveredElement : title ,
55
+ } ) ;
47
56
} ) ;
48
- } ) ;
49
57
}
50
58
}
51
59
@@ -77,7 +85,7 @@ export class Title extends Component {
77
85
* @param width the width of the svg container that holds the title
78
86
*/
79
87
protected getSubstringIndex ( title , start , end , width ) {
80
- const mid = Math . floor ( ( end + start ) / 2 ) ;
88
+ const mid = Math . floor ( ( end + start ) / 2 ) ;
81
89
if ( title . getSubStringLength ( 0 , mid ) > width ) {
82
90
return this . getSubstringIndex ( title , start , mid , width ) ;
83
91
} else if ( title . getSubStringLength ( 0 , mid ) < width ) {
0 commit comments