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