From af2bd4348e087ead60fe8d2172dbdb1887df501d Mon Sep 17 00:00:00 2001 From: Rico Sonntag Date: Tue, 2 Apr 2024 14:55:10 +0200 Subject: [PATCH] Fix name mismatch --- resources/js/modules/lib/tree/name.js | 23 ++++---- resources/js/pedigree-chart.min.js | 2 +- src/Processor/NameProcessor.php | 77 ++++++++++++++++++++------- 3 files changed, 73 insertions(+), 29 deletions(-) diff --git a/resources/js/modules/lib/tree/name.js b/resources/js/modules/lib/tree/name.js index cfc5940..7a8dc48 100644 --- a/resources/js/modules/lib/tree/name.js +++ b/resources/js/modules/lib/tree/name.js @@ -152,16 +152,14 @@ export default class Name this.addNameElements( text, (datum) => { - const nameGroups = this.createNamesData(datum); + const [first, ...last] = this.createNamesData(datum); + + // Merge the firstname and lastname groups, as we display the whole name in one line + const combined = [].concat(first, typeof last[0] !== "undefined" ? last[0] : []); return this.truncateNamesData( text, - // Merge the firstname and lastname groups together, - // as we display the whole name in one line - [ - ...nameGroups[0], - ...nameGroups[1], - ], + combined, this.getAvailableWidth(datum) ) } @@ -276,13 +274,16 @@ export default class Name let lastnames = {}; let minPosFirstnames = Number.MAX_SAFE_INTEGER; let minPosLastnames = Number.MAX_SAFE_INTEGER; + let offset = 0; // Iterate over the individual name components and determine their position in the overall // name and insert the component at the corresponding position in the result object. for (let i in datum.data.data.firstNames) { - const pos = datum.data.data.name.indexOf(datum.data.data.firstNames[i]); + const pos = datum.data.data.name.indexOf(datum.data.data.firstNames[i], offset); if (pos !== -1) { + offset = pos; + if (pos < minPosFirstnames) { minPosFirstnames = pos; } @@ -299,9 +300,11 @@ export default class Name names[minPosFirstnames] = Object.values(firstnames); for (let i in datum.data.data.lastNames) { - const pos = datum.data.data.name.indexOf(datum.data.data.lastNames[i]); + const pos = datum.data.data.name.indexOf(datum.data.data.lastNames[i], offset); if (pos !== -1) { + offset = pos; + if (pos < minPosLastnames) { minPosLastnames = pos; } @@ -317,7 +320,7 @@ export default class Name names[minPosLastnames] = Object.values(lastnames); - // Extract the values (keys doesn't matter anymore) + // Extract the values (keys don't matter anymore) return Object.values(names); } diff --git a/resources/js/pedigree-chart.min.js b/resources/js/pedigree-chart.min.js index 50e265e..eed1f72 100644 --- a/resources/js/pedigree-chart.min.js +++ b/resources/js/pedigree-chart.min.js @@ -1 +1 @@ -var t,e;t=this,e=function(t){function e(t){if(!t.ok)throw new Error(t.status+" "+t.statusText);return t.text()}function n(t){var e=0,n=t.children,i=n&&n.length;if(i)for(;--i>=0;)e+=n[i].value;else e=1;t.value=e}function i(t,e){t instanceof Map?(t=[void 0,t],void 0===e&&(e=a)):void 0===e&&(e=r);for(var n,i,o,u,l,c=new h(t),f=[c];n=f.pop();)if((o=e(n.data))&&(l=(o=Array.from(o)).length))for(n.children=o,u=l-1;u>=0;--u)f.push(i=o[u]=new h(o[u])),i.parent=n,i.depth=n.depth+1;return c.eachBefore(s)}function r(t){return t.children}function a(t){return Array.isArray(t)?t[1]:null}function o(t){void 0!==t.data.value&&(t.value=t.data.value),t.data=t.data.data}function s(t){var e=0;do{t.height=e}while((t=t.parent)&&t.height<++e)}function h(t){this.data=t,this.depth=this.height=0,this.parent=null}function u(t,e){return t.parent===e.parent?1:2}function l(t){var e=t.children;return e?e[0]:t.t}function c(t){var e=t.children;return e?e[e.length-1]:t.t}function f(t,e,n){var i=n/(e.i-t.i);e.c-=i,e.s+=n,t.c+=i,e.z+=n,e.m+=n}function d(t,e,n){return t.a.parent===e.parent?t.a:n}function p(t,e){this._=t,this.parent=null,this.children=null,this.A=null,this.a=this,this.z=0,this.m=0,this.c=0,this.s=0,this.t=null,this.i=e}function g(){var t=u,e=1,n=1,i=null;function r(r){var h=function(t){for(var e,n,i,r,a,o=new p(t,0),s=[o];e=s.pop();)if(i=e._.children)for(e.children=new Array(a=i.length),r=a-1;r>=0;--r)s.push(n=e.children[r]=new p(i[r],r)),n.parent=e;return(o.parent=new p(null,0)).children=[o],o}(r);if(h.eachAfter(a),h.parent.m=-h.z,h.eachBefore(o),i)r.eachBefore(s);else{var u=r,l=r,c=r;r.eachBefore((function(t){t.xl.x&&(l=t),t.depth>c.depth&&(c=t)}));var f=u===l?1:t(u,l)/2,d=f-u.x,g=e/(l.x+f+d),_=n/(c.depth||1);r.eachBefore((function(t){t.x=(t.x+d)*g,t.y=t.depth*_}))}return r}function a(e){var n=e.children,i=e.parent.children,r=e.i?i[e.i-1]:null;if(n){!function(t){for(var e,n=0,i=0,r=t.children,a=r.length;--a>=0;)(e=r[a]).z+=n,e.m+=n,n+=e.s+(i+=e.c)}(e);var a=(n[0].z+n[n.length-1].z)/2;r?(e.z=r.z+t(e._,r._),e.m=e.z-a):e.z=a}else r&&(e.z=r.z+t(e._,r._));e.parent.A=function(e,n,i){if(n){for(var r,a=e,o=e,s=n,h=a.parent.children[0],u=a.m,p=o.m,g=s.m,_=h.m;s=c(s),a=l(a),s&&a;)h=l(h),(o=c(o)).a=e,(r=s.z+g-a.z-u+t(s._,a._))>0&&(f(d(s,e,i),e,r),u+=r,p+=r),g+=s.m,u+=a.m,_+=h.m,p+=o.m;s&&!c(o)&&(o.t=s,o.m+=g-p),a&&!l(h)&&(h.t=a,h.m+=u-_,i=e)}return i}(e,r,e.parent.A||i[0])}function o(t){t._.x=t.z+t.parent.m,t.m+=t.parent.m}function s(t){t.x*=e,t.y=t.depth*n}return r.separation=function(e){return arguments.length?(t=e,r):t},r.size=function(t){return arguments.length?(i=!1,e=+t[0],n=+t[1],r):i?null:[e,n]},r.nodeSize=function(t){return arguments.length?(i=!0,e=+t[0],n=+t[1],r):i?[e,n]:null},r}h.prototype=i.prototype={constructor:h,count:function(){return this.eachAfter(n)},each:function(t,e){let n=-1;for(const i of this)t.call(e,i,++n,this);return this},eachAfter:function(t,e){for(var n,i,r,a=this,o=[a],s=[],h=-1;a=o.pop();)if(s.push(a),n=a.children)for(i=0,r=n.length;i=0;--i)a.push(n[i]);return this},find:function(t,e){let n=-1;for(const i of this)if(t.call(e,i,++n,this))return i},sum:function(t){return this.eachAfter((function(e){for(var n=+t(e.data)||0,i=e.children,r=i&&i.length;--r>=0;)n+=i[r].value;e.value=n}))},sort:function(t){return this.eachBefore((function(e){e.children&&e.children.sort(t)}))},path:function(t){for(var e=this,n=function(t,e){if(t===e)return t;var n=t.ancestors(),i=e.ancestors(),r=null;for(t=n.pop(),e=i.pop();t===e;)r=t,t=n.pop(),e=i.pop();return r}(e,t),i=[e];e!==n;)e=e.parent,i.push(e);for(var r=i.length;t!==n;)i.splice(r,0,t),t=t.parent;return i},ancestors:function(){for(var t=this,e=[t];t=t.parent;)e.push(t);return e},descendants:function(){return Array.from(this)},leaves:function(){var t=[];return this.eachBefore((function(e){e.children||t.push(e)})),t},links:function(){var t=this,e=[];return t.each((function(n){n!==t&&e.push({source:n.parent,target:n})})),e},copy:function(){return i(this).eachBefore(o)},[Symbol.iterator]:function*(){var t,e,n,i,r=this,a=[r];do{for(t=a.reverse(),a=[];r=t.pop();)if(yield r,e=r.children)for(n=0,i=e.length;n=0))throw new Error(`invalid digits: ${t}`);if(e>15)return w;const n=10**e;return function(t){this._+=t[0];for(let e=1,i=t.length;ey)if(Math.abs(l*s-h*u)>y&&r){let f=n-a,d=i-o,p=s*s+h*h,g=f*f+d*d,m=Math.sqrt(p),v=Math.sqrt(c),w=r*Math.tan((_-Math.acos((p+c-g)/(2*m*v)))/2),x=w/v,b=w/m;Math.abs(x-1)>y&&this._append`L${t+x*u},${e+x*l}`,this._append`A${r},${r},0,0,${+(l*f>u*d)},${this._x1=t+b*s},${this._y1=e+b*h}`}else this._append`L${this._x1=t},${this._y1=e}`}arc(t,e,n,i,r,a){if(t=+t,e=+e,a=!!a,(n=+n)<0)throw new Error(`negative radius: ${n}`);let o=n*Math.cos(i),s=n*Math.sin(i),h=t+o,u=e+s,l=1^a,c=a?i-r:r-i;null===this._x1?this._append`M${h},${u}`:(Math.abs(this._x1-h)>y||Math.abs(this._y1-u)>y)&&this._append`L${h},${u}`,n&&(c<0&&(c=c%m+m),c>v?this._append`A${n},${n},0,1,${l},${t-o},${e-s}A${n},${n},0,1,${l},${this._x1=h},${this._y1=u}`:c>y&&this._append`A${n},${n},0,${+(c>=_)},${l},${this._x1=t+n*Math.cos(r)},${this._y1=e+n*Math.sin(r)}`)}rect(t,e,n,i){this._append`M${this._x0=this._x1=+t},${this._y0=this._y1=+e}h${n=+n}v${+i}h${-n}Z`}toString(){return this._}}function b(){return new x}function N(t,e,n){t.prototype=e.prototype=n,n.constructor=t}function A(t,e){var n=Object.create(t.prototype);for(var i in e)n[i]=e[i];return n}function k(){}b.prototype=x.prototype;var E=.7,M=1/E,$="\\s*([+-]?\\d+)\\s*",z="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",T="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",R=/^#([0-9a-f]{3,8})$/,S=new RegExp(`^rgb\\(${$},${$},${$}\\)$`),P=new RegExp(`^rgb\\(${T},${T},${T}\\)$`),C=new RegExp(`^rgba\\(${$},${$},${$},${z}\\)$`),D=new RegExp(`^rgba\\(${T},${T},${T},${z}\\)$`),O=new RegExp(`^hsl\\(${z},${T},${T}\\)$`),L=new RegExp(`^hsla\\(${z},${T},${T},${z}\\)$`),I={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};function X(){return this.rgb().formatHex()}function B(){return this.rgb().formatRgb()}function H(t){var e,n;return t=(t+"").trim().toLowerCase(),(e=R.exec(t))?(n=e[1].length,e=parseInt(e[1],16),6===n?W(e):3===n?new j(e>>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e,1):8===n?Y(e>>24&255,e>>16&255,e>>8&255,(255&e)/255):4===n?Y(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|240&e,((15&e)<<4|15&e)/255):null):(e=S.exec(t))?new j(e[1],e[2],e[3],1):(e=P.exec(t))?new j(255*e[1]/100,255*e[2]/100,255*e[3]/100,1):(e=C.exec(t))?Y(e[1],e[2],e[3],e[4]):(e=D.exec(t))?Y(255*e[1]/100,255*e[2]/100,255*e[3]/100,e[4]):(e=O.exec(t))?Q(e[1],e[2]/100,e[3]/100,1):(e=L.exec(t))?Q(e[1],e[2]/100,e[3]/100,e[4]):I.hasOwnProperty(t)?W(I[t]):"transparent"===t?new j(NaN,NaN,NaN,0):null}function W(t){return new j(t>>16&255,t>>8&255,255&t,1)}function Y(t,e,n,i){return i<=0&&(t=e=n=NaN),new j(t,e,n,i)}function q(t,e,n,i){return 1===arguments.length?((r=t)instanceof k||(r=H(r)),r?new j((r=r.rgb()).r,r.g,r.b,r.opacity):new j):new j(t,e,n,null==i?1:i);var r}function j(t,e,n,i){this.r=+t,this.g=+e,this.b=+n,this.opacity=+i}function U(){return`#${K(this.r)}${K(this.g)}${K(this.b)}`}function V(){const t=G(this.opacity);return`${1===t?"rgb(":"rgba("}${F(this.r)}, ${F(this.g)}, ${F(this.b)}${1===t?")":`, ${t})`}`}function G(t){return isNaN(t)?1:Math.max(0,Math.min(1,t))}function F(t){return Math.max(0,Math.min(255,Math.round(t)||0))}function K(t){return((t=F(t))<16?"0":"")+t.toString(16)}function Q(t,e,n,i){return i<=0?t=e=n=NaN:n<=0||n>=1?t=e=NaN:e<=0&&(t=NaN),new J(t,e,n,i)}function Z(t){if(t instanceof J)return new J(t.h,t.s,t.l,t.opacity);if(t instanceof k||(t=H(t)),!t)return new J;if(t instanceof J)return t;var e=(t=t.rgb()).r/255,n=t.g/255,i=t.b/255,r=Math.min(e,n,i),a=Math.max(e,n,i),o=NaN,s=a-r,h=(a+r)/2;return s?(o=e===a?(n-i)/s+6*(n0&&h<1?0:o,new J(o,s,h,t.opacity)}function J(t,e,n,i){this.h=+t,this.s=+e,this.l=+n,this.opacity=+i}function tt(t){return(t=(t||0)%360)<0?t+360:t}function et(t){return Math.max(0,Math.min(1,t||0))}function nt(t,e,n){return 255*(t<60?e+(n-e)*t/60:t<180?n:t<240?e+(n-e)*(240-t)/60:e)}N(k,H,{copy(t){return Object.assign(new this.constructor,this,t)},displayable(){return this.rgb().displayable()},hex:X,formatHex:X,formatHex8:function(){return this.rgb().formatHex8()},formatHsl:function(){return Z(this).formatHsl()},formatRgb:B,toString:B}),N(j,q,A(k,{brighter(t){return t=null==t?M:Math.pow(M,t),new j(this.r*t,this.g*t,this.b*t,this.opacity)},darker(t){return t=null==t?E:Math.pow(E,t),new j(this.r*t,this.g*t,this.b*t,this.opacity)},rgb(){return this},clamp(){return new j(F(this.r),F(this.g),F(this.b),G(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:U,formatHex:U,formatHex8:function(){return`#${K(this.r)}${K(this.g)}${K(this.b)}${K(255*(isNaN(this.opacity)?1:this.opacity))}`},formatRgb:V,toString:V})),N(J,(function(t,e,n,i){return 1===arguments.length?Z(t):new J(t,e,n,null==i?1:i)}),A(k,{brighter(t){return t=null==t?M:Math.pow(M,t),new J(this.h,this.s,this.l*t,this.opacity)},darker(t){return t=null==t?E:Math.pow(E,t),new J(this.h,this.s,this.l*t,this.opacity)},rgb(){var t=this.h%360+360*(this.h<0),e=isNaN(t)||isNaN(this.s)?0:this.s,n=this.l,i=n+(n<.5?n:1-n)*e,r=2*n-i;return new j(nt(t>=240?t-240:t+120,r,i),nt(t,r,i),nt(t<120?t+240:t-120,r,i),this.opacity)},clamp(){return new J(tt(this.h),et(this.s),et(this.l),G(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const t=G(this.opacity);return`${1===t?"hsl(":"hsla("}${tt(this.h)}, ${100*et(this.s)}%, ${100*et(this.l)}%${1===t?")":`, ${t})`}`}}));var it=t=>()=>t;function rt(t){return 1==(t=+t)?at:function(e,n){return n-e?function(t,e,n){return t=Math.pow(t,n),e=Math.pow(e,n)-t,n=1/n,function(i){return Math.pow(t+i*e,n)}}(e,n,t):it(isNaN(e)?n:e)}}function at(t,e){var n=e-t;return n?function(t,e){return function(n){return t+n*e}}(t,n):it(isNaN(t)?e:t)}var ot=function t(e){var n=rt(e);function i(t,e){var i=n((t=q(t)).r,(e=q(e)).r),r=n(t.g,e.g),a=n(t.b,e.b),o=at(t.opacity,e.opacity);return function(e){return t.r=i(e),t.g=r(e),t.b=a(e),t.opacity=o(e),t+""}}return i.gamma=t,i}(1);function st(t,e){return t=+t,e=+e,function(n){return t*(1-n)+e*n}}var ht=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,ut=new RegExp(ht.source,"g");function lt(t,e){var n,i,r,a=ht.lastIndex=ut.lastIndex=0,o=-1,s=[],h=[];for(t+="",e+="";(n=ht.exec(t))&&(i=ut.exec(e));)(r=i.index)>a&&(r=e.slice(a,r),s[o]?s[o]+=r:s[++o]=r),(n=n[0])===(i=i[0])?s[o]?s[o]+=i:s[++o]=i:(s[++o]=null,h.push({i:o,x:st(n,i)})),a=ut.lastIndex;return a180?e+=360:e-t>180&&(t+=360),a.push({i:n.push(r(n)+"rotate(",null,i)-2,x:st(t,e)})):e&&n.push(r(n)+"rotate("+e+i)}(a.rotate,o.rotate,s,h),function(t,e,n,a){t!==e?a.push({i:n.push(r(n)+"skewX(",null,i)-2,x:st(t,e)}):e&&n.push(r(n)+"skewX("+e+i)}(a.skewX,o.skewX,s,h),function(t,e,n,i,a,o){if(t!==n||e!==i){var s=a.push(r(a)+"scale(",null,",",null,")");o.push({i:s-4,x:st(t,n)},{i:s-2,x:st(e,i)})}else 1===n&&1===i||a.push(r(a)+"scale("+n+","+i+")")}(a.scaleX,a.scaleY,o.scaleX,o.scaleY,s,h),a=o=null,function(t){for(var e,n=-1,i=h.length;++n=0&&"xmlns"!==(e=t.slice(0,n))&&(t=t.slice(n+1)),xt.hasOwnProperty(e)?{space:xt[e],local:t}:t}function Nt(t){return function(){var e=this.ownerDocument,n=this.namespaceURI;return n===wt&&e.documentElement.namespaceURI===wt?e.createElement(t):e.createElementNS(n,t)}}function At(t){return function(){return this.ownerDocument.createElementNS(t.space,t.local)}}function kt(t){var e=bt(t);return(e.local?At:Nt)(e)}function Et(){}function Mt(t){return null==t?Et:function(){return this.querySelector(t)}}function $t(t){return null==t?[]:Array.isArray(t)?t:Array.from(t)}function zt(){return[]}function Tt(t){return null==t?zt:function(){return this.querySelectorAll(t)}}function Rt(t){return function(){return this.matches(t)}}function St(t){return function(e){return e.matches(t)}}var Pt=Array.prototype.find;function Ct(){return this.firstElementChild}var Dt=Array.prototype.filter;function Ot(){return Array.from(this.children)}function Lt(t){return new Array(t.length)}function It(t,e){this.ownerDocument=t.ownerDocument,this.namespaceURI=t.namespaceURI,this._next=null,this._parent=t,this.__data__=e}function Xt(t,e,n,i,r,a){for(var o,s=0,h=e.length,u=a.length;se?1:t>=e?0:NaN}function qt(t){return function(){this.removeAttribute(t)}}function jt(t){return function(){this.removeAttributeNS(t.space,t.local)}}function Ut(t,e){return function(){this.setAttribute(t,e)}}function Vt(t,e){return function(){this.setAttributeNS(t.space,t.local,e)}}function Gt(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttribute(t):this.setAttribute(t,n)}}function Ft(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttributeNS(t.space,t.local):this.setAttributeNS(t.space,t.local,n)}}function Kt(t){return t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView}function Qt(t){return function(){this.style.removeProperty(t)}}function Zt(t,e,n){return function(){this.style.setProperty(t,e,n)}}function Jt(t,e,n){return function(){var i=e.apply(this,arguments);null==i?this.style.removeProperty(t):this.style.setProperty(t,i,n)}}function te(t,e){return t.style.getPropertyValue(e)||Kt(t).getComputedStyle(t,null).getPropertyValue(e)}function ee(t){return function(){delete this[t]}}function ne(t,e){return function(){this[t]=e}}function ie(t,e){return function(){var n=e.apply(this,arguments);null==n?delete this[t]:this[t]=n}}function re(t){return t.trim().split(/^|\s+/)}function ae(t){return t.classList||new oe(t)}function oe(t){this._node=t,this._names=re(t.getAttribute("class")||"")}function se(t,e){for(var n=ae(t),i=-1,r=e.length;++i=0&&(this._names.splice(e,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(t){return this._names.indexOf(t)>=0}};var ze=[null];function Te(t,e){this._groups=t,this._parents=e}function Re(){return new Te([[document.documentElement]],ze)}function Se(t){return"string"==typeof t?new Te([[document.querySelector(t)]],[document.documentElement]):new Te([[t]],ze)}function Pe(t,e){if(t=function(t){let e;for(;e=t.sourceEvent;)t=e;return t}(t),void 0===e&&(e=t.currentTarget),e){var n=e.ownerSVGElement||e;if(n.createSVGPoint){var i=n.createSVGPoint();return i.x=t.clientX,i.y=t.clientY,[(i=i.matrixTransform(e.getScreenCTM().inverse())).x,i.y]}if(e.getBoundingClientRect){var r=e.getBoundingClientRect();return[t.clientX-r.left-e.clientLeft,t.clientY-r.top-e.clientTop]}}return[t.pageX,t.pageY]}Te.prototype=Re.prototype={constructor:Te,select:function(t){"function"!=typeof t&&(t=Mt(t));for(var e=this._groups,n=e.length,i=new Array(n),r=0;r=x&&(x=w+1);!(v=m[x])&&++x=0;)(i=r[a])&&(o&&4^i.compareDocumentPosition(o)&&o.parentNode.insertBefore(i,o),o=i);return this},sort:function(t){function e(e,n){return e&&n?t(e.__data__,n.__data__):!e-!n}t||(t=Yt);for(var n=this._groups,i=n.length,r=new Array(i),a=0;a1?this.each((null==e?Qt:"function"==typeof e?Jt:Zt)(t,e,null==n?"":n)):te(this.node(),t)},property:function(t,e){return arguments.length>1?this.each((null==e?ee:"function"==typeof e?ie:ne)(t,e)):this.node()[t]},classed:function(t,e){var n=re(t+"");if(arguments.length<2){for(var i=ae(this.node()),r=-1,a=n.length;++r=0&&(e=t.slice(n+1),t=t.slice(0,n)),{type:t,name:e}}))}(t+""),o=a.length;if(!(arguments.length<2)){for(s=e?ke:Ae,i=0;i=0&&e._call.call(void 0,t),e=e._next;--Oe}()}finally{Oe=0,function(){for(var t,e,n=Ce,i=1/0;n;)n._call?(i>n._time&&(i=n._time),t=n,n=n._next):(e=n._next,n._next=null,n=t?t._next=e:Ce=e);De=t,Qe(i)}(),He=0}}function Ke(){var t=Ye.now(),e=t-Be;e>Xe&&(We-=e,Be=t)}function Qe(t){Oe||(Le&&(Le=clearTimeout(Le)),t-He>24?(t<1/0&&(Le=setTimeout(Fe,t-Ye.now()-We)),Ie&&(Ie=clearInterval(Ie))):(Ie||(Be=Ye.now(),Ie=setInterval(Ke,Xe)),Oe=1,qe(Fe)))}function Ze(t,e,n){var i=new Ve;return e=null==e?0:+e,i.restart((n=>{i.stop(),t(n+e)}),e,n),i}Ve.prototype=Ge.prototype={constructor:Ve,restart:function(t,e,n){if("function"!=typeof t)throw new TypeError("callback is not a function");n=(null==n?je():+n)+(null==e?0:+e),this._next||De===this||(De?De._next=this:Ce=this,De=this),this._call=t,this._time=n,Qe()},stop:function(){this._call&&(this._call=null,this._time=1/0,Qe())}};var Je={value:()=>{}};function tn(){for(var t,e=0,n=arguments.length,i={};e=0&&(e=t.slice(n+1),t=t.slice(0,n)),t&&!i.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:e}}))),o=-1,s=a.length;if(!(arguments.length<2)){if(null!=e&&"function"!=typeof e)throw new Error("invalid callback: "+e);for(;++o0)for(var n,i,r=new Array(n),a=0;asn)throw new Error("too late; already scheduled");return n}function _n(t,e){var n=mn(t,e);if(n.state>ln)throw new Error("too late; already running");return n}function mn(t,e){var n=t.__transition;if(!n||!(n=n[e]))throw new Error("transition not found");return n}function yn(t,e){var n,i,r,a=t.__transition,o=!0;if(a){for(r in e=null==e?null:e+"",a)(n=a[r]).name===e?(i=n.state>un&&n.state=0&&(t=t.slice(0,e)),!t||"start"===t}))}(e)?gn:_n;return function(){var o=a(this,t),s=o.on;s!==i&&(r=(i=s).copy()).on(e,n),o.on=r}}(n,t,e))},attr:function(t,e){var n=bt(t),i="transform"===n?mt:bn;return this.attrTween(t,"function"==typeof e?(n.local?$n:Mn)(n,i,xn(this,"attr."+t,e)):null==e?(n.local?An:Nn)(n):(n.local?En:kn)(n,i,e))},attrTween:function(t,e){var n="attr."+t;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(null==e)return this.tween(n,null);if("function"!=typeof e)throw new Error;var i=bt(t);return this.tween(n,(i.local?zn:Tn)(i,e))},style:function(t,e,n){var i="transform"==(t+="")?_t:bn;return null==e?this.styleTween(t,function(t,e){var n,i,r;return function(){var a=te(this,t),o=(this.style.removeProperty(t),te(this,t));return a===o?null:a===n&&o===i?r:r=e(n=a,i=o)}}(t,i)).on("end.style."+t,On(t)):"function"==typeof e?this.styleTween(t,function(t,e,n){var i,r,a;return function(){var o=te(this,t),s=n(this),h=s+"";return null==s&&(this.style.removeProperty(t),h=s=te(this,t)),o===h?null:o===i&&h===r?a:(r=h,a=e(i=o,s))}}(t,i,xn(this,"style."+t,e))).each(function(t,e){var n,i,r,a,o="style."+e,s="end."+o;return function(){var h=_n(this,t),u=h.on,l=null==h.value[o]?a||(a=On(e)):void 0;u===n&&r===l||(i=(n=u).copy()).on(s,r=l),h.on=i}}(this._id,t)):this.styleTween(t,function(t,e,n){var i,r,a=n+"";return function(){var o=te(this,t);return o===a?null:o===i?r:r=e(i=o,n)}}(t,i,e),n).on("end.style."+t,null)},styleTween:function(t,e,n){var i="style."+(t+="");if(arguments.length<2)return(i=this.tween(i))&&i._value;if(null==e)return this.tween(i,null);if("function"!=typeof e)throw new Error;return this.tween(i,function(t,e,n){var i,r;function a(){var a=e.apply(this,arguments);return a!==r&&(i=(r=a)&&function(t,e,n){return function(i){this.style.setProperty(t,e.call(this,i),n)}}(t,a,n)),i}return a._value=e,a}(t,e,null==n?"":n))},text:function(t){return this.tween("text","function"==typeof t?function(t){return function(){var e=t(this);this.textContent=null==e?"":e}}(xn(this,"text",t)):function(t){return function(){this.textContent=t}}(null==t?"":t+""))},textTween:function(t){var e="text";if(arguments.length<1)return(e=this.tween(e))&&e._value;if(null==t)return this.tween(e,null);if("function"!=typeof t)throw new Error;return this.tween(e,function(t){var e,n;function i(){var i=t.apply(this,arguments);return i!==n&&(e=(n=i)&&function(t){return function(e){this.textContent=t.call(this,e)}}(i)),e}return i._value=t,i}(t))},remove:function(){return this.on("end.remove",function(t){return function(){var e=this.parentNode;for(var n in this.__transition)if(+n!==t)return;e&&e.removeChild(this)}}(this._id))},tween:function(t,e){var n=this._id;if(t+="",arguments.length<2){for(var i,r=mn(this.node(),n).tween,a=0,o=r.length;a()=>t;function Un(t,{sourceEvent:e,target:n,transform:i,dispatch:r}){Object.defineProperties(this,{type:{value:t,enumerable:!0,configurable:!0},sourceEvent:{value:e,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:i,enumerable:!0,configurable:!0},_:{value:r}})}function Vn(t,e,n){this.k=t,this.x=e,this.y=n}Vn.prototype={constructor:Vn,scale:function(t){return 1===t?this:new Vn(this.k*t,this.x,this.y)},translate:function(t,e){return 0===t&0===e?this:new Vn(this.k,this.x+this.k*t,this.y+this.k*e)},apply:function(t){return[t[0]*this.k+this.x,t[1]*this.k+this.y]},applyX:function(t){return t*this.k+this.x},applyY:function(t){return t*this.k+this.y},invert:function(t){return[(t[0]-this.x)/this.k,(t[1]-this.y)/this.k]},invertX:function(t){return(t-this.x)/this.k},invertY:function(t){return(t-this.y)/this.k},rescaleX:function(t){return t.copy().domain(t.range().map(this.invertX,this).map(t.invert,t))},rescaleY:function(t){return t.copy().domain(t.range().map(this.invertY,this).map(t.invert,t))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var Gn=new Vn(1,0,0);function Fn(t){for(;!t.__zoom;)if(!(t=t.parentNode))return Gn;return t.__zoom}function Kn(t){t.stopImmediatePropagation()}function Qn(t){t.preventDefault(),t.stopImmediatePropagation()}function Zn(t){return!(t.ctrlKey&&"wheel"!==t.type||t.button)}function Jn(){var t=this;return t instanceof SVGElement?(t=t.ownerSVGElement||t).hasAttribute("viewBox")?[[(t=t.viewBox.baseVal).x,t.y],[t.x+t.width,t.y+t.height]]:[[0,0],[t.width.baseVal.value,t.height.baseVal.value]]:[[0,0],[t.clientWidth,t.clientHeight]]}function ti(){return this.__zoom||Gn}function ei(t){return-t.deltaY*(1===t.deltaMode?.05:t.deltaMode?1:.002)*(t.ctrlKey?10:1)}function ni(){return navigator.maxTouchPoints||"ontouchstart"in this}function ii(t,e,n){var i=t.invertX(e[0][0])-n[0][0],r=t.invertX(e[1][0])-n[1][0],a=t.invertY(e[0][1])-n[0][1],o=t.invertY(e[1][1])-n[1][1];return t.translate(r>i?(i+r)/2:Math.min(0,i)||Math.max(0,r),o>a?(a+o)/2:Math.min(0,a)||Math.max(0,o))}function ri(){var t,e,n,i=Zn,r=Jn,a=ii,o=ei,s=ni,h=[0,1/0],u=[[-1/0,-1/0],[1/0,1/0]],l=250,c=vt,f=tn("start","zoom","end"),d=500,p=150,g=0,_=10;function m(t){t.property("__zoom",ti).on("wheel.zoom",A,{passive:!1}).on("mousedown.zoom",k).on("dblclick.zoom",E).filter(s).on("touchstart.zoom",M).on("touchmove.zoom",$).on("touchend.zoom touchcancel.zoom",z).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function y(t,e){return(e=Math.max(h[0],Math.min(h[1],e)))===t.k?t:new Vn(e,t.x,t.y)}function v(t,e,n){var i=e[0]-n[0]*t.k,r=e[1]-n[1]*t.k;return i===t.x&&r===t.y?t:new Vn(t.k,i,r)}function w(t){return[(+t[0][0]+ +t[1][0])/2,(+t[0][1]+ +t[1][1])/2]}function x(t,e,n,i){t.on("start.zoom",(function(){b(this,arguments).event(i).start()})).on("interrupt.zoom end.zoom",(function(){b(this,arguments).event(i).end()})).tween("zoom",(function(){var t=this,a=arguments,o=b(t,a).event(i),s=r.apply(t,a),h=null==n?w(s):"function"==typeof n?n.apply(t,a):n,u=Math.max(s[1][0]-s[0][0],s[1][1]-s[0][1]),l=t.__zoom,f="function"==typeof e?e.apply(t,a):e,d=c(l.invert(h).concat(u/l.k),f.invert(h).concat(u/f.k));return function(t){if(1===t)t=f;else{var e=d(t),n=u/e[2];t=new Vn(n,h[0]-e[0]*n,h[1]-e[1]*n)}o.zoom(null,t)}}))}function b(t,e,n){return!n&&t.__zooming||new N(t,e)}function N(t,e){this.that=t,this.args=e,this.active=0,this.sourceEvent=null,this.extent=r.apply(t,e),this.taps=0}function A(t,...e){if(i.apply(this,arguments)){var n=b(this,e).event(t),r=this.__zoom,s=Math.max(h[0],Math.min(h[1],r.k*Math.pow(2,o.apply(this,arguments)))),l=Pe(t);if(n.wheel)n.mouse[0][0]===l[0]&&n.mouse[0][1]===l[1]||(n.mouse[1]=r.invert(n.mouse[0]=l)),clearTimeout(n.wheel);else{if(r.k===s)return;n.mouse=[l,r.invert(l)],yn(this),n.start()}Qn(t),n.wheel=setTimeout((function(){n.wheel=null,n.end()}),p),n.zoom("mouse",a(v(y(r,s),n.mouse[0],n.mouse[1]),n.extent,u))}}function k(t,...e){if(!n&&i.apply(this,arguments)){var r=t.currentTarget,o=b(this,e,!0).event(t),s=Se(t.view).on("mousemove.zoom",(function(t){if(Qn(t),!o.moved){var e=t.clientX-l,n=t.clientY-c;o.moved=e*e+n*n>g}o.event(t).zoom("mouse",a(v(o.that.__zoom,o.mouse[0]=Pe(t,r),o.mouse[1]),o.extent,u))}),!0).on("mouseup.zoom",(function(t){s.on("mousemove.zoom mouseup.zoom",null),function(t,e){var n=t.document.documentElement,i=Se(t).on("dragstart.drag",null);e&&(i.on("click.drag",qn,Yn),setTimeout((function(){i.on("click.drag",null)}),0)),"onselectstart"in n?i.on("selectstart.drag",null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}(t.view,o.moved),Qn(t),o.event(t).end()}),!0),h=Pe(t,r),l=t.clientX,c=t.clientY;!function(t){var e=t.document.documentElement,n=Se(t).on("dragstart.drag",qn,Yn);"onselectstart"in e?n.on("selectstart.drag",qn,Yn):(e.__noselect=e.style.MozUserSelect,e.style.MozUserSelect="none")}(t.view),Kn(t),o.mouse=[h,this.__zoom.invert(h)],yn(this),o.start()}}function E(t,...e){if(i.apply(this,arguments)){var n=this.__zoom,o=Pe(t.changedTouches?t.changedTouches[0]:t,this),s=n.invert(o),h=n.k*(t.shiftKey?.5:2),c=a(v(y(n,h),o,s),r.apply(this,e),u);Qn(t),l>0?Se(this).transition().duration(l).call(x,c,o,t):Se(this).call(m.transform,c,o,t)}}function M(n,...r){if(i.apply(this,arguments)){var a,o,s,h,u=n.touches,l=u.length,c=b(this,r,n.changedTouches.length===l).event(n);for(Kn(n),o=0;o=0&&(a-=ui(t,e)),null===t.coords&&(n.moveTo(t.spouse.x+r,a),n.lineTo(t.source.x-r,a)),t.coords&&t.coords.length>0){for(let e=0;e0&&(o=t.coords[e-1].x+r);let h=e>0?i:0,u=e+1<=t.coords.length?i:0;n.moveTo(o+h,a),n.lineTo(s-u,a)}n.moveTo(t.coords[t.coords.length-1].x+r+i,a),n.lineTo(t.source.x-r,a)}return n.toString()}(t,e)}function ui(t,e){return(t.source.data.family-Math.ceil(t.spouse.data.spouses.length/2))*e.direction*5}class li extends si{constructor(t,e){super(t,e),this._splittNames=!0}get direction(){return 1}get nodeWidth(){return this._boxWidth+this._xOffset}get nodeHeight(){return this._boxHeight+this._yOffset}norm(t){t.y*=this.direction}elbow(t){return hi(t,this)}}class ci extends si{constructor(t,e){super(t,e),this._splittNames=!0}get direction(){return-1}get nodeWidth(){return this._boxWidth+this._xOffset}get nodeHeight(){return this._boxHeight+this._yOffset}norm(t){t.y*=this.direction}elbow(t){return hi(t,this)}}function fi(t,e){const n=e.xOffset/2,i=e.yOffset/2;let r=t.source.x,a=t.source.y;if(void 0!==t.spouse&&0===t.source.data.family?(r-=di(t,e),a-=(t.source.y-t.spouse.y)/2):r+=e.boxWidth/2*e.direction,null===t.source.data.data&&(r+=e.boxWidth/2*e.direction,a-=e.boxHeight/2+i/2),null!==t.target){let i=t.target.x-e.direction*(e.boxWidth/2+n),o=t.target.y;const s=b();return s.moveTo(r,a),s.lineTo(i,a),s.lineTo(i,o),s.lineTo(i+e.direction*n,o),s.toString()}return function(t,e){const n=b(),i=2,r=e.boxHeight/2;let a=t.source.x;if(t.spouse.data.spouses.length>=0&&(a-=di(t,e)),null===t.coords&&(n.moveTo(a,t.spouse.y+r),n.lineTo(a,t.source.y-r)),t.coords&&t.coords.length>0){for(let e=0;e0&&(o=t.coords[e-1].y+r);let h=e>0?i:0,u=e+1<=t.coords.length?i:0;n.moveTo(a,o+h),n.lineTo(a,s-u)}n.moveTo(a,t.coords[t.coords.length-1].y+r+i),n.lineTo(a,t.source.y-r)}return n.toString()}(t,e)}function di(t,e){return(t.source.data.family-Math.ceil(t.spouse.data.spouses.length/2))*e.direction*5}class pi extends si{constructor(t,e){super(t,e),this._xOffset=40,this._yOffset=20}get direction(){return this.isDocumentRtl?-1:1}get nodeWidth(){return this._boxHeight+this._yOffset}get nodeHeight(){return this._boxWidth+this._xOffset}norm(t){[t.x,t.y]=[t.y*this.direction,t.x]}elbow(t){return fi(t,this)}}class gi extends si{constructor(t,e){super(t,e),this._xOffset=40,this._yOffset=20}get direction(){return this.isDocumentRtl?1:-1}get nodeWidth(){return this._boxHeight+this._yOffset}get nodeHeight(){return this._boxWidth+this._xOffset}norm(t){[t.x,t.y]=[t.y*this.direction,t.x]}elbow(t){return fi(t,this)}}class _i{constructor(){this._orientations={down:new li(160,175),up:new ci(160,175),[ai]:new pi(325,95),left:new gi(325,95)}}get(){return this._orientations}}class mi{constructor(t,e=4,n=!1,i=ai,r=!0,a=!0,o=!1,s=1){this._treeLayout=i,this._orientations=new _i,this._showEmptyBoxes=n,this._openNewTabOnClick=r,this._showAlternativeName=a,this.duration=750,this.padding=15,this._generations=e,this.textPadding=8,this._fontSize=14,this.fontColor="rgb(0, 0, 0)",this.rtl=o,this.labels=t,this.direction=s}get generations(){return this._generations}set generations(t){this._generations=t}get showEmptyBoxes(){return this._showEmptyBoxes}get treeLayout(){return this._treeLayout}set treeLayout(t){this._treeLayout=t}get orientation(){return this._orientations.get()[this.treeLayout]}get openNewTabOnClick(){return this._openNewTabOnClick}get showAlternativeName(){return this._showAlternativeName}}class yi{constructor(t){this._configuration=t,this._nodes=null,this._root=null}init(t){this._configuration.showAlternativeName&&(this._configuration.orientation instanceof li||this._configuration.orientation instanceof ci)&&(this._configuration.orientation.boxHeight+=30);const e=({parents:t})=>1+(t?Math.max(...t.map(e)):0),n=e(t);this._root=i(t,(t=>this._configuration.showEmptyBoxes?(!t.parents&&t.data.generation{t.id=e}));const r=g().nodeSize([this._configuration.orientation.nodeWidth,this._configuration.orientation.nodeHeight]).separation((()=>1));this._nodes=r(this._root),this._root.each((t=>{this._configuration.orientation.norm(t)}))}get nodes(){return this._nodes}get root(){return this._root}createEmptyNode(t,e){return{data:{id:0,xref:"",url:"",updateUrl:"",generation:t,name:"",isNameRtl:!1,firstNames:[],lastNames:[],preferredName:"",alternativeName:"",isAltRtl:!1,sex:"U",timespan:""}}}}class vi{constructor(t){this._element=t.append("defs")}get(){return this._element}}class wi{constructor(t){this._zoom=null,this._parent=t,this.init()}init(){this._zoom=ri(),this._zoom.scaleExtent([.1,20]).on("zoom",(t=>{this._parent.attr("transform",t.transform)})),this._zoom.wheelDelta((t=>-t.deltaY*(1===t.deltaMode?.05:t.deltaMode?1:.002))),this._zoom.filter((t=>{if("wheel"===t.type){if(!t.ctrlKey)return!1;const e=Fn(this);if(e.k){if(e.k<=.1&&t.deltaY>0)return t.preventDefault(),!1;if(e.k>=20&&t.deltaY<0)return t.preventDefault(),!1}return!0}return t.button||"touchstart"!==t.type?!(t.ctrlKey&&"wheel"!==t.type||t.button):2===t.touches.length}))}get(){return this._zoom}}class xi{triggerDownload(t,e){let n=new MouseEvent("click",{view:window,bubbles:!1,cancelable:!0}),i=document.createElement("a");i.setAttribute("download",e),i.setAttribute("href",t),i.setAttribute("target","_blank"),i.dispatchEvent(n)}}class bi extends xi{copyStylesInline(t,e){let n=["svg","g","text","textPath"];for(let i=0;i{let r=(new XMLSerializer).serializeToString(t),a=window.URL||window.webkitURL||window,o=new Blob([r],{type:"image/svg+xml;charset=utf-8"}),s=a.createObjectURL(o),h=new Image;h.onload=()=>{let t=this.createCanvas(e,n),r=t.getContext("2d");r.fillStyle="rgb(255,255,255)",r.fillRect(0,0,t.width,t.height),r.drawImage(h,0,0),a.revokeObjectURL(s);let o=t.toDataURL("image/png").replace("image/png","image/octet-stream");i(o)},h.src=s}))}cloneSvg(t){return new Promise((e=>{e(t.cloneNode(!0))}))}svgToImage(t,e){const n=[4960,3508];this.cloneSvg(t.get().node()).then((e=>{this.copyStylesInline(t.get().node(),e);const i=this.calculateViewBox(t.get().node()),r=Math.max(n[0],i[2]),a=Math.max(n[1],i[3]);return e.setAttribute("width",""+r),e.setAttribute("height",""+a),e.setAttribute("viewBox",""+i),this.convertToDataUrl(e,r,a)})).then((t=>this.triggerDownload(t,e))).catch((()=>{console.log("Failed to save chart as PNG image")}))}}class Ni extends xi{copyStylesInline(t,n,i){return new Promise((r=>{Promise.all(t.map((t=>function(t,n){return fetch(t,n).then(e)}(t)))).then((t=>{t.forEach((t=>{t=t.replace(new RegExp("."+i+" ","g"),"");let e=document.createElementNS("http://www.w3.org/2000/svg","style");e.appendChild(document.createTextNode(t)),n.prepend(e)})),n.classList.add("wt-global"),r(n)}))}))}convertToObjectUrl(t){return new Promise((e=>{let n=(new XMLSerializer).serializeToString(t),i=window.URL||window.webkitURL||window,r=new Blob([n],{type:"image/svg+xml;charset=utf-8"}),a=i.createObjectURL(r),o=new Image;o.onload=()=>{e(a)},o.src=a}))}cloneSvg(t){return new Promise((e=>{e(t.cloneNode(!0))}))}svgToImage(t,e,n,i){this.cloneSvg(t.get().node()).then((t=>this.copyStylesInline(e,t,n))).then((t=>this.convertToObjectUrl(t))).then((t=>this.triggerDownload(t,i))).catch((()=>{console.log("Failed to save chart as SVG image")}))}}class Ai{constructor(){this._exportClass=null}setExportClass(t){switch(t){case"png":this._exportClass=bi;break;case"svg":this._exportClass=Ni}}createExport(t){switch(this.setExportClass(t),t){case"png":case"svg":return new this._exportClass}}}class ki{constructor(t,e){this._element=t.append("svg"),this._defs=new vi(this._element),this._visual=null,this._zoom=null,this._configuration=e,this.init()}init(){this._element.attr("width","100%").attr("height","100%").attr("text-rendering","optimizeLegibility").attr("text-anchor","middle").attr("xmlns:xlink","https://www.w3.org/1999/xlink")}initEvents(t){this._element.on("contextmenu",(t=>t.preventDefault())).on("wheel",(e=>{e.ctrlKey||t.show(this._configuration.labels.zoom,300,(()=>{t.hide(200,600)}))})).on("touchend",(e=>{e.touches.length<2&&t.hide(0,600)})).on("touchmove",(e=>{e.touches.length>=2?t.hide():t.show(this._configuration.labels.move)})).on("click",(t=>this.doStopPropagation(t)),!0),this._configuration.rtl&&this._element.classed("rtl",!0),this._visual=this._element.append("g"),this._zoom=new wi(this._visual),this._element.call(this._zoom.get())}doStopPropagation(t){t.defaultPrevented&&t.stopPropagation()}export(t){return(new Ai).createExport(t)}get defs(){return this._defs}get zoom(){return this._zoom}get visual(){return this._visual}get(){return this._element}}class Ei{constructor(t){this._element=t.append("div").attr("class","overlay").style("opacity",1e-6)}show(t,e=0,n=null){this._element.select("p").remove(),this._element.append("p").attr("class","tooltip").text(t),this._element.transition().duration(e).style("opacity",1).on("end",(()=>{"function"==typeof n&&n()}))}hide(t=0,e=0){this._element.transition().delay(t).duration(e).style("opacity",1e-6)}get(){return this._element}}let Mi=null;function $i(t,e,n,i=400){null===Mi&&(Mi=document.createElement("canvas"));const r=Mi.getContext("2d"),a=`${i||""} ${n} ${e}`;return r.font!==a&&(r.font=a),r.measureText(t).width}class zi{constructor(t,e,n,i){this._svg=t,this._orientation=e,this._image=n,this._text=i}appendName(t){const e=t.append("g").attr("class","name");if(this._orientation instanceof li||this._orientation instanceof ci){const t=this,n=e.selectAll("text").data((t=>[{data:t.data,isRtl:t.data.data.isNameRtl,isAltRtl:t.data.data.isAltRtl,withImage:!0}])).enter();n.each((function(e){const n=Se(this),i=t.createNamesData(e),r=t.getAvailableWidth(e);i.forEach(((e,i)=>{const a=n.append("text").attr("class","wt-chart-box-name").attr("direction",(t=>t.isRtl?"rtl":"ltr")).attr("text-anchor","middle").attr("alignment-baseline","central").attr("y",t._text.y-5+20*i);t.addNameElements(a,t.truncateNamesData(a,e,r))}))})),this._svg._configuration.showAlternativeName&&n.filter((t=>""!==t.data.data.alternativeName)).call((t=>{const e=t.append("text").classed("wt-chart-box-name-alt",!0).attr("class","wt-chart-box-name").attr("direction",(t=>t.isAltRtl?"rtl":"ltr")).attr("text-anchor","middle").attr("alignment-baseline","central").attr("y",this._text.y+40);this.addNameElements(e,(t=>this.truncateNamesData(e,this.createAlternativeNamesData(t),this.getAvailableWidth(t))))}))}else{const t=e.selectAll("text").data((t=>[{data:t.data,isRtl:t.data.data.isNameRtl,isAltRtl:t.data.data.isAltRtl,withImage:""!==t.data.data.thumbnail}])).enter();t.call((t=>{const e=t.append("text").attr("class","wt-chart-box-name").attr("direction",(t=>t.isRtl?"rtl":"ltr")).attr("text-anchor",(t=>t.isRtl&&this._orientation.isDocumentRtl?"start":t.isRtl||this._orientation.isDocumentRtl?"end":"start")).attr("x",(t=>this.textX(t))).attr("y",this._text.y-10);this.addNameElements(e,(t=>{const n=this.createNamesData(t);return this.truncateNamesData(e,[...n[0],...n[1]],this.getAvailableWidth(t))}))})),this._svg._configuration.showAlternativeName&&t.filter((t=>""!==t.data.data.alternativeName)).call((t=>{const e=t.append("text").classed("wt-chart-box-name-alt",!0).attr("class","wt-chart-box-name").attr("direction",(t=>t.isAltRtl?"rtl":"ltr")).attr("text-anchor",(t=>t.isAltRtl&&this._orientation.isDocumentRtl?"start":t.isAltRtl||this._orientation.isDocumentRtl?"end":"start")).attr("x",(t=>this.textX(t))).attr("y",this._text.y+8);this.addNameElements(e,(t=>this.truncateNamesData(e,this.createAlternativeNamesData(t),this.getAvailableWidth(t))))}))}}getAvailableWidth(t){let e=this._text.width;return t.withImage&&(this._orientation instanceof pi||this._orientation instanceof gi)&&(e-=this._image.width),e}addNameElements(t,e){t.selectAll("tspan").data(e).enter().call((t=>{t.append("tspan").text((t=>t.label)).attr("dx",((t,e)=>0!==e?.25*(t.isNameRtl?-1:1)+"em":null)).classed("preferred",(t=>t.isPreferred)).classed("lastName",(t=>t.isLastName))}))}createNamesData(t){let e={},n={},i={},r=Number.MAX_SAFE_INTEGER,a=Number.MAX_SAFE_INTEGER;for(let e in t.data.data.firstNames){const i=t.data.data.name.indexOf(t.data.data.firstNames[e]);-1!==i&&(i({label:e,isPreferred:!1,isLastName:!1,isNameRtl:t.data.data.isAltRtl})))),n}truncateNames(t,e,n,i){let r=t.map((t=>t.label)).join(" ");return t.reverse().map((a=>(!1===a.isPreferred&&!1===a.isLastName&&this.measureText(r,e,n)>i&&(a.label=a.label.slice(0,1)+".",r=t.map((t=>t.label)).join(" ")),a))).map((a=>(!0===a.isPreferred&&this.measureText(r,e,n)>i&&(a.label=a.label.slice(0,1)+".",r=t.map((t=>t.label)).join(" ")),a))).map((a=>(!0===a.isLastName&&this.measureText(r,e,n)>i&&(a.label=a.label.slice(0,1)+".",r=t.map((t=>t.label)).join(" ")),a))).reverse()}textX(t){const e=this._text.x+(t.withImage?this._image.width:0);return this._orientation.isDocumentRtl?-e:e}measureText(t,e,n=400){return $i(t,this._svg.get().style("font-family"),e,n)}}let Ti=class{constructor(t,e,n,i){this._svg=t,this._orientation=e,this._image=n,this._text=i}appendDate(t){const e=t.append("g").attr("class","table");if(this._orientation instanceof li||this._orientation instanceof ci){const t=e.selectAll("text.date").data((t=>[{label:t.data.data.timespan,withImage:!0}])).enter();let n=this._text.y+45;this._svg._configuration.showAlternativeName&&(n+=30);const i=t.append("text").attr("class","date").attr("text-anchor","middle").attr("alignment-baseline","central").attr("y",n);i.append("title").text((t=>t.label));const r=i.append("tspan");r.text((t=>this.truncateDate(r,t.label,this._text.width)))}else e.selectAll("text").data((t=>{let e=[];return t.data.data.birth&&e.push({icon:"★",label:t.data.data.birth,birth:!0,withImage:""!==t.data.data.thumbnail}),t.data.data.death&&e.push({icon:"†",label:t.data.data.death,death:!0,withImage:""!==t.data.data.thumbnail}),e})).enter().call((t=>{t.append("text").attr("fill","currentColor").attr("text-anchor","middle").attr("dominant-baseline","middle").attr("x",(t=>this.textX(t))).attr("y",((t,e)=>this._text.y+30+(0===e?0:21))).append("tspan").text((t=>t.icon)).attr("dx",5*(this._orientation.isDocumentRtl?-1:1));const e=t.append("text").attr("class","date").attr("text-anchor","start").attr("dominant-baseline","middle").attr("x",(t=>this.textX(t))).attr("y",((t,e)=>this._text.y+30+(0===e?0:20)));e.append("title").text((t=>t.label));const n=e.append("tspan");n.text((t=>this.truncateDate(n,t.label,this._text.width-(t.withImage?this._image.width:0)-25))).attr("dx",15*(this._orientation.isDocumentRtl?-1:1))}))}truncateDate(t,e,n){const i=t.style("font-size"),r=t.style("font-weight");let a=!1;for(;this.measureText(e,i,r)>n&&e.length>1;)e=e.slice(0,-1).trim(),a=!0;return"."===e[e.length-1]&&(e=e.slice(0,-1).trim()),a?e+"…":e}textX(t){const e=this._text.x+(t.withImage?this._image.width:0);return this._orientation.isDocumentRtl?-e:e}measureText(t,e,n=400){return $i(t,this._svg.get().style("font-family"),e,n)}},Ri=class{constructor(t,e){this._orientation=t,this._cornerRadius=e,this._imagePadding=5,this._imageRadius=Math.min(40,this._orientation.boxHeight/2-this._imagePadding),this._width=this.calculateImageWidth(),this._height=this.calculateImageHeight(),this._rx=this.calculateCornerRadius(),this._ry=this.calculateCornerRadius(),this._x=this.calculateX(),this._y=this.calculateY()}calculateX(){return this._orientation instanceof pi||this._orientation instanceof gi?this._orientation.isDocumentRtl?this._width-this._imagePadding:-(this._orientation.boxWidth-this._imagePadding)/2+this._imagePadding:-this._orientation.boxWidth/2+this._width/2}calculateY(){return this._orientation instanceof pi||this._orientation instanceof gi?-this._imageRadius:-(this._orientation.boxHeight-this._imagePadding)/2+this._imagePadding}calculateImageWidth(){return 2*this._imageRadius}calculateImageHeight(){return 2*this._imageRadius}calculateCornerRadius(){return this._cornerRadius-this._imagePadding}get x(){return this._x}get y(){return this._y}get rx(){return this._rx}get ry(){return this._ry}get width(){return this._width}get height(){return this._height}};class Si{constructor(t,e=null){this._orientation=t,this._image=e,this._textPaddingX=15,this._textPaddingY=15,(this._orientation instanceof li||this._orientation instanceof ci)&&(this._textPaddingX=5,this._textPaddingY=15),this._x=this.calculateX(),this._y=this.calculateY(),this._width=this.calculateWidth()}calculateX(){return-this._orientation.boxWidth/2+this._textPaddingX}calculateY(){return this._orientation instanceof pi||this._orientation instanceof gi?-this._textPaddingY:this._image.y+this._image.height+2*this._textPaddingY}calculateWidth(){return this._orientation.boxWidth-2*this._textPaddingX}get x(){return this._x}get y(){return this._y}get width(){return this._width}}class Pi{constructor(t,e,n){this._svg=t,this._hierarchy=e,this._configuration=n,this._orientation=this._configuration.orientation,this._image=new Ri(this._orientation,20),this._text=new Si(this._orientation,this._image),this._name=new zi(this._svg,this._orientation,this._image,this._text),this._date=new Ti(this._svg,this._orientation,this._image,this._text)}drawNodes(t,e){this._svg.defs.get().append("clipPath").attr("id","clip-image").append("rect").attr("rx",this._image.rx).attr("ry",this._image.ry).attr("x",this._image.x).attr("y",this._image.y).attr("width",this._image.width).attr("height",this._image.height),this._svg.visual.selectAll("g.person").data(t,(t=>t.id)).join((t=>this.nodeEnter(t,e)),(t=>this.nodeUpdate(t)),(t=>this.nodeExit(t,e))),this._hierarchy.root.eachBefore((t=>{t.x0=t.x,t.y0=t.y}))}nodeEnter(t,e){t.append("g").attr("opacity",0).attr("class",(t=>"person"+(t.data.spouse?" spouse":""))).attr("transform",(t=>"translate("+t.x+","+t.y+")")).call((t=>{t.append("rect").attr("class",(t=>"F"===t.data.data.sex?"female":t.data.data.sex===oi?"male":"unknown")).attr("rx",20).attr("ry",20).attr("x",-this._orientation.boxWidth/2).attr("y",-this._orientation.boxHeight/2).attr("width",this._orientation.boxWidth).attr("height",this._orientation.boxHeight).attr("fill-opacity",.5),t.append("title").text((t=>t.data.data.name))})).call((t=>this.drawNode(t))).call((t=>t.transition().duration(this._configuration.duration).attr("opacity",1)))}nodeUpdate(t){t.call((t=>t.transition().duration(this._configuration.duration).attr("opacity",1).attr("transform",(t=>"translate("+t.x+","+t.y+")"))))}nodeExit(t,e){t.call((t=>t.transition().duration(this._configuration.duration).attr("opacity",0).attr("transform",(()=>"translate("+e.x0+","+e.y0+")")).remove()))}drawNode(t){const e=t.selectAll("g.image").data((t=>{let e=[];return t.data.data.thumbnail&&e.push({image:t.data.data.thumbnail}),e})).enter().append("g").attr("class","image");e.append("rect").attr("x",this._image.x).attr("y",this._image.y).attr("width",this._image.width).attr("height",this._image.height).attr("rx",this._image.rx).attr("ry",this._image.ry).attr("fill","rgb(255, 255, 255)"),e.append("image").attr("x",this._image.x).attr("y",this._image.y).attr("width",this._image.width).attr("height",this._image.height).attr("clip-path","url(#clip-image)"),e.append("rect").attr("x",this._image.x).attr("y",this._image.y).attr("width",this._image.width).attr("height",this._image.height).attr("rx",this._image.rx).attr("ry",this._image.ry).attr("fill","none").attr("stroke","rgb(200, 200, 200)").attr("stroke-width",1.5),function(t){return"string"==typeof t?new Te([document.querySelectorAll(t)],[document.documentElement]):new Te([$t(t)],ze)}("g.image image").each((function(t){let e=Se(this);(function(t,e=null){return fetch(t,e).then((t=>t.blob())).then((t=>new Promise(((e,n)=>{const i=new FileReader;i.onloadend=()=>e(i.result),i.onerror=n,i.readAsDataURL(t)}))))})(t.image).then((t=>e.attr("xlink:href",t))).catch((t=>{console.error(t)}))})),this._name.appendName(t),this._date.appendDate(t)}}class Ci{constructor(t,e){this._svg=t,this._configuration=e,this._orientation=this._configuration.orientation}drawLinks(t,e){this._svg.visual.selectAll("path.link").data(t).join((t=>this.linkEnter(t,e)),(t=>this.linkUpdate(t)),(t=>this.linkExit(t,e)))}linkEnter(t,e){t.append("path").classed("link",!0).attr("d",(t=>this._orientation.elbow(t))).call((t=>t.transition().duration(this._configuration.duration).attr("opacity",1)))}linkUpdate(t){}linkExit(t,e){}}class Di{constructor(t,e,n){this._svg=t,this._configuration=e,this._hierarchy=n,this._hierarchy.root.x0=0,this._hierarchy.root.y0=0,this._orientation=this._configuration.orientation,this._nodeDrawer=new Pi(this._svg,this._hierarchy,this._configuration),this._linkDrawer=new Ci(this._svg,this._configuration),this.draw(this._hierarchy.root)}draw(t){const e=this._hierarchy.root.descendants(),n=this._hierarchy.nodes.links();this._linkDrawer.drawLinks(n,t),this._nodeDrawer.drawNodes(e,t)}centerTree(){console.log("centerTree")}togglePerson(t,e){e.parents?(e._parents=e.parents,e.parents=null):(e.parents=e._parents,e._parents=null),this.draw(e)}collapse(t){t.parents&&(t._parents=t.parents,t._parents.forEach((t=>this.collapse(t))),t.parents=null)}}class Oi{constructor(t,e){this._configuration=e,this._parent=t,this._hierarchy=new yi(this._configuration),this._data={}}get svg(){return this._svg}updateViewBox(){let t=this._svg.visual.node().getBBox(),e=this._parent.node().getBoundingClientRect(),n=Math.max(e.width,t.width),i=Math.max(e.height,t.height,300),r=(n-t.width)/2,a=(i-t.height)/2,o=Math.ceil(t.x-r-10),s=Math.ceil(t.y-a-10);n=Math.ceil(n+20),i=Math.ceil(i+20),this._svg.get().attr("viewBox",[o,s,n,i])}get data(){return this._data}set data(t){this._data=t,this._hierarchy.init(this._data)}draw(){this._parent.html(""),this._svg=new ki(this._parent,this._configuration),this._overlay=new Ei(this._parent),this._svg.initEvents(this._overlay),new Di(this._svg,this._configuration,this._hierarchy),this.bindClickEventListener(),this.updateViewBox()}bindClickEventListener(){let t=this;this._svg.visual.selectAll("g.person").filter((t=>""!==t.data.data.xref)).each((function(e){Se(this).on("click",(function(){t.personClick(e.data)}))}))}personClick(t){1===t.data.generation?this.redirectToIndividual(t.data.url):this.update(t.data.updateUrl)}redirectToIndividual(t){this._configuration.openNewTabOnClick?window.open(t,"_blank"):window.location=t}update(t){window.location=t}}t.PedigreeChart=class{constructor(t,e){this._selector=t,this._parent=Se(this._selector),this._configuration=new mi(e.labels,e.generations,e.showEmptyBoxes,e.treeLayout,e.openNewTabOnClick,e.showAlternativeName,e.rtl),this._cssFiles=e.cssFiles,this._chart=new Oi(this._parent,this._configuration),this.init(),this.draw(e.data)}init(){Se("#centerButton").on("click",(()=>this.center())),Se("#exportPNG").on("click",(()=>this.exportPNG())),Se("#exportSVG").on("click",(()=>this.exportSVG()))}center(){this._chart.svg.get().transition().duration(750).call(this._chart.svg.zoom.get().transform,Gn)}get configuration(){return this._configuration}update(t){this._chart.update(t)}draw(t){this._chart.data=t,this._chart.draw()}exportPNG(){this._chart.svg.export("png").svgToImage(this._chart.svg,"pedigree-chart.png")}exportSVG(){this._chart.svg.export("svg").svgToImage(this._chart.svg,this._cssFiles,"webtrees-pedigree-chart-container","pedigree-chart.svg")}}},"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).WebtreesPedigreeChart={}); +var t,e;t=this,e=function(t){function e(t){if(!t.ok)throw new Error(t.status+" "+t.statusText);return t.text()}function n(t){var e=0,n=t.children,i=n&&n.length;if(i)for(;--i>=0;)e+=n[i].value;else e=1;t.value=e}function i(t,e){t instanceof Map?(t=[void 0,t],void 0===e&&(e=a)):void 0===e&&(e=r);for(var n,i,o,u,l,c=new h(t),f=[c];n=f.pop();)if((o=e(n.data))&&(l=(o=Array.from(o)).length))for(n.children=o,u=l-1;u>=0;--u)f.push(i=o[u]=new h(o[u])),i.parent=n,i.depth=n.depth+1;return c.eachBefore(s)}function r(t){return t.children}function a(t){return Array.isArray(t)?t[1]:null}function o(t){void 0!==t.data.value&&(t.value=t.data.value),t.data=t.data.data}function s(t){var e=0;do{t.height=e}while((t=t.parent)&&t.height<++e)}function h(t){this.data=t,this.depth=this.height=0,this.parent=null}function u(t,e){return t.parent===e.parent?1:2}function l(t){var e=t.children;return e?e[0]:t.t}function c(t){var e=t.children;return e?e[e.length-1]:t.t}function f(t,e,n){var i=n/(e.i-t.i);e.c-=i,e.s+=n,t.c+=i,e.z+=n,e.m+=n}function d(t,e,n){return t.a.parent===e.parent?t.a:n}function p(t,e){this._=t,this.parent=null,this.children=null,this.A=null,this.a=this,this.z=0,this.m=0,this.c=0,this.s=0,this.t=null,this.i=e}function g(){var t=u,e=1,n=1,i=null;function r(r){var h=function(t){for(var e,n,i,r,a,o=new p(t,0),s=[o];e=s.pop();)if(i=e._.children)for(e.children=new Array(a=i.length),r=a-1;r>=0;--r)s.push(n=e.children[r]=new p(i[r],r)),n.parent=e;return(o.parent=new p(null,0)).children=[o],o}(r);if(h.eachAfter(a),h.parent.m=-h.z,h.eachBefore(o),i)r.eachBefore(s);else{var u=r,l=r,c=r;r.eachBefore((function(t){t.xl.x&&(l=t),t.depth>c.depth&&(c=t)}));var f=u===l?1:t(u,l)/2,d=f-u.x,g=e/(l.x+f+d),_=n/(c.depth||1);r.eachBefore((function(t){t.x=(t.x+d)*g,t.y=t.depth*_}))}return r}function a(e){var n=e.children,i=e.parent.children,r=e.i?i[e.i-1]:null;if(n){!function(t){for(var e,n=0,i=0,r=t.children,a=r.length;--a>=0;)(e=r[a]).z+=n,e.m+=n,n+=e.s+(i+=e.c)}(e);var a=(n[0].z+n[n.length-1].z)/2;r?(e.z=r.z+t(e._,r._),e.m=e.z-a):e.z=a}else r&&(e.z=r.z+t(e._,r._));e.parent.A=function(e,n,i){if(n){for(var r,a=e,o=e,s=n,h=a.parent.children[0],u=a.m,p=o.m,g=s.m,_=h.m;s=c(s),a=l(a),s&&a;)h=l(h),(o=c(o)).a=e,(r=s.z+g-a.z-u+t(s._,a._))>0&&(f(d(s,e,i),e,r),u+=r,p+=r),g+=s.m,u+=a.m,_+=h.m,p+=o.m;s&&!c(o)&&(o.t=s,o.m+=g-p),a&&!l(h)&&(h.t=a,h.m+=u-_,i=e)}return i}(e,r,e.parent.A||i[0])}function o(t){t._.x=t.z+t.parent.m,t.m+=t.parent.m}function s(t){t.x*=e,t.y=t.depth*n}return r.separation=function(e){return arguments.length?(t=e,r):t},r.size=function(t){return arguments.length?(i=!1,e=+t[0],n=+t[1],r):i?null:[e,n]},r.nodeSize=function(t){return arguments.length?(i=!0,e=+t[0],n=+t[1],r):i?[e,n]:null},r}h.prototype=i.prototype={constructor:h,count:function(){return this.eachAfter(n)},each:function(t,e){let n=-1;for(const i of this)t.call(e,i,++n,this);return this},eachAfter:function(t,e){for(var n,i,r,a=this,o=[a],s=[],h=-1;a=o.pop();)if(s.push(a),n=a.children)for(i=0,r=n.length;i=0;--i)a.push(n[i]);return this},find:function(t,e){let n=-1;for(const i of this)if(t.call(e,i,++n,this))return i},sum:function(t){return this.eachAfter((function(e){for(var n=+t(e.data)||0,i=e.children,r=i&&i.length;--r>=0;)n+=i[r].value;e.value=n}))},sort:function(t){return this.eachBefore((function(e){e.children&&e.children.sort(t)}))},path:function(t){for(var e=this,n=function(t,e){if(t===e)return t;var n=t.ancestors(),i=e.ancestors(),r=null;for(t=n.pop(),e=i.pop();t===e;)r=t,t=n.pop(),e=i.pop();return r}(e,t),i=[e];e!==n;)e=e.parent,i.push(e);for(var r=i.length;t!==n;)i.splice(r,0,t),t=t.parent;return i},ancestors:function(){for(var t=this,e=[t];t=t.parent;)e.push(t);return e},descendants:function(){return Array.from(this)},leaves:function(){var t=[];return this.eachBefore((function(e){e.children||t.push(e)})),t},links:function(){var t=this,e=[];return t.each((function(n){n!==t&&e.push({source:n.parent,target:n})})),e},copy:function(){return i(this).eachBefore(o)},[Symbol.iterator]:function*(){var t,e,n,i,r=this,a=[r];do{for(t=a.reverse(),a=[];r=t.pop();)if(yield r,e=r.children)for(n=0,i=e.length;n=0))throw new Error(`invalid digits: ${t}`);if(e>15)return w;const n=10**e;return function(t){this._+=t[0];for(let e=1,i=t.length;ey)if(Math.abs(l*s-h*u)>y&&r){let f=n-a,d=i-o,p=s*s+h*h,g=f*f+d*d,m=Math.sqrt(p),v=Math.sqrt(c),w=r*Math.tan((_-Math.acos((p+c-g)/(2*m*v)))/2),x=w/v,b=w/m;Math.abs(x-1)>y&&this._append`L${t+x*u},${e+x*l}`,this._append`A${r},${r},0,0,${+(l*f>u*d)},${this._x1=t+b*s},${this._y1=e+b*h}`}else this._append`L${this._x1=t},${this._y1=e}`}arc(t,e,n,i,r,a){if(t=+t,e=+e,a=!!a,(n=+n)<0)throw new Error(`negative radius: ${n}`);let o=n*Math.cos(i),s=n*Math.sin(i),h=t+o,u=e+s,l=1^a,c=a?i-r:r-i;null===this._x1?this._append`M${h},${u}`:(Math.abs(this._x1-h)>y||Math.abs(this._y1-u)>y)&&this._append`L${h},${u}`,n&&(c<0&&(c=c%m+m),c>v?this._append`A${n},${n},0,1,${l},${t-o},${e-s}A${n},${n},0,1,${l},${this._x1=h},${this._y1=u}`:c>y&&this._append`A${n},${n},0,${+(c>=_)},${l},${this._x1=t+n*Math.cos(r)},${this._y1=e+n*Math.sin(r)}`)}rect(t,e,n,i){this._append`M${this._x0=this._x1=+t},${this._y0=this._y1=+e}h${n=+n}v${+i}h${-n}Z`}toString(){return this._}}function b(){return new x}function N(t,e,n){t.prototype=e.prototype=n,n.constructor=t}function A(t,e){var n=Object.create(t.prototype);for(var i in e)n[i]=e[i];return n}function k(){}b.prototype=x.prototype;var E=.7,M=1/E,$="\\s*([+-]?\\d+)\\s*",z="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",T="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",R=/^#([0-9a-f]{3,8})$/,S=new RegExp(`^rgb\\(${$},${$},${$}\\)$`),P=new RegExp(`^rgb\\(${T},${T},${T}\\)$`),C=new RegExp(`^rgba\\(${$},${$},${$},${z}\\)$`),D=new RegExp(`^rgba\\(${T},${T},${T},${z}\\)$`),O=new RegExp(`^hsl\\(${z},${T},${T}\\)$`),L=new RegExp(`^hsla\\(${z},${T},${T},${z}\\)$`),I={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};function X(){return this.rgb().formatHex()}function B(){return this.rgb().formatRgb()}function H(t){var e,n;return t=(t+"").trim().toLowerCase(),(e=R.exec(t))?(n=e[1].length,e=parseInt(e[1],16),6===n?W(e):3===n?new j(e>>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e,1):8===n?Y(e>>24&255,e>>16&255,e>>8&255,(255&e)/255):4===n?Y(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|240&e,((15&e)<<4|15&e)/255):null):(e=S.exec(t))?new j(e[1],e[2],e[3],1):(e=P.exec(t))?new j(255*e[1]/100,255*e[2]/100,255*e[3]/100,1):(e=C.exec(t))?Y(e[1],e[2],e[3],e[4]):(e=D.exec(t))?Y(255*e[1]/100,255*e[2]/100,255*e[3]/100,e[4]):(e=O.exec(t))?Q(e[1],e[2]/100,e[3]/100,1):(e=L.exec(t))?Q(e[1],e[2]/100,e[3]/100,e[4]):I.hasOwnProperty(t)?W(I[t]):"transparent"===t?new j(NaN,NaN,NaN,0):null}function W(t){return new j(t>>16&255,t>>8&255,255&t,1)}function Y(t,e,n,i){return i<=0&&(t=e=n=NaN),new j(t,e,n,i)}function q(t,e,n,i){return 1===arguments.length?((r=t)instanceof k||(r=H(r)),r?new j((r=r.rgb()).r,r.g,r.b,r.opacity):new j):new j(t,e,n,null==i?1:i);var r}function j(t,e,n,i){this.r=+t,this.g=+e,this.b=+n,this.opacity=+i}function U(){return`#${K(this.r)}${K(this.g)}${K(this.b)}`}function V(){const t=G(this.opacity);return`${1===t?"rgb(":"rgba("}${F(this.r)}, ${F(this.g)}, ${F(this.b)}${1===t?")":`, ${t})`}`}function G(t){return isNaN(t)?1:Math.max(0,Math.min(1,t))}function F(t){return Math.max(0,Math.min(255,Math.round(t)||0))}function K(t){return((t=F(t))<16?"0":"")+t.toString(16)}function Q(t,e,n,i){return i<=0?t=e=n=NaN:n<=0||n>=1?t=e=NaN:e<=0&&(t=NaN),new J(t,e,n,i)}function Z(t){if(t instanceof J)return new J(t.h,t.s,t.l,t.opacity);if(t instanceof k||(t=H(t)),!t)return new J;if(t instanceof J)return t;var e=(t=t.rgb()).r/255,n=t.g/255,i=t.b/255,r=Math.min(e,n,i),a=Math.max(e,n,i),o=NaN,s=a-r,h=(a+r)/2;return s?(o=e===a?(n-i)/s+6*(n0&&h<1?0:o,new J(o,s,h,t.opacity)}function J(t,e,n,i){this.h=+t,this.s=+e,this.l=+n,this.opacity=+i}function tt(t){return(t=(t||0)%360)<0?t+360:t}function et(t){return Math.max(0,Math.min(1,t||0))}function nt(t,e,n){return 255*(t<60?e+(n-e)*t/60:t<180?n:t<240?e+(n-e)*(240-t)/60:e)}N(k,H,{copy(t){return Object.assign(new this.constructor,this,t)},displayable(){return this.rgb().displayable()},hex:X,formatHex:X,formatHex8:function(){return this.rgb().formatHex8()},formatHsl:function(){return Z(this).formatHsl()},formatRgb:B,toString:B}),N(j,q,A(k,{brighter(t){return t=null==t?M:Math.pow(M,t),new j(this.r*t,this.g*t,this.b*t,this.opacity)},darker(t){return t=null==t?E:Math.pow(E,t),new j(this.r*t,this.g*t,this.b*t,this.opacity)},rgb(){return this},clamp(){return new j(F(this.r),F(this.g),F(this.b),G(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:U,formatHex:U,formatHex8:function(){return`#${K(this.r)}${K(this.g)}${K(this.b)}${K(255*(isNaN(this.opacity)?1:this.opacity))}`},formatRgb:V,toString:V})),N(J,(function(t,e,n,i){return 1===arguments.length?Z(t):new J(t,e,n,null==i?1:i)}),A(k,{brighter(t){return t=null==t?M:Math.pow(M,t),new J(this.h,this.s,this.l*t,this.opacity)},darker(t){return t=null==t?E:Math.pow(E,t),new J(this.h,this.s,this.l*t,this.opacity)},rgb(){var t=this.h%360+360*(this.h<0),e=isNaN(t)||isNaN(this.s)?0:this.s,n=this.l,i=n+(n<.5?n:1-n)*e,r=2*n-i;return new j(nt(t>=240?t-240:t+120,r,i),nt(t,r,i),nt(t<120?t+240:t-120,r,i),this.opacity)},clamp(){return new J(tt(this.h),et(this.s),et(this.l),G(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const t=G(this.opacity);return`${1===t?"hsl(":"hsla("}${tt(this.h)}, ${100*et(this.s)}%, ${100*et(this.l)}%${1===t?")":`, ${t})`}`}}));var it=t=>()=>t;function rt(t){return 1==(t=+t)?at:function(e,n){return n-e?function(t,e,n){return t=Math.pow(t,n),e=Math.pow(e,n)-t,n=1/n,function(i){return Math.pow(t+i*e,n)}}(e,n,t):it(isNaN(e)?n:e)}}function at(t,e){var n=e-t;return n?function(t,e){return function(n){return t+n*e}}(t,n):it(isNaN(t)?e:t)}var ot=function t(e){var n=rt(e);function i(t,e){var i=n((t=q(t)).r,(e=q(e)).r),r=n(t.g,e.g),a=n(t.b,e.b),o=at(t.opacity,e.opacity);return function(e){return t.r=i(e),t.g=r(e),t.b=a(e),t.opacity=o(e),t+""}}return i.gamma=t,i}(1);function st(t,e){return t=+t,e=+e,function(n){return t*(1-n)+e*n}}var ht=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,ut=new RegExp(ht.source,"g");function lt(t,e){var n,i,r,a=ht.lastIndex=ut.lastIndex=0,o=-1,s=[],h=[];for(t+="",e+="";(n=ht.exec(t))&&(i=ut.exec(e));)(r=i.index)>a&&(r=e.slice(a,r),s[o]?s[o]+=r:s[++o]=r),(n=n[0])===(i=i[0])?s[o]?s[o]+=i:s[++o]=i:(s[++o]=null,h.push({i:o,x:st(n,i)})),a=ut.lastIndex;return a180?e+=360:e-t>180&&(t+=360),a.push({i:n.push(r(n)+"rotate(",null,i)-2,x:st(t,e)})):e&&n.push(r(n)+"rotate("+e+i)}(a.rotate,o.rotate,s,h),function(t,e,n,a){t!==e?a.push({i:n.push(r(n)+"skewX(",null,i)-2,x:st(t,e)}):e&&n.push(r(n)+"skewX("+e+i)}(a.skewX,o.skewX,s,h),function(t,e,n,i,a,o){if(t!==n||e!==i){var s=a.push(r(a)+"scale(",null,",",null,")");o.push({i:s-4,x:st(t,n)},{i:s-2,x:st(e,i)})}else 1===n&&1===i||a.push(r(a)+"scale("+n+","+i+")")}(a.scaleX,a.scaleY,o.scaleX,o.scaleY,s,h),a=o=null,function(t){for(var e,n=-1,i=h.length;++n=0&&"xmlns"!==(e=t.slice(0,n))&&(t=t.slice(n+1)),xt.hasOwnProperty(e)?{space:xt[e],local:t}:t}function Nt(t){return function(){var e=this.ownerDocument,n=this.namespaceURI;return n===wt&&e.documentElement.namespaceURI===wt?e.createElement(t):e.createElementNS(n,t)}}function At(t){return function(){return this.ownerDocument.createElementNS(t.space,t.local)}}function kt(t){var e=bt(t);return(e.local?At:Nt)(e)}function Et(){}function Mt(t){return null==t?Et:function(){return this.querySelector(t)}}function $t(t){return null==t?[]:Array.isArray(t)?t:Array.from(t)}function zt(){return[]}function Tt(t){return null==t?zt:function(){return this.querySelectorAll(t)}}function Rt(t){return function(){return this.matches(t)}}function St(t){return function(e){return e.matches(t)}}var Pt=Array.prototype.find;function Ct(){return this.firstElementChild}var Dt=Array.prototype.filter;function Ot(){return Array.from(this.children)}function Lt(t){return new Array(t.length)}function It(t,e){this.ownerDocument=t.ownerDocument,this.namespaceURI=t.namespaceURI,this._next=null,this._parent=t,this.__data__=e}function Xt(t,e,n,i,r,a){for(var o,s=0,h=e.length,u=a.length;se?1:t>=e?0:NaN}function qt(t){return function(){this.removeAttribute(t)}}function jt(t){return function(){this.removeAttributeNS(t.space,t.local)}}function Ut(t,e){return function(){this.setAttribute(t,e)}}function Vt(t,e){return function(){this.setAttributeNS(t.space,t.local,e)}}function Gt(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttribute(t):this.setAttribute(t,n)}}function Ft(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttributeNS(t.space,t.local):this.setAttributeNS(t.space,t.local,n)}}function Kt(t){return t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView}function Qt(t){return function(){this.style.removeProperty(t)}}function Zt(t,e,n){return function(){this.style.setProperty(t,e,n)}}function Jt(t,e,n){return function(){var i=e.apply(this,arguments);null==i?this.style.removeProperty(t):this.style.setProperty(t,i,n)}}function te(t,e){return t.style.getPropertyValue(e)||Kt(t).getComputedStyle(t,null).getPropertyValue(e)}function ee(t){return function(){delete this[t]}}function ne(t,e){return function(){this[t]=e}}function ie(t,e){return function(){var n=e.apply(this,arguments);null==n?delete this[t]:this[t]=n}}function re(t){return t.trim().split(/^|\s+/)}function ae(t){return t.classList||new oe(t)}function oe(t){this._node=t,this._names=re(t.getAttribute("class")||"")}function se(t,e){for(var n=ae(t),i=-1,r=e.length;++i=0&&(this._names.splice(e,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(t){return this._names.indexOf(t)>=0}};var ze=[null];function Te(t,e){this._groups=t,this._parents=e}function Re(){return new Te([[document.documentElement]],ze)}function Se(t){return"string"==typeof t?new Te([[document.querySelector(t)]],[document.documentElement]):new Te([[t]],ze)}function Pe(t,e){if(t=function(t){let e;for(;e=t.sourceEvent;)t=e;return t}(t),void 0===e&&(e=t.currentTarget),e){var n=e.ownerSVGElement||e;if(n.createSVGPoint){var i=n.createSVGPoint();return i.x=t.clientX,i.y=t.clientY,[(i=i.matrixTransform(e.getScreenCTM().inverse())).x,i.y]}if(e.getBoundingClientRect){var r=e.getBoundingClientRect();return[t.clientX-r.left-e.clientLeft,t.clientY-r.top-e.clientTop]}}return[t.pageX,t.pageY]}Te.prototype=Re.prototype={constructor:Te,select:function(t){"function"!=typeof t&&(t=Mt(t));for(var e=this._groups,n=e.length,i=new Array(n),r=0;r=x&&(x=w+1);!(v=m[x])&&++x=0;)(i=r[a])&&(o&&4^i.compareDocumentPosition(o)&&o.parentNode.insertBefore(i,o),o=i);return this},sort:function(t){function e(e,n){return e&&n?t(e.__data__,n.__data__):!e-!n}t||(t=Yt);for(var n=this._groups,i=n.length,r=new Array(i),a=0;a1?this.each((null==e?Qt:"function"==typeof e?Jt:Zt)(t,e,null==n?"":n)):te(this.node(),t)},property:function(t,e){return arguments.length>1?this.each((null==e?ee:"function"==typeof e?ie:ne)(t,e)):this.node()[t]},classed:function(t,e){var n=re(t+"");if(arguments.length<2){for(var i=ae(this.node()),r=-1,a=n.length;++r=0&&(e=t.slice(n+1),t=t.slice(0,n)),{type:t,name:e}}))}(t+""),o=a.length;if(!(arguments.length<2)){for(s=e?ke:Ae,i=0;i=0&&e._call.call(void 0,t),e=e._next;--Oe}()}finally{Oe=0,function(){for(var t,e,n=Ce,i=1/0;n;)n._call?(i>n._time&&(i=n._time),t=n,n=n._next):(e=n._next,n._next=null,n=t?t._next=e:Ce=e);De=t,Qe(i)}(),He=0}}function Ke(){var t=Ye.now(),e=t-Be;e>Xe&&(We-=e,Be=t)}function Qe(t){Oe||(Le&&(Le=clearTimeout(Le)),t-He>24?(t<1/0&&(Le=setTimeout(Fe,t-Ye.now()-We)),Ie&&(Ie=clearInterval(Ie))):(Ie||(Be=Ye.now(),Ie=setInterval(Ke,Xe)),Oe=1,qe(Fe)))}function Ze(t,e,n){var i=new Ve;return e=null==e?0:+e,i.restart((n=>{i.stop(),t(n+e)}),e,n),i}Ve.prototype=Ge.prototype={constructor:Ve,restart:function(t,e,n){if("function"!=typeof t)throw new TypeError("callback is not a function");n=(null==n?je():+n)+(null==e?0:+e),this._next||De===this||(De?De._next=this:Ce=this,De=this),this._call=t,this._time=n,Qe()},stop:function(){this._call&&(this._call=null,this._time=1/0,Qe())}};var Je={value:()=>{}};function tn(){for(var t,e=0,n=arguments.length,i={};e=0&&(e=t.slice(n+1),t=t.slice(0,n)),t&&!i.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:e}}))),o=-1,s=a.length;if(!(arguments.length<2)){if(null!=e&&"function"!=typeof e)throw new Error("invalid callback: "+e);for(;++o0)for(var n,i,r=new Array(n),a=0;asn)throw new Error("too late; already scheduled");return n}function _n(t,e){var n=mn(t,e);if(n.state>ln)throw new Error("too late; already running");return n}function mn(t,e){var n=t.__transition;if(!n||!(n=n[e]))throw new Error("transition not found");return n}function yn(t,e){var n,i,r,a=t.__transition,o=!0;if(a){for(r in e=null==e?null:e+"",a)(n=a[r]).name===e?(i=n.state>un&&n.state=0&&(t=t.slice(0,e)),!t||"start"===t}))}(e)?gn:_n;return function(){var o=a(this,t),s=o.on;s!==i&&(r=(i=s).copy()).on(e,n),o.on=r}}(n,t,e))},attr:function(t,e){var n=bt(t),i="transform"===n?mt:bn;return this.attrTween(t,"function"==typeof e?(n.local?$n:Mn)(n,i,xn(this,"attr."+t,e)):null==e?(n.local?An:Nn)(n):(n.local?En:kn)(n,i,e))},attrTween:function(t,e){var n="attr."+t;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(null==e)return this.tween(n,null);if("function"!=typeof e)throw new Error;var i=bt(t);return this.tween(n,(i.local?zn:Tn)(i,e))},style:function(t,e,n){var i="transform"==(t+="")?_t:bn;return null==e?this.styleTween(t,function(t,e){var n,i,r;return function(){var a=te(this,t),o=(this.style.removeProperty(t),te(this,t));return a===o?null:a===n&&o===i?r:r=e(n=a,i=o)}}(t,i)).on("end.style."+t,On(t)):"function"==typeof e?this.styleTween(t,function(t,e,n){var i,r,a;return function(){var o=te(this,t),s=n(this),h=s+"";return null==s&&(this.style.removeProperty(t),h=s=te(this,t)),o===h?null:o===i&&h===r?a:(r=h,a=e(i=o,s))}}(t,i,xn(this,"style."+t,e))).each(function(t,e){var n,i,r,a,o="style."+e,s="end."+o;return function(){var h=_n(this,t),u=h.on,l=null==h.value[o]?a||(a=On(e)):void 0;u===n&&r===l||(i=(n=u).copy()).on(s,r=l),h.on=i}}(this._id,t)):this.styleTween(t,function(t,e,n){var i,r,a=n+"";return function(){var o=te(this,t);return o===a?null:o===i?r:r=e(i=o,n)}}(t,i,e),n).on("end.style."+t,null)},styleTween:function(t,e,n){var i="style."+(t+="");if(arguments.length<2)return(i=this.tween(i))&&i._value;if(null==e)return this.tween(i,null);if("function"!=typeof e)throw new Error;return this.tween(i,function(t,e,n){var i,r;function a(){var a=e.apply(this,arguments);return a!==r&&(i=(r=a)&&function(t,e,n){return function(i){this.style.setProperty(t,e.call(this,i),n)}}(t,a,n)),i}return a._value=e,a}(t,e,null==n?"":n))},text:function(t){return this.tween("text","function"==typeof t?function(t){return function(){var e=t(this);this.textContent=null==e?"":e}}(xn(this,"text",t)):function(t){return function(){this.textContent=t}}(null==t?"":t+""))},textTween:function(t){var e="text";if(arguments.length<1)return(e=this.tween(e))&&e._value;if(null==t)return this.tween(e,null);if("function"!=typeof t)throw new Error;return this.tween(e,function(t){var e,n;function i(){var i=t.apply(this,arguments);return i!==n&&(e=(n=i)&&function(t){return function(e){this.textContent=t.call(this,e)}}(i)),e}return i._value=t,i}(t))},remove:function(){return this.on("end.remove",function(t){return function(){var e=this.parentNode;for(var n in this.__transition)if(+n!==t)return;e&&e.removeChild(this)}}(this._id))},tween:function(t,e){var n=this._id;if(t+="",arguments.length<2){for(var i,r=mn(this.node(),n).tween,a=0,o=r.length;a()=>t;function Un(t,{sourceEvent:e,target:n,transform:i,dispatch:r}){Object.defineProperties(this,{type:{value:t,enumerable:!0,configurable:!0},sourceEvent:{value:e,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:i,enumerable:!0,configurable:!0},_:{value:r}})}function Vn(t,e,n){this.k=t,this.x=e,this.y=n}Vn.prototype={constructor:Vn,scale:function(t){return 1===t?this:new Vn(this.k*t,this.x,this.y)},translate:function(t,e){return 0===t&0===e?this:new Vn(this.k,this.x+this.k*t,this.y+this.k*e)},apply:function(t){return[t[0]*this.k+this.x,t[1]*this.k+this.y]},applyX:function(t){return t*this.k+this.x},applyY:function(t){return t*this.k+this.y},invert:function(t){return[(t[0]-this.x)/this.k,(t[1]-this.y)/this.k]},invertX:function(t){return(t-this.x)/this.k},invertY:function(t){return(t-this.y)/this.k},rescaleX:function(t){return t.copy().domain(t.range().map(this.invertX,this).map(t.invert,t))},rescaleY:function(t){return t.copy().domain(t.range().map(this.invertY,this).map(t.invert,t))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var Gn=new Vn(1,0,0);function Fn(t){for(;!t.__zoom;)if(!(t=t.parentNode))return Gn;return t.__zoom}function Kn(t){t.stopImmediatePropagation()}function Qn(t){t.preventDefault(),t.stopImmediatePropagation()}function Zn(t){return!(t.ctrlKey&&"wheel"!==t.type||t.button)}function Jn(){var t=this;return t instanceof SVGElement?(t=t.ownerSVGElement||t).hasAttribute("viewBox")?[[(t=t.viewBox.baseVal).x,t.y],[t.x+t.width,t.y+t.height]]:[[0,0],[t.width.baseVal.value,t.height.baseVal.value]]:[[0,0],[t.clientWidth,t.clientHeight]]}function ti(){return this.__zoom||Gn}function ei(t){return-t.deltaY*(1===t.deltaMode?.05:t.deltaMode?1:.002)*(t.ctrlKey?10:1)}function ni(){return navigator.maxTouchPoints||"ontouchstart"in this}function ii(t,e,n){var i=t.invertX(e[0][0])-n[0][0],r=t.invertX(e[1][0])-n[1][0],a=t.invertY(e[0][1])-n[0][1],o=t.invertY(e[1][1])-n[1][1];return t.translate(r>i?(i+r)/2:Math.min(0,i)||Math.max(0,r),o>a?(a+o)/2:Math.min(0,a)||Math.max(0,o))}function ri(){var t,e,n,i=Zn,r=Jn,a=ii,o=ei,s=ni,h=[0,1/0],u=[[-1/0,-1/0],[1/0,1/0]],l=250,c=vt,f=tn("start","zoom","end"),d=500,p=150,g=0,_=10;function m(t){t.property("__zoom",ti).on("wheel.zoom",A,{passive:!1}).on("mousedown.zoom",k).on("dblclick.zoom",E).filter(s).on("touchstart.zoom",M).on("touchmove.zoom",$).on("touchend.zoom touchcancel.zoom",z).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function y(t,e){return(e=Math.max(h[0],Math.min(h[1],e)))===t.k?t:new Vn(e,t.x,t.y)}function v(t,e,n){var i=e[0]-n[0]*t.k,r=e[1]-n[1]*t.k;return i===t.x&&r===t.y?t:new Vn(t.k,i,r)}function w(t){return[(+t[0][0]+ +t[1][0])/2,(+t[0][1]+ +t[1][1])/2]}function x(t,e,n,i){t.on("start.zoom",(function(){b(this,arguments).event(i).start()})).on("interrupt.zoom end.zoom",(function(){b(this,arguments).event(i).end()})).tween("zoom",(function(){var t=this,a=arguments,o=b(t,a).event(i),s=r.apply(t,a),h=null==n?w(s):"function"==typeof n?n.apply(t,a):n,u=Math.max(s[1][0]-s[0][0],s[1][1]-s[0][1]),l=t.__zoom,f="function"==typeof e?e.apply(t,a):e,d=c(l.invert(h).concat(u/l.k),f.invert(h).concat(u/f.k));return function(t){if(1===t)t=f;else{var e=d(t),n=u/e[2];t=new Vn(n,h[0]-e[0]*n,h[1]-e[1]*n)}o.zoom(null,t)}}))}function b(t,e,n){return!n&&t.__zooming||new N(t,e)}function N(t,e){this.that=t,this.args=e,this.active=0,this.sourceEvent=null,this.extent=r.apply(t,e),this.taps=0}function A(t,...e){if(i.apply(this,arguments)){var n=b(this,e).event(t),r=this.__zoom,s=Math.max(h[0],Math.min(h[1],r.k*Math.pow(2,o.apply(this,arguments)))),l=Pe(t);if(n.wheel)n.mouse[0][0]===l[0]&&n.mouse[0][1]===l[1]||(n.mouse[1]=r.invert(n.mouse[0]=l)),clearTimeout(n.wheel);else{if(r.k===s)return;n.mouse=[l,r.invert(l)],yn(this),n.start()}Qn(t),n.wheel=setTimeout((function(){n.wheel=null,n.end()}),p),n.zoom("mouse",a(v(y(r,s),n.mouse[0],n.mouse[1]),n.extent,u))}}function k(t,...e){if(!n&&i.apply(this,arguments)){var r=t.currentTarget,o=b(this,e,!0).event(t),s=Se(t.view).on("mousemove.zoom",(function(t){if(Qn(t),!o.moved){var e=t.clientX-l,n=t.clientY-c;o.moved=e*e+n*n>g}o.event(t).zoom("mouse",a(v(o.that.__zoom,o.mouse[0]=Pe(t,r),o.mouse[1]),o.extent,u))}),!0).on("mouseup.zoom",(function(t){s.on("mousemove.zoom mouseup.zoom",null),function(t,e){var n=t.document.documentElement,i=Se(t).on("dragstart.drag",null);e&&(i.on("click.drag",qn,Yn),setTimeout((function(){i.on("click.drag",null)}),0)),"onselectstart"in n?i.on("selectstart.drag",null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}(t.view,o.moved),Qn(t),o.event(t).end()}),!0),h=Pe(t,r),l=t.clientX,c=t.clientY;!function(t){var e=t.document.documentElement,n=Se(t).on("dragstart.drag",qn,Yn);"onselectstart"in e?n.on("selectstart.drag",qn,Yn):(e.__noselect=e.style.MozUserSelect,e.style.MozUserSelect="none")}(t.view),Kn(t),o.mouse=[h,this.__zoom.invert(h)],yn(this),o.start()}}function E(t,...e){if(i.apply(this,arguments)){var n=this.__zoom,o=Pe(t.changedTouches?t.changedTouches[0]:t,this),s=n.invert(o),h=n.k*(t.shiftKey?.5:2),c=a(v(y(n,h),o,s),r.apply(this,e),u);Qn(t),l>0?Se(this).transition().duration(l).call(x,c,o,t):Se(this).call(m.transform,c,o,t)}}function M(n,...r){if(i.apply(this,arguments)){var a,o,s,h,u=n.touches,l=u.length,c=b(this,r,n.changedTouches.length===l).event(n);for(Kn(n),o=0;o=0&&(a-=ui(t,e)),null===t.coords&&(n.moveTo(t.spouse.x+r,a),n.lineTo(t.source.x-r,a)),t.coords&&t.coords.length>0){for(let e=0;e0&&(o=t.coords[e-1].x+r);let h=e>0?i:0,u=e+1<=t.coords.length?i:0;n.moveTo(o+h,a),n.lineTo(s-u,a)}n.moveTo(t.coords[t.coords.length-1].x+r+i,a),n.lineTo(t.source.x-r,a)}return n.toString()}(t,e)}function ui(t,e){return(t.source.data.family-Math.ceil(t.spouse.data.spouses.length/2))*e.direction*5}class li extends si{constructor(t,e){super(t,e),this._splittNames=!0}get direction(){return 1}get nodeWidth(){return this._boxWidth+this._xOffset}get nodeHeight(){return this._boxHeight+this._yOffset}norm(t){t.y*=this.direction}elbow(t){return hi(t,this)}}class ci extends si{constructor(t,e){super(t,e),this._splittNames=!0}get direction(){return-1}get nodeWidth(){return this._boxWidth+this._xOffset}get nodeHeight(){return this._boxHeight+this._yOffset}norm(t){t.y*=this.direction}elbow(t){return hi(t,this)}}function fi(t,e){const n=e.xOffset/2,i=e.yOffset/2;let r=t.source.x,a=t.source.y;if(void 0!==t.spouse&&0===t.source.data.family?(r-=di(t,e),a-=(t.source.y-t.spouse.y)/2):r+=e.boxWidth/2*e.direction,null===t.source.data.data&&(r+=e.boxWidth/2*e.direction,a-=e.boxHeight/2+i/2),null!==t.target){let i=t.target.x-e.direction*(e.boxWidth/2+n),o=t.target.y;const s=b();return s.moveTo(r,a),s.lineTo(i,a),s.lineTo(i,o),s.lineTo(i+e.direction*n,o),s.toString()}return function(t,e){const n=b(),i=2,r=e.boxHeight/2;let a=t.source.x;if(t.spouse.data.spouses.length>=0&&(a-=di(t,e)),null===t.coords&&(n.moveTo(a,t.spouse.y+r),n.lineTo(a,t.source.y-r)),t.coords&&t.coords.length>0){for(let e=0;e0&&(o=t.coords[e-1].y+r);let h=e>0?i:0,u=e+1<=t.coords.length?i:0;n.moveTo(a,o+h),n.lineTo(a,s-u)}n.moveTo(a,t.coords[t.coords.length-1].y+r+i),n.lineTo(a,t.source.y-r)}return n.toString()}(t,e)}function di(t,e){return(t.source.data.family-Math.ceil(t.spouse.data.spouses.length/2))*e.direction*5}class pi extends si{constructor(t,e){super(t,e),this._xOffset=40,this._yOffset=20}get direction(){return this.isDocumentRtl?-1:1}get nodeWidth(){return this._boxHeight+this._yOffset}get nodeHeight(){return this._boxWidth+this._xOffset}norm(t){[t.x,t.y]=[t.y*this.direction,t.x]}elbow(t){return fi(t,this)}}class gi extends si{constructor(t,e){super(t,e),this._xOffset=40,this._yOffset=20}get direction(){return this.isDocumentRtl?1:-1}get nodeWidth(){return this._boxHeight+this._yOffset}get nodeHeight(){return this._boxWidth+this._xOffset}norm(t){[t.x,t.y]=[t.y*this.direction,t.x]}elbow(t){return fi(t,this)}}class _i{constructor(){this._orientations={down:new li(160,175),up:new ci(160,175),[ai]:new pi(325,95),left:new gi(325,95)}}get(){return this._orientations}}class mi{constructor(t,e=4,n=!1,i=ai,r=!0,a=!0,o=!1,s=1){this._treeLayout=i,this._orientations=new _i,this._showEmptyBoxes=n,this._openNewTabOnClick=r,this._showAlternativeName=a,this.duration=750,this.padding=15,this._generations=e,this.textPadding=8,this._fontSize=14,this.fontColor="rgb(0, 0, 0)",this.rtl=o,this.labels=t,this.direction=s}get generations(){return this._generations}set generations(t){this._generations=t}get showEmptyBoxes(){return this._showEmptyBoxes}get treeLayout(){return this._treeLayout}set treeLayout(t){this._treeLayout=t}get orientation(){return this._orientations.get()[this.treeLayout]}get openNewTabOnClick(){return this._openNewTabOnClick}get showAlternativeName(){return this._showAlternativeName}}class yi{constructor(t){this._configuration=t,this._nodes=null,this._root=null}init(t){this._configuration.showAlternativeName&&(this._configuration.orientation instanceof li||this._configuration.orientation instanceof ci)&&(this._configuration.orientation.boxHeight+=30);const e=({parents:t})=>1+(t?Math.max(...t.map(e)):0),n=e(t);this._root=i(t,(t=>this._configuration.showEmptyBoxes?(!t.parents&&t.data.generation{t.id=e}));const r=g().nodeSize([this._configuration.orientation.nodeWidth,this._configuration.orientation.nodeHeight]).separation((()=>1));this._nodes=r(this._root),this._root.each((t=>{this._configuration.orientation.norm(t)}))}get nodes(){return this._nodes}get root(){return this._root}createEmptyNode(t,e){return{data:{id:0,xref:"",url:"",updateUrl:"",generation:t,name:"",isNameRtl:!1,firstNames:[],lastNames:[],preferredName:"",alternativeName:"",isAltRtl:!1,sex:"U",timespan:""}}}}class vi{constructor(t){this._element=t.append("defs")}get(){return this._element}}class wi{constructor(t){this._zoom=null,this._parent=t,this.init()}init(){this._zoom=ri(),this._zoom.scaleExtent([.1,20]).on("zoom",(t=>{this._parent.attr("transform",t.transform)})),this._zoom.wheelDelta((t=>-t.deltaY*(1===t.deltaMode?.05:t.deltaMode?1:.002))),this._zoom.filter((t=>{if("wheel"===t.type){if(!t.ctrlKey)return!1;const e=Fn(this);if(e.k){if(e.k<=.1&&t.deltaY>0)return t.preventDefault(),!1;if(e.k>=20&&t.deltaY<0)return t.preventDefault(),!1}return!0}return t.button||"touchstart"!==t.type?!(t.ctrlKey&&"wheel"!==t.type||t.button):2===t.touches.length}))}get(){return this._zoom}}class xi{triggerDownload(t,e){let n=new MouseEvent("click",{view:window,bubbles:!1,cancelable:!0}),i=document.createElement("a");i.setAttribute("download",e),i.setAttribute("href",t),i.setAttribute("target","_blank"),i.dispatchEvent(n)}}class bi extends xi{copyStylesInline(t,e){let n=["svg","g","text","textPath"];for(let i=0;i{let r=(new XMLSerializer).serializeToString(t),a=window.URL||window.webkitURL||window,o=new Blob([r],{type:"image/svg+xml;charset=utf-8"}),s=a.createObjectURL(o),h=new Image;h.onload=()=>{let t=this.createCanvas(e,n),r=t.getContext("2d");r.fillStyle="rgb(255,255,255)",r.fillRect(0,0,t.width,t.height),r.drawImage(h,0,0),a.revokeObjectURL(s);let o=t.toDataURL("image/png").replace("image/png","image/octet-stream");i(o)},h.src=s}))}cloneSvg(t){return new Promise((e=>{e(t.cloneNode(!0))}))}svgToImage(t,e){const n=[4960,3508];this.cloneSvg(t.get().node()).then((e=>{this.copyStylesInline(t.get().node(),e);const i=this.calculateViewBox(t.get().node()),r=Math.max(n[0],i[2]),a=Math.max(n[1],i[3]);return e.setAttribute("width",""+r),e.setAttribute("height",""+a),e.setAttribute("viewBox",""+i),this.convertToDataUrl(e,r,a)})).then((t=>this.triggerDownload(t,e))).catch((()=>{console.log("Failed to save chart as PNG image")}))}}class Ni extends xi{copyStylesInline(t,n,i){return new Promise((r=>{Promise.all(t.map((t=>function(t,n){return fetch(t,n).then(e)}(t)))).then((t=>{t.forEach((t=>{t=t.replace(new RegExp("."+i+" ","g"),"");let e=document.createElementNS("http://www.w3.org/2000/svg","style");e.appendChild(document.createTextNode(t)),n.prepend(e)})),n.classList.add("wt-global"),r(n)}))}))}convertToObjectUrl(t){return new Promise((e=>{let n=(new XMLSerializer).serializeToString(t),i=window.URL||window.webkitURL||window,r=new Blob([n],{type:"image/svg+xml;charset=utf-8"}),a=i.createObjectURL(r),o=new Image;o.onload=()=>{e(a)},o.src=a}))}cloneSvg(t){return new Promise((e=>{e(t.cloneNode(!0))}))}svgToImage(t,e,n,i){this.cloneSvg(t.get().node()).then((t=>this.copyStylesInline(e,t,n))).then((t=>this.convertToObjectUrl(t))).then((t=>this.triggerDownload(t,i))).catch((()=>{console.log("Failed to save chart as SVG image")}))}}class Ai{constructor(){this._exportClass=null}setExportClass(t){switch(t){case"png":this._exportClass=bi;break;case"svg":this._exportClass=Ni}}createExport(t){switch(this.setExportClass(t),t){case"png":case"svg":return new this._exportClass}}}class ki{constructor(t,e){this._element=t.append("svg"),this._defs=new vi(this._element),this._visual=null,this._zoom=null,this._configuration=e,this.init()}init(){this._element.attr("width","100%").attr("height","100%").attr("text-rendering","optimizeLegibility").attr("text-anchor","middle").attr("xmlns:xlink","https://www.w3.org/1999/xlink")}initEvents(t){this._element.on("contextmenu",(t=>t.preventDefault())).on("wheel",(e=>{e.ctrlKey||t.show(this._configuration.labels.zoom,300,(()=>{t.hide(200,600)}))})).on("touchend",(e=>{e.touches.length<2&&t.hide(0,600)})).on("touchmove",(e=>{e.touches.length>=2?t.hide():t.show(this._configuration.labels.move)})).on("click",(t=>this.doStopPropagation(t)),!0),this._configuration.rtl&&this._element.classed("rtl",!0),this._visual=this._element.append("g"),this._zoom=new wi(this._visual),this._element.call(this._zoom.get())}doStopPropagation(t){t.defaultPrevented&&t.stopPropagation()}export(t){return(new Ai).createExport(t)}get defs(){return this._defs}get zoom(){return this._zoom}get visual(){return this._visual}get(){return this._element}}class Ei{constructor(t){this._element=t.append("div").attr("class","overlay").style("opacity",1e-6)}show(t,e=0,n=null){this._element.select("p").remove(),this._element.append("p").attr("class","tooltip").text(t),this._element.transition().duration(e).style("opacity",1).on("end",(()=>{"function"==typeof n&&n()}))}hide(t=0,e=0){this._element.transition().delay(t).duration(e).style("opacity",1e-6)}get(){return this._element}}let Mi=null;function $i(t,e,n,i=400){null===Mi&&(Mi=document.createElement("canvas"));const r=Mi.getContext("2d"),a=`${i||""} ${n} ${e}`;return r.font!==a&&(r.font=a),r.measureText(t).width}class zi{constructor(t,e,n,i){this._svg=t,this._orientation=e,this._image=n,this._text=i}appendName(t){const e=t.append("g").attr("class","name");if(this._orientation instanceof li||this._orientation instanceof ci){const t=this,n=e.selectAll("text").data((t=>[{data:t.data,isRtl:t.data.data.isNameRtl,isAltRtl:t.data.data.isAltRtl,withImage:!0}])).enter();n.each((function(e){const n=Se(this),i=t.createNamesData(e),r=t.getAvailableWidth(e);i.forEach(((e,i)=>{const a=n.append("text").attr("class","wt-chart-box-name").attr("direction",(t=>t.isRtl?"rtl":"ltr")).attr("text-anchor","middle").attr("alignment-baseline","central").attr("y",t._text.y-5+20*i);t.addNameElements(a,t.truncateNamesData(a,e,r))}))})),this._svg._configuration.showAlternativeName&&n.filter((t=>""!==t.data.data.alternativeName)).call((t=>{const e=t.append("text").classed("wt-chart-box-name-alt",!0).attr("class","wt-chart-box-name").attr("direction",(t=>t.isAltRtl?"rtl":"ltr")).attr("text-anchor","middle").attr("alignment-baseline","central").attr("y",this._text.y+40);this.addNameElements(e,(t=>this.truncateNamesData(e,this.createAlternativeNamesData(t),this.getAvailableWidth(t))))}))}else{const t=e.selectAll("text").data((t=>[{data:t.data,isRtl:t.data.data.isNameRtl,isAltRtl:t.data.data.isAltRtl,withImage:""!==t.data.data.thumbnail}])).enter();t.call((t=>{const e=t.append("text").attr("class","wt-chart-box-name").attr("direction",(t=>t.isRtl?"rtl":"ltr")).attr("text-anchor",(t=>t.isRtl&&this._orientation.isDocumentRtl?"start":t.isRtl||this._orientation.isDocumentRtl?"end":"start")).attr("x",(t=>this.textX(t))).attr("y",this._text.y-10);this.addNameElements(e,(t=>{const[n,...i]=this.createNamesData(t),r=[].concat(n,void 0!==i[0]?i[0]:[]);return this.truncateNamesData(e,r,this.getAvailableWidth(t))}))})),this._svg._configuration.showAlternativeName&&t.filter((t=>""!==t.data.data.alternativeName)).call((t=>{const e=t.append("text").classed("wt-chart-box-name-alt",!0).attr("class","wt-chart-box-name").attr("direction",(t=>t.isAltRtl?"rtl":"ltr")).attr("text-anchor",(t=>t.isAltRtl&&this._orientation.isDocumentRtl?"start":t.isAltRtl||this._orientation.isDocumentRtl?"end":"start")).attr("x",(t=>this.textX(t))).attr("y",this._text.y+8);this.addNameElements(e,(t=>this.truncateNamesData(e,this.createAlternativeNamesData(t),this.getAvailableWidth(t))))}))}}getAvailableWidth(t){let e=this._text.width;return t.withImage&&(this._orientation instanceof pi||this._orientation instanceof gi)&&(e-=this._image.width),e}addNameElements(t,e){t.selectAll("tspan").data(e).enter().call((t=>{t.append("tspan").text((t=>t.label)).attr("dx",((t,e)=>0!==e?.25*(t.isNameRtl?-1:1)+"em":null)).classed("preferred",(t=>t.isPreferred)).classed("lastName",(t=>t.isLastName))}))}createNamesData(t){let e={},n={},i={},r=Number.MAX_SAFE_INTEGER,a=Number.MAX_SAFE_INTEGER,o=0;for(let e in t.data.data.firstNames){const i=t.data.data.name.indexOf(t.data.data.firstNames[e],o);-1!==i&&(o=i,i({label:e,isPreferred:!1,isLastName:!1,isNameRtl:t.data.data.isAltRtl})))),n}truncateNames(t,e,n,i){let r=t.map((t=>t.label)).join(" ");return t.reverse().map((a=>(!1===a.isPreferred&&!1===a.isLastName&&this.measureText(r,e,n)>i&&(a.label=a.label.slice(0,1)+".",r=t.map((t=>t.label)).join(" ")),a))).map((a=>(!0===a.isPreferred&&this.measureText(r,e,n)>i&&(a.label=a.label.slice(0,1)+".",r=t.map((t=>t.label)).join(" ")),a))).map((a=>(!0===a.isLastName&&this.measureText(r,e,n)>i&&(a.label=a.label.slice(0,1)+".",r=t.map((t=>t.label)).join(" ")),a))).reverse()}textX(t){const e=this._text.x+(t.withImage?this._image.width:0);return this._orientation.isDocumentRtl?-e:e}measureText(t,e,n=400){return $i(t,this._svg.get().style("font-family"),e,n)}}let Ti=class{constructor(t,e,n,i){this._svg=t,this._orientation=e,this._image=n,this._text=i}appendDate(t){const e=t.append("g").attr("class","table");if(this._orientation instanceof li||this._orientation instanceof ci){const t=e.selectAll("text.date").data((t=>[{label:t.data.data.timespan,withImage:!0}])).enter();let n=this._text.y+45;this._svg._configuration.showAlternativeName&&(n+=30);const i=t.append("text").attr("class","date").attr("text-anchor","middle").attr("alignment-baseline","central").attr("y",n);i.append("title").text((t=>t.label));const r=i.append("tspan");r.text((t=>this.truncateDate(r,t.label,this._text.width)))}else e.selectAll("text").data((t=>{let e=[];return t.data.data.birth&&e.push({icon:"★",label:t.data.data.birth,birth:!0,withImage:""!==t.data.data.thumbnail}),t.data.data.death&&e.push({icon:"†",label:t.data.data.death,death:!0,withImage:""!==t.data.data.thumbnail}),e})).enter().call((t=>{t.append("text").attr("fill","currentColor").attr("text-anchor","middle").attr("dominant-baseline","middle").attr("x",(t=>this.textX(t))).attr("y",((t,e)=>this._text.y+30+(0===e?0:21))).append("tspan").text((t=>t.icon)).attr("dx",5*(this._orientation.isDocumentRtl?-1:1));const e=t.append("text").attr("class","date").attr("text-anchor","start").attr("dominant-baseline","middle").attr("x",(t=>this.textX(t))).attr("y",((t,e)=>this._text.y+30+(0===e?0:20)));e.append("title").text((t=>t.label));const n=e.append("tspan");n.text((t=>this.truncateDate(n,t.label,this._text.width-(t.withImage?this._image.width:0)-25))).attr("dx",15*(this._orientation.isDocumentRtl?-1:1))}))}truncateDate(t,e,n){const i=t.style("font-size"),r=t.style("font-weight");let a=!1;for(;this.measureText(e,i,r)>n&&e.length>1;)e=e.slice(0,-1).trim(),a=!0;return"."===e[e.length-1]&&(e=e.slice(0,-1).trim()),a?e+"…":e}textX(t){const e=this._text.x+(t.withImage?this._image.width:0);return this._orientation.isDocumentRtl?-e:e}measureText(t,e,n=400){return $i(t,this._svg.get().style("font-family"),e,n)}},Ri=class{constructor(t,e){this._orientation=t,this._cornerRadius=e,this._imagePadding=5,this._imageRadius=Math.min(40,this._orientation.boxHeight/2-this._imagePadding),this._width=this.calculateImageWidth(),this._height=this.calculateImageHeight(),this._rx=this.calculateCornerRadius(),this._ry=this.calculateCornerRadius(),this._x=this.calculateX(),this._y=this.calculateY()}calculateX(){return this._orientation instanceof pi||this._orientation instanceof gi?this._orientation.isDocumentRtl?this._width-this._imagePadding:-(this._orientation.boxWidth-this._imagePadding)/2+this._imagePadding:-this._orientation.boxWidth/2+this._width/2}calculateY(){return this._orientation instanceof pi||this._orientation instanceof gi?-this._imageRadius:-(this._orientation.boxHeight-this._imagePadding)/2+this._imagePadding}calculateImageWidth(){return 2*this._imageRadius}calculateImageHeight(){return 2*this._imageRadius}calculateCornerRadius(){return this._cornerRadius-this._imagePadding}get x(){return this._x}get y(){return this._y}get rx(){return this._rx}get ry(){return this._ry}get width(){return this._width}get height(){return this._height}};class Si{constructor(t,e=null){this._orientation=t,this._image=e,this._textPaddingX=15,this._textPaddingY=15,(this._orientation instanceof li||this._orientation instanceof ci)&&(this._textPaddingX=5,this._textPaddingY=15),this._x=this.calculateX(),this._y=this.calculateY(),this._width=this.calculateWidth()}calculateX(){return-this._orientation.boxWidth/2+this._textPaddingX}calculateY(){return this._orientation instanceof pi||this._orientation instanceof gi?-this._textPaddingY:this._image.y+this._image.height+2*this._textPaddingY}calculateWidth(){return this._orientation.boxWidth-2*this._textPaddingX}get x(){return this._x}get y(){return this._y}get width(){return this._width}}class Pi{constructor(t,e,n){this._svg=t,this._hierarchy=e,this._configuration=n,this._orientation=this._configuration.orientation,this._image=new Ri(this._orientation,20),this._text=new Si(this._orientation,this._image),this._name=new zi(this._svg,this._orientation,this._image,this._text),this._date=new Ti(this._svg,this._orientation,this._image,this._text)}drawNodes(t,e){this._svg.defs.get().append("clipPath").attr("id","clip-image").append("rect").attr("rx",this._image.rx).attr("ry",this._image.ry).attr("x",this._image.x).attr("y",this._image.y).attr("width",this._image.width).attr("height",this._image.height),this._svg.visual.selectAll("g.person").data(t,(t=>t.id)).join((t=>this.nodeEnter(t,e)),(t=>this.nodeUpdate(t)),(t=>this.nodeExit(t,e))),this._hierarchy.root.eachBefore((t=>{t.x0=t.x,t.y0=t.y}))}nodeEnter(t,e){t.append("g").attr("opacity",0).attr("class",(t=>"person"+(t.data.spouse?" spouse":""))).attr("transform",(t=>"translate("+t.x+","+t.y+")")).call((t=>{t.append("rect").attr("class",(t=>"F"===t.data.data.sex?"female":t.data.data.sex===oi?"male":"unknown")).attr("rx",20).attr("ry",20).attr("x",-this._orientation.boxWidth/2).attr("y",-this._orientation.boxHeight/2).attr("width",this._orientation.boxWidth).attr("height",this._orientation.boxHeight).attr("fill-opacity",.5),t.append("title").text((t=>t.data.data.name))})).call((t=>this.drawNode(t))).call((t=>t.transition().duration(this._configuration.duration).attr("opacity",1)))}nodeUpdate(t){t.call((t=>t.transition().duration(this._configuration.duration).attr("opacity",1).attr("transform",(t=>"translate("+t.x+","+t.y+")"))))}nodeExit(t,e){t.call((t=>t.transition().duration(this._configuration.duration).attr("opacity",0).attr("transform",(()=>"translate("+e.x0+","+e.y0+")")).remove()))}drawNode(t){const e=t.selectAll("g.image").data((t=>{let e=[];return t.data.data.thumbnail&&e.push({image:t.data.data.thumbnail}),e})).enter().append("g").attr("class","image");e.append("rect").attr("x",this._image.x).attr("y",this._image.y).attr("width",this._image.width).attr("height",this._image.height).attr("rx",this._image.rx).attr("ry",this._image.ry).attr("fill","rgb(255, 255, 255)"),e.append("image").attr("x",this._image.x).attr("y",this._image.y).attr("width",this._image.width).attr("height",this._image.height).attr("clip-path","url(#clip-image)"),e.append("rect").attr("x",this._image.x).attr("y",this._image.y).attr("width",this._image.width).attr("height",this._image.height).attr("rx",this._image.rx).attr("ry",this._image.ry).attr("fill","none").attr("stroke","rgb(200, 200, 200)").attr("stroke-width",1.5),function(t){return"string"==typeof t?new Te([document.querySelectorAll(t)],[document.documentElement]):new Te([$t(t)],ze)}("g.image image").each((function(t){let e=Se(this);(function(t,e=null){return fetch(t,e).then((t=>t.blob())).then((t=>new Promise(((e,n)=>{const i=new FileReader;i.onloadend=()=>e(i.result),i.onerror=n,i.readAsDataURL(t)}))))})(t.image).then((t=>e.attr("xlink:href",t))).catch((t=>{console.error(t)}))})),this._name.appendName(t),this._date.appendDate(t)}}class Ci{constructor(t,e){this._svg=t,this._configuration=e,this._orientation=this._configuration.orientation}drawLinks(t,e){this._svg.visual.selectAll("path.link").data(t).join((t=>this.linkEnter(t,e)),(t=>this.linkUpdate(t)),(t=>this.linkExit(t,e)))}linkEnter(t,e){t.append("path").classed("link",!0).attr("d",(t=>this._orientation.elbow(t))).call((t=>t.transition().duration(this._configuration.duration).attr("opacity",1)))}linkUpdate(t){}linkExit(t,e){}}class Di{constructor(t,e,n){this._svg=t,this._configuration=e,this._hierarchy=n,this._hierarchy.root.x0=0,this._hierarchy.root.y0=0,this._orientation=this._configuration.orientation,this._nodeDrawer=new Pi(this._svg,this._hierarchy,this._configuration),this._linkDrawer=new Ci(this._svg,this._configuration),this.draw(this._hierarchy.root)}draw(t){const e=this._hierarchy.root.descendants(),n=this._hierarchy.nodes.links();this._linkDrawer.drawLinks(n,t),this._nodeDrawer.drawNodes(e,t)}centerTree(){console.log("centerTree")}togglePerson(t,e){e.parents?(e._parents=e.parents,e.parents=null):(e.parents=e._parents,e._parents=null),this.draw(e)}collapse(t){t.parents&&(t._parents=t.parents,t._parents.forEach((t=>this.collapse(t))),t.parents=null)}}class Oi{constructor(t,e){this._configuration=e,this._parent=t,this._hierarchy=new yi(this._configuration),this._data={}}get svg(){return this._svg}updateViewBox(){let t=this._svg.visual.node().getBBox(),e=this._parent.node().getBoundingClientRect(),n=Math.max(e.width,t.width),i=Math.max(e.height,t.height,300),r=(n-t.width)/2,a=(i-t.height)/2,o=Math.ceil(t.x-r-10),s=Math.ceil(t.y-a-10);n=Math.ceil(n+20),i=Math.ceil(i+20),this._svg.get().attr("viewBox",[o,s,n,i])}get data(){return this._data}set data(t){this._data=t,this._hierarchy.init(this._data)}draw(){this._parent.html(""),this._svg=new ki(this._parent,this._configuration),this._overlay=new Ei(this._parent),this._svg.initEvents(this._overlay),new Di(this._svg,this._configuration,this._hierarchy),this.bindClickEventListener(),this.updateViewBox()}bindClickEventListener(){let t=this;this._svg.visual.selectAll("g.person").filter((t=>""!==t.data.data.xref)).each((function(e){Se(this).on("click",(function(){t.personClick(e.data)}))}))}personClick(t){1===t.data.generation?this.redirectToIndividual(t.data.url):this.update(t.data.updateUrl)}redirectToIndividual(t){this._configuration.openNewTabOnClick?window.open(t,"_blank"):window.location=t}update(t){window.location=t}}t.PedigreeChart=class{constructor(t,e){this._selector=t,this._parent=Se(this._selector),this._configuration=new mi(e.labels,e.generations,e.showEmptyBoxes,e.treeLayout,e.openNewTabOnClick,e.showAlternativeName,e.rtl),this._cssFiles=e.cssFiles,this._chart=new Oi(this._parent,this._configuration),this.init(),this.draw(e.data)}init(){Se("#centerButton").on("click",(()=>this.center())),Se("#exportPNG").on("click",(()=>this.exportPNG())),Se("#exportSVG").on("click",(()=>this.exportSVG()))}center(){this._chart.svg.get().transition().duration(750).call(this._chart.svg.zoom.get().transform,Gn)}get configuration(){return this._configuration}update(t){this._chart.update(t)}draw(t){this._chart.data=t,this._chart.draw()}exportPNG(){this._chart.svg.export("png").svgToImage(this._chart.svg,"pedigree-chart.png")}exportSVG(){this._chart.svg.export("svg").svgToImage(this._chart.svg,this._cssFiles,"webtrees-pedigree-chart-container","pedigree-chart.svg")}}},"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).WebtreesPedigreeChart={}); diff --git a/src/Processor/NameProcessor.php b/src/Processor/NameProcessor.php index 7abda59..1cd9924 100644 --- a/src/Processor/NameProcessor.php +++ b/src/Processor/NameProcessor.php @@ -12,6 +12,7 @@ namespace MagicSunday\Webtrees\PedigreeChart\Processor; use DOMDocument; +use DOMNode; use DOMXPath; use Fisharebest\Webtrees\Individual; @@ -20,7 +21,7 @@ * * @author Rico Sonntag * @license https://opensource.org/licenses/GPL-3.0 GNU General Public License v3.0 - * @link https://github.com/magicsunday/webtrees-module-base/ + * @link https://github.com/magicsunday/webtrees-pedigree-chart/ */ class NameProcessor { @@ -34,6 +35,17 @@ class NameProcessor */ private const FULL_NAME = 'full'; + /** + * The XPath identifier to extract the first name parts (including the prefix). + */ + private const XPATH_FIRST_NAMES + = './/text()[count(.|(//span[@class="SURN"]/text() | //span[@class="SURN"]/following::text()))!=count((//span[@class="SURN"]/text() | //span[@class="SURN"]/following::text()))]'; + + /** + * The XPath identifier to extract the last name parts (surname + surname suffix). + */ + private const XPATH_LAST_NAMES = '//span[@class="NAME"]//span[@class="SURN"]/text()|//span[@class="SURN"]/following::text()'; + /** * The XPath identifier to extract the starred name part. */ @@ -97,7 +109,7 @@ private function getDomXPathInstance(string $input): DOMXPath /** * Extracts the primary name from the individual. * - * @param Individual|null $spouse + * @param null|Individual $spouse * @param bool $useMarriedName TRUE to return the married name instead of the primary one * * @return array @@ -164,36 +176,65 @@ private function replacePlaceholders(string $value): string ); } + /** + * Returns the full name of the individual without formatting of the individual parts of the name. + * All placeholders were removed as we do not need them in this module. + * + * @return string + */ + public function getFullName(): string + { + // The name of the person without formatting of the individual parts of the name. + // Remove placeholders as we do not need them in this module + return $this->replacePlaceholders($this->primaryName[self::FULL_NAME_WITH_PLACEHOLDERS]); + } + /** * Splits a name into an array, removing all name placeholders. * - * @param string $name + * @param string[] $names * * @return string[] */ - private function splitAndCleanName(string $name): array + private function splitAndCleanName(array $names): array { + $values = [[]]; + + foreach ($names as $name) { + $values[] = explode(' ', $name); + } + + // Remove empty values and reindex array return array_values( array_filter( - explode( - ' ', - $this->replacePlaceholders($name) - ) + array_merge(...$values) ) ); } /** - * Returns the full name of the individual without formatting of the individual parts of the name. - * All placeholders were removed as we do not need them in this module. + * Returns all name parts by given identifier. * - * @return string + * @param string $expression The XPath expression to execute + * + * @return string[] */ - public function getFullName(): string + private function getNamesByIdentifier(string $expression): array { - // The name of the person without formatting of the individual parts of the name. - // Remove placeholders as we do not need them in this module - return $this->replacePlaceholders($this->primaryName[self::FULL_NAME_WITH_PLACEHOLDERS]); + $nodeList = $this->xPath->query($expression); + $names = []; + + if ($nodeList !== false) { + /** @var DOMNode $node */ + foreach ($nodeList as $node) { + $names[] = $node->nodeValue ?? ''; + } + } + + // Remove all leading/trailing whitespace characters + $names = array_map('trim', $names); + + return $this->splitAndCleanName($names); } /** @@ -203,7 +244,7 @@ public function getFullName(): string */ public function getFirstNames(): array { - return $this->splitAndCleanName($this->primaryName['givn']); + return $this->getNamesByIdentifier(self::XPATH_FIRST_NAMES); } /** @@ -213,7 +254,7 @@ public function getFirstNames(): array */ public function getLastNames(): array { - return $this->splitAndCleanName($this->primaryName['surn']); + return $this->getNamesByIdentifier(self::XPATH_LAST_NAMES); } /** @@ -247,7 +288,7 @@ public function getAlternateName(Individual $individual): string $individual->canShowName() && ($individual->getPrimaryName() !== $individual->getSecondaryName()) ) { - $allNames = $individual->getAllNames(); + $allNames = $individual->getAllNames(); $alternativeName = $allNames[$individual->getSecondaryName()][self::FULL_NAME_WITH_PLACEHOLDERS]; return $this->replacePlaceholders($alternativeName);