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

Function collapseArray

src/plots/cartesian/autorange.js:602–625  ·  view source on GitHub ↗

* collapseArray * * Takes items from 'array' and compares them to 'newVal', 'newPad'. * * @param {array} array: * current set of min or max extremes * @param {number} newVal: * new value to compare against * @param {number} newPad: * pad value associated with 'newVal' * @param {object}

(array, newVal, newPad, opts, atLeastAsExtreme)

Source from the content-addressed store, hash-verified

600 * - If the new pt supersedes the item, delete it from 'array'
601 */
602function collapseArray(array, newVal, newPad, opts, atLeastAsExtreme) {
603 var tozero = opts.tozero;
604 var extrapad = opts.extrapad;
605 var includeThis = true;
606
607 for(var j = 0; j < array.length && includeThis; j++) {
608 var v = array[j];
609 if(atLeastAsExtreme(v.val, newVal) && v.pad >= newPad && (v.extrapad || !extrapad)) {
610 includeThis = false;
611 break;
612 } else if(atLeastAsExtreme(newVal, v.val) && v.pad <= newPad && (extrapad || !v.extrapad)) {
613 array.splice(j, 1);
614 j--;
615 }
616 }
617 if(includeThis) {
618 var clipAtZero = (tozero && newVal === 0);
619 array.push({
620 val: newVal,
621 pad: clipAtZero ? 0 : newPad,
622 extrapad: clipAtZero ? false : extrapad
623 });
624 }
625}
626
627// In order to stop overflow errors, don't consider points
628// too close to the limits of js floating point

Callers 2

collapseMinArrayFunction · 0.85
collapseMaxArrayFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…