@upsetjs/venn.js
Advanced tools
Comparing version 1.4.1 to 1.4.2
import { nelderMead, bisect, norm2, zeros, conjugateGradient, scale, zerosM } from 'fmin'; | ||
const SMALL = 1e-10; | ||
const SMALL$1 = 1e-10; | ||
@@ -125,3 +125,3 @@ /** | ||
p1: { x: smallest.x, y: smallest.y + smallest.radius }, | ||
p2: { x: smallest.x - SMALL, y: smallest.y + smallest.radius }, | ||
p2: { x: smallest.x - SMALL$1, y: smallest.y + smallest.radius }, | ||
width: smallest.radius * 2, | ||
@@ -155,3 +155,3 @@ large: true, | ||
function containedInCircles(point, circles) { | ||
return circles.every((circle) => distance(point, circle) < circle.radius + SMALL); | ||
return circles.every((circle) => distance(point, circle) < circle.radius + SMALL$1); | ||
} | ||
@@ -330,3 +330,3 @@ | ||
const SMALL$1 = 1e-10; | ||
const SMALL = 1e-10; | ||
@@ -343,3 +343,3 @@ /** | ||
// handle complete overlapped circles | ||
if (Math.min(r1, r2) * Math.min(r1, r2) * Math.PI <= overlap + SMALL$1) { | ||
if (Math.min(r1, r2) * Math.min(r1, r2) * Math.PI <= overlap + SMALL) { | ||
return Math.abs(r1 - r2); | ||
@@ -623,3 +623,3 @@ } | ||
// completely overlapped circles shouldn't be positioned early here | ||
if (current.size + SMALL$1 >= Math.min(circles[left].size, circles[right].size)) { | ||
if (current.size + SMALL >= Math.min(circles[left].size, circles[right].size)) { | ||
weight = 0; | ||
@@ -1074,6 +1074,6 @@ } | ||
* @param {readonly {x: number, y: number, radius: number, setid: string}[]} circles | ||
* @returns {{[setid: string]: {x: number, y: number, radius: number}}} | ||
* @returns {{[setid: string]: {x: number, y: number, radius: number, setid: string}}} | ||
*/ | ||
function toObjectNotation(circles) { | ||
/** @type {{[setid: string]: {x: number, y: number, radius: number}}} */ | ||
/** @type {{[setid: string]: {x: number, y: number, radius: number, setid: string}}} */ | ||
const r = {}; | ||
@@ -1080,0 +1080,0 @@ for (const circle of circles) { |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).venn={})}(this,function(t){"use strict";const e=1e-10;function n(t,n){const i=function(t){const e=[];for(let n=0;n<t.length;++n)for(let s=n+1;s<t.length;++s){const r=o(t[n],t[s]);for(const t of r)t.parentIndex=[n,s],e.push(t)}return e}(t),l=i.filter(n=>(function(t,n){return n.every(n=>r(t,n)<n.radius+e)})(n,t));let c=0,f=0;const u=[];if(l.length>1){const e=a(l);for(let t=0;t<l.length;++t){const n=l[t];n.angle=Math.atan2(n.x-e.x,n.y-e.y)}l.sort((t,e)=>e.angle-t.angle);let n=l[l.length-1];for(let e=0;e<l.length;++e){const i=l[e];f+=(n.x+i.x)*(i.y-n.y);const o={x:(i.x+n.x)/2,y:(i.y+n.y)/2};let a=null;for(let e=0;e<i.parentIndex.length;++e)if(n.parentIndex.includes(i.parentIndex[e])){const s=t[i.parentIndex[e]],l=Math.atan2(i.x-s.x,i.y-s.y),c=Math.atan2(n.x-s.x,n.y-s.y);let f=c-l;f<0&&(f+=2*Math.PI);const u=c-f/2;let h=r(o,{x:s.x+s.radius*Math.sin(u),y:s.y+s.radius*Math.cos(u)});h>2*s.radius&&(h=2*s.radius),(null==a||a.width>h)&&(a={circle:s,width:h,p1:i,p2:n,large:h>s.radius,sweep:!0})}null!=a&&(u.push(a),c+=s(a.circle.radius,a.width),n=i)}}else{let n=t[0];for(let e=1;e<t.length;++e)t[e].radius<n.radius&&(n=t[e]);let s=!1;for(let e=0;e<t.length;++e)if(r(t[e],n)>Math.abs(n.radius-t[e].radius)){s=!0;break}s?c=f=0:(c=n.radius*n.radius*Math.PI,u.push({circle:n,p1:{x:n.x,y:n.y+n.radius},p2:{x:n.x-e,y:n.y+n.radius},width:2*n.radius,large:!0,sweep:!0}))}return f/=2,n&&(n.area=c+f,n.arcArea=c,n.polygonArea=f,n.arcs=u,n.innerPoints=l,n.intersectionPoints=i),c+f}function s(t,e){return t*t*Math.acos(1-e/t)-(t-e)*Math.sqrt(e*(2*t-e))}function r(t,e){return Math.sqrt((t.x-e.x)*(t.x-e.x)+(t.y-e.y)*(t.y-e.y))}function i(t,e,n){if(n>=t+e)return 0;if(n<=Math.abs(t-e))return Math.PI*Math.min(t,e)*Math.min(t,e);const r=e-(n*n-t*t+e*e)/(2*n);return s(t,t-(n*n-e*e+t*t)/(2*n))+s(e,r)}function o(t,e){const n=r(t,e),s=t.radius,i=e.radius;if(n>=s+i||n<=Math.abs(s-i))return[];const o=(s*s-i*i+n*n)/(2*n),a=Math.sqrt(s*s-o*o),l=t.x+o*(e.x-t.x)/n,c=t.y+o*(e.y-t.y)/n,f=-(e.y-t.y)*(a/n),u=-(e.x-t.x)*(a/n);return[{x:l+f,y:c-u},{x:l-f,y:c+u}]}function a(t){const e={x:0,y:0};for(const n of t)e.x+=n.x,e.y+=n.y;return e.x/=t.length,e.y/=t.length,e}"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var l,c=(function(t,e){!function(t){function e(t){for(var e=new Array(t),n=0;n<t;++n)e[n]=0;return e}function n(t,e){for(var n=0,s=0;s<t.length;++s)n+=t[s]*e[s];return n}function s(t){return Math.sqrt(n(t,t))}function r(t,e,n){for(var s=0;s<e.length;++s)t[s]=e[s]*n}function i(t,e,n,s,r){for(var i=0;i<t.length;++i)t[i]=e*n[i]+s*r[i]}function o(t,e,s,r,o,a,l){var c=s.fx,f=n(s.fxprime,e),u=c,h=c,x=f,g=0;function d(h,g,d){for(var p=0;p<16;++p)if(o=(h+g)/2,i(r.x,1,s.x,o,e),u=r.fx=t(r.x,r.fxprime),x=n(r.fxprime,e),u>c+a*o*f||u>=d)g=o;else{if(Math.abs(x)<=-l*f)return o;x*(g-h)>=0&&(g=h),h=o,d=u}return 0}o=o||1,a=a||1e-6,l=l||.1;for(var p=0;p<10;++p){if(i(r.x,1,s.x,o,e),u=r.fx=t(r.x,r.fxprime),x=n(r.fxprime,e),u>c+a*o*f||p&&u>=h)return d(g,o,h);if(Math.abs(x)<=-l*f)return o;if(x>=0)return d(o,g,u);h=u,g=o,o*=2}return o}t.bisect=function(t,e,n,s){var r=(s=s||{}).maxIterations||100,i=s.tolerance||1e-10,o=t(e),a=t(n),l=n-e;if(o*a>0)throw"Initial bisect points must have opposite signs";if(0===o)return e;if(0===a)return n;for(var c=0;c<r;++c){var f=e+(l/=2),u=t(f);if(u*o>=0&&(e=f),Math.abs(l)<i||0===u)return f}return e+l},t.nelderMead=function(t,e,n){var s,r=(n=n||{}).maxIterations||200*e.length,o=n.nonZeroDelta||1.05,a=n.zeroDelta||.001,l=n.minErrorDelta||1e-6,c=n.minErrorDelta||1e-5,f=void 0!==n.rho?n.rho:1,u=void 0!==n.chi?n.chi:2,h=void 0!==n.psi?n.psi:-.5,x=void 0!==n.sigma?n.sigma:.5,g=e.length,d=new Array(g+1);d[0]=e,d[0].fx=t(e),d[0].id=0;for(var p=0;p<g;++p){var y=e.slice();y[p]=y[p]?y[p]*o:a,d[p+1]=y,d[p+1].fx=t(y),d[p+1].id=p+1}function m(t){for(var e=0;e<t.length;e++)d[g][e]=t[e];d[g].fx=t.fx}for(var M=function(t,e){return t.fx-e.fx},b=e.slice(),v=e.slice(),z=e.slice(),w=e.slice(),I=0;I<r;++I){if(d.sort(M),n.history){var R=d.map(function(t){var e=t.slice();return e.fx=t.fx,e.id=t.id,e});R.sort(function(t,e){return t.id-e.id}),n.history.push({x:d[0].slice(),fx:d[0].fx,simplex:R})}for(s=0,p=0;p<g;++p)s=Math.max(s,Math.abs(d[0][p]-d[1][p]));if(Math.abs(d[0].fx-d[g].fx)<l&&s<c)break;for(p=0;p<g;++p){b[p]=0;for(var A=0;A<g;++A)b[p]+=d[A][p];b[p]/=g}var F=d[g];if(i(v,1+f,b,-f,F),v.fx=t(v),v.fx<d[0].fx)i(w,1+u,b,-u,F),w.fx=t(w),w.fx<v.fx?m(w):m(v);else if(v.fx>=d[g-1].fx){var P=!1;if(v.fx>F.fx?(i(z,1+h,b,-h,F),z.fx=t(z),z.fx<F.fx?m(z):P=!0):(i(z,1-h*f,b,h*f,F),z.fx=t(z),z.fx<v.fx?m(z):P=!0),P){if(x>=1)break;for(p=1;p<d.length;++p)i(d[p],1-x,d[0],x,d[p]),d[p].fx=t(d[p])}}else m(v)}return d.sort(M),{fx:d[0].fx,x:d[0]}},t.conjugateGradient=function(t,e,a){var l,c,f,u={x:e.slice(),fx:0,fxprime:e.slice()},h={x:e.slice(),fx:0,fxprime:e.slice()},x=e.slice(),g=1;f=(a=a||{}).maxIterations||20*e.length,u.fx=t(u.x,u.fxprime),r(l=u.fxprime.slice(),u.fxprime,-1);for(var d=0;d<f;++d){if(g=o(t,l,u,h,g),a.history&&a.history.push({x:u.x.slice(),fx:u.fx,fxprime:u.fxprime.slice(),alpha:g}),g){i(x,1,h.fxprime,-1,u.fxprime);var p=n(u.fxprime,u.fxprime),y=Math.max(0,n(x,h.fxprime)/p);i(l,y,l,-1,h.fxprime),c=u,u=h,h=c}else r(l,u.fxprime,-1);if(s(u.fxprime)<=1e-5)break}return a.history&&a.history.push({x:u.x.slice(),fx:u.fx,fxprime:u.fxprime.slice(),alpha:g}),u},t.gradientDescent=function(t,e,n){for(var r=(n=n||{}).maxIterations||100*e.length,o=n.learnRate||.001,a={x:e.slice(),fx:0,fxprime:e.slice()},l=0;l<r&&(a.fx=t(a.x,a.fxprime),n.history&&n.history.push({x:a.x.slice(),fx:a.fx,fxprime:a.fxprime.slice()}),i(a.x,1,a.x,-o,a.fxprime),!(s(a.fxprime)<=1e-5));++l);return a},t.gradientDescentLineSearch=function(t,e,n){n=n||{};var i,a={x:e.slice(),fx:0,fxprime:e.slice()},l={x:e.slice(),fx:0,fxprime:e.slice()},c=n.maxIterations||100*e.length,f=n.learnRate||1,u=e.slice(),h=n.c1||.001,x=n.c2||.1,g=[];if(n.history){var d=t;t=function(t,e){return g.push(t.slice()),d(t,e)}}a.fx=t(a.x,a.fxprime);for(var p=0;p<c&&(r(u,a.fxprime,-1),f=o(t,u,a,l,f,h,x),n.history&&(n.history.push({x:a.x.slice(),fx:a.fx,fxprime:a.fxprime.slice(),functionCalls:g,learnRate:f,alpha:f}),g=[]),i=a,a=l,l=i,!(0===f||s(a.fxprime)<1e-5));++p);return a},t.zeros=e,t.zerosM=function(t,n){return e(t).map(function(){return e(n)})},t.norm2=s,t.weightedSum=i,t.scale=r}(e)}(l={exports:{}},l.exports),l.exports);function f(t,e={}){e.maxIterations=e.maxIterations||500;const n=e.initialLayout||x,s=e.lossFunction||d,r=function(t,e={}){const n=e.distinct,s=t.map(t=>Object.assign({},t));function r(t){return t.join(";")}if(n){const t=new Map;for(const e of s)for(let n=0;n<e.sets.length;n++){const s=String(e.sets[n]);t.set(s,e.size+(t.get(s)||0));for(let r=n+1;r<e.sets.length;r++){const n=String(e.sets[r]),i=`${s};${n}`,o=`${n};${s}`;t.set(i,e.size+(t.get(i)||0)),t.set(o,e.size+(t.get(o)||0))}}for(const e of s)e.sets.length<3&&(e.size=t.get(r(e.sets)))}const i=[],o=new Set;for(const t of s)if(1===t.sets.length)i.push(t.sets[0]);else if(2===t.sets.length){const e=t.sets[0],n=t.sets[1];o.add(r(t.sets)),o.add(r([n,e]))}i.sort((t,e)=>t===e?0:t<e?-1:1);for(let t=0;t<i.length;++t){const e=i[t];for(let n=t+1;n<i.length;++n){const t=i[n];o.has(r([e,t]))||s.push({sets:[e,t],size:0})}}return s}(t,e),i=n(r,e),o=Object.keys(i),a=[];for(const t of o)a.push(i[t].x),a.push(i[t].y);const l=c.nelderMead(t=>{const e={};for(let n=0;n<o.length;++n){const s=o[n];e[s]={x:t[2*n],y:t[2*n+1],radius:i[s].radius}}return s(e,r)},a,e).x;for(let t=0;t<o.length;++t){const e=o[t];i[e].x=l[2*t],i[e].y=l[2*t+1]}return i}const u=1e-10;function h(t,e,n){return Math.min(t,e)*Math.min(t,e)*Math.PI<=n+u?Math.abs(t-e):c.bisect(s=>i(t,e,s)-n,0,t+e)}function x(t,e={}){let n=g(t,e);const s=e.lossFunction||d;if(t.length>=8){const r=function(t,e={}){const n=e.restarts||10,s=[],r={};for(const e of t)1===e.sets.length&&(r[e.sets[0]]=s.length,s.push(e));let{distances:i,constraints:o}=function(t,e,n){const s=c.zerosM(e.length,e.length),r=c.zerosM(e.length,e.length);return t.filter(t=>2===t.sets.length).forEach(t=>{const i=n[t.sets[0]],o=n[t.sets[1]],a=h(Math.sqrt(e[i].size/Math.PI),Math.sqrt(e[o].size/Math.PI),t.size);s[i][o]=s[o][i]=a;let l=0;t.size+1e-10>=Math.min(e[i].size,e[o].size)?l=1:t.size<=1e-10&&(l=-1),r[i][o]=r[o][i]=l}),{distances:s,constraints:r}}(t,s,r);const a=c.norm2(i.map(c.norm2))/i.length;i=i.map(t=>t.map(t=>t/a));const l=(t,e)=>(function(t,e,n,s){for(let t=0;t<e.length;++t)e[t]=0;let r=0;for(let i=0;i<n.length;++i){const o=t[2*i],a=t[2*i+1];for(let l=i+1;l<n.length;++l){const c=t[2*l],f=t[2*l+1],u=n[i][l],h=s[i][l],x=(c-o)*(c-o)+(f-a)*(f-a),g=Math.sqrt(x),d=x-u*u;h>0&&g<=u||h<0&&g>=u||(r+=2*d*d,e[2*i]+=4*d*(o-c),e[2*i+1]+=4*d*(a-f),e[2*l]+=4*d*(c-o),e[2*l+1]+=4*d*(f-a))}}return r})(t,e,i,o);let f=null;for(let t=0;t<n;++t){const t=c.zeros(2*i.length).map(Math.random),n=c.conjugateGradient(l,t,e);(!f||n.fx<f.fx)&&(f=n)}const u=f.x,x={};for(let t=0;t<s.length;++t){const e=s[t];x[e.sets[0]]={x:u[2*t]*a,y:u[2*t+1]*a,radius:Math.sqrt(e.size/Math.PI)}}if(e.history)for(const t of e.history)c.scale(t.x,a);return x}(t,e);s(r,t)+1e-8<s(n,t)&&(n=r)}return n}function g(t,e){const n=e&&e.lossFunction?e.lossFunction:d,s={},r={};for(const e of t)if(1===e.sets.length){const t=e.sets[0];s[t]={x:1e10,y:1e10,rowid:s.length,size:e.size,radius:Math.sqrt(e.size/Math.PI)},r[t]=[]}t=t.filter(t=>2===t.sets.length);for(const e of t){let t=null!=e.weight?e.weight:1;const n=e.sets[0],i=e.sets[1];e.size+u>=Math.min(s[n].size,s[i].size)&&(t=0),r[n].push({set:i,size:e.size,weight:t}),r[i].push({set:n,size:e.size,weight:t})}const i=[];function a(t,e){return e.size-t.size}Object.keys(r).forEach(t=>{let e=0;for(let n=0;n<r[t].length;++n)e+=r[t][n].size*r[t][n].weight;i.push({set:t,size:e})}),i.sort(a);const l={};function c(t){return t.set in l}function f(t,e){s[e].x=t.x,s[e].y=t.y,l[e]=!0}f({x:0,y:0},i[0].set);for(let e=1;e<i.length;++e){const l=i[e].set,u=r[l].filter(c),g=s[l];if(u.sort(a),0===u.length)throw"ERROR: missing pairwise overlap information";const d=[];for(var x=0;x<u.length;++x){const t=s[u[x].set],e=h(g.radius,t.radius,u[x].size);d.push({x:t.x+e,y:t.y}),d.push({x:t.x-e,y:t.y}),d.push({y:t.y+e,x:t.x}),d.push({y:t.y-e,x:t.x});for(let n=x+1;n<u.length;++n){const r=s[u[n].set],i=h(g.radius,r.radius,u[n].size),a=o({x:t.x,y:t.y,radius:e},{x:r.x,y:r.y,radius:i});d.push(...a)}}let p=1e50,y=d[0];for(const e of d){s[l].x=e.x,s[l].y=e.y;const r=n(s,t);r<p&&(p=r,y=e)}f(y,l)}return s}function d(t,e){let s=0;for(const o of e){if(1===o.sets.length)continue;let e;if(2===o.sets.length){const n=t[o.sets[0]],s=t[o.sets[1]];e=i(n.radius,s.radius,r(n,s))}else e=n(o.sets.map(e=>t[e]));s+=(null!=o.weight?o.weight:1)*(e-o.size)*(e-o.size)}return s}function p(t,e){let s=0;for(const o of e){if(1===o.sets.length)continue;let e;if(2===o.sets.length){const n=t[o.sets[0]],s=t[o.sets[1]];e=i(n.radius,s.radius,r(n,s))}else e=n(o.sets.map(e=>t[e]));const a=null!=o.weight?o.weight:1,l=Math.log((e+1)/(o.size+1));s+=a*l*l}return s}function y(t,e,n){if(null==n?t.sort((t,e)=>e.radius-t.radius):t.sort(n),t.length>0){const e=t[0].x,n=t[0].y;for(const s of t)s.x-=e,s.y-=n}if(2===t.length){r(t[0],t[1])<Math.abs(t[1].radius-t[0].radius)&&(t[1].x=t[0].x+t[0].radius-t[1].radius-1e-10,t[1].y=t[0].y)}if(t.length>1){const n=Math.atan2(t[1].x,t[1].y)-e,s=Math.cos(n),r=Math.sin(n);for(const e of t){const t=e.x,n=e.y;e.x=s*t-r*n,e.y=r*t+s*n}}if(t.length>2){let n=Math.atan2(t[2].x,t[2].y)-e;for(;n<0;)n+=2*Math.PI;for(;n>2*Math.PI;)n-=2*Math.PI;if(n>Math.PI){const e=t[1].y/(1e-10+t[1].x);for(const n of t){var s=(n.x+e*n.y)/(1+e*e);n.x=2*s-n.x,n.y=2*s*e-n.y}}}}function m(t){function e(t){return t.parent!==t&&(t.parent=e(t.parent)),t.parent}function n(t,n){const s=e(t),r=e(n);s.parent=r}t.forEach(t=>{t.parent=t});for(let e=0;e<t.length;++e)for(let s=e+1;s<t.length;++s){const i=t[e].radius+t[s].radius;r(t[e],t[s])+1e-10<i&&n(t[s],t[e])}const s=new Map;for(let n=0;n<t.length;++n){const r=e(t[n]).parent.setid;s.has(r)||s.set(r,[]),s.get(r).push(t[n])}return t.forEach(t=>{delete t.parent}),Array.from(s.values())}function M(t){const e=e=>{return{max:t.reduce((t,n)=>Math.max(t,n[e]+n.radius),Number.NEGATIVE_INFINITY),min:t.reduce((t,n)=>Math.min(t,n[e]-n.radius),Number.POSITIVE_INFINITY)}};return{xRange:e("x"),yRange:e("y")}}function b(t,e,n){null==e&&(e=Math.PI/2);let s=w(t).map(t=>Object.assign({},t));const r=m(s);for(const t of r){y(t,e,n);const s=M(t);t.size=(s.xRange.max-s.xRange.min)*(s.yRange.max-s.yRange.min),t.bounds=s}r.sort((t,e)=>e.size-t.size);let i=(s=r[0]).bounds;const o=(i.xRange.max-i.xRange.min)/50;function a(t,e,n){if(!t)return;const r=t.bounds;let a,l;if(e)a=i.xRange.max-r.xRange.min+o;else{a=i.xRange.max-r.xRange.max;const t=(r.xRange.max-r.xRange.min)/2-(i.xRange.max-i.xRange.min)/2;t<0&&(a+=t)}if(n)l=i.yRange.max-r.yRange.min+o;else{l=i.yRange.max-r.yRange.max;const t=(r.yRange.max-r.yRange.min)/2-(i.yRange.max-i.yRange.min)/2;t<0&&(l+=t)}for(const e of t)e.x+=a,e.y+=l,s.push(e)}let l=1;for(;l<r.length;)a(r[l],!0,!1),a(r[l+1],!1,!0),a(r[l+2],!0,!0),l+=3,i=M(s);return z(s)}function v(t,e,n,s,r){const i=w(t);e-=2*s,n-=2*s;const{xRange:o,yRange:a}=M(i);if(o.max===o.min||a.max===a.min)return console.log("not scaling solution: zero size detected"),t;let l,c;if(r){const t=2*Math.sqrt(r/Math.PI);l=e/t,c=n/t}else l=e/(o.max-o.min),c=n/(a.max-a.min);const f=Math.min(c,l),u=(e-(o.max-o.min)*f)/2,h=(n-(a.max-a.min)*f)/2;return z(i.map(t=>({radius:f*t.radius,x:s+u+(t.x-o.min)*f,y:s+h+(t.y-a.min)*f,setid:t.setid})))}function z(t){const e={};for(const n of t)e[n.setid]=n;return e}function w(t){return Object.keys(t).map(e=>Object.assign(t[e],{setid:e}))}function I(t,e){return function(n){const s=this,r=t[n.sets[0]].radius||50,i=e(n)||"",o=i.split(/\s+/).reverse(),a=(i.length+o.length)/3;let l=o.pop(),c=[l],f=0;s.textContent=null;const u=[];function h(t){const e=s.ownerDocument.createElementNS(s.namespaceURI,"tspan");return e.textContent=t,u.push(e),s.append(e),e}let x=h(l);for(;l=o.pop();){c.push(l);const t=c.join(" ");x.textContent=t,t.length>a&&x.getComputedTextLength()>r&&(c.pop(),x.textContent=c.join(" "),c=[l],x=h(l),f++)}const g=.35-1.1*f/2,d=s.getAttribute("x"),p=s.getAttribute("y");u.forEach((t,e)=>{t.setAttribute("x",d),t.setAttribute("y",p),t.setAttribute("dy",`${g+1.1*e}em`)})}}function R(t,e,n){let s=e[0].radius-r(e[0],t);for(let n=1;n<e.length;++n){const i=e[n].radius-r(e[n],t);i<=s&&(s=i)}for(let e=0;e<n.length;++e){const i=r(n[e],t)-n[e].radius;i<=s&&(s=i)}return s}function A(t,e,s){const i=[];for(const e of t)i.push({x:e.x,y:e.y}),i.push({x:e.x+e.radius/2,y:e.y}),i.push({x:e.x-e.radius/2,y:e.y}),i.push({x:e.x,y:e.y+e.radius/2}),i.push({x:e.x,y:e.y-e.radius/2});let o=i[0],l=R(i[0],t,e);for(let n=1;n<i.length;++n){const s=R(i[n],t,e);s>=l&&(o=i[n],l=s)}const f=c.nelderMead(n=>-1*R({x:n[0],y:n[1]},t,e),[o.x,o.y],{maxIterations:500,minErrorDelta:1e-10}).x,u={x:s?0:f[0],y:f[1]};let h=!0;for(const e of t)if(r(u,e)>e.radius){h=!1;break}for(const t of e)if(r(u,t)<t.radius){h=!1;break}if(h)return u;if(1==t.length)return{x:t[0].x,y:t[0].y};const x={};return n(t,x),0===x.arcs.length?{x:0,y:-1e3,disjoint:!0}:1==x.arcs.length?{x:x.arcs[0].circle.x,y:x.arcs[0].circle.y}:e.length?A(t,[]):a(x.arcs.map(t=>t.p1))}function F(t){const e={},n=Object.keys(t);for(const t of n)e[t]=[];for(let s=0;s<n.length;s++){const i=n[s],o=t[i];for(let a=s+1;a<n.length;++a){const s=n[a],l=t[s],c=r(o,l);c+l.radius<=o.radius+1e-10?e[s].push(i):c+o.radius<=l.radius+1e-10&&e[i].push(s)}}return e}function P(t,e,n){const s={},r=F(t);for(let i=0;i<e.length;++i){const o=e[i].sets,a={},l={};for(let t=0;t<o.length;++t){a[o[t]]=!0;const e=r[o[t]];for(let t=0;t<e.length;++t)l[e[t]]=!0}const c=[],f=[];for(let e in t)e in a?c.push(t[e]):e in l||f.push(t[e]);const u=A(c,f,n);s[o]=u,u.disjoint&&e[i].size>0&&console.log("WARNING: area "+o+" not represented on screen")}return s}function j(t,e,n){const s=[];return s.push("\nM",t,e),s.push("\nm",-n,0),s.push("\na",n,n,0,1,0,2*n,0),s.push("\na",n,n,0,1,0,2*-n,0),s.join(" ")}function T(t){const e=t.split(" ");return{x:Number.parseFloat(e[1]),y:Number.parseFloat(e[2]),radius:-Number.parseFloat(e[4])}}function S(t){if(0===t.length)return[];const e={};return n(t,e),e.arcs}function E(t,e){if(0===t.length)return"M 0 0";const n=Math.pow(10,e||0),s=null!=e?t=>Math.round(t*n)/n:t=>t;if(1==t.length){const e=t[0].circle;return j(s(e.x),s(e.y),s(e.radius))}const r=["\nM",s(t[0].p2.x),s(t[0].p2.y)];for(const e of t){const t=s(e.circle.radius);r.push("\nA",t,t,0,e.large?1:0,e.sweep?1:0,s(e.p1.x),s(e.p1.y))}return r.join(" ")}function C(t,e){return E(S(t),e)}t.VennDiagram=function(t={}){let e=!1,n=600,s=350,r=15,i=1e3,o=Math.PI/2,a=!0,l=null,c=!0,u=!0,h=null,x=null,g=!1,y=null,m=!(!t||!t.symmetricalTextCentre)&&t.symmetricalTextCentre,M={},z=t&&t.colourScheme?t.colourScheme:t&&t.colorScheme?t.colorScheme:["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f","#bcbd22","#17becf"],w=0,R=function(t){if(t in M)return M[t];var e=M[t]=z[w];return(w+=1)>=z.length&&(w=0),e},A=f,F=d;function j(f){let d=f.datum();const p=new Set;d.forEach(t=>{0==t.size&&1==t.sets.length&&p.add(t.sets[0])}),d=d.filter(t=>!t.sets.some(t=>p.has(t)));let M={},z={};if(d.length>0){let t=A(d,{lossFunction:F,distinct:g});a&&(t=b(t,o,x)),M=v(t,n,s,r,l),z=P(M,d,m)}const w={};function j(t){return t.sets in w?w[t.sets]:1==t.sets.length?""+t.sets[0]:void 0}d.forEach(t=>{t.label&&(w[t.sets]=t.label)}),f.selectAll("svg").data([M]).enter().append("svg");const S=f.select("svg");e?S.attr("viewBox",`0 0 ${n} ${s}`):S.attr("width",n).attr("height",s);const E={};let O=!1;function N(t){return e=>C(t.sets.map(t=>{let r=E[t],i=M[t];return r||(r={x:n/2,y:s/2,radius:1}),i||(i={x:n/2,y:s/2,radius:1}),{x:r.x*(1-e)+i.x*e,y:r.y*(1-e)+i.y*e,radius:r.radius*(1-e)+i.radius*e}}),y)}S.selectAll(".venn-area path").each(function(t){const e=this.getAttribute("d");1==t.sets.length&&e&&!g&&(O=!0,E[t.sets[0]]=T(e))});const k=S.selectAll(".venn-area").data(d,t=>t.sets),q=k.enter().append("g").attr("class",t=>`venn-area venn-${1==t.sets.length?"circle":"intersection"}${t.colour||t.color?" venn-coloured":""}`).attr("data-venn-sets",t=>t.sets.join("_")),D=q.append("path"),$=q.append("text").attr("class","label").text(t=>j(t)).attr("text-anchor","middle").attr("dy",".35em").attr("x",n/2).attr("y",s/2);function L(t){return"function"==typeof t.transition?t.transition("venn").duration(i):t}u&&(D.style("fill-opacity","0").filter(t=>1==t.sets.length).style("fill",t=>t.colour?t.colour:t.color?t.color:R(t.sets)).style("fill-opacity",".25"),$.style("fill",e=>e.colour||e.color?"#FFF":t.textFill?t.textFill:1==e.sets.length?R(e.sets):"#444"));let _=f;O&&"function"==typeof _.transition?(_=L(f)).selectAll("path").attrTween("d",N):_.selectAll("path").attr("d",t=>C(t.sets.map(t=>M[t])),y);const G=_.selectAll("text").filter(t=>t.sets in z).text(t=>j(t)).attr("x",t=>Math.floor(z[t.sets].x)).attr("y",t=>Math.floor(z[t.sets].y));c&&(O?"on"in G?G.on("end",I(M,j)):G.each("end",I(M,j)):G.each(I(M,j)));const V=L(k.exit()).remove();"function"==typeof k.transition&&V.selectAll("path").attrTween("d",N);const B=V.selectAll("text").attr("x",n/2).attr("y",s/2);return null!==h&&($.style("font-size","0px"),G.style("font-size",h),B.style("font-size","0px")),{circles:M,textCentres:z,nodes:k,enter:q,update:_,exit:V}}return j.wrap=function(t){return arguments.length?(c=t,j):c},j.useViewBox=function(){return e=!0,j},j.width=function(t){return arguments.length?(n=t,j):n},j.height=function(t){return arguments.length?(s=t,j):s},j.padding=function(t){return arguments.length?(r=t,j):r},j.distinct=function(t){return arguments.length?(g=t,j):g},j.colours=function(t){return arguments.length?(R=t,j):R},j.colors=function(t){return arguments.length?(R=t,j):colors},j.fontSize=function(t){return arguments.length?(h=t,j):h},j.round=function(t){return arguments.length?(y=t,j):y},j.duration=function(t){return arguments.length?(i=t,j):i},j.layoutFunction=function(t){return arguments.length?(A=t,j):A},j.normalize=function(t){return arguments.length?(a=t,j):a},j.scaleToFit=function(t){return arguments.length?(l=t,j):l},j.styled=function(t){return arguments.length?(u=t,j):u},j.orientation=function(t){return arguments.length?(o=t,j):o},j.orientationOrder=function(t){return arguments.length?(x=t,j):x},j.lossFunction=function(t){return arguments.length?(F="default"===t?d:"logRatio"===t?p:t,j):F},j},t.bestInitialLayout=x,t.circleArea=s,t.circleCircleIntersection=o,t.circleFromPath=T,t.circleOverlap=i,t.circlePath=j,t.computeTextCentre=A,t.computeTextCentres=P,t.disjointCluster=m,t.distance=r,t.distanceFromIntersectArea=h,t.greedyLayout=g,t.intersectionArea=n,t.intersectionAreaPath=C,t.layout=function(t,e={}){const{lossFunction:n,layoutFunction:s=f,normalize:r=!0,orientation:i=Math.PI/2,orientationOrder:o,width:a=600,height:l=350,padding:c=15,scaleToFit:u=!1,symmetricalTextCentre:h=!1,distinct:x,round:g=2}=e;let y=s(t,{lossFunction:"default"!==n&&n?"logRatio"===n?p:n:d,distinct:x});r&&(y=b(y,i,o));const m=v(y,a,l,c,u),M=P(m,t,h),z=new Map(Object.keys(m).map(t=>[t,{set:t,x:m[t].x,y:m[t].y,radius:m[t].radius}])),w=t.map(t=>{const e=t.sets.map(t=>z.get(t)),n=S(e);return{circles:e,arcs:n,path:E(n,g),area:t,has:new Set(t.sets)}});return w.map(({circles:t,arcs:e,path:n,area:s})=>({data:s,text:M[s.sets],circles:t,arcs:e,path:n,distinctPath:n+function(t){let e="";for(const n of w)n.has.size>t.length&&t.every(t=>n.has.has(t))&&(e+=" "+n.path);return e}(s.sets)}))},t.logRatioLossFunction=p,t.lossFunction=d,t.normalizeSolution=b,t.scaleSolution=v,t.sortAreas=function(t,e){const n=F(t.selectAll("svg").datum()),s=new Set;for(const t of e.sets)for(let e in n){const r=n[e];for(let n=0;n<r.length;++n)if(r[n]==t){s.add(e);break}}function r(t){return t.every(t=>!s.has(t))}t.selectAll("g").sort((t,n)=>t.sets.length!=n.sets.length?t.sets.length-n.sets.length:t==e?r(n.sets)?-1:1:n==e?r(t.sets)?1:-1:n.size-t.size)},t.venn=f,t.wrapText=I,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).venn={})}(this,function(t){"use strict";const e=1e-10;function n(t,n){const o=function(t){const e=[];for(let n=0;n<t.length;++n)for(let s=n+1;s<t.length;++s){const r=i(t[n],t[s]);for(const t of r)t.parentIndex=[n,s],e.push(t)}return e}(t),l=o.filter(n=>(function(t,n){return n.every(n=>r(t,n)<n.radius+e)})(n,t));let c=0,f=0;const u=[];if(l.length>1){const e=a(l);for(let t=0;t<l.length;++t){const n=l[t];n.angle=Math.atan2(n.x-e.x,n.y-e.y)}l.sort((t,e)=>e.angle-t.angle);let n=l[l.length-1];for(let e=0;e<l.length;++e){const o=l[e];f+=(n.x+o.x)*(o.y-n.y);const i={x:(o.x+n.x)/2,y:(o.y+n.y)/2};let a=null;for(let e=0;e<o.parentIndex.length;++e)if(n.parentIndex.includes(o.parentIndex[e])){const s=t[o.parentIndex[e]],l=Math.atan2(o.x-s.x,o.y-s.y),c=Math.atan2(n.x-s.x,n.y-s.y);let f=c-l;f<0&&(f+=2*Math.PI);const u=c-f/2;let x=r(i,{x:s.x+s.radius*Math.sin(u),y:s.y+s.radius*Math.cos(u)});x>2*s.radius&&(x=2*s.radius),(null==a||a.width>x)&&(a={circle:s,width:x,p1:o,p2:n,large:x>s.radius,sweep:!0})}null!=a&&(u.push(a),c+=s(a.circle.radius,a.width),n=o)}}else{let n=t[0];for(let e=1;e<t.length;++e)t[e].radius<n.radius&&(n=t[e]);let s=!1;for(let e=0;e<t.length;++e)if(r(t[e],n)>Math.abs(n.radius-t[e].radius)){s=!0;break}s?c=f=0:(c=n.radius*n.radius*Math.PI,u.push({circle:n,p1:{x:n.x,y:n.y+n.radius},p2:{x:n.x-e,y:n.y+n.radius},width:2*n.radius,large:!0,sweep:!0}))}return f/=2,n&&(n.area=c+f,n.arcArea=c,n.polygonArea=f,n.arcs=u,n.innerPoints=l,n.intersectionPoints=o),c+f}function s(t,e){return t*t*Math.acos(1-e/t)-(t-e)*Math.sqrt(e*(2*t-e))}function r(t,e){return Math.sqrt((t.x-e.x)*(t.x-e.x)+(t.y-e.y)*(t.y-e.y))}function o(t,e,n){if(n>=t+e)return 0;if(n<=Math.abs(t-e))return Math.PI*Math.min(t,e)*Math.min(t,e);const r=e-(n*n-t*t+e*e)/(2*n);return s(t,t-(n*n-e*e+t*t)/(2*n))+s(e,r)}function i(t,e){const n=r(t,e),s=t.radius,o=e.radius;if(n>=s+o||n<=Math.abs(s-o))return[];const i=(s*s-o*o+n*n)/(2*n),a=Math.sqrt(s*s-i*i),l=t.x+i*(e.x-t.x)/n,c=t.y+i*(e.y-t.y)/n,f=-(e.y-t.y)*(a/n),u=-(e.x-t.x)*(a/n);return[{x:l+f,y:c-u},{x:l-f,y:c+u}]}function a(t){const e={x:0,y:0};for(const n of t)e.x+=n.x,e.y+=n.y;return e.x/=t.length,e.y/=t.length,e}"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var l={exports:{}};function c(t,e={}){e.maxIterations=e.maxIterations||500;const n=e.initialLayout||x,s=e.lossFunction||p,r=function(t,e={}){const n=e.distinct,s=t.map(t=>Object.assign({},t));function r(t){return t.join(";")}if(n){const t=new Map;for(const e of s)for(let n=0;n<e.sets.length;n++){const s=String(e.sets[n]);t.set(s,e.size+(t.get(s)||0));for(let r=n+1;r<e.sets.length;r++){const n=String(e.sets[r]),o=`${s};${n}`,i=`${n};${s}`;t.set(o,e.size+(t.get(o)||0)),t.set(i,e.size+(t.get(i)||0))}}for(const e of s)e.sets.length<3&&(e.size=t.get(r(e.sets)))}const o=[],i=new Set;for(const t of s)if(1===t.sets.length)o.push(t.sets[0]);else if(2===t.sets.length){const e=t.sets[0],n=t.sets[1];i.add(r(t.sets)),i.add(r([n,e]))}o.sort((t,e)=>t===e?0:t<e?-1:1);for(let t=0;t<o.length;++t){const e=o[t];for(let n=t+1;n<o.length;++n){const t=o[n];i.has(r([e,t]))||s.push({sets:[e,t],size:0})}}return s}(t,e),o=n(r,e),i=Object.keys(o),a=[];for(const t of i)a.push(o[t].x),a.push(o[t].y);const c=l.exports.nelderMead(t=>{const e={};for(let n=0;n<i.length;++n){const s=i[n];e[s]={x:t[2*n],y:t[2*n+1],radius:o[s].radius}}return s(e,r)},a,e).x;for(let t=0;t<i.length;++t){const e=i[t];o[e].x=c[2*t],o[e].y=c[2*t+1]}return o}!function(t){function e(t){for(var e=new Array(t),n=0;n<t;++n)e[n]=0;return e}function n(t,e){for(var n=0,s=0;s<t.length;++s)n+=t[s]*e[s];return n}function s(t){return Math.sqrt(n(t,t))}function r(t,e,n){for(var s=0;s<e.length;++s)t[s]=e[s]*n}function o(t,e,n,s,r){for(var o=0;o<t.length;++o)t[o]=e*n[o]+s*r[o]}function i(t,e,s,r,i,a,l){var c=s.fx,f=n(s.fxprime,e),u=c,x=c,h=f,p=0;function g(x,p,g){for(var d=0;d<16;++d)if(i=(x+p)/2,o(r.x,1,s.x,i,e),u=r.fx=t(r.x,r.fxprime),h=n(r.fxprime,e),u>c+a*i*f||u>=g)p=i;else{if(Math.abs(h)<=-l*f)return i;h*(p-x)>=0&&(p=x),x=i,g=u}return 0}i=i||1,a=a||1e-6,l=l||.1;for(var d=0;d<10;++d){if(o(r.x,1,s.x,i,e),u=r.fx=t(r.x,r.fxprime),h=n(r.fxprime,e),u>c+a*i*f||d&&u>=x)return g(p,i,x);if(Math.abs(h)<=-l*f)return i;if(h>=0)return g(i,p,u);x=u,p=i,i*=2}return i}t.bisect=function(t,e,n,s){var r=(s=s||{}).maxIterations||100,o=s.tolerance||1e-10,i=t(e),a=t(n),l=n-e;if(i*a>0)throw"Initial bisect points must have opposite signs";if(0===i)return e;if(0===a)return n;for(var c=0;c<r;++c){var f=e+(l/=2),u=t(f);if(u*i>=0&&(e=f),Math.abs(l)<o||0===u)return f}return e+l},t.nelderMead=function(t,e,n){var s,r=(n=n||{}).maxIterations||200*e.length,i=n.nonZeroDelta||1.05,a=n.zeroDelta||.001,l=n.minErrorDelta||1e-6,c=n.minErrorDelta||1e-5,f=void 0!==n.rho?n.rho:1,u=void 0!==n.chi?n.chi:2,x=void 0!==n.psi?n.psi:-.5,h=void 0!==n.sigma?n.sigma:.5,p=e.length,g=new Array(p+1);g[0]=e,g[0].fx=t(e),g[0].id=0;for(var d=0;d<p;++d){var y=e.slice();y[d]=y[d]?y[d]*i:a,g[d+1]=y,g[d+1].fx=t(y),g[d+1].id=d+1}function m(t){for(var e=0;e<t.length;e++)g[p][e]=t[e];g[p].fx=t.fx}for(var M=function(t,e){return t.fx-e.fx},b=e.slice(),v=e.slice(),z=e.slice(),w=e.slice(),I=0;I<r;++I){if(g.sort(M),n.history){var R=g.map(function(t){var e=t.slice();return e.fx=t.fx,e.id=t.id,e});R.sort(function(t,e){return t.id-e.id}),n.history.push({x:g[0].slice(),fx:g[0].fx,simplex:R})}for(s=0,d=0;d<p;++d)s=Math.max(s,Math.abs(g[0][d]-g[1][d]));if(Math.abs(g[0].fx-g[p].fx)<l&&s<c)break;for(d=0;d<p;++d){b[d]=0;for(var A=0;A<p;++A)b[d]+=g[A][d];b[d]/=p}var F=g[p];if(o(v,1+f,b,-f,F),v.fx=t(v),v.fx<g[0].fx)o(w,1+u,b,-u,F),w.fx=t(w),w.fx<v.fx?m(w):m(v);else if(v.fx>=g[p-1].fx){var P=!1;if(v.fx>F.fx?(o(z,1+x,b,-x,F),z.fx=t(z),z.fx<F.fx?m(z):P=!0):(o(z,1-x*f,b,x*f,F),z.fx=t(z),z.fx<v.fx?m(z):P=!0),P){if(h>=1)break;for(d=1;d<g.length;++d)o(g[d],1-h,g[0],h,g[d]),g[d].fx=t(g[d])}}else m(v)}return g.sort(M),{fx:g[0].fx,x:g[0]}},t.conjugateGradient=function(t,e,a){var l,c,f,u={x:e.slice(),fx:0,fxprime:e.slice()},x={x:e.slice(),fx:0,fxprime:e.slice()},h=e.slice(),p=1;f=(a=a||{}).maxIterations||20*e.length,u.fx=t(u.x,u.fxprime),r(l=u.fxprime.slice(),u.fxprime,-1);for(var g=0;g<f;++g){if(p=i(t,l,u,x,p),a.history&&a.history.push({x:u.x.slice(),fx:u.fx,fxprime:u.fxprime.slice(),alpha:p}),p){o(h,1,x.fxprime,-1,u.fxprime);var d=n(u.fxprime,u.fxprime),y=Math.max(0,n(h,x.fxprime)/d);o(l,y,l,-1,x.fxprime),c=u,u=x,x=c}else r(l,u.fxprime,-1);if(s(u.fxprime)<=1e-5)break}return a.history&&a.history.push({x:u.x.slice(),fx:u.fx,fxprime:u.fxprime.slice(),alpha:p}),u},t.gradientDescent=function(t,e,n){for(var r=(n=n||{}).maxIterations||100*e.length,i=n.learnRate||.001,a={x:e.slice(),fx:0,fxprime:e.slice()},l=0;l<r&&(a.fx=t(a.x,a.fxprime),n.history&&n.history.push({x:a.x.slice(),fx:a.fx,fxprime:a.fxprime.slice()}),o(a.x,1,a.x,-i,a.fxprime),!(s(a.fxprime)<=1e-5));++l);return a},t.gradientDescentLineSearch=function(t,e,n){n=n||{};var o,a={x:e.slice(),fx:0,fxprime:e.slice()},l={x:e.slice(),fx:0,fxprime:e.slice()},c=n.maxIterations||100*e.length,f=n.learnRate||1,u=e.slice(),x=n.c1||.001,h=n.c2||.1,p=[];if(n.history){var g=t;t=function(t,e){return p.push(t.slice()),g(t,e)}}a.fx=t(a.x,a.fxprime);for(var d=0;d<c&&(r(u,a.fxprime,-1),f=i(t,u,a,l,f,x,h),n.history&&(n.history.push({x:a.x.slice(),fx:a.fx,fxprime:a.fxprime.slice(),functionCalls:p,learnRate:f,alpha:f}),p=[]),o=a,a=l,l=o,!(0===f||s(a.fxprime)<1e-5));++d);return a},t.zeros=e,t.zerosM=function(t,n){return e(t).map(function(){return e(n)})},t.norm2=s,t.weightedSum=o,t.scale=r}(l.exports);const f=1e-10;function u(t,e,n){return Math.min(t,e)*Math.min(t,e)*Math.PI<=n+f?Math.abs(t-e):l.exports.bisect(s=>o(t,e,s)-n,0,t+e)}function x(t,e={}){let n=h(t,e);const s=e.lossFunction||p;if(t.length>=8){const r=function(t,e={}){const n=e.restarts||10,s=[],r={};for(const e of t)1===e.sets.length&&(r[e.sets[0]]=s.length,s.push(e));let{distances:o,constraints:i}=function(t,e,n){const s=l.exports.zerosM(e.length,e.length),r=l.exports.zerosM(e.length,e.length);return t.filter(t=>2===t.sets.length).forEach(t=>{const o=n[t.sets[0]],i=n[t.sets[1]],a=u(Math.sqrt(e[o].size/Math.PI),Math.sqrt(e[i].size/Math.PI),t.size);s[o][i]=s[i][o]=a;let l=0;t.size+1e-10>=Math.min(e[o].size,e[i].size)?l=1:t.size<=1e-10&&(l=-1),r[o][i]=r[i][o]=l}),{distances:s,constraints:r}}(t,s,r);const a=l.exports.norm2(o.map(l.exports.norm2))/o.length;o=o.map(t=>t.map(t=>t/a));const c=(t,e)=>(function(t,e,n,s){for(let t=0;t<e.length;++t)e[t]=0;let r=0;for(let o=0;o<n.length;++o){const i=t[2*o],a=t[2*o+1];for(let l=o+1;l<n.length;++l){const c=t[2*l],f=t[2*l+1],u=n[o][l],x=s[o][l],h=(c-i)*(c-i)+(f-a)*(f-a),p=Math.sqrt(h),g=h-u*u;x>0&&p<=u||x<0&&p>=u||(r+=2*g*g,e[2*o]+=4*g*(i-c),e[2*o+1]+=4*g*(a-f),e[2*l]+=4*g*(c-i),e[2*l+1]+=4*g*(f-a))}}return r})(t,e,o,i);let f=null;for(let t=0;t<n;++t){const t=l.exports.zeros(2*o.length).map(Math.random),n=l.exports.conjugateGradient(c,t,e);(!f||n.fx<f.fx)&&(f=n)}const x=f.x,h={};for(let t=0;t<s.length;++t){const e=s[t];h[e.sets[0]]={x:x[2*t]*a,y:x[2*t+1]*a,radius:Math.sqrt(e.size/Math.PI)}}if(e.history)for(const t of e.history)l.exports.scale(t.x,a);return h}(t,e);s(r,t)+1e-8<s(n,t)&&(n=r)}return n}function h(t,e){const n=e&&e.lossFunction?e.lossFunction:p,s={},r={};for(const e of t)if(1===e.sets.length){const t=e.sets[0];s[t]={x:1e10,y:1e10,rowid:s.length,size:e.size,radius:Math.sqrt(e.size/Math.PI)},r[t]=[]}t=t.filter(t=>2===t.sets.length);for(const e of t){let t=null!=e.weight?e.weight:1;const n=e.sets[0],o=e.sets[1];e.size+f>=Math.min(s[n].size,s[o].size)&&(t=0),r[n].push({set:o,size:e.size,weight:t}),r[o].push({set:n,size:e.size,weight:t})}const o=[];function a(t,e){return e.size-t.size}Object.keys(r).forEach(t=>{let e=0;for(let n=0;n<r[t].length;++n)e+=r[t][n].size*r[t][n].weight;o.push({set:t,size:e})}),o.sort(a);const l={};function c(t){return t.set in l}function x(t,e){s[e].x=t.x,s[e].y=t.y,l[e]=!0}x({x:0,y:0},o[0].set);for(let e=1;e<o.length;++e){const l=o[e].set,f=r[l].filter(c),p=s[l];if(f.sort(a),0===f.length)throw"ERROR: missing pairwise overlap information";const g=[];for(var h=0;h<f.length;++h){const t=s[f[h].set],e=u(p.radius,t.radius,f[h].size);g.push({x:t.x+e,y:t.y}),g.push({x:t.x-e,y:t.y}),g.push({y:t.y+e,x:t.x}),g.push({y:t.y-e,x:t.x});for(let n=h+1;n<f.length;++n){const r=s[f[n].set],o=u(p.radius,r.radius,f[n].size),a=i({x:t.x,y:t.y,radius:e},{x:r.x,y:r.y,radius:o});g.push(...a)}}let d=1e50,y=g[0];for(const e of g){s[l].x=e.x,s[l].y=e.y;const r=n(s,t);r<d&&(d=r,y=e)}x(y,l)}return s}function p(t,e){let s=0;for(const i of e){if(1===i.sets.length)continue;let e;if(2===i.sets.length){const n=t[i.sets[0]],s=t[i.sets[1]];e=o(n.radius,s.radius,r(n,s))}else e=n(i.sets.map(e=>t[e]));s+=(null!=i.weight?i.weight:1)*(e-i.size)*(e-i.size)}return s}function g(t,e){let s=0;for(const i of e){if(1===i.sets.length)continue;let e;if(2===i.sets.length){const n=t[i.sets[0]],s=t[i.sets[1]];e=o(n.radius,s.radius,r(n,s))}else e=n(i.sets.map(e=>t[e]));const a=null!=i.weight?i.weight:1,l=Math.log((e+1)/(i.size+1));s+=a*l*l}return s}function d(t,e,n){if(null==n?t.sort((t,e)=>e.radius-t.radius):t.sort(n),t.length>0){const e=t[0].x,n=t[0].y;for(const s of t)s.x-=e,s.y-=n}if(2===t.length){r(t[0],t[1])<Math.abs(t[1].radius-t[0].radius)&&(t[1].x=t[0].x+t[0].radius-t[1].radius-1e-10,t[1].y=t[0].y)}if(t.length>1){const n=Math.atan2(t[1].x,t[1].y)-e,s=Math.cos(n),r=Math.sin(n);for(const e of t){const t=e.x,n=e.y;e.x=s*t-r*n,e.y=r*t+s*n}}if(t.length>2){let n=Math.atan2(t[2].x,t[2].y)-e;for(;n<0;)n+=2*Math.PI;for(;n>2*Math.PI;)n-=2*Math.PI;if(n>Math.PI){const e=t[1].y/(1e-10+t[1].x);for(const n of t){var s=(n.x+e*n.y)/(1+e*e);n.x=2*s-n.x,n.y=2*s*e-n.y}}}}function y(t){function e(t){return t.parent!==t&&(t.parent=e(t.parent)),t.parent}function n(t,n){const s=e(t),r=e(n);s.parent=r}t.forEach(t=>{t.parent=t});for(let e=0;e<t.length;++e)for(let s=e+1;s<t.length;++s){const o=t[e].radius+t[s].radius;r(t[e],t[s])+1e-10<o&&n(t[s],t[e])}const s=new Map;for(let n=0;n<t.length;++n){const r=e(t[n]).parent.setid;s.has(r)||s.set(r,[]),s.get(r).push(t[n])}return t.forEach(t=>{delete t.parent}),Array.from(s.values())}function m(t){const e=e=>{return{max:t.reduce((t,n)=>Math.max(t,n[e]+n.radius),Number.NEGATIVE_INFINITY),min:t.reduce((t,n)=>Math.min(t,n[e]-n.radius),Number.POSITIVE_INFINITY)}};return{xRange:e("x"),yRange:e("y")}}function M(t,e,n){null==e&&(e=Math.PI/2);let s=z(t).map(t=>Object.assign({},t));const r=y(s);for(const t of r){d(t,e,n);const s=m(t);t.size=(s.xRange.max-s.xRange.min)*(s.yRange.max-s.yRange.min),t.bounds=s}r.sort((t,e)=>e.size-t.size);let o=(s=r[0]).bounds;const i=(o.xRange.max-o.xRange.min)/50;function a(t,e,n){if(!t)return;const r=t.bounds;let a,l;if(e)a=o.xRange.max-r.xRange.min+i;else{a=o.xRange.max-r.xRange.max;const t=(r.xRange.max-r.xRange.min)/2-(o.xRange.max-o.xRange.min)/2;t<0&&(a+=t)}if(n)l=o.yRange.max-r.yRange.min+i;else{l=o.yRange.max-r.yRange.max;const t=(r.yRange.max-r.yRange.min)/2-(o.yRange.max-o.yRange.min)/2;t<0&&(l+=t)}for(const e of t)e.x+=a,e.y+=l,s.push(e)}let l=1;for(;l<r.length;)a(r[l],!0,!1),a(r[l+1],!1,!0),a(r[l+2],!0,!0),l+=3,o=m(s);return v(s)}function b(t,e,n,s,r){const o=z(t);e-=2*s,n-=2*s;const{xRange:i,yRange:a}=m(o);if(i.max===i.min||a.max===a.min)return console.log("not scaling solution: zero size detected"),t;let l,c;if(r){const t=2*Math.sqrt(r/Math.PI);l=e/t,c=n/t}else l=e/(i.max-i.min),c=n/(a.max-a.min);const f=Math.min(c,l),u=(e-(i.max-i.min)*f)/2,x=(n-(a.max-a.min)*f)/2;return v(o.map(t=>({radius:f*t.radius,x:s+u+(t.x-i.min)*f,y:s+x+(t.y-a.min)*f,setid:t.setid})))}function v(t){const e={};for(const n of t)e[n.setid]=n;return e}function z(t){return Object.keys(t).map(e=>Object.assign(t[e],{setid:e}))}function w(t,e){return function(n){const s=this,r=t[n.sets[0]].radius||50,o=e(n)||"",i=o.split(/\s+/).reverse(),a=(o.length+i.length)/3;let l=i.pop(),c=[l],f=0;s.textContent=null;const u=[];function x(t){const e=s.ownerDocument.createElementNS(s.namespaceURI,"tspan");return e.textContent=t,u.push(e),s.append(e),e}let h=x(l);for(;l=i.pop();){c.push(l);const t=c.join(" ");h.textContent=t,t.length>a&&h.getComputedTextLength()>r&&(c.pop(),h.textContent=c.join(" "),c=[l],h=x(l),f++)}const p=.35-1.1*f/2,g=s.getAttribute("x"),d=s.getAttribute("y");u.forEach((t,e)=>{t.setAttribute("x",g),t.setAttribute("y",d),t.setAttribute("dy",`${p+1.1*e}em`)})}}function I(t,e,n){let s=e[0].radius-r(e[0],t);for(let n=1;n<e.length;++n){const o=e[n].radius-r(e[n],t);o<=s&&(s=o)}for(let e=0;e<n.length;++e){const o=r(n[e],t)-n[e].radius;o<=s&&(s=o)}return s}function R(t,e,s){const o=[];for(const e of t)o.push({x:e.x,y:e.y}),o.push({x:e.x+e.radius/2,y:e.y}),o.push({x:e.x-e.radius/2,y:e.y}),o.push({x:e.x,y:e.y+e.radius/2}),o.push({x:e.x,y:e.y-e.radius/2});let i=o[0],c=I(o[0],t,e);for(let n=1;n<o.length;++n){const s=I(o[n],t,e);s>=c&&(i=o[n],c=s)}const f=l.exports.nelderMead(n=>-1*I({x:n[0],y:n[1]},t,e),[i.x,i.y],{maxIterations:500,minErrorDelta:1e-10}).x,u={x:s?0:f[0],y:f[1]};let x=!0;for(const e of t)if(r(u,e)>e.radius){x=!1;break}for(const t of e)if(r(u,t)<t.radius){x=!1;break}if(x)return u;if(1==t.length)return{x:t[0].x,y:t[0].y};const h={};return n(t,h),0===h.arcs.length?{x:0,y:-1e3,disjoint:!0}:1==h.arcs.length?{x:h.arcs[0].circle.x,y:h.arcs[0].circle.y}:e.length?R(t,[]):a(h.arcs.map(t=>t.p1))}function A(t){const e={},n=Object.keys(t);for(const t of n)e[t]=[];for(let s=0;s<n.length;s++){const o=n[s],i=t[o];for(let a=s+1;a<n.length;++a){const s=n[a],l=t[s],c=r(i,l);c+l.radius<=i.radius+1e-10?e[s].push(o):c+i.radius<=l.radius+1e-10&&e[o].push(s)}}return e}function F(t,e,n){const s={},r=A(t);for(let o=0;o<e.length;++o){const i=e[o].sets,a={},l={};for(let t=0;t<i.length;++t){a[i[t]]=!0;const e=r[i[t]];for(let t=0;t<e.length;++t)l[e[t]]=!0}const c=[],f=[];for(let e in t)e in a?c.push(t[e]):e in l||f.push(t[e]);const u=R(c,f,n);s[i]=u,u.disjoint&&e[o].size>0&&console.log("WARNING: area "+i+" not represented on screen")}return s}function P(t,e,n){const s=[];return s.push("\nM",t,e),s.push("\nm",-n,0),s.push("\na",n,n,0,1,0,2*n,0),s.push("\na",n,n,0,1,0,2*-n,0),s.join(" ")}function j(t){const e=t.split(" ");return{x:Number.parseFloat(e[1]),y:Number.parseFloat(e[2]),radius:-Number.parseFloat(e[4])}}function T(t){if(0===t.length)return[];const e={};return n(t,e),e.arcs}function S(t,e){if(0===t.length)return"M 0 0";const n=Math.pow(10,e||0),s=null!=e?t=>Math.round(t*n)/n:t=>t;if(1==t.length){const e=t[0].circle;return P(s(e.x),s(e.y),s(e.radius))}const r=["\nM",s(t[0].p2.x),s(t[0].p2.y)];for(const e of t){const t=s(e.circle.radius);r.push("\nA",t,t,0,e.large?1:0,e.sweep?1:0,s(e.p1.x),s(e.p1.y))}return r.join(" ")}function E(t,e){return S(T(t),e)}t.VennDiagram=function(t={}){let e=!1,n=600,s=350,r=15,o=1e3,i=Math.PI/2,a=!0,l=null,f=!0,u=!0,x=null,h=null,d=!1,y=null,m=!(!t||!t.symmetricalTextCentre)&&t.symmetricalTextCentre,v={},z=t&&t.colourScheme?t.colourScheme:t&&t.colorScheme?t.colorScheme:["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f","#bcbd22","#17becf"],I=0,R=function(t){if(t in v)return v[t];var e=v[t]=z[I];return(I+=1)>=z.length&&(I=0),e},A=c,P=p;function T(c){let p=c.datum();const g=new Set;p.forEach(t=>{0==t.size&&1==t.sets.length&&g.add(t.sets[0])}),p=p.filter(t=>!t.sets.some(t=>g.has(t)));let v={},z={};if(p.length>0){let t=A(p,{lossFunction:P,distinct:d});a&&(t=M(t,i,h)),v=b(t,n,s,r,l),z=F(v,p,m)}const I={};function T(t){return t.sets in I?I[t.sets]:1==t.sets.length?""+t.sets[0]:void 0}p.forEach(t=>{t.label&&(I[t.sets]=t.label)}),c.selectAll("svg").data([v]).enter().append("svg");const S=c.select("svg");e?S.attr("viewBox",`0 0 ${n} ${s}`):S.attr("width",n).attr("height",s);const C={};let O=!1;function N(t){return e=>E(t.sets.map(t=>{let r=C[t],o=v[t];return r||(r={x:n/2,y:s/2,radius:1}),o||(o={x:n/2,y:s/2,radius:1}),{x:r.x*(1-e)+o.x*e,y:r.y*(1-e)+o.y*e,radius:r.radius*(1-e)+o.radius*e}}),y)}S.selectAll(".venn-area path").each(function(t){const e=this.getAttribute("d");1==t.sets.length&&e&&!d&&(O=!0,C[t.sets[0]]=j(e))});const k=S.selectAll(".venn-area").data(p,t=>t.sets),q=k.enter().append("g").attr("class",t=>`venn-area venn-${1==t.sets.length?"circle":"intersection"}${t.colour||t.color?" venn-coloured":""}`).attr("data-venn-sets",t=>t.sets.join("_")),D=q.append("path"),$=q.append("text").attr("class","label").text(t=>T(t)).attr("text-anchor","middle").attr("dy",".35em").attr("x",n/2).attr("y",s/2);function L(t){return"function"==typeof t.transition?t.transition("venn").duration(o):t}u&&(D.style("fill-opacity","0").filter(t=>1==t.sets.length).style("fill",t=>t.colour?t.colour:t.color?t.color:R(t.sets)).style("fill-opacity",".25"),$.style("fill",e=>e.colour||e.color?"#FFF":t.textFill?t.textFill:1==e.sets.length?R(e.sets):"#444"));let _=c;O&&"function"==typeof _.transition?(_=L(c)).selectAll("path").attrTween("d",N):_.selectAll("path").attr("d",t=>E(t.sets.map(t=>v[t])),y);const G=_.selectAll("text").filter(t=>t.sets in z).text(t=>T(t)).attr("x",t=>Math.floor(z[t.sets].x)).attr("y",t=>Math.floor(z[t.sets].y));f&&(O?"on"in G?G.on("end",w(v,T)):G.each("end",w(v,T)):G.each(w(v,T)));const V=L(k.exit()).remove();"function"==typeof k.transition&&V.selectAll("path").attrTween("d",N);const B=V.selectAll("text").attr("x",n/2).attr("y",s/2);return null!==x&&($.style("font-size","0px"),G.style("font-size",x),B.style("font-size","0px")),{circles:v,textCentres:z,nodes:k,enter:q,update:_,exit:V}}return T.wrap=function(t){return arguments.length?(f=t,T):f},T.useViewBox=function(){return e=!0,T},T.width=function(t){return arguments.length?(n=t,T):n},T.height=function(t){return arguments.length?(s=t,T):s},T.padding=function(t){return arguments.length?(r=t,T):r},T.distinct=function(t){return arguments.length?(d=t,T):d},T.colours=function(t){return arguments.length?(R=t,T):R},T.colors=function(t){return arguments.length?(R=t,T):colors},T.fontSize=function(t){return arguments.length?(x=t,T):x},T.round=function(t){return arguments.length?(y=t,T):y},T.duration=function(t){return arguments.length?(o=t,T):o},T.layoutFunction=function(t){return arguments.length?(A=t,T):A},T.normalize=function(t){return arguments.length?(a=t,T):a},T.scaleToFit=function(t){return arguments.length?(l=t,T):l},T.styled=function(t){return arguments.length?(u=t,T):u},T.orientation=function(t){return arguments.length?(i=t,T):i},T.orientationOrder=function(t){return arguments.length?(h=t,T):h},T.lossFunction=function(t){return arguments.length?(P="default"===t?p:"logRatio"===t?g:t,T):P},T},t.bestInitialLayout=x,t.circleArea=s,t.circleCircleIntersection=i,t.circleFromPath=j,t.circleOverlap=o,t.circlePath=P,t.computeTextCentre=R,t.computeTextCentres=F,t.disjointCluster=y,t.distance=r,t.distanceFromIntersectArea=u,t.greedyLayout=h,t.intersectionArea=n,t.intersectionAreaPath=E,t.layout=function(t,e={}){const{lossFunction:n,layoutFunction:s=c,normalize:r=!0,orientation:o=Math.PI/2,orientationOrder:i,width:a=600,height:l=350,padding:f=15,scaleToFit:u=!1,symmetricalTextCentre:x=!1,distinct:h,round:d=2}=e;let y=s(t,{lossFunction:"default"!==n&&n?"logRatio"===n?g:n:p,distinct:h});r&&(y=M(y,o,i));const m=b(y,a,l,f,u),v=F(m,t,x),z=new Map(Object.keys(m).map(t=>[t,{set:t,x:m[t].x,y:m[t].y,radius:m[t].radius}])),w=t.map(t=>{const e=t.sets.map(t=>z.get(t)),n=T(e);return{circles:e,arcs:n,path:S(n,d),area:t,has:new Set(t.sets)}});return w.map(({circles:t,arcs:e,path:n,area:s})=>({data:s,text:v[s.sets],circles:t,arcs:e,path:n,distinctPath:n+function(t){let e="";for(const n of w)n.has.size>t.length&&t.every(t=>n.has.has(t))&&(e+=" "+n.path);return e}(s.sets)}))},t.logRatioLossFunction=g,t.lossFunction=p,t.normalizeSolution=M,t.scaleSolution=b,t.sortAreas=function(t,e){const n=A(t.selectAll("svg").datum()),s=new Set;for(const t of e.sets)for(let e in n){const r=n[e];for(let n=0;n<r.length;++n)if(r[n]==t){s.add(e);break}}function r(t){return t.every(t=>!s.has(t))}t.selectAll("g").sort((t,n)=>t.sets.length!=n.sets.length?t.sets.length-n.sets.length:t==e?r(n.sets)?-1:1:n==e?r(t.sets)?1:-1:n.size-t.size)},t.venn=c,t.wrapText=w,Object.defineProperty(t,"__esModule",{value:!0})}); |
{ | ||
"name": "@upsetjs/venn.js", | ||
"description": "Area Proportional Venn and Euler Diagrams", | ||
"version": "1.4.1", | ||
"version": "1.4.2", | ||
"publishConfig": { | ||
@@ -54,4 +54,4 @@ "access": "public" | ||
"optionalDependencies": { | ||
"d3-selection": "^2.0.0", | ||
"d3-transition": "^2.0.0" | ||
"d3-selection": "^3.0.0", | ||
"d3-transition": "^3.0.1" | ||
}, | ||
@@ -62,20 +62,20 @@ "dependencies": { | ||
"devDependencies": { | ||
"@babel/core": "^7.12.13", | ||
"@babel/plugin-transform-runtime": "^7.12.15", | ||
"@babel/preset-env": "^7.12.13", | ||
"@rollup/plugin-babel": "^5.2.3", | ||
"@rollup/plugin-commonjs": "^17.1.0", | ||
"@rollup/plugin-node-resolve": "^11.1.1", | ||
"@yarnpkg/pnpify": "^2.4.0", | ||
"babel-jest": "^26.6.3", | ||
"canvas": "^2.6.1", | ||
"eslint": "^7.19.0", | ||
"eslint-config-prettier": "^7.2.0", | ||
"eslint-plugin-prettier": "^3.3.1", | ||
"jest": "^26.6.3", | ||
"jest-image-snapshot": "^4.3.0", | ||
"prettier": "^2.2.1", | ||
"release-it": "^14.3.0", | ||
"@babel/core": "^7.16.5", | ||
"@babel/plugin-transform-runtime": "^7.16.5", | ||
"@babel/preset-env": "^7.16.5", | ||
"@rollup/plugin-babel": "^5.3.0", | ||
"@rollup/plugin-commonjs": "^21.0.1", | ||
"@rollup/plugin-node-resolve": "^13.1.1", | ||
"@yarnpkg/sdks": "^2.5.1-rc.6", | ||
"babel-jest": "^27.4.5", | ||
"canvas": "^2.8.0", | ||
"eslint": "^8.5.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"jest": "^27.4.5", | ||
"jest-image-snapshot": "^4.5.1", | ||
"prettier": "^2.5.1", | ||
"release-it": "^14.11.8", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^2.38.5", | ||
"rollup": "^2.61.1", | ||
"rollup-plugin-pnp-resolve": "^2.0.0", | ||
@@ -101,3 +101,4 @@ "uglify-es": "^3.3.9" | ||
"release:pre": "release-it --disable-metrics --npm.skipChecks --preRelease=alpha --npm.tag=next" | ||
} | ||
}, | ||
"packageManager": "yarn@3.1.1" | ||
} |
@@ -246,5 +246,4 @@ # venn.js | ||
npm i -g yarn | ||
yarn set version 2 | ||
yarn | ||
yarn pnpify --sdk vscode | ||
yarn install | ||
yarn sdks vscode | ||
``` | ||
@@ -251,0 +250,0 @@ |
@@ -22,2 +22,3 @@ import { Selection } from 'd3-selection'; | ||
radius: number; | ||
setid: string; | ||
} | ||
@@ -24,0 +25,0 @@ |
@@ -803,6 +803,6 @@ import { nelderMead, bisect, conjugateGradient, zeros, zerosM, norm2, scale } from 'fmin'; | ||
* @param {readonly {x: number, y: number, radius: number, setid: string}[]} circles | ||
* @returns {{[setid: string]: {x: number, y: number, radius: number}}} | ||
* @returns {{[setid: string]: {x: number, y: number, radius: number, setid: string}}} | ||
*/ | ||
function toObjectNotation(circles) { | ||
/** @type {{[setid: string]: {x: number, y: number, radius: number}}} */ | ||
/** @type {{[setid: string]: {x: number, y: number, radius: number, setid: string}}} */ | ||
const r = {}; | ||
@@ -809,0 +809,0 @@ for (const circle of circles) { |
Sorry, the diff of this file is too big to display
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
241445
5886
268