@@ -394,21 +394,21 @@ exports.labelFormatter = function(gd, cd0) {
394394 var trace = cd0 . trace ;
395395 var contours = trace . contours ;
396396
397+ var formatAxis = {
398+ type : 'linear' ,
399+ _id : 'ycontour' ,
400+ showexponent : 'all' ,
401+ exponentformat : 'B'
402+ } ;
403+
397404 if ( contours . labelformat ) {
398- return fullLayout . _d3locale . numberFormat ( contours . labelformat ) ;
405+ formatAxis . tickformat = contours . labelformat ;
406+ setConvert ( formatAxis , fullLayout ) ;
399407 } else {
400- var formatAxis ;
401408 var cOpts = Colorscale . extractOpts ( trace ) ;
402409 if ( cOpts && cOpts . colorbar && cOpts . colorbar . _axis ) {
403410 formatAxis = cOpts . colorbar . _axis ;
404411 } else {
405- formatAxis = {
406- type : 'linear' ,
407- _id : 'ycontour' ,
408- showexponent : 'all' ,
409- exponentformat : 'B'
410- } ;
411-
412412 if ( contours . type === 'constraint' ) {
413413 var value = contours . value ;
414414 if ( Array . isArray ( value ) ) {
@@ -429,22 +429,24 @@ exports.labelFormatter = function(gd, cd0) {
429429 formatAxis . _tmin = null ;
430430 formatAxis . _tmax = null ;
431431 }
432- return function ( v ) {
433- return Axes . tickText ( formatAxis , v ) . text ;
434- } ;
435432 }
433+
434+ return function ( v ) { return Axes . tickText ( formatAxis , v ) . text ; } ;
436435} ;
437436
438437exports . calcTextOpts = function ( level , contourFormat , dummyText , gd ) {
439438 var text = contourFormat ( level ) ;
440439 dummyText . text ( text )
441440 . 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 ) ;
443444
444445 return {
445446 text : text ,
446447 width : bBox . width ,
447448 height : bBox . height ,
449+ fontSize : + ( el . style [ 'font-size' ] . replace ( 'px' , '' ) ) ,
448450 level : level ,
449451 dy : ( bBox . top + bBox . bottom ) / 2
450452 } ;
@@ -544,24 +546,29 @@ function locationCost(loc, textOpts, labelData, bounds) {
544546}
545547
546548exports . 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 ) ;
549552
550553 var x = loc . x ;
551554 var y = loc . y ;
552555 var theta = loc . theta ;
553556
554557 var sin = Math . sin ( theta ) ;
555558 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+
560567 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 )
565572 ] ;
566573
567574 labelData . push ( {
@@ -571,8 +578,8 @@ exports.addLabelData = function(loc, textOpts, labelData, labelClipPathData) {
571578 dy : textOpts . dy ,
572579 theta : theta ,
573580 level : textOpts . level ,
574- width : textOpts . width ,
575- height : textOpts . height
581+ width : w ,
582+ height : h
576583 } ) ;
577584
578585 labelClipPathData . push ( bBoxPts ) ;
0 commit comments