(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vega-util'), require('vega-expression')) : typeof define === 'function' && define.amd ? define(['exports', 'vega-util', 'vega-expression'], factory) : (global = global || self, factory(global.vega = {}, global.vega, global.vega)); }(this, (function (exports, vegaUtil, vegaExpression) { 'use strict'; const Intersect = 'intersect'; const Union = 'union'; const VlMulti = 'vlMulti'; const Or = 'or'; const And = 'and'; var 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? function testPoint(datum, entry) { var fields = entry.fields, values = entry.values, n = fields.length, i = 0, dval, f; for (; i, values: array<*>}. * Fielddef is of the form * {field: string, channel: string, type: 'E' | 'R'} where * 'type' identifies whether tuples in the dataset enumerate * values for the field, or specify a continuous range. * @param {object} datum - The tuple to test for inclusion. * @param {string} op - The set operation for combining selections. * One of 'intersect' or 'union' (default). * @return {boolean} - True if the datum is in the selection, false otherwise. */ function selectionTest(name, datum, op) { 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; for (; i (obj[fields[j].field] = curr, obj), {})); } } // Then resolve fields across units as per the op. op = op || Union; Object.keys(resolved).forEach(function (field) { resolved[field] = Object.keys(resolved[field]) .map(unit => resolved[field][unit]) .reduce((acc, curr) => acc === undefined ? curr : ops[types[field] + '_' + op](acc, curr)); }); entries = Object.keys(multiRes); if (isMulti && entries.length) { resolved[VlMulti] = op === Union ? {[Or]: entries.reduce((acc, k) => (acc.push.apply(acc, multiRes[k]), acc), [])} : {[And]: entries.map(k => ({[Or]: multiRes[k]}))}; } return resolved; } var ops = { E_union: function(base, value) { if (!base.length) return value; var i = 0, n = value.length; for (; i= 0; }); }, R_union: function(base, value) { var lo = vegaUtil.toNumber(value[0]), hi = vegaUtil.toNumber(value[1]); if (lo > hi) { lo = value[1]; hi = value[0]; } if (!base.length) return [lo, hi]; if (base[0] > lo) base[0] = lo; if (base[1] < hi) base[1] = hi; return base; }, R_intersect: function(base, value) { var lo = vegaUtil.toNumber(value[0]), hi = vegaUtil.toNumber(value[1]); if (lo > hi) { lo = value[1]; hi = value[0]; } if (!base.length) return [lo, hi]; if (hi < base[0] || base[1] < lo) { return []; } else { if (base[0] < lo) base[0] = lo; if (base[1] > hi) base[1] = hi; } return base; } }; const DataPrefix = ':', IndexPrefix = '@'; function selectionVisitor(name, args, scope, params) { if (args[0].type !== vegaExpression.Literal) vegaUtil.error('First argument to selection functions must be a string literal.'); const data = args[0].value, op = args.length >= 2 && vegaUtil.peek(args).value, field = 'unit', indexName = IndexPrefix + field, dataName = DataPrefix + data; // eslint-disable-next-line no-prototype-builtins if (op === Intersect && !vegaUtil.hasOwnProperty(params, indexName)) { params[indexName] = scope.getData(data).indataRef(scope, field); } // eslint-disable-next-line no-prototype-builtins if (!vegaUtil.hasOwnProperty(params, dataName)) { params[dataName] = scope.getData(data).tuplesRef(); } } exports.selectionResolve = selectionResolve; exports.selectionTest = selectionTest; exports.selectionVisitor = selectionVisitor; Object.defineProperty(exports, '__esModule', { value: true }); })));