@@ -2547,3 +2547,123 @@ describe('Cartesian plots with css transforms', function() {
2547
2547
} ) ;
2548
2548
} ) ;
2549
2549
} ) ;
2550
+
2551
+ describe ( 'Cartesian taces with zindex' , function ( ) {
2552
+ var gd ;
2553
+
2554
+ beforeEach ( function ( ) {
2555
+ gd = createGraphDiv ( ) ;
2556
+ } ) ;
2557
+
2558
+ afterEach ( destroyGraphDiv ) ;
2559
+
2560
+ var data0 = [
2561
+ { x : [ 1 , 2 ] , y : [ 1 , 1 ] , type : 'scatter' , zindex : 10 } ,
2562
+ { x : [ 1 , 2 ] , y : [ 1 , 2 ] , type : 'scatter' } ,
2563
+ { x : [ 1 , 2 ] , y : [ 1 , 3 ] , type : 'scatter' , zindex : 5 }
2564
+ ] ;
2565
+
2566
+ var data1 = [
2567
+ { x : [ 1 , 2 ] , y : [ 1 , 1 ] , type : 'scatter' } ,
2568
+ { x : [ 1 , 2 ] , y : [ 1 , 2 ] , type : 'scatter' , zindex : - 5 } ,
2569
+ { x : [ 1 , 2 ] , y : [ 1 , 3 ] , type : 'scatter' , zindex : 10 } ,
2570
+ ] ;
2571
+
2572
+ function fig ( data ) {
2573
+ return {
2574
+ data : data ,
2575
+ layout : {
2576
+ width : 400 , height : 400
2577
+ }
2578
+ } ;
2579
+ }
2580
+
2581
+ function assertZIndices ( data , expectedData ) {
2582
+ for ( var i = 0 ; i < data . length ; i ++ ) {
2583
+ var zindex = expectedData [ i ] . zindex ? expectedData [ i ] . zindex : 0 ;
2584
+ expect ( data [ i ] . zindex ) . toEqual ( zindex ) ;
2585
+ }
2586
+ }
2587
+
2588
+ function assertZIndicesSorted ( data ) {
2589
+ var prevZIndex ;
2590
+ expect ( data . length ) . toBeGreaterThan ( 0 ) ;
2591
+ for ( var i = 0 ; i < data . length ; i ++ ) {
2592
+ var currentZIndex = data [ i ] . __data__ . zindex ;
2593
+ if ( prevZIndex !== undefined ) {
2594
+ expect ( currentZIndex ) . toBeGreaterThanOrEqual ( prevZIndex ) ;
2595
+ }
2596
+ prevZIndex = currentZIndex ;
2597
+ }
2598
+ }
2599
+
2600
+ it ( 'should be able to update zindex' , function ( done ) {
2601
+ Plotly . newPlot ( gd , fig ( data0 ) )
2602
+ . then ( function ( ) {
2603
+ var data = gd . _fullData ;
2604
+ assertZIndices ( data , data0 ) ;
2605
+ } )
2606
+ . then ( function ( ) {
2607
+ return Plotly . react ( gd , fig ( data1 ) ) ;
2608
+ } )
2609
+ . then ( function ( ) {
2610
+ var data = gd . _fullData ;
2611
+ assertZIndices ( data , data1 ) ;
2612
+ } )
2613
+ . then ( done , done . fail ) ;
2614
+ } ) ;
2615
+
2616
+ it ( 'should display traces in ascending order' , function ( done ) {
2617
+ Plotly . newPlot ( gd , fig ( data0 ) )
2618
+ . then ( function ( ) {
2619
+ var tracesData = d3SelectAll ( 'g[class^="scatterlayer"]' ) ;
2620
+ assertZIndicesSorted ( tracesData [ 0 ] ) ;
2621
+ } )
2622
+ . then ( function ( ) {
2623
+ return Plotly . react ( gd , fig ( data1 ) ) ;
2624
+ } )
2625
+ . then ( function ( ) {
2626
+ var tracesData = d3SelectAll ( 'g[class^="scatterlayer"]' ) ;
2627
+ assertZIndicesSorted ( tracesData [ 0 ] ) ;
2628
+ } )
2629
+ . then ( done , done . fail ) ;
2630
+ } ) ;
2631
+
2632
+ it ( 'should display traces in ascending zindex order after restyle' , function ( done ) {
2633
+ Plotly . newPlot ( gd , fig ( data0 ) )
2634
+ . then ( function ( ) {
2635
+ var tracesData = d3SelectAll ( 'g[class^="scatterlayer"]' ) ;
2636
+ var data = gd . _fullData ;
2637
+ assertZIndices ( data , data0 ) ;
2638
+ assertZIndicesSorted ( tracesData [ 0 ] ) ;
2639
+ } )
2640
+ . then ( function ( ) {
2641
+ return Plotly . restyle ( gd , 'type' , 'bar' ) ;
2642
+ } )
2643
+ . then ( function ( ) {
2644
+ var tracesData = d3SelectAll ( 'g[class^="barlayer"]' ) ;
2645
+ var data = gd . _fullData ;
2646
+ assertZIndices ( data , data0 ) ;
2647
+ assertZIndicesSorted ( tracesData [ 0 ] ) ;
2648
+ } )
2649
+ . then ( function ( ) {
2650
+ return Plotly . react ( gd , fig ( data1 ) ) ;
2651
+ } )
2652
+ . then ( function ( ) {
2653
+ var tracesData = d3SelectAll ( 'g[class^="scatterlayer"]' ) ;
2654
+ var data = gd . _fullData ;
2655
+ assertZIndices ( data , data1 ) ;
2656
+ assertZIndicesSorted ( tracesData [ 0 ] ) ;
2657
+ } )
2658
+ . then ( function ( ) {
2659
+ return Plotly . restyle ( gd , { type : 'bar' } ) ;
2660
+ } )
2661
+ . then ( function ( ) {
2662
+ var tracesData = d3SelectAll ( 'g[class^="barlayer"]' ) ;
2663
+ var data = gd . _fullData ;
2664
+ assertZIndices ( data , data1 ) ;
2665
+ assertZIndicesSorted ( tracesData [ 0 ] ) ;
2666
+ } )
2667
+ . then ( done , done . fail ) ;
2668
+ } ) ;
2669
+ } ) ;
0 commit comments