@@ -2493,12 +2493,11 @@ Plotly.relayout = function relayout(gd, astr, val) {
2493
2493
* @param {string id or DOM element } gd
2494
2494
* the id or DOM element of the graph container div
2495
2495
*/
2496
- Plotly . transition = function ( gd , data , layout , traces , transitionConfig ) {
2496
+ Plotly . transition = function ( gd , data , layout , traceIndices , transitionConfig ) {
2497
2497
gd = getGraphDiv ( gd ) ;
2498
2498
2499
- return Promise . resolve ( ) ;
2500
-
2501
- /*var fullLayout = gd._fullLayout;
2499
+ var i , value , traceIdx ;
2500
+ var fullLayout = gd . _fullLayout ;
2502
2501
2503
2502
transitionConfig = Lib . extendFlat ( {
2504
2503
ease : 'cubic-in-out' ,
@@ -2517,76 +2516,112 @@ Plotly.transition = function(gd, data, layout, traces, transitionConfig) {
2517
2516
}
2518
2517
2519
2518
// Select which traces will be updated:
2520
- if(isNumeric(traces )) traces = [traces ];
2521
- else if(!Array.isArray(traces ) || !traces .length) {
2522
- traces = gd._fullData.map(function(v, i) {return i;});
2519
+ if ( isNumeric ( traceIndices ) ) traceIndices = [ traceIndices ] ;
2520
+ else if ( ! Array . isArray ( traceIndices ) || ! traceIndices . length ) {
2521
+ traceIndices = gd . _fullData . map ( function ( v , i ) { return i ; } ) ;
2523
2522
}
2524
2523
2525
- var transitioningTraces = [];
2524
+ var animatedTraces = [ ] ;
2526
2525
2527
- function prepareAnimations () {
2528
- for(i = 0; i < traces .length; i++) {
2529
- var traceIdx = traces [i];
2526
+ function prepareTransitions ( ) {
2527
+ for ( i = 0 ; i < traceIndices . length ; i ++ ) {
2528
+ var traceIdx = traceIndices [ i ] ;
2530
2529
var trace = gd . _fullData [ traceIdx ] ;
2531
2530
var module = trace . _module ;
2532
2531
2533
2532
if ( ! module . animatable ) {
2534
2533
continue ;
2535
2534
}
2536
2535
2537
- transitioningTraces .push(traceIdx);
2536
+ animatedTraces . push ( traceIdx ) ;
2538
2537
2539
- newTraceData = newData[i];
2540
- curData = gd.data[traces[i]];
2541
-
2542
- for(var ai in newTraceData) {
2543
- var value = newTraceData[ai];
2544
- Lib.nestedProperty(curData, ai).set(value);
2545
- }
2546
-
2547
- var traceIdx = traces[i];
2548
- if(gd.data[traceIdx].marker && gd.data[traceIdx].marker.size) {
2549
- gd._fullData[traceIdx].marker.size = gd.data[traceIdx].marker.size;
2550
- }
2551
- if(gd.data[traceIdx].error_y && gd.data[traceIdx].error_y.array) {
2552
- gd._fullData[traceIdx].error_y.array = gd.data[traceIdx].error_y.array;
2553
- }
2554
- if(gd.data[traceIdx].error_x && gd.data[traceIdx].error_x.array) {
2555
- gd._fullData[traceIdx].error_x.array = gd.data[traceIdx].error_x.array;
2556
- }
2557
- gd._fullData[traceIdx].x = gd.data[traceIdx].x;
2558
- gd._fullData[traceIdx].y = gd.data[traceIdx].y;
2559
- gd._fullData[traceIdx].z = gd.data[traceIdx].z;
2560
- gd._fullData[traceIdx].key = gd.data[traceIdx].key;
2538
+ Lib . extendDeepNoArrays ( gd . data [ traceIndices [ i ] ] , data [ i ] ) ;
2561
2539
}
2562
2540
2563
- doCalcdata(gd, transitioningTraces);
2541
+ Plots . supplyDefaults ( gd )
2542
+
2543
+ // doCalcdata(gd, animatedTraces);
2544
+ doCalcdata ( gd ) ;
2564
2545
2565
2546
ErrorBars . calc ( gd ) ;
2566
2547
}
2567
2548
2568
- function doAnimations() {
2569
- var a, i, j;
2549
+ var restyleList = [ ] ;
2550
+ var relayoutList = [ ] ;
2551
+ var completionTimeout = null ;
2552
+ var completion = null ;
2553
+
2554
+ function executeTransitions ( ) {
2555
+ var j ;
2570
2556
var basePlotModules = fullLayout . _basePlotModules ;
2571
- for(j = 0; j < basePlotModules.length; j++) {
2572
- basePlotModules[j].plot(gd, transitioningTraces, transitionOpts );
2557
+ for ( j = 0 ; j < basePlotModules . length ; j ++ ) {
2558
+ basePlotModules [ j ] . plot ( gd , animatedTraces , transitionConfig ) ;
2573
2559
}
2574
2560
2575
- if(layout) {
2576
- for(j = 0; j < basePlotModules.length; j++) {
2577
- if(basePlotModules[j].transitionAxes) {
2578
- basePlotModules[j].transitionAxes(gd, layout, transitionOpts);
2561
+ if ( layout ) {
2562
+ for ( j = 0 ; j < basePlotModules . length ; j ++ ) {
2563
+ if ( basePlotModules [ j ] . transitionAxes ) {
2564
+ var newLayout = Lib . extendDeep ( { } , gd . _fullLayout , layout ) ;
2565
+ basePlotModules [ j ] . transitionAxes ( gd , newLayout , transitionConfig ) ;
2579
2566
}
2580
2567
}
2581
2568
}
2582
2569
2583
- if(!transitionOpts.leadingEdgeRestyle) {
2584
- return new Promise(function(resolve, reject) {
2585
- completion = resolve;
2586
- completionTimeout = setTimeout(resolve, transitionOpts.duration);
2587
- });
2570
+ return new Promise ( function ( resolve , reject ) {
2571
+ completion = resolve ;
2572
+ completionTimeout = setTimeout ( resolve , transitionConfig . duration ) ;
2573
+ } ) ;
2574
+ }
2575
+
2576
+ function interruptPreviousTransitions ( ) {
2577
+ var ret ;
2578
+ clearTimeout ( completionTimeout ) ;
2579
+
2580
+ if ( completion ) {
2581
+ completion ( ) ;
2582
+ }
2583
+
2584
+ if ( gd . _animationInterrupt ) {
2585
+ ret = gd . _animationInterrupt ( ) ;
2586
+ gd . _animationInterrupt = null ;
2588
2587
}
2589
- }*/
2588
+ return ret ;
2589
+ }
2590
+
2591
+ for ( i = 0 ; i < traceIndices . length ; i ++ ) {
2592
+ var traceIdx = traceIndices [ i ] ;
2593
+ var contFull = gd . _fullData [ traceIdx ] ;
2594
+ var module = contFull . _module ;
2595
+
2596
+ if ( ! module . animatable ) {
2597
+ var thisTrace = [ traceIdx ] ;
2598
+ var thisUpdate = { } ;
2599
+
2600
+ for ( var ai in data [ i ] ) {
2601
+ thisUpdate [ ai ] = [ data [ i ] [ ai ] ] ;
2602
+ }
2603
+
2604
+ restyleList . push ( ( function ( md , data , traces ) {
2605
+ return function ( ) {
2606
+ return Plotly . restyle ( gd , data , traces ) ;
2607
+ }
2608
+ } ( module , thisUpdate , [ traceIdx ] ) ) ) ;
2609
+ }
2610
+ }
2611
+
2612
+ var seq = [ Plots . previousPromises , interruptPreviousTransitions , prepareTransitions , executeTransitions ] ;
2613
+ seq = seq . concat ( restyleList ) ;
2614
+
2615
+ var plotDone = Lib . syncOrAsync ( seq , gd ) ;
2616
+
2617
+ if ( ! plotDone || ! plotDone . then ) plotDone = Promise . resolve ( ) ;
2618
+
2619
+ return plotDone . then ( function ( ) {
2620
+ gd . emit ( 'plotly_beginanimate' , [ ] ) ;
2621
+ return gd ;
2622
+ } ) ;
2623
+
2624
+ return Promise . resolve ( ) ;
2590
2625
} ;
2591
2626
2592
2627
/**
0 commit comments