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