@@ -34,8 +34,9 @@ describe('contour defaults', function() {
3434 [ 0.625 , 1.25 , 3.125 , 6.25 ] ] ,
3535 contours : {
3636 start : 4 ,
37- end : 14 ,
38- size : 0.5
37+ end : 14
38+ // missing size does NOT set autocontour true
39+ // even though in calc we set an autosize.
3940 }
4041 } ;
4142 supplyDefaults ( traceIn , traceOut , defaultColor , layout ) ;
@@ -46,7 +47,8 @@ describe('contour defaults', function() {
4647 z : [ [ 10 , 10.625 , 12.5 , 15.625 ] ,
4748 [ 5.625 , 6.25 , 8.125 , 11.25 ] ,
4849 [ 2.5 , 3.125 , 5.0 , 8.125 ] ,
49- [ 0.625 , 1.25 , 3.125 , 6.25 ] ]
50+ [ 0.625 , 1.25 , 3.125 , 6.25 ] ] ,
51+ contours : { start : 4 } // you need at least start and end
5052 } ;
5153 supplyDefaults ( traceIn , traceOut , defaultColor , layout ) ;
5254 expect ( traceOut . autocontour ) . toBe ( true ) ;
@@ -183,7 +185,9 @@ describe('contour calc', function() {
183185 Plots . supplyDefaults ( gd ) ;
184186 var fullTrace = gd . _fullData [ 0 ] ;
185187
186- return Contour . calc ( gd , fullTrace ) [ 0 ] ;
188+ var out = Contour . calc ( gd , fullTrace ) [ 0 ] ;
189+ out . trace = fullTrace ;
190+ return out ;
187191 }
188192
189193 it ( 'should fill in bricks if x/y not given' , function ( ) {
@@ -269,4 +273,69 @@ describe('contour calc', function() {
269273 expect ( out . y ) . toBeCloseToArray ( [ 0 , 1 ] ) ;
270274 expect ( out . z ) . toBeCloseTo2DArray ( [ [ 1 , 2 , 3 ] , [ 3 , 1 , 2 ] ] ) ;
271275 } ) ;
276+
277+ it ( 'should make nice autocontour values' , function ( ) {
278+ var incompleteContours = [
279+ undefined ,
280+ { start : 12 } ,
281+ { end : 45 } ,
282+ { start : 2 , size : 2 } // size gets ignored
283+ ] ;
284+
285+ var contoursFinal = [
286+ // fully auto. These are *not* exactly the output contours objects,
287+ // I put the input ncontours in here too.
288+ { inputNcontours : undefined , start : 0.5 , end : 4.5 , size : 0.5 } ,
289+ // explicit ncontours
290+ { inputNcontours : 6 , start : 1 , end : 4 , size : 1 } ,
291+ // edge case where low ncontours makes start and end cross
292+ { inputNcontours : 2 , start : 2.5 , end : 2.5 , size : 5 }
293+ ] ;
294+
295+ incompleteContours . forEach ( function ( contoursIn ) {
296+ contoursFinal . forEach ( function ( spec ) {
297+ var out = _calc ( {
298+ z : [ [ 0 , 2 ] , [ 3 , 5 ] ] ,
299+ contours : contoursIn ,
300+ ncontours : spec . inputNcontours
301+ } ) . trace ;
302+
303+ [ 'start' , 'end' , 'size' ] . forEach ( function ( attr ) {
304+ expect ( out . contours [ attr ] ) . toBe ( spec [ attr ] , [ contoursIn , attr ] ) ;
305+ // all these get copied back to the input trace
306+ expect ( out . _input . contours [ attr ] ) . toBe ( spec [ attr ] , [ contoursIn , attr ] ) ;
307+ } ) ;
308+ } ) ;
309+ } ) ;
310+ } ) ;
311+
312+ it ( 'should supply size and reorder start/end if autocontour is off' , function ( ) {
313+ var specs = [
314+ { start : 1 , end : 100 , ncontours : undefined , size : 10 } ,
315+ { start : 1 , end : 100 , ncontours : 5 , size : 20 } ,
316+ { start : 10 , end : 10 , ncontours : 10 , size : 1 }
317+ ] ;
318+
319+ specs . forEach ( function ( spec ) {
320+ [
321+ [ spec . start , spec . end , 'normal' ] ,
322+ [ spec . end , spec . start , 'reversed' ]
323+ ] . forEach ( function ( v ) {
324+ var startIn = v [ 0 ] ,
325+ endIn = v [ 1 ] ,
326+ order = v [ 2 ] ;
327+
328+ var out = _calc ( {
329+ z : [ [ 1 , 2 ] , [ 3 , 4 ] ] ,
330+ contours : { start : startIn , end : endIn } ,
331+ ncontours : spec . ncontours
332+ } ) . trace ;
333+
334+ [ 'start' , 'end' , 'size' ] . forEach ( function ( attr ) {
335+ expect ( out . contours [ attr ] ) . toBe ( spec [ attr ] , [ spec , order , attr ] ) ;
336+ expect ( out . _input . contours [ attr ] ) . toBe ( spec [ attr ] , [ spec , order , attr ] ) ;
337+ } ) ;
338+ } ) ;
339+ } ) ;
340+ } ) ;
272341} ) ;
0 commit comments