@@ -561,11 +561,12 @@ function drawNumbers(gd, plotGroup, cd, opts) {
561561 . transition ( )
562562 . duration ( transitionOpts . duration )
563563 . ease ( transitionOpts . easing )
564- . each ( 'end' , function ( ) { trace . _lastValue = cd [ 0 ] . y ; onComplete && onComplete ( ) ; } )
564+ . each ( 'end' , function ( ) { onComplete && onComplete ( ) ; } )
565565 . each ( 'interrupt' , function ( ) { onComplete && onComplete ( ) ; } )
566566 . attrTween ( 'text' , function ( ) {
567567 var that = d3 . select ( this ) ;
568568 var interpolator = d3 . interpolateNumber ( cd [ 0 ] . lastY , cd [ 0 ] . y ) ;
569+ trace . _lastValue = cd [ 0 ] . y ;
569570 return function ( t ) {
570571 that . text ( bignumberPrefix + fmt ( interpolator ( t ) ) + bignumberSuffix ) ;
571572 } ;
@@ -584,7 +585,6 @@ function drawNumbers(gd, plotGroup, cd, opts) {
584585 // delta
585586 var deltaAx = mockAxis ( gd , { tickformat : trace . delta . valueformat } ) ;
586587 var deltaFmt = function ( v ) { return Axes . tickText ( deltaAx , v ) . text ; } ;
587- if ( ! trace . _deltaLastValue ) trace . _deltaLastValue = 0 ;
588588 var deltaValue = function ( d ) {
589589 var value = trace . delta . relative ? d . relativeDelta : d . delta ;
590590 return value ;
@@ -596,31 +596,37 @@ function drawNumbers(gd, plotGroup, cd, opts) {
596596 var deltaFill = function ( d ) {
597597 return d . delta >= 0 ? trace . delta . increasing . color : trace . delta . decreasing . color ;
598598 } ;
599+ if ( trace . _deltaLastValue === undefined ) {
600+ trace . _deltaLastValue = deltaValue ( cd [ 0 ] ) ;
601+ }
599602 var delta = numbers . select ( 'text.delta' ) ;
600603 delta
601604 . call ( Drawing . font , trace . delta . font )
602- . call ( Color . fill , deltaFill ( cd [ 0 ] ) ) ;
605+ . call ( Color . fill , deltaFill ( { delta : trace . _deltaLastValue } ) ) ;
603606
604607 if ( hasTransition ) {
605608 delta
606609 . transition ( )
607610 . duration ( transitionOpts . duration )
608611 . ease ( transitionOpts . easing )
609- . each ( 'end' , function ( d ) { trace . _deltaLastValue = deltaValue ( d ) ; onComplete && onComplete ( ) ; } )
610- . each ( 'interrupt' , function ( ) { onComplete && onComplete ( ) ; } )
611- . attrTween ( 'text' , function ( ) {
612+ . tween ( 'text' , function ( ) {
612613 var that = d3 . select ( this ) ;
613614 var to = deltaValue ( cd [ 0 ] ) ;
614615 var from = trace . _deltaLastValue ;
615616 var interpolator = d3 . interpolateNumber ( from , to ) ;
617+ trace . _deltaLastValue = to ;
616618 return function ( t ) {
617619 that . text ( deltaFormatText ( interpolator ( t ) ) ) ;
620+ that . call ( Color . fill , deltaFill ( { delta : interpolator ( t ) } ) ) ;
618621 } ;
619- } ) ;
622+ } )
623+ . each ( 'end' , function ( ) { onComplete && onComplete ( ) ; } )
624+ . each ( 'interrupt' , function ( ) { onComplete && onComplete ( ) ; } ) ;
620625 } else {
621626 delta . text ( function ( ) {
622627 return deltaFormatText ( deltaValue ( cd [ 0 ] ) ) ;
623- } ) ;
628+ } )
629+ . call ( Color . fill , deltaFill ( cd [ 0 ] ) ) ;
624630 }
625631
626632 delta . attr ( 'data-unformatted' , deltaFormatText ( deltaValue ( cd [ 0 ] ) ) ) ;
0 commit comments