@@ -137,13 +137,17 @@ describe('Test histogram2d', function() {
137
137
} ) ;
138
138
} ) ;
139
139
140
- describe ( 'relayout interaction' , function ( ) {
140
+ describe ( 'restyle / relayout interaction' , function ( ) {
141
+
142
+ var gd ;
143
+
144
+ beforeEach ( function ( ) {
145
+ gd = createGraphDiv ( ) ;
146
+ } ) ;
141
147
142
148
afterEach ( destroyGraphDiv ) ;
143
149
144
150
it ( 'should update paths on zooms' , function ( done ) {
145
- var gd = createGraphDiv ( ) ;
146
-
147
151
Plotly . newPlot ( gd , [ {
148
152
type : 'histogram2dcontour' ,
149
153
x : [ 1 , 1 , 2 , 2 , 3 ] ,
@@ -156,6 +160,75 @@ describe('Test histogram2d', function() {
156
160
. then ( done ) ;
157
161
} ) ;
158
162
163
+
164
+ it ( 'handles autobin correctly on restyles' , function ( ) {
165
+ var x1 = [
166
+ 1 , 1 , 1 , 1 , 2 , 2 , 2 , 2 , 3 , 3 , 3 , 3 , 4 , 4 , 4 , 4 ,
167
+ 1 , 1 , 1 , 1 , 2 , 2 , 2 , 2 , 3 , 3 , 3 , 3 , 4 , 4 , 4 , 4 ] ;
168
+ var y1 = [
169
+ 1 , 2 , 3 , 4 , 1 , 2 , 3 , 4 , 1 , 2 , 3 , 4 , 1 , 2 , 3 , 4 ,
170
+ 1 , 2 , 3 , 4 , 1 , 2 , 3 , 4 , 1 , 2 , 3 , 4 , 1 , 2 , 3 , 4 ] ;
171
+ Plotly . newPlot ( gd , [ { type : 'histogram2d' , x : x1 , y : y1 } ] ) ;
172
+ expect ( gd . _fullData [ 0 ] . xbins ) . toEqual ( { start : 0.5 , end : 4.5 , size : 1 } ) ;
173
+ expect ( gd . _fullData [ 0 ] . ybins ) . toEqual ( { start : 0.5 , end : 4.5 , size : 1 } ) ;
174
+ expect ( gd . _fullData [ 0 ] . autobinx ) . toBe ( true ) ;
175
+ expect ( gd . _fullData [ 0 ] . autobiny ) . toBe ( true ) ;
176
+
177
+ // same range but fewer samples increases sizes
178
+ Plotly . restyle ( gd , { x : [ [ 1 , 3 , 4 ] ] , y : [ [ 1 , 2 , 4 ] ] } ) ;
179
+ expect ( gd . _fullData [ 0 ] . xbins ) . toEqual ( { start : - 0.5 , end : 5.5 , size : 2 } ) ;
180
+ expect ( gd . _fullData [ 0 ] . ybins ) . toEqual ( { start : - 0.5 , end : 5.5 , size : 2 } ) ;
181
+ expect ( gd . _fullData [ 0 ] . autobinx ) . toBe ( true ) ;
182
+ expect ( gd . _fullData [ 0 ] . autobiny ) . toBe ( true ) ;
183
+
184
+ // larger range
185
+ Plotly . restyle ( gd , { x : [ [ 10 , 30 , 40 ] ] , y : [ [ 10 , 20 , 40 ] ] } ) ;
186
+ expect ( gd . _fullData [ 0 ] . xbins ) . toEqual ( { start : - 0.5 , end : 59.5 , size : 20 } ) ;
187
+ expect ( gd . _fullData [ 0 ] . ybins ) . toEqual ( { start : - 0.5 , end : 59.5 , size : 20 } ) ;
188
+ expect ( gd . _fullData [ 0 ] . autobinx ) . toBe ( true ) ;
189
+ expect ( gd . _fullData [ 0 ] . autobiny ) . toBe ( true ) ;
190
+
191
+ // explicit changes to bin settings
192
+ Plotly . restyle ( gd , 'xbins.start' , 12 ) ;
193
+ expect ( gd . _fullData [ 0 ] . xbins ) . toEqual ( { start : 12 , end : 59.5 , size : 20 } ) ;
194
+ expect ( gd . _fullData [ 0 ] . ybins ) . toEqual ( { start : - 0.5 , end : 59.5 , size : 20 } ) ;
195
+ expect ( gd . _fullData [ 0 ] . autobinx ) . toBe ( false ) ;
196
+ expect ( gd . _fullData [ 0 ] . autobiny ) . toBe ( true ) ;
197
+
198
+ Plotly . restyle ( gd , { 'ybins.end' : 12 , 'ybins.size' : 3 } ) ;
199
+ expect ( gd . _fullData [ 0 ] . xbins ) . toEqual ( { start : 12 , end : 59.5 , size : 20 } ) ;
200
+ expect ( gd . _fullData [ 0 ] . ybins ) . toEqual ( { start : - 0.5 , end : 12 , size : 3 } ) ;
201
+ expect ( gd . _fullData [ 0 ] . autobinx ) . toBe ( false ) ;
202
+ expect ( gd . _fullData [ 0 ] . autobiny ) . toBe ( false ) ;
203
+
204
+ // restart autobin
205
+ Plotly . restyle ( gd , { autobinx : true , autobiny : true } ) ;
206
+ expect ( gd . _fullData [ 0 ] . xbins ) . toEqual ( { start : - 0.5 , end : 59.5 , size : 20 } ) ;
207
+ expect ( gd . _fullData [ 0 ] . ybins ) . toEqual ( { start : - 0.5 , end : 59.5 , size : 20 } ) ;
208
+ expect ( gd . _fullData [ 0 ] . autobinx ) . toBe ( true ) ;
209
+ expect ( gd . _fullData [ 0 ] . autobiny ) . toBe ( true ) ;
210
+ } ) ;
211
+
212
+ it ( 'respects explicit autobin: false as a one-time autobin' , function ( ) {
213
+ var x1 = [
214
+ 1 , 1 , 1 , 1 , 2 , 2 , 2 , 2 , 3 , 3 , 3 , 3 , 4 , 4 , 4 , 4 ,
215
+ 1 , 1 , 1 , 1 , 2 , 2 , 2 , 2 , 3 , 3 , 3 , 3 , 4 , 4 , 4 , 4 ] ;
216
+ var y1 = [
217
+ 1 , 2 , 3 , 4 , 1 , 2 , 3 , 4 , 1 , 2 , 3 , 4 , 1 , 2 , 3 , 4 ,
218
+ 1 , 2 , 3 , 4 , 1 , 2 , 3 , 4 , 1 , 2 , 3 , 4 , 1 , 2 , 3 , 4 ] ;
219
+ Plotly . newPlot ( gd , [ { type : 'histogram2d' , x : x1 , y : y1 , autobinx : false , autobiny : false } ] ) ;
220
+ expect ( gd . _fullData [ 0 ] . xbins ) . toEqual ( { start : 0.5 , end : 4.5 , size : 1 } ) ;
221
+ expect ( gd . _fullData [ 0 ] . ybins ) . toEqual ( { start : 0.5 , end : 4.5 , size : 1 } ) ;
222
+ expect ( gd . _fullData [ 0 ] . autobinx ) . toBe ( false ) ;
223
+ expect ( gd . _fullData [ 0 ] . autobiny ) . toBe ( false ) ;
224
+
225
+ // with autobin false this will no longer update the bins.
226
+ Plotly . restyle ( gd , { x : [ [ 1 , 3 , 4 ] ] , y : [ [ 1 , 2 , 4 ] ] } ) ;
227
+ expect ( gd . _fullData [ 0 ] . xbins ) . toEqual ( { start : 0.5 , end : 4.5 , size : 1 } ) ;
228
+ expect ( gd . _fullData [ 0 ] . ybins ) . toEqual ( { start : 0.5 , end : 4.5 , size : 1 } ) ;
229
+ expect ( gd . _fullData [ 0 ] . autobinx ) . toBe ( false ) ;
230
+ expect ( gd . _fullData [ 0 ] . autobiny ) . toBe ( false ) ;
231
+ } ) ;
159
232
} ) ;
160
233
161
234
} ) ;
0 commit comments