@@ -1802,14 +1802,11 @@ axes.drawOne = function(gd, ax, opts) {
1802
1802
// TODO: mirror labels, esp for subplots
1803
1803
1804
1804
seq . push ( function ( ) {
1805
- var labelFns = axes . makeLabelFns ( ax , mainLinePosition ) ;
1806
1805
return axes . drawLabels ( gd , ax , {
1807
1806
vals : vals ,
1808
1807
layer : mainAxLayer ,
1809
1808
transFn : transFn ,
1810
- labelXFn : labelFns . labelXFn ,
1811
- labelYFn : labelFns . labelYFn ,
1812
- labelAnchorFn : labelFns . labelAnchorFn ,
1809
+ labelFns : axes . makeLabelFns ( ax , mainLinePosition )
1813
1810
} ) ;
1814
1811
} ) ;
1815
1812
@@ -1821,8 +1818,6 @@ axes.drawOne = function(gd, ax, opts) {
1821
1818
seq . push ( function ( ) {
1822
1819
labelLength += getLabelLevelSpan ( ax , axId + 'tick' ) + pad ;
1823
1820
labelLength += ax . _tickAngles [ axId + 'tick' ] ? ax . tickfont . size * LINE_SPACING : 0 ;
1824
- var secondaryPosition = mainLinePosition + labelLength * sgn ;
1825
- var secondaryLabelFns = axes . makeLabelFns ( ax , secondaryPosition ) ;
1826
1821
1827
1822
return axes . drawLabels ( gd , ax , {
1828
1823
vals : getSecondaryLabelVals ( ax , vals ) ,
@@ -1831,9 +1826,7 @@ axes.drawOne = function(gd, ax, opts) {
1831
1826
repositionOnUpdate : true ,
1832
1827
secondary : true ,
1833
1828
transFn : transFn ,
1834
- labelXFn : secondaryLabelFns . labelXFn ,
1835
- labelYFn : secondaryLabelFns . labelYFn ,
1836
- labelAnchorFn : secondaryLabelFns . labelAnchorFn ,
1829
+ labelFns : axes . makeLabelFns ( ax , mainLinePosition + labelLength * sgn )
1837
1830
} ) ;
1838
1831
} ) ;
1839
1832
@@ -2178,9 +2171,9 @@ axes.makeTickPath = function(ax, shift, sgn, len) {
2178
2171
* @param {number } shift
2179
2172
* @param {number } angle [in degrees] ...
2180
2173
* @return {object }
2181
- * - {fn} labelXFn
2182
- * - {fn} labelYFn
2183
- * - {fn} labelAnchorFn
2174
+ * - {fn} xFn
2175
+ * - {fn} yFn
2176
+ * - {fn} anchorFn
2184
2177
* - {number} labelStandoff (gap parallel to ticks)
2185
2178
* - {number} labelShift (gap perpendicular to ticks)
2186
2179
*/
@@ -2210,15 +2203,16 @@ axes.makeLabelFns = function(ax, shift, angle) {
2210
2203
} ;
2211
2204
2212
2205
var x0 , y0 , ff , flipIt ;
2206
+
2213
2207
if ( axLetter === 'x' ) {
2214
2208
flipIt = ax . side === 'bottom' ? 1 : - 1 ;
2215
2209
x0 = labelShift * flipIt ;
2216
2210
y0 = shift + labelStandoff * flipIt ;
2217
2211
ff = ax . side === 'bottom' ? 1 : - 0.2 ;
2218
2212
2219
- out . labelXFn = function ( d ) { return d . dx + x0 ; } ;
2220
- out . labelYFn = function ( d ) { return d . dy + y0 + d . fontSize * ff ; } ;
2221
- out . labelAnchorFn = function ( a ) {
2213
+ out . xFn = function ( d ) { return d . dx + x0 ; } ;
2214
+ out . yFn = function ( d ) { return d . dy + y0 + d . fontSize * ff ; } ;
2215
+ out . anchorFn = function ( d , a ) {
2222
2216
if ( ! isNumeric ( a ) || a === 0 || a === 180 ) {
2223
2217
return 'middle' ;
2224
2218
}
@@ -2230,9 +2224,9 @@ axes.makeLabelFns = function(ax, shift, angle) {
2230
2224
y0 = - labelShift * flipIt ;
2231
2225
ff = Math . abs ( ax . tickangle ) === 90 ? 0.5 : 0 ;
2232
2226
2233
- out . labelXFn = function ( d ) { return d . dx + shift + ( x0 + d . fontSize * ff ) * flipIt ; } ;
2234
- out . labelYFn = function ( d ) { return d . dy + y0 + d . fontSize * MID_SHIFT ; } ;
2235
- out . labelAnchorFn = function ( a ) {
2227
+ out . xFn = function ( d ) { return d . dx + shift + ( x0 + d . fontSize * ff ) * flipIt ; } ;
2228
+ out . yFn = function ( d ) { return d . dy + y0 + d . fontSize * MID_SHIFT ; } ;
2229
+ out . anchorFn = function ( d , a ) {
2236
2230
if ( isNumeric ( a ) && Math . abs ( a ) === 90 ) {
2237
2231
return 'middle' ;
2238
2232
}
@@ -2411,10 +2405,11 @@ axes.drawZeroLine = function(gd, ax, opts) {
2411
2405
* - {string (optional)} cls (node className)
2412
2406
* - {boolean} repositionOnUpdate (set to true to reposition update selection)
2413
2407
* - {boolean} secondary
2414
- * - {fn} transFn
2415
- * - {fn} labelXFn
2416
- * - {fn} labelYFn
2417
- * - {fn} labelAnchorFn
2408
+ * - {object} labelFns
2409
+ * + {fn} transFn
2410
+ * + {fn} labelXFn
2411
+ * + {fn} labelYFn
2412
+ * + {fn} labelAnchorFn
2418
2413
*/
2419
2414
axes . drawLabels = function ( gd , ax , opts ) {
2420
2415
opts = opts || { } ;
@@ -2423,9 +2418,7 @@ axes.drawLabels = function(gd, ax, opts) {
2423
2418
var axLetter = axId . charAt ( 0 ) ;
2424
2419
var cls = opts . cls || axId + 'tick' ;
2425
2420
var vals = opts . vals ;
2426
- var labelXFn = opts . labelXFn ;
2427
- var labelYFn = opts . labelYFn ;
2428
- var labelAnchorFn = opts . labelAnchorFn ;
2421
+ var labelFns = opts . labelFns ;
2429
2422
var tickAngle = opts . secondary ? 0 : ax . tickangle ;
2430
2423
var lastAngle = ( ax . _tickAngles || { } ) [ cls ] ;
2431
2424
@@ -2445,7 +2438,7 @@ axes.drawLabels = function(gd, ax, opts) {
2445
2438
var newPromise = gd . _promises . length ;
2446
2439
2447
2440
thisLabel
2448
- . call ( svgTextUtils . positionText , labelXFn ( d ) , labelYFn ( d ) )
2441
+ . call ( svgTextUtils . positionText , labelFns . xFn ( d ) , labelFns . yFn ( d ) )
2449
2442
. call ( Drawing . font , d . font , d . fontSize , d . fontColor )
2450
2443
. text ( d . text )
2451
2444
. call ( svgTextUtils . convertToTspans , gd ) ;
@@ -2469,7 +2462,7 @@ axes.drawLabels = function(gd, ax, opts) {
2469
2462
if ( opts . repositionOnUpdate ) {
2470
2463
tickLabels . each ( function ( d ) {
2471
2464
d3 . select ( this ) . select ( 'text' )
2472
- . call ( svgTextUtils . positionText , labelXFn ( d ) , labelYFn ( d ) ) ;
2465
+ . call ( svgTextUtils . positionText , labelFns . xFn ( d ) , labelFns . yFn ( d ) ) ;
2473
2466
} ) ;
2474
2467
}
2475
2468
@@ -2497,12 +2490,12 @@ axes.drawLabels = function(gd, ax, opts) {
2497
2490
s . each ( function ( d ) {
2498
2491
var thisLabel = d3 . select ( this ) ;
2499
2492
var mathjaxGroup = thisLabel . select ( '.text-math-group' ) ;
2500
- var anchor = labelAnchorFn ( angle , d ) ;
2493
+ var anchor = labelFns . anchorFn ( d , angle ) ;
2501
2494
2502
2495
var transform = opts . transFn . call ( thisLabel . node ( ) , d ) +
2503
2496
( ( isNumeric ( angle ) && + angle !== 0 ) ?
2504
- ( ' rotate(' + angle + ',' + labelXFn ( d ) + ',' +
2505
- ( labelYFn ( d ) - d . fontSize / 2 ) + ')' ) :
2497
+ ( ' rotate(' + angle + ',' + labelFns . xFn ( d ) + ',' +
2498
+ ( labelFns . yFn ( d ) - d . fontSize / 2 ) + ')' ) :
2506
2499
'' ) ;
2507
2500
2508
2501
var anchorHeight = getAnchorHeight (
0 commit comments