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

Function testPoint

docs/app/js/sanddance-app.js:144580–144608  ·  view source on GitHub ↗
(datum, entry)

Source from the content-addressed store, hash-verified

144578const $selectionId = (0, _vegaUtil.field)(SelectionId);
144579const TYPE_ENUM = "E", TYPE_RANGE_INC = "R", TYPE_RANGE_EXC = "R-E", TYPE_RANGE_LE = "R-LE", TYPE_RANGE_RE = "R-RE", UNIT_INDEX = "index:unit"; // TODO: revisit date coercion?
144580function testPoint(datum, entry) {
144581 var fields = entry.fields, values = entry.values, n = fields.length, i = 0, dval, f;
144582 for(; i < n; ++i){
144583 f = fields[i];
144584 f.getter = (0, _vegaUtil.field).getter || (0, _vegaUtil.field)(f.field);
144585 dval = f.getter(datum);
144586 if ((0, _vegaUtil.isDate)(dval)) dval = (0, _vegaUtil.toNumber)(dval);
144587 if ((0, _vegaUtil.isDate)(values[i])) values[i] = (0, _vegaUtil.toNumber)(values[i]);
144588 if ((0, _vegaUtil.isDate)(values[i][0])) values[i] = values[i].map((0, _vegaUtil.toNumber));
144589 if (f.type === TYPE_ENUM) {
144590 // Enumerated fields can either specify individual values (single/multi selections)
144591 // or an array of values (interval selections).
144592 if ((0, _vegaUtil.isArray)(values[i]) ? values[i].indexOf(dval) < 0 : dval !== values[i]) return false;
144593 } else {
144594 if (f.type === TYPE_RANGE_INC) {
144595 if (!(0, _vegaUtil.inrange)(dval, values[i])) return false;
144596 } else if (f.type === TYPE_RANGE_RE) {
144597 // Discrete selection of bins test within the range [bin_start, bin_end).
144598 if (!(0, _vegaUtil.inrange)(dval, values[i], true, false)) return false;
144599 } else if (f.type === TYPE_RANGE_EXC) {
144600 // 'R-E'/'R-LE' included for completeness.
144601 if (!(0, _vegaUtil.inrange)(dval, values[i], false, false)) return false;
144602 } else if (f.type === TYPE_RANGE_LE) {
144603 if (!(0, _vegaUtil.inrange)(dval, values[i], false, true)) return false;
144604 }
144605 }
144606 }
144607 return true;
144608}
144609/**
144610 * Tests if a tuple is contained within an interactive selection.
144611 * @param {string} name - The name of the data set representing the selection.

Callers 1

selectionTestFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected