3 lines
104 KiB
JavaScript
3 lines
104 KiB
JavaScript
// https://donatso.github.io/family-chart/ v0.9.0 Copyright 2025 donatso
|
|||
|
|
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("d3")):"function"==typeof define&&define.amd?define(["exports","d3"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).f3={},e.d3)}(this,function(e,t){"use strict";function n(e){var t=Object.create(null);return e&&Object.keys(e).forEach(function(n){if("default"!==n){var i=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,i.get?i:{enumerable:!0,get:function(){return e[n]}})}}),t.default=e,Object.freeze(t)}var i=n(t);function r(e,t,n){return n.find(n=>n.id!==t.id&&e.rels.parents.includes(n.id))}function s(e,t,n){if(e.exiting=n,t)if(0!==e.depth||e.spouse)if(e.spouse)e._x=e.spouse.x,e._y=e.spouse.y;else if(e.is_ancestry){if(!e.parent)throw new Error("no parent");e._x=e.parent.x,e._y=e.parent.y}else e._x=e.psx,e._y=e.psy;else e._x=e.x,e._y=e.y;else if(n){const t=e.x>0?1:-1,n=e.y>0?1:-1;e._x=e.x+400*t,e._y=e.y+400*n}}function a({tree:e,data_stash:t,private_cards_config:n}){const i={},r=n.condition;if(!r)return console.error("private_cards_config.condition is not set");e.forEach(e=>{if(e.data._new_rel_data)return;const n=function(e){const n=[];let s=!1;return a(e),i[e]=s,s;function a(e){if(s)return;if(i.hasOwnProperty(e))return s=i[e],s;const o=t.find(t=>t.id===e);if(!o)throw new Error("no d");if(o._new_rel_data)return;if(r(o))return s=!0,!0;const d=o.rels;[...d.parents,...d.spouses||[]].forEach(e=>{e&&(n.includes(e)||(n.push(e),a(e)))})}}(e.data.id);n&&(e.is_private=n)})}function o(e,t){const n=t.find(t=>t.id===e);if(!n)throw new Error("no datum");const r=i.hierarchy(n,e=>function(e){return e.rels.parents.filter(e=>e).map(e=>t.find(t=>t.id===e)).filter(e=>e&&!e._new_rel_data&&!e.to_add)}(e)),s=i.hierarchy(n,e=>function(e){return[...e.rels.children||[]].map(e=>t.find(t=>t.id===e)).filter(e=>e&&!e._new_rel_data&&!e.to_add)}(e));return{ancestry:r.height,progeny:s.height}}function d({data:e,rels:t}){return{id:(n=(new Date).getTime(),i=performance&&performance.now&&1e3*performance.now()||0,"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random();return n>0?(t=(n+t)%16|0,n=Math.floor(n/16)):(t=(i+t)%16|0,i=Math.floor(i/16)),("x"===e?t:3&t|8).toString(16)})),data:e||{},rels:Object.assign({parents:[],children:[],spouses:[]},t||{})};var n,i}function l(e,t){const n=e.data.rels;return[...n.parents,...n.spouses||[],...n.children||[]].filter(e=>e).every(e=>t.some(t=>t.data.id===e))}function c(e,t,n){const i=.4*n,r=Math.max(...e.data.map(e=>e.is_ancestry?e.depth:0));let s=t.depth*i;return 0===t.depth&&!t.spouse||t.is_ancestry||(s+=r*i,t.spouse&&(s+=i),s+=t.depth*i),s}function u(e,t,n=!0){const i=[];function r(e,t){return e.every(e=>t.some(t=>e.id===t.id))}function s(e){const t={},n=e;return(e.children||[]).forEach(e=>{const i=e.data.rels,r=i.parents[0]===n.data.id?i.parents[1]:i.parents[0];t[r]||(t[r]=[]),t[r].push(e)}),t}!function a(o){if(!o.children)return;const d=o.data,l=(o.data.rels.spouses||[]).map(e=>t.find(t=>t.id===e)),c=s(o);l.forEach(l=>{if(i.some(e=>e.some(e=>r([d,l],[e.p1,e.p2]))))return;const u=function(n,i,a){const o=[];return d(e),o;function d(e){if(e!==n&&e.children){const n=e.data,l=(e.data.rels.spouses||[]).map(e=>t.find(t=>t.id===e)),c=s(e);l.forEach(t=>{r([i,a],[n,t])?o.push({d:e,p1:n,p2:t}):(c[t.id]||[]).forEach(e=>{d(e)})})}}}(o,d,l);if(u.length>0){const t=[{d:o,p1:d,p2:l},...u];i.push(t),function(t){if(t.forEach(({d:n,p1:i,p2:r},s)=>{n.data._tgdp_sp||(n.data._tgdp_sp={});let a=e===n?"main":n.parent.data.id;!function(e,t,n){e.data.__tgdp_sp&&e.data.__tgdp_sp[t]&&e.data.__tgdp_sp[t].hasOwnProperty(n.id)&&(e.data._tgdp_sp[t][n.id]=e.data.__tgdp_sp[t][n.id],delete e.data.__tgdp_sp[t][n.id])}(n,a,r),n.data._tgdp_sp[a]||(n.data._tgdp_sp[a]={});let o=1;n.data._tgdp_sp[a].hasOwnProperty(r.id)?o=n.data._tgdp_sp[a][r.id]:n.data._tgdp_sp[a][r.id]=o,t[s].val=o}),n){if(t.every(e=>e.val<0)){const n=t.sort((e,t)=>t.val-e.val)[0],{d:i,p1:r,p2:s}=n,a=e===i?"main":i.parent.data.id;i.data._tgdp_sp[a][s.id]=1}if(t.filter(e=>e.val>0).length>1){const n=t.sort((e,t)=>t.val-e.val)[0];t.forEach(t=>{if(
|