@@ -43,7 +43,9 @@ function overlappingDomain(xDomain, yDomain, domains) {
43
43
exports . lsInner = function ( gd ) {
44
44
var fullLayout = gd . _fullLayout ;
45
45
var gs = fullLayout . _size ;
46
+ var pad = gs . p ;
46
47
var axList = Plotly . Axes . list ( gd ) ;
48
+ var hasSVGCartesian = fullLayout . _has ( 'cartesian' ) ;
47
49
var i ;
48
50
49
51
// clear axis line positions, to be set in the subplot loop below
@@ -122,7 +124,7 @@ exports.lsInner = function(gd) {
122
124
fullLayout . _plots [ subplot ] . bg = d3 . select ( this ) ;
123
125
} ) ;
124
126
125
- var freefinished = [ ] ;
127
+ var freeFinished = { } ;
126
128
subplotSelection . each ( function ( subplot ) {
127
129
var plotinfo = fullLayout . _plots [ subplot ] ;
128
130
var xa = plotinfo . xaxis ;
@@ -132,11 +134,11 @@ exports.lsInner = function(gd) {
132
134
xa . setScale ( ) ;
133
135
ya . setScale ( ) ;
134
136
135
- if ( plotinfo . bg && fullLayout . _has ( 'cartesian' ) ) {
137
+ if ( plotinfo . bg && hasSVGCartesian ) {
136
138
plotinfo . bg
137
139
. call ( Drawing . setRect ,
138
- xa . _offset - gs . p , ya . _offset - gs . p ,
139
- xa . _length + 2 * gs . p , ya . _length + 2 * gs . p )
140
+ xa . _offset - pad , ya . _offset - pad ,
141
+ xa . _length + 2 * pad , ya . _length + 2 * pad )
140
142
. call ( Color . fill , fullLayout . plot_bgcolor )
141
143
. style ( 'stroke-width' , 0 ) ;
142
144
}
@@ -162,129 +164,132 @@ exports.lsInner = function(gd) {
162
164
} ) ;
163
165
164
166
165
- plotinfo . plot . call ( Drawing . setTranslate , xa . _offset , ya . _offset ) ;
166
- plotinfo . plot . call ( Drawing . setClipUrl , plotinfo . clipId ) ;
167
+ plotinfo . plot
168
+ . call ( Drawing . setTranslate , xa . _offset , ya . _offset )
169
+ . call ( Drawing . setClipUrl , plotinfo . clipId ) ;
170
+
171
+ function shouldShowLine ( ax , counterAx , side ) {
172
+ return ( ax . anchor === counterAx . _id && ( ax . mirror || ax . side === side ) ) ||
173
+ ax . mirror === 'all' || ax . mirror === 'allticks' ||
174
+ ( ax . mirrors && ax . mirrors [ counterAx . _id + side ] ) ;
175
+ }
176
+
177
+ var showFreeX = xa . anchor === 'free' && ! freeFinished [ xa . _id ] ;
178
+ var showBottom = shouldShowLine ( xa , ya , 'bottom' ) ;
179
+ var showTop = shouldShowLine ( xa , ya , 'top' ) ;
180
+
181
+ var showFreeY = ya . anchor === 'free' && ! freeFinished [ ya . _id ] ;
182
+ var showLeft = shouldShowLine ( ya , xa , 'left' ) ;
183
+ var showRight = shouldShowLine ( ya , xa , 'right' ) ;
167
184
168
185
var xlw = Drawing . crispRound ( gd , xa . linewidth , 1 ) ;
169
186
var ylw = Drawing . crispRound ( gd , ya . linewidth , 1 ) ;
170
- var xp = gs . p + ylw ;
171
- var xpathPrefix = 'M' + ( - xp ) + ',' ;
172
- var xpathSuffix = 'h' + ( xa . _length + 2 * xp ) ;
173
- var showfreex = xa . anchor === 'free' &&
174
- freefinished . indexOf ( xa . _id ) === - 1 ;
175
- var freeposx = gs . h * ( 1 - ( xa . position || 0 ) ) + ( ( xlw / 2 ) % 1 ) ;
176
- var showbottom =
177
- ( xa . anchor === ya . _id && ( xa . mirror || xa . side !== 'top' ) ) ||
178
- xa . mirror === 'all' || xa . mirror === 'allticks' ||
179
- ( xa . mirrors && xa . mirrors [ ya . _id + 'bottom' ] ) ;
180
- var bottompos = ya . _length + gs . p + xlw / 2 ;
181
- var showtop =
182
- ( xa . anchor === ya . _id && ( xa . mirror || xa . side === 'top' ) ) ||
183
- xa . mirror === 'all' || xa . mirror === 'allticks' ||
184
- ( xa . mirrors && xa . mirrors [ ya . _id + 'top' ] ) ;
185
- var toppos = - gs . p - xlw / 2 ;
187
+
188
+ // TODO: this gets more complicated with multiple x and y axes
189
+ var xLinesXLeft = - pad - ylw ;
190
+ var xLinesXRight = xa . _length + pad + ylw ;
191
+ var xLinesYFree = gs . h * ( 1 - ( xa . position || 0 ) ) + ( ( xlw / 2 ) % 1 ) ;
192
+ var xLinesYBottom = ya . _length + pad + xlw / 2 ;
193
+ var xLinesYTop = - pad - xlw / 2 ;
186
194
187
195
// shorten y axis lines so they don't overlap x axis lines
188
- var yp = gs . p ;
189
196
// except where there's no x line
190
197
// TODO: this gets more complicated with multiple x and y axes
191
- var ypbottom = showbottom ? 0 : xlw ;
192
- var yptop = showtop ? 0 : xlw ;
193
- var ypathSuffix = ',' + ( - yp - yptop ) +
194
- 'v' + ( ya . _length + 2 * yp + yptop + ypbottom ) ;
195
- var showfreey = ya . anchor === 'free' &&
196
- freefinished . indexOf ( ya . _id ) === - 1 ;
197
- var freeposy = gs . w * ( ya . position || 0 ) + ( ( ylw / 2 ) % 1 ) ;
198
- var showleft =
199
- ( ya . anchor === xa . _id && ( ya . mirror || ya . side !== 'right' ) ) ||
200
- ya . mirror === 'all' || ya . mirror === 'allticks' ||
201
- ( ya . mirrors && ya . mirrors [ xa . _id + 'left' ] ) ;
202
- var leftpos = - gs . p - ylw / 2 ;
203
- var showright =
204
- ( ya . anchor === xa . _id && ( ya . mirror || ya . side === 'right' ) ) ||
205
- ya . mirror === 'all' || ya . mirror === 'allticks' ||
206
- ( ya . mirrors && ya . mirrors [ xa . _id + 'right' ] ) ;
207
- var rightpos = xa . _length + gs . p + ylw / 2 ;
198
+ var yLinesYBottom = ya . _length + ( showBottom ? 0 : xlw ) + pad ;
199
+ var yLinesYTop = ( showTop ? 0 : - xlw ) - pad ;
200
+ var yLinesXFree = gs . w * ( ya . position || 0 ) + ( ( ylw / 2 ) % 1 ) ;
201
+ var yLinesXLeft = - pad - ylw / 2 ;
202
+ var yLinesXRight = xa . _length + pad + ylw / 2 ;
203
+
204
+ function xLinePath ( y , showThis ) {
205
+ if ( ! showThis ) return '' ;
206
+ return 'M' + xLinesXLeft + ',' + y + 'H' + xLinesXRight ;
207
+ }
208
+
209
+ function yLinePath ( x , showThis ) {
210
+ if ( ! showThis ) return '' ;
211
+ return 'M' + x + ',' + yLinesYTop + 'V' + yLinesYBottom ;
212
+ }
208
213
209
214
// save axis line positions for ticks, draggers, etc to reference
210
215
// each subplot gets an entry:
211
216
// [left or bottom, right or top, free, main]
212
217
// main is the position at which to draw labels and draggers, if any
213
218
xa . _linepositions [ subplot ] = [
214
- showbottom ? bottompos : undefined ,
215
- showtop ? toppos : undefined ,
216
- showfreex ? freeposx : undefined
219
+ showBottom ? xLinesYBottom : undefined ,
220
+ showTop ? xLinesYTop : undefined ,
221
+ showFreeX ? xLinesYFree : undefined
217
222
] ;
218
223
if ( xa . anchor === ya . _id ) {
219
224
xa . _linepositions [ subplot ] [ 3 ] = xa . side === 'top' ?
220
- toppos : bottompos ;
225
+ xLinesYTop : xLinesYBottom ;
221
226
}
222
- else if ( showfreex ) {
223
- xa . _linepositions [ subplot ] [ 3 ] = freeposx ;
227
+ else if ( showFreeX ) {
228
+ xa . _linepositions [ subplot ] [ 3 ] = xLinesYFree ;
224
229
}
225
230
226
231
ya . _linepositions [ subplot ] = [
227
- showleft ? leftpos : undefined ,
228
- showright ? rightpos : undefined ,
229
- showfreey ? freeposy : undefined
232
+ showLeft ? yLinesXLeft : undefined ,
233
+ showRight ? yLinesXRight : undefined ,
234
+ showFreeY ? yLinesXFree : undefined
230
235
] ;
231
236
if ( ya . anchor === xa . _id ) {
232
237
ya . _linepositions [ subplot ] [ 3 ] = ya . side === 'right' ?
233
- rightpos : leftpos ;
238
+ yLinesXRight : yLinesXLeft ;
234
239
}
235
- else if ( showfreey ) {
236
- ya . _linepositions [ subplot ] [ 3 ] = freeposy ;
240
+ else if ( showFreeY ) {
241
+ ya . _linepositions [ subplot ] [ 3 ] = yLinesXFree ;
237
242
}
238
243
239
244
// translate all the extra stuff to have the
240
245
// same origin as the plot area or axes
241
246
var origin = 'translate(' + xa . _offset + ',' + ya . _offset + ')' ;
242
- var originx = origin ;
243
- var originy = origin ;
244
- if ( showfreex ) {
245
- originx = 'translate(' + xa . _offset + ',' + gs . t + ')' ;
246
- toppos += ya . _offset - gs . t ;
247
- bottompos += ya . _offset - gs . t ;
247
+ var originX = origin ;
248
+ var originY = origin ;
249
+ if ( showFreeX ) {
250
+ originX = 'translate(' + xa . _offset + ',' + gs . t + ')' ;
251
+ xLinesYTop += ya . _offset - gs . t ;
252
+ xLinesYBottom += ya . _offset - gs . t ;
248
253
}
249
- if ( showfreey ) {
250
- originy = 'translate(' + gs . l + ',' + ya . _offset + ')' ;
251
- leftpos += xa . _offset - gs . l ;
252
- rightpos += xa . _offset - gs . l ;
254
+ if ( showFreeY ) {
255
+ originY = 'translate(' + gs . l + ',' + ya . _offset + ')' ;
256
+ yLinesXLeft += xa . _offset - gs . l ;
257
+ yLinesXRight += xa . _offset - gs . l ;
253
258
}
254
259
255
- if ( fullLayout . _has ( 'cartesian' ) ) {
260
+ if ( hasSVGCartesian ) {
256
261
plotinfo . xlines
257
- . attr ( 'transform' , originx )
262
+ . attr ( 'transform' , originX )
258
263
. attr ( 'd' , (
259
- ( showbottom ? ( xpathPrefix + bottompos + xpathSuffix ) : '' ) +
260
- ( showtop ? ( xpathPrefix + toppos + xpathSuffix ) : '' ) +
261
- ( showfreex ? ( xpathPrefix + freeposx + xpathSuffix ) : '' ) ) ||
264
+ xLinePath ( xLinesYBottom , showBottom ) +
265
+ xLinePath ( xLinesYTop , showTop ) +
266
+ xLinePath ( xLinesYFree , showFreeX ) ) ||
262
267
// so it doesn't barf with no lines shown
263
268
'M0,0' )
264
269
. style ( 'stroke-width' , xlw + 'px' )
265
270
. call ( Color . stroke , xa . showline ?
266
271
xa . linecolor : 'rgba(0,0,0,0)' ) ;
267
272
plotinfo . ylines
268
- . attr ( 'transform' , originy )
273
+ . attr ( 'transform' , originY )
269
274
. attr ( 'd' , (
270
- ( showleft ? ( 'M' + leftpos + ypathSuffix ) : '' ) +
271
- ( showright ? ( 'M' + rightpos + ypathSuffix ) : '' ) +
272
- ( showfreey ? ( 'M' + freeposy + ypathSuffix ) : '' ) ) ||
275
+ yLinePath ( yLinesXLeft , showLeft ) +
276
+ yLinePath ( yLinesXRight , showRight ) +
277
+ yLinePath ( yLinesXFree , showFreeY ) ) ||
273
278
'M0,0' )
274
- . attr ( 'stroke-width' , ylw + 'px' )
279
+ . style ( 'stroke-width' , ylw + 'px' )
275
280
. call ( Color . stroke , ya . showline ?
276
281
ya . linecolor : 'rgba(0,0,0,0)' ) ;
277
282
}
278
283
279
- plotinfo . xaxislayer . attr ( 'transform' , originx ) ;
280
- plotinfo . yaxislayer . attr ( 'transform' , originy ) ;
284
+ plotinfo . xaxislayer . attr ( 'transform' , originX ) ;
285
+ plotinfo . yaxislayer . attr ( 'transform' , originY ) ;
281
286
plotinfo . gridlayer . attr ( 'transform' , origin ) ;
282
287
plotinfo . zerolinelayer . attr ( 'transform' , origin ) ;
283
288
plotinfo . draglayer . attr ( 'transform' , origin ) ;
284
289
285
290
// mark free axes as displayed, so we don't draw them again
286
- if ( showfreex ) { freefinished . push ( xa . _id ) ; }
287
- if ( showfreey ) { freefinished . push ( ya . _id ) ; }
291
+ if ( showFreeX ) freeFinished [ xa . _id ] = 1 ;
292
+ if ( showFreeY ) freeFinished [ ya . _id ] = 1 ;
288
293
} ) ;
289
294
290
295
Plotly . Axes . makeClipPaths ( gd ) ;
0 commit comments