@@ -2946,20 +2946,42 @@ function calcLabelLevelBbox(ax, cls, mainLinePositionShift) {
2946
2946
bottom = - Infinity ;
2947
2947
left = Infinity ;
2948
2948
right = - Infinity ;
2949
+ var xAxis = ax . _id . charAt ( 0 ) === 'x' ;
2949
2950
ax . _selections [ cls ] . each ( function ( ) {
2950
2951
var thisLabel = selectTickLabel ( this ) ;
2952
+ var hidden = thisLabel . style ( 'display' ) === 'none' ;
2951
2953
// Use parent node <g.(x|y)tick>, to make Drawing.bBox
2952
2954
// retrieve a bbox computed with transform info
2953
2955
//
2954
2956
// To improve perf, it would be nice to use `thisLabel.node()`
2955
2957
// (like in fixLabelOverlaps) instead and use Axes.getPxPosition
2956
2958
// together with the makeLabelFns outputs and `tickangle`
2957
2959
// to compute one bbox per (tick value x tick style)
2960
+ if ( hidden ) {
2961
+ // turn on label display temporarily to calculate its bbox
2962
+ thisLabel . style ( 'display' , null ) ;
2963
+ }
2958
2964
var bb = Drawing . bBox ( thisLabel . node ( ) . parentNode ) ;
2959
- top = Math . min ( top , bb . top ) ;
2960
- bottom = Math . max ( bottom , bb . bottom ) ;
2961
- left = Math . min ( left , bb . left ) ;
2962
- right = Math . max ( right , bb . right ) ;
2965
+ if ( hidden ) {
2966
+ selectTickLabel ( this ) . style ( 'display' , 'none' ) ;
2967
+ }
2968
+ var currentTop = bb . top ;
2969
+ var currentBottom = bb . bottom ;
2970
+ var currentLeft = bb . left ;
2971
+ var currentRight = bb . right ;
2972
+ if ( hidden ) {
2973
+ if ( xAxis ) {
2974
+ currentTop = top ;
2975
+ currentBottom = bottom ;
2976
+ } else {
2977
+ currentLeft = left ;
2978
+ currentRight = right ;
2979
+ }
2980
+ }
2981
+ top = Math . min ( top , currentTop ) ;
2982
+ bottom = Math . max ( bottom , currentBottom ) ;
2983
+ left = Math . min ( left , currentLeft ) ;
2984
+ right = Math . max ( right , currentRight ) ;
2963
2985
} ) ;
2964
2986
} else {
2965
2987
var dummyCalc = axes . makeLabelFns ( ax , mainLinePositionShift ) ;
@@ -3707,8 +3729,8 @@ axes.drawLabels = function(gd, ax, opts) {
3707
3729
var t = thisLabel . select ( 'text' ) ;
3708
3730
if ( adjust ) {
3709
3731
if ( hideOverflow ) t . style ( 'display' , 'none' ) ; // hidden
3710
- } else {
3711
- t . style ( 'display' , null ) ; // visible
3732
+ } else if ( t . node ( ) . style . display !== 'none' ) {
3733
+ t . style ( 'display' , null ) ;
3712
3734
3713
3735
if ( side === 'bottom' || side === 'right' ) {
3714
3736
visibleLabelMin = Math . min ( visibleLabelMin , isX ? bb . top : bb . left ) ;
0 commit comments