@@ -19,7 +19,6 @@ module.exports = {
19
19
getAutoRange : getAutoRange ,
20
20
makePadFn : makePadFn ,
21
21
doAutoRange : doAutoRange ,
22
- expand : expand ,
23
22
findExtremes : findExtremes ,
24
23
concatExtremes : concatExtremes
25
24
} ;
@@ -265,160 +264,6 @@ function doAutoRange(gd, ax) {
265
264
}
266
265
}
267
266
268
- /*
269
- * expand: if autoranging, include new data in the outer limits for this axis.
270
- * Note that `expand` is called during `calc`, when we don't yet know the axis
271
- * length; all the inputs should be based solely on the trace data, nothing
272
- * about the axis layout.
273
- * Note that `ppad` and `vpad` as well as their asymmetric variants refer to
274
- * the before and after padding of the passed `data` array, not to the whole axis.
275
- *
276
- * @param {object } ax: the axis being expanded. The result will be more entries
277
- * in ax._min and ax._max if necessary to include the new data
278
- * @param {array } data: an array of numbers (ie already run through ax.d2c)
279
- * @param {object } options: available keys are:
280
- * vpad: (number or number array) pad values (data value +-vpad)
281
- * ppad: (number or number array) pad pixels (pixel location +-ppad)
282
- * ppadplus, ppadminus, vpadplus, vpadminus:
283
- * separate padding for each side, overrides symmetric
284
- * padded: (boolean) add 5% padding to both ends
285
- * (unless one end is overridden by tozero)
286
- * tozero: (boolean) make sure to include zero if axis is linear,
287
- * and make it a tight bound if possible
288
- */
289
- function expand ( ax , data , options ) {
290
- if ( ! ax . _min ) ax . _min = [ ] ;
291
- if ( ! ax . _max ) ax . _max = [ ] ;
292
- if ( ! options ) options = { } ;
293
- if ( ! ax . _m ) ax . setScale ( ) ;
294
-
295
- var len = data . length ;
296
- var extrapad = options . padded || false ;
297
- var tozero = options . tozero && ( ax . type === 'linear' || ax . type === '-' ) ;
298
- var isLog = ( ax . type === 'log' ) ;
299
-
300
- var i , j , k , v , di , dmin , dmax , ppadiplus , ppadiminus , includeThis , vmin , vmax ;
301
-
302
- var hasArrayOption = false ;
303
-
304
- function makePadAccessor ( item ) {
305
- if ( Array . isArray ( item ) ) {
306
- hasArrayOption = true ;
307
- return function ( i ) { return Math . max ( Number ( item [ i ] || 0 ) , 0 ) ; } ;
308
- }
309
- else {
310
- var v = Math . max ( Number ( item || 0 ) , 0 ) ;
311
- return function ( ) { return v ; } ;
312
- }
313
- }
314
-
315
- var ppadplus = makePadAccessor ( ( ax . _m > 0 ?
316
- options . ppadplus : options . ppadminus ) || options . ppad || 0 ) ;
317
- var ppadminus = makePadAccessor ( ( ax . _m > 0 ?
318
- options . ppadminus : options . ppadplus ) || options . ppad || 0 ) ;
319
- var vpadplus = makePadAccessor ( options . vpadplus || options . vpad ) ;
320
- var vpadminus = makePadAccessor ( options . vpadminus || options . vpad ) ;
321
-
322
- if ( ! hasArrayOption ) {
323
- // with no arrays other than `data` we don't need to consider
324
- // every point, only the extreme data points
325
- vmin = Infinity ;
326
- vmax = - Infinity ;
327
-
328
- if ( isLog ) {
329
- for ( i = 0 ; i < len ; i ++ ) {
330
- v = data [ i ] ;
331
- // data is not linearized yet so we still have to filter out negative logs
332
- if ( v < vmin && v > 0 ) vmin = v ;
333
- if ( v > vmax && v < FP_SAFE ) vmax = v ;
334
- }
335
- }
336
- else {
337
- for ( i = 0 ; i < len ; i ++ ) {
338
- v = data [ i ] ;
339
- if ( v < vmin && v > - FP_SAFE ) vmin = v ;
340
- if ( v > vmax && v < FP_SAFE ) vmax = v ;
341
- }
342
- }
343
-
344
- data = [ vmin , vmax ] ;
345
- len = 2 ;
346
- }
347
-
348
- function addItem ( i ) {
349
- di = data [ i ] ;
350
- if ( ! isNumeric ( di ) ) return ;
351
- ppadiplus = ppadplus ( i ) ;
352
- ppadiminus = ppadminus ( i ) ;
353
- vmin = di - vpadminus ( i ) ;
354
- vmax = di + vpadplus ( i ) ;
355
- // special case for log axes: if vpad makes this object span
356
- // more than an order of mag, clip it to one order. This is so
357
- // we don't have non-positive errors or absurdly large lower
358
- // range due to rounding errors
359
- if ( isLog && vmin < vmax / 10 ) vmin = vmax / 10 ;
360
-
361
- dmin = ax . c2l ( vmin ) ;
362
- dmax = ax . c2l ( vmax ) ;
363
-
364
- if ( tozero ) {
365
- dmin = Math . min ( 0 , dmin ) ;
366
- dmax = Math . max ( 0 , dmax ) ;
367
- }
368
-
369
- for ( k = 0 ; k < 2 ; k ++ ) {
370
- var newVal = k ? dmax : dmin ;
371
- if ( goodNumber ( newVal ) ) {
372
- var extremes = k ? ax . _max : ax . _min ;
373
- var newPad = k ? ppadiplus : ppadiminus ;
374
- var atLeastAsExtreme = k ? greaterOrEqual : lessOrEqual ;
375
-
376
- includeThis = true ;
377
- /*
378
- * Take items v from ax._min/_max and compare them to the presently active point:
379
- * - Since we don't yet know the relationship between pixels and values
380
- * (that's what we're trying to figure out!) AND we don't yet know how
381
- * many pixels `extrapad` represents (it's going to be 5% of the length,
382
- * but we don't want to have to redo _min and _max just because length changed)
383
- * two point must satisfy three criteria simultaneously for one to supersede the other:
384
- * - at least as extreme a `val`
385
- * - at least as big a `pad`
386
- * - an unpadded point cannot supersede a padded point, but any other combination can
387
- *
388
- * - If the item supersedes the new point, set includethis false
389
- * - If the new pt supersedes the item, delete it from ax._min/_max
390
- */
391
- for ( j = 0 ; j < extremes . length && includeThis ; j ++ ) {
392
- v = extremes [ j ] ;
393
- if ( atLeastAsExtreme ( v . val , newVal ) && v . pad >= newPad && ( v . extrapad || ! extrapad ) ) {
394
- includeThis = false ;
395
- break ;
396
- }
397
- else if ( atLeastAsExtreme ( newVal , v . val ) && v . pad <= newPad && ( extrapad || ! v . extrapad ) ) {
398
- extremes . splice ( j , 1 ) ;
399
- j -- ;
400
- }
401
- }
402
- if ( includeThis ) {
403
- var clipAtZero = ( tozero && newVal === 0 ) ;
404
- extremes . push ( {
405
- val : newVal ,
406
- pad : clipAtZero ? 0 : newPad ,
407
- extrapad : clipAtZero ? false : extrapad
408
- } ) ;
409
- }
410
- }
411
- }
412
- }
413
-
414
- // For efficiency covering monotonic or near-monotonic data,
415
- // check a few points at both ends first and then sweep
416
- // through the middle
417
- var iMax = Math . min ( 6 , len ) ;
418
- for ( i = 0 ; i < iMax ; i ++ ) addItem ( i ) ;
419
- for ( i = len - 1 ; i >= iMax ; i -- ) addItem ( i ) ;
420
- }
421
-
422
267
/**
423
268
* findExtremes
424
269
*
0 commit comments