@@ -449,15 +449,22 @@ function updatePositionAxis(gd, pa, sieve, allowMinDtick) {
449
449
Axes . expand ( pa , [ pMin , pMax ] , { padded : false } ) ;
450
450
}
451
451
452
+ function expandRange ( range , newValue ) {
453
+ if ( isNumeric ( range [ 0 ] ) ) range [ 0 ] = Math . min ( range [ 0 ] , newValue ) ;
454
+ else range [ 0 ] = newValue ;
455
+
456
+ if ( isNumeric ( range [ 1 ] ) ) range [ 1 ] = Math . max ( range [ 1 ] , newValue ) ;
457
+ else range [ 1 ] = newValue ;
458
+ }
452
459
453
460
function setBaseAndTop ( gd , sa , sieve ) {
454
461
// store these bar bases and tops in calcdata
455
462
// and make sure the size axis includes zero,
456
463
// along with the bases and tops of each bar.
457
464
var traces = sieve . traces ,
458
465
sLetter = getAxisLetter ( sa ) ,
459
- sMax = sa . l2c ( sa . c2l ( 0 ) ) ,
460
- sMin = sMax ;
466
+ s0 = sa . l2c ( sa . c2l ( 0 ) ) ,
467
+ sRange = [ s0 , s0 ] ;
461
468
462
469
for ( var i = 0 ; i < traces . length ; i ++ ) {
463
470
var trace = traces [ i ] ;
@@ -469,18 +476,12 @@ function setBaseAndTop(gd, sa, sieve) {
469
476
470
477
bar [ sLetter ] = barTop ;
471
478
472
- if ( isNumeric ( sa . c2l ( barTop ) ) ) {
473
- sMax = Math . max ( sMax , barTop ) ;
474
- sMin = Math . min ( sMin , barTop ) ;
475
- }
476
- if ( isNumeric ( sa . c2l ( barBase ) ) ) {
477
- sMax = Math . max ( sMax , barBase ) ;
478
- sMin = Math . min ( sMin , barBase ) ;
479
- }
479
+ if ( isNumeric ( sa . c2l ( barTop ) ) ) expandRange ( sRange , barTop ) ;
480
+ if ( isNumeric ( sa . c2l ( barBase ) ) ) expandRange ( sRange , barBase ) ;
480
481
}
481
482
}
482
483
483
- Axes . expand ( sa , [ sMin , sMax ] , { tozero : true , padded : true } ) ;
484
+ Axes . expand ( sa , sRange , { tozero : true , padded : true } ) ;
484
485
}
485
486
486
487
@@ -492,8 +493,8 @@ function stackBars(gd, sa, sieve) {
492
493
i , trace ,
493
494
j , bar ;
494
495
495
- var sMax = sa . l2c ( sa . c2l ( 0 ) ) ,
496
- sMin = sMax ;
496
+ var s0 = sa . l2c ( sa . c2l ( 0 ) ) ,
497
+ sRange = [ s0 , s0 ] ;
497
498
498
499
for ( i = 0 ; i < traces . length ; i ++ ) {
499
500
trace = traces [ i ] ;
@@ -512,20 +513,14 @@ function stackBars(gd, sa, sieve) {
512
513
bar [ sLetter ] = barTop ;
513
514
514
515
if ( ! barnorm ) {
515
- if ( isNumeric ( sa . c2l ( barTop ) ) ) {
516
- sMax = Math . max ( sMax , barTop ) ;
517
- sMin = Math . min ( sMin , barTop ) ;
518
- }
519
- if ( isNumeric ( sa . c2l ( barBase ) ) ) {
520
- sMax = Math . max ( sMax , barBase ) ;
521
- sMin = Math . min ( sMin , barBase ) ;
522
- }
516
+ if ( isNumeric ( sa . c2l ( barTop ) ) ) expandRange ( sRange , barTop ) ;
517
+ if ( isNumeric ( sa . c2l ( barBase ) ) ) expandRange ( sRange , barBase ) ;
523
518
}
524
519
}
525
520
}
526
521
527
522
// if barnorm is set, let normalizeBars update the axis range
528
- if ( ! barnorm ) Axes . expand ( sa , [ sMin , sMax ] , { tozero : true , padded : true } ) ;
523
+ if ( ! barnorm ) Axes . expand ( sa , sRange , { tozero : true , padded : true } ) ;
529
524
}
530
525
531
526
@@ -554,10 +549,20 @@ function normalizeBars(gd, sa, sieve) {
554
549
sLetter = getAxisLetter ( sa ) ,
555
550
sTop = ( gd . _fullLayout . barnorm === 'fraction' ) ? 1 : 100 ,
556
551
sTiny = sTop / 1e9 , // in case of rounding error in sum
557
- sMin = 0 ,
558
- sMax = ( gd . _fullLayout . barmode === 'stack' ) ? sTop : 0 ,
552
+ sMin = sa . l2c ( sa . c2l ( 0 ) ) ,
553
+ sMax = ( gd . _fullLayout . barmode === 'stack' ) ? sTop : sMin ,
554
+ sRange = [ sMin , sMax ] ,
559
555
padded = false ;
560
556
557
+ function maybeExpand ( newValue ) {
558
+ if ( isNumeric ( sa . c2l ( newValue ) ) &&
559
+ ( ( newValue < sMin - sTiny ) || ( newValue > sMax + sTiny ) || ! isNumeric ( sMin ) )
560
+ ) {
561
+ padded = true ;
562
+ expandRange ( sRange , newValue ) ;
563
+ }
564
+ }
565
+
561
566
for ( var i = 0 ; i < traces . length ; i ++ ) {
562
567
var trace = traces [ i ] ;
563
568
@@ -574,32 +579,13 @@ function normalizeBars(gd, sa, sieve) {
574
579
barTop = barBase + bar . s ;
575
580
bar [ sLetter ] = barTop ;
576
581
577
- if ( isNumeric ( sa . c2l ( barTop ) ) ) {
578
- if ( barTop < sMin - sTiny ) {
579
- padded = true ;
580
- sMin = barTop ;
581
- }
582
- if ( barTop > sMax + sTiny ) {
583
- padded = true ;
584
- sMax = barTop ;
585
- }
586
- }
587
-
588
- if ( isNumeric ( sa . c2l ( barBase ) ) ) {
589
- if ( barBase < sMin - sTiny ) {
590
- padded = true ;
591
- sMin = barBase ;
592
- }
593
- if ( barBase > sMax + sTiny ) {
594
- padded = true ;
595
- sMax = barBase ;
596
- }
597
- }
582
+ maybeExpand ( barTop ) ;
583
+ maybeExpand ( barBase ) ;
598
584
}
599
585
}
600
586
601
587
// update range of size axis
602
- Axes . expand ( sa , [ sMin , sMax ] , { tozero : true , padded : padded } ) ;
588
+ Axes . expand ( sa , sRange , { tozero : true , padded : padded } ) ;
603
589
}
604
590
605
591
0 commit comments