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