MCPcopy Index your code
hub / github.com/plotly/plotly.js / findExtremes

Function findExtremes

src/plots/cartesian/autorange.js:450–555  ·  view source on GitHub ↗

* findExtremes * * Find min/max extremes of an array of coordinates on a given axis. * * Note that findExtremes is called during `calc`, when we don't yet know the axis * length; all the inputs should be based solely on the trace data, nothing * about the axis layout. * * Note that `ppad` an

(ax, data, opts)

Source from the content-addressed store, hash-verified

448 * - opts {object}: a ref to the passed "options" object
449 */
450function findExtremes(ax, data, opts) {
451 if(!opts) opts = {};
452 if(!ax._m) ax.setScale();
453
454 var minArray = [];
455 var maxArray = [];
456
457 var len = data.length;
458 var extrapad = opts.padded || false;
459 var tozero = opts.tozero && (ax.type === 'linear' || ax.type === '-');
460 var isLog = ax.type === 'log';
461 var hasArrayOption = false;
462 var vpadLinearized = opts.vpadLinearized || false;
463 var i, v, di, dmin, dmax, ppadiplus, ppadiminus, vmin, vmax;
464
465 function makePadAccessor(item) {
466 if(Array.isArray(item)) {
467 hasArrayOption = true;
468 return function(i) { return Math.max(Number(item[i]||0), 0); };
469 } else {
470 var v = Math.max(Number(item||0), 0);
471 return function() { return v; };
472 }
473 }
474
475 var ppadplus = makePadAccessor((ax._m > 0 ?
476 opts.ppadplus : opts.ppadminus) || opts.ppad || 0);
477 var ppadminus = makePadAccessor((ax._m > 0 ?
478 opts.ppadminus : opts.ppadplus) || opts.ppad || 0);
479 var vpadplus = makePadAccessor(opts.vpadplus || opts.vpad);
480 var vpadminus = makePadAccessor(opts.vpadminus || opts.vpad);
481
482 if(!hasArrayOption) {
483 // with no arrays other than `data` we don't need to consider
484 // every point, only the extreme data points
485 vmin = Infinity;
486 vmax = -Infinity;
487
488 if(isLog) {
489 for(i = 0; i < len; i++) {
490 v = data[i];
491 // data is not linearized yet so we still have to filter out negative logs
492 if(v < vmin && v > 0) vmin = v;
493 if(v > vmax && v < FP_SAFE) vmax = v;
494 }
495 } else {
496 for(i = 0; i < len; i++) {
497 v = data[i];
498 if(v < vmin && v > -FP_SAFE) vmin = v;
499 if(v > vmax && v < FP_SAFE) vmax = v;
500 }
501 }
502
503 data = [vmin, vmax];
504 len = 2;
505 }
506
507 var collapseOpts = {tozero: tozero, extrapad: extrapad};

Callers 1

axes_test.jsFile · 0.50

Calls 2

makePadAccessorFunction · 0.85
addItemFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…