@@ -523,13 +523,26 @@ function computeTextDimensions(g, gd) {
523
523
legendItem . height = Math . max ( height , 16 ) + 3 ;
524
524
legendItem . width = width ;
525
525
} else { // case of title
526
- if ( opts . title . side . indexOf ( 'left' ) !== - 1 ) {
527
- opts . _titleWidth = width ;
526
+ opts . _titleWidth = width ;
527
+ opts . _titleHeight = height ;
528
+ }
529
+ }
530
+
531
+ function getTitleSize ( opts ) {
532
+ var w = 0 ;
533
+ var h = 0 ;
534
+
535
+ var side = opts . title . side ;
536
+ if ( side ) {
537
+ if ( side . indexOf ( 'left' ) !== - 1 ) {
538
+ w = opts . _titleWidth ;
528
539
}
529
- if ( opts . title . side . indexOf ( 'top' ) !== - 1 ) {
530
- opts . _titleHeight = height ;
540
+ if ( side . indexOf ( 'top' ) !== - 1 ) {
541
+ h = opts . _titleHeight ;
531
542
}
532
543
}
544
+
545
+ return [ w , h ] ;
533
546
}
534
547
535
548
/*
@@ -570,13 +583,14 @@ function computeLegendDimensions(gd, groups, traces) {
570
583
var toggleRectWidth = 0 ;
571
584
opts . _width = 0 ;
572
585
opts . _height = 0 ;
586
+ var titleSize = getTitleSize ( opts ) ;
573
587
574
588
if ( isVertical ) {
575
589
traces . each ( function ( d ) {
576
590
var h = d [ 0 ] . height ;
577
591
Drawing . setTranslate ( this ,
578
- bw + opts . _titleWidth ,
579
- bw + opts . _titleHeight + opts . _height + h / 2 + itemGap
592
+ bw + titleSize [ 0 ] ,
593
+ bw + titleSize [ 1 ] + opts . _height + h / 2 + itemGap
580
594
) ;
581
595
opts . _height += h ;
582
596
opts . _width = Math . max ( opts . _width , d [ 0 ] . width ) ;
@@ -628,8 +642,8 @@ function computeLegendDimensions(gd, groups, traces) {
628
642
d3 . select ( this ) . selectAll ( 'g.traces' ) . each ( function ( d ) {
629
643
var h = d [ 0 ] . height ;
630
644
Drawing . setTranslate ( this ,
631
- opts . _titleWidth ,
632
- bw + opts . _titleHeight + itemGap + h / 2 + offsetY
645
+ titleSize [ 0 ] ,
646
+ titleSize [ 1 ] + bw + itemGap + h / 2 + offsetY
633
647
) ;
634
648
offsetY += h ;
635
649
maxWidthInGroup = Math . max ( maxWidthInGroup , textGap + d [ 0 ] . width ) ;
@@ -674,8 +688,8 @@ function computeLegendDimensions(gd, groups, traces) {
674
688
}
675
689
676
690
Drawing . setTranslate ( this ,
677
- bw + opts . _titleWidth + offsetX ,
678
- bw + opts . _titleHeight + offsetY + h / 2 + itemGap
691
+ titleSize [ 0 ] + bw + offsetX ,
692
+ titleSize [ 1 ] + bw + offsetY + h / 2 + itemGap
679
693
) ;
680
694
681
695
rowWidth = offsetX + w + itemGap ;
@@ -693,8 +707,19 @@ function computeLegendDimensions(gd, groups, traces) {
693
707
}
694
708
}
695
709
696
- opts . _width = Math . ceil ( opts . _width + opts . _titleWidth ) ;
697
- opts . _height = Math . ceil ( opts . _height + opts . _titleHeight ) ;
710
+ opts . _width = Math . ceil (
711
+ Math . max (
712
+ opts . _width + titleSize [ 0 ] ,
713
+ opts . _titleWidth + 2 * ( bw + constants . titlePad )
714
+ )
715
+ ) ;
716
+
717
+ opts . _height = Math . ceil (
718
+ Math . max (
719
+ opts . _height + titleSize [ 1 ] ,
720
+ opts . _titleHeight + 2 * ( bw + constants . itemGap )
721
+ )
722
+ ) ;
698
723
699
724
opts . _effHeight = Math . min ( opts . _height , opts . _maxHeight ) ;
700
725
0 commit comments