vega-selections
Advanced tools
Comparing version 5.0.1 to 5.1.0
@@ -5,6 +5,9 @@ (function (global, factory) { | ||
(global = global || self, factory(global.vega = {}, global.vega, global.vega)); | ||
}(this, function (exports, vegaUtil, vegaExpression) { 'use strict'; | ||
}(this, (function (exports, vegaUtil, vegaExpression) { 'use strict'; | ||
const Intersect = 'intersect'; | ||
const Union = 'union'; | ||
const VlMulti = 'vlMulti'; | ||
const Or = 'or'; | ||
const And = 'and'; | ||
@@ -120,6 +123,6 @@ var TYPE_ENUM = 'E', | ||
*/ | ||
function selectionResolve(name, op) { | ||
function selectionResolve(name, op, isMulti) { | ||
var data = this.context.data[name], | ||
entries = data ? data.values.value : [], | ||
resolved = {}, types = {}, | ||
resolved = {}, multiRes = {}, types = {}, | ||
entry, fields, values, unit, field, res, resUnit, type, union, | ||
@@ -143,2 +146,13 @@ n = entries.length, i = 0, j, m; | ||
} | ||
// If the same multi-selection is repeated over views and projected over | ||
// an encoding, it may operate over different fields making it especially | ||
// tricky to reliably resolve it. At best, we can de-dupe identical entries | ||
// but doing so may be more computationally expensive than it is worth. | ||
// Instead, for now, we simply transform our store representation into | ||
// a more human-friendly one. | ||
if (isMulti) { | ||
resUnit = multiRes[unit] || (multiRes[unit] = []); | ||
resUnit.push(vegaUtil.array(values).reduce((obj, curr, j) => (obj[fields[j].field] = curr, obj), {})); | ||
} | ||
} | ||
@@ -150,9 +164,13 @@ | ||
resolved[field] = Object.keys(resolved[field]) | ||
.map(function (unit) { return resolved[field][unit]; }) | ||
.reduce(function (acc, curr) { | ||
return acc === undefined ? curr : | ||
ops[types[field] + '_' + op](acc, curr); | ||
}); | ||
.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; | ||
@@ -235,2 +253,2 @@ } | ||
})); | ||
}))); |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vega-util"),require("vega-expression")):"function"==typeof define&&define.amd?define(["exports","vega-util","vega-expression"],t):t((e=e||self).vega={},e.vega,e.vega)}(this,function(e,t,n){"use strict";const r="intersect",i="union";var u="E",o="R",f="R-E",a="R-LE",s="R-RE",l="index:unit";function c(e,n){for(var r,i,l=n.fields,c=n.values,g=l.length,v=0;v<g;++v)if((i=l[v]).getter=t.field.getter||t.field(i.field),r=i.getter(e),t.isDate(r)&&(r=t.toNumber(r)),t.isDate(c[v])&&(c[v]=t.toNumber(c[v])),t.isDate(c[v][0])&&(c[v]=c[v].map(t.toNumber)),i.type===u){if(t.isArray(c[v])?c[v].indexOf(r)<0:r!==c[v])return!1}else if(i.type===o){if(!t.inrange(r,c[v]))return!1}else if(i.type===s){if(!t.inrange(r,c[v],!0,!1))return!1}else if(i.type===f){if(!t.inrange(r,c[v],!1,!1))return!1}else if(i.type===a&&!t.inrange(r,c[v],!1,!0))return!1;return!0}var g={E_union:function(e,t){if(!e.length)return t;for(var n=0,r=t.length;n<r;++n)e.indexOf(t[n])<0&&e.push(t[n]);return e},E_intersect:function(e,t){return e.length?e.filter(function(e){return t.indexOf(e)>=0}):t},R_union:function(e,n){var r=t.toNumber(n[0]),i=t.toNumber(n[1]);return r>i&&(r=n[1],i=n[0]),e.length?(e[0]>r&&(e[0]=r),e[1]<i&&(e[1]=i),e):[r,i]},R_intersect:function(e,n){var r=t.toNumber(n[0]),i=t.toNumber(n[1]);return r>i&&(r=n[1],i=n[0]),e.length?i<e[0]||e[1]<r?[]:(e[0]<r&&(e[0]=r),e[1]>i&&(e[1]=i),e):[r,i]}};const v=":",d="@";e.selectionResolve=function(e,n){for(var r,u,o,f,a,s,l,c,v,d,p,h=this.context.data[e],y=h?h.values.value:[],m={},b={},x=y.length,R=0;R<x;++R)for(f=(r=y[R]).unit,u=r.fields,o=r.values,d=0,p=u.length;d<p;++d)a=u[d],l=(s=m[a.field]||(m[a.field]={}))[f]||(s[f]=[]),b[a.field]=c=a.type.charAt(0),v=g[c+"_union"],s[f]=v(l,t.array(o[d]));return n=n||i,Object.keys(m).forEach(function(e){m[e]=Object.keys(m[e]).map(function(t){return m[e][t]}).reduce(function(t,r){return void 0===t?r:g[b[e]+"_"+n](t,r)})}),m},e.selectionTest=function(e,t,n){for(var i,u,o,f,a,s=this.context.data[e],g=s?s.values.value:[],v=s?s[l]&&s[l].value:void 0,d=n===r,p=g.length,h=0;h<p;++h)if(i=g[h],v&&d){if(-1===(o=(u=u||{})[f=i.unit]||0))continue;if(a=c(t,i),u[f]=a?-1:++o,a&&1===v.size)return!0;if(!a&&o===v.get(f).count)return!1}else if(d^(a=c(t,i)))return a;return p&&d},e.selectionVisitor=function(e,i,u,o){i[0].type!==n.Literal&&t.error("First argument to selection functions must be a string literal.");const f=i[0].value,a=i.length>=2&&t.peek(i).value,s=d+"unit",l=v+f;a!==r||t.hasOwnProperty(o,s)||(o[s]=u.getData(f).indataRef(u,"unit")),t.hasOwnProperty(o,l)||(o[l]=u.getData(f).tuplesRef())},Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vega-util"),require("vega-expression")):"function"==typeof define&&define.amd?define(["exports","vega-util","vega-expression"],t):t((e=e||self).vega={},e.vega,e.vega)}(this,(function(e,t,n){"use strict";const r="intersect",i="union",u="vlMulti",o="or",a="and";var f="E",s="R",l="R-E",c="R-LE",d="R-RE",g="index:unit";function v(e,n){for(var r,i,u=n.fields,o=n.values,a=u.length,g=0;g<a;++g)if((i=u[g]).getter=t.field.getter||t.field(i.field),r=i.getter(e),t.isDate(r)&&(r=t.toNumber(r)),t.isDate(o[g])&&(o[g]=t.toNumber(o[g])),t.isDate(o[g][0])&&(o[g]=o[g].map(t.toNumber)),i.type===f){if(t.isArray(o[g])?o[g].indexOf(r)<0:r!==o[g])return!1}else if(i.type===s){if(!t.inrange(r,o[g]))return!1}else if(i.type===d){if(!t.inrange(r,o[g],!0,!1))return!1}else if(i.type===l){if(!t.inrange(r,o[g],!1,!1))return!1}else if(i.type===c&&!t.inrange(r,o[g],!1,!0))return!1;return!0}var p={E_union:function(e,t){if(!e.length)return t;for(var n=0,r=t.length;n<r;++n)e.indexOf(t[n])<0&&e.push(t[n]);return e},E_intersect:function(e,t){return e.length?e.filter((function(e){return t.indexOf(e)>=0})):t},R_union:function(e,n){var r=t.toNumber(n[0]),i=t.toNumber(n[1]);return r>i&&(r=n[1],i=n[0]),e.length?(e[0]>r&&(e[0]=r),e[1]<i&&(e[1]=i),e):[r,i]},R_intersect:function(e,n){var r=t.toNumber(n[0]),i=t.toNumber(n[1]);return r>i&&(r=n[1],i=n[0]),e.length?i<e[0]||e[1]<r?[]:(e[0]<r&&(e[0]=r),e[1]>i&&(e[1]=i),e):[r,i]}};const h=":",y="@";e.selectionResolve=function(e,n,r){for(var f,s,l,c,d,g,v,h,y,m,b,x=this.context.data[e],R=x?x.values.value:[],O={},_={},E={},N=R.length,j=0;j<N;++j){for(c=(f=R[j]).unit,s=f.fields,l=f.values,m=0,b=s.length;m<b;++m)d=s[m],v=(g=O[d.field]||(O[d.field]={}))[c]||(g[c]=[]),E[d.field]=h=d.type.charAt(0),y=p[h+"_union"],g[c]=y(v,t.array(l[m]));r&&(v=_[c]||(_[c]=[])).push(t.array(l).reduce((e,t,n)=>(e[s[n].field]=t,e),{}))}return n=n||i,Object.keys(O).forEach((function(e){O[e]=Object.keys(O[e]).map(t=>O[e][t]).reduce((t,r)=>void 0===t?r:p[E[e]+"_"+n](t,r))})),R=Object.keys(_),r&&R.length&&(O[u]=n===i?{[o]:R.reduce((e,t)=>(e.push.apply(e,_[t]),e),[])}:{[a]:R.map(e=>({[o]:_[e]}))}),O},e.selectionTest=function(e,t,n){for(var i,u,o,a,f,s=this.context.data[e],l=s?s.values.value:[],c=s?s[g]&&s[g].value:void 0,d=n===r,p=l.length,h=0;h<p;++h)if(i=l[h],c&&d){if(-1===(o=(u=u||{})[a=i.unit]||0))continue;if(f=v(t,i),u[a]=f?-1:++o,f&&1===c.size)return!0;if(!f&&o===c.get(a).count)return!1}else if(d^(f=v(t,i)))return f;return p&&d},e.selectionVisitor=function(e,i,u,o){i[0].type!==n.Literal&&t.error("First argument to selection functions must be a string literal.");const a=i[0].value,f=i.length>=2&&t.peek(i).value,s=y+"unit",l=h+a;f!==r||t.hasOwnProperty(o,s)||(o[s]=u.getData(a).indataRef(u,"unit")),t.hasOwnProperty(o,l)||(o[l]=u.getData(a).tuplesRef())},Object.defineProperty(e,"__esModule",{value:!0})})); |
{ | ||
"name": "vega-selections", | ||
"version": "5.0.1", | ||
"version": "5.1.0", | ||
"description": "Vega expression functions for Vega-Lite selections.", | ||
@@ -29,3 +29,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "b45fc90406ce2de167073b73d4ae5cf79c5e1705" | ||
"gitHead": "8180e8ca9379dec7f1722ce0ebd2aa01083be7b2" | ||
} |
export const Intersect = 'intersect'; | ||
export const Union = 'union'; | ||
export const VlMulti = 'vlMulti'; | ||
export const Or = 'or'; | ||
export const And = 'and'; |
@@ -1,2 +0,2 @@ | ||
import {Union} from './constants'; | ||
import {Union, VlMulti, Or, And} from './constants'; | ||
import {array, toNumber} from 'vega-util'; | ||
@@ -11,6 +11,6 @@ | ||
*/ | ||
export function selectionResolve(name, op) { | ||
export function selectionResolve(name, op, isMulti) { | ||
var data = this.context.data[name], | ||
entries = data ? data.values.value : [], | ||
resolved = {}, types = {}, | ||
resolved = {}, multiRes = {}, types = {}, | ||
entry, fields, values, unit, field, res, resUnit, type, union, | ||
@@ -34,2 +34,13 @@ n = entries.length, i = 0, j, m; | ||
} | ||
// If the same multi-selection is repeated over views and projected over | ||
// an encoding, it may operate over different fields making it especially | ||
// tricky to reliably resolve it. At best, we can de-dupe identical entries | ||
// but doing so may be more computationally expensive than it is worth. | ||
// Instead, for now, we simply transform our store representation into | ||
// a more human-friendly one. | ||
if (isMulti) { | ||
resUnit = multiRes[unit] || (multiRes[unit] = []); | ||
resUnit.push(array(values).reduce((obj, curr, j) => (obj[fields[j].field] = curr, obj), {})); | ||
} | ||
} | ||
@@ -41,9 +52,13 @@ | ||
resolved[field] = Object.keys(resolved[field]) | ||
.map(function (unit) { return resolved[field][unit]; }) | ||
.reduce(function (acc, curr) { | ||
return acc === undefined ? curr : | ||
ops[types[field] + '_' + op](acc, curr); | ||
}); | ||
.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; | ||
@@ -50,0 +65,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23156
422