@@ -215,7 +215,6 @@ function appendBarText(gd, bar, calcTrace, i, x0, x1, y0, y1) {
215
215
216
216
barWidth = Math . abs ( x1 - x0 ) - 2 * TEXTPAD , // padding excluded
217
217
barHeight = Math . abs ( y1 - y0 ) - 2 * TEXTPAD , // padding excluded
218
- barIsTooSmall = ( barWidth <= 0 || barHeight <= 0 ) ,
219
218
220
219
textSelection ,
221
220
textBB ,
@@ -226,10 +225,6 @@ function appendBarText(gd, bar, calcTrace, i, x0, x1, y0, y1) {
226
225
if ( ! isOutmostBar ) textPosition = 'inside' ;
227
226
}
228
227
229
- if ( textPosition === 'inside' ) {
230
- if ( barIsTooSmall ) return ;
231
- }
232
-
233
228
if ( textPosition === 'auto' ) {
234
229
if ( isOutmostBar ) {
235
230
// draw text using insideTextFont and check if it fits inside bar
@@ -253,8 +248,7 @@ function appendBarText(gd, bar, calcTrace, i, x0, x1, y0, y1) {
253
248
textSelection = null ;
254
249
}
255
250
}
256
- else if ( ! barIsTooSmall ) textPosition = 'inside' ;
257
- else return ;
251
+ else textPosition = 'inside' ;
258
252
}
259
253
260
254
if ( ! textSelection ) {
@@ -292,13 +286,22 @@ function getTransformToMoveInsideBar(x0, x1, y0, y1, textBB, orientation) {
292
286
textHeight = textBB . height ,
293
287
textX = ( textBB . left + textBB . right ) / 2 ,
294
288
textY = ( textBB . top + textBB . bottom ) / 2 ,
295
- barWidth = Math . abs ( x1 - x0 ) - 2 * TEXTPAD ,
296
- barHeight = Math . abs ( y1 - y0 ) - 2 * TEXTPAD ,
289
+ barWidth = Math . abs ( x1 - x0 ) ,
290
+ barHeight = Math . abs ( y1 - y0 ) ,
297
291
targetWidth ,
298
292
targetHeight ,
299
293
targetX ,
300
294
targetY ;
301
295
296
+ // apply text padding
297
+ var textpad ;
298
+ if ( barWidth > 2 * TEXTPAD && barHeight > 2 * TEXTPAD ) {
299
+ textpad = TEXTPAD ;
300
+ barWidth -= 2 * textpad ;
301
+ barHeight -= 2 * textpad ;
302
+ }
303
+ else textpad = 0 ;
304
+
302
305
// compute rotation and scale
303
306
var needsRotating ,
304
307
scale ;
@@ -337,23 +340,23 @@ function getTransformToMoveInsideBar(x0, x1, y0, y1, textBB, orientation) {
337
340
if ( orientation === 'h' ) {
338
341
if ( x1 < x0 ) {
339
342
// bar end is on the left hand side
340
- targetX = x1 + TEXTPAD + targetWidth / 2 ;
343
+ targetX = x1 + textpad + targetWidth / 2 ;
341
344
targetY = ( y0 + y1 ) / 2 ;
342
345
}
343
346
else {
344
- targetX = x1 - TEXTPAD - targetWidth / 2 ;
347
+ targetX = x1 - textpad - targetWidth / 2 ;
345
348
targetY = ( y0 + y1 ) / 2 ;
346
349
}
347
350
}
348
351
else {
349
352
if ( y1 > y0 ) {
350
353
// bar end is on the bottom
351
354
targetX = ( x0 + x1 ) / 2 ;
352
- targetY = y1 - TEXTPAD - targetHeight / 2 ;
355
+ targetY = y1 - textpad - targetHeight / 2 ;
353
356
}
354
357
else {
355
358
targetX = ( x0 + x1 ) / 2 ;
356
- targetY = y1 + TEXTPAD + targetHeight / 2 ;
359
+ targetY = y1 + textpad + targetHeight / 2 ;
357
360
}
358
361
}
359
362
@@ -367,16 +370,23 @@ function getTransformToMoveOutsideBar(x0, x1, y0, y1, textBB, orientation) {
367
370
textWidth ,
368
371
textHeight ;
369
372
if ( orientation === 'h' ) {
370
- barWidth = Math . abs ( y1 - y0 ) - 2 * TEXTPAD ;
373
+ barWidth = Math . abs ( y1 - y0 ) ;
371
374
textWidth = textBB . height ;
372
375
textHeight = textBB . width ;
373
376
}
374
377
else {
375
- barWidth = Math . abs ( x1 - x0 ) - 2 * TEXTPAD ;
378
+ barWidth = Math . abs ( x1 - x0 ) ;
376
379
textWidth = textBB . width ;
377
380
textHeight = textBB . height ;
378
381
}
379
382
383
+ // apply text padding
384
+ var textpad ;
385
+ if ( barWidth > 2 * TEXTPAD ) {
386
+ textpad = TEXTPAD ;
387
+ barWidth -= 2 * textpad ;
388
+ }
389
+
380
390
// compute rotation and scale
381
391
var needsRotating ,
382
392
scale ;
@@ -422,23 +432,23 @@ function getTransformToMoveOutsideBar(x0, x1, y0, y1, textBB, orientation) {
422
432
if ( orientation === 'h' ) {
423
433
if ( x1 < x0 ) {
424
434
// bar end is on the left hand side
425
- targetX = x1 - TEXTPAD - targetWidth / 2 ;
435
+ targetX = x1 - textpad - targetWidth / 2 ;
426
436
targetY = ( y0 + y1 ) / 2 ;
427
437
}
428
438
else {
429
- targetX = x1 + TEXTPAD + targetWidth / 2 ;
439
+ targetX = x1 + textpad + targetWidth / 2 ;
430
440
targetY = ( y0 + y1 ) / 2 ;
431
441
}
432
442
}
433
443
else {
434
444
if ( y1 > y0 ) {
435
445
// bar end is on the bottom
436
446
targetX = ( x0 + x1 ) / 2 ;
437
- targetY = y1 + TEXTPAD + targetHeight / 2 ;
447
+ targetY = y1 + textpad + targetHeight / 2 ;
438
448
}
439
449
else {
440
450
targetX = ( x0 + x1 ) / 2 ;
441
- targetY = y1 - TEXTPAD - targetHeight / 2 ;
451
+ targetY = y1 - textpad - targetHeight / 2 ;
442
452
}
443
453
}
444
454
0 commit comments