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

Function multiTester

src/components/selections/select.js:620–676  ·  view source on GitHub ↗

* Wraps multiple selection testers. * * @param {Array} list - An array of selection testers. * * @return a selection tester object with a contains function * that can be called to evaluate a point against all wrapped * selection testers that were passed in list.

(list)

Source from the content-addressed store, hash-verified

618 * selection testers that were passed in list.
619 */
620function multiTester(list) {
621 if(!list.length) return;
622
623 var testers = [];
624 var xmin = isPointSelectionDef(list[0]) ? 0 : list[0][0][0];
625 var xmax = xmin;
626 var ymin = isPointSelectionDef(list[0]) ? 0 : list[0][0][1];
627 var ymax = ymin;
628
629 for(var i = 0; i < list.length; i++) {
630 if(isPointSelectionDef(list[i])) {
631 testers.push(newPointNumTester(list[i]));
632 } else {
633 var tester = polygonTester(list[i]);
634 tester.subtract = !!list[i].subtract;
635 testers.push(tester);
636
637 xmin = Math.min(xmin, tester.xmin);
638 xmax = Math.max(xmax, tester.xmax);
639 ymin = Math.min(ymin, tester.ymin);
640 ymax = Math.max(ymax, tester.ymax);
641 }
642 }
643
644 /**
645 * Tests if the given point is within this tester.
646 *
647 * @param {Array} pt - [0] is the x coordinate, [1] is the y coordinate of the point.
648 * @param {*} arg - An optional parameter to pass down to wrapped testers.
649 * @param {number} pointNumber - The point number of the point within the underlying data array.
650 * @param {number} searchInfo - An object identifying the trace the point is contained in.
651 *
652 * @return {boolean} true if point is considered to be selected, false otherwise.
653 */
654 function contains(pt, arg, pointNumber, searchInfo) {
655 var contained = false;
656 for(var i = 0; i < testers.length; i++) {
657 if(testers[i].contains(pt, arg, pointNumber, searchInfo)) {
658 // if contained by subtract tester - exclude the point
659 contained = !testers[i].subtract;
660 }
661 }
662
663 return contained;
664 }
665
666 return {
667 xmin: xmin,
668 xmax: xmax,
669 ymin: ymin,
670 ymax: ymax,
671 pts: [],
672 contains: contains,
673 isRect: false,
674 degenerate: false
675 };
676}
677

Callers 3

prepSelectFunction · 0.85
selectOnClickFunction · 0.85
addTesterFunction · 0.85

Calls 2

isPointSelectionDefFunction · 0.85
newPointNumTesterFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…