@@ -2177,12 +2177,18 @@ axes.drawOne = function(gd, ax, opts) {
2177
2177
// TODO: mirror labels, esp for subplots
2178
2178
2179
2179
seq . push ( function ( ) {
2180
- return axes . drawLabels ( gd , ax , {
2180
+ var opts = {
2181
2181
vals : vals ,
2182
2182
layer : mainAxLayer ,
2183
2183
transFn : transTickLabelFn ,
2184
2184
labelFns : axes . makeLabelFns ( ax , mainLinePosition )
2185
- } ) ;
2185
+ } ;
2186
+
2187
+ if ( ax . _anchorAxis ) {
2188
+ opts . grid = plotinfo . gridlayer . select ( '.' + ax . _anchorAxis . _id ) ;
2189
+ }
2190
+
2191
+ return axes . drawLabels ( gd , ax , opts ) ;
2186
2192
} ) ;
2187
2193
2188
2194
if ( ax . type === 'multicategory' ) {
@@ -2861,7 +2867,9 @@ axes.drawGrid = function(gd, ax, opts) {
2861
2867
grid . attr ( 'transform' , opts . transFn )
2862
2868
. attr ( 'd' , opts . path )
2863
2869
. call ( Color . stroke , ax . gridcolor || '#ddd' )
2864
- . style ( 'stroke-width' , ax . _gw + 'px' ) ;
2870
+ . style ( 'stroke-width' , ax . _gw + 'px' )
2871
+ . style ( { opacity : 100 } ) ; // ensure visible
2872
+
2865
2873
2866
2874
if ( typeof opts . path === 'function' ) grid . attr ( 'd' , opts . path ) ;
2867
2875
} ;
@@ -3054,6 +3062,9 @@ axes.drawLabels = function(gd, ax, opts) {
3054
3062
3055
3063
var isX = ax . _id . charAt ( 0 ) === 'x' ;
3056
3064
3065
+ var visibleLabelMin = Infinity ;
3066
+ var visibleLabelMax = - Infinity ;
3067
+
3057
3068
tickLabels . each ( function ( d ) {
3058
3069
var thisLabel = d3 . select ( this ) ;
3059
3070
var mathjaxGroup = thisLabel . select ( '.text-math-group' ) ;
@@ -3068,9 +3079,31 @@ axes.drawLabels = function(gd, ax, opts) {
3068
3079
if ( bb . bottom > max ) hide = true ;
3069
3080
else if ( bb . top + ( ax . tickangle ? 0 : d . fontSize / 4 ) < min ) hide = true ;
3070
3081
}
3071
- if ( hide ) thisLabel . select ( 'text' ) . style ( { opacity : 0 } ) ;
3082
+ if ( hide ) {
3083
+ thisLabel . select ( 'text' ) . style ( { opacity : 0 } ) ;
3084
+ } else {
3085
+ visibleLabelMin = Math . min ( visibleLabelMin , isX ? bb . top : bb . left ) ;
3086
+ visibleLabelMax = Math . max ( visibleLabelMax , isX ? bb . bottom : bb . right ) ;
3087
+ }
3072
3088
} // TODO: hide mathjax?
3073
3089
} ) ;
3090
+
3091
+ var anchorAx = ax . _anchorAxis || { } ;
3092
+
3093
+ if ( ( anchorAx . ticklabelposition || '' ) . indexOf ( 'inside' ) !== - 1 ) {
3094
+ var grid = opts . grid ;
3095
+ if ( grid ) {
3096
+ grid . each ( function ( ) {
3097
+ d3 . select ( this ) . selectAll ( 'path' ) . each ( function ( d ) {
3098
+ var q = anchorAx . l2p ( d . x ) + anchorAx . _offset ;
3099
+
3100
+ if ( q < visibleLabelMax && q > visibleLabelMin ) {
3101
+ d3 . select ( this ) . style ( { opacity : 0 } ) ;
3102
+ }
3103
+ } ) ;
3104
+ } ) ;
3105
+ }
3106
+ }
3074
3107
} ;
3075
3108
}
3076
3109
0 commit comments