@@ -165,7 +165,8 @@ function appendBarText(gd, bar, calcTrace, i, x0, x1, y0, y1) {
165
165
}
166
166
167
167
// get trace attributes
168
- var trace = calcTrace [ 0 ] . trace ;
168
+ var trace = calcTrace [ 0 ] . trace ,
169
+ orientation = trace . orientation ;
169
170
170
171
var text = getText ( trace , i ) ;
171
172
if ( ! text ) return ;
@@ -211,8 +212,12 @@ function appendBarText(gd, bar, calcTrace, i, x0, x1, y0, y1) {
211
212
fitsInside =
212
213
( textWidth <= barWidth && textHeight <= barHeight ) ,
213
214
fitsInsideIfRotated =
214
- ( textWidth <= barHeight && textHeight <= barWidth ) ;
215
- if ( textHasSize && ( fitsInside || fitsInsideIfRotated ) ) {
215
+ ( textWidth <= barHeight && textHeight <= barWidth ) ,
216
+ fitsInsideIfShrunk = ( orientation === 'h' ) ?
217
+ ( barWidth >= textWidth * ( barHeight / textHeight ) ) :
218
+ ( barHeight >= textHeight * ( barWidth / textWidth ) ) ;
219
+ if ( textHasSize &&
220
+ ( fitsInside || fitsInsideIfRotated || fitsInsideIfShrunk ) ) {
216
221
textPosition = 'inside' ;
217
222
}
218
223
else {
@@ -243,11 +248,11 @@ function appendBarText(gd, bar, calcTrace, i, x0, x1, y0, y1) {
243
248
var transform ;
244
249
if ( textPosition === 'outside' ) {
245
250
transform = getTransformToMoveOutsideBar ( x0 , x1 , y0 , y1 , textBB ,
246
- trace . orientation ) ;
251
+ orientation ) ;
247
252
}
248
253
else {
249
254
transform = getTransformToMoveInsideBar ( x0 , x1 , y0 , y1 , textBB ,
250
- trace . orientation ) ;
255
+ orientation ) ;
251
256
}
252
257
253
258
textSelection . attr ( 'transform' , transform ) ;
@@ -268,7 +273,7 @@ function getTransformToMoveInsideBar(x0, x1, y0, y1, textBB, orientation) {
268
273
269
274
// apply text padding
270
275
var textpad ;
271
- if ( barWidth > 2 * TEXTPAD && barHeight > 2 * TEXTPAD ) {
276
+ if ( barWidth > ( 2 * TEXTPAD ) && barHeight > ( 2 * TEXTPAD ) ) {
272
277
textpad = TEXTPAD ;
273
278
barWidth -= 2 * textpad ;
274
279
barHeight -= 2 * textpad ;
0 commit comments