@@ -237,14 +237,14 @@ function plot(gd, plotinfo, cdModule, traceLayer, opts, makeOnCompleteCallback)
237237 Registry . getComponentMethod ( 'errorbars' , 'plot' ) ( gd , bartraces , plotinfo , opts ) ;
238238}
239239
240- function appendBarText ( gd , plotinfo , bar , calcTrace , i , x0 , x1 , y0 , y1 , opts , makeOnCompleteCallback ) {
240+ function appendBarText ( gd , plotinfo , bar , cd , i , x0 , x1 , y0 , y1 , opts , makeOnCompleteCallback ) {
241241 var xa = plotinfo . xaxis ;
242242 var ya = plotinfo . yaxis ;
243243
244244 var fullLayout = gd . _fullLayout ;
245245 var textPosition ;
246246
247- function appendTextNode ( bar , text , textFont ) {
247+ function appendTextNode ( bar , text , font ) {
248248 var textSelection = Lib . ensureSingle ( bar , 'text' )
249249 . text ( text )
250250 . attr ( {
@@ -254,25 +254,25 @@ function appendBarText(gd, plotinfo, bar, calcTrace, i, x0, x1, y0, y1, opts, ma
254254 // tex and regular text together
255255 'data-notex' : 1
256256 } )
257- . call ( Drawing . font , textFont )
257+ . call ( Drawing . font , font )
258258 . call ( svgTextUtils . convertToTspans , gd ) ;
259259
260260 return textSelection ;
261261 }
262262
263263 // get trace attributes
264- var trace = calcTrace [ 0 ] . trace ;
264+ var trace = cd [ 0 ] . trace ;
265265 var isHorizontal = ( trace . orientation === 'h' ) ;
266266
267- var text = getText ( fullLayout , calcTrace , i , xa , ya ) ;
267+ var text = getText ( fullLayout , cd , i , xa , ya ) ;
268268 textPosition = getTextPosition ( trace , i ) ;
269269
270270 // compute text position
271271 var inStackOrRelativeMode =
272272 opts . mode === 'stack' ||
273273 opts . mode === 'relative' ;
274274
275- var calcBar = calcTrace [ i ] ;
275+ var calcBar = cd [ i ] ;
276276 var isOutmostBar = ! inStackOrRelativeMode || calcBar . _outmost ;
277277
278278 if ( ! text ||
@@ -285,7 +285,7 @@ function appendBarText(gd, plotinfo, bar, calcTrace, i, x0, x1, y0, y1, opts, ma
285285 }
286286
287287 var layoutFont = fullLayout . font ;
288- var barColor = style . getBarColor ( calcTrace [ i ] , trace ) ;
288+ var barColor = style . getBarColor ( cd [ i ] , trace ) ;
289289 var insideTextFont = style . getInsideTextFont ( trace , i , layoutFont , barColor ) ;
290290 var outsideTextFont = style . getOutsideTextFont ( trace , i , layoutFont ) ;
291291
@@ -318,6 +318,7 @@ function appendBarText(gd, plotinfo, bar, calcTrace, i, x0, x1, y0, y1, opts, ma
318318 var textBB ;
319319 var textWidth ;
320320 var textHeight ;
321+ var font ;
321322
322323 if ( textPosition === 'outside' ) {
323324 if ( ! isOutmostBar && ! calcBar . hasB ) textPosition = 'inside' ;
@@ -327,7 +328,10 @@ function appendBarText(gd, plotinfo, bar, calcTrace, i, x0, x1, y0, y1, opts, ma
327328 if ( isOutmostBar ) {
328329 // draw text using insideTextFont and check if it fits inside bar
329330 textPosition = 'inside' ;
330- textSelection = appendTextNode ( bar , text , insideTextFont ) ;
331+
332+ font = Lib . ensureUniformFontSize ( gd , insideTextFont ) ;
333+
334+ textSelection = appendTextNode ( bar , text , font ) ;
331335
332336 textBB = Drawing . bBox ( textSelection . node ( ) ) ,
333337 textWidth = textBB . width ,
@@ -357,9 +361,9 @@ function appendBarText(gd, plotinfo, bar, calcTrace, i, x0, x1, y0, y1, opts, ma
357361 }
358362
359363 if ( ! textSelection ) {
360- textSelection = appendTextNode ( bar , text ,
361- ( textPosition === 'outside' ) ?
362- outsideTextFont : insideTextFont ) ;
364+ font = Lib . ensureUniformFontSize ( gd , ( textPosition === 'outside' ) ? outsideTextFont : insideTextFont ) ;
365+
366+ textSelection = appendTextNode ( bar , text , font ) ;
363367
364368 var currentTransform = textSelection . attr ( 'transform' ) ;
365369 textSelection . attr ( 'transform' , '' ) ;
@@ -374,32 +378,61 @@ function appendBarText(gd, plotinfo, bar, calcTrace, i, x0, x1, y0, y1, opts, ma
374378 }
375379 }
376380
381+ var angle = trace . textangle ;
382+
377383 // compute text transform
378384 var transform , constrained ;
379385 if ( textPosition === 'outside' ) {
380386 constrained =
381387 trace . constraintext === 'both' ||
382388 trace . constraintext === 'outside' ;
383389
384- transform = Lib . getTextTransform ( toMoveOutsideBar ( x0 , x1 , y0 , y1 , textBB , {
390+ transform = toMoveOutsideBar ( x0 , x1 , y0 , y1 , textBB , {
385391 isHorizontal : isHorizontal ,
386392 constrained : constrained ,
387- angle : trace . textangle
388- } ) ) ;
393+ angle : angle
394+ } ) ;
389395 } else {
390396 constrained =
391397 trace . constraintext === 'both' ||
392398 trace . constraintext === 'inside' ;
393399
394- transform = Lib . getTextTransform ( toMoveInsideBar ( x0 , x1 , y0 , y1 , textBB , {
400+ transform = toMoveInsideBar ( x0 , x1 , y0 , y1 , textBB , {
395401 isHorizontal : isHorizontal ,
396402 constrained : constrained ,
397- angle : trace . textangle ,
403+ angle : angle ,
398404 anchor : trace . insidetextanchor
399- } ) ) ;
405+ } ) ;
400406 }
401407
402- transition ( textSelection , opts , makeOnCompleteCallback ) . attr ( 'transform' , transform ) ;
408+ transform . fontSize = font . size ;
409+ recordMinTextSize ( trace . type , transform , fullLayout ) ;
410+ calcBar . transform = transform ;
411+
412+ transition ( textSelection , opts , makeOnCompleteCallback )
413+ . attr ( 'transform' , Lib . getTextTransform ( transform ) ) ;
414+ }
415+
416+ function recordMinTextSize (
417+ traceType , // in
418+ transform , // inout
419+ fullLayout // inout
420+ ) {
421+ if ( fullLayout . uniformtext . mode ) {
422+ var minKey = '_' + traceType + 'Text_minsize' ;
423+ var minSize = fullLayout . uniformtext . minsize ;
424+ var size = transform . scale * transform . fontSize ;
425+
426+ transform . hide = size < minSize ;
427+
428+ fullLayout [ minKey ] = fullLayout [ minKey ] || Infinity ;
429+ if ( ! transform . hide ) {
430+ fullLayout [ minKey ] = Math . min (
431+ fullLayout [ minKey ] ,
432+ Math . max ( size , minSize )
433+ ) ;
434+ }
435+ }
403436}
404437
405438function getRotateFromAngle ( angle ) {
@@ -549,15 +582,15 @@ function toMoveOutsideBar(x0, x1, y0, y1, textBB, opts) {
549582 } ;
550583}
551584
552- function getText ( fullLayout , calcTrace , index , xa , ya ) {
553- var trace = calcTrace [ 0 ] . trace ;
585+ function getText ( fullLayout , cd , index , xa , ya ) {
586+ var trace = cd [ 0 ] . trace ;
554587 var texttemplate = trace . texttemplate ;
555588
556589 var value ;
557590 if ( texttemplate ) {
558- value = calcTexttemplate ( fullLayout , calcTrace , index , xa , ya ) ;
591+ value = calcTexttemplate ( fullLayout , cd , index , xa , ya ) ;
559592 } else if ( trace . textinfo ) {
560- value = calcTextinfo ( calcTrace , index , xa , ya ) ;
593+ value = calcTextinfo ( cd , index , xa , ya ) ;
561594 } else {
562595 value = helpers . getValue ( trace . text , index ) ;
563596 }
@@ -570,8 +603,8 @@ function getTextPosition(trace, index) {
570603 return helpers . coerceEnumerated ( attributeTextPosition , value ) ;
571604}
572605
573- function calcTexttemplate ( fullLayout , calcTrace , index , xa , ya ) {
574- var trace = calcTrace [ 0 ] . trace ;
606+ function calcTexttemplate ( fullLayout , cd , index , xa , ya ) {
607+ var trace = cd [ 0 ] . trace ;
575608 var texttemplate = Lib . castOption ( trace , index , 'texttemplate' ) ;
576609 if ( ! texttemplate ) return '' ;
577610 var isWaterfall = ( trace . type === 'waterfall' ) ;
@@ -599,7 +632,7 @@ function calcTexttemplate(fullLayout, calcTrace, index, xa, ya) {
599632 return tickText ( vAxis , + v , true ) . text ;
600633 }
601634
602- var cdi = calcTrace [ index ] ;
635+ var cdi = cd [ index ] ;
603636 var obj = { } ;
604637
605638 obj . label = cdi . p ;
@@ -640,8 +673,8 @@ function calcTexttemplate(fullLayout, calcTrace, index, xa, ya) {
640673 return Lib . texttemplateString ( texttemplate , obj , fullLayout . _d3locale , pt , obj , trace . _meta || { } ) ;
641674}
642675
643- function calcTextinfo ( calcTrace , index , xa , ya ) {
644- var trace = calcTrace [ 0 ] . trace ;
676+ function calcTextinfo ( cd , index , xa , ya ) {
677+ var trace = cd [ 0 ] . trace ;
645678 var isHorizontal = ( trace . orientation === 'h' ) ;
646679 var isWaterfall = ( trace . type === 'waterfall' ) ;
647680 var isFunnel = ( trace . type === 'funnel' ) ;
@@ -657,7 +690,7 @@ function calcTextinfo(calcTrace, index, xa, ya) {
657690 }
658691
659692 var textinfo = trace . textinfo ;
660- var cdi = calcTrace [ index ] ;
693+ var cdi = cd [ index ] ;
661694
662695 var parts = textinfo . split ( '+' ) ;
663696 var text = [ ] ;
@@ -666,7 +699,7 @@ function calcTextinfo(calcTrace, index, xa, ya) {
666699 var hasFlag = function ( flag ) { return parts . indexOf ( flag ) !== - 1 ; } ;
667700
668701 if ( hasFlag ( 'label' ) ) {
669- text . push ( formatLabel ( calcTrace [ index ] . p ) ) ;
702+ text . push ( formatLabel ( cd [ index ] . p ) ) ;
670703 }
671704
672705 if ( hasFlag ( 'text' ) ) {
@@ -717,5 +750,5 @@ function calcTextinfo(calcTrace, index, xa, ya) {
717750module . exports = {
718751 plot : plot ,
719752 toMoveInsideBar : toMoveInsideBar ,
720- toMoveOutsideBar : toMoveOutsideBar
753+ recordMinTextSize : recordMinTextSize
721754} ;
0 commit comments