@@ -88,8 +88,8 @@ function transpose(a) {
8888 return a [ 0 ] . map ( function ( ignore , columnIndex ) { return a . map ( function ( row ) { return row [ columnIndex ] ; } ) ; } ) ;
8989}
9090
91- function jitter ( n ) {
92- return n + ( Math . random ( ) - 0.5 ) / 2 ;
91+ function jitter ( maxJitterRatio , n ) {
92+ return n * ( 1 + maxJitterRatio * ( 2 * Math . random ( ) - 1 ) ) ;
9393}
9494
9595function rotate ( rad , point ) {
@@ -99,61 +99,62 @@ function rotate(rad, point) {
9999 }
100100}
101101
102- function generator ( ) {
102+ function generate ( maxJitter ) {
103103 var x = d3 . range ( - 12 , 13 , 1 ) ; // left closed, right open interval
104104 var y = d3 . range ( - 12 , 13 , 1 ) ; // left closed, right open interval
105105 var i , j , p , z = new Array ( x . length ) ;
106106 for ( i = 0 ; i < x . length ; i ++ ) {
107107 z [ i ] = new Array ( y . length ) ;
108108 for ( j = 0 ; j < y . length ; j ++ ) {
109109 p = rotate ( Math . PI / 4 , { x : x [ i ] , y : - y [ j ] } )
110- z [ i ] [ j ] = jitter ( Math . pow ( p . x , 2 ) / ( 10 * 10 ) + Math . pow ( p . y , 2 ) / ( 4 * 4 ) )
110+ z [ i ] [ j ] = jitter ( maxJitter , Math . pow ( p . x , 2 ) / ( 10 * 10 ) + Math . pow ( p . y , 2 ) / ( 4 * 4 ) )
111111 }
112112 }
113113 return { x : x , y : y , z : z } // looking forward to the ES2015 return {x, y, z}
114114}
115115
116- var model = generator ( ) ;
117-
118116// equivalent to the new example case in gl-contour2d
119- var plotDataCircular = {
120- "data" : [
121- {
122- "type" : "contourgl" ,
123- "x" : model . x . map ( jitter ) ,
124- "y" : model . y . map ( jitter ) ,
125- "z" : transpose ( model . z ) , // gl-vis is column-major order while ploly is row-major order
126- "colorscale" : "Jet" ,
127- "contours" : {
128- "start" : 0 ,
129- "end" : 2 ,
130- "size" : 0.1 ,
131- "coloring" : "lines"
117+ var plotDataElliptical = function ( maxJitter ) {
118+ var model = generate ( maxJitter ) ;
119+ return {
120+ "data" : [
121+ {
122+ "type" : "contour" ,
123+ "x" : model . x ,
124+ "y" : model . y ,
125+ "z" : transpose ( model . z ) , // gl-vis is column-major order while ploly is row-major order
126+ "colorscale" : "Jet" ,
127+ "contours" : {
128+ "start" : 0 ,
129+ "end" : 2 ,
130+ "size" : 0.1 ,
131+ "coloring" : "fill"
132+ } ,
133+ "uid" : "ad5624" ,
134+ "zmin" : 0 ,
135+ "zmax" : 2
136+ }
137+ ] ,
138+ "layout" : {
139+ "xaxis" : {
140+ "range" : [
141+ - 10 ,
142+ 10
143+ ] ,
144+ "autorange" : true
132145 } ,
133- "uid" : "ad5624" ,
134- "zmin" : 0 ,
135- "zmax" : 2
146+ "yaxis" : {
147+ "range" : [
148+ - 10 ,
149+ 10
150+ ] ,
151+ "autorange" : true
152+ } ,
153+ "height" : 600 ,
154+ "width" : 600 ,
155+ "autosize" : true
136156 }
137- ] ,
138- "layout" : {
139- "xaxis" : {
140- "range" : [
141- - 10 ,
142- 10
143- ] ,
144- "autorange" : true
145- } ,
146- "yaxis" : {
147- "range" : [
148- - 10 ,
149- 10
150- ] ,
151- "autorange" : true
152- } ,
153- "height" : 600 ,
154- "width" : 600 ,
155- "autosize" : true
156- }
157+ } ;
157158} ;
158159
159160
@@ -171,20 +172,30 @@ fdescribe('contourgl plots', function() {
171172 } ) ;
172173 } ) ;
173174
174- // this dataset is less forgiving because it uses a noisy surface (random, will look different on each run)
175175 it ( 'render without raising an error (coloring: "lines")' , function ( done ) {
176+ var mock = Lib . extendDeep ( { } , plotDataElliptical ( 0 ) ) ;
177+ mock . data [ 0 ] . contours . coloring = "lines" ; // "fill" is the default
176178 withSetupTeardown ( done , function ( gd ) {
177- return makePlot ( gd , plotDataCircular ) ;
179+ return makePlot ( gd , plotDataElliptical ) ;
178180 } ) ;
179181 } ) ;
180182
181- // same with fill
182- fit ( 'render without raising an error (coloring: "fill")' , function ( done ) {
183- var mock = Lib . extendDeep ( { } , plotDataCircular ) ;
184- mock . data [ 0 ] . contours . coloring = "fill" ; // or delete property - fill is the default
183+ it ( 'render smooth, regular ellipses without raising an error (coloring: "fill")' , function ( done ) {
184+ var mock = plotDataElliptical ( 0 ) ;
185185 withSetupTeardown ( done , function ( gd ) {
186186 return makePlot ( gd , mock ) ;
187187 } ) ;
188188 } ) ;
189189
190+ fit ( 'render ellipses with added noise without raising an error (coloring: "fill")' , function ( done ) {
191+ var mock = plotDataElliptical ( 0.5 ) ;
192+ withSetupTeardown ( done , function ( gd ) {
193+ return makePlot ( gd , mock ) ;
194+ } ) ;
195+ } ) ;
196+
197+
198+
199+
200+
190201} ) ;
0 commit comments