vega-functions
Advanced tools
Comparing version 5.7.1 to 5.7.2
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vega-util'), require('vega-expression'), require('d3-geo'), require('d3-color'), require('vega-dataflow'), require('vega-scale'), require('vega-scenegraph'), require('vega-selections'), require('vega-statistics'), require('vega-time'), require('d3-array')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'vega-util', 'vega-expression', 'd3-geo', 'd3-color', 'vega-dataflow', 'vega-scale', 'vega-scenegraph', 'vega-selections', 'vega-statistics', 'vega-time', 'd3-array'], factory) : | ||
(global = global || self, factory(global.vega = {}, global.vega, global.vega, global.d3, global.d3, global.vega, global.vega, global.vega, global.vega, global.vega, global.vega, global.d3)); | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.vega = {}, global.vega, global.vega, global.d3, global.d3, global.vega, global.vega, global.vega, global.vega, global.vega, global.vega, global.d3)); | ||
}(this, (function (exports, vegaUtil, vegaExpression, d3Geo, d3Color, vegaDataflow, vegaScale, vegaScenegraph, vegaSelections, vegaStatistics, vegaTime, d3Array) { 'use strict'; | ||
@@ -47,3 +47,3 @@ | ||
var dateObj = new Date(2000, 0, 1); | ||
const dateObj = new Date(2000, 0, 1); | ||
@@ -240,3 +240,3 @@ function time(month, day, specifier) { | ||
function merge() { | ||
var args = [].slice.call(arguments); | ||
const args = [].slice.call(arguments); | ||
args.unshift({}); | ||
@@ -488,3 +488,3 @@ return vegaUtil.extend.apply(null, args); | ||
const functionContext = { | ||
random: function() { return vegaStatistics.random(); }, // override default | ||
random() { return vegaStatistics.random(); }, // override default | ||
cumulativeNormal: vegaStatistics.cumulativeNormal, | ||
@@ -505,3 +505,3 @@ cumulativeLogNormal: vegaStatistics.cumulativeLogNormal, | ||
isDate: vegaUtil.isDate, | ||
isDefined: function(_) { return _ !== undefined; }, | ||
isDefined(_) { return _ !== undefined; }, | ||
isNumber: vegaUtil.isNumber, | ||
@@ -512,3 +512,3 @@ isObject: vegaUtil.isObject, | ||
isTuple: vegaDataflow.isTuple, | ||
isValid: function(_) { return _ != null && _ === _; }, | ||
isValid(_) { return _ != null && _ === _; }, | ||
toBoolean: vegaUtil.toBoolean, | ||
@@ -585,2 +585,16 @@ toDate: vegaUtil.toDate, | ||
// export code generator parameters | ||
const codegenParams = { | ||
blacklist: ['_'], | ||
whitelist: ['datum', 'event', 'item'], | ||
fieldvar: 'datum', | ||
globalvar: id => `_[${vegaUtil.stringValue(SignalPrefix + id)}]`, | ||
functions: buildFunctions, | ||
constants: vegaExpression.constants, | ||
visitors: astVisitors | ||
}; | ||
// export code generator | ||
const codeGenerator = vegaExpression.codegen(codegenParams); | ||
// Build expression function registry | ||
@@ -634,17 +648,4 @@ function buildFunctions(codegen) { | ||
// Export code generator and parameters | ||
const codegenParams = { | ||
blacklist: ['_'], | ||
whitelist: ['datum', 'event', 'item'], | ||
fieldvar: 'datum', | ||
globalvar: id => '_[' + vegaUtil.stringValue(SignalPrefix + id) + ']', | ||
functions: buildFunctions, | ||
constants: vegaExpression.constants, | ||
visitors: astVisitors | ||
}; | ||
var codeGenerator = vegaExpression.codegen(codegenParams); | ||
function parser(expr, scope) { | ||
var params = {}, ast, gen; | ||
let params = {}, ast, gen; | ||
@@ -662,4 +663,4 @@ // parse the expression to an abstract syntax tree (ast) | ||
if (node.type !== vegaExpression.CallExpression) return; | ||
var name = node.callee.name, | ||
visit = codegenParams.visitors[name]; | ||
const name = node.callee.name, | ||
visit = codegenParams.visitors[name]; | ||
if (visit) visit(name, node.arguments, scope, params); | ||
@@ -673,3 +674,3 @@ }); | ||
gen.globals.forEach(name => { | ||
var signalName = SignalPrefix + name; | ||
const signalName = SignalPrefix + name; | ||
if (!vegaUtil.hasOwnProperty(params, signalName) && scope.getSignal(name)) { | ||
@@ -676,0 +677,0 @@ params[signalName] = scope.signalRef(name); |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("vega-util"),require("vega-expression"),require("d3-geo"),require("d3-color"),require("vega-dataflow"),require("vega-scale"),require("vega-scenegraph"),require("vega-selections"),require("vega-statistics"),require("vega-time"),require("d3-array")):"function"==typeof define&&define.amd?define(["exports","vega-util","vega-expression","d3-geo","d3-color","vega-dataflow","vega-scale","vega-scenegraph","vega-selections","vega-statistics","vega-time","d3-array"],e):e((t=t||self).vega={},t.vega,t.vega,t.d3,t.d3,t.vega,t.vega,t.vega,t.vega,t.vega,t.vega,t.d3)}(this,(function(t,e,n,r,a,o,i,s,c,u,l,f){"use strict";function d(t){const e=this.context.data[t];return e?e.values.value:[]}function m(t,e,n){const r=this.context.data[t]["index:"+e],a=r?r.value.get(n):void 0;return a?a.count:a}function g(t,n){const r=this.context.dataflow,a=this.context.data[t].input;return r.pulse(a,r.changeset().remove(e.truthy).insert(n)),1}function p(t,e,n){if(t){const n=this.context.dataflow,r=t.mark.source;n.pulse(r,n.changeset().encode(t,e))}return void 0!==n?n:t}const h=t=>function(e,n){return this.context.dataflow.locale()[t](n)(e)},v=h("format"),y=h("timeFormat"),x=h("utcFormat"),b=h("timeParse"),w=h("utcParse");var S=new Date(2e3,0,1);function q(t,e,n){return Number.isInteger(t)&&Number.isInteger(e)?(S.setYear(2e3),S.setMonth(t),S.setDate(e),y.call(this,S,n)):""}function P(t){return q.call(this,t,1,"%B")}function N(t){return q.call(this,t,1,"%b")}function L(t){return q.call(this,0,2+t,"%A")}function A(t){return q.call(this,0,2+t,"%a")}function F(t,r,a,o){r[0].type!==n.Literal&&e.error("First argument to data functions must be a string literal.");const i=r[0].value,s=":"+i;if(!e.hasOwnProperty(s,o))try{o[s]=a.getData(i).tuplesRef()}catch(t){}}function k(t,r,a,o){r[0].type!==n.Literal&&e.error("First argument to indata must be a string literal."),r[1].type!==n.Literal&&e.error("Second argument to indata must be a string literal.");const i=r[0].value,s=r[1].value,c="@"+s;e.hasOwnProperty(c,o)||(o[c]=a.getData(i).indataRef(a,s))}function _(t,e,r,a){if(e[0].type===n.Literal)O(r,a,e[0].value);else for(t in r.scales)O(r,a,t)}function O(t,n,r){const a="%"+r;if(!e.hasOwnProperty(n,a))try{n[a]=t.scaleRef(r)}catch(t){}}function R(t,n){let r;return e.isFunction(t)?t:e.isString(t)?(r=n.scales[t])&&r.value:void 0}function z(t,e){return function(n,r,a){if(n){const e=R(n,(a||this).context);return e&&e.path[t](r)}return e(r)}}const D=z("area",r.geoArea),E=z("bounds",r.geoBounds),U=z("centroid",r.geoCentroid);function V(t){let e=this.context.group,n=!1;if(e)for(;t;){if(t===e){n=!0;break}t=t.mark.group}return n}function B(t,e,n){try{t[e].apply(t,["EXPRESSION"].concat([].slice.call(n)))}catch(e){t.warn(e)}return n[n.length-1]}function $(){return B(this.context.dataflow,"warn",arguments)}function M(){return B(this.context.dataflow,"info",arguments)}function j(){return B(this.context.dataflow,"debug",arguments)}function C(t){const e=t/255;return e<=.03928?e/12.92:Math.pow((e+.055)/1.055,2.4)}function T(t){const e=a.rgb(t);return.2126*C(e.r)+.7152*C(e.g)+.0722*C(e.b)}function X(t,e){const n=T(t),r=T(e);return(Math.max(n,r)+.05)/(Math.min(n,r)+.05)}function Y(){var t=[].slice.call(arguments);return t.unshift({}),e.extend.apply(null,t)}function I(t,n){return t===n||t!=t&&n!=n||(e.isArray(t)?!(!e.isArray(n)||t.length!==n.length)&&function(t,e){for(let n=0,r=t.length;n<r;++n)if(!I(t[n],e[n]))return!1;return!0}(t,n):!(!e.isObject(t)||!e.isObject(n))&&G(t,n))}function G(t,e){for(let n in t)if(!I(t[n],e[n]))return!1;return!0}function H(t){return e=>G(t,e)}function W(t,n,r,a,i,s){let c,u,l=this.context.dataflow,f=this.context.data[t],d=f.input,m=f.changes,g=l.stamp();if(!1===l._trigger||!(d.value.length||n||a))return 0;if((!m||m.stamp<g)&&(f.changes=m=l.changeset(),m.stamp=g,l.runAfter((function(){f.modified=!0,l.pulse(d,m).run()}),!0,1)),r&&(c=!0===r?e.truthy:e.isArray(r)||o.isTuple(r)?r:H(r),m.remove(c)),n&&m.insert(n),a&&(c=H(a),d.value.some(c)?m.remove(c):m.insert(a)),i)for(u in s)m.modify(i,u,s[u]);return 1}function J(t){const e=t.touches,n=e[0].clientX-e[1].clientX,r=e[0].clientY-e[1].clientY;return Math.sqrt(n*n+r*r)}function K(t){const e=t.touches;return Math.atan2(e[0].clientY-e[1].clientY,e[0].clientX-e[1].clientX)}function Q(t,e,n){return i.bandSpace(t||0,e||0,n||0)}function Z(t,e){const n=R(t,(e||this).context);return n&&n.bandwidth?n.bandwidth():0}function tt(t,e){const n=R(t,(e||this).context);return n?n.copy():void 0}function et(t,e){const n=R(t,(e||this).context);return n?n.domain():[]}function nt(t,n,r){const a=R(t,(r||this).context);return a?e.isArray(n)?(a.invertRange||a.invert)(n):(a.invert||a.invertExtent)(n):void 0}function rt(t,e){const n=R(t,(e||this).context);return n&&n.range?n.range():[]}function at(t,e,n){const r=R(t,(n||this).context);return r?r(e):void 0}function ot(t,n,r,a,o){t=R(t,(o||this).context);const c=s.Gradient(n,r);let u=t.domain(),l=u[0],f=e.peek(u),d=e.identity;return f-l?d=i.scaleFraction(t,l,f):t=(t.interpolator?i.scale("sequential")().interpolator(t.interpolator()):i.scale("linear")().interpolate(t.interpolate()).range(t.range())).domain([l=0,f=1]),t.ticks&&(u=t.ticks(+a||15),l!==u[0]&&u.unshift(l),f!==e.peek(u)&&u.push(f)),u.forEach(e=>c.stop(d(e),t(e))),c}function it(t,e,n){const r=R(t,(n||this).context);return function(t){return r?r.path.context(t)(e):""}}function st(t){let e=null;return function(n){return n?s.pathRender(n,e=e||s.pathParse(t)):t}}const ct=t=>t.data;function ut(t,e){const n=d.call(e,t);return n.root&&n.root.lookup||{}}function lt(t,e,n){const r=ut(t,this),a=r[e],o=r[n];return a&&o?a.path(o).map(ct):void 0}function ft(t,e){const n=ut(t,this)[e];return n?n.ancestors().map(ct):void 0}const dt=()=>"undefined"!=typeof window&&window||null;function mt(){const t=dt();return t?t.screen:{}}function gt(){const t=dt();return t?[t.innerWidth,t.innerHeight]:[void 0,void 0]}function pt(){const t=this.context.dataflow,e=t.container&&t.container();return e?[e.clientWidth,e.clientHeight]:[void 0,void 0]}const ht={random:function(){return u.random()},cumulativeNormal:u.cumulativeNormal,cumulativeLogNormal:u.cumulativeLogNormal,cumulativeUniform:u.cumulativeUniform,densityNormal:u.densityNormal,densityLogNormal:u.densityLogNormal,densityUniform:u.densityUniform,quantileNormal:u.quantileNormal,quantileLogNormal:u.quantileLogNormal,quantileUniform:u.quantileUniform,sampleNormal:u.sampleNormal,sampleLogNormal:u.sampleLogNormal,sampleUniform:u.sampleUniform,isArray:e.isArray,isBoolean:e.isBoolean,isDate:e.isDate,isDefined:function(t){return void 0!==t},isNumber:e.isNumber,isObject:e.isObject,isRegExp:e.isRegExp,isString:e.isString,isTuple:o.isTuple,isValid:function(t){return null!=t&&t==t},toBoolean:e.toBoolean,toDate:e.toDate,toNumber:e.toNumber,toString:e.toString,flush:e.flush,lerp:e.lerp,merge:Y,pad:e.pad,peek:e.peek,span:e.span,inrange:e.inrange,truncate:e.truncate,rgb:a.rgb,lab:a.lab,hcl:a.hcl,hsl:a.hsl,luminance:T,contrast:X,sequence:f.range,format:v,utcFormat:x,utcParse:w,utcOffset:l.utcOffset,utcSequence:l.utcSequence,timeFormat:y,timeParse:b,timeOffset:l.timeOffset,timeSequence:l.timeSequence,timeUnitSpecifier:l.timeUnitSpecifier,monthFormat:P,monthAbbrevFormat:N,dayFormat:L,dayAbbrevFormat:A,quarter:e.quarter,utcquarter:e.utcquarter,week:l.week,utcweek:l.utcweek,dayofyear:l.dayofyear,utcdayofyear:l.utcdayofyear,warn:$,info:M,debug:j,extent:e.extent,inScope:V,intersect:function(t,n,r){if(!t)return[];const[a,o]=t,i=(new s.Bounds).set(a[0],a[1],o[0],o[1]),c=r||this.context.dataflow.scenegraph().root;return s.intersect(c,i,function(t){let n=null;if(t){const r=e.array(t.marktype),a=e.array(t.markname);n=t=>(!r.length||r.some(e=>t.marktype===e))&&(!a.length||a.some(e=>t.name===e))}return n}(n))},clampRange:e.clampRange,pinchDistance:J,pinchAngle:K,screen:mt,containerSize:pt,windowSize:gt,bandspace:Q,setdata:g,pathShape:st,panLinear:e.panLinear,panLog:e.panLog,panPow:e.panPow,panSymlog:e.panSymlog,zoomLinear:e.zoomLinear,zoomLog:e.zoomLog,zoomPow:e.zoomPow,zoomSymlog:e.zoomSymlog,encode:p,modify:W},vt=["view","item","group","xy","x","y"],yt={};function xt(t,e,n){return 1===arguments.length?ht[t]:(ht[t]=e,n&&(yt[t]=n),wt&&(wt.functions[t]="this."+t),this)}xt("bandwidth",Z,_),xt("copy",tt,_),xt("domain",et,_),xt("range",rt,_),xt("invert",nt,_),xt("scale",at,_),xt("gradient",ot,_),xt("geoArea",D,_),xt("geoBounds",E,_),xt("geoCentroid",U,_),xt("geoShape",it,_),xt("indata",m,k),xt("data",d,F),xt("treePath",lt,F),xt("treeAncestors",ft,F),xt("vlSelectionTest",c.selectionTest,c.selectionVisitor),xt("vlSelectionResolve",c.selectionResolve,c.selectionVisitor);const bt={blacklist:["_"],whitelist:["datum","event","item"],fieldvar:"datum",globalvar:t=>"_["+e.stringValue("$"+t)+"]",functions:function(t){const r=n.functions(t);vt.forEach(t=>r[t]="event.vega."+t);for(let t in ht)r[t]="this."+t;return e.extend(r,function(t,r,a){r.__bandwidth=t=>t&&t.bandwidth?t.bandwidth():0,a._bandwidth=_,a._range=_,a._scale=_;const o=r=>"_["+(r.type===n.Literal?e.stringValue("%"+r.value):e.stringValue("%")+"+"+t(r))+"]";return{_bandwidth:t=>`this.__bandwidth(${o(t[0])})`,_range:t=>o(t[0])+".range()",_scale:e=>`${o(e[0])}(${t(e[1])})`}}(t,ht,yt)),r},constants:n.constants,visitors:yt};var wt=n.codegen(bt);t.DataPrefix=":",t.IndexPrefix="@",t.ScalePrefix="%",t.SignalPrefix="$",t.bandspace=Q,t.bandwidth=Z,t.codeGenerator=wt,t.codegenParams=bt,t.containerSize=pt,t.contrast=X,t.copy=tt,t.data=d,t.dataVisitor=F,t.dayAbbrevFormat=A,t.dayFormat=L,t.debug=j,t.domain=et,t.encode=p,t.expressionFunction=xt,t.format=v,t.functionContext=ht,t.geoArea=D,t.geoBounds=E,t.geoCentroid=U,t.geoShape=it,t.inScope=V,t.indata=m,t.indataVisitor=k,t.info=M,t.invert=nt,t.luminance=T,t.merge=Y,t.modify=W,t.monthAbbrevFormat=N,t.monthFormat=P,t.parseExpression=function(t,r){var a,o,i={};try{t=e.isString(t)?t:e.stringValue(t)+"",a=n.parse(t)}catch(n){e.error("Expression parse error: "+t)}return a.visit(t=>{if(t.type===n.CallExpression){var e=t.callee.name,a=bt.visitors[e];a&&a(e,t.arguments,r,i)}}),(o=wt(a)).globals.forEach(t=>{var n="$"+t;!e.hasOwnProperty(i,n)&&r.getSignal(t)&&(i[n]=r.signalRef(t))}),{$expr:e.extend({code:o.code},r.options.ast?{ast:a}:null),$fields:o.fields,$params:i}},t.pathShape=st,t.pinchAngle=K,t.pinchDistance=J,t.range=rt,t.scale=at,t.scaleGradient=ot,t.scaleVisitor=_,t.screen=mt,t.setdata=g,t.timeFormat=y,t.timeParse=b,t.treeAncestors=ft,t.treePath=lt,t.utcFormat=x,t.utcParse=w,t.warn=$,t.windowSize=gt,Object.defineProperty(t,"__esModule",{value:!0})})); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("vega-util"),require("vega-expression"),require("d3-geo"),require("d3-color"),require("vega-dataflow"),require("vega-scale"),require("vega-scenegraph"),require("vega-selections"),require("vega-statistics"),require("vega-time"),require("d3-array")):"function"==typeof define&&define.amd?define(["exports","vega-util","vega-expression","d3-geo","d3-color","vega-dataflow","vega-scale","vega-scenegraph","vega-selections","vega-statistics","vega-time","d3-array"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).vega={},t.vega,t.vega,t.d3,t.d3,t.vega,t.vega,t.vega,t.vega,t.vega,t.vega,t.d3)}(this,(function(t,e,n,r,o,a,i,s,c,u,l,f){"use strict";function d(t){const e=this.context.data[t];return e?e.values.value:[]}function m(t,e,n){const r=this.context.data[t]["index:"+e],o=r?r.value.get(n):void 0;return o?o.count:o}function g(t,n){const r=this.context.dataflow,o=this.context.data[t].input;return r.pulse(o,r.changeset().remove(e.truthy).insert(n)),1}function h(t,e,n){if(t){const n=this.context.dataflow,r=t.mark.source;n.pulse(r,n.changeset().encode(t,e))}return void 0!==n?n:t}const p=t=>function(e,n){return this.context.dataflow.locale()[t](n)(e)},v=p("format"),y=p("timeFormat"),b=p("utcFormat"),x=p("timeParse"),w=p("utcParse"),S=new Date(2e3,0,1);function q(t,e,n){return Number.isInteger(t)&&Number.isInteger(e)?(S.setYear(2e3),S.setMonth(t),S.setDate(e),y.call(this,S,n)):""}function P(t){return q.call(this,t,1,"%B")}function N(t){return q.call(this,t,1,"%b")}function L(t){return q.call(this,0,2+t,"%A")}function A(t){return q.call(this,0,2+t,"%a")}function F(t,r,o,a){r[0].type!==n.Literal&&e.error("First argument to data functions must be a string literal.");const i=r[0].value,s=":"+i;if(!e.hasOwnProperty(s,a))try{a[s]=o.getData(i).tuplesRef()}catch(t){}}function k(t,r,o,a){r[0].type!==n.Literal&&e.error("First argument to indata must be a string literal."),r[1].type!==n.Literal&&e.error("Second argument to indata must be a string literal.");const i=r[0].value,s=r[1].value,c="@"+s;e.hasOwnProperty(c,a)||(a[c]=o.getData(i).indataRef(o,s))}function _(t,e,r,o){if(e[0].type===n.Literal)O(r,o,e[0].value);else for(t in r.scales)O(r,o,t)}function O(t,n,r){const o="%"+r;if(!e.hasOwnProperty(n,o))try{n[o]=t.scaleRef(r)}catch(t){}}function R(t,n){let r;return e.isFunction(t)?t:e.isString(t)?(r=n.scales[t])&&r.value:void 0}function z(t,r,o){r.__bandwidth=t=>t&&t.bandwidth?t.bandwidth():0,o._bandwidth=_,o._range=_,o._scale=_;const a=r=>"_["+(r.type===n.Literal?e.stringValue("%"+r.value):e.stringValue("%")+"+"+t(r))+"]";return{_bandwidth:t=>`this.__bandwidth(${a(t[0])})`,_range:t=>a(t[0])+".range()",_scale:e=>`${a(e[0])}(${t(e[1])})`}}function D(t,e){return function(n,r,o){if(n){const e=R(n,(o||this).context);return e&&e.path[t](r)}return e(r)}}const E=D("area",r.geoArea),U=D("bounds",r.geoBounds),V=D("centroid",r.geoCentroid);function $(t){let e=this.context.group,n=!1;if(e)for(;t;){if(t===e){n=!0;break}t=t.mark.group}return n}function B(t,e,n){try{t[e].apply(t,["EXPRESSION"].concat([].slice.call(n)))}catch(e){t.warn(e)}return n[n.length-1]}function M(){return B(this.context.dataflow,"warn",arguments)}function T(){return B(this.context.dataflow,"info",arguments)}function j(){return B(this.context.dataflow,"debug",arguments)}function C(t){const e=t/255;return e<=.03928?e/12.92:Math.pow((e+.055)/1.055,2.4)}function X(t){const e=o.rgb(t);return.2126*C(e.r)+.7152*C(e.g)+.0722*C(e.b)}function Y(t,e){const n=X(t),r=X(e);return(Math.max(n,r)+.05)/(Math.min(n,r)+.05)}function I(){const t=[].slice.call(arguments);return t.unshift({}),e.extend.apply(null,t)}function G(t,n){return t===n||t!=t&&n!=n||(e.isArray(t)?!(!e.isArray(n)||t.length!==n.length)&&function(t,e){for(let n=0,r=t.length;n<r;++n)if(!G(t[n],e[n]))return!1;return!0}(t,n):!(!e.isObject(t)||!e.isObject(n))&&H(t,n))}function H(t,e){for(let n in t)if(!G(t[n],e[n]))return!1;return!0}function W(t){return e=>H(t,e)}function J(t,n,r,o,i,s){let c,u,l=this.context.dataflow,f=this.context.data[t],d=f.input,m=f.changes,g=l.stamp();if(!1===l._trigger||!(d.value.length||n||o))return 0;if((!m||m.stamp<g)&&(f.changes=m=l.changeset(),m.stamp=g,l.runAfter((function(){f.modified=!0,l.pulse(d,m).run()}),!0,1)),r&&(c=!0===r?e.truthy:e.isArray(r)||a.isTuple(r)?r:W(r),m.remove(c)),n&&m.insert(n),o&&(c=W(o),d.value.some(c)?m.remove(c):m.insert(o)),i)for(u in s)m.modify(i,u,s[u]);return 1}function K(t){const e=t.touches,n=e[0].clientX-e[1].clientX,r=e[0].clientY-e[1].clientY;return Math.sqrt(n*n+r*r)}function Q(t){const e=t.touches;return Math.atan2(e[0].clientY-e[1].clientY,e[0].clientX-e[1].clientX)}function Z(t,e,n){return i.bandSpace(t||0,e||0,n||0)}function tt(t,e){const n=R(t,(e||this).context);return n&&n.bandwidth?n.bandwidth():0}function et(t,e){const n=R(t,(e||this).context);return n?n.copy():void 0}function nt(t,e){const n=R(t,(e||this).context);return n?n.domain():[]}function rt(t,n,r){const o=R(t,(r||this).context);return o?e.isArray(n)?(o.invertRange||o.invert)(n):(o.invert||o.invertExtent)(n):void 0}function ot(t,e){const n=R(t,(e||this).context);return n&&n.range?n.range():[]}function at(t,e,n){const r=R(t,(n||this).context);return r?r(e):void 0}function it(t,n,r,o,a){t=R(t,(a||this).context);const c=s.Gradient(n,r);let u=t.domain(),l=u[0],f=e.peek(u),d=e.identity;return f-l?d=i.scaleFraction(t,l,f):t=(t.interpolator?i.scale("sequential")().interpolator(t.interpolator()):i.scale("linear")().interpolate(t.interpolate()).range(t.range())).domain([l=0,f=1]),t.ticks&&(u=t.ticks(+o||15),l!==u[0]&&u.unshift(l),f!==e.peek(u)&&u.push(f)),u.forEach(e=>c.stop(d(e),t(e))),c}function st(t,e,n){const r=R(t,(n||this).context);return function(t){return r?r.path.context(t)(e):""}}function ct(t){let e=null;return function(n){return n?s.pathRender(n,e=e||s.pathParse(t)):t}}const ut=t=>t.data;function lt(t,e){const n=d.call(e,t);return n.root&&n.root.lookup||{}}function ft(t,e,n){const r=lt(t,this),o=r[e],a=r[n];return o&&a?o.path(a).map(ut):void 0}function dt(t,e){const n=lt(t,this)[e];return n?n.ancestors().map(ut):void 0}const mt=()=>"undefined"!=typeof window&&window||null;function gt(){const t=mt();return t?t.screen:{}}function ht(){const t=mt();return t?[t.innerWidth,t.innerHeight]:[void 0,void 0]}function pt(){const t=this.context.dataflow,e=t.container&&t.container();return e?[e.clientWidth,e.clientHeight]:[void 0,void 0]}const vt={random:()=>u.random(),cumulativeNormal:u.cumulativeNormal,cumulativeLogNormal:u.cumulativeLogNormal,cumulativeUniform:u.cumulativeUniform,densityNormal:u.densityNormal,densityLogNormal:u.densityLogNormal,densityUniform:u.densityUniform,quantileNormal:u.quantileNormal,quantileLogNormal:u.quantileLogNormal,quantileUniform:u.quantileUniform,sampleNormal:u.sampleNormal,sampleLogNormal:u.sampleLogNormal,sampleUniform:u.sampleUniform,isArray:e.isArray,isBoolean:e.isBoolean,isDate:e.isDate,isDefined:t=>void 0!==t,isNumber:e.isNumber,isObject:e.isObject,isRegExp:e.isRegExp,isString:e.isString,isTuple:a.isTuple,isValid:t=>null!=t&&t==t,toBoolean:e.toBoolean,toDate:e.toDate,toNumber:e.toNumber,toString:e.toString,flush:e.flush,lerp:e.lerp,merge:I,pad:e.pad,peek:e.peek,span:e.span,inrange:e.inrange,truncate:e.truncate,rgb:o.rgb,lab:o.lab,hcl:o.hcl,hsl:o.hsl,luminance:X,contrast:Y,sequence:f.range,format:v,utcFormat:b,utcParse:w,utcOffset:l.utcOffset,utcSequence:l.utcSequence,timeFormat:y,timeParse:x,timeOffset:l.timeOffset,timeSequence:l.timeSequence,timeUnitSpecifier:l.timeUnitSpecifier,monthFormat:P,monthAbbrevFormat:N,dayFormat:L,dayAbbrevFormat:A,quarter:e.quarter,utcquarter:e.utcquarter,week:l.week,utcweek:l.utcweek,dayofyear:l.dayofyear,utcdayofyear:l.utcdayofyear,warn:M,info:T,debug:j,extent:e.extent,inScope:$,intersect:function(t,n,r){if(!t)return[];const[o,a]=t,i=(new s.Bounds).set(o[0],o[1],a[0],a[1]),c=r||this.context.dataflow.scenegraph().root;return s.intersect(c,i,function(t){let n=null;if(t){const r=e.array(t.marktype),o=e.array(t.markname);n=t=>(!r.length||r.some(e=>t.marktype===e))&&(!o.length||o.some(e=>t.name===e))}return n}(n))},clampRange:e.clampRange,pinchDistance:K,pinchAngle:Q,screen:gt,containerSize:pt,windowSize:ht,bandspace:Z,setdata:g,pathShape:ct,panLinear:e.panLinear,panLog:e.panLog,panPow:e.panPow,panSymlog:e.panSymlog,zoomLinear:e.zoomLinear,zoomLog:e.zoomLog,zoomPow:e.zoomPow,zoomSymlog:e.zoomSymlog,encode:h,modify:J},yt=["view","item","group","xy","x","y"],bt={},xt={blacklist:["_"],whitelist:["datum","event","item"],fieldvar:"datum",globalvar:t=>`_[${e.stringValue("$"+t)}]`,functions:function(t){const r=n.functions(t);yt.forEach(t=>r[t]="event.vega."+t);for(let t in vt)r[t]="this."+t;return e.extend(r,z(t,vt,bt)),r},constants:n.constants,visitors:bt},wt=n.codegen(xt);function St(t,e,n){return 1===arguments.length?vt[t]:(vt[t]=e,n&&(bt[t]=n),wt&&(wt.functions[t]="this."+t),this)}St("bandwidth",tt,_),St("copy",et,_),St("domain",nt,_),St("range",ot,_),St("invert",rt,_),St("scale",at,_),St("gradient",it,_),St("geoArea",E,_),St("geoBounds",U,_),St("geoCentroid",V,_),St("geoShape",st,_),St("indata",m,k),St("data",d,F),St("treePath",ft,F),St("treeAncestors",dt,F),St("vlSelectionTest",c.selectionTest,c.selectionVisitor),St("vlSelectionResolve",c.selectionResolve,c.selectionVisitor),t.DataPrefix=":",t.IndexPrefix="@",t.ScalePrefix="%",t.SignalPrefix="$",t.bandspace=Z,t.bandwidth=tt,t.codeGenerator=wt,t.codegenParams=xt,t.containerSize=pt,t.contrast=Y,t.copy=et,t.data=d,t.dataVisitor=F,t.dayAbbrevFormat=A,t.dayFormat=L,t.debug=j,t.domain=nt,t.encode=h,t.expressionFunction=St,t.format=v,t.functionContext=vt,t.geoArea=E,t.geoBounds=U,t.geoCentroid=V,t.geoShape=st,t.inScope=$,t.indata=m,t.indataVisitor=k,t.info=T,t.invert=rt,t.luminance=X,t.merge=I,t.modify=J,t.monthAbbrevFormat=N,t.monthFormat=P,t.parseExpression=function(t,r){let o,a,i={};try{t=e.isString(t)?t:e.stringValue(t)+"",o=n.parse(t)}catch(n){e.error("Expression parse error: "+t)}return o.visit(t=>{if(t.type!==n.CallExpression)return;const e=t.callee.name,o=xt.visitors[e];o&&o(e,t.arguments,r,i)}),a=wt(o),a.globals.forEach(t=>{const n="$"+t;!e.hasOwnProperty(i,n)&&r.getSignal(t)&&(i[n]=r.signalRef(t))}),{$expr:e.extend({code:a.code},r.options.ast?{ast:o}:null),$fields:a.fields,$params:i}},t.pathShape=ct,t.pinchAngle=Q,t.pinchDistance=K,t.range=ot,t.scale=at,t.scaleGradient=it,t.scaleVisitor=_,t.screen=gt,t.setdata=g,t.timeFormat=y,t.timeParse=x,t.treeAncestors=dt,t.treePath=ft,t.utcFormat=b,t.utcParse=w,t.warn=M,t.windowSize=ht,Object.defineProperty(t,"__esModule",{value:!0})})); |
{ | ||
"name": "vega-functions", | ||
"version": "5.7.1", | ||
"version": "5.7.2", | ||
"description": "Custom functions for the Vega expression language.", | ||
@@ -26,18 +26,18 @@ "keywords": [ | ||
"dependencies": { | ||
"d3-array": "^2.4.0", | ||
"d3-array": "^2.5.1", | ||
"d3-color": "^1.4.1", | ||
"d3-geo": "^1.12.1", | ||
"vega-dataflow": "^5.7.0", | ||
"vega-expression": "^2.6.5", | ||
"vega-scale": "^7.0.0", | ||
"vega-scenegraph": "^4.8.0", | ||
"vega-selections": "^5.1.1", | ||
"vega-statistics": "^1.7.5", | ||
"vega-time": "^2.0.1", | ||
"vega-util": "^1.14.0" | ||
"vega-dataflow": "^5.7.1", | ||
"vega-expression": "^2.6.6", | ||
"vega-scale": "^7.0.1", | ||
"vega-scenegraph": "^4.9.0", | ||
"vega-selections": "^5.1.2", | ||
"vega-statistics": "^1.7.7", | ||
"vega-time": "^2.0.2", | ||
"vega-util": "^1.15.0" | ||
}, | ||
"devDependencies": { | ||
"vega-format": "^1.0.0" | ||
"vega-format": "^1.0.2" | ||
}, | ||
"gitHead": "62565bbe084a422c4a0cbc6e19c6f7c45a3e5137" | ||
"gitHead": "28db83352e43e321dfe55fc5cb6489b211e45662" | ||
} |
@@ -185,3 +185,3 @@ import { | ||
export const functionContext = { | ||
random: function() { return random(); }, // override default | ||
random() { return random(); }, // override default | ||
cumulativeNormal, | ||
@@ -202,3 +202,3 @@ cumulativeLogNormal, | ||
isDate, | ||
isDefined: function(_) { return _ !== undefined; }, | ||
isDefined(_) { return _ !== undefined; }, | ||
isNumber, | ||
@@ -209,3 +209,3 @@ isObject, | ||
isTuple, | ||
isValid: function(_) { return _ != null && _ === _; }, | ||
isValid(_) { return _ != null && _ === _; }, | ||
toBoolean, | ||
@@ -282,2 +282,16 @@ toDate, | ||
// export code generator parameters | ||
export const codegenParams = { | ||
blacklist: ['_'], | ||
whitelist: ['datum', 'event', 'item'], | ||
fieldvar: 'datum', | ||
globalvar: id => `_[${stringValue(SignalPrefix + id)}]`, | ||
functions: buildFunctions, | ||
constants: constants, | ||
visitors: astVisitors | ||
}; | ||
// export code generator | ||
export const codeGenerator = codegen(codegenParams); | ||
// Build expression function registry | ||
@@ -330,14 +344,1 @@ function buildFunctions(codegen) { | ||
expressionFunction('vlSelectionResolve', selectionResolve, selectionVisitor); | ||
// Export code generator and parameters | ||
export const codegenParams = { | ||
blacklist: ['_'], | ||
whitelist: ['datum', 'event', 'item'], | ||
fieldvar: 'datum', | ||
globalvar: id => '_[' + stringValue(SignalPrefix + id) + ']', | ||
functions: buildFunctions, | ||
constants: constants, | ||
visitors: astVisitors | ||
}; | ||
export var codeGenerator = codegen(codegenParams); |
@@ -12,3 +12,3 @@ const wrap = method => function(value, spec) { | ||
var dateObj = new Date(2000, 0, 1); | ||
const dateObj = new Date(2000, 0, 1); | ||
@@ -15,0 +15,0 @@ function time(month, day, specifier) { |
import {extend} from 'vega-util'; | ||
export default function() { | ||
var args = [].slice.call(arguments); | ||
const args = [].slice.call(arguments); | ||
args.unshift({}); | ||
return extend.apply(null, args); | ||
} |
@@ -7,3 +7,3 @@ import {codeGenerator, codegenParams} from './codegen'; | ||
export default function(expr, scope) { | ||
var params = {}, ast, gen; | ||
let params = {}, ast, gen; | ||
@@ -21,4 +21,4 @@ // parse the expression to an abstract syntax tree (ast) | ||
if (node.type !== CallExpression) return; | ||
var name = node.callee.name, | ||
visit = codegenParams.visitors[name]; | ||
const name = node.callee.name, | ||
visit = codegenParams.visitors[name]; | ||
if (visit) visit(name, node.arguments, scope, params); | ||
@@ -32,3 +32,3 @@ }); | ||
gen.globals.forEach(name => { | ||
var signalName = SignalPrefix + name; | ||
const signalName = SignalPrefix + name; | ||
if (!hasOwnProperty(params, signalName) && scope.getSignal(name)) { | ||
@@ -35,0 +35,0 @@ params[signalName] = scope.signalRef(name); |
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
65122
1486
Updatedd3-array@^2.5.1
Updatedvega-dataflow@^5.7.1
Updatedvega-expression@^2.6.6
Updatedvega-scale@^7.0.1
Updatedvega-scenegraph@^4.9.0
Updatedvega-selections@^5.1.2
Updatedvega-statistics@^1.7.7
Updatedvega-time@^2.0.2
Updatedvega-util@^1.15.0