New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

vega-voronoi

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vega-voronoi - npm Package Compare versions

Comparing version 4.1.4 to 4.1.5

build/vega-voronoi.min.js.map

67

build/vega-voronoi.js

@@ -10,37 +10,50 @@ (function (global, factory) {

}
Voronoi.Definition = {
'type': 'Voronoi',
'metadata': {'modifies': true},
'params': [
{ 'name': 'x', 'type': 'field', 'required': true },
{ 'name': 'y', 'type': 'field', 'required': true },
{ 'name': 'size', 'type': 'number', 'array': true, 'length': 2 },
{ 'name': 'extent', 'type': 'array', 'array': true, 'length': 2,
'default': [[-1e5, -1e5], [1e5, 1e5]],
'content': {'type': 'number', 'array': true, 'length': 2} },
{ 'name': 'as', 'type': 'string', 'default': 'path' }
]
'metadata': {
'modifies': true
},
'params': [{
'name': 'x',
'type': 'field',
'required': true
}, {
'name': 'y',
'type': 'field',
'required': true
}, {
'name': 'size',
'type': 'number',
'array': true,
'length': 2
}, {
'name': 'extent',
'type': 'array',
'array': true,
'length': 2,
'default': [[-1e5, -1e5], [1e5, 1e5]],
'content': {
'type': 'number',
'array': true,
'length': 2
}
}, {
'name': 'as',
'type': 'string',
'default': 'path'
}]
};
const defaultExtent = [-1e5, -1e5, 1e5, 1e5];
vegaUtil.inherits(Voronoi, vegaDataflow.Transform, {
transform(_, pulse) {
const as = _.as || 'path',
data = pulse.source;
data = pulse.source; // nothing to do if no data
// nothing to do if no data
if (!data || !data.length) return pulse;
if (!data || !data.length) return pulse; // configure and construct voronoi diagram
// configure and construct voronoi diagram
let s = _.size;
s = s ? [0, 0, s[0], s[1]]
: (s = _.extent) ? [s[0][0], s[0][1], s[1][0], s[1][1]]
: defaultExtent;
s = s ? [0, 0, s[0], s[1]] : (s = _.extent) ? [s[0][0], s[0][1], s[1][0], s[1][1]] : defaultExtent;
const voronoi = this.value = d3Delaunay.Delaunay.from(data, _.x, _.y).voronoi(s); // map polygons to paths
const voronoi = this.value = d3Delaunay.Delaunay.from(data, _.x, _.y).voronoi(s);
// map polygons to paths
for (let i=0, n=data.length; i<n; ++i) {
for (let i = 0, n = data.length; i < n; ++i) {
const polygon = voronoi.cellPolygon(i);

@@ -52,10 +65,10 @@ data[i][as] = polygon ? toPathString(polygon) : null;

}
});
// suppress duplicated end point vertices
}); // suppress duplicated end point vertices
function toPathString(p) {
const x = p[0][0],
y = p[0][1];
let n = p.length - 1;
let n = p.length - 1;
for (; p[n][0] === x && p[n][1] === y; --n);

@@ -62,0 +75,0 @@

@@ -1,1 +0,2 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vega-dataflow"),require("vega-util"),require("d3-delaunay")):"function"==typeof define&&define.amd?define(["exports","vega-dataflow","vega-util","d3-delaunay"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).vega=e.vega||{},e.vega.transforms={}),e.vega,e.vega,e.d3)}(this,(function(e,t,n,a){"use strict";function o(e){t.Transform.call(this,null,e)}o.Definition={type:"Voronoi",metadata:{modifies:!0},params:[{name:"x",type:"field",required:!0},{name:"y",type:"field",required:!0},{name:"size",type:"number",array:!0,length:2},{name:"extent",type:"array",array:!0,length:2,default:[[-1e5,-1e5],[1e5,1e5]],content:{type:"number",array:!0,length:2}},{name:"as",type:"string",default:"path"}]};const r=[-1e5,-1e5,1e5,1e5];function i(e){const t=e[0][0],n=e[0][1];let a=e.length-1;for(;e[a][0]===t&&e[a][1]===n;--a);return"M"+e.slice(0,a+1).join("L")+"Z"}n.inherits(o,t.Transform,{transform(e,t){const n=e.as||"path",o=t.source;if(!o||!o.length)return t;let l=e.size;l=l?[0,0,l[0],l[1]]:(l=e.extent)?[l[0][0],l[0][1],l[1][0],l[1][1]]:r;const f=this.value=a.Delaunay.from(o,e.x,e.y).voronoi(l);for(let e=0,t=o.length;e<t;++e){const t=f.cellPolygon(e);o[e][n]=t?i(t):null}return t.reflow(e.modified()).modifies(n)}}),e.voronoi=o,Object.defineProperty(e,"__esModule",{value:!0})}));
this.vega=this.vega||{},this.vega.transforms=function(t,e,i){"use strict";const n=Math.pow(2,-52),s=new Uint32Array(512);class l{static from(t,e=_,i=g){const n=t.length,s=new Float64Array(2*n);for(let l=0;l<n;l++){const n=t[l];s[2*l]=e(n),s[2*l+1]=i(n)}return new l(s)}constructor(t){const e=t.length>>1;if(e>0&&"number"!=typeof t[0])throw new Error("Expected coords to contain numbers.");this.coords=t;const i=Math.max(2*e-5,0);this._triangles=new Uint32Array(3*i),this._halfedges=new Int32Array(3*i),this._hashSize=Math.ceil(Math.sqrt(e)),this._hullPrev=new Uint32Array(e),this._hullNext=new Uint32Array(e),this._hullTri=new Uint32Array(e),this._hullHash=new Int32Array(this._hashSize).fill(-1),this._ids=new Uint32Array(e),this._dists=new Float64Array(e),this.update()}update(){const{coords:t,_hullPrev:e,_hullNext:i,_hullTri:s,_hullHash:l}=this,r=t.length>>1;let a=1/0,f=1/0,_=-1/0,g=-1/0;for(let e=0;e<r;e++){const i=t[2*e],n=t[2*e+1];i<a&&(a=i),n<f&&(f=n),i>_&&(_=i),n>g&&(g=n),this._ids[e]=e}const d=(a+_)/2,y=(f+g)/2;let m,x,p,w=1/0;for(let e=0;e<r;e++){const i=h(d,y,t[2*e],t[2*e+1]);i<w&&(m=e,w=i)}const v=t[2*m],b=t[2*m+1];w=1/0;for(let e=0;e<r;e++){if(e===m)continue;const i=h(v,b,t[2*e],t[2*e+1]);i<w&&i>0&&(x=e,w=i)}let T=t[2*x],M=t[2*x+1],A=1/0;for(let e=0;e<r;e++){if(e===m||e===x)continue;const i=c(v,b,T,M,t[2*e],t[2*e+1]);i<A&&(p=e,A=i)}let k=t[2*p],P=t[2*p+1];if(A===1/0){for(let e=0;e<r;e++)this._dists[e]=t[2*e]-t[0]||t[2*e+1]-t[1];u(this._ids,this._dists,0,r-1);const e=new Uint32Array(r);let i=0;for(let t=0,n=-1/0;t<r;t++){const s=this._ids[t];this._dists[s]>n&&(e[i++]=s,n=this._dists[s])}return this.hull=e.subarray(0,i),this.triangles=new Uint32Array(0),void(this.halfedges=new Uint32Array(0))}if(o(v,b,T,M,k,P)){const t=x,e=T,i=M;x=p,T=k,M=P,p=t,k=e,P=i}const S=function(t,e,i,n,s,l){const h=i-t,r=n-e,o=s-t,a=l-e,c=h*h+r*r,u=o*o+a*a,f=.5/(h*a-r*o);return{x:t+(a*c-r*u)*f,y:e+(h*u-o*c)*f}}(v,b,T,M,k,P);this._cx=S.x,this._cy=S.y;for(let e=0;e<r;e++)this._dists[e]=h(t[2*e],t[2*e+1],S.x,S.y);u(this._ids,this._dists,0,r-1),this._hullStart=m;let I=3;i[m]=e[p]=x,i[x]=e[m]=p,i[p]=e[x]=m,s[m]=0,s[x]=1,s[p]=2,l.fill(-1),l[this._hashKey(v,b)]=m,l[this._hashKey(T,M)]=x,l[this._hashKey(k,P)]=p,this.trianglesLen=0,this._addTriangle(m,x,p,-1,-1,-1);for(let h,r,a=0;a<this._ids.length;a++){const c=this._ids[a],u=t[2*c],f=t[2*c+1];if(a>0&&Math.abs(u-h)<=n&&Math.abs(f-r)<=n)continue;if(h=u,r=f,c===m||c===x||c===p)continue;let _=0;for(let t=0,e=this._hashKey(u,f);t<this._hashSize&&(_=l[(e+t)%this._hashSize],-1===_||_===i[_]);t++);_=e[_];let g,d=_;for(;g=i[d],!o(u,f,t[2*d],t[2*d+1],t[2*g],t[2*g+1]);)if(d=g,d===_){d=-1;break}if(-1===d)continue;let y=this._addTriangle(d,c,i[d],-1,-1,s[d]);s[c]=this._legalize(y+2),s[d]=y,I++;let w=i[d];for(;g=i[w],o(u,f,t[2*w],t[2*w+1],t[2*g],t[2*g+1]);)y=this._addTriangle(w,c,g,s[c],-1,s[w]),s[c]=this._legalize(y+2),i[w]=w,I--,w=g;if(d===_)for(;g=e[d],o(u,f,t[2*g],t[2*g+1],t[2*d],t[2*d+1]);)y=this._addTriangle(g,c,d,-1,s[d],s[g]),this._legalize(y+2),s[g]=y,i[d]=d,I--,d=g;this._hullStart=e[c]=d,i[d]=e[w]=c,i[c]=w,l[this._hashKey(u,f)]=c,l[this._hashKey(t[2*d],t[2*d+1])]=d}this.hull=new Uint32Array(I);for(let t=0,e=this._hullStart;t<I;t++)this.hull[t]=e,e=i[e];this.triangles=this._triangles.subarray(0,this.trianglesLen),this.halfedges=this._halfedges.subarray(0,this.trianglesLen)}_hashKey(t,e){return Math.floor(function(t,e){const i=t/(Math.abs(t)+Math.abs(e));return(e>0?3-i:1+i)/4}(t-this._cx,e-this._cy)*this._hashSize)%this._hashSize}_legalize(t){const{_triangles:e,_halfedges:i,coords:n}=this;let l=0,h=0;for(;;){const r=i[t],o=t-t%3;if(h=o+(t+2)%3,-1===r){if(0===l)break;t=s[--l];continue}const c=r-r%3,u=o+(t+1)%3,f=c+(r+2)%3,_=e[h],g=e[t],d=e[u],y=e[f];if(a(n[2*_],n[2*_+1],n[2*g],n[2*g+1],n[2*d],n[2*d+1],n[2*y],n[2*y+1])){e[t]=y,e[r]=_;const n=i[f];if(-1===n){let e=this._hullStart;do{if(this._hullTri[e]===f){this._hullTri[e]=t;break}e=this._hullPrev[e]}while(e!==this._hullStart)}this._link(t,n),this._link(r,i[h]),this._link(h,f);const o=c+(r+1)%3;l<s.length&&(s[l++]=o)}else{if(0===l)break;t=s[--l]}}return h}_link(t,e){this._halfedges[t]=e,-1!==e&&(this._halfedges[e]=t)}_addTriangle(t,e,i,n,s,l){const h=this.trianglesLen;return this._triangles[h]=t,this._triangles[h+1]=e,this._triangles[h+2]=i,this._link(h,n),this._link(h+1,s),this._link(h+2,l),this.trianglesLen+=3,h}}function h(t,e,i,n){const s=t-i,l=e-n;return s*s+l*l}function r(t,e,i,n,s,l){const h=(n-e)*(s-t),r=(i-t)*(l-e);return Math.abs(h-r)>=33306690738754716e-32*Math.abs(h+r)?h-r:0}function o(t,e,i,n,s,l){return(r(s,l,t,e,i,n)||r(t,e,i,n,s,l)||r(i,n,s,l,t,e))<0}function a(t,e,i,n,s,l,h,r){const o=t-h,a=e-r,c=i-h,u=n-r,f=s-h,_=l-r,g=c*c+u*u,d=f*f+_*_;return o*(u*d-g*_)-a*(c*d-g*f)+(o*o+a*a)*(c*_-u*f)<0}function c(t,e,i,n,s,l){const h=i-t,r=n-e,o=s-t,a=l-e,c=h*h+r*r,u=o*o+a*a,f=.5/(h*a-r*o),_=(a*c-r*u)*f,g=(h*u-o*c)*f;return _*_+g*g}function u(t,e,i,n){if(n-i<=20)for(let s=i+1;s<=n;s++){const n=t[s],l=e[n];let h=s-1;for(;h>=i&&e[t[h]]>l;)t[h+1]=t[h--];t[h+1]=n}else{let s=i+1,l=n;f(t,i+n>>1,s),e[t[i]]>e[t[n]]&&f(t,i,n),e[t[s]]>e[t[n]]&&f(t,s,n),e[t[i]]>e[t[s]]&&f(t,i,s);const h=t[s],r=e[h];for(;;){do{s++}while(e[t[s]]<r);do{l--}while(e[t[l]]>r);if(l<s)break;f(t,s,l)}t[i+1]=t[l],t[l]=h,n-s+1>=l-i?(u(t,e,s,n),u(t,e,i,l-1)):(u(t,e,i,l-1),u(t,e,s,n))}}function f(t,e,i){const n=t[e];t[e]=t[i],t[i]=n}function _(t){return t[0]}function g(t){return t[1]}const d=1e-6;class y{constructor(){this._x0=this._y0=this._x1=this._y1=null,this._=""}moveTo(t,e){this._+="M".concat(this._x0=this._x1=+t,",").concat(this._y0=this._y1=+e)}closePath(){null!==this._x1&&(this._x1=this._x0,this._y1=this._y0,this._+="Z")}lineTo(t,e){this._+="L".concat(this._x1=+t,",").concat(this._y1=+e)}arc(t,e,i){const n=(t=+t)+(i=+i),s=e=+e;if(i<0)throw new Error("negative radius");null===this._x1?this._+="M".concat(n,",").concat(s):(Math.abs(this._x1-n)>d||Math.abs(this._y1-s)>d)&&(this._+="L"+n+","+s),i&&(this._+="A".concat(i,",").concat(i,",0,1,1,").concat(t-i,",").concat(e,"A").concat(i,",").concat(i,",0,1,1,").concat(this._x1=n,",").concat(this._y1=s))}rect(t,e,i,n){this._+="M".concat(this._x0=this._x1=+t,",").concat(this._y0=this._y1=+e,"h").concat(+i,"v").concat(+n,"h").concat(-i,"Z")}value(){return this._||null}}class m{constructor(){this._=[]}moveTo(t,e){this._.push([t,e])}closePath(){this._.push(this._[0].slice())}lineTo(t,e){this._.push([t,e])}value(){return this._.length?this._:null}}class x{constructor(t,[e,i,n,s]=[0,0,960,500]){if(!((n=+n)>=(e=+e)&&(s=+s)>=(i=+i)))throw new Error("invalid bounds");this.delaunay=t,this._circumcenters=new Float64Array(2*t.points.length),this.vectors=new Float64Array(2*t.points.length),this.xmax=n,this.xmin=e,this.ymax=s,this.ymin=i,this._init()}update(){return this.delaunay.update(),this._init(),this}_init(){const{delaunay:{points:t,hull:e,triangles:i},vectors:n}=this,s=this.circumcenters=this._circumcenters.subarray(0,i.length/3*2);for(let e,n,l=0,h=0,r=i.length;l<r;l+=3,h+=2){const r=2*i[l],o=2*i[l+1],a=2*i[l+2],c=t[r],u=t[r+1],f=t[o],_=t[o+1],g=t[a],d=t[a+1],y=f-c,m=_-u,x=g-c,p=d-u,w=y*y+m*m,v=x*x+p*p,b=2*(y*p-m*x);if(b)if(Math.abs(b)<1e-8)e=(c+g)/2,n=(u+d)/2;else{const t=1/b;e=c+(p*w-m*v)*t,n=u+(y*v-x*w)*t}else e=(c+g)/2-1e8*p,n=(u+d)/2+1e8*x;s[h]=e,s[h+1]=n}let l,h,r,o=e[e.length-1],a=4*o,c=t[2*o],u=t[2*o+1];n.fill(0);for(let i=0;i<e.length;++i)o=e[i],l=a,h=c,r=u,a=4*o,c=t[2*o],u=t[2*o+1],n[l+2]=n[a]=r-u,n[l+3]=n[a+1]=c-h}render(t){const e=null==t?t=new y:void 0,{delaunay:{halfedges:i,inedges:n,hull:s},circumcenters:l,vectors:h}=this;if(s.length<=1)return null;for(let e=0,n=i.length;e<n;++e){const n=i[e];if(n<e)continue;const s=2*Math.floor(e/3),h=2*Math.floor(n/3),r=l[s],o=l[s+1],a=l[h],c=l[h+1];this._renderSegment(r,o,a,c,t)}let r,o=s[s.length-1];for(let e=0;e<s.length;++e){r=o,o=s[e];const i=2*Math.floor(n[o]/3),a=l[i],c=l[i+1],u=4*r,f=this._project(a,c,h[u+2],h[u+3]);f&&this._renderSegment(a,c,f[0],f[1],t)}return e&&e.value()}renderBounds(t){const e=null==t?t=new y:void 0;return t.rect(this.xmin,this.ymin,this.xmax-this.xmin,this.ymax-this.ymin),e&&e.value()}renderCell(t,e){const i=null==e?e=new y:void 0,n=this._clip(t);if(null===n||!n.length)return;e.moveTo(n[0],n[1]);let s=n.length;for(;n[0]===n[s-2]&&n[1]===n[s-1]&&s>1;)s-=2;for(let t=2;t<s;t+=2)n[t]===n[t-2]&&n[t+1]===n[t-1]||e.lineTo(n[t],n[t+1]);return e.closePath(),i&&i.value()}*cellPolygons(){const{delaunay:{points:t}}=this;for(let e=0,i=t.length/2;e<i;++e){const t=this.cellPolygon(e);t&&(t.index=e,yield t)}}cellPolygon(t){const e=new m;return this.renderCell(t,e),e.value()}_renderSegment(t,e,i,n,s){let l;const h=this._regioncode(t,e),r=this._regioncode(i,n);0===h&&0===r?(s.moveTo(t,e),s.lineTo(i,n)):(l=this._clipSegment(t,e,i,n,h,r))&&(s.moveTo(l[0],l[1]),s.lineTo(l[2],l[3]))}contains(t,e,i){return(e=+e)==e&&(i=+i)==i&&this.delaunay._step(t,e,i)===t}*neighbors(t){const e=this._clip(t);if(e)for(const i of this.delaunay.neighbors(t)){const t=this._clip(i);if(t)t:for(let n=0,s=e.length;n<s;n+=2)for(let l=0,h=t.length;l<h;l+=2)if(e[n]==t[l]&&e[n+1]==t[l+1]&&e[(n+2)%s]==t[(l+h-2)%h]&&e[(n+3)%s]==t[(l+h-1)%h]){yield i;break t}}}_cell(t){const{circumcenters:e,delaunay:{inedges:i,halfedges:n,triangles:s}}=this,l=i[t];if(-1===l)return null;const h=[];let r=l;do{const i=Math.floor(r/3);if(h.push(e[2*i],e[2*i+1]),r=r%3==2?r-2:r+1,s[r]!==t)break;r=n[r]}while(r!==l&&-1!==r);return h}_clip(t){if(0===t&&1===this.delaunay.hull.length)return[this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax,this.xmin,this.ymin];const e=this._cell(t);if(null===e)return null;const{vectors:i}=this,n=4*t;return i[n]||i[n+1]?this._clipInfinite(t,e,i[n],i[n+1],i[n+2],i[n+3]):this._clipFinite(t,e)}_clipFinite(t,e){const i=e.length;let n,s,l,h,r,o=null,a=e[i-2],c=e[i-1],u=this._regioncode(a,c);for(let f=0;f<i;f+=2)if(n=a,s=c,a=e[f],c=e[f+1],l=u,u=this._regioncode(a,c),0===l&&0===u)h=r,r=0,o?o.push(a,c):o=[a,c];else{let e,i,f,_,g;if(0===l){if(null===(e=this._clipSegment(n,s,a,c,l,u)))continue;[i,f,_,g]=e}else{if(null===(e=this._clipSegment(a,c,n,s,u,l)))continue;[_,g,i,f]=e,h=r,r=this._edgecode(i,f),h&&r&&this._edge(t,h,r,o,o.length),o?o.push(i,f):o=[i,f]}h=r,r=this._edgecode(_,g),h&&r&&this._edge(t,h,r,o,o.length),o?o.push(_,g):o=[_,g]}if(o)h=r,r=this._edgecode(o[0],o[1]),h&&r&&this._edge(t,h,r,o,o.length);else if(this.contains(t,(this.xmin+this.xmax)/2,(this.ymin+this.ymax)/2))return[this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax,this.xmin,this.ymin];return o}_clipSegment(t,e,i,n,s,l){for(;;){if(0===s&&0===l)return[t,e,i,n];if(s&l)return null;let h,r,o=s||l;8&o?(h=t+(i-t)*(this.ymax-e)/(n-e),r=this.ymax):4&o?(h=t+(i-t)*(this.ymin-e)/(n-e),r=this.ymin):2&o?(r=e+(n-e)*(this.xmax-t)/(i-t),h=this.xmax):(r=e+(n-e)*(this.xmin-t)/(i-t),h=this.xmin),s?(t=h,e=r,s=this._regioncode(t,e)):(i=h,n=r,l=this._regioncode(i,n))}}_clipInfinite(t,e,i,n,s,l){let h,r=Array.from(e);if((h=this._project(r[0],r[1],i,n))&&r.unshift(h[0],h[1]),(h=this._project(r[r.length-2],r[r.length-1],s,l))&&r.push(h[0],h[1]),r=this._clipFinite(t,r))for(let e,i=0,n=r.length,s=this._edgecode(r[n-2],r[n-1]);i<n;i+=2)e=s,s=this._edgecode(r[i],r[i+1]),e&&s&&(i=this._edge(t,e,s,r,i),n=r.length);else this.contains(t,(this.xmin+this.xmax)/2,(this.ymin+this.ymax)/2)&&(r=[this.xmin,this.ymin,this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax]);return r}_edge(t,e,i,n,s){for(;e!==i;){let i,l;switch(e){case 5:e=4;continue;case 4:e=6,i=this.xmax,l=this.ymin;break;case 6:e=2;continue;case 2:e=10,i=this.xmax,l=this.ymax;break;case 10:e=8;continue;case 8:e=9,i=this.xmin,l=this.ymax;break;case 9:e=1;continue;case 1:e=5,i=this.xmin,l=this.ymin}n[s]===i&&n[s+1]===l||!this.contains(t,i,l)||(n.splice(s,0,i,l),s+=2)}if(n.length>4)for(let t=0;t<n.length;t+=2){const e=(t+2)%n.length,i=(t+4)%n.length;(n[t]===n[e]&&n[e]===n[i]||n[t+1]===n[e+1]&&n[e+1]===n[i+1])&&(n.splice(e,2),t-=2)}return s}_project(t,e,i,n){let s,l,h,r=1/0;if(n<0){if(e<=this.ymin)return null;(s=(this.ymin-e)/n)<r&&(h=this.ymin,l=t+(r=s)*i)}else if(n>0){if(e>=this.ymax)return null;(s=(this.ymax-e)/n)<r&&(h=this.ymax,l=t+(r=s)*i)}if(i>0){if(t>=this.xmax)return null;(s=(this.xmax-t)/i)<r&&(l=this.xmax,h=e+(r=s)*n)}else if(i<0){if(t<=this.xmin)return null;(s=(this.xmin-t)/i)<r&&(l=this.xmin,h=e+(r=s)*n)}return[l,h]}_edgecode(t,e){return(t===this.xmin?1:t===this.xmax?2:0)|(e===this.ymin?4:e===this.ymax?8:0)}_regioncode(t,e){return(t<this.xmin?1:t>this.xmax?2:0)|(e<this.ymin?4:e>this.ymax?8:0)}}const p=2*Math.PI,w=Math.pow;function v(t){return t[0]}function b(t){return t[1]}function T(t,e,i){return[t+Math.sin(t+e)*i,e+Math.cos(t-e)*i]}class M{static from(t,e=v,i=b,n){return new M("length"in t?function(t,e,i,n){const s=t.length,l=new Float64Array(2*s);for(let h=0;h<s;++h){const s=t[h];l[2*h]=e.call(n,s,h,t),l[2*h+1]=i.call(n,s,h,t)}return l}(t,e,i,n):Float64Array.from(function*(t,e,i,n){let s=0;for(const l of t)yield e.call(n,l,s,t),yield i.call(n,l,s,t),++s}(t,e,i,n)))}constructor(t){this._delaunator=new l(t),this.inedges=new Int32Array(t.length/2),this._hullIndex=new Int32Array(t.length/2),this.points=this._delaunator.coords,this._init()}update(){return this._delaunator.update(),this._init(),this}_init(){const t=this._delaunator,e=this.points;if(t.hull&&t.hull.length>2&&function(t){const{triangles:e,coords:i}=t;for(let t=0;t<e.length;t+=3){const n=2*e[t],s=2*e[t+1],l=2*e[t+2];if((i[l]-i[n])*(i[s+1]-i[n+1])-(i[s]-i[n])*(i[l+1]-i[n+1])>1e-10)return!1}return!0}(t)){this.collinear=Int32Array.from({length:e.length/2},(t,e)=>e).sort((t,i)=>e[2*t]-e[2*i]||e[2*t+1]-e[2*i+1]);const t=this.collinear[0],i=this.collinear[this.collinear.length-1],n=[e[2*t],e[2*t+1],e[2*i],e[2*i+1]],s=1e-8*Math.hypot(n[3]-n[1],n[2]-n[0]);for(let t=0,i=e.length/2;t<i;++t){const i=T(e[2*t],e[2*t+1],s);e[2*t]=i[0],e[2*t+1]=i[1]}this._delaunator=new l(e)}else delete this.collinear;const i=this.halfedges=this._delaunator.halfedges,n=this.hull=this._delaunator.hull,s=this.triangles=this._delaunator.triangles,h=this.inedges.fill(-1),r=this._hullIndex.fill(-1);for(let t=0,e=i.length;t<e;++t){const e=s[t%3==2?t-2:t+1];-1!==i[t]&&-1!==h[e]||(h[e]=t)}for(let t=0,e=n.length;t<e;++t)r[n[t]]=t;n.length<=2&&n.length>0&&(this.triangles=new Int32Array(3).fill(-1),this.halfedges=new Int32Array(3).fill(-1),this.triangles[0]=n[0],this.triangles[1]=n[1],this.triangles[2]=n[1],h[n[0]]=1,2===n.length&&(h[n[1]]=0))}voronoi(t){return new x(this,t)}*neighbors(t){const{inedges:e,hull:i,_hullIndex:n,halfedges:s,triangles:l,collinear:h}=this;if(h){const e=h.indexOf(t);return e>0&&(yield h[e-1]),void(e<h.length-1&&(yield h[e+1]))}const r=e[t];if(-1===r)return;let o=r,a=-1;do{if(yield a=l[o],o=o%3==2?o-2:o+1,l[o]!==t)return;if(o=s[o],-1===o){const e=i[(n[t]+1)%i.length];return void(e!==a&&(yield e))}}while(o!==r)}find(t,e,i=0){if((t=+t)!=t||(e=+e)!=e)return-1;const n=i;let s;for(;(s=this._step(i,t,e))>=0&&s!==i&&s!==n;)i=s;return s}_step(t,e,i){const{inedges:n,hull:s,_hullIndex:l,halfedges:h,triangles:r,points:o}=this;if(-1===n[t]||!o.length)return(t+1)%(o.length>>1);let a=t,c=w(e-o[2*t],2)+w(i-o[2*t+1],2);const u=n[t];let f=u;do{let n=r[f];const u=w(e-o[2*n],2)+w(i-o[2*n+1],2);if(u<c&&(c=u,a=n),f=f%3==2?f-2:f+1,r[f]!==t)break;if(f=h[f],-1===f){if(f=s[(l[t]+1)%s.length],f!==n&&w(e-o[2*f],2)+w(i-o[2*f+1],2)<c)return f;break}}while(f!==u);return a}render(t){const e=null==t?t=new y:void 0,{points:i,halfedges:n,triangles:s}=this;for(let e=0,l=n.length;e<l;++e){const l=n[e];if(l<e)continue;const h=2*s[e],r=2*s[l];t.moveTo(i[h],i[h+1]),t.lineTo(i[r],i[r+1])}return this.renderHull(t),e&&e.value()}renderPoints(t,e=2){const i=null==t?t=new y:void 0,{points:n}=this;for(let i=0,s=n.length;i<s;i+=2){const s=n[i],l=n[i+1];t.moveTo(s+e,l),t.arc(s,l,e,0,p)}return i&&i.value()}renderHull(t){const e=null==t?t=new y:void 0,{hull:i,points:n}=this,s=2*i[0],l=i.length;t.moveTo(n[s],n[s+1]);for(let e=1;e<l;++e){const s=2*i[e];t.lineTo(n[s],n[s+1])}return t.closePath(),e&&e.value()}hullPolygon(){const t=new m;return this.renderHull(t),t.value()}renderTriangle(t,e){const i=null==e?e=new y:void 0,{points:n,triangles:s}=this,l=2*s[t*=3],h=2*s[t+1],r=2*s[t+2];return e.moveTo(n[l],n[l+1]),e.lineTo(n[h],n[h+1]),e.lineTo(n[r],n[r+1]),e.closePath(),i&&i.value()}*trianglePolygons(){const{triangles:t}=this;for(let e=0,i=t.length/3;e<i;++e)yield this.trianglePolygon(e)}trianglePolygon(t){const e=new m;return this.renderTriangle(t,e),e.value()}}function A(t){e.Transform.call(this,null,t)}A.Definition={type:"Voronoi",metadata:{modifies:!0},params:[{name:"x",type:"field",required:!0},{name:"y",type:"field",required:!0},{name:"size",type:"number",array:!0,length:2},{name:"extent",type:"array",array:!0,length:2,default:[[-1e5,-1e5],[1e5,1e5]],content:{type:"number",array:!0,length:2}},{name:"as",type:"string",default:"path"}]};const k=[-1e5,-1e5,1e5,1e5];function P(t){const e=t[0][0],i=t[0][1];let n=t.length-1;for(;t[n][0]===e&&t[n][1]===i;--n);return"M"+t.slice(0,n+1).join("L")+"Z"}return i.inherits(A,e.Transform,{transform(t,e){const i=t.as||"path",n=e.source;if(!n||!n.length)return e;let s=t.size;s=s?[0,0,s[0],s[1]]:(s=t.extent)?[s[0][0],s[0][1],s[1][0],s[1][1]]:k;const l=this.value=M.from(n,t.x,t.y).voronoi(s);for(let t=0,e=n.length;t<e;++t){const e=l.cellPolygon(t);n[t][i]=e?P(e):null}return e.reflow(t.modified()).modifies(i)}}),t.voronoi=A,t}({},vega,vega);
//# sourceMappingURL=vega-voronoi.min.js.map
{
"name": "vega-voronoi",
"version": "4.1.4",
"version": "4.1.5",
"description": "Voronoi diagram transform for Vega dataflows.",

@@ -12,18 +12,16 @@ "keywords": [

"main": "build/vega-voronoi.js",
"module": "index",
"module": "build/vega-voronoi.module.js",
"unpkg": "build/vega-voronoi.min.js",
"repository": "vega/vega",
"scripts": {
"rollup": "rollup -g d3-delaunay:d3,vega-dataflow:vega,vega-util:vega -f umd -n vega.transforms -o build/vega-voronoi.js -- index.js",
"prebuild": "rimraf build && mkdir build",
"build": "yarn rollup",
"postbuild": "terser build/vega-voronoi.js -c -m -o build/vega-voronoi.min.js",
"pretest": "yarn prebuild && yarn rollup",
"prebuild": "rimraf build",
"build": "rollup -c --config-transform",
"pretest": "yarn build --config-test",
"test": "tape 'test/**/*-test.js'",
"prepublishOnly": "yarn test && yarn build",
"postpublish": "git push && git push --tags"
"prepublishOnly": "yarn test && yarn build"
},
"dependencies": {
"d3-delaunay": "^5.3.0",
"vega-dataflow": "^5.7.2",
"vega-util": "^1.15.1"
"vega-dataflow": "^5.7.3",
"vega-util": "^1.15.2"
},

@@ -33,3 +31,3 @@ "devDependencies": {

},
"gitHead": "8d6793f4ca7eaaf2d22186764e9ce2dae687cf52"
"gitHead": "4affcbedb9d14815dbb6d3b250ed231b54fc95c0"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc