@@ -394,21 +394,21 @@ exports.labelFormatter = function(gd, cd0) {
394
394
var trace = cd0 . trace ;
395
395
var contours = trace . contours ;
396
396
397
+ var formatAxis = {
398
+ type : 'linear' ,
399
+ _id : 'ycontour' ,
400
+ showexponent : 'all' ,
401
+ exponentformat : 'B'
402
+ } ;
403
+
397
404
if ( contours . labelformat ) {
398
- return fullLayout . _d3locale . numberFormat ( contours . labelformat ) ;
405
+ formatAxis . tickformat = contours . labelformat ;
406
+ setConvert ( formatAxis , fullLayout ) ;
399
407
} else {
400
- var formatAxis ;
401
408
var cOpts = Colorscale . extractOpts ( trace ) ;
402
409
if ( cOpts && cOpts . colorbar && cOpts . colorbar . _axis ) {
403
410
formatAxis = cOpts . colorbar . _axis ;
404
411
} else {
405
- formatAxis = {
406
- type : 'linear' ,
407
- _id : 'ycontour' ,
408
- showexponent : 'all' ,
409
- exponentformat : 'B'
410
- } ;
411
-
412
412
if ( contours . type === 'constraint' ) {
413
413
var value = contours . value ;
414
414
if ( Array . isArray ( value ) ) {
@@ -429,22 +429,24 @@ exports.labelFormatter = function(gd, cd0) {
429
429
formatAxis . _tmin = null ;
430
430
formatAxis . _tmax = null ;
431
431
}
432
- return function ( v ) {
433
- return Axes . tickText ( formatAxis , v ) . text ;
434
- } ;
435
432
}
433
+
434
+ return function ( v ) { return Axes . tickText ( formatAxis , v ) . text ; } ;
436
435
} ;
437
436
438
437
exports . calcTextOpts = function ( level , contourFormat , dummyText , gd ) {
439
438
var text = contourFormat ( level ) ;
440
439
dummyText . text ( text )
441
440
. call ( svgTextUtils . convertToTspans , gd ) ;
442
- var bBox = Drawing . bBox ( dummyText . node ( ) , true ) ;
441
+
442
+ var el = dummyText . node ( ) ;
443
+ var bBox = Drawing . bBox ( el , true ) ;
443
444
444
445
return {
445
446
text : text ,
446
447
width : bBox . width ,
447
448
height : bBox . height ,
449
+ fontSize : + ( el . style [ 'font-size' ] . replace ( 'px' , '' ) ) ,
448
450
level : level ,
449
451
dy : ( bBox . top + bBox . bottom ) / 2
450
452
} ;
@@ -544,24 +546,29 @@ function locationCost(loc, textOpts, labelData, bounds) {
544
546
}
545
547
546
548
exports . addLabelData = function ( loc , textOpts , labelData , labelClipPathData ) {
547
- var halfWidth = textOpts . width / 2 ;
548
- var halfHeight = textOpts . height / 2 ;
549
+ var fontSize = textOpts . fontSize ;
550
+ var w = textOpts . width + fontSize / 3 ;
551
+ var h = Math . max ( 0 , textOpts . height - fontSize / 3 ) ;
549
552
550
553
var x = loc . x ;
551
554
var y = loc . y ;
552
555
var theta = loc . theta ;
553
556
554
557
var sin = Math . sin ( theta ) ;
555
558
var cos = Math . cos ( theta ) ;
556
- var dxw = halfWidth * cos ;
557
- var dxh = halfHeight * sin ;
558
- var dyw = halfWidth * sin ;
559
- var dyh = - halfHeight * cos ;
559
+
560
+ var rotateXY = function ( dx , dy ) {
561
+ return [
562
+ x + dx * cos - dy * sin ,
563
+ y + dx * sin + dy * cos
564
+ ] ;
565
+ } ;
566
+
560
567
var bBoxPts = [
561
- [ x - dxw - dxh , y - dyw - dyh ] ,
562
- [ x + dxw - dxh , y + dyw - dyh ] ,
563
- [ x + dxw + dxh , y + dyw + dyh ] ,
564
- [ x - dxw + dxh , y - dyw + dyh ] ,
568
+ rotateXY ( - w / 2 , - h / 2 ) ,
569
+ rotateXY ( - w / 2 , h / 2 ) ,
570
+ rotateXY ( w / 2 , h / 2 ) ,
571
+ rotateXY ( w / 2 , - h / 2 )
565
572
] ;
566
573
567
574
labelData . push ( {
@@ -571,8 +578,8 @@ exports.addLabelData = function(loc, textOpts, labelData, labelClipPathData) {
571
578
dy : textOpts . dy ,
572
579
theta : theta ,
573
580
level : textOpts . level ,
574
- width : textOpts . width ,
575
- height : textOpts . height
581
+ width : w ,
582
+ height : h
576
583
} ) ;
577
584
578
585
labelClipPathData . push ( bBoxPts ) ;
0 commit comments