@@ -55,7 +55,6 @@ function lsInner(gd) {
55
55
var gs = fullLayout . _size ;
56
56
var pad = gs . p ;
57
57
var axList = Axes . list ( gd , '' , true ) ;
58
- var i , subplot , plotinfo , ax , xa , ya ;
59
58
60
59
fullLayout . _paperdiv . style ( {
61
60
width : ( gd . _context . responsive && fullLayout . autosize && ! gd . _context . _hasZeroWidth && ! gd . layout . width ) ? '100%' : fullLayout . width + 'px' ,
@@ -74,43 +73,7 @@ function lsInner(gd) {
74
73
if ( ! fullLayout . _has ( 'cartesian' ) ) {
75
74
return Plots . previousPromises ( gd ) ;
76
75
}
77
-
78
- function getLinePosition ( ax , counterAx , side ) {
79
- var lwHalf = ax . _lw / 2 ;
80
-
81
- if ( ax . _id . charAt ( 0 ) === 'x' ) {
82
- if ( ! counterAx ) return gs . t + gs . h * ( 1 - ( ax . position || 0 ) ) + ( lwHalf % 1 ) ;
83
- else if ( side === 'top' ) return counterAx . _offset - pad - lwHalf ;
84
- return counterAx . _offset + counterAx . _length + pad + lwHalf ;
85
- }
86
-
87
- if ( ! counterAx ) return gs . l + gs . w * ( ax . position || 0 ) + ( lwHalf % 1 ) ;
88
- else if ( side === 'right' ) return counterAx . _offset + counterAx . _length + pad + lwHalf ;
89
- return counterAx . _offset - pad - lwHalf ;
90
- }
91
-
92
- // some preparation of axis position info
93
- for ( i = 0 ; i < axList . length ; i ++ ) {
94
- ax = axList [ i ] ;
95
-
96
- var counterAx = ax . _anchorAxis ;
97
-
98
- // clear axis line positions, to be set in the subplot loop below
99
- ax . _linepositions = { } ;
100
-
101
- // stash crispRounded linewidth so we don't need to pass gd all over the place
102
- ax . _lw = Drawing . crispRound ( gd , ax . linewidth , 1 ) ;
103
-
104
- // figure out the main axis line and main mirror line position.
105
- // it's easier to follow the logic if we handle these separately from
106
- // ax._linepositions, which are only used by mirror=allticks
107
- // for non-main-subplot ticks, and mirror=all(ticks)? for zero line
108
- // hiding logic
109
- ax . _mainLinePosition = getLinePosition ( ax , counterAx , ax . side ) ;
110
- ax . _mainMirrorPosition = ( ax . mirror && counterAx ) ?
111
- getLinePosition ( ax , counterAx ,
112
- alignmentConstants . OPPOSITE_SIDE [ ax . side ] ) : null ;
113
- }
76
+ var i , subplot , plotinfo , xa , ya ;
114
77
115
78
// figure out which backgrounds we need to draw,
116
79
// and in which layers to put them
@@ -253,9 +216,10 @@ function lsInner(gd) {
253
216
254
217
function mainPath ( ax , pathFn , pathFnFree ) {
255
218
if ( ! ax . showline || subplot !== ax . _mainSubplot ) return '' ;
256
- if ( ! ax . _anchorAxis ) return pathFnFree ( ax . _mainLinePosition ) ;
257
- var out = pathFn ( ax . _mainLinePosition ) ;
258
- if ( ax . mirror ) out += pathFn ( ax . _mainMirrorPosition ) ;
219
+ var mainLinePosition = Axes . getAxisLinePosition ( gd , ax ) ;
220
+ if ( ! ax . _anchorAxis ) return pathFnFree ( mainLinePosition ) ;
221
+ var out = pathFn ( mainLinePosition ) ;
222
+ if ( ax . mirror ) out += pathFn ( Axes . getAxisMirrorLinePosition ( gd , ax ) ) ;
259
223
return out ;
260
224
}
261
225
@@ -280,30 +244,25 @@ function lsInner(gd) {
280
244
*/
281
245
var xPath = 'M0,0' ;
282
246
if ( shouldShowLinesOrTicks ( xa , subplot ) ) {
283
- leftYLineWidth = findCounterAxisLineWidth ( xa , 'left' , ya , axList ) ;
247
+ leftYLineWidth = findCounterAxisLineWidth ( gd , xa , 'left' , ya , axList ) ;
284
248
xLinesXLeft = xa . _offset - ( leftYLineWidth ? ( pad + leftYLineWidth ) : 0 ) ;
285
- rightYLineWidth = findCounterAxisLineWidth ( xa , 'right' , ya , axList ) ;
249
+ rightYLineWidth = findCounterAxisLineWidth ( gd , xa , 'right' , ya , axList ) ;
286
250
xLinesXRight = xa . _offset + xa . _length + ( rightYLineWidth ? ( pad + rightYLineWidth ) : 0 ) ;
287
- xLinesYBottom = getLinePosition ( xa , ya , 'bottom' ) ;
288
- xLinesYTop = getLinePosition ( xa , ya , 'top' ) ;
251
+ xLinesYBottom = Axes . getAxisLinePosition ( gd , xa , ya , 'bottom' ) ;
252
+ xLinesYTop = Axes . getAxisLinePosition ( gd , xa , ya , 'top' ) ;
289
253
290
254
// save axis line positions for extra ticks to reference
291
255
// each subplot that gets ticks from "allticks" gets an entry:
292
256
// [left or bottom, right or top]
293
257
extraSubplot = ( ! xa . _anchorAxis || subplot !== xa . _mainSubplot ) ;
294
- if ( extraSubplot && ( xa . mirror === 'allticks' || xa . mirror === 'all' ) ) {
295
- xa . _linepositions [ subplot ] = [ xLinesYBottom , xLinesYTop ] ;
296
- }
297
-
298
258
xPath = mainPath ( xa , xLinePath , xLinePathFree ) ;
299
259
if ( extraSubplot && xa . showline && ( xa . mirror === 'all' || xa . mirror === 'allticks' ) ) {
300
260
xPath += xLinePath ( xLinesYBottom ) + xLinePath ( xLinesYTop ) ;
301
261
}
302
262
303
263
plotinfo . xlines
304
- . style ( 'stroke-width' , xa . _lw + 'px' )
305
- . call ( Color . stroke , xa . showline ?
306
- xa . linecolor : 'rgba(0,0,0,0)' ) ;
264
+ . style ( 'stroke-width' , crispRoundLineWidth ( gd , xa ) + 'px' )
265
+ . call ( Color . stroke , xa . showline ? xa . linecolor : 'rgba(0,0,0,0)' ) ;
307
266
}
308
267
plotinfo . xlines . attr ( 'd' , xPath ) ;
309
268
@@ -320,27 +279,22 @@ function lsInner(gd) {
320
279
*/
321
280
var yPath = 'M0,0' ;
322
281
if ( shouldShowLinesOrTicks ( ya , subplot ) ) {
323
- connectYBottom = findCounterAxisLineWidth ( ya , 'bottom' , xa , axList ) ;
282
+ connectYBottom = findCounterAxisLineWidth ( gd , ya , 'bottom' , xa , axList ) ;
324
283
yLinesYBottom = ya . _offset + ya . _length + ( connectYBottom ? pad : 0 ) ;
325
- connectYTop = findCounterAxisLineWidth ( ya , 'top' , xa , axList ) ;
284
+ connectYTop = findCounterAxisLineWidth ( gd , ya , 'top' , xa , axList ) ;
326
285
yLinesYTop = ya . _offset - ( connectYTop ? pad : 0 ) ;
327
- yLinesXLeft = getLinePosition ( ya , xa , 'left' ) ;
328
- yLinesXRight = getLinePosition ( ya , xa , 'right' ) ;
286
+ yLinesXLeft = Axes . getAxisLinePosition ( gd , ya , xa , 'left' ) ;
287
+ yLinesXRight = Axes . getAxisLinePosition ( gd , ya , xa , 'right' ) ;
329
288
330
289
extraSubplot = ( ! ya . _anchorAxis || subplot !== ya . _mainSubplot ) ;
331
- if ( extraSubplot && ( ya . mirror === 'allticks' || ya . mirror === 'all' ) ) {
332
- ya . _linepositions [ subplot ] = [ yLinesXLeft , yLinesXRight ] ;
333
- }
334
-
335
290
yPath = mainPath ( ya , yLinePath , yLinePathFree ) ;
336
291
if ( extraSubplot && ya . showline && ( ya . mirror === 'all' || ya . mirror === 'allticks' ) ) {
337
292
yPath += yLinePath ( yLinesXLeft ) + yLinePath ( yLinesXRight ) ;
338
293
}
339
294
340
295
plotinfo . ylines
341
- . style ( 'stroke-width' , ya . _lw + 'px' )
342
- . call ( Color . stroke , ya . showline ?
343
- ya . linecolor : 'rgba(0,0,0,0)' ) ;
296
+ . style ( 'stroke-width' , crispRoundLineWidth ( gd , ya ) + 'px' )
297
+ . call ( Color . stroke , ya . showline ? ya . linecolor : 'rgba(0,0,0,0)' ) ;
344
298
}
345
299
plotinfo . ylines . attr ( 'd' , yPath ) ;
346
300
}
@@ -360,9 +314,9 @@ function shouldShowLinesOrTicks(ax, subplot) {
360
314
* It's assumed that counterAx is known to overlay the subplot we're working on
361
315
* but it may not be its main axis.
362
316
*/
363
- function shouldShowLineThisSide ( ax , side , counterAx ) {
317
+ function shouldShowLineThisSide ( gd , ax , side , counterAx ) {
364
318
// does counterAx get a line at all?
365
- if ( ! counterAx . showline || ! counterAx . _lw ) return false ;
319
+ if ( ! counterAx . showline || ! crispRoundLineWidth ( gd , ax ) ) return false ;
366
320
367
321
// are we drawing *all* lines for counterAx?
368
322
if ( counterAx . mirror === 'all' || counterAx . mirror === 'allticks' ) return true ;
@@ -388,19 +342,23 @@ function shouldShowLineThisSide(ax, side, counterAx) {
388
342
* then at all other potential counteraxes on or overlaying this subplot.
389
343
* Take the line width from the first one that has a line.
390
344
*/
391
- function findCounterAxisLineWidth ( ax , side , counterAx , axList ) {
392
- if ( shouldShowLineThisSide ( ax , side , counterAx ) ) {
393
- return counterAx . _lw ;
345
+ function findCounterAxisLineWidth ( gd , ax , side , counterAx , axList ) {
346
+ if ( shouldShowLineThisSide ( gd , ax , side , counterAx ) ) {
347
+ return crispRoundLineWidth ( gd , counterAx ) ;
394
348
}
395
349
for ( var i = 0 ; i < axList . length ; i ++ ) {
396
350
var axi = axList [ i ] ;
397
- if ( axi . _mainAxis === counterAx . _mainAxis && shouldShowLineThisSide ( ax , side , axi ) ) {
398
- return axi . _lw ;
351
+ if ( axi . _mainAxis === counterAx . _mainAxis && shouldShowLineThisSide ( gd , ax , side , axi ) ) {
352
+ return crispRoundLineWidth ( gd , axi ) ;
399
353
}
400
354
}
401
355
return 0 ;
402
356
}
403
357
358
+ function crispRoundLineWidth ( gd , ax ) {
359
+ return Drawing . crispRound ( gd , ax . linewidth , 1 ) ;
360
+ }
361
+
404
362
exports . drawMainTitle = function ( gd ) {
405
363
var fullLayout = gd . _fullLayout ;
406
364
0 commit comments