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

Function selectionResolve

docs/app/js/sanddance-app.js:144682–144740  ·  view source on GitHub ↗

* Resolves selection for use as a scale domain or reads via the API. * @param {string} name - The name of the dataset representing the selection * @param {string} [op='union'] - The set operation for combining selections. * One of 'intersect' or 'union' (default). * @param {boole

(name, op, isMulti, vl5)

Source from the content-addressed store, hash-verified

144680 * a major version bump for Vega.
144681 * @returns {object} An object of selected fields and values.
144682 */ function selectionResolve(name, op, isMulti, vl5) {
144683 var data = this.context.data[name], entries = data ? data.values.value : [], resolved = {}, multiRes = {}, types = {}, entry, fields, values, unit1, field1, value, res, resUnit, type, union, n = entries.length, i = 0, j1, m; // First union all entries within the same unit.
144684 for(; i < n; ++i){
144685 entry = entries[i];
144686 unit1 = entry.unit;
144687 fields = entry.fields;
144688 values = entry.values;
144689 if (fields && values) {
144690 // Intentional selection stores
144691 for(j1 = 0, m = fields.length; j1 < m; ++j1){
144692 field1 = fields[j1];
144693 res = resolved[field1.field] || (resolved[field1.field] = {});
144694 resUnit = res[unit1] || (res[unit1] = []);
144695 types[field1.field] = type = field1.type.charAt(0);
144696 union = ops["".concat(type, "_union")];
144697 res[unit1] = union(resUnit, (0, _vegaUtil.array)(values[j1]));
144698 } // If the same multi-selection is repeated over views and projected over
144699 // an encoding, it may operate over different fields making it especially
144700 // tricky to reliably resolve it. At best, we can de-dupe identical entries
144701 // but doing so may be more computationally expensive than it is worth.
144702 // Instead, for now, we simply transform our store representation into
144703 // a more human-friendly one.
144704 if (isMulti) {
144705 resUnit = multiRes[unit1] || (multiRes[unit1] = []);
144706 resUnit.push((0, _vegaUtil.array)(values).reduce((obj, curr, j)=>(obj[fields[j].field] = curr, obj), {}));
144707 }
144708 } else {
144709 // Short circuit extensional selectionId stores which hold sorted IDs unique to each unit.
144710 field1 = SelectionId;
144711 value = $selectionId(entry);
144712 res = resolved[field1] || (resolved[field1] = {});
144713 resUnit = res[unit1] || (res[unit1] = []);
144714 resUnit.push(value);
144715 if (isMulti) {
144716 resUnit = multiRes[unit1] || (multiRes[unit1] = []);
144717 resUnit.push({
144718 [SelectionId]: value
144719 });
144720 }
144721 }
144722 } // Then resolve fields across units as per the op.
144723 op = op || Union;
144724 if (resolved[SelectionId]) resolved[SelectionId] = ops["".concat(SelectionId, "_").concat(op)](...Object.values(resolved[SelectionId]));
144725 else Object.keys(resolved).forEach((field)=>{
144726 resolved[field] = Object.keys(resolved[field]).map((unit)=>resolved[field][unit]).reduce((acc, curr)=>acc === undefined ? curr : ops["".concat(types[field], "_").concat(op)](acc, curr));
144727 });
144728 entries = Object.keys(multiRes);
144729 if (isMulti && entries.length) {
144730 const key = vl5 ? VlPoint : VlMulti;
144731 resolved[key] = op === Union ? {
144732 [Or]: entries.reduce((acc, k)=>(acc.push(...multiRes[k]), acc), [])
144733 } : {
144734 [And]: entries.map((k)=>({
144735 [Or]: multiRes[k]
144736 }))
144737 };
144738 }
144739 return resolved;

Callers

nothing calls this directly

Calls 2

unionFunction · 0.70
forEachMethod · 0.45

Tested by

no test coverage detected