@@ -34,6 +34,11 @@ var ONESEC = constants.ONESEC;
34
34
var MINUS_SIGN = constants . MINUS_SIGN ;
35
35
var BADNUM = constants . BADNUM ;
36
36
37
+ var ZERO_PATH = { K : 'zeroline' } ;
38
+ var GRID_PATH = { K : 'gridline' , L : 'path' } ;
39
+ var TICK_PATH = { K : 'tick' , L : 'path' } ;
40
+ var TICK_TEXT = { K : 'tick' , L : 'text' } ;
41
+
37
42
var alignmentConstants = require ( '../../constants/alignment' ) ;
38
43
var MID_SHIFT = alignmentConstants . MID_SHIFT ;
39
44
var CAP_SHIFT = alignmentConstants . CAP_SHIFT ;
@@ -1449,7 +1454,7 @@ function formatDate(ax, out, hover, extraPrecision) {
1449
1454
ax . _prevDateHead = headStr ;
1450
1455
dateStr += '<br>' + headStr ;
1451
1456
} else {
1452
- var isInside = ( ax . ticklabelposition || '' ) . indexOf ( 'inside' ) !== - 1 ;
1457
+ var isInside = insideTicklabelposition ( ax ) ;
1453
1458
var side = ax . _realSide || ax . side ; // polar mocks the side of the radial axis
1454
1459
if (
1455
1460
( ! isInside && side === 'top' ) ||
@@ -2180,6 +2185,7 @@ axes.drawOne = function(gd, ax, opts) {
2180
2185
return axes . drawLabels ( gd , ax , {
2181
2186
vals : vals ,
2182
2187
layer : mainAxLayer ,
2188
+ plotinfo : plotinfo ,
2183
2189
transFn : transTickLabelFn ,
2184
2190
labelFns : axes . makeLabelFns ( ax , mainLinePosition )
2185
2191
} ) ;
@@ -2798,7 +2804,10 @@ axes.drawTicks = function(gd, ax, opts) {
2798
2804
. classed ( 'crisp' , opts . crisp !== false )
2799
2805
. call ( Color . stroke , ax . tickcolor )
2800
2806
. style ( 'stroke-width' , Drawing . crispRound ( gd , ax . tickwidth , 1 ) + 'px' )
2801
- . attr ( 'd' , opts . path ) ;
2807
+ . attr ( 'd' , opts . path )
2808
+ . style ( 'display' , null ) ; // visible
2809
+
2810
+ hideCounterAxisInsideTickLabels ( ax , [ TICK_PATH ] ) ;
2802
2811
2803
2812
ticks . attr ( 'transform' , opts . transFn ) ;
2804
2813
} ;
@@ -2861,7 +2870,10 @@ axes.drawGrid = function(gd, ax, opts) {
2861
2870
grid . attr ( 'transform' , opts . transFn )
2862
2871
. attr ( 'd' , opts . path )
2863
2872
. call ( Color . stroke , ax . gridcolor || '#ddd' )
2864
- . style ( 'stroke-width' , ax . _gw + 'px' ) ;
2873
+ . style ( 'stroke-width' , ax . _gw + 'px' )
2874
+ . style ( 'display' , null ) ; // visible
2875
+
2876
+ hideCounterAxisInsideTickLabels ( ax , [ GRID_PATH ] ) ;
2865
2877
2866
2878
if ( typeof opts . path === 'function' ) grid . attr ( 'd' , opts . path ) ;
2867
2879
} ;
@@ -2910,7 +2922,10 @@ axes.drawZeroLine = function(gd, ax, opts) {
2910
2922
zl . attr ( 'transform' , opts . transFn )
2911
2923
. attr ( 'd' , opts . path )
2912
2924
. call ( Color . stroke , ax . zerolinecolor || Color . defaultLine )
2913
- . style ( 'stroke-width' , Drawing . crispRound ( gd , ax . zerolinewidth , ax . _gw || 1 ) + 'px' ) ;
2925
+ . style ( 'stroke-width' , Drawing . crispRound ( gd , ax . zerolinewidth , ax . _gw || 1 ) + 'px' )
2926
+ . style ( 'display' , null ) ; // visible
2927
+
2928
+ hideCounterAxisInsideTickLabels ( ax , [ ZERO_PATH ] ) ;
2914
2929
} ;
2915
2930
2916
2931
/**
@@ -2983,7 +2998,10 @@ axes.drawLabels = function(gd, ax, opts) {
2983
2998
// sync label: just position it now.
2984
2999
positionLabels ( thisLabel , tickAngle ) ;
2985
3000
}
2986
- } ) ;
3001
+ } )
3002
+ . style ( 'display' , null ) ; // visible
3003
+
3004
+ hideCounterAxisInsideTickLabels ( ax , [ TICK_TEXT ] ) ;
2987
3005
2988
3006
tickLabels . exit ( ) . remove ( ) ;
2989
3007
@@ -2995,7 +3013,7 @@ axes.drawLabels = function(gd, ax, opts) {
2995
3013
}
2996
3014
2997
3015
function positionLabels ( s , angle ) {
2998
- var isInside = ( ax . ticklabelposition || '' ) . indexOf ( 'inside' ) !== - 1 ;
3016
+ var isInside = insideTicklabelposition ( ax ) ;
2999
3017
3000
3018
s . each ( function ( d ) {
3001
3019
var thisLabel = d3 . select ( this ) ;
@@ -3025,8 +3043,7 @@ axes.drawLabels = function(gd, ax, opts) {
3025
3043
} ) ;
3026
3044
3027
3045
if ( isInside ) {
3028
- // ensure visible
3029
- thisText . style ( { opacity : 100 } ) ;
3046
+ thisText . style ( 'opacity' , 0 ) ; // visible
3030
3047
3031
3048
if ( ax . _hideOutOfRangeInsideTickLabels ) {
3032
3049
ax . _hideOutOfRangeInsideTickLabels ( ) ;
@@ -3040,9 +3057,8 @@ axes.drawLabels = function(gd, ax, opts) {
3040
3057
} ) ;
3041
3058
}
3042
3059
3043
- ax . _hideOutOfRangeInsideTickLabels = undefined ;
3044
- if ( ( ax . ticklabelposition || '' ) . indexOf ( 'inside' ) !== - 1 ) {
3045
- ax . _hideOutOfRangeInsideTickLabels = function ( ) {
3060
+ ax . _hideOutOfRangeInsideTickLabels = function ( ) {
3061
+ if ( insideTicklabelposition ( ax ) ) {
3046
3062
var rl = Lib . simpleMap ( ax . range , ax . r2l ) ;
3047
3063
3048
3064
// hide inside tick labels that go outside axis end points
@@ -3052,8 +3068,12 @@ axes.drawLabels = function(gd, ax, opts) {
3052
3068
var min = Math . min ( p0 , p1 ) + ax . _offset ;
3053
3069
var max = Math . max ( p0 , p1 ) + ax . _offset ;
3054
3070
3071
+ var side = ax . side ;
3055
3072
var isX = ax . _id . charAt ( 0 ) === 'x' ;
3056
3073
3074
+ var visibleLabelMin = Infinity ;
3075
+ var visibleLabelMax = - Infinity ;
3076
+
3057
3077
tickLabels . each ( function ( d ) {
3058
3078
var thisLabel = d3 . select ( this ) ;
3059
3079
var mathjaxGroup = thisLabel . select ( '.text-math-group' ) ;
@@ -3068,11 +3088,69 @@ axes.drawLabels = function(gd, ax, opts) {
3068
3088
if ( bb . bottom > max ) hide = true ;
3069
3089
else if ( bb . top + ( ax . tickangle ? 0 : d . fontSize / 4 ) < min ) hide = true ;
3070
3090
}
3071
- if ( hide ) thisLabel . select ( 'text' ) . style ( { opacity : 0 } ) ;
3091
+
3092
+ var t = thisLabel . select ( 'text' ) ;
3093
+ if ( hide ) {
3094
+ t . style ( 'opacity' , 0 ) ; // hidden
3095
+ } else {
3096
+ t . style ( 'opacity' , 1 ) ; // visible
3097
+
3098
+ if ( side === 'bottom' || side === 'right' ) {
3099
+ visibleLabelMin = Math . min ( visibleLabelMin , isX ? bb . top : bb . left ) ;
3100
+ } else {
3101
+ visibleLabelMin = - Infinity ;
3102
+ }
3103
+
3104
+ if ( side === 'top' || side === 'left' ) {
3105
+ visibleLabelMax = Math . max ( visibleLabelMax , isX ? bb . bottom : bb . right ) ;
3106
+ } else {
3107
+ visibleLabelMax = Infinity ;
3108
+ }
3109
+ }
3072
3110
} // TODO: hide mathjax?
3073
3111
} ) ;
3074
- } ;
3075
- }
3112
+
3113
+ if ( ax . _anchorAxis ) {
3114
+ ax . _anchorAxis . _visibleLabelMin = visibleLabelMin ;
3115
+ ax . _anchorAxis . _visibleLabelMax = visibleLabelMax ;
3116
+ }
3117
+ }
3118
+ } ;
3119
+
3120
+ ax . _hideCounterAxisInsideTickLabels = function ( partialOpts ) {
3121
+ if ( insideTicklabelposition ( ax . _anchorAxis || { } ) ) {
3122
+ ( partialOpts || [
3123
+ ZERO_PATH ,
3124
+ GRID_PATH ,
3125
+ TICK_PATH ,
3126
+ TICK_TEXT
3127
+ ] ) . forEach ( function ( e ) {
3128
+ var isTickText = e . K === 'tick' && e . L === 'text' ;
3129
+ if ( isTickText && ax . ticklabelmode === 'period' ) return ;
3130
+
3131
+ var sel ;
3132
+ if ( e . K === ZERO_PATH . K ) sel = opts . plotinfo . zerolinelayer . selectAll ( '.' + ax . _id + 'zl' ) ;
3133
+ else if ( e . K === GRID_PATH . K ) sel = opts . plotinfo . gridlayer . selectAll ( '.' + ax . _id ) ;
3134
+ else sel = opts . plotinfo [ ax . _id . charAt ( 0 ) + 'axislayer' ] ;
3135
+
3136
+ sel . each ( function ( ) {
3137
+ var w = d3 . select ( this ) ;
3138
+ if ( e . L ) w = w . selectAll ( e . L ) ;
3139
+
3140
+ w . each ( function ( d ) {
3141
+ var q = ax . l2p ( d . x ) + ax . _offset ;
3142
+
3143
+ var t = d3 . select ( this ) ;
3144
+ if ( q < ax . _visibleLabelMax && q > ax . _visibleLabelMin ) {
3145
+ t . style ( 'display' , 'none' ) ; // hidden
3146
+ } else if ( e . K === 'tick' ) {
3147
+ t . style ( 'display' , null ) ; // visible
3148
+ }
3149
+ } ) ;
3150
+ } ) ;
3151
+ } ) ;
3152
+ }
3153
+ } ;
3076
3154
3077
3155
// make sure all labels are correctly positioned at their base angle
3078
3156
// the positionLabels call above is only for newly drawn labels.
@@ -3201,7 +3279,7 @@ axes.drawLabels = function(gd, ax, opts) {
3201
3279
var anchorAx = ax . _anchorAxis ;
3202
3280
if (
3203
3281
anchorAx && anchorAx . autorange &&
3204
- ( ax . ticklabelposition || '' ) . indexOf ( 'inside' ) !== - 1 &&
3282
+ insideTicklabelposition ( ax ) &&
3205
3283
! isLinked ( fullLayout , ax . _id )
3206
3284
) {
3207
3285
if ( ! fullLayout . _insideTickLabelsAutorange ) {
@@ -3350,7 +3428,7 @@ function drawTitle(gd, ax) {
3350
3428
if ( ax . title . hasOwnProperty ( 'standoff' ) ) {
3351
3429
titleStandoff = ax . _depth + ax . title . standoff + approxTitleDepth ( ax ) ;
3352
3430
} else {
3353
- var isInside = ( ax . ticklabelposition || '' ) . indexOf ( 'inside' ) !== - 1 ;
3431
+ var isInside = insideTicklabelposition ( ax ) ;
3354
3432
3355
3433
if ( ax . type === 'multicategory' ) {
3356
3434
titleStandoff = ax . _depth ;
@@ -3708,3 +3786,15 @@ function moveOutsideBreak(v, ax) {
3708
3786
}
3709
3787
return v ;
3710
3788
}
3789
+
3790
+ function insideTicklabelposition ( ax ) {
3791
+ return ( ( ax . ticklabelposition || '' ) . indexOf ( 'inside' ) !== - 1 ) ;
3792
+ }
3793
+
3794
+ function hideCounterAxisInsideTickLabels ( ax , opts ) {
3795
+ if ( insideTicklabelposition ( ax . _anchorAxis || { } ) ) {
3796
+ if ( ax . _hideCounterAxisInsideTickLabels ) {
3797
+ ax . _hideCounterAxisInsideTickLabels ( opts ) ;
3798
+ }
3799
+ }
3800
+ }
0 commit comments