@qe-libs/qeviz 0.5.6 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/qeviz.umd.js CHANGED
@@ -1,11 +1,11 @@
1
- (function(S,B){typeof exports=="object"&&typeof module<"u"?B(exports):typeof define=="function"&&define.amd?define(["exports"],B):(S=typeof globalThis<"u"?globalThis:S||self,B(S.QEViz={}))})(this,(function(S){"use strict";var Li=Object.defineProperty;var ri=S=>{throw TypeError(S)};var _=(S,B)=>Li(S,"name",{value:B,configurable:!0});var oi=(S,B,dt)=>B.has(S)||ri("Cannot "+dt);var C=(S,B,dt)=>(oi(S,B,"read from private field"),dt?dt.call(S):B.get(S)),nt=(S,B,dt)=>B.has(S)?ri("Cannot add the same private member more than once"):B instanceof WeakSet?B.add(S):B.set(S,dt),W=(S,B,dt,Ct)=>(oi(S,B,"write to private field"),Ct?Ct.call(S,dt):B.set(S,dt),dt);var me,pe,be,bt,ye,xe,yt,Ht,Pt,Mt,ht,we,Ft,It,Vt,Kt,Me;const rs=class rs extends Array{constructor(e,s,i,n,r){super(...s);nt(this,me);nt(this,pe);nt(this,be);nt(this,bt);nt(this,ye);W(this,be,e),W(this,pe,i),W(this,bt,n),W(this,ye,n==null?void 0:n.classes),W(this,me,r)}get parent(){return C(this,bt)}get names(){return C(this,be)}get rowName(){return C(this,pe)}get types(){if(!C(this,bt))throw new Error("No parent DataFrame attached to this row.");return C(this,bt).types}get classes(){return C(this,ye)}get rowNumber(){return C(this,me)}col(e){if(!C(this,bt))throw new Error("No parent DataFrame attached to this row.");return C(this,bt).col(e)}cols(...e){if(!C(this,bt))throw new Error("No parent DataFrame attached to this row.");return C(this,bt).cols(...e)}filter(e){console.error("DataFrameRow does not currently support filtering.")}};me=new WeakMap,pe=new WeakMap,be=new WeakMap,bt=new WeakMap,ye=new WeakMap,_(rs,"DataFrameRow");let B=rs;var dt=(d=>(d.Character="character",d.Double="double",d.Logical="logical",d.Integer="integer",d))(dt||{});const os=class os extends Array{constructor(e,s,i,n){super(s.length);nt(this,xe);nt(this,yt);nt(this,Ht);nt(this,Pt);for(let r=0;r<s.length;r++)this[r]=s[r];if(W(this,xe,e),s.type!==void 0?W(this,yt,s.type):s.every(r=>typeof r=="string"||r===null||r===void 0)?W(this,yt,"character"):s.every(r=>Number.isInteger(r)||r===null||r===void 0)?s.every(r=>r===0||r===1||r===null||r===void 0)?W(this,yt,"logical"):W(this,yt,"integer"):s.every(r=>typeof r=="number"||r===null||r===void 0)?W(this,yt,"double"):s.every(r=>typeof r=="boolean"||r===null||r===void 0)?W(this,yt,"logical"):W(this,yt,"character"),W(this,Pt,n),i&&i.length!==this.length)throw new Error("Row names length must match the number of rows in the DataFrameColumn.");i&&i.length>0?W(this,Ht,i):W(this,Ht,void 0)}get name(){return C(this,xe)}get type(){return C(this,yt)}get rowNames(){return C(this,Ht)}row(e){if(!C(this,Pt))throw new Error("No parent DataFrame attached to this column.");return C(this,Pt).row(e)}rows(...e){if(!C(this,Pt))throw new Error("No parent DataFrame attached to this column.");return C(this,Pt).rows(...e)}};xe=new WeakMap,yt=new WeakMap,Ht=new WeakMap,Pt=new WeakMap,_(os,"DataFrameColumn");let Ct=os;const Ae=class Ae extends Array{constructor(e,s,i,n){if((!e||!s)&&(s=[],e=[]),s.map(r=>r.length).every(r=>r===e.length)){const r=[];for(let a=0;a<e.length;a++){const h=[];for(let o=0;o<s.length;o++)h.push(s[o][a]);r.push(h)}s=r}super(s.length);nt(this,Mt);nt(this,ht);nt(this,we);if(s.forEach((r,a)=>{r instanceof Ct?this[a]=r:this[a]=new Ct(e[a],r,i,this)}),W(this,Mt,e),i&&this[0]&&i.length!==this[0].length)throw new Error("Row names length must match the number of rows in the DataFrame.");if(i&&i.length>0&&W(this,ht,i),n&&n.length!==this.length)throw new Error("Classes length must match the number of columns in the DataFrame.");n&&n.length>0&&W(this,we,n)}get classes(){return C(this,we)}getColumnByName(e){const s=C(this,Mt).indexOf(e);return s>=0?this[s]:void 0}getRowByIndex(e){if(this&&this.length===0)return console.warn("DataFrame is empty, cannot get row by index",e),new B(C(this,Mt),[],void 0,this,e);const s=[];for(let i of this){let n=i[e];s.push(n)}return new B(C(this,Mt),s,C(this,ht)?C(this,ht)[e]:void 0,this,e)}getRowByName(e){if(!C(this,ht))return;const s=C(this,ht).indexOf(e);if(s!==-1)return this.getRowByIndex(s)}get types(){return this.map(e=>e.type)}type(e){var s;if(typeof e=="number")return(s=this[e])==null?void 0:s.type;if(typeof e=="string"){const i=this.getColumnByName(e);return i?i.type:void 0}}row(e){if(typeof e=="number")return this.getRowByIndex(e);if(typeof e=="string")return this.getRowByName(e)}rows(...e){let s,i=[],n=[];if(e.length===0){if(!this[0]||this.length===0)return[];const r=this[0].length;i=Array.from({length:r},(a,h)=>this.getRowByIndex(h)),n=C(this,ht)}else e.length===1&&Array.isArray(e[0])?s=e[0]:s=e,i=s.map((r,a)=>{let h=this.row(r);return C(this,ht)&&h&&(n==null||n.push(C(this,ht)[a])),h}).filter(r=>r!==void 0);return i}col(e){if(typeof e=="number")return this[e];if(typeof e=="string")return this.getColumnByName(e)}cols(...e){let s,i,n=[];return e.length===0?(i=this.slice(),n=C(this,Mt)):(e.length===1&&Array.isArray(e[0])?s=e[0]:s=e,i=s.map(r=>this.col(r)).filter(r=>r!==void 0),n=i.map(r=>r.name)),new Ae(n,i,C(this,ht))}subset(e,s){const i=s&&s.length>0?this.cols(...s):this.slice();return new Ae(i.map(n=>n.name),i.map(n=>n.values),C(this,ht))}get names(){return C(this,Mt)}get rowNames(){return C(this,ht)}get nrow(){return this[0]?this[0].length:0}get ncol(){return this.length}};Mt=new WeakMap,ht=new WeakMap,we=new WeakMap,_(Ae,"DataFrame");let Lt=Ae;const as=class as{constructor(t={}){this.unit_id_col="id",this.node_id_col="id",this.group_col=null,this.directed=!1,this.palette=[],this._points=t.points??new Lt,this._nodes=t.nodes??new Lt,this._edges=t.edges??new Lt,this._dimensions=t.dimensions??[],this._confidence=void 0,this._outlier=void 0,this._groups=void 0}get updated(){return this._updated}set updated(t){this._updated=t}get points(){return this._points}set points(t){this._points=t}get nodes(){return this._nodes}set nodes(t){this._nodes=t}get edges(){return this._edges}set edges(t){this._edges=t}get confidence(){return this._confidence}set confidence(t){this._confidence=t}get outlier(){return this._outlier}set outlier(t){this._outlier=t}get groups(){return this._groups}set groups(t){this._groups=t}get trajectories(){return this._trajectories}set trajectories(t){this._trajectories=t}get networks(){return this._networks}set networks(t){this._networks=t}get pointsets(){return this._pointsets}set pointsets(t){this._pointsets=t}get dimensions(){return this._dimensions}set dimensions(t){this._dimensions=t}get params(){return this._params}set params(t){this._params=t}point(t){return this._points.row(t)}setByKey(t,e){this[t]=e}};_(as,"Model");let Ke=as;const ai=globalThis.__QEVIZ_DEBUG__===!0;function Es(...d){ai&&console.log(...d)}_(Es,"dbg");const hi={get:_(d=>{const t=[...document.querySelectorAll("qe-graph")];return typeof d=="number"&&d>=0?t[d]:t},"get")},Xt=class Xt extends HTMLElement{constructor(){super(),this._isVisible=!0,this.output="",this._updated="",this._active_points=[],this._points=new Map,this._edges=new Map,this._labels=new Map,this._model=new Ke;const t=this.attachShadow({mode:"open"}),e=document.createElement("style");e.textContent=Xt.styles,t.appendChild(e),this._outputElement=document.createElement("div"),t.appendChild(this._outputElement)}static get observedAttributes(){return["updated"]}get model(){return this._model}get updated(){return this._updated}set updated(t){this._updated=t,this.setAttribute("updated",t),this.dispatchEvent(new CustomEvent("model-updated",{detail:this._model,bubbles:!0,composed:!0}))}get points(){return this._points}set points(t){this._points.clear(),t instanceof Map?this._points=t:Array.isArray(t)&&t.forEach(e=>this._points.set(e.ID,e))}get active_points(){return Array.from(this._active_points.values())}get edges(){return this._edges}set edges(t){this._edges.clear(),t instanceof Map?this._edges=t:Array.isArray(t)&&(this._edges=new Map,t.forEach(e=>this._edges.set(e.ID,e)))}get labels(){return this._labels}connectedCallback(){Es("QEVisualElement connected"),this.render()}setModelData(t){var r,a,h,o;["nodes","edges","points","groups","confidence","outlier","trajectories","networks","pointsets"].forEach(l=>{var v;const u=t[l];if(!((v=u==null?void 0:u.data)!=null&&v.length))return;const g=u.data,c=u.types||{},M=Object.keys(g[0]),m=g.map(j=>Object.values(j)),E=M.map(j=>c[j]??"character");let L;l==="networks"?L="name":l==="pointsets"?L="id":l==="nodes"?L=t.node_id_col??M.find(j=>(c[j]??"character")==="character"):l==="edges"||l==="points"||l==="trajectories"?L=t.id_col??M.find(j=>(c[j]??"character")==="character"):L=t.group_col??M.find(j=>(c[j]??"character")==="character");const Y=L?M.indexOf(L):0,q=m.map(j=>String(j[Y]));this._model.setByKey(l,new Lt(M,m,q,E))}),t.updated!==void 0&&this._model.setByKey("updated",t.updated),t.directed!==void 0&&(this._model.directed=t.directed),Array.isArray(t.palette)&&(this._model.palette=t.palette.map(String));const s=this._model.nodes;this._model.node_id_col=t.node_id_col??((r=s==null?void 0:s.names)==null?void 0:r.find(l=>{var u;return((u=s.col(l))==null?void 0:u.type)==="character"}))??"id";const i=this._model.points;this._model.unit_id_col=t.id_col??((a=i==null?void 0:i.names)==null?void 0:a.find(l=>{var u;return((u=i.col(l))==null?void 0:u.type)==="character"}))??"id";const n=this._model.unit_id_col;if(this._model.group_col=t.group_col??((h=i==null?void 0:i.names)==null?void 0:h.find(l=>{var u;return l!==n&&((u=i.col(l))==null?void 0:u.type)==="character"}))??null,(o=s==null?void 0:s.names)!=null&&o.length){const l=this._model.node_id_col,u=t.x_col,g=t.y_col;if(u&&g)this._model.dimensions=[u,g];else{const c=s.names.filter(M=>{if(M===l)return!1;const m=s.col(M);return m&&m.type!=="character"&&m.type!=="logical"});c.length>=2&&(this._model.dimensions=[u??c[0],g??c[1]])}}this.updated=this._model.updated!==void 0?String(this._model.updated):String(Date.now()),Es("Model updated via setModelData:",this.updated),this.render()}async calculate(){}render(){var t;this._isVisible?this.classList.remove("hidden"):this.classList.add("hidden"),((t=this._model)==null?void 0:t.updated)!==void 0&&this._model.updated!==null?this._outputElement.innerHTML=`${this.output}<slot></slot>`:this._outputElement.innerHTML="Define the model on the left."}};_(Xt,"QEVisualElement"),Xt.tagName="qe-visual",Xt.styles=`
1
+ (function(O,U){typeof exports=="object"&&typeof module<"u"?U(exports):typeof define=="function"&&define.amd?define(["exports"],U):(O=typeof globalThis<"u"?globalThis:O||self,U(O.QEViz={}))})(this,(function(O){"use strict";var Hi=Object.defineProperty;var fi=O=>{throw TypeError(O)};var c=(O,U)=>Hi(O,"name",{value:U,configurable:!0});var pi=(O,U,_t)=>U.has(O)||fi("Cannot "+_t);var R=(O,U,_t)=>(pi(O,U,"read from private field"),_t?_t.call(O):U.get(O)),nt=(O,U,_t)=>U.has(O)?fi("Cannot add the same private member more than once"):U instanceof WeakSet?U.add(O):U.set(O,_t),X=(O,U,_t,Ot)=>(pi(O,U,"write to private field"),Ot?Ot.call(O,_t):U.set(O,_t),_t);var xe,we,ve,xt,Ae,Se,wt,Kt,$t,Mt,at,Ee,qt,It,te,ee,ze;const us=class us extends Array{constructor(e,s,i,n,r){super(...s);nt(this,xe);nt(this,we);nt(this,ve);nt(this,xt);nt(this,Ae);X(this,ve,e),X(this,we,i),X(this,xt,n),X(this,Ae,n==null?void 0:n.classes),X(this,xe,r)}get parent(){return R(this,xt)}get names(){return R(this,ve)}get rowName(){return R(this,we)}get types(){if(!R(this,xt))throw new Error("No parent DataFrame attached to this row.");return R(this,xt).types}get classes(){return R(this,Ae)}get rowNumber(){return R(this,xe)}col(e){if(!R(this,xt))throw new Error("No parent DataFrame attached to this row.");return R(this,xt).col(e)}cols(...e){if(!R(this,xt))throw new Error("No parent DataFrame attached to this row.");return R(this,xt).cols(...e)}filter(e){console.error("DataFrameRow does not currently support filtering.")}};xe=new WeakMap,we=new WeakMap,ve=new WeakMap,xt=new WeakMap,Ae=new WeakMap,c(us,"DataFrameRow");let U=us;var _t=(m=>(m.Character="character",m.Double="double",m.Logical="logical",m.Integer="integer",m))(_t||{});const ds=class ds extends Array{constructor(e,s,i,n){super(s.length);nt(this,Se);nt(this,wt);nt(this,Kt);nt(this,$t);for(let r=0;r<s.length;r++)this[r]=s[r];if(X(this,Se,e),s.type!==void 0?X(this,wt,s.type):s.every(r=>typeof r=="string"||r===null||r===void 0)?X(this,wt,"character"):s.every(r=>Number.isInteger(r)||r===null||r===void 0)?s.every(r=>r===0||r===1||r===null||r===void 0)?X(this,wt,"logical"):X(this,wt,"integer"):s.every(r=>typeof r=="number"||r===null||r===void 0)?X(this,wt,"double"):s.every(r=>typeof r=="boolean"||r===null||r===void 0)?X(this,wt,"logical"):X(this,wt,"character"),X(this,$t,n),i&&i.length!==this.length)throw new Error("Row names length must match the number of rows in the DataFrameColumn.");i&&i.length>0?X(this,Kt,i):X(this,Kt,void 0)}get name(){return R(this,Se)}get type(){return R(this,wt)}get rowNames(){return R(this,Kt)}row(e){if(!R(this,$t))throw new Error("No parent DataFrame attached to this column.");return R(this,$t).row(e)}rows(...e){if(!R(this,$t))throw new Error("No parent DataFrame attached to this column.");return R(this,$t).rows(...e)}};Se=new WeakMap,wt=new WeakMap,Kt=new WeakMap,$t=new WeakMap,c(ds,"DataFrameColumn");let Ot=ds;const Me=class Me extends Array{constructor(e,s,i,n){if((!e||!s)&&(s=[],e=[]),s.map(r=>r.length).every(r=>r===e.length)){const r=[];for(let a=0;a<e.length;a++){const h=[];for(let o=0;o<s.length;o++)h.push(s[o][a]);r.push(h)}s=r}super(s.length);nt(this,Mt);nt(this,at);nt(this,Ee);if(s.forEach((r,a)=>{r instanceof Ot?this[a]=r:this[a]=new Ot(e[a],r,i,this)}),X(this,Mt,e),i&&this[0]&&i.length!==this[0].length)throw new Error("Row names length must match the number of rows in the DataFrame.");if(i&&i.length>0&&X(this,at,i),n&&n.length!==this.length)throw new Error("Classes length must match the number of columns in the DataFrame.");n&&n.length>0&&X(this,Ee,n)}get classes(){return R(this,Ee)}getColumnByName(e){const s=R(this,Mt).indexOf(e);return s>=0?this[s]:void 0}getRowByIndex(e){if(this&&this.length===0)return console.warn("DataFrame is empty, cannot get row by index",e),new U(R(this,Mt),[],void 0,this,e);const s=[];for(let i of this){let n=i[e];s.push(n)}return new U(R(this,Mt),s,R(this,at)?R(this,at)[e]:void 0,this,e)}getRowByName(e){if(!R(this,at))return;const s=R(this,at).indexOf(e);if(s!==-1)return this.getRowByIndex(s)}get types(){return this.map(e=>e.type)}type(e){var s;if(typeof e=="number")return(s=this[e])==null?void 0:s.type;if(typeof e=="string"){const i=this.getColumnByName(e);return i?i.type:void 0}}row(e){if(typeof e=="number")return this.getRowByIndex(e);if(typeof e=="string")return this.getRowByName(e)}rows(...e){let s,i=[],n=[];if(e.length===0){if(!this[0]||this.length===0)return[];const r=this[0].length;i=Array.from({length:r},(a,h)=>this.getRowByIndex(h)),n=R(this,at)}else e.length===1&&Array.isArray(e[0])?s=e[0]:s=e,i=s.map((r,a)=>{let h=this.row(r);return R(this,at)&&h&&(n==null||n.push(R(this,at)[a])),h}).filter(r=>r!==void 0);return i}col(e){if(typeof e=="number")return this[e];if(typeof e=="string")return this.getColumnByName(e)}cols(...e){let s,i,n=[];return e.length===0?(i=this.slice(),n=R(this,Mt)):(e.length===1&&Array.isArray(e[0])?s=e[0]:s=e,i=s.map(r=>this.col(r)).filter(r=>r!==void 0),n=i.map(r=>r.name)),new Me(n,i,R(this,at))}subset(e,s){const i=s&&s.length>0?this.cols(...s):this.slice();return new Me(i.map(n=>n.name),i.map(n=>n.values),R(this,at))}get names(){return R(this,Mt)}get rowNames(){return R(this,at)}get nrow(){return this[0]?this[0].length:0}get ncol(){return this.length}};Mt=new WeakMap,at=new WeakMap,Ee=new WeakMap,c(Me,"DataFrame");let Ft=Me;const gs=class gs{constructor(t={}){this.unit_id_col="id",this.node_id_col="id",this.group_col=null,this.directed=!1,this.palette=[],this._points=t.points??new Ft,this._nodes=t.nodes??new Ft,this._edges=t.edges??new Ft,this._dimensions=t.dimensions??[],this._confidence=void 0,this._outlier=void 0,this._groups=void 0}get updated(){return this._updated}set updated(t){this._updated=t}get points(){return this._points}set points(t){this._points=t}get nodes(){return this._nodes}set nodes(t){this._nodes=t}get edges(){return this._edges}set edges(t){this._edges=t}get confidence(){return this._confidence}set confidence(t){this._confidence=t}get outlier(){return this._outlier}set outlier(t){this._outlier=t}get groups(){return this._groups}set groups(t){this._groups=t}get trajectories(){return this._trajectories}set trajectories(t){this._trajectories=t}get networks(){return this._networks}set networks(t){this._networks=t}get pointsets(){return this._pointsets}set pointsets(t){this._pointsets=t}get dimensions(){return this._dimensions}set dimensions(t){this._dimensions=t}get params(){return this._params}set params(t){this._params=t}point(t){return this._points.row(t)}setByKey(t,e){this[t]=e}};c(gs,"Model");let is=gs;const bi=globalThis.__QEVIZ_DEBUG__===!0;function Xt(...m){bi&&console.log(...m)}c(Xt,"dbg");const yi={get:c(m=>{const t=[...document.querySelectorAll("qe-graph")];return typeof m=="number"&&m>=0?t[m]:t},"get")},Jt=class Jt extends HTMLElement{constructor(){super(),this._isVisible=!0,this.output="",this._updated="",this._active_points=[],this._points=new Map,this._edges=new Map,this._labels=new Map,this._model=new is;const t=this.attachShadow({mode:"open"}),e=document.createElement("style");e.textContent=Jt.styles,t.appendChild(e),this._outputElement=document.createElement("div"),t.appendChild(this._outputElement)}static get observedAttributes(){return["updated"]}get model(){return this._model}get updated(){return this._updated}set updated(t){this._updated=t,this.setAttribute("updated",t),this.dispatchEvent(new CustomEvent("model-updated",{detail:this._model,bubbles:!0,composed:!0}))}get points(){return this._points}set points(t){this._points.clear(),t instanceof Map?this._points=t:Array.isArray(t)&&t.forEach(e=>this._points.set(e.ID,e))}get active_points(){return Array.from(this._active_points.values())}get edges(){return this._edges}set edges(t){this._edges.clear(),t instanceof Map?this._edges=t:Array.isArray(t)&&(this._edges=new Map,t.forEach(e=>this._edges.set(e.ID,e)))}get labels(){return this._labels}connectedCallback(){Xt("QEVisualElement connected"),this.render()}setModelData(t){var r,a,h,o;["nodes","edges","points","groups","confidence","outlier","trajectories","networks","pointsets"].forEach(_=>{var z;const g=t[_];if(!((z=g==null?void 0:g.data)!=null&&z.length))return;const p=g.data,u=g.types||{},d=Object.keys(p[0]),l=p.map(j=>Object.values(j)),b=d.map(j=>u[j]??"character");let f;_==="networks"?f="name":_==="pointsets"?f="id":_==="nodes"?f=t.node_id_col??d.find(j=>(u[j]??"character")==="character"):_==="edges"||_==="points"||_==="trajectories"?f=t.id_col??d.find(j=>(u[j]??"character")==="character"):f=t.group_col??d.find(j=>(u[j]??"character")==="character");const w=f?d.indexOf(f):0,T=l.map(j=>String(j[w]));this._model.setByKey(_,new Ft(d,l,T,b))}),t.updated!==void 0&&this._model.setByKey("updated",t.updated),t.directed!==void 0&&(this._model.directed=t.directed),Array.isArray(t.palette)&&(this._model.palette=t.palette.map(String));const s=this._model.nodes;this._model.node_id_col=t.node_id_col??((r=s==null?void 0:s.names)==null?void 0:r.find(_=>{var g;return((g=s.col(_))==null?void 0:g.type)==="character"}))??"id";const i=this._model.points;this._model.unit_id_col=t.id_col??((a=i==null?void 0:i.names)==null?void 0:a.find(_=>{var g;return((g=i.col(_))==null?void 0:g.type)==="character"}))??"id";const n=this._model.unit_id_col;if(this._model.group_col=t.group_col??((h=i==null?void 0:i.names)==null?void 0:h.find(_=>{var g;return _!==n&&((g=i.col(_))==null?void 0:g.type)==="character"}))??null,(o=s==null?void 0:s.names)!=null&&o.length){const _=this._model.node_id_col,g=t.x_col,p=t.y_col;if(g&&p)this._model.dimensions=[g,p];else{const u=s.names.filter(d=>{if(d===_)return!1;const l=s.col(d);return l&&l.type!=="character"&&l.type!=="logical"});u.length>=2&&(this._model.dimensions=[g??u[0],p??u[1]])}}this.updated=this._model.updated!==void 0?String(this._model.updated):String(Date.now()),Xt("Model updated via setModelData:",this.updated),this.render()}async calculate(){}render(){var t;this._isVisible?this.classList.remove("hidden"):this.classList.add("hidden"),((t=this._model)==null?void 0:t.updated)!==void 0&&this._model.updated!==null?this._outputElement.innerHTML=`${this.output}<slot></slot>`:this._outputElement.innerHTML="Define the model on the left."}};c(Jt,"QEVisualElement"),Jt.tagName="qe-visual",Jt.styles=`
2
2
  :host { display: block; width: 100%; }
3
3
  :host(.hidden) { display: none !important; }
4
4
  /* The output wrapper and the slotted graph fill the host so the plot
5
5
  stretches to its container instead of collapsing to intrinsic size. */
6
6
  div { display: block; width: 100%; height: 100%; }
7
7
  ::slotted(qe-graph) { display: block; width: 100%; height: 100%; }
8
- `;let te=Xt;customElements.define(te.tagName,te);const gt=class gt{constructor(t){return this.base=typeof t=="string"?t:t.base,new Proxy(this,{get(e,s){if(typeof s=="string"&&/^[0-2]$/.test(s)){const{r:i,g:n,b:r}=gt.parseColor(e.base);return[i,n,r][Number(s)]}return e[s]}})}toString(){return this.base}setBase(t){this.base=t}static parseColor(t){const e=String(t).trim();if(/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(e)){const n=parseInt(e.slice(1,7),16);return{r:n>>16&255,g:n>>8&255,b:n&255}}if(/^#[0-9a-f]{3}$/i.test(e)){const[n,r,a]=[1,2,3].map(h=>parseInt(e[h]+e[h],16));return{r:n,g:r,b:a}}const s=e.match(/^rgba?\(\s*([\d.]+)[,\s]+([\d.]+)[,\s]+([\d.]+)/i);if(s)return{r:Math.round(+s[1]),g:Math.round(+s[2]),b:Math.round(+s[3])};const i=gt.resolveCss(e);if(i)return gt.parseColor(i);throw new Error(`Unsupported color format: ${t}`)}static resolveCss(t){if(gt._cssCache.has(t))return gt._cssCache.get(t);gt._ctx===void 0&&(gt._ctx=typeof document<"u"?document.createElement("canvas").getContext("2d"):null);let e=null;const s=gt._ctx;if(s){s.fillStyle="#000000",s.fillStyle=t;const i=s.fillStyle;s.fillStyle="#ffffff",s.fillStyle=t;const n=s.fillStyle;i===n&&(e=String(i))}return gt._cssCache.set(t,e),e}static rgb(t,e,s){return`rgb(${t}, ${e}, ${s})`}};_(gt,"Color"),gt._cssCache=new Map;let et=gt;const ve=class ve extends et{constructor(t,e,s){super(t),this.weight=e,this.alpha=s}static toHSV(t){const{r:e,g:s,b:i}=et.parseColor(t),n=e/255,r=s/255,a=i/255,h=Math.max(n,r,a),o=Math.min(n,r,a),l=h-o,u=h,g=h===0?0:l/h;let c=0;if(l>0)switch(h){case n:c=((r-a)/l+(r<a?6:0))/6;break;case r:c=((a-n)/l+2)/6;break;default:c=((n-r)/l+4)/6}return{h:c*360,s:g,v:u}}static hsvToRgba(t,e,s,i){const n=s*e,r=n*(1-Math.abs(t/60%2-1)),a=s-n;let h=0,o=0,l=0;return t<60?(h=n,o=r,l=0):t<120?(h=r,o=n,l=0):t<180?(h=0,o=n,l=r):t<240?(h=0,o=r,l=n):t<300?(h=r,o=0,l=n):(h=n,o=0,l=r),`rgba(${Math.round((h+a)*255)},${Math.round((o+a)*255)},${Math.round((l+a)*255)},${i.toFixed(4)})`}toString(){const{h:t,v:e}=ve.toHSV(this.base),s=Math.min(1,Math.abs(this.weight)),i=this.alpha===void 0?s:Math.min(1,Math.max(0,this.alpha));return ve.hsvToRgba(t,s,e,i)}};_(ve,"WeightedColor");let ee=ve;const hs=class hs{constructor(t=null){this._values=[1,0,0,1,0,0],this._keys=["a","b","c","d","e","f"],t&&(this.values=t)}get values(){return this._values}set values(t){t&&t.length===6&&(this._values=t)}get keys(){return this._keys}set keys(t){t&&t.length===6&&(this._keys=t)}toString(){return`matrix(${this.keys.map((e,s)=>this.values[s]).join(" ")})`}toMatrix(){return Object.fromEntries(this._keys.map((t,e)=>[t,this._values[e]]))}toArray(){return this._values}set(t,e){e!==.0075&&e!==0&&(this._values[this._keys.findIndex(s=>s===t)]=e)}get(t){return this._values[this._keys.findIndex(e=>e===t)]}scale(t,e=t){this.a=t,this.d=e}zoom(t){this.a=t,this.d=t}pan(t,e){this.e=this.e+t,this.f=this.f+e}set a(t){this.set("a",t)}set b(t){this.set("b",t)}set c(t){this.set("c",t)}set d(t){this.set("d",t)}set e(t){this.set("e",t)}set f(t){this.set("f",t)}get a(){return this.get("a")}get b(){return this.get("b")}get c(){return this.get("c")}get d(){return this.get("d")}get e(){return this.get("e")}get f(){return this.get("f")}};_(hs,"Transform");let se=hs;var ie;(d=>{(t=>{function e(s){return`matrix(${["a","b","c","d","e","f"].map(n=>s[n]).join(" ")})`}_(e,"matrixString"),t.matrixString=e})(d.Matrix||(d.Matrix={})),(t=>{(s=>{function i(r,a,h){const o=e.toRad(a);return[r[0]+h*Math.cos(o),r[1]+h*Math.sin(o)]}_(i,"translate"),s.translate=i;function n(r,a,h){const o=e.toRad(a);function l(u,g){return[u[0]*Math.cos(g)-u[1]*Math.sin(g),u[0]*Math.sin(g)+u[1]*Math.cos(g)]}if(_(l,"rotatePoint"),!h||h[0]===0&&h[1]===0)return l(r,o);{const u=r.map((c,M)=>c-h[M]);return l(u,o).map((c,M)=>c+h[M])}}_(n,"rotate"),s.rotate=n})(t.Point||(t.Point={})),(s=>{function i(m,E){return(E[1]-m[1])/(E[0]-m[0])}_(i,"slope"),s.slope=i;function n(m,E){const L=i(m,E);return m[1]-L*m[0]}_(n,"intercept"),s.intercept=n;function r(m,E){return{slope:i(m,E),intercept:n(m,E)}}_(r,"slopeIntercept"),s.slopeIntercept=r;function a(m,E=0){const L=E,Y=(1-L)*m[0][0]+L*m[1][0],q=(1-L)*m[0][1]+L*m[1][1];return[Y,q]}_(a,"point_along"),s.point_along=a;function h(m,E,L=.5){return Array.isArray(m[0])&&(E=m[1],m=m[0]),[0,1].map(Y=>(parseFloat(m[Y])+parseFloat(E[Y]))*L)}_(h,"midpoint"),s.midpoint=h;function o(m,E){return Array.isArray(m[0])&&(E=m[1],m=m[0]),Math.sqrt([0,1].map(L=>Math.pow(E[L]-m[L],2)).reduce((L,Y)=>L+Y,0))}_(o,"length"),s.length=o;function l(m,E=[0,0]){const L=[m[1][0]-E[0],m[1][1]-E[1]],Y=[-L[1],L[0]],q=[-Y[0],-Y[1]],v=[Y[0]+E[0],Y[1]+E[1]],j=[q[0]+E[0],q[1]+E[1]];return[v,j]}_(l,"rotate"),s.rotate=l;function u(m,E,L=90){const Y=d.Geometry.Line.slope(m[0],m[1]),q=d.Geometry.Line.intercept(m[0],m[1]),v=[0,q],j=[1,Y+q];m=[v,j];const ot=[m[0][0],m[1][0]],lt=[m[0][1],m[1][1]],rt=E[0],mt=E[1],Q=-2*Math.PI*L/360,Rt=ot.map((Xe,pt)=>(Xe-rt)*Math.cos(Q)-(lt[pt]-mt)*Math.sin(Q)+rt),jt=lt.map((Xe,pt)=>(ot[pt]-rt)*Math.sin(Q)-(Xe-mt)*Math.cos(Q)+mt);return[[Rt[0],jt[0]],[Rt[1],jt[1]]]}_(u,"rotate2"),s.rotate2=u;function g(m,E){const[[L,Y],[q,v]]=m,[[j,ot],[lt,rt]]=E,mt=(L-q)*(ot-rt)-(Y-v)*(j-lt),Q=(L*v-Y*q)*(j-lt)-(L-q)*(j*rt-ot*lt),Rt=(L*v-Y*q)*(ot-rt)-(Y-v)*(j*rt-ot*lt);return[Q/mt,Rt/mt]}_(g,"intersection"),s.intersection=g;function c(m,E,L){let{slope:Y,intercept:q}=d.Geometry.Line.slopeIntercept(m[0],m[1]),v=1+Math.pow(Y,2),j=2*Y*q-2*E[1]*Y-2*E[0],ot=Math.pow(E[0],2)+Math.pow(q,2)+Math.pow(E[1],2)-2*E[1]*q-Math.pow(L,2),lt=[[1/0,1/0],[1/0,1/0]];if(Math.sqrt(Math.pow(j,2)-4*v*ot)>=0){let rt=(-j+Math.sqrt(Math.pow(j,2)-4*v*ot))/(2*v),mt=(-j-Math.sqrt(Math.pow(j,2)-4*v*ot))/(2*v),Q=Y*rt+q,Rt=Y*mt+q;lt=[[rt,Q],[mt,Rt]]}else console.error("The line and the circumference do not intersect");return lt}_(c,"intersect_circle"),s.intersect_circle=c;function M(m){return E=>E===0?m[0]:E===1?m[1]:d.Geometry.Point.translate(m[0],d.Geometry.Angle.line(m),d.Geometry.Line.length(m)*E)}_(M,"interpolate"),s.interpolate=M})(t.Line||(t.Line={}));let e;(s=>{function i(a){return a/180*Math.PI}_(i,"toRad"),s.toRad=i;function n(a){return a*180/Math.PI}_(n,"toDeg"),s.toDeg=n;function r(a){if(a.length!==2||!Array.isArray(a[0])||!Array.isArray(a[1])||a[0].length!==2||a[1].length!==2)throw new Error("Invalid line format. Expected [[x1, y1], [x2, y2]].");return d.Geometry.Angle.toDeg(Math.atan2(a[1][1]-a[0][1],a[1][0]-a[0][0]))}_(r,"line"),s.line=r})(e=t.Angle||(t.Angle={}))})(d.Geometry||(d.Geometry={})),(t=>{function e(n){return[...new Set(n)]}_(e,"unique"),t.unique=e;function s(n,r){if(Array.isArray(n)){if(Array.isArray(r)){if(n.length!==r.length)throw new Error("Arrays must be of equal length");return n.map((a,h)=>a/r[h])}return n.map(a=>a/r)}return n/r}_(s,"divide"),t.divide=s;function i(n){return typeof Array.isArray=="function"?Array.isArray(n):n&&typeof n=="object"&&n.constructor.name==="Array"}_(i,"isArray"),t.isArray=i})(d.ArrayTools||(d.ArrayTools={})),(t=>{function e(n){return n.reduce((r,a)=>r+a,0)}_(e,"sum"),t.sum=e;function s(n){return e(n)/n.length}_(s,"mean"),t.mean=s;function i(n,r){const a=Math.pow(10,r);return Math.round(n*a)/a}_(i,"round"),t.round=i})(d.Mathematics||(d.Mathematics={})),(t=>{function e(s,i,n){return new CustomEvent(s,{bubbles:!0,cancelable:!0,detail:{element:i,data:n||(i?i.__data__:void 0)}})}_(e,"createEvent"),t.createEvent=e})(d.Events||(d.Events={})),(t=>{function e(){return location.hash.replace(/#/,"").split(/\//).filter(i=>i).map(i=>i.split(/:/))}_(e,"parts"),t.parts=e;function s(i){return e().flat().findIndex(n=>n===i)>=0}_(s,"exists"),t.exists=s})(d.Hash||(d.Hash={})),(t=>{function e(n,r,a=!1){if(a){if(typeof n!="object"||n===null)return n;for(const h in n)Object.prototype.hasOwnProperty.call(n,h)&&(n[h]=e(n[h],r,a));return new Proxy(n,r)}else return new Proxy(n,r)}_(e,"proxy"),t.proxy=e,t.handler={set(n,r,a){return n[r]=a,window.dispatchEvent(d.Events.createEvent("settingUpdate",window,{target:n,property:r,value:a})),!0},get(n,r){return n[r]}};function s(n,r){const a=r.split(".");let h=n;for(const o of a)if(h&&typeof h=="object"&&Object.prototype.hasOwnProperty.call(h,o))h=h[o];else return;return h}_(s,"get"),t.get=s;function i(n,r,a){const h=r.split(".");let o=n,l;for(l=0;l<h.length-1;l++){const u=h[l];if(o&&typeof o=="object")Object.prototype.hasOwnProperty.call(o,u)||(o[u]={}),o=o[u];else return!1}return o&&typeof o=="object"?(o[h[l]]=a,!0):!1}_(i,"set"),t.set=i})(d.Objects||(d.Objects={})),(t=>{function e(s=window.location){return Object.fromEntries(new URLSearchParams(s.search))}_(e,"parse"),t.parse=e,(s=>{function i(a=window.location.search){return Object.fromEntries(a.replace(/^\?/,"").split(/&/).map(h=>h.split(/=/)))}_(i,"parse2"),s.parse=i;function n(a=window.location.search){return a.replace(/^\?/,"").split(/&/).map(h=>h.split(/=/)[0])}_(n,"keys"),s.keys=n;function r(a,h=window.location.search){return n(h).findIndex(o=>o===a)>=0}_(r,"has"),s.has=r})(t.Query||(t.Query={}))})(d.URL||(d.URL={}))})(ie||(ie={}));const ls=class ls{constructor(){this._state=new Map,this.listeners=new Map}get state(){return this._state}hasVariable(t){return this._state.has(t)}getVariable(t){return this._state.get(t)}setVariable(t,e,s){const i=this._state.get(t);this._state.set(t,e),s!=null&&s.lazy||this.notifyListeners(t,e,i)}addListener(t,e,s){this.listeners.has(t)||this.listeners.set(t,new Map);const i=this.listeners.get(t);i.has(e)||i.set(e,new Set),i.get(e).add(s)}removeListener(t,e,s){var i,n;(n=(i=this.listeners.get(t))==null?void 0:i.get(e))==null||n.delete(s)}getListeners(t,e){var s;return Array.from(((s=this.listeners.get(t))==null?void 0:s.get(e))??[])}notifyListeners(t,e,s){const i=this.listeners.get(t);if(i)for(const n of i.values())n.forEach(r=>{typeof r=="function"?r({key:t,newValue:e,oldValue:s}):typeof r.calculate=="function"&&r.calculate.call(r,{key:t,newValue:e,oldValue:s})})}};_(ls,"EventBus");let Ne=ls;const{ArrayTools:Ms}=ie,Se=class Se extends Array{constructor(...t){super(...t)}search(t,e){let s;function i(r){return r.name===e?r:void 0}_(i,"fn");function n(r,a,h=null){if(Ms.isArray(r)){for(const[o,l]of r.entries())if(s=n(l,o,h),s)return s}else{if(s=i(r),s)return s;if(r&&Ms.isArray(r[t])){for(const[o,l]of r[t].entries())if(s=n(l,o,r),s)return s}}return s}return _(n,"recurse"),n(this)}flatten(){return this.reduce((t,e)=>(t.push(e),e.layers&&Array.isArray(e.layers)&&t.push(...e.layers),t),[])}recurse(t,e,s=null,i=0){let n=new Se;for(const r of this){let a=e(r,s,i);if(r[t]&&Array.isArray(r[t])){let h=new Se(...r[t]).recurse(t,e,r,i+1);h!==void 0&&n.push(...h)}n.push(a)}return console.log("Recurse results: ",n),n}};_(Se,"LayerArray");let qt=Se;const cs=class cs{constructor(t,e,s){this.__state__=new Ne,this.scale_x=1,this.scale_y=1,this.scale_objects=!0,this.layers=new qt,this.objects=new Map,this.visible=!0,this.ID=t,this.name=e.name||`layer-${t}`,this.tabindex=e.tabindex,this.parent=s,this._transform=new se,s==null||s.__state__.addListener("graph_updated","live",({key:i,newValue:n,oldValue:r})=>{}),s==null||s.__state__.addListener(`graph_updated_${this.name}`,"live",({key:i,newValue:n,oldValue:r})=>{this.objects=n,this.__state__.setVariable("layer_updated",this)})}get transform(){return this._transform}set transform(t){this._transform=t}};_(cs,"Layer");let Je=cs;const Te=class Te extends Array{constructor(...e){super(arguments.length);nt(this,Ft,!1);nt(this,It);for(let s=0;s<e.length;s++)this[s]=e[s];W(this,Ft,!1)}static fromArray(e){const s=new Te;return e.forEach((i,n)=>{s.push(i)}),W(s,It,e.names),s}flip(){W(this,Ft,!C(this,Ft));for(let e=0;e<this.length;e++)this[e]=-this[e];return this}get(e){return typeof e=="number"?this[e]:C(this,It)&&C(this,It).includes(e)?this[C(this,It).indexOf(e)]:void 0}get flipped(){return C(this,Ft)}get names(){return C(this,It)?C(this,It):this.map((e,s)=>`V${s+1}`)}};Ft=new WeakMap,It=new WeakMap,_(Te,"DimensionVector");let Tt=Te;const us=class us{constructor(t,e){this.scale_x=1,this.scale_y=1,this.scale_size=.05,this.active=!1,this.visible=!1,this.highlighting=!1,this.meta={},this._x=0,this._y=0,this._highlight_default=new et("#000000"),this._size=0,this.ID=e.ID,this._transform=new se,t instanceof Tt?this._dimensions=t:t instanceof B?this._dimensions=Tt.fromArray(t):Array.isArray(t)?this._dimensions=new Tt(...t):(console.warn("Invalid dimensions provided, using default DimensionVector(0, 0)"),this._dimensions=new Tt(0,0));let s={...e};this._original={...s},this.ID=s.ID,this.x=s.x||this._dimensions[0],this.y=s.y||this._dimensions[1],this._size=s.size||1,this._color=s.color||new et("#000000"),this.active=s.active||!1,this.shape=s.shape||null,this.meta=s.meta||{},this._highlight=this._highlight_default,s.highlight&&(this._highlight=s.highlight)}get dimensions(){return this._dimensions}get color(){return this.highlighting&&this._highlight?this._highlight:this._color}set color(t){this._color=t}get highlight(){return this._highlight||this._highlight_default}set highlight(t){this._highlight=t}get size(){return this._size}set size(t){this._size=t}get original(){return this._original}get x(){return this._x}get y(){return this._y}set x(t){this._x=t}set y(t){this._y=t}dimension(t){return this._dimensions.get(t)}get transform(){return this._transform}set transform(t){this._transform=t}};_(us,"PlottedObject");let Ot=us;const _s=class _s extends Ot{constructor(t,e,s){super([],{}),this.from=e,this.to=s}get line(){return[[this.from.x,this.from.y],[this.to.x,this.to.y]]}get midpoint(){return[(this.from.x+this.to.x)/2,(this.from.y+this.to.y)/2]}get length(){return Math.sqrt(Math.pow(this.to.x-this.from.x,2)+Math.pow(this.to.y-this.from.y,2))}get color(){return this._color}set color(t){this._color=t}};_(_s,"Line");let Gt=_s;const Ee=class Ee extends Ot{constructor(t){var n,r;let e,s,i;t?t instanceof B?(e=(n=t.classes)==null?void 0:n.map((a,h)=>a==="ena.co.occurrence"||a==="ena.dimension"?t[h]:-1).filter(a=>a!==-1),s=(r=t.classes)==null?void 0:r.map((a,h)=>a==="ena.metadata"?[t.names[h],t[h]]:null).filter(a=>a!==null).reduce((a,h)=>(a[h[0]]=h[1],a),{}),i=t.rowName||`point-${Math.random().toString(36).substring(2,9)}`):typeof t=="object"?(e=t.dimensions||[],s=t.meta||{},i=t.ID||`point-${Math.random().toString(36).substring(2,9)}`):(console.warn("Invalid data provided for Point, using default values"),e=[],s={},i=`point-${Math.random().toString(36).substring(2,9)}`):(e=[],s={},i=`point-${Math.random().toString(36).substring(2,9)}`),super(e??[],{meta:s,ID:i}),this.edges=new Map,this.shape=Ee.SHAPES.CIRCLE}set label(t){this._label=t}get label(){return this._label}get x(){return this._x}get y(){return this._y}set x(t){this._x=parseFloat(t)}set y(t){this._y=parseFloat(t)}};_(Ee,"Point"),Ee.SHAPES={CIRCLE:"circle",SQUARE:"rect"};let Z=Ee;const Wt=class Wt extends Ot{constructor(t,e){super(e.dimensions,e),this._visible=!1,this.offset=0,this.text=t,this.ID=e.ID,this.object=e,this.x=this.dimensions[0],this.y=this.dimensions[1],this.offset=e.size||0,this.size=this.offset/4,this.visible=!1,this._transform.set("e",1),this._transform.set("f",1)}get x(){return parseFloat(this._x)}get y(){return parseFloat(this._y)}set x(t){this._x=t}set y(t){this._y=t}get transform(){return console.warn("transform is disabled - need updated reference for the graph options"),this._transform}set transform(t){this._transform=t}};_(Wt,"Label"),Wt.DISPLAY_TYPES={OFF:0,AUTO:1,CLICK:2,ON:3},Wt.HIGHLIGHT={OFF:0,ON:2},Wt.POSITION={OBJECT:1,STATIC:2,CONTAINER:3,CUSTOM:4};let H=Wt;const ds=class ds{constructor(t,e,s=0,i=0){this.x_max=t,this.y_max=e,this.cx=s,this.cy=i}as_viewBox(t=1.2){let e=this.x_max*t,s=this.y_max*t;return`${this.cx-e} ${this.cy-s} ${e*2} ${s*2}`}get height(){return this.y_max*2}get width(){return this.x_max*2}get top(){return this.y_max*-1}get bottom(){return this.y_max}get left(){return this.x_max*-1}get right(){return this.x_max}};_(ds,"Extremes");let Dt=ds;const gs=class gs extends Ot{constructor(t,e){super(t,e),this.visible=!0,this.size=e.size}set size(t){this._size=t}get size(){return this._size}get x(){return this._x}get y(){return this._y}set x(t){this._x=t}set y(t){this._y=t}get transform(){return this._transform}};_(gs,"AxisPoint");let Ze=gs,Is={GRAPH:{ratio:1,x_max:1,y_max:1,selector:"body",width:1,height:1,axes:!0,SIZE_EFFECT:1,dimensions:[0,1]},NODE:{size:1,highlight:{color:"yellow",labels:H.DISPLAY_TYPES.ON},labels:H.DISPLAY_TYPES.ON,labelposition:H.POSITION.OBJECT},POINT:{active:2,size:.05,color:"#000",shape:Z.SHAPES.CIRCLE,labels:H.DISPLAY_TYPES.AUTO,labelposition:H.POSITION.OBJECT},MEAN:{shape:Z.SHAPES.SQUARE,labels:H.DISPLAY_TYPES.AUTO},LABEL:{highlight:H.HIGHLIGHT.OFF,position:["top","left"],container:"#label-container"},EDGE:{multiplier:1}};const fs=class fs{constructor(t={...Is}){this.__state__=new Ne,this.name="unnamed-graph",this.origin=void 0,this.points=new Map,this.nodes=new Map,this.edges=new Map,this.trajectories=new Map,this.labels=new Map,this.transform=new se,this.scale_x=1,this.scale_y=1,this.SIZE_EFFECT=1,this._mirror_y=!0,this._mirror_x=!1,this._layers=new qt({name:"graph",tabindex:0,layers:[{name:"axes",layers:[{name:"axis_lines",tabindex:0,layers:[],objects:[]},{name:"axis_labels",tabindex:0,layers:[],objects:[]},{name:"axis_points",tabindex:0,layers:[],objects:[this.origin]}]},{name:"network",layers:[{name:"edges",layers:[],tabindex:0},{name:"nodes",layers:[],tabindex:0},{name:"edgenodes",layers:[],tabindex:0}]},{name:"trajectories",layers:[],tabindex:0},{name:"points",layers:[],tabindex:0},{name:"labels",layers:[],tabindex:0}]}),this.options=t,this.origin=new Ze(new Tt(0,0),{ID:"origin",x:0,y:0,size:0,meta:{},graph:this,color:new et("#FFFFFF"),highlight:new et("#FFFFFF"),active:!1});let e=1;function s(r,a,h){const o=new Je(`${e}`,r,h);return e+=1,o.parent=a||void 0,r.layers&&Array.isArray(r.layers)&&(o.layers=new qt(...r.layers.map(l=>s(l,o,h)))),o}_(s,"buildLayerTree"),this.layers=new qt(...this._layers.map(r=>s(r,null,this)));let i=this.layers.search("layers","axis_points");i&&i.objects.set(this.origin.ID,this.origin);let n=this.layers.search("layers","axis_lines");if(n){let r=this.extremes||new Dt(1,1),a=new Gt({},new Z({ID:"axis-x-start",dimensions:[-r.x_max,0],classes:["ena.dimension","ena.dimension"]}),new Z({ID:"axis-x-end",dimensions:[r.x_max,0],classes:["ena.dimension","ena.dimension"]}));a.ID="axis-x",n.objects.set(a.ID,a);let h=new Gt({},new Z({ID:"axis-y-start",dimensions:[0,-r.y_max],classes:["ena.dimension","ena.dimension"]}),new Z({ID:"axis-y-end",dimensions:[0,r.y_max],classes:["ena.dimension","ena.dimension"]}));h.ID="axis-y",n.objects.set(h.ID,h),console.log("Added axis lines to layer: ",n)}this.extremes=new Dt(t.GRAPH.x_max,t.GRAPH.y_max)}set extremes(t){this._extremes=t}get extremes(){return this._extremes}get mirror_x(){return this._mirror_x}set mirror_x(t){this._mirror_x=t}get mirror_y(){return this._mirror_y}set mirror_y(t){this._mirror_y=t}x_mirror(){return this.mirror_x?-1:1}y_mirror(){return this.mirror_y?-1:1}add_point(t){const e=new Z(t);this.points.set(e.ID,e)}add_points(t){let e=this;t.rows().forEach(s=>{e.add_point(s)})}add_nodes(t){let e=this;t.forEach(s=>{s.label=new H(s.ID,s),e.labels.set(s.label.ID,s.label),e.nodes.set(s.ID,s);const i=e.layers.search("layers","nodes");i&&i.objects.push(s)}),e.update_extremes()}add_edge(t,e,s){return this.edges.set(t.ID,t),this.add_nodes([e||t.from,s||t.to]),t}add_edges(t){let e=t.map(i=>this.add_edge(i));const s=this.layers.search("layers","edges");return s&&s.objects.push(...e),e}update_extremes(t=!1){const e=[this.layers.search("layers","points"),this.layers.search("layers","nodes")].filter(s=>s!==void 0);if(e.length===0)this.extremes=new Dt(1,1);else{let s=1/0,i=-1/0,n=1/0,r=-1/0;e.forEach(g=>g.objects.forEach(c=>{Number.isFinite(c.x)&&(s=Math.min(s,c.x),i=Math.max(i,c.x)),Number.isFinite(c.y)&&(n=Math.min(n,c.y),r=Math.max(r,c.y))}));const a=Number.isFinite(s)&&Number.isFinite(n),h=t&&a?(s+i)/2:0,o=t&&a?(n+r)/2:0,l=a?Math.max(Math.abs(s-h),Math.abs(i-h),Math.abs(n-o),Math.abs(r-o)):0,u=(l>0?l:1)*1.3;this.extremes=new Dt(u,u,h,o)}}nodeExtentFrom(t,e){const s=this.layers.search("layers","nodes");let i=0;return s==null||s.objects.forEach(n=>{Number.isFinite(n.x)&&Number.isFinite(n.y)&&(i=Math.max(i,Math.abs(n.x-t),Math.abs(n.y-e)))}),i}base_point_size(t=8){let e=Math.min(this.extremes.x_max,this.extremes.y_max),s=this.points.size+this.nodes.size;return Math.min(1,e/(Math.sqrt(s)*t))}};_(fs,"Graph");let ke=fs;const De=class De extends HTMLElement{constructor(){super(),this.element=null,this.object=null;const t=this,e=t.attachShadow({mode:"open"}),s=document.createElement("style"),i=document.createElement("div");s.textContent=this.constructor.style,e.appendChild(s),i.setAttribute("class","wrapper"),e.appendChild(i)}get wrapper(){const t=this,e=t.shadowRoot;return e==null?void 0:e.querySelector(".wrapper")}};_(De,"DrawableElement"),De.style=`
8
+ `;let oe=Jt;customElements.define(oe.tagName,oe);const ut=class ut{constructor(t){return this.base=typeof t=="string"?t:t.base,new Proxy(this,{get(e,s){if(typeof s=="string"&&/^[0-2]$/.test(s)){const{r:i,g:n,b:r}=ut.parseColor(e.base);return[i,n,r][Number(s)]}return e[s]}})}toString(){return this.base}setBase(t){this.base=t}static parseColor(t){const e=String(t).trim();if(/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(e)){const n=parseInt(e.slice(1,7),16);return{r:n>>16&255,g:n>>8&255,b:n&255}}if(/^#[0-9a-f]{3}$/i.test(e)){const[n,r,a]=[1,2,3].map(h=>parseInt(e[h]+e[h],16));return{r:n,g:r,b:a}}const s=e.match(/^rgba?\(\s*([\d.]+)[,\s]+([\d.]+)[,\s]+([\d.]+)/i);if(s)return{r:Math.round(+s[1]),g:Math.round(+s[2]),b:Math.round(+s[3])};const i=ut.resolveCss(e);if(i)return ut.parseColor(i);throw new Error(`Unsupported color format: ${t}`)}static resolveCss(t){if(ut._cssCache.has(t))return ut._cssCache.get(t);ut._ctx===void 0&&(ut._ctx=typeof document<"u"?document.createElement("canvas").getContext("2d"):null);let e=null;const s=ut._ctx;if(s){s.fillStyle="#000000",s.fillStyle=t;const i=s.fillStyle;s.fillStyle="#ffffff",s.fillStyle=t;const n=s.fillStyle;i===n&&(e=String(i))}return ut._cssCache.set(t,e),e}static rgb(t,e,s){return`rgb(${t}, ${e}, ${s})`}};c(ut,"Color"),ut._cssCache=new Map;let tt=ut;const Ie=class Ie extends tt{constructor(t,e,s){super(t),this.weight=e,this.alpha=s}static toHSV(t){const{r:e,g:s,b:i}=tt.parseColor(t),n=e/255,r=s/255,a=i/255,h=Math.max(n,r,a),o=Math.min(n,r,a),_=h-o,g=h,p=h===0?0:_/h;let u=0;if(_>0)switch(h){case n:u=((r-a)/_+(r<a?6:0))/6;break;case r:u=((a-n)/_+2)/6;break;default:u=((n-r)/_+4)/6}return{h:u*360,s:p,v:g}}static hsvToRgba(t,e,s,i){const n=s*e,r=n*(1-Math.abs(t/60%2-1)),a=s-n;let h=0,o=0,_=0;return t<60?(h=n,o=r,_=0):t<120?(h=r,o=n,_=0):t<180?(h=0,o=n,_=r):t<240?(h=0,o=r,_=n):t<300?(h=r,o=0,_=n):(h=n,o=0,_=r),`rgba(${Math.round((h+a)*255)},${Math.round((o+a)*255)},${Math.round((_+a)*255)},${i.toFixed(4)})`}toString(){const{h:t,v:e}=Ie.toHSV(this.base),s=Math.min(1,Math.abs(this.weight)),i=this.alpha===void 0?s:Math.min(1,Math.max(0,this.alpha));return Ie.hsvToRgba(t,s,e,i)}};c(Ie,"WeightedColor");let ae=Ie;const ms=class ms{constructor(t=null){this._values=[1,0,0,1,0,0],this._keys=["a","b","c","d","e","f"],t&&(this.values=t)}get values(){return this._values}set values(t){t&&t.length===6&&(this._values=t)}get keys(){return this._keys}set keys(t){t&&t.length===6&&(this._keys=t)}toString(){return`matrix(${this.keys.map((e,s)=>this.values[s]).join(" ")})`}toMatrix(){return Object.fromEntries(this._keys.map((t,e)=>[t,this._values[e]]))}toArray(){return this._values}set(t,e){const s=this._keys.indexOf(t);s>=0&&Number.isFinite(e)&&(this._values[s]=e)}get(t){return this._values[this._keys.findIndex(e=>e===t)]}scale(t,e=t){this.a=t,this.d=e}zoom(t){this.a=t,this.d=t}pan(t,e){this.e=this.e+t,this.f=this.f+e}set a(t){this.set("a",t)}set b(t){this.set("b",t)}set c(t){this.set("c",t)}set d(t){this.set("d",t)}set e(t){this.set("e",t)}set f(t){this.set("f",t)}get a(){return this.get("a")}get b(){return this.get("b")}get c(){return this.get("c")}get d(){return this.get("d")}get e(){return this.get("e")}get f(){return this.get("f")}};c(ms,"Transform");let he=ms;var le;(m=>{(t=>{function e(s){return`matrix(${["a","b","c","d","e","f"].map(n=>s[n]).join(" ")})`}c(e,"matrixString"),t.matrixString=e})(m.Matrix||(m.Matrix={})),(t=>{(s=>{function i(r,a,h){const o=e.toRad(a);return[r[0]+h*Math.cos(o),r[1]+h*Math.sin(o)]}c(i,"translate"),s.translate=i;function n(r,a,h){const o=e.toRad(a);function _(g,p){return[g[0]*Math.cos(p)-g[1]*Math.sin(p),g[0]*Math.sin(p)+g[1]*Math.cos(p)]}if(c(_,"rotatePoint"),!h||h[0]===0&&h[1]===0)return _(r,o);{const g=r.map((u,d)=>u-h[d]);return _(g,o).map((u,d)=>u+h[d])}}c(n,"rotate"),s.rotate=n})(t.Point||(t.Point={})),(s=>{function i(l,b){return(b[1]-l[1])/(b[0]-l[0])}c(i,"slope"),s.slope=i;function n(l,b){const f=i(l,b);return l[1]-f*l[0]}c(n,"intercept"),s.intercept=n;function r(l,b){return{slope:i(l,b),intercept:n(l,b)}}c(r,"slopeIntercept"),s.slopeIntercept=r;function a(l,b=0){const f=b,w=(1-f)*l[0][0]+f*l[1][0],T=(1-f)*l[0][1]+f*l[1][1];return[w,T]}c(a,"point_along"),s.point_along=a;function h(l,b,f=.5){return Array.isArray(l[0])&&(b=l[1],l=l[0]),[0,1].map(w=>(parseFloat(l[w])+parseFloat(b[w]))*f)}c(h,"midpoint"),s.midpoint=h;function o(l,b){return Array.isArray(l[0])&&(b=l[1],l=l[0]),Math.sqrt([0,1].map(f=>Math.pow(b[f]-l[f],2)).reduce((f,w)=>f+w,0))}c(o,"length"),s.length=o;function _(l,b=[0,0]){const f=[l[1][0]-b[0],l[1][1]-b[1]],w=[-f[1],f[0]],T=[-w[0],-w[1]],z=[w[0]+b[0],w[1]+b[1]],j=[T[0]+b[0],T[1]+b[1]];return[z,j]}c(_,"rotate"),s.rotate=_;function g(l,b,f=90){const w=m.Geometry.Line.slope(l[0],l[1]),T=m.Geometry.Line.intercept(l[0],l[1]),z=[0,T],j=[1,w+T];l=[z,j];const dt=[l[0][0],l[1][0]],gt=[l[0][1],l[1][1]],et=b[0],mt=b[1],Q=-2*Math.PI*f/360,Tt=dt.map((Gt,Nt)=>(Gt-et)*Math.cos(Q)-(gt[Nt]-mt)*Math.sin(Q)+et),Os=gt.map((Gt,Nt)=>(dt[Nt]-et)*Math.sin(Q)-(Gt-mt)*Math.cos(Q)+mt);return[[Tt[0],Os[0]],[Tt[1],Os[1]]]}c(g,"rotate2"),s.rotate2=g;function p(l,b){const[[f,w],[T,z]]=l,[[j,dt],[gt,et]]=b,mt=(f-T)*(dt-et)-(w-z)*(j-gt),Q=(f*z-w*T)*(j-gt)-(f-T)*(j*et-dt*gt),Tt=(f*z-w*T)*(dt-et)-(w-z)*(j*et-dt*gt);return[Q/mt,Tt/mt]}c(p,"intersection"),s.intersection=p;function u(l,b,f){let{slope:w,intercept:T}=m.Geometry.Line.slopeIntercept(l[0],l[1]),z=1+Math.pow(w,2),j=2*w*T-2*b[1]*w-2*b[0],dt=Math.pow(b[0],2)+Math.pow(T,2)+Math.pow(b[1],2)-2*b[1]*T-Math.pow(f,2),gt=[[1/0,1/0],[1/0,1/0]];if(Math.sqrt(Math.pow(j,2)-4*z*dt)>=0){let et=(-j+Math.sqrt(Math.pow(j,2)-4*z*dt))/(2*z),mt=(-j-Math.sqrt(Math.pow(j,2)-4*z*dt))/(2*z),Q=w*et+T,Tt=w*mt+T;gt=[[et,Q],[mt,Tt]]}else console.error("The line and the circumference do not intersect");return gt}c(u,"intersect_circle"),s.intersect_circle=u;function d(l){return b=>b===0?l[0]:b===1?l[1]:m.Geometry.Point.translate(l[0],m.Geometry.Angle.line(l),m.Geometry.Line.length(l)*b)}c(d,"interpolate"),s.interpolate=d})(t.Line||(t.Line={}));let e;(s=>{function i(a){return a/180*Math.PI}c(i,"toRad"),s.toRad=i;function n(a){return a*180/Math.PI}c(n,"toDeg"),s.toDeg=n;function r(a){if(a.length!==2||!Array.isArray(a[0])||!Array.isArray(a[1])||a[0].length!==2||a[1].length!==2)throw new Error("Invalid line format. Expected [[x1, y1], [x2, y2]].");return m.Geometry.Angle.toDeg(Math.atan2(a[1][1]-a[0][1],a[1][0]-a[0][0]))}c(r,"line"),s.line=r})(e=t.Angle||(t.Angle={}))})(m.Geometry||(m.Geometry={})),(t=>{function e(n){return[...new Set(n)]}c(e,"unique"),t.unique=e;function s(n,r){if(Array.isArray(n)){if(Array.isArray(r)){if(n.length!==r.length)throw new Error("Arrays must be of equal length");return n.map((a,h)=>a/r[h])}return n.map(a=>a/r)}return n/r}c(s,"divide"),t.divide=s;function i(n){return typeof Array.isArray=="function"?Array.isArray(n):n&&typeof n=="object"&&n.constructor.name==="Array"}c(i,"isArray"),t.isArray=i})(m.ArrayTools||(m.ArrayTools={})),(t=>{function e(n){return n.reduce((r,a)=>r+a,0)}c(e,"sum"),t.sum=e;function s(n){return e(n)/n.length}c(s,"mean"),t.mean=s;function i(n,r){const a=Math.pow(10,r);return Math.round(n*a)/a}c(i,"round"),t.round=i})(m.Mathematics||(m.Mathematics={})),(t=>{function e(s,i,n){return new CustomEvent(s,{bubbles:!0,cancelable:!0,detail:{element:i,data:n||(i?i.__data__:void 0)}})}c(e,"createEvent"),t.createEvent=e})(m.Events||(m.Events={})),(t=>{function e(){return location.hash.replace(/#/,"").split(/\//).filter(i=>i).map(i=>i.split(/:/))}c(e,"parts"),t.parts=e;function s(i){return e().flat().findIndex(n=>n===i)>=0}c(s,"exists"),t.exists=s})(m.Hash||(m.Hash={})),(t=>{function e(n,r,a=!1){if(a){if(typeof n!="object"||n===null)return n;for(const h in n)Object.prototype.hasOwnProperty.call(n,h)&&(n[h]=e(n[h],r,a));return new Proxy(n,r)}else return new Proxy(n,r)}c(e,"proxy"),t.proxy=e,t.handler={set(n,r,a){return n[r]=a,window.dispatchEvent(m.Events.createEvent("settingUpdate",window,{target:n,property:r,value:a})),!0},get(n,r){return n[r]}};function s(n,r){const a=r.split(".");let h=n;for(const o of a)if(h&&typeof h=="object"&&Object.prototype.hasOwnProperty.call(h,o))h=h[o];else return;return h}c(s,"get"),t.get=s;function i(n,r,a){const h=r.split(".");let o=n,_;for(_=0;_<h.length-1;_++){const g=h[_];if(o&&typeof o=="object")Object.prototype.hasOwnProperty.call(o,g)||(o[g]={}),o=o[g];else return!1}return o&&typeof o=="object"?(o[h[_]]=a,!0):!1}c(i,"set"),t.set=i})(m.Objects||(m.Objects={})),(t=>{function e(s=window.location){return Object.fromEntries(new URLSearchParams(s.search))}c(e,"parse"),t.parse=e,(s=>{function i(a=window.location.search){return Object.fromEntries(a.replace(/^\?/,"").split(/&/).map(h=>h.split(/=/)))}c(i,"parse2"),s.parse=i;function n(a=window.location.search){return a.replace(/^\?/,"").split(/&/).map(h=>h.split(/=/)[0])}c(n,"keys"),s.keys=n;function r(a,h=window.location.search){return n(h).findIndex(o=>o===a)>=0}c(r,"has"),s.has=r})(t.Query||(t.Query={}))})(m.URL||(m.URL={}))})(le||(le={}));const fs=class fs{constructor(){this._state=new Map,this.listeners=new Map}get state(){return this._state}hasVariable(t){return this._state.has(t)}getVariable(t){return this._state.get(t)}setVariable(t,e,s){const i=this._state.get(t);this._state.set(t,e),s!=null&&s.lazy||this.notifyListeners(t,e,i)}addListener(t,e,s){this.listeners.has(t)||this.listeners.set(t,new Map);const i=this.listeners.get(t);i.has(e)||i.set(e,new Set),i.get(e).add(s)}removeListener(t,e,s){var i,n;(n=(i=this.listeners.get(t))==null?void 0:i.get(e))==null||n.delete(s)}getListeners(t,e){var s;return Array.from(((s=this.listeners.get(t))==null?void 0:s.get(e))??[])}notifyListeners(t,e,s){const i=this.listeners.get(t);if(i)for(const n of i.values())n.forEach(r=>{typeof r=="function"?r({key:t,newValue:e,oldValue:s}):typeof r.calculate=="function"&&r.calculate.call(r,{key:t,newValue:e,oldValue:s})})}};c(fs,"EventBus");let Le=fs;const{ArrayTools:Ps}=le,Ne=class Ne extends Array{constructor(...t){super(...t)}search(t,e){let s;function i(r){return r.name===e?r:void 0}c(i,"fn");function n(r,a,h=null){if(Ps.isArray(r)){for(const[o,_]of r.entries())if(s=n(_,o,h),s)return s}else{if(s=i(r),s)return s;if(r&&Ps.isArray(r[t])){for(const[o,_]of r[t].entries())if(s=n(_,o,r),s)return s}}return s}return c(n,"recurse"),n(this)}flatten(){return this.reduce((t,e)=>(t.push(e),e.layers&&Array.isArray(e.layers)&&t.push(...e.layers),t),[])}recurse(t,e,s=null,i=0){let n=new Ne;for(const r of this){let a=e(r,s,i);if(r[t]&&Array.isArray(r[t])){let h=new Ne(...r[t]).recurse(t,e,r,i+1);h!==void 0&&n.push(...h)}n.push(a)}return Xt("Recurse results: ",n),n}};c(Ne,"LayerArray");let Wt=Ne;const ps=class ps{constructor(t,e,s){this.__state__=new Le,this.scale_x=1,this.scale_y=1,this.scale_objects=!0,this.layers=new Wt,this.objects=new Map,this.visible=!0,this.ID=t,this.name=e.name||`layer-${t}`,this.tabindex=e.tabindex,this.parent=s,this._transform=new he,s==null||s.__state__.addListener("graph_updated","live",({key:i,newValue:n,oldValue:r})=>{}),s==null||s.__state__.addListener(`graph_updated_${this.name}`,"live",({key:i,newValue:n,oldValue:r})=>{this.objects=n,this.__state__.setVariable("layer_updated",this)})}get transform(){return this._transform}set transform(t){this._transform=t}};c(ps,"Layer");let ns=ps;const Be=class Be extends Array{constructor(...e){super(arguments.length);nt(this,qt,!1);nt(this,It);for(let s=0;s<e.length;s++)this[s]=e[s];X(this,qt,!1)}static fromArray(e){const s=new Be;return e.forEach((i,n)=>{s.push(i)}),X(s,It,e.names),s}flip(){X(this,qt,!R(this,qt));for(let e=0;e<this.length;e++)this[e]=-this[e];return this}get(e){return typeof e=="number"?this[e]:R(this,It)&&R(this,It).includes(e)?this[R(this,It).indexOf(e)]:void 0}get flipped(){return R(this,qt)}get names(){return R(this,It)?R(this,It):this.map((e,s)=>`V${s+1}`)}};qt=new WeakMap,It=new WeakMap,c(Be,"DimensionVector");let Dt=Be;const bs=class bs{constructor(t,e){this.scale_x=1,this.scale_y=1,this.scale_size=.05,this.active=!1,this.visible=!1,this.highlighting=!1,this.meta={},this._x=0,this._y=0,this._highlight_default=new tt("#000000"),this._size=0,this.ID=e.ID,this._transform=new he,t instanceof Dt?this._dimensions=t:t instanceof U?this._dimensions=Dt.fromArray(t):Array.isArray(t)?this._dimensions=new Dt(...t):(console.warn("Invalid dimensions provided, using default DimensionVector(0, 0)"),this._dimensions=new Dt(0,0));let s={...e};this._original={...s},this.ID=s.ID,this.x=s.x||this._dimensions[0],this.y=s.y||this._dimensions[1],this._size=s.size||1,this._color=s.color||new tt("#000000"),this.active=s.active||!1,this.shape=s.shape||null,this.meta=s.meta||{},this._highlight=this._highlight_default,s.highlight&&(this._highlight=s.highlight)}get dimensions(){return this._dimensions}get color(){return this.highlighting&&this._highlight?this._highlight:this._color}set color(t){this._color=t}get highlight(){return this._highlight||this._highlight_default}set highlight(t){this._highlight=t}get size(){return this._size}set size(t){this._size=t}get original(){return this._original}get x(){return this._x}get y(){return this._y}set x(t){this._x=t}set y(t){this._y=t}dimension(t){return this._dimensions.get(t)}get transform(){return this._transform}set transform(t){this._transform=t}};c(bs,"PlottedObject");let Pt=bs;const ys=class ys extends Pt{constructor(t,e,s){super([],{}),this.from=e,this.to=s}get line(){return[[this.from.x,this.from.y],[this.to.x,this.to.y]]}get midpoint(){return[(this.from.x+this.to.x)/2,(this.from.y+this.to.y)/2]}get length(){return Math.sqrt(Math.pow(this.to.x-this.from.x,2)+Math.pow(this.to.y-this.from.y,2))}get color(){return this._color}set color(t){this._color=t}};c(ys,"Line");let Ht=ys;const ke=class ke extends Pt{constructor(t){var n,r;let e,s,i;t?t instanceof U?(e=(n=t.classes)==null?void 0:n.map((a,h)=>a==="ena.co.occurrence"||a==="ena.dimension"?t[h]:-1).filter(a=>a!==-1),s=(r=t.classes)==null?void 0:r.map((a,h)=>a==="ena.metadata"?[t.names[h],t[h]]:null).filter(a=>a!==null).reduce((a,h)=>(a[h[0]]=h[1],a),{}),i=t.rowName||`point-${Math.random().toString(36).substring(2,9)}`):typeof t=="object"?(e=t.dimensions||[],s=t.meta||{},i=t.ID||`point-${Math.random().toString(36).substring(2,9)}`):(console.warn("Invalid data provided for Point, using default values"),e=[],s={},i=`point-${Math.random().toString(36).substring(2,9)}`):(e=[],s={},i=`point-${Math.random().toString(36).substring(2,9)}`),super(e??[],{meta:s,ID:i}),this.edges=new Map,this.shape=ke.SHAPES.CIRCLE}set label(t){this._label=t}get label(){return this._label}get x(){return this._x}get y(){return this._y}set x(t){this._x=parseFloat(t)}set y(t){this._y=parseFloat(t)}};c(ke,"Point"),ke.SHAPES={CIRCLE:"circle",SQUARE:"rect"};let J=ke;const Qt=class Qt extends Pt{constructor(t,e){super(e.dimensions,e),this._visible=!1,this.offset=0,this.text=t,this.ID=e.ID,this.object=e,this.x=this.dimensions[0],this.y=this.dimensions[1],this.offset=e.size||0,this.size=this.offset/4,this.visible=!1,this._transform.set("e",1),this._transform.set("f",1)}get x(){return parseFloat(this._x)}get y(){return parseFloat(this._y)}set x(t){this._x=t}set y(t){this._y=t}get transform(){return console.warn("transform is disabled - need updated reference for the graph options"),this._transform}set transform(t){this._transform=t}};c(Qt,"Label"),Qt.DISPLAY_TYPES={OFF:0,AUTO:1,CLICK:2,ON:3},Qt.HIGHLIGHT={OFF:0,ON:2},Qt.POSITION={OBJECT:1,STATIC:2,CONTAINER:3,CUSTOM:4};let q=Qt;const xs=class xs{constructor(t,e,s=0,i=0){this.x_max=t,this.y_max=e,this.cx=s,this.cy=i}as_viewBox(t=1.2){let e=this.x_max*t,s=this.y_max*t;return`${this.cx-e} ${this.cy-s} ${e*2} ${s*2}`}get height(){return this.y_max*2}get width(){return this.x_max*2}get top(){return this.y_max*-1}get bottom(){return this.y_max}get left(){return this.x_max*-1}get right(){return this.x_max}};c(xs,"Extremes");let Lt=xs;const ws=class ws extends Pt{constructor(t,e){super(t,e),this.visible=!0,this.size=e.size}set size(t){this._size=t}get size(){return this._size}get x(){return this._x}get y(){return this._y}set x(t){this._x=t}set y(t){this._y=t}get transform(){return this._transform}};c(ws,"AxisPoint");let rs=ws,Ls={GRAPH:{ratio:1,x_max:1,y_max:1,selector:"body",width:1,height:1,axes:!0,SIZE_EFFECT:1,dimensions:[0,1]},NODE:{size:1,highlight:{color:"yellow",labels:q.DISPLAY_TYPES.ON},labels:q.DISPLAY_TYPES.ON,labelposition:q.POSITION.OBJECT},POINT:{active:2,size:.05,color:"#000",shape:J.SHAPES.CIRCLE,labels:q.DISPLAY_TYPES.AUTO,labelposition:q.POSITION.OBJECT},MEAN:{shape:J.SHAPES.SQUARE,labels:q.DISPLAY_TYPES.AUTO},LABEL:{highlight:q.HIGHLIGHT.OFF,position:["top","left"],container:"#label-container"},EDGE:{multiplier:1}};const vs=class vs{constructor(t={...Ls}){this.__state__=new Le,this.name="unnamed-graph",this.origin=void 0,this.points=new Map,this.nodes=new Map,this.edges=new Map,this.trajectories=new Map,this.labels=new Map,this.transform=new he,this.scale_x=1,this.scale_y=1,this.SIZE_EFFECT=1,this._mirror_y=!0,this._mirror_x=!1,this._layers=new Wt({name:"graph",tabindex:0,layers:[{name:"axes",layers:[{name:"axis_lines",tabindex:0,layers:[],objects:[]},{name:"axis_labels",tabindex:0,layers:[],objects:[]},{name:"axis_points",tabindex:0,layers:[],objects:[this.origin]}]},{name:"network",layers:[{name:"edges",layers:[],tabindex:0},{name:"nodes",layers:[],tabindex:0},{name:"edgenodes",layers:[],tabindex:0}]},{name:"trajectories",layers:[],tabindex:0},{name:"points",layers:[],tabindex:0},{name:"labels",layers:[],tabindex:0}]}),this.options=t,this.origin=new rs(new Dt(0,0),{ID:"origin",x:0,y:0,size:0,meta:{},graph:this,color:new tt("#FFFFFF"),highlight:new tt("#FFFFFF"),active:!1});let e=1;function s(r,a,h){const o=new ns(`${e}`,r,h);return e+=1,o.parent=a||void 0,r.layers&&Array.isArray(r.layers)&&(o.layers=new Wt(...r.layers.map(_=>s(_,o,h)))),o}c(s,"buildLayerTree"),this.layers=new Wt(...this._layers.map(r=>s(r,null,this)));let i=this.layers.search("layers","axis_points");i&&i.objects.set(this.origin.ID,this.origin);let n=this.layers.search("layers","axis_lines");if(n){let r=this.extremes||new Lt(1,1),a=new Ht({},new J({ID:"axis-x-start",dimensions:[-r.x_max,0],classes:["ena.dimension","ena.dimension"]}),new J({ID:"axis-x-end",dimensions:[r.x_max,0],classes:["ena.dimension","ena.dimension"]}));a.ID="axis-x",n.objects.set(a.ID,a);let h=new Ht({},new J({ID:"axis-y-start",dimensions:[0,-r.y_max],classes:["ena.dimension","ena.dimension"]}),new J({ID:"axis-y-end",dimensions:[0,r.y_max],classes:["ena.dimension","ena.dimension"]}));h.ID="axis-y",n.objects.set(h.ID,h),Xt("Added axis lines to layer: ",n)}this.extremes=new Lt(t.GRAPH.x_max,t.GRAPH.y_max)}set extremes(t){this._extremes=t}get extremes(){return this._extremes}get mirror_x(){return this._mirror_x}set mirror_x(t){this._mirror_x=t}get mirror_y(){return this._mirror_y}set mirror_y(t){this._mirror_y=t}x_mirror(){return this.mirror_x?-1:1}y_mirror(){return this.mirror_y?-1:1}add_point(t){const e=new J(t);this.points.set(e.ID,e)}add_points(t){let e=this;t.rows().forEach(s=>{e.add_point(s)})}add_nodes(t){let e=this;t.forEach(s=>{s.label=new q(s.ID,s),e.labels.set(s.label.ID,s.label),e.nodes.set(s.ID,s);const i=e.layers.search("layers","nodes");i&&i.objects.push(s)}),e.update_extremes()}add_edge(t,e,s){return this.edges.set(t.ID,t),this.add_nodes([e||t.from,s||t.to]),t}add_edges(t){let e=t.map(i=>this.add_edge(i));const s=this.layers.search("layers","edges");return s&&s.objects.push(...e),e}update_extremes(t=!1){const e=[this.layers.search("layers","points"),this.layers.search("layers","nodes")].filter(s=>s!==void 0);if(e.length===0)this.extremes=new Lt(1,1);else{let s=1/0,i=-1/0,n=1/0,r=-1/0;e.forEach(p=>p.objects.forEach(u=>{Number.isFinite(u.x)&&(s=Math.min(s,u.x),i=Math.max(i,u.x)),Number.isFinite(u.y)&&(n=Math.min(n,u.y),r=Math.max(r,u.y))}));const a=Number.isFinite(s)&&Number.isFinite(n),h=t&&a?(s+i)/2:0,o=t&&a?(n+r)/2:0,_=a?Math.max(Math.abs(s-h),Math.abs(i-h),Math.abs(n-o),Math.abs(r-o)):0,g=(_>0?_:1)*1.3;this.extremes=new Lt(g,g,h,o)}}nodeExtentFrom(t,e){const s=this.layers.search("layers","nodes");let i=0;return s==null||s.objects.forEach(n=>{Number.isFinite(n.x)&&Number.isFinite(n.y)&&(i=Math.max(i,Math.abs(n.x-t),Math.abs(n.y-e)))}),i}base_point_size(t=8){let e=Math.min(this.extremes.x_max,this.extremes.y_max),s=this.points.size+this.nodes.size;return Math.min(1,e/(Math.sqrt(s)*t))}};c(vs,"Graph");let Re=vs;const Ue=class Ue extends HTMLElement{constructor(){super(),this.element=null,this.object=null;const t=this,e=t.attachShadow({mode:"open"}),s=document.createElement("style"),i=document.createElement("div");s.textContent=this.constructor.style,e.appendChild(s),i.setAttribute("class","wrapper"),e.appendChild(i)}get wrapper(){const t=this,e=t.shadowRoot;return e==null?void 0:e.querySelector(".wrapper")}};c(Ue,"DrawableElement"),Ue.style=`
9
9
  :host {
10
10
  max-width: 100%;
11
11
  display: block;
@@ -15,8 +15,8 @@
15
15
  display: flex;
16
16
  justify-content: center;
17
17
  }
18
- `;let Ce=De;const Ns=1e-8;function Qe(d,t=Ns){return d.filter(e=>Math.abs(e.x)>t||Math.abs(e.y)>t)}_(Qe,"nearOriginFilter");function ks(d){if(d<=0)return[];if(d===1)return[0];const t=new Array(d);for(let e=0;e<d;e++)t[e]=e/(d-1);return t}_(ks,"normalizedT");function Cs(d,t){return d.map(e=>{const s=new Array(t+1);let i=1;for(let n=0;n<=t;n++)s[n]=i,i*=e;return s})}_(Cs,"design");function Os(d){const t=d.length,e=d[0].length,s=d.map(n=>n.slice()),i=Array.from({length:e},()=>new Array(e).fill(0));for(let n=0;n<e;n++){let r=0;for(let a=0;a<t;a++)r+=s[a][n]*s[a][n];if(r=Math.sqrt(r),i[n][n]=r,r>1e-300)for(let a=0;a<t;a++)s[a][n]/=r;for(let a=n+1;a<e;a++){let h=0;for(let o=0;o<t;o++)h+=s[o][n]*s[o][a];i[n][a]=h;for(let o=0;o<t;o++)s[o][a]-=h*s[o][n]}}return{Q:s,R:i}}_(Os,"qr");function ts(d,t){const e=d.length,s=d[0].length,i=new Array(s).fill(0);for(let n=0;n<s;n++){let r=0;for(let a=0;a<e;a++)r+=d[a][n]*t[a];i[n]=r}return i}_(ts,"qtY");function es(d,t){const e=t.length,s=new Array(e).fill(0);for(let i=e-1;i>=0;i--){let n=t[i];for(let r=i+1;r<e;r++)n-=d[i][r]*s[r];s[i]=Math.abs(d[i][i])>1e-12?n/d[i][i]:0}return s}_(es,"backSolve");function li(d){return d.map(t=>{let e=0;for(let s=0;s<t.length;s++)e+=t[s]*t[s];return e})}_(li,"leverages");function $s(d,t,e){const s=Cs(d,e),{Q:i,R:n}=Os(s);return es(n,ts(i,t))}_($s,"fitCoeffs");function Oe(d,t){let e=0,s=1;for(let i=0;i<d.length;i++)e+=d[i]*s,s*=t;return e}_(Oe,"evalPoly");function ci(d,t,e,s){const i=Cs(d,s),{Q:n,R:r}=Os(i),a=li(n),h=es(r,ts(n,t)),o=es(r,ts(n,e));let l=0;for(let u=0;u<d.length;u++){const g=1-a[u];if(g<=0)return 1/0;const c=t[u]-Oe(h,d[u]),M=e[u]-Oe(o,d[u]);l+=(c/g)**2+(M/g)**2}return l}_(ci,"loocv2d");function Ps(d,t,e){const s=d.length,i=Math.min(Math.max(1,Math.floor(t)),Math.max(1,s-1));if(e==="fixed"||s<3)return i;const n=ks(s),r=d.map(l=>l.x),a=d.map(l=>l.y);let h=1,o=1/0;for(let l=1;l<=i;l++){const u=ci(n,r,a,l);u<o&&(o=u,h=l)}return h}_(Ps,"selectDegree");function Rs(d,t){const e=Qe(d);if(e.length<3)return null;const s=t.selectionSet?Qe(t.selectionSet):e,i=s.length>=3?s:e;let n=Ps(i,t.maxDegree,t.degreeSelection);n=Math.min(n,Math.max(1,e.length-1));const r=ks(e.length),a=$s(r,e.map(o=>o.x),n),h=$s(r,e.map(o=>o.y),n);return{degree:n,coeffsX:a,coeffsY:h}}_(Rs,"fitTrajectory");function ss(d,t=100){const e=[];for(let s=0;s<=t;s++){const i=s/t;e.push({x:Oe(d.coeffsX,i),y:Oe(d.coeffsY,i)})}return e}_(ss,"sampleCurve");const Ls=100,ms=class ms extends Ot{constructor(t={}){const e=t.color instanceof et?t.color:new et(typeof t.color=="string"?t.color:"#000000");super([],{ID:t.ID||`traj-${Math.random().toString(36).substring(2,9)}`,size:t.size||1,color:e,highlight:null,active:t.active||!1,meta:t.meta||{},...t}),this._typeName="Trajectory",this.trajPoints=[],this.smooth="none",this.maxDegree=3,this.degreeSelection="loocv_2d",this.selectedDegree=-1,this.polyCoeffsX=[],this.polyCoeffsY=[],this.currentTime=1/0,this.showPoints=!0,this.showTips=!0,this.lineStyle="uniform",this.strokeWidth=2,this.strokeWidthRange=[1,6],this.opacityRange=[.3,1],this.smooth=t.smooth||"none",this.maxDegree=t.maxDegree!==void 0?t.maxDegree:3,this.degreeSelection=t.degreeSelection||"loocv_2d",this.polyCoeffsX=t.polyCoeffsX||[],this.polyCoeffsY=t.polyCoeffsY||[],this.currentTime=t.currentTime!==void 0?t.currentTime:1/0,this.showPoints=t.showPoints!==void 0?t.showPoints:!0,this.showTips=t.showTips!==void 0?t.showTips:!0,this.lineStyle=t.lineStyle||"uniform",this.strokeWidth=t.strokeWidth||2,this.strokeWidthRange=t.strokeWidthRange||[1,6],this.opacityRange=t.opacityRange||[.3,1],t.points&&Array.isArray(t.points)&&(this.trajPoints=t.points.map(s=>{if(s instanceof Z)return s;const i=new Z({dimensions:[s.x,s.y],meta:{time:s.time,label:s.label}});return i.x=s.x,i.y=s.y,i}))}get activePoints(){return this.currentTime===1/0?this.trajPoints:this.trajPoints.filter(t=>(t.meta&&typeof t.meta.time=="number"?t.meta.time:0)<=this.currentTime)}get path(){return this.pathPoints.reduce((t,e,s)=>s===0?`M${e.x},${e.y}`:`${t} L${e.x},${e.y}`,"")}get pathPoints(){const t=this.activePoints;if(t.length<2)return[];if(this.smooth==="poly"){if(this.polyCoeffsX.length>0&&this.polyCoeffsY.length>0)return ss({degree:this.polyCoeffsX.length-1,coeffsX:this.polyCoeffsX,coeffsY:this.polyCoeffsY},Ls);const e=Rs(t.map(s=>({x:s.x,y:s.y})),{maxDegree:this.maxDegree,degreeSelection:this.degreeSelection,selectionSet:this.trajPoints.map(s=>({x:s.x,y:s.y}))});if(e)return this.selectedDegree=e.degree,ss(e,Ls)}return t.map(e=>({x:e.x,y:e.y}))}};_(ms,"Trajectory");let ne=ms;const Ts=1,ps=class ps extends Gt{constructor(t,e,s,i=0){super(t,e,s),this._totalweight=0,this._weight=i}get base_color(){return this._color}get color(){const t=this._color||new et("#000000");return new ee(t,Math.abs(this.weight))}set color(t){this._color=t}base_weight(){return this._weight}get weight(){return Array.isArray(this._weight)?this._weight[0]-this._weight[1]:this._weight}set weight(t){this._weight=t}get totalweight(){return this.weight}set totalweight(t){this._totalweight=t}};_(ps,"Edge");let re=ps;const bs=class bs extends Ot{constructor(e){super(e.dimensions||[],e);nt(this,Vt);W(this,Vt,e)}get edge(){return C(this,Vt)}get path(){const e=C(this,Vt),s=[e.to.x,e.to.y],i=e.from_point,[n,r]=e.base_pts,a=Math.hypot(i[0]-s[0],i[1]-s[1]),h=Math.hypot(n[0]-r[0],n[1]-r[1]);if(!(a>0)||!(h>0))return"";const o=[(i[0]-s[0])/a,(i[1]-s[1])/a],l=Math.hypot(n[0]-s[0],n[1]-s[1]),u=[(n[0]-s[0])/l,(n[1]-s[1])/l],g=_(q=>h/2*Math.max(0,1-q/a),"halfW"),c=_((q,v)=>`${s[0]+o[0]*q+u[0]*v} ${s[1]+o[1]*q+u[1]*v}`,"at"),M=.2*a,m=Math.min(.15*a,.8*2*g(M)),E=M+m/2,L=M+m;return`M${c(M,0)} L${c(E,g(E))} L${c(L,g(L))} L${c(E,0)} L${c(L,-g(L))} L${c(E,-g(E))}z`}};Vt=new WeakMap,_(bs,"EdgeArrow");let $e=bs;const ze=class ze extends re{constructor(e,s,i){super(e,s,i);nt(this,Kt);nt(this,Me);this._path="",W(this,Kt,!1),this._directions=["from","to"],this.towards="to",C(this,Kt)===!0&&W(this,Me,new $e(this))}get path(){return`M${this.from.x} ${this.from.y} L${this.base_pts[0].join(" ")} L${this.base_pts[1].join(" ")}z`}static calculate_base_points(e){const s=e.towards,i=e._directions.find(E=>E!==e.towards),n=e[i].x,r=e[i].y,a=e[s].x,h=e[s].y,o=a-n,l=h-r,u=Math.hypot(o,l),g=(e.weight??0)*Ts;if(u===0||!isFinite(g)||g===0)return[[a,h],[a,h]];const c=-l/u,M=o/u,m=g/2;return[[a+c*m,h+M*m],[a-c*m,h-M*m]]}get base_pts(){return ze.calculate_base_points(this)}get arrow(){return C(this,Me)}get with_arrow(){return C(this,Kt)}get from_point(){return[this.from.x,this.from.y]}};Kt=new WeakMap,Me=new WeakMap,_(ze,"TaperedEdge");let Ut=ze;const Fe=class Fe extends Ut{constructor(t,e,s){super(t,e,s),this._dataWeight=0,this._totalweight=t.totalweight??0,this._dataWeight=t.weight??this._weight}get weighted_midpoint(){return ie.Geometry.Line.interpolate(this.line)(1-this._dataWeight/this._totalweight)}get base_pts(){return Ut.calculate_base_points(this)}static build_path(t){return t._totalweight>0?`M${t.weighted_midpoint[0]} ${t.weighted_midpoint[1]} L${t.base_pts[0].join(" ")} L${t.base_pts[1].join(" ")}z`:(console.error("TaperedWeightedMidpointEdge: No totalweight, returning empty path"),"")}get path(){return Fe.build_path(this)}get from_point(){return this.weighted_midpoint}};_(Fe,"TaperedWeightedMidpointEdge");let is=Fe;const je=class je extends re{constructor(t,e,s){super(t,e,s)}static build_path(t,e){let s=t/2,i=e.x-s,n=s*2;return`M ${i}, ${e.y} a ${s},${s} 0 1,0 ${n},0 a ${s},${s} 0 1,0 -${n},0`}get path(){let t=this.weight*Ts;return je.build_path(t,this.to)}};_(je,"NodeEdge");let oe=je;const ys=class ys{constructor(t,e,s,i=new $t){this.__data__=t,this.parent=e,this.graph=s,this.__children__=i,this.svg_element=this.create()}get_size(){return this.__data__.size}draw(){var t;(t=this.parent)==null||t.appendChild(this.svg_element)}update(t,e=!0){}animateSVGAttribute(t,e,s){const i=parseFloat(t.getAttribute(e)||"0");if(i===s)return;const n=5e3,r=performance.now();function a(h){const o=Math.min(1,(h-r)/n),l=i+(s-i)*o;t.setAttribute(e,l.toString()),o<1?requestAnimationFrame(a):t.setAttribute(e,s.toString())}_(a,"animate"),requestAnimationFrame(a)}};_(ys,"Drawable");let ae=ys;const ui=.04,_i=[.25,1],di=[.3,1];function Ds(d,t,e,s){const i=Math.abs(d);if(!(i>0))return 0;if(!(e>t))return s[1];const n=Math.min(1,Math.max(0,(i-t)/(e-t)));return s[0]+n*(s[1]-s[0])}_(Ds,"rampFor");const gi=.011,fi=.75,mi=.8,pi=.75,zs=.006,bi=.6;function yi(d){return 2*d}_(yi,"widthPerWeight");function xi(d,t){return d*t/(2*zs)}_(xi,"nodeSizeForEdges");function wi(d){const t=/rgba?\(([^)]+)\)/.exec(d);if(!t)return d;const[e,s,i,n=1]=t[1].split(",").map(Number),r=_(a=>Math.round(255+(a-255)*n),"f");return`rgb(${r(e)},${r(s)},${r(i)})`}_(wi,"flattenOnWhite");function Ai(d,t){const e=/rgba?\(([^)]+)\)/.exec(d);if(!e)return d;const[s,i,n,r=1]=e[1].split(",").map(Number);return`rgba(${Math.round(s*t)},${Math.round(i*t)},${Math.round(n*t)},${r})`}_(Ai,"darkenRgba");const xs=class xs extends ae{constructor(t,e,s,i=new $t){super(t,e,s,i),this.__data__=t,this.parent=e,this.graph=s,this.__children__=i,this.__name__="unnamed-line",this._arrow_el=null,this._hit_el=null,this.svg_element=this.create()}_stampEdge(t){const e=this.__data__.meta??{};e.isMeanEdge&&(t.setAttribute("data-edge-source",String(e.source??"")),t.setAttribute("data-edge-target",String(e.target??"")),t.setAttribute("data-edge-weight",String(e.weight??0)),t.setAttribute("data-edge-directed",e.isDirected?"true":"false"),e.isSelf&&t.setAttribute("data-edge-self","true"),e.group!=null&&t.setAttribute("data-edge-group",String(e.group)),e.unit!=null&&t.setAttribute("data-edge-unit",String(e.unit)))}create(){if(this.__data__ instanceof oe){const e=document.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("fill",this.__data__.color.toString()),e.setAttribute("stroke","none"),this.svg_element=e,e}if(this.__data__ instanceof Ut){const e=document.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("fill",this.__data__.color.toString()),e.setAttribute("stroke","none"),this.svg_element=e,e}const t=document.createElementNS("http://www.w3.org/2000/svg","line");return t.setAttribute("x1",this.__data__.from.x.toString()),t.setAttribute("y1",this.__data__.from.y.toString()),t.setAttribute("x2",this.__data__.to.x.toString()),t.setAttribute("y2",this.__data__.to.y.toString()),t.setAttribute("stroke-width",this.get_size().toString()),t.setAttribute("stroke",this.__data__.color.toString()),this.svg_element=t,t}update(){var s;this.svg_element||this.create(),this.svg_element.parentElement||this.parent.appendChild(this.svg_element);const t=((s=this.graph.__data__.extremes)==null?void 0:s.x_max)??1,e=this.__data__.meta??{};if(e.isMeanEdge){this._stampEdge(this.svg_element);const i=typeof e.weight=="number"?e.weight:0,n=typeof e.maxWeight=="number"?e.maxWeight:1,r=typeof e.opacity=="number"?e.opacity:Math.min(1,i/(n||1)),a=t>0?t:1,h=typeof e.widthFrac=="number"?a*e.widthFrac*i:a*gi*(i/(n||1)),o=this.__data__._color||new et("#000000"),l=typeof e.saturation=="number"?e.saturation:r,u=new ee(o,l,r).toString();if(this.__data__ instanceof oe)this.__data__.weight=h,this.svg_element.setAttribute("d",this.__data__.path),this.svg_element.setAttribute("fill",u),this.svg_element.setAttribute("stroke","none");else if(this.__data__ instanceof Ut){if(this.__data__.weight=h,this.svg_element.setAttribute("d",this.__data__.path),this.svg_element.setAttribute("fill",u),this.svg_element.setAttribute("stroke",u),this.svg_element.setAttribute("stroke-width",String(fi)),this.svg_element.setAttribute("vector-effect","non-scaling-stroke"),this.svg_element.setAttribute("stroke-linejoin","round"),e.isDirected)try{const c=new $e(this.__data__).path;c&&!c.includes("NaN")&&!c.includes("Infinity")&&(this._arrow_el||(this._arrow_el=document.createElementNS("http://www.w3.org/2000/svg","path"),this._arrow_el.setAttribute("stroke","none")),this._arrow_el.parentElement||this.parent.appendChild(this._arrow_el),this._arrow_el.setAttribute("d",c),this._arrow_el.setAttribute("fill",Ai(wi(u),mi)),this._arrow_el.setAttribute("stroke","#ffffff"),this._arrow_el.setAttribute("stroke-width",String(pi)),this._arrow_el.setAttribute("vector-effect","non-scaling-stroke"),this._arrow_el.setAttribute("stroke-linejoin","round"))}catch{}}else{const g=this.__data__.from.x,c=this.__data__.from.y,M=this.__data__.to.x,m=this.__data__.to.y;this.svg_element.setAttribute("x1",g.toString()),this.svg_element.setAttribute("y1",c.toString()),this.svg_element.setAttribute("x2",M.toString()),this.svg_element.setAttribute("y2",m.toString()),this.svg_element.setAttribute("stroke-width",h.toString()),this.svg_element.setAttribute("stroke",u),this.svg_element.setAttribute("pointer-events","stroke"),this.svg_element.removeAttribute("marker-end"),this._hit_el||(this._hit_el=document.createElementNS("http://www.w3.org/2000/svg","line"),this._hit_el.setAttribute("stroke","transparent"),this._hit_el.setAttribute("stroke-linecap","round"),this._hit_el.setAttribute("pointer-events","stroke")),this._hit_el.parentElement||this.parent.appendChild(this._hit_el),this._hit_el.setAttribute("x1",g.toString()),this._hit_el.setAttribute("y1",c.toString()),this._hit_el.setAttribute("x2",M.toString()),this._hit_el.setAttribute("y2",m.toString()),this._hit_el.setAttribute("stroke-width",Math.max(h,t*.03).toString()),this._stampEdge(this._hit_el)}}else{this.svg_element.setAttribute("x1",this.__data__.from.x.toString()),this.svg_element.setAttribute("y1",this.__data__.from.y.toString()),this.svg_element.setAttribute("x2",this.__data__.to.x.toString()),this.svg_element.setAttribute("y2",this.__data__.to.y.toString());const i=(t>0?t:1)*.004*this.get_size();this.svg_element.setAttribute("stroke-width",i.toString()),this.svg_element.setAttribute("stroke-opacity","1"),this.svg_element.setAttribute("stroke",this.__data__.color.toString())}}draw(){var t,e,s;this._hit_el&&((t=this.parent)==null||t.appendChild(this._hit_el)),(e=this.parent)==null||e.appendChild(this.svg_element),this._arrow_el&&((s=this.parent)==null||s.appendChild(this._arrow_el))}};_(xs,"QELine");let vt=xs;const ws=class ws extends ae{constructor(t,e,s,i=new $t){super(t,e,s,i),this.__data__=t,this.parent=e,this.graph=s,this.__children__=i,this.__name__="unnamed-point",this.svg_element=this.create()}get x(){return this.__data__.dimensions[this.graph.__data__.options.GRAPH.dimensions[0]]}get y(){return this.__data__.dimensions[this.graph.__data__.options.GRAPH.dimensions[1]]}get isSquare(){return this.__data__.shape==="rect"}get shapeKind(){const t=this.__data__.shape;return t==="rect"||t==="square"?"rect":t==="triangle"||t==="diamond"?t:"circle"}get tag(){const t=this.shapeKind;return t==="circle"?"circle":t==="rect"?"rect":"path"}setGeometry(t,e){const s=this.x,i=this.y;switch(this.shapeKind){case"rect":t.setAttribute("x",(s-e).toString()),t.setAttribute("y",(i-e).toString()),t.setAttribute("width",(e*2).toString()),t.setAttribute("height",(e*2).toString());break;case"triangle":{const n=e*1.15;t.setAttribute("d",`M${s} ${i-n} L${s+n*.866} ${i+n*.5} L${s-n*.866} ${i+n*.5}Z`);break}case"diamond":t.setAttribute("d",`M${s} ${i-e*1.2} L${s+e} ${i} L${s} ${i+e*1.2} L${s-e} ${i}Z`);break;default:t.setAttribute("cx",s.toString()),t.setAttribute("cy",i.toString()),t.setAttribute("r",e.toString())}}computeRadius(){var s;const t=this.baseRadius(),e=(s=this.__data__.meta)==null?void 0:s.maxRadius;return typeof e=="number"&&e>0?Math.min(t,e):t}baseRadius(){var s,i,n,r;const t=this.graph.__data__.extremes.x_max||1,e=((s=this.__data__.meta)==null?void 0:s.sizeScale)??1;if((i=this.__data__.meta)!=null&&i.fixedSize){const a=(r=(n=this.graph.svg_element)==null?void 0:n.getBoundingClientRect)==null?void 0:r.call(n),h=this.graph.zoom_level||1,o=a&&a.width>0?a.width/(2*t):1;return this.__data__.size*2*e/o/h}return t*zs*this.__data__.size*e}applyStroke(t){var s;const e=(s=this.__data__.meta)==null?void 0:s.stroke;e&&(t.setAttribute("stroke",e),t.setAttribute("stroke-width",(this.computeRadius()*.22).toString()))}create(){const t=document.createElementNS("http://www.w3.org/2000/svg",this.tag);t.setAttribute("data-point-id",this.__data__.ID);const e=this.__data__.meta??{};return e.kind&&t.setAttribute("data-kind",e.kind),e.name!=null&&t.setAttribute("data-name",String(e.name)),e.group!=null&&t.setAttribute("data-group",String(e.group)),e.unit!=null&&t.setAttribute("data-unit",String(e.unit)),t.setAttribute("fill",this.__data__.color.toString()),this.applyStroke(t),this.setGeometry(t,this.computeRadius()),this.svg_element=t,t.addEventListener("click",()=>{this.__data__.active=!this.__data__.active,this.update();const s=new CustomEvent("point-clicked",{detail:{pointData:this.__data__},bubbles:!0,composed:!0});this.svg_element.dispatchEvent(s)}),t.addEventListener("mouseover",()=>{}),t}update(){this.svg_element||this.parent.__data__.__children__.push(this.create()),this.svg_element.parentElement||this.parent.appendChild(this.svg_element),this.svg_element.setAttribute("fill",this.__data__.color.toString()),this.applyStroke(this.svg_element),this.setGeometry(this.svg_element,this.computeRadius())}draw(){var t;(t=this.parent)==null||t.appendChild(this.svg_element)}};_(ws,"QEPoint");let Bt=ws;const As=class As extends ae{constructor(t,e,s,i=new $t){super(t,e,s,i),this.__data__=t,this.parent=e,this.graph=s,this.__children__=i,this.__name__="trajectory",this._path_el=null,this._segments_group=null,this._tip_el=null,this._points_group=null,this.svg_element=this.create()}graphUnitsForPixels(t){var i;const e=this.graph.__data__.extremes.x_max||1,s=((i=this.graph.svg_element)==null?void 0:i.getBoundingClientRect().width)||0;return s>0?t*(2*e/s):t*e*.006}create(){const t=document.createElementNS("http://www.w3.org/2000/svg","g");t.setAttribute("class","qe-trajectory-group");const e=document.createElementNS("http://www.w3.org/2000/svg","path");e.setAttribute("fill","none"),e.setAttribute("stroke",this.__data__.color.toString()),e.setAttribute("stroke-width",this.graphUnitsForPixels(this.__data__.strokeWidth).toString()),t.appendChild(e),this._path_el=e;const s=document.createElementNS("http://www.w3.org/2000/svg","g");s.setAttribute("class","qe-trajectory-segments"),t.appendChild(s),this._segments_group=s;const i=document.createElementNS("http://www.w3.org/2000/svg","g");if(i.setAttribute("class","qe-trajectory-points"),t.appendChild(i),this._points_group=i,this.__data__.showTips){const n=document.createElementNS("http://www.w3.org/2000/svg","circle");n.setAttribute("fill",this.__data__.color.toString()),n.setAttribute("r",this.graphUnitsForPixels(4).toString()),n.setAttribute("stroke","#ffffff"),n.setAttribute("stroke-width",this.graphUnitsForPixels(1.5).toString()),t.appendChild(n),this._tip_el=n}return this.svg_element=t,t}update(){this.svg_element||this.create(),this.svg_element.parentElement||this.parent.appendChild(this.svg_element);const t=this.__data__.path;if(this._path_el&&(this._path_el.setAttribute("d",t),this._path_el.setAttribute("stroke",this.__data__.color.toString()),this._path_el.setAttribute("stroke-width",this.graphUnitsForPixels(this.__data__.strokeWidth).toString()),this._path_el.style.display=this.__data__.lineStyle==="tapered"?"none":"block"),this._segments_group)if(this._segments_group.innerHTML="",this.__data__.lineStyle==="tapered"){const s=this.__data__.pathPoints,i=s.length-1,[n,r]=this.__data__.strokeWidthRange,[a,h]=this.__data__.opacityRange;for(let o=0;o<i;o++){const l=s[o],u=s[o+1],g=i<=1?1:o/(i-1),c=n+(r-n)*g,M=a+(h-a)*g,m=document.createElementNS("http://www.w3.org/2000/svg","path");m.setAttribute("d",`M${l.x},${l.y} L${u.x},${u.y}`),m.setAttribute("fill","none"),m.setAttribute("stroke",this.__data__.color.toString()),m.setAttribute("stroke-linecap","round"),m.setAttribute("stroke-linejoin","round"),m.setAttribute("stroke-width",this.graphUnitsForPixels(c).toString()),m.setAttribute("opacity",M.toString()),this._segments_group.appendChild(m)}this._segments_group.style.display="block"}else this._segments_group.style.display="none";const e=this.__data__.activePoints;if(this._points_group&&(this.__data__.showPoints&&e.length>0?(this._points_group.innerHTML="",e.forEach(s=>{var n;const i=document.createElementNS("http://www.w3.org/2000/svg","circle");i.setAttribute("cx",s.x.toString()),i.setAttribute("cy",s.y.toString()),i.setAttribute("r",this.graphUnitsForPixels(2.5).toString()),i.setAttribute("fill",this.__data__.color.toString()),i.setAttribute("opacity","0.7"),(n=this._points_group)==null||n.appendChild(i)}),this._points_group.style.display="block"):this._points_group.style.display="none"),this._tip_el&&this.__data__.showTips)if(e.length>0){const s=e[e.length-1];this._tip_el.setAttribute("cx",s.x.toString()),this._tip_el.setAttribute("cy",s.y.toString()),this._tip_el.setAttribute("fill",this.__data__.color.toString()),this._tip_el.setAttribute("r",this.graphUnitsForPixels(4).toString()),this._tip_el.setAttribute("stroke-width",this.graphUnitsForPixels(1.5).toString()),this._tip_el.style.display="block"}else this._tip_el.style.display="none"}draw(){this.svg_element&&!this.svg_element.parentElement&&this.parent.appendChild(this.svg_element),this.update()}};_(As,"QETrajectory");let he=As;const{ArrayTools:Fs}=ie,vs=class vs extends Array{constructor(...t){super(...t)}search(t,e){let s;function i(r){return r.name===e?r:void 0}_(i,"fn");function n(r,a,h=null){if(Fs.isArray(r)){for(const[o,l]of r.entries())if(s=n(l,o,h),s)return s}else{if(s=i(r),s)return s;if(r&&Fs.isArray(r[t])){for(const[o,l]of r[t].entries())if(s=n(l,o,r),s)return s}}return s}return _(n,"recurse"),n(this)}flatten(){return this.reduce((t,e)=>(t.push(e),e.layers&&Array.isArray(e.layers)&&t.push(...e.layers),t),[])}};_(vs,"QEArray");let $t=vs;const vi={AxisPoint:Bt,AxisLine:vt,Point:Bt,Line:vt,Edge:vt,TaperedEdge:vt,TaperedWeightedMidpointEdge:vt,NodeEdge:vt,Trajectory:he},Jt=class Jt{constructor(t,e,s,i=new $t){this.__data__=t,this.parent=e,this.graph=s,this.__children__=i,this.__name__=t.name||"unnamed-layer",t.__state__.addListener("layer_updated","live",({key:n,newValue:r,oldValue:a})=>{const h=_(g=>{var c;return(c=g.__data__)==null?void 0:c.ID},"childId"),o=this.__children__.filter(g=>!r.objects.has(h(g))),l=this.__children__.filter(g=>r.objects.has(h(g)));[...r.objects.values()].filter(g=>!this.__children__.some(c=>h(c)===g.ID)).forEach(g=>{const c=g._typeName||g.constructor.name;let M=vi[c];M||(g instanceof ne?M=he:g instanceof Z?M=Bt:M=vt);const m=new M(g,this.svg_element,this.graph);this.__children__.push(m)}),l.forEach(g=>{const c=r.objects.get(h(g));c&&(g.__data__=c),g.update()}),o.forEach(g=>{g.svg_element.parentElement&&g.svg_element.parentElement.removeChild(g.svg_element);const c=this.__children__.indexOf(g);c>=0&&this.__children__.splice(c,1)}),this.update()}),this.svg_element=this.create()}get name(){return this.__name__}create(){if(!this.__data__)throw new Error("Layer is null");let t=this.__data__;return this.svg_element=document.createElementNS("http://www.w3.org/2000/svg",Jt.tagName),this.svg_element.setAttribute("data-layer-name",t.name),this.svg_element.setAttribute("data-layer-id",t.ID),this.svg_element.__data__=t,this.svg_element.classList.add("ena-layer"),this.__data__.layers&&this.__data__.layers.length>0&&this.__data__.layers.forEach(e=>{const s=new Jt(e,this.svg_element,this.graph);this.__children__.push(s)}),this.svg_element}update(){if(!this.__data__)throw new Error("Layer is null");this.__data__.visible&&(this.parent.nodeName.toLowerCase(),this.__children__.forEach(t=>{t.update()}),this.__data__.scale_objects===!0&&this.__name__)}draw(){var t;(t=this.parent)==null||t.appendChild(this.svg_element),this.__children__.forEach(e=>{e.draw()})}add(t){this.__children__.push(t)}};_(Jt,"QELayer"),Jt.tagName="g";let Pe=Jt;const Ss=class Ss{constructor(t,e,s,i,n=H.DISPLAY_TYPES.ON,r=H.POSITION.OBJECT,a,h){this.text=t,this.point=e,this.parent=s,this.graph=i,this.displayMode=n,this.position=r,this.customX=a,this.customY=h,this._visible=!1,this._offsetX=0,this._offsetY=0,this.pinned=!1,this.svg_element=this._create(),n===H.DISPLAY_TYPES.ON?(this._visible=!0,this.svg_element.setAttribute("display","block")):(this._visible=!1,this.svg_element.setAttribute("display","none"))}_create(){const t=document.createElementNS("http://www.w3.org/2000/svg","text");return t.textContent=this.text,t.setAttribute("data-label-for",this.point.ID),t.setAttribute("pointer-events","auto"),t.style.cursor="grab",this._attachDrag(t),this.parent.appendChild(t),t}_attachDrag(t){t.addEventListener("mousedown",e=>{e.preventDefault(),e.stopPropagation();const s=t.ownerSVGElement;if(!s)return;const i=_((l,u)=>{const g=s.createSVGPoint();g.x=l,g.y=u;const c=s.getScreenCTM();return c?g.matrixTransform(c.inverse()):{x:0,y:0}},"toUser"),n=i(e.clientX,e.clientY),r=this._offsetX,a=this._offsetY;t.style.cursor="grabbing";const h=_(l=>{const u=i(l.clientX,l.clientY);this._offsetX=r+(u.x-n.x),this._offsetY=a+(u.y-n.y),this.pinned=!0,this._visible=!0,this.svg_element.setAttribute("display","block"),this.update()},"onMove"),o=_(()=>{document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",o),t.style.cursor="grab",this.graph.dispatchEvent(new CustomEvent("qe-label-move",{detail:{id:this.point.ID,transform:{x:this._offsetX,y:this._offsetY}},bubbles:!0,composed:!0}))},"onUp");document.addEventListener("mousemove",h),document.addEventListener("mouseup",o)})}update(){var h;if(!this._visible)return;const t=this.graph.__data__.extremes.x_max;if(t<=0)return;const e=this.graph._labelFont??{},s=e.size?e.size*this.graph.unitsPerPixel():t*.06,i=s*1.2;let n,r,a;switch(this.position){case H.POSITION.STATIC:{n=this.point.x,r=this.point.y-i*.3,a="middle";break}case H.POSITION.CONTAINER:{const{cx:o,cy:l}=this.graph.__data__.extremes,u=this.point.x-o,g=this.point.y-l,c=Math.sqrt(u*u+g*g)||1,M=t*.93/c;n=o+u*M,r=l+g*M-i*.3,a=u>=0?"start":"end";break}case H.POSITION.CUSTOM:if(this.customX!=null&&this.customY!=null){n=this.customX,r=this.customY,a="start";break}default:case H.POSITION.OBJECT:{const o=this.point.x>=0?i:-i;a=this.point.x>=0?"start":"end",n=this.point.x+o,r=this.point.y-i*.4;break}}this.svg_element.setAttribute("x",n.toString()),this.svg_element.setAttribute("y",r.toString()),(this._offsetX||this._offsetY)&&this.svg_element.setAttribute("transform",`translate(${this._offsetX}, ${this._offsetY})`),this.svg_element.setAttribute("font-size",s.toString()),this.svg_element.setAttribute("font-family",e.family??"system-ui, sans-serif"),this.svg_element.setAttribute("font-weight","500"),this.svg_element.setAttribute("text-anchor",a),this.svg_element.setAttribute("fill",e.color??((h=this.point.color)==null?void 0:h.toString())??"#333333")}show(){this._visible=!0,this.svg_element.setAttribute("display","block"),this.update()}hide(){this.pinned||(this._visible=!1,this.svg_element.setAttribute("display","none"))}toggle(){this._visible?this.hide():this.show()}get visible(){return this._visible}remove(){this.svg_element.remove()}};_(Ss,"QELabel");let le=Ss;const Ye=class Ye extends HTMLElement{};_(Ye,"QENodesElement"),Ye.tagName="qe-nodes";let ce=Ye;const qe=class qe extends HTMLElement{};_(qe,"QEMeansElement"),qe.tagName="qe-means";let ue=qe;const Ge=class Ge extends HTMLElement{};_(Ge,"QEPointsElement"),Ge.tagName="qe-points";let _e=Ge;const Ue=class Ue extends HTMLElement{};_(Ue,"QEEdgesElement"),Ue.tagName="qe-edges";let de=Ue;const Be=class Be extends HTMLElement{};_(Be,"QETrajectoriesElement"),Be.tagName="qe-trajectories";let ge=Be;const He=class He extends HTMLElement{};_(He,"QEAxesElement"),He.tagName="qe-axes";let fe=He;customElements.define(ce.tagName,ce),customElements.define(ue.tagName,ue),customElements.define(_e.tagName,_e),customElements.define(de.tagName,de),customElements.define(ge.tagName,ge),customElements.define(fe.tagName,fe);const js=["#4477AA","#EE6677","#228833","#CCBB44","#66CCEE","#AA3377","#BBBBBB","#000000"];function Si(d,t){for(const e of t)if(d===`${e}.${e}`)return[e,e];for(const e of t)if(d.startsWith(e+".")){const s=d.slice(e.length+1);if(t.includes(s))return[e,s]}return null}_(Si,"parseEdgePair");function Ei(d,t,e,s){const i=Math.max(1,e-1),n=i>=120?1.96:i>=60?2:i>=30?2.042:i>=20?2.086:i>=10?2.228:i>=5?2.571:4.303,r=Math.sqrt(Math.max(0,d)/e)*s,a=Math.sqrt(Math.max(0,t)/e)*s;return{halfW:n*r,halfH:n*a}}_(Ei,"computeCIRect");const Mi=.5;function Re(d,t,e){if(!d)return;const s=Math.min(Math.abs(t),Math.abs(e));s>0&&(d.meta={...d.meta??{},maxRadius:s*Mi})}_(Re,"capMeanToInterval");function Le(d,t,e,s=""){const i=_(o=>{const l=d.names.indexOf(o),u=l>=0?d[l]:null;if(u==null||u==="")return;const g=Number(u);return Number.isFinite(g)?g:void 0},"get"),n=i(`${t}.${s}low`)??i(`${t}_${s}low`),r=i(`${t}.${s}high`)??i(`${t}_${s}high`),a=i(`${e}.${s}low`)??i(`${e}_${s}low`),h=i(`${e}.${s}high`)??i(`${e}_${s}high`);return n==null||r==null||a==null||h==null?null:{x_low:n,x_high:r,y_low:a,y_high:h}}_(Le,"readIntervalBounds");function Ii(d){var i,n;const t=_(r=>d.getAttribute(r),"a"),e=((i=t("colors"))==null?void 0:i.split(",").map(r=>r.trim()).filter(Boolean))??[],s=((n=t("threshold"))==null?void 0:n.split(",").map(Number).filter(Number.isFinite))??[];return{group:t("group"),unit:t("unit"),compare:t("compare"),also:t("also"),network:t("network"),colors:e.length?[e[0],e[1]??null]:null,threshold:s.length?[s[0],s.length>1?s[1]:1/0]:null,name:t("name")}}_(Ii,"parseEdgeLayer");function Ni(d){const{r:t,g:e,b:s}=et.parseColor(d),i=Math.max(t,e,s),n=Math.min(t,e,s),r=_(a=>(i+n-a).toString(16).padStart(2,"0"),"f");return`#${r(t)}${r(e)}${r(s)}`}_(Ni,"complementColor");function ki(d){const t=d==null?void 0:d.trim().toLowerCase();return t==="plot"||t==="absolute"?t:"model"}_(ki,"parseColorScale");function ns(d,t){switch(d==null?void 0:d.toLowerCase()){case"on":return 3;case"off":return 0;case"click":return 2;case"auto":return 1;default:return t}}_(ns,"parseLabelMode");const ft=class ft extends Ce{constructor(){super(),this.zoom_level=1,this.__children__=new $t,this._hasModel=!1,this._renderPending=!1,this._childObserver=null,this._ciRects=new Map,this._outlierRects=new Map,this._ciCross=new Map,this._labelsGroup=null,this._nodeLabels=new Map,this._meanLabels=new Map,this._pointLabels=new Map,this._showAxes=!1,this._axisXText=null,this._axisYText=null,this._axisLabelEls=new Map,this._magnifyText=null,this._magnifyEl=null,this._rangeExtent=null,this._rangeMode=null,this._centerContent=!1,this._plotTitle=null,this._titleEl=null,this._resizeObs=null,this._labelFont={size:null,family:null,color:null},this._animateMs=0,this._tweenRaf=null,this._highlight={edges:new Set,nodes:new Set},this._highlightGroup=null,this._tooltipEl=null,this.graph=this,this.parent=null,this.__data__=new ke(Is),this.__name__=this.__data__.name||"unnamed-graph",this.svg_element=this.create(),console.log("Created ena-graph svg element: ",this.svg_element),document.addEventListener("model-updated",t=>{var Gs,Us,Bs,Hs,Xs,Ws,Vs,Ks,Js,Zs,Qs,ti,ei,si,ii;const e=((Gs=t.composedPath)==null?void 0:Gs.call(t)[0])??t.target;if(this._vizena&&e!==this._vizena)return;const s=t.detail;if(!s)return;this._animateMs=this.hasAttribute("animate")?parseInt(this.getAttribute("animate")||"",10)||300:0;const i=this._animateMs>0&&this._hasModel?this._captureTween():null;this._hasModel=!0;const n=s.dimensions,r=s.unit_id_col,a=s.node_id_col,h=s.group_col,o=this._readLayerConfig();this._showAxes=o.showAxes,this._axisXText=o.axisXLabel===null?null:o.axisXLabel||String((n==null?void 0:n[0])??"x"),this._magnifyText=o.edgeMagnify==null?null:`(scaled ${o.edgeMagnify.toFixed(1)}x)`,this._axisYText=o.axisYLabel===null?null:o.axisYLabel||String((n==null?void 0:n[1])??"y");const l={},u=(Us=s.palette)!=null&&Us.length?s.palette:js;if(h&&((Bs=s.points)!=null&&Bs.names)){const O=s.points.col(h);O&&[...new Set([...O].map(String))].forEach((P,y)=>{l[P]=u[y%u.length]})}(Hs=s.groups)!=null&&Hs.rows&&s.groups.rows().length>0&&s.groups.rows().forEach(O=>{const N=O.rowName??String(O[0]),P=O.names.indexOf("color"),y=P>=0?O[P]:null;y&&String(y)!=="NA"?l[N]=String(y):l[N]||(l[N]=u[Object.keys(l).length%u.length])});const g=Object.keys(l),c=o.activeMeanGroups&&o.activeMeanGroups.trim()?new Set(o.activeMeanGroups.split(",").map(O=>O.trim()).filter(O=>l[O])):new Set(g),M=o.scalePoints,m=_(O=>{let N=0;return O.forEach(P=>{const y=P.names.indexOf(n[0]),b=n.length>1?P.names.indexOf(n[1]):-1;y>=0&&(N=Math.max(N,Math.abs(Number(P[y])))),b>=0&&(N=Math.max(N,Math.abs(Number(P[b]))))}),N},"getExtent"),E=(Xs=s.nodes)!=null&&Xs.rows?m(s.nodes.rows()):0,L=(Ws=s.points)!=null&&Ws.rows?m(s.points.rows()):0,Y=(Vs=s.trajectories)!=null&&Vs.rows?m(s.trajectories.rows()):0,q=L>0?L:Y,v=o.pointScale!==null?o.pointScale:M&&q>0&&E>0?E/q:1;this._rangeExtent=o.range==="network"?E*1.2:o.range==="points"?q*v*1.2:typeof o.range=="number"?o.range:null,this._rangeMode=o.range==="network"||o.range==="points"?o.range:typeof o.range=="number"?"number":null,this._centerContent=o.centerContent,this._plotTitle=o.plotTitle,this._labelFont=o.labelFont;const j=o.labelNodes,ot=o.labelMeans,lt=o.labelPoints,rt=this._labelsGroup,mt=_((O,N,P,y=1)=>{const b=O.names.indexOf(N),A=O.names.indexOf(n[0]),$=n.length>1?O.names.indexOf(n[1]):-1,p=new Z({ID:b>=0?String(O[b]):O.rowName||`pt-${Math.random().toString(36).slice(2)}`,dimensions:[A>=0?Number(O[A])*y:0,$>=0?-Number(O[$])*y:0],meta:{}});return P&&(p.color=new et(P)),p},"rowToPoint"),Q={},Rt=o.showPoints,jt=s.pointsets;if(o.pointSets.length&&(jt!=null&&jt.rows)){const O=this.__children__.search("__children__","points"),N=_((P,y)=>{const b=P.names.indexOf(y);return b>=0?P[b]:null},"col");o.pointSets.forEach((P,y)=>{jt.rows().forEach(b=>{if(String(N(b,"set"))!==P.set)return;const A=String(N(b,"id")),$=N(b,"group")!=null&&String(N(b,"group"))!=="NA"?String(N(b,"group")):null,p=N(b,"color")&&String(N(b,"color"))!=="NA"?String(N(b,"color")):$&&l[$]?l[$]:u[y%u.length],w=mt(b,"id",p,v);w.ID=`${P.set}::${A}`,w.size=P.size??o.pointSize??2.5;const R=N(b,"shape");R&&String(R)!=="NA"&&(w.shape=String(R));const G=N(b,"label");w.meta={stroke:"#ffffff",kind:"point",name:G!=null&&String(G)!=="NA"?String(G):A,group:$??void 0,unit:A,set:P.set,fixedSize:P.fixedSize},this.__data__.points.set(w.ID,w),O==null||O.__data__.objects.set(w.ID,w)})})}if((Ks=s.points)!=null&&Ks.rows){const O=this.__children__.search("__children__","points");if(O){s.points.rows().forEach(y=>{const b=h?y.names.indexOf(h):-1,A=b>=0?String(y[b]):null,$=A?l[A]??"#888888":"#888888";if(Rt){const p=mt(y,r,$,v);p.size=o.pointSize??2.5,p.meta={...p.meta??{},stroke:"#ffffff",kind:"point",name:p.ID,group:A??void 0,unit:p.ID,fixedSize:o.pointFixedSize},this.__data__.points.set(p.ID,p),O.__data__.objects.set(p.ID,p)}if(A){const p=y.names.indexOf(n[0]),w=n.length>1?y.names.indexOf(n[1]):-1;Q[A]||(Q[A]={x:0,y:0,x2:0,y2:0,xy:0,n:0,color:$});const R=p>=0?Number(y[p]):0,G=w>=0?Number(y[w]):0;Q[A].x+=R,Q[A].y+=G,Q[A].x2+=R*R,Q[A].y2+=G*G,Q[A].xy+=R*G,Q[A].n+=1}});const N=!!((Js=s.groups)!=null&&Js.rows&&s.groups.rows().length>0),P=o.showMeans&&N?s.groups.rows().filter(y=>{const b=y.rowName??String(y[0]);return c.size===0||c.has(b)}):[];if(o.showMeans){const y=O.svg_element,b=this._rangeExtent?this._rangeExtent/1.2:E,A=(b>0?b:1)*.008;if(N){const $=new Set(P.map(p=>p.rowName??String(p[0])));this._ciRects.forEach((p,w)=>{$.has(w)||(p.remove(),this._ciRects.delete(w))}),this._outlierRects.forEach((p,w)=>{$.has(w)||(p.remove(),this._outlierRects.delete(w))}),this._ciCross.forEach((p,w)=>{$.has(w.slice(2))||(p.remove(),this._ciCross.delete(w))}),P.forEach(p=>{var k,F,D;const w=p.rowName??String(p[0]),R=l[w]??"#888888",G=p.names.indexOf(n[0]),V=n.length>1?p.names.indexOf(n[1]):-1,K=G>=0?Number(p[G])*v:0,wt=V>=0?-Number(p[V])*v:0,tt=new Z({ID:`mean-${w}`,dimensions:[K,wt],meta:{kind:"mean",name:w,group:w,fixedSize:o.meanFixedSize}});tt.color=new et(R),tt.size=4;const ct=p.names.indexOf("shape"),T=ct>=0?p[ct]:null;tt.shape=T&&String(T)!=="NA"?String(T):"rect",this.__data__.points.set(tt.ID,tt),O.__data__.objects.set(tt.ID,tt);const Qt=_(I=>{const it=p.names.indexOf(I),X=it>=0?p[it]:null;return X==null||String(X)==="NA"||String(X)===""?null:X},"cell"),St=Qt("intervals"),Nt=St==="box"||St==="crosshairs"||St==="none"?St:o.intervals,kt=Qt("outlier"),U=(kt==null?o.showOutlier:kt===!0||String(kt)==="true")?Le(p,n[0],n[1],"o"):null;if(!U)(k=this._outlierRects.get(w))==null||k.remove(),this._outlierRects.delete(w);else{let I=this._outlierRects.get(w);I||(I=document.createElementNS("http://www.w3.org/2000/svg","rect"),I.setAttribute("data-outlier-group",w),this._outlierRects.set(w,I)),I.setAttribute("x",(U.x_low*v).toString()),I.setAttribute("y",(-U.y_high*v).toString()),I.setAttribute("width",((U.x_high-U.x_low)*v).toString()),I.setAttribute("height",((U.y_high-U.y_low)*v).toString()),I.setAttribute("fill","none"),I.setAttribute("stroke",R),I.setAttribute("stroke-width",A.toString()),I.setAttribute("stroke-opacity","0.5"),I.setAttribute("stroke-dasharray",`${A*2} ${A*2}`),y&&!I.parentElement&&y.insertBefore(I,y.firstChild)}const f=Nt!=="none"?Le(p,n[0],n[1]):null,x=`x:${w}`;if((!f||Nt!=="crosshairs")&&((F=this._ciCross.get(x))==null||F.remove(),this._ciCross.delete(x)),f&&Nt==="crosshairs"){(D=this._ciRects.get(w))==null||D.remove(),this._ciRects.delete(w);const I=f.x_low*v,it=f.x_high*v,X=-f.y_high*v,at=-f.y_low*v;Re(tt,(it-I)/2,(at-X)/2);let z=this._ciCross.get(x);z||(z=document.createElementNS("http://www.w3.org/2000/svg","path"),z.setAttribute("data-ci-group",w),z.setAttribute("data-ci-kind","crosshairs"),this._ciCross.set(x,z)),z.setAttribute("d",`M${I} ${wt} L${it} ${wt} M${K} ${X} L${K} ${at}`),z.setAttribute("fill","none"),z.setAttribute("stroke",R),z.setAttribute("stroke-width",(A*1.25).toString()),z.setAttribute("stroke-opacity","0.8"),y&&!z.parentElement&&y.insertBefore(z,y.firstChild)}else if(f){const I=f.x_low*v,it=-f.y_high*v,X=(f.x_high-f.x_low)*v,at=(f.y_high-f.y_low)*v;Re(tt,X/2,at/2);let z=this._ciRects.get(w);z||(z=document.createElementNS("http://www.w3.org/2000/svg","rect"),z.setAttribute("data-ci-group",w),this._ciRects.set(w,z)),z.setAttribute("x",I.toString()),z.setAttribute("y",it.toString()),z.setAttribute("width",X.toString()),z.setAttribute("height",at.toString()),z.setAttribute("fill","none"),z.setAttribute("stroke",R),z.setAttribute("stroke-width",A.toString()),z.setAttribute("stroke-opacity","0.8"),z.setAttribute("stroke-dasharray",`${A*4} ${A*3}`),y&&!z.parentElement&&y.insertBefore(z,y.firstChild)}else{const I=this._ciRects.get(w);I&&(I.remove(),this._ciRects.delete(w))}})}else Object.entries(Q).forEach(([p,{x:w,y:R,n:G,color:V}])=>{const K=new Z({ID:`mean-${p}`,dimensions:[w/G*v,-(R/G)*v],meta:{kind:"mean",name:p,group:p,fixedSize:o.meanFixedSize}});K.color=new et(V),K.size=4,K.shape="rect",this.__data__.points.set(K.ID,K),O.__data__.objects.set(K.ID,K)}),o.showCI&&(this._ciRects.forEach((p,w)=>{Q[w]||(p.remove(),this._ciRects.delete(w))}),(Zs=s.confidence)!=null&&Zs.rows?s.confidence.rows().forEach(p=>{const w=p.names.indexOf(h??"group"),R=w>=0?String(p[w]):p.rowName??null;if(!R)return;const G=l[R]??"#888888",V=Le(p,n[0],n[1]);if(!V)return;const K=V.x_low*v,wt=-V.y_high*v,tt=(V.x_high-V.x_low)*v,ct=(V.y_high-V.y_low)*v;Re(this.__data__.points.get(`mean-${R}`),tt/2,ct/2);let T=this._ciRects.get(R);T||(T=document.createElementNS("http://www.w3.org/2000/svg","rect"),T.setAttribute("data-ci-group",R),this._ciRects.set(R,T)),T.setAttribute("x",K.toString()),T.setAttribute("y",wt.toString()),T.setAttribute("width",tt.toString()),T.setAttribute("height",ct.toString()),T.setAttribute("fill","none"),T.setAttribute("stroke",G),T.setAttribute("stroke-width",A.toString()),T.setAttribute("stroke-opacity","0.8"),T.setAttribute("stroke-dasharray",`${A*4} ${A*3}`),y&&!T.parentElement&&y.insertBefore(T,y.firstChild)}):Object.entries(Q).forEach(([p,{x:w,y:R,x2:G,y2:V,n:K,color:wt}])=>{if(K<2)return;const tt=w/K,ct=R/K,T=G/K-tt*tt,Qt=V/K-ct*ct,{halfW:St,halfH:Nt}=Ei(T,Qt,K,v),kt=tt*v,Yt=-ct*v;Re(this.__data__.points.get(`mean-${p}`),St,Nt);let U=this._ciRects.get(p);U||(U=document.createElementNS("http://www.w3.org/2000/svg","rect"),U.setAttribute("data-ci-group",p),this._ciRects.set(p,U)),U.setAttribute("x",(kt-St).toString()),U.setAttribute("y",(Yt-Nt).toString()),U.setAttribute("width",(St*2).toString()),U.setAttribute("height",(Nt*2).toString()),U.setAttribute("fill","none"),U.setAttribute("stroke",wt),U.setAttribute("stroke-width",A.toString()),U.setAttribute("stroke-opacity","0.8"),U.setAttribute("stroke-dasharray",`${A*4} ${A*3}`),y&&!U.parentElement&&y.insertBefore(U,y.firstChild)})),(Qs=s.outlier)!=null&&Qs.rows&&(this._outlierRects.forEach((p,w)=>{l[w]||(p.remove(),this._outlierRects.delete(w))}),s.outlier.rows().forEach(p=>{const w=p.names.indexOf(h??"group"),R=w>=0?String(p[w]):p.rowName??null;if(!R)return;const G=l[R]??"#888888",V=Le(p,n[0],n[1]);if(!V)return;const K=V.x_low*v,wt=-V.y_high*v,tt=(V.x_high-V.x_low)*v,ct=(V.y_high-V.y_low)*v;let T=this._outlierRects.get(R);T||(T=document.createElementNS("http://www.w3.org/2000/svg","rect"),T.setAttribute("data-outlier-group",R),this._outlierRects.set(R,T)),T.setAttribute("x",K.toString()),T.setAttribute("y",wt.toString()),T.setAttribute("width",tt.toString()),T.setAttribute("height",ct.toString()),T.setAttribute("fill","none"),T.setAttribute("stroke",G),T.setAttribute("stroke-width",A.toString()),T.setAttribute("stroke-opacity","0.5"),T.setAttribute("stroke-dasharray",`${A*2} ${A*2}`),y&&!T.parentElement&&y.insertBefore(T,y.firstChild)}))}rt&&(this._pointLabels.forEach((y,b)=>{O.__data__.objects.get(b)||(y.remove(),this._pointLabels.delete(b))}),this._meanLabels.forEach((y,b)=>{O.__data__.objects.get(`mean-${b}`)||(y.remove(),this._meanLabels.delete(b))}),lt!==0&&s.points.rows().forEach(y=>{const b=y.names.indexOf(r),A=b>=0?String(y[b]):null;if(!A)return;const $=O.__data__.objects.get(A);if(!$)return;const p=A;let w=this._pointLabels.get(A);w?lt===H.DISPLAY_TYPES.ON?w.show():w.hide():(w=new le(p,$,rt,this,lt),this._pointLabels.set(A,w))}),ot!==0&&(N?P.map(b=>b.rowName??String(b[0])):Object.keys(Q)).forEach(b=>{const A=`mean-${b}`,$=O.__data__.objects.get(A);if(!$)return;let p=this._meanLabels.get(b);p?ot===H.DISPLAY_TYPES.ON?p.show():p.hide():(p=new le(b,$,rt,this,ot),this._meanLabels.set(b,p))})),O.__data__.__state__.setVariable("layer_updated",O.__data__)}}const Zt=this.__children__.search("__children__","trajectories");if(o.showTrajectories&&Zt){Zt.__data__.objects.clear(),this.__data__.trajectories.clear();const O=(ti=s.trajectories)!=null&&ti.rows?s.trajectories:s.points;if(O!=null&&O.rows){const N={},P=o.trajectoryUnits?o.trajectoryUnits.split(",").map(b=>b.trim()):null;O.rows().forEach(b=>{const A=b.names.indexOf(r)>=0?b.names.indexOf(r):b.names.indexOf("unit")>=0?b.names.indexOf("unit"):b.names.indexOf("ENA_UNIT")>=0?b.names.indexOf("ENA_UNIT"):-1,$=A>=0?String(b[A]):b.rowName||"unit-1";if(P&&!P.includes($))return;const p=b.names.indexOf(n[0]),w=n.length>1?b.names.indexOf(n[1]):-1,R=b.names.indexOf("time")>=0?b.names.indexOf("time"):b.names.indexOf("ActivityNumber")>=0?b.names.indexOf("ActivityNumber"):b.names.indexOf("RowID")>=0?b.names.indexOf("RowID"):-1,G=R>=0?Number(b[R]):N[$]?N[$].length+1:1;p>=0&&w>=0&&(N[$]||(N[$]=[]),N[$].push({x:Number(b[p])*v,y:-Number(b[w])*v,time:G}))}),Object.keys(N).forEach((b,A)=>{const $=N[b];if($.length===0)return;const p=u[A%u.length],w=new ne({ID:`traj-${b}`,unitId:b,color:new et(p),lineStyle:o.trajectoryLineStyle,strokeWidth:o.trajectoryStrokeWidth,strokeWidthRange:o.trajectoryStrokeWidthRange,opacityRange:o.trajectoryOpacityRange,smooth:o.trajectorySmooth,maxDegree:o.trajectoryMaxDegree,degreeSelection:o.trajectoryDegreeSelection,currentTime:o.trajectoryPlayhead??1/0,showPoints:o.trajectoryShowPoints,showTips:o.trajectoryShowTips,points:$.map(R=>({x:R.x,y:R.y,time:R.time}))});this.__data__.trajectories.set(b,w),Zt.__data__.objects.set(w.ID,w)})}Zt.__data__.__state__.setVariable("layer_updated",Zt.__data__)}const pt=this.__children__.search("__children__","network"),Ie=pt==null?void 0:pt.__children__.search("__children__","edges"),xt=pt==null?void 0:pt.__children__.search("__children__","nodes"),We=pt==null?void 0:pt.__children__.search("__children__","edgenodes"),$i=o.showEdges;if((ei=s.nodes)!=null&&ei.rows&&xt){if(s.nodes.rows().forEach(N=>{const P=mt(N,a,"#444444");P.size=2;const y=N.names.indexOf("label"),b=y>=0?N[y]:null;P.meta={...P.meta??{},kind:"node",name:b!=null&&String(b)!=="NA"&&String(b)!==""?String(b):P.ID},xt.__data__.objects.set(P.ID,P)}),$i&&Ie&&((si=s.edges)!=null&&si.rows)){const N={};h&&((ii=s.points)!=null&&ii.rows)&&s.points.rows().forEach(f=>{const x=f.names.indexOf(r),k=f.names.indexOf(h);x>=0&&k>=0&&(N[String(f[x])]=String(f[k]))});const P=s.nodes.rows().map(f=>{const x=f.names.indexOf(a);return x>=0?String(f[x]):""}).filter(Boolean),y=[];(s.edges.names??[]).forEach(f=>{const x=Si(f,P);x&&y.push({col:f,pair:x})});const b=_(f=>{const x={};return s.edges.rows().forEach(k=>{const F=k.names.indexOf(r);F<0||String(k[F])!==f||y.forEach(({col:D})=>{const I=k.names.indexOf(D);I>=0&&(x[D]=Number(k[I])||0)})}),x},"getUnitEdges"),A=_(f=>{const x={};let k=0;if(s.edges.rows().forEach(D=>{const I=D.names.indexOf(r),it=I>=0?String(D[I]):null,X=h?D.names.indexOf(h):-1;(X>=0?String(D[X]):it?N[it]:null)===f&&(k++,y.forEach(({col:z})=>{const At=D.names.indexOf(z);if(At>=0){const J=Number(D[At]);isNaN(J)||(x[z]=(x[z]??0)+J)}}))}),k===0)return{};const F={};return y.forEach(({col:D})=>{F[D]=(x[D]??0)/k}),F},"getGroupEdges"),$=_(f=>{if(l[f])return{weights:A(f),color:l[f],label:f};const x=N[f]??null,k=x?l[x]??"#888888":"#888888";return{weights:b(f),color:k,label:f}},"resolve"),p=[],w=_(f=>{var D;const x=s.networks,k=(D=x==null?void 0:x.rows)==null?void 0:D.call(x).find(I=>I.rowName===f);if(!k)return null;const F={};return y.forEach(({col:I})=>{const it=k.names.indexOf(I);if(it>=0){const X=Number(k[it]);Number.isFinite(X)&&(F[I]=X)}}),F},"networkRow"),R=_((f,x)=>{if(!x)return f;const k=Math.abs(f);return k<x[0]?0:k>x[1]?Math.sign(f)*x[1]:f},"thresholded");o.edgeLayers.forEach((f,x)=>{const k=_((J,ut,st,Et,_t)=>{st=R(st,f.threshold),!(Math.abs(st)<1e-6)&&p.push({col:`${x}:${J}`,pair:ut,weight:Math.abs(st),color:Et,layer:x,..._t})},"push"),F=_((J,ut)=>f.colors?[f.colors[0],f.colors[1]??Ni(f.colors[0])]:[J,ut],"signColors");if(f.network){const J=w(f.network);if(!J)return;const[ut,st]=F(u[0],u[1]),Et={name:f.name??f.network};y.forEach(({col:_t,pair:ni})=>{const Ve=J[_t]??0;k(_t,ni,Ve,Ve>=0?ut:st,Et)});return}const D=f.unit??f.group??null;if(!D)return;const I=$(D),it=f.compare??f.also??null,X=it?$(it):null,at={name:f.name??D,group:f.group??void 0,unit:f.unit??void 0},[z,At]=F(I.color,(X==null?void 0:X.color)??I.color);X&&f.compare?y.forEach(({col:J,pair:ut})=>{const st=(I.weights[J]??0)-(X.weights[J]??0);k(J,ut,st,st>0?z:At,at)}):X&&f.also?y.forEach(({col:J,pair:ut})=>{const st=I.weights[J]??0,Et=X.weights[J]??0;st>0&&k(J+"-a",ut,st,z,at),Et>0&&k(J+"-b",ut,Et,At,{...at,name:f.also??void 0,group:f.also??void 0})}):y.forEach(({col:J,pair:ut})=>{const st=I.weights[J]??0;st>0&&k(J,ut,st,z,at)})}),p.sort((f,x)=>x.weight-f.weight);const G=!!s.directed,V=yi(o.edgeWidth)*(o.edgeMagnify??1),K=_(f=>{const x=f.map(Math.abs).filter(k=>k>0);return x.length?[Math.min(...x),Math.max(...x)]:[0,0]},"rangeOf"),wt=_(f=>{const x=[];return y.forEach(({col:k,pair:F})=>{if(F[0]===F[1]!==f)return;const D=s.edges.col(k);if(D)for(const I of D)x.push(Number(I))}),K(x)},"modelRange"),tt=_(f=>K(p.filter(x=>x.pair[0]===x.pair[1]===f).map(x=>x.weight)),"plotRange"),ct=o.edgeColorScale,T=_(f=>ct==="plot"?tt(f):wt(f),"colourRange"),Qt=T(!1),St=T(!0),Nt=_((f,x)=>{if(ct==="absolute"){const D=Math.min(1,Math.abs(f));return{saturation:D,opacity:D}}const[k,F]=x?St:Qt;return{saturation:Ds(f,k,F,_i),opacity:Ds(f,k,F,di)}},"colourOf"),kt={};p.forEach(({pair:f,weight:x})=>{if(f[0]===f[1]&&!G)return;const F=_(D=>{kt[D]=(kt[D]??0)+Math.abs(x)},"add");if(G){F(f[1]);return}F(f[0]),F(f[1])}),s.nodes.rows().forEach(f=>{const x=f.names.indexOf(a),k=x>=0?String(f[x]):"";if(!k)return;const F=xt.__data__.objects.get(k);if(!F)return;const D=kt[k]??0,I=!(D>0);F.size=I?o.hideUnconnectedNodes?0:bi:xi(D,V),F.meta={...F.meta??{},hidden:I&&o.hideUnconnectedNodes}});const Yt={},U=_((f,x,k,F)=>`${f}:${x??""}:${k}.${F}`,"pairKey");G&&p.forEach(({pair:f,weight:x,layer:k,name:F})=>{const D=U(k,F,f[0],f[1]);Yt[D]=(Yt[D]??0)+x}),p.forEach(({col:f,pair:x,weight:k,color:F,layer:D,name:I,group:it,unit:X})=>{const at=xt.__data__.objects.get(x[0]),z=xt.__data__.objects.get(x[1]);if(!at||!z)return;const At=x[0]===x[1];if(At&&!G)return;const{saturation:J,opacity:ut}=Nt(k,At),st=new Z({ID:`${x[0]}-src`,dimensions:[at.x,at.y],meta:{}}),Et=new Z({ID:`${x[1]}-dst`,dimensions:[z.x,z.y],meta:{}});let _t;if(At)_t=new oe({},st,Et),_t.weight=0;else if(G){const Ve=Yt[U(D,I,x[0],x[1])]??k,Pi=Yt[U(D,I,x[1],x[0])]??0,Ri=Ve+Pi;_t=new is({weight:k,totalweight:Ri},st,Et)}else _t=new Gt({},st,Et);_t.ID=`edge-${f}`,_t.color=new et(F),_t.meta={isMeanEdge:!0,weight:k,widthFrac:V,saturation:J,opacity:ut,isDirected:G,isSelf:At,source:x[0],target:x[1],group:it,unit:X,layer:I},(At?We??Ie:Ie).__data__.objects.set(_t.ID,_t)}),Ie.__data__.__state__.setVariable("layer_updated",Ie.__data__),We&&We.__data__.__state__.setVariable("layer_updated",We.__data__)}const O=o.showNodes;xt.svg_element&&(xt.svg_element.style.display=O?"":"none"),O||(this._nodeLabels.forEach(N=>N.remove()),this._nodeLabels.clear()),rt&&j!==0&&O&&(this._nodeLabels.forEach((N,P)=>{xt.__data__.objects.get(P)||(N.remove(),this._nodeLabels.delete(P))}),s.nodes.rows().forEach(N=>{var p,w,R;const P=N.names.indexOf(a),y=P>=0?String(N[P]):"";if(!y)return;const b=xt.__data__.objects.get(y);if(!b)return;if((p=b.meta)!=null&&p.hidden){(w=this._nodeLabels.get(y))==null||w.remove(),this._nodeLabels.delete(y);return}const A=String(((R=b.meta)==null?void 0:R.name)??y);let $=this._nodeLabels.get(y);$&&$.text!==A&&($.remove(),this._nodeLabels.delete(y),$=void 0),$?j===H.DISPLAY_TYPES.ON?$.show():$.hide():($=new le(A,b,rt,this,j),this._nodeLabels.set(y,$))})),xt.__data__.__state__.setVariable("layer_updated",xt.__data__)}const Ys=this.__children__.search("__children__","axis_points"),qs=this.__children__.search("__children__","axis_lines");Ys&&this.__data__.__state__.setVariable("graph_updated_axis_points",Ys.__data__.objects),qs&&this.__data__.__state__.setVariable("graph_updated_axis_lines",qs.__data__.objects),this.update(),i&&this._runTween(i)})}static get observedAttributes(){return["width","height","for","scale-points","point-scale","center","labels","label-nodes","label-means","label-points"]}get vizena(){return this._vizena}unitsPerPixel(){var i,n;const t=this.__data__.extremes.x_max||1,e=(n=(i=this.svg_element)==null?void 0:i.getBoundingClientRect)==null?void 0:n.call(i),s=this.zoom_level||1;return e&&e.width>0?2*t/e.width/s:t*.004}_scheduleRerender(){!this._vizena||!this._hasModel||this._renderPending||(this._renderPending=!0,queueMicrotask(()=>{var t;this._renderPending=!1,(t=this._vizena)==null||t.dispatchEvent(new CustomEvent("model-updated",{detail:this._vizena.model,bubbles:!0,composed:!0}))}))}_readLayerConfig(){var g;const t=this.querySelector("qe-nodes"),e=this.querySelector("qe-means"),s=[...this.querySelectorAll("qe-points")],i=s.find(c=>!c.hasAttribute("set"))??null,n=s.filter(c=>c.hasAttribute("set")),r=[...this.querySelectorAll("qe-edges")],a=_(c=>{var M;return((M=r.find(m=>m.hasAttribute(c)))==null?void 0:M.getAttribute(c))??null},"firstAttr"),h=r.find(c=>c.hasAttribute("magnify")),o=this.querySelector("qe-trajectories"),l=this.querySelector("qe-axes"),u=this.getAttribute("labels");return{labelNodes:ns((t==null?void 0:t.getAttribute("label"))??this.getAttribute("label-nodes")??u,H.DISPLAY_TYPES.ON),showNodes:!!t,range:(()=>{const c=this.getAttribute("range");if(c==="network"||c==="points")return c;const M=Number(c);return c!=null&&Number.isFinite(M)&&M>0?M:null})(),plotTitle:this.getAttribute("plot-title")||null,labelFont:{size:(()=>{const c=Number(this.getAttribute("label-font-size"));return Number.isFinite(c)&&c>0?c:null})(),family:this.getAttribute("label-font-family")||null,color:this.getAttribute("label-font-color")||null},edgeWidth:(()=>{const c=Number(this.getAttribute("edge-width"));return Number.isFinite(c)&&c>0&&c<=1?c:ui})(),hideUnconnectedNodes:((g=t==null?void 0:t.getAttribute("unconnected"))==null?void 0:g.toLowerCase())==="hide",scalePoints:this.getAttribute("scale-points")!=="false",pointScale:(()=>{const c=Number(this.getAttribute("point-scale"));return this.hasAttribute("point-scale")&&Number.isFinite(c)&&c>0?c:null})(),centerContent:this.getAttribute("center")==="content",showMeans:!!e,activeMeanGroups:(e==null?void 0:e.getAttribute("groups"))??null,showCI:!!e&&e.hasAttribute("confidence"),intervals:(()=>{const c=e==null?void 0:e.getAttribute("intervals");return c==="box"||c==="crosshairs"||c==="none"?c:e!=null&&e.hasAttribute("confidence")?"box":"none"})(),showOutlier:!!e&&e.hasAttribute("outlier"),labelMeans:ns((e==null?void 0:e.getAttribute("label"))??this.getAttribute("label-means")??u,H.DISPLAY_TYPES.ON),meanFixedSize:!!e&&e.hasAttribute("fixed-size"),showPoints:!!i,pointSets:n.map(c=>({set:c.getAttribute("set"),size:c.getAttribute("size")?parseFloat(c.getAttribute("size")):null,fixedSize:c.hasAttribute("fixed-size")})),labelPoints:ns((i==null?void 0:i.getAttribute("label"))??this.getAttribute("label-points")??u,H.DISPLAY_TYPES.OFF),pointSize:i!=null&&i.getAttribute("size")?parseFloat(i.getAttribute("size")):null,pointFixedSize:!!i&&i.hasAttribute("fixed-size"),showEdges:r.length>0,edgeLayers:r.map(Ii),edgeColorScale:ki(a("color-scale")),edgeMagnify:h?(()=>{const c=Number(h.getAttribute("magnify"));return Number.isFinite(c)&&c>0?c:1})():null,showTrajectories:!!o,trajectoryUnits:(o==null?void 0:o.getAttribute("units"))??null,trajectorySmooth:(o==null?void 0:o.getAttribute("smooth"))??"none",trajectoryMaxDegree:o!=null&&o.getAttribute("max-degree")?parseInt(o.getAttribute("max-degree"),10):3,trajectoryDegreeSelection:(o==null?void 0:o.getAttribute("degree-selection"))??"loocv_2d",trajectoryShowPoints:(o==null?void 0:o.getAttribute("points"))!=="false",trajectoryShowTips:(o==null?void 0:o.getAttribute("tips"))!=="false",trajectoryPlayhead:o!=null&&o.getAttribute("playhead")?parseFloat(o.getAttribute("playhead")):null,trajectoryLineStyle:(o==null?void 0:o.getAttribute("line-style"))??"uniform",trajectoryStrokeWidth:o!=null&&o.getAttribute("stroke-width")?parseFloat(o.getAttribute("stroke-width")):2,trajectoryStrokeWidthRange:this._parseNumberPair(o==null?void 0:o.getAttribute("stroke-width-range"),[1,6]),trajectoryOpacityRange:this._parseNumberPair(o==null?void 0:o.getAttribute("opacity-range"),[.3,1]),showAxes:!!l,axisXLabel:l!=null&&l.hasAttribute("x")?l.getAttribute("x")??"":null,axisYLabel:l!=null&&l.hasAttribute("y")?l.getAttribute("y")??"":null}}_parseNumberPair(t,e){if(!t)return e;const s=t.split(",").map(i=>Number(i.trim()));return s.length<2||!s.every(Number.isFinite)?e:[s[0],s[1]]}attributeChangedCallback(t,e,s){e!==s&&this._scheduleRerender()}connectedCallback(){var n;const t=this.getAttribute("width"),e=this.getAttribute("height");this.style.display="block",t&&(this.style.width=isNaN(Number(t))?t:`${t}px`),e&&(this.style.height=isNaN(Number(e))?e:`${e}px`),this.appendChild(this.svg_element),ft._instances.add(this),this._childObserver=new MutationObserver(()=>this._scheduleRerender()),this._childObserver.observe(this,{childList:!0,attributes:!0,subtree:!0,attributeFilter:["group","unit","compare","also","color-scale","magnify","network","colors","threshold","name","groups","confidence","label","intervals","outlier","set","unconnected","scale-points","point-scale","edge-width","labels","range","center","plot-title","label-font-size","label-font-family","label-font-color","label-nodes","label-means","label-points","units","smooth","degree","points","tips","playhead","line-style","stroke-width","stroke-width-range","opacity-range","x","y","size","fixed-size"]});const s=this.getAttribute("for");this._vizena=(s?document.getElementById(s):null)??this.closest("qe-visual")??((n=this.parentElement)==null?void 0:n.closest("qe-visual"))??document.querySelector("qe-visual"),this.draw();const i=this.__children__.search("__children__","labels");if(i!=null&&i.svg_element)this._labelsGroup=i.svg_element;else{console.warn("[ena-graph] labels layer not found in layer tree; creating fallback <g>");const r=this.__children__[0];r!=null&&r.svg_element&&(this._labelsGroup=document.createElementNS("http://www.w3.org/2000/svg","g"),this._labelsGroup.setAttribute("data-layer-name","labels-fallback"),r.svg_element.appendChild(this._labelsGroup))}}disconnectedCallback(){var t,e,s;(t=this._childObserver)==null||t.disconnect(),this._childObserver=null,(e=this._resizeObs)==null||e.disconnect(),this._resizeObs=null,ft._instances.delete(this),(s=this._tooltipEl)==null||s.remove(),this._tooltipEl=null}static instances(){return[...ft._instances]}static getGraph(t){for(const e of ft._instances)if(e.id===t||e.getAttribute("plot-group")===t)return e;return null}getNodes(){const t=this.__children__.search("__children__","nodes");return t?[...t.__data__.objects.values()].map(e=>{var s;return{id:e.ID,name:((s=e.meta)==null?void 0:s.name)??e.ID,x:e.x,y:e.y}}):[]}getEdges(){const t=_(e=>{const s=this.__children__.search("__children__",e);return s?[...s.__data__.objects.values()]:[]},"collect");return[...t("edges"),...t("edgenodes")].map(e=>{const s=e.meta??{};return{source:s.source,target:s.target,weight:s.weight??0,directed:!!s.isDirected,self:!!s.isSelf}}).filter(e=>e.source!=null&&e.target!=null)}_tweenTargets(){return[...this.svg_element.querySelectorAll("circle[data-point-id], rect[data-point-id], line[data-edge-source], path[data-edge-source]")]}_readCoords(t){const e=t.tagName.toLowerCase(),s=_(i=>parseFloat(t.getAttribute(i)||"0"),"n");if(e==="circle")return{t:"c",cx:s("cx"),cy:s("cy")};if(e==="rect")return{t:"r",x:s("x"),y:s("y")};if(e==="line")return{t:"l",x1:s("x1"),y1:s("y1"),x2:s("x2"),y2:s("y2")};if(e==="path"){const i=t.getAttribute("d")||"";return{t:"p",d:i,nums:(i.match(ft._PATH_NUM_RE)||[]).map(Number)}}return null}_captureTween(){const t=new Map;return this._tweenTargets().forEach(e=>{const s=this._readCoords(e);s&&t.set(e,s)}),t}_runTween(t){this._tweenRaf!==null&&(cancelAnimationFrame(this._tweenRaf),this._tweenRaf=null);const e=new Map;if(this._tweenTargets().forEach(h=>{if(t.has(h)){const o=this._readCoords(h);o&&e.set(h,o)}}),!e.size)return;const s=this._animateMs,i=performance.now(),n=_(h=>h<.5?2*h*h:1-Math.pow(-2*h+2,2)/2,"ease"),r=_((h,o,l)=>h+(o-h)*l,"lerp"),a=_(h=>{const o=Math.min(1,(h-i)/s),l=n(o);e.forEach((u,g)=>{const c=t.get(g);if(!(!c||c.t!==u.t))if(u.t==="c")g.setAttribute("cx",String(r(c.cx,u.cx,l))),g.setAttribute("cy",String(r(c.cy,u.cy,l)));else if(u.t==="r")g.setAttribute("x",String(r(c.x,u.x,l))),g.setAttribute("y",String(r(c.y,u.y,l)));else if(u.t==="l")g.setAttribute("x1",String(r(c.x1,u.x1,l))),g.setAttribute("y1",String(r(c.y1,u.y1,l))),g.setAttribute("x2",String(r(c.x2,u.x2,l))),g.setAttribute("y2",String(r(c.y2,u.y2,l)));else{if(!c.nums||c.nums.length!==u.nums.length)return;let M=0;const m=u.d.replace(ft._PATH_NUM_RE,()=>String(r(c.nums[M],u.nums[M++],l)));g.setAttribute("d",m)}}),this._tweenRaf=o<1?requestAnimationFrame(a):null},"step");this._tweenRaf=requestAnimationFrame(a)}toSVG(){const t=this.svg_element.cloneNode(!0);t.setAttribute("xmlns","http://www.w3.org/2000/svg"),t.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink");const e=this.svg_element.getBoundingClientRect();return e.width&&t.setAttribute("width",String(Math.round(e.width))),e.height&&t.setAttribute("height",String(Math.round(e.height))),new XMLSerializer().serializeToString(t)}toPNG(t=2){const e=this.toSVG(),s=this.svg_element.getBoundingClientRect(),i=Math.max(1,Math.round(s.width)),n=Math.max(1,Math.round(s.height));return new Promise((r,a)=>{const h=new Blob([e],{type:"image/svg+xml;charset=utf-8"}),o=URL.createObjectURL(h),l=new Image;l.onload=()=>{try{const u=document.createElement("canvas");u.width=i*t,u.height=n*t;const g=u.getContext("2d");if(!g){URL.revokeObjectURL(o),a(new Error("no 2d context"));return}g.scale(t,t),g.drawImage(l,0,0,i,n),URL.revokeObjectURL(o),r(u.toDataURL("image/png"))}catch(u){URL.revokeObjectURL(o),a(u)}},l.onerror=u=>{URL.revokeObjectURL(o),a(u)},l.src=o})}getPoints(){const t=this.__children__.search("__children__","points");return t?[...t.__data__.objects.values()].filter(e=>{var s;return((s=e.meta)==null?void 0:s.kind)==="point"}).map(e=>{var s,i,n;return{id:((s=e.meta)==null?void 0:s.unit)??e.ID,group:(i=e.meta)==null?void 0:i.group,set:(n=e.meta)==null?void 0:n.set,x:e.x,y:e.y}}):[]}pointsInRect(t){return this.getPoints().filter(e=>e.x>=t.x&&e.x<=t.x+t.w&&e.y>=t.y&&e.y<=t.y+t.h).map(e=>e.id)}_edgeKey(t,e){return t<=e?`${t}\0${e}`:`${e}\0${t}`}setHighlight(t){this._highlight.edges=new Set((t.edges??[]).map(e=>this._edgeKey(e.source,e.target))),this._highlight.nodes=new Set((t.nodes??[]).map(String)),this._applyHighlights()}clearHighlight(){this._highlight.edges.clear(),this._highlight.nodes.clear(),this._applyHighlights()}_applyHighlights(){if(!this.svg_element)return;this._highlightGroup||(this._highlightGroup=document.createElementNS("http://www.w3.org/2000/svg","g"),this._highlightGroup.setAttribute("data-layer-name","highlight"),this._highlightGroup.setAttribute("pointer-events","none")),this.svg_element.appendChild(this._highlightGroup);const t=this._highlightGroup;t.textContent="";const e=this.__data__.extremes.x_max||1,s="#f5a623",i=_((n,r)=>{const a=document.createElementNS("http://www.w3.org/2000/svg",n);for(const h in r)a.setAttribute(h,String(r[h]));return a},"mk");if(this._highlight.edges.size){const n={};this.getNodes().forEach(r=>{n[r.id]={x:r.x,y:r.y}}),this._highlight.edges.forEach(r=>{const[a,h]=r.split("\0"),o=n[a],l=n[h];!o||!l||t.appendChild(i("line",{x1:o.x,y1:o.y,x2:l.x,y2:l.y,stroke:s,"stroke-width":e*.02,"stroke-opacity":.6,"stroke-linecap":"round"}))})}this._highlight.nodes.forEach(n=>{var u;const r=this.svg_element.querySelector(`[data-point-id="${(u=window.CSS)!=null&&u.escape?CSS.escape(n):n}"]`);if(!r)return;const a=r.tagName.toLowerCase();let h,o,l;if(a==="rect"){const g=parseFloat(r.getAttribute("width")||"0");h=parseFloat(r.getAttribute("x")||"0")+g/2,o=parseFloat(r.getAttribute("y")||"0")+parseFloat(r.getAttribute("height")||"0")/2,l=g/2}else h=parseFloat(r.getAttribute("cx")||"0"),o=parseFloat(r.getAttribute("cy")||"0"),l=parseFloat(r.getAttribute("r")||"0");t.appendChild(i("circle",{cx:h,cy:o,r:l*1.7+e*.004,fill:"none",stroke:s,"stroke-width":e*.006}))})}create(){const t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.classList.add("graph"),t.style.display="block",t.style.width="100%",t.style.height="100%",t.setAttribute("preserveAspectRatio","xMidYMid meet"),t.setAttribute("viewBox",this.__data__.extremes.as_viewBox()),t.setAttribute("transform",this.__data__.transform.toString()),t.setAttribute("role","figure"),t.setAttribute("data-graph-size",`${Math.min(this.__data__.extremes.width,this.__data__.extremes.height)}`),this.svg_element=t;const e=document.createElementNS("http://www.w3.org/2000/svg","defs"),s=.22,i=.15,n=_((r,a)=>{const h=document.createElementNS("http://www.w3.org/2000/svg","marker");h.setAttribute("id",r),h.setAttribute("markerWidth",String(s)),h.setAttribute("markerHeight",String(i)),h.setAttribute("refX",String(s)),h.setAttribute("refY",String(i/2)),h.setAttribute("orient","auto"),h.setAttribute("markerUnits","userSpaceOnUse");const o=document.createElementNS("http://www.w3.org/2000/svg","path");o.setAttribute("d",`M0,0 L0,${i} L${s},${i/2} z`),o.setAttribute("fill",a),h.appendChild(o),e.appendChild(h)},"makeArrow");return js.forEach(r=>n(`qe-arrow-${r.slice(1)}`,r)),t.appendChild(e),this.__data__.layers.forEach(r=>{const a=new Pe(r,this.svg_element,this);this.__children__.push(a)}),this.__data__.__state__.setVariable("graph_updated",this.__data__),this.attach_events(),t}attach_events(){this.svg_element.addEventListener("wheel",o=>{console.log("Wheel event: ",o),o.preventDefault(),Math.sign(o.deltaY)<0?this.zoom_level*=1.1:this.zoom_level/=1.1,this.__data__.transform.zoom(this.zoom_level),this.update()});let t=!1,e,s;this.svg_element.addEventListener("mousedown",o=>{t=!0,e=o.clientX,s=o.clientY});let i=null,n=null;const r=_(()=>{n&&(this.__data__.transform.pan(n.dx,n.dy),this.__children__[0].svg_element.setAttribute("transform",this.__data__.transform.toString()),n=null),i=null},"panUpdate");this.svg_element.addEventListener("mousemove",o=>{if(!t)return;const l=o.clientX-e,u=o.clientY-s;n={dx:l/100,dy:u/100},e=o.clientX,s=o.clientY,i===null&&(i=requestAnimationFrame(r))}),this.svg_element.addEventListener("mouseup",o=>{t=!1}),this.svg_element.addEventListener("point-clicked",(o=>{var g,c;const l=(c=(g=o.detail)==null?void 0:g.pointData)==null?void 0:c.ID;if(!l)return;const u=this._pointLabels.get(l)??this._meanLabels.get(l.replace("mean-",""))??this._nodeLabels.get(l);u&&u.displayMode===H.DISPLAY_TYPES.CLICK&&u.toggle()}));const a=_(o=>{var l;for(;o&&o!==this.svg_element;){const u=(l=o.getAttribute)==null?void 0:l.call(o,"data-point-id");if(u)return u;o=o.parentElement}return null},"findPointId"),h=_(o=>this._pointLabels.get(o)??this._meanLabels.get(o.replace(/^mean-/,""))??this._nodeLabels.get(o),"getAutoLabel");this.svg_element.addEventListener("mouseover",o=>{const l=a(o.target);if(!l)return;const u=h(l);(u==null?void 0:u.displayMode)===H.DISPLAY_TYPES.AUTO&&u.show()}),this.svg_element.addEventListener("mouseout",o=>{const l=a(o.target);if(!l)return;const u=o.relatedTarget;if(a(u)===l)return;const c=h(l);(c==null?void 0:c.displayMode)===H.DISPLAY_TYPES.AUTO&&c.hide()}),this._attachInteractionEvents()}_emit(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e,bubbles:!0,composed:!0}))}_closestWith(t,e){var s,i;for(;t&&t!==this.svg_element;){if(((s=t.getAttribute)==null?void 0:s.call(t,e))!=null&&((i=t.hasAttribute)!=null&&i.call(t,e)))return t;t=t.parentElement}return null}_edgeDetail(t){const e=this._closestWith(t,"data-edge-source");if(!e)return null;const s={source:e.getAttribute("data-edge-source"),target:e.getAttribute("data-edge-target"),weight:parseFloat(e.getAttribute("data-edge-weight")||"0"),directed:e.getAttribute("data-edge-directed")==="true",self:e.getAttribute("data-edge-self")==="true"};return e.hasAttribute("data-edge-group")&&(s.group=e.getAttribute("data-edge-group")),e.hasAttribute("data-edge-unit")&&(s.unit=e.getAttribute("data-edge-unit")),s}_nodeDetail(t){const e=this._closestWith(t,"data-point-id");if(!e)return null;const s=e.tagName.toLowerCase();let i,n;s==="rect"?(i=parseFloat(e.getAttribute("x")||"0")+parseFloat(e.getAttribute("width")||"0")/2,n=parseFloat(e.getAttribute("y")||"0")+parseFloat(e.getAttribute("height")||"0")/2):(i=parseFloat(e.getAttribute("cx")||"0"),n=parseFloat(e.getAttribute("cy")||"0"));const r=e.getAttribute("data-point-id"),a={id:r,kind:e.getAttribute("data-kind")||"point",name:e.getAttribute("data-name")||r,x:i,y:n};return e.hasAttribute("data-group")&&(a.group=e.getAttribute("data-group")),e.hasAttribute("data-unit")&&(a.unit=e.getAttribute("data-unit")),a}_attachInteractionEvents(){const t=this.svg_element;t.addEventListener("click",i=>{const n=i.target,r=this._edgeDetail(n);if(r){this._emit("qe-edge-click",{...r,originalEvent:i});return}const a=this._nodeDetail(n);a&&this._emit("qe-node-click",{...a,originalEvent:i})});let e=null;const s=_((i,n)=>i==="edge"?`${n.source}\0${n.target}`:String(n.id),"keyOf");t.addEventListener("mousemove",i=>{const n=i.target,r=this._edgeDetail(n),a=r?null:this._nodeDetail(n),h=r?{type:"edge",detail:r}:a?{type:"node",detail:a}:null,o=h?s(h.type,h.detail):null;e&&(!h||e.key!==o)&&(this._emit(e.type==="edge"?"qe-edge-unhover":"qe-node-unhover",{key:e.key}),e=null),h&&(!e||e.key!==o)&&(this._emit(h.type==="edge"?"qe-edge-hover":"qe-node-hover",{...h.detail,originalEvent:i}),e={type:h.type,key:o}),this.hasAttribute("tooltip")&&h?this._showTooltip(this._tooltipText(h.type,h.detail),i.clientX,i.clientY):this._hideTooltip()}),t.addEventListener("mouseleave",()=>{e&&(this._emit(e.type==="edge"?"qe-edge-unhover":"qe-node-unhover",{key:e.key}),e=null),this._hideTooltip()})}_tooltipText(t,e){if(t==="edge"){const s=Number(e.weight),i=Number.isFinite(s)?` (${+s.toFixed(3)})`:"";return`${e.source} – ${e.target}${i}`}return String(e.name??e.id)}_showTooltip(t,e,s){if(!this._tooltipEl){const i=document.createElement("div");i.setAttribute("data-qe-tooltip",""),Object.assign(i.style,{position:"fixed",zIndex:"2147483647",pointerEvents:"none",background:"rgba(20,20,20,0.92)",color:"#fff",font:"12px/1.4 system-ui, sans-serif",padding:"3px 7px",borderRadius:"4px",whiteSpace:"nowrap",transform:"translate(-50%, calc(-100% - 8px))"}),document.body.appendChild(i),this._tooltipEl=i}this._tooltipEl.textContent=t,this._tooltipEl.style.left=`${e}px`,this._tooltipEl.style.top=`${s}px`,this._tooltipEl.style.display="block"}_hideTooltip(){this._tooltipEl&&(this._tooltipEl.style.display="none")}draw(){var t;if(!this.svg_element){console.error("No element to draw to: ",this);return}if((t=this.wrapper)==null||t.appendChild(this.svg_element),this.__children__.forEach(e=>{e.draw()}),!this._resizeObs&&typeof ResizeObserver<"u"&&this.svg_element){let e=0;this._resizeObs=new ResizeObserver(s=>{var n;const i=((n=s[0])==null?void 0:n.contentRect.width)??0;i>0&&Math.abs(i-e)>.5&&(e=i,this.update_labels(),this.update_axes())}),this._resizeObs.observe(this.svg_element)}}update(){this.update_extremes(),this.update_layers(),this.update_labels(),this.update_extremes(),this.update_axes(),this._applyHighlights()}update_axes(){var o,l;const t=this.__children__.search("__children__","axes");t!=null&&t.svg_element&&(t.svg_element.style.display=this._showAxes?"":"none");const e=this._labelsGroup,s=this.__data__.extremes.x_max,{cx:i,cy:n}=this.__data__.extremes;if(!e||s<=0)return;const r=s*.06,a=r*.6,h=_((u,g)=>{let c=this._axisLabelEls.get(u);if(!this._showAxes||g==null){c&&(c.remove(),this._axisLabelEls.delete(u));return}c||(c=document.createElementNS("http://www.w3.org/2000/svg","text"),c.setAttribute("data-axis-label",u),c.setAttribute("pointer-events","none"),e.appendChild(c),this._axisLabelEls.set(u,c)),c.textContent=g,c.setAttribute("font-size",r.toString()),c.setAttribute("font-family","system-ui, sans-serif"),c.setAttribute("font-weight","600"),c.setAttribute("fill","#556"),u==="x"?(c.setAttribute("x",(i+s-a).toString()),c.setAttribute("y",(-a).toString()),c.setAttribute("text-anchor","end")):(c.setAttribute("x",a.toString()),c.setAttribute("y",(n-s+r+a).toString()),c.setAttribute("text-anchor","start"))},"place");if(h("x",this._axisXText),h("y",this._axisYText),this._magnifyText==null)(o=this._magnifyEl)==null||o.remove(),this._magnifyEl=null;else{this._magnifyEl||(this._magnifyEl=document.createElementNS("http://www.w3.org/2000/svg","text"),this._magnifyEl.setAttribute("data-magnify-label",""),this._magnifyEl.setAttribute("pointer-events","none")),this._magnifyEl.parentElement||e.appendChild(this._magnifyEl);const u=this._magnifyEl;u.textContent=this._magnifyText,u.setAttribute("font-size",(r*.85).toString()),u.setAttribute("font-family","system-ui, sans-serif"),u.setAttribute("font-style","italic"),u.setAttribute("fill","#556"),u.setAttribute("x",(i-s+a).toString()),u.setAttribute("y",(n-s+r+a).toString()),u.setAttribute("text-anchor","start")}if(!this._plotTitle)(l=this._titleEl)==null||l.remove(),this._titleEl=null;else{this._titleEl||(this._titleEl=document.createElementNS("http://www.w3.org/2000/svg","text"),this._titleEl.setAttribute("data-plot-title",""),this._titleEl.setAttribute("pointer-events","none")),this._titleEl.parentElement||e.appendChild(this._titleEl);const g=(this._labelFont.size??12)*1.35*this.unitsPerPixel(),c=this._titleEl;c.textContent=this._plotTitle,c.setAttribute("font-size",g.toString()),c.setAttribute("font-family",this._labelFont.family??"system-ui, sans-serif"),c.setAttribute("font-weight","600"),c.setAttribute("fill",this._labelFont.color??"#223"),c.setAttribute("x",i.toString()),c.setAttribute("y",(n-s+g*1.1).toString()),c.setAttribute("text-anchor","middle")}}update_labels(){this._nodeLabels.forEach(t=>t.update()),this._meanLabels.forEach(t=>t.update()),this._pointLabels.forEach(t=>t.update())}update_extremes(){var s;const t=this.__data__;if(t.update_extremes(this._centerContent),this._rangeExtent&&this._rangeExtent>0){const{cx:i,cy:n}=t.extremes,r=this._centerContent&&this._rangeMode==="network"?t.nodeExtentFrom(i,n)*1.2:this._rangeExtent;t.extremes=new Dt(r,r,i,n)}const e=(s=this.svg_element)==null?void 0:s.getBoundingClientRect();if(this.svg_element&&e){console.log("SVG rect: ",e);let i,n;e.width===0||e.height===0?(i=1,n=1):(i=e.width,n=e.height),this.__data__.scale_x=1/(i/(4*this.__data__.extremes.x_max)),this.__data__.scale_y=1/(n/(4*this.__data__.extremes.y_max)),this.__children__[0].svg_element.setAttribute("transform",this.__data__.transform.toString()),this.svg_element.setAttribute("viewBox",this.__data__.extremes.as_viewBox());let r=this.__data__.layers.search("layers","axis_lines");if(r){let a=r.objects.get("axis-x"),h=r.objects.get("axis-y");if(a&&h){const o=this.__data__.extremes;a.from=new Z({ID:"axis-x-start",dimensions:[o.cx-o.x_max,0],classes:["ena.dimension","ena.dimension"]}),a.to=new Z({ID:"axis-x-end",dimensions:[o.cx+o.x_max,0],classes:["ena.dimension","ena.dimension"]}),h.from=new Z({ID:"axis-y-start",dimensions:[0,o.cy-o.y_max],classes:["ena.dimension","ena.dimension"]}),h.to=new Z({ID:"axis-y-end",dimensions:[0,o.cy+o.y_max],classes:["ena.dimension","ena.dimension"]})}}}}update_layers(){this.__children__.forEach(t=>{t.update()})}};_(ft,"QEGraphElement"),ft.tagName="qe-graph",ft.style=`
19
- ${Ce.style}
18
+ `;let $e=Ue;const Rs=1e-8;function os(m,t=Rs){return m.filter(e=>Math.abs(e.x)>t||Math.abs(e.y)>t)}c(os,"nearOriginFilter");function $s(m){if(m<=0)return[];if(m===1)return[0];const t=new Array(m);for(let e=0;e<m;e++)t[e]=e/(m-1);return t}c($s,"normalizedT");function Ts(m,t){return m.map(e=>{const s=new Array(t+1);let i=1;for(let n=0;n<=t;n++)s[n]=i,i*=e;return s})}c(Ts,"design");function Fs(m){const t=m.length,e=m[0].length,s=m.map(n=>n.slice()),i=Array.from({length:e},()=>new Array(e).fill(0));for(let n=0;n<e;n++){let r=0;for(let a=0;a<t;a++)r+=s[a][n]*s[a][n];if(r=Math.sqrt(r),i[n][n]=r,r>1e-300)for(let a=0;a<t;a++)s[a][n]/=r;for(let a=n+1;a<e;a++){let h=0;for(let o=0;o<t;o++)h+=s[o][n]*s[o][a];i[n][a]=h;for(let o=0;o<t;o++)s[o][a]-=h*s[o][n]}}return{Q:s,R:i}}c(Fs,"qr");function as(m,t){const e=m.length,s=m[0].length,i=new Array(s).fill(0);for(let n=0;n<s;n++){let r=0;for(let a=0;a<e;a++)r+=m[a][n]*t[a];i[n]=r}return i}c(as,"qtY");function hs(m,t){const e=t.length,s=new Array(e).fill(0);for(let i=e-1;i>=0;i--){let n=t[i];for(let r=i+1;r<e;r++)n-=m[i][r]*s[r];s[i]=Math.abs(m[i][i])>1e-12?n/m[i][i]:0}return s}c(hs,"backSolve");function xi(m){return m.map(t=>{let e=0;for(let s=0;s<t.length;s++)e+=t[s]*t[s];return e})}c(xi,"leverages");function Ds(m,t,e){const s=Ts(m,e),{Q:i,R:n}=Fs(s);return hs(n,as(i,t))}c(Ds,"fitCoeffs");function Te(m,t){let e=0,s=1;for(let i=0;i<m.length;i++)e+=m[i]*s,s*=t;return e}c(Te,"evalPoly");function wi(m,t,e,s){const i=Ts(m,s),{Q:n,R:r}=Fs(i),a=xi(n),h=hs(r,as(n,t)),o=hs(r,as(n,e));let _=0;for(let g=0;g<m.length;g++){const p=1-a[g];if(p<=0)return 1/0;const u=t[g]-Te(h,m[g]),d=e[g]-Te(o,m[g]);_+=(u/p)**2+(d/p)**2}return _}c(wi,"loocv2d");function js(m,t,e){const s=m.length,i=Math.min(Math.max(1,Math.floor(t)),Math.max(1,s-1));if(e==="fixed"||s<3)return i;const n=$s(s),r=m.map(_=>_.x),a=m.map(_=>_.y);let h=1,o=1/0;for(let _=1;_<=i;_++){const g=wi(n,r,a,_);g<o&&(o=g,h=_)}return h}c(js,"selectDegree");function Ys(m,t){const e=os(m);if(e.length<3)return null;const s=t.selectionSet?os(t.selectionSet):e,i=s.length>=3?s:e;let n=js(i,t.maxDegree,t.degreeSelection);n=Math.min(n,Math.max(1,e.length-1));const r=$s(e.length),a=Ds(r,e.map(o=>o.x),n),h=Ds(r,e.map(o=>o.y),n);return{degree:n,coeffsX:a,coeffsY:h}}c(Ys,"fitTrajectory");function ls(m,t=100){const e=[];for(let s=0;s<=t;s++){const i=s/t;e.push({x:Te(m.coeffsX,i),y:Te(m.coeffsY,i)})}return e}c(ls,"sampleCurve");const qs=100,As=class As extends Pt{constructor(t={}){const e=t.color instanceof tt?t.color:new tt(typeof t.color=="string"?t.color:"#000000");super([],{ID:t.ID||`traj-${Math.random().toString(36).substring(2,9)}`,size:t.size||1,color:e,highlight:null,active:t.active||!1,meta:t.meta||{},...t}),this._typeName="Trajectory",this.trajPoints=[],this.smooth="none",this.maxDegree=3,this.degreeSelection="loocv_2d",this.selectedDegree=-1,this.polyCoeffsX=[],this.polyCoeffsY=[],this.currentTime=1/0,this.showPoints=!0,this.showTips=!0,this.lineStyle="uniform",this.strokeWidth=2,this.strokeWidthRange=[1,6],this.opacityRange=[.3,1],this.smooth=t.smooth||"none",this.maxDegree=t.maxDegree!==void 0?t.maxDegree:3,this.degreeSelection=t.degreeSelection||"loocv_2d",this.polyCoeffsX=t.polyCoeffsX||[],this.polyCoeffsY=t.polyCoeffsY||[],this.currentTime=t.currentTime!==void 0?t.currentTime:1/0,this.showPoints=t.showPoints!==void 0?t.showPoints:!0,this.showTips=t.showTips!==void 0?t.showTips:!0,this.lineStyle=t.lineStyle||"uniform",this.strokeWidth=t.strokeWidth||2,this.strokeWidthRange=t.strokeWidthRange||[1,6],this.opacityRange=t.opacityRange||[.3,1],t.points&&Array.isArray(t.points)&&(this.trajPoints=t.points.map(s=>{if(s instanceof J)return s;const i=new J({dimensions:[s.x,s.y],meta:{time:s.time,label:s.label}});return i.x=s.x,i.y=s.y,i}))}get activePoints(){return this.currentTime===1/0?this.trajPoints:this.trajPoints.filter(t=>(t.meta&&typeof t.meta.time=="number"?t.meta.time:0)<=this.currentTime)}get path(){return this.pathPoints.reduce((t,e,s)=>s===0?`M${e.x},${e.y}`:`${t} L${e.x},${e.y}`,"")}get pathPoints(){const t=this.activePoints;if(t.length<2)return[];if(this.smooth==="poly"){if(this.polyCoeffsX.length>0&&this.polyCoeffsY.length>0)return ls({degree:this.polyCoeffsX.length-1,coeffsX:this.polyCoeffsX,coeffsY:this.polyCoeffsY},qs);const e=Ys(t.map(s=>({x:s.x,y:s.y})),{maxDegree:this.maxDegree,degreeSelection:this.degreeSelection,selectionSet:this.trajPoints.map(s=>({x:s.x,y:s.y}))});if(e)return this.selectedDegree=e.degree,ls(e,qs)}return t.map(e=>({x:e.x,y:e.y}))}};c(As,"Trajectory");let ce=As;const Gs=1,Ss=class Ss extends Ht{constructor(t,e,s,i=0){super(t,e,s),this._totalweight=0,this._weight=i}get base_color(){return this._color}get color(){const t=this._color||new tt("#000000");return new ae(t,Math.abs(this.weight))}set color(t){this._color=t}base_weight(){return this._weight}get weight(){return Array.isArray(this._weight)?this._weight[0]-this._weight[1]:this._weight}set weight(t){this._weight=t}get totalweight(){return this.weight}set totalweight(t){this._totalweight=t}};c(Ss,"Edge");let _e=Ss;const Es=class Es extends Pt{constructor(e){super(e.dimensions||[],e);nt(this,te);X(this,te,e)}get edge(){return R(this,te)}get path(){const e=R(this,te),s=[e.to.x,e.to.y],i=e.from_point,[n,r]=e.base_pts,a=Math.hypot(i[0]-s[0],i[1]-s[1]),h=Math.hypot(n[0]-r[0],n[1]-r[1]);if(!(a>0)||!(h>0))return"";const o=[(i[0]-s[0])/a,(i[1]-s[1])/a],_=Math.hypot(n[0]-s[0],n[1]-s[1]),g=[(n[0]-s[0])/_,(n[1]-s[1])/_],p=c(T=>h/2*Math.max(0,1-T/a),"halfW"),u=c((T,z)=>`${s[0]+o[0]*T+g[0]*z} ${s[1]+o[1]*T+g[1]*z}`,"at"),d=.2*a,l=Math.min(.15*a,.8*2*p(d)),b=d+l/2,f=d+l;return`M${u(d,0)} L${u(b,p(b))} L${u(f,p(f))} L${u(b,0)} L${u(f,-p(f))} L${u(b,-p(b))}z`}};te=new WeakMap,c(Es,"EdgeArrow");let Fe=Es;const Xe=class Xe extends _e{constructor(e,s,i){super(e,s,i);nt(this,ee);nt(this,ze);this._path="",X(this,ee,!1),this._directions=["from","to"],this.towards="to",R(this,ee)===!0&&X(this,ze,new Fe(this))}get path(){return`M${this.from.x} ${this.from.y} L${this.base_pts[0].join(" ")} L${this.base_pts[1].join(" ")}z`}static calculate_base_points(e){const s=e.towards,i=e._directions.find(b=>b!==e.towards),n=e[i].x,r=e[i].y,a=e[s].x,h=e[s].y,o=a-n,_=h-r,g=Math.hypot(o,_),p=(e.weight??0)*Gs;if(g===0||!isFinite(p)||p===0)return[[a,h],[a,h]];const u=-_/g,d=o/g,l=p/2;return[[a+u*l,h+d*l],[a-u*l,h-d*l]]}get base_pts(){return Xe.calculate_base_points(this)}get arrow(){return R(this,ze)}get with_arrow(){return R(this,ee)}get from_point(){return[this.from.x,this.from.y]}};ee=new WeakMap,ze=new WeakMap,c(Xe,"TaperedEdge");let jt=Xe;const We=class We extends jt{constructor(t,e,s){super(t,e,s),this._dataWeight=0,this._totalweight=t.totalweight??0,this._dataWeight=t.weight??this._weight}get weighted_midpoint(){return le.Geometry.Line.interpolate(this.line)(1-this._dataWeight/this._totalweight)}get base_pts(){return jt.calculate_base_points(this)}static build_path(t){return t._totalweight>0?`M${t.weighted_midpoint[0]} ${t.weighted_midpoint[1]} L${t.base_pts[0].join(" ")} L${t.base_pts[1].join(" ")}z`:(console.error("TaperedWeightedMidpointEdge: No totalweight, returning empty path"),"")}get path(){return We.build_path(this)}get from_point(){return this.weighted_midpoint}};c(We,"TaperedWeightedMidpointEdge");let cs=We;const He=class He extends _e{constructor(t,e,s){super(t,e,s)}static build_path(t,e){let s=t/2,i=e.x-s,n=s*2;return`M ${i}, ${e.y} a ${s},${s} 0 1,0 ${n},0 a ${s},${s} 0 1,0 -${n},0`}get path(){let t=this.weight*Gs;return He.build_path(t,this.to)}};c(He,"NodeEdge");let Vt=He;const Ms=class Ms{constructor(t,e,s,i=new Rt){this.__data__=t,this.parent=e,this.graph=s,this.__children__=i,this.svg_element=this.create()}get_size(){return this.__data__.size}draw(){var t;(t=this.parent)==null||t.appendChild(this.svg_element)}update(t,e=!0){}animateSVGAttribute(t,e,s){const i=parseFloat(t.getAttribute(e)||"0");if(i===s)return;const n=5e3,r=performance.now();function a(h){const o=Math.min(1,(h-r)/n),_=i+(s-i)*o;t.setAttribute(e,_.toString()),o<1?requestAnimationFrame(a):t.setAttribute(e,s.toString())}c(a,"animate"),requestAnimationFrame(a)}};c(Ms,"Drawable");let ue=Ms;const vi=.04,Ai=[.25,1],Si=[.3,1];function Bs(m,t,e,s){const i=Math.abs(m);if(!(i>0))return 0;if(!(e>t))return s[1];const n=Math.min(1,Math.max(0,(i-t)/(e-t)));return s[0]+n*(s[1]-s[0])}c(Bs,"rampFor");const Ei=.011,Mi=.75,Ii=.8,Ni=.75,Us=.006,ki=.6;function zi(m){return 2*m}c(zi,"widthPerWeight");function Ci(m,t){return m*t/(2*Us)}c(Ci,"nodeSizeForEdges");function Oi(m){const t=/rgba?\(([^)]+)\)/.exec(m);if(!t)return m;const[e,s,i,n=1]=t[1].split(",").map(Number),r=c(a=>Math.round(255+(a-255)*n),"f");return`rgb(${r(e)},${r(s)},${r(i)})`}c(Oi,"flattenOnWhite");function Pi(m,t){const e=/rgba?\(([^)]+)\)/.exec(m);if(!e)return m;const[s,i,n,r=1]=e[1].split(",").map(Number);return`rgba(${Math.round(s*t)},${Math.round(i*t)},${Math.round(n*t)},${r})`}c(Pi,"darkenRgba");const Is=class Is extends ue{constructor(t,e,s,i=new Rt){super(t,e,s,i),this.__data__=t,this.parent=e,this.graph=s,this.__children__=i,this.__name__="unnamed-line",this._arrow_el=null,this._hit_el=null,this.svg_element=this.create()}_stampEdge(t){const e=this.__data__.meta??{};if(!e.isMeanEdge)return;t.setAttribute("data-edge-source",String(e.source??"")),t.setAttribute("data-edge-target",String(e.target??"")),t.setAttribute("data-edge-weight",String(e.weight??0)),t.setAttribute("data-edge-directed",e.isDirected?"true":"false");const s=c((i,n)=>n!=null&&n!==!1?t.setAttribute(i,n===!0?"true":String(n)):t.removeAttribute(i),"opt");s("data-edge-self",!!e.isSelf),s("data-edge-group",e.group),s("data-edge-unit",e.unit)}create(){if(this.__data__ instanceof Vt){const e=document.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("fill",this.__data__.color.toString()),e.setAttribute("stroke","none"),this.svg_element=e,e}if(this.__data__ instanceof jt){const e=document.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("fill",this.__data__.color.toString()),e.setAttribute("stroke","none"),this.svg_element=e,e}const t=document.createElementNS("http://www.w3.org/2000/svg","line");return t.setAttribute("x1",this.__data__.from.x.toString()),t.setAttribute("y1",this.__data__.from.y.toString()),t.setAttribute("x2",this.__data__.to.x.toString()),t.setAttribute("y2",this.__data__.to.y.toString()),t.setAttribute("stroke-width",this.get_size().toString()),t.setAttribute("stroke",this.__data__.color.toString()),this.svg_element=t,t}get drawsPath(){return this.__data__ instanceof Vt||this.__data__ instanceof jt}update(){var i,n,r,a;if(this.svg_element||this.create(),this.svg_element.tagName.toLowerCase()==="path"!==this.drawsPath){const h=this.svg_element;this.create(),h.parentElement&&h.replaceWith(this.svg_element)}this.drawsPath&&((i=this._hit_el)==null||i.remove(),this._hit_el=null),this.svg_element.parentElement||this.parent.appendChild(this.svg_element);const t=((n=this.graph.__data__.extremes)==null?void 0:n.x_max)??1,e=this.__data__.meta??{};let s=!1;if(e.isMeanEdge){this._stampEdge(this.svg_element);const h=typeof e.weight=="number"?e.weight:0,o=typeof e.maxWeight=="number"?e.maxWeight:1,_=typeof e.opacity=="number"?e.opacity:Math.min(1,h/(o||1)),g=t>0?t:1,p=e.fixedSize&&this.graph.zoom_level||1,u=(typeof e.widthFrac=="number"?g*e.widthFrac*h:g*Ei*(h/(o||1)))/p,d=this.__data__._color||new tt("#000000"),l=typeof e.saturation=="number"?e.saturation:_,b=new ae(d,l,_).toString();if(this.__data__ instanceof Vt){const f=typeof e.selfSize=="number"&&e.selfSize>0?e.selfSize:null,w=f!=null?(a=(r=this.graph)._nodeRadius)==null?void 0:a.call(r,String(e.source)):null;this.__data__.weight=typeof w=="number"?2*f*w:u,this.svg_element.setAttribute("d",this.__data__.path),this.svg_element.setAttribute("fill",b),this.svg_element.setAttribute("stroke","none")}else if(this.__data__ instanceof jt){if(this.__data__.weight=u,this.svg_element.setAttribute("d",this.__data__.path),this.svg_element.setAttribute("fill",b),this.svg_element.setAttribute("stroke",b),this.svg_element.setAttribute("stroke-width",String(Mi)),this.svg_element.setAttribute("vector-effect","non-scaling-stroke"),this.svg_element.setAttribute("stroke-linejoin","round"),e.isDirected)try{const w=new Fe(this.__data__).path;w&&!w.includes("NaN")&&!w.includes("Infinity")&&(this._arrow_el||(this._arrow_el=document.createElementNS("http://www.w3.org/2000/svg","path"),this._arrow_el.setAttribute("stroke","none")),this._arrow_el.parentElement||this.parent.appendChild(this._arrow_el),this._arrow_el.setAttribute("d",w),this._arrow_el.setAttribute("fill",Pi(Oi(b),Ii)),this._arrow_el.setAttribute("stroke","#ffffff"),this._arrow_el.setAttribute("stroke-width",String(Ni)),this._arrow_el.setAttribute("vector-effect","non-scaling-stroke"),this._arrow_el.setAttribute("stroke-linejoin","round"),s=!0)}catch{}}else{const f=this.__data__.from.x,w=this.__data__.from.y,T=this.__data__.to.x,z=this.__data__.to.y;this.svg_element.setAttribute("x1",f.toString()),this.svg_element.setAttribute("y1",w.toString()),this.svg_element.setAttribute("x2",T.toString()),this.svg_element.setAttribute("y2",z.toString()),this.svg_element.setAttribute("stroke-width",u.toString()),this.svg_element.setAttribute("stroke",b),this.svg_element.setAttribute("pointer-events","stroke"),this.svg_element.removeAttribute("marker-end"),this._hit_el||(this._hit_el=document.createElementNS("http://www.w3.org/2000/svg","line"),this._hit_el.setAttribute("stroke","transparent"),this._hit_el.setAttribute("stroke-linecap","round"),this._hit_el.setAttribute("pointer-events","stroke")),this._hit_el.parentElement||this.parent.appendChild(this._hit_el),this._hit_el.setAttribute("x1",f.toString()),this._hit_el.setAttribute("y1",w.toString()),this._hit_el.setAttribute("x2",T.toString()),this._hit_el.setAttribute("y2",z.toString()),this._hit_el.setAttribute("stroke-width",Math.max(u,t*.03/p).toString()),this._stampEdge(this._hit_el)}}else{this.svg_element.setAttribute("x1",this.__data__.from.x.toString()),this.svg_element.setAttribute("y1",this.__data__.from.y.toString()),this.svg_element.setAttribute("x2",this.__data__.to.x.toString()),this.svg_element.setAttribute("y2",this.__data__.to.y.toString());const h=this.graph._axesFixedSize&&String(this.__data__.ID).startsWith("axis-")&&this.graph.zoom_level||1,o=(t>0?t:1)*.004*this.get_size()/h;this.svg_element.setAttribute("stroke-width",o.toString()),this.svg_element.setAttribute("stroke-opacity","1"),this.svg_element.setAttribute("stroke",this.__data__.color.toString())}!s&&this._arrow_el&&(this._arrow_el.remove(),this._arrow_el=null)}remove(){var t,e,s;(t=this.svg_element)==null||t.remove(),(e=this._hit_el)==null||e.remove(),(s=this._arrow_el)==null||s.remove()}draw(){var t,e,s;this._hit_el&&((t=this.parent)==null||t.appendChild(this._hit_el)),(e=this.parent)==null||e.appendChild(this.svg_element),this._arrow_el&&((s=this.parent)==null||s.appendChild(this._arrow_el))}};c(Is,"QELine");let St=Is;const Ns=class Ns extends ue{constructor(t,e,s,i=new Rt){super(t,e,s,i),this.__data__=t,this.parent=e,this.graph=s,this.__children__=i,this.__name__="unnamed-point",this.svg_element=this.create()}get x(){return this.__data__.dimensions[this.graph.__data__.options.GRAPH.dimensions[0]]}get y(){return this.__data__.dimensions[this.graph.__data__.options.GRAPH.dimensions[1]]}get isSquare(){return this.__data__.shape==="rect"}get shapeKind(){const t=this.__data__.shape;return t==="rect"||t==="square"?"rect":t==="triangle"||t==="diamond"?t:"circle"}get tag(){const t=this.shapeKind;return t==="circle"?"circle":t==="rect"?"rect":"path"}setGeometry(t,e){const s=this.x,i=this.y;switch(this.shapeKind){case"rect":t.setAttribute("x",(s-e).toString()),t.setAttribute("y",(i-e).toString()),t.setAttribute("width",(e*2).toString()),t.setAttribute("height",(e*2).toString());break;case"triangle":{const n=e*1.15;t.setAttribute("d",`M${s} ${i-n} L${s+n*.866} ${i+n*.5} L${s-n*.866} ${i+n*.5}Z`);break}case"diamond":t.setAttribute("d",`M${s} ${i-e*1.2} L${s+e} ${i} L${s} ${i+e*1.2} L${s-e} ${i}Z`);break;default:t.setAttribute("cx",s.toString()),t.setAttribute("cy",i.toString()),t.setAttribute("r",e.toString())}}computeRadius(){var s;const t=this.baseRadius(),e=(s=this.__data__.meta)==null?void 0:s.maxRadius;return typeof e=="number"&&e>0?Math.min(t,e):t}baseRadius(){var e;const t=this.dataRadius();return(e=this.__data__.meta)!=null&&e.zoomFixed?t/(this.graph.zoom_level||1):t}dataRadius(){var i,n,r,a,h,o,_;const t=this.graph.__data__.extremes.x_max||1,e=((i=this.__data__.meta)==null?void 0:i.sizeScale)??1,s=(n=this.__data__.meta)==null?void 0:n.sizePx;if(typeof s=="number"&&s>0){const g=(a=(r=this.graph.svg_element)==null?void 0:r.getBoundingClientRect)==null?void 0:a.call(r),p=g&&g.width>0?2*t/g.width:t*.004;return s/2*p}if((h=this.__data__.meta)!=null&&h.fixedSize){const g=(_=(o=this.graph.svg_element)==null?void 0:o.getBoundingClientRect)==null?void 0:_.call(o),p=this.graph.zoom_level||1,u=g&&g.width>0?g.width/(2*t):1;return this.__data__.size*2*e/u/p}return t*Us*this.__data__.size*e}applyStroke(t){var s;const e=(s=this.__data__.meta)==null?void 0:s.stroke;e&&(t.setAttribute("stroke",e),t.setAttribute("stroke-width",(this.computeRadius()*.22).toString()))}stampIdentity(t){t.setAttribute("data-point-id",this.__data__.ID);const e=this.__data__.meta??{},s=c((i,n)=>n!=null&&n!==""?t.setAttribute(i,String(n)):t.removeAttribute(i),"opt");s("data-kind",e.kind),s("data-name",e.name),s("data-group",e.group),s("data-unit",e.unit)}create(){const t=document.createElementNS("http://www.w3.org/2000/svg",this.tag);return this.stampIdentity(t),t.setAttribute("fill",this.__data__.color.toString()),this.applyStroke(t),this.setGeometry(t,this.computeRadius()),this.svg_element=t,t.addEventListener("click",()=>{this.__data__.active=!this.__data__.active,this.update();const e=new CustomEvent("point-clicked",{detail:{pointData:this.__data__},bubbles:!0,composed:!0});this.svg_element.dispatchEvent(e)}),t.addEventListener("mouseover",()=>{}),t}update(){if(this.svg_element||this.parent.__data__.__children__.push(this.create()),this.svg_element.tagName.toLowerCase()!==this.tag){const t=this.svg_element;this.create(),t.parentElement&&t.replaceWith(this.svg_element)}this.svg_element.parentElement||this.parent.appendChild(this.svg_element),this.stampIdentity(this.svg_element),this.svg_element.setAttribute("fill",this.__data__.color.toString()),this.applyStroke(this.svg_element),this.setGeometry(this.svg_element,this.computeRadius())}draw(){var t;(t=this.parent)==null||t.appendChild(this.svg_element)}};c(Ns,"QEPoint");let Zt=Ns;const ks=class ks extends ue{constructor(t,e,s,i=new Rt){super(t,e,s,i),this.__data__=t,this.parent=e,this.graph=s,this.__children__=i,this.__name__="trajectory",this._path_el=null,this._segments_group=null,this._tip_el=null,this._points_group=null,this.svg_element=this.create()}graphUnitsForPixels(t){var i;const e=this.graph.__data__.extremes.x_max||1,s=((i=this.graph.svg_element)==null?void 0:i.getBoundingClientRect().width)||0;return s>0?t*(2*e/s):t*e*.006}create(){const t=document.createElementNS("http://www.w3.org/2000/svg","g");t.setAttribute("class","qe-trajectory-group");const e=document.createElementNS("http://www.w3.org/2000/svg","path");e.setAttribute("fill","none"),e.setAttribute("stroke",this.__data__.color.toString()),e.setAttribute("stroke-width",this.graphUnitsForPixels(this.__data__.strokeWidth).toString()),t.appendChild(e),this._path_el=e;const s=document.createElementNS("http://www.w3.org/2000/svg","g");s.setAttribute("class","qe-trajectory-segments"),t.appendChild(s),this._segments_group=s;const i=document.createElementNS("http://www.w3.org/2000/svg","g");if(i.setAttribute("class","qe-trajectory-points"),t.appendChild(i),this._points_group=i,this.__data__.showTips){const n=document.createElementNS("http://www.w3.org/2000/svg","circle");n.setAttribute("fill",this.__data__.color.toString()),n.setAttribute("r",this.graphUnitsForPixels(4).toString()),n.setAttribute("stroke","#ffffff"),n.setAttribute("stroke-width",this.graphUnitsForPixels(1.5).toString()),t.appendChild(n),this._tip_el=n}return this.svg_element=t,t}update(){this.svg_element||this.create(),this.svg_element.parentElement||this.parent.appendChild(this.svg_element);const t=this.__data__.path;if(this._path_el&&(this._path_el.setAttribute("d",t),this._path_el.setAttribute("stroke",this.__data__.color.toString()),this._path_el.setAttribute("stroke-width",this.graphUnitsForPixels(this.__data__.strokeWidth).toString()),this._path_el.style.display=this.__data__.lineStyle==="tapered"?"none":"block"),this._segments_group)if(this._segments_group.innerHTML="",this.__data__.lineStyle==="tapered"){const s=this.__data__.pathPoints,i=s.length-1,[n,r]=this.__data__.strokeWidthRange,[a,h]=this.__data__.opacityRange;for(let o=0;o<i;o++){const _=s[o],g=s[o+1],p=i<=1?1:o/(i-1),u=n+(r-n)*p,d=a+(h-a)*p,l=document.createElementNS("http://www.w3.org/2000/svg","path");l.setAttribute("d",`M${_.x},${_.y} L${g.x},${g.y}`),l.setAttribute("fill","none"),l.setAttribute("stroke",this.__data__.color.toString()),l.setAttribute("stroke-linecap","round"),l.setAttribute("stroke-linejoin","round"),l.setAttribute("stroke-width",this.graphUnitsForPixels(u).toString()),l.setAttribute("opacity",d.toString()),this._segments_group.appendChild(l)}this._segments_group.style.display="block"}else this._segments_group.style.display="none";const e=this.__data__.activePoints;if(this._points_group&&(this.__data__.showPoints&&e.length>0?(this._points_group.innerHTML="",e.forEach(s=>{var n;const i=document.createElementNS("http://www.w3.org/2000/svg","circle");i.setAttribute("cx",s.x.toString()),i.setAttribute("cy",s.y.toString()),i.setAttribute("r",this.graphUnitsForPixels(2.5).toString()),i.setAttribute("fill",this.__data__.color.toString()),i.setAttribute("opacity","0.7"),(n=this._points_group)==null||n.appendChild(i)}),this._points_group.style.display="block"):this._points_group.style.display="none"),this._tip_el&&this.__data__.showTips)if(e.length>0){const s=e[e.length-1];this._tip_el.setAttribute("cx",s.x.toString()),this._tip_el.setAttribute("cy",s.y.toString()),this._tip_el.setAttribute("fill",this.__data__.color.toString()),this._tip_el.setAttribute("r",this.graphUnitsForPixels(4).toString()),this._tip_el.setAttribute("stroke-width",this.graphUnitsForPixels(1.5).toString()),this._tip_el.style.display="block"}else this._tip_el.style.display="none"}draw(){this.svg_element&&!this.svg_element.parentElement&&this.parent.appendChild(this.svg_element),this.update()}};c(ks,"QETrajectory");let de=ks;const{ArrayTools:Xs}=le,zs=class zs extends Array{constructor(...t){super(...t)}search(t,e){let s;function i(r){return r.name===e?r:void 0}c(i,"fn");function n(r,a,h=null){if(Xs.isArray(r)){for(const[o,_]of r.entries())if(s=n(_,o,h),s)return s}else{if(s=i(r),s)return s;if(r&&Xs.isArray(r[t])){for(const[o,_]of r[t].entries())if(s=n(_,o,r),s)return s}}return s}return c(n,"recurse"),n(this)}flatten(){return this.reduce((t,e)=>(t.push(e),e.layers&&Array.isArray(e.layers)&&t.push(...e.layers),t),[])}};c(zs,"QEArray");let Rt=zs;const Li={AxisPoint:Zt,AxisLine:St,Point:Zt,Line:St,Edge:St,TaperedEdge:St,TaperedWeightedMidpointEdge:St,NodeEdge:St,Trajectory:de},se=class se{constructor(t,e,s,i=new Rt){this.__data__=t,this.parent=e,this.graph=s,this.__children__=i,this.__name__=t.name||"unnamed-layer",t.__state__.addListener("layer_updated","live",({key:n,newValue:r,oldValue:a})=>{const h=c(p=>{var u;return(u=p.__data__)==null?void 0:u.ID},"childId"),o=this.__children__.filter(p=>!r.objects.has(h(p))),_=this.__children__.filter(p=>r.objects.has(h(p)));[...r.objects.values()].filter(p=>!this.__children__.some(u=>h(u)===p.ID)).forEach(p=>{const u=p._typeName||p.constructor.name;let d=Li[u];d||(p instanceof ce?d=de:p instanceof J?d=Zt:d=St);const l=new d(p,this.svg_element,this.graph);this.__children__.push(l)}),_.forEach(p=>{const u=r.objects.get(h(p));u&&(p.__data__=u),p.update()}),o.forEach(p=>{var d;typeof p.remove=="function"?p.remove():(d=p.svg_element.parentElement)==null||d.removeChild(p.svg_element);const u=this.__children__.indexOf(p);u>=0&&this.__children__.splice(u,1)}),this.update()}),this.svg_element=this.create()}get name(){return this.__name__}create(){if(!this.__data__)throw new Error("Layer is null");let t=this.__data__;return this.svg_element=document.createElementNS("http://www.w3.org/2000/svg",se.tagName),this.svg_element.setAttribute("data-layer-name",t.name),this.svg_element.setAttribute("data-layer-id",t.ID),this.svg_element.__data__=t,this.svg_element.classList.add("ena-layer"),this.__data__.layers&&this.__data__.layers.length>0&&this.__data__.layers.forEach(e=>{const s=new se(e,this.svg_element,this.graph);this.__children__.push(s)}),this.svg_element}update(){if(!this.__data__)throw new Error("Layer is null");this.__data__.visible&&(this.parent.nodeName.toLowerCase(),this.__children__.forEach(t=>{t.update()}),this.__data__.scale_objects===!0&&this.__name__)}draw(){var t;(t=this.parent)==null||t.appendChild(this.svg_element),this.__children__.forEach(e=>{e.draw()})}add(t){this.__children__.push(t)}};c(se,"QELayer"),se.tagName="g";let De=se;const Cs=class Cs{constructor(t,e,s,i,n=q.DISPLAY_TYPES.ON,r=q.POSITION.OBJECT,a,h){this.text=t,this.parent=s,this.graph=i,this.displayMode=n,this.position=r,this.customX=a,this.customY=h,this._visible=!1,this._offsetX=0,this._offsetY=0,this.pinned=!1,this._hostPinned=!1,this.fontWeight=null,this._point=e,this.svg_element=this._create(),n===q.DISPLAY_TYPES.ON?(this._visible=!0,this.svg_element.setAttribute("display","block")):(this._visible=!1,this.svg_element.setAttribute("display","none"))}get point(){return this._point}_create(){const t=document.createElementNS("http://www.w3.org/2000/svg","text");return t.textContent=this.text,t.setAttribute("data-label-for",this.point.ID),t.setAttribute("pointer-events","auto"),t.style.cursor="grab",this._attachDrag(t),this.parent.appendChild(t),t}setPoint(t){this._point=t,this.svg_element.setAttribute("data-label-for",t.ID)}setOffset(t,e){this._offsetX=Number.isFinite(t)?t:0,this._offsetY=Number.isFinite(e)?e:0}setHostPinned(t){t!==this._hostPinned&&(this._hostPinned=t,t?this.show():this.displayMode!==q.DISPLAY_TYPES.ON&&this.hide())}_attachDrag(t){t.addEventListener("mousedown",e=>{e.preventDefault(),e.stopPropagation(),this._drag(t,e.clientX,e.clientY,"mouse")}),t.addEventListener("pointerdown",e=>{e.pointerType==="touch"&&(e.preventDefault(),e.stopPropagation(),this._drag(t,e.clientX,e.clientY,e.pointerId))})}_drag(t,e,s,i){const n=t.parentNode??t.ownerSVGElement,r=t.ownerSVGElement;if(!r||!n)return;const a=c((u,d)=>{const l=r.createSVGPoint();l.x=u,l.y=d;const b=n.getScreenCTM();return b?l.matrixTransform(b.inverse()):{x:0,y:0}},"toUser"),h=a(e,s),o=this._offsetX,_=this._offsetY;t.style.cursor="grabbing";const g=c((u,d)=>{const l=a(u,d);this._offsetX=o+(l.x-h.x),this._offsetY=_+(l.y-h.y),this.pinned=!0,this._visible=!0,this.svg_element.setAttribute("display","block"),this.update()},"move"),p=c(()=>{t.style.cursor="grab",this.graph.dispatchEvent(new CustomEvent("qe-label-move",{detail:{id:this.point.ID,transform:{x:this._offsetX,y:this._offsetY}},bubbles:!0,composed:!0}))},"done");if(i==="mouse"){const u=c(l=>g(l.clientX,l.clientY),"onMove"),d=c(()=>{document.removeEventListener("mousemove",u),document.removeEventListener("mouseup",d),p()},"onUp");document.addEventListener("mousemove",u),document.addEventListener("mouseup",d)}else{const u=c(l=>{l.pointerId===i&&g(l.clientX,l.clientY)},"onMove"),d=c(l=>{l.pointerId===i&&(document.removeEventListener("pointermove",u),document.removeEventListener("pointerup",d),document.removeEventListener("pointercancel",d),p())},"onUp");document.addEventListener("pointermove",u),document.addEventListener("pointerup",d),document.addEventListener("pointercancel",d)}}update(){var h;if(!this._visible)return;const t=this.graph.__data__.extremes.x_max;if(t<=0)return;const e=this.graph._labelFont??{},s=e.size?e.size*this.graph.unitsPerPixel():t*.06,i=s*1.2;let n,r,a;switch(this.position){case q.POSITION.STATIC:{n=this.point.x,r=this.point.y-i*.3,a="middle";break}case q.POSITION.CONTAINER:{const{cx:o,cy:_}=this.graph.__data__.extremes,g=this.point.x-o,p=this.point.y-_,u=Math.sqrt(g*g+p*p)||1,d=t*.93/u;n=o+g*d,r=_+p*d-i*.3,a=g>=0?"start":"end";break}case q.POSITION.CUSTOM:if(this.customX!=null&&this.customY!=null){n=this.customX,r=this.customY,a="start";break}default:case q.POSITION.OBJECT:{const o=this.point.x>=0?i:-i;a=this.point.x>=0?"start":"end",n=this.point.x+o,r=this.point.y-i*.4;break}}this.svg_element.setAttribute("x",n.toString()),this.svg_element.setAttribute("y",r.toString()),this._offsetX||this._offsetY?this.svg_element.setAttribute("transform",`translate(${this._offsetX}, ${this._offsetY})`):this.svg_element.removeAttribute("transform"),this.svg_element.setAttribute("font-size",s.toString()),this.svg_element.setAttribute("font-family",e.family??"system-ui, sans-serif"),this.svg_element.setAttribute("font-weight",this.fontWeight??"500"),this.svg_element.setAttribute("text-anchor",a),this.svg_element.setAttribute("fill",e.color??((h=this.point.color)==null?void 0:h.toString())??"#333333"),!this._offsetX&&!this._offsetY&&this.position!==q.POSITION.CUSTOM&&this.fitInside(n,r,a,i,s*.3)}visibleBounds(){var h;const t=this.svg_element,e=t.ownerSVGElement,s=(h=t.getScreenCTM)==null?void 0:h.call(t);if(!e||!s)return null;const i=e.getBoundingClientRect();if(!(i.width>0&&i.height>0))return null;const n=s.inverse(),r=new DOMPoint(i.left,i.top).matrixTransform(n),a=new DOMPoint(i.right,i.bottom).matrixTransform(n);return{left:Math.min(r.x,a.x),right:Math.max(r.x,a.x),top:Math.min(r.y,a.y),bottom:Math.max(r.y,a.y)}}bbox(){try{const t=this.svg_element.getBBox();return t.width>0?t:null}catch{return null}}fitInside(t,e,s,i,n){const r=this.visibleBounds();let a=this.bbox();if(!r||!a)return;const h=r.left+n,o=r.right-n,_=r.top+n,g=r.bottom-n,p=c(b=>Math.max(0,h-b.x)+Math.max(0,b.x+b.width-o),"over"),u=this.svg_element;if(p(a)>0&&this.position===q.POSITION.OBJECT&&s!=="middle"){const b=s==="end"?"start":"end",f=s==="end"?this.point.x+i:this.point.x-i;u.setAttribute("text-anchor",b),u.setAttribute("x",f.toString());const w=this.bbox();w&&p(w)<p(a)?(a=w,t=f):(u.setAttribute("text-anchor",s),u.setAttribute("x",t.toString()))}let d=0,l=0;a.x<h?d=h-a.x:a.x+a.width>o&&(d=Math.max(o-(a.x+a.width),h-a.x)),a.y<_?l=_-a.y:a.y+a.height>g&&(l=Math.max(g-(a.y+a.height),_-a.y)),d&&u.setAttribute("x",(t+d).toString()),l&&u.setAttribute("y",(e+l).toString())}show(){this._visible=!0,this.svg_element.setAttribute("display","block"),this.update()}hide(){this.pinned||this._hostPinned||(this._visible=!1,this.svg_element.setAttribute("display","none"))}toggle(){this._visible?this.hide():this.show()}get visible(){return this._visible}remove(){this.svg_element.remove()}};c(Cs,"QELabel");let _s=Cs;const Ve=class Ve extends HTMLElement{};c(Ve,"QENodesElement"),Ve.tagName="qe-nodes";let ge=Ve;const Ze=class Ze extends HTMLElement{};c(Ze,"QEMeansElement"),Ze.tagName="qe-means";let me=Ze;const Ke=class Ke extends HTMLElement{};c(Ke,"QEPointsElement"),Ke.tagName="qe-points";let fe=Ke;const Je=class Je extends HTMLElement{};c(Je,"QEEdgesElement"),Je.tagName="qe-edges";let pe=Je;const Qe=class Qe extends HTMLElement{};c(Qe,"QETrajectoriesElement"),Qe.tagName="qe-trajectories";let be=Qe;const ts=class ts extends HTMLElement{};c(ts,"QEAxesElement"),ts.tagName="qe-axes";let ye=ts;customElements.define(ge.tagName,ge),customElements.define(me.tagName,me),customElements.define(fe.tagName,fe),customElements.define(pe.tagName,pe),customElements.define(be.tagName,be),customElements.define(ye.tagName,ye);const Ws=["#4477AA","#EE6677","#228833","#CCBB44","#66CCEE","#AA3377","#BBBBBB","#000000"];function Ri(m,t){for(const e of t)if(m===`${e}.${e}`)return[e,e];for(const e of t)if(m.startsWith(e+".")){const s=m.slice(e.length+1);if(t.includes(s))return[e,s]}return null}c(Ri,"parseEdgePair");function $i(m,t,e,s){const i=Math.max(1,e-1),n=i>=120?1.96:i>=60?2:i>=30?2.042:i>=20?2.086:i>=10?2.228:i>=5?2.571:4.303,r=Math.sqrt(Math.max(0,m)/e)*s,a=Math.sqrt(Math.max(0,t)/e)*s;return{halfW:n*r,halfH:n*a}}c($i,"computeCIRect");const Ti=.5;function je(m,t,e){if(!m)return;const s=Math.min(Math.abs(t),Math.abs(e));s>0&&(m.meta={...m.meta??{},maxRadius:s*Ti})}c(je,"capMeanToInterval");function Ye(m,t,e,s=""){const i=c(o=>{const _=m.names.indexOf(o),g=_>=0?m[_]:null;if(g==null||g==="")return;const p=Number(g);return Number.isFinite(p)?p:void 0},"get"),n=i(`${t}.${s}low`)??i(`${t}_${s}low`),r=i(`${t}.${s}high`)??i(`${t}_${s}high`),a=i(`${e}.${s}low`)??i(`${e}_${s}low`),h=i(`${e}.${s}high`)??i(`${e}_${s}high`);return n==null||r==null||a==null||h==null?null:{x_low:n,x_high:r,y_low:a,y_high:h}}c(Ye,"readIntervalBounds");function qe(m,t){const e=c(o=>{if(!m)return;const _=m.names.indexOf(o);return _>=0?m[_]:void 0},"raw"),s=c(o=>o==null||o==="NA"||typeof o=="number"&&Number.isNaN(o),"isNA"),i=e("label"),n=s(i)?t:String(i)===""?null:String(i),r=c(o=>{const _=e(o),g=s(_)||_===""?0:Number(_);return Number.isFinite(g)?g:0},"num"),a=!!m&&(m.names.includes("label.dx")||m.names.includes("label.dy")),h=e("label.pinned");return{text:n,offset:a?{x:r("label.dx"),y:r("label.dy")}:null,pinned:h===!0||h===1||String(h).toLowerCase()==="true"}}c(qe,"readLabelSpec");function Fi(m){const t=m==null?void 0:m.trim().toLowerCase();if(!t)return null;if(t==="node")return .5;const e=Number(t);return Number.isFinite(e)&&e>0?e:null}c(Fi,"parseSelfSize");function Di(m){var i,n;const t=c(r=>m.getAttribute(r),"a"),e=((i=t("colors"))==null?void 0:i.split(",").map(r=>r.trim()).filter(Boolean))??[],s=((n=t("threshold"))==null?void 0:n.split(",").map(Number).filter(Number.isFinite))??[];return{group:t("group"),unit:t("unit"),compare:t("compare"),also:t("also"),network:t("network"),colors:e.length?[e[0],e[1]??null]:null,threshold:s.length?[s[0],s.length>1?s[1]:1/0]:null,name:t("name"),selfSize:Fi(t("self-size")),fixedSize:m.hasAttribute("fixed-size")}}c(Di,"parseEdgeLayer");function ji(m){const{r:t,g:e,b:s}=tt.parseColor(m),i=Math.max(t,e,s),n=Math.min(t,e,s),r=c(a=>(i+n-a).toString(16).padStart(2,"0"),"f");return`#${r(t)}${r(e)}${r(s)}`}c(ji,"complementColor");function Yi(m){const t=m==null?void 0:m.trim().toLowerCase();return t==="plot"||t==="absolute"?t:"model"}c(Yi,"parseColorScale");function Ge(m,t){switch(m==null?void 0:m.toLowerCase()){case"on":return 3;case"off":return 0;case"click":return 2;case"auto":return 1;default:return t}}c(Ge,"parseLabelMode");const it=class it extends $e{constructor(){super(),this.zoom_level=1,this.__children__=new Rt,this._hasModel=!1,this._renderPending=!1,this._childObserver=null,this._ciRects=new Map,this._outlierRects=new Map,this._ciCross=new Map,this._labelsGroup=null,this._nodeLabels=new Map,this._meanLabels=new Map,this._pointLabels=new Map,this._setLabels=new Map,this._showAxes=!1,this._axisXText=null,this._axisYText=null,this._axisLabelEls=new Map,this._magnifyText=null,this._magnifyEl=null,this._rangeExtent=null,this._rangeMode=null,this._centerContent=!1,this._edgesFixedSize=!1,this._meansFixedSize=!1,this._intervalBase=new WeakMap,this._axesFixedSize=!1,this._plotTitle=null,this._titleEl=null,this._resizeObs=null,this._labelFont={size:null,family:null,color:null},this._zoomAnim=null,this._animateMs=0,this._tweenRaf=null,this._tween=null,this._tweenView=null,this._highlight={edges:new Set,nodes:new Set},this._highlightGroup=null,this._tooltipEl=null,this.graph=this,this.parent=null,this.__data__=new Re(Ls),this.__name__=this.__data__.name||"unnamed-graph",this.svg_element=this.create(),Xt("Created qe-graph svg element: ",this.svg_element),document.addEventListener("model-updated",t=>{var Ks,Js,Qs,ti,ei,si,ii,ni,ri,oi,ai,hi,li,ci,_i,ui,di;const e=((Ks=t.composedPath)==null?void 0:Ks.call(t)[0])??t.target;if(this._vizena&&e!==this._vizena)return;const s=t.detail;if(!s)return;this._renderPending=!1,(Js=this._childObserver)==null||Js.takeRecords(),this._animateMs=this.hasAttribute("animate")?parseInt(this.getAttribute("animate")||"",10)||300:0;const i=this._animateMs>0&&this._hasModel?this._captureTweenState():null;this._stopTween(),this._hasModel=!0;const n=s.dimensions,r=s.unit_id_col,a=s.node_id_col,h=s.group_col,o=this._readLayerConfig();this._showAxes=o.showAxes,this._axisXText=o.axisXLabel===null?null:o.axisXLabel||String((n==null?void 0:n[0])??"x"),this._magnifyText=o.edgeMagnify==null?null:`(scaled ${o.edgeMagnify.toFixed(1)}x)`,this._axisYText=o.axisYLabel===null?null:o.axisYLabel||String((n==null?void 0:n[1])??"y");const _={},g=(Qs=s.palette)!=null&&Qs.length?s.palette:Ws;if(h&&((ti=s.points)!=null&&ti.names)){const I=s.points.col(h);I&&[...new Set([...I].map(String))].forEach((L,N)=>{_[L]=g[N%g.length]})}(ei=s.groups)!=null&&ei.rows&&s.groups.rows().length>0&&s.groups.rows().forEach(I=>{const k=I.rowName??String(I[0]),L=I.names.indexOf("color"),N=L>=0?I[L]:null;N&&String(N)!=="NA"?_[k]=String(N):_[k]||(_[k]=g[Object.keys(_).length%g.length])});const p=Object.keys(_),u=o.activeMeanGroups&&o.activeMeanGroups.trim()?new Set(o.activeMeanGroups.split(",").map(I=>I.trim()).filter(I=>_[I])):new Set(p),d=o.scalePoints,l=c(I=>{let k=0;return I.forEach(L=>{const N=L.names.indexOf(n[0]),S=n.length>1?L.names.indexOf(n[1]):-1;N>=0&&(k=Math.max(k,Math.abs(Number(L[N])))),S>=0&&(k=Math.max(k,Math.abs(Number(L[S]))))}),k},"getExtent"),b=(si=s.nodes)!=null&&si.rows?l(s.nodes.rows()):0,f=(ii=s.points)!=null&&ii.rows?l(s.points.rows()):0,w=(ni=s.trajectories)!=null&&ni.rows?l(s.trajectories.rows()):0,T=f>0?f:w,z=o.pointScale!==null?o.pointScale:d&&T>0&&b>0?b/T:1;this._rangeExtent=o.range==="network"?b*1.2:o.range==="points"?T*z*1.2:typeof o.range=="number"?o.range:null,this._rangeMode=o.range==="network"||o.range==="points"?o.range:typeof o.range=="number"?"number":null,this._centerContent=o.centerContent,this._edgesFixedSize=o.edgeLayers.some(I=>I.fixedSize),this._meansFixedSize=o.meanFixedSize,this._axesFixedSize=o.axesFixedSize,this._plotTitle=o.plotTitle,this._labelFont=o.labelFont;const j=o.labelNodes,dt=o.labelMeans,gt=o.labelPoints,et=this._labelsGroup,mt=c((I,k,L,N=1)=>{const S=I.names.indexOf(k),y=I.names.indexOf(n[0]),P=n.length>1?I.names.indexOf(n[1]):-1,v=new J({ID:S>=0?String(I[S]):I.rowName||`pt-${Math.random().toString(36).slice(2)}`,dimensions:[y>=0?Number(I[y])*N:0,P>=0?-Number(I[P])*N:0],meta:{}});return L&&(v.color=new tt(L)),v},"rowToPoint"),Q={},Tt=o.showPoints;["points","nodes","edges","edgenodes"].map(I=>this.__children__.search("__children__",I)).filter(I=>!!I).forEach(I=>I.__data__.objects.clear()),this.__data__.points.clear();const Ce=s.pointsets,Gt=[];if(o.pointSets.length&&(Ce!=null&&Ce.rows)){const I=this.__children__.search("__children__","points"),k=c((L,N)=>{const S=L.names.indexOf(N);return S>=0?L[S]:null},"col");o.pointSets.forEach((L,N)=>{Ce.rows().forEach(S=>{if(String(k(S,"set"))!==L.set)return;const y=String(k(S,"id")),P=k(S,"group")!=null&&String(k(S,"group"))!=="NA"?String(k(S,"group")):null,v=k(S,"color")&&String(k(S,"color"))!=="NA"?String(k(S,"color")):P&&_[P]?_[P]:g[N%g.length],E=mt(S,"id",v,z);E.ID=`${L.set}::${y}`,E.size=L.size??o.pointSize??2.5;const D=k(S,"shape");D&&String(D)!=="NA"&&(E.shape=String(D));const W=k(S,"label");E.meta={stroke:"#ffffff",kind:"point",name:W!=null&&String(W)!=="NA"?String(W):y,group:P??void 0,unit:y,set:L.set,fixedSize:L.fixedSize},this.__data__.points.set(E.ID,E),I==null||I.__data__.objects.set(E.ID,E),Gt.push({pt:E,spec:qe(S,y),mode:L.labelMode,weight:L.labelWeight})})})}if(et){const I=new Set(Gt.map(k=>k.pt.ID));this._setLabels.forEach((k,L)=>{I.has(L)||(k.remove(),this._setLabels.delete(L))}),Gt.forEach(k=>this._syncLabel(this._setLabels,k.pt.ID,k.spec,k.pt,et,k.mode,k.weight))}if((ri=s.points)!=null&&ri.rows){const I=this.__children__.search("__children__","points");if(I){s.points.rows().forEach(N=>{const S=h?N.names.indexOf(h):-1,y=S>=0?String(N[S]):null,P=y?_[y]??"#888888":"#888888";if(Tt){const v=mt(N,r,P,z);v.size=o.pointSize??2.5,v.meta={...v.meta??{},stroke:"#ffffff",kind:"point",name:v.ID,group:y??void 0,unit:v.ID,fixedSize:o.pointFixedSize},this.__data__.points.set(v.ID,v),I.__data__.objects.set(v.ID,v)}if(y){const v=N.names.indexOf(n[0]),E=n.length>1?N.names.indexOf(n[1]):-1;Q[y]||(Q[y]={x:0,y:0,x2:0,y2:0,xy:0,n:0,color:P});const D=v>=0?Number(N[v]):0,W=E>=0?Number(N[E]):0;Q[y].x+=D,Q[y].y+=W,Q[y].x2+=D*D,Q[y].y2+=W*W,Q[y].xy+=D*W,Q[y].n+=1}});const k=!!((oi=s.groups)!=null&&oi.rows&&s.groups.rows().length>0),L=o.showMeans&&k?s.groups.rows().filter(N=>{const S=N.rowName??String(N[0]);return u.size===0||u.has(S)}):[];if(o.showMeans){const N=I.svg_element,S=this._rangeExtent?this._rangeExtent/1.2:b,y=(S>0?S:1)*.008;if(k){const P=new Set(L.map(v=>v.rowName??String(v[0])));this._ciRects.forEach((v,E)=>{P.has(E)||(v.remove(),this._ciRects.delete(E))}),this._outlierRects.forEach((v,E)=>{P.has(E)||(v.remove(),this._outlierRects.delete(E))}),this._ciCross.forEach((v,E)=>{P.has(E.slice(2))||(v.remove(),this._ciCross.delete(E))}),L.forEach(v=>{var ss,re,Ut;const E=v.rowName??String(v[0]),D=_[E]??"#888888",W=v.names.indexOf(n[0]),G=n.length>1?v.names.indexOf(n[1]):-1,V=W>=0?Number(v[W])*z:0,vt=G>=0?-Number(v[G])*z:0,H=new J({ID:`mean-${E}`,dimensions:[V,vt],meta:{kind:"mean",name:E,group:E,fixedSize:o.meanFixedSize}});H.color=new tt(D),H.size=4;const ht=v.names.indexOf("shape"),$=ht>=0?v[ht]:null;H.shape=$&&String($)!=="NA"?String($):"rect",this.__data__.points.set(H.ID,H),I.__data__.objects.set(H.ID,H);const ie=c(Y=>{const x=v.names.indexOf(Y),A=x>=0?v[x]:null;return A==null||String(A)==="NA"||String(A)===""?null:A},"cell"),pt=ie("intervals"),zt=pt==="box"||pt==="crosshairs"||pt==="none"?pt:o.intervals,Bt=ie("outlier"),B=(Bt==null?o.showOutlier:Bt===!0||String(Bt)==="true")?Ye(v,n[0],n[1],"o"):null;if(!B)(ss=this._outlierRects.get(E))==null||ss.remove(),this._outlierRects.delete(E);else{let Y=this._outlierRects.get(E);Y||(Y=document.createElementNS("http://www.w3.org/2000/svg","rect"),Y.setAttribute("data-outlier-group",E),this._outlierRects.set(E,Y)),Y.setAttribute("x",(B.x_low*z).toString()),Y.setAttribute("y",(-B.y_high*z).toString()),Y.setAttribute("width",((B.x_high-B.x_low)*z).toString()),Y.setAttribute("height",((B.y_high-B.y_low)*z).toString()),Y.setAttribute("fill","none"),Y.setAttribute("stroke",D),Y.setAttribute("stroke-width",y.toString()),Y.setAttribute("stroke-opacity","0.5"),Y.setAttribute("stroke-dasharray",`${y*2} ${y*2}`),this._intervalStroke(Y,y,[y*2,y*2]),N&&!Y.parentElement&&N.insertBefore(Y,N.firstChild)}const ot=zt!=="none"?Ye(v,n[0],n[1]):null,ne=`x:${E}`;if((!ot||zt!=="crosshairs")&&((re=this._ciCross.get(ne))==null||re.remove(),this._ciCross.delete(ne)),ot&&zt==="crosshairs"){(Ut=this._ciRects.get(E))==null||Ut.remove(),this._ciRects.delete(E);const Y=ot.x_low*z,x=ot.x_high*z,A=-ot.y_high*z,C=-ot.y_low*z;je(H,(x-Y)/2,(C-A)/2);let M=this._ciCross.get(ne);M||(M=document.createElementNS("http://www.w3.org/2000/svg","path"),M.setAttribute("data-ci-group",E),M.setAttribute("data-ci-kind","crosshairs"),this._ciCross.set(ne,M)),M.setAttribute("d",`M${Y} ${vt} L${x} ${vt} M${V} ${A} L${V} ${C}`),M.setAttribute("fill","none"),M.setAttribute("stroke",D),M.setAttribute("stroke-width",(y*1.25).toString()),this._intervalStroke(M,y*1.25,null),M.setAttribute("stroke-opacity","0.8"),N&&!M.parentElement&&N.insertBefore(M,N.firstChild)}else if(ot){const Y=ot.x_low*z,x=-ot.y_high*z,A=(ot.x_high-ot.x_low)*z,C=(ot.y_high-ot.y_low)*z;je(H,A/2,C/2);let M=this._ciRects.get(E);M||(M=document.createElementNS("http://www.w3.org/2000/svg","rect"),M.setAttribute("data-ci-group",E),this._ciRects.set(E,M)),M.setAttribute("x",Y.toString()),M.setAttribute("y",x.toString()),M.setAttribute("width",A.toString()),M.setAttribute("height",C.toString()),M.setAttribute("fill","none"),M.setAttribute("stroke",D),M.setAttribute("stroke-width",y.toString()),M.setAttribute("stroke-opacity","0.8"),M.setAttribute("stroke-dasharray",`${y*4} ${y*3}`),this._intervalStroke(M,y,[y*4,y*3]),N&&!M.parentElement&&N.insertBefore(M,N.firstChild)}else{const Y=this._ciRects.get(E);Y&&(Y.remove(),this._ciRects.delete(E))}})}else this._removeIntervals(this._ciCross),Object.entries(Q).forEach(([v,{x:E,y:D,n:W,color:G}])=>{const V=new J({ID:`mean-${v}`,dimensions:[E/W*z,-(D/W)*z],meta:{kind:"mean",name:v,group:v,fixedSize:o.meanFixedSize}});V.color=new tt(G),V.size=4,V.shape="rect",this.__data__.points.set(V.ID,V),I.__data__.objects.set(V.ID,V)}),o.showCI?(this._ciRects.forEach((v,E)=>{Q[E]||(v.remove(),this._ciRects.delete(E))}),(ai=s.confidence)!=null&&ai.rows?s.confidence.rows().forEach(v=>{const E=v.names.indexOf(h??"group"),D=E>=0?String(v[E]):v.rowName??null;if(!D)return;const W=_[D]??"#888888",G=Ye(v,n[0],n[1]);if(!G)return;const V=G.x_low*z,vt=-G.y_high*z,H=(G.x_high-G.x_low)*z,ht=(G.y_high-G.y_low)*z;je(this.__data__.points.get(`mean-${D}`),H/2,ht/2);let $=this._ciRects.get(D);$||($=document.createElementNS("http://www.w3.org/2000/svg","rect"),$.setAttribute("data-ci-group",D),this._ciRects.set(D,$)),$.setAttribute("x",V.toString()),$.setAttribute("y",vt.toString()),$.setAttribute("width",H.toString()),$.setAttribute("height",ht.toString()),$.setAttribute("fill","none"),$.setAttribute("stroke",W),$.setAttribute("stroke-width",y.toString()),$.setAttribute("stroke-opacity","0.8"),$.setAttribute("stroke-dasharray",`${y*4} ${y*3}`),this._intervalStroke($,y,[y*4,y*3]),N&&!$.parentElement&&N.insertBefore($,N.firstChild)}):Object.entries(Q).forEach(([v,{x:E,y:D,x2:W,y2:G,n:V,color:vt}])=>{if(V<2)return;const H=E/V,ht=D/V,$=W/V-H*H,ie=G/V-ht*ht,{halfW:pt,halfH:zt}=$i($,ie,V,z),Bt=H*z,Oe=-ht*z;je(this.__data__.points.get(`mean-${v}`),pt,zt);let B=this._ciRects.get(v);B||(B=document.createElementNS("http://www.w3.org/2000/svg","rect"),B.setAttribute("data-ci-group",v),this._ciRects.set(v,B)),B.setAttribute("x",(Bt-pt).toString()),B.setAttribute("y",(Oe-zt).toString()),B.setAttribute("width",(pt*2).toString()),B.setAttribute("height",(zt*2).toString()),B.setAttribute("fill","none"),B.setAttribute("stroke",vt),B.setAttribute("stroke-width",y.toString()),B.setAttribute("stroke-opacity","0.8"),B.setAttribute("stroke-dasharray",`${y*4} ${y*3}`),this._intervalStroke(B,y,[y*4,y*3]),N&&!B.parentElement&&N.insertBefore(B,N.firstChild)})):this._removeIntervals(this._ciRects),(hi=s.outlier)!=null&&hi.rows?(this._outlierRects.forEach((v,E)=>{_[E]||(v.remove(),this._outlierRects.delete(E))}),s.outlier.rows().forEach(v=>{const E=v.names.indexOf(h??"group"),D=E>=0?String(v[E]):v.rowName??null;if(!D)return;const W=_[D]??"#888888",G=Ye(v,n[0],n[1]);if(!G)return;const V=G.x_low*z,vt=-G.y_high*z,H=(G.x_high-G.x_low)*z,ht=(G.y_high-G.y_low)*z;let $=this._outlierRects.get(D);$||($=document.createElementNS("http://www.w3.org/2000/svg","rect"),$.setAttribute("data-outlier-group",D),this._outlierRects.set(D,$)),$.setAttribute("x",V.toString()),$.setAttribute("y",vt.toString()),$.setAttribute("width",H.toString()),$.setAttribute("height",ht.toString()),$.setAttribute("fill","none"),$.setAttribute("stroke",W),$.setAttribute("stroke-width",y.toString()),$.setAttribute("stroke-opacity","0.5"),$.setAttribute("stroke-dasharray",`${y*2} ${y*2}`),this._intervalStroke($,y,[y*2,y*2]),N&&!$.parentElement&&N.insertBefore($,N.firstChild)})):this._removeIntervals(this._outlierRects)}else[this._ciRects,this._outlierRects,this._ciCross].forEach(N=>this._removeIntervals(N));if(et){this._pointLabels.forEach((y,P)=>{I.__data__.objects.get(P)||(y.remove(),this._pointLabels.delete(P))}),this._meanLabels.forEach((y,P)=>{I.__data__.objects.get(`mean-${P}`)||(y.remove(),this._meanLabels.delete(P))}),gt!==0?s.points.rows().forEach(y=>{const P=y.names.indexOf(r),v=P>=0?String(y[P]):null;if(!v)return;const E=I.__data__.objects.get(v);E&&this._syncLabel(this._pointLabels,v,qe(null,v),E,et,gt,o.labelWeightPoints)}):this._clearLabels(this._pointLabels);const N=new Map(L.map(y=>[y.rowName??String(y[0]),y]));(k?[...N.keys()]:Object.keys(Q)).forEach(y=>{const P=`mean-${y}`,v=I.__data__.objects.get(P);v&&this._syncLabel(this._meanLabels,y,qe(N.get(y),y),v,et,dt,o.labelWeightMeans)})}I.__data__.__state__.setVariable("layer_updated",I.__data__)}}else{const I=this.__children__.search("__children__","points");I==null||I.__data__.__state__.setVariable("layer_updated",I.__data__)}const Nt=this.__children__.search("__children__","trajectories");if(o.showTrajectories&&Nt){Nt.__data__.objects.clear(),this.__data__.trajectories.clear();const I=(li=s.trajectories)!=null&&li.rows?s.trajectories:s.points;if(I!=null&&I.rows){const k={},L=o.trajectoryUnits?o.trajectoryUnits.split(",").map(S=>S.trim()):null;I.rows().forEach(S=>{const y=S.names.indexOf(r)>=0?S.names.indexOf(r):S.names.indexOf("unit")>=0?S.names.indexOf("unit"):S.names.indexOf("ENA_UNIT")>=0?S.names.indexOf("ENA_UNIT"):-1,P=y>=0?String(S[y]):S.rowName||"unit-1";if(L&&!L.includes(P))return;const v=S.names.indexOf(n[0]),E=n.length>1?S.names.indexOf(n[1]):-1,D=S.names.indexOf("time")>=0?S.names.indexOf("time"):S.names.indexOf("ActivityNumber")>=0?S.names.indexOf("ActivityNumber"):S.names.indexOf("RowID")>=0?S.names.indexOf("RowID"):-1,W=D>=0?Number(S[D]):k[P]?k[P].length+1:1;v>=0&&E>=0&&(k[P]||(k[P]=[]),k[P].push({x:Number(S[v])*z,y:-Number(S[E])*z,time:W}))}),Object.keys(k).forEach((S,y)=>{const P=k[S];if(P.length===0)return;const v=g[y%g.length],E=new ce({ID:`traj-${S}`,unitId:S,color:new tt(v),lineStyle:o.trajectoryLineStyle,strokeWidth:o.trajectoryStrokeWidth,strokeWidthRange:o.trajectoryStrokeWidthRange,opacityRange:o.trajectoryOpacityRange,smooth:o.trajectorySmooth,maxDegree:o.trajectoryMaxDegree,degreeSelection:o.trajectoryDegreeSelection,currentTime:o.trajectoryPlayhead??1/0,showPoints:o.trajectoryShowPoints,showTips:o.trajectoryShowTips,points:P.map(D=>({x:D.x,y:D.y,time:D.time}))});this.__data__.trajectories.set(S,E),Nt.__data__.objects.set(E.ID,E)})}Nt.__data__.__state__.setVariable("layer_updated",Nt.__data__)}const kt=this.__children__.search("__children__","network"),es=kt==null?void 0:kt.__children__.search("__children__","edges"),rt=kt==null?void 0:kt.__children__.search("__children__","nodes"),Hs=kt==null?void 0:kt.__children__.search("__children__","edgenodes"),Bi=o.showEdges;if((ci=s.nodes)!=null&&ci.rows&&rt){if(s.nodes.rows().forEach(k=>{const L=mt(k,a,"#444444");L.size=2;const N=k.names.indexOf("label"),S=N>=0?k[N]:null,y=k.names.indexOf("size"),P=y>=0&&k[y]!=null&&k[y]!==""?Number(k[y]):NaN;L.meta={...L.meta??{},kind:"node",name:S!=null&&String(S)!=="NA"&&String(S)!==""?String(S):L.ID,sizePx:Number.isFinite(P)&&P>0?P:void 0,zoomFixed:o.nodeFixedSize||void 0},rt.__data__.objects.set(L.ID,L)}),Bi&&es){const k={};h&&((_i=s.points)!=null&&_i.rows)&&s.points.rows().forEach(x=>{const A=x.names.indexOf(r),C=x.names.indexOf(h);A>=0&&C>=0&&(k[String(x[A])]=String(x[C]))});const L=s.nodes.rows().map(x=>{const A=x.names.indexOf(a);return A>=0?String(x[A]):""}).filter(Boolean),N=c(x=>{const A=[];return x.forEach(C=>{const M=Ri(C,L);M&&A.push({col:C,pair:M})}),A},"parsePairs"),S=(ui=s.edges)!=null&&ui.rows?s.edges.rows():[],y=s.networks,P=N(((di=s.edges)==null?void 0:di.names)??[]),v=N((y==null?void 0:y.names)??[]),E=c(x=>{const A={};return S.forEach(C=>{const M=C.names.indexOf(r);M<0||String(C[M])!==x||P.forEach(({col:F})=>{const Z=C.names.indexOf(F);Z>=0&&(A[F]=Number(C[Z])||0)})}),A},"getUnitEdges"),D=c(x=>{const A={};let C=0;if(S.forEach(F=>{const Z=F.names.indexOf(r),ft=Z>=0?String(F[Z]):null,bt=h?F.names.indexOf(h):-1;(bt>=0?String(F[bt]):ft?k[ft]:null)===x&&(C++,P.forEach(({col:At})=>{const yt=F.names.indexOf(At);if(yt>=0){const K=Number(F[yt]);isNaN(K)||(A[At]=(A[At]??0)+K)}}))}),C===0)return{};const M={};return P.forEach(({col:F})=>{M[F]=(A[F]??0)/C}),M},"getGroupEdges"),W=c(x=>{if(_[x])return{weights:D(x),color:_[x],label:x};const A=k[x]??null,C=A?_[A]??"#888888":"#888888";return{weights:E(x),color:C,label:x}},"resolve"),G=[],V=c(x=>{var M;const A=(M=y==null?void 0:y.rows)==null?void 0:M.call(y).find(F=>F.rowName===x);if(!A)return null;const C={};return v.forEach(({col:F})=>{const Z=A.names.indexOf(F);if(Z>=0){const ft=Number(A[Z]);Number.isFinite(ft)&&(C[F]=ft)}}),C},"networkRow"),vt=c((x,A)=>{if(!A)return x;const C=Math.abs(x);return C<A[0]?0:C>A[1]?Math.sign(x)*A[1]:x},"thresholded");o.edgeLayers.forEach((x,A)=>{const C=c((K,lt,st,Et,ct)=>{st=vt(st,x.threshold),!(Math.abs(st)<1e-6)&&G.push({col:`${A}:${K}`,pair:lt,weight:Math.abs(st),color:Et,layer:A,...ct})},"push"),M=c((K,lt)=>x.colors?[x.colors[0],x.colors[1]??ji(x.colors[0])]:[K,lt],"signColors");if(x.network){const K=V(x.network);if(!K)return;const[lt,st]=M(g[0],g[1]),Et={name:x.name??x.network};v.forEach(({col:ct,pair:gi})=>{const Pe=K[ct]??0;C(ct,gi,Pe,Pe>=0?lt:st,Et)});return}const F=x.unit??x.group??null;if(!F)return;const Z=W(F),ft=x.compare??x.also??null,bt=ft?W(ft):null,Ct={name:x.name??F,group:x.group??void 0,unit:x.unit??void 0},[At,yt]=M(Z.color,(bt==null?void 0:bt.color)??Z.color);bt&&x.compare?P.forEach(({col:K,pair:lt})=>{const st=(Z.weights[K]??0)-(bt.weights[K]??0);C(K,lt,st,st>0?At:yt,Ct)}):bt&&x.also?P.forEach(({col:K,pair:lt})=>{const st=Z.weights[K]??0,Et=bt.weights[K]??0;st>0&&C(K+"-a",lt,st,At,Ct),Et>0&&C(K+"-b",lt,Et,yt,{...Ct,name:x.also??void 0,group:x.also??void 0})}):P.forEach(({col:K,pair:lt})=>{const st=Z.weights[K]??0;st>0&&C(K,lt,st,At,Ct)})}),G.sort((x,A)=>A.weight-x.weight);const H=!!s.directed,ht=zi(o.edgeWidth)*(o.edgeMagnify??1),$=c(x=>{const A=x.map(Math.abs).filter(C=>C>0);return A.length?[Math.min(...A),Math.max(...A)]:[0,0]},"rangeOf"),[ie,pt]=S.length?[P,s.edges]:[v,y],zt=c(x=>{const A=[];return ie.forEach(({col:C,pair:M})=>{if(M[0]===M[1]!==x)return;const F=pt==null?void 0:pt.col(C);if(F)for(const Z of F)A.push(Number(Z))}),$(A)},"modelRange"),Bt=c(x=>$(G.filter(A=>A.pair[0]===A.pair[1]===x).map(A=>A.weight)),"plotRange"),Oe=o.edgeColorScale,B=c(x=>Oe==="plot"?Bt(x):zt(x),"colourRange"),ot=B(!1),ne=B(!0),ss=c((x,A)=>{if(Oe==="absolute"){const F=Math.min(1,Math.abs(x));return{saturation:F,opacity:F}}const[C,M]=A?ne:ot;return{saturation:Bs(x,C,M,Ai),opacity:Bs(x,C,M,Si)}},"colourOf"),re={};G.forEach(({pair:x,weight:A})=>{if(x[0]===x[1]&&!H)return;const M=c(F=>{re[F]=(re[F]??0)+Math.abs(A)},"add");if(H){M(x[1]);return}M(x[0]),M(x[1])}),s.nodes.rows().forEach(x=>{var ft;const A=x.names.indexOf(a),C=A>=0?String(x[A]):"";if(!C)return;const M=rt.__data__.objects.get(C);if(!M)return;const F=re[C]??0,Z=!(F>0);M.size=Z?o.hideUnconnectedNodes?0:ki:Ci(F,ht),M.meta={...M.meta??{},hidden:Z&&o.hideUnconnectedNodes,sizePx:Z||(ft=M.meta)==null?void 0:ft.sizePx}});const Ut={},Y=c((x,A,C,M)=>`${x}:${A??""}:${C}.${M}`,"pairKey");H&&G.forEach(({pair:x,weight:A,layer:C,name:M})=>{const F=Y(C,M,x[0],x[1]);Ut[F]=(Ut[F]??0)+A}),G.forEach(({col:x,pair:A,weight:C,color:M,layer:F,name:Z,group:ft,unit:bt})=>{var Pe,mi;const Ct=rt.__data__.objects.get(A[0]),At=rt.__data__.objects.get(A[1]);if(!Ct||!At)return;const yt=A[0]===A[1];if(yt&&!H)return;const{saturation:K,opacity:lt}=ss(C,yt),st=new J({ID:`${A[0]}-src`,dimensions:[Ct.x,Ct.y],meta:{}}),Et=new J({ID:`${A[1]}-dst`,dimensions:[At.x,At.y],meta:{}});let ct;if(yt)ct=new Vt({},st,Et),ct.weight=0;else if(H){const Ui=Ut[Y(F,Z,A[0],A[1])]??C,Xi=Ut[Y(F,Z,A[1],A[0])]??0,Wi=Ui+Xi;ct=new cs({weight:C,totalweight:Wi},st,Et)}else ct=new Ht({},st,Et);ct.ID=`edge-${x}`,ct.color=new tt(M),ct.meta={isMeanEdge:!0,weight:C,widthFrac:ht,saturation:K,opacity:lt,isDirected:H,isSelf:yt,source:A[0],target:A[1],group:ft,unit:bt,layer:Z,selfSize:yt?((Pe=o.edgeLayers[F])==null?void 0:Pe.selfSize)??void 0:void 0,fixedSize:((mi=o.edgeLayers[F])==null?void 0:mi.fixedSize)||void 0},(yt?Hs??es:es).__data__.objects.set(ct.ID,ct)})}const I=o.showNodes;rt.svg_element&&(rt.svg_element.style.display=I?"":"none"),I||this._clearLabels(this._nodeLabels),et&&I&&(this._nodeLabels.forEach((k,L)=>{rt.__data__.objects.get(L)||(k.remove(),this._nodeLabels.delete(L))}),s.nodes.rows().forEach(k=>{var y,P,v;const L=k.names.indexOf(a),N=L>=0?String(k[L]):"";if(!N)return;const S=rt.__data__.objects.get(N);if(S){if((y=S.meta)!=null&&y.hidden){(P=this._nodeLabels.get(N))==null||P.remove(),this._nodeLabels.delete(N);return}this._syncLabel(this._nodeLabels,N,qe(k,String(((v=S.meta)==null?void 0:v.name)??N)),S,et,j,o.labelWeightNodes)}})),rt.__data__.__state__.setVariable("layer_updated",rt.__data__)}else rt==null||rt.__data__.__state__.setVariable("layer_updated",rt.__data__);[es,Hs].forEach(I=>I==null?void 0:I.__data__.__state__.setVariable("layer_updated",I.__data__));const Vs=this.__children__.search("__children__","axis_points"),Zs=this.__children__.search("__children__","axis_lines");Vs&&this.__data__.__state__.setVariable("graph_updated_axis_points",Vs.__data__.objects),Zs&&this.__data__.__state__.setVariable("graph_updated_axis_lines",Zs.__data__.objects),this.update(),i&&this._startTween(i)})}static get observedAttributes(){return["width","height","for","scale-points","point-scale","center","view-padding","labels","label-nodes","label-means","label-points"]}get vizena(){return this._vizena}_viewPadding(){const t=Number(this.getAttribute("view-padding"));return this.hasAttribute("view-padding")&&Number.isFinite(t)&&t>0?t:1.2}unitsPerPixel(){var i,n;const t=this.__data__.extremes.x_max||1,e=(n=(i=this.svg_element)==null?void 0:i.getBoundingClientRect)==null?void 0:n.call(i),s=this.zoom_level||1;return e&&e.width>0?2*t/e.width/s:t*.004}_syncLabel(t,e,s,i,n,r,a){let h=t.get(e);const o=s.text!=null&&(r!==q.DISPLAY_TYPES.OFF||s.pinned);h&&(!o||h.text!==s.text||h.displayMode!==r)&&(h.remove(),t.delete(e),h=void 0),o&&(h?(h.setPoint(i),r===q.DISPLAY_TYPES.ON&&h.show()):(h=new _s(s.text,i,n,this,r),t.set(e,h)),s.offset&&h.setOffset(s.offset.x,s.offset.y),h.fontWeight=a,h.setHostPinned(s.pinned))}_nodeRadius(t){const e=this.__children__.search("__children__","nodes"),s=e==null?void 0:e.__children__.find(i=>{var n;return((n=i.__data__)==null?void 0:n.ID)===t});return s?s.computeRadius():null}_intervalStroke(t,e,s){this._intervalBase.set(t,{w:e,dash:s}),this._applyIntervalStroke(t)}_applyIntervalStroke(t){const e=this._intervalBase.get(t);if(!e)return;const s=this._meansFixedSize&&this.zoom_level||1;t.setAttribute("stroke-width",String(e.w/s)),e.dash&&t.setAttribute("stroke-dasharray",e.dash.map(i=>i/s).join(" "))}_removeIntervals(t){t.forEach(e=>e.remove()),t.clear()}_clearLabels(t){t.forEach(e=>e.remove()),t.clear()}_scheduleRerender(){!this._vizena||!this._hasModel||this._renderPending||(this._renderPending=!0,queueMicrotask(()=>{var t;this._renderPending&&(this._renderPending=!1,(t=this._vizena)==null||t.dispatchEvent(new CustomEvent("model-updated",{detail:this._vizena.model,bubbles:!0,composed:!0})))}))}_readLayerConfig(){var p;const t=this.querySelector("qe-nodes"),e=this.querySelector("qe-means"),s=[...this.querySelectorAll("qe-points")],i=s.find(u=>!u.hasAttribute("set"))??null,n=s.filter(u=>u.hasAttribute("set")),r=[...this.querySelectorAll("qe-edges")],a=c(u=>{var d;return((d=r.find(l=>l.hasAttribute(u)))==null?void 0:d.getAttribute(u))??null},"firstAttr"),h=r.find(u=>u.hasAttribute("magnify")),o=this.querySelector("qe-trajectories"),_=this.querySelector("qe-axes"),g=this.getAttribute("labels");return{labelNodes:Ge((t==null?void 0:t.getAttribute("label"))??this.getAttribute("label-nodes")??g,q.DISPLAY_TYPES.ON),labelWeightNodes:(t==null?void 0:t.getAttribute("label-font-weight"))||null,nodeFixedSize:!!t&&t.hasAttribute("fixed-size"),showNodes:!!t,range:(()=>{const u=this.getAttribute("range");if(u==="network"||u==="points")return u;const d=Number(u);return u!=null&&Number.isFinite(d)&&d>0?d:null})(),plotTitle:this.getAttribute("plot-title")||null,labelFont:{size:(()=>{const u=Number(this.getAttribute("label-font-size"));return Number.isFinite(u)&&u>0?u:null})(),family:this.getAttribute("label-font-family")||null,color:this.getAttribute("label-font-color")||null},edgeWidth:(()=>{const u=Number(this.getAttribute("edge-width"));return Number.isFinite(u)&&u>0&&u<=1?u:vi})(),hideUnconnectedNodes:((p=t==null?void 0:t.getAttribute("unconnected"))==null?void 0:p.toLowerCase())==="hide",scalePoints:this.getAttribute("scale-points")!=="false",pointScale:(()=>{const u=Number(this.getAttribute("point-scale"));return this.hasAttribute("point-scale")&&Number.isFinite(u)&&u>0?u:null})(),centerContent:this.getAttribute("center")==="content",showMeans:!!e,activeMeanGroups:(e==null?void 0:e.getAttribute("groups"))??null,showCI:!!e&&e.hasAttribute("confidence"),intervals:(()=>{const u=e==null?void 0:e.getAttribute("intervals");return u==="box"||u==="crosshairs"||u==="none"?u:e!=null&&e.hasAttribute("confidence")?"box":"none"})(),showOutlier:!!e&&e.hasAttribute("outlier"),labelMeans:Ge((e==null?void 0:e.getAttribute("label"))??this.getAttribute("label-means")??g,q.DISPLAY_TYPES.ON),labelWeightMeans:(e==null?void 0:e.getAttribute("label-font-weight"))||null,meanFixedSize:!!e&&e.hasAttribute("fixed-size"),showPoints:!!i,pointSets:n.map(u=>({set:u.getAttribute("set"),size:u.getAttribute("size")?parseFloat(u.getAttribute("size")):null,fixedSize:u.hasAttribute("fixed-size"),labelMode:Ge(u.getAttribute("label")??this.getAttribute("label-points")??g,q.DISPLAY_TYPES.OFF),labelWeight:u.getAttribute("label-font-weight")||null})),labelPoints:Ge((i==null?void 0:i.getAttribute("label"))??this.getAttribute("label-points")??g,q.DISPLAY_TYPES.OFF),labelWeightPoints:(i==null?void 0:i.getAttribute("label-font-weight"))||null,pointSize:i!=null&&i.getAttribute("size")?parseFloat(i.getAttribute("size")):null,pointFixedSize:!!i&&i.hasAttribute("fixed-size"),showEdges:r.length>0,edgeLayers:r.map(Di),edgeColorScale:Yi(a("color-scale")),edgeMagnify:h?(()=>{const u=Number(h.getAttribute("magnify"));return Number.isFinite(u)&&u>0?u:1})():null,showTrajectories:!!o,trajectoryUnits:(o==null?void 0:o.getAttribute("units"))??null,trajectorySmooth:(o==null?void 0:o.getAttribute("smooth"))??"none",trajectoryMaxDegree:o!=null&&o.getAttribute("max-degree")?parseInt(o.getAttribute("max-degree"),10):3,trajectoryDegreeSelection:(o==null?void 0:o.getAttribute("degree-selection"))??"loocv_2d",trajectoryShowPoints:(o==null?void 0:o.getAttribute("points"))!=="false",trajectoryShowTips:(o==null?void 0:o.getAttribute("tips"))!=="false",trajectoryPlayhead:o!=null&&o.getAttribute("playhead")?parseFloat(o.getAttribute("playhead")):null,trajectoryLineStyle:(o==null?void 0:o.getAttribute("line-style"))??"uniform",trajectoryStrokeWidth:o!=null&&o.getAttribute("stroke-width")?parseFloat(o.getAttribute("stroke-width")):2,trajectoryStrokeWidthRange:this._parseNumberPair(o==null?void 0:o.getAttribute("stroke-width-range"),[1,6]),trajectoryOpacityRange:this._parseNumberPair(o==null?void 0:o.getAttribute("opacity-range"),[.3,1]),showAxes:!!_,axesFixedSize:!!_&&_.hasAttribute("fixed-size"),axisXLabel:_!=null&&_.hasAttribute("x")?_.getAttribute("x")??"":null,axisYLabel:_!=null&&_.hasAttribute("y")?_.getAttribute("y")??"":null}}_parseNumberPair(t,e){if(!t)return e;const s=t.split(",").map(i=>Number(i.trim()));return s.length<2||!s.every(Number.isFinite)?e:[s[0],s[1]]}attributeChangedCallback(t,e,s){e!==s&&this._scheduleRerender()}connectedCallback(){var n;const t=this.getAttribute("width"),e=this.getAttribute("height");this.style.display="block",t&&(this.style.width=isNaN(Number(t))?t:`${t}px`),e&&(this.style.height=isNaN(Number(e))?e:`${e}px`),this.appendChild(this.svg_element),it._instances.add(this),this._childObserver=new MutationObserver(()=>this._scheduleRerender()),this._childObserver.observe(this,{childList:!0,attributes:!0,subtree:!0,attributeFilter:["group","unit","compare","also","color-scale","magnify","network","colors","threshold","name","groups","confidence","label","intervals","outlier","set","unconnected","scale-points","point-scale","edge-width","labels","range","center","view-padding","plot-title","label-font-size","label-font-family","label-font-color","label-font-weight","label-nodes","label-means","label-points","self-size","units","smooth","degree","points","tips","playhead","line-style","stroke-width","stroke-width-range","opacity-range","x","y","size","fixed-size"]});const s=this.getAttribute("for");this._vizena=(s?document.getElementById(s):null)??this.closest("qe-visual")??((n=this.parentElement)==null?void 0:n.closest("qe-visual"))??document.querySelector("qe-visual"),this.draw();const i=this.__children__.search("__children__","labels");if(i!=null&&i.svg_element)this._labelsGroup=i.svg_element;else{console.warn("[ena-graph] labels layer not found in layer tree; creating fallback <g>");const r=this.__children__[0];r!=null&&r.svg_element&&(this._labelsGroup=document.createElementNS("http://www.w3.org/2000/svg","g"),this._labelsGroup.setAttribute("data-layer-name","labels-fallback"),r.svg_element.appendChild(this._labelsGroup))}}disconnectedCallback(){var t,e,s;this._stopTween(),(t=this._childObserver)==null||t.disconnect(),this._childObserver=null,(e=this._resizeObs)==null||e.disconnect(),this._resizeObs=null,it._instances.delete(this),(s=this._tooltipEl)==null||s.remove(),this._tooltipEl=null}static instances(){return[...it._instances]}static getGraph(t){for(const e of it._instances)if(e.id===t||e.getAttribute("plot-group")===t)return e;return null}getNodes(){const t=this.__children__.search("__children__","nodes");return t?[...t.__data__.objects.values()].map(e=>{var s;return{id:e.ID,name:((s=e.meta)==null?void 0:s.name)??e.ID,x:e.x,y:e.y}}):[]}getEdges(){const t=c(e=>{const s=this.__children__.search("__children__",e);return s?[...s.__data__.objects.values()]:[]},"collect");return[...t("edges"),...t("edgenodes")].map(e=>{const s=e.meta??{};return{source:s.source,target:s.target,weight:s.weight??0,directed:!!s.isDirected,self:!!s.isSelf}}).filter(e=>e.source!=null&&e.target!=null)}_zoomLimits(){const t=c(e=>{const s=Number(this.getAttribute(e));return this.hasAttribute(e)&&Number.isFinite(s)&&s>0?s:null},"num");return[t("zoom-min")??0,t("zoom-max")??1/0]}_clampZoom(t){const[e,s]=this._zoomLimits();return Math.min(s,Math.max(e,t))}_zoomStep(){const t=Number(this.getAttribute("zoom-step"));return this.hasAttribute("zoom-step")&&Number.isFinite(t)&&t>0?t:1.1}_clientToRoot(t,e){var n,r;const s=(r=(n=this.svg_element).getScreenCTM)==null?void 0:r.call(n);if(!s)return null;const i=new DOMPoint(t,e).matrixTransform(s.inverse());return[i.x,i.y]}_zoomAbout(t,e,s){if(!(Number.isFinite(t)&&t>0))return;t=this._clampZoom(t);const i=this.__data__.transform,n=t/(this.zoom_level||1);i.e=e-n*(e-i.e),i.f=s-n*(s-i.f),i.zoom(t),this.zoom_level=t,this.update()}_stopZoomAnim(){this._zoomAnim!==null&&cancelAnimationFrame(this._zoomAnim),this._zoomAnim=null}_animateZoomAbout(t,e,s,i){this._stopZoomAnim();const n=this.zoom_level||1,r=this._clampZoom(t);if(r===n)return;const a=performance.now(),h=c(o=>{const _=Math.min(1,Math.max(0,(o-a)/i));this._zoomAbout(_>=1?r:n*Math.pow(r/n,1-Math.pow(1-_,3)),e,s),this._zoomAnim=_<1?requestAnimationFrame(h):null},"step");this._zoomAnim=requestAnimationFrame(h)}zoomTo(t){this._stopZoomAnim();const{cx:e,cy:s}=this.__data__.extremes;this._zoomAbout(t,e,s)}zoomBy(t){Number.isFinite(t)&&t>0&&this.zoomTo((this.zoom_level||1)*t)}resetView(){this._stopZoomAnim();const t=this._clampZoom(1),{cx:e,cy:s}=this.__data__.extremes;this.zoom_level=t,this.__data__.transform.values=t===1?[1,0,0,1,0,0]:[t,0,0,t,e*(1-t),s*(1-t)],this.update()}static _ease(t){return t<.5?2*t*t:1-Math.pow(-2*t+2,2)/2}static _setXY(t,e,s){t.x=e,t.y=s,t.dimensions&&(t.dimensions[0]=e,t.dimensions[1]=s)}_layerObjects(t){var e;return(e=this.__children__.search("__children__",t))==null?void 0:e.__data__.objects}_intervalMarks(){return[...this._ciRects.values(),...this._outlierRects.values(),...this._ciCross.values()]}_boxGeom(t){return t.tagName.toLowerCase()==="rect"?["x","y","width","height"].map(e=>parseFloat(t.getAttribute(e)||"0")):((t.getAttribute("d")||"").match(it._PATH_NUM_RE)||[]).map(Number)}_captureTweenState(){var n;const t=new Map;for(const r of["points","nodes"])(n=this._layerObjects(r))==null||n.forEach((a,h)=>t.set(`${r}:${h}`,[a.x,a.y]));const e=new Map;this._intervalMarks().forEach(r=>e.set(r,this._boxGeom(r)));const s=this.__data__.extremes,i=this._tween;return{marks:t,boxes:e,view:[s.x_max,s.y_max,s.cx,s.cy],running:i?{t0:i.t0,k:i.k,marks:new Map(i.marks.map(r=>[r.key,[r.tx,r.ty]])),boxes:new Map(i.boxes.map(r=>[r.el,r.to])),view:i.view.to}:null}}_stopTween(){this._tweenRaf!==null&&cancelAnimationFrame(this._tweenRaf),this._tweenRaf=null,this._tween=null,this._tweenView=null}_startTween(t){var b;const e=performance.now(),s=c((f,w)=>!!w&&f.length===w.length&&f.every((T,z)=>T===w[z]),"same"),i=[];for(const f of["points","nodes"])(b=this._layerObjects(f))==null||b.forEach((w,T)=>{const z=`${f}:${T}`,j=t.marks.get(z);j&&i.push({key:z,o:w,tx:w.x,ty:w.y,cx:j[0],cy:j[1]})});const n=this._intervalMarks().map(f=>({el:f,to:this._boxGeom(f),cur:t.boxes.get(f)})).filter(f=>f.cur&&f.cur.length===f.to.length),r=this.__data__.extremes,a=[r.x_max,r.y_max,r.cx,r.cy],h=t.running,o=!!h&&h.k<.95&&s(a,h.view)&&i.every(f=>s([f.tx,f.ty],h.marks.get(f.key)??[f.cx,f.cy]))&&n.every(f=>s(f.to,h.boxes.get(f.el)??f.cur)),_=o?h.k:0,g=c((f,w)=>_>0?(f-_*w)/(1-_):f,"from"),p=i.map(f=>({key:f.key,o:f.o,tx:f.tx,ty:f.ty,fx:g(f.cx,f.tx),fy:g(f.cy,f.ty)})).filter(f=>f.fx!==f.tx||f.fy!==f.ty),u=n.map(f=>({el:f.el,to:f.to,from:f.cur.map((w,T)=>g(w,f.to[T])),attrs:Object.fromEntries(["x","y","width","height","d"].filter(w=>f.el.hasAttribute(w)).map(w=>[w,f.el.getAttribute(w)]))})).filter(f=>!s(f.from,f.to)),d=t.view.map((f,w)=>g(f,a[w]));if(!p.length&&!u.length&&s(d,a))return;this._tween={t0:o?h.t0:e,dur:this._animateMs,k:_,marks:p,boxes:u,view:{from:d,to:a}},this._tweenFrame(_);const l=c(f=>{const w=this._tween;if(!w)return;const T=(f-w.t0)/w.dur;if(T>=1){this._endTween();return}this._tweenFrame(Math.max(w.k,it._ease(Math.max(0,T)))),this._tweenRaf=requestAnimationFrame(l)},"step");this._tweenRaf=requestAnimationFrame(l)}_tweenFrame(t){const e=this._tween;if(!e)return;e.k=t;const s=c((i,n)=>i+(n-i)*t,"lerp");e.marks.forEach(i=>it._setXY(i.o,s(i.fx,i.tx),s(i.fy,i.ty))),this._attachEdges(),e.boxes.forEach(i=>{const n=i.from.map((r,a)=>s(r,i.to[a]));if("d"in i.attrs){let r=0;i.el.setAttribute("d",i.attrs.d.replace(it._PATH_NUM_RE,()=>String(n[r++])))}else["x","y","width","height"].forEach((r,a)=>i.el.setAttribute(r,String(n[a])))}),this._tweenView=e.view.from.map((i,n)=>s(i,e.view.to[n])),this.update()}_endTween(){const t=this._tween;t&&(t.marks.forEach(e=>it._setXY(e.o,e.tx,e.ty)),this._attachEdges(),t.boxes.forEach(e=>Object.entries(e.attrs).forEach(([s,i])=>e.el.setAttribute(s,i))),this._stopTween(),this.update())}_attachEdges(){var e;const t=this._layerObjects("nodes");if(t)for(const s of["edges","edgenodes"])(e=this._layerObjects(s))==null||e.forEach(i=>{var a,h;const n=t.get((a=i.meta)==null?void 0:a.source),r=t.get((h=i.meta)==null?void 0:h.target);n&&i.from&&it._setXY(i.from,n.x,n.y),r&&i.to&&it._setXY(i.to,r.x,r.y)})}toSVG(){const t=this.svg_element.cloneNode(!0);t.setAttribute("xmlns","http://www.w3.org/2000/svg"),t.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink");const e=this.svg_element.getBoundingClientRect();return e.width&&t.setAttribute("width",String(Math.round(e.width))),e.height&&t.setAttribute("height",String(Math.round(e.height))),new XMLSerializer().serializeToString(t)}toPNG(t=2){const e=this.toSVG(),s=this.svg_element.getBoundingClientRect(),i=Math.max(1,Math.round(s.width)),n=Math.max(1,Math.round(s.height));return new Promise((r,a)=>{const h=new Blob([e],{type:"image/svg+xml;charset=utf-8"}),o=URL.createObjectURL(h),_=new Image;_.onload=()=>{try{const g=document.createElement("canvas");g.width=i*t,g.height=n*t;const p=g.getContext("2d");if(!p){URL.revokeObjectURL(o),a(new Error("no 2d context"));return}p.scale(t,t),p.drawImage(_,0,0,i,n),URL.revokeObjectURL(o),r(g.toDataURL("image/png"))}catch(g){URL.revokeObjectURL(o),a(g)}},_.onerror=g=>{URL.revokeObjectURL(o),a(g)},_.src=o})}getPoints(){const t=this.__children__.search("__children__","points");return t?[...t.__data__.objects.values()].filter(e=>{var s;return((s=e.meta)==null?void 0:s.kind)==="point"}).map(e=>{var s,i,n;return{id:((s=e.meta)==null?void 0:s.unit)??e.ID,group:(i=e.meta)==null?void 0:i.group,set:(n=e.meta)==null?void 0:n.set,x:e.x,y:e.y}}):[]}pointsInRect(t){return this.getPoints().filter(e=>e.x>=t.x&&e.x<=t.x+t.w&&e.y>=t.y&&e.y<=t.y+t.h).map(e=>e.id)}_edgeKey(t,e){return t<=e?`${t}\0${e}`:`${e}\0${t}`}setHighlight(t){this._highlight.edges=new Set((t.edges??[]).map(e=>this._edgeKey(e.source,e.target))),this._highlight.nodes=new Set((t.nodes??[]).map(String)),this._applyHighlights()}clearHighlight(){this._highlight.edges.clear(),this._highlight.nodes.clear(),this._applyHighlights()}_applyHighlights(){var _;if(!this.svg_element)return;this._highlightGroup||(this._highlightGroup=document.createElementNS("http://www.w3.org/2000/svg","g"),this._highlightGroup.setAttribute("data-layer-name","highlight"),this._highlightGroup.setAttribute("pointer-events","none"));const t=this._highlight.edges.size>0||this._highlight.nodes.size>0,e=(_=this.__children__[0])==null?void 0:_.svg_element;(t&&e?e:this.svg_element).appendChild(this._highlightGroup);const s=this._highlightGroup;s.textContent="";const i=this.__data__.extremes.x_max||1,n="#f5a623",r=this.zoom_level||1,a=this._edgesFixedSize?r:1,h=c(g=>{var d;const p=c(l=>{var b;return(b=this.__children__.search("__children__",l))==null?void 0:b.__data__.objects.get(g)},"find"),u=(d=p("nodes")??p("points"))==null?void 0:d.meta;return u!=null&&u.zoomFixed||u!=null&&u.fixedSize?r:1},"markK"),o=c((g,p)=>{const u=document.createElementNS("http://www.w3.org/2000/svg",g);for(const d in p)u.setAttribute(d,String(p[d]));return u},"mk");if(this._highlight.edges.size){const g={};this.getNodes().forEach(p=>{g[p.id]={x:p.x,y:p.y}}),this._highlight.edges.forEach(p=>{const[u,d]=p.split("\0"),l=g[u],b=g[d];!l||!b||s.appendChild(o("line",{x1:l.x,y1:l.y,x2:b.x,y2:b.y,stroke:n,"stroke-width":i*.02/a,"stroke-opacity":.6,"stroke-linecap":"round"}))})}this._highlight.nodes.forEach(g=>{var f;const p=this.svg_element.querySelector(`[data-point-id="${(f=window.CSS)!=null&&f.escape?CSS.escape(g):g}"]`);if(!p)return;const u=p.tagName.toLowerCase();let d,l,b;if(u==="rect"){const w=parseFloat(p.getAttribute("width")||"0");d=parseFloat(p.getAttribute("x")||"0")+w/2,l=parseFloat(p.getAttribute("y")||"0")+parseFloat(p.getAttribute("height")||"0")/2,b=w/2}else d=parseFloat(p.getAttribute("cx")||"0"),l=parseFloat(p.getAttribute("cy")||"0"),b=parseFloat(p.getAttribute("r")||"0");s.appendChild(o("circle",{cx:d,cy:l,r:b*1.7+i*.004/h(g),fill:"none",stroke:n,"stroke-width":i*.006/h(g)}))})}create(){const t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.classList.add("graph"),t.style.display="block",t.style.width="100%",t.style.height="100%",t.setAttribute("preserveAspectRatio","xMidYMid meet"),t.setAttribute("viewBox",this.__data__.extremes.as_viewBox()),t.setAttribute("transform",this.__data__.transform.toString()),t.setAttribute("role","figure"),t.setAttribute("data-graph-size",`${Math.min(this.__data__.extremes.width,this.__data__.extremes.height)}`),this.svg_element=t;const e=document.createElementNS("http://www.w3.org/2000/svg","defs"),s=.22,i=.15,n=c((r,a)=>{const h=document.createElementNS("http://www.w3.org/2000/svg","marker");h.setAttribute("id",r),h.setAttribute("markerWidth",String(s)),h.setAttribute("markerHeight",String(i)),h.setAttribute("refX",String(s)),h.setAttribute("refY",String(i/2)),h.setAttribute("orient","auto"),h.setAttribute("markerUnits","userSpaceOnUse");const o=document.createElementNS("http://www.w3.org/2000/svg","path");o.setAttribute("d",`M0,0 L0,${i} L${s},${i/2} z`),o.setAttribute("fill",a),h.appendChild(o),e.appendChild(h)},"makeArrow");return Ws.forEach(r=>n(`qe-arrow-${r.slice(1)}`,r)),t.appendChild(e),this.__data__.layers.forEach(r=>{const a=new De(r,this.svg_element,this);this.__children__.push(a)}),this.__data__.__state__.setVariable("graph_updated",this.__data__),this.attach_events(),t}attach_events(){const t=c(()=>this.hasAttribute("view-locked"),"locked");this.svg_element.addEventListener("wheel",d=>{if(t())return;d.preventDefault();const l=d.deltaMode===1?33:d.deltaMode===2?this.svg_element.clientHeight||800:1,b=d.deltaY*l,f=d.ctrlKey?Math.exp(-b/100):Math.pow(this._zoomStep(),-b/100);this._stopZoomAnim();const w=this._clientToRoot(d.clientX,d.clientY);w?this._zoomAbout((this.zoom_level||1)*f,w[0],w[1]):this.zoomBy(f)},{passive:!1}),this.svg_element.addEventListener("dblclick",d=>{var b,f;if(t()||(f=(b=d.target)==null?void 0:b.closest)!=null&&f.call(b,"text[data-label-for]"))return;d.preventDefault();const l=this._clientToRoot(d.clientX,d.clientY);l&&this._animateZoomAbout((this.zoom_level||1)*2.2,l[0],l[1],200)});const e=new Map;let s=null;const i=c(()=>{const[d,l]=[...e.values()];return d?l?{mid:[(d[0]+l[0])/2,(d[1]+l[1])/2],dist:Math.hypot(d[0]-l[0],d[1]-l[1]),n:2}:{mid:d,dist:0,n:1}:null},"measure");this.svg_element.addEventListener("pointerdown",d=>{d.pointerType!=="touch"||t()||(e.set(d.pointerId,[d.clientX,d.clientY]),s=i(),this._stopZoomAnim())}),this.svg_element.addEventListener("pointermove",d=>{if(!e.has(d.pointerId))return;if(t()){e.clear(),s=null;return}e.set(d.pointerId,[d.clientX,d.clientY]);const l=i();if(l&&s&&l.n===s.n){const b=this._clientToRoot(...s.mid),f=this._clientToRoot(...l.mid);if(b&&f){const w=this.__data__.transform;w.pan(f[0]-b[0],f[1]-b[1]),l.n===2&&s.dist>0&&l.dist>0?this._zoomAbout((this.zoom_level||1)*l.dist/s.dist,f[0],f[1]):this.__children__[0].svg_element.setAttribute("transform",w.toString())}}s=l});const n=c(d=>{e.delete(d.pointerId)&&(s=i())},"touchEnd");this.svg_element.addEventListener("pointerup",n),this.svg_element.addEventListener("pointercancel",n);let r=!1,a=0,h=0;this.svg_element.addEventListener("mousedown",d=>{t()||(r=!0,a=d.clientX,h=d.clientY)});let o=null,_=null;const g=c(()=>{_&&(this.__data__.transform.pan(_.dx,_.dy),this.__children__[0].svg_element.setAttribute("transform",this.__data__.transform.toString()),_=null),o=null},"panUpdate");this.svg_element.addEventListener("mousemove",d=>{if(!r)return;if(d.buttons===0){r=!1;return}const l=this._clientToRoot(a,h),b=this._clientToRoot(d.clientX,d.clientY);a=d.clientX,h=d.clientY,!(!l||!b)&&(_={dx:((_==null?void 0:_.dx)??0)+b[0]-l[0],dy:((_==null?void 0:_.dy)??0)+b[1]-l[1]},o===null&&(o=requestAnimationFrame(g)))}),this.svg_element.addEventListener("mouseup",d=>{r=!1}),this.svg_element.addEventListener("point-clicked",(d=>{var f,w;const l=(w=(f=d.detail)==null?void 0:f.pointData)==null?void 0:w.ID;if(!l)return;const b=this._pointLabels.get(l)??this._setLabels.get(l)??this._meanLabels.get(l.replace("mean-",""))??this._nodeLabels.get(l);b&&b.displayMode===q.DISPLAY_TYPES.CLICK&&b.toggle()}));const p=c(d=>{var l;for(;d&&d!==this.svg_element;){const b=(l=d.getAttribute)==null?void 0:l.call(d,"data-point-id");if(b)return b;d=d.parentElement}return null},"findPointId"),u=c(d=>this._pointLabels.get(d)??this._setLabels.get(d)??this._meanLabels.get(d.replace(/^mean-/,""))??this._nodeLabels.get(d),"getAutoLabel");this.svg_element.addEventListener("mouseover",d=>{const l=p(d.target);if(!l)return;const b=u(l);(b==null?void 0:b.displayMode)===q.DISPLAY_TYPES.AUTO&&b.show()}),this.svg_element.addEventListener("mouseout",d=>{const l=p(d.target);if(!l)return;const b=d.relatedTarget;if(p(b)===l)return;const w=u(l);(w==null?void 0:w.displayMode)===q.DISPLAY_TYPES.AUTO&&w.hide()}),this._attachInteractionEvents()}_emit(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e,bubbles:!0,composed:!0}))}_closestWith(t,e){var s,i;for(;t&&t!==this.svg_element;){if(((s=t.getAttribute)==null?void 0:s.call(t,e))!=null&&((i=t.hasAttribute)!=null&&i.call(t,e)))return t;t=t.parentElement}return null}_edgeDetail(t){const e=this._closestWith(t,"data-edge-source");if(!e)return null;const s={source:e.getAttribute("data-edge-source"),target:e.getAttribute("data-edge-target"),weight:parseFloat(e.getAttribute("data-edge-weight")||"0"),directed:e.getAttribute("data-edge-directed")==="true",self:e.getAttribute("data-edge-self")==="true"};return e.hasAttribute("data-edge-group")&&(s.group=e.getAttribute("data-edge-group")),e.hasAttribute("data-edge-unit")&&(s.unit=e.getAttribute("data-edge-unit")),s}_nodeDetail(t){const e=this._closestWith(t,"data-point-id");if(!e)return null;const s=e.tagName.toLowerCase();let i,n;s==="rect"?(i=parseFloat(e.getAttribute("x")||"0")+parseFloat(e.getAttribute("width")||"0")/2,n=parseFloat(e.getAttribute("y")||"0")+parseFloat(e.getAttribute("height")||"0")/2):(i=parseFloat(e.getAttribute("cx")||"0"),n=parseFloat(e.getAttribute("cy")||"0"));const r=e.getAttribute("data-point-id"),a={id:r,kind:e.getAttribute("data-kind")||"point",name:e.getAttribute("data-name")||r,x:i,y:n};return e.hasAttribute("data-group")&&(a.group=e.getAttribute("data-group")),e.hasAttribute("data-unit")&&(a.unit=e.getAttribute("data-unit")),a}_attachInteractionEvents(){const t=this.svg_element;t.addEventListener("click",i=>{const n=i.target,r=this._edgeDetail(n);if(r){this._emit("qe-edge-click",{...r,originalEvent:i});return}const a=this._nodeDetail(n);a&&this._emit("qe-node-click",{...a,originalEvent:i})});let e=null;const s=c((i,n)=>i==="edge"?`${n.source}\0${n.target}`:String(n.id),"keyOf");t.addEventListener("mousemove",i=>{const n=i.target,r=this._edgeDetail(n),a=r?null:this._nodeDetail(n),h=r?{type:"edge",detail:r}:a?{type:"node",detail:a}:null,o=h?s(h.type,h.detail):null;e&&(!h||e.key!==o)&&(this._emit(e.type==="edge"?"qe-edge-unhover":"qe-node-unhover",{key:e.key}),e=null),h&&(!e||e.key!==o)&&(this._emit(h.type==="edge"?"qe-edge-hover":"qe-node-hover",{...h.detail,originalEvent:i}),e={type:h.type,key:o}),this.hasAttribute("tooltip")&&h?this._showTooltip(this._tooltipText(h.type,h.detail),i.clientX,i.clientY):this._hideTooltip()}),t.addEventListener("mouseleave",()=>{e&&(this._emit(e.type==="edge"?"qe-edge-unhover":"qe-node-unhover",{key:e.key}),e=null),this._hideTooltip()})}_tooltipText(t,e){if(t==="edge"){const s=Number(e.weight),i=Number.isFinite(s)?` (${+s.toFixed(3)})`:"";return`${e.source} – ${e.target}${i}`}return String(e.name??e.id)}_showTooltip(t,e,s){if(!this._tooltipEl){const i=document.createElement("div");i.setAttribute("data-qe-tooltip",""),Object.assign(i.style,{position:"fixed",zIndex:"2147483647",pointerEvents:"none",background:"rgba(20,20,20,0.92)",color:"#fff",font:"12px/1.4 system-ui, sans-serif",padding:"3px 7px",borderRadius:"4px",whiteSpace:"nowrap",transform:"translate(-50%, calc(-100% - 8px))"}),document.body.appendChild(i),this._tooltipEl=i}this._tooltipEl.textContent=t,this._tooltipEl.style.left=`${e}px`,this._tooltipEl.style.top=`${s}px`,this._tooltipEl.style.display="block"}_hideTooltip(){this._tooltipEl&&(this._tooltipEl.style.display="none")}draw(){var t;if(!this.svg_element){console.error("No element to draw to: ",this);return}if((t=this.wrapper)==null||t.appendChild(this.svg_element),this.__children__.forEach(e=>{e.draw()}),!this._resizeObs&&typeof ResizeObserver<"u"&&this.svg_element){let e=0;this._resizeObs=new ResizeObserver(s=>{var n;const i=((n=s[0])==null?void 0:n.contentRect.width)??0;i>0&&Math.abs(i-e)>.5&&(e=i,this.update_labels(),this.update_axes())}),this._resizeObs.observe(this.svg_element)}}update(){this.update_extremes(),this.update_layers(),[this._ciRects,this._outlierRects,this._ciCross].forEach(t=>t.forEach(e=>this._applyIntervalStroke(e))),this.update_labels(),this.update_extremes(),this.update_axes(),this._applyHighlights()}update_axes(){var g,p;const t=this.__children__.search("__children__","axes");t!=null&&t.svg_element&&(t.svg_element.style.display=this._showAxes?"":"none");const e=this._labelsGroup,s=this.__data__.extremes.x_max,{cx:i,cy:n}=this.__data__.extremes;if(!e||s<=0)return;const r=s*.06,a=r*.6,h=r/(this._axesFixedSize&&this.zoom_level||1),o=h*.6,_=c((u,d)=>{let l=this._axisLabelEls.get(u);if(!this._showAxes||d==null){l&&(l.remove(),this._axisLabelEls.delete(u));return}l||(l=document.createElementNS("http://www.w3.org/2000/svg","text"),l.setAttribute("data-axis-label",u),l.setAttribute("pointer-events","none"),e.appendChild(l),this._axisLabelEls.set(u,l)),l.textContent=d,l.setAttribute("font-size",h.toString()),l.setAttribute("font-family","system-ui, sans-serif"),l.setAttribute("font-weight","600"),l.setAttribute("fill","#556"),u==="x"?(l.setAttribute("x",(i+s-o).toString()),l.setAttribute("y",(-o).toString()),l.setAttribute("text-anchor","end")):(l.setAttribute("x",o.toString()),l.setAttribute("y",(n-s+h+o).toString()),l.setAttribute("text-anchor","start"))},"place");if(_("x",this._axisXText),_("y",this._axisYText),this._magnifyText==null)(g=this._magnifyEl)==null||g.remove(),this._magnifyEl=null;else{this._magnifyEl||(this._magnifyEl=document.createElementNS("http://www.w3.org/2000/svg","text"),this._magnifyEl.setAttribute("data-magnify-label",""),this._magnifyEl.setAttribute("pointer-events","none")),this._magnifyEl.parentElement||e.appendChild(this._magnifyEl);const u=this._magnifyEl;u.textContent=this._magnifyText,u.setAttribute("font-size",(r*.85).toString()),u.setAttribute("font-family","system-ui, sans-serif"),u.setAttribute("font-style","italic"),u.setAttribute("fill","#556"),u.setAttribute("x",(i-s+a).toString()),u.setAttribute("y",(n-s+r+a).toString()),u.setAttribute("text-anchor","start")}if(!this._plotTitle)(p=this._titleEl)==null||p.remove(),this._titleEl=null;else{this._titleEl||(this._titleEl=document.createElementNS("http://www.w3.org/2000/svg","text"),this._titleEl.setAttribute("data-plot-title",""),this._titleEl.setAttribute("pointer-events","none")),this._titleEl.parentElement||e.appendChild(this._titleEl);const d=(this._labelFont.size??12)*1.35*this.unitsPerPixel(),l=this._titleEl;l.textContent=this._plotTitle,l.setAttribute("font-size",d.toString()),l.setAttribute("font-family",this._labelFont.family??"system-ui, sans-serif"),l.setAttribute("font-weight","600"),l.setAttribute("fill",this._labelFont.color??"#223"),l.setAttribute("x",i.toString()),l.setAttribute("y",(n-s+d*1.1).toString()),l.setAttribute("text-anchor","middle")}}update_labels(){this._nodeLabels.forEach(t=>t.update()),this._meanLabels.forEach(t=>t.update()),this._pointLabels.forEach(t=>t.update()),this._setLabels.forEach(t=>t.update())}update_extremes(){var s;const t=this.__data__;if(this._tweenView){const[i,n,r,a]=this._tweenView;t.extremes=new Lt(i,n,r,a)}else if(t.update_extremes(this._centerContent),this._rangeExtent&&this._rangeExtent>0){const{cx:i,cy:n}=t.extremes,r=this._centerContent&&this._rangeMode==="network"?t.nodeExtentFrom(i,n)*1.2:this._rangeExtent;t.extremes=new Lt(r,r,i,n)}const e=(s=this.svg_element)==null?void 0:s.getBoundingClientRect();if(this.svg_element&&e){Xt("SVG rect: ",e);let i,n;e.width===0||e.height===0?(i=1,n=1):(i=e.width,n=e.height),this.__data__.scale_x=1/(i/(4*this.__data__.extremes.x_max)),this.__data__.scale_y=1/(n/(4*this.__data__.extremes.y_max)),this.__children__[0].svg_element.setAttribute("transform",this.__data__.transform.toString()),this.svg_element.setAttribute("viewBox",this.__data__.extremes.as_viewBox(this._viewPadding()));let r=this.__data__.layers.search("layers","axis_lines");if(r){let a=r.objects.get("axis-x"),h=r.objects.get("axis-y");if(a&&h){const o=this.__data__.extremes;a.from=new J({ID:"axis-x-start",dimensions:[o.cx-o.x_max,0],classes:["ena.dimension","ena.dimension"]}),a.to=new J({ID:"axis-x-end",dimensions:[o.cx+o.x_max,0],classes:["ena.dimension","ena.dimension"]}),h.from=new J({ID:"axis-y-start",dimensions:[0,o.cy-o.y_max],classes:["ena.dimension","ena.dimension"]}),h.to=new J({ID:"axis-y-end",dimensions:[0,o.cy+o.y_max],classes:["ena.dimension","ena.dimension"]})}}}}update_layers(){this.__children__.forEach(t=>{t.update()})}};c(it,"QEGraphElement"),it.tagName="qe-graph",it.style=`
19
+ ${$e.style}
20
20
 
21
21
  :host {
22
22
  display: block;
@@ -32,6 +32,26 @@
32
32
  height: 100%;
33
33
  aspect-ratio: 1 / 1;
34
34
  background-color: #FFF;
35
+ /* Touch pans and pinch-zooms the plot, not the page; a double-click
36
+ zooms instead of selecting label text. */
37
+ touch-action: none;
38
+ -webkit-user-select: none;
39
+ user-select: none;
35
40
  }
36
- `,ft._instances=new Set,ft._PATH_NUM_RE=/-?\d*\.?\d+(?:e[-+]?\d+)?/gi;let zt=ft;customElements.define(zt.tagName,zt);const Ci=_(d=>zt.getGraph(d),"getGraph"),Oi=_(()=>zt.instances(),"getGraphs");S.Color=et,S.DataFrame=Lt,S.DataFrameColumn=Ct,S.DataFrameColumnType=dt,S.DataFrameRow=B,S.Edge=re,S.Graph=ke,S.QEAxesElement=fe,S.QEEdgesElement=de,S.QEGraphElement=zt,S.QELayer=Pe,S.QELine=vt,S.QEMeansElement=ue,S.QENodesElement=ce,S.QEPoint=Bt,S.QEPointsElement=_e,S.QETrajectoriesElement=ge,S.QETrajectory=he,S.QEVisualElement=te,S.TRAJECTORY_ZERO_EPS=Ns,S.Trajectory=ne,S.WeightedColor=ee,S.fitTrajectory=Rs,S.getGraph=Ci,S.getGraphs=Oi,S.nearOriginFilter=Qe,S.sampleCurve=ss,S.selectDegree=Ps,S.vizENA=hi,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"})}));
41
+
42
+ /* Marks that emit qe-node-click / qe-edge-click: nodes, means, points,
43
+ edges, their hover lines and self-connection dots. Custom properties
44
+ cross the shadow boundary, so a host can set --qe-mark-cursor on
45
+ <qe-graph>. Labels keep their own grab / grabbing cursor. */
46
+ svg [data-point-id],
47
+ svg [data-edge-source] {
48
+ cursor: var(--qe-mark-cursor, pointer);
49
+ }
50
+
51
+ /* A directed edge's chevron sits on top of its triangle without the
52
+ edge's identity; let clicks and the cursor reach the triangle. */
53
+ svg [data-layer-name="edges"] path:not([data-edge-source]) {
54
+ pointer-events: none;
55
+ }
56
+ `,it._instances=new Set,it._PATH_NUM_RE=/-?\d*\.?\d+(?:e[-+]?\d+)?/gi;let Yt=it;customElements.define(Yt.tagName,Yt);const qi=c(m=>Yt.getGraph(m),"getGraph"),Gi=c(()=>Yt.instances(),"getGraphs");O.Color=tt,O.DataFrame=Ft,O.DataFrameColumn=Ot,O.DataFrameColumnType=_t,O.DataFrameRow=U,O.Edge=_e,O.Graph=Re,O.QEAxesElement=ye,O.QEEdgesElement=pe,O.QEGraphElement=Yt,O.QELayer=De,O.QELine=St,O.QEMeansElement=me,O.QENodesElement=ge,O.QEPoint=Zt,O.QEPointsElement=fe,O.QETrajectoriesElement=be,O.QETrajectory=de,O.QEVisualElement=oe,O.TRAJECTORY_ZERO_EPS=Rs,O.Trajectory=ce,O.WeightedColor=ae,O.fitTrajectory=Ys,O.getGraph=qi,O.getGraphs=Gi,O.nearOriginFilter=os,O.sampleCurve=ls,O.selectDegree=js,O.vizENA=yi,Object.defineProperty(O,Symbol.toStringTag,{value:"Module"})}));
37
57
  //# sourceMappingURL=qeviz.umd.js.map