9
9
10
10
'use strict' ;
11
11
12
+
12
13
var d3 = require ( 'd3' ) ;
13
14
var m4FromQuat = require ( 'gl-mat4/fromQuat' ) ;
14
15
var isNumeric = require ( 'fast-isnumeric' ) ;
@@ -2563,6 +2564,7 @@ Plotly.transition = function(gd, data, layout, traceIndices, transitionConfig) {
2563
2564
var transitionedTraces = [ ] ;
2564
2565
2565
2566
function prepareTransitions ( ) {
2567
+ var plotinfo , i ;
2566
2568
for ( i = 0 ; i < traceIndices . length ; i ++ ) {
2567
2569
var traceIdx = traceIndices [ i ] ;
2568
2570
var trace = gd . _fullData [ traceIdx ] ;
@@ -2586,30 +2588,46 @@ Plotly.transition = function(gd, data, layout, traceIndices, transitionConfig) {
2586
2588
Lib . extendDeepNoArrays ( gd . data [ traceIndices [ i ] ] , update ) ;
2587
2589
}
2588
2590
2589
- Plots . supplyDataDefaults ( gd . data , gd . _fullData , gd . _fullLayout ) ;
2591
+ // Supply defaults after applying the incoming properties. Note that any attempt
2592
+ // to simplify this step and reduce the amount of work resulted in the reconstruction
2593
+ // of essentially the whole supplyDefaults step, so that it seems sensible to just use
2594
+ // supplyDefaults even though it's heavier than would otherwise be desired for
2595
+ // transitions:
2596
+ Plots . supplyDefaults ( gd ) ;
2590
2597
2591
- // TODO: Add logic that computes transitionedTraces to avoid unnecessary work while
2592
- // still handling things like box plots that are interrelated.
2593
- // doCalcdata(gd, transitionedTraces);
2598
+ //Plotly.Axes.saveRangeInitial(gd, true);
2599
+
2600
+ // This step fies the .xaxis and .yaxis references that otherwise
2601
+ // aren't updated by the supplyDefaults step:
2602
+ var subplots = Plotly . Axes . getSubplots ( gd ) ;
2603
+ for ( i = 0 ; i < subplots . length ; i ++ ) {
2604
+ plotinfo = gd . _fullLayout . _plots [ subplots [ i ] ] ;
2605
+ plotinfo . xaxis = plotinfo . x ( ) ;
2606
+ plotinfo . yaxis = plotinfo . y ( ) ;
2607
+ }
2594
2608
2595
2609
doCalcdata ( gd ) ;
2596
2610
2597
2611
ErrorBars . calc ( gd ) ;
2612
+ }
2598
2613
2599
- // While transitions are occuring, occurring, we get a double-transform
2600
- // issue if we transform the drawn layer *and* use the new axis range to
2601
- // draw the data. This causes setConvert to use the pre-interaction values
2602
- // of the axis range:
2603
- var axList = Plotly . Axes . list ( gd ) ;
2604
- for ( i = 0 ; i < axList . length ; i ++ ) {
2605
- axList [ i ] . setScale ( true ) ;
2614
+ function executeCallbacks ( list ) {
2615
+ var p = Promise . resolve ( ) ;
2616
+ if ( ! list ) return p ;
2617
+ while ( list . length ) {
2618
+ p = p . then ( ( list . shift ( ) ) ) ;
2606
2619
}
2620
+ return p ;
2607
2621
}
2608
2622
2609
- var restyleList = [ ] ;
2610
- var completionTimeout = null ;
2611
- var resolveTransitionCallback = null ;
2623
+ function flushCallbacks ( list ) {
2624
+ if ( ! list ) return ;
2625
+ while ( list . length ) {
2626
+ list . shift ( ) ;
2627
+ }
2628
+ }
2612
2629
2630
+ var restyleList = [ ] ;
2613
2631
function executeTransitions ( ) {
2614
2632
var hasTraceTransition = false ;
2615
2633
var j ;
@@ -2632,30 +2650,33 @@ Plotly.transition = function(gd, data, layout, traceIndices, transitionConfig) {
2632
2650
}
2633
2651
}
2634
2652
2653
+ gd . _transitionData . _completionTimeout = setTimeout ( completeTransition , transitionConfig . duration ) ;
2654
+
2635
2655
if ( ! hasAxisTransition && ! hasTraceTransition ) {
2636
2656
return false ;
2637
2657
}
2658
+ }
2638
2659
2639
- return new Promise ( function ( resolve ) {
2640
- resolveTransitionCallback = resolve ;
2641
- completionTimeout = setTimeout ( resolve , transitionConfig . duration ) ;
2642
- } ) ;
2660
+ function completeTransition ( ) {
2661
+ flushCallbacks ( gd . _transitionData . _interruptCallbacks ) ;
2662
+
2663
+ gd . emit ( 'plotly_endtransition' , [ ] ) ;
2664
+
2665
+ return executeCallbacks ( gd . _transitionData . _cleanupCallbacks ) ;
2643
2666
}
2644
2667
2645
2668
function interruptPreviousTransitions ( ) {
2646
- clearTimeout ( completionTimeout ) ;
2647
-
2648
- if ( resolveTransitionCallback ) {
2649
- resolveTransitionCallback ( ) ;
2650
- }
2669
+ if ( gd . _transitionData . _completionTimeout ) {
2670
+ // Prevent the previous completion from occurring:
2671
+ clearTimeout ( gd . _transitionData . _completionTimeout ) ;
2672
+ gd . _transitionData . _completionTimeout = null ;
2651
2673
2652
- while ( gd . _frameData . _layoutInterrupts . length ) {
2653
- ( gd . _frameData . _layoutInterrupts . pop ( ) ) ( ) ;
2674
+ // Interrupt an event to indicate that a transition was running:
2675
+ gd . emit ( 'plotly_interrupttransition' , [ ] ) ;
2654
2676
}
2655
2677
2656
- while ( gd . _frameData . _styleInterrupts . length ) {
2657
- ( gd . _frameData . _styleInterrupts . pop ( ) ) ( ) ;
2658
- }
2678
+ flushCallbacks ( gd . _transitionData . _cleanupCallbacks ) ;
2679
+ return executeCallbacks ( gd . _transitionData . _interruptCallbacks ) ;
2659
2680
}
2660
2681
2661
2682
for ( i = 0 ; i < traceIndices . length ; i ++ ) {
@@ -2672,23 +2693,23 @@ Plotly.transition = function(gd, data, layout, traceIndices, transitionConfig) {
2672
2693
thisUpdate [ ai ] = [ data [ i ] [ ai ] ] ;
2673
2694
}
2674
2695
2675
- restyleList . push ( ( function ( md , data , traces ) {
2696
+ /* restyleList.push((function(md, data, traces) {
2676
2697
return function() {
2677
2698
return Plotly.restyle(gd, data, traces);
2678
2699
};
2679
- } ( module , thisUpdate , [ traceIdx ] ) ) ) ;
2700
+ }(module, thisUpdate, [traceIdx])));*/
2680
2701
}
2681
2702
}
2682
2703
2683
2704
var seq = [ Plots . previousPromises , interruptPreviousTransitions , prepareTransitions , executeTransitions ] ;
2684
- seq = seq . concat ( restyleList ) ;
2705
+ // seq = seq.concat(restyleList);
2685
2706
2686
2707
var plotDone = Lib . syncOrAsync ( seq , gd ) ;
2687
2708
2688
2709
if ( ! plotDone || ! plotDone . then ) plotDone = Promise . resolve ( ) ;
2689
2710
2690
2711
return plotDone . then ( function ( ) {
2691
- gd . emit ( 'plotly_beginanimate ' , [ ] ) ;
2712
+ gd . emit ( 'plotly_begintransition ' , [ ] ) ;
2692
2713
return gd ;
2693
2714
} ) ;
2694
2715
} ;
@@ -2704,7 +2725,7 @@ Plotly.transition = function(gd, data, layout, traceIndices, transitionConfig) {
2704
2725
Plotly . animate = function ( gd , frameName , transitionConfig ) {
2705
2726
gd = getGraphDiv ( gd ) ;
2706
2727
2707
- if ( ! gd . _frameData . _frameHash [ frameName ] ) {
2728
+ if ( ! gd . _transitionData . _frameHash [ frameName ] ) {
2708
2729
Lib . warn ( 'animateToFrame failure: keyframe does not exist' , frameName ) ;
2709
2730
return Promise . reject ( ) ;
2710
2731
}
@@ -2734,8 +2755,8 @@ Plotly.addFrames = function(gd, frameList, indices) {
2734
2755
gd = getGraphDiv ( gd ) ;
2735
2756
2736
2757
var i , frame , j , idx ;
2737
- var _frames = gd . _frameData . _frames ;
2738
- var _hash = gd . _frameData . _frameHash ;
2758
+ var _frames = gd . _transitionData . _frames ;
2759
+ var _hash = gd . _transitionData . _frameHash ;
2739
2760
2740
2761
2741
2762
if ( ! Array . isArray ( frameList ) ) {
@@ -2775,7 +2796,7 @@ Plotly.addFrames = function(gd, frameList, indices) {
2775
2796
if ( ! frame . name ) {
2776
2797
// Repeatedly assign a default name, incrementing the counter each time until
2777
2798
// we get a name that's not in the hashed lookup table:
2778
- while ( _hash [ ( frame . name = 'frame ' + gd . _frameData . _counter ++ ) ] ) ;
2799
+ while ( _hash [ ( frame . name = 'frame ' + gd . _transitionData . _counter ++ ) ] ) ;
2779
2800
}
2780
2801
2781
2802
if ( _hash [ frame . name ] ) {
@@ -2815,7 +2836,7 @@ Plotly.deleteFrames = function(gd, frameList) {
2815
2836
gd = getGraphDiv ( gd ) ;
2816
2837
2817
2838
var i , idx ;
2818
- var _frames = gd . _frameData . _frames ;
2839
+ var _frames = gd . _transitionData . _frames ;
2819
2840
var ops = [ ] ;
2820
2841
var revops = [ ] ;
2821
2842
0 commit comments