@@ -19,7 +19,7 @@ var normFunctions = require('./norm_functions');
19
19
var doAvg = require ( './average' ) ;
20
20
var getBinSpanLabelRound = require ( './bin_label_vals' ) ;
21
21
22
- module . exports = function calc ( gd , trace ) {
22
+ function calc ( gd , trace ) {
23
23
var pos = [ ] ;
24
24
var size = [ ] ;
25
25
var pa = Axes . getFromId ( gd , trace . orientation === 'h' ? trace . yaxis : trace . xaxis ) ;
@@ -193,23 +193,30 @@ module.exports = function calc(gd, trace) {
193
193
}
194
194
195
195
return cd ;
196
- } ;
196
+ }
197
197
198
198
/*
199
- * calcAllAutoBins: we want all histograms on the same axes to share bin specs
200
- * if they're grouped or stacked. If the user has explicitly specified differing
199
+ * calcAllAutoBins: we want all histograms inside the same bingroup
200
+ * (see logic in Histogram.crossTraceDefaults) to share bin specs
201
+ *
202
+ * If the user has explicitly specified differing
201
203
* bin specs, there's nothing we can do, but if possible we will try to use the
202
- * smallest bins of any of the auto values for all histograms grouped/stacked
203
- * together .
204
+ * smallest bins of any of the auto values for all histograms inside the same
205
+ * bingroup .
204
206
*/
205
207
function calcAllAutoBins ( gd , trace , pa , mainData , _overlayEdgeCase ) {
206
208
var binAttr = mainData + 'bins' ;
207
209
var fullLayout = gd . _fullLayout ;
210
+ var groupName = trace [ '_' + mainData + 'bingroup' ] ;
211
+ var binOpts = fullLayout . _histogramBinOpts [ groupName ] ;
208
212
var isOverlay = fullLayout . barmode === 'overlay' ;
209
213
var i , traces , tracei , calendar , pos0 , autoVals , cumulativeSpec ;
210
214
211
- var cleanBound = ( pa . type === 'date' ) ?
212
- function ( v ) { return ( v || v === 0 ) ? Lib . cleanDate ( v , null , pa . calendar ) : null ; } :
215
+ var r2c = function ( v ) { return pa . r2c ( v , 0 , calendar ) ; } ;
216
+ var c2r = function ( v ) { return pa . c2r ( v , 0 , calendar ) ; } ;
217
+
218
+ var cleanBound = pa . type === 'date' ?
219
+ function ( v ) { return ( v || v === 0 ) ? Lib . cleanDate ( v , null , calendar ) : null ; } :
213
220
function ( v ) { return isNumeric ( v ) ? Number ( v ) : null ; } ;
214
221
215
222
function setBound ( attr , bins , newBins ) {
@@ -222,28 +229,29 @@ function calcAllAutoBins(gd, trace, pa, mainData, _overlayEdgeCase) {
222
229
}
223
230
}
224
231
225
- var binOpts = fullLayout . _histogramBinOpts [ trace . _groupName ] ;
226
-
227
232
// all but the first trace in this group has already been marked finished
228
233
// clear this flag, so next time we run calc we will run autobin again
229
234
if ( trace . _autoBinFinished ) {
230
235
delete trace . _autoBinFinished ;
231
236
} else {
232
237
traces = binOpts . traces ;
233
- var sizeFound = binOpts . sizeFound ;
234
238
var allPos = [ ] ;
235
- autoVals = traces [ 0 ] . _autoBin = { } ;
239
+
236
240
// Note: we're including `legendonly` traces here for autobin purposes,
237
241
// so that showing & hiding from the legend won't affect bins.
238
242
// But this complicates things a bit since those traces don't `calc`,
239
243
// hence `isFirstVisible`.
240
244
var isFirstVisible = true ;
241
245
for ( i = 0 ; i < traces . length ; i ++ ) {
242
246
tracei = traces [ i ] ;
247
+
243
248
if ( tracei . visible ) {
244
- pos0 = tracei . _pos0 = pa . makeCalcdata ( tracei , mainData ) ;
249
+ var mainDatai = binOpts . dirs [ i ] ;
250
+ pos0 = tracei [ '_' + mainDatai + 'pos0' ] = pa . makeCalcdata ( tracei , mainDatai ) ;
251
+
245
252
allPos = Lib . concat ( allPos , pos0 ) ;
246
253
delete tracei . _autoBinFinished ;
254
+
247
255
if ( trace . visible === true ) {
248
256
if ( isFirstVisible ) {
249
257
isFirstVisible = false ;
@@ -254,10 +262,15 @@ function calcAllAutoBins(gd, trace, pa, mainData, _overlayEdgeCase) {
254
262
}
255
263
}
256
264
}
265
+
257
266
calendar = traces [ 0 ] [ mainData + 'calendar' ] ;
258
- var newBinSpec = Axes . autoBin (
259
- allPos , pa , binOpts . nbins , false , calendar , sizeFound && binOpts . size ) ;
267
+ var newBinSpec = Axes . autoBin ( allPos , pa , binOpts . nbins , false , calendar , binOpts . sizeFound && binOpts . size ) ;
268
+
269
+ var autoBin = traces [ 0 ] . _autoBin = { } ;
270
+ autoVals = autoBin [ binOpts . dirs [ 0 ] ] = { } ;
260
271
272
+ // TODO how does work with bingroup ????
273
+ //
261
274
// Edge case: single-valued histogram overlaying others
262
275
// Use them all together to calculate the bin size for the single-valued one
263
276
if ( isOverlay && newBinSpec . _dataSpan === 0 &&
@@ -274,20 +287,16 @@ function calcAllAutoBins(gd, trace, pa, mainData, _overlayEdgeCase) {
274
287
cumulativeSpec = tracei . cumulative ;
275
288
if ( cumulativeSpec . enabled && ( cumulativeSpec . currentbin !== 'include' ) ) {
276
289
if ( cumulativeSpec . direction === 'decreasing' ) {
277
- newBinSpec . start = pa . c2r ( Axes . tickIncrement (
278
- pa . r2c ( newBinSpec . start , 0 , calendar ) ,
279
- newBinSpec . size , true , calendar
280
- ) ) ;
290
+ newBinSpec . start = c2r ( Axes . tickIncrement (
291
+ r2c ( newBinSpec . start ) , newBinSpec . size , true , calendar ) ) ;
281
292
} else {
282
- newBinSpec . end = pa . c2r ( Axes . tickIncrement (
283
- pa . r2c ( newBinSpec . end , 0 , calendar ) ,
284
- newBinSpec . size , false , calendar
285
- ) ) ;
293
+ newBinSpec . end = c2r ( Axes . tickIncrement (
294
+ r2c ( newBinSpec . end ) , newBinSpec . size , false , calendar ) ) ;
286
295
}
287
296
}
288
297
289
298
binOpts . size = newBinSpec . size ;
290
- if ( ! sizeFound ) {
299
+ if ( ! binOpts . sizeFound ) {
291
300
autoVals . size = newBinSpec . size ;
292
301
Lib . nestedProperty ( traces [ 0 ] , binAttr + '.size' ) . set ( newBinSpec . size ) ;
293
302
}
@@ -296,8 +305,8 @@ function calcAllAutoBins(gd, trace, pa, mainData, _overlayEdgeCase) {
296
305
setBound ( 'end' , binOpts , newBinSpec ) ;
297
306
}
298
307
299
- pos0 = trace . _pos0 ;
300
- delete trace . _pos0 ;
308
+ pos0 = trace [ '_' + mainData + 'pos0' ] ;
309
+ delete trace [ '_' + mainData + 'pos0' ] ;
301
310
302
311
// Each trace can specify its own start/end, or if omitted
303
312
// we ensure they're beyond the bounds of this trace's data,
@@ -390,7 +399,7 @@ function handleSingleValueOverlays(gd, trace, pa, mainData, binAttr) {
390
399
// so we can use this result when we get to tracei in the normal
391
400
// course of events, mark it as done and put _pos0 back
392
401
tracei . _autoBinFinished = 1 ;
393
- tracei . _pos0 = resulti [ 1 ] ;
402
+ tracei [ '_' + mainData + 'pos0' ] = resulti [ 1 ] ;
394
403
395
404
if ( isSingleValued ) {
396
405
singleValuedTraces . push ( tracei ) ;
@@ -404,7 +413,7 @@ function handleSingleValueOverlays(gd, trace, pa, mainData, binAttr) {
404
413
// hunt through pos0 for the first valid value
405
414
var dataVals = new Array ( singleValuedTraces . length ) ;
406
415
for ( i = 0 ; i < singleValuedTraces . length ; i ++ ) {
407
- var pos0 = singleValuedTraces [ i ] . _pos0 ;
416
+ var pos0 = singleValuedTraces [ i ] [ '_' + mainData + 'pos0' ] ;
408
417
for ( var j = 0 ; j < pos0 . length ; j ++ ) {
409
418
if ( pos0 [ j ] !== undefined ) {
410
419
dataVals [ i ] = pos0 [ j ] ;
@@ -462,7 +471,6 @@ function getConnectedHistograms(gd, trace) {
462
471
return out ;
463
472
}
464
473
465
-
466
474
function cdf ( size , direction , currentBin ) {
467
475
var i , vi , prevSum ;
468
476
@@ -510,3 +518,8 @@ function cdf(size, direction, currentBin) {
510
518
}
511
519
}
512
520
}
521
+
522
+ module . exports = {
523
+ calc : calc ,
524
+ calcAllAutoBins : calcAllAutoBins
525
+ } ;
0 commit comments