@@ -8,6 +8,7 @@ var d3 = require('d3');
88var createGraphDiv = require ( '../assets/create_graph_div' ) ;
99var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
1010var mouseEvent = require ( '../assets/mouse_event' ) ;
11+ var failTest = require ( '../assets/fail_test' ) ;
1112
1213var customAssertions = require ( '../assets/custom_assertions' ) ;
1314var assertHoverLabelStyle = customAssertions . assertHoverLabelStyle ;
@@ -175,7 +176,7 @@ describe('Test choropleth hover:', function() {
175176 } ) ;
176177} ) ;
177178
178- describe ( 'choropleth bad data ' , function ( ) {
179+ describe ( 'choropleth drawing ' , function ( ) {
179180 var gd ;
180181
181182 beforeEach ( function ( ) {
@@ -196,7 +197,38 @@ describe('choropleth bad data', function() {
196197 // only utopia logs - others are silently ignored
197198 expect ( Lib . log ) . toHaveBeenCalledTimes ( 1 ) ;
198199 } )
199- . catch ( fail )
200+ . catch ( failTest )
201+ . then ( done ) ;
202+ } ) ;
203+
204+ it ( 'preserves order after hide/show' , function ( done ) {
205+ function getIndices ( ) {
206+ var out = [ ] ;
207+ d3 . selectAll ( '.choropleth' ) . each ( function ( d ) { out . push ( d [ 0 ] . trace . index ) ; } ) ;
208+ return out ;
209+ }
210+
211+ Plotly . newPlot ( gd , [ {
212+ type : 'choropleth' ,
213+ locations : [ 'CAN' , 'USA' ] ,
214+ z : [ 1 , 2 ]
215+ } , {
216+ type : 'choropleth' ,
217+ locations : [ 'CAN' , 'USA' ] ,
218+ z : [ 2 , 1 ]
219+ } ] )
220+ . then ( function ( ) {
221+ expect ( getIndices ( ) ) . toEqual ( [ 0 , 1 ] ) ;
222+ return Plotly . restyle ( gd , 'visible' , false , [ 0 ] ) ;
223+ } )
224+ . then ( function ( ) {
225+ expect ( getIndices ( ) ) . toEqual ( [ 1 ] ) ;
226+ return Plotly . restyle ( gd , 'visible' , true , [ 0 ] ) ;
227+ } )
228+ . then ( function ( ) {
229+ expect ( getIndices ( ) ) . toEqual ( [ 0 , 1 ] ) ;
230+ } )
231+ . catch ( failTest )
200232 . then ( done ) ;
201233 } ) ;
202234} ) ;
0 commit comments