MCPcopy Create free account
hub / github.com/microsoft/SandDance / selectionTest

Function selectionTest

docs/app/js/sanddance-app.js:144622–144645  ·  view source on GitHub ↗

* Tests if a tuple is contained within an interactive selection. * @param {string} name - The name of the data set representing the selection. * Tuples in the dataset are of the form * {unit: string, fields: array , values: array<*>}. * Fielddef is of the form * {field: string, cha

(name, datum, op)

Source from the content-addressed store, hash-verified

144620 * One of 'intersect' or 'union' (default).
144621 * @return {boolean} - True if the datum is in the selection, false otherwise.
144622 */ function selectionTest(name, datum, op) {
144623 var data = this.context.data[name], entries = data ? data.values.value : [], unitIdx = data ? data[UNIT_INDEX] && data[UNIT_INDEX].value : undefined, intersect = op === Intersect, n = entries.length, i = 0, entry, miss, count, unit, b;
144624 for(; i < n; ++i){
144625 entry = entries[i];
144626 if (unitIdx && intersect) {
144627 // multi selections union within the same unit and intersect across units.
144628 miss = miss || {};
144629 count = miss[unit = entry.unit] || 0; // if we've already matched this unit, skip.
144630 if (count === -1) continue;
144631 b = testPoint(datum, entry);
144632 miss[unit] = b ? -1 : ++count; // if we match and there are no other units return true
144633 // if we've missed against all tuples in this unit return false
144634 if (b && unitIdx.size === 1) return true;
144635 if (!b && count === unitIdx.get(unit).count) return false;
144636 } else {
144637 b = testPoint(datum, entry); // if we find a miss and we do require intersection return false
144638 // if we find a match and we don't require intersection return true
144639 if (intersect ^ b) return b;
144640 }
144641 } // if intersecting and we made it here, then we saw no misses
144642 // if not intersecting, then we saw no matches
144643 // if no active selections, return false
144644 return n && intersect;
144645}
144646const bisect = (0, _d3Array.bisector)($selectionId), bisectLeft = bisect.left, bisectRight = bisect.right;
144647function selectionIdTest(name, datum, op) {
144648 const data = this.context.data[name], entries = data ? data.values.value : [], unitIdx = data ? data[UNIT_INDEX] && data[UNIT_INDEX].value : undefined, intersect = op === Intersect, value = $selectionId(datum), index = bisectLeft(entries, value);

Callers

nothing calls this directly

Calls 2

testPointFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected