This repository has been archived by the owner on Jun 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 147
/
d3-chord.v2.min.js
2 lines (2 loc) · 4.24 KB
/
d3-chord.v2.min.js
1
2
// https://d3js.org/d3-chord/ v2.0.0 Copyright 2020 Mike Bostock
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("d3-path")):"function"==typeof define&&define.amd?define(["exports","d3-path"],t):t((n=n||self).d3=n.d3||{},n.d3)}(this,function(n,t){"use strict";var e=Math.abs,r=Math.cos,u=Math.sin,o=Math.PI,l=o/2,a=2*o,i=Math.max,c=1e-12;function f(n,t){return Array.from({length:t-n},(t,e)=>n+e)}function s(n){return function(t,e){return n(t.source.value+t.target.value,e.source.value+e.target.value)}}function g(n,t){var e=0,r=null,u=null,o=null;function l(l){var c,s=l.length,g=new Array(s),p=f(0,s),d=new Array(s*s),h=new Array(s),y=0;l=Float64Array.from({length:s*s},t?(n,t)=>l[t%s][t/s|0]:(n,t)=>l[t/s|0][t%s]);for(let t=0;t<s;++t){let e=0;for(let r=0;r<s;++r)e+=l[t*s+r]+n*l[r*s+t];y+=g[t]=e}c=(y=i(0,a-e*s)/y)?e:a/s;{let t=0;r&&p.sort((n,t)=>r(g[n],g[t]));for(const e of p){const r=t;if(n){const n=f(1+~s,s).filter(n=>n<0?l[~n*s+e]:l[e*s+n]);u&&n.sort((n,t)=>u(n<0?-l[~n*s+e]:l[e*s+n],t<0?-l[~t*s+e]:l[e*s+t]));for(const r of n)if(r<0){(d[~r*s+e]||(d[~r*s+e]={source:null,target:null})).target={index:e,startAngle:t,endAngle:t+=l[~r*s+e]*y,value:l[~r*s+e]}}else{(d[e*s+r]||(d[e*s+r]={source:null,target:null})).source={index:e,startAngle:t,endAngle:t+=l[e*s+r]*y,value:l[e*s+r]}}h[e]={index:e,startAngle:r,endAngle:t,value:g[e]}}else{const n=f(0,s).filter(n=>l[e*s+n]||l[n*s+e]);u&&n.sort((n,t)=>u(l[e*s+n],l[e*s+t]));for(const r of n){let n;if(e<r?(n=d[e*s+r]||(d[e*s+r]={source:null,target:null})).source={index:e,startAngle:t,endAngle:t+=l[e*s+r]*y,value:l[e*s+r]}:((n=d[r*s+e]||(d[r*s+e]={source:null,target:null})).target={index:e,startAngle:t,endAngle:t+=l[e*s+r]*y,value:l[e*s+r]},e===r&&(n.source=n.target)),n.source&&n.target&&n.source.value<n.target.value){const t=n.source;n.source=n.target,n.target=t}}h[e]={index:e,startAngle:r,endAngle:t,value:g[e]}}t+=c}}return(d=Object.values(d)).groups=h,o?d.sort(o):d}return l.padAngle=function(n){return arguments.length?(e=i(0,n),l):e},l.sortGroups=function(n){return arguments.length?(r=n,l):r},l.sortSubgroups=function(n){return arguments.length?(u=n,l):u},l.sortChords=function(n){return arguments.length?(null==n?o=null:(o=s(n))._=n,l):o&&o._},l}var p=Array.prototype.slice;function d(n){return function(){return n}}function h(n){return n.source}function y(n){return n.target}function v(n){return n.radius}function A(n){return n.startAngle}function x(n){return n.endAngle}function b(){return 0}function T(){return 10}function m(n){var o=h,a=y,i=v,f=v,s=A,g=x,T=b,m=null;function M(){var d,h=o.apply(this,arguments),y=a.apply(this,arguments),v=T.apply(this,arguments)/2,A=p.call(arguments),x=+i.apply(this,(A[0]=h,A)),b=s.apply(this,A)-l,M=g.apply(this,A)-l,q=+f.apply(this,(A[0]=y,A)),w=s.apply(this,A)-l,C=g.apply(this,A)-l;if(m||(m=d=t.path()),v>c&&(e(M-b)>2*v+c?M>b?(b+=v,M-=v):(b-=v,M+=v):b=M=(b+M)/2,e(C-w)>2*v+c?C>w?(w+=v,C-=v):(w-=v,C+=v):w=C=(w+C)/2),m.moveTo(x*r(b),x*u(b)),m.arc(0,0,x,b,M),b!==w||M!==C)if(n){var _=q-+n.apply(this,arguments),j=(w+C)/2;m.quadraticCurveTo(0,0,_*r(w),_*u(w)),m.lineTo(q*r(j),q*u(j)),m.lineTo(_*r(C),_*u(C))}else m.quadraticCurveTo(0,0,q*r(w),q*u(w)),m.arc(0,0,q,w,C);if(m.quadraticCurveTo(0,0,x*r(b),x*u(b)),m.closePath(),d)return m=null,d+""||null}return n&&(M.headRadius=function(t){return arguments.length?(n="function"==typeof t?t:d(+t),M):n}),M.radius=function(n){return arguments.length?(i=f="function"==typeof n?n:d(+n),M):i},M.sourceRadius=function(n){return arguments.length?(i="function"==typeof n?n:d(+n),M):i},M.targetRadius=function(n){return arguments.length?(f="function"==typeof n?n:d(+n),M):f},M.startAngle=function(n){return arguments.length?(s="function"==typeof n?n:d(+n),M):s},M.endAngle=function(n){return arguments.length?(g="function"==typeof n?n:d(+n),M):g},M.padAngle=function(n){return arguments.length?(T="function"==typeof n?n:d(+n),M):T},M.source=function(n){return arguments.length?(o=n,M):o},M.target=function(n){return arguments.length?(a=n,M):a},M.context=function(n){return arguments.length?(m=null==n?null:n,M):m},M}n.chord=function(){return g(!1,!1)},n.chordDirected=function(){return g(!0,!1)},n.chordTranspose=function(){return g(!1,!0)},n.ribbon=function(){return m()},n.ribbonArrow=function(){return m(T)},Object.defineProperty(n,"__esModule",{value:!0})});