@@ -88,8 +88,8 @@ function transpose(a) {
88
88
return a [ 0 ] . map ( function ( ignore , columnIndex ) { return a . map ( function ( row ) { return row [ columnIndex ] ; } ) ; } ) ;
89
89
}
90
90
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 ) ) ;
93
93
}
94
94
95
95
function rotate ( rad , point ) {
@@ -99,61 +99,62 @@ function rotate(rad, point) {
99
99
}
100
100
}
101
101
102
- function generator ( ) {
102
+ function generate ( maxJitter ) {
103
103
var x = d3 . range ( - 12 , 13 , 1 ) ; // left closed, right open interval
104
104
var y = d3 . range ( - 12 , 13 , 1 ) ; // left closed, right open interval
105
105
var i , j , p , z = new Array ( x . length ) ;
106
106
for ( i = 0 ; i < x . length ; i ++ ) {
107
107
z [ i ] = new Array ( y . length ) ;
108
108
for ( j = 0 ; j < y . length ; j ++ ) {
109
109
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 ) )
111
111
}
112
112
}
113
113
return { x : x , y : y , z : z } // looking forward to the ES2015 return {x, y, z}
114
114
}
115
115
116
- var model = generator ( ) ;
117
-
118
116
// 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
132
145
} ,
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
136
156
}
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
+ } ;
157
158
} ;
158
159
159
160
@@ -171,20 +172,30 @@ fdescribe('contourgl plots', function() {
171
172
} ) ;
172
173
} ) ;
173
174
174
- // this dataset is less forgiving because it uses a noisy surface (random, will look different on each run)
175
175
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
176
178
withSetupTeardown ( done , function ( gd ) {
177
- return makePlot ( gd , plotDataCircular ) ;
179
+ return makePlot ( gd , plotDataElliptical ) ;
178
180
} ) ;
179
181
} ) ;
180
182
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 ) ;
185
185
withSetupTeardown ( done , function ( gd ) {
186
186
return makePlot ( gd , mock ) ;
187
187
} ) ;
188
188
} ) ;
189
189
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
+
190
201
} ) ;
0 commit comments