mascot-vis 4.2.1 → 4.4.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.
@@ -1,2 +1,4 @@
1
- // version: 4.2.1
2
- import*as e from"d3";const t=Object.freeze({Rect:"rect",Circle:"circle",Line:"line",Ring:"ring",Path:"path",Image:"image",SimpleText:"text",RichText:"richText",Arc:"arc",BezierCurve:"bezierCurve",BundledPath:"bundledPath",Chord:"chord",Arrow:"arrow"}),i=Object.freeze({Area:"area",Rect:"rect",Ellipse:"ellipse",Circle:"circle",Pie:"pie",Ring:"ring",Arc:"arc",BezierCurve:"bezierCurve",BundledPath:"bundledPath",Chord:"chord",Line:"line",Path:"path",Image:"image",SimpleText:"text",RichText:"richText",Collection:"collection",Group:"group",Composite:"composite",Scene:"scene",Axis:"axis",Glyph:"glyph",Legend:"legend",Polygon:"polygon",Gridlines:"gridlines",LinearGradient:"LinearGradient",Link:"link",DataTable:"datatable",Layout:"layout",NetworkData:"networkdata",TreeData:"treedata",Arrow:"arrow"}),r=Object.freeze({Axis:"axis",Legend:"legend",Gridlines:"gridlines"});function s(){return Date.now().toString(36)+"_"+Math.random().toString(36).slice(2)}function n(e,t){if(t.has(e))return!0;if(t.tree&&t.tree.nodeTable.has(e.split(".")[1]))return!0;throw new Error(["Attribute",e,"does not exist in the table",t.name].join(" "))}const a=Object.freeze({Boolean:"boolean",Integer:"integer",Number:"number",Date:"date",String:"string"});function o(e){var t=Object.values(a);for(let i=0;i<e.length;i++){let r=e[i];if(null!=r){for(let e=0;e<t.length;e++)l[t[e]](r)||(t.splice(e,1),e-=1);if(1==t.length)return t[0]}}return t[0]}const l={boolean:function(e){return"true"===e||"false"===e||!0===e||!1===e||"[object Boolean]"==toString.call(e)},integer:function(e){return l.number(e)&&(e=+e)===~~e},number:function(e){return!isNaN(+e)&&"[object Date]"!=toString.call(e)},date:function(e){let t=new Date(e);return null!=t&&!isNaN(t)},string:function(e){return!0}};function h(t,i){let r={};switch(i){case a.Boolean:r.trueCount=t.filter(e=>e).length,r.falseCount=t.filter(e=>!e).length;break;case a.Date:r.min=e.min(t),r.max=e.max(t),r.extent=[r.min,r.max],r.unique=[...new Set(t)];break;case a.String:r.unique=[...new Set(t)];break;default:r.min=e.min(t),r.max=e.max(t),r.extent=[r.min,r.max],r.mean=e.mean(t),r.median=e.median(t),r.unique=[...new Set(t)]}return r}const c="max",d="min",u="avg",_="mean",p="median",f="count",g="percentile 25",y="percentile 75";function m(e,t={},i){return{dataTable:e,filters:Object.assign({},t),rowIds:i?i.slice():void 0}}function b(e){if(e)return m(e.dataTable,e.filters,e.rowIds)}function x(e){return b(e)}function v(e){if(e)return e.dataTable}function w(e){return e&&e.filters||{}}function E(e){return e?e.rowIds&&e.dataTable?e.dataTable.rows({[M]:e.rowIds}):e.dataTable?e.dataTable.rows(e.filters):[]:[]}function C(e){let t=E(e);return t.length>0?t[0]:{}}function A(e){return E(e).length}function S(e,t){return t in w(e)}function k(e,t){let i=w(e);if(t in i)return i[t];let r=E(e);return r.length>0?r[0][t]:void 0}function R(e,t){let i=w(e);return t in i?[i[t]]:Array.from(new Set(E(e).map(e=>e[t])))}function T(t,i,r){let s=E(t).map(e=>e[i]);switch(r){case c:return e.max(s);case d:return e.min(s);case u:case _:return e.mean(s);case p:return e.median(s);case f:return s.length;case g:return e.quantile(s,.25);case y:return e.quantile(s,.75);default:return e.sum(s)}}function O(e,t,i){let r=v(e),s=Object.assign({},w(e),{[t]:i});return m(r,s,P(r,s))}function I(e,t){if(!e)return x(t);if(!t)return x(e);let i=v(e),r=Object.assign({},w(e));for(let[e,i]of Object.entries(w(t)))e in r&&r[e]!==i?console.warn("Conflict in attribute values when merging dataScope:",e,r[e],i):r[e]=i;return m(i,r,P(i,r))}function N(e){return m(e,{},e.data.map(e=>e[M]))}function L(e,t,i=!1){let r=v(e),s=w(e),n=Object.entries(s).filter(([e])=>e!==t),a=r._attrValueIndexes.get(t),o=[];for(let e of r.unique(t)){let l=a&&a.get(e)?a.get(e):[];n.length>0&&(l=l.filter(e=>n.every(([t,i])=>e[t]==i))),(i||0!==l.length)&&o.push(m(r,Object.assign({},s,{[t]:e}),l.map(e=>e[M])))}return o}function P(e,t){return e.rows(t).map(e=>e[M])}class V{constructor(e,t,r){this._id=i.DataTable+s(),this.initialize(e,t,r)}initialize(e,t,i){if(this.url=t,this._rawData=JSON.parse(JSON.stringify(e)),this._data=e,this._dataScopeCache=new Map,this._scopeTupleCache=new Map,this._attrValueIndexes=new Map,this._rowIdIndex=new Map,this._dateMap=new Map,this._attributes=0===this._data.length?[]:Object.keys(this._data[0]),this._newAttribute=0,i)this._attrTypes=i;else{this._attrTypes={};for(let e of this._attributes)this._attrTypes[e]=o(this.data.map(t=>t[e])),"year"==e.toLowerCase()&&this._attrTypes[e]==a.Integer&&(this._attrTypes[e]=a.Date)}this._validate(this.data,this._attrTypes),this._attrSummaries={};for(let e of this._attributes)this._attrSummaries[e]=h(this.data.map(t=>t[e]),this._attrTypes[e]);this._attributes.indexOf(M)<0&&this.addAttr(M,a.String,this.data.map((e,t)=>"r"+t)),this._buildAttributeValueIndexes()}clone(){let e=[];for(let t of this._data)e.push(Object.assign({},t));let t=new V(e,this.url,Object.assign({},this._attrTypes));return t.sourceDataTable=this,t}get id(){return this._id}get name(){return this.url?function(e){var t=e.indexOf("\\")>=0?e.lastIndexOf("\\"):e.lastIndexOf("/"),i=e.substring(t);0!==i.indexOf("\\")&&0!==i.indexOf("/")||(i=i.substring(1));return i}(this.url):this.id}get data(){return this._data}encodable(e){switch(e){case"x":case"y":case"width":case"height":case"radius":case"fillColor":case"strokeColor":case"text":return this.measures.concat(this.dimensions);default:return this.measures}}addAttr(e,t,i){this._data.forEach((t,r)=>t[e]=i[r]),e!==M&&this._rawData.forEach((t,r)=>t[e]=i[r]),this._attrTypes[e]=t,this._attributes.includes(e)||this._attributes.push(e),this._attrSummaries[e]=h(i,t),this._clearDataCaches()}type(e){return this._attrTypes[e]}summary(e){return this._attrSummaries[e]}values(e){return this.data.map(t=>t[e])}unique(e){return this._attrSummaries[e].unique}order(e,t){this._attrSummaries[e].unique=t}load(e){this._data=e,this._clearDataCaches(),this.summarize()}rows(e={}){let t=this._getFilterKey(e);if(this._scopeTupleCache.has(t))return this._scopeTupleCache.get(t);let i=Object.entries(e);if(0===i.length)return this._scopeTupleCache.set(t,this.data),this.data;if(1===i.length&&i[0][0]===M&&Array.isArray(i[0][1])){let e=i[0][1].map(e=>this._rowIdIndex.get(e)).filter(e=>e);return this._scopeTupleCache.set(t,e),e}let r=this.data;for(let[e,t]of i){if(Array.isArray(t)||D(t))continue;let i=this._getRowsByAttributeValue(e,t);i&&i.length<r.length&&(r=i)}let s=r.filter(e=>i.every(([t,i])=>{if(D(i)){let r=e[t];return(!("min"in i)||r>=i.min)&&(!("max"in i)||r<=i.max)}return Array.isArray(i)?i.includes(e[t]):e[t]==i}));return this._scopeTupleCache.set(t,s),s}_getRowsByAttributeValue(e,t){let i=this._attrValueIndexes.get(e);return i?i.get(t):void 0}_buildAttributeValueIndexes(){this._attrValueIndexes=new Map,this._rowIdIndex=new Map;for(let e of this._attributes){let t=new Map;for(let i of this.data){let r=i[e];t.has(r)||t.set(r,[]),t.get(r).push(i)}this._attrValueIndexes.set(e,t)}for(let e of this.data)this._rowIdIndex.set(e[M],e)}_getFilterKey(e={}){return Object.entries(e).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>D(t)?e+":["+(t.min??"-inf")+","+(t.max??"+inf")+"]":e+":"+JSON.stringify(t)).join("|")}_clearDataCaches(){this._dataScopeCache&&this._dataScopeCache.clear(),this._scopeTupleCache&&this._scopeTupleCache.clear(),this._attrValueIndexes&&(this._attrValueIndexes.clear(),this._buildAttributeValueIndexes())}count(){return this.data.length}has(e){return this._attributes.indexOf(e)>=0}parseDate(t,i){let r=e.timeParse(i);for(let e of this.data){let i=e[t];null==i||null==i?(i="",e[t]=new Date(1899,11,31).getTime()):e[t]=r(i).getTime(),this._dateMap.set(e[t],i)}this._attrTypes[t]=a.Date,this._attrSummaries[t]=h(this.data.map(e=>e[t]),a.Date),this._clearDataCaches()}raw(e,t){return this.type(e)===a.Date?this._dateMap.get(t).toString():t}get dimensions(){let e=[];for(let t in this._attrTypes)this._attrTypes[t]!=a.Number&&this._attrTypes[t]!=a.Integer&&t!=V.RowID&&e.push(t);return e.sort((e,t)=>this.unique(e).length-this.unique(t).length),e}get measures(){let e=[];for(let t in this._attrTypes)this._attrTypes[t]!==a.Number&&this._attrTypes[t]!==a.Integer||t==V.RowID||e.push(t);return e}attrs(e){if(void 0===e)return this._attributes;let t=[];for(let i in this._attrTypes)this._attrTypes[i]===e&&i!=V.RowID&&t.push(i);return t}summarize(){for(let e of this._attributes)this._attrSummaries[e]=h(this.data.map(t=>t[e]),this._attrTypes[e])}_validate(e,t){for(let i of e)for(let e in t){let r,s=t[e],n=i[e];if(null==i[e]||null==i[e])switch(s){case a.Boolean:r=!1;break;case a.Date:r=new Date(1899,11,31).getTime();break;case a.String:r="";break;default:r=0}else switch(s){case a.Boolean:r=n;break;case a.Date:r=Number.isInteger(n)&&n<=9999?new Date(n,0).getTime():Number.isInteger(n)?n:new Date(n+"").getTime(),this._dateMap.set(r,n);break;case a.String:r=n.toString();break;default:r=n}i[e]=r}}}function D(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)&&("min"in e||"max"in e)}function B(e){return e.dataScope?v(e.dataScope):e.parent&&e.parent.dataScope?v(e.parent.dataScope):void 0}const M="mascot_rowId";class G{constructor(e,t){this._id=i.TreeData+s(),this.initialize(e,t)}initialize(e,t){this.url=t,this._data=e,this._nodeList=[],this._linkList=[],this._nodeHash={},this._traverse(e,this._nodeList,this._linkList),this._nodeTable=new V(this._nodeList,"nodes"),this._linkTable=new V(this._linkList,"links"),this._nodeTable.tree=this,this._linkTable.tree=this}get nodeTable(){return this._nodeTable}get linkTable(){return this._linkTable}_traverse(e,t,i,r=0){let s={};Y in e||(e[Y]="n"+t.length),t.push(s),e._depth=r;for(let n in e)if("children"==n&&e[n]&&e[n].length>0)for(let s of e[n]){let n=this._traverse(s,t,i,r+1);i.push({parent:e[Y],child:n})}else s[n]=e[n];return this._nodeHash[s[Y]]=s,s[Y]}getNodeDataScopeRef(e){return O(N(this._nodeTable),M,e[M])}getNode(e){return this._nodeHash[e]}getRoot(){return this._nodeTable.data[0]}getChildren(e){let t=e[Y],i=[],r=this._linkTable.data,s=this._nodeTable.data;for(let e in r)if(r[e].parent==t){let t=r[e].child,n=s.findIndex(e=>e[Y]==t);i.push(s[n])}return i}getParent(e){let t=e[Y],i=this._linkTable.data,r=this._nodeTable.data;for(let e in i)if(i[e].child==t){let t=i[e].parent,s=r.findIndex(e=>e[Y]==t);return r[s]}}}function z(e){return v(e.dataScope).tree}class F{constructor(e,t){this._id=i.NetworkData+s(),this.initialize(e,t)}initialize(e,t){this.url=t,this._nodeTable=new V(e.nodes,this._id+"_nodes"),this._linkTable=new V(e.links,this._id+"_links"),this._nodeTable.graph=this,this._linkTable.graph=this,this._rawNodes=e.nodes,this._rawLinks=e.links,this._nodeHash={};for(let t of e.nodes)this._nodeHash[t[Y]]=t}get nodeTable(){return this._nodeTable}get linkTable(){return this._linkTable}get nodeList(){return this._rawNodes}get linkList(){return this._rawLinks}getNode(e){return this._nodeHash[e]}getLinks(e){let t=e[Y],i=this._rawLinks,r=[];for(let e in i)i[e].target!==t&&i[e].source!==t||r.push(i[e]);return r}buildNodeHierarchy(e){let t={};return t[Y]="root",W(t,this._rawNodes,e),new G(t,this.url)}}function j(e){return v(e.dataScope).graph}function W(e,t,i){if(0===t.length||0===i.length)return;"children"in e||(e.children=[]);let r={};for(let e of t){let t=e[i[0]];t in r||(r[t]=[]),r[t].push(e)}if(1===i.length)for(let t in r){let i={children:r[t]};i[Y]=t,e.children.push(i)}else for(let t in r){let s={};s[Y]=t,e.children.push(s),W(s,r[t],i.slice(1))}}const Y="id";function U(e,t){return fetch(t,{method:e}).then(e=>e.ok?e.text():(console.log(e.status),Promise.reject({status:e.status,statusText:e.statusText}))).catch(e=>(console.log(e),Promise.reject({status:e.status,statusText:e.statusText})))}class H{constructor(e,t,i){this._id="predicate_"+s(),this._type=e||X.POINT,this._variableType=t,this._variableName=i,this._value=void 0}get type(){return this._type}get value(){return this._value}set value(e){this._value=e}get id(){return this._id}get variableType(){return this._variableType}get variableName(){return this._variableName}}const X=Object.freeze({POINT:"point",INTERVAL:"interval",LIST:"list"});class q extends H{constructor(e,t,i){super(e,t,i)}testElement(e){let t;if("attribute"==this._variableType){if(!e.dataScope)return!1;t=e.datum[this._variableName]}else t=e[this._variableName];return this._value[0]<=t&&this._value[1]>=t}testTuple(e){if("attribute"==this._variableType){let t=e[this._variableName];return this._value[0]<=t&&this._value[1]>=t}return!1}}class K extends H{constructor(e,t,i){super(e,t,i)}addValue(e){this._value||(this._value=[]),this._value.push(e)}resetValue(){this._value=void 0}testElement(e){if("attribute"==this._variableType){if(!e.dataScope)return!1;let t=Array.from(new Set(e.data.map(e=>e[this._variableName])));return 1===t.length&&this._value.indexOf(t[0])>=0}return this._value.indexOf(e[this._variableName])>=0}testTuple(e){if("attribute"==this._variableType){let t=e[this._variableName];return this._value.indexOf(t)>=0}return!1}}class Z extends H{constructor(e,t,i){super(e,t,i)}testElement(e){if("attribute"==this._variableType){if(!e.dataScope)return!1;return e.datum[this._variableName]==this._value}return e[this._variableName]==this._value}testTuple(e){if("attribute"==this._variableType){let t=e[this._variableName];return this._value===t}return!1}equals(e){return this.type===e.type&&this.variableName===e.variableName&&this.value===e.value}}function $(e){let t,i="attribute"in e?"attribute":"property",r=e[i];switch(e.type){case X.LIST:t=new K(e.type,i,r);break;case X.INTERVAL:t=new q(e.type,i,r);break;case X.POINT:default:t=new Z(e.type,i,r)}return t.value=e.value,t}function J(e,t){for(let i of t)if(!i.testElement(e))return!1;return!0}const Q={svg:void 0,getSVG:function(){return window?(void 0===this.svg&&(this.svg=document.createElementNS("http://www.w3.org/2000/svg","svg"),this.svg.style.visibility="hidden",this.svg.style.pointerEvents="none",this.svg.setAttribute("aria-hidden","true"),document.body.appendChild(this.svg)),this.svg):null}};function ee(e,t,i,r,s){const n=s*Math.PI/180,a=e-i,o=t-r;return{x:a*Math.cos(n)-o*Math.sin(n)+i,y:a*Math.sin(n)+o*Math.cos(n)+r}}function te(e,t,i,r){return Math.sqrt(Math.pow(e-i,2)+Math.pow(t-r,2))}function ie(e,t,i){const r=document.getElementById(e),s=r.createSVGPoint();s.x=t,s.y=i;const n=s.matrixTransform(r.getScreenCTM().inverse());return[n.x,n.y]}const re=Object.freeze({fillColor:"fill",strokeColor:"stroke",strokeWidth:"stroke-width",fillOpacity:"fill-opacity",strokeOpacity:"stroke-opacity",strokeDash:"stroke-dasharray",opacity:"opacity",fontSize:"font-size",fontFamily:"font-family",fontWeight:"font-weight",visibility:"visibility",cursor:"cursor"});class se{constructor(e,t,i,r){this._x=e+i/2,this._y=t+r/2,this._width=i,this._height=r}translate(e,t){this._x+=e,this._y+=t}toJSON(){let e={};return e.x=this._x,e.y=this._y,e.width=this._width,e.height=this._height,e}union(e){let t=d3.min([this.left,e.left]),i=d3.min([this.top,e.top]),r=d3.max([this.right,e.right]),s=d3.max([this.bottom,e.bottom]);return new se(t,i,r-t,s-i)}clone(){return new se(this.left,this.top,this._width,this._height)}get left(){return this._x-this._width/2}set left(e){this._x=e+this._width/2}get right(){return this._x+this._width/2}set right(e){this._x=e-this._width/2}get top(){return this._y-this._height/2}set top(e){this._y=e+this._height/2}get bottom(){return this._y+this._height/2}set bottom(e){this._y=e-this._height/2}get x(){return this._x}get y(){return this._y}get center(){return this.x}get middle(){return this.y}get width(){return this._width}setWidth(e,t){switch(t){case he.RIGHT:this._x=this.right-e/2;break;case he.CENTER:this._width=2*e;break;default:this._x=this.left+e/2}this._width=e}get height(){return this._height}setHeight(e,t){switch(t){case he.TOP:this._y=this.top+e/2;break;case he.MIDDLE:this._height=2*e;break;default:this._y=this.bottom-e/2}this._height=e}contains(e,t){return this.left<=e&&this.right>=e&&this.top<=t&&this.bottom>=t}intersects(e){return!(this.right<e.left||this.bottom<e.top||this.left>e.right||this.top>e.bottom)}}function ne(e){let t=e[0].clone();for(let i=1;i<e.length;i++)t=t.union(e[i]);return t}function ae(e){return ne(("vertex"==e[0].type||"segment"==e[0].type?e.map(e=>e.parent):e).map(e=>e.refBounds?e.refBounds:e.bounds))}function oe(e){return ne(("vertex"==e[0].type||"segment"==e[0].type?e.map(e=>e.parent):e).map(e=>e.bounds))}function le(e){let t=we(e);for(let e of t)e._updateBounds();let i=[];for(let e of t)e.parent&&!i.includes(e.parent)&&i.push(e.parent);for(let e of i)le(e)}const he=Object.freeze({TOP:"top",LEFT:"left",RIGHT:"right",BOTTOM:"bottom",CENTER:"center",MIDDLE:"middle"});class ce{constructor(e){if(this._dataScopeRef=void 0,this._type="type"in e?e.type:i.Mark,this._id=e.id?e.id:this._type+"_"+s(),this._classId=void 0,this._bounds=void 0,this._rotate=void 0,this._refBounds=void 0,this._dirty=!0,this._clipMask=void 0,this._cursor=void 0,this._styles={},void 0!==e)for(let t in re)t in e&&(this.styles[t]=e[t])}get scene(){return Ie(this)}get datum(){return C(this._dataScopeRef)}get data(){return E(this._dataScopeRef)}set strokeColor(e){this.styles.strokeColor!==e&&(this.styles.strokeColor=e,this._dirty=!0)}get strokeColor(){return this.styles.strokeColor}set strokeWidth(e){this.styles.strokeWidth!==e&&(this.styles.strokeWidth=e,this._dirty=!0)}get strokeWidth(){return this.styles.strokeWidth}get strokeDash(){return this.styles.strokeDash}set strokeDash(e){this.styles.strokeDash!==e&&(this.styles.strokeDash=e,this._dirty=!0)}set fillColor(e){this.styles.fillColor!==e&&(this.styles.fillColor=e,this._dirty=!0)}get fillColor(){return this.styles.fillColor}get rotation(){return this._rotate}get cursor(){return this._cursor}get id(){return this._id}set id(e){this.getScene()?(delete this.getScene()._itemMap[this._id],this._id=e,this.getScene()._itemMap[e]=this):this._id=e}get classId(){return this._classId?this._classId:this._id}set classId(e){this._classId=e}get type(){return this._type}get bounds(){return this._bounds||this._updateBounds(),this._bounds}get refBounds(){return this._refBounds?this._refBounds:this.bounds}set dataScope(e){this._dataScopeRef=b(e)}get dataScope(){return this._dataScopeRef}get styles(){return this._styles}set styles(e){this._styles!==e&&(this._styles=e,this._dirty=!0)}set visibility(e){this.styles.visibility!==e&&(this.styles.visibility=e,this._dirty=!0)}get visibility(){return this.styles.visibility?this.styles.visibility:"visible"}get opacity(){return"opacity"in this.styles?this.styles.opacity:1}set opacity(e){this.styles.opacity!==e&&(this.styles.opacity=e,this._dirty=!0)}get z(){return"z"in this.styles?this.styles.z:0}set z(e){this.styles.z!==e&&(this.styles.z=e,this._dirty=!0)}copyPropertiesTo(e){e.styles=Object.assign({},this.styles),this._dataScopeRef&&(e._dataScopeRef=x(this._dataScopeRef))}createClipMask(){let e=this._bounds;this._clipMask=new se(e.left,e.top,e.width,e.height)}get clipMask(){return this._clipMask}}function de(e){return e instanceof ce&&e.type!==i.Gridlines}const ue=Object.freeze({Area:"area",Rect:"rect",Ellipse:"ellipse",Circle:"circle",Pie:"pie",Ring:"ring",Arc:"arc",Line:"line",Path:"path",Image:"image",SimpleText:"text",RichText:"richText",Polygon:"polygon",BezierCurve:"bezierCurve"});class _e{constructor(){this._refElements=[]}addRefElement(e){this._refElements.push(e)}get refElements(){return this._refElements}clearRefElements(){this._refElements=[]}}function pe(e){return e instanceof _e}const fe=Object.freeze({GRID:"grid",STACK:"stack",PACKING:"packing",FORCE:"force",DIRECTED:"directedgraph",TIDYTREE:"tidytree",TREEMAP:"treemap",STRATA:"strata",CIRCULAR:"circular",CLUSTER:"cluster"});function ge(e,t){return!!(e.startsWith("h")&&[he.LEFT,he.CENTER,he.RIGHT].indexOf(t)>=0)||(!!(e.startsWith("v")&&[he.TOP,he.MIDDLE,he.BOTTOM].indexOf(t)>=0)||(console.warn("Invalid alignment:",t),!1))}class ye{constructor(e){this._id=e+"_"+s(),this._type=e,this._inputVars=[],this._outputVars=[]}run(){}get id(){return this._id}get type(){return this._type}get inputVars(){return this._inputVars}get outputVars(){return this._outputVars}get outputVar(){return this._outputVars[0]}isIsolated(){return 0==this._inputVars.length&&0==this._outputVars.length}}const me=Object.freeze({CONDUIT:"conduit",ENCODER:"encoder",LAYOUT:"layout",LINK_PLACER:"linkRouter",CONSTRAINT:"constraint",EVAL_BBOX:"evalBBox",EVAL_REFBOUNDS:"evalRefBounds",AFFIXER:"affixer",ALIGNER:"aligner",DATA_EXTRACTOR:"dataExtractor",SCALE_BUILDER:"scaleBuilder",AXIS_PATH_PLACER:"axisPathPlacer",AXIS_TICKS_PLACER:"axisTicksPlacer",AXIS_LABELS_PLACER:"axisLabelsPlacer",AXIS_TITLE_PLACER:"axisTitlePlacer",GRIDLINES_PLACER:"gridlinesPlacer",GRID_LAYOUT:"gridLayout",STACK_LAYOUT:"stackLayout",PACK_LAYOUT:"packLayout",FORCE_LAYOUT:"forceLayout",DIRECTED_LAYOUT:"directedLayout",TIDY_TREE_LAYOUT:"tidyTreeLayout",TREEMAP_LAYOUT:"treemapLayout",STRATA_LAYOUT:"strataLayout",CIRCULAR_LAYOUT:"circularLayout",CLUSTER_LAYOUT:"clusterLayout",BIN_TRANSFORMER:"binTransformer",FILTER_TRANSFORMER:"filterTransformer",KDE_TRANSFORMER:"kdeTransformer",CUSTOM_TRANSFORMER:"customTransformer",REPOPULATE:"repopulate",TARGET_EVALUATOR:"targetEvaluator",TARGET_UPDATER:"targetUpdater"});class be{constructor(e){this._id="v_"+s(),this._type=e,this._incomings=[],this._outgoings=[],this._undirected=[]}get id(){return this._id}get incomingEdges(){return this._incomings}get outgoingEdges(){return this._outgoings}get undirectedEdges(){return this._undirected}get type(){return this._type}get incomingDataflow(){for(let e of this._incomings)if(e.fromNode&&e.fromNode instanceof ye)return e.fromNode;return null}isIsolated(){return 0==this._incomings.length&&0==this._outgoings.length}}const xe=Object.freeze({CHANNEL:"channel",PROPERTY:"property",STATE:"state",ATTRIBUTE:"attribute",ITEMS:"items",DATASCOPE:"datascope",ATTR_VALUE:"dataValue",BOUNDS:"bounds",SCALE:"scale",CONDITION_RESULT:"conditionResult",AFFIXATION:"affixation",ALIGNMENT:"alignment",EVT_CTX:"evtContext"});class ve extends Map{constructor(e){super(),this._scene=e}get scene(){return this._scene}var(e){if("string"!=typeof e||0===e.length)throw new Error("state.var(...) expects a non-empty variable name");return{type:"stateVar",key:e,stateContext:this}}set(e,t){const i=this.get(e);return super.set(e,t),i!==t&&(this._scene.depGraph.getVariable(xe.STATE,e,this),this._scene.onChange(xe.STATE,e,this)),this}}function we(e,t){let i=Ie(e);return"vertex"===e.type||"segment"===e.type?function(e,t){let i=Ie(e),r=t||i;if("vertex"===e.type){return Ee(e,ke(r,[{property:"classId",value:e.parent.classId}],!0))}if("segment"===e.type){return Se(e,ke(r,[{property:"classId",value:e.parent.classId}],!0))}return e.classId?ke(r,[{property:"classId",value:e.classId}]):[e]}(e,t):e.classId?ke(t||i,[{property:"classId",value:e.classId}]):[e]}function Ee(e,t){if(!e.classId){if(e.dataScope){let r=e.parent;if(!r)throw new Error("vertex has no parent mark");let s=[];if(r.type!==i.Area||e._isAnyVertex)for(let e of t)s=s.concat(e.vertices.filter(e=>e.dataScope));else{let i=r.vertices.indexOf(e)<r.vertices.length/2;for(let e of t){let t=i?e.vertices.slice(0,e.vertices.length/2):e.vertices.slice(e.vertices.length/2);s=s.concat(t.filter(e=>e.dataScope))}}return s}{let i=e.parent;if(!i)throw new Error("vertex has no parent mark");let r=i.vertices.indexOf(e),s=[];for(let e of t)s.push(e.vertices[r]);return s}}}function Ce(e,t){return e.id+"_v_"+e._vertices._ids[t]}function Ae(e,t){let r=e.parent,s=e._index,n=[];if(e.dataScope)if(r.type!==i.Area||e._isAnyVertex)for(let e of t){let t=[];for(let i=0;i<e._vertices.length;i++)e._vertices.hasDataScope(i)&&t.push(i);n.push({parent:e,indices:t})}else{let e=s<r._vertices.length/2;for(let i of t){let t=e?0:i._vertices.length/2,r=e?i._vertices.length/2:i._vertices.length,s=[];for(let e=t;e<r;e++)i._vertices.hasDataScope(e)&&s.push(e);n.push({parent:i,indices:s})}}else for(let e of t)n.push({parent:e,indices:[s]});return n}function Se(e,t){if(e._dataScopeRef){if(!e.parent)throw new Error("segment has no parent mark");let i=[];for(let e of t)i=i.concat(e.segments);return i}{let i=e.parent;if(!i)throw new Error("segment has no parent mark");let r=i.segments.indexOf(e),s=[];for(let e of t)s.push(e.segments[r]);return s}}function ke(e,t,i){let r=[];return Oe(e,t?t.map(e=>$(e)):[],r,i),r}function Re(e,t){let r=e.children.filter(e=>e.type==i.Collection);if(0!==r.length)for(let e of r){let i=e;for(;i&&i.dataScope;){if(S(i.dataScope,t))return i;i=i.children?i.children[0]:void 0}}}function Te(e){return e.type==i.Collection?e:e.parent?Te(e.parent):void 0}function Oe(e,t,i,r){if(e)if(J(e,t)&&i.push(e),e.vertices&&r)for(let r of e.vertices.concat(e.segments))J(r,t)&&i.push(r);else if(e.children&&e.children.length>0)for(let s of e.children)Oe(s,t,i,r)}function Ie(e){let t;if(t=Array.isArray(e)?e[0]:e,t){if(t instanceof ve)return t.scene;if(t._scene)return t._scene;for(pe(t)&&t.group&&(t=t.group),t.id.startsWith("encoding_")&&(t=t.element);t;){if(t.type==i.Scene)return t;t=t.parent}}}function Ne(e){let t=e;for("vertex"!=t.type&&"segment"!=t.type||(t=t.parent);t.parent&&[i.Collection,i.Glyph].includes(t.parent.type);)t=t.parent;return t}function Le(e,t){let i=[];if(Pe(e,i),t){let e={};for(let t of i)e[t.classId]=t;return Object.values(e)}return i}function Pe(e,t){if(de(e))t.push(e);else if(e.children&&!Object.values(r).includes(e.type))for(let i of e.children)Pe(i,t)}class Ve extends be{constructor(e,t,i){super(e),this._channel=t,this._elem=i}get channel(){return this._channel}get element(){return this._elem}}const De=Object.freeze({X:"x",Y:"y",WIDTH:"width",HEIGHT:"height",RADIUS:"radius",FILLCOLOR:"fillColor",STROKECOLOR:"strokeColor",FILLGRADIENT:"fillGradient",TEXT:"text",ANGLE:"angle",THICKNESS:"thickness",AREA:"area",FONTSIZE:"fontSize",RADIALDISTANCE:"radialDistance",STROKEWIDTH:"strokeWidth",OPACITY:"opacity",VISIBILITY:"visibility",STRENGTH:"strength",SRC:"src",Z:"z"});class Be extends be{constructor(e,t,i){super(e),this._property=t,this._elem=i}get property(){return this._property}get element(){return this._elem}}function Me(e){return e in Ge?Ge[e]:e}const Ge=Object.freeze({numCols:"layoutParameter",numRows:"layoutParameter",startCorner:"layoutParameter",direction:"layoutParameter"}),ze=Object.freeze({AXIS_ORIENTATION:"axisOrientation",AXIS_PATH_POSITION:"axisPathPosition",AXIS_TICK_SIZE:"axisTickSize",AXIS_TICK_OFFSET:"axisTickOffset",AXIS_TICKS_POSITION:"axisTicksPosition",AXIS_LABELS_POSITION:"axisLabelsPosition",AXIS_TITLE_POSITION:"axisTitlePosition",AXIS_LABEL_OFFSET:"axisLabelOffset",AXIS_LABEL_FORMAT:"axisLabelFormat",AXIS_FONT_SIZE:"axisFontSize",LEGEND_POSITION:"legendPosition",GRIDLINES_POSITION:"gridlinesPosition",INCLUDE_ZERO:"includeZero",FLIP_SCALE:"flipScale",RANGE_START:"rangeStart",RANGE_EXTENT:"rangeExtent",BASE_LINE:"baseline",LAYOUT_PARAMETER:"layoutParameter",NUM_BINS:"numBins",CHILDREN_ORDER:"childrenOrder",ATTRIBUTE:"attribute"});function Fe(e){let t=e?Ie(e):void 0;t&&t._clearInteractionCaches&&t._clearInteractionCaches()}function je(e,t){if(Fe(e),t.findVariable(xe.BOUNDS,[e]))return;let r=t.getVariable(xe.BOUNDS,e),s=t.createOneWayDependency(me.EVAL_BBOX);switch(t.connect(s,r),e.type){case i.Circle:case i.Polygon:{let i=t.getVariable(xe.CHANNEL,"x",e),r=t.getVariable(xe.CHANNEL,"y",e),n=t.getVariable(xe.CHANNEL,"radius",e),a=t.getVariable(xe.CHANNEL,"area",e);t.connect(n,s),t.connect(i,s),t.connect(r,s),t.connect(a,s);break}case i.Area:case i.Line:case i.BezierCurve:case i.Path:case i.Image:{let i=t.getVariable(xe.CHANNEL,"x",e),r=t.getVariable(xe.CHANNEL,"y",e),n=t.getVariable(xe.CHANNEL,"width",e),a=t.getVariable(xe.CHANNEL,"height",e);t.connect(i,s),t.connect(r,s),t.connect(n,s),t.connect(a,s);break}case i.Rect:{let i=t.getVariable(xe.CHANNEL,"x",e),r=t.getVariable(xe.CHANNEL,"y",e),n=t.getVariable(xe.CHANNEL,"width",e),a=t.getVariable(xe.CHANNEL,"height",e),o=t.getVariable(xe.CHANNEL,"area",e);t.connect(i,s),t.connect(r,s),t.connect(n,s),t.connect(a,s),t.connect(o,s);break}case i.SimpleText:case i.RichText:{let i=t.getVariable(xe.CHANNEL,"x",e),r=t.getVariable(xe.CHANNEL,"y",e),n=t.getVariable(xe.CHANNEL,"text",e);t.connect(i,s),t.connect(r,s),t.connect(n,s);break}case i.Ring:{let i=t.getVariable(xe.CHANNEL,"x",e),r=t.getVariable(xe.CHANNEL,"y",e),n=t.getVariable(xe.CHANNEL,"innerRadius",e),a=t.getVariable(xe.CHANNEL,"outerRadius",e);t.connect(i,s),t.connect(r,s),t.connect(n,s),t.connect(a,s);break}case i.Pie:case i.Arc:{let i=t.getVariable(xe.CHANNEL,"x",e),r=t.getVariable(xe.CHANNEL,"y",e),n=t.getVariable(xe.CHANNEL,"innerRadius",e),a=t.getVariable(xe.CHANNEL,"outerRadius",e),o=t.getVariable(xe.CHANNEL,"startAngle",e),l=t.getVariable(xe.CHANNEL,"endAngle",e),h=t.getVariable(xe.CHANNEL,"angle",e),c=t.getVariable(xe.CHANNEL,"thickness",e);t.connect(i,s),t.connect(r,s),t.connect(n,s),t.connect(a,s),t.connect(o,s),t.connect(l,s),t.connect(h,s),t.connect(c,s);break}}s.run()}function We(e,t){Fe(e);let i=t.findVariablesByElement(e);for(let e in i){let r=i[e];for(let e of r)t.deleteVariable(e)}}function Ye(e,t){if(e.type===i.Axis){let i=t.findVariable(xe.PROPERTY,[ze.AXIS_PATH_POSITION,e]).incomingDataflow;console.log(i,e),t.deleteOperator(i),i=t.findVariable(xe.PROPERTY,[ze.AXIS_TICKS_POSITION,e]).incomingDataflow,t.deleteOperator(i),i=t.findVariable(xe.PROPERTY,[ze.AXIS_LABELS_POSITION,e]).incomingDataflow,t.deleteOperator(i),i=t.findVariable(xe.PROPERTY,[ze.AXIS_TITLE_POSITION,e]).incomingDataflow,t.deleteOperator(i)}else if(e.type===i.Gridlines){let i=t.findVariable(xe.PROPERTY,[ze.GRIDLINES_POSITION,e]).incomingDataflow;t.deleteOperator(i)}}function Ue(e,t){if(Fe(e),t.findVariable(xe.BOUNDS,[e]))return;let i=t.getVariable(xe.BOUNDS,e),r=t.getVariable(xe.CHANNEL,"x",e),s=t.getVariable(xe.CHANNEL,"y",e),n=t.getVariable(xe.CHANNEL,"width",e),a=t.getVariable(xe.CHANNEL,"height",e),o=t.createOneWayDependency(me.EVAL_BBOX);t.connect(r,o),t.connect(s,o),t.connect(n,o),t.connect(a,o),t.connect(o,i),o.run()}function He(e,t){Fe(e);let i=t.getVariable(xe.BOUNDS,e),r=t.getVariable(xe.CHANNEL,"x",e),s=t.getVariable(xe.CHANNEL,"y",e),n=t.getVariable(xe.CHANNEL,"width",e),a=t.getVariable(xe.CHANNEL,"height",e),o=t.createOneWayDependency(me.EVAL_BBOX);t.connect(r,o),t.connect(s,o),t.connect(n,o),t.connect(a,o),t.connect(o,i),o.run()}function Xe(e,t,i){Fe(e);let r=i.getVariable(xe.BOUNDS,e),s=i.getVariable(xe.BOUNDS,t),n=i.getIncomingDataflowOperator(me.EVAL_BBOX,r),a=s.outgoingEdges.find(e=>e.fromNode===s&&e.toNode===n);if(a&&i.disconnect(s,n,a),e.layout){let r=i.getVariable(xe.CHANNEL,"x",t),s=i.getIncomingDataflowOperator(Ze(e.layout.type),r);s&&i.deleteOperator(s)}}function qe(e,t,i){Fe(e);let r=i.getVariable(xe.BOUNDS,e),s=i.getVariable(xe.BOUNDS,t),n=i.getIncomingDataflowOperator(me.EVAL_BBOX,r);i.connect(s,n),i.connect(n,r),e.layout&&Je(e,e.layout,i)}function Ke(e,t){Fe(e);let i=t.getVariable(xe.BOUNDS,e),r=t.getVariable(xe.CHANNEL,"x",e),s=t.getVariable(xe.CHANNEL,"y",e),n=t.getIncomingDataflowOperator(me.EVAL_BBOX,i);t.connect(r,n),t.connect(s,n);for(let i of e.children)t.connect(t.getVariable(xe.BOUNDS,i),n);t.connect(n,i),n.run()}function Ze(e){switch(e){case fe.GRID:return me.GRID_LAYOUT;case fe.STACK:return me.STACK_LAYOUT;case fe.PACKING:return me.PACK_LAYOUT;case fe.FORCE:return me.FORCE_LAYOUT;case fe.DIRECTED:return me.DIRECTED_LAYOUT;case fe.TIDYTREE:return me.TIDY_TREE_LAYOUT;case fe.TREEMAP:return me.TREEMAP_LAYOUT;case fe.STRATA:return me.STRATA_LAYOUT;case fe.CIRCULAR:return me.CIRCULAR_LAYOUT;case fe.CLUSTER:return me.CLUSTER_LAYOUT}}function $e(e,t,i){let r=i.getVariable(xe.PROPERTY,ze.CHILDREN_ORDER,e),s=i.getOutgoingDataflowOperator(Ze(t.type),r);i.deleteOperator(s)}function Je(e,t,r){let s=t?t.type:"none",n=s===fe.TREEMAP?Le(e)[0]:e.children[0];if(!n)return;let a=r.getVariable(xe.CHANNEL,"width",n),o=r.getVariable(xe.CHANNEL,"height",n),l=r.getVariable(xe.PROPERTY,ze.CHILDREN_ORDER,e),h=r.getVariable(xe.CHANNEL,"x",n),c=r.getVariable(xe.CHANNEL,"y",n),d=r.getVariable(xe.CHANNEL,"visibility",n),u=r.getVariable(xe.PROPERTY,ze.LAYOUT_PARAMETER,t),_=r.getOutgoingDataflowOperator(Ze(s),l);if(r.connect(a,_),r.connect(o,_),r.connect(l,_),r.connect(u,_),r.connect(d,_),r.connect(_,h),r.connect(_,c),r.disconnectChannelVarFromBBoxOperator(a),r.disconnectChannelVarFromBBoxOperator(o),n.type===i.Arc||n.type===i.Pie){let e=r.getVariable(xe.CHANNEL,"angle",n),t=r.getVariable(xe.CHANNEL,"thickness",n);r.connect(e,_),r.connect(t,_)}else if(n.type===i.Circle){let e=r.getVariable(xe.CHANNEL,"area",n),t=r.getVariable(xe.CHANNEL,"radius",n);r.connect(e,_),r.connect(t,_),r.disconnectChannelVarFromBBoxOperator(e),r.disconnectChannelVarFromBBoxOperator(t)}else if(n.type===i.Rect){let e=r.getVariable(xe.CHANNEL,"area",n);r.connect(e,_),r.disconnectChannelVarFromBBoxOperator(e)}if(_.run(),n.links&&Qe(n,r),n.children&&n.children[0]){let e=r.getVariable(xe.BOUNDS,n.children[0]),t=r.getVariable(xe.CHANNEL,"x",n).incomingDataflow;t&&r.connect(e,t),r.disconnectChannelVarFromBBoxOperator(e)}}function Qe(e,t){let i=e.links[0],r=t.getVariable(xe.CHANNEL,"x",e),s=t.getVariable(xe.CHANNEL,"x",i),n=t.getVariable(xe.CHANNEL,"strokeWidth",i),a=t.getVariable(xe.CHANNEL,"strength",i),o=t.createOneWayDependency(me.LINK_PLACER);t.connect(r,o),t.connect(n,o),t.connect(a,o),t.connect(o,s)}function et(e,t,i){if(!e||"segment"!==e.type)return;let r=B(e),s=r?i.findVariable(xe.ITEMS,[r]):null;if(s)for(let e of s.outgoingEdges)if(e.isDirected&&e.toNode.type===me.REPOPULATE)return void i.connect(e.toNode,t)}function tt(e,t,r){let s=e.attribute,n=e.channel,a=e.element,o=t.createOneWayDependency(me.ENCODER);if(["width","height"].includes(e.channel)&&a.type===i.Area){let e=t.getVariable(xe.PROPERTY,ze.BASE_LINE,a);t.connect(e,o)}if(r){let i=t.getVariable(xe.ATTR_VALUE,r),s=t.getVariable(xe.SCALE,r),l=t.getVariable(xe.CHANNEL,n,a);t.connect(s,o),t.connect(o,l),i.addLinkedEncoding(e),s.addLinkedEncoding(e);let h=t.getVariable(xe.DATASCOPE,e.element),c=i.incomingDataflow;c&&h&&(t.connect(h,c),et(e.element,h,t)),i.incomingDataflow.run()}else{let i=t.getVariable(xe.ATTRIBUTE,s,B(a),e),r=t.getVariable(xe.PROPERTY,ze.INCLUDE_ZERO,e),l=t.getVariable(xe.ATTR_VALUE,e),h=t.getVariable(xe.DATASCOPE,a),c=t.createOneWayDependency(me.DATA_EXTRACTOR);t.connect(i,c),t.connect(r,c),t.connect(h,c),t.connect(c,l),et(a,h,t),c.run();let d=t.getVariable(xe.PROPERTY,ze.RANGE_START,e),u=t.getVariable(xe.PROPERTY,ze.RANGE_EXTENT,e),_=t.getVariable(xe.PROPERTY,ze.FLIP_SCALE,e),p=t.getVariable(xe.SCALE,e),f=t.createOneWayDependency(me.SCALE_BUILDER);t.connect(d,f),t.connect(u,f),t.connect(_,f),t.connect(l,f),t.connect(f,p),f.run();let g=t.getVariable(xe.CHANNEL,n,a);t.connect(p,o),t.connect(o,g),o.run()}}function it(e,t){let i=t.getVariable(xe.PROPERTY,ze.AXIS_ORIENTATION,e),r=t.getVariable(xe.BOUNDS,e.elements[0].parent),s=t.getVariable(xe.PROPERTY,ze.AXIS_PATH_POSITION,e),n=t.createOneWayDependency(me.AXIS_PATH_PLACER);t.connect(i,n),t.connect(r,n),t.connect(n,s),n.run();let a=t.getVariable(xe.PROPERTY,ze.AXIS_TICK_OFFSET,e),o=t.getVariable(xe.PROPERTY,ze.AXIS_TICK_SIZE,e),l=t.createOneWayDependency(me.AXIS_TICKS_PLACER),h=t.getVariable(xe.PROPERTY,ze.AXIS_TICKS_POSITION,e);t.connect(s,l),t.connect(a,l),t.connect(o,l),t.connect(l,h),l.run();let c=t.getVariable(xe.PROPERTY,ze.AXIS_LABEL_OFFSET,e),d=t.getVariable(xe.PROPERTY,ze.AXIS_LABEL_FORMAT,e),u=t.getVariable(xe.PROPERTY,ze.AXIS_FONT_SIZE,e),_=t.createOneWayDependency(me.AXIS_LABELS_PLACER),p=t.getVariable(xe.PROPERTY,ze.AXIS_LABELS_POSITION,e);t.connect(s,_),t.connect(c,_),t.connect(d,_),t.connect(u,_),t.connect(_,p),_.run();let f=t.getVariable(xe.PROPERTY,ze.AXIS_TITLE_POSITION,e),g=t.createOneWayDependency(me.AXIS_TITLE_PLACER);t.connect(s,g),t.connect(g,f),g.run();let y=t.getVariable(xe.BOUNDS,e),m=t.getIncomingDataflowOperator(me.EVAL_BBOX,y);t.connect(h,m),t.connect(p,m),t.connect(m,y)}function rt(e,t){let i=t.getVariable(xe.PROPERTY,ze.AXIS_ORIENTATION,e),r=t.getVariable(xe.BOUNDS,Ne(e.elements[0])),s=t.getVariable(xe.PROPERTY,ze.AXIS_PATH_POSITION,e),n=t.createOneWayDependency(me.AXIS_PATH_PLACER);t.connect(i,n),t.connect(r,n),t.connect(n,s),n.run();let a=t.getVariable(xe.PROPERTY,ze.AXIS_TICK_OFFSET,e),o=t.getVariable(xe.PROPERTY,ze.AXIS_TICK_SIZE,e),l=t.createOneWayDependency(me.AXIS_TICKS_PLACER),h=t.getVariable(xe.PROPERTY,ze.AXIS_TICKS_POSITION,e);t.connect(s,l),t.connect(a,l),t.connect(o,l),t.connect(l,h),l.run();let c=t.getVariable(xe.PROPERTY,ze.AXIS_LABEL_OFFSET,e),d=t.getVariable(xe.PROPERTY,ze.AXIS_LABEL_FORMAT,e),u=t.getVariable(xe.PROPERTY,ze.AXIS_FONT_SIZE,e),_=t.createOneWayDependency(me.AXIS_LABELS_PLACER),p=t.getVariable(xe.PROPERTY,ze.AXIS_LABELS_POSITION,e);t.connect(s,_),t.connect(c,_),t.connect(d,_),t.connect(u,_),t.connect(_,p),_.run();let f=t.getVariable(xe.PROPERTY,ze.AXIS_TITLE_POSITION,e),g=t.createOneWayDependency(me.AXIS_TITLE_PLACER);t.connect(s,g),t.connect(g,f),g.run();let y=t.getVariable(xe.BOUNDS,e),m=t.getIncomingDataflowOperator(me.EVAL_BBOX,y);t.connect(h,m),t.connect(p,m),t.connect(m,y)}function st(e,t){let i=t.getVariable(xe.BOUNDS,Ne(e.elements[0])),r=t.getVariable(xe.PROPERTY,ze.GRIDLINES_POSITION,e),s=t.createOneWayDependency(me.GRIDLINES_PLACER);t.connect(i,s),t.connect(s,r),s.run();let n=t.getVariable(xe.BOUNDS,e),a=t.getIncomingDataflowOperator(me.EVAL_BBOX,n);t.connect(r,a),t.connect(a,n)}class nt{constructor(){this._id=this.type+s(),this._type=i.Group,this._dataScopeRef=void 0,this._bounds=void 0,this._layout=void 0,this._children=[],this._sortBy={property:M,descending:!1},this._z=0}get id(){return this._id}get type(){return this._type}get datum(){return C(this._dataScopeRef)}get data(){return E(this._dataScopeRef)}get children(){return this._children}addChild(e){this._children.indexOf(e)>=0||(e.parent&&e.parent.removeChild(e),this._children.push(e),e.parent=this)}addChildAt(e,t){e.parent&&e.parent.removeChild(e),this.children.splice(t,0,e),e.parent=this}removeChild(e){let t=this.children.indexOf(e);t>=0&&(this.children.splice(t,1),e.parent=null)}removeChildAt(e){this.children[e].parent=null,this.children.splice(e,1)}removeAll(){for(let e of this.children)e.parent=null;this._children=[]}get dataScope(){return this._dataScopeRef}set dataScope(e){if(this._dataScopeRef=b(e),void 0===this._dataScopeRef)for(let e of this.children)e.dataScope=void 0;else for(let e of this.children)e.dataScope?e.dataScope=I(e.dataScope,this._dataScopeRef):e.dataScope=this._dataScopeRef}getInternalEncodings(e){if(0==this.children.length)return[];let t=this.children[0],r=this.getScene(),s=Object.keys(r.encodings),n=[];for(;t;){if(t.classId&&n.indexOf(t.classId)<0&&n.push(t.classId),t.type===i.Glyph){t.children.forEach(e=>n.push(e.classId));break}if(!t.children)break;t=t.children[0]}let a=[];for(let t of s){let i=t.split("_");for(let s of n)i[0]==s&&r.encodings[t][e]&&a.push(r.encodings[t][e])}return a}get firstChild(){return this.children[0]}get lastChild(){return this.children[this.children.length-1]}set layout(e){if(this._layout=e,e&&(e.group=this),Je(this,e,this.scene._depGraph),this.children&&this.children.length>0){let e=Le(this,!0);for(let t of e)this.scene.onChange(xe.CHANNEL,"x",t)}}get layout(){return this._layout}get bounds(){return this._bounds||this._updateBounds(),this._bounds}get refBounds(){let e=this.children.map(e=>e.refBounds),t=d3.min(e.map(e=>e.left)),i=d3.min(e.map(e=>e.top)),r=d3.max(e.map(e=>e.right)),s=d3.max(e.map(e=>e.bottom));return new se(t,i,r-t,s-i)}get x(){return this.bounds.x}get y(){return this.bounds.y}_updateBounds(){let e=this.children;if(e.length>0){this._bounds=e[0].bounds.clone();for(let t=1;t<e.length;t++)"hidden"!=e[t].visibility&&(this._bounds=this._bounds.union(e[t].bounds))}else this._bounds=new se(0,0,0,0)}set visibility(e){let t="hidden"==e?"hidden":"visible";if(this.visibility!==t){this._visibility="hidden"==e?e:"visible";for(let t of this.children)t.visibility=e}}get visibility(){return this._visibility?this._visibility:"visible"}get z(){return this._z}set z(e){this._z!==e&&(this._z=e)}get scene(){return Ie(this)}get sortBy(){return this._sortBy}}function at(e){return e.type===i.Axis||e.type===i.Legend||e.type===i.Gridlines}class ot extends nt{constructor(e){super(),this._type=i.Collection,this._id=e.id?e.id:this._type+"_"+s(),this._classId=this.id,this._childrenOrder=void 0,this._clipMask=void 0}get classId(){return this._classId}getSVGPathData(){let e="";for(let t of this.children)if(t.getSVGPathData)e+=t.getSVGPathData();else if(t.bounds){let i=t.bounds;e+=["M",i.left,i.top].join(" "),e+=["L",i.right,i.top].join(" "),e+=["L",i.right,i.bottom].join(" "),e+=["L",i.left,i.bottom,"Z"].join(" ")}return e}createClipMask(){let e=ae(this._children);this._clipMask=new se(e.left,e.top,e.width,e.height)}get clipMask(){return this._clipMask}}class lt extends nt{constructor(e){if(super(),this._type=i.Glyph,this._id=e&&e.id?e.id:this.type+"_"+s(),this._classId=this._id,e&&e.children)for(let t of e.children)this.addChild(t)}get classId(){return this._classId}}const ht=Object.freeze({RowFirst:"rowFirst",ColumnFirst:"columnFirst"}),ct=Object.freeze({TopLeft:"topLeft",TopRight:"topRight",BottomLeft:"bottomLeft",BottomRight:"bottomRight"}),dt="horizontal",ut="vertical",_t="angular",pt="radial",ft={Left2Right:"l2r",Right2Left:"r2l",Top2Bottom:"t2b",Bottom2Top:"b2t"},gt=Object.freeze({CLOCKWISE:"clockwise",ANTI_CLOCKWISE:"anti-clockwise"}),yt=Object.freeze({INWARD:"inward",OUTWARD:"outward"});class mt{constructor(e,t){this.type="vertex",this.parent=e,this._index=t}_getStored(e){return this.parent._vertices.getProperty(this._index,e)}_setStored(e,t){this._getStored(e)!==t&&(this.parent._vertices.setProperty(this._index,e,t),this.parent._dirty=!0)}get datum(){return this.dataScope?C(this.dataScope):this.parent.datum}get data(){return this.dataScope?E(this.dataScope):this.parent.data}get dataScope(){return this.parent._vertices.getDataScopeRef(this._index)}set dataScope(e){this.dataScope!==e&&(this.parent._vertices.setDataScopeRef(this._index,e),this.parent._dirty=!0)}get bounds(){switch(this.shape){case"rect":return new se(this.x-this.width/2,this.y-this.height/2,this.width,this.height);case"circle":return new se(this.x-this.radius,this.y-this.radius,2*this.radius,2*this.radius);default:return new se(this.x-.5,this.y-.5,1,1)}}get id(){return this.parent.id+"_v_"+this.parent._vertices._ids[this._index]}set polarAngle(e){this._setStored("polarAngle",e)}get polarAngle(){return this._getStored("polarAngle")}get _polarAngle(){return this.polarAngle}set _polarAngle(e){this.polarAngle=e}get scene(){return this.parent.scene}get x(){return this.parent._vertices._xs[this._index]}set x(e){this.parent._vertices._xs[this._index]!==e&&(this.parent._vertices._xs[this._index]=e,this.parent._dirty=!0)}get y(){return this.parent._vertices._ys[this._index]}set y(e){this.parent._vertices._ys[this._index]!==e&&(this.parent._vertices._ys[this._index]=e,this.parent._dirty=!0)}get shape(){return this._getStored("shape")}set shape(e){this._setStored("shape",e)}get width(){return this._getStored("width")}set width(e){this._setStored("width",e)}get height(){return this._getStored("height")}set height(e){this._setStored("height",e)}get radius(){return this._getStored("radius")}set radius(e){this._setStored("radius",e)}get fillColor(){return this._getStored("fillColor")}set fillColor(e){this._setStored("fillColor",e)}get opacity(){return this._getStored("opacity")}set opacity(e){this._setStored("opacity",e)}get strokeWidth(){return this._getStored("strokeWidth")}set strokeWidth(e){this._setStored("strokeWidth",e)}get strokeColor(){return this._getStored("strokeColor")}set strokeColor(e){this._setStored("strokeColor",e)}}mt.styles=["vxShape","vxWidth","vxHeight","vxRadius","vxFillColor","vxStrokeColor","vxStrokeWidth","vxOpacity"];class bt{constructor(e,t,i,r){this.type="segment",this._id=r,this._vertex1Index="number"==typeof e?e:e._index,this._vertex2Index="number"==typeof t?t:t._index,this._dataScopeRef=void 0,this.parent=i}get dataScope(){return this._dataScopeRef?this._dataScopeRef:this.parent.dataScope}set dataScope(e){this._dataScopeRef=b(e)}get datum(){return this.dataScope?C(this.dataScope):this.parent.datum}get data(){return this.dataScope?E(this.dataScope):this.parent.data}get id(){return this.parent.id+"_s_"+this._id}get vertex1(){return this.parent.vertices[this._vertex1Index]}set vertex1(e){this._vertex1Index="number"==typeof e?e:e._index}get vertex2(){return this.parent.vertices[this._vertex2Index]}set vertex2(e){this._vertex2Index="number"==typeof e?e:e._index}get x(){return(this.parent._vertices._xs[this._vertex1Index]+this.parent._vertices._xs[this._vertex2Index])/2}get y(){return(this.parent._vertices._ys[this._vertex1Index]+this.parent._vertices._ys[this._vertex2Index])/2}get scene(){return this.parent.scene}}class xt{constructor(e){return this._path=e,this.clear(),new Proxy(this,{get:(e,t)=>"length"===t?e.length:t===Symbol.iterator?e[Symbol.iterator].bind(e):xt._isIndex(t)?e.get(Number(t)):e[t],set(e,t,i){if(xt._isIndex(t))return e.replace(Number(t),i),!0;if("string"==typeof t&&"_"===t[0])return e[t]=i,!0;throw new Error("path.vertices is read-only; mutate vertex properties or use path.vertices = [...].")}})}static _isIndex(e){if("string"!=typeof e||""===e)return!1;let t=Number(e);return Number.isInteger(t)&&t>=0&&String(t)===e}static getCoords(e){return Array.isArray(e)?e:[e.x,e.y]}static getId(e){return e&&e.parent&&e.parent._vertices&&void 0!==e._index?e.parent._vertices._ids[e._index]:e?e.id:void 0}static get storageKeys(){return["_ids","_xs","_ys","_dataScopeRefs","_polarAngles","_shapes","_widths","_heights","_radii","_fillColors","_opacities","_strokeWidths","_strokeColors","_refs"]}static get propertyArrays(){return{dataScope:"_dataScopeRefs",polarAngle:"_polarAngles",shape:"_shapes",width:"_widths",height:"_heights",radius:"_radii",fillColor:"_fillColors",opacity:"_opacities",strokeWidth:"_strokeWidths",strokeColor:"_strokeColors"}}get length(){return this._xs.length}clear(){this._ids=[],this._xs=[],this._ys=[],this._dataScopeRefs=[],this._polarAngles=[],this._shapes=[],this._widths=[],this._heights=[],this._radii=[],this._fillColors=[],this._opacities=[],this._strokeWidths=[],this._strokeColors=[],this._refs=[]}get(e){if(!(e<0||e>=this.length))return this._refs[e]||(this._refs[e]=new mt(this._path,e)),this._refs[e]}at(e){return e<0&&(e=this.length+e),this.get(e)}append(e,t){let[i,r]=xt.getCoords(e),s=Array.isArray(e)?void 0:e.dataScope,n=void 0!==t?t:xt.getId(e),a=this.length;return this._ids.push(n),this._xs.push(i),this._ys.push(r),this._dataScopeRefs.push(s?this._copyDataScopeRef(s):void 0),this._polarAngles.push(Array.isArray(e)?void 0:e.polarAngle),this._shapes.push(Array.isArray(e)?void 0:e.shape),this._widths.push(Array.isArray(e)?0:e.width),this._heights.push(Array.isArray(e)?0:e.height),this._radii.push(Array.isArray(e)?0:e.radius),this._fillColors.push(Array.isArray(e)?"#555":e.fillColor),this._opacities.push(Array.isArray(e)?1:e.opacity),this._strokeWidths.push(Array.isArray(e)?0:e.strokeWidth),this._strokeColors.push(Array.isArray(e)?"#aaa":e.strokeColor),this._refs.push(void 0),a}insert(e,t,i,r){let s="number"==typeof t,n=s?[t,i]:xt.getCoords(t),a=n[0],o=n[1],l=s||Array.isArray(t)?void 0:t.dataScope,h=s?r:xt.getId(t);this._ids.splice(e,0,h),this._xs.splice(e,0,a),this._ys.splice(e,0,o),this._dataScopeRefs.splice(e,0,l?this._copyDataScopeRef(l):void 0),this._polarAngles.splice(e,0,s||Array.isArray(t)?void 0:t.polarAngle),this._shapes.splice(e,0,s||Array.isArray(t)?void 0:t.shape),this._widths.splice(e,0,s||Array.isArray(t)?0:t.width),this._heights.splice(e,0,s||Array.isArray(t)?0:t.height),this._radii.splice(e,0,s||Array.isArray(t)?0:t.radius),this._fillColors.splice(e,0,s||Array.isArray(t)?"#555":t.fillColor),this._opacities.splice(e,0,s||Array.isArray(t)?1:t.opacity),this._strokeWidths.splice(e,0,s||Array.isArray(t)?0:t.strokeWidth),this._strokeColors.splice(e,0,s||Array.isArray(t)?"#aaa":t.strokeColor),this._refs.splice(e,0,void 0),this._reindexRefs()}replace(e,t){let[i,r]=xt.getCoords(t),s=Array.isArray(t)?void 0:t.dataScope;this._xs[e]=i,this._ys[e]=r,this._dataScopeRefs[e]=s?this._copyDataScopeRef(s):void 0,this._polarAngles[e]=Array.isArray(t)?void 0:t.polarAngle,this._shapes[e]=Array.isArray(t)?void 0:t.shape,this._widths[e]=Array.isArray(t)?0:t.width,this._heights[e]=Array.isArray(t)?0:t.height,this._radii[e]=Array.isArray(t)?0:t.radius,this._fillColors[e]=Array.isArray(t)?"#555":t.fillColor,this._opacities[e]=Array.isArray(t)?1:t.opacity,this._strokeWidths[e]=Array.isArray(t)?0:t.strokeWidth,this._strokeColors[e]=Array.isArray(t)?"#aaa":t.strokeColor,this._refs[e]=void 0}copyFrom(e){this._ids=e._ids.slice(),this._xs=e._xs.slice(),this._ys=e._ys.slice(),this._dataScopeRefs=e._dataScopeRefs.map(e=>this._copyDataScopeRef(e)),this._polarAngles=e._polarAngles.slice(),this._shapes=e._shapes.slice(),this._widths=e._widths.slice(),this._heights=e._heights.slice(),this._radii=e._radii.slice(),this._fillColors=e._fillColors.slice(),this._opacities=e._opacities.slice(),this._strokeWidths=e._strokeWidths.slice(),this._strokeColors=e._strokeColors.slice(),this._refs=[]}getProperty(e,t){let i=xt.propertyArrays[t];return"dataScope"===t?this.getDataScopeRef(e):i?this[i][e]:void 0}setProperty(e,t,i){let r=xt.propertyArrays[t];r&&("dataScope"===t?this.setDataScopeRef(e,i):this[r][e]=i)}setDataScopeRef(e,t){this._dataScopeRefs[e]=t?this._copyDataScopeRef(t):void 0}getDataScopeRef(e){return this._dataScopeRefs[e]}hasDataScope(e){return!!this._dataScopeRefs[e]}getDataScopeRows(e){let t=this._dataScopeRefs[e];if(t)return E(t)}getDataScopeAttrVal(e,t){let i=this._dataScopeRefs[e];if(i)return k(i,t)}getDataScopeAttributeValues(e,t){let i=this._dataScopeRefs[e];return i?R(i,t):[]}aggregateDataScopeAttribute(e,t,i){return T(this._dataScopeRefs[e],t,i)}_copyDataScopeRef(e){return e?b(e):e}sort(e){let t=Array.from({length:this.length},(e,t)=>t);return t.sort((t,i)=>e(this.get(t),this.get(i))),this._reorder(t),this._path._reindexSegments(),this}reverse(){let e=Array.from({length:this.length},(e,t)=>this.length-t-1);return this._reorder(e),this._path._reindexSegments(),this}splice(e,t,...i){let r=this.slice(e,e+t);for(let i of xt.storageKeys)this[i].splice(e,t);for(let t=0;t<i.length;t++)this.insert(e+t,i[t],void 0);return this._reindexRefs(),this._path._reindexSegments(),r}push(...e){for(let t of e)this.append(t,void 0);return this._path._reindexSegments(),this.length}map(e,t){let i=[];for(let r=0;r<this.length;r++)i.push(e.call(t,this.get(r),r,this));return i}filter(e,t){let i=[];for(let r=0;r<this.length;r++){let s=this.get(r);e.call(t,s,r,this)&&i.push(s)}return i}find(e,t){for(let i=0;i<this.length;i++){let r=this.get(i);if(e.call(t,r,i,this))return r}}forEach(e,t){for(let i=0;i<this.length;i++)e.call(t,this.get(i),i,this)}slice(e,t){return Array.from(this).slice(e,t)}concat(...e){return Array.from(this).concat(...e)}entries(){let e=this;return function*(){for(let t=0;t<e.length;t++)yield[t,e.get(t)]}()}indexOf(e){return e&&e.parent===this._path?e._index:-1}includes(e){return this.indexOf(e)>=0}[Symbol.iterator](){let e=this;return function*(){for(let t=0;t<e.length;t++)yield e.get(t)}()}_reorder(e){for(let t of xt.storageKeys){let i=this[t];this[t]=e.map(e=>i[e])}this._reindexRefs()}_reindexRefs(){for(let e=0;e<this._refs.length;e++)this._refs[e]&&(this._refs[e]._index=e)}}let vt=class extends ce{constructor(e){super(e),this._type="type"in e?e.type:i.Path,this._vertices=new xt(this),this.vertexCounter=0,this._sortBy={},this.segmentCounter=0,this.segments=[],this.anchor=void 0,this.closed="closed"in e&&e.closed,this.curveMode="curveMode"in e?e.curveMode:"linear",this._vxShape=void 0,this._vxWidth=0,this._vxHeight=0,this._vxRadius=0,this._vxFillColor="#555555",this._vxStrokeColor="#aaaaaa",this._vxStrokeWidth=0,this._vxOpacity=1;for(let t of mt.styles)t in e&&(this["_"+t]=e[t]);"vertices"in e&&(this.vertices=e.vertices),this._sourceAnchor="sourceAnchor"in e?e.sourceAnchor:["center","middle"],this._targetAnchor="targetAnchor"in e?e.targetAnchor:["center","middle"],this._sourceOffset="sourceOffset"in e?e.sourceOffset:[0,0],this._targetOffset="targetOffset"in e?e.targetOffset:[0,0],this._strength="strength"in e?e.strength:.85,"strokeColor"in this.styles||(this.styles.strokeColor="#ccc"),"fillColor"in this.styles||(this.styles.fillColor="none"),"strokeWidth"in this.styles||(this.styles.strokeWidth=1),"strokeDash"in this.styles||(this.styles.strokeDash="none")}set vertices(e){if(this._vertices.clear(),this.segments=[],this.vertexCounter=0,this.segmentCounter=0,0===e.length)return this._dirty=!0,void(this._bounds=void 0);for(let t=0;t<e.length;t++){let r=xt.getCoords(e[t]),s=xt.getCoords(e[0]);if(t==e.length-1&&r[0]===s[0]&&r[1]===s[1]&&this.type===i.Path)continue;let n=Array.isArray(e[t])?this.vertexCounter++:xt.getId(e[t]),a=this._vertices.append(e[t],n);!Array.isArray(e[t])&&"number"==typeof n&&n>=this.vertexCounter&&(this.vertexCounter=n+1);for(let e of mt.styles)if(void 0!==this[e]){let t=e.replace("vx","");this._vertices.setProperty(a,t[0].toLowerCase()+t.slice(1),this[e])}t>0&&this.segments.push(new bt(a-1,a,this,this.segmentCounter++))}let t=xt.getCoords(e[0]),r=xt.getCoords(e[e.length-1]);this._vertices.length>1&&(this.closed||t[0]===r[0]&&t[1]===r[1]||this.type===i.Rect)&&(this.closed=!0,"fillColor"in this.styles||(this.styles.fillColor="#fff"),this.segments.push(new bt(this._vertices.length-1,0,this,this.segmentCounter++))),this._dirty=!0,this._updateBounds()}copyPropertiesTo(e){e.attrs=Object.assign({},this.attrs),e.styles=Object.assign({},this.styles);for(let t of mt.styles)void 0!==this["_"+t]&&(e["_"+t]=this["_"+t]);this._dataScopeRef&&(e.dataScope=this._dataScopeRef),e.closed=this.closed,e.curveMode=this.curveMode,e.vertexCounter=this.vertexCounter,e._vertices.copyFrom(this._vertices),e.segments=[],e.segmentCounter=0;for(let t=1;t<e._vertices.length;t++)e.segments.push(new bt(t-1,t,e,e.segmentCounter++));e.closed&&e.segments.push(new bt(e._vertices.length-1,0,e,e.segmentCounter++)),e._sourceAnchor=this._sourceAnchor.slice(),e._targetAnchor=this._targetAnchor.slice(),e._sourceOffset=this._sourceOffset.slice(),e._targetOffset=this._targetOffset.slice(),e._beta=this._beta}get bounds(){return this._bounds||this._updateBounds(),this._bounds}get x(){return this.bounds.x}get y(){return this.bounds.y}resize(e,t,i,r){let s=this.bounds,n=0===s.width?1:s.width,a=0===s.height?1:s.height,o=this._vertices._xs,l=this._vertices._ys;if("right"===i)for(let t=0;t<this._vertices.length;t++)o[t]=s.right-e/n*(s.right-o[t]);else for(let t=0;t<this._vertices.length;t++)o[t]=s.left+e/n*(o[t]-s.left);if("top"===r)for(let e=0;e<this._vertices.length;e++)l[e]=s.top+t/a*(l[e]-s.top);else for(let e=0;e<this._vertices.length;e++)l[e]=s.bottom-t/a*(s.bottom-l[e]);this._updateBounds(),this._dirty=!0}_updateBounds(){let t=[],r=[];if(this._d){const e=this._d.match(/[a-zA-Z][^a-zA-Z]*/g),i=" ";e.forEach(e=>{let s=e.slice(1).trim().split(i).map(Number);for(let[e,i]of s.entries())e%2==0?t.push(i):r.push(i)})}else t=this._vertices._xs,r=this._vertices._ys;let s=e.min(t),n=e.min(r),a=e.max(t),o=e.max(r),l=a-s,h=o-n;if(this._bounds=new se(s,n,l,h),this.type===i.Line||this.type===i.Path){let e=this.styles.strokeWidth?this.styles.strokeWidth:1;s===a?this._bounds=new se(s-e/2,n,a-s+e,o-n):n===o&&(this._bounds=new se(s,n-e/2,a-s,o-n+e))}}addVertex(e,t,i){void 0===i&&(i=this._vertices.length),this._vertices.insert(i,e,t,this.vertexCounter++),this._reindexSegments()}sortVertices(e,t){this._vertices.sort((t,i)=>t[e]-i[e]),t&&this._vertices.reverse();for(let e=0;e<this.segments.length;e++){let t=this.segments[e];t.vertex1=e,t.vertex2=(e+1)%this._vertices.length}this._dirty=!0}sortVerticesByData(e,t,i){let r;r=i?(t,r)=>i.indexOf(t.datum[e])-i.indexOf(r.datum[e]):(t,i)=>t.datum[e]<i.datum[e]?-1:1,this._vertices.sort(r),t&&this._vertices.reverse();for(let e=0;e<this.segments.length;e++){let t=this.segments[e];t.vertex1=e,t.vertex2=(e+1)%this._vertices.length}this._dirty=!0}getSVGPathData(){if(this._d)return this._d;if(this._vertices.length<2)return"";let t=e.path(),i=this._getD3CurveFunction(this.curveMode)(t);i.lineStart();for(let e=0;e<this._vertices.length;e++)i.point(this._vertices._xs[e],this._vertices._ys[e]);return this.closed&&i.point(this._vertices._xs[0],this._vertices._ys[0]),i.lineEnd(),t._}get firstVertex(){return this._vertices[0]}get anyVertex(){return this._anyVertexRef||(this._anyVertexRef=new mt(this,0),this._anyVertexRef._isAnyVertex=!0),this._anyVertexRef}get firstSegment(){return this.segments[0]}get lastVertex(){return this._vertices[this._vertices.length-1]}get lastSegment(){return this.segments[this.segments.length-1]}_reindexSegments(){for(let e=0;e<this.segments.length;e++)this.segments[e].vertex1=e,this.segments[e].vertex2=(e+1)%this._vertices.length}_getD3CurveFunction(t){switch(t){case Ct.Natural:return e.curveNatural;case Ct.Basis:return e.curveBasis;case Ct.BumpX:return e.curveBumpX;case Ct.BumpY:return e.curveBumpY;case Ct.Linear:return e.curveLinear;case Ct.Step:return e.curveStep;case Ct.CatmullRom:return e.curveCatmullRom;case Ct.Cardinal:return e.curveCardinal;case Ct.Bundle:return e.curveBundle.beta(.5);default:return e.curveLinear}}get vxShape(){return this._vxShape}get vxWidth(){return this._vxWidth}get vxHeight(){return this._vxHeight}get vxRadius(){return this._vxRadius}get vxFillColor(){return this._vxFillColor}get vxStrokeColor(){return this._vxStrokeColor}get vxStrokeWidth(){return this._vxStrokeWidth}get vxOpacity(){return this._vxOpacity}set vxOpacity(e){this._vxOpacity=e;for(let t of this.vertices)t.opacity=e}get sourceAnchor(){return this._sourceAnchor}get targetAnchor(){return this._targetAnchor}get sourceOffset(){return this._sourceOffset}get targetOffset(){return this._targetOffset}get strength(){return this._strength}set strength(e){this._strength=e,this._dirty=!0}get vertices(){return this._vertices}};function wt(e,t){const i=Q.getSVG();let r=document.createElementNS("http://www.w3.org/2000/svg","path");r.setAttribute("d",e.getSVGPathData()),i.appendChild(r);let s=r.getTotalLength();return r.getPointAtLength(s*t)}function Et(e){return e instanceof vt&&e.source&&e.target}const Ct={Natural:"natural",Basis:"basis",BumpX:"bumpX",BumpY:"bumpY",Bundle:"bundle",Linear:"linear",Step:"step",CatmullRom:"CatmullRom",Cardinal:"cardinal"};function At(e,t,i){const r=e.match(/[a-zA-Z][^a-zA-Z]*/g),s=",";return r.map(e=>{const r=e[0],n=e.slice(1).trim();if("M"===r||"L"===r||"T"===r){const[e,a]=n.split(s).map(Number);return`${r}${e+t} ${a+i}`}if("C"===r){const e=n.split(s).map(Number);return`${r}${e[0]+t} ${e[1]+i} ${e[2]+t} ${e[3]+i} ${e[4]+t} ${e[5]+i}`}if("Q"===r){const e=n.split(s).map(Number);return`${r}${e[0]+t} ${e[1]+i} ${e[2]+t} ${e[3]+i}`}if("A"===r){const e=n.split(s).map(Number);return`${r}${e[0]} ${e[1]} ${e[2]} ${e[3]} ${e[4]} ${e[5]+t} ${e[6]+i}`}return"Z"===r||"z"===r?r:e}).join(" ")}class St extends vt{constructor(e){super(e),this._type=i.Arc,this.closed=!0,this._x="x"in e?e.x:100,this._y="y"in e?e.y:100,this._innerRadius="innerRadius"in e?e.innerRadius:100,this._outerRadius="outerRadius"in e?e.outerRadius:200,this._thickness="thickness"in e?e.thickness:this._outerRadius-this._innerRadius,this._startAngle="startAngle"in e?e.startAngle:0,this._endAngle="endAngle"in e?e.endAngle:90,this._sr=kt(this._startAngle),this._er=kt(this._endAngle),this._direction="direction"in e?e.direction:gt.ANTI_CLOCKWISE;let t=this._x+this._innerRadius*Math.cos(this._sr),r=this._y-this._innerRadius*Math.sin(this._sr),s=this._x+this._innerRadius*Math.cos(this._er),n=this._y-this._innerRadius*Math.sin(this._er),a=this._x+this._outerRadius*Math.cos(this._sr),o=this._y-this._outerRadius*Math.sin(this._sr),l=this._x+this._outerRadius*Math.cos(this._er),h=this._y-this._outerRadius*Math.sin(this._er);this.vertices=[[t,r],[a,o],[l,h],[s,n]]}get type(){return 0===this._innerRadius?i.Pie:i.Arc}get innerRadius(){return this._innerRadius}get outerRadius(){return this._outerRadius}get thickness(){return this._outerRadius-this._innerRadius}get direction(){return this._direction}get x(){return this._x}get y(){return this._y}get startAngle(){return this._startAngle}get endAngle(){return this._endAngle}get angle(){return this._endAngle<this._startAngle?this._endAngle+360-this._startAngle:this._endAngle-this._startAngle}setAngles(e,t){this._startAngle=e,this._endAngle=t,this._sr=kt(this._startAngle),this._er=kt(this._endAngle),this.vertices[0].x=this._x+this._innerRadius*Math.cos(this._sr),this.vertices[0].y=this._y-this._innerRadius*Math.sin(this._sr),this.vertices[1].x=this._x+this._outerRadius*Math.cos(this._sr),this.vertices[1].y=this._y-this._outerRadius*Math.sin(this._sr),this.vertices[2].x=this._x+this._outerRadius*Math.cos(this._er),this.vertices[2].y=this._y-this._outerRadius*Math.sin(this._er),this.vertices[3].x=this._x+this._innerRadius*Math.cos(this._er),this.vertices[3].y=this._y-this._innerRadius*Math.sin(this._er),this._dirty=!0}_updateBounds(){let e=this.vertices.map(e=>e.x),t=this.vertices.map(e=>e.y),i=d3.min(e),r=d3.min(t),s=d3.max(e)-i,n=d3.max(t)-r;this._bounds=new se(i,r,s,n)}copyPropertiesTo(e){super.copyPropertiesTo(e),e._x=this._x,e._y=this._y,e._innerRadius=this._innerRadius,e._outerRadius=this._outerRadius,e._startAngle=this._startAngle,e._endAngle=this._endAngle,e._thickness=this._thickness,e._direction=this._direction,e._sr=this._sr,e._er=this._er}getSVGPathData(){let e=this._endAngle<this._startAngle?this._endAngle+360-this._startAngle:this._endAngle-this._startAngle,t=e>180?1:0;return["M "+this.vertices[0].x+", "+this.vertices[0].y,"L "+this.vertices[1].x+", "+this.vertices[1].y,"A "+[this._outerRadius,this._outerRadius,e,t,0,this.vertices[2].x,this.vertices[2].y].join(" "),"L "+this.vertices[3].x+", "+this.vertices[3].y,"A "+[this._innerRadius,this._innerRadius,e,t,1,this.vertices[0].x,this.vertices[0].y].join(" ")].join(" ")}}function kt(e){return e*Math.PI/180}function Rt(e){return 180*e/Math.PI}function Tt(e){return(e%360+360)%360}function Ot(e,t,i,r){let s=e-i,n=r-t;return Math.atan2(n,s)*(180/Math.PI)}class It extends vt{constructor(e){super(e),this._type=i.Area,this.closed=!0,this._orientation="orientation"in e?e.orientation:void 0,this._baseline="baseline"in e?e.baseline:void 0,e&&"vertices"in e&&this.segments.push(new bt(this.vertices.length-1,0,this,this.segmentCounter++))}get topLeftVertex(){return this._orientation===dt?this.vertices[0]:this.vertices[this.vertices.length-1]}get bottomLeftVertex(){return this._orientation===dt?this.vertices[this.vertices.length-1]:this.vertices[this.vertices.length/2]}get topRightVertex(){return this._orientation===dt?this.vertices[this.vertices.length/2-1]:this.vertices[0]}get bottomRightVertex(){return this._orientation===dt?this.vertices[this.vertices.length/2]:this.vertices[this.vertices.length/2-1]}get baseline(){return this._baseline}set baseline(e){this._baseline=e,this._dirty=!0}get orientation(){return this._orientation}set orientation(e){this._orientation=e,this._dirty=!0}get firstVertexPair(){return[this.vertices[0],this.vertices[this.vertices.length-1]]}get width(){return this.vertices[this.vertices.length/2].x-this.vertices[0].x}get height(){return this.vertices[this.vertices.length/2].y-this.vertices[0].y}get left(){return this.vertices[0].x}get top(){return this.vertices[0].y}copyPropertiesTo(e){super.copyPropertiesTo(e),e._baseline=this._baseline,e._orientation=this._orientation}getSVGPathData(){return super.getSVGPathData()+" z"}}class Nt extends vt{constructor(e){super(e),this._type=i.BezierCurve,this._orientation="orientation"in e?e.orientation:dt}get type(){return this._type}get orientation(){return this._orientation}copyPropertiesTo(e){super.copyPropertiesTo(e),e._orientation=this._orientation}getSVGPathData(){if(this._d)return this._d;let e="M ";return e+=this.vertices[0].x+" "+this.vertices[0].y+" ",e+="C "+this.vertices[1].x+" "+this.vertices[1].y+" ",e+=this.vertices[2].x+" "+this.vertices[2].y+" ",e+=this.vertices[3].x+" "+this.vertices[3].y,e}}class Lt extends ce{constructor(e){super(e),this._type=i.Circle,this._x="x"in e?e.x:0,this._y="y"in e?e.y:0,this._radius="radius"in e?e.radius:100,"strokeColor"in this.styles||(this.styles.strokeColor="#ccc"),"fillColor"in this.styles||(this.styles.fillColor="none"),"strokeWidth"in this.styles||(this.styles.strokeWidth=1),"strokeDash"in this.styles||(this.styles.strokeDash="none")}set x(e){this._x=e,this._dirty=!0}set y(e){this._y=e,this._dirty=!0}get x(){return this._x}get y(){return this._y}get radius(){return this._radius}set radius(e){this._radius=e,this._dirty=!0}get area(){return Math.PI*Math.pow(this._radius,2)}_updateBounds(){if(this._rotate){let e=ee(this._x,this._y,this._rotate[1],this._rotate[2],this._rotate[0]);this._bounds=new se(e.x-this._radius,e.y-this._radius,2*this._radius,2*this._radius)}else this._bounds=new se(this._x-this._radius,this._y-this._radius,2*this._radius,2*this._radius)}copyPropertiesTo(e){super.copyPropertiesTo(e),e._x=this._x,e._y=this._y,e._radius=this._radius}getSVGPathData(){return["M",this._x,this._y,"m",-this._radius,", 0 a",this._radius,",",this._radius,"0 1,0",2*this._radius,",0 a",this._radius,",",this._radius,"0 1,0",-2*this._radius,",0"].join(" ")}}class Pt extends ce{constructor(e){super(e),this._type=i.Image,this._src=e.src,this._x="x"in e?e.x:0,this._y="y"in e?e.y:0,this._width="width"in e?e.width:100,this._height="height"in e?e.height:100}get src(){return this._src}set src(e){this._src=e,this._dirty=!0}get width(){return this._width}set width(e){this._width=e,this._updateBounds(),this._dirty=!0}get height(){return this._height}set height(e){this._height=e,this._updateBounds(),this._dirty=!0}resize(e,t){this._width=e,this._height=t,this._dirty=!0,this._updateBounds()}get x(){return this._x}set x(e){this._x=e,this._dirty=!0,this._updateBounds()}get y(){return this._y}set y(e){this._y=e,this._dirty=!0,this._updateBounds()}get bounds(){return this._bounds||this._updateBounds(),this._bounds}_updateBounds(){this._bounds=new se(this._x,this._y,this._width,this._height)}copyPropertiesTo(e){e.attrs=Object.assign({},this.attrs),e.styles=Object.assign({},this.styles),this._dataScopeRef&&(e.dataScope=this._dataScopeRef),e.x=this._x,e.y=this._y,e.width=this._width,e.height=this._height,e.src=this._src}}class Vt extends vt{constructor(e){super(e)}get x1(){return this.vertices[0].x}get y1(){return this.vertices[0].y}get x2(){return this.vertices[1].x}get y2(){return this.vertices[1].y}get x(){return(this.vertices[0].x+this.vertices[1].x)/2}get y(){return(this.vertices[0].y+this.vertices[1].y)/2}set x(e){let t=e-this.x;this.vertices[0].x+=t,this.vertices[1].x+=t,this._dirty=!0}set y(e){let t=e-this.y;this.vertices[0].y+=t,this.vertices[1].y+=t,this._dirty=!0}set x1(e){this.vertices[0].x=e,this._dirty=!0}set x2(e){this.vertices[1].x=e,this._dirty=!0}set y1(e){this.vertices[0].y=e,this._dirty=!0}set y2(e){this.vertices[1].y=e,this._dirty=!0}}const Dt="filled",Bt="none";class Mt extends vt{constructor(e={}){const t="x1"in e?e.x1:0,r="y1"in e?e.y1:0,s="x2"in e?e.x2:100,n="y2"in e?e.y2:0,a=[[t,r],...e.controlPoints||[],[s,n]];super({...e,type:i.Arrow,vertices:a}),this._startStyle=e.startStyle??Bt,this._startSize=e.startSize??8,this._endStyle=e.endStyle??Dt,this._endSize=e.endSize??8}get x1(){return this.vertices[0].x}set x1(e){this.vertices[0].x=e,this._dirty=!0}get y1(){return this.vertices[0].y}set y1(e){this.vertices[0].y=e,this._dirty=!0}get x2(){return this.vertices[this.vertices.length-1].x}set x2(e){this.vertices[this.vertices.length-1].x=e,this._dirty=!0}get y2(){return this.vertices[this.vertices.length-1].y}set y2(e){this.vertices[this.vertices.length-1].y=e,this._dirty=!0}get startStyle(){return this._startStyle}set startStyle(e){this._startStyle=e,this._dirty=!0}get startSize(){return this._startSize}set startSize(e){this._startSize=e,this._dirty=!0}get endStyle(){return this._endStyle}set endStyle(e){this._endStyle=e,this._dirty=!0}get endSize(){return this._endSize}set endSize(e){this._endSize=e,this._dirty=!0}}class Gt extends ce{constructor(e){super(e),this._type=i.SimpleText,this._x="x"in e?e.x:0,this._y="y"in e?e.y:0,this._text="text"in e?e.text:"",this._anchor="anchor"in e?e.anchor:[he.CENTER,he.MIDDLE],this._textPath=void 0,this._textPathOffset="50%","fontSize"in this.styles||(this.styles.fontSize="12px"),"fontFamily"in this.styles||(this.styles.fontFamily="Arial, sans-serif"),"fontWeight"in this.styles||(this.styles.fontWeight="normal"),"fillColor"in this.styles||(this.styles.fillColor="black"),"backgroundColor"in e&&(this._backgroundColor=e.backgroundColor),"borderWidth"in e&&(this._borderWidth=e.borderWidth),"borderColor"in e&&(this._borderColor=e.borderColor),this._rotate="rotate"in e?e.rotate:void 0}hasBackground(){return this._backgroundColor||this._borderStroke||this._borderColor}_updateBounds(){let e,t,i=function(e,t,i){const r=Q.getSVG(),s=document.createElementNS("http://www.w3.org/2000/svg","text");s.setAttribute("font-family",t),s.setAttribute("font-size",i),s.textContent=e,r.appendChild(s);const n=s.getBBox();return r.removeChild(s),{width:n.width,height:n.height}}(this._text,[this.fontWeight,this.fontSize,this.fontFamily].join(" "),parseFloat(this.fontSize)),r=i.width,s=i.height;switch(this._anchor[0]){case he.LEFT:e=this._x;break;case he.RIGHT:e=this._x-r;break;case he.CENTER:e=this._x-r/2;break;default:e=this._x}switch(this._anchor[1]){case he.TOP:t=this._y;break;case he.BOTTOM:t=this._y-s;break;case he.MIDDLE:default:t=this._y-s/2}if(this._rotate&&3===this._rotate.length){let i=[{x:e,y:t},{x:e+r,y:t},{x:e,y:t+s},{x:e+r,y:t+s}].map(e=>ee(e.x,e.y,this._rotate[1],this._rotate[2],this._rotate[0])),n=d3.min(i.map(e=>e.x)),a=d3.max(i.map(e=>e.x)),o=d3.min(i.map(e=>e.y)),l=d3.max(i.map(e=>e.y));this._bounds=new se(n,o,a-n,l-o)}else this._bounds=new se(e,t,r,s)}get x(){return this._x}set x(e){this._x=e,this._dirty=!0}get y(){return this._y}set y(e){this._y=e,this._dirty=!0}get text(){return this._text}set text(e){this._text=e,this._dirty=!0}get anchor(){return this._anchor}get fontFamily(){return this.styles.fontFamily}get fontSize(){return this.styles.fontSize}get fontWeight(){return this.styles.fontWeight}set fontWeight(e){this.styles.fontWeight=e,this._dirty=!0}get textPath(){return this._textPath}set textPath(e){this._textPath=e,this._dirty=!0}get textPathOffset(){return this._textPathOffset}set textPathOffset(e){this._textPathOffset=e,this._dirty=!0}get backgroundColor(){return this._backgroundColor?this._backgroundColor:"#fff"}get borderColor(){return this._borderColor?this._borderColor:"#ccc"}get borderWidth(){return this._borderWidth?this._borderWidth:1}copyPropertiesTo(e){e.styles=Object.assign({},this.styles),this._dataScopeRef&&(e.dataScope=this._dataScopeRef),e._x=this._x,e._y=this._y,e._text=this._text,e._anchor=[this._anchor[0],this._anchor[1]],e._backgroundColor=this._backgroundColor,e._borderColor=this._borderColor,e._borderStroke=this._borderStroke}}class zt extends vt{constructor(e){super(e),this._type=i.Polygon,this.closed=!0,"x"in e&&(this._x=e.x),"y"in e&&(this._y=e.y),"radius"in e&&(this._radius=e.radius)}get radius(){return this._radius}get x(){return this._x}get y(){return this._y}set x(e){this._x=e,this._dirty=!0}set y(e){this._y=e,this._dirty=!0}set radius(e){this._radius=e,this._dirty=!0}copyPropertiesTo(e){super.copyPropertiesTo(e),e._x=this._x,e._y=this._y,e._radius=this._radius}}class Ft extends vt{constructor(e){super(e)}get width(){return this.vertices[1].x-this.vertices[0].x}get height(){return this.vertices[2].y-this.vertices[1].y}get left(){return this.vertices[0].x}get top(){return this.vertices[0].y}get right(){return this.vertices[1].x}get bottom(){return this.vertices[2].y}get area(){return this.width*this.height}setBounds(e,t,i,r){this.vertices[0].x=e,this.vertices[0].y=t,this.vertices[1].x=e+i,this.vertices[1].y=t,this.vertices[2].x=e+i,this.vertices[2].y=t+r,this.vertices[3].x=e,this.vertices[3].y=t+r,this._dirty=!0}resize(e,t,i,r){e!==this.width&&("right"===i?(this.vertices[1].x=this.refBounds.right,this.vertices[2].x=this.refBounds.right,this.vertices[0].x=this.vertices[1].x-e,this.vertices[3].x=this.vertices[0].x):(this.vertices[0].x=this.refBounds.left,this.vertices[3].x=this.refBounds.left,this.vertices[1].x=this.vertices[0].x+e,this.vertices[2].x=this.vertices[1].x)),t!==this.height&&("top"===r?(this.vertices[0].y=this.refBounds.top,this.vertices[1].y=this.refBounds.top,this.vertices[3].y=this.vertices[0].y+t,this.vertices[2].y=this.vertices[3].y):(this.vertices[2].y=this.refBounds.bottom,this.vertices[3].y=this.refBounds.bottom,this.vertices[0].y=this.vertices[3].y-t,this.vertices[1].y=this.vertices[0].y)),this._dirty=!0}get leftSegment(){return this.segments[3]}get rightSegment(){return this.segments[1]}get topSegment(){return this.segments[0]}get bottomSegment(){return this.segments[2]}}class jt extends vt{constructor(e){super(e),this._type=i.Ring,this.closed=!0,this._x="x"in e?e.x:0,this._y="y"in e?e.y:0,this._innerRadius="innerRadius"in e?e.innerRadius:100,this._outerRadius="outerRadius"in e?e.outerRadius:200}get innerRadius(){return this._innerRadius}get outerRadius(){return this._outerRadius}get x(){return this._x}get y(){return this._y}get thickness(){return this._outerRadius-this._innerRadius}copyPropertiesTo(e){super.copyPropertiesTo(e),e._x=this._x,e._y=this._y,e._innerRadius=this._innerRadius,e._outerRadius=this._outerRadius}getSVGPathData(){return["M "+this._x+" "+this._y,"m 0, -"+this._outerRadius,"a "+this._outerRadius+","+this._outerRadius+", 0, 1, 0, 1, 0","Z","m 0 "+(this._outerRadius-this._innerRadius),"a "+this._innerRadius+", "+this._innerRadius+", 0, 1, 1, -1, 0","Z"].join(" ")}}class Wt extends ce{constructor(e){super(e),this._type=i.RichText,this._x="x"in e?e.x:0,this._y="y"in e?e.y:0,this._text="text"in e?e.text:"",this._width="width"in e?e.width:200,this._anchor="anchor"in e?e.anchor:[he.CENTER,he.MIDDLE],"fontSize"in this.styles||(this.styles.fontSize="12px"),"fontFamily"in this.styles||(this.styles.fontFamily="Arial, sans-serif"),"fontWeight"in this.styles||(this.styles.fontWeight="normal"),"fillColor"in this.styles||(this.styles.fillColor="black"),"backgroundColor"in e&&(this._backgroundColor=e.backgroundColor),"borderWidth"in e&&(this._borderWidth=e.borderWidth),"borderColor"in e&&(this._borderColor=e.borderColor),this._rotate="rotate"in e?e.rotate:void 0}hasBackground(){return this._backgroundColor||this._borderStroke||this._borderColor}_updateBounds(){let e,t,i=function(e,t,i){const r=Q.getSVG(),s=document.createElementNS("http://www.w3.org/2000/svg","text");s.setAttribute("font-family",t),s.setAttribute("font-size",i),s.textContent=e,r.appendChild(s);const n=s.getBBox();return r.removeChild(s),{width:n.width,height:n.height}}(this._text,[this.fontWeight,this.fontSize,this.fontFamily].join(" "),parseFloat(this.fontSize)),r=i.width,s=i.height;switch(this._anchor[0]){case he.LEFT:e=this._x;break;case he.RIGHT:e=this._x-r;break;case he.CENTER:e=this._x-r/2;break;default:e=this._x}switch(this._anchor[1]){case he.TOP:t=this._y;break;case he.BOTTOM:t=this._y-s;break;case he.MIDDLE:default:t=this._y-s/2}if(this._rotate&&3===this._rotate.length){let i=[{x:e,y:t},{x:e+r,y:t},{x:e,y:t+s},{x:e+r,y:t+s}].map(e=>ee(e.x,e.y,this._rotate[1],this._rotate[2],this._rotate[0])),n=d3.min(i.map(e=>e.x)),a=d3.max(i.map(e=>e.x)),o=d3.min(i.map(e=>e.y)),l=d3.max(i.map(e=>e.y));this._bounds=new se(n,o,a-n,l-o)}else this._bounds=new se(e,t,r,s)}get x(){return this._x}get y(){return this._y}set x(e){this._x=e,this._dirty=!0}set y(e){this._y=e,this._dirty=!0}get text(){return this._text}set text(e){this._text=e,this._dirty=!0}get anchor(){return this._anchor}get fontFamily(){return this.styles.fontFamily}get fontSize(){return this.styles.fontSize}get fontWeight(){return this.styles.fontWeight}get textPath(){return this._textPath}set textPath(e){this._textPath=e,this._dirty=!0}get textPathOffset(){return this._textPathOffset}set textPathOffset(e){this._textPathOffset=e,this._dirty=!0}get backgroundColor(){return this._backgroundColor?this._backgroundColor:"#fff"}get borderColor(){return this._borderColor?this._borderColor:"#ccc"}get borderWidth(){return this._borderWidth?this._borderWidth:1}get width(){return this._width}copyPropertiesTo(e){e.styles=Object.assign({},this.styles),this._dataScopeRef&&(e.dataScope=this._dataScopeRef),e._x=this._x,e._y=this._y,e._text=this._text,e._anchor=[this._anchor[0],this._anchor[1]],e._backgroundColor=this._backgroundColor,e._borderColor=this._borderColor,e._borderStroke=this._borderStroke}}class Yt{constructor(e){let t=e||{};this._stops=[],this.type=i.LinearGradient,this.id=this.type+s(),this.x1="x1"in t?t.x1:0,this.x2="x2"in t?t.x2:100,this.y1="y1"in t?t.y1:0,this.y2="y2"in t?t.y2:0}toJSON(){let e={};return e.type=this.type,e.id=this.id,e.x1=this.x1,e.x2=this.x2,e.y1=this.y1,e.y2=this.y2,e.stops=this._stops,e}addStop(e,t,i){this._stops.push({offset:e,color:t,opacity:i})}get stops(){return this._stops}}function Ut(t,i,r,s){let n,a=t.domain,o=t.range;switch(t.type){case"linear":case"log":{let l=Math.abs(o[0]-o[1]);n="width"==i||"x"==i?45:30;let h,c=Math.max(2,Math.floor(l/n));if("width"==i||"height"==i){let e=!!s&&(s.elements[0].parent.layout&&s.elements[0].parent.layout.type==fe.STACK);a[1]=t._scale.invert(e?oe(r)[i]:ae(r)[i])}if("log"===t.type){h=[];let e=t._scale.ticks();for(let t of e){let i=Math.log(t)/Math.log(10)+1e-6;Math.abs(i-Math.floor(i))<c/e.length&&h.push(t)}}else h=e.ticks(a[0],a[1],c);return h}case"point":{n="width"==i||"x"==i?80:30;let e=Math.floor(t.rangeExtent/a.length),r=Math.ceil(n/e);return"x"==i?a.filter((e,t)=>t%r==0):a}case"band":{n="width"==i||"x"==i?80:30;let e=Math.floor(t.rangeExtent/a.length),r=Math.max(1,Math.ceil(n/e));return a.filter((e,t)=>t%r==0)}case"time":{n="width"==i||"x"==i?80:30;let t,r,s=Math.floor((o[1]-o[0])/n),l=Math.ceil((a[1]-a[0])/s)/1e3,h=[1,60,3600,86400,2628003,31536e3],c=[e.timeSeconds,e.timeMinutes,e.timeHours,e.timeDays,e.timeMonths,e.timeYears];for(let e=0;e<h.length-1;e++)if(l>=h[e]&&l<h[e+1])return t=Math.floor(l/h[e]),r=c[e],r(a[0],a[1],t);return l>h[h.length-1]?(t=Math.floor(l/h[h.length-1]),r=c[h.length-1],r(a[0],a[1],t)):[]}default:return[]}}function Ht(e,t){t.removeChild(e)}class Xt extends nt{constructor(e){super(),this._type=i.Axis,this._id=e.id?e.id:this._type+s(),this._attribute=void 0,this._channel=void 0,this._orientation=void 0,this._strokeColor="strokeColor"in e?e.strokeColor:"#555",this._textColor="textColor"in e?e.textColor:"#555",this._fontSize="fontSize"in e?e.fontSize:"12px",this._tickOffset="tickOffset"in e?e.tickOffset:0,this._tickSize="tickSize"in e?e.tickSize:5,this._tickAnchor=e.tickAnchor,this._tickVisible=!("tickVisible"in e)||e.tickVisible,this._pathVisible=!("pathVisible"in e)||e.pathVisible,this._labelVisible=!("labelVisible"in e)||e.labelVisible,this._labelOffset="labelOffset"in e?e.labelOffset:this._tickSize+this._tickOffset+3,this._labelFormat="labelFormat"in e?e.labelFormat:"",this._titleOffset="titleOffset"in e?e.titleOffset:40,this._rotateYTitle=!("rotateTitle"in e&&!e.rotateTitle),this._showTitle=!("titleVisible"in e)||e.titleVisible,this._labelRotation="labelRotation"in e?e.labelRotation:0,this._ticks=new nt,this._ticks._id=this._id+"_ticks",this.addChild(this._ticks),this._labels=new nt,this._labels._id=this._id+"_labels",this.addChild(this._labels),this._title=new Gt({text:this._titleText,fillColor:this._textColor,fontWeight:"bold"}),this._title._id=this.id+"_title",this.addChild(this._title),this._showTitle||(this._title.visibility="hidden"),this._pathPos=void 0,this._args=e}get id(){return this._id}get pathPosition(){return this._pathPos}get pathVisible(){return this._pathVisible}get attribute(){return this._attribute}get channel(){return this._channel}get orientation(){return this._orientation}get ticksVisible(){return this._tickVisible}get labelsVisible(){return this._labelVisible}get tickSize(){return this._tickSize}get tickOffset(){return this._tickOffset}get tickAnchor(){return this._tickAnchor?this._tickAnchor:"x"===this._channel||"width"===this._channel?"center":"middle"}get labelOffset(){return this._labelOffset}get labelFormat(){return this._labelFormat}get labelRotation(){return this._labelRotation}get tickValues(){return this._tickValues}get labelValues(){return this._labelValues}get titleOffset(){return this._titleOffset}get titleVisisble(){return this._showTitle}get boundsWithoutTitle(){let e=this.children.filter(e=>e.type!==i.SimpleText),t=e[0].bounds.clone();for(let i=1;i<e.length;i++)"hidden"!=e[i].visibility&&(t=t.union(e[i].bounds));return t}get strokeColor(){return this._strokeColor}get textColor(){return this._textColor}}const qt="top",Kt="bottom",Zt="left";class $t extends Xt{constructor(e,t,i,r){super(r),this._encoding=e,this._attribute=this._encoding.attribute,this._channel=this._encoding.channel,this._scale=t,this._elems=i,this._flip="flip"in r&&r.flip,this._posArg="x"==this._channel||"width"==this._channel?r.pathY:r.pathX,this._orientation="orientation"in r?r.orientation:"x"===this._channel||"width"==this._channel?Kt:Zt,this._titleText="title"in r?r.title:this._encoding.sourceAttribute??this._encoding.attribute,this._path="angle"===this._channel?new Lt({strokeColor:this._strokeColor,id:this._id+"_path"}):new vt({strokeColor:this._strokeColor,id:this._id+"_path"}),this._pathVisible||(this._path.visibility="hidden"),this.addChild(this._path),this.createTicksLabels(r),e.dataTable.type(this._attribute)!==a.Date||"labelFormat"in r||(this._labelFormat="%m/%d/%y"),"radialDistance"===this._channel&&"rotation"in r&&(this._rotate=[-r.rotation,this._elems[0].parent.x,this._elems[0].parent.y])}isFlipped(){return this._flip}get elements(){return this._elems}get scale(){return this._scale}get encoding(){return this._encoding}get includeZero(){return this._encoding.includeZero}createTicksLabels(t){"tickValues"in t?(this._tickValues=t.tickValues,this._labelValues=t.tickValues):(this._tickValues=Ut(this._scale,this._channel,this._elems,this),this._labelValues=this._tickValues),this._ticks.removeAll();for(let e=0;e<this._tickValues.length;e++){let t=new vt({strokeColor:this._strokeColor,id:this._id+"_tick"+e});this._tickVisible||(t.visibility="hidden"),this._ticks.addChild(t)}let i;switch(this._labels.removeAll(),this._encoding.dataTable.type(this._attribute)){case a.Date:i=e.utcFormat(this._labelFormat);break;case a.String:i=function(e){return e};break;default:i=e.format(this._labelFormat)}for(let[e,t]of this._labelValues.entries()){let r=new Gt({text:i(t),fontSize:this._fontSize,fillColor:this._textColor,id:this._id+"_label"+e});this._labelVisible||(r.visibility="hidden"),this._labels.addChild(r)}this._title._text=this._titleText}}class Jt{constructor(t,i){switch(this._id="scale_"+s(),this._type=t,i&&(this._args=i),t){case"linear":this._scale=e.scaleLinear();break;case"point":this._scale=e.scalePoint();break;case"band":this._scale=e.scaleBand().padding(0);break;case"ordinal":this._scale=e.scaleOrdinal();break;case"ordinalColor":this._scale=e.scaleOrdinal(e[i.scheme]);break;case"power":this._scale=e.scalePow().exponent(2);break;case"sqrt":this._scale=e.scalePow().exponent(.5);break;case"log":this._scale=e.scaleLog();break;case"identity":case"time":this._scale=e.scaleTime();break;case"sequentialColor":i.scheme?this._scale=e.scaleSequential(e[i.scheme]):this._scale=e.scaleSequential()}}get id(){return this._id}get domain(){return this._scale.domain()}set domain(e){this._scale.domain(e)}get range(){return this._scale.range()}set range(e){this._scale.range(e)}get rangeExtent(){let e=this._scale.range();return Math.abs(e[1]-e[0])}set rangeExtent(e){let t=this._scale.range();t[0]<t[1]?this._scale.range([t[0],t[0]+e]):this._scale.range([t[1]+e,t[1]])}get type(){return this._type}map(e){return this._scale(e)}invert(t,i){let r=e.min(this._scale.range()),s=e.max(this._scale.range()),n=t;if(i||(n=e.max([r,e.min([t,s])])),"time"===this._type)return this._scale.invert(n).getTime();if(["point","band","ordinal","ordinalColor"].includes(this._type)){return this._scale.domain().reduce((e,t)=>{let i=this._scale(t);"band"===this._type&&(i+=this._scale.bandwidth()/2);let r=this._scale(e);return"band"===this._type&&(r+=this._scale.bandwidth()/2),Math.abs(i-n)<Math.abs(r-n)?t:e})}return this._scale.invert(n)}}function Qt(e){if(e.scaleType)return new Jt(e.scaleType);if(e._baseEnc&&e._baseEnc.scales.length>0){let t=e._baseEnc.scales[0];return new Jt(t.type,t._args)}if("text"===e.channel||"src"===e.channel)return new Jt("ordinal");switch(e.dataTable.type(e.attribute)){case a.Boolean:break;case a.Date:return new Jt("time");case a.String:if("count"==e.aggregator)return new Jt("linear");if(e.channel.indexOf("Color")>=0){let t={};return t.scheme=e.colorScheme?e.colorScheme:"schemeCategory10",new Jt("ordinalColor",t)}return new Jt("point");default:return["strokeColor","fillColor","fillGradient"].indexOf(e.channel)>=0?e.mapping?new Jt("linear"):new Jt("sequentialColor",{scheme:e.colorScheme}):new Jt("linear")}}const ei=["schemeBrBG","schemePRGn","schemePiYG","schemePuOr","schemeRdBu","schemeRdGy","schemeRdYlBu","schemeRdYlGn","schemeSpectral"],ti=["schemeBlues","schemeGreens","schemeGreys","schemeOranges","schemePurples","schemeReds","schemeBuGn","schemeBuPu","schemeGnBu","schemeOrRd","schemePuBuGn","schemePuBu","schemePuRd","schemeRdPu","schemeYlGnBu","schemeYlGn","schemeYlOrBr","schemeYlOrRd"];function ii(e,t){let i=t||Ie(e.element);delete i._encodings[oi(e.element)][e.channel],console.log("remove encoding",e.channel,e.attribute),function(e,t){let i=t.findVariable(xe.CHANNEL,[e.channel,e.element]);i||console.warn("cannot find encoding to remove from the dep graph");let r=i.incomingDataflow;t.deleteOperator(r)}(e,i._depGraph);for(let t of e.refElements)Ht(t,i),Ye(t,i._depGraph);e.clearRefElements()}function ri(e,t){let i=e.scene._encodings[oi(e)],r=[];if(i&&(r=r.concat(Object.values(i))),t){let t=e.scene;for(let i in t._encodings){let s=i.split("_");s.pop(),s.join("_")===e.classId&&(r=r.concat(Object.values(t._encodings[i])))}}return r}function si(e,t){let i=[];for(let r in t._encodings)for(let s in t._encodings[r])s===e&&i.push(t._encodings[r][s]);return i}function ni(e,t,i){for(let r in i._encodings){let s=i._encodings[r];if(s[t]&&s[t].attribute==e)return s[t]}return null}function ai(e,t){let i=e.scene._encodings[oi(e)];return i&&i[t]?i[t]:null}function oi(e){if(Array.isArray(e))return e.map(e=>oi(e)).join("_");if(e.classId)return e.classId;if("vertex"==e.type&&e._isAnyVertex)return e.parent.classId+"_vAny";if("vertex"==e.type&&e.dataScope){if(e.parent.type===i.Area){let t=e._index<e.parent._vertices.length/2;return e.parent.classId+"_v"+(t?0:e.parent._vertices.length-1)}return e.parent.classId+"_v"}return"vertex"==e.type?e.parent.classId+"_v"+e._index:"segment"==e.type&&e._dataScopeRef?e.parent.classId+"_s":"segment"==e.type?e.parent.classId+"_s"+e.parent.segments.indexOf(e):null}function li(e,t){if(0==e.children.length)return[];let r=Ie(e),s=e.type===i.Composite?e.children:[e.children[0]],n=Object.keys(r._encodings),a=[];for(let e of s){let t=e;for(;t;){if(t.classId&&a.indexOf(t.classId)<0&&a.push(t.classId),t.type===i.Glyph){t.children.forEach(e=>a.push(e.classId));break}if(!t.children)break;t=t.children[0]}}let o=[];for(let e of n)for(let i of a)0===e.indexOf(i)&&r._encodings[e][t]&&o.push(r._encodings[e][t]);return o}function hi(e){let t=ai(e,"y"),i=ai(e,"height");return t||i&&i.scales[0].domain[0]<0}function ci(e){let t=ai(e,"x"),i=ai(e,"width");return t||i&&i.scales[0].domain[0]<0}function di(e,t){return"x"===t||"width"===t?ci(e):"y"===t||"height"===t?hi(e):null!==ai(e,t)}class ui extends vt{constructor(e,t,r,n,a){super(a),this._type=i.Gridlines,this._id=this._type+s(),this._attribute=t,this._channel=e,this._scale=r,this._elems=n,this._args=a,"strokeColor"in a||(this.styles.strokeColor="#ddd"),"opacity"in a||(this.styles.opacity=.5),this.updateValues(),this._lines=[]}updateValues(){"values"in this._args?this._values=this._args.values:this._scale?this._values=Ut(this._scale,this._channel,this._elems):this._values=this._elems.map(e=>e.datum[this._attribute])}get type(){return this._type}get id(){return this._id}getSVGPathData(){let e="";if("radialDistance"===this._channel)for(let t of this._lines)e+="M "+t.x+" "+t.y+" m -"+t.r+" 0 a "+t.r+" "+t.r+" 0 1 0 "+2*t.r+" 0 a "+t.r+" "+t.r+" 0 1 0 -"+2*t.r+" 0 ";else for(let t of this._lines)e+=["M",t.x1,t.y1].join(" ")+[" L",t.x2,t.y2].join(" ")+" ";return e}_updateBounds(){if("radialDistance"===this._channel){let e=this._lines.map(e=>new se(e.x-e.r,e.y-e.y,2*e.r,2*e.r));this._bounds=ne(e)}else{let e=this._lines.map(e=>e.x1).concat(this._lines.map(e=>e.x2)),t=this._lines.map(e=>e.y1).concat(this._lines.map(e=>e.y2)),i=d3.min(e),r=d3.max(e),s=d3.min(t),n=d3.max(t);this._bounds=new se(i,s,r-i,n-s)}}get elements(){return this._elems}get values(){return this._values}get channel(){return this._channel}get attribute(){return this._attribute}get scale(){return this._scale}get lines(){return this._lines}set lines(e){this._lines=e}}class _i{constructor(e,t,i,r,n){this._id="encoding_"+s(),this._elem=e,this._channel=t,this._attribute=i,this._table=n.table,this._aggregator=r,this._includeZero=n.includeZero,this._flipScale=n.flipScale,this._mapping=n.mapping,this._preferredRangeExtent=n.rangeExtent,this._preferredRangeStart=n.rangeStart,this._preferredDomain=n.domain,this._scaleType=n.scaleType,this._colorScheme=n.scheme,this._forLegend=n.forLegend,this._sourceAttribute=n.sourceAttribute??null,n.shareScale&&(this._baseEnc=n.shareScale),this._scales=[],this._elemGroups=[],this._elem2scale={},this._refElements=[],["width","height","radius","angle","thickness","radialDistance","strokeWidth","area"].indexOf(this._channel)>=0&&(this._includeZero=!0),this.initialize()}get id(){return this._id}initialize(){if(this._scales=[],this._elemGroups=[],"vertex"===this._elem.type){let e,t=Ne(this._elem),i=we(this._elem.parent);if("x"!==this._channel&&"y"!==this._channel||!t.layout||t.layout.type!=fe.GRID)e=ci(this._elem.parent)||hi(this._elem.parent)?i.map(e=>Ae(this._elem,[e])):[Ae(this._elem,i)];else{e=("x"===this._channel?t.layout.getElementsByCol(!0,this._elem.parent):t.layout.getElementsByRow(!0,this._elem.parent)).map(e=>Ae(this._elem,e))}for(let t of e)this._createScaleForVertexIndices(t)}else if("x"===this._channel||"y"===this._channel){let e=this._elem,t=Ne(e);if(t.layout&&t.layout.type==fe.GRID){let i="x"===this._channel?t.layout.getElementsByCol(!0,e):t.layout.getElementsByRow(!0,e);for(let e of i)this._createScaleForElems(e)}else{let e=we(this._elem);this._createScaleForElems(e)}}else if("angle"===this._channel){let e=we(this._elem).reduce((e,t)=>{const i=t.parent.id;return e[i]||(e[i]=[]),e[i].push(t),e},{}),t=Object.values(e);for(let e of t)this._createScaleForElems(e)}else{let e=we(this._elem);this._createScaleForElems(e)}}_createScaleForElems(e){this._elemGroups.push(e);var t=Qt(this);this._scales.push(t);for(let i of e)this._elem2scale[i.id]=t}_createScaleForVertexIndices(e){this._elemGroups.push({type:"vertexIndices",groups:e});var t=Qt(this);this._scales.push(t);for(let i of e)for(let e of i.indices)this._elem2scale[Ce(i.parent,e)]=t}refreshElementMappings(){if(1===this._scales.length)if(this._elem2scale={},"vertex"===this._elem.type){let e=we(this._elem.parent),t=Ae(this._elem,e);this._elemGroups=[{type:"vertexIndices",groups:t}];for(let e of t)for(let t of e.indices)this._elem2scale[Ce(e.parent,t)]=this._scales[0]}else{let e=we(this._elem);this._elemGroups=[e];for(let t of e)this._elem2scale[t.id]=this._scales[0]}}getScale(e){return this._elem2scale[e.id]}getAttrValue(t,i,r){let s=(i?this.getScale(i):this._scales[0]).invert(t,r),n=this._attribute;if(this.dataTable.type(n)===a.Date){const t=this.dataTable.values(n).slice().sort((e,t)=>e-t);let i=e.bisectLeft(t,s);return i=Math.min(i,t.length-1),i>0&&Math.abs(t[i-1]-s)<Math.abs(t[i]-s)&&i--,t[i]}return s}getChannelValue(e,t){return(t?this.getScale(t):this._scales[0]).map(e)}getElements(e){let t=this._scales.indexOf(e);return this._elemGroups[t]}getNormalizedElements(e){let t=this.getElements(e);return t&&"vertexIndices"===t.type?Array.from(new Set(t.groups.map(e=>e.parent))):t}get elementGroups(){return this._elemGroups}get element(){return this._elem}get channel(){return this._channel}get attribute(){return this._attribute}get sourceAttribute(){return this._sourceAttribute}set attribute(e){let t=this._attribute;this._attribute=e;for(let t of this._refElements)t instanceof $t?(t._attribute=e,t.createTicksLabels({}),t._titleText&&(t._titleText=this._sourceAttribute??e)):t instanceof ui&&(t._attribute=e,t.updateValues());const i=this._elem.scene._depGraph.getVariable(xe.ATTRIBUTE,t,this.dataTable,this);i&&(i._attribute=e,this._elem.scene.onChange(xe.ATTRIBUTE,e,this.dataTable,this))}get dataTable(){return this._table}get aggregator(){return this._aggregator}hasMultipleScales(){return this._scales.length>0}get scales(){return this._scales}getRangeStart(t){let i=this.getScale(t);return e.min(i.range)}getRangeExtent(e){return this.getScale(e).rangeExtent}get domain(){if(1===this._scales.length)return this._scales[0].domain;throw new Error("AttributeEncoding: multiple scales exist, specify element to get domain.")}get rangeExtent(){if(1===this._scales.length)return this._scales[0].rangeExtent;throw new Error("AttributeEncoding: multiple scales exist, specify element to get rangeExtent.")}get scaleType(){return this._scaleType}set scaleType(e){this._scaleType=e}getDomain(e){return this.getScale(e).domain}set domain(e){this._preferredDomain=e;for(let t of this._scales)t._scale.domain(e);for(let e of this._refElements)e instanceof $t&&e.createTicksLabels({});this._elem.scene.onChange(xe.ATTR_VALUE,this)}set rangeExtent(e){let t=e<1?1:Math.round(e);for(let e of this._scales)e.rangeExtent=t;for(let e of this._refElements)e instanceof $t&&e.createTicksLabels({});this._elem.scene.onChange(xe.PROPERTY,ze.RANGE_EXTENT,this)}set includeZero(e){this._includeZero=e;for(let e of this._refElements)e instanceof $t&&e.createTicksLabels({});this._elem.scene.onChange(xe.PROPERTY,ze.INCLUDE_ZERO,this)}get includeZero(){return this._includeZero}set flipScale(e){this._flipScale=e,this._elem.scene.onChange(xe.PROPERTY,ze.FLIP_SCALE,this)}get flipScale(){return this._flipScale}set mapping(e){this._mapping=e}get mapping(){return this._mapping}set colorScheme(e){this._colorScheme=e}get colorScheme(){return this._colorScheme}addRefElement(e){this._refElements.indexOf(e)<0&&this._refElements.push(e)}get refElements(){return this._refElements}clearRefElements(){this._refElements=[]}zoom(t,i,r,s){let n=s||this._elem,a=this.getDomain(n),o=e.min(a),l=e.max(a),h="log"!==this._scales[0].type,c=this.getAttrValue(i,n,h),d=o-(c-o)*t*r,u=l+(l-c)*t*r;d!==u&&(!h&&d<=0||(this.domain=[d,u]))}}function pi(e,t){let r=function(e){let t=e.parent,r=[];for(;t.type!==i.Scene;)r.push(t),t=t.parent;return r}(e);for(let e of r)if(ai(e,t))return!1;return r.length>=2?r[r.length-2]:e}function fi(e,t,i){gi(e,t,i);let r=Ie(e);if(!r)return;let s=Le(e,!0);for(let e of s)le(e);for(let e of s)r.onChange(xe.CHANNEL,"x",e)}function gi(e,t,r){switch(e.type){case i.Rect:case i.Path:case i.Line:case i.Area:!function(e,t,i){for(let r of e.vertices)yi(r,t,i);e._updateBounds(),e._refBounds&&e._refBounds.translate(t,i)}(e,t,r),0===t&&0===r||(e._dirty=!0);break;case i.Group:case i.Collection:case i.Glyph:!function(e,t,i){for(let r of e.children)gi(r,t,i);e._layout&&(void 0!==e._layout._left&&(e._layout._left+=t),void 0!==e._layout._top&&(e._layout._top+=i),e._layout._cellBounds&&e._layout._cellBounds.forEach(e=>e.translate(t,i)));0===t&&0===i||(e._dirty=!0);e._updateBounds(),e._refBounds&&e._refBounds.translate(t,i)}(e,t,r);break;case"segment":!function(e,t,i){yi(e.vertex1,t,i),yi(e.vertex2,t,i)}(e,t,r),0===t&&0===r||(e.parent._dirty=!0);break;case"vertex":yi(e,t,r),0===t&&0===r||(e.parent._dirty=!0);break;default:!function(e,t,i){e._x+=t,e._y+=i,e._updateBounds(),e._refBounds&&e._refBounds.translate(t,i)}(e,t,r),0===t&&0===r||(e._dirty=!0)}}function yi(e,t,i){e.x+=t,e.y+=i}function mi(e,t,r,s={}){let n={channel:t,attribute:r,...s};if("rowId"===n.attribute&&(n.attribute=M),function(e,t,i){if(!e||!t||!i)throw new Error("encode(elem, channel, attribute) — all three arguments are required");if(!Object.values(De).includes(t))throw new Error(`Unknown channel "${t}"`);let r=B(e);if(r&&r.tree){if(i.indexOf(".")>0&&!r.tree.nodeTable.has(i.split(".")[1]))throw new Error(`Data attribute "${i}" does not exist in the data table`)}else if(!r||!r.has(i))throw new Error(`Data attribute "${i}" does not exist in the data table`)}(e,t,r),n.shareScale){let e=n.shareScale;if(e.channel!=n.channel&&e.channel.indexOf("Color")<0&&n.channel.indexOf("Color")<0)throw new Error("Cannot share scales between "+e.channel+" and "+n.channel+" encodings");n.scheme=n.shareScale.colorScheme}!function(e){let t;"vertex"===e.type&&e.parent.type===i.Area?t=e.parent:e.type===i.Area&&(t=e),t&&!t._refBounds&&we(t).forEach(e=>e._refBounds=e.bounds.clone())}(e);let a=n.aggregator?n.aggregator:"sum";n.table=B(e);let o=new _i(e,n.channel,n.attribute,a,n),l=e.scene;return l._addAttributeEncoding(o),tt(o,l._depGraph,n.shareScale),n.shareScale?l.onChange(xe.ATTR_VALUE,o):l.onChange(xe.CHANNEL,n.channel,e),o}function bi(e,t,i,r){for(let s=t;s<i;s++)e._vertices._xs[s]=r;e._dirty=!0}function xi(e,t,i,r){for(let s=t;s<i;s++)e._vertices._xs[s]=r(s);e._dirty=!0}function vi(e,t,i,r){for(let s=t;s<i;s++)e._vertices._ys[s]=r;e._dirty=!0}function wi(e,t,i,r){for(let s=t;s<i;s++)e._vertices._ys[s]=r(s);e._dirty=!0}function Ei(e,t,i){return"number"==typeof t?function(e,t){if(!Number.isInteger(t)||t<1)throw new Error("Repeat count must be a positive integer");let i=[];for(let e=0;e<t;e++)i.push({index:e});let r=new V(i,"from count");return Ci(e,r)}(e,t):function(e){if(!e||"object"!=typeof e||Array.isArray(e))return!1;if(e instanceof V||e instanceof G||e instanceof F)return!1;let t=Object.values(e);return t.length>0&&t.every(e=>"number"==typeof e)}(t)?function(e,t,i){let r=[];for(let e of Object.keys(t)){let i=t[e];if(!Number.isInteger(i)||i<0)throw new Error("Repeat group counts must be non-negative integers: "+e+" = "+i);for(let t=0;t<i;t++)r.push({group:e})}if(0===r.length)throw new Error("Repeat counts must include at least one group with a positive count");let s=new V(r,"from group counts");return Ci(e,s,i)}(e,t,i):Ci(e,t,i)}function Ci(e,t,r){let s=Ie(e),o=r||{};if(o.attribute=o.attribute||M,function(e,t,i){if(!e||void 0===t)throw new Error("Incomplete information to do repeat. You must specify an element, a categorical data attribute and a data table");if(t instanceof G||t instanceof F){if(!Array.isArray(e)||2!==e.length)throw new Error("To repeat with a tree or a network, you need to provide two marks, one for node and one for link")}else t instanceof V&&n(i.attribute,t);if(i.layout&&!(i.layout instanceof _e))throw new Error("Invalid layout: "+i.layout)}(e,t,o),t instanceof G||t instanceof F){let r=e[0].parent,n=e[1].parent,[a,o]=function(e,t,r,s){let n=t.dataScope?t.dataScope:N(s.nodeTable),a=L(n,Y),o=Ni(e,{type:i.Collection}),l=Ni(e,{type:i.Collection}),h={};l.dataScope=n,l.addChild(t);for(let e=1;e<a.length;e++){let e=Vi(t);l.addChild(e)}l.children.forEach((e,t)=>{e.dataScope=a[t],e.links=[],h[k(e.dataScope,Y)]=e});let c=r.dataScope?r.dataScope:N(s.linkTable),d=L(c,M);o.dataScope=c,o.addChild(r);for(let e=1;e<d.length;e++){let e=Vi(r);o.addChild(e)}o.children.forEach((e,t)=>e.dataScope=d[t]);let u=s instanceof G?"parent":"source",_=s instanceof G?"child":"target";for(let e of o.children){let t=k(e.dataScope,u),i=k(e.dataScope,_),r=h[t],s=h[i];e.source=r,e.target=s,r.links.push(e),s.links.push(e)}return[l,o]}(s,e[0],e[1],t);return Xe(r,e[0],s._depGraph),Xe(n,e[1],s._depGraph),Ue(a,s._depGraph),Ue(o,s._depGraph),qe(a,e[0],s._depGraph),qe(a.parent,a,s._depGraph),qe(o,e[1],s._depGraph),qe(o.parent,o,s._depGraph),[a,o]}if(t instanceof V){let r=e.parent,n=function(e,t,r,s){let n=s.type(r);if(n!=a.String&&n!=a.Date&&n!=a.Integer)throw new Error("Repeat only works on a string or date attribute: "+r+" is "+n);if(!function(e){if(Array.isArray(e)){if(1===e.length)return Ai(e[0]);for(let t of e)if(!de(t)||t.dataScope)return!1;return!0}return Ai(e)}(t))throw new Error("The "+t.type+" is not repeatable");return function(e,t,r,s){let n=t.dataScope?t.dataScope:N(s),a=L(n,r),o=Ni(e,{type:i.Collection});o.dataScope=n,o.addChild(t),t._refBounds||(t._refBounds=t.bounds.clone());for(let e=1;e<a.length;e++){let e=Vi(t);o.addChild(e)}return o.children.forEach((e,t)=>e.dataScope=a[t]),o}(e,t,r,s)}(s,e,o.attribute,t);return Xe(r,e,s._depGraph),Ue(n,s._depGraph),qe(n,e,s._depGraph),qe(n.parent,n,s._depGraph),function(e,t,i,r){let s=r.getVariable(xe.ITEMS,i),n=r.createOneWayDependency(me.REPOPULATE);n._collection=e,n._repeatAttr=t,r.connect(s,n);let a=e.children[0],o=new Set([a,...Le(a)]);for(let e of o)r.connect(n,r.getVariable(xe.DATASCOPE,e))}(n,o.attribute,t,s._depGraph),o.layout&&(n.layout=o.layout),n}}function Ai(e){return!(!de(e)&&e.type!=i.Glyph||e.dataScope)||e.type===i.Collection&&A(e.firstChild.dataScope)>1}class Si extends _e{constructor(e){super(),this.type=fe.GRID,this._numCols=e.numCols,this._numRows=e.numRows,this._start="start"in e?e.start:ct.TopLeft,this._direction="direction"in e?e.direction:ht.RowFirst,this._rowGap="rowGap"in e&&void 0!==e.rowGap?e.rowGap:5,this._colGap="colGap"in e&&void 0!==e.colGap?e.colGap:5,this._cellHorzAlignment="horzCellAlignment"in e&&ge("h",e.horzCellAlignment)?e.horzCellAlignment:he.LEFT,this._cellVertAlignment="vertCellAlignment"in e&&ge("v",e.vertCellAlignment)?e.vertCellAlignment:he.BOTTOM,this._rowOffset="rowOffset"in e&&void 0!==e.rowOffset?e.rowOffset:0,this._colOffset="colOffset"in e&&void 0!==e.colOffset?e.colOffset:0,this._numCols||this._numRows||(this._numRows=1),this._includeInvisible=!1,this._left=void 0,this._top=void 0,this._cellBounds=void 0,this._grid=void 0}get includeInvisible(){return this._includeInvisible}set includeInvisible(e){this._includeInvisible=e}get cellBounds(){return this._cellBounds}get numCols(){return this._numCols?this._numCols:this._numRows?Math.ceil(this.group.children.length/this._numRows):0}set numCols(e){this._numCols=e}set numRows(e){this._numRows=e}get numRows(){return this._numRows?this._numRows:this._numCols?Math.ceil(this.group.children.length/this._numCols):0}get rowOffset(){return this._rowOffset}set rowOffset(e){this._rowOffset=e}get colOffset(){return this._colOffset}set colOffset(e){this._colOffset=e}clone(){let e=new Si({numCols:this._numCols,numRows:this._numRows,start:this._start,direction:this._direction,colGap:this._colGap,rowGap:this._rowGap,horzCellAlignment:this._cellHorzAlignment,vertCellAlignment:this._cellVertAlignment,rowOffset:this._rowOffset,colOffset:this._colOffset});return e._includeInvisible=this._includeInvisible,e._left=this._left,e._top=this._top,this._cellBounds&&(e._cellBounds=this._cellBounds.map(e=>e.clone())),e}getElementsByRow(e,t){let i=[],r=this.group.children;for(let t=0;t<this.numRows;t++){let s=this._grid[t].filter(e=>null!=e).map(e=>r[e]);if(e){let e=[];for(let t of s)e=e.concat(Le(t));i.push(e)}else i.push(s)}return t&&(i=this._filterElementsByExample(i,t)),i}getElementsByCol(e,t){let i=[],r=this.group.children,s=this._grid;for(let t=0;t<this.numCols;t++){let n=s.map(e=>e[t]).filter(e=>null!=e).map(e=>r[e]);if(e){let e=[];for(let t of n)e=e.concat(Le(t));i.push(e)}else i.push(n)}return t&&(i=this._filterElementsByExample(i,t)),i}getElementsByCell(e,t){let i=[],r=this.group.children;for(let t=0;t<r.length;t++)if(e){let e=Le(r[t]);i.push(e)}else i.push(r[t]);return t&&(i=this._filterElementsByExample(i,t)),i}_filterElementsByExample(e,t){let i;return"vertex"===t.type?(i=e.map(e=>e.filter(e=>e.classId===t.parent.classId)),i=i.map(e=>Ee(t,e))):"segment"===t.type?(i=e.map(e=>e.filter(e=>e.classId===t.parent.classId)),i=i.map(e=>Se(t,e))):i=e.map(e=>e.filter(e=>e.classId===t.classId)),i}getIndex(e){let t=e;for(;t&&t.parent!==this.group;)t=t.parent;return this.group.children.indexOf(t)}getRowCol(e){let t,i;switch(this._direction){case ht.RowFirst:t=Math.floor(e/this.numCols),i=e%this.numCols;break;case ht.ColumnFirst:t=e%this.numRows,i=Math.floor(e/this.numRows);break;default:throw new Error("Invalid fill direction. Use 'row_first' or 'column_first'.")}return this._start.toLowerCase().includes("bottom")&&(t=this.numRows-1-t),this._start.toLowerCase().includes("right")&&(i=this.numCols-1-i),{row:t,col:i}}get startCorner(){return this._start}set startCorner(e){this._start=e}get direction(){return this._direction}set direction(e){this._direction=e}}class ki extends nt{constructor(e,t){super(),this._type=i.Axis,this._id=this._type+s(),this._enc=e,this._textColor="textColor"in t?t.textColor:"#555",this._strokeColor="strokeColor"in t?t.strokeColor:"#555",this._fontSize="fontSize"in t?t.fontSize:"12px",this._x="x"in t?t.x:100,this._y="y"in t?t.y:100,this._showTitle=!("showTitle"in t)||t.showTitle,this._orientation="orientation"in t?t.orientation:ut,this._numberFormat=t.numberFormat?t.numberFormat:""}get attribute(){return this._enc.attribute}get channel(){return this._enc.channel}get attributeType(){return B(this._enc.element).getFieldType(this.attribute)}get orientation(){return this._orientation}get textColor(){return this._textColor}}class Ri extends ki{constructor(e,t){super(e,t),"numCols"in t||"numRows"in t?(this._numCols=t.numCols,this._numRows=t.numRows):this._orientation===ut?this._numCols=1:this._numRows=1,this._initialize()}_initialize(){let e=this._enc.element.scene,t=this._enc.attribute,i=this._enc.scales[0],r=new V(i.domain.map(e=>({category:e,value:i.map(e)}))),s=r.unique("category").sort((e,t)=>t.length-e.length)[0],n=this._enc.element,a=n instanceof vt&&n.closed&&"strokeColor"!==this._enc.channel?n.strokeWidth:0;if(this._orientation===ut){let i=0;this._showTitle&&(this.addChild(new Gt({fillColor:this._textColor,fontSize:this._fontSize,text:t,x:this._x,y:this._y,anchor:["left","top"]})),i=parseFloat(this._fontSize)+5);let o=e.mark("rect",{top:this._y+2+i,left:this._x,width:10,height:10,strokeWidth:a,strokeColor:n.strokeColor,opacity:n.opacity}),l=e.mark("text",{text:s,fillColor:this._textColor,fontSize:this._fontSize,x:this._x+20,y:this._y+i+12+a,anchor:["left","bottom"]}),h=Ei(e.glyph(o,l),r);mi(l,"text","category",{forLegend:!0}),mi(o,"fillColor","category",{shareScale:this._enc,forLegend:!0}),h.layout=new Si({numCols:this._numCols,numRows:this._numRows}),this.addChild(h)}else{let t=e.mark("rect",{top:this._y,left:this._x,width:10,height:10,strokeWidth:a,strokeColor:n.strokeColor,opacity:n.opacity}),i=e.mark("text",{text:s,fillColor:this._textColor,fontSize:this._fontSize,x:this._x+15,y:this._y,anchor:["left","top"]}),o=Ei(e.glyph(t,i),r);mi(i,"text","category",{forLegend:!0}),mi(t,"fillColor","category",{shareScale:this._enc,forLegend:!0}),o.layout=new Si({numCols:this._numCols,numRows:this._numRows,colGap:15}),this.addChild(o)}}}class Ti extends ki{constructor(e,t){super(e,t),this._initialize()}_initialize(){let t,i,r,s=this._enc.element.scene,n=this._enc.attribute;if(this._orientation==ut?(t=15,i=300):(t=300,i=15),this._showTitle){let e=s.mark("text",{fillColor:this._textColor,text:n,x:this._x+t/2,y:this._y,anchor:["center","middle"]});this.addChild(e),r=20}else r=0;let o,l=s.mark("rect",{top:this._y+r,left:this._x,width:t,height:i,strokeWidth:0,opacity:this._enc.element.opacity}),h=Object.values(this._enc.attrValues),c=[e.min(h),e.max(h)],d=this._enc.mapping,u=[],_=[],p=e.format(this._numberFormat);if(d){let e=Object.keys(d).map(e=>parseFloat(e)).sort((e,t)=>e-t);this._orientation==ut?(o=new Yt({x1:0,y1:100,x2:0,y2:0}),e.forEach(e=>{let n=(e-c[0])/(c[1]-c[0]);o.addStop(100*n,d[e],1);let a=s.mark("line",{x1:this._x+t,x2:this._x+t+5,y1:this._y+i-n*i+r,y2:this._y+i-n*i+r,strokeColor:this._strokeColor});_.push(a);let l=s.mark("text",{fillColor:this._textColor,text:this._numberFormat?p(e):e.toFixed(0),x:this._x+t+5+5,y:this._y+i-n*i+r,anchor:["left","middle"]});u.push(l)})):(o=new Yt({x1:0,y1:0,x2:100,y2:0}),e.forEach(e=>{let n=(e-c[0])/(c[1]-c[0]);o.addStop(100*n,d[e],1);let a=s.mark("line",{x1:this._x+n*t,x2:this._x+n*t,y1:this._y+20-5+r,y2:this._y+i+5+r,strokeColor:this._strokeColor});_.push(a);let l=s.mark("text",{fillColor:this._textColor,text:this._numberFormat?p(e):e.toFixed(0),x:this._x+n*t,y:this._y+i+5+r,anchor:["center","top"]});u.push(l)}))}else{let e=this._enc.scales[0].domain,l=B(this._enc.element),h=l.type(n),c=[],d=h===a.Date?l.getUniqueFieldValues(n):[...new Set(Object.values(this._enc.attrValues))];if(d.length<=10)c=d,c.sort((e,t)=>e-t);else if(h===a.Date){d.sort((e,t)=>e-t);for(let e=0;e<d.length;e+=Math.ceil(d.length/10))c.push(d[e])}else{let t=(e[1]-e[0])/9;for(let i=0;i<10;i++)c.push(e[0]+i*t)}let f=0,g=(c[c.length-1]-c[0])/c.length;for(;g<1;)g*=10,f++;c=c.map(e=>e.toFixed(f)),this._orientation==ut?(o=new Yt({x1:0,y1:100,x2:0,y2:0}),c.forEach(c=>{let d=(c-e[0])/(e[1]-e[0]);o.addStop(100*d,this._enc.scales[0].map(c),1);let f=s.mark("line",{x1:this._x+t,x2:this._x+t+5,y1:this._y+i-d*i+r,y2:this._y+i-d*i+r,strokeColor:this._strokeColor});_.push(f);let g=s.mark("text",{fillColor:this._textColor,text:h===a.Date?l.raw(n,c):this._numberFormat?p(c):c,x:this._x+t+5+5,y:this._y+i-d*i+r,anchor:["left","middle"]});u.push(g)})):(o=new Yt({x1:0,y1:0,x2:100,y2:0}),c.forEach(c=>{let d=(c-e[0])/(e[1]-e[0]);o.addStop(100*d,this._enc.scale.map(c),1);let p=s.mark("line",{x1:this._x+d*t,x2:this._x+d*t,y1:this._y+i+r,y2:this._y+i+5+r,strokeColor:this._strokeColor});_.push(p);let f=s.mark("text",{fillColor:this._textColor,text:h===a.Date?l.raw(n,c):c,x:this._x+d*t,y:this._y+i+5+r,anchor:["center","top"]});u.push(f)}))}l.styles.fillColor=o,this.addChild(l);for(let e of u)this.addChild(e);for(let e of _)this.addChild(e)}}class Oi extends Xt{constructor(e,t,i,r){super(r),this._elems=e,this._attribute=i,this._channel=t,this._posArg="x"==this._channel||"width"==this._channel?r.pathY:r.pathX,this._labelAttribute=r.labelAttribute,this._orientation="orientation"in r?r.orientation:"x"===this._channel||"width"==this._channel?Kt:Zt,this._titleText="title"in r?r.title:this._attribute,this._path="angle"===this._channel?new Lt({strokeColor:this._strokeColor,id:this._id+"_path"}):new vt({strokeColor:this._strokeColor,id:this._id+"_path"}),this._pathVisible||(this._path.visibility="hidden"),this.addChild(this._path),this.createTicksLabels(r),v(this._elems[0].dataScope).type(this._attribute)!==a.Date||"labelFormat"in r||(this._labelFormat="%m/%d/%y")}get elements(){if(this.layout.type===fe.CLUSTER){const e=new Map(this._elems.map(e=>[e.datum[Y],e]));return this.layout._d3Root.leaves().map(t=>e.get(t.data[Y]))}return this._elems}get layout(){return this._elems[0].parent.layout}createTicksLabels(t){"tickValues"in t?(this._tickValues=t.tickValues,this._labelValues=t.tickValues):(this._tickValues=this.elements.map(e=>e.datum[this._labelAttribute?this._labelAttribute:this._attribute]),this._labelValues=this._tickValues),this._ticks.removeAll();for(let e=0;e<this._tickValues.length;e++){let t=new vt({strokeColor:this._strokeColor,id:this._id+"_tick"+e});this._tickVisible||(t.visibility="hidden"),this._ticks.addChild(t)}let i;switch(this._labels.removeAll(),v(this._elems[0].dataScope).type(this._labelAttribute?this._labelAttribute:this._attribute)){case a.Date:i=e.timeFormat(this._labelFormat);break;case a.String:i=function(e){return e};break;default:i=e.format(this._labelFormat)}for(let[e,t]of this._labelValues.entries()){let r=new Gt({text:i(t),fontSize:this._fontSize,fillColor:this._textColor,id:this._id+"_label"+e});this._labels.addChild(r)}this._title._text=this._titleText}}class Ii extends nt{constructor(e){super(),this._type=i.Composite,this._id=e&&e.id?e.id:this._type+s()}addChild(e){let t=e.parent;super.addChild(e);let i=Ie(e)._depGraph;t&&Xe(t,e,i),qe(this,e,i)}}function Ni(e,t){let i;switch(t.type){case"collection":i=Pi(t);break;case"glyph":i=function(e){let t=new lt(e);return t}(t);break;case"axis":i=function(e){if("encoding"===e.axisType){return new $t(e.enc,e.scale,e.elems,e)}if("layout"===e.axisType){return new Oi(e.elems,e.channel,e.attribute,e)}}(t);break;case"legend":i=function(e){let t="string"===e.attrType?new Ri(e.enc,e):new Ti(e.enc,e);return t}(t);break;case"composite":i=function(e){let t=new Ii(e);return t}(t);break;default:i=Li(t)}return e.addChild(i),e._itemMap[i.id]=i,i}function Li(e){let t=null;switch(e.type){case i.Circle:t=new Lt(e);break;case i.Line:var r="x1"in e?e.x1:0,s="y1"in e?e.y1:0,n="x2"in e?e.x2:100,a="y2"in e?e.y2:100;e.vertices=[[r,s],[n,a]],t=new Vt(e);break;case i.Rect:var o="top"in e?e.top:0,l="left"in e?e.left:0,h="width"in e?e.width:50,c="height"in e?e.height:30;e.vertices=[[l,o],[l+h,o],[l+h,o+c],[l,o+c]],t=new Ft(e);break;case i.SimpleText:t=new Gt(e);break;case i.RichText:t=new Wt(e);break;case i.Image:t=new Pt(e);break;case i.BundledPath:case i.Chord:case i.Path:t=new vt(e);break;case i.Arrow:t=new Mt(e);break;case i.Area:t=new It(e);break;case i.Ring:t=new jt(e);break;case i.Arc:t=new St(e);break;case i.BezierCurve:"vertices"in e||(e.vertices=[[0,100],[20,120],[80,180],[100,200]]),t=new Nt(e);break;case i.Polygon:t=new zt(e)}return t&&t._updateBounds(),t}function Pi(e){return new ot(e)}function Vi(e){switch(e.type){case i.Collection:return function(e){let t=Pi({});for(let i=0;i<e.children.length;i++){let r=e.children[i];t.addChild(Vi(r))}if(t._classId=e.classId,e._layout){let i=e._layout.clone();t._layout=i,i.group=t}return t._updateBounds(),e.scene._itemMap[t.id]=t,t}(e);case i.Glyph:return function(e){let t=new lt;for(let i of e.children)t.addChild(Vi(i));t._classId=e.classId,e.dataScope&&(t.dataScope=e.dataScope);return e.scene._itemMap[t.id]=t,t}(e);default:return function(e){let t=Li({type:e.type});e.copyPropertiesTo(t),t._classId=e.classId,t._bounds=e.bounds.clone(),e._refBounds||(e._refBounds=e.bounds.clone());if(t._refBounds=e._refBounds.clone(),e.vertices)for(let i=0;i<e.vertices.length;i++)e.vertices[i].dataScope&&(t.vertices[i].dataScope=e.vertices[i].dataScope);return e.scene._itemMap[t.id]=t,t}(e)}}class Di extends be{constructor(e,t){super(e),this._elem=t}get element(){return this._elem}}class Bi extends be{constructor(e,t){super(e),this._item=t}get element(){return this._item}}class Mi{constructor(e){this._id=e+"_"+s(),this._type=e,this._vars=[],this._edges=[]}get vars(){return this._vars}get edges(){return this._edges}run(){console.log("-",this._type)}}class Gi{constructor(e,t,i=!0){this._id="e_"+s(),this._fromNode=e,this._toNode=t,this._isDirected=i}get id(){return this._id}get fromNode(){return this._fromNode}get toNode(){return this._toNode}get isDirected(){return this._isDirected}get operator(){return this._fromNode instanceof ye||this._fromNode instanceof Mi?this._fromNode:this._toNode}}class zi extends be{constructor(e,t){super(e),this._encs={},this._encs[t.channel+"_"+oi(t.element)]=t,this._initialized=!1}addLinkedEncoding(e){this._encs[e.channel+"_"+oi(e.element)]=e}getEncoding(e,t){let i=e+"_"+oi(t);return this._encs[i]}get encodings(){return Object.values(this._encs)}get initialized(){return this._initialized}set initialized(e){this._initialized=e}}class Fi extends be{constructor(e,t){super(e),this._encs=[t],this._valueMap={}}addLinkedEncoding(e){this._encs.push(e)}get encodings(){return this._encs}get attrValues(){return this._valueMap}set attrValues(e){this._valueMap=e}}class ji extends ye{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof Fi),t=this.outputVar,r=t.encodings,s=r[0],n=s.channel,o=s.attribute,l=e.encodings[0].dataTable.type(e.encodings[0].attribute),h=Object.values(e.attrValues);if("angle"===s.channel&&[i.Arc,i.Pie].indexOf(s.element.type)>=0)for(let t of e.encodings)for(let e of t.scales){let i=t.getElements(e).map(e=>t.attrValues[e.id]);e.domain=s._preferredDomain?s._preferredDomain:t.dataTable.tree?[0,t.dataTable.tree.getRoot()[o]]:this._getDomainForNumbers(i),console.log("domain for",o,e.domain)}else{let t;t=s._preferredDomain?s._preferredDomain:l==a.String||"text"===e.encodings[0].channel?this._getDomainForStrings(h):this._getDomainForNumbers(h);for(let i of e.encodings)for(let e of i.scales)e.domain=t.slice()}for(let e=0;e<s.scales.length;e++){let i=s.scales[e],a=s.getElements(i),o=this._buildRange(n,a,s,t);if(o)for(let t of r)t.scales[e].range=o}t.initialized=!0}_getDomainForNumbers(t){let i=this.outputVar.encodings[0],r=[e.min(t),e.max(t)];if(i.includeZero&&r[0]>0&&(r=[0,e.max(t)]),i.mapping)r=Object.keys(i.mapping),r=r.map(e=>parseFloat(e)),r.sort((e,t)=>e-t);else if("sequentialColor"===i.scales[0].type){if(r[0]<0&&r[1]>0){let e=Math.max(Math.abs(r[0]),Math.abs(r[1]));r=[-e,e]}}else if("angle"===i.channel){r=[0,Object.values(t).reduce((e,t)=>e+t,0)]}return r}_getDomainForStrings(e){let t,i=this.outputVar,r=i.encodings[0];return t="count"==i.encodings[0].aggregator?[0,Math.max(...e)]:Array.from(new Set(e)),r.mapping&&(t=Object.keys(r.mapping)),t}_buildRange(e,t,i,r){if("x"===e)return this._buildXRange(t,i,r);if("y"===e)return this._buildYRange(t,i,r);if(["width","height","radius","area","fontSize","radialDistance","strokeWidth"].includes(e))return this._buildSizeRange(t,i,r);if(e.indexOf("Color")>0||"fillGradient"===e)return this._buildColorRange(t,i);if("angle"===e)return this._buildAngleRange(t,i);if("thickness"===e)return this._buildThicknessRange(t,i,r);if("src"===e){let e=i.scales[0].domain;return i.mapping?e.map(e=>i.mapping[e+""]):e.slice()}}_buildThicknessRange(e,t,i){let r=e.map(e=>e.outerRadius-e.innerRadius);return[0,i.initialized?t.getRangeExtent(e[0]):t._preferredRangeExtent?t._preferredRangeExtent:Math.max(...r)]}_buildAngleRange(e,t){return[0,360]}_buildColorRange(t,i){if(i.mapping){return i.scales[0].domain.map(e=>i.mapping[e+""])}if("sequentialColor"===i.scales[0].type){let t=this.outputVar,r=i.scales[0].domain;for(let s of t.encodings)if(!i.colorScheme)for(let t of s.scales){let i=t.domain;t._scale=e.scaleSequential(r[0]<0&&r[1]>0?e.interpolatePuOr:e.interpolateTurbo),t._scale.domain(i)}}if((ei.indexOf(i.colorScheme)>=0||ti.indexOf(i.colorScheme)>=0)&&"ordinalColor"===i.scales[0].type){let t=this.outputVar,r=i.scales[0].domain;for(let s of t.encodings)for(let t of s.scales){let s=t.domain;t._scale=e.scaleOrdinal(e[i.colorScheme][r.length]),t._scale.domain(s)}}}_buildSizeRange(e,t,r){let s,n;if(s=0,"vertexIndices"===e.type){let i=Ce(e.groups[0].parent,e.groups[0].indices[0]);return n=r.initialized?t._elem2scale[i].rangeExtent:t._preferredRangeExtent?t._preferredRangeExtent:Math.max(...this._getVertexIndexSizeValues(e,t.channel)),[0,0+n]}return n=r.initialized?t.getRangeExtent(e[0]):t._preferredRangeExtent?t._preferredRangeExtent:Math.max(...e.map(e=>"radius"===t.channel?e.refBounds.width/2:"strokeWidth"===t.channel?e.strokeWidth:"radialDistance"===t.channel?e.parent.radius:"area"===t.channel?e.type===i.Circle?Math.PI*Math.pow(e.radius,2):e.width*e.height:"fontSize"===t.channel?parseFloat(e.fontSize):e.refBounds[t.channel])),[0,0+n]}_getVertexIndexSizeValues(e,t){let i=[];for(let r of e.groups){let e=r.parent._vertices;for(let s of r.indices)i.push("radius"===t?e._radii[s]:"strokeWidth"===t?e._strokeWidths[s]:"radialDistance"===t?r.parent.radius:"width"===t?e._widths[s]:"height"===t?e._heights[s]:0)}return i}_buildXRange(t,i,r){let s,n,a=i.scales[0].type;if("vertexIndices"===t.type){let a=t.groups[0].parent,o=Ce(a,t.groups[0].indices[0]),l=a.refBounds?a.refBounds:a.bounds;return s=r.initialized?e.min(i._elem2scale[o].range):l.left,n=r.initialized?i._elem2scale[o].rangeExtent:i._preferredRangeExtent?i._preferredRangeExtent:l.width,i.flipScale?[s+n,s]:[s,s+n]}switch(t[0].type){case"vertex":case"segment":var o=t[0].parent.refBounds?t[0].parent.refBounds:t[0].parent.bounds;s=r.initialized?i.getRangeStart(t[0]):o.left,n=r.initialized?i.getRangeExtent(t[0]):i._preferredRangeExtent?i._preferredRangeExtent:o.width;break;default:s=r.initialized?i.getRangeStart(t[0]):i._preferredRangeStart?i._preferredRangeStart:Ne(t[0]).bounds.left+t[0].bounds.width/2,n="band"===a?t[0].bounds.width*i.scales[0].domain.length:r.initialized?i.getRangeExtent(t[0]):i._preferredRangeExtent?i._preferredRangeExtent:e.max([450,e.max(t.map(e=>e.bounds.x))-e.min(t.map(e=>e.bounds.x))])}return i.flipScale?[s+n,s]:[s,s+n]}_buildYRange(t,i,r){let s,n;if(i.scales[0].type,"vertexIndices"===t.type){let a=t.groups[0].parent,o=Ce(a,t.groups[0].indices[0]),l=a.refBounds?a.refBounds:a.bounds;return s=r.initialized?e.min(i._elem2scale[o].range):l.top,n=r.initialized?i._elem2scale[o].rangeExtent:i._preferredRangeExtent?i._preferredRangeExtent:l.height,i.flipScale?[s,s+n]:[s+n,s]}switch(t[0].type){case"vertex":case"segment":var a=t[0].parent.refBounds?t[0].parent.refBounds:t[0].parent.bounds;s=r.initialized?i.getRangeStart(t[0]):a.top,n=r.initialized?i.getRangeExtent(t[0]):i._preferredRangeExtent?i._preferredRangeExtent:a.height;break;default:s=r.initialized?i.getRangeStart(t[0]):Ne(t[0]).bounds.top+t[0].bounds.height/2,n=r.initialized?i.getRangeExtent(t[0]):i._preferredRangeExtent?i._preferredRangeExtent:450}return i.flipScale?[s,s+n]:[s+n,s]}}class Wi extends ye{constructor(e){super(e)}run(){super.run()}}class Yi extends ye{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof Be&&e.property==ze.AXIS_ORIENTATION).element;e.createTicksLabels(e._args),e instanceof $t?this._runForEncoding(e):e instanceof Oi&&this._runForLayout(e),le(e._path)}_runForLayout(e){let t=e.channel,i=e.elements[0].parent.layout&&e.elements[0].parent.layout.type==fe.STACK?oe(e.elements):ae(e.elements),r=[];if("x"===t){let t=e.orientation===qt?i.top-2:i.bottom+2;e._pathPos=e._posArg?e._posArg:t,r.push([i.left,e._pathPos]),r.push([i.right,e._pathPos]),e._path.vertices=r}else if("y"===t){let t=e.orientation===Zt?i.left-2:i.right+2;e._pathPos=e._posArg?e._posArg:t,r.push([e._pathPos,i.top]),r.push([e._pathPos,i.bottom]),e._path.vertices=r}else if("angle"===t){let t=e.elements[0].parent.layout;t.type===fe.CLUSTER&&(e._path._x=t.x,e._path._y=t.y,e._path._radius=t.radius)}}_runForEncoding(e){let t=e.channel,i=e.elements,r=i[0].parent.layout&&i[0].parent.layout.type==fe.STACK?oe(i):ae(i),s=[],n=Ne(i[0]);if(n&&n.clipMask&&(r=n.clipMask),"x"===t){let t,n,a=ai(i[0],"y");a?(t=Math.min(...a.getScale(i[0]).range,r.top),n=Math.max(...a.getScale(i[0]).range,r.bottom)):(t=r.top,n=r.bottom);let o=e.orientation===qt?t-2:n+2;e._pathPos=e._posArg?e._posArg:o,s.push([e.scale.range[0],e._pathPos]),s.push([e.scale.range[1],e._pathPos])}else if("width"===t){let t=e.orientation===qt?r.top-2:r.bottom+2;e._pathPos=e._posArg?e._posArg:t,s.push([r.left,e._pathPos]),s.push([r.right,e._pathPos])}else if("radialDistance"===t){let t=e.elements[0].parent,i=t.y;e._pathPos=e._posArg?e._posArg:i,s.push([e.scale.range[0]+t.x,e._pathPos]),s.push([e.scale.range[1]+t.x,e._pathPos])}else if("y"===t){let t,n,a=ai(i[0],"x");a?(t=Math.min(...a.getScale(i[0]).range,r.left),n=Math.max(...a.getScale(i[0]).range,r.right)):(t=r.left,n=r.right);let o=e.orientation===Zt?t-2:n+2;e._pathPos=e._posArg?e._posArg:o,s.push([e._pathPos,e.scale.range[0]]),s.push([e._pathPos,e.scale.range[1]])}else if("height"===t){let t=e.orientation===Zt?r.left-2:r.right+2;e._pathPos=e._posArg?e._posArg:t,s.push([e._pathPos,r.bottom]),s.push([e._pathPos,r.top])}e._path.vertices=s}}class Ui extends ye{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof Be&&e.property==ze.AXIS_PATH_POSITION).element;e instanceof $t?this._runForEncoding(e):e instanceof Oi&&this._runForLayout(e);let t=[];if("width"===e.channel||"x"===e.channel){let i=e._ticks.children.map(e=>e.vertices[0].x),r=[e._path.vertices[0].x,e._path.vertices[1].x];t.push([d3.min(i.concat(r)),e._path.vertices[0].y]),t.push([d3.max(i.concat(r)),e._path.vertices[0].y]),e._path.vertices=t}else if("height"===e.channel||"y"===e.channel){let i=e._ticks.children.map(e=>e.vertices[0].y),r=[e._path.vertices[0].y,e._path.vertices[1].y];t.push([e._pathPos,d3.min(i.concat(r))]),t.push([e._pathPos,d3.max(i.concat(r))]),e._path.vertices=t}for(let t of e._ticks.children)t._updateBounds();le(e._ticks)}_runForLayout(e){let t=e.channel;if("x"==t){let t=e.orientation==Kt?e._pathPos+e.tickOffset:e._pathPos-e.tickOffset,i=e.orientation==Kt?e.tickSize:-e.tickSize;for(let[r,s]of e._ticks.children.entries()){let n=e.elements[r].bounds[e.tickAnchor];s.vertices=[[n,t],[n,t+i]]}}else if("y"===t){let t=e.orientation==Zt?e._pathPos-e.tickOffset:e._pathPos+e.tickOffset,i=e.orientation==Zt?-e.tickSize:e.tickSize;for(let[r,s]of e._ticks.children.entries()){let n=e.elements[r].bounds[e.tickAnchor];s.vertices=[[t,n],[t+i,n]]}}else if("angle"===t){let t=e.elements[0].parent.layout;if(t.type===fe.CLUSTER){let i=t._d3Root.leaves();const r=new Map(i.map(e=>[e.data[Y],[e.x,e.y]]));for(let[i,s]of e._ticks.children.entries()){let n=e.elements[i].datum[Y],a=Rt(r.get(n)[0])-90;s.vertices=[[t.x+r.get(n)[1]+e.elements[i].bounds.width/2,t.y],[t.x+r.get(n)[1]+e.elements[i].bounds.width/2+e.tickSize,t.y]],s._rotate=[a,t.x,t.y]}}}}_runForEncoding(e){let t=e.channel,r=ae(e.elements);if("x"==t){let t=e.orientation==Kt?e._pathPos+e.tickOffset:e._pathPos-e.tickOffset,i=e.orientation==Kt?e.tickSize:-e.tickSize;for(let[r,s]of e._ticks.children.entries())s.vertices=[[e.scale.map(e._tickValues[r]),t],[e.scale.map(e._tickValues[r]),t+i]]}else if("width"==t){let t=e.orientation==Kt?e._pathPos+e.tickOffset:e._pathPos-e.tickOffset,s=e.orientation==Kt?e.tickSize:-e.tickSize;if(!!(e.isFlipped()||e.elements[0].type===i.Area&&"right"===e.elements[0].baseline))for(let[i,n]of e._ticks.children.entries())n.vertices=[[r.left+e.scale.rangeExtent-e.scale.map(e._tickValues[i]),t],[r.left+e.scale.rangeExtent-e.scale.map(e._tickValues[i]),t+s]];else for(let[i,n]of e._ticks.children.entries())n.vertices=[[e.scale.map(e._tickValues[i])+r.left,t],[e.scale.map(e._tickValues[i])+r.left,t+s]]}else if("y"===t){let t=e.orientation==Zt?e._pathPos-e.tickOffset:e._pathPos+e.tickOffset,i=e.orientation==Zt?-e.tickSize:e.tickSize;for(let[r,s]of e._ticks.children.entries())s.vertices=[[t,e.scale.map(e._tickValues[r])],[t+i,e.scale.map(e._tickValues[r])]]}else if("height"===t){let t=e.orientation==Zt?e._pathPos-e.tickOffset:e._pathPos+e.tickOffset,s=e.orientation==Zt?-e.tickSize:e.tickSize;if(!!(e.isFlipped()||e.elements[0].type===i.Area&&"top"===e.elements[0].baseline))for(let[i,n]of e._ticks.children.entries())n.vertices=[[t,r.top+e.scale.map(e._tickValues[i])],[t+s,r.top+e.scale.map(e._tickValues[i])]];else for(let[i,n]of e._ticks.children.entries()){let a=r.bottom-e.scale.map(e._tickValues[i]);n.vertices=[[t,a],[t+s,a]]}}else if("radialDistance"===t){let t=e.orientation==Kt?e._pathPos+e.tickOffset:e._pathPos-e.tickOffset,i=e.orientation==Kt?e.tickSize:-e.tickSize,r=e.elements[0].parent;for(let[s,n]of e._ticks.children.entries())n.vertices=[[r.x+e.scale.map(e._tickValues[s]),t],[r.x+e.scale.map(e._tickValues[s]),t+i]]}}}class Hi extends ye{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof Be&&e.property==ze.AXIS_PATH_POSITION).element;e instanceof $t?this._runForEncoding(e):e instanceof Oi&&this._runForLayout(e);for(let t of e._labels.children)t._updateBounds();le(e._labels)}_runForLayout(e){let t=e.channel;if("x"==t){let t=e.orientation==Kt?e.labelOffset:-e.labelOffset,i=e.orientation==Kt?[he.CENTER,he.TOP]:[he.CENTER,he.BOTTOM];for(let[r,s]of e._labels.children.entries()){let n=e.elements[r].bounds;s.x=n[e.tickAnchor],s._y=e._pathPos+t,s._anchor=i,e._labelRotation&&(s._rotate=[e._labelRotation,s.x,s.y],s._anchor=[he.RIGHT,he.MIDDLE])}}else if("y"===t){let t=e.orientation==Zt?-e.labelOffset:e.labelOffset,i=e.orientation==Zt?[he.RIGHT,he.MIDDLE]:[he.LEFT,he.MIDDLE];for(let[r,s]of e._labels.children.entries()){let n=e.elements[r].bounds;s.x=e._pathPos+t,s._y=e.tickAnchor==he.MIDDLE?n.y:n[e.tickAnchor],s._anchor=i,e._labelRotation&&(s._rotate=[e._labelRotation,s.x,s.y],s._anchor=[he.RIGHT,i[1]])}}else if("angle"===t){let t=e.elements[0].parent.layout;if(t.type===fe.CLUSTER){let i=t._d3Root.leaves();const r=new Map(i.map(e=>[e.data[Y],[e.x,e.y]]));let s=5;for(let[i,n]of e._labels.children.entries()){let a=e.elements[i].datum[Y];if(r.get(a)[0]<Math.PI){let o=Rt(r.get(a)[0])-90;n._anchor=[he.LEFT,he.MIDDLE],n.x=t.x+r.get(a)[1]+e.elements[i].bounds.width/2+s,n._y=t.y,n._rotate=[o,t.x,t.y]}else{let o=Rt(r.get(a)[0])+90;n._anchor=[he.RIGHT,he.MIDDLE],n.x=t.x-r.get(a)[1]-e.elements[i].bounds.width/2-s,n._y=t.y,n._rotate=[o,t.x,t.y]}}}}}_runForEncoding(e){let t=e.channel,r=ae(e.elements);if("x"==t){let t=e.orientation==Kt?e.labelOffset:-e.labelOffset,i=e.orientation==Kt?[he.CENTER,he.TOP]:[he.CENTER,he.BOTTOM];for(let[r,s]of e._labels.children.entries())s.x=e.scale.map(e.labelValues[r]),s._y=e._pathPos+t,s._anchor=i,e._labelRotation&&(s._rotate=[e._labelRotation,s.x,s.y],s._anchor=[he.RIGHT,i[1]])}else if("width"===t){let t=e.orientation==Kt?e.labelOffset:-e.labelOffset,s=e.orientation==Kt?[he.CENTER,he.TOP]:[he.CENTER,he.BOTTOM],n=!!(e.isFlipped()||e.elements[0].type===i.Area&&"right"===e.elements[0].baseline);for(let[i,a]of e._labels.children.entries())a.x=n?r.left+e.scale.rangeExtent-e.scale.map(e.labelValues[i]):e.scale.map(e.labelValues[i])+r.left,a._y=e._pathPos+t,a._anchor=s,e._labelRotation&&(a._rotate=[e._labelRotation,a.x,a.y],a._anchor=[he.RIGHT,s[1]])}else if("y"===t){let t=e.orientation==Zt?-e.labelOffset:e.labelOffset,i=e.orientation==Zt?[he.RIGHT,he.MIDDLE]:[he.LEFT,he.MIDDLE];for(let[r,s]of e._labels.children.entries())s.x=e._pathPos+t,s._y=e.scale.map(e.labelValues[r]),s._anchor=i,e._labelRotation&&(s._rotate=[e._labelRotation,s.x,s.y],s._anchor=[he.RIGHT,i[1]])}else if("height"===t){let t=e.orientation==Zt?-e.labelOffset:e.labelOffset,s=e.orientation==Zt?[he.RIGHT,he.MIDDLE]:[he.LEFT,he.MIDDLE],n=e.elements[0].type===i.Area&&"top"===e.elements[0].baseline;for(let[i,a]of e._labels.children.entries())a.x=e._pathPos+t,a._y=n?r.top+e.scale.map(e.labelValues[i]):r.bottom-e.scale.map(e.labelValues[i]),a._anchor=s,e._labelRotation&&(a._rotate=[e._labelRotation,a.x,a.y],a._anchor=[he.RIGHT,s[1]])}else if("radialDistance"==t){let t=e.orientation==Kt?e.labelOffset:-e.labelOffset,i=e.orientation==Kt?[he.CENTER,he.TOP]:[he.CENTER,he.BOTTOM],r=e.elements[0].parent;for(let[s,n]of e._labels.children.entries())n.x=r.x+e.scale.map(e.labelValues[s]),n._y=e._pathPos+t,n._anchor=i,e._labelRotation&&(n._rotate=[e._labelRotation,n.x,n.y],n._anchor=[he.RIGHT,i[1]])}}}function Xi(e,t){let i=e.getElements(t);return i&&"vertexIndices"===i.type?i.groups[0].parent:i[0]}class qi extends ye{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=we(e.parent);for(let e of t){let t=e.layout;if(!t)return;let i=t._includeInvisible?e.children:e.children.filter(e=>"hidden"!==e.visibility);this.fillGrid(e,t,i),this.computeCellBounds(e,t,i),this.placeElements(e,t,i)}let i=Le(e,!0);for(let e of i)le(e)}placeElements(e,t,i){let r=li(e,"x"),s=li(e,"y");for(let i=0;i<e.children.length;i++){let r=e.children[i],s=t.cellBounds[i];if(!s)continue;let n=0,a=0;switch(t._cellHorzAlignment){case he.LEFT:n=s.left-r.refBounds.left;break;case he.CENTER:n=s.x-r.refBounds.x;break;case he.RIGHT:n=s.right-r.refBounds.right}switch(t._cellVertAlignment){case he.TOP:a=s.top-r.refBounds.top;break;case he.MIDDLE:a=s.y-r.refBounds.y;break;case he.BOTTOM:a=s.bottom-r.refBounds.bottom}gi(r,n,a)}if(r.length>0)for(let e of r)for(let i of e.scales){let r=Xi(e,i),s=t.getIndex(r);if(s<0||!t.cellBounds[s])continue;let n="point"===i.type?t.cellBounds[s].left+r.bounds.width/2:t.cellBounds[s].left,a=n+i.rangeExtent;i.range=i.range[0]<i.range[1]?[n,a]:[a,n]}if(s.length>0)for(let e of s)for(let i of e.scales){let r=Xi(e,i),s=t.getIndex(r);if(s<0||!t.cellBounds[s])continue;let n="point"===i.type?t.cellBounds[s].top+r.bounds.height/2:t.cellBounds[s].top,a=n+i.rangeExtent;i.range=i.range[0]<i.range[1]?[n,a]:[a,n]}}fillGrid(e,t,i){let r=i.length,s=t._numCols?t._numCols:t._numRows?Math.ceil(r/t._numRows):1,n=t._numRows?t._numRows:Math.ceil(r/s);t._grid=new Array(n).fill(null).map(()=>new Array(s).fill(null));for(let a=0;a<r;a++){let r,o;switch(t._direction){case ht.RowFirst:r=Math.floor(a/s),o=a%s;break;case ht.ColumnFirst:r=a%n,o=Math.floor(a/n);break;default:throw new Error("Invalid fill direction. Use 'row_first' or 'column_first'.")}t._start.toLowerCase().includes("bottom")&&(r=n-1-r),t._start.toLowerCase().includes("right")&&(o=s-1-o);let l=e.children.indexOf(i[a]);t._grid[r][o]=l}}computeCellBounds(e,t,i){let r=i.map(e=>e.refBounds?e.refBounds:e.bounds),s=t._colGap,n=t._rowGap;if(void 0===t._left){let e=r.map(e=>e.left),i=r.map(e=>e.top);t._left=d3.min(e),t._top=d3.min(i)}let a=r.map(e=>e.width),o=r.map(e=>e.height),l=d3.max(a),h=d3.max(o);t._cellBounds=new Array(e.children.length).fill(null);let c=t._grid.length,d=c>0&&t._grid[0]?t._grid[0].length:0,u=t._rowOffset||0,_=t._colOffset||0;for(let i=0;i<c;i++)for(let r=0;r<d;r++){let a=t._grid[i][r];if(null==a||a>=e.children.length)continue;let o=t._left+(l+s)*r+(i%2==1?u:0),c=t._top+(h+n)*i+(r%2==1?_:0);t._cellBounds[a]=new se(o,c,l,h)}}}function Ki(e,t,r){let s=e.scene,o=r||{};if(o.attribute=o.attribute||M,function(e,t,i){if(!e||void 0===t)throw new Error("Incomplete information to do densification. You must specify an element, a categorical data attribute and a data table");t instanceof V&&n(i.attribute,t)}(e,t,o),t instanceof G||t instanceof F)throw"Not implemented";if(t instanceof V){let r=function(e,t,r,s,n){let o=n.type(r);if(o!=a.String&&o!=a.Date&&o!=a.Number&&o!=a.Integer)throw new Error("Densify only works on a string or date attribute: "+r+" is "+o);if(!$i(t))throw new Error("The "+t.type+" is not dividable");switch(t.type){case i.Line:return function(e,t,i,r){let s,n,a=we(t);for(let o of a){let a=o.dataScope?o.dataScope:N(r),l=L(a,i,!1);1===l.length&&l.push(l[0]);let h=Object.assign({},o.styles);for(let e of mt.styles)void 0!==o[e]&&(h[e]=o[e]);let c=o.vertices[0].x,d=o.vertices[0].y,u=[],_=o.vertices[1].x-c,p=o.vertices[1].y-d;for(let e=0;e<l.length;e++)u.push([c+e*_/(l.length-1),d+e*p/(l.length-1)]);h.vertices=u,h.type="path";let f=Ni(e,h);n||(n=f.id),f._classId=n,f.dataScope=a,f._updateBounds(),f._refBounds=f.bounds.clone();let g=o.parent;g.addChild(f),g.removeChild(o);for(let e=0;e<f._vertices.length;e++)f._vertices.setDataScopeRef(e,l[e]);o==t&&(s=f)}return s}(e,t,r,n);case i.Circle:return function(e,t,i,r){let s,n,o=we(t),l=r.type(i);for(let h of o){let o=h.dataScope?h.dataScope:N(r),c=L(o,i,l==a.Number),d=c.length;if(d<3)throw new Error("INSUFFICIENT_DATA_SCOPES");let u=90,_=360/d,p=[],f=[],g=-1;for(let e=0;e<c.length;e++){let t=u+g*e*_;f[e]=t;let i=Zi(h.x,h.y,h.radius,f[e]);p.push(i)}let y=Object.assign({},h.styles);y.vertices=p,y.type="polygon",y.x=h.x,y.y=h.y,y.radius=h.radius;let m=Ni(e,y);n||(n=m.id),m._classId=n,m.dataScope=o;let b=h.parent;b.addChild(m),b.removeChild(h);for(let e=0;e<m._vertices.length;e++)m._vertices.setProperty(e,"polarAngle",f[e]),m._vertices.setDataScopeRef(e,c[e]);h===t&&(s=m)}return s}(e,t,r,n);case i.Rect:return function(e,t,i,r,s){let n,o,l=we(t),h=i||dt;if(h!=dt&&h!=ut)throw new Error("Unknown orientation: "+h);for(let i of l){let l=s.type(r),c=i.dataScope?i.dataScope:N(s),d=L(c,r,l==a.Number);1===d.length&&d.push(d[0]),l!=a.Number&&l!=a.Date||d.sort((e,t)=>e.filters[r]>t.filters[r]?1:-1);let u=Object.assign({},i.styles),_=i.vertices[0].x,p=i.vertices[0].y,f=i.vertices[i.vertices.length-2].x,g=i.vertices[i.vertices.length-2].y,y=[],m=f-_,b=g-p;for(let e=0;e<d.length;e++)y.push(h==ut?[f,p+e*b/(d.length-1)]:[_+e*m/(d.length-1),p]);for(let e=0;e<d.length;e++)y.push(h==ut?[_,p+(d.length-1-e)*b/(d.length-1)]:[_+(d.length-1-e)*m/(d.length-1),g]);u.vertices=y,u.type="area";let x=Ni(e,u);o||(o=x.id),x._classId=o,x.dataScope=c,x.orientation=h,x.baseline=h===dt?he.BOTTOM:he.LEFT;let v=i.parent;v.addChild(x),v.removeChild(i);for(let e=0;e<x._vertices.length;e++)e>=d.length?x._vertices.setDataScopeRef(e,d[2*d.length-1-e]):x._vertices.setDataScopeRef(e,d[e]);i===t&&(n=x)}return n}(e,t,s,r,n)}}(s,e,o.attribute,o.orientation,t);return We(e,s._depGraph),je(r,s._depGraph),r.parent.type!==i.Scene&&qe(r.parent,r,s._depGraph),function(e,t,i){let r=i.findVariable(xe.ITEMS,[t]);if(!r)return;let s=null;for(let e of r.outgoingEdges)if(e.isDirected&&e.toNode.type===me.REPOPULATE){s=e.toNode;break}if(!s)return;let n=i.getVariable(xe.DATASCOPE,e);if(i.connect(s,n),e._vertices&&e._vertices.length>0){let t=e.vertices[0],r=i.getVariable(xe.DATASCOPE,t);i.connect(s,r)}}(r,t,s._depGraph),r.type===i.Area&&function(e,t,i,r){let s=r.findVariable(xe.ITEMS,[i]);if(!s)return;for(let e of s.outgoingEdges)if(e.isDirected&&e.toNode.type===me.REPOPULATE)return;let n=r.createOneWayDependency(me.REPOPULATE);n._area=e,n._repeatAttr=t,r.connect(s,n);let a=r.getVariable(xe.DATASCOPE,e);if(r.connect(n,a),e._vertices&&e._vertices.length>0){let t=r.getVariable(xe.DATASCOPE,e.vertices[0]);r.connect(n,t)}}(r,o.attribute,t,s._depGraph),s.onChange(xe.CHANNEL,"width",r),r}}function Zi(e,t,i,r){return[i*Math.cos(kt(r))+e,t-i*Math.sin(kt(r))]}function $i(e){if([i.Line,i.Circle,i.Rect,i.Area].indexOf(e.type)<0)return!1;if(e.dataScope){let t=we(e,e.scene);for(let e of t)if(A(e.dataScope)>1)return!0;return!1}return!0}function Ji(e,t){if(!e)throw new Error("update: target is required");if(!t||"object"!=typeof t||Array.isArray(t))throw new Error("update: patch must be an object");if(pe(e)){let i=e.group?[e.group]:[],r=[];for(let e of i)r=r.concat(we(e));0===r.length&&(r=i);for(let e of r)if(e.layout)for(const[i,r]of Object.entries(t))e.layout[i]=r;let s=Ie(e);if(s)for(let e of i)e.firstChild&&s.onChange(xe.CHANNEL,"width",e.firstChild);return}let i=we(e),r=Ie(e);for(const[s,n]of Object.entries(t))if("layout"!==s)for(let e of i)Qi(e,s,n);else if(r&&"function"==typeof r.setLayout)r.setLayout(e,n);else for(let e of i)e.layout=n;if("width"in t&&i.forEach(e=>{e._refBounds&&e._refBounds.setWidth(t.width)}),"height"in t&&i.forEach(e=>{e._refBounds&&e._refBounds.setHeight(t.height)}),r)for(let i in t)"layout"!==i&&(["vertex","segment"].includes(e.type)&&!["x","y"].includes(i)||(Object.values(De).includes(i)?r.onChange(xe.CHANNEL,i,e):r.onChange(xe.PROPERTY,i,e)))}function Qi(e,t,r){switch(t){case"x":tr(e,r);break;case"y":ir(e,r);break;case"width":!function(e,t){e.resize(t,e.height)}(e,r);break;case"height":!function(e,t){e.resize(e.width,t)}(e,r);break;case"radius":e.radius=r;break;case"strength":e._strength=r;break;case"area":e.type===i.Circle?e.radius=Math.sqrt(r/Math.PI):e.type===i.Rect&&e.resize(Math.sqrt(r),Math.sqrt(r)),e._updateBounds();break;case"text":e._text=r;break;case"curveMode":e.curveMode=r;break;case"baseline":e.baseline=r;break;case"angle":[i.Arc,i.Pie].includes(e.type)&&function(e,t){e._endAngle=Tt(e._startAngle+t),e._sr=kt(e._startAngle),e._er=kt(e._endAngle),e.vertices[0].x=e._x+e._innerRadius*Math.cos(e._sr),e.vertices[0].y=e._y-e._innerRadius*Math.sin(e._sr),e.vertices[1].x=e._x+e._outerRadius*Math.cos(e._sr),e.vertices[1].y=e._y-e._outerRadius*Math.sin(e._sr),e.vertices[2].x=e._x+e._outerRadius*Math.cos(e._er),e.vertices[2].y=e._y-e._outerRadius*Math.sin(e._er),e.vertices[3].x=e._x+e._innerRadius*Math.cos(e._er),e.vertices[3].y=e._y-e._innerRadius*Math.sin(e._er)}(e,r);break;case"startAngle":!function(e,t){let i=e.angle;e._startAngle=t,e._endAngle=Tt(e._startAngle+i),e._sr=kt(e._startAngle),e._er=kt(e._endAngle),e.vertices[0].x=e._x+e._innerRadius*Math.cos(e._sr),e.vertices[0].y=e._y-e._innerRadius*Math.sin(e._sr),e.vertices[1].x=e._x+e._outerRadius*Math.cos(e._sr),e.vertices[1].y=e._y-e._outerRadius*Math.sin(e._sr),e.vertices[2].x=e._x+e._outerRadius*Math.cos(e._er),e.vertices[2].y=e._y-e._outerRadius*Math.sin(e._er),e.vertices[3].x=e._x+e._innerRadius*Math.cos(e._er),e.vertices[3].y=e._y-e._innerRadius*Math.sin(e._er)}(e,r);break;case"thickness":!function(e,t){er(e,e._innerRadius+t)}(e,r);break;case"innerRadius":!function(e,t){e._innerRadius=t,e.vertices[0].x=e._x+e._innerRadius*Math.cos(e._sr),e.vertices[0].y=e._y-e._innerRadius*Math.sin(e._sr),e.vertices[3].x=e._x+e._innerRadius*Math.cos(e._er),e.vertices[3].y=e._y-e._innerRadius*Math.sin(e._er)}(e,r);break;case"outerRadius":er(e,r);break;case"radialDistance":{let t=Zi(e.parent.x,e.parent.y,r,e.polarAngle);tr(e,t[0]),ir(e,t[1]);break}case"visibility":e.visibility=r;break;case"src":e.src=r;break;case"vxOpacity":if(e instanceof nt)for(let i of e.children)Qi(i,t,r);else e.vxOpacity=r;break;default:if("vertex"===e.type)e[t]=r;else if(e instanceof nt)for(let i of e.children)Qi(i,t,r);else{if(e.styles[t]==r)return;e.styles[t]=r}}"vertex"===e.type?e.parent._dirty=!0:e._dirty=!0}function er(e,t){e._outerRadius=t,e.vertices[1].x=e._x+e._outerRadius*Math.cos(e._sr),e.vertices[1].y=e._y-e._outerRadius*Math.sin(e._sr),e.vertices[2].x=e._x+e._outerRadius*Math.cos(e._er),e.vertices[2].y=e._y-e._outerRadius*Math.sin(e._er)}function tr(e,t){"vertex"==e.type?e.x=t:gi(e,t-e.x,0)}function ir(e,t){"vertex"==e.type?e.y=t:gi(e,0,t-e.y)}class rr extends be{constructor(e,t){super(e),this._result=t.evalResult,this._condEnc=t}get result(){return this._condEnc.evalResult}clearResult(){this._condEnc.evalResult={}}get conditionalEncoding(){return this._condEnc}}class sr extends ye{constructor(e){super(e)}storeValues(e,t){this._storedValues={};let i=we(e);for(let e of i)this._storedValues[e.id]=e[t]}_restoreValue(e,t){let i=this._storedValues[e.id];e.styles?e.styles[t]!==i&&(e._dirty=!0,e.styles[t]=i):e[t]!==i&&(e._dirty=!0,e[t]=i)}run(){super.run();let e=this.inputVars.find(e=>e instanceof zi),t=this.outputVar,i=e?e.getEncoding(t.channel,t.element):null,r=t.channel,s=this.inputVars.filter(e=>e instanceof rr),n=s.length>0?s.map(e=>e.conditionalEncoding):[],a=n.length>0?n[0].eventContext:null,o=["x","y","width","height","radius"].includes(t.channel);if(e&&"vertex"===t.element.type)return this._runVertexIndexEncoding(i,r),void le(t.element.parent);let l=we(t.element),h=l[0].scene;for(let t of l){if(e){let e=i.getScale(t);this._doMapping(t,e,i.attrValues,i),o&&this._updateRefBounds(t,e,i)}else this._restoreValue(t,r);if(s.length>0){let e=n.map(e=>e.evalResult[t.id]).every(e=>e||void 0===e);n[0].stylingFunction(e,a,h.state,t)}}if(o){le(["vertex","segment"].includes(t.element.type)?t.element.parent:t.element)}}_runVertexIndexEncoding(e,t){for(let i=0;i<e.scales.length;i++){let r=e.scales[i],s=e.getElements(r),n=[];for(let i of s.groups){i.parent._vertices;for(let s of i.indices){let n=Ce(i.parent,s),a=e.attrValues[n],o="text"===t?a:r.map(a);this._setVertexIndexChannel(i.parent,s,t,o)}i.parent._dirty=!0,"x"!==t&&"y"!==t||n.includes(i.parent)||(this._updateVertexParentRefBounds(i.parent,t,r,e),n.push(i.parent))}}}_setVertexIndexChannel(e,t,i,r){let s=e._vertices;switch(i){case"x":s._xs[t]=r;break;case"y":s._ys[t]=r;break;case"radialDistance":{let i=s._polarAngles[t]*Math.PI/180;s._xs[t]=e.x+r*Math.cos(i),s._ys[t]=e.y-r*Math.sin(i);break}default:s.setProperty(t,i,r)}}_updateVertexParentRefBounds(e,t,i,r){let s=e.refBounds;"x"===t?e._refBounds=new se(r.flipScale?i.range[1]:i.range[0],s.top,i.rangeExtent,s.height):"y"===t&&(e._refBounds=new se(s.left,r.flipScale?i.range[0]:i.range[1],s.width,i.rangeExtent))}_updateRefBounds(t,i,r){switch(this.outputVar.channel){case"width":t._refBounds.setWidth(i.rangeExtent);break;case"height":t._refBounds.setHeight(i.rangeExtent);break;case"radius":t._refBounds.setWidth(2*i.rangeExtent,he.CENTER),t._refBounds.setHeight(2*i.rangeExtent,he.MIDDLE);break;case"x":if("vertex"==t.type||"segment"==t.type){let e=t.parent._refBounds;t.parent._refBounds=new se(r.flipScale?i.range[1]:i.range[0],e.top,i.rangeExtent,e.height)}else if(t._refBounds)if("band"===i.type){let e=i.map(r.attrValues[t.id]),s=t._refBounds;t._refBounds=new se(e-t.width/2,s.top,t.width,s.height)}else{let e=t.parent;for(;e&&(!e.layout||e.layout.type!==fe.GRID);)e=e.parent;if(e){let e=t._refBounds;t._refBounds=new se(r.flipScale?i.range[1]:i.range[0],e.top,i.rangeExtent,e.height)}}break;case"y":if("vertex"==t.type||"segment"==t.type){let e=t.parent._refBounds;t.parent._refBounds=new se(e.left,r.flipScale?i.range[0]:i.range[1],e.width,i.rangeExtent)}else if(t._refBounds){let s=t.parent;for(;s&&(!s.layout||s.layout.type!==fe.GRID);)s=s.parent;if(s){let s=t._refBounds,n=e.min(i.range);t._refBounds=new se(s.left,r.flipScale?i.range[0]:n,s.width,i.rangeExtent)}}}}_doMapping(e,t,r,s){switch(this.outputVar.channel){case"width":t.domain[0]<0&&e instanceof Ft?function(e,t,i){let r=e.refBounds.left+t.map(0),s=e.refBounds.left+t.map(i[e.id]);gi(e.leftSegment,r-e.leftSegment.x,0),gi(e.rightSegment,s-e.rightSegment.x,0)}(e,t,r):t.domain[0]<0&&e instanceof It||(e.type===i.Area?function(e,t,i){let r=e.baseline;if(e.orientation===ut){let s=e._vertices.length/2;switch(r){case"left":bi(e,s,e._vertices.length,e.refBounds.left),xi(e,0,s,r=>e.refBounds.left+t.map(i[Ce(e,r)]));break;case"right":xi(e,s,e._vertices.length,r=>e.refBounds.right-t.map(i[Ce(e,r)])),bi(e,0,s,e.refBounds.right);break;case"center":console.log("center"),xi(e,s,e._vertices.length,r=>e.refBounds.center-t.map(i[Ce(e,r)])/2),xi(e,0,s,r=>e.refBounds.center+t.map(i[Ce(e,r)])/2)}}}(e,t,r):this._doStandardMapping(e,t,r));break;case"height":t.domain[0]<0&&e instanceof Ft?function(e,t,i){let r=e.refBounds.bottom-t.map(0),s=e.refBounds.bottom-t.map(i[e.id]);gi(e.bottomSegment,0,r-e.bottomSegment.y),gi(e.topSegment,0,s-e.topSegment.y)}(e,t,r):t.domain[0]<0&&e instanceof It?function(e,t,i){let r=e._vertices.length/2;wi(e,0,r,r=>e.refBounds.bottom-t.map(i[Ce(e,r)])),vi(e,r,e._vertices.length,e.refBounds.bottom-t.map(0))}(e,t,r):e.type===i.Area?function(e,t,i){let r=e.baseline;if(e.orientation===dt){let s=e._vertices.length/2;switch(r){case"top":wi(e,s,e._vertices.length,r=>e.refBounds.top+t.map(i[Ce(e,r)])),vi(e,0,s,e.refBounds.top);break;case"middle":wi(e,0,s,r=>e.refBounds.middle-t.map(i[Ce(e,r)])/2),wi(e,s,e._vertices.length,r=>e.refBounds.middle+t.map(i[Ce(e,r)])/2);break;default:wi(e,0,s,r=>e.refBounds.bottom-t.map(i[Ce(e,r)])),vi(e,s,e._vertices.length,e.refBounds.bottom)}}}(e,t,r):this._doStandardMapping(e,t,r);break;case"text":this._doTextMapping(e,r);break;case"fillGradient":!function(e,t,i,r){let s=e._vertices._ids.map((t,r)=>i[Ce(e,r)]),n=d3.min(s),a=d3.max(s),o="horizontal"===e.orientation?new Yt({x1:0,y1:100,x2:0,y2:0}):new Yt({x1:0,y1:0,x2:100,y2:0});if(o.addStop(0,t.map(n),1),r._mapping){let e=Object.keys(r._mapping).map(e=>parseFloat(e)).sort();for(let i of e)i>n&&i<a&&o.addStop(100*(i-n)/(a-n),t.map(i),1)}else"divergingColor"===t.type&&o.addStop(100*-n/(a-n),t.map(0),1);"sequentialColor"===t.type&&o.addStop(100*-n/(a-n),t.map(0),1),o.addStop(100,t.map(a),1),e.fillColor=o}(e,t,r,s);break;default:this._doStandardMapping(e,t,r)}}_doTextMapping(e,t){Qi(e,this.outputVar.channel,t[e.id])}_doStandardMapping(e,t,i){let r=this.outputVar.channel,s=t.map(i[e.id]);Qi(e,r,s),e instanceof vt&&e.firstVertex&&e.firstVertex.shape&&"strokeColor"===r&&e.vertices.forEach(e=>e.fillColor=s)}_doCondEncoding(e,t){let i=e[0].scene;for(let r of e){let e=t.map(e=>e.evalResult[r.id]).every(e=>e||void 0===e),s=t[0].eventContext;t[0].stylingFunction(e,s,r,i)}}_updateElement(e,t,i,r){let s;"object"==typeof r&&e.triggerElement?"property"in r?s=e.triggerElement[r.property]:"attribute"in r&&(s=e.triggerElement.datum[r.attribute]):s=r,["x","y"].includes(i)&&"offset"in r&&(s+=r.offset),Qi(t,i,s)}}class nr extends ye{constructor(e){super(e)}run(){let e=this.outputVar.element;e.updateValues(),e.scale?this._runForEncoding(e):this._runForLayout(e),le(e)}_runForLayout(e){let t=e.channel,i=ae(e.elements),r=[];if("x"===t)for(let t=0;t<e.values.length;t++){let s=e.elements[t].refBounds;r.push({x1:s.x,y1:i.bottom,x2:s.x,y2:i.top})}else if("y"===t)for(let t=0;t<e.values.length;t++){let s=e.elements[t].refBounds;r.push({x1:i.left,y1:s.y,x2:i.right,y2:s.y})}e.lines=r,e._dirty=!0}_runForEncoding(e){let t=e.channel,i=ae(e.elements),r=[];if("x"===t){let t,s,n=ai(e.elements[0],"y");n?(t=Math.min(...n.getScale(e.elements[0]).range,i.top),s=Math.max(...n.getScale(e.elements[0]).range,i.bottom)):(t=i.top,s=i.bottom);for(let i of e.values)r.push({x1:e.scale.map(i),y1:s,x2:e.scale.map(i),y2:t})}else if("width"===t)for(let t of e.values)r.push({x1:e.scale.map(t)+i.left,y1:i.bottom,x2:e.scale.map(t)+i.left,y2:i.top});else if("y"===t){let t,s,n=ai(e.elements[0],"x");n?(t=Math.min(...n.getScale(e.elements[0]).range,i.left),s=Math.max(...n.getScale(e.elements[0]).range,i.right)):(t=i.left,s=i.right);for(let i of e.values)r.push({x1:t,y1:e.scale.map(i),x2:s,y2:e.scale.map(i)})}else if("height"===t)for(let t of e.values)r.push({x1:i.left,y1:i.bottom-e.scale.map(t),x2:i.right,y2:i.bottom-e.scale.map(t)});else if("radialDistance"===t){let t=e.elements[0].parent;for(let i=0;i<e.values.length;i++)r.push({x:t.x,y:t.y,r:e.scale.map(e.values[i])})}e.lines=r,e._dirty=!0}}class ar extends ye{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=Le(e)[0],r=we(e.parent);for(let e of r){let r=e.layout;if(!r)return;switch(t.type){case i.Rect:case i.Circle:case i.Image:this._stackRects(e,r);break;case i.Area:e.children[0].orientation===dt?this._stackAreasVert(e,r):this._stackAreasHorz(e,r);break;case i.Arc:case i.Pie:t.parent.classId===e.classId&&this._stackArcs(e,r)}}le(t)}_stackArcs(e,t){if(t.orientation===_t){let t=90;if((this._direction?this._direction:gt.Clockwise)===gt.Clockwise)for(let i of e.children){let e=Tt(t-i.angle);Qi(i,"startAngle",e),t=e}else for(let i of e.children){let e=Tt(t+i.angle);Qi(i,"startAngle",e),t=e}}else if(t.orientation===pt){let t=d3.min(e.children.map(e=>e.innerRadius));for(let i of e.children){let e=i.outerRadius-i.innerRadius;Qi(i,"innerRadius",t),Qi(i,"outerRadius",t+e),t=i._outerRadius}}}_stackAreasVert(e,t){let i=e.children.filter(e=>"visible"===e.visibility),r=e.bounds,s=t.vertCellAlignment===he.TOP?r.top:r.bottom,n=t.vertCellAlignment===he.TOP?1:-1;if(0===i.length)return;t.vertCellAlignment===he.BOTTOM&&i.reverse();let a=i[0].vertices.length/2,o=new Array(a).fill(0);for(let e of i){for(let t=0;t<a;t++){let i=e.vertices[t],r=e.vertices[2*a-t-1],l=Math.abs(i.y-r.y),h=s+o[t]*n,c=s+(o[t]+l)*n;gi(i,0,h-i.y),gi(r,0,c-r.y),o[t]+=l}let t=e.bounds.bottom;e._updateBounds(),e._refBounds.translate(0,e.bounds.bottom-t)}if(t.vertCellAlignment===he.MIDDLE)for(let e of i){for(let t=0;t<a;t++){let i=e.vertices[t],s=e.vertices[2*a-t-1],n=r.middle+o[t]/2;gi(i,0,n-r.bottom),gi(s,0,n-r.bottom)}let t=e.bounds.bottom;e._updateBounds(),e._refBounds.translate(0,e.bounds.bottom-t)}}_stackAreasHorz(e,t){}_stackRects(e,t){e.scene;let i=t._orientation,r=e.children.map(e=>e.bounds),s=r.map(e=>e.left),n=r.map(e=>e.top),a=r.map(e=>e.width),o=r.map(e=>e.height),l=null==t._left?d3.min(s):t._left,h=null==t._top?d3.min(n):t._top,c=d3.max(a),d=d3.max(o);if(i==ut)for(let i=0;i<e.children.length;i++){let r=e.children[i],s=0,n=h+r.bounds.height/2-r.bounds.y;h+=r.bounds.height+t._gap,gi(r,s,n),r._updateBounds();let a=0,o=0;if(!ci(r))switch(t._horzCellAlignment){case he.LEFT:a=l-r.bounds.left;break;case he.CENTER:a=l+c/2-r.bounds.x;break;case he.RIGHT:a=l+c-r.bounds.right}gi(r,a,o)}else for(let i=0;i<e.children.length;i++){let r=e.children[i],s=l+r.bounds.width/2-r.bounds.x,n=0;l+=r.bounds.width+t._gap,gi(r,s,n),r._updateBounds();let a=0,o=0;if(!hi(r))switch(t._vertCellAlignment){case he.TOP:o=h-r.bounds.top;break;case he.MIDDLE:o=h+d/2-r.bounds.y;break;case he.BOTTOM:o=h+d-r.bounds.bottom}gi(r,a,o)}}}class or extends ye{constructor(e){super(e)}run(){super.run()}}class lr extends ye{constructor(e){super(e)}run(){let t=this._binConfig.attribute,i=this._binConfig.startAttr,r=this._binConfig.endAttr,s=this._binConfig.binIdAttr,n=this.inputVars[0].dataset,o=this.outputVar.dataset,l=n.values(t),h=e.bin();null!=this._binConfig?.numBins&&(h=h.thresholds(this._binConfig.numBins));let c=h(l);this._binConfig.actualNumBins=c.length;let d=String(c.length-1).length,u=e=>String(e).padStart(d,"0"),_=this._findBin,p=l.map(e=>_(e,c).x0),f=l.map(e=>_(e,c).x1),g=l.map(e=>{let t=c.indexOf(_(e,c));return u(t)}),y=c.map((e,t)=>u(t));o.addAttr(i,a.Number,p),o.addAttr(r,a.Number,f),o.addAttr(s,a.String,g),o.order(s,y)}_findBin(e,t){for(let i of t)if(i.indexOf(e)>=0)return i}}class hr extends be{constructor(e,t){super(e),this._dataset=t}get dataset(){return this._dataset}}class cr extends ye{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof hr),t=this.outputVar.dataset;if(!e)return;let i=e.dataset,r=this._spec;if(!r.value)return void t.load(i.data.slice());let s=$(r);t.load(i.data.filter(e=>s.testTuple(e)))}}function dr(e,t,i){e.dataScope=void 0;let r=Ie(e),s=e;for(let e in i){ur(r,s,i[e],t);let n=ri(s.children[0],!0);for(let e of n)ii(e,r);let a=we(s);for(let e of a)if(e.layout){for(let t of e.layout.refElements)Ht(t,r),Ye(t,r._depGraph);e.layout.clearRefElements()}s=s.children[0]}e.dataScope=N(t),r.onChange(xe.CHANNEL,"width",e.children[0])}function ur(e,t,i,r){let s=r.type(i);if(s!=a.String&&s!=a.Date&&s!=a.Integer)throw new Error("Repopulate only works on a string or date attribute: "+i+" is "+s);let n=we(t);for(let e of n){let t=L(e.dataScope?e.dataScope:N(r),i,!0),s=e.children.length-t.length,n=t.length-e.children.length;for(let t=0;t<s;t++)e.removeChildAt(e.children.length-1);let a=e._children.length;for(let t=0;t<n;t++){let i=Vi(e._children[t%a]);e.addChild(i)}e.children.forEach((e,i)=>e.dataScope=t[i])}}class _r extends ye{constructor(e){super(e),this._collection=null,this._area=null,this._repeatAttr=null}run(){if(super.run(),this._area&&this._repeatAttr){let e=this.inputVars[0];if(!e)return;let t=e.dataset;Ie(this._area);return function(e,t,i,r){let s=r.type(i),n=N(r),o=L(n,i,s===a.Number);s!==a.Number&&s!==a.Date||o.sort((e,t)=>e.filters[i]>t.filters[i]?1:-1),1===o.length&&o.push(o[0]);let l=o.length,h=t.refBounds??t.bounds,{left:c,top:d,right:u,bottom:_}=h,p=u-c,f=_-d,g=t.orientation===ut,y=[];if(l>0){for(let e=0;e<l;e++)y.push(g?[u,d+e*f/(l-1)]:[c+e*p/(l-1),d]);for(let e=0;e<l;e++)y.push(g?[c,d+(l-1-e)*f/(l-1)]:[c+(l-1-e)*p/(l-1),_])}t.vertices=y;for(let e=0;e<t._vertices.length;e++){let i=e<l?o[e]:o[2*l-1-e];t._vertices.setDataScopeRef(e,i)}let m=t.classId??t.id,b=Math.floor(t._vertices.length/2);for(let e in t.scene._encodings)if(e===m)for(let i of Object.values(t.scene._encodings[e]))1===i._scales.length&&(i._elem2scale={[t.id]:i._scales[0]},i._elemGroups=[[t]]);else if(e===m+"_vAny"){let i=[];for(let e=0;e<t._vertices.length;e++)t._vertices.hasDataScope(e)&&i.push(e);let r=[{parent:t,indices:i}];for(let s of Object.values(t.scene._encodings[e]))if(1===s._scales.length){s._elem2scale={},s._elemGroups=[{type:"vertexIndices",groups:r}];for(let e of i)s._elem2scale[Ce(t,e)]=s._scales[0]}}else if(e.startsWith(m+"_v")){let i=e===m+"_v0",r=i?0:b,s=i?b:t._vertices.length,n=[];for(let e=r;e<s;e++)t._vertices.hasDataScope(e)&&n.push(e);let a=[{parent:t,indices:n}];for(let i of Object.values(t.scene._encodings[e]))if(1===i._scales.length){i._elem2scale={},i._elemGroups=[{type:"vertexIndices",groups:a}];for(let e of n)i._elem2scale[Ce(t,e)]=i._scales[0]}}t.dataScope=n}(0,this._area,this._repeatAttr,t),void(this.needsFullRender=!0)}if(!this._collection||!this._repeatAttr)return;let e=this.inputVars[0];if(!e)return;let t=e.dataset,i=this._collection;Ie(i);i.dataScope=void 0,ur(0,i,this._repeatAttr,t),i.dataScope=N(t);for(let e of ri(i.children[0],!0))e.refreshElementMappings();if(i.layout)for(let e of i.layout.refElements)e instanceof Oi&&(e._elems=i.children.slice());this.needsFullRender=!0}}class pr extends ye{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e.type===xe.AFFIXATION).affixation,t=e.base,i=e.element,r=we(t),s=we(i),n=e.channels,a=e.attribute;if(de(i)&&de(t)){let e=r.map(e=>e.datum[a]);s=s.filter(t=>e.includes(t.datum[a]));let t=(e,t)=>e.datum[a]<t.datum[a]?-1:e.datum[a]>t.datum[a]?1:0;s.sort(t),r.sort(t)}if(n.includes("x")||n.includes("y"))for(let t of n)this._handleXY(t,s,r,e.getElementAnchor(t),e.getBaseAnchor(t),e.getOffset(t));(n.includes("radialDistance")||n.includes("angle"))&&this._handlePolar(s,r,e);let o=Le(i,!0);for(let e of o)le(e)}_handlePolar(e,t,r){let s=r.hasChannel("radialDistance")?r.getBaseAnchor("radialDistance"):he.MIDDLE,n=r.hasChannel("radialDistance")?r.getElementAnchor("radialDistance"):he.MIDDLE,a=r.hasChannel("angle")?r.getBaseAnchor("angle"):he.CENTER;r.hasChannel("angle")?r.getElementAnchor("angle"):he.CENTER;let o=r.hasChannel("radialDistance")?r.getOffset("radialDistance"):0,l=r.hasChannel("angle")?r.getOffset("angle"):0;if([i.Arc,i.Ring].indexOf(t[0].type)>=0&&e[0].type==i.SimpleText)for(let r=0;r<e.length;r++){let n=t[r],l=e[r],h=s===he.MIDDLE?(n.outerRadius+n.innerRadius)/2:s===he.TOP?n.outerRadius-5:n.innerRadius+5;if(h+=o,n.type===i.Arc){let e=Zi(n.x,n.y,h,n.startAngle),t=Zi(n.x,n.y,h,n.endAngle);n.endAngle>=180&&n.endAngle<=360?l._textPath=["M",e[0],e[1],"A",h,h,n.angle,n.angle>=180?1:0,0,t[0],t[1]].join(" "):l._textPath=["M",t[0],t[1],"A",h,h,n.angle,n.angle>=180?1:0,1,e[0],e[1]].join(" ")}else if(n.type===i.Ring){let e=275,t=265,i=350,r=Zi(n.x,n.y,h,e),s=Zi(n.x,n.y,h,t);l._textPath=["M",s[0],s[1],"A",h,h,i,1,1,r[0],r[1]].join(" ")}l.textPathOffset=a===he.LEFT?"0%":"50%"}else for(let r=0;r<e.length;r++){let h,c,d=t[r],u=e[r];d.type==i.Arc||d.type==i.Ring?(c="left"==a?d.endAngle+l:"center"==a?d.startAngle+d.angle/2+l:d.startAngle+l,h="top"==s?d.outerRadius+o:"bottom"==s?d.innerRadius+o:(d.outerRadius+d.innerRadius)/2+o):d.type==i.Circle&&(c=90,h="top"==s?d.radius+o:"bottom"==s?o:d.radius/2+o),gi(u,d.x-u.x,d.y-h-u.bounds[n]),u._rotate=[90-c,d.x,d.y]}}_handleXY(e,t,r,s,n,a){for(let o=0;o<t.length;o++){let l,h=r[o],c=t[o];if(Et(h)){l=wt(h,[he.LEFT,he.TOP].includes(n)?0:[he.CENTER,he.MIDDLE].includes(n)?.5:1)[e]}else l=h.bounds[n]+a;t[0].type===i.SimpleText?(c.anchor["x"==e?0:1]=s,Qi(c,e,l)):"x"==e?gi(c,l-c.bounds[s],0):gi(c,0,l-c.bounds[s])}}}class fr extends be{constructor(e,t){super(e),this._affx=t}get affixation(){return this._affx}}class gr extends ye{constructor(e){super(e)}run(){let e=this.inputVars[0],t=this.outputVar,i=e.attribute,r=t.attribute,s=e.dataset,n=t.dataset,o=this.args,l=null!=o.min?o.min:s.summary(i).min,h=null!=o.max?o.max:s.summary(i).max,c=l,d=[];for(;c<h;)d.push(c),c+=o.interval;d.push(c);let u={},_={};if(o.groupBy)for(let e of s.data){let t=o.groupBy.map(t=>e[t]).join("-");t in u||(u[t]=[],_[t]=o.groupBy.map(t=>e[t])),u[t].push(e[i])}else u[""]=s.data.map(e=>e[i]),_[""]="";let p=[];for(let e in _){let t=yr(mr(o.bandwidth),d,u[e]);for(let s of t){let t={};""!==e&&o.groupBy.forEach((i,r)=>t[i]=_[e][r]),t[i]=s[0],t[r]=s[1],p.push(t)}}let f={};if(f[i]=s.type(i),f[r]=a.Number,o.groupBy)for(let e of o.groupBy)f[e]=s.type(e);n.initialize(p,n.url,f)}}function yr(t,i,r){return i.map(i=>[i,e.mean(r,e=>t(i-e))])}function mr(e){return t=>Math.abs(t/=e)<=1?.75*(1-t*t)/e:0}class br extends ye{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof hr);if(!e)return;let t=e.dataset,i=this.outputVar.dataset;this._spec.fn(t,i,this._spec)}}class xr extends ye{constructor(e){super(e)}run(){super.run();let t=this._outputVars[0].element,i=we(t.parent);for(let t of i){let i=t.layout;if(!i)return;let r=t.children.map(e=>({name:e.id,radius:e.radius,itm:e})),s=r.reduce((e,t)=>e+Math.pow(t.radius,2),0),n=Math.sqrt(s);void 0===i._width&&(i._width=n),void 0===i._height&&(i._height=n);let a=e.hierarchy({name:"root",children:r}).sum(e=>e.radius?e.radius:0).sort((e,t)=>t.value-e.value);e.pack().size([i._width,i._height]).radius(e=>e.value)(a);for(let e of a.children){let t=e.data.itm;gi(t,i._x-a.x+e.x-t.x,i._y-a.y+e.y-t.y)}}let r=Le(t,!0);for(let e of r)le(e)}}class vr extends ye{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof Be&&e.property==ze.AXIS_PATH_POSITION).element;e instanceof $t?this._runForEncoding(e):e instanceof Oi&&this._runForLayout(e),le(e._title)}_runForEncoding(e){let t=e.channel,i=ae(e.elements);if("x"==t)e._title.x=(e.scale.range[0]+e.scale.range[1])/2,e._title._y=e.orientation==Kt?e._pathPos+e.titleOffset:e._pathPos-e.titleOffset;else if("width"==t)e._title.x=i.left+e.scale.rangeExtent/2,e._title._y=e.orientation==Kt?e._pathPos+e.titleOffset:e._pathPos-e.titleOffset;else if("y"===t)e._rotateYTitle?(e._title.x=e.orientation==Zt?e._pathPos-e.titleOffset:e._pathPos+e.titleOffset,e._title._y=(e.scale.range[0]+e.scale.range[1])/2,e._title._rotate=e.orientation==Zt?[-90,e._title._x,e._title._y]:[90,e._title._x,e._title._y]):(e._title.x=e.orientation==Zt?e._pathPos-e.titleOffset:e._pathPos+e.titleOffset,e._title._y=d3.min([e.scale.range[0],e.scale.range[1]])-25,e._title._rotate=void 0);else if("height"===t)e._title.x=i.center,e._title._y=(i.top+i.bottom)/2-i.width/2-e.titleOffset,e._title._rotate=e.orientation==Zt?[-90,i.center,i.middle]:[90,i.center,i.middle];else if("radialDistance"===t){let t=e.elements[0].parent;e._title.x=t.x+e.scale.rangeExtent/2,e._title._y=e.orientation==Kt?e._pathPos+e.titleOffset:e._pathPos-e.titleOffset,e._rotate&&(e._title._rotate=e._rotate.slice())}}_runForLayout(e){let t=e.channel,i=e.elements[0].parent.layout&&e.elements[0].parent.layout.type==fe.STACK?oe(e.elements):ae(e.elements);if("x"==t)e._title.x=i.center,e._title._y=e.orientation==Kt?e._pathPos+e.titleOffset:e._pathPos-e.titleOffset;else if("y"===t)e._title.x=i.center,e._title._y=i.middle-i.width/2-e.titleOffset,e._title._rotate=e.orientation==Zt?[-90,i.center,i.middle]:[90,i.center,i.middle];else if("angle"===t){let t=e.elements[0].parent.layout;t.type===fe.CLUSTER&&(e._title.x=t.x,e._title._y=t.y)}}}class wr extends Mi{constructor(e){super(e)}run(){super.run();let t,i=this.vars.find(e=>e.type===xe.ALIGNMENT).alignment,r=i.anchor,s=i.elements;r==he.Top||r==he.LEFT?t=e.min(s.map(e=>e.bounds[r])):r==he.BOTTOM||r==he.RIGHT?t=e.max(s.map(e=>e.bounds[r])):r!=he.CENTER&&r!=he.MIDDLE||(t=e.mean(s.map(e=>e.bounds[r])));for(let e of s){let s=pi(e,i.channel);if(s){let n=t-e.bounds[r];gi(s,"x"===i.channel?n:0,"x"===i.channel?0:n)}}for(let e of s)le(e)}}class Er extends be{constructor(e,t){super(e),this._aln=t}get alignment(){return this._aln}}class Cr extends ye{constructor(e){super(e)}run(){super.run();let t=this._outputVars[0].element,i=we(t.parent);for(let t of i){let i=t.layout;if(!i)continue;let r=j(t.children[0]);if(!r)continue;let s=r.linkList.map(e=>({source:r.getNode(e.source),target:r.getNode(e.target)})),n=e.forceSimulation(r.nodeList).force("charge",e.forceManyBody().strength(-i._repulsion)).force("link",e.forceLink(s).id(e=>e.id).distance(i._linkDistance)).force("x",e.forceX()).force("y",e.forceY()).force("center",e.forceCenter(i._x,i._y).strength(i._attraction));n.stop(),n.tick(i._iterations);for(let e=0;e<t.children.length;e++){let i=t.children[e],s=r.nodeList[e];gi(i,s.x-i.x,s.y-i.y)}}let r=Le(t,!0);for(let e of r)le(e)}}class Ar extends ye{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=we(e);switch(e.type){case i.Arc:this._updateArcLinks(t);break;case i.BezierCurve:this._updateBezierLinks(t);break;case i.BundledPath:this._updateBundledLinks(t);break;case i.Chord:this._updateChordLinks(t);break;case i.Line:default:this._updateLineLinks(t)}le(e)}_updateArcLinks(e){for(let t of e){let e=t.source.x<t.target.x?t.source:t.target,i=t.source.x<t.target.x?t.target:t.source;t._x=(e.x+i.x)/2,t._y=(e.y+i.y)/2,t._innerRadius=Math.sqrt(Math.pow(e.x-i.x,2)+Math.pow(e.y-i.y,2))/2,t._outerRadius=t._innerRadius+t._thickness;let r=Ot(e.x,e.y,t._x,t._y),s=Ot(i.x,i.y,t._x,t._y);t.direction===gt.CLOCKWISE&&([r,s]=[s,r]),Qi(t,"startAngle",r),Qi(t,"angle",Math.abs(s-r))}}_updateBezierLinks(e){let t=this._inputVars[0].element,i=we(t),r=t.parent.layout;r.type===fe.DIRECTED||r.type===fe.TIDYTREE?this._updateBezierLinksForDirectedGraph(i,e,r):r.type===fe.CLUSTER&&this._updateBezierLinksForClusteredGraph(i,e,r)}_updateBezierLinksForClusteredGraph(t,i,r){const s=r._d3Root.descendants(),n=new Map(s.map(e=>[Sr(e),e])),a=new Map(s.map(e=>[e.data[Y],Sr(e)]));if(r.isRadial()){const t=e.linkRadial().angle(e=>e.x).radius(e=>e.y);for(let e of i){let i=e.source,s=e.target,o=i.datum[Y],l=s.datum[Y],h=n.get(a.get(o)),c=n.get(a.get(l));e._d=At(t({source:h,target:c}),r.x,r.y)}}else if(r.orientation===ut){const t=e.linkVertical().x(e=>e.x).y(e=>e.y);for(let e of i){let i=e.source,s=e.target,o=i.datum[Y],l=s.datum[Y],h=n.get(a.get(o)),c=n.get(a.get(l));e._d=At(t({source:h,target:c}),r.left-r._x0,r.top)}}else if(r.orientation===dt){const t=e.linkHorizontal().x(e=>e.y).y(e=>e.x);for(let e of i){let i=e.source,s=e.target,o=i.datum[Y],l=s.datum[Y],h=n.get(a.get(o)),c=n.get(a.get(l));e._d=At(t({source:h,target:c}),r.left,r.top-r._x0)}}}_updateBezierLinksForDirectedGraph(e,t,i){let r={},s={},n={},a={};for(let t of e){s[t.id]=0,r[t.id]=0;let e=t.links.filter(e=>e.source===t),i=t.links.filter(e=>e.target===t);a[t.id]=i.map(e=>e.strokeWidth).reduce((e,t)=>e+t,0),n[t.id]=e.map(e=>e.strokeWidth).reduce((e,t)=>e+t,0)}const o=i.direction===ft.Left2Right||i.direction===ft.Right2Left;if(i.spreadLinks){const e=o?e=>e.bounds.y:e=>e.bounds.x,i=[...t].sort((t,i)=>e(t.target)-e(i.target));for(let e of i)e._outLane=r[e.source.id],r[e.source.id]+=e.strokeWidth;const n=[...t].sort((t,i)=>e(t.source)-e(i.source));for(let e of n)e._inLane=s[e.target.id],s[e.target.id]+=e.strokeWidth}for(let e of t){let t,r,s,l,h=e.source,c=e.target;i.spreadLinks?o?(t=h.bounds[e.sourceAnchor[0]]+e.sourceOffset[0],s=c.bounds[e.targetAnchor[0]]+e.targetOffset[0],r=h.bounds[e.sourceAnchor[1]]+e.sourceOffset[1]-n[h.id]/2+e._outLane+e.strokeWidth/2,l=c.bounds[e.targetAnchor[1]]+e.targetOffset[1]-a[c.id]/2+e._inLane+e.strokeWidth/2):(r=h.bounds[e.sourceAnchor[1]]+e.sourceOffset[1],l=c.bounds[e.targetAnchor[1]]+e.targetOffset[1],t=h.bounds[e.sourceAnchor[0]]+e.sourceOffset[0]-n[h.id]/2+e._outLane+e.strokeWidth/2,s=c.bounds[e.targetAnchor[0]]+e.targetOffset[0]-a[c.id]/2+e._inLane+e.strokeWidth/2):(t=h.bounds[e.sourceAnchor[0]]+e.sourceOffset[0],r=h.bounds[e.sourceAnchor[1]]+e.sourceOffset[1],s=c.bounds[e.targetAnchor[0]]+e.targetOffset[0],l=c.bounds[e.targetAnchor[1]]+e.targetOffset[1]),e.orientation===dt?e.vertices=[[t,r],[(t+s)/2,r],[t,l],[s,l]]:e.orientation===ut&&(e.vertices=[[t,r],[t,(r+l)/2],[s,r],[s,l]])}}_updateBundledLinks(t){let i=this._inputVars[0].element.parent.layout;if(i.type!==fe.CLUSTER)throw"Bundled links must work on a cluster layout";let r=i._d3Root.leaves();const s=new Map(r.map(e=>[Sr(e),e])),n=new Map(r.map(e=>[e.data[Y],Sr(e)])),a=e.lineRadial().curve(e.curveBundle.beta(t[0]._strength)).radius(e=>e.y).angle(e=>e.x);for(let e of t){let t=e.source.datum[Y],r=e.target.datum[Y],o=s.get(n.get(t)),l=s.get(n.get(r));(o.outgoing??=[]).push([o,l]),l.incoming??=[];let h=o.path(l);e._d=At(a(h),i.x,i.y),e._dirty=!0}}_updateChordLinks(e){for(let t of e){let e=t.source,i=t.target,r=Zi(e.x,e.y,e.innerRadius,e.startAngle),s=Zi(e.x,e.y,e.innerRadius,e.endAngle),n=Zi(i.x,i.y,i.innerRadius,i.startAngle),a=Zi(i.x,i.y,i.innerRadius,i.endAngle);t._d=["M",r[0],r[1],"Q",e.x,e.y,a[0],a[1],"A",e.x,e.y,i.angle,i.angle>180?1:0,1,n[0],n[1],"Q",e.x,e.y,s[0],s[1],"A",e.x,e.y,e.angle,e.angle>180?1:0,1,r[0],r[1]].join(" "),t._dirty=!0}}_updateLineLinks(e){for(let t of e){let e=t.source,i=t.target;t.vertices[0].x=e.bounds.x,t.vertices[0].y=e.bounds.y,t.vertices[1].x=i.bounds.x,t.vertices[1].y=i.bounds.y,t._dirty=!0}}}function Sr(e){return`${e.parent?Sr(e.parent)+".":""}${e.data[Y]}`}var kr="\0";function Rr(e,t){e[t]?e[t]++:e[t]=1}function Tr(e,t){--e[t]||delete e[t]}function Or(e,t,i,r){var s=""+t,n=""+i;if(!e&&s>n){var a=s;s=n,n=a}return s+""+n+""+(void 0===r?"\0":r)}function Ir(e,t){return Or(e,t.v,t.w,t.name)}var Nr=class{_isDirected=!0;_isMultigraph=!1;_isCompound=!1;_label;_defaultNodeLabelFn=()=>{};_defaultEdgeLabelFn=()=>{};_nodes={};_in={};_preds={};_out={};_sucs={};_edgeObjs={};_edgeLabels={};_nodeCount=0;_edgeCount=0;_parent;_children;constructor(e){e&&(this._isDirected=!Object.hasOwn(e,"directed")||e.directed,this._isMultigraph=!!Object.hasOwn(e,"multigraph")&&e.multigraph,this._isCompound=!!Object.hasOwn(e,"compound")&&e.compound),this._isCompound&&(this._parent={},this._children={},this._children[kr]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(e){return this._label=e,this}graph(){return this._label}setDefaultNodeLabel(e){return this._defaultNodeLabelFn=e,"function"!=typeof e&&(this._defaultNodeLabelFn=()=>e),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var e=this;return this.nodes().filter(t=>0===Object.keys(e._in[t]).length)}sinks(){var e=this;return this.nodes().filter(t=>0===Object.keys(e._out[t]).length)}setNodes(e,t){var i=arguments,r=this;return e.forEach(function(e){i.length>1?r.setNode(e,t):r.setNode(e)}),this}setNode(e,t){return Object.hasOwn(this._nodes,e)?(arguments.length>1&&(this._nodes[e]=t),this):(this._nodes[e]=arguments.length>1?t:this._defaultNodeLabelFn(e),this._isCompound&&(this._parent[e]=kr,this._children[e]={},this._children[kr][e]=!0),this._in[e]={},this._preds[e]={},this._out[e]={},this._sucs[e]={},++this._nodeCount,this)}node(e){return this._nodes[e]}hasNode(e){return Object.hasOwn(this._nodes,e)}removeNode(e){var t=this;if(Object.hasOwn(this._nodes,e)){var i=e=>t.removeEdge(t._edgeObjs[e]);delete this._nodes[e],this._isCompound&&(this._removeFromParentsChildList(e),delete this._parent[e],this.children(e).forEach(function(e){t.setParent(e)}),delete this._children[e]),Object.keys(this._in[e]).forEach(i),delete this._in[e],delete this._preds[e],Object.keys(this._out[e]).forEach(i),delete this._out[e],delete this._sucs[e],--this._nodeCount}return this}setParent(e,t){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(void 0===t)t=kr;else{for(var i=t+="";void 0!==i;i=this.parent(i))if(i===e)throw new Error("Setting "+t+" as parent of "+e+" would create a cycle");this.setNode(t)}return this.setNode(e),this._removeFromParentsChildList(e),this._parent[e]=t,this._children[t][e]=!0,this}_removeFromParentsChildList(e){delete this._children[this._parent[e]][e]}parent(e){if(this._isCompound){var t=this._parent[e];if(t!==kr)return t}}children(e=kr){if(this._isCompound){var t=this._children[e];if(t)return Object.keys(t)}else{if(e===kr)return this.nodes();if(this.hasNode(e))return[]}}predecessors(e){var t=this._preds[e];if(t)return Object.keys(t)}successors(e){var t=this._sucs[e];if(t)return Object.keys(t)}neighbors(e){var t=this.predecessors(e);if(t){const r=new Set(t);for(var i of this.successors(e))r.add(i);return Array.from(r.values())}}isLeaf(e){return 0===(this.isDirected()?this.successors(e):this.neighbors(e)).length}filterNodes(e){var t=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});t.setGraph(this.graph());var i=this;Object.entries(this._nodes).forEach(function([i,r]){e(i)&&t.setNode(i,r)}),Object.values(this._edgeObjs).forEach(function(e){t.hasNode(e.v)&&t.hasNode(e.w)&&t.setEdge(e,i.edge(e))});var r={};function s(e){var n=i.parent(e);return void 0===n||t.hasNode(n)?(r[e]=n,n):n in r?r[n]:s(n)}return this._isCompound&&t.nodes().forEach(e=>t.setParent(e,s(e))),t}setDefaultEdgeLabel(e){return this._defaultEdgeLabelFn=e,"function"!=typeof e&&(this._defaultEdgeLabelFn=()=>e),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(e,t){var i=this,r=arguments;return e.reduce(function(e,s){return r.length>1?i.setEdge(e,s,t):i.setEdge(e,s),s}),this}setEdge(){var e,t,i,r,s=!1,n=arguments[0];"object"==typeof n&&null!==n&&"v"in n?(e=n.v,t=n.w,i=n.name,2===arguments.length&&(r=arguments[1],s=!0)):(e=n,t=arguments[1],i=arguments[3],arguments.length>2&&(r=arguments[2],s=!0)),e=""+e,t=""+t,void 0!==i&&(i=""+i);var a=Or(this._isDirected,e,t,i);if(Object.hasOwn(this._edgeLabels,a))return s&&(this._edgeLabels[a]=r),this;if(void 0!==i&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(e),this.setNode(t),this._edgeLabels[a]=s?r:this._defaultEdgeLabelFn(e,t,i);var o=function(e,t,i,r){var s=""+t,n=""+i;if(!e&&s>n){var a=s;s=n,n=a}var o={v:s,w:n};r&&(o.name=r);return o}(this._isDirected,e,t,i);return e=o.v,t=o.w,Object.freeze(o),this._edgeObjs[a]=o,Rr(this._preds[t],e),Rr(this._sucs[e],t),this._in[t][a]=o,this._out[e][a]=o,this._edgeCount++,this}edge(e,t,i){var r=1===arguments.length?Ir(this._isDirected,arguments[0]):Or(this._isDirected,e,t,i);return this._edgeLabels[r]}edgeAsObj(){const e=this.edge(...arguments);return"object"!=typeof e?{label:e}:e}hasEdge(e,t,i){var r=1===arguments.length?Ir(this._isDirected,arguments[0]):Or(this._isDirected,e,t,i);return Object.hasOwn(this._edgeLabels,r)}removeEdge(e,t,i){var r=1===arguments.length?Ir(this._isDirected,arguments[0]):Or(this._isDirected,e,t,i),s=this._edgeObjs[r];return s&&(e=s.v,t=s.w,delete this._edgeLabels[r],delete this._edgeObjs[r],Tr(this._preds[t],e),Tr(this._sucs[e],t),delete this._in[t][r],delete this._out[e][r],this._edgeCount--),this}inEdges(e,t){var i=this._in[e];if(i){var r=Object.values(i);return t?r.filter(e=>e.v===t):r}}outEdges(e,t){var i=this._out[e];if(i){var r=Object.values(i);return t?r.filter(e=>e.w===t):r}}nodeEdges(e,t){var i=this.inEdges(e,t);if(i)return i.concat(this.outEdges(e,t))}},Lr={Graph:Nr,version:"2.2.4"},Pr=Nr,Vr={write:function(e){var t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:Dr(e),edges:Br(e)};void 0!==e.graph()&&(t.value=structuredClone(e.graph()));return t},read:function(e){var t=new Pr(e.options).setGraph(e.value);return e.nodes.forEach(function(e){t.setNode(e.v,e.value),e.parent&&t.setParent(e.v,e.parent)}),e.edges.forEach(function(e){t.setEdge({v:e.v,w:e.w,name:e.name},e.value)}),t}};function Dr(e){return e.nodes().map(function(t){var i=e.node(t),r=e.parent(t),s={v:t};return void 0!==i&&(s.value=i),void 0!==r&&(s.parent=r),s})}function Br(e){return e.edges().map(function(t){var i=e.edge(t),r={v:t.v,w:t.w};return void 0!==t.name&&(r.name=t.name),void 0!==i&&(r.value=i),r})}var Mr=function(e){var t,i={},r=[];function s(r){Object.hasOwn(i,r)||(i[r]=!0,t.push(r),e.successors(r).forEach(s),e.predecessors(r).forEach(s))}return e.nodes().forEach(function(e){t=[],s(e),t.length&&r.push(t)}),r};var Gr=class{_arr=[];_keyIndices={};size(){return this._arr.length}keys(){return this._arr.map(function(e){return e.key})}has(e){return Object.hasOwn(this._keyIndices,e)}priority(e){var t=this._keyIndices[e];if(void 0!==t)return this._arr[t].priority}min(){if(0===this.size())throw new Error("Queue underflow");return this._arr[0].key}add(e,t){var i=this._keyIndices;if(e=String(e),!Object.hasOwn(i,e)){var r=this._arr,s=r.length;return i[e]=s,r.push({key:e,priority:t}),this._decrease(s),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var e=this._arr.pop();return delete this._keyIndices[e.key],this._heapify(0),e.key}decrease(e,t){var i=this._keyIndices[e];if(t>this._arr[i].priority)throw new Error("New priority is greater than current priority. Key: "+e+" Old: "+this._arr[i].priority+" New: "+t);this._arr[i].priority=t,this._decrease(i)}_heapify(e){var t=this._arr,i=2*e,r=i+1,s=e;i<t.length&&(s=t[i].priority<t[s].priority?i:s,r<t.length&&(s=t[r].priority<t[s].priority?r:s),s!==e&&(this._swap(e,s),this._heapify(s)))}_decrease(e){for(var t,i=this._arr,r=i[e].priority;0!==e&&!(i[t=e>>1].priority<r);)this._swap(e,t),e=t}_swap(e,t){var i=this._arr,r=this._keyIndices,s=i[e],n=i[t];i[e]=n,i[t]=s,r[n.key]=e,r[s.key]=t}},zr=Gr,Fr=function(e,t,i,r){return function(e,t,i,r){var s,n,a={},o=new zr,l=function(e){var t=e.v!==s?e.v:e.w,r=a[t],l=i(e),h=n.distance+l;if(l<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+e+" Weight: "+l);h<r.distance&&(r.distance=h,r.predecessor=s,o.decrease(t,h))};e.nodes().forEach(function(e){var i=e===t?0:Number.POSITIVE_INFINITY;a[e]={distance:i},o.add(e,i)});for(;o.size()>0&&(s=o.removeMin(),(n=a[s]).distance!==Number.POSITIVE_INFINITY);)r(s).forEach(l);return a}(e,String(t),i||jr,r||function(t){return e.outEdges(t)})},jr=()=>1;var Wr=Fr,Yr=function(e,t,i){return e.nodes().reduce(function(r,s){return r[s]=Wr(e,s,t,i),r},{})};var Ur=function(e){var t=0,i=[],r={},s=[];function n(a){var o=r[a]={onStack:!0,lowlink:t,index:t++};if(i.push(a),e.successors(a).forEach(function(e){Object.hasOwn(r,e)?r[e].onStack&&(o.lowlink=Math.min(o.lowlink,r[e].index)):(n(e),o.lowlink=Math.min(o.lowlink,r[e].lowlink))}),o.lowlink===o.index){var l,h=[];do{l=i.pop(),r[l].onStack=!1,h.push(l)}while(a!==l);s.push(h)}}return e.nodes().forEach(function(e){Object.hasOwn(r,e)||n(e)}),s};var Hr=Ur,Xr=function(e){return Hr(e).filter(function(t){return t.length>1||1===t.length&&e.hasEdge(t[0],t[0])})};var qr=function(e,t,i){return function(e,t,i){var r={},s=e.nodes();return s.forEach(function(e){r[e]={},r[e][e]={distance:0},s.forEach(function(t){e!==t&&(r[e][t]={distance:Number.POSITIVE_INFINITY})}),i(e).forEach(function(i){var s=i.v===e?i.w:i.v,n=t(i);r[e][s]={distance:n,predecessor:e}})}),s.forEach(function(e){var t=r[e];s.forEach(function(i){var n=r[i];s.forEach(function(i){var r=n[e],s=t[i],a=n[i],o=r.distance+s.distance;o<a.distance&&(a.distance=o,a.predecessor=s.predecessor)})})}),r}(e,t||Kr,i||function(t){return e.outEdges(t)})},Kr=()=>1;function Zr(e){var t={},i={},r=[];if(e.sinks().forEach(function s(n){if(Object.hasOwn(i,n))throw new $r;Object.hasOwn(t,n)||(i[n]=!0,t[n]=!0,e.predecessors(n).forEach(s),delete i[n],r.push(n))}),Object.keys(t).length!==e.nodeCount())throw new $r;return r}class $r extends Error{constructor(){super(...arguments)}}var Jr=Zr;Zr.CycleException=$r;var Qr=Jr;var es=function(e,t,i){Array.isArray(t)||(t=[t]);var r=e.isDirected()?t=>e.successors(t):t=>e.neighbors(t),s="post"===i?ts:is,n=[],a={};return t.forEach(t=>{if(!e.hasNode(t))throw new Error("Graph does not have node: "+t);s(t,r,a,n)}),n};function ts(e,t,i,r){for(var s=[[e,!1]];s.length>0;){var n=s.pop();n[1]?r.push(n[0]):Object.hasOwn(i,n[0])||(i[n[0]]=!0,s.push([n[0],!0]),rs(t(n[0]),e=>s.push([e,!1])))}}function is(e,t,i,r){for(var s=[e];s.length>0;){var n=s.pop();Object.hasOwn(i,n)||(i[n]=!0,r.push(n),rs(t(n),e=>s.push(e)))}}function rs(e,t){for(var i=e.length;i--;)t(e[i],i,e);return e}var ss=es;var ns=es;var as=Nr,os=Gr;var ls={Graph:Lr.Graph,json:Vr,alg:{components:Mr,dijkstra:Fr,dijkstraAll:Yr,findCycles:Xr,floydWarshall:qr,isAcyclic:function(e){try{Qr(e)}catch(e){if(e instanceof Qr.CycleException)return!1;throw e}return!0},postorder:function(e,t){return ss(e,t,"post")},preorder:function(e,t){return ns(e,t,"pre")},prim:function(e,t){var i,r=new as,s={},n=new os;function a(e){var r=e.v===i?e.w:e.v,a=n.priority(r);if(void 0!==a){var o=t(e);o<a&&(s[r]=i,n.decrease(r,o))}}if(0===e.nodeCount())return r;e.nodes().forEach(function(e){n.add(e,Number.POSITIVE_INFINITY),r.setNode(e)}),n.decrease(e.nodes()[0],0);var o=!1;for(;n.size()>0;){if(i=n.removeMin(),Object.hasOwn(s,i))r.setEdge(i,s[i]);else{if(o)throw new Error("Input graph is not connected: "+e);o=!0}e.nodeEdges(i).forEach(a)}return r},tarjan:Ur,topsort:Jr},version:Lr.version};function hs(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function cs(e,t){if("_next"!==e&&"_prev"!==e)return t}let ds=ls.Graph,us=class{constructor(){let e={};e._next=e._prev=e,this._sentinel=e}dequeue(){let e=this._sentinel,t=e._prev;if(t!==e)return hs(t),t}enqueue(e){let t=this._sentinel;e._prev&&e._next&&hs(e),e._next=t._next,t._next._prev=e,t._next=e,e._prev=t}toString(){let e=[],t=this._sentinel,i=t._prev;for(;i!==t;)e.push(JSON.stringify(i,cs)),i=i._prev;return"["+e.join(", ")+"]"}};var _s=function(e,t){if(e.nodeCount()<=1)return[];let i=function(e,t){let i=new ds,r=0,s=0;e.nodes().forEach(e=>{i.setNode(e,{v:e,in:0,out:0})}),e.edges().forEach(e=>{let n=i.edge(e.v,e.w)||0,a=t(e),o=n+a;i.setEdge(e.v,e.w,o),s=Math.max(s,i.node(e.v).out+=a),r=Math.max(r,i.node(e.w).in+=a)});let n=function(e){const t=[];for(let i=0;i<e;i++)t.push(i);return t}(s+r+3).map(()=>new us),a=r+1;return i.nodes().forEach(e=>{gs(n,a,i.node(e))}),{graph:i,buckets:n,zeroIdx:a}}(e,t||ps);return function(e,t,i){let r,s=[],n=t[t.length-1],a=t[0];for(;e.nodeCount();){for(;r=a.dequeue();)fs(e,t,i,r);for(;r=n.dequeue();)fs(e,t,i,r);if(e.nodeCount())for(let n=t.length-2;n>0;--n)if(r=t[n].dequeue(),r){s=s.concat(fs(e,t,i,r,!0));break}}return s}(i.graph,i.buckets,i.zeroIdx).flatMap(t=>e.outEdges(t.v,t.w))};let ps=()=>1;function fs(e,t,i,r,s){let n=s?[]:void 0;return e.inEdges(r.v).forEach(r=>{let a=e.edge(r),o=e.node(r.v);s&&n.push({v:r.v,w:r.w}),o.out-=a,gs(t,i,o)}),e.outEdges(r.v).forEach(r=>{let s=e.edge(r),n=r.w,a=e.node(n);a.in-=s,gs(t,i,a)}),e.removeNode(r.v),n}function gs(e,t,i){i.out?i.in?e[i.out-i.in+t].enqueue(i):e[e.length-1].enqueue(i):e[0].enqueue(i)}let ys=ls.Graph;var ms={addBorderNode:function(e,t,i,r){let s={width:0,height:0};arguments.length>=4&&(s.rank=i,s.order=r);return bs(e,"border",s,t)},addDummyNode:bs,applyWithChunking:vs,asNonCompoundGraph:function(e){let t=new ys({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(i=>{e.children(i).length||t.setNode(i,e.node(i))}),e.edges().forEach(i=>{t.setEdge(i,e.edge(i))}),t},buildLayerMatrix:function(e){let t=As(ws(e)+1).map(()=>[]);return e.nodes().forEach(i=>{let r=e.node(i),s=r.rank;void 0!==s&&(t[s][r.order]=i)}),t},intersectRect:function(e,t){let i,r,s=e.x,n=e.y,a=t.x-s,o=t.y-n,l=e.width/2,h=e.height/2;if(!a&&!o)throw new Error("Not possible to find intersection inside of the rectangle");Math.abs(o)*l>Math.abs(a)*h?(o<0&&(h=-h),i=h*a/o,r=h):(a<0&&(l=-l),i=l,r=l*o/a);return{x:s+i,y:n+r}},mapValues:function(e,t){let i=t;"string"==typeof t&&(i=e=>e[t]);return Object.entries(e).reduce((e,[t,r])=>(e[t]=i(r,t),e),{})},maxRank:ws,normalizeRanks:function(e){let t=e.nodes().map(t=>{let i=e.node(t).rank;return void 0===i?Number.MAX_VALUE:i}),i=vs(Math.min,t);e.nodes().forEach(t=>{let r=e.node(t);Object.hasOwn(r,"rank")&&(r.rank-=i)})},notime:function(e,t){return t()},partition:function(e,t){let i={lhs:[],rhs:[]};return e.forEach(e=>{t(e)?i.lhs.push(e):i.rhs.push(e)}),i},pick:function(e,t){const i={};for(const r of t)void 0!==e[r]&&(i[r]=e[r]);return i},predecessorWeights:function(e){let t=e.nodes().map(t=>{let i={};return e.inEdges(t).forEach(t=>{i[t.v]=(i[t.v]||0)+e.edge(t).weight}),i});return Ss(e.nodes(),t)},range:As,removeEmptyRanks:function(e){let t=e.nodes().map(t=>e.node(t).rank),i=vs(Math.min,t),r=[];e.nodes().forEach(t=>{let s=e.node(t).rank-i;r[s]||(r[s]=[]),r[s].push(t)});let s=0,n=e.graph().nodeRankFactor;Array.from(r).forEach((t,i)=>{void 0===t&&i%n!==0?--s:void 0!==t&&s&&t.forEach(t=>e.node(t).rank+=s)})},simplify:function(e){let t=(new ys).setGraph(e.graph());return e.nodes().forEach(i=>t.setNode(i,e.node(i))),e.edges().forEach(i=>{let r=t.edge(i.v,i.w)||{weight:0,minlen:1},s=e.edge(i);t.setEdge(i.v,i.w,{weight:r.weight+s.weight,minlen:Math.max(r.minlen,s.minlen)})}),t},successorWeights:function(e){let t=e.nodes().map(t=>{let i={};return e.outEdges(t).forEach(t=>{i[t.w]=(i[t.w]||0)+e.edge(t).weight}),i});return Ss(e.nodes(),t)},time:function(e,t){let i=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-i)+"ms")}},uniqueId:Cs,zipObject:Ss};function bs(e,t,i,r){for(var s=r;e.hasNode(s);)s=Cs(r);return i.dummy=t,e.setNode(s,i),s}const xs=65535;function vs(e,t){if(t.length>xs){const i=function(e,t=xs){const i=[];for(let r=0;r<e.length;r+=t){const s=e.slice(r,r+t);i.push(s)}return i}(t);return e.apply(null,i.map(t=>e.apply(null,t)))}return e.apply(null,t)}function ws(e){const t=e.nodes().map(t=>{let i=e.node(t).rank;return void 0===i?Number.MIN_VALUE:i});return vs(Math.max,t)}let Es=0;function Cs(e){return e+""+ ++Es}function As(e,t,i=1){null==t&&(t=e,e=0);let r=e=>e<t;i<0&&(r=e=>t<e);const s=[];for(let t=e;r(t);t+=i)s.push(t);return s}function Ss(e,t){return e.reduce((e,i,r)=>(e[i]=t[r],e),{})}let ks=_s,Rs=ms.uniqueId;var Ts={run:function(e){("greedy"===e.graph().acyclicer?ks(e,function(e){return t=>e.edge(t).weight}(e)):function(e){let t=[],i={},r={};function s(n){Object.hasOwn(r,n)||(r[n]=!0,i[n]=!0,e.outEdges(n).forEach(e=>{Object.hasOwn(i,e.w)?t.push(e):s(e.w)}),delete i[n])}return e.nodes().forEach(s),t}(e)).forEach(t=>{let i=e.edge(t);e.removeEdge(t),i.forwardName=t.name,i.reversed=!0,e.setEdge(t.w,t.v,i,Rs("rev"))})},undo:function(e){e.edges().forEach(t=>{let i=e.edge(t);if(i.reversed){e.removeEdge(t);let r=i.forwardName;delete i.reversed,delete i.forwardName,e.setEdge(t.w,t.v,i,r)}})}};let Os=ms;var Is={run:function(e){e.graph().dummyChains=[],e.edges().forEach(t=>function(e,t){let i,r,s,n=t.v,a=e.node(n).rank,o=t.w,l=e.node(o).rank,h=t.name,c=e.edge(t),d=c.labelRank;if(l===a+1)return;for(e.removeEdge(t),s=0,++a;a<l;++s,++a)c.points=[],r={width:0,height:0,edgeLabel:c,edgeObj:t,rank:a},i=Os.addDummyNode(e,"edge",r,"_d"),a===d&&(r.width=c.width,r.height=c.height,r.dummy="edge-label",r.labelpos=c.labelpos),e.setEdge(n,i,{weight:c.weight},h),0===s&&e.graph().dummyChains.push(i),n=i;e.setEdge(n,o,{weight:c.weight},h)}(e,t))},undo:function(e){e.graph().dummyChains.forEach(t=>{let i,r=e.node(t),s=r.edgeLabel;for(e.setEdge(r.edgeObj,s);r.dummy;)i=e.successors(t)[0],e.removeNode(t),s.points.push({x:r.x,y:r.y}),"edge-label"===r.dummy&&(s.x=r.x,s.y=r.y,s.width=r.width,s.height=r.height),t=i,r=e.node(t)})}};const{applyWithChunking:Ns}=ms;var Ls={longestPath:function(e){var t={};e.sources().forEach(function i(r){var s=e.node(r);if(Object.hasOwn(t,r))return s.rank;t[r]=!0;let n=e.outEdges(r).map(t=>null==t?Number.POSITIVE_INFINITY:i(t.w)-e.edge(t).minlen);var a=Ns(Math.min,n);return a===Number.POSITIVE_INFINITY&&(a=0),s.rank=a})},slack:function(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}};var Ps=ls.Graph,Vs=Ls.slack,Ds=function(e){var t,i,r=new Ps({directed:!1}),s=e.nodes()[0],n=e.nodeCount();r.setNode(s,{});for(;Bs(r,e)<n;)t=Ms(r,e),i=r.hasNode(t.v)?Vs(e,t):-Vs(e,t),Gs(r,e,i);return r};function Bs(e,t){return e.nodes().forEach(function i(r){t.nodeEdges(r).forEach(s=>{var n=s.v,a=r===n?s.w:n;e.hasNode(a)||Vs(t,s)||(e.setNode(a,{}),e.setEdge(r,a,{}),i(a))})}),e.nodeCount()}function Ms(e,t){return t.edges().reduce((i,r)=>{let s=Number.POSITIVE_INFINITY;return e.hasNode(r.v)!==e.hasNode(r.w)&&(s=Vs(t,r)),s<i[0]?[s,r]:i},[Number.POSITIVE_INFINITY,null])[1]}function Gs(e,t,i){e.nodes().forEach(e=>t.node(e).rank+=i)}var zs=Ds,Fs=Ls.slack,js=Ls.longestPath,Ws=ls.alg.preorder,Ys=ls.alg.postorder,Us=ms.simplify,Hs=Xs;function Xs(e){e=Us(e),js(e);var t,i=zs(e);for(Zs(i),qs(i,e);t=Js(i);)en(i,e,t,Qs(i,e,t))}function qs(e,t){var i=Ys(e,e.nodes());(i=i.slice(0,i.length-1)).forEach(i=>function(e,t,i){var r=e.node(i),s=r.parent;e.edge(i,s).cutvalue=Ks(e,t,i)}(e,t,i))}function Ks(e,t,i){var r=e.node(i).parent,s=!0,n=t.edge(i,r),a=0;return n||(s=!1,n=t.edge(r,i)),a=n.weight,t.nodeEdges(i).forEach(n=>{var o,l,h=n.v===i,c=h?n.w:n.v;if(c!==r){var d=h===s,u=t.edge(n).weight;if(a+=d?u:-u,o=i,l=c,e.hasEdge(o,l)){var _=e.edge(i,c).cutvalue;a+=d?-_:_}}}),a}function Zs(e,t){arguments.length<2&&(t=e.nodes()[0]),$s(e,{},1,t)}function $s(e,t,i,r,s){var n=i,a=e.node(r);return t[r]=!0,e.neighbors(r).forEach(s=>{Object.hasOwn(t,s)||(i=$s(e,t,i,s,r))}),a.low=n,a.lim=i++,s?a.parent=s:delete a.parent,i}function Js(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function Qs(e,t,i){var r=i.v,s=i.w;t.hasEdge(r,s)||(r=i.w,s=i.v);var n=e.node(r),a=e.node(s),o=n,l=!1;n.lim>a.lim&&(o=a,l=!0);var h=t.edges().filter(t=>l===tn(e,e.node(t.v),o)&&l!==tn(e,e.node(t.w),o));return h.reduce((e,i)=>Fs(t,i)<Fs(t,e)?i:e)}function en(e,t,i,r){var s=i.v,n=i.w;e.removeEdge(s,n),e.setEdge(r.v,r.w,{}),Zs(e),qs(e,t),function(e,t){var i=e.nodes().find(e=>!t.node(e).parent),r=Ws(e,i);(r=r.slice(1)).forEach(i=>{var r=e.node(i).parent,s=t.edge(i,r),n=!1;s||(s=t.edge(r,i),n=!0),t.node(i).rank=t.node(r).rank+(n?s.minlen:-s.minlen)})}(e,t)}function tn(e,t,i){return i.low<=t.lim&&t.lim<=i.lim}Xs.initLowLimValues=Zs,Xs.initCutValues=qs,Xs.calcCutValue=Ks,Xs.leaveEdge=Js,Xs.enterEdge=Qs,Xs.exchangeEdges=en;var rn=Ls.longestPath,sn=Ds,nn=Hs,an=function(e){var t=e.graph().ranker;if(t instanceof Function)return t(e);switch(e.graph().ranker){case"network-simplex":default:ln(e);break;case"tight-tree":!function(e){rn(e),sn(e)}(e);break;case"longest-path":on(e);case"none":}};var on=rn;function ln(e){nn(e)}var hn=function(e){let t=function(e){let t={},i=0;function r(s){let n=i;e.children(s).forEach(r),t[s]={low:n,lim:i++}}return e.children().forEach(r),t}(e);e.graph().dummyChains.forEach(i=>{let r=e.node(i),s=r.edgeObj,n=function(e,t,i,r){let s,n,a=[],o=[],l=Math.min(t[i].low,t[r].low),h=Math.max(t[i].lim,t[r].lim);s=i;do{s=e.parent(s),a.push(s)}while(s&&(t[s].low>l||h>t[s].lim));n=s,s=r;for(;(s=e.parent(s))!==n;)o.push(s);return{path:a.concat(o.reverse()),lca:n}}(e,t,s.v,s.w),a=n.path,o=n.lca,l=0,h=a[l],c=!0;for(;i!==s.w;){if(r=e.node(i),c){for(;(h=a[l])!==o&&e.node(h).maxRank<r.rank;)l++;h===o&&(c=!1)}if(!c){for(;l<a.length-1&&e.node(h=a[l+1]).minRank<=r.rank;)l++;h=a[l]}e.setParent(i,h),i=e.successors(i)[0]}})};let cn=ms;var dn={run:function(e){let t=cn.addDummyNode(e,"root",{},"_root"),i=function(e){var t={};function i(r,s){var n=e.children(r);n&&n.length&&n.forEach(e=>i(e,s+1)),t[r]=s}return e.children().forEach(e=>i(e,1)),t}(e),r=Object.values(i),s=cn.applyWithChunking(Math.max,r)-1,n=2*s+1;e.graph().nestingRoot=t,e.edges().forEach(t=>e.edge(t).minlen*=n);let a=function(e){return e.edges().reduce((t,i)=>t+e.edge(i).weight,0)}(e)+1;e.children().forEach(r=>un(e,t,n,a,s,i,r)),e.graph().nodeRankFactor=n},cleanup:function(e){var t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(t=>{e.edge(t).nestingEdge&&e.removeEdge(t)})}};function un(e,t,i,r,s,n,a){let o=e.children(a);if(!o.length)return void(a!==t&&e.setEdge(t,a,{weight:0,minlen:i}));let l=cn.addBorderNode(e,"_bt"),h=cn.addBorderNode(e,"_bb"),c=e.node(a);e.setParent(l,a),c.borderTop=l,e.setParent(h,a),c.borderBottom=h,o.forEach(o=>{un(e,t,i,r,s,n,o);let c=e.node(o),d=c.borderTop?c.borderTop:o,u=c.borderBottom?c.borderBottom:o,_=c.borderTop?r:2*r,p=d!==u?1:s-n[a]+1;e.setEdge(l,d,{weight:_,minlen:p,nestingEdge:!0}),e.setEdge(u,h,{weight:_,minlen:p,nestingEdge:!0})}),e.parent(a)||e.setEdge(t,l,{weight:0,minlen:s+n[a]})}let _n=ms;var pn=function(e){e.children().forEach(function t(i){let r=e.children(i),s=e.node(i);if(r.length&&r.forEach(t),Object.hasOwn(s,"minRank")){s.borderLeft=[],s.borderRight=[];for(let t=s.minRank,r=s.maxRank+1;t<r;++t)fn(e,"borderLeft","_bl",i,s,t),fn(e,"borderRight","_br",i,s,t)}})};function fn(e,t,i,r,s,n){let a={width:0,height:0,rank:n,borderType:t},o=s[t][n-1],l=_n.addDummyNode(e,"border",a,i);s[t][n]=l,e.setParent(l,r),o&&e.setEdge(o,l,{weight:1})}function gn(e){e.nodes().forEach(t=>yn(e.node(t))),e.edges().forEach(t=>yn(e.edge(t)))}function yn(e){let t=e.width;e.width=e.height,e.height=t}function mn(e){e.y=-e.y}function bn(e){let t=e.x;e.x=e.y,e.y=t}let xn=ms;var vn=function(e){let t={},i=e.nodes().filter(t=>!e.children(t).length),r=i.map(t=>e.node(t).rank),s=xn.applyWithChunking(Math.max,r),n=xn.range(s+1).map(()=>[]);function a(i){if(t[i])return;t[i]=!0;let r=e.node(i);n[r.rank].push(i),e.successors(i).forEach(a)}return i.sort((t,i)=>e.node(t).rank-e.node(i).rank).forEach(a),n};let wn=ms.zipObject;function En(e,t,i){let r=wn(i,i.map((e,t)=>t)),s=t.flatMap(t=>e.outEdges(t).map(t=>({pos:r[t.w],weight:e.edge(t).weight})).sort((e,t)=>e.pos-t.pos)),n=1;for(;n<i.length;)n<<=1;let a=2*n-1;n-=1;let o=new Array(a).fill(0),l=0;return s.forEach(e=>{let t=e.pos+n;o[t]+=e.weight;let i=0;for(;t>0;)t%2&&(i+=o[t+1]),t=t-1>>1,o[t]+=e.weight;l+=e.weight*i}),l}let Cn=ms;let An=ms;function Sn(e,t,i){let r;for(;t.length&&(r=t[t.length-1]).i<=i;)t.pop(),e.push(r.vs),i++;return i}let kn=function(e,t=[]){return t.map(t=>{let i=e.inEdges(t);if(i.length){let r=i.reduce((t,i)=>{let r=e.edge(i),s=e.node(i.v);return{sum:t.sum+r.weight*s.order,weight:t.weight+r.weight}},{sum:0,weight:0});return{v:t,barycenter:r.sum/r.weight,weight:r.weight}}return{v:t}})},Rn=function(e,t){let i={};return e.forEach((e,t)=>{let r=i[e.v]={indegree:0,in:[],out:[],vs:[e.v],i:t};void 0!==e.barycenter&&(r.barycenter=e.barycenter,r.weight=e.weight)}),t.edges().forEach(e=>{let t=i[e.v],r=i[e.w];void 0!==t&&void 0!==r&&(r.indegree++,t.out.push(i[e.w]))}),function(e){let t=[];function i(e){return t=>{t.merged||(void 0===t.barycenter||void 0===e.barycenter||t.barycenter>=e.barycenter)&&function(e,t){let i=0,r=0;e.weight&&(i+=e.barycenter*e.weight,r+=e.weight);t.weight&&(i+=t.barycenter*t.weight,r+=t.weight);e.vs=t.vs.concat(e.vs),e.barycenter=i/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}(e,t)}}function r(t){return i=>{i.in.push(t),0===--i.indegree&&e.push(i)}}for(;e.length;){let s=e.pop();t.push(s),s.in.reverse().forEach(i(s)),s.out.forEach(r(s))}return t.filter(e=>!e.merged).map(e=>Cn.pick(e,["vs","i","barycenter","weight"]))}(Object.values(i).filter(e=>!e.indegree))},Tn=function(e,t){let i=An.partition(e,e=>Object.hasOwn(e,"barycenter")),r=i.lhs,s=i.rhs.sort((e,t)=>t.i-e.i),n=[],a=0,o=0,l=0;r.sort((h=!!t,(e,t)=>e.barycenter<t.barycenter?-1:e.barycenter>t.barycenter?1:h?t.i-e.i:e.i-t.i)),l=Sn(n,s,l),r.forEach(e=>{l+=e.vs.length,n.push(e.vs),a+=e.barycenter*e.weight,o+=e.weight,l=Sn(n,s,l)});var h;let c={vs:n.flat(!0)};o&&(c.barycenter=a/o,c.weight=o);return c};var On=function e(t,i,r,s){let n=t.children(i),a=t.node(i),o=a?a.borderLeft:void 0,l=a?a.borderRight:void 0,h={};o&&(n=n.filter(e=>e!==o&&e!==l));let c=kn(t,n);c.forEach(i=>{if(t.children(i.v).length){let o=e(t,i.v,r,s);h[i.v]=o,Object.hasOwn(o,"barycenter")&&(a=o,void 0!==(n=i).barycenter?(n.barycenter=(n.barycenter*n.weight+a.barycenter*a.weight)/(n.weight+a.weight),n.weight+=a.weight):(n.barycenter=a.barycenter,n.weight=a.weight))}var n,a});let d=Rn(c,r);!function(e,t){e.forEach(e=>{e.vs=e.vs.flatMap(e=>t[e]?t[e].vs:e)})}(d,h);let u=Tn(d,s);if(o&&(u.vs=[o,u.vs,l].flat(!0),t.predecessors(o).length)){let e=t.node(t.predecessors(o)[0]),i=t.node(t.predecessors(l)[0]);Object.hasOwn(u,"barycenter")||(u.barycenter=0,u.weight=0),u.barycenter=(u.barycenter*u.weight+e.order+i.order)/(u.weight+2),u.weight+=2}return u};let In=ls.Graph,Nn=ms;var Ln=function(e,t,i,r){r||(r=e.nodes());let s=function(e){var t;for(;e.hasNode(t=Nn.uniqueId("_root")););return t}(e),n=new In({compound:!0}).setGraph({root:s}).setDefaultNodeLabel(t=>e.node(t));return r.forEach(r=>{let a=e.node(r),o=e.parent(r);(a.rank===t||a.minRank<=t&&t<=a.maxRank)&&(n.setNode(r),n.setParent(r,o||s),e[i](r).forEach(t=>{let i=t.v===r?t.w:t.v,s=n.edge(i,r),a=void 0!==s?s.weight:0;n.setEdge(i,r,{weight:e.edge(t).weight+a})}),Object.hasOwn(a,"minRank")&&n.setNode(r,{borderLeft:a.borderLeft[t],borderRight:a.borderRight[t]}))}),n};let Pn=vn,Vn=function(e,t){let i=0;for(let r=1;r<t.length;++r)i+=En(e,t[r-1],t[r]);return i},Dn=On,Bn=Ln,Mn=function(e,t,i){let r,s={};i.forEach(i=>{let n,a,o=e.parent(i);for(;o;){if(n=e.parent(o),n?(a=s[n],s[n]=o):(a=r,r=o),a&&a!==o)return void t.setEdge(a,o);o=n}})},Gn=ls.Graph,zn=ms;var Fn=function e(t,i){if(i&&"function"==typeof i.customOrder)return void i.customOrder(t,e);let r=zn.maxRank(t),s=jn(t,zn.range(1,r+1),"inEdges"),n=jn(t,zn.range(r-1,-1,-1),"outEdges"),a=Pn(t);if(Yn(t,a),i&&i.disableOptimalOrderHeuristic)return;let o,l=Number.POSITIVE_INFINITY;for(let e=0,i=0;i<4;++e,++i){Wn(e%2?s:n,e%4>=2),a=zn.buildLayerMatrix(t);let r=Vn(t,a);r<l&&(i=0,o=Object.assign({},a),l=r)}Yn(t,o)};function jn(e,t,i){const r=new Map,s=(e,t)=>{r.has(e)||r.set(e,[]),r.get(e).push(t)};for(const t of e.nodes()){const i=e.node(t);if("number"==typeof i.rank&&s(i.rank,t),"number"==typeof i.minRank&&"number"==typeof i.maxRank)for(let e=i.minRank;e<=i.maxRank;e++)e!==i.rank&&s(e,t)}return t.map(function(t){return Bn(e,t,i,r.get(t)||[])})}function Wn(e,t){let i=new Gn;e.forEach(function(e){let r=e.graph().root,s=Dn(e,r,i,t);s.vs.forEach((t,i)=>e.node(t).order=i),Mn(e,i,s.vs)})}function Yn(e,t){Object.values(t).forEach(t=>t.forEach((t,i)=>e.node(t).order=i))}let Un=ls.Graph,Hn=ms;var Xn=function(e){let t,i=Hn.buildLayerMatrix(e),r=Object.assign(function(e,t){let i={};function r(t,r){let s=0,n=0,a=t.length,o=r[r.length-1];return r.forEach((t,l)=>{let h=function(e,t){if(e.node(t).dummy)return e.predecessors(t).find(t=>e.node(t).dummy)}(e,t),c=h?e.node(h).order:a;(h||t===o)&&(r.slice(n,l+1).forEach(t=>{e.predecessors(t).forEach(r=>{let n=e.node(r),a=n.order;!(a<s||c<a)||n.dummy&&e.node(t).dummy||qn(i,r,t)})}),n=l+1,s=c)}),r}return t.length&&t.reduce(r),i}(e,i),function(e,t){let i={};function r(t,r,s,n,a){let o;Hn.range(r,s).forEach(r=>{o=t[r],e.node(o).dummy&&e.predecessors(o).forEach(t=>{let r=e.node(t);r.dummy&&(r.order<n||r.order>a)&&qn(i,t,o)})})}function s(t,i){let s,n=-1,a=0;return i.forEach((o,l)=>{if("border"===e.node(o).dummy){let t=e.predecessors(o);t.length&&(s=e.node(t[0]).order,r(i,a,l,n,s),a=l,n=s)}r(i,a,i.length,s,t.length)}),i}return t.length&&t.reduce(s),i}(e,i)),s={};["u","d"].forEach(n=>{t="u"===n?i:Object.values(i).reverse(),["l","r"].forEach(i=>{"r"===i&&(t=t.map(e=>Object.values(e).reverse()));let a=("u"===n?e.predecessors:e.successors).bind(e),o=function(e,t,i,r){let s={},n={},a={};return t.forEach(e=>{e.forEach((e,t)=>{s[e]=e,n[e]=e,a[e]=t})}),t.forEach(e=>{let t=-1;e.forEach(e=>{let o=r(e);if(o.length){o=o.sort((e,t)=>a[e]-a[t]);let r=(o.length-1)/2;for(let l=Math.floor(r),h=Math.ceil(r);l<=h;++l){let r=o[l];n[e]===e&&t<a[r]&&!Kn(i,e,r)&&(n[r]=e,n[e]=s[e]=s[r],t=a[r])}}})}),{root:s,align:n}}(0,t,r,a),l=function(e,t,i,r,s){let n={},a=function(e,t,i,r){let s=new Un,n=e.graph(),a=function(e,t,i){return(r,s,n)=>{let a,o=r.node(s),l=r.node(n),h=0;if(h+=o.width/2,Object.hasOwn(o,"labelpos"))switch(o.labelpos.toLowerCase()){case"l":a=-o.width/2;break;case"r":a=o.width/2}if(a&&(h+=i?a:-a),a=0,h+=(o.dummy?t:e)/2,h+=(l.dummy?t:e)/2,h+=l.width/2,Object.hasOwn(l,"labelpos"))switch(l.labelpos.toLowerCase()){case"l":a=l.width/2;break;case"r":a=-l.width/2}return a&&(h+=i?a:-a),a=0,h}}(n.nodesep,n.edgesep,r);return t.forEach(t=>{let r;t.forEach(t=>{let n=i[t];if(s.setNode(n),r){var o=i[r],l=s.edge(o,n);s.setEdge(o,n,Math.max(a(e,t,r),l||0))}r=t})}),s}(e,t,i,s),o=s?"borderLeft":"borderRight";function l(e,t){let i=a.nodes(),r=i.pop(),s={};for(;r;)s[r]?e(r):(s[r]=!0,i.push(r),i=i.concat(t(r))),r=i.pop()}function h(e){n[e]=a.inEdges(e).reduce((e,t)=>Math.max(e,n[t.v]+a.edge(t)),0)}function c(t){let i=a.outEdges(t).reduce((e,t)=>Math.min(e,n[t.w]-a.edge(t)),Number.POSITIVE_INFINITY),r=e.node(t);i!==Number.POSITIVE_INFINITY&&r.borderType!==o&&(n[t]=Math.max(n[t],i))}return l(h,a.predecessors.bind(a)),l(c,a.successors.bind(a)),Object.keys(r).forEach(e=>n[e]=n[i[e]]),n}(e,t,o.root,o.align,"r"===i);"r"===i&&(l=Hn.mapValues(l,e=>-e)),s[n+i]=l})});let n=function(e,t){return Object.values(t).reduce((t,i)=>{let r=Number.NEGATIVE_INFINITY,s=Number.POSITIVE_INFINITY;Object.entries(i).forEach(([t,i])=>{let n=function(e,t){return e.node(t).width}(e,t)/2;r=Math.max(i+n,r),s=Math.min(i-n,s)});const n=r-s;return n<t[0]&&(t=[n,i]),t},[Number.POSITIVE_INFINITY,null])[1]}(e,s);return function(e,t){let i=Object.values(t),r=Hn.applyWithChunking(Math.min,i),s=Hn.applyWithChunking(Math.max,i);["u","d"].forEach(i=>{["l","r"].forEach(n=>{let a=i+n,o=e[a];if(o===t)return;let l=Object.values(o),h=r-Hn.applyWithChunking(Math.min,l);"l"!==n&&(h=s-Hn.applyWithChunking(Math.max,l)),h&&(e[a]=Hn.mapValues(o,e=>e+h))})})}(s,n),function(e,t){return Hn.mapValues(e.ul,(i,r)=>{if(t)return e[t.toLowerCase()][r];{let t=Object.values(e).map(e=>e[r]).sort((e,t)=>e-t);return(t[1]+t[2])/2}})}(s,e.graph().align)};function qn(e,t,i){if(t>i){let e=t;t=i,i=e}let r=e[t];r||(e[t]=r={}),r[i]=!0}function Kn(e,t,i){if(t>i){let e=t;t=i,i=e}return!!e[t]&&Object.hasOwn(e[t],i)}let Zn=ms,$n=Xn;let Jn=Ts,Qn=Is,ea=an,ta=ms.normalizeRanks,ia=hn,ra=ms.removeEmptyRanks,sa=dn,na=pn,aa={adjust:function(e){let t=e.graph().rankdir.toLowerCase();"lr"!==t&&"rl"!==t||gn(e)},undo:function(e){let t=e.graph().rankdir.toLowerCase();"bt"!==t&&"rl"!==t||function(e){e.nodes().forEach(t=>mn(e.node(t))),e.edges().forEach(t=>{let i=e.edge(t);i.points.forEach(mn),Object.hasOwn(i,"y")&&mn(i)})}(e);"lr"!==t&&"rl"!==t||(!function(e){e.nodes().forEach(t=>bn(e.node(t))),e.edges().forEach(t=>{let i=e.edge(t);i.points.forEach(bn),Object.hasOwn(i,"x")&&bn(i)})}(e),gn(e))}},oa=Fn,la=function(e){(function(e){let t=Zn.buildLayerMatrix(e),i=e.graph().ranksep,r=0;t.forEach(t=>{const s=t.reduce((t,i)=>{const r=e.node(i).height;return t>r?t:r},0);t.forEach(t=>e.node(t).y=r+s/2),r+=s+i})})(e=Zn.asNonCompoundGraph(e)),Object.entries($n(e)).forEach(([t,i])=>e.node(t).x=i)},ha=ms,ca=ls.Graph;var da=function(e,t){let i=t&&t.debugTiming?ha.time:ha.notime;i("layout",()=>{let r=i(" buildLayoutGraph",()=>function(e){let t=new ca({multigraph:!0,compound:!0}),i=va(e.graph());return t.setGraph(Object.assign({},_a,xa(i,ua),ha.pick(i,pa))),e.nodes().forEach(i=>{const r=xa(va(e.node(i)),fa);Object.keys(ga).forEach(e=>{void 0===r[e]&&(r[e]=ga[e])}),t.setNode(i,r),t.setParent(i,e.parent(i))}),e.edges().forEach(i=>{let r=va(e.edge(i));t.setEdge(i,Object.assign({},ma,xa(r,ya),ha.pick(r,ba)))}),t}(e));i(" runLayout",()=>function(e,t,i){t(" makeSpaceForEdgeLabels",()=>function(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(i=>{let r=e.edge(i);r.minlen*=2,"c"!==r.labelpos.toLowerCase()&&("TB"===t.rankdir||"BT"===t.rankdir?r.width+=r.labeloffset:r.height+=r.labeloffset)})}(e)),t(" removeSelfEdges",()=>function(e){e.edges().forEach(t=>{if(t.v===t.w){var i=e.node(t.v);i.selfEdges||(i.selfEdges=[]),i.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}(e)),t(" acyclic",()=>Jn.run(e)),t(" nestingGraph.run",()=>sa.run(e)),t(" rank",()=>ea(ha.asNonCompoundGraph(e))),t(" injectEdgeLabelProxies",()=>function(e){e.edges().forEach(t=>{let i=e.edge(t);if(i.width&&i.height){let i=e.node(t.v),r={rank:(e.node(t.w).rank-i.rank)/2+i.rank,e:t};ha.addDummyNode(e,"edge-proxy",r,"_ep")}})}(e)),t(" removeEmptyRanks",()=>ra(e)),t(" nestingGraph.cleanup",()=>sa.cleanup(e)),t(" normalizeRanks",()=>ta(e)),t(" assignRankMinMax",()=>function(e){let t=0;e.nodes().forEach(i=>{let r=e.node(i);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=Math.max(t,r.maxRank))}),e.graph().maxRank=t}(e)),t(" removeEdgeLabelProxies",()=>function(e){e.nodes().forEach(t=>{let i=e.node(t);"edge-proxy"===i.dummy&&(e.edge(i.e).labelRank=i.rank,e.removeNode(t))})}(e)),t(" normalize.run",()=>Qn.run(e)),t(" parentDummyChains",()=>ia(e)),t(" addBorderSegments",()=>na(e)),t(" order",()=>oa(e,i)),t(" insertSelfEdges",()=>function(e){var t=ha.buildLayerMatrix(e);t.forEach(t=>{var i=0;t.forEach((t,r)=>{var s=e.node(t);s.order=r+i,(s.selfEdges||[]).forEach(t=>{ha.addDummyNode(e,"selfedge",{width:t.label.width,height:t.label.height,rank:s.rank,order:r+ ++i,e:t.e,label:t.label},"_se")}),delete s.selfEdges})})}(e)),t(" adjustCoordinateSystem",()=>aa.adjust(e)),t(" position",()=>la(e)),t(" positionSelfEdges",()=>function(e){e.nodes().forEach(t=>{var i=e.node(t);if("selfedge"===i.dummy){var r=e.node(i.e.v),s=r.x+r.width/2,n=r.y,a=i.x-s,o=r.height/2;e.setEdge(i.e,i.label),e.removeNode(t),i.label.points=[{x:s+2*a/3,y:n-o},{x:s+5*a/6,y:n-o},{x:s+a,y:n},{x:s+5*a/6,y:n+o},{x:s+2*a/3,y:n+o}],i.label.x=i.x,i.label.y=i.y}})}(e)),t(" removeBorderNodes",()=>function(e){e.nodes().forEach(t=>{if(e.children(t).length){let i=e.node(t),r=e.node(i.borderTop),s=e.node(i.borderBottom),n=e.node(i.borderLeft[i.borderLeft.length-1]),a=e.node(i.borderRight[i.borderRight.length-1]);i.width=Math.abs(a.x-n.x),i.height=Math.abs(s.y-r.y),i.x=n.x+i.width/2,i.y=r.y+i.height/2}}),e.nodes().forEach(t=>{"border"===e.node(t).dummy&&e.removeNode(t)})}(e)),t(" normalize.undo",()=>Qn.undo(e)),t(" fixupEdgeLabelCoords",()=>function(e){e.edges().forEach(t=>{let i=e.edge(t);if(Object.hasOwn(i,"x"))switch("l"!==i.labelpos&&"r"!==i.labelpos||(i.width-=i.labeloffset),i.labelpos){case"l":i.x-=i.width/2+i.labeloffset;break;case"r":i.x+=i.width/2+i.labeloffset}})}(e)),t(" undoCoordinateSystem",()=>aa.undo(e)),t(" translateGraph",()=>function(e){let t=Number.POSITIVE_INFINITY,i=0,r=Number.POSITIVE_INFINITY,s=0,n=e.graph(),a=n.marginx||0,o=n.marginy||0;function l(e){let n=e.x,a=e.y,o=e.width,l=e.height;t=Math.min(t,n-o/2),i=Math.max(i,n+o/2),r=Math.min(r,a-l/2),s=Math.max(s,a+l/2)}e.nodes().forEach(t=>l(e.node(t))),e.edges().forEach(t=>{let i=e.edge(t);Object.hasOwn(i,"x")&&l(i)}),t-=a,r-=o,e.nodes().forEach(i=>{let s=e.node(i);s.x-=t,s.y-=r}),e.edges().forEach(i=>{let s=e.edge(i);s.points.forEach(e=>{e.x-=t,e.y-=r}),Object.hasOwn(s,"x")&&(s.x-=t),Object.hasOwn(s,"y")&&(s.y-=r)}),n.width=i-t+a,n.height=s-r+o}(e)),t(" assignNodeIntersects",()=>function(e){e.edges().forEach(t=>{let i,r,s=e.edge(t),n=e.node(t.v),a=e.node(t.w);s.points?(i=s.points[0],r=s.points[s.points.length-1]):(s.points=[],i=a,r=n),s.points.unshift(ha.intersectRect(n,i)),s.points.push(ha.intersectRect(a,r))})}(e)),t(" reversePoints",()=>function(e){e.edges().forEach(t=>{let i=e.edge(t);i.reversed&&i.points.reverse()})}(e)),t(" acyclic.undo",()=>Jn.undo(e))}(r,i,t)),i(" updateInputGraph",()=>function(e,t){e.nodes().forEach(i=>{let r=e.node(i),s=t.node(i);r&&(r.x=s.x,r.y=s.y,r.rank=s.rank,t.children(i).length&&(r.width=s.width,r.height=s.height))}),e.edges().forEach(i=>{let r=e.edge(i),s=t.edge(i);r.points=s.points,Object.hasOwn(s,"x")&&(r.x=s.x,r.y=s.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}(e,r))})};let ua=["nodesep","edgesep","ranksep","marginx","marginy"],_a={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},pa=["acyclicer","ranker","rankdir","align"],fa=["width","height","rank"],ga={width:0,height:0},ya=["minlen","weight","width","height","labeloffset"],ma={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},ba=["labelpos"];function xa(e,t){return ha.mapValues(ha.pick(e,t),Number)}function va(e){var t={};return e&&Object.entries(e).forEach(([e,i])=>{"string"==typeof e&&(e=e.toLowerCase()),t[e]=i}),t}let wa=ms,Ea=ls.Graph;var Ca={graphlib:ls,layout:da,debug:{debugOrdering:function(e){let t=wa.buildLayerMatrix(e),i=new Ea({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(t=>{i.setNode(t,{label:t}),i.setParent(t,"layer"+e.node(t).rank)}),e.edges().forEach(e=>i.setEdge(e.v,e.w,{},e.name)),t.forEach((e,t)=>{let r="layer"+t;i.setNode(r,{rank:"same"}),e.reduce((e,t)=>(i.setEdge(e,t,{style:"invis"}),t))}),i}},util:{time:ms.time,notime:ms.notime},version:"1.1.8"};class Aa extends ye{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=we(e.parent);for(let e of t){let t=e.layout;if(!t)continue;let r=j(e.children[0]);if(!r)continue;var i=new Ca.graphlib.Graph;i.setGraph({edgesep:t.edgeSep,nodesep:t.nodeSep,ranksep:t.rankSep}),i.setDefaultEdgeLabel(function(){return{}}),i.graph().rankdir=this._getDagreDirection(t.direction);let s=new Map;for(let t of e.children){let e=t.datum[Y];s.set(e,e+""),i.setNode(e,{label:t.text?t.text:"",width:t.bounds.width,height:t.bounds.height})}for(let e of r.linkList)i.setEdge(e.source,e.target);Ca.layout(i);const n={};let a=d3.min(i.nodes().map(e=>i.node(e).y)),o=d3.min(i.nodes().map(e=>i.node(e).x)),l=t.left-o,h=t.top-a;for(const e of i.nodes())n[e]={x:i.node(e).x+l,y:i.node(e).y+h};for(let t of e.children){let e=t.datum[Y];gi(t,n[s.get(e)].x-t.x,n[s.get(e)].y-t.y)}}let r=Le(e,!0);for(let e of r)le(e)}_getDagreDirection(e){switch(e){case ft.Left2Right:return"LR";case ft.Right2Left:return"RL";case ft.Top2Bottom:return"TB";case ft.Bottom2Top:return"BT"}}}class Sa extends ye{constructor(e){super(e)}run(){super.run();let t=this._outputVars[0].element,i=we(t.parent);for(let t of i){let i=t.layout;if(!i)continue;let r=z(t.children[0]);if(!r)continue;let s=e.hierarchy(r._data),n=Math.max(...t.children.map(e=>e.bounds.width)),a=Math.max(...t.children.map(e=>e.bounds.height)),o=i.orientation==dt?[i.height,i.width]:[i.width,i.height],l=e.tree().nodeSize([n,a]).size(o)(s);this._apply(l,i,t)}le(t)}_apply(e,t,i){let r,s,n=i.children.filter(t=>t.datum[Y]==e.data[Y])[0];switch(t.orientation){case dt:r=e.y+t.left,s=e.x+t.top;break;case ut:r=e.x+t.left,s=t.top+e.y}if(gi(n,r-n.x,s-n.y),e.children&&e.children.length>0)for(let r of e.children)this._apply(r,t,i)}}class ka extends ye{constructor(e){super(e)}run(){super.run();let t=this._outputVars[0].element,r=this._inputVars.filter(e=>e.type===xe.PROPERTY&&e.property===ze.CHILDREN_ORDER)[0].element,s=r.layout,n=s.width?s.width:r.bounds.width,a=s.height?s.height:r.bounds.height,o=void 0===s.top?r.bounds.top:s.top,l=void 0===s.left?r.bounds.left:s.left,h=e.hierarchy(r).sum(e=>e.type===i.Rect?e.width*e.height:0);e.treemap().size([n,a])(h),this._apply(h,l,o);let c=Le(t,!0);for(let e of c)le(e)}_apply(e,t,r){if(e.data.type==i.Collection&&e.children)for(let i of e.children)this._apply(i,t,r);else e.data.type==i.Rect&&(e.data.resize(e.x1-e.x0,e.y1-e.y0),gi(e.data,e.x0+t-e.data.left,e.y0+r-e.data.top))}}class Ra extends ye{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=we(e.parent);for(let e of t){if(!e.layout)continue;if(0===e.children.length)continue;let t=z(e.children[0]);if(!t)continue;let r={};for(let t of e.children)r[t.datum[Y]]=t;e.children[0].type===i.Rect?this._layoutRects(t.getRoot(),t,r):this._layoutArcs(t.getRoot(),t,r)}le(e)}_layoutArcs(e,t,r){let s=t.getChildren(e);if(0===s.length)return;let n=r[e[Y]],a=!n||n.type!=i.Arc&&n.type!=i.Pie?60:n.startAngle;for(let e=0;e<s.length;e++){let n=s[e],o=r[n[Y]];if(o.type===i.Arc){let e=Tt(a+o.angle);o.setAngles(a,e),a=e}this._layoutArcs(n,t,r)}}_layoutRects(e,t,i){let r=t.getChildren(e);if(0===r.length)return;let s,n,a=i[e[Y]];this._direction,s=a.left,n=a.bottom;for(let e=0;e<r.length;e++){let a=r[e],o=i[a[Y]];gi(o,s-o.left,n-o.top),s+=o.width,this._layoutRects(a,t,i)}}}class Ta extends ye{constructor(e){super(e)}run(){super.run();let e=this.outputVar;e.clearResult();let t=this.inputVars.find(e=>void 0!==e.context),i=e.conditionalEncoding,r=t?t.context:void 0,s=Ie(i.responderComponent).state,n=e.result;if(i.evalFunction){i.getResponderPeers().forEach(e=>n[e.id]=!!i.evalFunction(r,s,e))}}}class Oa extends ye{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=we(e.parent);for(let e of t){let t=e.layout;if(!t)continue;let i=360/e.children.length;for(let[r,s]of e.children.entries())gi(s,t.x+t.radius-s.bounds.x,t.y-s.bounds.y),s._rotate=[r*i,t.x,t.y]}let i=Le(e,!0);for(let e of i)le(e)}}class Ia extends ye{constructor(e){super(e)}run(){super.run();let t=this._outputVars[0].element,i=we(t.parent);for(let r of i){let i=r.layout;if(!i)continue;let s=i._tree?i._tree._data:z(r.children[0])._data,n=e.hierarchy(s);if(i.isRadial()){n=e.cluster().size([kt(i.angleExtent),i.radius])(n),i._d3Root=n;const t=new Map(n.descendants().map(e=>[e.data[Y],[e.x,e.y]]));for(let e of r.children){let r=e.datum[Y];gi(e,i.x-e.bounds.x,i.y-t.get(r)[1]-e.bounds.y),e._rotate=[Rt(t.get(r)[0]),i.x,i.y]}}else if(i.orientation===ut){!i.width||i.width;let s=i.height?i.height:600;n=e.cluster().nodeSize([t.bounds.width+1,s/(n.height+1)])(n),i._d3Root=n;const a=new Map(n.descendants().map(e=>[e.data[Y],[e.x,e.y]]));let o=1/0,l=-o;n.each(e=>{e.x>l&&(l=e.x),e.x<o&&(o=e.x)}),i._x0=o;for(let e of r.children){let t=e.datum[Y];gi(e,a.get(t)[0]-o+i.left-e.bounds.x,a.get(t)[1]+i.top-e.bounds.y)}}else if(i.orientation===dt){!i.width||i.width;let s=i.height?i.height:600;n=e.cluster().nodeSize([t.bounds.height,s/(n.height+1)])(n),i._d3Root=n;const a=new Map(n.descendants().map(e=>[e.data[Y],[e.x,e.y]]));let o=1/0,l=-o;n.each(e=>{e.x>l&&(l=e.x),e.x<o&&(o=e.x)}),i._x0=o;for(let e of r.children){let t=e.datum[Y];gi(e,a.get(t)[1]+i.left-e.bounds.x,a.get(t)[0]-o+i.top-e.bounds.y)}}}let r=Le(t,!0);for(let e of r)le(e)}}class Na extends be{constructor(e,t){super(e),this._cond=t}get context(){return this._cond}}class La extends ye{constructor(e,t,i){super(e),this._fn=t,this._compnt=i}run(){super.run();let e=this.inputVars.find(e=>e instanceof Na),t=e?e.context:void 0,i=Ie(this._compnt);if(this._fn(void 0,t,i?i.state:void 0,this._compnt),i)for(let e of this._outputVars){let t=e.element||e.stateContext;t&&t._scene&&(e.type===xe.CHANNEL?i.onChange(xe.CHANNEL,e.channel,t):e.type===xe.PROPERTY?i.onChange(xe.PROPERTY,e.property,t):e.type===xe.STATE&&i.onChange(xe.STATE,e.key,e.stateContext))}}}class Pa extends be{constructor(e,t,i,r=null){super(e),this._attribute=t,this._dataset=i,this._encoding=r}get attribute(){return this._attribute}get dataset(){return this._dataset}get encoding(){return this._encoding}}class Va extends ye{constructor(e){super(e)}run(){super.run();let e=this.outputVar,t=this.inputVars.find(e=>e instanceof Pa),i=e.encodings[0].dataTable.type(t.attribute),r={};for(let t of e.encodings){let e=this._computeAttrValues(t,i);Object.assign(r,e)}e.attrValues=r}_computeAttrValues(e,t){if("vertex"===e.element.type)return this._computeVertexIndexAttrValues(e,t);let r=we(e.element),s={};if(e.element.type===i.Area&&["width","height","fillGradient"].indexOf(e.channel)>=0)for(let t of r)for(let i=0;i<t._vertices.length;i++)s[Ce(t,i)]=t._vertices.hasDataScope(i)?t._vertices.aggregateDataScopeAttribute(i,e.attribute,e.aggregator):T(t.dataScope,e.attribute,e.aggregator);else switch(t){case a.Boolean:break;case a.Date:for(let t of r)s[t.id]=k(t.dataScope,e.attribute);break;case a.String:try{if("count"==e.aggregator)for(let t of r)s[t.id]=R(t.dataScope,e.attribute).length;else for(let t of r)s[t.id]=k(t.dataScope,e.attribute)}catch(t){throw new Error("Cannot bind "+this.channel+" to "+e.attribute+" : "+t)}break;default:if(e.attribute.startsWith("parent.")||e.attribute.startsWith("child.")){let t=e.dataTable.tree.nodeTable,i=e.attribute.split(".")[0],n=e.attribute.split(".")[1];for(let e of r){let r=k(e.dataScope,i);s[e.id]=k(O(N(t),Y,r),n)}}else for(let t of r)s[t.id]=T(t.dataScope,e.attribute,e.aggregator)}return e.attrValues=s,s}_computeVertexIndexAttrValues(e,t){let i={};for(let r of e.elementGroups)for(let s of r.groups)for(let r of s.indices){i[Ce(s.parent,r)]=this._computeVertexIndexValue(s.parent,r,e,t)}return e.attrValues=i,i}_getVertexIndexContext(e,t,i){let r={type:"vertex",parent:e,index:t,_index:t,id:i};return Object.defineProperty(r,"dataScope",{get:()=>e._vertices.hasDataScope(t)?e._vertices.getDataScopeRef(t):e.dataScope}),Object.defineProperty(r,"datum",{get:()=>C(r.dataScope)}),Object.defineProperty(r,"data",{get:()=>E(r.dataScope)}),r}_computeVertexIndexValue(e,t,i,r){if(!e._vertices.hasDataScope(t))return this._computeValue(e.dataScope,i,r);if(i.attribute.startsWith("parent.")||i.attribute.startsWith("child."))return this._computeValue(e._vertices.getDataScopeRef(t),i,r);switch(r){case a.Boolean:return;case a.Date:return e._vertices.getDataScopeAttrVal(t,i.attribute);case a.String:return"count"==i.aggregator?e._vertices.getDataScopeAttributeValues(t,i.attribute).length:e._vertices.getDataScopeAttrVal(t,i.attribute);default:return e._vertices.aggregateDataScopeAttribute(t,i.attribute,i.aggregator)}}_computeValue(e,t,i){switch(i){case a.Boolean:return;case a.Date:return k(e,t.attribute);case a.String:return"count"==t.aggregator?R(e,t.attribute).length:k(e,t.attribute);default:if(t.attribute.startsWith("parent.")||t.attribute.startsWith("child.")){let i=t.dataTable.tree.nodeTable,r=t.attribute.split(".")[0],s=t.attribute.split(".")[1],n=k(e,r);return k(O(N(i),Y,n),s)}return T(e,t.attribute,t.aggregator)}}}class Da extends be{constructor(e,t,i){super(e),this._key=t,this._stateContext=i}get key(){return this._key}get stateContext(){return this._stateContext}}class Ba{constructor(){this._variables={},this._operators={},this._edges=[]}toJSON(){const e=this._edges.map(e=>({from:e.fromNode.id,to:e.toNode.id,isDirected:e.isDirected})),t={};for(const e in this._variables)t[e]=Object.values(this._variables[e]).map(e=>{let t={id:e.id,type:e.type,incoming:e.incomingEdges.map(e=>e.id),outgoing:e.outgoingEdges.map(e=>e.id),undirected:e.undirectedEdges.map(e=>e.id)};return"ChannelVar"===e.type?(t.channel=e.channel,t.element=e.element):"BoundsVar"===e.type||"DataScopeVar"===e.type?t.element=e.element:"dataValue"===e.type?(t.scale=e.scale,t.attrValues=e.attrValues):"FieldVar"===e.type?(t.field=e.field,t.dataset=e.dataset):"PropertyVar"===e.type?(t.property=e.property,t.element=e.element):e.type===xe.STATE?t.key=e.key:t.scale=e.scale,t});const i={};for(const e in this._operators)i[e]=Object.values(this._operators[e]).map(e=>{let t={id:e.id,type:e.type,inputVars:e.inputVars.map(e=>e.id),outputVar:e.outputVar?e.outputVar.id:null};return e.type===me.DOMAIN_BUILDER?t.aggregator=e.aggregator:e.type===me.SCALE_BUILDER&&(t.channel=e.channel),t});return{edges:e,variables:t,operators:i}}getVariable(e,...t){if(Object.values(xe).indexOf(e)<0)throw console.log(e),new Error("Variable Type Not Known");let i=this.findVariable(e,t);if(i)return i;switch(e){case xe.CHANNEL:i=new Ve(e,t[0],t[1]),"vertex"!=t[1].type&&"segment"!=t[1].type||this._connectPathElement2Size(t[1],i);break;case xe.PROPERTY:i=new Be(e,t[0],t[1]);break;case xe.STATE:i=new Da(e,t[0],t[1]);break;case xe.ATTRIBUTE:i=new Pa(e,t[0],t[1],t[2]||null);break;case xe.ITEMS:i=new hr(e,t[0]);break;case xe.ATTR_VALUE:i=new Fi(e,t[0]);break;case xe.DATASCOPE:i=new Bi(e,t[0]);break;case xe.BOUNDS:i=new Di(e,t[0]);break;case xe.SCALE:i=new zi(e,t[0]);break;case xe.AFFIXATION:i=new fr(e,t[0]);break;case xe.ALIGNMENT:i=new Er(e,t[0]);break;case xe.EVT_CTX:i=new Na(e,t[0],t[1]);break;case xe.CONDITION_RESULT:i=new rr(e,t[0])}return e in this._variables||(this._variables[e]={}),this._variables[e][i.id]=i,i}_connectPathElement2Size(e,t){let i=e.parent,r=t.channel,s=this.findVariable(xe.CHANNEL,["x"===r?"width":"height",i]);if(s){let e=s.incomingDataflow;e||(e=this.createOneWayDependency(me.CONDUIT)),this.connect(t,e),this.connect(e,s)}}findIncomingDataflowOperator(e,t){return t.incomingDataflow&&t.incomingDataflow.type===e?t.incomingDataflow:void 0}getIncomingDataflowOperator(e,t){let i=this.findIncomingDataflowOperator(e,t);return i||this.createOneWayDependency(e)}getOutgoingDataflowOperator(e,t){for(let i of t.outgoingEdges)if(i.toNode instanceof ye&&i.toNode.type===e)return i.toNode;return this.createOneWayDependency(e)}createOneWayDependency(e,...t){if(Object.values(me).indexOf(e)<0)throw new Error("Dependency Type Not Known");let i;switch(e){case me.EVAL_BBOX:i=new Wi(e);break;case me.AFFIXER:i=new pr(e);break;case me.DATA_EXTRACTOR:i=new Va(e,t[0]);break;case me.SCALE_BUILDER:i=new ji(e,t[0]);break;case me.ENCODER:i=new sr(e,t[0]);break;case me.AXIS_PATH_PLACER:i=new Yi(e);break;case me.AXIS_TICKS_PLACER:i=new Ui(e);break;case me.AXIS_LABELS_PLACER:i=new Hi(e);break;case me.AXIS_TITLE_PLACER:i=new vr(e);break;case me.LINK_PLACER:i=new Ar(e);break;case me.GRID_LAYOUT:i=new qi(e);break;case me.STACK_LAYOUT:i=new ar(e);break;case me.PACK_LAYOUT:i=new xr(e);break;case me.FORCE_LAYOUT:i=new Cr(e);break;case me.DIRECTED_LAYOUT:i=new Aa(e);break;case me.TIDY_TREE_LAYOUT:i=new Sa(e);break;case me.TREEMAP_LAYOUT:i=new ka(e);break;case me.STRATA_LAYOUT:i=new Ra(e);break;case me.CIRCULAR_LAYOUT:i=new Oa(e);break;case me.CLUSTER_LAYOUT:i=new Ia(e);break;case me.GRIDLINES_PLACER:i=new nr(e);break;case me.BIN_TRANSFORMER:i=new lr(e);break;case me.FILTER_TRANSFORMER:i=new cr(e);break;case me.KDE_TRANSFORMER:i=new gr(e);break;case me.CUSTOM_TRANSFORMER:i=new br(e);break;case me.REPOPULATE:i=new _r(e);break;case me.TARGET_EVALUATOR:i=new Ta(e);break;case me.TARGET_UPDATER:i=new La(e,t[0],t[1]);break;case me.CONDUIT:default:i=new or(e)}return e in this._operators||(this._operators[e]={}),this._operators[e][i.id]=i,i}createMultiWayDependency(e){if(Object.values(me).indexOf(e)<0)throw new Error("Dependency Type Not Known");let t;return me.ALIGNER,t=new wr(e),e in this._operators||(this._operators[e]={}),this._operators[e][t.id]=t,t}connect(e,t,i=!0){if(e instanceof be&&t instanceof ye){if(!t.inputVars.includes(e)){const r=new Gi(e,t,i);return this._edges.push(r),e.outgoingEdges.push(r),t.inputVars.push(e),r}}else if(e instanceof ye&&t instanceof be){if(!e.outputVars.includes(t)){const r=new Gi(e,t,i);return this._edges.push(r),e.outputVars.push(t),t.incomingEdges.push(r),r}}else if(e instanceof be&&t instanceof Mi){if(!t.vars.includes(e)){const i=new Gi(e,t,!1);return this._edges.push(i),t.vars.push(e),t.edges.push(e),e.undirectedEdges.push(i),i}}else{if(!(e instanceof Mi&&t instanceof be))throw new Error("An edge must connect a variable and an operator.");if(!e.vars.includes(t)){const i=new Gi(t,e,!1);return this._edges.push(i),e.vars.push(t),e.edges.push(t),t.undirectedEdges.push(i),i}}}disconnectChannelVarFromBBoxOperator(e){let t=this.getOutgoingDataflowOperator(me.EVAL_BBOX,e),i=e.outgoingEdges.find(i=>i.fromNode===e&&i.toNode===t);i&&this.disconnect(e,t,i)}disconnect(e,t,i){if(e instanceof be&&t instanceof ye){let r=e.outgoingEdges.findIndex(e=>e===i);r>=0&&(this._edges.splice(this._edges.indexOf(i),1),e.outgoingEdges.splice(r,1));let s=t.inputVars.findIndex(t=>t==e);s>=0&&t.inputVars.splice(s,1)}else if(e instanceof ye&&t instanceof be){let r=t.incomingEdges.findIndex(e=>e===i);r>=0&&(this._edges.splice(this._edges.indexOf(i),1),t.incomingEdges.splice(r,1));let s=e.outputVars.findIndex(e=>e===t);s>=0&&e.outputVars.splice(s,1)}}deleteVariable(e){for(let t=e.incomingEdges.length-1;t>=0;t--){let i=e.incomingEdges[t],r=i.fromNode;this.disconnect(r,e,i),r.isIsolated()&&delete this._operators[r.type][r.id]}for(let t=e.outgoingEdges.length-1;t>=0;t--){let i=e.outgoingEdges[t],r=i.toNode;this.disconnect(e,r,i),r.isIsolated()&&delete this._operators[r.type][r.id]}delete this._variables[e.type][e.id]}deleteOperator(e){for(let t=e.outputVars.length-1;t>=0;t--){let i=e.outputVars[t],r=i.incomingEdges.find(t=>t.fromNode===e&&t.toNode===i);this.disconnect(e,i,r),i.isIsolated()&&delete this._variables[i.type][i.id]}for(let t=e.inputVars.length-1;t>=0;t--){let i=e.inputVars[t],r=i.outgoingEdges.find(t=>t.fromNode===i&&t.toNode===e);this.disconnect(i,e,r),i.isIsolated()&&delete this._variables[i.type][i.id]}delete this._operators[e.type][e.id]}addInteraction(e){}_dfs(e,t,i){if(e&&0!==e.outgoingEdges.length)for(let r of e.outgoingEdges)r.isDirected&&(t.push(r.toNode),this._dfs(r.toNode.outputVars[0],t.slice(),i));else i.push(t)}getOperatorsOnPath(e,t,i,...r){let s=this.findVariable(e,r);if(s){for(let e of s.outgoingEdges)if(e.isDirected){let r=e.toNode,s=t.indexOf(r);-1!==s&&t.splice(s,1),t.push(r);for(let e of r.outputVars)switch(e.type){case xe.ITEMS:this.getOperatorsOnPath(e.type,t,i,e.dataset);break;case xe.ATTRIBUTE:this.getOperatorsOnPath(e.type,t,i,e.attribute,e.dataset);break;case xe.DATASCOPE:case xe.BOUNDS:this.getOperatorsOnPath(e.type,t,i,e.element);break;case xe.CHANNEL:this.getOperatorsOnPath(e.type,t,i,e.channel,e.element);break;case xe.PROPERTY:this.getOperatorsOnPath(e.type,t,i,e.property,e.element);break;case xe.STATE:this.getOperatorsOnPath(e.type,t,i,e.key,e.stateContext);break;case xe.SCALE:case xe.ATTR_VALUE:this.getOperatorsOnPath(e.type,t,i,e.encodings[0]);break;case xe.CONDITION_RESULT:this.getOperatorsOnPath(e.type,t,i,e.conditionalEncoding)}}for(let e of s.undirectedEdges)i.push(e.operator)}else console.warn("Unable to find variables matching the described change: ",e,r)}findVariable(e,t){if(!(e in this._variables))return null;let i=Object.values(this._variables[e]);switch(e){case xe.CHANNEL:return i.find(e=>e.channel==t[0]&&oi(e.element)==oi(t[1]));case xe.PROPERTY:return i.find(e=>e.property==t[0]&&e.element==t[1]);case xe.STATE:return i.find(e=>e.key==t[0]&&e.stateContext==t[1]);case xe.AFFIXATION:return i.find(e=>e.affixation==t[0]);case xe.ATTRIBUTE:return t[2]?i.find(e=>e.attribute==t[0]&&e.dataset==t[1]&&e.encoding===t[2]):i.find(e=>e.attribute==t[0]&&e.dataset==t[1]&&!e.encoding);case xe.ITEMS:return i.find(e=>e.dataset==t[0]);case xe.ATTR_VALUE:case xe.SCALE:return i.find(e=>e.encodings.includes(t[0]));case xe.EVT_CTX:return i.find(e=>e.context===t[0]);case xe.CONDITION_RESULT:return i.find(e=>e.conditionalEncoding==t[0]);case xe.DATASCOPE:default:return t[0].classId?i.find(e=>oi(e.element)==oi(t[0])):i.find(e=>e.element.id==t[0].id)}}findVariablesByElement(e){let t={};for(let i in this._variables){let r=Object.values(this._variables[i]).filter(t=>t.element&&oi(t.element)==oi(e));r.length>0&&(t[i]=r)}return t}}class Ma{constructor(e={}){this._attribute=e.attribute??null,this._numBins=e.numBins??null}get attribute(){return this._attribute}set attribute(e){this._attribute=e}get numBins(){return this._numBins}set numBins(e){this._numBins=e}get startAttr(){return this._attribute+"_bin_start"}get endAttr(){return this._attribute+"_bin_end"}get binIdAttr(){return this._attribute+"_bin_id"}}class Ga{constructor(e={}){this._attribute=e.attribute??null,this._newAttribute=e.newAttribute??null,this._groupBy=e.groupBy??null,this._min=e.min??null,this._max=e.max??null,this._interval=e.interval??null,this._bandwidth=e.bandwidth??null}get attribute(){return this._attribute}set attribute(e){this._attribute=e}get newAttribute(){return this._newAttribute}set newAttribute(e){this._newAttribute=e}get groupBy(){return this._groupBy}set groupBy(e){this._groupBy=e}get min(){return this._min}set min(e){this._min=e}get max(){return this._max}set max(e){this._max=e}get interval(){return this._interval}set interval(e){this._interval=e}get bandwidth(){return this._bandwidth}set bandwidth(e){this._bandwidth=e}}class za{constructor(e={}){this._attribute=e.attribute??null,this._type=e.type??null,this._value=e.value??null}get attribute(){return this._attribute}set attribute(e){this._attribute=e}get type(){return this._type}set type(e){this._type=e}get value(){return this._value}set value(e){this._value=e}}class Fa{constructor(e,t){this._fn=e,t&&Object.assign(this,t)}get fn(){return this._fn}}class ja extends nt{constructor(e){super(),this._itemMap={},this._type=i.Scene,this._id=e&&e.id?e.id:this._type+s(),e&&e.fillColor&&(this.fillColor=e.fillColor),this._encodings={},this._relations=[],this._triggers={},this._condEncodings={},this._stateContext=new ve(this),this._stateContext.__scene__=this,this._depGraph=new Ba,this._renderers=[]}get depGraph(){return this._depGraph}get interactionTriggers(){return this._triggers}getConditionalEncodings(e){return this._condEncodings[e]||[]}_clearInteractionCaches(){for(let e in this._condEncodings)for(let t of this._condEncodings[e])t.clearResponderPeers()}get state(){return this._stateContext}mark(e,i){if(Object.values(t).indexOf(e)<0)throw new Error("Mascot does not allow directly creating a "+e);let r=void 0===i?{}:i;r.type=e;let s=Ni(this,r);return null!==s&&(s._classId=s.id,this.addChild(s),this._itemMap[s.id]=s,je(s,this._depGraph),qe(this,s,this._depGraph)),s}glyph(...e){let t=[];for(let i of e)t.push([i.parent,i]);let r=Ni(this,{type:i.Glyph,children:e});if(null!==r){r._classId=r.id;for(let e of t)Xe(e[0],e[1],this._depGraph);Ke(r,this._depGraph),qe(this,r,this._depGraph)}return r}composite(){let e=Ni(this,{type:i.Composite});return null!==e&&(e._classId=e.id,this.addChild(e),this._itemMap[e.id]=e,He(e,this._depGraph),qe(this,e,this._depGraph)),e}_addAttributeEncoding(e){let t=oi(e.element);t in this._encodings||(this._encodings[t]={}),this._encodings[t][e.channel]=e}get tables(){let e={},t=this.children.filter(e=>e.type===i.Collection);for(let i of t){let t=i.dataScope?v(i.dataScope):null;t&&!(t.id in e)&&(e[t.id]=t)}return e}onChange(e,...t){if(Object.values(xe).indexOf(e)<0)throw new Error("Unknown Variable Type: "+e);let i=[],r=[],s=[];this._depGraph.getOperatorsOnPath(e,i,r,...t);let n=!1;for(let e of i)e.run(),e.needsFullRender&&(n=!0),s=s.concat(e.outputVars.filter(e=>e.type===xe.CHANNEL||e.type===xe.PROPERTY));for(let e of r)e.run();const a={};for(let e of s){let t="vertex"===e.element.type||"segment"===e.element.type?e.element.parent:e.element;t.id in a||(a[t.id]=[]);let i=e.channel||e.property;a[t.id].includes(i)||a[t.id].push(i)}if(n){for(const e of this._renderers)e._render(this);for(const e of this._renderers)e._renderChanges(this,a)}else for(const e of this._renderers)e._renderChanges(this,a);return a}gridlines(e,t,i){let r=i||{},s="rowId"==t?M:t,n=r.element?ai(r.element,e):ni(s,e,this);if(n){n.attribute!==s&&console.warn("Cannot create a "+e+" axis for "+t);let i=[];if("x"==e)for(let e of n.scales)i.push({scale:e,elems:n.getNormalizedElements(e)});else if("width"==e){let e=Ne(n.element),t=n.scales[0];if(e.layout&&e.layout.type==fe.GRID&&e.layout.numCols>1){let r=e.layout.getElementsByCol(!0);for(let e of r)i.push({scale:t,elems:e})}else i.push({scale:n.scales[0],elems:n.getNormalizedElements(n.scales[0])})}else if("y"==e){let e=Ne(n.element);if(e.layout&&e.layout.type==fe.GRID&&e.layout.numRows>1){let t=e.layout.getElementsByRow(!0,n.element);for(let e of t)i.push({scale:n.getScale(e[0]),elems:e})}else i.push({scale:n.scales[0],elems:n.getNormalizedElements(n.scales[0])})}else if("height"==e){let e=Ne(n.element),t=n.scales[0];if(e.layout&&e.layout.type==fe.GRID&&e.layout.numRows>1){let r=e.layout.getElementsByRow(!0,n.element);for(let e of r)i.push({scale:t,elems:e})}else i.push({scale:t,elems:n.getNormalizedElements(t)})}else if("radialDistance"==e){let e=r.element?r.element:n.element;i.push({scale:n.scales[0],elems:we(e,e.parent)})}for(let e of i){let t=new ui(n.channel,n.attribute,e.scale,e.elems,r);this.addChild(t),this._itemMap[t.id]=t,n.addRefElement(t),st(t,this._depGraph),qe(this,t,this._depGraph)}}else{let i=r.element?r.element:Re(this,t);if(!i)return void console.warn("Cannot create "+e+" gridlines for "+t);let s=Te(i.parent);if(!s.layout)return void console.warn("Cannot create "+e+" gridlines for "+t);let n=we(s);for(let i of n){let s=[];i.layout.type==fe.GRID&&i.layout.numRows>1&&"x"==e?s=i.layout.getElementsByRow():i.layout.type==fe.GRID&&i.layout.numCols>1&&"y"==e?s=i.layout.getElementsByCol():s.push(i.children);for(let n of s){let s=new ui(e,t,null,n,r);this.addChild(s),this._itemMap[s.id]=s,i.layout.addRefElement(s),st(s,this._depGraph),qe(this,s,this._depGraph)}}}}axis(e,t,i){let r=i||{},s="rowId"==t?M:t,n=[],a=r.element?ai(r.element,e):ni(s,e,this);if(a){a.attribute!==s&&console.warn("Cannot create a "+e+" axis for "+s);let t=[];if("x"==e||"width"==e){let e=Ne(r.element?r.element:a.element);if(e.layout&&e.layout.type==fe.GRID&&e.layout.numCols>1){let i=e.layout.getElementsByCell(!0,a.element);for(let e of i)t.push({scale:a.getScale(e[0]),elems:e})}else t.push({scale:a.scales[0],elems:a.getNormalizedElements(a.scales[0])})}else if("y"==e||"height"==e){let e=Ne(r.element?r.element:a.element);if(e.layout&&e.layout.type==fe.GRID&&e.layout.numRows>1){let i=e.layout.getElementsByCell(!0,a.element);for(let e of i)t.push({scale:a.getScale(e[0]),elems:e})}else t.push({scale:a.scales[0],elems:a.getNormalizedElements(a.scales[0])})}else if("radialDistance"==e){let e=r.element?r.element:a.element;t.push({scale:a.scales[0],elems:we(e,e.parent)})}for(let e of t){let t=Object.assign({},r);t.scale=e.scale,t.elems=e.elems,t.type="axis",t.axisType="encoding",t.enc=a,t.rawArgs=r;let i=Ni(this,t);n.push(i),a.addRefElement(i),rt(i,this._depGraph),qe(this,i,this._depGraph),this.onChange(xe.PROPERTY,ze.AXIS_PATH_POSITION,i)}}else{let t=r.element?r.element:Re(this,s);if(!t)return void console.warn("Cannot create a "+e+" axis for "+s);let i=Te(t.parent);if(!i.layout)return void console.warn("Cannot create a "+e+" axis for "+s);let a=we(i);for(let t of a){let i=[];t.layout.type==fe.GRID&&t.layout.numRows>1&&"x"==e?i=t.layout.getElementsByRow():t.layout.type==fe.GRID&&t.layout.numCols>1&&"y"==e?i=t.layout.getElementsByCol():i.push(t.children);for(let a of i){let i=Object.assign({},r);i.elems=a.slice(),i.type="axis",i.axisType="layout",i.channel=e,i.attribute=s;let o=Ni(this,i);n.push(o),t.layout.addRefElement(o),it(o,this._depGraph),qe(this,o,this._depGraph),this.onChange(xe.PROPERTY,ze.AXIS_PATH_POSITION,o)}}}return n.length>1?n:n[0]}legend(e,t,i){let r=i||{},s="rowId"==t?M:t,n=r.element?ai(r.element,e):ni(s,e,this);if(n){n.attribute!==t&&console.warn("Cannot create a "+e+" legend for "+t);let i=B(n.element).type(t);r.type="legend",r.enc=n,r.attrType=i;let s=Ni(this,r);!function(e,t){let i=t.getVariable(xe.BOUNDS,e),r=t.getVariable(xe.PROPERTY,ze.LEGEND_POSITION,e),s=t.getIncomingDataflowOperator(me.EVAL_BBOX,i);t.connect(r,s),t.connect(s,i)}(s,this._depGraph),qe(this,s,this._depGraph),le(s),this.onChange(xe.PROPERTY,ze.LEGEND_POSITION,s)}else console.warn("Cannot create a "+e+" legend for "+s)}mask(e){let t=Ne(e),i=t||e;i.clipMask||i.createClipMask()}setLayout(e,t){if(e.layout&&($e(e,e.layout,this._depGraph),t.type===fe.TREEMAP)){let t=e.firstChild;for(;t&&t.type===i.Collection&&t.layout;)$e(t,t.layout,this._depGraph),t=t.firstChild}if(we(e).forEach(e=>{let i=t?t.clone():t;e._layout=i,i&&(i.group=e)}),Je(e,t,this._depGraph),e.children&&e.children.length>0){let t=Le(e,!0);for(let e of t)this.onChange(xe.CHANNEL,"x",e)}}derive(e,t){let i=e.clone();return t._scene=this,t instanceof Ma?(!function(e,t,i,r){let s=r.getVariable(xe.ITEMS,t),n=r.getVariable(xe.ITEMS,i),a=r.createOneWayDependency(me.BIN_TRANSFORMER);r.connect(s,a),r.connect(a,n);let o=r.getVariable(xe.PROPERTY,ze.NUM_BINS,e);r.connect(o,a),a._binConfig=e,a.run()}(t,e,i,this._depGraph),i._binTransform=t):t instanceof Ga?function(e,t,i,r){let s=r.getVariable(xe.ATTRIBUTE,e.attribute,t),n=r.getVariable(xe.ATTRIBUTE,e.newAttribute,i),a=r.getVariable(xe.ITEMS,i),o=r.createOneWayDependency(me.KDE_TRANSFORMER);o.args=e,r.connect(s,o),r.connect(o,n),r.connect(o,a),o.run()}(t,e,i,this._depGraph):t instanceof za?function(e,t,i,r){let s=r.getVariable(xe.ITEMS,t),n=r.getVariable(xe.ITEMS,i),a=r.createOneWayDependency(me.FILTER_TRANSFORMER);a._spec=e,r.connect(s,a),r.connect(a,n);let o=r.getVariable(xe.PROPERTY,"value",e);r.connect(o,a),a.run()}(t,e,i,this._depGraph):t instanceof Fa&&function(e,t,i,r){let s=r.getVariable(xe.ITEMS,t),n=r.getVariable(xe.ITEMS,i),a=r.createOneWayDependency(me.CUSTOM_TRANSFORMER);a._spec=e,r.connect(s,a),r.connect(a,n);for(let t of Object.keys(e)){if(t.startsWith("_"))continue;let i=r.getVariable(xe.PROPERTY,t,e);r.connect(i,a)}a.run()}(t,e,i,this._depGraph),i}getElement(e){return this._itemMap[e]}getAxis(e,t){return ni(e,t,this).refElements[0]}}function Wa(e,t){return m(t[e.dt],e.attr2value||e.filters||{},e.rowIds)}class Ya extends _e{constructor(e){super(),this.type=fe.DIRECTED,this._top="top"in e?e.top:0,this._left="left"in e?e.left:0,this._nodeSep="nodeSep"in e?e.nodeSep:100,this._edgeSep="edgeSep"in e?e.edgeSep:50,this._rankSep="rankSep"in e?e.rankSep:50,this._spreadLinks=!("spreadLinks"in e)||e.spreadLinks,this._direction="direction"in e?e.direction:ft.Top2Bottom}clone(){return new Ya({top:this._top,left:this._left,nodeSep:this._nodeSep,edgeSep:this._edgeSep,rankSep:this._rankSep,spreadLinks:this._spreadLinks,direction:this._direction})}get top(){return this._top}get left(){return this._left}get nodeSep(){return this._nodeSep}get edgeSep(){return this._edgeSep}get rankSep(){return this._rankSep}get spreadLinks(){return this._spreadLinks}get direction(){return this._direction}}class Ua extends _e{constructor(e){super(),this.type=fe.FORCE,this._x="x"in e?e.x:0,this._y="y"in e?e.y:0,this._iterations="iterations"in e?e.iterations:1,this._repulsion="repulsion"in e?e.repulsion:30,this._attraction="attraction"in e?e.attraction:1,this._linkDistance="linkDistance"in e?e.linkDistance:30}clone(){return new Ua({x:this._x,y:this._y,iterations:this._iterations,repulsion:this._repulsion,attraction:this._attraction,linkDistance:this._linkDistance})}}class Ha extends _e{constructor(e){super(),this.type=fe.PACKING,this._x="x"in e?e.x:400,this._y="y"in e?e.y:400,this._width=e.width,this._height=e.height}clone(){return new Ha({x:this._x,y:this._y,width:this._width,height:this._height})}}class Xa extends _e{constructor(e){super(),this.type=fe.STACK,this._orientation=e.orientation,this._direction=e.direction,this._left=e.left,this._top=e.top,this._horzCellAlignment="horzCellAlignment"in e&&e.horzCellAlignment?e.horzCellAlignment:he.LEFT,this._vertCellAlignment="vertCellAlignment"in e&&e.vertCellAlignment?e.vertCellAlignment:he.BOTTOM,this._gap="gap"in e?e.gap:0}clone(){let e=new Xa({orientation:this._orientation,direction:this._direction,left:this._left,top:this._top});return e._horzCellAlignment=this._horzCellAlignment,e._vertCellAlignment=this._vertCellAlignment,e}get horzCellAlignment(){return this._horzCellAlignment}get vertCellAlignment(){return this._vertCellAlignment}get orientation(){return this._orientation}set horzCellAlignment(e){this._horzCellAlignment=e}set vertCellAlignment(e){this._vertCellAlignment=e}set orientation(e){this._orientation=e}}class qa extends _e{constructor(e){super(),this.type=fe.STRATA,this._direction=e.direction,this._gap="gap"in e?e.gap:0}clone(){return new qa({direction:this._direction,gap:this._gap})}}class Ka extends _e{constructor(e){super(),this.type=fe.TIDYTREE,this._width="width"in e?e.width:500,this._height="height"in e?e.height:500,this._left="left"in e?e.left:100,this._top="top"in e?e.top:100,this._orientation="orientation"in e?e.orientation:dt}get width(){return this._width}get height(){return this._height}get top(){return this._top}get left(){return this._left}get orientation(){return this._orientation}clone(){return new Ka({width:this._width,height:this._height,top:this._top,left:this._left,orientation:this._orientation})}}class Za extends _e{constructor(e){super(),this.type=fe.TREEMAP,this._width=e.width,this._height=e.height,this._left=e.left,this._top=e.top}get width(){return this._width}get height(){return this._height}get top(){return this._top}get left(){return this._left}clone(){return new Za({width:this._width,height:this._height,top:this._top,left:this._left})}}function $a(e){switch(e.type){case fe.GRID:return function(e){let t=new Si(e.args);"left"in e&&(t._left=e.left);"top"in e&&(t._top=e.top);"cellBounds"in e&&(t._cellBounds=e.cellBounds.map(e=>Ja(e)));"grid"in e&&(t._grid=e.grid);return t}(e);case fe.STACK:return function(e){let t=new Xa(e.args);return t}(e);case fe.PACKING:return function(e){let t=new Ha(e.args);return t}(e);case fe.FORCE:return function(e){return new Ua(e.args)}(e);case fe.DIRECTED:return function(e){return new Ya(e.args)}(e);case fe.TIDYTREE:return function(e){return new Ka(e.args)}(e);case fe.TREEMAP:return function(e){return new Za(e.args)}(e);case fe.STRATA:return function(e){return new qa(e.args)}(e);default:return void console.warn("unsupported layout type for deserialization:",e.type)}}function Ja(e){return new se(e.x-e.width/2,e.y-e.height/2,e.width,e.height)}function Qa(e,t,r){e.type===i.Pie&&(e.type=i.Arc),e.args.type=e.type;let s=Ni(t,e.args);return e.id&&(s._id=e.id),e.classId&&(s._classId=e.classId),e.dataScope&&(s.dataScope=Wa(e.dataScope,r)),e.bounds&&(s._bounds=Ja(e.bounds)),e.refBounds&&(s._refBounds=Ja(e.refBounds)),function(e,t,i,r){if(e.vertices){const i=[];for(let t of e.vertices){const e=eo(t,r);i.push(e)}t.vertices=i}t.vertexCounter=e.vertexCounter,t.segmentCounter=e.segmentCounter,t.curveMode=e.curveMode}(e,s,0,r),s}function eo(e,t){let i={type:"vertex",id:e.id,x:e.x,y:e.y,shape:e.shape,width:e.width,height:e.height,radius:e.radius,fillColor:e.fillColor,opacity:e.opacity,strokeWidth:e.strokeWidth,strokeColor:e.strokeColor};return e.dataScope&&(i.dataScope=Wa(e.dataScope,t)),"polarAngle"in e&&(i.polarAngle=e.polarAngle),i}function to(e){let t={};t.fillColor=e.fillColor;let i=new ja(t);console.log("======== deserialization =========");let r={};if(e.tables)for(let t in e.tables){let i=e.tables[t];r[t]=new V(i.data,i.url,i.attributeTypes),r[t]._id=i.id}let s={};if(e.scales)for(let t in e.scales)s[t]=no(e.scales[t]);if(i.scales=s,so(e,i,i,r),ro(e,i),e.encodings){let t={};for(let s of e.encodings){let e=ao(s,i,r);t[e.id]=e}for(let e in t){i._addAttributeEncoding(t[e]);let r=t[e]._baseEnc?t[t[e]._baseEnc]:void 0;tt(t[e],i._depGraph,r),r?i.onChange(xe.ATTR_VALUE,t[e]):i.onChange(xe.CHANNEL,t[e].channel,t[e].element)}}if(e.axes)for(let t of e.axes){let e=t.args?t.args:{};e.tickValues&&Object.values(r)[0].type(t.attr)===a.Date&&(e.tickValues=e.tickValues.map(e=>new Date(new Date(e).toISOString()))),t.id&&(e.id=t.id),i.axis(t.channel,t.attr,e)}if(e.gridlines)for(let t of e.gridlines)i.gridlines(t.channel,t.attr,t.args);return e.bounds&&(i._bounds=Ja(e.bounds)),delete i.scales,i}function io(e,t,r,s){if(e.type===i.Collection){let n=Ni(r,{type:i.Collection,id:e.id});e.classId&&(n._classId=e.classId),t.addChild(n),Ue(n,r._depGraph),qe(t,n,r._depGraph),so(e,n,r,s)}else if(e.type===i.Glyph){let n=Ni(r,{type:i.Glyph,id:e.id});e.classId&&(n._classId=e.classId),t.addChild(n),Ke(n,r._depGraph),qe(t,n,r._depGraph),so(e,n,r,s)}else if(e.type===i.Composite){let n=Ni(r,{type:i.Composite,id:e.id});t.addChild(n),r._itemMap[n.id]=n,He(n,r._depGraph),qe(t,n,r._depGraph),so(e,n,r,s),n._bounds=Ja(e.bounds)}else if(e.type===i.Axis){let i=new Xt({});t.addChild(i),function(e,t,i,r){e.id&&(t._id=e.id);if(t._children=[],e.labels){let s=new nt;so(e.labels,s,i,r),t._labels=s,t._children.push(s)}e.path&&(t._path=io(e.path,t,i,r));if(e.ticks){let s=new nt;so(e.ticks,s,i,r),t._ticks=s,t._children.push(s)}e.title&&(t._title=io(e.title,t,i,r))}(e,i,r,s),r._itemMap[i.id]=i}else if(Object.values(ue).includes(e.type)){let i=Qa(e,r,s);return r._itemMap[i.id]=i,t.addChild(i),je(i,r._depGraph),qe(t,i,r._depGraph),i}}function ro(e,t,i){if(e.children)for(let i of e.children)ro(i,t);else if(Object.values(ue).includes(e.type)){let i=t._itemMap[e.id];e.links&&(i.links=e.links.map(e=>t._itemMap[e])),e.source&&(i.source=t._itemMap[e.source]),e.target&&(i.target=t._itemMap[e.target])}}function so(e,t,i,r){if(e.id&&(t._id=e.id),e.classId&&(t._classId=e.classId),e.dataScope&&(t.dataScope=Wa(e.dataScope,r)),e.bounds&&(t._bounds=Ja(e.bounds)),t._sortBy=e.sortBy,e.children)for(let s of e.children)io(s,t,i,r);e.layout&&(t._layout=$a(e.layout),t._layout.group=t,Je(t,t._layout,i._depGraph))}function no(e){let t=new Jt(e.type,e.args);return t._id=e.id,t.domain=e.domain,t.range=e.range,t}function ao(e,t,i){let r=oo(e.element,e.elementType,t);r||console.warn("element not created:",e.element,e.elementType);let s=e.args?e.args:{};e.table&&(s.table=i[e.table]);let n=new _i(r,e.channel,e.attr,e.aggregator?e.aggregator:"sum",s);if(n._id=e.id,e.scales&&(n._scales=e.scales.map(e=>t.scales[e])),s.baseEnc&&(n._baseEnc=e.args.baseEnc),e.elemGroups&&(n._elemGroups=e.elemGroups.map(e=>e.map(e=>oo(e,r.type,t)))),e.elem2scale){n._elem2scale={};for(let i in e.elem2scale)n._elem2scale[i]=t.scales[e.elem2scale[i]]}return s.startAngle&&(n.startAngle=s.startAngle),n}function oo(e,t,i){if("vertex"===t){let t=e.split("_v_");return i._itemMap[t[0]].vertices.find(t=>t.id===e)}if("segment"===t){let t=e.split("_s_");return i._itemMap[t[0]].segments.find(e=>e._id===parseInt(t[1]))}return i._itemMap[e]}function lo(e){let t={};return t.id=e._id,t.data=e._rawData,t.attributeTypes=e._attrTypes,t.url=e.url,t}function ho(e){let t={};return t.dt=e.dataTable.id,t.attr2value=Object.assign({},e.filters),e.rowIds&&(t.rowIds=e.rowIds.slice()),t}function co(e,t){t.vertices=[];for(let i=0;i<e._vertices.length;i++)t.vertices.push(uo(e._vertices,i));t.vertexCounter=e.vertexCounter,t.segmentCounter=e.segmentCounter,t.curveMode=e.curveMode}function uo(e,t){let i={type:"vertex"};return i.id=e._ids[t],i.x=e._xs[t],i.y=e._ys[t],e.hasDataScope(t)&&(i.dataScope=ho(e.getDataScopeRef(t))),void 0!==e._polarAngles[t]&&(i.polarAngle=e._polarAngles[t]),i.shape=e._shapes[t],i.width=e._widths[t],i.height=e._heights[t],i.radius=e._radii[t],i.fillColor=e._fillColors[t],i.opacity=e._opacities[t],i.strokeWidth=e._strokeWidths[t],i.strokeColor=e._strokeColors[t],i}function _o(e){return e.type===i.Scene?function(e){let t=go(e,{});t.fillColor=e.fillColor,t.scales={},t.encodings=[];for(let i in e._encodings)for(let r in e._encodings[i]){let s=e._encodings[i][r];s._forLegend||t.encodings.push(fo(s));for(let e of s._scales)e.id in t.scales||(t.scales[e.id]=po(e))}t.tables={};let r=function(e){let t={};for(let i in e._encodings)for(let r in e._encodings[i]){let s=e._encodings[i][r];s.dataTable.id in t||s._forLegend||(t[s.dataTable.id]=s.dataTable)}for(let r of e.children)if(![i.Axis,i.Legend,i.Gridlines].includes(r.type)){if(r.dataScope){let e=v(r.dataScope);t[e.id]=e;break}if(r.children&&r.children.length>0){let e=r.firstChild;for(;e;){if(e.dataScope){let i=v(e.dataScope);t[i.id]=i;break}e=e.children&&e.children.length>0?e.firstChild:void 0}}}return t}(e);for(let e in r)t.tables[e]=lo(r[e]);return console.log("======== serialization ========="),console.log(t),t}(e):[i.Collection,i.Glyph,i.Composite].includes(e.type)?go(e,{}):e instanceof Xt?yo(e,{}):e instanceof ce?function(e){let t={args:{}};t.type=e.type,t.id=e.id,e.classId&&(t.classId=e.classId),e.dataScope&&(t.dataScope=ho(e.dataScope)),e.bounds&&(t.bounds=e.bounds.toJSON()),e.refBounds&&(t.refBounds=e.refBounds.toJSON()),e.links&&(t.links=e.links.map(e=>e.id)),e.source&&(t.source=e.source.id),e.target&&(t.target=e.target.id);for(let i in e.styles)i.indexOf("Color")>0&&e.styles[i]instanceof Yt?t.args[i]=e.styles[i].toJSON():t.args[i]=e.styles[i];switch(e.type){case i.Arc:case i.Pie:!function(e,t){t.args.x=e._x,t.args.y=e._y,t.args.innerRadius=e._innerRadius,t.args.outerRadius=e._outerRadius,t.args.startAngle=e._startAngle,t.args.endAngle=e._endAngle,t.args.direction=e._direction,t.args.thickness=e._thickness}(e,t),co(e,t);break;case i.Area:!function(e,t){t.args.baseline=e._baseline,t.args.orientation=e._orientation}(e,t),co(e,t);break;case i.Circle:!function(e,t){t.args.x=e.x,t.args.y=e.y,t.args.radius=e.radius}(e,t);break;case i.Image:break;case i.Line:case i.Path:case i.BezierCurve:co(e,t);break;case i.SimpleText:!function(e,t){t.args.x=e._x,t.args.y=e._y,t.args.text=e._text,t.args.anchor=e._anchor,e._backgroundColor&&(t.args.backgroundColor=e._backgroundColor),e._borderWidth&&(t.args.borderWidth=e._borderWidth),e._borderColor&&(t.args.borderColor=e._borderColor)}(e,t);break;case i.Polygon:!function(e,t){t.args.x=e._x,t.args.y=e._y,t.args.radius=e._radius}(e,t),co(e,t);break;case i.Rect:!function(e,t){t.args.width=e.width,t.args.height=e.height,t.args.top=e.top,t.args.left=e.left}(e,t),co(e,t);case i.Ring:}return t}(e):(console.warn("unsupported serialization",e.type),{type:e.type})}function po(e){let t={};return t.type=e.type,t.id=e.id,e._args&&(t.args=e._args),t.domain=e.domain,t.range=e.range,t}function fo(e){let t={};t.id=e._id,t.element=e._elem.id,t.elementType=e._elem.type,t.channel=e._channel,t.attr=e._attribute,t.aggregator=e._aggregator,t.table=e._table.id,t.args={},t.args.includeZero=e._includeZero,t.args.flipScale=e._flipScale,t.args.mapping=e._mapping,t.args.rangeExtent=e._preferredRangeExtent,t.args.domain=e._preferredDomain,t.args.scaleType=e._scaleType,t.args.scheme=e._colorScheme,e._baseEnc&&(t.args.baseEnc=e._baseEnc.id),t.scales=e._scales.map(e=>e.id),t.elemGroups=e._elemGroups.map(e=>e.map(e=>e.id)),t.elem2scale={};for(let i in e._elem2scale)t.elem2scale[i]=e._elem2scale[i].id;return"angle"==e.channel&&(t.args.startAngle=e.startAngle),t}function go(e,t){if(t.id=e.id,t.type=e.type,e.classId&&(t.classId=e.classId),e.dataScope&&(t.dataScope=ho(e.dataScope)),t.bounds=e.bounds.toJSON(),e._layout&&(t.layout=function(e){switch(e.type){case fe.GRID:return function(e){let t={args:{}};return t.type=e.type,t.args.numCols=e._numCols,t.args.numRows=e._numRows,t.args.start=e._start,t.args.direction=e._direction,t.args.colGap=e._colGap,t.args.rowGap=e._rowGap,t.args.horzCellAlignment=e._cellHorzAlignment,t.args.vertCellAlignment=e._cellVertAlignment,t.args.rowOffset=e._rowOffset,t.args.colOffset=e._colOffset,t.left=e._left,t.top=e._top,t.group=e.group.id,t}(e);case fe.STACK:return function(e){let t={args:{}};return t.type=e.type,t.args.orientation=e._orientation,t.args.direction=e._direction,t.args.left=e._left,t.args.top=e._top,t.args.horzCellAlignment=e._horzCellAlignment,t.args.vertCellAlignment=e._vertCellAlignment,t.args.gap=e._gap,t.group=e.group.id,t}(e);case fe.PACKING:return function(e){let t={args:{}};return t.type=e.type,t.args.x=e._x,t.args.y=e._y,t.args.width=e._width,t.args.height=e._height,t.group=e.group.id,t}(e);case fe.FORCE:return function(e){let t={args:{}};return t.type=e.type,t.args.x=e._x,t.args.y=e._y,t.args.iterations=e._iterations,t.args.repulsion=e._repulsion,t.args.attraction=e._attraction,t.args.linkDistance=e._linkDistance,t.group=e.group.id,t}(e);case fe.CLUSTER:return function(e){let t={args:{}};return t.type=e.type,t.args.size=e._size,t.args.rootX=e._rootX,t.args.rootY=e._rootY,t}(e);case fe.DIRECTED:return function(e){let t={args:{}};return t.type=e.type,t.args.left=e._left,t.args.top=e._top,t.args.width=e._width,t.args.height=e._height,t.args.edgeSep=e._edgeSep,t.args.spreadLinks=e._spreadLinks,t.args.direction=e._direction,t}(e);case fe.TIDYTREE:return function(e){let t={args:{}};return t.type=e.type,t.args.left=e._left,t.args.top=e._top,t.args.width=e._width,t.args.height=e._height,t.args.orientation=e._orientation,t}(e);case fe.TREEMAP:return function(e){let t={args:{}};return t.type=e.type,t.args.left=e._left,t.args.top=e._top,t.args.width=e._width,t.args.height=e._height,t}(e);case fe.STRATA:return function(e){let t={args:{}};return t.type=e.type,t.args.direction=e._direction,t.args.gap=e._gap,t}(e);default:throw new Error("unknow layout type "+e.type)}}(e._layout)),t.children=[],e.children.length>0)for(let i of e.children)i instanceof Xt?yo(i,t):i instanceof ui?mo(i,t):t.children.push(_o(i));return t.sortBy=e._sortBy,t}function yo(e,t){t.axes??=[];let i={};i.type=e._type,i.id=e._id,i.attr=e._attribute,i.channel=e._channel,i.args={},i.args.orientation=e._orientation,i.args.strokeColor=e._strokeColor,i.args.textColor=e._textColor,i.args.fontSize=e._fontSize,i.args.tickOffset=e._tickOffset,i.args.tickSize=e._tickSize,i.args.tickAnchor=e._tickAnchor,i.args.tickVisible=e._tickVisible,i.args.pathVisible=e._pathVisible,i.args.labelOffset=e._labelOffset,i.args.labelFormat=e._labelFormat,i.args.titleOffset=e._titleOffset,i.args.title=e._titleText,i.args.rotateTitle=e._rotateTitle,i.args.titleVisible=e._showTitle,i.args.labelRotation=e._labelRotation,t.axes.push(i)}function mo(e,t){t.gridlines??=[];let i={};i.type=e._type,i.id=e._id,i.attr=e._attribute,i.channel=e._channel,i.args=e._args,t.gridlines.push(i)}const bo={canvas:void 0,getContext:function(){return window?(void 0===this.canvas&&(this.canvas=document.createElement("canvas")),this.canvas?this.canvas.getContext("2d"):null):null},getPath2D:function(e){return e?new Path2D(e):new Path2D}};function xo(e,t,r){if(!e.bounds.contains(t,r))return!1;switch(e.type){case i.Path:case i.Arc:case i.BezierCurve:case i.Line:{let i=bo.getContext(),s=bo.getPath2D(e.getSVGPathData());return i.lineWidth=Math.max(e.strokeWidth,2.5),i.stroke(s),e.closed||"none"!==e.fillColor?i.isPointInPath(s,t,r):i.isPointInStroke(s,t,r)}case i.Circle:{let i=e.x,s=e.y;if(e.rotation){let t=ee(i,s,e.rotation[1],e.rotation[2],e.rotation[0]);i=t.x,s=t.y}return Math.sqrt(Math.pow(t-i,2)+Math.pow(r-s,2))<=e.radius+e.strokeWidth}case i.Collection:if([i.Arc,i.Pie,i.Polygon,i.Area].indexOf(e.firstChild.type)>=0){let i=e.getSVGPathData();if(""!==i){let s=bo.getContext(),n=bo.getPath2D(i);return s.lineWidth=Math.max(e.firstChild.strokeWidth,2.5),s.stroke(n),s.isPointInPath(n,t,r)}}return e.bounds.contains(t,r);default:return e.bounds.contains(t,r)}}function vo(e,t,i,r){let s=Le(e),n=r?r.map(e=>obj2Predicate(e)):[];for(let e=s.length-1;e>=0;e--){let r=s[e];if(xo(r,t,i)&&J(r,n))return r}}function wo(e,t,r,s){let n=s?s.map(e=>obj2Predicate(e)):[];if(!e.children||0==e.children.length)return xo(e,t,r)&&e.type!==i.Scene?e:void 0;let a=e.children;e.type===i.Scene&&(a=a.slice(),a.sort((e,t)=>at(e)?1:at(t)?-1:0));for(let e=0;e<a.length;e++){let i=a[e];if(xo(i,t,r)&&J(i,n))return i}}function Eo(e,t,r){let s=[];if(!e.children||0==e.children.length)return e.bounds.overlap(t)&&e.type!==i.Scene?[e]:[];for(let i=e.children.length-1;i>=0;i--){let r=e.children[i];r.bounds.overlap(t)&&s.push(r)}return s}function Co(e,t,i,r){let s,n=Le(e),a=r||2,o=bo.getContext();for(let e of n){if(!(e instanceof Path))continue;let r=bo.getPath2D(e.getSVGPathData());if(o.lineWidth=Math.max(e.strokeWidth,2*a),o.stroke(r),o.isPointInStroke(r,t,i)){s=e;break}}if(!s)return null;let l=[];for(let e of s.vertices){let t=Math.max(a,e.width,2*e.radius),i=Math.max(a,e.height,2*e.radius);l.push({i:e,b:new se(e.x-t/2,e.y-i/2,t,i)})}for(let e of l)if(e.b.contains(t,i))return e.i;if(s.segments&&s.segments.length>0)for(let e of s.segments){let r=bo.getPath2D();if(r.moveTo(e.vertex1.x,e.vertex1.y),r.lineTo(e.vertex2.x,e.vertex2.y),o.lineWidth=Math.max(s.strokeWidth,a),o.stroke(r),o.isPointInStroke(r,t,i))return e}return null}function Ao(e,t,i){let r=i||2;if(de(e)){let i=[];for(let t of e.vertices){let e=Math.max(r,t.width,2*t.radius),s=Math.max(r,t.height,2*t.radius);i.push({i:t,b:new se(t.x-e/2,t.y-s/2,e,s)})}if(e.type===ItemType.Rect)for(let t of e.segments){let s=Math.max(e.strokeWidth,r);"v"===(t.vertex1.x===t.vertex2.x?"v":"h")?i.push({i:t,b:new se(t.vertex1.x-s/2,d3.min([t.vertex1.y,t.vertex2.y])-s/2,s,Math.abs(t.vertex1.y-t.vertex2.y))}):i.push({i:t,b:new se(d3.min([t.vertex1.x,t.vertex2.x])-s/2,t.vertex1.y-s/2,Math.abs(t.vertex1.x-t.vertex2.x),s)})}for(let e of i)if(e.b.intersects(t))return e.i;return null}if(!isGuide(e)&&e.children&&e.children.length>0){for(let i of e.children)if(i.bounds.intersects(t)){let e=Ao(i,t,r);if(e)return e}return null}return null}const So="x",ko="y",Ro="xAttr",To="yAttr",Oo="xCoords",Io="yCoords",No="xVals",Lo="yVals",Po="xVal",Vo="yVal",Do="selectedRows",Bo="dx",Mo="dy",Go="dxData",zo="dyData",Fo="deltaX",jo="deltaY",Wo="element";function Yo(e,t,i){let r=e.getScale(i),s=r?r.type:null;if("band"===s){let e=r._scale,i=e.bandwidth();return e.domain().filter(r=>{let s=e(r);return s+i/2>t[0]&&s-i/2<t[1]})}if("point"===s){let e=r._scale,i=e.step();return e.domain().filter(r=>{let s=e(r);return s+i/2>t[0]&&s-i/2<t[1]})}let n=t.map(t=>e.getAttrValue(t,i)).sort((e,t)=>e-t);return{min:n[0],max:n[1]}}function Uo(e){let t=new Map;for(let r of e)if(r)if(r.type===i.Collection&&r.children&&r.children.length>0){let e=r.children[0],i=msc.getChannelEncodingByElement(e,"x"),s=msc.getChannelEncodingByElement(e,"y"),n=e,a=e;!i&&e.leftSegment&&(i=msc.getChannelEncodingByElement(e.leftSegment,"x"),i&&(n=e.leftSegment)),!s&&e.bottomSegment&&(s=msc.getChannelEncodingByElement(e.bottomSegment,"y"),s&&(a=e.bottomSegment)),t.set(r.id,{element:r,child:e,xEnc:i,yEnc:s,xChild:n,yChild:a,xAttr:i?i.sourceAttribute??i.attribute:void 0,yAttr:s?s.sourceAttribute??s.attribute:void 0})}else if(r.type===i.Area){let e=null,i=null,s=null,n=null;r.anyVertex&&(e=msc.getChannelEncodingByElement(r.anyVertex,"x"),e&&(i=r.anyVertex)),!e&&r.topLeftVertex&&(e=msc.getChannelEncodingByElement(r.topLeftVertex,"x"),e&&(i=r.topLeftVertex)),!e&&r.bottomLeftVertex&&(e=msc.getChannelEncodingByElement(r.bottomLeftVertex,"x"),e&&(i=r.bottomLeftVertex)),s=msc.getChannelEncodingByElement(r,"y")??msc.getChannelEncodingByElement(r,"height"),s&&(n=r),!s&&r.anyVertex&&(s=msc.getChannelEncodingByElement(r.anyVertex,"y"),s&&(n=r.anyVertex)),!s&&r.topLeftVertex&&(s=msc.getChannelEncodingByElement(r.topLeftVertex,"y"),s&&(n=r.topLeftVertex)),t.set(r.id,{element:r,child:r,xEnc:e,yEnc:s,xChild:i,yChild:n,xAttr:e?e.sourceAttribute??e.attribute:void 0,yAttr:s?s.sourceAttribute??s.attribute:void 0})}return t}function Ho(t,r,s,n,a){for(let n of t){let t,a="background"===n.source?s:n.source;a=Array.isArray(a)?a:[a];let l="brushX"===n.event?e.brushX():"brushY"===n.event?e.brushY():e.brush();var o;l.on("start",function(i){t=Uo(a),o&&a.length>1&&e.select(o).call(l.move,null),o=this}),l.on("brush end",function(i){let r,o;if(i&&i.selection)switch(n.event){case"brushX":r=[i.selection[0],i.selection[1]],o=void 0;break;case"brushY":r=void 0,o=[i.selection[0],i.selection[1]];break;default:r=[i.selection[0][0],i.selection[1][0]],o=[i.selection[0][1],i.selection[1][1]]}else r=void 0,o=void 0;let l=n.eventContext;l.clear(),l.set(Oo,r),l.set(Io,o);let h=e.select(this).attr("id").replace("brush-","");t||(t=Uo(a));let c=t.get(h),d=c&&c.xAttr&&r?r.map(e=>c.xEnc.getAttrValue(e,c.xChild)).sort((e,t)=>e-t):void 0,u=c&&c.yAttr&&o?o.map(e=>c.yEnc.getAttrValue(e,c.yChild)).sort((e,t)=>e-t):void 0,_=c&&c.xAttr?c.xEnc.dataTable:c&&c.yAttr?c.yEnc.dataTable:void 0,p={};c&&c.xAttr&&r&&(p[c.xAttr]=Yo(c.xEnc,r,c.xChild)),c&&c.yAttr&&o&&(p[c.yAttr]=Yo(c.yEnc,o,c.yChild));let f=_?_.rows(p):void 0;c&&(l.set(Ro,c.xAttr),l.set(To,c.yAttr),l.set(No,d),l.set(Lo,u),l.set(Do,f)),s.onChange(xe.EVT_CTX,l),i&&"end"===i.type&&(t=void 0)});for(let e of a){let t=e.type===i.Axis?e.boundsWithoutTitle:e.bounds,s=[[t.left,t.top],[t.right,t.bottom]];r.append("g").attr("class","brush").attr("id","brush-"+e.id).call(l.extent(s))}}}function Xo(t,i,r,s,n){for(let s of t){"background"===s.source||s.source;let t=e.zoom();t.on("zoom",e=>{e.sourceEvent.preventDefault(),e.sourceEvent.stopPropagation();let t=s.eventContext;t.clear();let[n,a]=ie(i.attr("id"),e.sourceEvent.clientX,e.sourceEvent.clientY);t.set(So,n),t.set(ko,a),t.set(Fo,e.sourceEvent.deltaX),t.set(jo,e.sourceEvent.deltaY),r.onChange(xe.EVT_CTX,t)}),i.call(t)}}function qo(t,i,r,s,n){for(let s of t){let t="background"===s.source?i.select("#"+r.id):Array.isArray(s.source)?i.selectAll(s.source.map(e=>e.classId?"."+e.classId:"#"+e.id).join(", ")):s.source.classId?i.selectAll("."+s.source.classId):i.select("#"+s.source.id),n=e.drag();n.on("start",e=>{let t=e.sourceEvent.target.__data__;if(!t||!msc.getChannelEncodingByElement(t,"x")&&!msc.getChannelEncodingByElement(t,"y")){let[s,n]=ie(i.attr("id"),e.sourceEvent.clientX,e.sourceEvent.clientY);const a=ke(r,[]);t=a.find(e=>"vertex"!==e.type&&"segment"!==e.type&&!e.children&&xo(e,s,n)&&(msc.getChannelEncodingByElement(e,"x")||msc.getChannelEncodingByElement(e,"y"))),t||(t=a.find(e=>{if("vertex"===e.type||"segment"===e.type)return!1;if(e.children)return!1;if(!msc.getChannelEncodingByElement(e,"x")&&!msc.getChannelEncodingByElement(e,"y"))return!1;let t=e.parent?.bounds;return t&&s>=t.left&&s<=t.right&&n>=t.top&&n<=t.bottom}))}s._dragElem=t}),n.on("drag",e=>{let[t,n]=ie(i.attr("id"),e.sourceEvent.clientX,e.sourceEvent.clientY),a=s.eventContext;a.set(So,t),a.set(ko,n),a.set(Bo,e.dx),a.set(Mo,e.dy);let o=s._dragElem;if(a.set("element",o),o){let i=msc.getChannelEncodingByElement(o,"x"),r=msc.getChannelEncodingByElement(o,"y");if(i){let r="log"!==i.getScale(o)?.type;a.set(Ro,i.attribute),a.set(Go,i.getAttrValue(t-e.dx,o,r)-i.getAttrValue(t,o,r))}if(r){let t="log"!==r.getScale(o)?.type;a.set(To,r.attribute),a.set(zo,r.getAttrValue(n-e.dy,o,t)-r.getAttrValue(n,o,t))}}r.onChange(xe.EVT_CTX,a)}),n.on("end",e=>{s._dragElem=void 0;let t=s.eventContext;t.set("element",void 0),r.onChange(xe.EVT_CTX,t)}),t.call(n)}}function Ko(e,t,i,r,s){for(let r of e){let e="background"===r.source?t.select("#"+i.id):Array.isArray(r.source)?t.selectAll(r.source.map(e=>e.classId?"."+e.classId:"#"+e.id).join(", ")):r.source.classId?t.selectAll("."+r.source.classId):t.select("#"+r.source.id);const s=e=>{let[s,n]=ie(t.attr("id"),e.clientX,e.clientY),a=r.eventContext;if(a.set(So,s),a.set(ko,n),"background"===r.source){let e=msc.getEncodingsByChannel("x",i)[0],t=msc.getEncodingsByChannel("y",i)[0],r=e?e.attribute:void 0,o=t?t.attribute:void 0,l=r?e.getAttrValue(s):void 0,h=o?t.getAttrValue(n):void 0;a.set(Ro,r),a.set(To,o),a.set(Po,l),a.set(Vo,h)}let o=e.target.__data__;a.set(Wo,o),i.onChange(xe.EVT_CTX,a)};"background"===r.source?t.on("mousemove",s):e.on("mouseover",s);const n=e=>{let t=r.eventContext;t.set(Wo,void 0),i.onChange(xe.EVT_CTX,t)};"background"===r.source?t.on("mouseleave",n):e.on("mouseout",n)}}function Zo(e,t,i,r,s){let n=e.filter(e=>e.isKeyboardDriven());n.length>0&&$o(n,t,i);for(let t of e)if(!t.isStateDriven()&&!t.isKeyboardDriven()&&t.isWidgetDriven()){let e=(Array.isArray(t.source)?t.source:[t.source]).map(e=>document.getElementById(e)),r=t.eventContext;for(let s of e)s&&s.addEventListener(t.event,function(){r.set("inputValue",s.value),"checkbox"===s.type&&r.set("checked",s.checked),i.onChange(xe.EVT_CTX,r)})}}function $o(t,i,r,s,n){let a=".mascot-keyboard-"+r.id+"-"+i.attr("id"),o={};for(let e of t){let t=["keydown","keyup"].includes(e.event)?e.event:"keydown";t in o||(o[t]=[]),o[t].push(e)}for(let t in o)e.select(window).on(t+a,null),e.select(window).on(t+a,e=>{for(let i of o[t]){if(void 0!==i.source&&e.key!==i.source)continue;let s=i.eventContext;s.clear(),s.set("event",t),s.set("source",i.source),s.set("key",e.key),s.set("code",e.code),s.set("altKey",e.altKey),s.set("ctrlKey",e.ctrlKey),s.set("metaKey",e.metaKey),s.set("shiftKey",e.shiftKey),s.set("repeat",e.repeat),r.onChange(xe.EVT_CTX,s)}})}function Jo(e,t,i,r,s){t.on("wheel",r=>{for(let s of e){r.preventDefault(),r.stopPropagation();let[e,n]=ie(t.attr("id"),r.clientX,r.clientY),a=s.eventContext;a.set("deltaX",r.deltaX),a.set("deltaY",r.deltaY),a.set("x",e),a.set("y",n),i.onChange(xe.EVT_CTX,a)}})}function Qo(e,t,i,r,s){t.on("click",r=>{for(let s of e){let[e,n]=ie(t.attr("id"),r.clientX,r.clientY),a=s.eventContext,o=[];s.source.type&&o.push({property:"type",value:s.source.type}),s.source.classId&&o.push({property:"classId",value:s.source.classId});let l=ke(i,o).filter(t=>xo(t,e,n))[0];a.clear(),a.set("x",e),a.set("y",n),a.set("element",l),i.onChange(xe.EVT_CTX,a)}})}function el(e,t,i){const r=i.querySelector("defs");if(!r)return;const s=e.styles&&e.styles.strokeColor||"#ccc";if(t.removeAttribute("marker-start"),t.removeAttribute("marker-end"),e.startStyle&&"none"!==e.startStyle){const i=e.id+"-marker-start";tl(r,i,e.startStyle,e.startSize,s),t.setAttribute("marker-start","url(#"+i+")")}if(e.endStyle&&"none"!==e.endStyle){const i=e.id+"-marker-end";tl(r,i,e.endStyle,e.endSize,s),t.setAttribute("marker-end","url(#"+i+")")}}function tl(e,t,i,r,s){let n=e.querySelector("#"+t);for(n||(n=document.createElementNS("http://www.w3.org/2000/svg","marker"),e.appendChild(n));n.firstChild;)n.firstChild.remove();n.setAttribute("id",t),n.setAttribute("viewBox","0 0 "+r+" "+r),n.setAttribute("refX",r),n.setAttribute("refY",r/2),n.setAttribute("markerWidth",r/2),n.setAttribute("markerHeight",r/2),n.setAttribute("orient","auto-start-reverse");const a=document.createElementNS("http://www.w3.org/2000/svg","path");"filled"===i?(a.setAttribute("d","M0,0 L"+r+","+r/2+" L0,"+r+" Z"),a.style.fill=s,a.style.stroke="none"):(a.setAttribute("d","M0,0 L"+r+","+r/2+" L0,"+r),a.style.fill="none",a.style.stroke=s,a.style.strokeWidth="2",a.style.strokeLinecap="round",a.style.strokeLinejoin="round"),n.appendChild(a)}function il(e){return e.id+"-bg"}function rl(e){return e.id+"-path"}function sl(e){switch(e){case he.TOP:return"text-before-edge";case he.BOTTOM:return"auto";case he.LEFT:return"start";case he.RIGHT:return"end";case he.CENTER:case he.MIDDLE:return"middle";default:return e}}function nl(e,t,i){let r=e.bounds;for(let s of i)switch(s){case"x":t.setAttribute("x",r.left);break;case"y":t.setAttribute("y",r.top);break;case"width":t.setAttribute("width",r.width);break;case"height":t.setAttribute("height",r.height);break;default:t.style[re[s]]=e[s]}e._dirty=!1}function al(e,t,i){for(let r of i)switch(r){case"x":t.setAttribute("cx",e.x);break;case"y":t.setAttribute("cy",e.y);break;case"radius":t.setAttribute("r",e.radius);break;default:t.style[re[r]]=e[r]}e._dirty=!1}function ol(e,t,r){let s=t[e.id];for(let t of r)switch(t){case"d":case"strength":case"vertices":case"x1":case"y1":case"x2":case"y2":s.setAttribute("d",e.getSVGPathData());break;case"startStyle":case"startSize":case"endStyle":case"endSize":break;default:s.style[re[t]]=e[t]}if(e.type===i.Arrow){const t=s.ownerSVGElement;t&&el(e,s,t)}if(e.vertices&&e.vertices.length>0){let i=e.vertices.filter(e=>void 0!==e.shape);if(i.length>0)for(let r of i){let i=t[e.id+"-vertices-"+r.id];"rect"==r.shape?(i.setAttribute("x",r.x-r.width/2),i.setAttribute("y",r.y-r.height/2),i.setAttribute("width",r.width),i.setAttribute("height",r.height)):"circle"==r.shape&&(i.setAttribute("cx",r.x),i.setAttribute("cy",r.y),i.setAttribute("r",r.radius)),i.style.fill=r.fillColor,i.style.opacity=r.opacity,i.style.strokeWidth=r.strokeWidth,i.style.stroke=r.strokeColor}}e._dirty=!1}function ll(e,t,i,r){for(let s of i)switch(s){case"text":t.textContent=e.text,r&&(r.setAttribute("width",e.bounds.width+10),r.setAttribute("height",e.bounds.height+10));break;case"x":t.setAttribute("x",e.x),r&&r.setAttribute("x",e.bounds.left-5);break;case"y":t.setAttribute("y",e.y),r&&r.setAttribute("y",e.bounds.top-5);break;default:t.style[re[s]]=e[s],r&&(r.style[re[s]]=e[s])}e._dirty=!1}function hl(e,t,i){for(let r of i)switch(r){case"text":{const i=t.querySelector("div");i&&(i.innerHTML=e.text,t.setAttribute("height",i.offsetHeight));break}case"x":t.setAttribute("x",e.x);break;case"y":t.setAttribute("y",e.y);break;case"width":t.setAttribute("width",e.width);break;case"visibility":const i=t.querySelector("div");i&&(i.style.visibility=e.visibility),t.style[re[r]]=e[r];break;default:t.style[re[r]]=e[r]}e._dirty=!1}function cl(e,t,i){for(let r of i)"gridlinesPosition"===r?t.setAttribute("d",e.getSVGPathData()):t.style[re[r]]=e[r];e._dirty=!1}function dl(e,t,i){let r=t.some(e=>"x"===e||"y"===e);we(e).forEach(e=>{let s=i._compMap[e.id];if(s){if(r)for(let t of e.children)i._renderItem(t,{});if(!1!==e._dirty||!r){for(let i of t)"visibility"===i?s.style.visibility=e.visibility:"opacity"===i&&(s.style.opacity=e.opacity);e._dirty=!1}}})}function ul(e,t){let i=Object.keys(t._compMap).filter(t=>t.startsWith(e.id+"_"));for(let e of i)t._removed[e]=1;t._renderItem(e);for(let e in t._removed)e in t._compMap&&(t._compMap[e].remove(),delete t._compMap[e]);for(let e of i)delete t._removed[e]}class _l{constructor(e){this._svgId=e,this._svg=document.getElementById(this._svgId),this._compMap={},this._decoMap={},this._lastTriggerEvt=void 0}render(e,t){if(!this._svg&&(this._svg=document.getElementById(this._svgId),!this._svg)){const i=()=>{this._svg=document.getElementById(this._svgId),this._svg?this.render(e,t):console.error("SVGRenderer: SVG element '#"+this._svgId+"' not found after DOMContentLoaded.")};return void("loading"===document.readyState?document.addEventListener("DOMContentLoaded",i,{once:!0}):Promise.resolve().then(i))}let i=t||{};if(!this._svg.querySelector("defs")){const e=document.createElementNS("http://www.w3.org/2000/svg","defs");this._svg.appendChild(e)}this._render(e,i),this._registerEvents(e,i),e._renderers.includes(this)||e._renderers.push(this)}_render(e,t,i){for(let e in this._decoMap)this._decoMap[e].remove(),delete this._decoMap[e];this._removed={};for(let e in this._compMap)this._removed[e]=1;this._renderItem(e,t,i);for(let e in this._removed)this._compMap[e].remove(),delete this._compMap[e]}_registerEvents(t,i){let r=e.select("#"+this._svgId);r.on(".",null);for(let e in t.interactionTriggers){let i=Object.values(t.interactionTriggers[e]);switch(e){case"click":r.on("click",null),Qo(i,r,t);break;case"brush":case"brushX":case"brushY":Ho(i,r,t);break;case"drag":case"dragX":case"dragY":qo(i,r,t);break;case"hover":Ko(i,r,t);break;case"change":case"input":Zo(i,r,t);break;case"keydown":case"keyup":$o(i,r,t);break;case"zoom":Xo(i,r,t);break;case"scroll":Jo(i,r,t)}}}clear(){if(this._svg){for(;this._svg.firstChild;)this._svg.firstChild.remove();e.select("#"+this._svgId).on(".",null),console.log("clearing canvas"),this._compMap={},this._decoMap={}}}_renderItem(e,t,r){if(this._configSVG(e),!e.children&&!1===e._dirty)return;let s=this._compMap[e.id];if(r){const e=r.delay||0,t=r.duration||0;s.style.transition=`all ${t}ms ease ${e}ms`}switch(e.type){case i.Scene:!function(e,t){t.style.background=e.fillColor?e.fillColor:"#fff"}(e,this._svg);break;case i.Circle:!function(e,t){t.setAttribute("cx",e.x),t.setAttribute("cy",e.y),t.setAttribute("r",e.radius)}(e,s);break;case i.Rect:!function(e,t){let i=e.bounds;t.setAttribute("x",i.left),t.setAttribute("y",i.top),t.setAttribute("width",i.width),t.setAttribute("height",i.height)}(e,s);break;case i.Path:case i.BezierCurve:case i.BundledPath:case i.Chord:case i.Polygon:case i.Link:case i.Pie:case i.Line:case i.Area:case i.Ring:case i.Arc:case i.Gridlines:case i.Arrow:!function(e,t,r){t.setAttribute("d",e.getSVGPathData()),e.closed||(t.style.fill="none"),(e.id.includes("axis")||e.id.includes("gridlines"))&&(t.style.shapeRendering="crispEdges"),e.type===i.BundledPath&&(t.style.mixBlendMode="multiply"),e.type===i.Arrow&&r&&el(e,t,r)}(e,s,this._svg);break;case i.SimpleText:!function(e,t,i){if(t.setAttribute("text-anchor",sl(e.anchor[0])),t.setAttribute("alignment-baseline",sl(e.anchor[1])),t.setAttribute("dominant-baseline",sl(e.anchor[1])),t.setAttribute("x",e.x),t.setAttribute("y",e.y),i){e._updateBounds();let t=e.bounds;i.setAttribute("x",t.left-5),i.setAttribute("y",t.top-5),i.setAttribute("width",t.width+10),i.setAttribute("height",t.height+10),i.setAttribute("rx",5),i.setAttribute("ry",5),i.style.fill=e.backgroundColor,i.style.stroke=e.borderColor,i.style.strokeWidth=e.borderWidth}if(e.textPath){let i=t.querySelector("textPath");i||(i=document.createElementNS("http://www.w3.org/2000/svg","textPath"),t.appendChild(i)),i.setAttribute("href","#"+rl(e)),i.setAttribute("startOffset",e.textPathOffset),i.textContent=e.text}else t.textContent=e.text}(e,s,this._compMap[il(e)]);break;case i.RichText:!function(e,t){for(;t.firstChild;)t.firstChild.remove();t.setAttribute("width",e.width),t.setAttribute("x",e.x),t.setAttribute("y",e.y),t.style.border="1px solid #ddd";let i=document.createElementNS("http://www.w3.org/1999/xhtml","div");i.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),i.style.width="100%",i.style.padding="10px",i.style.backgroundColor="rgba(255, 255, 255, 0.85)",i.style.color="black",i.style.visibility="visible",i.style.boxSizing="border-box",i.style.opacity="1",i.innerHTML=e.text,t.appendChild(i),t.setAttribute("height",i.offsetHeight)}(e,s);break;case i.Image:!function(e,t){t.setAttribute("href",e.src),t.setAttribute("x",e.x),t.setAttribute("y",e.y),t.setAttribute("width",e.width),t.setAttribute("height",e.height)}(e,s)}if(e._rotate&&s.setAttribute("transform","rotate("+e._rotate.join(" ")+")"),function(e,t,r){if(!e.styles)return;let s=Object.keys(e.styles);e.type===i.RichText&&(s=s.filter(e=>["textAnchor","fillColor"].indexOf(e)<0));for(let n of s)if(void 0!==e.styles[n])if(n.indexOf("Color")>0&&e.styles[n].type==i.LinearGradient){const i=r.querySelector("defs"),s=e.styles[n];if(!i.querySelector("#"+s.id)){const e=document.createElementNS("http://www.w3.org/2000/svg","linearGradient");e.setAttribute("id",s.id),e.setAttribute("x1",s.x1+"%"),e.setAttribute("x2",s.x2+"%"),e.setAttribute("y1",s.y1+"%"),e.setAttribute("y2",s.y2+"%");for(let t of s.stops){const i=document.createElementNS("http://www.w3.org/2000/svg","stop");i.setAttribute("offset",t.offset+"%"),i.style.stopColor=t.color,i.style.stopOpacity=t.opacity,e.appendChild(i)}i.appendChild(e)}t.style[re[n]]="url(#"+s.id+")"}else if(t.style[re[n]]=e.styles[n],"visibility"===n)if(e.type===i.SimpleText){if(e.hasBackground()){const t=r.querySelector("#"+il(e));t&&(t.style[re[n]]=e.styles[n])}}else if(e.type===i.RichText){const i=t.querySelector("div");i&&(i.style.visibility=e.styles[n])}}(e,s,this._svg),e.vertices&&e.vertices.length>0&&e.vertices.map(e=>e.shape).filter(e=>void 0!==e).length>0&&this._renderVertices(e),t&&t.bounds?this._renderBounds(e):de(e)&&t&&t.refBounds&&this._renderRefBounds(e),e.clipMask){const t=this._svg.querySelector("defs");let i=t.querySelector("#"+e.id+"-clipPath");i||(i=document.createElementNS("http://www.w3.org/2000/svg","clipPath"),i.setAttribute("id",e.id+"-clipPath"),t.appendChild(i));let r=i.querySelector("rect");r||(r=document.createElementNS("http://www.w3.org/2000/svg","rect"),i.appendChild(r)),r.setAttribute("x",e.clipMask.left),r.setAttribute("y",e.clipMask.top),r.setAttribute("width",e.clipMask.width),r.setAttribute("height",e.clipMask.height),s.setAttribute("clip-path","url(#"+e.id+"-clipPath)");let n=e.id+"-bg",a=s.querySelector("#"+n);a||(a=document.createElementNS("http://www.w3.org/2000/svg","rect"),a.setAttribute("id",n),a.setAttribute("pointer-events","all"),a.setAttribute("fill","transparent"),s.insertBefore(a,s.firstChild)),a.setAttribute("x",e.clipMask.left),a.setAttribute("y",e.clipMask.top),a.setAttribute("width",e.clipMask.width),a.setAttribute("height",e.clipMask.height)}if(e.children){let i=[...e.children].sort((e,t)=>(e.z||0)-(t.z||0));for(let e of i)this._renderItem(e,t,r)}else e._dirty=!1}_renderChanges(e,t){for(let r in t){let s=e.getElement(r);if(s){switch(s.type){case i.Rect:we(s).forEach(e=>{!1!==e._dirty&&nl(e,this._compMap[e.id],t[r])});break;case i.Circle:we(s).forEach(e=>{!1!==e._dirty&&al(e,this._compMap[e.id],t[r])});break;case i.Path:case i.Area:case i.Line:case i.Arrow:case i.BezierCurve:case i.BundledPath:let e=[],n=["x","y","width","height"];for(let i of t[r])n.includes(i)?e.indexOf("d")<0&&e.push("d"):e.push(i);we(s).forEach(t=>{!1!==t._dirty&&ol(t,this._compMap,e)});break;case i.SimpleText:we(s).forEach(e=>{!1!==e._dirty&&ll(e,this._compMap[e.id],t[r],this._compMap[il(e)])});break;case i.RichText:we(s).forEach(e=>{!1!==e._dirty&&hl(e,this._compMap[e.id],t[r])});break;case i.Glyph:dl(s,t[r],this);break;case i.Gridlines:!0===s._dirty&&cl(s,this._compMap[s.id],t[r]);break;case i.Axis:we(s).forEach(e=>{ul(e,this)});break;case i.Collection:case i.Group:case i.Composite:break;default:console.warn("unsupported element type for update: "+s.type)}t[r].includes("z")&&s.parent&&this._reorderSiblingsByZ(s.parent)}}}_reorderSiblingsByZ(e){let t=this._compMap[e.id];if(!t)return;let i=[...e.children].sort((e,t)=>(e.z||0)-(t.z||0));for(let e of i){let i=this._compMap[e.id];i&&t.appendChild(i)}}_configSVG(e){if(e.id in this._compMap)delete this._removed[e.id],e.type===i.SimpleText&&(e.hasBackground()&&delete this._removed[il(e)],e.textPath&&delete this._removed[rl(e)]);else{let t,r=e.parent;if(t=r&&r.id&&r.id in this._compMap?this._svg.querySelector("#"+r.id):this._svg,e.type===i.SimpleText){if(e.hasBackground()){const i=document.createElementNS("http://www.w3.org/2000/svg","rect");i.setAttribute("id",il(e)),t.appendChild(i),this._compMap[il(e)]=i}if(e.textPath){const t=this._svg.querySelector("defs"),i=rl(e);let r=t.querySelector("#"+i);r||(r=document.createElementNS("http://www.w3.org/2000/svg","path"),r.setAttribute("id",i),t.appendChild(r),this._compMap[i]=r),r.setAttribute("d",e.textPath),r.style.fill="none"}}const s=document.createElementNS("http://www.w3.org/2000/svg",this._getSVGElementType(e));t?t.appendChild(s):console.warn("Parent element not found for ",e.id,e.parent?e.parent.id:null),this._compMap[e.id]=s}if(e.type==i.Gridlines){const t=this._compMap[e.id].parentNode;t.insertBefore(this._compMap[e.id],t.firstChild)}this._compMap[e.id].setAttribute("id",e.id),this._compMap[e.id].__data__=e;let t=e.type;e.classId&&(t+=" "+e.classId),e.parent&&e.parent.type===i.Axis&&(t+=e.id.endsWith("_ticks")?" axis_ticks":e.id.endsWith("_labels")?" axis_labels":""),this._compMap[e.id].setAttribute("class",t)}_renderBounds(e){let t=e.bounds;if(e.layout&&"grid"==e.layout.type&&this._renderLayout(e),!(e.id in this._decoMap)){const t=document.createElementNS("http://www.w3.org/2000/svg","rect");t.setAttribute("class","deco"),this._svg.appendChild(t),this._decoMap[e.id]=t}const i=this._decoMap[e.id];i.setAttribute("x",t.left),i.setAttribute("y",t.top),i.setAttribute("width",t.width),i.setAttribute("height",t.height),i.setAttribute("fill","none"),i.setAttribute("stroke","blue"),i.setAttribute("stroke-width","1px"),i.setAttribute("stroke-dasharray","5,5")}_renderRefBounds(e){let t=e.refBounds;if(t){if(!(e.id in this._decoMap)){const t=document.createElementNS("http://www.w3.org/2000/svg","rect");t.setAttribute("class","deco"),this._svg.appendChild(t),this._decoMap[e.id]=t}const i=this._decoMap[e.id];i.setAttribute("x",t.left),i.setAttribute("y",t.top),i.setAttribute("width",t.width),i.setAttribute("height",t.height),i.setAttribute("fill","none"),i.setAttribute("stroke","blue"),i.setAttribute("stroke-width","1px"),i.setAttribute("stroke-dasharray","5,5")}}_renderVertices(e){let t=e.id+"-vertices";if(t in this._compMap)delete this._removed[t];else{let i=e.parent,r=i?i.id:this._svgId;const s=this._svg.querySelector("#"+r),n=document.createElementNS("http://www.w3.org/2000/svg","g");n.setAttribute("id",t),s.appendChild(n),this._compMap[t]=n}if(0===e.vertices.map(e=>e.shape).filter(e=>void 0!==e).length)return void(this._compMap[t].style.visibility="hidden");this._compMap[t].style.visibility="visible";let i=e.vertices.filter(e=>void 0!==e.shape);for(let e of i){let i=t+"-"+e.id;if(i in this._compMap)if(e.shape!==this._compMap[i].tagName){this._compMap[i].remove();const r=document.createElementNS("http://www.w3.org/2000/svg",e.shape);r.setAttribute("id",i),this._compMap[t].appendChild(r),this._compMap[i]=r,delete this._removed[i]}else delete this._removed[i];else{const r=document.createElementNS("http://www.w3.org/2000/svg",e.shape);r.setAttribute("id",i),this._compMap[t].appendChild(r),this._compMap[i]=r}const r=this._compMap[i];"rect"==e.shape?(r.setAttribute("x",e.x-e.width/2),r.setAttribute("y",e.y-e.height/2),r.setAttribute("width",e.width),r.setAttribute("height",e.height)):"circle"==e.shape&&(r.setAttribute("cx",e.x),r.setAttribute("cy",e.y),r.setAttribute("r",e.radius)),r.style.fill=e.fillColor,r.style.opacity=e.opacity,r.style.strokeWidth=e.strokeWidth,r.style.stroke=e.strokeColor}}_renderLayout(e){let t=e.id+"-grid";if(!(t in this._decoMap)){const e=document.createElementNS("http://www.w3.org/2000/svg","g");e.setAttribute("id",t),e.setAttribute("class","deco"),this._svg.appendChild(e),this._decoMap[t]=e}let i=e.layout.cellBounds;e.layout.rowGap;this._decoMap[t].querySelectorAll("rect").forEach(e=>e.remove());for(let e of i){const i=document.createElementNS("http://www.w3.org/2000/svg","rect");i.setAttribute("x",e.left),i.setAttribute("y",e.top),i.setAttribute("width",e.width),i.setAttribute("height",e.height),i.setAttribute("stroke","blue"),i.setAttribute("stroke-width","1px"),i.setAttribute("stroke-dasharray","5,5"),i.setAttribute("fill","none"),this._decoMap[t].appendChild(i)}}_getSVGElementType(e){switch(e.type){case i.Rect:return"rect";case i.Collection:case i.Group:case i.Glyph:case i.Scene:case i.Axis:case i.Legend:case i.Composite:return"g";case i.Area:case i.Path:case i.Polygon:case i.Ring:case i.Pie:case i.Arc:case i.BezierCurve:case i.BundledPath:case i.Chord:case i.Line:case i.Gridlines:case i.Arrow:return"path";case i.Circle:return"circle";case i.SimpleText:return"text";case i.RichText:return"foreignObject";case"vertex":if("circle"==e.shape)return"circle";if("rect"==e.shape)return"rect";throw"argument exception";case"image":return"image"}}}function pl(e,t){return void 0===e&&void 0===t||void 0!==e&&void 0!==t}function fl(e,t){const i=Object.keys(e),r=Object.keys(t);return i.length===r.length&&(0===i.length||i.every(e=>r.includes(e)))}function gl(e,t){if(!pl(e.layout,t.layout))return console.log("Not both defined or undefined:",e.bounds,t.bounds),!1;let i=e.layout,r=t.layout;if(!i&&!r)return!0;if(i.type!==r.type)return console.log("layout types are different:",i,r),!1;switch(i.type){case fe.GRID:return function(e,t){e._cellBounds.length!==t._cellBounds.length&&console.log("cell bounds length different:",e,t);for(let i=0;i<e._cellBounds;i++)if(!ml(e._cellBounds[i],t._cellBounds[i]))return console.log("cell bounds not equal:",e,t),!1;for(let i=0;i<e._grid.length;i++)for(let r=0;r<e._grid[i].length;r++)if(e._grid[i][r]!==t._grid[i][r])return console.log("grid not equal",e,t),!1;return e._numCols===t._numCols&&e._numRows===t._numRows&&e._start===t._start&&e._direction===t._direction&&e._rowGap===t._rowGap&&e._colGap===t._colGap&&e._cellHorzAlignment===t._cellHorzAlignment&&e._cellVertAlignment===t._cellVertAlignment&&e._rowOffset===t._rowOffset&&e._colOffset===t._colOffset&&e._left===t._left&&e._top===t._top}(i,r);case fe.STACK:return function(e,t){return e._orientation===t._orientation&&e._direction===t._direction&&e._left===t._left&&e._top===t._top&&e._horzCellAlignment===t._horzCellAlignment&&e._vertCellAlignment===t._vertCellAlignment&&e._gap===t._gap}(i,r);case fe.PACKING:return function(e,t){return e._x===t._x&&e._y===t._y&&e._width===t._width&&e._height===t._height}(i,r);case fe.FORCE:return function(e,t){return e._x===t._x&&e._y===t._y&&e._iterations===t._iterations&&e._repulsion===t._repulsion&&e._attraction===t._attraction&&e._linkDistance===t._linkDistance}(i,r);case fe.DIRECTED:return function(e,t){return e._width===t._width&&e._height===t._height&&e._top===t._top&&e._left===t._left&&e._edgeSep===t._edgeSep&&e._spreadLinks===t._spreadLinks&&e._direction===t._direction}(i,r);case fe.TIDYTREE:return function(e,t){return e._width===t._width&&e._height===t._height&&e._top===t._top&&e._left===t._left&&e._orientation===t._orientation}(i,r);case fe.STRATA:return function(e,t){return e._direction===t._direction&&e._gap===t._gap}(i,r);case fe.TREEMAP:return function(e,t){return e._width===t._width&&e._height===t._height&&e._top===t._top&&e._left===t._left}(i,r);default:return!1}}function yl(e,t){if(!pl(e.bounds,t.bounds))return console.log("Not both defined or undefined:",e.bounds,t.bounds),!1;let i=e.bounds,r=t.bounds;return!i&&!r||ml(i,r)}function ml(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function bl(e,t){if(!pl(e,t))return console.log("Not both defined or undefined:",e,t),!1;if(e.type!==t.type)return console.log("Different mark types:",e,t),!1;if(e.id!==t.id)return console.log("id not equal:",e,t),!1;if(e.classId!==t.classId)return console.log("class id not equal:",e,t),!1;if(!vl(e,t))return console.log("DataScopes not equal",e,t),!1;if(!yl(e,t))return console.log("Bounds not equal",e,t),!1;if(!pl(e.links,t.links))return console.log("Not both defined or undefined: links ",e.links,t.links),!1;if(!pl(e.source,t.source))return console.log("Not both defined or undefined: source ",e.source,t.source),!1;if(!pl(e.target,t.target))return console.log("Not both defined or undefined: links ",e.target,t.target),!1;if(e.links&&t.links&&e.links.length!==t.links.length)return console.log("unequal number of links",e,t),!1;if(e.source&&t.source&&!bl(e.source,t.source))return console.log("different sources",e.source,t.source),!1;if(e.target&&t.target&&!bl(e.target,t.target))return console.log("different targets",e.target,t.target),!1;switch(e.type){case i.Arc:case i.Pie:return xl(e,t)?e.x===t.x&&e.y===t.y&&e.innerRadius===t.innerRadius&&e.outerRadius===t.outerRadius&&e.startAngle===t.startAngle&&e.endAngle===t.endAngle&&e.direction===t.direction&&e.thickness===t.thickness:(console.log("vertices not equal:",e,t),!1);case i.Area:return xl(e,t)?e.baseline===t.baseline&&e.orientation===t.orientation:(console.log("vertices not equal:",e,t),!1);case i.Circle:return e.x===t.x&&e.y===t.y&&e.radius===t.radius;case i.Image:return console.warn("not implemented"),!0;case i.Line:case i.Path:case i.BezierCurve:return!!xl(e,t)||(console.log("vertices not equal:",e,t),!1);case i.SimpleText:return e.x===t.x&&e.y===t.y&&e.text===t.text&&e.anchor[0]===t.anchor[0]&&e.anchor[1]===t.anchor[1];case i.Polygon:return xl(e,t)?e.x===t.x&&e.y===t.y&&e.radius===t.radius:(console.log("vertices not equal:",e,t),!1);case i.Rect:return xl(e,t)?e.width===t.width&&e.height===t.height&&e.top===t.top&&e.left===t.left:(console.log("vertices not equal:",e,t),!1);case i.Ring:default:return console.warn("not implemented"),!0}}function xl(e,t){if(e.vertices.length!==t.vertices.length)return console.log("unequal number of vertices:",e,t),!1;for(let i=0;i<e.vertices.length;i++){let r=e.vertices[i],s=t.vertices[i];return r.id!==s.id?(console.log("vertex id not equal:",r,s),!1):r.x!==s.x||r.y!==s.y?(console.log("vertex position not equal:",r,s),!1):vl(r,s)?r._polarAngle===s._polarAngle&&r.shape===s.shape&&r.width===s.width&&r.height==s.height&&r.radius==s.radius&&r.fillColor==s.fillColor&&r.opacity==s.opacity&&r.strokeWidth==s.strokeWidth&&r.strokeColor==s.strokeColor:(console.log("vertex data scopes not equal:",r.dataScope,s.dataScope),!1)}}function vl(e,t){if(!pl(e.dataScope,t.dataScope))return console.log("Not both defined or undefined:",e.dataScope,t.dataScope),!1;if(!e.dataScope&&!t.dataScope)return!0;let i=e.dataScope,r=t.dataScope,s=i.filters||{},n=r.filters||{};if(!fl(s,n))return!1;for(let e in s)if(s[e]!==n[e])return!1;return i.dataTable.id===r.dataTable.id&&E(i).length===E(r).length}function wl(e,t){return e.type!==t.type&&console.log("Different types:",e.type,t.type),[i.Collection,i.Glyph,i.Composite].includes(e.type)?El(e,t):e instanceof ce?bl(e,t):void 0}function El(e,t){let i=e.children.filter(e=>!Object.values(r).includes(e.type)),s=t.children.filter(e=>!Object.values(r).includes(e.type));if(i.length!==s.length)return console.log("children length not equal:",i,s),!1;if(e.id!==t.id)return console.log("id not equal:",e,t),!1;if(e.classId!==t.classId)return console.log("class id not equal:",e,t),!1;if(!vl(e,t))return console.log("DataScopes not equal",e.dataScope,t.dataScope),!1;if(!yl(e,t))return console.log("Bounds not equal",e,t),!1;if(!gl(e,t))return console.log("Layouts not equal",e,t),!1;if(!function(e,t){if(!fl(e,t))return console.log("different keys",e,t),!1;for(let i in e)if(e[i]!==t[i])return!1;return!0}(e._sortBy,t._sortBy))return console.log("SortBy not equal",e,t),!1;for(let e=0;e<i.length;e++)if(!wl(i[e],s[e]))return console.log("Not equal",i[e],s[e]),!1;return!0}class Cl extends _e{constructor(e){super(),this.type=fe.CIRCULAR,this._x="x"in e?e.x:100,this._y="y"in e?e.y:100,this._radius="radius"in e?e.radius:100}get x(){return this._x}get y(){return this._y}get radius(){return this._radius}clone(){return new Cl({x:this._x,y:this._y,radius:this._radius})}}class Al extends _e{constructor(e){super(),this.type=fe.CLUSTER,this._isRadial="radial"in e&&e.radial,this._angleExtent="angleExtent"in e?e.angleExtent:360,this._radius="radius"in e?e.radius:300,this._rootX="x"in e?e.x:300,this._rootY="y"in e?e.y:300,this._orientation="orientation"in e?e.orientation:dt,this._width="width"in e?e.width:800,this._height="height"in e?e.height:600,this._left="left"in e?e.left:60,this._top="top"in e?e.top:100,this._tree="tree"in e?e.tree:void 0}get radius(){return this._radius}get angleExtent(){return this._angleExtent}get x(){return this._rootX}get y(){return this._rootY}get width(){return this._width}get height(){return this._height}get left(){return this._left}get top(){return this._top}isRadial(){return this._isRadial}get orientation(){return this._orientation}clone(){return new Al({radius:this._radius,angleExtent:this._angleExtent,x:this._rootX,y:this._rootY,radial:this._isRadial,orientation:this._orientation,left:this._left,top:this._top,width:this._width,height:this._height,tree:this._tree})}}function Sl(e,t,r){let s=e.scene,o=r||{};if(o.attribute=o.attribute||M,console.log("------ divide by",o.attribute," ----"),function(e,t,i){if(!e||void 0===t)throw new Error("Incomplete information to do divide. You must specify an element, a categorical data attribute and a data table");t instanceof V&&n(i.attribute,t);if(i.layout&&!(i.layout instanceof _e))throw new Error("Invalid layout: "+i.layout)}(e,t,o),t instanceof G||t instanceof F)throw"Not implemented";if(t instanceof V){let{newMark:r,collection:n}=function(e,t,r,s,n){let o=n.type(r);if(o!=a.String&&o!=a.Date&&o!=a.Integer)throw new Error("Divide only works on a string or date attribute: "+r+" is "+o);if(!kl(t))throw new Error("The "+t.type+" is not dividable");switch(t.type){case i.Line:case i.Path:return;case i.Circle:return function(e,t,r,s,n){let a,o,l,h=we(t),c=r||_t;if(c!=_t&&c!=pt)throw new Error("Unknown orientation: "+c);c===_t&&h.forEach(r=>{let h=r.dataScope?r.dataScope:N(n),c=L(h,s),d=Ni(e,{type:i.Collection});null==o&&(o=d.id),d._classId=o,d.dataScope=h;let u=r.parent;u.removeChild(r),delete e._itemMap[r.id];let _=360/c.length,p=90;for(let i=0;i<c.length;i++){let s=Ni(e,{type:"arc",innerRadius:0,outerRadius:r.radius,x:r.x,y:r.y,startAngle:Tt(p-_*(i+1)),endAngle:Tt(p-_*i),strokeColor:r.strokeColor,fillColor:r.fillColor,strokeWidth:r.strokeWidth,opacity:r.opacity});l||(l=s.id),s.classId=l,s.dataScope=c[i],s._updateBounds(),s._refBounds=s.bounds.clone(),d.addChild(s),d._layout=new Xa({orientation:_t,direction:gt.CLOCKWISE}),d._layout.group=d,u.removeChild(r),u.addChild(d),r===t&&(a=d)}});return{newMark:a.children[0],collection:a}}(e,t,s,r,n);case i.Rect:return function(e,t,r,s,n){let a,o=we(t),l=r||dt;if(l!=dt&&l!=ut)throw new Error("Unknown orientation: "+l);let h={},c=0;for(let e of o){let t=L(e.dataScope?e.dataScope:N(n),s);t.length>c&&(c=t.length),h[e.id]=t}let d,u=Ni(e,{type:"rect",left:t.bounds.left,top:t.bounds.top,width:t.bounds.width,height:t.bounds.height,strokeColor:t.strokeColor,fillColor:t.fillColor,strokeWidth:t.strokeWidth,opacity:t.opacity});u._classId=u.id;for(let r of o){let s=Ni(e,{type:i.Collection});null==d&&(d=s.id),s._classId=d,s.dataScope=r.dataScope?r.dataScope:N(n);let o=r.parent;o.removeChild(r),delete e._itemMap[r.id];let c=h[r.id],_=r.bounds,p=_.left,f=_.top,g=l==dt?_.width/c.length:_.width,y=l==dt?_.height:_.height/c.length;for(let e=0;e<c.length;e++){let t=Vi(u);t.dataScope=c[e],t.resize(g,y),t._updateBounds(),t._refBounds=t.bounds.clone(),s.addChild(t)}o.addChild(s),s._layout=new Xa({orientation:l,left:p,top:f}),s._layout.group=s,r==t&&(a=s)}return e.removeChild(u),delete e._itemMap[u.id],{newMark:a.children[0],collection:a}}(e,t,s,r,n);case i.Area:return function(e,t,r,s,n){let a,o=we(t),l=r||dt;if(l!=dt&&l!=ut)throw new Error("Unknown orientation: "+l);let h,c={},d=0;for(let e of o){let t=L(e.dataScope?e.dataScope:N(n),s);t.length>d&&(d=t.length),c[e.id]=t}let u=Object.assign({},t.styles);u.vertices=t.vertices.map(e=>[e.x,e.y]),u.type="area",u.orientation=t.orientation,u.baseline=t.baseline;let _=Ni(e,u);_._classId=_.id;for(let r of o){let s=Ni(e,{type:i.Collection});null==h&&(h=s.id),s._classId=h,s.dataScope=r.dataScope?r.dataScope:N(n);let o=r.parent;o.removeChild(r),delete e._itemMap[r.id];let d=c[r.id],u=r.bounds,p=u.left,f=u.top,g=l==dt?u.width/d.length:u.width,y=l==dt?u.height:u.height/d.length;for(let e=0;e<d.length;e++){let t=Vi(_);t.dataScope=d[e],t.resize(g,y),t._updateBounds(),t._refBounds=t.bounds.clone(),s.addChild(t);for(let e=0;e<t.vertices.length;e++){let i=t.vertices[e],s=r.vertices[e];s&&s.dataScope?i.dataScope=I(t.dataScope,s.dataScope):i.dataScope=t.dataScope}}o.addChild(s),s._layout=new Xa({orientation:l,left:p,top:f}),s._layout.group=s,r==t&&(a=s)}return e.removeChild(_),delete e._itemMap[_.id],{newMark:a.children[0],collection:a}}(e,t,s,r,n);case i.Ring:return function(e,t,r,s,n){let a,o,l,h=we(t),c=r||_t;if(c!=_t&&c!=pt)throw new Error("Unknown orientation: "+c);c===_t&&h.forEach(r=>{let h=r.dataScope?r.dataScope:N(n),c=L(h,s),d=Ni(e,{type:i.Collection});null==o&&(o=d.id),d._classId=o,d.dataScope=h;let u=r.parent;u.removeChild(r),delete e._itemMap[r.id];let _=360/c.length,p=90;for(let i=0;i<c.length;i++){let s=Ni(e,{type:"arc",innerRadius:r.innerRadius,outerRadius:r.outerRadius,x:r.x,y:r.y,startAngle:Tt(p-_*(i+1)),endAngle:Tt(p-_*i),strokeColor:r.strokeColor,fillColor:r.fillColor,strokeWidth:r.strokeWidth,opacity:r.opacity});l||(l=s.id),s.classId=l,s.dataScope=c[i],s._updateBounds(),s._refBounds=s.bounds.clone(),d.addChild(s),d._layout=new Xa({orientation:_t,direction:gt.CLOCKWISE}),d._layout.group=d,u.removeChild(r),u.addChild(d),r===t&&(a=d)}});return{newMark:a.children[0],collection:a}}(e,t,s,r,n);case i.Pie:case i.Arc:return function(e,t,r,s,n){let a,o,l,h=we(t),c=r||_t;if(c!=_t&&c!=pt)throw new Error("Unknown orientation: "+c);c===_t||h.forEach(r=>{let h=r.dataScope?r.dataScope:N(n),c=L(h,s),d=Ni(e,{type:i.Collection});null==o&&(o=d.id),d._classId=o,d.dataScope=h;let u=r.parent;u.removeChild(r),delete e._itemMap[r.id];for(let i=0;i<c.length;i++){let s=Ni(e,{type:"arc",innerRadius:r.innerRadius+i*(r.outerRadius-r.innerRadius)/c.length,outerRadius:r.innerRadius+(i+1)*(r.outerRadius-r.innerRadius)/c.length,x:r.x,y:r.y,startAngle:r.startAngle,endAngle:r.endAngle,strokeColor:r.strokeColor,fillColor:r.fillColor,strokeWidth:r.strokeWidth,opacity:r.opacity});l||(l=s.id),s.classId=l,s.dataScope=c[i],s._updateBounds(),s._refBounds=s.bounds.clone(),d.addChild(s),d._layout=new Xa({orientation:pt}),d._layout.group=d,u.removeChild(r),u.addChild(d),r===t&&(a=d)}});return{newMark:a.children[0],collection:a}}(e,t,s,r,n)}}(s,e,o.attribute,o.orientation,t);return We(e,s._depGraph),je(r,s._depGraph),Ue(n,s._depGraph),qe(n,r,s._depGraph),n.parent.type!==i.Scene&&qe(n.parent,n,s._depGraph),s.onChange(xe.CHANNEL,"width",r),{newMark:r,collection:n}}}function kl(e){if([i.Line,i.Circle,i.Rect,i.Area,i.Ring,i.Pie,i.Path].indexOf(e.type)<0)return!1;if(e.type===i.Path&&(e.closed||!e.firstVertex.dataScope))return!1;if(e.dataScope){let t=we(e);for(let e of t)if(A(e.dataScope)>1)return!0;return!1}return!0}function Rl(e,t){let r=Ie(e),s=t||{};if(console.log("------ classify by",s.attribute," ----"),!Tl(e))throw new Error("The "+e.type+" is not classifiable");return function(e,t,r,s){let n=we(t);for(let t of n){let n,a={},o=t.children;for(let e of o){let t=k(e.dataScope,r);t in a||(a[t]=[]),a[t].push(e)}let l=B(o[0]);for(let o in a){let h=Ni(e,{type:i.Collection});t.addChild(h),void 0===n&&(n=h.id),h._classId=n,h.dataScope=O(t.dataScope?t.dataScope:N(l),r,o);for(let e of a[o])h.addChild(e);s&&(h._layout=s.clone(),h._layout.group=h)}}}(r,e,s.attribute,s.layout),Xe(e,e.firstChild.firstChild,r._depGraph),Ue(e.firstChild,r._depGraph),qe(e.firstChild,e.firstChild.firstChild,r._depGraph),qe(e,e.firstChild,r._depGraph),r.onChange(xe.CHANNEL,"width",e.firstChild.firstChild),e.firstChild}function Tl(e){return e.type===i.Collection&&!(e.children.length<2)}function Ol(e,t,r){if(!(t instanceof G||Array.isArray(t)&&t.every(e=>e instanceof G)))throw"Cannot stratify on a non-tree dataset";if(![i.Circle,i.Rect,i.Ring].includes(e.type))throw"Cannot stratify elements that are not rects, circles, or rings";let s=Ie(e),n=r||{},a=n.direction,o=n.size,l=e.parent,h=function(e,t,r,s,n,a){switch(t.type){case i.Circle:case i.Ring:return function(e,t,r,s,n,a){let o,l=r||yt.OUTWARD,h=n||50;if(l!==yt.INWARD&&l!==yt.OUTWARD)throw"Unknown direction to stratify";let c,d=we(t,e),u=Array.isArray(a)?a:[a];if(s){let r=Ni(e,{type:i.Collection});r.dataScope=void 0,null==c&&(c=r.id),r._classId=c;let s=d.map(e=>u[0].getNode(e.datum[Y]));Il(e,d,s,u[0],r,t.classId?t.classId:t.id,400,350,l,h),o=r}else d.forEach((r,s)=>{let n=Ni(e,{type:i.Collection});n.dataScope=void 0,null==c&&(c=n.id),n._classId=c;let a=r.parent;Nl(r,t.id,l,h,u[s],u[s].getRoot(),n,e,!0),n._layout=new qa({direction:l}),n._layout.group=n,a.addChild(n),r===t&&(o=n)});return o}(e,t,r,s,n,a);case i.Rect:return function(e,t,r,s,n,a){let o,l,h=r||ft.Top2Bottom,c=n||50;if(!Object.values(ft).includes(h))throw"Unknown direction to stratify";return we(t).forEach(r=>{let s=Ni(e,{type:i.Collection});s.dataScope=void 0,null==l&&(l=s.id),s._classId=l;let n=r.parent;Ll(r,t.id,h,c,a,a.getRoot(),s,e,!0),s._layout=new qa({direction:h}),s._layout.group=s,n.addChild(s),r===t&&(o=s)}),o}(e,t,r,0,n,a)}}(s,e,a,n.startFromLeaf,o,t);return Xe(l,e,s._depGraph),Ue(h,s._depGraph),h.children.length>0&&qe(h,h.firstChild,s._depGraph),qe(h.parent,h,s._depGraph),h}function Il(e,t,r,s,n,a,o,l,h,c){let d=r.map(e=>s.getParent(e)).filter((e,t,i)=>i.findIndex(t=>t[Y]===e[Y])===t);if(d=d.filter(e=>e!==s.getRoot()),0===d.length)return;let u=[];for(let r of d){let d,_,p,f=t.filter(e=>s.getParent(s.getNode(e.datum[Y]))===r);if(f[0].type===i.Circle){let e=f.map(e=>te(o,l,e.bounds.x,e.bounds.y)-e.radius),t=f.map(e=>te(o,l,e.bounds.x,e.bounds.y)+e.radius);p=h===yt.OUTWARD?d3.max(t):d3.min(e)-c;let i=f.map(e=>Ot(e.bounds.x,e.bounds.y,o,l)),r=f.map(e=>Ot(o+te(o,l,e.bounds.x,e.bounds.y),l-e.radius,o,l)),s=i.map((e,t)=>e-r[t]),n=i.map((e,t)=>e+r[t]),a=s.concat(n);d=d3.min(a),_=d3.max(a)}else f[0].type===i.Arc&&(d=360,_=-360,f.forEach(e=>{let t=e.startAngle,i=e.endAngle;i<t&&(i+=360),d=d3.min([d,t]),_=d3.max([_,i])}),d=Tt(d),_=Tt(_),p=h===yt.OUTWARD?d3.max(f.map(e=>e.outerRadius)):d3.min(f.map(e=>e.innerRadius))-c);let g=Ni(e,{type:"arc",innerRadius:p,outerRadius:p+c,x:o,y:l,startAngle:Tt(d),endAngle:Tt(_),strokeColor:t[0].strokeColor,fillColor:t[0].fillColor,strokeWidth:t[0].strokeWidth,opacity:t[0].opacity});g._updateBounds(),g.dataScope=s.getNodeDataScopeRef(r),g._classId=a,n.addChild(g),u.push(g)}Il(e,u,d,s,n,a,o,l,h,c)}function Nl(e,t,r,s,n,a,o,l,h){h&&(e.dataScope=n.getNodeDataScopeRef(a),e._classId=t);let c=n.getChildren(a);if(0===c.length)return;let d=e.type===i.Circle||e.type===i.Ring?60:e.startAngle,u=(e.type===i.Circle||e.type===i.Ring?360:e.angle)/c.length;for(let a=0;a<c.length;a++){let h,_;_=r===yt.OUTWARD?e.type===i.Circle?e.radius:e.outerRadius:e.type===i.Circle?e.radius-s:e.innerRadius-s,h=Ni(l,360===u?{type:"ring",innerRadius:_,outerRadius:_+s,x:e.x,y:e.y,strokeColor:e.strokeColor,fillColor:e.fillColor,strokeWidth:e.strokeWidth,opacity:e.opacity}:{type:"arc",innerRadius:_,outerRadius:_+s,x:e.x,y:e.y,startAngle:Tt(d+u*a),endAngle:Tt(d+u*(a+1)),strokeColor:e.strokeColor,fillColor:e.fillColor,strokeWidth:e.strokeWidth,opacity:e.opacity}),h._updateBounds(),h.dataScope=n.getNodeDataScopeRef(c[a]),h._classId=t+"_strata",o.addChild(h),Nl(h,t,r,s,n,c[a],o,l)}}function Ll(e,t,i,r,s,n,a,o,l){l&&(e.dataScope=s.getNodeDataScopeRef(n),e._classId=t,a.addChild(e));let h,c,d,u=s.getChildren(n);if(0!==u.length){h=e.left,c=e.bottom,d=e.width/u.length;for(let n=0;n<u.length;n++){let o=Vi(e);gi(o,h-o.left,c-o.top),o.resize(d,r),o._updateBounds(),h+=d,o.dataScope=s.getNodeDataScopeRef(u[n]),o._classId=t,a.addChild(o),Ll(o,t,i,r,s,u[n],a)}}}function Pl(e,t){if(e.type==i.Glyph)for(let t of e.children)t._refBounds||(t._refBounds=t.bounds.clone());e.dataScope=N(t)}class Vl{constructor(e,t,i){this._elems=e,this._channel=t,this._anchor=i}get elements(){return this._elems}get channel(){return this._channel}get anchor(){return this._anchor}}class Dl{constructor(e,t){this._elem=e,this._base=t,this._id=Bl(e,t),this._channels={},this._attribute=void 0}get id(){return this._id}get element(){return this._elem}get base(){return this._base}get channels(){return Object.keys(this._channels)}addChannel(e,t){let i={};i.elemAnchor="elementAnchor"in t?t.elementAnchor:"x"==e||"angle"==e?he.CENTER:he.MIDDLE,i.baseAnchor="baseAnchor"in t?t.baseAnchor:"x"==e||"angle"==e?he.CENTER:he.MIDDLE,i.offset="offset"in t?t.offset:0,"attribute"in t&&(this._attribute=t.attribute),this._channels[e]=i}hasChannel(e){return e in this._channels}getElementAnchor(e){return this._channels[e].elemAnchor}getBaseAnchor(e){return this._channels[e].baseAnchor}getOffset(e){return this._channels[e].offset}get attribute(){return this._attribute?this._attribute:M}}function Bl(e,t){return(e.classId?e.classId:e.id)+":"+(t.classId?t.classId:t.id)}function Ml(e,t,i,r){let s=Ie(e);v(e.dataScope)!==v(t.dataScope)&&console.warn("Affix: elements and base elements are not created from the same table");let n=Bl(e,t),a=s._relations.find(e=>e.id===n);a||(a=new Dl(e,t),s._relations.push(a)),a.addChannel(i,r||{}),function(e,t){let i=t.getVariable(xe.AFFIXATION,e),r=t.getOutgoingDataflowOperator(me.AFFIXER,i);t.connect(i,r);for(let i of e.channels){let s=t.getVariable(xe.CHANNEL,i,e.element),n=t.getVariable(xe.CHANNEL,i,e.base);t.connect(n,r),t.connect(r,s)}r.run()}(a,s._depGraph)}function Gl(e,t,i){let r=Ie(e[0]),s=new Vl(e,t,i);!function(e,t){let i=t.createMultiWayDependency(me.ALIGNER),r=t.getVariable(xe.ALIGNMENT,e);t.connect(r,i);for(let r of e.elements){let s=t.getVariable(xe.CHANNEL,e.channel,r);t.connect(s,i)}i.run()}(s,r._depGraph),r._relations.push(s)}function zl(e,t){let i=Ie(e[0]),r={};e.forEach(e=>r[k(e.dataScope,Y)]=e);let s=v(t[0].dataScope),n=s.tree?"parent":"source",a=s.tree?"child":"target";for(let t of e)t.links=[];for(let e of t){let t=k(e.dataScope,n),i=k(e.dataScope,a),s=r[t],o=r[i];e.source=s,e.target=o,s.links.push(e),o.links.push(e)}Qe(e.find(e=>e.links.length>0),i._depGraph),i.onChange(xe.CHANNEL,"x",e[0])}function Fl(e,t,i,r){let s=Ie(e);if(e instanceof nt)!function(e,t,i,r){e.dataScope&&v(e.dataScope).has(t)?function(e,t,i,r){if(!v(e.dataScope).has(t))return void console.warn("Cannot order collection children by an non-existent attribute",t);let s;if(t===M)s=(e,i)=>parseInt(k(e.dataScope,t).substring(1))-parseInt(k(i.dataScope,t).substring(1));else{switch(v(e.children[0].dataScope).type(t)){case a.Date:break;case a.Number:case a.Integer:s=(e,i)=>T(e.dataScope,t)-T(i.dataScope,t);break;case a.String:s=r?(e,i)=>r.indexOf(k(e.dataScope,t))-r.indexOf(k(i.dataScope,t)):(e,i)=>k(e.dataScope,t)<k(i.dataScope,t)?-1:1}}e.children.sort(s),i&&e.children.reverse()}(e,t,i,r):function(e,t,i){let r;switch(t){case"x":case"y":case"width":case"height":r=(e,i)=>e.bounds[t]-i.bounds[t];break;default:r=(e,i)=>e[t]-i[t]}e._children.sort(r),i&&e.children.reverse()}(e,t,i);e._sortBy={property:t,descending:i,vals:r}}(e,t,i,r),s.onChange(xe.PROPERTY,ze.CHILDREN_ORDER,e);else if(e instanceof vt){let s=we(e);for(let e of s)jl(e,t,i,r)}}function jl(e,t,i,r){e.vertices[0].dataScope&&v(e.vertices[0].dataScope).has(t)?function(e,t,i,r){let s;if(t===M)s=(e,i)=>parseInt(k(e.dataScope,t).substring(1))-parseInt(k(i.dataScope,t).substring(1));else{switch(v(e.vertices[0].dataScope).type(t)){case a.Date:break;case a.Number:case a.Integer:s=(e,i)=>T(e.dataScope,t)-T(i.dataScope,t);break;case a.String:s=r?(e,i)=>r.indexOf(k(e.dataScope,t))-r.indexOf(k(i.dataScope,t)):(e,i)=>k(e.dataScope,t)<k(i.dataScope,t)?-1:1}}e.vertices.sort(s),i&&e.vertices.reverse()}(e,t,i,r):function(e,t,i){let r=(e,i)=>e[t]-i[t];e.vertices.sort(r),i&&e.vertices.reverse()}(e,t,i),e._sortBy={property:t,descending:i,vals:r}}class Wl{constructor(){this._vals={},this._vals.elements=[]}set(e,t){this._vals[e]=t}get(e){return this._vals[e]}clear(){this._vals={},this._vals.elements=[]}}class Yl{constructor(e,t,i,r){this._respCompnt=t.object,this._respProps=t.properties||t.channels,this._responderEval=i,this._efxFn=r,this._evtCtx=e,this._evalResult={},this._responderPeers=void 0}get responderComponent(){return this._respCompnt}getResponderPeers(){if(!this._responderPeers){let e=Array.isArray(this._respCompnt)?this._respCompnt:[this._respCompnt];this._responderPeers=e.map(e=>we(e)).flat()}return this._responderPeers}clearResponderPeers(){this._responderPeers=void 0}get responderProperties(){return this._respProps}get eventContext(){return this._evtCtx}get evalResult(){return this._evalResult}set evalResult(e){this._evalResult=e}get evalFunction(){return this._responderEval}get stylingFunction(){return this._efxFn}}class Ul{constructor(e,t,i,r){this._id=e,this._event=i,this._source=t,this._evtCtx=new Wl,this._cumulative=r}get id(){return this._id}get event(){return this._event}get eventContext(){return this._evtCtx}get source(){return this._source}isCumulative(){return this._cumulative}isMouseDriven(){return["brush","brushX","brushY","click","hover"].includes(this._event)}isKeyboardDriven(){return["keydown","keyup"].includes(this._event)}isWidgetDriven(){return["change","input"].includes(this._event)}isStateDriven(){return null!==this._source&&"object"==typeof this._source&&"stateVar"===this._source.type}}function Hl(e,t,i,r,s){const n=Ie(t.object);!function(e,t,i,r,s){if(!("event"in e)||!("source"in e))throw"Source and event must be specified in the trigger";if(!("object"in t))throw"Responder object must be specified";if(Array.isArray(r)){if(!r.every(e=>"function"==typeof e))throw"Updater must be a function";if(s&&!Array.isArray(s))throw"An array of effect setters must be accompanied by an array of animation effects";if(s&&Array.isArray(s)&&s.length!==r.length)throw"the length of effect setters is not equal to the length of animation effects"}else if("function"!=typeof r)throw"Updater must be a function"}(e,t,0,r,s);let a=e.event,o=function(e){return["string"==typeof e.source?e.source:Array.isArray(e.source)?e.source.map(e=>e.classId||e.id).join("_"):"stateVar"===e.source.type?"state:"+e.source.key:e.source.classId?e.source.classId:e.source.id,e.event].join("-")}(e);a=0===a.indexOf("brush")?"brush":0===a.indexOf("drag")?"drag":a,a in n._triggers||(n._triggers[a]={}),o in n._triggers[a]||(n._triggers[a][o]=new Ul(o,e.source,e.event,e.cumulative));let l=n._triggers[a][o].eventContext,h=new Yl(l,t,i,r);return o in n._condEncodings||(n._condEncodings[o]=[]),n._condEncodings[o].push(h),function(e,t,i,r,s){let n=t.responderComponent,a=s&&s.source&&"stateVar"===s.source.type?r.getVariable(xe.STATE,s.source.key,s.source.stateContext):r.getVariable(xe.EVT_CTX,e),o=i.properties?i.properties:i.channels;if(t.evalFunction){let e=r.getVariable(xe.CONDITION_RESULT,t),i=r.findIncomingDataflowOperator(me.TARGET_EVALUATOR,e);i||(i=r.createOneWayDependency(me.TARGET_EVALUATOR,t.evalFunction)),r.connect(a,i),r.connect(i,e);for(let t of o){let i=Array.isArray(n)?n:[n];for(let s of i){let i=r.getVariable(xe.CHANNEL,t,s),n=i.incomingDataflow;if(n&&n.type===me.ENCODER&&n.outputVar.channel===t)r.connect(e,n);else if(!n){let n=r.createOneWayDependency(me.ENCODER);r.connect(e,n),r.connect(n,i),n.storeValues(s,t)}}}}else{let e=r.createOneWayDependency(me.TARGET_UPDATER,t.stylingFunction,n);for(let t of o){let i;i=n instanceof ve?r.getVariable(xe.STATE,t,n):Object.values(De).includes(t)?r.getVariable(xe.CHANNEL,t,n):r.getVariable(xe.PROPERTY,Me(t),n),r.connect(a,e),r.connect(e,i)}}}(l,h,t,n._depGraph,e),n._triggers[a][o]}function Xl(e,t){let i=t||{};switch(e.toLowerCase()){case fe.STACK:return new Xa(i);case fe.PACKING:return new Ha(i);case fe.FORCE:return new Ua(i);case fe.DIRECTED:return new Ya(i);case fe.TIDYTREE:return new Ka(i);case fe.TREEMAP:return new Za(i);case fe.CIRCULAR:return new Cl(i);case fe.CLUSTER:return new Al(i);case fe.GRID:default:return new Si(i)}}function ql(e,t,i){switch(e){case"kde":return new Ga(t);case"filter":return new za(t);case"custom":return new Fa(t,i);default:return new Ma(t)}}function Kl(e){return new ja(e)}function Zl(e){return new V(e,"")}async function $l(t){return async function(t){let i=await U("GET",t),r=e.csvParse(i.trim(),e.autoType);return new V(r,t)}(t)}function Jl(t){return function(t){let i=e.csvParse(t.trim(),e.autoType);return new V(i,"fromString")}(t)}async function Ql(e){return async function(e){let t=await U("GET",e);return new F(JSON.parse(t),e)}(e)}async function eh(e){return async function(e){let t=await U("GET",e);return new G(JSON.parse(t),e)}(e)}function th(e,t){return new _l(t)}function ih(e){return _o(e)}function rh(e){return to(e)}function sh(e,t){return function(e,t){return e.fillColor!==t.fillColor?(console.log("fillColor not equal:",e,t),!1):El(e,t)}(e,t)}const nh=M;export{nh as ROW_ID,Hl as activate,Ml as affix,Gl as align,Pl as attach,Tl as canClassify,$i as canDensify,kl as canDivide,Ai as canRepeat,wo as childHitTest,Eo as childrenHitTestByRect,Rl as classify,zl as connect,xo as contains,$l as csv,Jl as csvString,Ki as densify,rh as deserialize,Sl as divide,mi as encode,ke as findElements,ni as getChannelEncodingByAttribute,ai as getChannelEncodingByElement,si as getEncodingsByChannel,ri as getEncodingsByElement,Le as getLeafMarks,we as getPeers,Ql as graphJSON,di as isDataBound,ci as isDataBoundHorizontally,hi as isDataBoundVertically,sh as isEqual,de as isMark,at as isRefElement,Xl as layout,vo as markHitTest,Co as markPrimitiveHitTest,Ao as markPrimitiveHitTestByRect,ii as removeEncoding,th as renderer,Ei as repeat,dr as repopulate,Kl as scene,ih as serialize,Fl as sortChildren,Ol as stratify,Zl as table,ql as transform,fi as translate,eh as treeJSON,Ji as update};
1
+ // version: 4.4.0
2
+ import*as e from"d3";const t=Object.freeze({Rect:"rect",Circle:"circle",Line:"line",Ring:"ring",Path:"path",Image:"image",Symbol:"symbol",SimpleText:"text",RichText:"richText",Arc:"arc",BezierCurve:"bezierCurve",BundledPath:"bundledPath",Chord:"chord",Arrow:"arrow"}),i=Object.freeze({Area:"area",Rect:"rect",Ellipse:"ellipse",Circle:"circle",Pie:"pie",Ring:"ring",Arc:"arc",BezierCurve:"bezierCurve",BundledPath:"bundledPath",Chord:"chord",Line:"line",Path:"path",Image:"image",Symbol:"symbol",SimpleText:"text",RichText:"richText",Collection:"collection",Group:"group",Composite:"composite",Scene:"scene",Axis:"axis",Glyph:"glyph",Legend:"legend",Polygon:"polygon",Gridlines:"gridlines",Trajectory:"trajectory",LinearGradient:"LinearGradient",PathGradient:"PathGradient",Link:"link",DataTable:"datatable",Layout:"layout",NetworkData:"networkdata",TreeData:"treedata",Arrow:"arrow"}),r=Object.freeze({Axis:"axis",Legend:"legend",Gridlines:"gridlines",Trajectory:"trajectory"});function s(){return Date.now().toString(36)+"_"+Math.random().toString(36).slice(2)}function n(e,t){if(t.has(e))return!0;if(t.tree&&t.tree.nodeTable.has(e.split(".")[1]))return!0;throw new Error(["Attribute",e,"does not exist in the table",t.name].join(" "))}const a=Object.freeze({Boolean:"boolean",Integer:"integer",Number:"number",Date:"date",String:"string"});function o(e){var t=Object.values(a);for(let i=0;i<e.length;i++){let r=e[i];if(null!=r){for(let e=0;e<t.length;e++)l[t[e]](r)||(t.splice(e,1),e-=1);if(1==t.length)return t[0]}}return t[0]}const l={boolean:function(e){return"true"===e||"false"===e||!0===e||!1===e||"[object Boolean]"==toString.call(e)},integer:function(e){return l.number(e)&&(e=+e)===~~e},number:function(e){return!isNaN(+e)&&"[object Date]"!=toString.call(e)},date:function(e){let t=new Date(e);return null!=t&&!isNaN(t)},string:function(e){return!0}};function h(t,i){let r={};switch(i){case a.Boolean:r.trueCount=t.filter(e=>e).length,r.falseCount=t.filter(e=>!e).length;break;case a.Date:r.min=e.min(t),r.max=e.max(t),r.extent=[r.min,r.max],r.unique=[...new Set(t)];break;case a.String:r.unique=[...new Set(t)];break;default:r.min=e.min(t),r.max=e.max(t),r.extent=[r.min,r.max],r.mean=e.mean(t),r.median=e.median(t),r.unique=[...new Set(t)]}return r}const c="max",d="min",u="avg",_="mean",p="median",f="count",g="percentile 25",y="percentile 75";function m(e,t={},i){return{dataTable:e,filters:Object.assign({},t),rowIds:i?i.slice():void 0}}function b(e){if(e)return m(e.dataTable,e.filters,e.rowIds)}function x(e){return b(e)}function v(e){if(e)return e.dataTable}function w(e){return e&&e.filters||{}}function E(e){return e?e.rowIds&&e.dataTable?e.dataTable.rows({[D]:e.rowIds}):e.dataTable?e.dataTable.rows(e.filters):[]:[]}function A(e){let t=E(e);return t.length>0?t[0]:{}}function C(e){return E(e).length}function S(e,t){return t in w(e)}function R(e,t){let i=w(e);if(t in i)return i[t];let r=E(e);return r.length>0?r[0][t]:void 0}function k(e,t){let i=w(e);return t in i?[i[t]]:Array.from(new Set(E(e).map(e=>e[t])))}function T(t,i,r){let s=E(t).map(e=>e[i]);switch(r){case c:return e.max(s);case d:return e.min(s);case u:case _:return e.mean(s);case p:return e.median(s);case f:return s.length;case g:return e.quantile(s,.25);case y:return e.quantile(s,.75);default:return e.sum(s)}}function O(e,t,i){let r=v(e),s=Object.assign({},w(e),{[t]:i});return m(r,s,P(r,s))}function I(e,t){if(!e)return x(t);if(!t)return x(e);let i=v(e),r=Object.assign({},w(e));for(let[e,i]of Object.entries(w(t)))e in r&&r[e]!==i?console.warn("Conflict in attribute values when merging dataScope:",e,r[e],i):r[e]=i;return m(i,r,P(i,r))}function N(e){return m(e,{},e.data.map(e=>e[D]))}function L(e,t,i=!1){let r=v(e),s=w(e),n=Object.entries(s).filter(([e])=>e!==t),a=r._attrValueIndexes.get(t),o=[];for(let e of r.unique(t)){let l=a&&a.get(e)?a.get(e):[];n.length>0&&(l=l.filter(e=>n.every(([t,i])=>e[t]==i))),(i||0!==l.length)&&o.push(m(r,Object.assign({},s,{[t]:e}),l.map(e=>e[D])))}return o}function P(e,t){return e.rows(t).map(e=>e[D])}class V{constructor(e,t,r){this._id=i.DataTable+s(),this.initialize(e,t,r)}initialize(e,t,i){if(this.url=t,this._rawData=JSON.parse(JSON.stringify(e)),this._data=e,this._dataScopeCache=new Map,this._scopeTupleCache=new Map,this._attrValueIndexes=new Map,this._rowIdIndex=new Map,this._dateMap=new Map,this._attributes=0===this._data.length?[]:Object.keys(this._data[0]),this._newAttribute=0,i)this._attrTypes=i;else{this._attrTypes={};for(let e of this._attributes)this._attrTypes[e]=o(this.data.map(t=>t[e])),"year"==e.toLowerCase()&&this._attrTypes[e]==a.Integer&&(this._attrTypes[e]=a.Date)}this._validate(this.data,this._attrTypes),this._attrSummaries={};for(let e of this._attributes)this._attrSummaries[e]=h(this.data.map(t=>t[e]),this._attrTypes[e]);this._attributes.indexOf(D)<0&&this.addAttr(D,a.String,this.data.map((e,t)=>"r"+t)),this._buildAttributeValueIndexes()}clone(){let e=[];for(let t of this._data)e.push(Object.assign({},t));let t=new V(e,this.url,Object.assign({},this._attrTypes));return t.sourceDataTable=this,t}get id(){return this._id}get name(){return this.url?function(e){var t=e.indexOf("\\")>=0?e.lastIndexOf("\\"):e.lastIndexOf("/"),i=e.substring(t);0!==i.indexOf("\\")&&0!==i.indexOf("/")||(i=i.substring(1));return i}(this.url):this.id}get data(){return this._data}encodable(e){switch(e){case"x":case"y":case"width":case"height":case"radius":case"fillColor":case"strokeColor":case"text":return this.measures.concat(this.dimensions);default:return this.measures}}addAttr(e,t,i){this._data.forEach((t,r)=>t[e]=i[r]),e!==D&&this._rawData.forEach((t,r)=>t[e]=i[r]),this._attrTypes[e]=t,this._attributes.includes(e)||this._attributes.push(e),this._attrSummaries[e]=h(i,t),this._clearDataCaches()}type(e){return this._attrTypes[e]}summary(e){return this._attrSummaries[e]}values(e){return this.data.map(t=>t[e])}unique(e){return this._attrSummaries[e].unique}order(e,t){this._attrSummaries[e].unique=t}load(e){this._data=e,this._clearDataCaches(),this.summarize()}rows(e={}){let t=this._getFilterKey(e);if(this._scopeTupleCache.has(t))return this._scopeTupleCache.get(t);let i=Object.entries(e);if(0===i.length)return this._scopeTupleCache.set(t,this.data),this.data;if(1===i.length&&i[0][0]===D&&Array.isArray(i[0][1])){let e=i[0][1].map(e=>this._rowIdIndex.get(e)).filter(e=>e);return this._scopeTupleCache.set(t,e),e}let r=this.data;for(let[e,t]of i){if(Array.isArray(t)||M(t))continue;let i=this._getRowsByAttributeValue(e,t);i&&i.length<r.length&&(r=i)}let s=r.filter(e=>i.every(([t,i])=>{if(M(i)){let r=e[t];return(!("min"in i)||r>=i.min)&&(!("max"in i)||r<=i.max)}return Array.isArray(i)?i.includes(e[t]):e[t]==i}));return this._scopeTupleCache.set(t,s),s}_getRowsByAttributeValue(e,t){let i=this._attrValueIndexes.get(e);return i?i.get(t):void 0}_buildAttributeValueIndexes(){this._attrValueIndexes=new Map,this._rowIdIndex=new Map;for(let e of this._attributes){let t=new Map;for(let i of this.data){let r=i[e];t.has(r)||t.set(r,[]),t.get(r).push(i)}this._attrValueIndexes.set(e,t)}for(let e of this.data)this._rowIdIndex.set(e[D],e)}_getFilterKey(e={}){return Object.entries(e).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>M(t)?e+":["+(t.min??"-inf")+","+(t.max??"+inf")+"]":e+":"+JSON.stringify(t)).join("|")}_clearDataCaches(){this._dataScopeCache&&this._dataScopeCache.clear(),this._scopeTupleCache&&this._scopeTupleCache.clear(),this._attrValueIndexes&&(this._attrValueIndexes.clear(),this._buildAttributeValueIndexes())}count(){return this.data.length}has(e){return this._attributes.indexOf(e)>=0}parseDate(t,i){let r=e.timeParse(i);for(let e of this.data){let i=e[t];null==i||null==i?(i="",e[t]=new Date(1899,11,31).getTime()):e[t]=r(i).getTime(),this._dateMap.set(e[t],i)}this._attrTypes[t]=a.Date,this._attrSummaries[t]=h(this.data.map(e=>e[t]),a.Date),this._clearDataCaches()}raw(e,t){return this.type(e)===a.Date?this._dateMap.get(t).toString():t}get dimensions(){let e=[];for(let t in this._attrTypes)this._attrTypes[t]!=a.Number&&this._attrTypes[t]!=a.Integer&&t!=V.RowID&&e.push(t);return e.sort((e,t)=>this.unique(e).length-this.unique(t).length),e}get measures(){let e=[];for(let t in this._attrTypes)this._attrTypes[t]!==a.Number&&this._attrTypes[t]!==a.Integer||t==V.RowID||e.push(t);return e}attrs(e){if(void 0===e)return this._attributes;let t=[];for(let i in this._attrTypes)this._attrTypes[i]===e&&i!=V.RowID&&t.push(i);return t}summarize(){for(let e of this._attributes)this._attrSummaries[e]=h(this.data.map(t=>t[e]),this._attrTypes[e])}_validate(e,t){for(let i of e)for(let e in t){let r,s=t[e],n=i[e];if(null==i[e]||null==i[e])switch(s){case a.Boolean:r=!1;break;case a.Date:r=new Date(1899,11,31).getTime();break;case a.String:r="";break;default:r=0}else switch(s){case a.Boolean:r=n;break;case a.Date:r=Number.isInteger(n)&&n<=9999?new Date(n,0).getTime():Number.isInteger(n)?n:new Date(n+"").getTime(),this._dateMap.set(r,n);break;case a.String:r=n.toString();break;default:r=n}i[e]=r}}}function M(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)&&("min"in e||"max"in e)}function B(e){return e.dataScope?v(e.dataScope):e.parent&&e.parent.dataScope?v(e.parent.dataScope):void 0}const D="mascot_rowId";class G{constructor(e,t){this._id=i.TreeData+s(),this.initialize(e,t)}initialize(e,t){this.url=t,this._data=e,this._nodeList=[],this._linkList=[],this._nodeHash={},this._traverse(e,this._nodeList,this._linkList),this._nodeTable=new V(this._nodeList,"nodes"),this._linkTable=new V(this._linkList,"links"),this._nodeTable.tree=this,this._linkTable.tree=this}get nodeTable(){return this._nodeTable}get linkTable(){return this._linkTable}_traverse(e,t,i,r=0){let s={};U in e||(e[U]="n"+t.length),t.push(s),e._depth=r;for(let n in e)if("children"==n&&e[n]&&e[n].length>0)for(let s of e[n]){let n=this._traverse(s,t,i,r+1);i.push({parent:e[U],child:n})}else s[n]=e[n];return this._nodeHash[s[U]]=s,s[U]}getNodeDataScopeRef(e){return O(N(this._nodeTable),D,e[D])}getNode(e){return this._nodeHash[e]}getRoot(){return this._nodeTable.data[0]}getChildren(e){let t=e[U],i=[],r=this._linkTable.data,s=this._nodeTable.data;for(let e in r)if(r[e].parent==t){let t=r[e].child,n=s.findIndex(e=>e[U]==t);i.push(s[n])}return i}getParent(e){let t=e[U],i=this._linkTable.data,r=this._nodeTable.data;for(let e in i)if(i[e].child==t){let t=i[e].parent,s=r.findIndex(e=>e[U]==t);return r[s]}}}function z(e){return v(e.dataScope).tree}class j{constructor(e,t){this._id=i.NetworkData+s(),this.initialize(e,t)}initialize(e,t){this.url=t,this._nodeTable=new V(e.nodes,this._id+"_nodes"),this._linkTable=new V(e.links,this._id+"_links"),this._nodeTable.graph=this,this._linkTable.graph=this,this._rawNodes=e.nodes,this._rawLinks=e.links,this._nodeHash={};for(let t of e.nodes)this._nodeHash[t[U]]=t}get nodeTable(){return this._nodeTable}get linkTable(){return this._linkTable}get nodeList(){return this._rawNodes}get linkList(){return this._rawLinks}getNode(e){return this._nodeHash[e]}getLinks(e){let t=e[U],i=this._rawLinks,r=[];for(let e in i)i[e].target!==t&&i[e].source!==t||r.push(i[e]);return r}buildNodeHierarchy(e){let t={};return t[U]="root",W(t,this._rawNodes,e),new G(t,this.url)}}function F(e){return v(e.dataScope).graph}function W(e,t,i){if(0===t.length||0===i.length)return;"children"in e||(e.children=[]);let r={};for(let e of t){let t=e[i[0]];t in r||(r[t]=[]),r[t].push(e)}if(1===i.length)for(let t in r){let i={children:r[t]};i[U]=t,e.children.push(i)}else for(let t in r){let s={};s[U]=t,e.children.push(s),W(s,r[t],i.slice(1))}}const U="id";function Y(e,t){return fetch(t,{method:e}).then(e=>e.ok?e.text():(console.log(e.status),Promise.reject({status:e.status,statusText:e.statusText}))).catch(e=>(console.log(e),Promise.reject({status:e.status,statusText:e.statusText})))}class H{constructor(e,t,i){this._id="predicate_"+s(),this._type=e||X.POINT,this._variableType=t,this._variableName=i,this._value=void 0}get type(){return this._type}get value(){return this._value}set value(e){this._value=e}get id(){return this._id}get variableType(){return this._variableType}get variableName(){return this._variableName}}const X=Object.freeze({POINT:"point",INTERVAL:"interval",LIST:"list"});class q extends H{constructor(e,t,i){super(e,t,i)}testElement(e){let t;if("attribute"==this._variableType){if(!e.dataScope)return!1;t=e.datum[this._variableName]}else t=e[this._variableName];return this._value[0]<=t&&this._value[1]>=t}testTuple(e){if("attribute"==this._variableType){let t=e[this._variableName];return this._value[0]<=t&&this._value[1]>=t}return!1}}class K extends H{constructor(e,t,i){super(e,t,i)}addValue(e){this._value||(this._value=[]),this._value.push(e)}resetValue(){this._value=void 0}testElement(e){if("attribute"==this._variableType){if(!e.dataScope)return!1;let t=Array.from(new Set(e.data.map(e=>e[this._variableName])));return 1===t.length&&this._value.indexOf(t[0])>=0}return this._value.indexOf(e[this._variableName])>=0}testTuple(e){if("attribute"==this._variableType){let t=e[this._variableName];return this._value.indexOf(t)>=0}return!1}}class Z extends H{constructor(e,t,i){super(e,t,i)}testElement(e){if("attribute"==this._variableType){if(!e.dataScope)return!1;return e.datum[this._variableName]==this._value}return e[this._variableName]==this._value}testTuple(e){if("attribute"==this._variableType){let t=e[this._variableName];return this._value===t}return!1}equals(e){return this.type===e.type&&this.variableName===e.variableName&&this.value===e.value}}function $(e){let t,i="attribute"in e?"attribute":"property",r=e[i];switch(e.type){case X.LIST:t=new K(e.type,i,r);break;case X.INTERVAL:t=new q(e.type,i,r);break;case X.POINT:default:t=new Z(e.type,i,r)}return t.value=e.value,t}function J(e,t){for(let i of t)if(!i.testElement(e))return!1;return!0}const Q={svg:void 0,getSVG:function(){return window?(void 0===this.svg&&(this.svg=document.createElementNS("http://www.w3.org/2000/svg","svg"),this.svg.style.visibility="hidden",this.svg.style.pointerEvents="none",this.svg.setAttribute("aria-hidden","true"),document.body.appendChild(this.svg)),this.svg):null}};function ee(e,t,i,r,s){const n=s*Math.PI/180,a=e-i,o=t-r;return{x:a*Math.cos(n)-o*Math.sin(n)+i,y:a*Math.sin(n)+o*Math.cos(n)+r}}function te(e,t,i,r){return Math.sqrt(Math.pow(e-i,2)+Math.pow(t-r,2))}function ie(e,t,i){const r=document.getElementById(e),s=r.createSVGPoint();s.x=t,s.y=i;const n=s.matrixTransform(r.getScreenCTM().inverse());return[n.x,n.y]}const re=Object.freeze({fillColor:"fill",strokeColor:"stroke",strokeWidth:"stroke-width",fillOpacity:"fill-opacity",strokeOpacity:"stroke-opacity",strokeDash:"stroke-dasharray",opacity:"opacity",fontSize:"font-size",fontFamily:"font-family",fontWeight:"font-weight",visibility:"visibility",cursor:"cursor"});class se{constructor(e,t,i,r){this._x=e+i/2,this._y=t+r/2,this._width=i,this._height=r}translate(e,t){this._x+=e,this._y+=t}toJSON(){let e={};return e.x=this._x,e.y=this._y,e.width=this._width,e.height=this._height,e}union(e){let t=d3.min([this.left,e.left]),i=d3.min([this.top,e.top]),r=d3.max([this.right,e.right]),s=d3.max([this.bottom,e.bottom]);return new se(t,i,r-t,s-i)}clone(){return new se(this.left,this.top,this._width,this._height)}get left(){return this._x-this._width/2}set left(e){this._x=e+this._width/2}get right(){return this._x+this._width/2}set right(e){this._x=e-this._width/2}get top(){return this._y-this._height/2}set top(e){this._y=e+this._height/2}get bottom(){return this._y+this._height/2}set bottom(e){this._y=e-this._height/2}get x(){return this._x}get y(){return this._y}get center(){return this.x}get middle(){return this.y}get width(){return this._width}setWidth(e,t){switch(t){case he.RIGHT:this._x=this.right-e/2;break;case he.CENTER:this._width=2*e;break;default:this._x=this.left+e/2}this._width=e}get height(){return this._height}setHeight(e,t){switch(t){case he.TOP:this._y=this.top+e/2;break;case he.MIDDLE:this._height=2*e;break;default:this._y=this.bottom-e/2}this._height=e}contains(e,t){return this.left<=e&&this.right>=e&&this.top<=t&&this.bottom>=t}intersects(e){return!(this.right<e.left||this.bottom<e.top||this.left>e.right||this.top>e.bottom)}}function ne(e){let t=e[0].clone();for(let i=1;i<e.length;i++)t=t.union(e[i]);return t}function ae(e){return ne(("vertex"==e[0].type||"segment"==e[0].type?e.map(e=>e.parent):e).map(e=>e.refBounds?e.refBounds:e.bounds))}function oe(e){return ne(("vertex"==e[0].type||"segment"==e[0].type?e.map(e=>e.parent):e).map(e=>e.bounds))}function le(e){let t=we(e);for(let e of t)e._updateBounds();let i=[];for(let e of t)e.parent&&!i.includes(e.parent)&&i.push(e.parent);for(let e of i)le(e)}const he=Object.freeze({TOP:"top",LEFT:"left",RIGHT:"right",BOTTOM:"bottom",CENTER:"center",MIDDLE:"middle"});class ce{constructor(e){if(this._dataScopeRef=void 0,this._type="type"in e?e.type:i.Mark,this._id=e.id?e.id:this._type+"_"+s(),this._classId=void 0,this._bounds=void 0,this._rotate=void 0,this._refBounds=void 0,this._dirty=!0,this._clipMask=void 0,this._cursor=void 0,this._styles={},void 0!==e)for(let t in re)t in e&&(this.styles[t]=e[t])}get scene(){return Ie(this)}get datum(){return A(this._dataScopeRef)}get data(){return E(this._dataScopeRef)}set strokeColor(e){this.styles.strokeColor!==e&&(this.styles.strokeColor=e,this._dirty=!0)}get strokeColor(){return this.styles.strokeColor}set strokeWidth(e){this.styles.strokeWidth!==e&&(this.styles.strokeWidth=e,this._dirty=!0)}get strokeWidth(){return this.styles.strokeWidth}get strokeDash(){return this.styles.strokeDash}set strokeDash(e){this.styles.strokeDash!==e&&(this.styles.strokeDash=e,this._dirty=!0)}set fillColor(e){this.styles.fillColor!==e&&(this.styles.fillColor=e,this._dirty=!0)}get fillColor(){return this.styles.fillColor}get rotation(){return this._rotate}get cursor(){return this._cursor}get id(){return this._id}set id(e){this.getScene()?(delete this.getScene()._itemMap[this._id],this._id=e,this.getScene()._itemMap[e]=this):this._id=e}get classId(){return this._classId?this._classId:this._id}set classId(e){this._classId=e}get type(){return this._type}get bounds(){return this._bounds||this._updateBounds(),this._bounds}get refBounds(){return this._refBounds?this._refBounds:this.bounds}set dataScope(e){this._dataScopeRef=b(e)}get dataScope(){return this._dataScopeRef}get styles(){return this._styles}set styles(e){this._styles!==e&&(this._styles=e,this._dirty=!0)}set visibility(e){this.styles.visibility!==e&&(this.styles.visibility=e,this._dirty=!0)}get visibility(){return this.styles.visibility?this.styles.visibility:"visible"}get opacity(){return"opacity"in this.styles?this.styles.opacity:1}set opacity(e){this.styles.opacity!==e&&(this.styles.opacity=e,this._dirty=!0)}get z(){return"z"in this.styles?this.styles.z:0}set z(e){this.styles.z!==e&&(this.styles.z=e,this._dirty=!0)}copyPropertiesTo(e){e.styles=Object.assign({},this.styles),this._dataScopeRef&&(e._dataScopeRef=x(this._dataScopeRef))}createClipMask(){let e=this._bounds;this._clipMask=new se(e.left,e.top,e.width,e.height)}get clipMask(){return this._clipMask}}function de(e){return e instanceof ce&&e.type!==i.Gridlines}const ue=Object.freeze({Area:"area",Rect:"rect",Ellipse:"ellipse",Circle:"circle",Pie:"pie",Ring:"ring",Arc:"arc",Line:"line",Path:"path",Image:"image",Symbol:"symbol",SimpleText:"text",RichText:"richText",Polygon:"polygon",BezierCurve:"bezierCurve",BundledPath:"bundledPath",Chord:"chord",Arrow:"arrow"});class _e{constructor(){this._refElements=[]}addRefElement(e){this._refElements.push(e)}get refElements(){return this._refElements}clearRefElements(){this._refElements=[]}}function pe(e){return e instanceof _e}const fe=Object.freeze({GRID:"grid",STACK:"stack",PACKING:"packing",FORCE:"force",DIRECTED:"directedgraph",TIDYTREE:"tidytree",TREEMAP:"treemap",STRATA:"strata",CIRCULAR:"circular",CLUSTER:"cluster",SPIRAL:"spiral",CUSTOM:"custom"});function ge(e,t){return!!(e.startsWith("h")&&[he.LEFT,he.CENTER,he.RIGHT].indexOf(t)>=0)||(!!(e.startsWith("v")&&[he.TOP,he.MIDDLE,he.BOTTOM].indexOf(t)>=0)||(console.warn("Invalid alignment:",t),!1))}class ye{constructor(e){this._id=e+"_"+s(),this._type=e,this._inputVars=[],this._outputVars=[]}run(){}get id(){return this._id}get type(){return this._type}get inputVars(){return this._inputVars}get outputVars(){return this._outputVars}get outputVar(){return this._outputVars[0]}isIsolated(){return 0==this._inputVars.length&&0==this._outputVars.length}}const me=Object.freeze({CONDUIT:"conduit",ENCODER:"encoder",LAYOUT:"layout",LINK_PLACER:"linkRouter",CONSTRAINT:"constraint",EVAL_BBOX:"evalBBox",EVAL_REFBOUNDS:"evalRefBounds",AFFIXER:"affixer",ALIGNER:"aligner",DATA_EXTRACTOR:"dataExtractor",SCALE_BUILDER:"scaleBuilder",AXIS_PATH_PLACER:"axisPathPlacer",AXIS_TICKS_PLACER:"axisTicksPlacer",AXIS_LABELS_PLACER:"axisLabelsPlacer",AXIS_TITLE_PLACER:"axisTitlePlacer",GRIDLINES_PLACER:"gridlinesPlacer",SPIRAL_TRAJECTORY_PLACER:"spiralTrajectoryPlacer",GRID_LAYOUT:"gridLayout",STACK_LAYOUT:"stackLayout",PACK_LAYOUT:"packLayout",FORCE_LAYOUT:"forceLayout",DIRECTED_LAYOUT:"directedLayout",TIDY_TREE_LAYOUT:"tidyTreeLayout",TREEMAP_LAYOUT:"treemapLayout",STRATA_LAYOUT:"strataLayout",CIRCULAR_LAYOUT:"circularLayout",CLUSTER_LAYOUT:"clusterLayout",SPIRAL_LAYOUT:"spiralLayout",CUSTOM_LAYOUT:"customLayout",BIN_TRANSFORMER:"binTransformer",FILTER_TRANSFORMER:"filterTransformer",KDE_TRANSFORMER:"kdeTransformer",CUSTOM_TRANSFORMER:"customTransformer",UNPIVOT_TRANSFORMER:"unpivotTransformer",REPOPULATE:"repopulate",TARGET_EVALUATOR:"targetEvaluator",TARGET_UPDATER:"targetUpdater"});class be{constructor(e){this._id="v_"+s(),this._type=e,this._incomings=[],this._outgoings=[],this._undirected=[]}get id(){return this._id}get incomingEdges(){return this._incomings}get outgoingEdges(){return this._outgoings}get undirectedEdges(){return this._undirected}get type(){return this._type}get incomingDataflow(){for(let e of this._incomings)if(e.fromNode&&e.fromNode instanceof ye)return e.fromNode;return null}isIsolated(){return 0==this._incomings.length&&0==this._outgoings.length}}const xe=Object.freeze({CHANNEL:"channel",PROPERTY:"property",STATE:"state",ATTRIBUTE:"attribute",ITEMS:"items",DATASCOPE:"datascope",ATTR_VALUE:"dataValue",BOUNDS:"bounds",SCALE:"scale",CONDITION_RESULT:"conditionResult",AFFIXATION:"affixation",ALIGNMENT:"alignment",EVT_CTX:"evtContext"});class ve extends Map{constructor(e){super(),this._scene=e}get scene(){return this._scene}var(e){if("string"!=typeof e||0===e.length)throw new Error("state.var(...) expects a non-empty variable name");return{type:"stateVar",key:e,stateContext:this}}set(e,t){const i=this.get(e);return super.set(e,t),i!==t&&(this._scene.depGraph.getVariable(xe.STATE,e,this),this._scene.onChange(xe.STATE,e,this)),this}}function we(e,t){let i=Ie(e);return"vertex"===e.type||"segment"===e.type?function(e,t){let i=Ie(e),r=t||i;if("vertex"===e.type){return Ee(e,Re(r,[{property:"classId",value:e.parent.classId}],!0))}if("segment"===e.type){return Se(e,Re(r,[{property:"classId",value:e.parent.classId}],!0))}return e.classId?Re(r,[{property:"classId",value:e.classId}]):[e]}(e,t):e.classId?Re(t||i,[{property:"classId",value:e.classId}]):[e]}function Ee(e,t){if(!e.classId){if(e.dataScope){let r=e.parent;if(!r)throw new Error("vertex has no parent mark");let s=[];if(r.type!==i.Area||e._isAnyVertex)for(let e of t)s=s.concat(e.vertices.filter(e=>e.dataScope));else{let i=r.vertices.indexOf(e)<r.vertices.length/2;for(let e of t){let t=i?e.vertices.slice(0,e.vertices.length/2):e.vertices.slice(e.vertices.length/2);s=s.concat(t.filter(e=>e.dataScope))}}return s}{let i=e.parent;if(!i)throw new Error("vertex has no parent mark");let r=i.vertices.indexOf(e),s=[];for(let e of t)s.push(e.vertices[r]);return s}}}function Ae(e,t){return e.id+"_v_"+e._vertices._ids[t]}function Ce(e,t){let r=e.parent,s=e._index,n=[];if(e.dataScope)if(r.type!==i.Area||e._isAnyVertex)for(let e of t){let t=[];for(let i=0;i<e._vertices.length;i++)e._vertices.hasDataScope(i)&&t.push(i);n.push({parent:e,indices:t})}else{let e=s<r._vertices.length/2;for(let i of t){let t=e?0:i._vertices.length/2,r=e?i._vertices.length/2:i._vertices.length,s=[];for(let e=t;e<r;e++)i._vertices.hasDataScope(e)&&s.push(e);n.push({parent:i,indices:s})}}else for(let e of t)n.push({parent:e,indices:[s]});return n}function Se(e,t){if(e._dataScopeRef){if(!e.parent)throw new Error("segment has no parent mark");let i=[];for(let e of t)i=i.concat(e.segments);return i}{let i=e.parent;if(!i)throw new Error("segment has no parent mark");let r=i.segments.indexOf(e),s=[];for(let e of t)s.push(e.segments[r]);return s}}function Re(e,t,i){let r=[];return Oe(e,t?t.map(e=>$(e)):[],r,i),r}function ke(e,t){let r=e.children.filter(e=>e.type==i.Collection);if(0!==r.length)for(let e of r){let i=e;for(;i&&i.dataScope;){if(S(i.dataScope,t))return i;i=i.children?i.children[0]:void 0}}}function Te(e){return e.type==i.Collection?e:e.parent?Te(e.parent):void 0}function Oe(e,t,i,r){if(e)if(J(e,t)&&i.push(e),e.vertices&&r)for(let r of e.vertices.concat(e.segments))J(r,t)&&i.push(r);else if(e.children&&e.children.length>0)for(let s of e.children)Oe(s,t,i,r)}function Ie(e){let t;if(t=Array.isArray(e)?e[0]:e,t){if(t instanceof ve)return t.scene;if(t._scene)return t._scene;for(pe(t)&&t.group&&(t=t.group),t.id.startsWith("encoding_")&&(t=t.element);t;){if(t.type==i.Scene)return t;t=t.parent}}}function Ne(e){let t=e;for("vertex"!=t.type&&"segment"!=t.type||(t=t.parent);t.parent&&[i.Collection,i.Glyph].includes(t.parent.type);)t=t.parent;return t}function Le(e,t){let i=[];if(Pe(e,i),t){let e={};for(let t of i)e[t.classId]=t;return Object.values(e)}return i}function Pe(e,t){if(de(e))t.push(e);else if(e.children&&!Object.values(r).includes(e.type))for(let i of e.children)Pe(i,t)}class Ve extends be{constructor(e,t,i){super(e),this._channel=t,this._elem=i}get channel(){return this._channel}get element(){return this._elem}}const Me=Object.freeze({X:"x",Y:"y",WIDTH:"width",HEIGHT:"height",RADIUS:"radius",FILLCOLOR:"fillColor",STROKECOLOR:"strokeColor",FILLGRADIENT:"fillGradient",STROKEGRADIENT:"strokeGradient",TEXT:"text",ANGLE:"angle",THICKNESS:"thickness",AREA:"area",FONTSIZE:"fontSize",POLARRADIUS:"polarRadius",POLARANGLE:"polarAngle",STROKEWIDTH:"strokeWidth",OPACITY:"opacity",VISIBILITY:"visibility",STRENGTH:"strength",SRC:"src",PATH:"path",Z:"z"});class Be extends be{constructor(e,t,i){super(e),this._property=t,this._elem=i}get property(){return this._property}get element(){return this._elem}}function De(e){return e in Ge?Ge[e]:e}const Ge=Object.freeze({numCols:"layoutParameter",numRows:"layoutParameter",startCorner:"layoutParameter",direction:"layoutParameter",params:"layoutParameter"}),ze=Object.freeze({AXIS_ORIENTATION:"axisOrientation",AXIS_PATH_POSITION:"axisPathPosition",AXIS_TICK_SIZE:"axisTickSize",AXIS_TICK_OFFSET:"axisTickOffset",AXIS_TICKS_POSITION:"axisTicksPosition",AXIS_LABELS_POSITION:"axisLabelsPosition",AXIS_TITLE_POSITION:"axisTitlePosition",AXIS_LABEL_OFFSET:"axisLabelOffset",AXIS_LABEL_FORMAT:"axisLabelFormat",AXIS_FONT_SIZE:"axisFontSize",LEGEND_POSITION:"legendPosition",GRIDLINES_POSITION:"gridlinesPosition",TRAJECTORY_POSITION:"trajectoryPosition",INCLUDE_ZERO:"includeZero",FLIP_SCALE:"flipScale",RANGE_START:"rangeStart",RANGE_EXTENT:"rangeExtent",BASE_LINE:"baseline",LAYOUT_PARAMETER:"layoutParameter",NUM_BINS:"numBins",CHILDREN_ORDER:"childrenOrder",ATTRIBUTE:"attribute"});class je{constructor(){this._vals={},this._vals.elements=[]}set(e,t){this._vals[e]=t}get(e){return this._vals[e]}clear(){this._vals={},this._vals.elements=[]}}class Fe{constructor(e,t,i,r){this._id=e,this._event=i,this._source=t,this._evtCtx=new je,this._cumulative=r}get id(){return this._id}get event(){return this._event}get eventContext(){return this._evtCtx}get source(){return this._source}isCumulative(){return this._cumulative}isMouseDriven(){return["brush","brushX","brushY","click","hover"].includes(this._event)}isKeyboardDriven(){return["keydown","keyup"].includes(this._event)}isWidgetDriven(){return["change","input"].includes(this._event)}isStateDriven(){return null!==this._source&&"object"==typeof this._source&&"stateVar"===this._source.type}}const We=Symbol("msc.TRIGGER_ELEMENT");function Ue(e){let t=e?Ie(e):void 0;t&&t._clearInteractionCaches&&t._clearInteractionCaches()}function Ye(e,t){if(Ue(e),t.findVariable(xe.BOUNDS,[e]))return;let r=t.getVariable(xe.BOUNDS,e),s=t.createOneWayDependency(me.EVAL_BBOX);switch(t.connect(s,r),e.type){case i.Circle:case i.Polygon:{let i=t.getVariable(xe.CHANNEL,"x",e),r=t.getVariable(xe.CHANNEL,"y",e),n=t.getVariable(xe.CHANNEL,"radius",e),a=t.getVariable(xe.CHANNEL,"area",e);t.connect(n,s),t.connect(i,s),t.connect(r,s),t.connect(a,s);break}case i.Area:case i.Line:case i.BezierCurve:case i.Path:case i.Image:case i.Symbol:{let i=t.getVariable(xe.CHANNEL,"x",e),r=t.getVariable(xe.CHANNEL,"y",e),n=t.getVariable(xe.CHANNEL,"width",e),a=t.getVariable(xe.CHANNEL,"height",e);t.connect(i,s),t.connect(r,s),t.connect(n,s),t.connect(a,s);break}case i.Rect:{let i=t.getVariable(xe.CHANNEL,"x",e),r=t.getVariable(xe.CHANNEL,"y",e),n=t.getVariable(xe.CHANNEL,"width",e),a=t.getVariable(xe.CHANNEL,"height",e),o=t.getVariable(xe.CHANNEL,"area",e);t.connect(i,s),t.connect(r,s),t.connect(n,s),t.connect(a,s),t.connect(o,s);break}case i.SimpleText:case i.RichText:{let i=t.getVariable(xe.CHANNEL,"x",e),r=t.getVariable(xe.CHANNEL,"y",e),n=t.getVariable(xe.CHANNEL,"text",e);t.connect(i,s),t.connect(r,s),t.connect(n,s);break}case i.Ring:{let i=t.getVariable(xe.CHANNEL,"x",e),r=t.getVariable(xe.CHANNEL,"y",e),n=t.getVariable(xe.CHANNEL,"innerRadius",e),a=t.getVariable(xe.CHANNEL,"outerRadius",e);t.connect(i,s),t.connect(r,s),t.connect(n,s),t.connect(a,s);break}case i.Pie:case i.Arc:{let i=t.getVariable(xe.CHANNEL,"x",e),r=t.getVariable(xe.CHANNEL,"y",e),n=t.getVariable(xe.CHANNEL,"innerRadius",e),a=t.getVariable(xe.CHANNEL,"outerRadius",e),o=t.getVariable(xe.CHANNEL,"startAngle",e),l=t.getVariable(xe.CHANNEL,"endAngle",e),h=t.getVariable(xe.CHANNEL,"angle",e),c=t.getVariable(xe.CHANNEL,"thickness",e);t.connect(i,s),t.connect(r,s),t.connect(n,s),t.connect(a,s),t.connect(o,s),t.connect(l,s),t.connect(h,s),t.connect(c,s);break}}s.run()}function He(e,t){Ue(e);let i=t.findVariablesByElement(e);for(let e in i){let r=i[e];for(let e of r)t.deleteVariable(e)}}function Xe(e,t){if(e.type===i.Axis){let i=t.findVariable(xe.PROPERTY,[ze.AXIS_PATH_POSITION,e]).incomingDataflow;console.log(i,e),t.deleteOperator(i),i=t.findVariable(xe.PROPERTY,[ze.AXIS_TICKS_POSITION,e]).incomingDataflow,t.deleteOperator(i),i=t.findVariable(xe.PROPERTY,[ze.AXIS_LABELS_POSITION,e]).incomingDataflow,t.deleteOperator(i),i=t.findVariable(xe.PROPERTY,[ze.AXIS_TITLE_POSITION,e]).incomingDataflow,t.deleteOperator(i)}else if(e.type===i.Gridlines){let i=t.findVariable(xe.PROPERTY,[ze.GRIDLINES_POSITION,e]).incomingDataflow;t.deleteOperator(i)}}function qe(e,t){if(Ue(e),t.findVariable(xe.BOUNDS,[e]))return;let i=t.getVariable(xe.BOUNDS,e),r=t.getVariable(xe.CHANNEL,"x",e),s=t.getVariable(xe.CHANNEL,"y",e),n=t.getVariable(xe.CHANNEL,"width",e),a=t.getVariable(xe.CHANNEL,"height",e),o=t.createOneWayDependency(me.EVAL_BBOX);t.connect(r,o),t.connect(s,o),t.connect(n,o),t.connect(a,o),t.connect(o,i),o.run()}function Ke(e,t){Ue(e);let i=t.getVariable(xe.BOUNDS,e),r=t.getVariable(xe.CHANNEL,"x",e),s=t.getVariable(xe.CHANNEL,"y",e),n=t.getVariable(xe.CHANNEL,"width",e),a=t.getVariable(xe.CHANNEL,"height",e),o=t.createOneWayDependency(me.EVAL_BBOX);t.connect(r,o),t.connect(s,o),t.connect(n,o),t.connect(a,o),t.connect(o,i),o.run()}function Ze(e,t,i){Ue(e);let r=i.getVariable(xe.BOUNDS,e),s=i.getVariable(xe.BOUNDS,t),n=i.getIncomingDataflowOperator(me.EVAL_BBOX,r),a=s.outgoingEdges.find(e=>e.fromNode===s&&e.toNode===n);if(a&&i.disconnect(s,n,a),e.layout){let r=i.getVariable(xe.CHANNEL,"x",t),s=i.getIncomingDataflowOperator(Qe(e.layout.type),r);s&&i.deleteOperator(s)}}function $e(e,t,i){Ue(e);let r=i.getVariable(xe.BOUNDS,e),s=i.getVariable(xe.BOUNDS,t),n=i.getIncomingDataflowOperator(me.EVAL_BBOX,r);i.connect(s,n),i.connect(n,r),e.layout&&tt(e,e.layout,i)}function Je(e,t){Ue(e);let i=t.getVariable(xe.BOUNDS,e),r=t.getVariable(xe.CHANNEL,"x",e),s=t.getVariable(xe.CHANNEL,"y",e),n=t.getIncomingDataflowOperator(me.EVAL_BBOX,i);t.connect(r,n),t.connect(s,n);for(let i of e.children)t.connect(t.getVariable(xe.BOUNDS,i),n);t.connect(n,i),n.run()}function Qe(e){switch(e){case fe.GRID:return me.GRID_LAYOUT;case fe.STACK:return me.STACK_LAYOUT;case fe.PACKING:return me.PACK_LAYOUT;case fe.FORCE:return me.FORCE_LAYOUT;case fe.DIRECTED:return me.DIRECTED_LAYOUT;case fe.TIDYTREE:return me.TIDY_TREE_LAYOUT;case fe.TREEMAP:return me.TREEMAP_LAYOUT;case fe.STRATA:return me.STRATA_LAYOUT;case fe.CIRCULAR:return me.CIRCULAR_LAYOUT;case fe.CLUSTER:return me.CLUSTER_LAYOUT;case fe.SPIRAL:return me.SPIRAL_LAYOUT;case fe.CUSTOM:return me.CUSTOM_LAYOUT}}function et(e,t,i){let r=i.getVariable(xe.PROPERTY,ze.CHILDREN_ORDER,e),s=i.getOutgoingDataflowOperator(Qe(t.type),r);i.deleteOperator(s)}function tt(e,t,r){let s=t?t.type:"none",n=s===fe.TREEMAP?Le(e)[0]:e.children[0];if(!n)return;let a=r.getVariable(xe.CHANNEL,"width",n),o=r.getVariable(xe.CHANNEL,"height",n),l=r.getVariable(xe.PROPERTY,ze.CHILDREN_ORDER,e),h=r.getVariable(xe.CHANNEL,"x",n),c=r.getVariable(xe.CHANNEL,"y",n),d=r.getVariable(xe.CHANNEL,"visibility",n),u=r.getVariable(xe.PROPERTY,ze.LAYOUT_PARAMETER,t),_=r.getOutgoingDataflowOperator(Qe(s),l);if(r.connect(a,_),r.connect(o,_),r.connect(l,_),r.connect(u,_),r.connect(d,_),r.connect(_,h),r.connect(_,c),r.disconnectChannelVarFromBBoxOperator(a),r.disconnectChannelVarFromBBoxOperator(o),n.type===i.Arc||n.type===i.Pie){let e=r.getVariable(xe.CHANNEL,"angle",n),t=r.getVariable(xe.CHANNEL,"thickness",n);r.connect(e,_),r.connect(t,_)}else if(n.type===i.Circle){let e=r.getVariable(xe.CHANNEL,"area",n),t=r.getVariable(xe.CHANNEL,"radius",n);r.connect(e,_),r.connect(t,_),r.disconnectChannelVarFromBBoxOperator(e),r.disconnectChannelVarFromBBoxOperator(t)}else if(n.type===i.Rect){let e=r.getVariable(xe.CHANNEL,"area",n);r.connect(e,_),r.disconnectChannelVarFromBBoxOperator(e)}if(_.run(),n.links&&it(n,r),n.children&&n.children[0]){let e=r.getVariable(xe.BOUNDS,n.children[0]),t=r.getVariable(xe.CHANNEL,"x",n).incomingDataflow;t&&r.connect(e,t),r.disconnectChannelVarFromBBoxOperator(e)}}function it(e,t){let i=e.links[0],r=t.getVariable(xe.CHANNEL,"x",e),s=t.getVariable(xe.CHANNEL,"x",i),n=t.getVariable(xe.CHANNEL,"strokeWidth",i),a=t.getVariable(xe.CHANNEL,"strength",i),o=t.createOneWayDependency(me.LINK_PLACER);t.connect(r,o),t.connect(n,o),t.connect(a,o),t.connect(o,s)}function rt(e,t,i){if(!e||"segment"!==e.type)return;let r=B(e),s=r?i.findVariable(xe.ITEMS,[r]):null;if(s)for(let e of s.outgoingEdges)if(e.isDirected&&e.toNode.type===me.REPOPULATE)return void i.connect(e.toNode,t)}function st(e,t,r){let s=e.attribute,n=e.channel,a=e.element,o=t.createOneWayDependency(me.ENCODER);if(["width","height"].includes(e.channel)&&a.type===i.Area){let e=t.getVariable(xe.PROPERTY,ze.BASE_LINE,a);t.connect(e,o)}if(r){let i=t.getVariable(xe.ATTR_VALUE,r),s=t.getVariable(xe.SCALE,r),l=t.getVariable(xe.CHANNEL,n,a);t.connect(s,o),t.connect(o,l),i.addLinkedEncoding(e),s.addLinkedEncoding(e);let h=t.getVariable(xe.DATASCOPE,e.element),c=i.incomingDataflow;c&&h&&(t.connect(h,c),rt(e.element,h,t)),i.incomingDataflow.run()}else{let i=t.getVariable(xe.ATTRIBUTE,s,B(a),e),r=t.getVariable(xe.PROPERTY,ze.INCLUDE_ZERO,e),l=t.getVariable(xe.ATTR_VALUE,e),h=t.getVariable(xe.DATASCOPE,a),c=t.createOneWayDependency(me.DATA_EXTRACTOR);t.connect(i,c),t.connect(r,c),t.connect(h,c),t.connect(c,l),rt(a,h,t),c.run();let d=t.getVariable(xe.PROPERTY,ze.RANGE_START,e),u=t.getVariable(xe.PROPERTY,ze.RANGE_EXTENT,e),_=t.getVariable(xe.PROPERTY,ze.FLIP_SCALE,e),p=t.getVariable(xe.SCALE,e),f=t.createOneWayDependency(me.SCALE_BUILDER);t.connect(d,f),t.connect(u,f),t.connect(_,f),t.connect(l,f),t.connect(f,p),f.run();let g=t.getVariable(xe.CHANNEL,n,a);t.connect(p,o),t.connect(o,g),o.run()}}function nt(e,t){let i=t.getVariable(xe.PROPERTY,ze.AXIS_ORIENTATION,e),r=t.getVariable(xe.BOUNDS,e.elements[0].parent),s=t.getVariable(xe.PROPERTY,ze.AXIS_PATH_POSITION,e),n=t.createOneWayDependency(me.AXIS_PATH_PLACER);t.connect(i,n),t.connect(r,n),t.connect(n,s),n.run();let a=t.getVariable(xe.PROPERTY,ze.AXIS_TICK_OFFSET,e),o=t.getVariable(xe.PROPERTY,ze.AXIS_TICK_SIZE,e),l=t.createOneWayDependency(me.AXIS_TICKS_PLACER),h=t.getVariable(xe.PROPERTY,ze.AXIS_TICKS_POSITION,e);t.connect(s,l),t.connect(a,l),t.connect(o,l),t.connect(l,h),l.run();let c=t.getVariable(xe.PROPERTY,ze.AXIS_LABEL_OFFSET,e),d=t.getVariable(xe.PROPERTY,ze.AXIS_LABEL_FORMAT,e),u=t.getVariable(xe.PROPERTY,ze.AXIS_FONT_SIZE,e),_=t.createOneWayDependency(me.AXIS_LABELS_PLACER),p=t.getVariable(xe.PROPERTY,ze.AXIS_LABELS_POSITION,e);t.connect(s,_),t.connect(c,_),t.connect(d,_),t.connect(u,_),t.connect(_,p),_.run();let f=t.getVariable(xe.PROPERTY,ze.AXIS_TITLE_POSITION,e),g=t.createOneWayDependency(me.AXIS_TITLE_PLACER);t.connect(s,g),t.connect(g,f),g.run();let y=t.getVariable(xe.BOUNDS,e),m=t.getIncomingDataflowOperator(me.EVAL_BBOX,y);t.connect(h,m),t.connect(p,m),t.connect(m,y)}function at(e,t){let i=t.getVariable(xe.PROPERTY,ze.AXIS_ORIENTATION,e),r=t.getVariable(xe.BOUNDS,Ne(e.elements[0])),s=t.getVariable(xe.PROPERTY,ze.AXIS_PATH_POSITION,e),n=t.createOneWayDependency(me.AXIS_PATH_PLACER);t.connect(i,n),t.connect(r,n),t.connect(n,s),n.run();let a=t.getVariable(xe.PROPERTY,ze.AXIS_TICK_OFFSET,e),o=t.getVariable(xe.PROPERTY,ze.AXIS_TICK_SIZE,e),l=t.createOneWayDependency(me.AXIS_TICKS_PLACER),h=t.getVariable(xe.PROPERTY,ze.AXIS_TICKS_POSITION,e);t.connect(s,l),t.connect(a,l),t.connect(o,l),t.connect(l,h),l.run();let c=t.getVariable(xe.PROPERTY,ze.AXIS_LABEL_OFFSET,e),d=t.getVariable(xe.PROPERTY,ze.AXIS_LABEL_FORMAT,e),u=t.getVariable(xe.PROPERTY,ze.AXIS_FONT_SIZE,e),_=t.createOneWayDependency(me.AXIS_LABELS_PLACER),p=t.getVariable(xe.PROPERTY,ze.AXIS_LABELS_POSITION,e);t.connect(s,_),t.connect(c,_),t.connect(d,_),t.connect(u,_),t.connect(_,p),_.run();let f=t.getVariable(xe.PROPERTY,ze.AXIS_TITLE_POSITION,e),g=t.createOneWayDependency(me.AXIS_TITLE_PLACER);t.connect(s,g),t.connect(g,f),g.run();let y=t.getVariable(xe.BOUNDS,e),m=t.getIncomingDataflowOperator(me.EVAL_BBOX,y);t.connect(h,m),t.connect(p,m),t.connect(m,y)}function ot(e,t){let i=t.getVariable(xe.BOUNDS,Ne(e.elements[0])),r=t.getVariable(xe.PROPERTY,ze.GRIDLINES_POSITION,e),s=t.createOneWayDependency(me.GRIDLINES_PLACER);t.connect(i,s),t.connect(s,r),s.run();let n=t.getVariable(xe.BOUNDS,e),a=t.getIncomingDataflowOperator(me.EVAL_BBOX,n);t.connect(r,a),t.connect(a,n)}function lt(t,i,r,s){let n,a=t.domain,o=t.range;switch(t.type){case"linear":case"log":{let l=Math.abs(o[0]-o[1]);n="width"==i||"x"==i?45:30;let h,c=Math.max(2,Math.floor(l/n));if("width"==i||"height"==i){let e=!!s&&(s.elements[0].parent.layout&&s.elements[0].parent.layout.type==fe.STACK);a[1]=t._scale.invert(e?oe(r)[i]:ae(r)[i])}if("log"===t.type){h=[];let e=t._scale.ticks();for(let t of e){let i=Math.log(t)/Math.log(10)+1e-6;Math.abs(i-Math.floor(i))<c/e.length&&h.push(t)}}else h=e.ticks(a[0],a[1],c);return h}case"point":{n="width"==i||"x"==i?80:30;let e=Math.floor(t.rangeExtent/a.length),r=Math.ceil(n/e);return"x"==i?a.filter((e,t)=>t%r==0):a}case"band":{n="width"==i||"x"==i?80:30;let e=Math.floor(t.rangeExtent/a.length),r=Math.max(1,Math.ceil(n/e));return a.filter((e,t)=>t%r==0)}case"time":{n="width"==i||"x"==i?80:30;let t,r,s=Math.floor((o[1]-o[0])/n),l=Math.ceil((a[1]-a[0])/s)/1e3,h=[1,60,3600,86400,2628003,31536e3],c=[e.timeSeconds,e.timeMinutes,e.timeHours,e.timeDays,e.timeMonths,e.timeYears];for(let e=0;e<h.length-1;e++)if(l>=h[e]&&l<h[e+1])return t=Math.floor(l/h[e]),r=c[e],r(a[0],a[1],t);return l>h[h.length-1]?(t=Math.floor(l/h[h.length-1]),r=c[h.length-1],r(a[0],a[1],t)):[]}default:return[]}}function ht(e,t){t.removeChild(e)}function ct(e,t){let i=t||Ie(e.element);delete i._encodings[ft(e.element)][e.channel],console.log("remove encoding",e.channel,e.attribute),function(e,t){let i=t.findVariable(xe.CHANNEL,[e.channel,e.element]);i||console.warn("cannot find encoding to remove from the dep graph");let r=i.incomingDataflow;t.deleteOperator(r)}(e,i._depGraph);for(let t of e.refElements)ht(t,i),Xe(t,i._depGraph);e.clearRefElements()}function dt(e,t){if(!e||!e.scene)return[];let i=e.scene._encodings[ft(e)],r=[];if(i&&(r=r.concat(Object.values(i))),t){let t=e.scene;for(let i in t._encodings){let s=i.split("_");s.pop(),s.join("_")===e.classId&&(r=r.concat(Object.values(t._encodings[i])))}}return r}function ut(e,t){let i=[];for(let r in t._encodings)for(let s in t._encodings[r])s===e&&i.push(t._encodings[r][s]);return i}function _t(e,t,i){for(let r in i._encodings){let s=i._encodings[r];if(s[t]&&s[t].attribute==e)return s[t]}return null}function pt(e,t){if(!e||!e.scene)return null;let i=e.scene._encodings[ft(e)];return i&&i[t]?i[t]:null}function ft(e){if(Array.isArray(e))return e.map(e=>ft(e)).join("_");if(e.classId)return e.classId;if("vertex"==e.type&&e._isAnyVertex)return e.parent.classId+"_vAny";if("vertex"==e.type&&e.dataScope){if(e.parent.type===i.Area){let t=e._index<e.parent._vertices.length/2;return e.parent.classId+"_v"+(t?0:e.parent._vertices.length-1)}return e.parent.classId+"_v"}return"vertex"==e.type?e.parent.classId+"_v"+e._index:"segment"==e.type&&e._dataScopeRef?e.parent.classId+"_s":"segment"==e.type?e.parent.classId+"_s"+e.parent.segments.indexOf(e):null}function gt(e,t){if(0==e.children.length)return[];let r=Ie(e),s=e.type===i.Composite?e.children:[e.children[0]],n=Object.keys(r._encodings),a=[];for(let e of s){let t=e;for(;t;){if(t.classId&&a.indexOf(t.classId)<0&&a.push(t.classId),t.type===i.Glyph){t.children.forEach(e=>a.push(e.classId));break}if(!t.children)break;t=t.children[0]}}let o=[];for(let e of n)for(let i of a)0===e.indexOf(i)&&r._encodings[e][t]&&o.push(r._encodings[e][t]);return o}function yt(e){let t=pt(e,"y"),i=pt(e,"height");return t||i&&i.scales[0].domain[0]<0}function mt(e){let t=pt(e,"x"),i=pt(e,"width");return t||i&&i.scales[0].domain[0]<0}function bt(e,t){return"x"===t||"width"===t?mt(e):"y"===t||"height"===t?yt(e):null!==pt(e,t)}function xt(e,t){let r=function(e){let t=e.parent,r=[];for(;t.type!==i.Scene;)r.push(t),t=t.parent;return r}(e);for(let e of r)if(pt(e,t))return!1;return r.length>=2?r[r.length-2]:e}function vt(e,t,i){wt(e,t,i);let r=Ie(e);if(!r)return;let s=Le(e,!0);for(let e of s)le(e);for(let e of s)r.onChange(xe.CHANNEL,"x",e)}function wt(e,t,r){switch(e.type){case i.Rect:case i.Path:case i.Line:case i.Area:!function(e,t,i){for(let r of e.vertices)Et(r,t,i);e._updateBounds(),e._refBounds&&e._refBounds.translate(t,i)}(e,t,r),0===t&&0===r||(e._dirty=!0);break;case i.Group:case i.Collection:case i.Glyph:!function(e,t,i){for(let r of e.children)wt(r,t,i);e._layout&&(void 0!==e._layout._left&&(e._layout._left+=t),void 0!==e._layout._top&&(e._layout._top+=i),e._layout._cellBounds&&e._layout._cellBounds.forEach(e=>e.translate(t,i)));0===t&&0===i||(e._dirty=!0);e._updateBounds(),e._refBounds&&e._refBounds.translate(t,i)}(e,t,r);break;case"segment":!function(e,t,i){Et(e.vertex1,t,i),Et(e.vertex2,t,i)}(e,t,r),0===t&&0===r||(e.parent._dirty=!0);break;case"vertex":Et(e,t,r),0===t&&0===r||(e.parent._dirty=!0);break;default:!function(e,t,i){e._x+=t,e._y+=i,e._updateBounds(),e._refBounds&&e._refBounds.translate(t,i)}(e,t,r),0===t&&0===r||(e._dirty=!0)}}function Et(e,t,i){e.x+=t,e.y+=i}class At{constructor(){this._id=this.type+s(),this._type=i.Group,this._dataScopeRef=void 0,this._bounds=void 0,this._layout=void 0,this._children=[],this._sortBy={property:D,descending:!1},this._z=0}get id(){return this._id}get type(){return this._type}get datum(){return A(this._dataScopeRef)}get data(){return E(this._dataScopeRef)}get children(){return this._children}addChild(e){this._children.indexOf(e)>=0||(e.parent&&e.parent.removeChild(e),this._children.push(e),e.parent=this)}addChildAt(e,t){e.parent&&e.parent.removeChild(e),this.children.splice(t,0,e),e.parent=this}removeChild(e){let t=this.children.indexOf(e);t>=0&&(this.children.splice(t,1),e.parent=null)}removeChildAt(e){this.children[e].parent=null,this.children.splice(e,1)}removeAll(){for(let e of this.children)e.parent=null;this._children=[]}get dataScope(){return this._dataScopeRef}set dataScope(e){if(this._dataScopeRef=b(e),void 0===this._dataScopeRef)for(let e of this.children)e.dataScope=void 0;else for(let e of this.children)e.dataScope?e.dataScope=I(e.dataScope,this._dataScopeRef):e.dataScope=this._dataScopeRef}getInternalEncodings(e){if(0==this.children.length)return[];let t=this.children[0],r=this.getScene(),s=Object.keys(r.encodings),n=[];for(;t;){if(t.classId&&n.indexOf(t.classId)<0&&n.push(t.classId),t.type===i.Glyph){t.children.forEach(e=>n.push(e.classId));break}if(!t.children)break;t=t.children[0]}let a=[];for(let t of s){let i=t.split("_");for(let s of n)i[0]==s&&r.encodings[t][e]&&a.push(r.encodings[t][e])}return a}get firstChild(){return this.children[0]}get lastChild(){return this.children[this.children.length-1]}set layout(e){if(this._layout=e,e&&(e.group=this),tt(this,e,this.scene._depGraph),this.children&&this.children.length>0){let e=Le(this,!0);for(let t of e)this.scene.onChange(xe.CHANNEL,"x",t)}}get layout(){return this._layout}get bounds(){return this._bounds||this._updateBounds(),this._bounds}get refBounds(){let e=this.children.map(e=>e.refBounds),t=d3.min(e.map(e=>e.left)),i=d3.min(e.map(e=>e.top)),r=d3.max(e.map(e=>e.right)),s=d3.max(e.map(e=>e.bottom));return new se(t,i,r-t,s-i)}get x(){return this.bounds.x}get y(){return this.bounds.y}set x(e){vt(this,e-this.bounds.x,0)}set y(e){vt(this,0,e-this.bounds.y)}_updateBounds(){let e=this.children;if(e.length>0){this._bounds=e[0].bounds.clone();for(let t=1;t<e.length;t++)"hidden"!=e[t].visibility&&(this._bounds=this._bounds.union(e[t].bounds))}else this._bounds=new se(0,0,0,0)}set visibility(e){let t="hidden"==e?"hidden":"visible";if(this.visibility!==t){this._visibility="hidden"==e?e:"visible";for(let t of this.children)t.visibility=e}}get visibility(){return this._visibility?this._visibility:"visible"}get z(){return this._z}set z(e){this._z!==e&&(this._z=e)}get scene(){return Ie(this)}get sortBy(){return this._sortBy}}function Ct(e){return e.type===i.Axis||e.type===i.Legend||e.type===i.Gridlines}class St extends At{constructor(e){super(),this._type=i.Collection,this._id=e.id?e.id:this._type+"_"+s(),this._classId=this.id,this._childrenOrder=void 0,this._clipMask=void 0}get classId(){return this._classId}getSVGPathData(){let e="";for(let t of this.children)if(t.getSVGPathData)e+=t.getSVGPathData();else if(t.bounds){let i=t.bounds;e+=["M",i.left,i.top].join(" "),e+=["L",i.right,i.top].join(" "),e+=["L",i.right,i.bottom].join(" "),e+=["L",i.left,i.bottom,"Z"].join(" ")}return e}createClipMask(){let e=ae(this._children);this._clipMask=new se(e.left,e.top,e.width,e.height)}get clipMask(){return this._clipMask}}class Rt extends At{constructor(e){if(super(),this._type=i.Glyph,this._id=e&&e.id?e.id:this.type+"_"+s(),this._classId=this._id,e&&e.children)for(let t of e.children)this.addChild(t)}get classId(){return this._classId}}const kt=Object.freeze({RowFirst:"rowFirst",ColumnFirst:"columnFirst"}),Tt=Object.freeze({TopLeft:"topLeft",TopRight:"topRight",BottomLeft:"bottomLeft",BottomRight:"bottomRight"}),Ot="horizontal",It="vertical",Nt="angular",Lt="radial",Pt={Left2Right:"l2r",Right2Left:"r2l",Top2Bottom:"t2b",Bottom2Top:"b2t"},Vt=Object.freeze({CLOCKWISE:"clockwise",ANTI_CLOCKWISE:"anti-clockwise"}),Mt=Object.freeze({INWARD:"inward",OUTWARD:"outward"}),Bt=Object.freeze({INWARD:"inward",OUTWARD:"outward",TANGENTIAL_CLOCKWISE:"tangentialClockwise",TANGENTIAL_COUNTERCLOCKWISE:"tangentialCounterClockwise",UPRIGHT:"upright"});class Dt{constructor(e,t){this.type="vertex",this.parent=e,this._index=t}_getStored(e){return this.parent._vertices.getProperty(this._index,e)}_setStored(e,t){this._getStored(e)!==t&&(this.parent._vertices.setProperty(this._index,e,t),this.parent._dirty=!0)}get datum(){return this.dataScope?A(this.dataScope):this.parent.datum}get data(){return this.dataScope?E(this.dataScope):this.parent.data}get dataScope(){return this.parent._vertices.getDataScopeRef(this._index)}set dataScope(e){this.dataScope!==e&&(this.parent._vertices.setDataScopeRef(this._index,e),this.parent._dirty=!0)}get bounds(){switch(this.shape){case"rect":return new se(this.x-this.width/2,this.y-this.height/2,this.width,this.height);case"circle":return new se(this.x-this.radius,this.y-this.radius,2*this.radius,2*this.radius);default:return new se(this.x-.5,this.y-.5,1,1)}}get id(){return this.parent.id+"_v_"+this.parent._vertices._ids[this._index]}set polarAngle(e){this._setStored("polarAngle",e)}get polarAngle(){return this._getStored("polarAngle")}get _polarAngle(){return this.polarAngle}set _polarAngle(e){this.polarAngle=e}get scene(){return this.parent.scene}get x(){return this.parent._vertices._xs[this._index]}set x(e){this.parent._vertices._xs[this._index]!==e&&(this.parent._vertices._xs[this._index]=e,this.parent._dirty=!0)}get y(){return this.parent._vertices._ys[this._index]}set y(e){this.parent._vertices._ys[this._index]!==e&&(this.parent._vertices._ys[this._index]=e,this.parent._dirty=!0)}get shape(){return this._getStored("shape")}set shape(e){this._setStored("shape",e)}get width(){return this._getStored("width")}set width(e){this._setStored("width",e)}get height(){return this._getStored("height")}set height(e){this._setStored("height",e)}get radius(){return this._getStored("radius")}set radius(e){this._setStored("radius",e)}get fillColor(){return this._getStored("fillColor")}set fillColor(e){this._setStored("fillColor",e)}get opacity(){return this._getStored("opacity")}set opacity(e){this._setStored("opacity",e)}get strokeWidth(){return this._getStored("strokeWidth")}set strokeWidth(e){this._setStored("strokeWidth",e)}get strokeColor(){return this._getStored("strokeColor")}set strokeColor(e){this._setStored("strokeColor",e)}}Dt.styles=["vxShape","vxWidth","vxHeight","vxRadius","vxFillColor","vxStrokeColor","vxStrokeWidth","vxOpacity"];class Gt{constructor(e,t,i,r){this.type="segment",this._id=r,this._vertex1Index="number"==typeof e?e:e._index,this._vertex2Index="number"==typeof t?t:t._index,this._dataScopeRef=void 0,this.parent=i}get dataScope(){return this._dataScopeRef?this._dataScopeRef:this.parent.dataScope}set dataScope(e){this._dataScopeRef=b(e)}get datum(){return this.dataScope?A(this.dataScope):this.parent.datum}get data(){return this.dataScope?E(this.dataScope):this.parent.data}get id(){return this.parent.id+"_s_"+this._id}get vertex1(){return this.parent.vertices[this._vertex1Index]}set vertex1(e){this._vertex1Index="number"==typeof e?e:e._index}get vertex2(){return this.parent.vertices[this._vertex2Index]}set vertex2(e){this._vertex2Index="number"==typeof e?e:e._index}get x(){return(this.parent._vertices._xs[this._vertex1Index]+this.parent._vertices._xs[this._vertex2Index])/2}get y(){return(this.parent._vertices._ys[this._vertex1Index]+this.parent._vertices._ys[this._vertex2Index])/2}get scene(){return this.parent.scene}}class zt{constructor(e){return this._path=e,this.clear(),new Proxy(this,{get:(e,t)=>"length"===t?e.length:t===Symbol.iterator?e[Symbol.iterator].bind(e):zt._isIndex(t)?e.get(Number(t)):e[t],set(e,t,i){if(zt._isIndex(t))return e.replace(Number(t),i),!0;if("string"==typeof t&&"_"===t[0])return e[t]=i,!0;throw new Error("path.vertices is read-only; mutate vertex properties or use path.vertices = [...].")}})}static _isIndex(e){if("string"!=typeof e||""===e)return!1;let t=Number(e);return Number.isInteger(t)&&t>=0&&String(t)===e}static getCoords(e){return Array.isArray(e)?e:[e.x,e.y]}static getId(e){return e&&e.parent&&e.parent._vertices&&void 0!==e._index?e.parent._vertices._ids[e._index]:e?e.id:void 0}static get storageKeys(){return["_ids","_xs","_ys","_dataScopeRefs","_polarAngles","_shapes","_widths","_heights","_radii","_fillColors","_opacities","_strokeWidths","_strokeColors","_refs"]}static get propertyArrays(){return{dataScope:"_dataScopeRefs",polarAngle:"_polarAngles",shape:"_shapes",width:"_widths",height:"_heights",radius:"_radii",fillColor:"_fillColors",opacity:"_opacities",strokeWidth:"_strokeWidths",strokeColor:"_strokeColors"}}get length(){return this._xs.length}clear(){this._ids=[],this._xs=[],this._ys=[],this._dataScopeRefs=[],this._polarAngles=[],this._shapes=[],this._widths=[],this._heights=[],this._radii=[],this._fillColors=[],this._opacities=[],this._strokeWidths=[],this._strokeColors=[],this._refs=[]}get(e){if(!(e<0||e>=this.length))return this._refs[e]||(this._refs[e]=new Dt(this._path,e)),this._refs[e]}at(e){return e<0&&(e=this.length+e),this.get(e)}append(e,t){let[i,r]=zt.getCoords(e),s=Array.isArray(e)?void 0:e.dataScope,n=void 0!==t?t:zt.getId(e),a=this.length;return this._ids.push(n),this._xs.push(i),this._ys.push(r),this._dataScopeRefs.push(s?this._copyDataScopeRef(s):void 0),this._polarAngles.push(Array.isArray(e)?void 0:e.polarAngle),this._shapes.push(Array.isArray(e)?void 0:e.shape),this._widths.push(Array.isArray(e)?0:e.width),this._heights.push(Array.isArray(e)?0:e.height),this._radii.push(Array.isArray(e)?0:e.radius),this._fillColors.push(Array.isArray(e)?"#555":e.fillColor),this._opacities.push(Array.isArray(e)?1:e.opacity),this._strokeWidths.push(Array.isArray(e)?0:e.strokeWidth),this._strokeColors.push(Array.isArray(e)?"#aaa":e.strokeColor),this._refs.push(void 0),a}insert(e,t,i,r){let s="number"==typeof t,n=s?[t,i]:zt.getCoords(t),a=n[0],o=n[1],l=s||Array.isArray(t)?void 0:t.dataScope,h=s?r:zt.getId(t);this._ids.splice(e,0,h),this._xs.splice(e,0,a),this._ys.splice(e,0,o),this._dataScopeRefs.splice(e,0,l?this._copyDataScopeRef(l):void 0),this._polarAngles.splice(e,0,s||Array.isArray(t)?void 0:t.polarAngle),this._shapes.splice(e,0,s||Array.isArray(t)?void 0:t.shape),this._widths.splice(e,0,s||Array.isArray(t)?0:t.width),this._heights.splice(e,0,s||Array.isArray(t)?0:t.height),this._radii.splice(e,0,s||Array.isArray(t)?0:t.radius),this._fillColors.splice(e,0,s||Array.isArray(t)?"#555":t.fillColor),this._opacities.splice(e,0,s||Array.isArray(t)?1:t.opacity),this._strokeWidths.splice(e,0,s||Array.isArray(t)?0:t.strokeWidth),this._strokeColors.splice(e,0,s||Array.isArray(t)?"#aaa":t.strokeColor),this._refs.splice(e,0,void 0),this._reindexRefs()}replace(e,t){let[i,r]=zt.getCoords(t),s=Array.isArray(t)?void 0:t.dataScope;this._xs[e]=i,this._ys[e]=r,this._dataScopeRefs[e]=s?this._copyDataScopeRef(s):void 0,this._polarAngles[e]=Array.isArray(t)?void 0:t.polarAngle,this._shapes[e]=Array.isArray(t)?void 0:t.shape,this._widths[e]=Array.isArray(t)?0:t.width,this._heights[e]=Array.isArray(t)?0:t.height,this._radii[e]=Array.isArray(t)?0:t.radius,this._fillColors[e]=Array.isArray(t)?"#555":t.fillColor,this._opacities[e]=Array.isArray(t)?1:t.opacity,this._strokeWidths[e]=Array.isArray(t)?0:t.strokeWidth,this._strokeColors[e]=Array.isArray(t)?"#aaa":t.strokeColor,this._refs[e]=void 0}copyFrom(e){this._ids=e._ids.slice(),this._xs=e._xs.slice(),this._ys=e._ys.slice(),this._dataScopeRefs=e._dataScopeRefs.map(e=>this._copyDataScopeRef(e)),this._polarAngles=e._polarAngles.slice(),this._shapes=e._shapes.slice(),this._widths=e._widths.slice(),this._heights=e._heights.slice(),this._radii=e._radii.slice(),this._fillColors=e._fillColors.slice(),this._opacities=e._opacities.slice(),this._strokeWidths=e._strokeWidths.slice(),this._strokeColors=e._strokeColors.slice(),this._refs=[]}getProperty(e,t){let i=zt.propertyArrays[t];return"dataScope"===t?this.getDataScopeRef(e):i?this[i][e]:void 0}setProperty(e,t,i){let r=zt.propertyArrays[t];r&&("dataScope"===t?this.setDataScopeRef(e,i):this[r][e]=i)}setDataScopeRef(e,t){this._dataScopeRefs[e]=t?this._copyDataScopeRef(t):void 0}getDataScopeRef(e){return this._dataScopeRefs[e]}hasDataScope(e){return!!this._dataScopeRefs[e]}getDataScopeRows(e){let t=this._dataScopeRefs[e];if(t)return E(t)}getDataScopeAttrVal(e,t){let i=this._dataScopeRefs[e];if(i)return R(i,t)}getDataScopeAttributeValues(e,t){let i=this._dataScopeRefs[e];return i?k(i,t):[]}aggregateDataScopeAttribute(e,t,i){return T(this._dataScopeRefs[e],t,i)}_copyDataScopeRef(e){return e?b(e):e}sort(e){let t=Array.from({length:this.length},(e,t)=>t);return t.sort((t,i)=>e(this.get(t),this.get(i))),this._reorder(t),this._path._reindexSegments(),this}reverse(){let e=Array.from({length:this.length},(e,t)=>this.length-t-1);return this._reorder(e),this._path._reindexSegments(),this}splice(e,t,...i){let r=this.slice(e,e+t);for(let i of zt.storageKeys)this[i].splice(e,t);for(let t=0;t<i.length;t++)this.insert(e+t,i[t],void 0);return this._reindexRefs(),this._path._reindexSegments(),r}push(...e){for(let t of e)this.append(t,void 0);return this._path._reindexSegments(),this.length}map(e,t){let i=[];for(let r=0;r<this.length;r++)i.push(e.call(t,this.get(r),r,this));return i}filter(e,t){let i=[];for(let r=0;r<this.length;r++){let s=this.get(r);e.call(t,s,r,this)&&i.push(s)}return i}find(e,t){for(let i=0;i<this.length;i++){let r=this.get(i);if(e.call(t,r,i,this))return r}}forEach(e,t){for(let i=0;i<this.length;i++)e.call(t,this.get(i),i,this)}slice(e,t){return Array.from(this).slice(e,t)}concat(...e){return Array.from(this).concat(...e)}entries(){let e=this;return function*(){for(let t=0;t<e.length;t++)yield[t,e.get(t)]}()}indexOf(e){return e&&e.parent===this._path?e._index:-1}includes(e){return this.indexOf(e)>=0}[Symbol.iterator](){let e=this;return function*(){for(let t=0;t<e.length;t++)yield e.get(t)}()}_reorder(e){for(let t of zt.storageKeys){let i=this[t];this[t]=e.map(e=>i[e])}this._reindexRefs()}_reindexRefs(){for(let e=0;e<this._refs.length;e++)this._refs[e]&&(this._refs[e]._index=e)}}let jt=class extends ce{constructor(e){super(e),this._type="type"in e?e.type:i.Path,this._vertices=new zt(this),this.vertexCounter=0,this._sortBy={},this.segmentCounter=0,this.segments=[],this.anchor=void 0,this.closed="closed"in e&&e.closed,this.curveMode="curveMode"in e?e.curveMode:"linear",this._vxShape=void 0,this._vxWidth=0,this._vxHeight=0,this._vxRadius=0,this._vxFillColor="#555555",this._vxStrokeColor="#aaaaaa",this._vxStrokeWidth=0,this._vxOpacity=1;for(let t of Dt.styles)t in e&&(this["_"+t]=e[t]);"vertices"in e&&(this.vertices=e.vertices),this._sourceAnchor="sourceAnchor"in e?e.sourceAnchor:["center","middle"],this._targetAnchor="targetAnchor"in e?e.targetAnchor:["center","middle"],this._sourceOffset="sourceOffset"in e?e.sourceOffset:[0,0],this._targetOffset="targetOffset"in e?e.targetOffset:[0,0],this._strength="strength"in e?e.strength:.85,"strokeColor"in this.styles||(this.styles.strokeColor="#ccc"),"fillColor"in this.styles||(this.styles.fillColor="none"),"strokeWidth"in this.styles||(this.styles.strokeWidth=1),"strokeDash"in this.styles||(this.styles.strokeDash="none")}set vertices(e){if(this._vertices.clear(),this.segments=[],this.vertexCounter=0,this.segmentCounter=0,0===e.length)return this._dirty=!0,void(this._bounds=void 0);for(let t=0;t<e.length;t++){let r=zt.getCoords(e[t]),s=zt.getCoords(e[0]);if(t==e.length-1&&r[0]===s[0]&&r[1]===s[1]&&this.type===i.Path)continue;let n=Array.isArray(e[t])?this.vertexCounter++:zt.getId(e[t]),a=this._vertices.append(e[t],n);!Array.isArray(e[t])&&"number"==typeof n&&n>=this.vertexCounter&&(this.vertexCounter=n+1);for(let i of Dt.styles){if(void 0===this[i])continue;let r=i.replace("vx",""),s=r[0].toLowerCase()+r.slice(1);(Array.isArray(e[t])||void 0===e[t][s])&&this._vertices.setProperty(a,s,this[i])}t>0&&this.segments.push(new Gt(a-1,a,this,this.segmentCounter++))}let t=zt.getCoords(e[0]),r=zt.getCoords(e[e.length-1]);this._vertices.length>1&&(this.closed||t[0]===r[0]&&t[1]===r[1]||this.type===i.Rect)&&(this.closed=!0,"fillColor"in this.styles||(this.styles.fillColor="#fff"),this.segments.push(new Gt(this._vertices.length-1,0,this,this.segmentCounter++))),this._dirty=!0,this._updateBounds()}copyPropertiesTo(e){e.attrs=Object.assign({},this.attrs),e.styles=Object.assign({},this.styles);for(let t of Dt.styles)void 0!==this["_"+t]&&(e["_"+t]=this["_"+t]);this._dataScopeRef&&(e.dataScope=this._dataScopeRef),e.closed=this.closed,e.curveMode=this.curveMode,e.vertexCounter=this.vertexCounter,e._vertices.copyFrom(this._vertices),e.segments=[],e.segmentCounter=0;for(let t=1;t<e._vertices.length;t++)e.segments.push(new Gt(t-1,t,e,e.segmentCounter++));e.closed&&e.segments.push(new Gt(e._vertices.length-1,0,e,e.segmentCounter++)),e._sourceAnchor=this._sourceAnchor.slice(),e._targetAnchor=this._targetAnchor.slice(),e._sourceOffset=this._sourceOffset.slice(),e._targetOffset=this._targetOffset.slice(),e._beta=this._beta}get bounds(){return this._bounds||this._updateBounds(),this._bounds}get x(){return this.bounds.x}get y(){return this.bounds.y}set x(e){vt(this,e-this.bounds.x,0)}set y(e){vt(this,0,e-this.bounds.y)}resize(e,t,i,r){let s=this.bounds,n=0===s.width?1:s.width,a=0===s.height?1:s.height,o=this._vertices._xs,l=this._vertices._ys;if("right"===i)for(let t=0;t<this._vertices.length;t++)o[t]=s.right-e/n*(s.right-o[t]);else for(let t=0;t<this._vertices.length;t++)o[t]=s.left+e/n*(o[t]-s.left);if("top"===r)for(let e=0;e<this._vertices.length;e++)l[e]=s.top+t/a*(l[e]-s.top);else for(let e=0;e<this._vertices.length;e++)l[e]=s.bottom-t/a*(s.bottom-l[e]);this._updateBounds(),this._dirty=!0}_updateBounds(){let t=[],r=[];if(this._d){const e=this._d.match(/[a-zA-Z][^a-zA-Z]*/g),i=" ";e.forEach(e=>{let s=e.slice(1).trim().split(i).map(Number);for(let[e,i]of s.entries())e%2==0?t.push(i):r.push(i)})}else t=this._vertices._xs,r=this._vertices._ys;let s=e.min(t),n=e.min(r),a=e.max(t),o=e.max(r),l=a-s,h=o-n;if(this._bounds=new se(s,n,l,h),this.type===i.Line||this.type===i.Path){let e=this.styles.strokeWidth?this.styles.strokeWidth:1;s===a?this._bounds=new se(s-e/2,n,a-s+e,o-n):n===o&&(this._bounds=new se(s,n-e/2,a-s,o-n+e))}}addVertex(e,t,i){void 0===i&&(i=this._vertices.length),this._vertices.insert(i,e,t,this.vertexCounter++),this._reindexSegments()}sortVertices(e,t){this._vertices.sort((t,i)=>t[e]-i[e]),t&&this._vertices.reverse();for(let e=0;e<this.segments.length;e++){let t=this.segments[e];t.vertex1=e,t.vertex2=(e+1)%this._vertices.length}this._dirty=!0}sortVerticesByData(e,t,i){let r;r=i?(t,r)=>i.indexOf(t.datum[e])-i.indexOf(r.datum[e]):(t,i)=>t.datum[e]<i.datum[e]?-1:1,this._vertices.sort(r),t&&this._vertices.reverse();for(let e=0;e<this.segments.length;e++){let t=this.segments[e];t.vertex1=e,t.vertex2=(e+1)%this._vertices.length}this._dirty=!0}getSVGPathData(){if(this._d)return this._d;if(this._vertices.length<2)return"";let t=e.path(),i=this._getD3CurveFunction(this.curveMode)(t);i.lineStart();for(let e=0;e<this._vertices.length;e++)i.point(this._vertices._xs[e],this._vertices._ys[e]);return this.closed&&i.point(this._vertices._xs[0],this._vertices._ys[0]),i.lineEnd(),t._}get firstVertex(){return this._vertices[0]}get anyVertex(){return this._anyVertexRef||(this._anyVertexRef=new Dt(this,0),this._anyVertexRef._isAnyVertex=!0),this._anyVertexRef}get firstSegment(){return this.segments[0]}get lastVertex(){return this._vertices[this._vertices.length-1]}get lastSegment(){return this.segments[this.segments.length-1]}_reindexSegments(){for(let e=0;e<this.segments.length;e++)this.segments[e].vertex1=e,this.segments[e].vertex2=(e+1)%this._vertices.length}_getD3CurveFunction(t){switch(t){case Ut.Natural:return e.curveNatural;case Ut.Basis:return e.curveBasis;case Ut.BumpX:return e.curveBumpX;case Ut.BumpY:return e.curveBumpY;case Ut.Linear:return e.curveLinear;case Ut.Step:return e.curveStep;case Ut.CatmullRom:return e.curveCatmullRom;case Ut.Cardinal:return e.curveCardinal;case Ut.Bundle:return e.curveBundle.beta(.5);default:return e.curveLinear}}get vxShape(){return this._vxShape}get vxWidth(){return this._vxWidth}get vxHeight(){return this._vxHeight}get vxRadius(){return this._vxRadius}get vxFillColor(){return this._vxFillColor}get vxStrokeColor(){return this._vxStrokeColor}get vxStrokeWidth(){return this._vxStrokeWidth}get vxOpacity(){return this._vxOpacity}set vxOpacity(e){this._vxOpacity=e;for(let t of this.vertices)t.opacity=e}get sourceAnchor(){return this._sourceAnchor}get targetAnchor(){return this._targetAnchor}get sourceOffset(){return this._sourceOffset}get targetOffset(){return this._targetOffset}get strength(){return this._strength}set strength(e){this._strength=e,this._dirty=!0}get vertices(){return this._vertices}};function Ft(e,t){const i=Q.getSVG();let r=document.createElementNS("http://www.w3.org/2000/svg","path");r.setAttribute("d",e.getSVGPathData()),i.appendChild(r);let s=r.getTotalLength();return r.getPointAtLength(s*t)}function Wt(e){return e instanceof jt&&e.source&&e.target}const Ut={Natural:"natural",Basis:"basis",BumpX:"bumpX",BumpY:"bumpY",Bundle:"bundle",Linear:"linear",Step:"step",CatmullRom:"CatmullRom",Cardinal:"cardinal"};function Yt(e,t,i){const r=e.match(/[a-zA-Z][^a-zA-Z]*/g),s=",";return r.map(e=>{const r=e[0],n=e.slice(1).trim();if("M"===r||"L"===r||"T"===r){const[e,a]=n.split(s).map(Number);return`${r}${e+t} ${a+i}`}if("C"===r){const e=n.split(s).map(Number);return`${r}${e[0]+t} ${e[1]+i} ${e[2]+t} ${e[3]+i} ${e[4]+t} ${e[5]+i}`}if("Q"===r){const e=n.split(s).map(Number);return`${r}${e[0]+t} ${e[1]+i} ${e[2]+t} ${e[3]+i}`}if("A"===r){const e=n.split(s).map(Number);return`${r}${e[0]} ${e[1]} ${e[2]} ${e[3]} ${e[4]} ${e[5]+t} ${e[6]+i}`}return"Z"===r||"z"===r?r:e}).join(" ")}class Ht extends jt{constructor(e){super(e),this._type=i.Arc,this.closed=!0,this._x="x"in e?e.x:100,this._y="y"in e?e.y:100,this._innerRadius="innerRadius"in e?e.innerRadius:100,this._outerRadius="outerRadius"in e?e.outerRadius:200,this._thickness="thickness"in e?e.thickness:this._outerRadius-this._innerRadius,this._startAngle="startAngle"in e?e.startAngle:0,this._endAngle="endAngle"in e?e.endAngle:90,this._sr=Xt(this._startAngle),this._er=Xt(this._endAngle),this._direction="direction"in e?e.direction:Vt.ANTI_CLOCKWISE;let t=this._x+this._innerRadius*Math.cos(this._sr),r=this._y-this._innerRadius*Math.sin(this._sr),s=this._x+this._innerRadius*Math.cos(this._er),n=this._y-this._innerRadius*Math.sin(this._er),a=this._x+this._outerRadius*Math.cos(this._sr),o=this._y-this._outerRadius*Math.sin(this._sr),l=this._x+this._outerRadius*Math.cos(this._er),h=this._y-this._outerRadius*Math.sin(this._er);this.vertices=[[t,r],[a,o],[l,h],[s,n]]}get type(){return 0===this._innerRadius?i.Pie:i.Arc}get innerRadius(){return this._innerRadius}get outerRadius(){return this._outerRadius}get thickness(){return this._outerRadius-this._innerRadius}get direction(){return this._direction}get x(){return this._x}get y(){return this._y}get startAngle(){return this._startAngle}get endAngle(){return this._endAngle}get angle(){return this._endAngle<this._startAngle?this._endAngle+360-this._startAngle:this._endAngle-this._startAngle}setAngles(e,t){this._startAngle=e,this._endAngle=t,this._sr=Xt(this._startAngle),this._er=Xt(this._endAngle),this.vertices[0].x=this._x+this._innerRadius*Math.cos(this._sr),this.vertices[0].y=this._y-this._innerRadius*Math.sin(this._sr),this.vertices[1].x=this._x+this._outerRadius*Math.cos(this._sr),this.vertices[1].y=this._y-this._outerRadius*Math.sin(this._sr),this.vertices[2].x=this._x+this._outerRadius*Math.cos(this._er),this.vertices[2].y=this._y-this._outerRadius*Math.sin(this._er),this.vertices[3].x=this._x+this._innerRadius*Math.cos(this._er),this.vertices[3].y=this._y-this._innerRadius*Math.sin(this._er),this._dirty=!0}_updateBounds(){let e=this.vertices.map(e=>e.x),t=this.vertices.map(e=>e.y),i=d3.min(e),r=d3.min(t),s=d3.max(e)-i,n=d3.max(t)-r;this._bounds=new se(i,r,s,n)}copyPropertiesTo(e){super.copyPropertiesTo(e),e._x=this._x,e._y=this._y,e._innerRadius=this._innerRadius,e._outerRadius=this._outerRadius,e._startAngle=this._startAngle,e._endAngle=this._endAngle,e._thickness=this._thickness,e._direction=this._direction,e._sr=this._sr,e._er=this._er}getSVGPathData(){let e=this._endAngle<this._startAngle?this._endAngle+360-this._startAngle:this._endAngle-this._startAngle,t=e>180?1:0;return["M "+this.vertices[0].x+", "+this.vertices[0].y,"L "+this.vertices[1].x+", "+this.vertices[1].y,"A "+[this._outerRadius,this._outerRadius,e,t,0,this.vertices[2].x,this.vertices[2].y].join(" "),"L "+this.vertices[3].x+", "+this.vertices[3].y,"A "+[this._innerRadius,this._innerRadius,e,t,1,this.vertices[0].x,this.vertices[0].y].join(" ")].join(" ")}}function Xt(e){return e*Math.PI/180}function qt(e){return 180*e/Math.PI}function Kt(e){return(e%360+360)%360}function Zt(e,t,i,r){let s=e-i,n=r-t;return Math.atan2(n,s)*(180/Math.PI)}class $t extends jt{constructor(e){super(e),this._type=i.Area,this.closed=!0,this._orientation="orientation"in e?e.orientation:void 0,this._baseline="baseline"in e?e.baseline:void 0,e&&"vertices"in e&&this.segments.push(new Gt(this.vertices.length-1,0,this,this.segmentCounter++))}get topLeftVertex(){return this._orientation===Ot?this.vertices[0]:this.vertices[this.vertices.length-1]}get bottomLeftVertex(){return this._orientation===Ot?this.vertices[this.vertices.length-1]:this.vertices[this.vertices.length/2]}get topRightVertex(){return this._orientation===Ot?this.vertices[this.vertices.length/2-1]:this.vertices[0]}get bottomRightVertex(){return this._orientation===Ot?this.vertices[this.vertices.length/2]:this.vertices[this.vertices.length/2-1]}get baseline(){return this._baseline}set baseline(e){this._baseline=e,this._dirty=!0}get orientation(){return this._orientation}set orientation(e){this._orientation=e,this._dirty=!0}get firstVertexPair(){return[this.vertices[0],this.vertices[this.vertices.length-1]]}get width(){return this.vertices[this.vertices.length/2].x-this.vertices[0].x}get height(){return this.vertices[this.vertices.length/2].y-this.vertices[0].y}get left(){return this.vertices[0].x}get top(){return this.vertices[0].y}copyPropertiesTo(e){super.copyPropertiesTo(e),e._baseline=this._baseline,e._orientation=this._orientation}getSVGPathData(){return super.getSVGPathData()+" z"}}class Jt extends jt{constructor(e){super(e),this._type=i.BezierCurve,this._orientation="orientation"in e?e.orientation:Ot}get type(){return this._type}get orientation(){return this._orientation}copyPropertiesTo(e){super.copyPropertiesTo(e),e._orientation=this._orientation}getSVGPathData(){if(this._d)return this._d;let e="M ";return e+=this.vertices[0].x+" "+this.vertices[0].y+" ",e+="C "+this.vertices[1].x+" "+this.vertices[1].y+" ",e+=this.vertices[2].x+" "+this.vertices[2].y+" ",e+=this.vertices[3].x+" "+this.vertices[3].y,e}}class Qt extends ce{constructor(e){super(e),this._type=i.Circle,this._x="x"in e?e.x:0,this._y="y"in e?e.y:0,this._radius="radius"in e?e.radius:100,"strokeColor"in this.styles||(this.styles.strokeColor="#ccc"),"fillColor"in this.styles||(this.styles.fillColor="none"),"strokeWidth"in this.styles||(this.styles.strokeWidth=1),"strokeDash"in this.styles||(this.styles.strokeDash="none")}set x(e){this._x=e,this._dirty=!0}set y(e){this._y=e,this._dirty=!0}get x(){return this._x}get y(){return this._y}get radius(){return this._radius}set radius(e){this._radius=e,this._dirty=!0}get area(){return Math.PI*Math.pow(this._radius,2)}_updateBounds(){if(this._rotate){let e=ee(this._x,this._y,this._rotate[1],this._rotate[2],this._rotate[0]);this._bounds=new se(e.x-this._radius,e.y-this._radius,2*this._radius,2*this._radius)}else this._bounds=new se(this._x-this._radius,this._y-this._radius,2*this._radius,2*this._radius)}copyPropertiesTo(e){super.copyPropertiesTo(e),e._x=this._x,e._y=this._y,e._radius=this._radius}getSVGPathData(){return["M",this._x,this._y,"m",-this._radius,", 0 a",this._radius,",",this._radius,"0 1,0",2*this._radius,",0 a",this._radius,",",this._radius,"0 1,0",-2*this._radius,",0"].join(" ")}}class ei extends ce{constructor(e){super(e),this._type=i.Image,this._src=e.src,this._x="x"in e?e.x:0,this._y="y"in e?e.y:0,this._width="width"in e?e.width:100,this._height="height"in e?e.height:100}get src(){return this._src}set src(e){this._src=e,this._dirty=!0}get width(){return this._width}set width(e){this._width=e,this._updateBounds(),this._dirty=!0}get height(){return this._height}set height(e){this._height=e,this._updateBounds(),this._dirty=!0}resize(e,t){this._width=e,this._height=t,this._dirty=!0,this._updateBounds()}get x(){return this._x}set x(e){this._x=e,this._dirty=!0,this._updateBounds()}get y(){return this._y}set y(e){this._y=e,this._dirty=!0,this._updateBounds()}get bounds(){return this._bounds||this._updateBounds(),this._bounds}_updateBounds(){this._bounds=new se(this._x,this._y,this._width,this._height)}copyPropertiesTo(e){e.attrs=Object.assign({},this.attrs),e.styles=Object.assign({},this.styles),this._dataScopeRef&&(e.dataScope=this._dataScopeRef),e.x=this._x,e.y=this._y,e.width=this._width,e.height=this._height,e.src=this._src}}let ti=class extends ce{constructor(e){super(e),this._type=i.Symbol,this._path=e.path,this._viewBox="viewBox"in e?e.viewBox:[0,0,24,24],this._x="x"in e?e.x:0,this._y="y"in e?e.y:0,this._width="width"in e?e.width:24,this._height="height"in e?e.height:24}get path(){return this._path}set path(e){this._path=e,this._dirty=!0}get viewBox(){return this._viewBox}set viewBox(e){this._viewBox=e,this._dirty=!0}get width(){return this._width}set width(e){this._width=e,this._updateBounds(),this._dirty=!0}get height(){return this._height}set height(e){this._height=e,this._updateBounds(),this._dirty=!0}resize(e,t){this._width=e,this._height=t,this._dirty=!0,this._updateBounds()}get x(){return this._x}set x(e){this._x=e,this._dirty=!0,this._updateBounds()}get y(){return this._y}set y(e){this._y=e,this._dirty=!0,this._updateBounds()}get bounds(){return this._bounds||this._updateBounds(),this._bounds}_updateBounds(){this._bounds=new se(this._x,this._y,this._width,this._height)}copyPropertiesTo(e){e.attrs=Object.assign({},this.attrs),e.styles=Object.assign({},this.styles),this._dataScopeRef&&(e.dataScope=this._dataScopeRef),e.x=this._x,e.y=this._y,e.width=this._width,e.height=this._height,e.path=this._path,e.viewBox=this._viewBox}};class ii extends jt{constructor(e){super(e)}get x1(){return this.vertices[0].x}get y1(){return this.vertices[0].y}get x2(){return this.vertices[1].x}get y2(){return this.vertices[1].y}get x(){return(this.vertices[0].x+this.vertices[1].x)/2}get y(){return(this.vertices[0].y+this.vertices[1].y)/2}set x(e){let t=e-this.x;this.vertices[0].x+=t,this.vertices[1].x+=t,this._dirty=!0}set y(e){let t=e-this.y;this.vertices[0].y+=t,this.vertices[1].y+=t,this._dirty=!0}set x1(e){this.vertices[0].x=e,this._dirty=!0}set x2(e){this.vertices[1].x=e,this._dirty=!0}set y1(e){this.vertices[0].y=e,this._dirty=!0}set y2(e){this.vertices[1].y=e,this._dirty=!0}}const ri="filled",si="none";class ni extends jt{constructor(e={}){const t="x1"in e?e.x1:0,r="y1"in e?e.y1:0,s="x2"in e?e.x2:100,n="y2"in e?e.y2:0,a=[[t,r],...e.controlPoints||[],[s,n]];super({...e,type:i.Arrow,vertices:a}),this._startStyle=e.startStyle??si,this._startSize=e.startSize??8,this._endStyle=e.endStyle??ri,this._endSize=e.endSize??8}get x1(){return this.vertices[0].x}set x1(e){this.vertices[0].x=e,this._dirty=!0}get y1(){return this.vertices[0].y}set y1(e){this.vertices[0].y=e,this._dirty=!0}get x2(){return this.vertices[this.vertices.length-1].x}set x2(e){this.vertices[this.vertices.length-1].x=e,this._dirty=!0}get y2(){return this.vertices[this.vertices.length-1].y}set y2(e){this.vertices[this.vertices.length-1].y=e,this._dirty=!0}get startStyle(){return this._startStyle}set startStyle(e){this._startStyle=e,this._dirty=!0}get startSize(){return this._startSize}set startSize(e){this._startSize=e,this._dirty=!0}get endStyle(){return this._endStyle}set endStyle(e){this._endStyle=e,this._dirty=!0}get endSize(){return this._endSize}set endSize(e){this._endSize=e,this._dirty=!0}}class ai extends ce{constructor(e){super(e),this._type=i.SimpleText,this._x="x"in e?e.x:0,this._y="y"in e?e.y:0,this._text="text"in e?e.text:"",this._anchor="anchor"in e?e.anchor:[he.CENTER,he.MIDDLE],this._textPath=void 0,this._textPathOffset="50%","fontSize"in this.styles||(this.styles.fontSize="12px"),"fontFamily"in this.styles||(this.styles.fontFamily="Arial, sans-serif"),"fontWeight"in this.styles||(this.styles.fontWeight="normal"),"fillColor"in this.styles||(this.styles.fillColor="black"),"backgroundColor"in e&&(this._backgroundColor=e.backgroundColor),"borderWidth"in e&&(this._borderWidth=e.borderWidth),"borderColor"in e&&(this._borderColor=e.borderColor),this._rotate="rotate"in e?e.rotate:void 0}hasBackground(){return this._backgroundColor||this._borderStroke||this._borderColor}_updateBounds(){let e,t,i=function(e,t,i){const r=Q.getSVG(),s=document.createElementNS("http://www.w3.org/2000/svg","text");s.setAttribute("font-family",t),s.setAttribute("font-size",i),s.textContent=e,r.appendChild(s);const n=s.getBBox();return r.removeChild(s),{width:n.width,height:n.height}}(this._text,[this.fontWeight,this.fontSize,this.fontFamily].join(" "),parseFloat(this.fontSize)),r=i.width,s=i.height;switch(this._anchor[0]){case he.LEFT:e=this._x;break;case he.RIGHT:e=this._x-r;break;case he.CENTER:e=this._x-r/2;break;default:e=this._x}switch(this._anchor[1]){case he.TOP:t=this._y;break;case he.BOTTOM:t=this._y-s;break;case he.MIDDLE:default:t=this._y-s/2}if(this._rotate&&3===this._rotate.length){let i=[{x:e,y:t},{x:e+r,y:t},{x:e,y:t+s},{x:e+r,y:t+s}].map(e=>ee(e.x,e.y,this._rotate[1],this._rotate[2],this._rotate[0])),n=d3.min(i.map(e=>e.x)),a=d3.max(i.map(e=>e.x)),o=d3.min(i.map(e=>e.y)),l=d3.max(i.map(e=>e.y));this._bounds=new se(n,o,a-n,l-o)}else this._bounds=new se(e,t,r,s)}get x(){return this._x}set x(e){this._x=e,this._dirty=!0}get y(){return this._y}set y(e){this._y=e,this._dirty=!0}get text(){return this._text}set text(e){this._text=e,this._dirty=!0}get anchor(){return this._anchor}get fontFamily(){return this.styles.fontFamily}get fontSize(){return this.styles.fontSize}get fontWeight(){return this.styles.fontWeight}set fontWeight(e){this.styles.fontWeight=e,this._dirty=!0}get textPath(){return this._textPath}set textPath(e){this._textPath=e,this._dirty=!0}get textPathOffset(){return this._textPathOffset}set textPathOffset(e){this._textPathOffset=e,this._dirty=!0}get backgroundColor(){return this._backgroundColor?this._backgroundColor:"#fff"}get borderColor(){return this._borderColor?this._borderColor:"#ccc"}get borderWidth(){return this._borderWidth?this._borderWidth:1}copyPropertiesTo(e){e.styles=Object.assign({},this.styles),this._dataScopeRef&&(e.dataScope=this._dataScopeRef),e._x=this._x,e._y=this._y,e._text=this._text,e._anchor=[this._anchor[0],this._anchor[1]],e._backgroundColor=this._backgroundColor,e._borderColor=this._borderColor,e._borderStroke=this._borderStroke}}class oi extends jt{constructor(e){super(e),this._type=i.Polygon,this.closed=!0,"x"in e&&(this._x=e.x),"y"in e&&(this._y=e.y),"radius"in e&&(this._radius=e.radius)}get radius(){return this._radius}get x(){return this._x}get y(){return this._y}set x(e){this._x=e,this._dirty=!0}set y(e){this._y=e,this._dirty=!0}set radius(e){this._radius=e,this._dirty=!0}copyPropertiesTo(e){super.copyPropertiesTo(e),e._x=this._x,e._y=this._y,e._radius=this._radius}}class li extends jt{constructor(e){super(e)}get width(){return this.vertices[1].x-this.vertices[0].x}get height(){return this.vertices[2].y-this.vertices[1].y}get left(){return this.vertices[0].x}get top(){return this.vertices[0].y}get right(){return this.vertices[1].x}get bottom(){return this.vertices[2].y}get area(){return this.width*this.height}setBounds(e,t,i,r){this.vertices[0].x=e,this.vertices[0].y=t,this.vertices[1].x=e+i,this.vertices[1].y=t,this.vertices[2].x=e+i,this.vertices[2].y=t+r,this.vertices[3].x=e,this.vertices[3].y=t+r,this._dirty=!0}resize(e,t,i,r){e!==this.width&&("right"===i?(this.vertices[1].x=this.refBounds.right,this.vertices[2].x=this.refBounds.right,this.vertices[0].x=this.vertices[1].x-e,this.vertices[3].x=this.vertices[0].x):(this.vertices[0].x=this.refBounds.left,this.vertices[3].x=this.refBounds.left,this.vertices[1].x=this.vertices[0].x+e,this.vertices[2].x=this.vertices[1].x)),t!==this.height&&("top"===r?(this.vertices[0].y=this.refBounds.top,this.vertices[1].y=this.refBounds.top,this.vertices[3].y=this.vertices[0].y+t,this.vertices[2].y=this.vertices[3].y):(this.vertices[2].y=this.refBounds.bottom,this.vertices[3].y=this.refBounds.bottom,this.vertices[0].y=this.vertices[3].y-t,this.vertices[1].y=this.vertices[0].y)),this._dirty=!0}get leftSegment(){return this.segments[3]}get rightSegment(){return this.segments[1]}get topSegment(){return this.segments[0]}get bottomSegment(){return this.segments[2]}}class hi extends jt{constructor(e){super(e),this._type=i.Ring,this.closed=!0,this._x="x"in e?e.x:0,this._y="y"in e?e.y:0,this._innerRadius="innerRadius"in e?e.innerRadius:100,this._outerRadius="outerRadius"in e?e.outerRadius:200}get innerRadius(){return this._innerRadius}get outerRadius(){return this._outerRadius}get x(){return this._x}get y(){return this._y}get thickness(){return this._outerRadius-this._innerRadius}copyPropertiesTo(e){super.copyPropertiesTo(e),e._x=this._x,e._y=this._y,e._innerRadius=this._innerRadius,e._outerRadius=this._outerRadius}getSVGPathData(){return["M "+this._x+" "+this._y,"m 0, -"+this._outerRadius,"a "+this._outerRadius+","+this._outerRadius+", 0, 1, 0, 1, 0","Z","m 0 "+(this._outerRadius-this._innerRadius),"a "+this._innerRadius+", "+this._innerRadius+", 0, 1, 1, -1, 0","Z"].join(" ")}}class ci extends ce{constructor(e){super(e),this._type=i.RichText,this._x="x"in e?e.x:0,this._y="y"in e?e.y:0,this._text="text"in e?e.text:"",this._width="width"in e?e.width:200,this._anchor="anchor"in e?e.anchor:[he.CENTER,he.MIDDLE],"fontSize"in this.styles||(this.styles.fontSize="12px"),"fontFamily"in this.styles||(this.styles.fontFamily="Arial, sans-serif"),"fontWeight"in this.styles||(this.styles.fontWeight="normal"),"fillColor"in this.styles||(this.styles.fillColor="black"),"backgroundColor"in e&&(this._backgroundColor=e.backgroundColor),"borderWidth"in e&&(this._borderWidth=e.borderWidth),"borderColor"in e&&(this._borderColor=e.borderColor),this._rotate="rotate"in e?e.rotate:void 0}hasBackground(){return this._backgroundColor||this._borderStroke||this._borderColor}_updateBounds(){let e,t,i=function(e,t,i){const r=Q.getSVG(),s=document.createElementNS("http://www.w3.org/2000/svg","text");s.setAttribute("font-family",t),s.setAttribute("font-size",i),s.textContent=e,r.appendChild(s);const n=s.getBBox();return r.removeChild(s),{width:n.width,height:n.height}}(this._text,[this.fontWeight,this.fontSize,this.fontFamily].join(" "),parseFloat(this.fontSize)),r=i.width,s=i.height;switch(this._anchor[0]){case he.LEFT:e=this._x;break;case he.RIGHT:e=this._x-r;break;case he.CENTER:e=this._x-r/2;break;default:e=this._x}switch(this._anchor[1]){case he.TOP:t=this._y;break;case he.BOTTOM:t=this._y-s;break;case he.MIDDLE:default:t=this._y-s/2}if(this._rotate&&3===this._rotate.length){let i=[{x:e,y:t},{x:e+r,y:t},{x:e,y:t+s},{x:e+r,y:t+s}].map(e=>ee(e.x,e.y,this._rotate[1],this._rotate[2],this._rotate[0])),n=d3.min(i.map(e=>e.x)),a=d3.max(i.map(e=>e.x)),o=d3.min(i.map(e=>e.y)),l=d3.max(i.map(e=>e.y));this._bounds=new se(n,o,a-n,l-o)}else this._bounds=new se(e,t,r,s)}get x(){return this._x}get y(){return this._y}set x(e){this._x=e,this._dirty=!0}set y(e){this._y=e,this._dirty=!0}get text(){return this._text}set text(e){this._text=e,this._dirty=!0}get anchor(){return this._anchor}get fontFamily(){return this.styles.fontFamily}get fontSize(){return this.styles.fontSize}get fontWeight(){return this.styles.fontWeight}get textPath(){return this._textPath}set textPath(e){this._textPath=e,this._dirty=!0}get textPathOffset(){return this._textPathOffset}set textPathOffset(e){this._textPathOffset=e,this._dirty=!0}get backgroundColor(){return this._backgroundColor?this._backgroundColor:"#fff"}get borderColor(){return this._borderColor?this._borderColor:"#ccc"}get borderWidth(){return this._borderWidth?this._borderWidth:1}get width(){return this._width}copyPropertiesTo(e){e.styles=Object.assign({},this.styles),this._dataScopeRef&&(e.dataScope=this._dataScopeRef),e._x=this._x,e._y=this._y,e._text=this._text,e._anchor=[this._anchor[0],this._anchor[1]],e._backgroundColor=this._backgroundColor,e._borderColor=this._borderColor,e._borderStroke=this._borderStroke}}class di{constructor(e){let t=e||{};this._stops=[],this.type=i.LinearGradient,this.id=this.type+s(),this.x1="x1"in t?t.x1:0,this.x2="x2"in t?t.x2:100,this.y1="y1"in t?t.y1:0,this.y2="y2"in t?t.y2:0}toJSON(){let e={};return e.type=this.type,e.id=this.id,e.x1=this.x1,e.x2=this.x2,e.y1=this.y1,e.y2=this.y2,e.stops=this._stops,e}addStop(e,t,i){this._stops.push({offset:e,color:t,opacity:i})}get stops(){return this._stops}}class ui{constructor(e){this.type=i.PathGradient,this.id=this.type+s(),this._colors=e?e.slice():[]}toJSON(){let e={};return e.type=this.type,e.id=this.id,e.colors=this._colors.slice(),e}get colors(){return this._colors}set colors(e){this._colors=e}}class _i extends At{constructor(e){super(),this._type=i.Axis,this._id=e.id?e.id:this._type+s(),this._attribute=void 0,this._channel=void 0,this._orientation=void 0,this._strokeColor="strokeColor"in e?e.strokeColor:"#555",this._textColor="textColor"in e?e.textColor:"#555",this._fontSize="fontSize"in e?e.fontSize:"12px",this._tickOffset="tickOffset"in e?e.tickOffset:0,this._tickSize="tickSize"in e?e.tickSize:5,this._tickAnchor=e.tickAnchor,this._tickVisible=!("tickVisible"in e)||e.tickVisible,this._pathVisible=!("pathVisible"in e)||e.pathVisible,this._labelVisible=!("labelVisible"in e)||e.labelVisible,this._labelOffset="labelOffset"in e?e.labelOffset:this._tickSize+this._tickOffset+3,this._labelFormat="labelFormat"in e?e.labelFormat:"",this._titleOffset="titleOffset"in e?e.titleOffset:40,this._rotateYTitle=!("rotateTitle"in e&&!e.rotateTitle),this._showTitle=!("titleVisible"in e)||e.titleVisible,this._labelRotation="labelRotation"in e?e.labelRotation:0,this._ticks=new At,this._ticks._id=this._id+"_ticks",this.addChild(this._ticks),this._labels=new At,this._labels._id=this._id+"_labels",this.addChild(this._labels),this._title=new ai({text:this._titleText,fillColor:this._textColor,fontWeight:"bold"}),this._title._id=this.id+"_title",this.addChild(this._title),this._showTitle||(this._title.visibility="hidden"),this._pathPos=void 0,this._args=e}get id(){return this._id}get pathPosition(){return this._pathPos}get pathVisible(){return this._pathVisible}get attribute(){return this._attribute}get channel(){return this._channel}get orientation(){return this._orientation}get ticksVisible(){return this._tickVisible}get labelsVisible(){return this._labelVisible}get tickSize(){return this._tickSize}get tickOffset(){return this._tickOffset}get tickAnchor(){return this._tickAnchor?this._tickAnchor:"x"===this._channel||"width"===this._channel?"center":"middle"}get labelOffset(){return this._labelOffset}get labelFormat(){return this._labelFormat}get labelRotation(){return this._labelRotation}get tickValues(){return this._tickValues}get labelValues(){return this._labelValues}get titleOffset(){return this._titleOffset}get titleVisisble(){return this._showTitle}get boundsWithoutTitle(){let e=this.children.filter(e=>e.type!==i.SimpleText),t=e[0].bounds.clone();for(let i=1;i<e.length;i++)"hidden"!=e[i].visibility&&(t=t.union(e[i].bounds));return t}get strokeColor(){return this._strokeColor}get textColor(){return this._textColor}}const pi="top",fi="bottom",gi="left";function yi(e,t,r){if(e&&e.origin)return e.origin;let s=t[0].parent;if(s.type===i.Polygon)return[s.x,s.y];throw new Error('Mascot: "polarRadius"/"polarAngle" '+r+' need an explicit {origin: [x, y]} option (passed to encode(), or to gridlines()/axis() themselves) because the encoded shape has no fixed center of its own -- e.g. it came from densify() on a "line" mark rather than a "circle".')}class mi extends _i{constructor(e,t,i,r){if(super(r),this._encoding=e,this._attribute=this._encoding.attribute,this._channel=this._encoding.channel,this._scale=t,this._elems=i,this._flip="flip"in r&&r.flip,this._posArg="x"==this._channel||"width"==this._channel?r.pathY:r.pathX,this._orientation="orientation"in r?r.orientation:"x"===this._channel||"width"==this._channel?fi:gi,this._titleText="title"in r?r.title:this._encoding.sourceAttribute??this._encoding.attribute,this._path="angle"===this._channel||"polarAngle"===this._channel?new Qt({strokeColor:this._strokeColor,id:this._id+"_path"}):new jt({strokeColor:this._strokeColor,id:this._id+"_path"}),this._pathVisible||(this._path.visibility="hidden"),this.addChild(this._path),this.createTicksLabels(r),e.dataTable.type(this._attribute)!==a.Date||"labelFormat"in r||(this._labelFormat="%m/%d/%y"),"polarRadius"===this._channel&&"rotation"in r){let[e,t]=this.origin;this._rotate=[-r.rotation,e,t]}"polarAngle"===this._channel&&(this._radius="radius"in r?r.radius:100)}get radius(){return this._radius}get origin(){return yi(this._args,this._elems,"axis")}isFlipped(){return this._flip}get elements(){return this._elems}get scale(){return this._scale}get encoding(){return this._encoding}get includeZero(){return this._encoding.includeZero}createTicksLabels(t){"tickValues"in t?(this._tickValues=t.tickValues,this._labelValues="labelValues"in t?t.labelValues:t.tickValues):(this._tickValues=lt(this._scale,this._channel,this._elems,this),this._labelValues="labelValues"in t?t.labelValues:this._tickValues),this._ticks.removeAll();for(let e=0;e<this._tickValues.length;e++){let t=new jt({strokeColor:this._strokeColor,id:this._id+"_tick"+e});this._tickVisible||(t.visibility="hidden"),this._ticks.addChild(t)}this._labels.removeAll();let i,r=this._encoding.dataTable.type(this._attribute);if("labelValues"in t)i=function(e){return e};else switch(r){case a.Date:i=e.utcFormat(this._labelFormat);break;case a.String:i=function(e){return e};break;default:i=e.format(this._labelFormat)}for(let[e,t]of this._labelValues.entries()){let r=new ai({text:i(t),fontSize:this._fontSize,fillColor:this._textColor,id:this._id+"_label"+e});this._labelVisible||(r.visibility="hidden"),this._labels.addChild(r)}this._title._text=this._titleText}}class bi{constructor(t,i){switch(this._id="scale_"+s(),this._type=t,i&&(this._args=i),t){case"linear":this._scale=e.scaleLinear();break;case"point":this._scale=e.scalePoint();break;case"band":this._scale=e.scaleBand().padding(0);break;case"ordinal":this._scale=e.scaleOrdinal();break;case"ordinalColor":this._scale=e.scaleOrdinal(e[i.scheme]);break;case"power":this._scale=e.scalePow().exponent(2);break;case"sqrt":this._scale=e.scalePow().exponent(.5);break;case"log":this._scale=e.scaleLog();break;case"identity":case"time":this._scale=e.scaleTime();break;case"sequentialColor":i.scheme?this._scale=e.scaleSequential(e[i.scheme]):this._scale=e.scaleSequential()}}get id(){return this._id}get domain(){return this._scale.domain()}set domain(e){this._scale.domain(e)}get range(){return this._scale.range()}set range(e){this._scale.range(e)}get rangeExtent(){let e=this._scale.range();return Math.abs(e[1]-e[0])}set rangeExtent(e){let t=this._scale.range();t[0]<t[1]?this._scale.range([t[0],t[0]+e]):this._scale.range([t[1]+e,t[1]])}get type(){return this._type}map(e){return this._scale(e)}invert(t,i){let r=e.min(this._scale.range()),s=e.max(this._scale.range()),n=t;if(i||(n=e.max([r,e.min([t,s])])),"time"===this._type)return this._scale.invert(n).getTime();if(["point","band","ordinal","ordinalColor"].includes(this._type)){return this._scale.domain().reduce((e,t)=>{let i=this._scale(t);"band"===this._type&&(i+=this._scale.bandwidth()/2);let r=this._scale(e);return"band"===this._type&&(r+=this._scale.bandwidth()/2),Math.abs(i-n)<Math.abs(r-n)?t:e})}return this._scale.invert(n)}}function xi(e){if(e.scaleType)return new bi(e.scaleType);if(e._baseEnc&&e._baseEnc.scales.length>0){let t=e._baseEnc.scales[0];return new bi(t.type,t._args)}if("text"===e.channel||"src"===e.channel||"path"===e.channel)return new bi("ordinal");switch(e.dataTable.type(e.attribute)){case a.Boolean:break;case a.Date:return new bi("time");case a.String:if("count"==e.aggregator)return new bi("linear");if(e.channel.indexOf("Color")>=0||"fillGradient"===e.channel||"strokeGradient"===e.channel){let t={};return t.scheme=e.colorScheme?e.colorScheme:"schemeCategory10",new bi("ordinalColor",t)}return new bi("point");default:return["strokeColor","fillColor","fillGradient","strokeGradient"].indexOf(e.channel)>=0?e.mapping?new bi("linear"):new bi("sequentialColor",{scheme:e.colorScheme}):new bi("linear")}}const vi=["schemeBrBG","schemePRGn","schemePiYG","schemePuOr","schemeRdBu","schemeRdGy","schemeRdYlBu","schemeRdYlGn","schemeSpectral"],wi=["schemeBlues","schemeGreens","schemeGreys","schemeOranges","schemePurples","schemeReds","schemeBuGn","schemeBuPu","schemeGnBu","schemeOrRd","schemePuBuGn","schemePuBu","schemePuRd","schemeRdPu","schemeYlGnBu","schemeYlGn","schemeYlOrBr","schemeYlOrRd"];class Ei extends jt{constructor(e,t,r,n,a){super(a),this._type=i.Gridlines,this._id=this._type+s(),this._attribute=t,this._channel=e,this._scale=r,this._elems=n,this._args=a,"strokeColor"in a||(this.styles.strokeColor="#ddd"),"opacity"in a||(this.styles.opacity=.5),this.updateValues(),this._lines=[]}updateValues(){"values"in this._args?this._values=this._args.values:this._scale?this._values=lt(this._scale,this._channel,this._elems):this._values=this._elems.map(e=>e.datum[this._attribute])}get type(){return this._type}get id(){return this._id}getSVGPathData(){let e="";if("polarRadius"===this._channel)for(let t of this._lines)e+="M "+t.x+" "+t.y+" m -"+t.r+" 0 a "+t.r+" "+t.r+" 0 1 0 "+2*t.r+" 0 a "+t.r+" "+t.r+" 0 1 0 -"+2*t.r+" 0 ";else for(let t of this._lines)e+=["M",t.x1,t.y1].join(" ")+[" L",t.x2,t.y2].join(" ")+" ";return e}_updateBounds(){if("polarRadius"===this._channel){let e=this._lines.map(e=>new se(e.x-e.r,e.y-e.y,2*e.r,2*e.r));this._bounds=ne(e)}else{let e=this._lines.map(e=>e.x1).concat(this._lines.map(e=>e.x2)),t=this._lines.map(e=>e.y1).concat(this._lines.map(e=>e.y2)),i=d3.min(e),r=d3.max(e),s=d3.min(t),n=d3.max(t);this._bounds=new se(i,s,r-i,n-s)}}get elements(){return this._elems}get values(){return this._values}get channel(){return this._channel}get attribute(){return this._attribute}get scale(){return this._scale}get origin(){return yi(this._args,this._elems,"gridlines")}get lines(){return this._lines}set lines(e){this._lines=e}}class Ai{constructor(e,t,i,r,n){this._id="encoding_"+s(),this._elem=e,this._channel=t,this._attribute=i,this._table=n.table,this._aggregator=r,this._includeZero=n.includeZero,this._flipScale=n.flipScale,this._mapping=n.mapping,this._preferredRangeExtent=n.rangeExtent,this._preferredRangeStart=n.rangeStart,this._preferredDomain=n.domain,this._preferredRange=n.range,this._preferredOrigin=n.origin,this._scaleType=n.scaleType,this._colorScheme=n.scheme,this._forLegend=n.forLegend,this._sourceAttribute=n.sourceAttribute??null,n.shareScale&&(this._baseEnc=n.shareScale),this._scales=[],this._elemGroups=[],this._elem2scale={},this._refElements=[],["width","height","radius","angle","thickness","polarRadius","strokeWidth","area"].indexOf(this._channel)>=0&&(this._includeZero=!0),this.initialize()}get id(){return this._id}initialize(){if(this._scales=[],this._elemGroups=[],"vertex"===this._elem.type){let e,t=Ne(this._elem),i=we(this._elem.parent);if("x"!==this._channel&&"y"!==this._channel||!t.layout||t.layout.type!=fe.GRID)e=mt(this._elem.parent)||yt(this._elem.parent)?i.map(e=>Ce(this._elem,[e])):[Ce(this._elem,i)];else{e=("x"===this._channel?t.layout.getElementsByCol(!0,this._elem.parent):t.layout.getElementsByRow(!0,this._elem.parent)).map(e=>Ce(this._elem,e))}for(let t of e)this._createScaleForVertexIndices(t)}else if("x"===this._channel||"y"===this._channel){let e=this._elem,t=Ne(e);if(t.layout&&t.layout.type==fe.GRID){let i="x"===this._channel?t.layout.getElementsByCol(!0,e):t.layout.getElementsByRow(!0,e);for(let e of i)this._createScaleForElems(e)}else{let e=we(this._elem);this._createScaleForElems(e)}}else if("angle"===this._channel){let e=we(this._elem).reduce((e,t)=>{const i=t.parent.id;return e[i]||(e[i]=[]),e[i].push(t),e},{}),t=Object.values(e);for(let e of t)this._createScaleForElems(e)}else{let e=we(this._elem);this._createScaleForElems(e)}}_createScaleForElems(e){this._elemGroups.push(e);var t=xi(this);this._scales.push(t);for(let i of e)this._elem2scale[i.id]=t}_createScaleForVertexIndices(e){this._elemGroups.push({type:"vertexIndices",groups:e});var t=xi(this);this._scales.push(t);for(let i of e)for(let e of i.indices)this._elem2scale[Ae(i.parent,e)]=t}refreshElementMappings(){if(1===this._scales.length)if(this._elem2scale={},"vertex"===this._elem.type){let e=we(this._elem.parent),t=Ce(this._elem,e);this._elemGroups=[{type:"vertexIndices",groups:t}];for(let e of t)for(let t of e.indices)this._elem2scale[Ae(e.parent,t)]=this._scales[0]}else{let e=we(this._elem);this._elemGroups=[e];for(let t of e)this._elem2scale[t.id]=this._scales[0]}}getScale(e){return this._elem2scale[e.id]}getAttrValue(t,i,r){let s=(i?this.getScale(i):this._scales[0]).invert(t,r),n=this._attribute;if(this.dataTable.type(n)===a.Date){const t=this.dataTable.values(n).slice().sort((e,t)=>e-t);let i=e.bisectLeft(t,s);return i=Math.min(i,t.length-1),i>0&&Math.abs(t[i-1]-s)<Math.abs(t[i]-s)&&i--,t[i]}return s}getChannelValue(e,t){return(t?this.getScale(t):this._scales[0]).map(e)}getElements(e){let t=this._scales.indexOf(e);return this._elemGroups[t]}getNormalizedElements(e){let t=this.getElements(e);return t&&"vertexIndices"===t.type?Array.from(new Set(t.groups.map(e=>e.parent))):t}get elementGroups(){return this._elemGroups}get element(){return this._elem}get channel(){return this._channel}get origin(){return this._preferredOrigin}get attribute(){return this._attribute}get sourceAttribute(){return this._sourceAttribute}set attribute(e){let t=this._attribute;this._attribute=e;for(let t of this._refElements)t instanceof mi?(t._attribute=e,t.createTicksLabels({}),t._titleText&&(t._titleText=this._sourceAttribute??e)):t instanceof Ei&&(t._attribute=e,t.updateValues());const i=this._elem.scene._depGraph.getVariable(xe.ATTRIBUTE,t,this.dataTable,this);i&&(i._attribute=e,this._elem.scene.onChange(xe.ATTRIBUTE,e,this.dataTable,this))}get dataTable(){return this._table}get aggregator(){return this._aggregator}hasMultipleScales(){return this._scales.length>0}get scales(){return this._scales}getRangeStart(t){let i=this.getScale(t);return e.min(i.range)}getRangeExtent(e){return this.getScale(e).rangeExtent}get domain(){if(1===this._scales.length)return this._scales[0].domain;throw new Error("AttributeEncoding: multiple scales exist, specify element to get domain.")}get rangeExtent(){if(1===this._scales.length)return this._scales[0].rangeExtent;throw new Error("AttributeEncoding: multiple scales exist, specify element to get rangeExtent.")}get scaleType(){return this._scaleType}set scaleType(e){this._scaleType=e}getDomain(e){return this.getScale(e).domain}set domain(e){this._preferredDomain=e;for(let t of this._scales)t._scale.domain(e);for(let e of this._refElements)e instanceof mi&&e.createTicksLabels({});this._elem.scene.onChange(xe.ATTR_VALUE,this)}set rangeExtent(e){let t=e<1?1:Math.round(e);for(let e of this._scales)e.rangeExtent=t;for(let e of this._refElements)e instanceof mi&&e.createTicksLabels({});this._elem.scene.onChange(xe.PROPERTY,ze.RANGE_EXTENT,this)}set includeZero(e){this._includeZero=e;for(let e of this._refElements)e instanceof mi&&e.createTicksLabels({});this._elem.scene.onChange(xe.PROPERTY,ze.INCLUDE_ZERO,this)}get includeZero(){return this._includeZero}set flipScale(e){this._flipScale=e,this._elem.scene.onChange(xe.PROPERTY,ze.FLIP_SCALE,this)}get flipScale(){return this._flipScale}set mapping(e){this._mapping=e}get mapping(){return this._mapping}set colorScheme(e){this._colorScheme=e}get colorScheme(){return this._colorScheme}addRefElement(e){this._refElements.indexOf(e)<0&&this._refElements.push(e)}get refElements(){return this._refElements}clearRefElements(){this._refElements=[]}zoom(t,i,r,s){let n=s||this._elem,a=this.getDomain(n),o=e.min(a),l=e.max(a),h="log"!==this._scales[0].type,c=this.getAttrValue(i,n,h),d=o-(c-o)*t*r,u=l+(l-c)*t*r;d!==u&&(!h&&d<=0||(this.domain=[d,u]))}}function Ci(e,t,r,s={}){let n={channel:t,attribute:r,...s};if("rowId"===n.attribute&&(n.attribute=D),function(e,t,i){if(!e||!t||!i)throw new Error("encode(elem, channel, attribute) — all three arguments are required");if(!Object.values(Me).includes(t))throw new Error(`Unknown channel "${t}"`);let r=B(e);if(r&&r.tree){if(i.indexOf(".")>0&&!r.tree.nodeTable.has(i.split(".")[1]))throw new Error(`Data attribute "${i}" does not exist in the data table`)}else if(!r||!r.has(i))throw new Error(`Data attribute "${i}" does not exist in the data table`)}(e,t,r),n.shareScale){let e=n.shareScale;if(e.channel!=n.channel&&e.channel.indexOf("Color")<0&&n.channel.indexOf("Color")<0)throw new Error("Cannot share scales between "+e.channel+" and "+n.channel+" encodings");n.scheme=n.shareScale.colorScheme}!function(e){let t;"vertex"===e.type&&e.parent.type===i.Area?t=e.parent:e.type===i.Area&&(t=e),t&&!t._refBounds&&we(t).forEach(e=>e._refBounds=e.bounds.clone())}(e);let a=n.aggregator?n.aggregator:"sum";n.table=B(e);let o=new Ai(e,n.channel,n.attribute,a,n),l=e.scene;return l._addAttributeEncoding(o),st(o,l._depGraph,n.shareScale),n.shareScale?l.onChange(xe.ATTR_VALUE,o):l.onChange(xe.CHANNEL,n.channel,e),o}function Si(e,t,i,r){for(let s=t;s<i;s++)e._vertices._xs[s]=r;e._dirty=!0}function Ri(e,t,i,r){for(let s=t;s<i;s++)e._vertices._xs[s]=r(s);e._dirty=!0}function ki(e,t,i,r){for(let s=t;s<i;s++)e._vertices._ys[s]=r;e._dirty=!0}function Ti(e,t,i,r){for(let s=t;s<i;s++)e._vertices._ys[s]=r(s);e._dirty=!0}function Oi(e,t,i){return"number"==typeof t?function(e,t){if(!Number.isInteger(t)||t<1)throw new Error("Repeat count must be a positive integer");let i=[];for(let e=0;e<t;e++)i.push({index:e});let r=new V(i,"from count");return Ii(e,r)}(e,t):function(e){if(!e||"object"!=typeof e||Array.isArray(e))return!1;if(e instanceof V||e instanceof G||e instanceof j)return!1;let t=Object.values(e);return t.length>0&&t.every(e=>"number"==typeof e)}(t)?function(e,t,i){let r=[];for(let e of Object.keys(t)){let i=t[e];if(!Number.isInteger(i)||i<0)throw new Error("Repeat group counts must be non-negative integers: "+e+" = "+i);for(let t=0;t<i;t++)r.push({group:e})}if(0===r.length)throw new Error("Repeat counts must include at least one group with a positive count");let s=new V(r,"from group counts");return Ii(e,s,i)}(e,t,i):Ii(e,t,i)}function Ii(e,t,r){let s=Ie(e),o=r||{};if(o.attribute=o.attribute||D,function(e,t,i){if(!e||void 0===t)throw new Error("Incomplete information to do repeat. You must specify an element, a categorical data attribute and a data table");if(t instanceof G||t instanceof j){if(!Array.isArray(e)||2!==e.length)throw new Error("To repeat with a tree or a network, you need to provide two marks, one for node and one for link")}else t instanceof V&&n(i.attribute,t);if(i.layout&&!(i.layout instanceof _e))throw new Error("Invalid layout: "+i.layout)}(e,t,o),t instanceof G||t instanceof j){let r=e[0].parent,n=e[1].parent,[a,o]=function(e,t,r,s){let n=t.dataScope?t.dataScope:N(s.nodeTable),a=L(n,U),o=Gi(e,{type:i.Collection}),l=Gi(e,{type:i.Collection}),h={};l.dataScope=n,l.addChild(t);for(let e=1;e<a.length;e++){let e=Fi(t);l.addChild(e)}l.children.forEach((e,t)=>{e.dataScope=a[t],e.links=[],h[R(e.dataScope,U)]=e});let c=r.dataScope?r.dataScope:N(s.linkTable),d=L(c,D);o.dataScope=c,o.addChild(r);for(let e=1;e<d.length;e++){let e=Fi(r);o.addChild(e)}o.children.forEach((e,t)=>e.dataScope=d[t]);let u=s instanceof G?"parent":"source",_=s instanceof G?"child":"target";for(let e of o.children){let t=R(e.dataScope,u),i=R(e.dataScope,_),r=h[t],s=h[i];e.source=r,e.target=s,r.links.push(e),s.links.push(e)}return[l,o]}(s,e[0],e[1],t);return Ze(r,e[0],s._depGraph),Ze(n,e[1],s._depGraph),qe(a,s._depGraph),qe(o,s._depGraph),$e(a,e[0],s._depGraph),$e(a.parent,a,s._depGraph),$e(o,e[1],s._depGraph),$e(o.parent,o,s._depGraph),[a,o]}if(t instanceof V){let r=e.parent,n=function(e,t,r,s){let n=s.type(r);if(n!=a.String&&n!=a.Date&&n!=a.Integer)throw new Error("Repeat only works on a string or date attribute: "+r+" is "+n);if(!function(e){if(Array.isArray(e)){if(1===e.length)return Ni(e[0]);for(let t of e)if(!de(t)||t.dataScope)return!1;return!0}return Ni(e)}(t))throw new Error("The "+t.type+" is not repeatable");return function(e,t,r,s){let n=t.dataScope?t.dataScope:N(s),a=L(n,r),o=Gi(e,{type:i.Collection});o.dataScope=n,o.addChild(t),t._refBounds||(t._refBounds=t.bounds.clone());for(let e=1;e<a.length;e++){let e=Fi(t);o.addChild(e)}return o.children.forEach((e,t)=>e.dataScope=a[t]),o}(e,t,r,s)}(s,e,o.attribute,t);return Ze(r,e,s._depGraph),qe(n,s._depGraph),$e(n,e,s._depGraph),$e(n.parent,n,s._depGraph),function(e,t,i,r){let s=r.getVariable(xe.ITEMS,i),n=r.createOneWayDependency(me.REPOPULATE);n._collection=e,n._repeatAttr=t,r.connect(s,n);let a=e.children[0],o=new Set([a,...Le(a)]);for(let e of o)r.connect(n,r.getVariable(xe.DATASCOPE,e))}(n,o.attribute,t,s._depGraph),o.layout&&(n.layout=o.layout),n}}function Ni(e){return!(!de(e)&&e.type!=i.Glyph||e.dataScope)||e.type===i.Collection&&C(e.firstChild.dataScope)>1}class Li extends _e{constructor(e){super(),this.type=fe.GRID,this._numCols=e.numCols,this._numRows=e.numRows,this._start="start"in e?e.start:Tt.TopLeft,this._direction="direction"in e?e.direction:kt.RowFirst,this._rowGap="rowGap"in e&&void 0!==e.rowGap?e.rowGap:5,this._colGap="colGap"in e&&void 0!==e.colGap?e.colGap:5,this._cellHorzAlignment="horzCellAlignment"in e&&ge("h",e.horzCellAlignment)?e.horzCellAlignment:he.LEFT,this._cellVertAlignment="vertCellAlignment"in e&&ge("v",e.vertCellAlignment)?e.vertCellAlignment:he.BOTTOM,this._rowOffset="rowOffset"in e&&void 0!==e.rowOffset?e.rowOffset:0,this._colOffset="colOffset"in e&&void 0!==e.colOffset?e.colOffset:0,this._numCols||this._numRows||(this._numRows=1),this._includeInvisible=!1,this._left=void 0,this._top=void 0,this._cellBounds=void 0,this._grid=void 0}get includeInvisible(){return this._includeInvisible}set includeInvisible(e){this._includeInvisible=e}get cellBounds(){return this._cellBounds}get numCols(){return this._numCols?this._numCols:this._numRows?Math.ceil(this.group.children.length/this._numRows):0}set numCols(e){this._numCols=e}set numRows(e){this._numRows=e}get numRows(){return this._numRows?this._numRows:this._numCols?Math.ceil(this.group.children.length/this._numCols):0}get rowOffset(){return this._rowOffset}set rowOffset(e){this._rowOffset=e}get colOffset(){return this._colOffset}set colOffset(e){this._colOffset=e}clone(){let e=new Li({numCols:this._numCols,numRows:this._numRows,start:this._start,direction:this._direction,colGap:this._colGap,rowGap:this._rowGap,horzCellAlignment:this._cellHorzAlignment,vertCellAlignment:this._cellVertAlignment,rowOffset:this._rowOffset,colOffset:this._colOffset});return e._includeInvisible=this._includeInvisible,e._left=this._left,e._top=this._top,this._cellBounds&&(e._cellBounds=this._cellBounds.map(e=>e.clone())),e}getElementsByRow(e,t){let i=[],r=this.group.children;for(let t=0;t<this.numRows;t++){let s=this._grid[t].filter(e=>null!=e).map(e=>r[e]);if(e){let e=[];for(let t of s)e=e.concat(Le(t));i.push(e)}else i.push(s)}return t&&(i=this._filterElementsByExample(i,t)),i}getElementsByCol(e,t){let i=[],r=this.group.children,s=this._grid;for(let t=0;t<this.numCols;t++){let n=s.map(e=>e[t]).filter(e=>null!=e).map(e=>r[e]);if(e){let e=[];for(let t of n)e=e.concat(Le(t));i.push(e)}else i.push(n)}return t&&(i=this._filterElementsByExample(i,t)),i}getElementsByCell(e,t){let i=[],r=this.group.children;for(let t=0;t<r.length;t++)if(e){let e=Le(r[t]);i.push(e)}else i.push(r[t]);return t&&(i=this._filterElementsByExample(i,t)),i}_filterElementsByExample(e,t){let i;return"vertex"===t.type?(i=e.map(e=>e.filter(e=>e.classId===t.parent.classId)),i=i.map(e=>Ee(t,e))):"segment"===t.type?(i=e.map(e=>e.filter(e=>e.classId===t.parent.classId)),i=i.map(e=>Se(t,e))):i=e.map(e=>e.filter(e=>e.classId===t.classId)),i}getIndex(e){let t=e;for(;t&&t.parent!==this.group;)t=t.parent;return this.group.children.indexOf(t)}getRowCol(e){let t,i;switch(this._direction){case kt.RowFirst:t=Math.floor(e/this.numCols),i=e%this.numCols;break;case kt.ColumnFirst:t=e%this.numRows,i=Math.floor(e/this.numRows);break;default:throw new Error("Invalid fill direction. Use 'row_first' or 'column_first'.")}return this._start.toLowerCase().includes("bottom")&&(t=this.numRows-1-t),this._start.toLowerCase().includes("right")&&(i=this.numCols-1-i),{row:t,col:i}}get startCorner(){return this._start}set startCorner(e){this._start=e}get direction(){return this._direction}set direction(e){this._direction=e}}class Pi extends At{constructor(e,t){super(),this._type=i.Legend,this._id=this._type+s(),this._enc=e,this._textColor="textColor"in t?t.textColor:"#555",this._strokeColor="strokeColor"in t?t.strokeColor:"#555",this._fontSize="fontSize"in t?t.fontSize:"12px",this._x="x"in t?t.x:100,this._y="y"in t?t.y:100,this._showTitle=!("showTitle"in t)||t.showTitle,this._orientation="orientation"in t?t.orientation:It,this._numberFormat=t.numberFormat?t.numberFormat:""}get attribute(){return this._enc.attribute}get channel(){return this._enc.channel}get attributeType(){return B(this._enc.element).getFieldType(this.attribute)}get orientation(){return this._orientation}get textColor(){return this._textColor}}class Vi extends Pi{constructor(e,t){super(e,t),"numCols"in t||"numRows"in t?(this._numCols=t.numCols,this._numRows=t.numRows):this._orientation===It?this._numCols=1:this._numRows=1,this._initialize()}_initialize(){let e=this._enc.element.scene,t=this._enc.attribute,i=this._enc.scales[0],r=new V(i.domain.map(e=>({category:e,value:i.map(e)}))),s=r.unique("category").sort((e,t)=>t.length-e.length)[0],n=this._enc.element,a=n instanceof jt&&n.closed&&"strokeColor"!==this._enc.channel?n.strokeWidth:0;if(this._orientation===It){let i=0;this._showTitle&&(this.addChild(new ai({fillColor:this._textColor,fontSize:this._fontSize,text:t,x:this._x,y:this._y,anchor:["left","top"]})),i=parseFloat(this._fontSize)+5);let o=e.mark("rect",{top:this._y+2+i,left:this._x,width:10,height:10,strokeWidth:a,strokeColor:n.strokeColor,opacity:n.opacity}),l=e.mark("text",{text:s,fillColor:this._textColor,fontSize:this._fontSize,x:this._x+20,y:this._y+i+12+a,anchor:["left","bottom"]}),h=Oi(e.glyph(o,l),r);Ci(l,"text","category",{forLegend:!0}),Ci(o,"fillColor","category",{shareScale:this._enc,forLegend:!0}),h.layout=new Li({numCols:this._numCols,numRows:this._numRows}),this.addChild(h)}else{let t=e.mark("rect",{top:this._y,left:this._x,width:10,height:10,strokeWidth:a,strokeColor:n.strokeColor,opacity:n.opacity}),i=e.mark("text",{text:s,fillColor:this._textColor,fontSize:this._fontSize,x:this._x+15,y:this._y,anchor:["left","top"]}),o=Oi(e.glyph(t,i),r);Ci(i,"text","category",{forLegend:!0}),Ci(t,"fillColor","category",{shareScale:this._enc,forLegend:!0}),o.layout=new Li({numCols:this._numCols,numRows:this._numRows,colGap:15}),this.addChild(o)}}}class Mi extends Pi{constructor(e,t){super(e,t),this._initialize()}_initialize(){let t,i,r,s=this._enc.element.scene,n=this._enc.attribute;if(this._orientation==It?(t=15,i=300):(t=300,i=15),this._showTitle){let e=s.mark("text",{fillColor:this._textColor,text:n,x:this._x+t/2,y:this._y,anchor:["center","middle"]});this.addChild(e),r=20}else r=0;let o,l=s.mark("rect",{top:this._y+r,left:this._x,width:t,height:i,strokeWidth:0,opacity:this._enc.element.opacity}),h=Object.values(this._enc.attrValues),c=[e.min(h),e.max(h)],d=this._enc.mapping,u=[],_=[],p=e.format(this._numberFormat);if(d){let e=Object.keys(d).map(e=>parseFloat(e)).sort((e,t)=>e-t);this._orientation==It?(o=new di({x1:0,y1:100,x2:0,y2:0}),e.forEach(e=>{let n=(e-c[0])/(c[1]-c[0]);o.addStop(100*n,d[e],1);let a=s.mark("line",{x1:this._x+t,x2:this._x+t+5,y1:this._y+i-n*i+r,y2:this._y+i-n*i+r,strokeColor:this._strokeColor});_.push(a);let l=s.mark("text",{fillColor:this._textColor,text:this._numberFormat?p(e):e.toFixed(0),x:this._x+t+5+5,y:this._y+i-n*i+r,anchor:["left","middle"]});u.push(l)})):(o=new di({x1:0,y1:0,x2:100,y2:0}),e.forEach(e=>{let n=(e-c[0])/(c[1]-c[0]);o.addStop(100*n,d[e],1);let a=s.mark("line",{x1:this._x+n*t,x2:this._x+n*t,y1:this._y+20-5+r,y2:this._y+i+5+r,strokeColor:this._strokeColor});_.push(a);let l=s.mark("text",{fillColor:this._textColor,text:this._numberFormat?p(e):e.toFixed(0),x:this._x+n*t,y:this._y+i+5+r,anchor:["center","top"]});u.push(l)}))}else{let e=this._enc.scales[0].domain,l=B(this._enc.element),h=l.type(n),c=[],d=h===a.Date?l.getUniqueFieldValues(n):[...new Set(Object.values(this._enc.attrValues))];if(d.length<=10)c=d,c.sort((e,t)=>e-t);else if(h===a.Date){d.sort((e,t)=>e-t);for(let e=0;e<d.length;e+=Math.ceil(d.length/10))c.push(d[e])}else{let t=(e[1]-e[0])/9;for(let i=0;i<10;i++)c.push(e[0]+i*t)}let f=0,g=Math.abs((c[c.length-1]-c[0])/c.length);for(;g>0&&g<1&&f<10;)g*=10,f++;c=c.map(e=>e.toFixed(f)),this._orientation==It?(o=new di({x1:0,y1:100,x2:0,y2:0}),c.forEach(c=>{let d=(c-e[0])/(e[1]-e[0]);o.addStop(100*d,this._enc.scales[0].map(c),1);let f=s.mark("line",{x1:this._x+t,x2:this._x+t+5,y1:this._y+i-d*i+r,y2:this._y+i-d*i+r,strokeColor:this._strokeColor});_.push(f);let g=s.mark("text",{fillColor:this._textColor,text:h===a.Date?l.raw(n,c):this._numberFormat?p(c):c,x:this._x+t+5+5,y:this._y+i-d*i+r,anchor:["left","middle"]});u.push(g)})):(o=new di({x1:0,y1:0,x2:100,y2:0}),c.forEach(c=>{let d=(c-e[0])/(e[1]-e[0]);o.addStop(100*d,this._enc.scales[0].map(c),1);let p=s.mark("line",{x1:this._x+d*t,x2:this._x+d*t,y1:this._y+i+r,y2:this._y+i+5+r,strokeColor:this._strokeColor});_.push(p);let f=s.mark("text",{fillColor:this._textColor,text:h===a.Date?l.raw(n,c):c,x:this._x+d*t,y:this._y+i+5+r,anchor:["center","top"]});u.push(f)}))}l.styles.fillColor=o,this.addChild(l);for(let e of u)this.addChild(e);for(let e of _)this.addChild(e)}}class Bi extends _i{constructor(e,t,i,r){super(r),this._elems=e,this._attribute=i,this._channel=t,this._posArg="x"==this._channel||"width"==this._channel?r.pathY:r.pathX,this._labelAttribute=r.labelAttribute,this._orientation="orientation"in r?r.orientation:"x"===this._channel||"width"==this._channel?fi:gi,this._titleText="title"in r?r.title:this._attribute,this._path="angle"===this._channel?new Qt({strokeColor:this._strokeColor,id:this._id+"_path"}):new jt({strokeColor:this._strokeColor,id:this._id+"_path"}),this._pathVisible||(this._path.visibility="hidden"),this.addChild(this._path),this.createTicksLabels(r),v(this._elems[0].dataScope).type(this._attribute)!==a.Date||"labelFormat"in r||(this._labelFormat="%m/%d/%y")}get elements(){if(this.layout.type===fe.CLUSTER){const e=new Map(this._elems.map(e=>[e.datum[U],e]));return this.layout._d3Root.leaves().map(t=>e.get(t.data[U]))}return this._elems}get layout(){return this._elems[0].parent.layout}createTicksLabels(t){"tickValues"in t?(this._tickValues=t.tickValues,this._labelValues=t.tickValues):(this._tickValues=this.elements.map(e=>e.datum[this._labelAttribute?this._labelAttribute:this._attribute]),this._labelValues=this._tickValues),this._ticks.removeAll();for(let e=0;e<this._tickValues.length;e++){let t=new jt({strokeColor:this._strokeColor,id:this._id+"_tick"+e});this._tickVisible||(t.visibility="hidden"),this._ticks.addChild(t)}let i;switch(this._labels.removeAll(),v(this._elems[0].dataScope).type(this._labelAttribute?this._labelAttribute:this._attribute)){case a.Date:i=e.timeFormat(this._labelFormat);break;case a.String:i=function(e){return e};break;default:i=e.format(this._labelFormat)}for(let[e,t]of this._labelValues.entries()){let r=new ai({text:i(t),fontSize:this._fontSize,fillColor:this._textColor,id:this._id+"_label"+e});this._labels.addChild(r)}this._title._text=this._titleText}}class Di extends At{constructor(e){super(),this._type=i.Composite,this._id=e&&e.id?e.id:this._type+s()}addChild(e){let t=e.parent;super.addChild(e);let i=Ie(e)._depGraph;t&&Ze(t,e,i),$e(this,e,i)}}function Gi(e,t){let i;switch(t.type){case"collection":i=ji(t);break;case"glyph":i=function(e){let t=new Rt(e);return t}(t);break;case"axis":i=function(e){if("encoding"===e.axisType){return new mi(e.enc,e.scale,e.elems,e)}if("layout"===e.axisType){return new Bi(e.elems,e.channel,e.attribute,e)}}(t);break;case"legend":i=function(e){let t="string"===e.attrType?new Vi(e.enc,e):new Mi(e.enc,e);return t}(t);break;case"composite":i=function(e){let t=new Di(e);return t}(t);break;default:i=zi(t)}return e.addChild(i),e._itemMap[i.id]=i,i}function zi(e){let t=null;switch(e.type){case i.Circle:t=new Qt(e);break;case i.Line:var r="x1"in e?e.x1:0,s="y1"in e?e.y1:0,n="x2"in e?e.x2:100,a="y2"in e?e.y2:100;e.vertices=[[r,s],[n,a]],t=new ii(e);break;case i.Rect:var o="top"in e?e.top:0,l="left"in e?e.left:0,h="width"in e?e.width:50,c="height"in e?e.height:30;e.vertices=[[l,o],[l+h,o],[l+h,o+c],[l,o+c]],t=new li(e);break;case i.SimpleText:t=new ai(e);break;case i.RichText:t=new ci(e);break;case i.Image:t=new ei(e);break;case i.Symbol:t=new ti(e);break;case i.BundledPath:case i.Chord:case i.Path:t=new jt(e);break;case i.Arrow:t=new ni(e);break;case i.Area:t=new $t(e);break;case i.Ring:t=new hi(e);break;case i.Arc:t=new Ht(e);break;case i.BezierCurve:"vertices"in e||(e.vertices=[[0,100],[20,120],[80,180],[100,200]]),t=new Jt(e);break;case i.Polygon:t=new oi(e)}return t&&t._updateBounds(),t}function ji(e){return new St(e)}function Fi(e){switch(e.type){case i.Collection:return function(e){let t=ji({});for(let i=0;i<e.children.length;i++){let r=e.children[i];t.addChild(Fi(r))}if(t._classId=e.classId,e._layout){let i=e._layout.clone();t._layout=i,i.group=t}return t._updateBounds(),e.scene._itemMap[t.id]=t,t}(e);case i.Glyph:return function(e){let t=new Rt;for(let i of e.children)t.addChild(Fi(i));t._classId=e.classId,e.dataScope&&(t.dataScope=e.dataScope);return e.scene._itemMap[t.id]=t,t}(e);default:return function(e){let t=zi({type:e.type});e.copyPropertiesTo(t),t._classId=e.classId,t._bounds=e.bounds.clone(),e._refBounds||(e._refBounds=e.bounds.clone());if(t._refBounds=e._refBounds.clone(),e.vertices)for(let i=0;i<e.vertices.length;i++)e.vertices[i].dataScope&&(t.vertices[i].dataScope=e.vertices[i].dataScope);return e.scene._itemMap[t.id]=t,t}(e)}}class Wi extends be{constructor(e,t){super(e),this._elem=t}get element(){return this._elem}}class Ui extends be{constructor(e,t){super(e),this._item=t}get element(){return this._item}}class Yi{constructor(e){this._id=e+"_"+s(),this._type=e,this._vars=[],this._edges=[]}get vars(){return this._vars}get edges(){return this._edges}run(){console.log("-",this._type)}}class Hi{constructor(e,t,i=!0){this._id="e_"+s(),this._fromNode=e,this._toNode=t,this._isDirected=i}get id(){return this._id}get fromNode(){return this._fromNode}get toNode(){return this._toNode}get isDirected(){return this._isDirected}get operator(){return this._fromNode instanceof ye||this._fromNode instanceof Yi?this._fromNode:this._toNode}}class Xi extends be{constructor(e,t){super(e),this._encs={},this._encs[t.channel+"_"+ft(t.element)]=t,this._initialized=!1}addLinkedEncoding(e){this._encs[e.channel+"_"+ft(e.element)]=e}getEncoding(e,t){let i=e+"_"+ft(t);return this._encs[i]}get encodings(){return Object.values(this._encs)}get initialized(){return this._initialized}set initialized(e){this._initialized=e}}class qi extends be{constructor(e,t){super(e),this._encs=[t],this._valueMap={}}addLinkedEncoding(e){this._encs.push(e)}get encodings(){return this._encs}get attrValues(){return this._valueMap}set attrValues(e){this._valueMap=e}}function Ki(e){if("number"!=typeof e.radius)throw new Error('Mascot: encode(..., "polarRadius", ...) needs an explicit {rangeExtent: N} (or {range: [...]}) option because the encoded shape has no fixed radius of its own -- e.g. it came from densify() on a "line" mark rather than a "circle".');return e.radius}class Zi extends ye{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof qi),t=this.outputVar,r=t.encodings,s=r[0],n=s.channel,o=s.attribute,l=e.encodings[0].dataTable.type(e.encodings[0].attribute),h=Object.values(e.attrValues);if("angle"===s.channel&&[i.Arc,i.Pie].indexOf(s.element.type)>=0)for(let t of e.encodings)for(let e of t.scales){let i=t.getElements(e).map(e=>t.attrValues[e.id]);e.domain=s._preferredDomain?s._preferredDomain:t.dataTable.tree?[0,t.dataTable.tree.getRoot()[o]]:this._getDomainForNumbers(i),console.log("domain for",o,e.domain)}else{let t;t=s._preferredDomain?s._preferredDomain:l==a.String||"text"===e.encodings[0].channel?this._getDomainForStrings(h):this._getDomainForNumbers(h);for(let i of e.encodings)for(let e of i.scales)e.domain=t.slice()}for(let e=0;e<s.scales.length;e++){let i=s.scales[e],a=s.getElements(i),o=this._buildRange(n,a,s,t);if(o)for(let t of r)t.scales[e].range=o}t.initialized=!0}_getDomainForNumbers(t){let i=this.outputVar.encodings[0],r=[e.min(t),e.max(t)];if(i.includeZero&&r[0]>0&&(r=[0,e.max(t)]),i.mapping)r=Object.keys(i.mapping),r=r.map(e=>parseFloat(e)),r.sort((e,t)=>e-t);else if("sequentialColor"===i.scales[0].type){if(r[0]<0&&r[1]>0){let e=Math.max(Math.abs(r[0]),Math.abs(r[1]));r=[-e,e]}}else if("angle"===i.channel){r=[0,Object.values(t).reduce((e,t)=>e+t,0)]}return r}_getDomainForStrings(e){let t,i=this.outputVar,r=i.encodings[0];return t="count"==i.encodings[0].aggregator?[0,Math.max(...e)]:Array.from(new Set(e)),r.mapping&&(t=Object.keys(r.mapping)),t}_buildRange(e,t,i,r){if(i._preferredRange)return i._preferredRange;if("x"===e)return this._buildXRange(t,i,r);if("y"===e)return this._buildYRange(t,i,r);if(["width","height","radius","area","fontSize","polarRadius","strokeWidth"].includes(e))return this._buildSizeRange(t,i,r);if(e.indexOf("Color")>0||"fillGradient"===e||"strokeGradient"===e)return this._buildColorRange(t,i);if("angle"===e)return this._buildAngleRange(t,i);if("polarAngle"===e)return[0,360];if("thickness"===e)return this._buildThicknessRange(t,i,r);if("src"===e||"path"===e){let e=i.scales[0].domain;return i.mapping?e.map(e=>i.mapping[e+""]):e.slice()}}_buildThicknessRange(e,t,i){let r=e.map(e=>e.outerRadius-e.innerRadius);return[0,i.initialized?t.getRangeExtent(e[0]):t._preferredRangeExtent?t._preferredRangeExtent:Math.max(...r)]}_buildAngleRange(e,t){return[0,360]}_buildColorRange(t,i){if(i.mapping){return i.scales[0].domain.map(e=>i.mapping[e+""])}if("sequentialColor"===i.scales[0].type){let t=this.outputVar,r=i.scales[0].domain;for(let s of t.encodings)if(!i.colorScheme)for(let t of s.scales){let i=t.domain;t._scale=e.scaleSequential(r[0]<0&&r[1]>0?e.interpolatePuOr:e.interpolateTurbo),t._scale.domain(i)}}if((vi.indexOf(i.colorScheme)>=0||wi.indexOf(i.colorScheme)>=0)&&"ordinalColor"===i.scales[0].type){let t=this.outputVar,r=i.scales[0].domain;for(let s of t.encodings)for(let t of s.scales){let s=t.domain;t._scale=e.scaleOrdinal(e[i.colorScheme][r.length]),t._scale.domain(s)}}}_buildSizeRange(e,t,r){let s,n;if(s=0,"vertexIndices"===e.type){let i=Ae(e.groups[0].parent,e.groups[0].indices[0]);return n=r.initialized?t._elem2scale[i].rangeExtent:t._preferredRangeExtent?t._preferredRangeExtent:Math.max(...this._getVertexIndexSizeValues(e,t.channel)),[0,0+n]}return n=r.initialized?t.getRangeExtent(e[0]):t._preferredRangeExtent?t._preferredRangeExtent:Math.max(...e.map(e=>"radius"===t.channel?e.refBounds.width/2:"strokeWidth"===t.channel?e.strokeWidth:"polarRadius"===t.channel?Ki(e.parent):"area"===t.channel?e.type===i.Circle?Math.PI*Math.pow(e.radius,2):e.width*e.height:"fontSize"===t.channel?parseFloat(e.fontSize):e.refBounds[t.channel])),[0,0+n]}_getVertexIndexSizeValues(e,t){let i=[];for(let r of e.groups){let e=r.parent._vertices;for(let s of r.indices)i.push("radius"===t?e._radii[s]:"strokeWidth"===t?e._strokeWidths[s]:"polarRadius"===t?Ki(r.parent):"width"===t?e._widths[s]:"height"===t?e._heights[s]:0)}return i}_buildXRange(t,i,r){let s,n,a=i.scales[0].type;if("vertexIndices"===t.type){let a=t.groups[0].parent,o=Ae(a,t.groups[0].indices[0]),l=a.refBounds?a.refBounds:a.bounds;return s=r.initialized?e.min(i._elem2scale[o].range):l.left,n=r.initialized?i._elem2scale[o].rangeExtent:i._preferredRangeExtent?i._preferredRangeExtent:l.width,i.flipScale?[s+n,s]:[s,s+n]}switch(t[0].type){case"vertex":case"segment":var o=t[0].parent.refBounds?t[0].parent.refBounds:t[0].parent.bounds;s=r.initialized?i.getRangeStart(t[0]):o.left,n=r.initialized?i.getRangeExtent(t[0]):i._preferredRangeExtent?i._preferredRangeExtent:o.width;break;default:s=r.initialized?i.getRangeStart(t[0]):i._preferredRangeStart?i._preferredRangeStart:Ne(t[0]).bounds.left+t[0].bounds.width/2,n="band"===a?t[0].bounds.width*i.scales[0].domain.length:r.initialized?i.getRangeExtent(t[0]):i._preferredRangeExtent?i._preferredRangeExtent:e.max([450,e.max(t.map(e=>e.bounds.x))-e.min(t.map(e=>e.bounds.x))])}return i.flipScale?[s+n,s]:[s,s+n]}_buildYRange(t,i,r){let s,n;if(i.scales[0].type,"vertexIndices"===t.type){let a=t.groups[0].parent,o=Ae(a,t.groups[0].indices[0]),l=a.refBounds?a.refBounds:a.bounds;return s=r.initialized?e.min(i._elem2scale[o].range):l.top,n=r.initialized?i._elem2scale[o].rangeExtent:i._preferredRangeExtent?i._preferredRangeExtent:l.height,i.flipScale?[s,s+n]:[s+n,s]}switch(t[0].type){case"vertex":case"segment":var a=t[0].parent.refBounds?t[0].parent.refBounds:t[0].parent.bounds;s=r.initialized?i.getRangeStart(t[0]):a.top,n=r.initialized?i.getRangeExtent(t[0]):i._preferredRangeExtent?i._preferredRangeExtent:a.height;break;default:s=r.initialized?i.getRangeStart(t[0]):Ne(t[0]).bounds.top+t[0].bounds.height/2,n=r.initialized?i.getRangeExtent(t[0]):i._preferredRangeExtent?i._preferredRangeExtent:450}return i.flipScale?[s,s+n]:[s+n,s]}}class $i extends ye{constructor(e){super(e)}run(){super.run()}}class Ji extends ye{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof Be&&e.property==ze.AXIS_ORIENTATION).element;e.createTicksLabels(e._args),e instanceof mi?this._runForEncoding(e):e instanceof Bi&&this._runForLayout(e),le(e._path)}_runForLayout(e){let t=e.channel,i=e.elements[0].parent.layout&&e.elements[0].parent.layout.type==fe.STACK?oe(e.elements):ae(e.elements),r=[];if("x"===t){let t=e.orientation===pi?i.top-2:i.bottom+2;e._pathPos=e._posArg?e._posArg:t,r.push([i.left,e._pathPos]),r.push([i.right,e._pathPos]),e._path.vertices=r}else if("y"===t){let t=e.orientation===gi?i.left-2:i.right+2;e._pathPos=e._posArg?e._posArg:t,r.push([e._pathPos,i.top]),r.push([e._pathPos,i.bottom]),e._path.vertices=r}else if("angle"===t){let t=e.elements[0].parent.layout;t.type===fe.CLUSTER&&(e._path._x=t.x,e._path._y=t.y,e._path._radius=t.radius)}}_runForEncoding(e){let t=e.channel,i=e.elements,r=i[0].parent.layout&&i[0].parent.layout.type==fe.STACK?oe(i):ae(i),s=[],n=Ne(i[0]);if(n&&n.clipMask&&(r=n.clipMask),"x"===t){let t,n,a=pt(i[0],"y");a?(t=Math.min(...a.getScale(i[0]).range,r.top),n=Math.max(...a.getScale(i[0]).range,r.bottom)):(t=r.top,n=r.bottom);let o=e.orientation===pi?t-2:n+2;e._pathPos=e._posArg?e._posArg:o,s.push([e.scale.range[0],e._pathPos]),s.push([e.scale.range[1],e._pathPos])}else if("width"===t){let t=e.orientation===pi?r.top-2:r.bottom+2;e._pathPos=e._posArg?e._posArg:t,s.push([r.left,e._pathPos]),s.push([r.right,e._pathPos])}else if("polarRadius"===t){let[t,i]=e.origin;e._pathPos=e._posArg?e._posArg:i,s.push([e.scale.range[0]+t,e._pathPos]),s.push([e.scale.range[1]+t,e._pathPos])}else{if("polarAngle"===t){let[t,i]=e.origin;return e._path._x=t,e._path._y=i,void(e._path._radius=e.radius)}if("y"===t){let t,n,a=pt(i[0],"x");a?(t=Math.min(...a.getScale(i[0]).range,r.left),n=Math.max(...a.getScale(i[0]).range,r.right)):(t=r.left,n=r.right);let o=e.orientation===gi?t-2:n+2;e._pathPos=e._posArg?e._posArg:o,s.push([e._pathPos,e.scale.range[0]]),s.push([e._pathPos,e.scale.range[1]])}else if("height"===t){let t=e.orientation===gi?r.left-2:r.right+2;e._pathPos=e._posArg?e._posArg:t,s.push([e._pathPos,r.bottom]),s.push([e._pathPos,r.top])}}e._path.vertices=s}}class Qi extends ye{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof Be&&e.property==ze.AXIS_PATH_POSITION).element;e instanceof mi?this._runForEncoding(e):e instanceof Bi&&this._runForLayout(e);let t=[];if("width"===e.channel||"x"===e.channel){let i=e._ticks.children.map(e=>e.vertices[0].x),r=[e._path.vertices[0].x,e._path.vertices[1].x];t.push([d3.min(i.concat(r)),e._path.vertices[0].y]),t.push([d3.max(i.concat(r)),e._path.vertices[0].y]),e._path.vertices=t}else if("height"===e.channel||"y"===e.channel){let i=e._ticks.children.map(e=>e.vertices[0].y),r=[e._path.vertices[0].y,e._path.vertices[1].y];t.push([e._pathPos,d3.min(i.concat(r))]),t.push([e._pathPos,d3.max(i.concat(r))]),e._path.vertices=t}for(let t of e._ticks.children)t._updateBounds();le(e._ticks)}_runForLayout(e){let t=e.channel;if("x"==t){let t=e.orientation==fi?e._pathPos+e.tickOffset:e._pathPos-e.tickOffset,i=e.orientation==fi?e.tickSize:-e.tickSize;for(let[r,s]of e._ticks.children.entries()){let n=e.elements[r].bounds[e.tickAnchor];s.vertices=[[n,t],[n,t+i]]}}else if("y"===t){let t=e.orientation==gi?e._pathPos-e.tickOffset:e._pathPos+e.tickOffset,i=e.orientation==gi?-e.tickSize:e.tickSize;for(let[r,s]of e._ticks.children.entries()){let n=e.elements[r].bounds[e.tickAnchor];s.vertices=[[t,n],[t+i,n]]}}else if("angle"===t){let t=e.elements[0].parent.layout;if(t.type===fe.CLUSTER){let i=t._d3Root.leaves();const r=new Map(i.map(e=>[e.data[U],[e.x,e.y]]));for(let[i,s]of e._ticks.children.entries()){let n=e.elements[i].datum[U],a=qt(r.get(n)[0])-90;s.vertices=[[t.x+r.get(n)[1]+e.elements[i].bounds.width/2,t.y],[t.x+r.get(n)[1]+e.elements[i].bounds.width/2+e.tickSize,t.y]],s._rotate=[a,t.x,t.y]}}}}_runForEncoding(e){let t=e.channel,r=ae(e.elements);if("x"==t){let t=e.orientation==fi?e._pathPos+e.tickOffset:e._pathPos-e.tickOffset,i=e.orientation==fi?e.tickSize:-e.tickSize;for(let[r,s]of e._ticks.children.entries())s.vertices=[[e.scale.map(e._tickValues[r]),t],[e.scale.map(e._tickValues[r]),t+i]]}else if("width"==t){let t=e.orientation==fi?e._pathPos+e.tickOffset:e._pathPos-e.tickOffset,s=e.orientation==fi?e.tickSize:-e.tickSize;if(!!(e.isFlipped()||e.elements[0].type===i.Area&&"right"===e.elements[0].baseline))for(let[i,n]of e._ticks.children.entries())n.vertices=[[r.left+e.scale.rangeExtent-e.scale.map(e._tickValues[i]),t],[r.left+e.scale.rangeExtent-e.scale.map(e._tickValues[i]),t+s]];else for(let[i,n]of e._ticks.children.entries())n.vertices=[[e.scale.map(e._tickValues[i])+r.left,t],[e.scale.map(e._tickValues[i])+r.left,t+s]]}else if("y"===t){let t=e.orientation==gi?e._pathPos-e.tickOffset:e._pathPos+e.tickOffset,i=e.orientation==gi?-e.tickSize:e.tickSize;for(let[r,s]of e._ticks.children.entries())s.vertices=[[t,e.scale.map(e._tickValues[r])],[t+i,e.scale.map(e._tickValues[r])]]}else if("height"===t){let t=e.orientation==gi?e._pathPos-e.tickOffset:e._pathPos+e.tickOffset,s=e.orientation==gi?-e.tickSize:e.tickSize;if(!!(e.isFlipped()||e.elements[0].type===i.Area&&"top"===e.elements[0].baseline))for(let[i,n]of e._ticks.children.entries())n.vertices=[[t,r.top+e.scale.map(e._tickValues[i])],[t+s,r.top+e.scale.map(e._tickValues[i])]];else for(let[i,n]of e._ticks.children.entries()){let a=r.bottom-e.scale.map(e._tickValues[i]);n.vertices=[[t,a],[t+s,a]]}}else if("polarRadius"===t){let t=e.orientation==fi?e._pathPos+e.tickOffset:e._pathPos-e.tickOffset,i=e.orientation==fi?e.tickSize:-e.tickSize,[r]=e.origin;for(let[s,n]of e._ticks.children.entries())n.vertices=[[r+e.scale.map(e._tickValues[s]),t],[r+e.scale.map(e._tickValues[s]),t+i]]}else if("polarAngle"===t){let[t,i]=e.origin,r=e.radius-e.tickSize/2,s=e.radius+e.tickSize/2;for(let[n,a]of e._ticks.children.entries()){let o=e.scale.map(e._tickValues[n])*Math.PI/180;a.vertices=[[t+r*Math.cos(o),i-r*Math.sin(o)],[t+s*Math.cos(o),i-s*Math.sin(o)]]}}}}class er extends ye{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof Be&&e.property==ze.AXIS_PATH_POSITION).element;e instanceof mi?this._runForEncoding(e):e instanceof Bi&&this._runForLayout(e);for(let t of e._labels.children)t._updateBounds();le(e._labels)}_runForLayout(e){let t=e.channel;if("x"==t){let t=e.orientation==fi?e.labelOffset:-e.labelOffset,i=e.orientation==fi?[he.CENTER,he.TOP]:[he.CENTER,he.BOTTOM];for(let[r,s]of e._labels.children.entries()){let n=e.elements[r].bounds;s.x=n[e.tickAnchor],s._y=e._pathPos+t,s._anchor=i,e._labelRotation&&(s._rotate=[e._labelRotation,s.x,s.y],s._anchor=[he.RIGHT,he.MIDDLE])}}else if("y"===t){let t=e.orientation==gi?-e.labelOffset:e.labelOffset,i=e.orientation==gi?[he.RIGHT,he.MIDDLE]:[he.LEFT,he.MIDDLE];for(let[r,s]of e._labels.children.entries()){let n=e.elements[r].bounds;s.x=e._pathPos+t,s._y=e.tickAnchor==he.MIDDLE?n.y:n[e.tickAnchor],s._anchor=i,e._labelRotation&&(s._rotate=[e._labelRotation,s.x,s.y],s._anchor=[he.RIGHT,i[1]])}}else if("angle"===t){let t=e.elements[0].parent.layout;if(t.type===fe.CLUSTER){let i=t._d3Root.leaves();const r=new Map(i.map(e=>[e.data[U],[e.x,e.y]]));let s=5;for(let[i,n]of e._labels.children.entries()){let a=e.elements[i].datum[U];if(r.get(a)[0]<Math.PI){let o=qt(r.get(a)[0])-90;n._anchor=[he.LEFT,he.MIDDLE],n.x=t.x+r.get(a)[1]+e.elements[i].bounds.width/2+s,n._y=t.y,n._rotate=[o,t.x,t.y]}else{let o=qt(r.get(a)[0])+90;n._anchor=[he.RIGHT,he.MIDDLE],n.x=t.x-r.get(a)[1]-e.elements[i].bounds.width/2-s,n._y=t.y,n._rotate=[o,t.x,t.y]}}}}}_runForEncoding(e){let t=e.channel,r=ae(e.elements);if("x"==t){let t=e.orientation==fi?e.labelOffset:-e.labelOffset,i=e.orientation==fi?[he.CENTER,he.TOP]:[he.CENTER,he.BOTTOM];for(let[r,s]of e._labels.children.entries())s.x=e.scale.map(e.labelValues[r]),s._y=e._pathPos+t,s._anchor=i,e._labelRotation&&(s._rotate=[e._labelRotation,s.x,s.y],s._anchor=[he.RIGHT,i[1]])}else if("width"===t){let t=e.orientation==fi?e.labelOffset:-e.labelOffset,s=e.orientation==fi?[he.CENTER,he.TOP]:[he.CENTER,he.BOTTOM],n=!!(e.isFlipped()||e.elements[0].type===i.Area&&"right"===e.elements[0].baseline);for(let[i,a]of e._labels.children.entries())a.x=n?r.left+e.scale.rangeExtent-e.scale.map(e.labelValues[i]):e.scale.map(e.labelValues[i])+r.left,a._y=e._pathPos+t,a._anchor=s,e._labelRotation&&(a._rotate=[e._labelRotation,a.x,a.y],a._anchor=[he.RIGHT,s[1]])}else if("y"===t){let t=e.orientation==gi?-e.labelOffset:e.labelOffset,i=e.orientation==gi?[he.RIGHT,he.MIDDLE]:[he.LEFT,he.MIDDLE];for(let[r,s]of e._labels.children.entries())s.x=e._pathPos+t,s._y=e.scale.map(e.labelValues[r]),s._anchor=i,e._labelRotation&&(s._rotate=[e._labelRotation,s.x,s.y],s._anchor=[he.RIGHT,i[1]])}else if("height"===t){let t=e.orientation==gi?-e.labelOffset:e.labelOffset,s=e.orientation==gi?[he.RIGHT,he.MIDDLE]:[he.LEFT,he.MIDDLE],n=e.elements[0].type===i.Area&&"top"===e.elements[0].baseline;for(let[i,a]of e._labels.children.entries())a.x=e._pathPos+t,a._y=n?r.top+e.scale.map(e.labelValues[i]):r.bottom-e.scale.map(e.labelValues[i]),a._anchor=s,e._labelRotation&&(a._rotate=[e._labelRotation,a.x,a.y],a._anchor=[he.RIGHT,s[1]])}else if("polarRadius"==t){let t=e.orientation==fi?e.labelOffset:-e.labelOffset,i=e.orientation==fi?[he.CENTER,he.TOP]:[he.CENTER,he.BOTTOM],[r]=e.origin;for(let[s,n]of e._labels.children.entries())n.x=r+e.scale.map(e.labelValues[s]),n._y=e._pathPos+t,n._anchor=i,e._labelRotation&&(n._rotate=[e._labelRotation,n.x,n.y],n._anchor=[he.RIGHT,i[1]])}else if("polarAngle"===t){let[t,i]=e.origin,r=e.radius+e.labelOffset;for(let[s,n]of e._labels.children.entries()){let a=e.scale.map(e.tickValues[s])*Math.PI/180;n.x=t+r*Math.cos(a),n._y=i-r*Math.sin(a),n._anchor=[he.CENTER,he.MIDDLE],e._labelRotation&&(n._rotate=[e._labelRotation,n.x,n.y])}}}}function tr(e,t){let i=e.getElements(t);return i&&"vertexIndices"===i.type?i.groups[0].parent:i[0]}class ir extends ye{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=we(e.parent);for(let e of t){let t=e.layout;if(!t)return;let i=t._includeInvisible?e.children:e.children.filter(e=>"hidden"!==e.visibility);this.fillGrid(e,t,i),this.computeCellBounds(e,t,i),this.placeElements(e,t,i)}let i=Le(e,!0);for(let e of i)le(e)}placeElements(e,t,i){let r=gt(e,"x"),s=gt(e,"y");for(let i=0;i<e.children.length;i++){let r=e.children[i],s=t.cellBounds[i];if(!s)continue;let n=0,a=0;switch(t._cellHorzAlignment){case he.LEFT:n=s.left-r.refBounds.left;break;case he.CENTER:n=s.x-r.refBounds.x;break;case he.RIGHT:n=s.right-r.refBounds.right}switch(t._cellVertAlignment){case he.TOP:a=s.top-r.refBounds.top;break;case he.MIDDLE:a=s.y-r.refBounds.y;break;case he.BOTTOM:a=s.bottom-r.refBounds.bottom}wt(r,n,a)}if(r.length>0)for(let e of r)for(let i of e.scales){let r=tr(e,i),s=t.getIndex(r);if(s<0||!t.cellBounds[s])continue;let n="point"===i.type?t.cellBounds[s].left+r.bounds.width/2:t.cellBounds[s].left,a=n+i.rangeExtent;i.range=i.range[0]<i.range[1]?[n,a]:[a,n]}if(s.length>0)for(let e of s)for(let i of e.scales){let r=tr(e,i),s=t.getIndex(r);if(s<0||!t.cellBounds[s])continue;let n="point"===i.type?t.cellBounds[s].top+r.bounds.height/2:t.cellBounds[s].top,a=n+i.rangeExtent;i.range=i.range[0]<i.range[1]?[n,a]:[a,n]}}fillGrid(e,t,i){let r=i.length,s=t._numCols?t._numCols:t._numRows?Math.ceil(r/t._numRows):1,n=t._numRows?t._numRows:Math.ceil(r/s);t._grid=new Array(n).fill(null).map(()=>new Array(s).fill(null));for(let a=0;a<r;a++){let r,o;switch(t._direction){case kt.RowFirst:r=Math.floor(a/s),o=a%s;break;case kt.ColumnFirst:r=a%n,o=Math.floor(a/n);break;default:throw new Error("Invalid fill direction. Use 'row_first' or 'column_first'.")}t._start.toLowerCase().includes("bottom")&&(r=n-1-r),t._start.toLowerCase().includes("right")&&(o=s-1-o);let l=e.children.indexOf(i[a]);t._grid[r][o]=l}}computeCellBounds(e,t,i){let r=i.map(e=>e.refBounds?e.refBounds:e.bounds),s=t._colGap,n=t._rowGap;if(void 0===t._left){let e=r.map(e=>e.left),i=r.map(e=>e.top);t._left=d3.min(e),t._top=d3.min(i)}let a=r.map(e=>e.width),o=r.map(e=>e.height),l=d3.max(a),h=d3.max(o);t._cellBounds=new Array(e.children.length).fill(null);let c=t._grid.length,d=c>0&&t._grid[0]?t._grid[0].length:0,u=t._rowOffset||0,_=t._colOffset||0;for(let i=0;i<c;i++)for(let r=0;r<d;r++){let a=t._grid[i][r];if(null==a||a>=e.children.length)continue;let o=t._left+(l+s)*r+(i%2==1?u:0),c=t._top+(h+n)*i+(r%2==1?_:0);t._cellBounds[a]=new se(o,c,l,h)}}}function rr(e,t,r){let s=e.scene,o=r||{};if(o.attribute=o.attribute||D,function(e,t,i){if(!e||void 0===t)throw new Error("Incomplete information to do densification. You must specify an element, a categorical data attribute and a data table");t instanceof V&&n(i.attribute,t)}(e,t,o),t instanceof G||t instanceof j)throw"Not implemented";if(t instanceof V){let r=function(e,t,r,s,n){let o=n.type(r);if(o!=a.String&&o!=a.Date&&o!=a.Number&&o!=a.Integer)throw new Error("Densify only works on a string or date attribute: "+r+" is "+o);if(!nr(t))throw new Error("The "+t.type+" is not dividable");switch(t.type){case i.Line:return function(e,t,i,r){let s,n,a=we(t);for(let o of a){let a=o.dataScope?o.dataScope:N(r),l=L(a,i,!1);1===l.length&&l.push(l[0]);let h=Object.assign({},o.styles);for(let e of Dt.styles)void 0!==o[e]&&(h[e]=o[e]);let c=o.vertices[0].x,d=o.vertices[0].y,u=[],_=o.vertices[1].x-c,p=o.vertices[1].y-d;for(let e=0;e<l.length;e++)u.push([c+e*_/(l.length-1),d+e*p/(l.length-1)]);h.vertices=u,h.type="path";let f=Gi(e,h);n||(n=f.id),f._classId=n,f.dataScope=a,f._updateBounds(),f._refBounds=f.bounds.clone();let g=o.parent;g.addChild(f),g.removeChild(o);for(let e=0;e<f._vertices.length;e++)f._vertices.setDataScopeRef(e,l[e]);o==t&&(s=f)}return s}(e,t,r,n);case i.Circle:return function(e,t,i,r){let s,n,o=we(t),l=r.type(i);for(let h of o){let o=h.dataScope?h.dataScope:N(r),c=L(o,i,l==a.Number),d=c.length;if(d<3)throw new Error("INSUFFICIENT_DATA_SCOPES");let u=90,_=360/d,p=[],f=[],g=-1;for(let e=0;e<c.length;e++){let t=u+g*e*_;f[e]=t;let i=sr(h.x,h.y,h.radius,f[e]);p.push(i)}let y=Object.assign({},h.styles);y.vertices=p,y.type="polygon",y.x=h.x,y.y=h.y,y.radius=h.radius;let m=Gi(e,y);n||(n=m.id),m._classId=n,m.dataScope=o;let b=h.parent;b.addChild(m),b.removeChild(h);for(let e=0;e<m._vertices.length;e++)m._vertices.setProperty(e,"polarAngle",f[e]),m._vertices.setDataScopeRef(e,c[e]);h===t&&(s=m)}return s}(e,t,r,n);case i.Rect:return function(e,t,i,r,s){let n,o,l=we(t),h=i||Ot;if(h!=Ot&&h!=It)throw new Error("Unknown orientation: "+h);for(let i of l){let l=s.type(r),c=i.dataScope?i.dataScope:N(s),d=L(c,r,l==a.Number);1===d.length&&d.push(d[0]),l!=a.Number&&l!=a.Date||d.sort((e,t)=>e.filters[r]>t.filters[r]?1:-1);let u=Object.assign({},i.styles),_=i.vertices[0].x,p=i.vertices[0].y,f=i.vertices[i.vertices.length-2].x,g=i.vertices[i.vertices.length-2].y,y=[],m=f-_,b=g-p;for(let e=0;e<d.length;e++)y.push(h==It?[f,p+e*b/(d.length-1)]:[_+e*m/(d.length-1),p]);for(let e=0;e<d.length;e++)y.push(h==It?[_,p+(d.length-1-e)*b/(d.length-1)]:[_+(d.length-1-e)*m/(d.length-1),g]);u.vertices=y,u.type="area";let x=Gi(e,u);o||(o=x.id),x._classId=o,x.dataScope=c,x.orientation=h,x.baseline=h===Ot?he.BOTTOM:he.LEFT;let v=i.parent;v.addChild(x),v.removeChild(i);for(let e=0;e<x._vertices.length;e++)e>=d.length?x._vertices.setDataScopeRef(e,d[2*d.length-1-e]):x._vertices.setDataScopeRef(e,d[e]);i===t&&(n=x)}return n}(e,t,s,r,n)}}(s,e,o.attribute,o.orientation,t);return He(e,s._depGraph),Ye(r,s._depGraph),r.parent.type!==i.Scene&&$e(r.parent,r,s._depGraph),function(e,t,i){let r=i.findVariable(xe.ITEMS,[t]);if(!r)return;let s=null;for(let e of r.outgoingEdges)if(e.isDirected&&e.toNode.type===me.REPOPULATE){s=e.toNode;break}if(!s)return;let n=i.getVariable(xe.DATASCOPE,e);if(i.connect(s,n),e._vertices&&e._vertices.length>0){let t=e.vertices[0],r=i.getVariable(xe.DATASCOPE,t);i.connect(s,r)}}(r,t,s._depGraph),r.type===i.Area&&function(e,t,i,r){let s=r.findVariable(xe.ITEMS,[i]);if(!s)return;for(let e of s.outgoingEdges)if(e.isDirected&&e.toNode.type===me.REPOPULATE)return;let n=r.createOneWayDependency(me.REPOPULATE);n._area=e,n._repeatAttr=t,r.connect(s,n);let a=r.getVariable(xe.DATASCOPE,e);if(r.connect(n,a),e._vertices&&e._vertices.length>0){let t=r.getVariable(xe.DATASCOPE,e.vertices[0]);r.connect(n,t)}}(r,o.attribute,t,s._depGraph),s.onChange(xe.CHANNEL,"width",r),r}}function sr(e,t,i,r){return[i*Math.cos(Xt(r))+e,t-i*Math.sin(Xt(r))]}function nr(e){if([i.Line,i.Circle,i.Rect,i.Area].indexOf(e.type)<0)return!1;if(e.dataScope){let t=we(e,e.scene);for(let e of t)if(C(e.dataScope)>1)return!0;return!1}return!0}function ar(e,t){if(!e)throw new Error("update: target is required");if(!t||"object"!=typeof t||Array.isArray(t))throw new Error("update: patch must be an object");if(pe(e)){let i=e.group?[e.group]:[],r=[];for(let e of i)r=r.concat(we(e));0===r.length&&(r=i);for(let e of r)if(e.layout)for(const[i,r]of Object.entries(t))e.layout[i]=r;let s=Ie(e);if(s)for(let e of i)e.firstChild&&s.onChange(xe.CHANNEL,"width",e.firstChild);return}let i=we(e),r=Ie(e);for(const[s,n]of Object.entries(t))if("layout"!==s)for(let e of i)or(e,s,n);else if(r&&"function"==typeof r.setLayout)r.setLayout(e,n);else for(let e of i)e.layout=n;if("width"in t&&i.forEach(e=>{e._refBounds&&e._refBounds.setWidth(t.width)}),"height"in t&&i.forEach(e=>{e._refBounds&&e._refBounds.setHeight(t.height)}),r)for(let i in t)"layout"!==i&&(["vertex","segment"].includes(e.type)&&!["x","y"].includes(i)||(Object.values(Me).includes(i)?r.onChange(xe.CHANNEL,i,e):r.onChange(xe.PROPERTY,i,e)))}function or(e,t,r,s){switch(t){case"x":hr(e,r);break;case"y":cr(e,r);break;case"width":!function(e,t){e.resize(t,e.height)}(e,r);break;case"height":!function(e,t){e.resize(e.width,t)}(e,r);break;case"radius":e.radius=r;break;case"strength":e._strength=r;break;case"area":e.type===i.Circle?e.radius=Math.sqrt(r/Math.PI):e.type===i.Rect&&e.resize(Math.sqrt(r),Math.sqrt(r)),e._updateBounds();break;case"text":e._text=r;break;case"curveMode":e.curveMode=r;break;case"baseline":e.baseline=r;break;case"angle":[i.Arc,i.Pie].includes(e.type)&&function(e,t){e._endAngle=Kt(e._startAngle+t),e._sr=Xt(e._startAngle),e._er=Xt(e._endAngle),e.vertices[0].x=e._x+e._innerRadius*Math.cos(e._sr),e.vertices[0].y=e._y-e._innerRadius*Math.sin(e._sr),e.vertices[1].x=e._x+e._outerRadius*Math.cos(e._sr),e.vertices[1].y=e._y-e._outerRadius*Math.sin(e._sr),e.vertices[2].x=e._x+e._outerRadius*Math.cos(e._er),e.vertices[2].y=e._y-e._outerRadius*Math.sin(e._er),e.vertices[3].x=e._x+e._innerRadius*Math.cos(e._er),e.vertices[3].y=e._y-e._innerRadius*Math.sin(e._er)}(e,r);break;case"startAngle":!function(e,t){let i=e.angle;e._startAngle=t,e._endAngle=Kt(e._startAngle+i),e._sr=Xt(e._startAngle),e._er=Xt(e._endAngle),e.vertices[0].x=e._x+e._innerRadius*Math.cos(e._sr),e.vertices[0].y=e._y-e._innerRadius*Math.sin(e._sr),e.vertices[1].x=e._x+e._outerRadius*Math.cos(e._sr),e.vertices[1].y=e._y-e._outerRadius*Math.sin(e._sr),e.vertices[2].x=e._x+e._outerRadius*Math.cos(e._er),e.vertices[2].y=e._y-e._outerRadius*Math.sin(e._er),e.vertices[3].x=e._x+e._innerRadius*Math.cos(e._er),e.vertices[3].y=e._y-e._innerRadius*Math.sin(e._er)}(e,r);break;case"thickness":!function(e,t){lr(e,e._innerRadius+t)}(e,r);break;case"innerRadius":!function(e,t){e._innerRadius=t,e.vertices[0].x=e._x+e._innerRadius*Math.cos(e._sr),e.vertices[0].y=e._y-e._innerRadius*Math.sin(e._sr),e.vertices[3].x=e._x+e._innerRadius*Math.cos(e._er),e.vertices[3].y=e._y-e._innerRadius*Math.sin(e._er)}(e,r);break;case"outerRadius":lr(e,r);break;case"polarAngle":
3
+ // as the vertex-level version of this pairing, polarAngle must be
4
+ e.polarAngle=r;break;case"polarRadius":{let t=sr(s&&s._preferredOrigin?s._preferredOrigin[0]:e.parent.x,s&&s._preferredOrigin?s._preferredOrigin[1]:e.parent.y,r,e.polarAngle);hr(e,t[0]),cr(e,t[1]);break}case"visibility":e.visibility=r;break;case"src":e.src=r;break;case"path":e.path=r;break;case"vxOpacity":if(e instanceof At)for(let i of e.children)or(i,t,r);else e.vxOpacity=r;break;default:if("vertex"===e.type)e[t]=r;else if(e instanceof At)for(let i of e.children)or(i,t,r);else{if(e.styles[t]==r)return;e.styles[t]=r}}"vertex"===e.type?e.parent._dirty=!0:e._dirty=!0}function lr(e,t){e._outerRadius=t,e.vertices[1].x=e._x+e._outerRadius*Math.cos(e._sr),e.vertices[1].y=e._y-e._outerRadius*Math.sin(e._sr),e.vertices[2].x=e._x+e._outerRadius*Math.cos(e._er),e.vertices[2].y=e._y-e._outerRadius*Math.sin(e._er)}function hr(e,t){"vertex"==e.type?e.x=t:wt(e,t-e.x,0)}function cr(e,t){"vertex"==e.type?e.y=t:wt(e,0,t-e.y)}class dr extends be{constructor(e,t){super(e),this._result=t.evalResult,this._condEnc=t}get result(){return this._condEnc.evalResult}clearResult(){this._condEnc.evalResult={}}get conditionalEncoding(){return this._condEnc}}class ur extends ye{constructor(e){super(e)}storeValues(e,t){this._storedValues={};let i=we(e);for(let e of i)this._storedValues[e.id]=e[t]}_restoreValue(e,t){let i=this._storedValues[e.id];e[t]!==i&&or(e,t,i)}run(){super.run();let e=this.inputVars.find(e=>e instanceof Xi),t=this.outputVar,i=e?e.getEncoding(t.channel,t.element):null,r=t.channel,s=this.inputVars.filter(e=>e instanceof dr),n=s.length>0?s.map(e=>e.conditionalEncoding):[],a=n.length>0?n[0].eventContext:null,o=["x","y","width","height","radius"].includes(t.channel);if(e&&"vertex"===t.element.type)return this._runVertexIndexEncoding(i,r),void le(t.element.parent);let l=we(t.element),h=l[0].scene;for(let t of l){if(e){let e=i.getScale(t);this._doMapping(t,e,i.attrValues,i),o&&this._updateRefBounds(t,e,i)}else this._restoreValue(t,r);if(s.length>0){let e=n.map(e=>e.evalResult[t.id]).every(e=>e||void 0===e);n[0].stylingFunction(e,a,h.state,t)}}if(o){le(["vertex","segment"].includes(t.element.type)?t.element.parent:t.element)}}_runVertexIndexEncoding(e,t){for(let i=0;i<e.scales.length;i++){let r=e.scales[i],s=e.getElements(r),n=[];for(let i of s.groups){i.parent._vertices;for(let s of i.indices){let n=Ae(i.parent,s),a=e.attrValues[n],o="text"===t?a:r.map(a);this._setVertexIndexChannel(i.parent,s,t,o,e)}i.parent._dirty=!0,"x"!==t&&"y"!==t||n.includes(i.parent)||(this._updateVertexParentRefBounds(i.parent,t,r,e),n.push(i.parent))}}}_setVertexIndexChannel(e,t,i,r,s){let n=e._vertices;switch(i){case"x":n._xs[t]=r;break;case"y":n._ys[t]=r;break;case"polarRadius":{let i=n._polarAngles[t]*Math.PI/180,a=s&&s._preferredOrigin;if(!a&&"number"!=typeof e.radius)throw new Error('Mascot: encode(..., "polarRadius", ...) needs an explicit {origin: [x, y]} option because the encoded shape has no fixed center of its own -- e.g. it came from densify() on a "line" mark rather than a "circle".');let o=a?s._preferredOrigin[0]:e.x,l=a?s._preferredOrigin[1]:e.y;n._xs[t]=o+r*Math.cos(i),n._ys[t]=l-r*Math.sin(i);break}default:n.setProperty(t,i,r)}}_updateVertexParentRefBounds(e,t,i,r){let s=e.refBounds;"x"===t?e._refBounds=new se(r.flipScale?i.range[1]:i.range[0],s.top,i.rangeExtent,s.height):"y"===t&&(e._refBounds=new se(s.left,r.flipScale?i.range[0]:i.range[1],s.width,i.rangeExtent))}_updateRefBounds(t,i,r){switch(this.outputVar.channel){case"width":t._refBounds.setWidth(i.rangeExtent);break;case"height":t._refBounds.setHeight(i.rangeExtent);break;case"radius":t._refBounds.setWidth(2*i.rangeExtent,he.CENTER),t._refBounds.setHeight(2*i.rangeExtent,he.MIDDLE);break;case"x":if("vertex"==t.type||"segment"==t.type){let e=t.parent._refBounds;t.parent._refBounds=new se(r.flipScale?i.range[1]:i.range[0],e.top,i.rangeExtent,e.height)}else if(t._refBounds)if("band"===i.type){let e=i.map(r.attrValues[t.id]),s=t._refBounds;t._refBounds=new se(e-t.width/2,s.top,t.width,s.height)}else{let e=t.parent;for(;e&&(!e.layout||e.layout.type!==fe.GRID);)e=e.parent;if(e){let e=t._refBounds;t._refBounds=new se(r.flipScale?i.range[1]:i.range[0],e.top,i.rangeExtent,e.height)}}break;case"y":if("vertex"==t.type||"segment"==t.type){let e=t.parent._refBounds;t.parent._refBounds=new se(e.left,r.flipScale?i.range[0]:i.range[1],e.width,i.rangeExtent)}else if(t._refBounds){let s=t.parent;for(;s&&(!s.layout||s.layout.type!==fe.GRID);)s=s.parent;if(s){let s=t._refBounds,n=e.min(i.range);t._refBounds=new se(s.left,r.flipScale?i.range[0]:n,s.width,i.rangeExtent)}}}}_doMapping(e,t,r,s){switch(this.outputVar.channel){case"width":t.domain[0]<0&&e instanceof li?function(e,t,i){let r=e.refBounds.left+t.map(0),s=e.refBounds.left+t.map(i[e.id]);wt(e.leftSegment,r-e.leftSegment.x,0),wt(e.rightSegment,s-e.rightSegment.x,0)}(e,t,r):t.domain[0]<0&&e instanceof $t||(e.type===i.Area?function(e,t,i){let r=e.baseline;if(e.orientation===It){let s=e._vertices.length/2;switch(r){case"left":Si(e,s,e._vertices.length,e.refBounds.left),Ri(e,0,s,r=>e.refBounds.left+t.map(i[Ae(e,r)]));break;case"right":Ri(e,s,e._vertices.length,r=>e.refBounds.right-t.map(i[Ae(e,r)])),Si(e,0,s,e.refBounds.right);break;case"center":console.log("center"),Ri(e,s,e._vertices.length,r=>e.refBounds.center-t.map(i[Ae(e,r)])/2),Ri(e,0,s,r=>e.refBounds.center+t.map(i[Ae(e,r)])/2)}}}(e,t,r):this._doStandardMapping(e,t,r,s));break;case"height":t.domain[0]<0&&e instanceof li?function(e,t,i){let r=e.refBounds.bottom-t.map(0),s=e.refBounds.bottom-t.map(i[e.id]);wt(e.bottomSegment,0,r-e.bottomSegment.y),wt(e.topSegment,0,s-e.topSegment.y)}(e,t,r):t.domain[0]<0&&e instanceof $t?function(e,t,i){let r=e._vertices.length/2;Ti(e,0,r,r=>e.refBounds.bottom-t.map(i[Ae(e,r)])),ki(e,r,e._vertices.length,e.refBounds.bottom-t.map(0))}(e,t,r):e.type===i.Area?function(e,t,i){let r=e.baseline;if(e.orientation===Ot){let s=e._vertices.length/2;switch(r){case"top":Ti(e,s,e._vertices.length,r=>e.refBounds.top+t.map(i[Ae(e,r)])),ki(e,0,s,e.refBounds.top);break;case"middle":Ti(e,0,s,r=>e.refBounds.middle-t.map(i[Ae(e,r)])/2),Ti(e,s,e._vertices.length,r=>e.refBounds.middle+t.map(i[Ae(e,r)])/2);break;default:Ti(e,0,s,r=>e.refBounds.bottom-t.map(i[Ae(e,r)])),ki(e,s,e._vertices.length,e.refBounds.bottom)}}}(e,t,r):this._doStandardMapping(e,t,r,s);break;case"text":this._doTextMapping(e,r);break;case"fillGradient":!function(e,t,i,r){let s=e._vertices._ids.map((t,r)=>i[Ae(e,r)]),n=d3.min(s),a=d3.max(s),o="horizontal"===e.orientation?new di({x1:0,y1:100,x2:0,y2:0}):new di({x1:0,y1:0,x2:100,y2:0});if(o.addStop(0,t.map(n),1),r._mapping){let e=Object.keys(r._mapping).map(e=>parseFloat(e)).sort();for(let i of e)i>n&&i<a&&o.addStop(100*(i-n)/(a-n),t.map(i),1)}else"divergingColor"===t.type&&o.addStop(100*-n/(a-n),t.map(0),1);"sequentialColor"===t.type&&o.addStop(100*-n/(a-n),t.map(0),1),o.addStop(100,t.map(a),1),e.fillColor=o}(e,t,r,s);break;case"strokeGradient":!function(e,t,i){let r=[];for(let s=0;s<e._vertices.length;s++)r.push(t.map(i[Ae(e,s)]));e.strokeColor=new ui(r)}(e,t,r);break;default:this._doStandardMapping(e,t,r,s)}}_doTextMapping(e,t){or(e,this.outputVar.channel,t[e.id])}_doStandardMapping(e,t,i,r){let s=this.outputVar.channel,n=t.map(i[e.id]);or(e,s,n,r),e instanceof jt&&e.firstVertex&&e.firstVertex.shape&&"strokeColor"===s&&e.vertices.forEach(e=>e.fillColor=n)}_doCondEncoding(e,t){let i=e[0].scene;for(let r of e){let e=t.map(e=>e.evalResult[r.id]).every(e=>e||void 0===e),s=t[0].eventContext;t[0].stylingFunction(e,s,r,i)}}_updateElement(e,t,i,r){let s;"object"==typeof r&&e.triggerElement?"property"in r?s=e.triggerElement[r.property]:"attribute"in r&&(s=e.triggerElement.datum[r.attribute]):s=r,["x","y"].includes(i)&&"offset"in r&&(s+=r.offset),or(t,i,s)}}class _r extends ye{constructor(e){super(e)}run(){let e=this.outputVar.element;e.updateValues(),e.scale?this._runForEncoding(e):this._runForLayout(e),le(e)}_runForLayout(e){let t=e.channel,i=ae(e.elements),r=[];if("x"===t)for(let t=0;t<e.values.length;t++){let s=e.elements[t].refBounds;r.push({x1:s.x,y1:i.bottom,x2:s.x,y2:i.top})}else if("y"===t)for(let t=0;t<e.values.length;t++){let s=e.elements[t].refBounds;r.push({x1:i.left,y1:s.y,x2:i.right,y2:s.y})}e.lines=r,e._dirty=!0}_runForEncoding(e){let t=e.channel,i=ae(e.elements),r=[];if("x"===t){let t,s,n=pt(e.elements[0],"y");n?(t=Math.min(...n.getScale(e.elements[0]).range,i.top),s=Math.max(...n.getScale(e.elements[0]).range,i.bottom)):(t=i.top,s=i.bottom);for(let i of e.values)r.push({x1:e.scale.map(i),y1:s,x2:e.scale.map(i),y2:t})}else if("width"===t)for(let t of e.values)r.push({x1:e.scale.map(t)+i.left,y1:i.bottom,x2:e.scale.map(t)+i.left,y2:i.top});else if("y"===t){let t,s,n=pt(e.elements[0],"x");n?(t=Math.min(...n.getScale(e.elements[0]).range,i.left),s=Math.max(...n.getScale(e.elements[0]).range,i.right)):(t=i.left,s=i.right);for(let i of e.values)r.push({x1:t,y1:e.scale.map(i),x2:s,y2:e.scale.map(i)})}else if("height"===t)for(let t of e.values)r.push({x1:i.left,y1:i.bottom-e.scale.map(t),x2:i.right,y2:i.bottom-e.scale.map(t)});else if("polarRadius"===t){let[t,i]=e.origin;for(let s=0;s<e.values.length;s++)r.push({x:t,y:i,r:e.scale.map(e.values[s])})}else if("polarAngle"===t){let[t,i]=e.origin,s="radius"in e._args?e._args.radius:100;for(let n of e.values){let a=e.scale.map(n)*Math.PI/180;r.push({x1:t,y1:i,x2:t+s*Math.cos(a),y2:i-s*Math.sin(a)})}}e.lines=r,e._dirty=!0}}class pr extends ye{constructor(e){super(e)}run(){let e=this.outputVar.element;e.updatePoints(),e._dirty=!0,le(e)}}class fr extends ye{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=Le(e)[0],r=we(e.parent);for(let e of r){let r=e.layout;if(!r)return;switch(t.type){case i.Rect:case i.Circle:case i.Image:case i.Symbol:this._stackRects(e,r);break;case i.Area:e.children[0].orientation===Ot?this._stackAreasVert(e,r):this._stackAreasHorz(e,r);break;case i.Arc:case i.Pie:t.parent.classId===e.classId&&this._stackArcs(e,r)}}le(t)}_stackArcs(e,t){if(t.orientation===Nt){let t=90;if((this._direction?this._direction:Vt.Clockwise)===Vt.Clockwise)for(let i of e.children){let e=Kt(t-i.angle);or(i,"startAngle",e),t=e}else for(let i of e.children){let e=Kt(t+i.angle);or(i,"startAngle",e),t=e}}else if(t.orientation===Lt){let t=d3.min(e.children.map(e=>e.innerRadius));for(let i of e.children){let e=i.outerRadius-i.innerRadius;or(i,"innerRadius",t),or(i,"outerRadius",t+e),t=i._outerRadius}}}_stackAreasVert(e,t){let i=e.children.filter(e=>"visible"===e.visibility),r=e.bounds,s=t.vertCellAlignment===he.TOP?r.top:r.bottom,n=t.vertCellAlignment===he.TOP?1:-1;if(0===i.length)return;t.vertCellAlignment===he.BOTTOM&&i.reverse();let a=i[0].vertices.length/2,o=new Array(a).fill(0);for(let e of i){for(let t=0;t<a;t++){let i=e.vertices[t],r=e.vertices[2*a-t-1],l=Math.abs(i.y-r.y),h=s+o[t]*n,c=s+(o[t]+l)*n;wt(i,0,h-i.y),wt(r,0,c-r.y),o[t]+=l}let t=e.bounds.bottom;e._updateBounds(),e._refBounds.translate(0,e.bounds.bottom-t)}if(t.vertCellAlignment===he.MIDDLE)for(let e of i){for(let t=0;t<a;t++){let i=e.vertices[t],s=e.vertices[2*a-t-1],n=r.middle+o[t]/2;wt(i,0,n-r.bottom),wt(s,0,n-r.bottom)}let t=e.bounds.bottom;e._updateBounds(),e._refBounds.translate(0,e.bounds.bottom-t)}}_stackAreasHorz(e,t){}_stackRects(e,t){e.scene;let i=t._orientation,r=e.children.map(e=>e.bounds),s=r.map(e=>e.left),n=r.map(e=>e.top),a=r.map(e=>e.width),o=r.map(e=>e.height),l=null==t._left?d3.min(s):t._left,h=null==t._top?d3.min(n):t._top,c=d3.max(a),d=d3.max(o);if(i==It)for(let i=0;i<e.children.length;i++){let r=e.children[i],s=0,n=h+r.bounds.height/2-r.bounds.y;h+=r.bounds.height+t._gap,wt(r,s,n),r._updateBounds();let a=0,o=0;if(!mt(r))switch(t._horzCellAlignment){case he.LEFT:a=l-r.bounds.left;break;case he.CENTER:a=l+c/2-r.bounds.x;break;case he.RIGHT:a=l+c-r.bounds.right}wt(r,a,o)}else for(let i=0;i<e.children.length;i++){let r=e.children[i],s=l+r.bounds.width/2-r.bounds.x,n=0;l+=r.bounds.width+t._gap,wt(r,s,n),r._updateBounds();let a=0,o=0;if(!yt(r))switch(t._vertCellAlignment){case he.TOP:o=h-r.bounds.top;break;case he.MIDDLE:o=h+d/2-r.bounds.y;break;case he.BOTTOM:o=h+d-r.bounds.bottom}wt(r,a,o)}}}class gr extends ye{constructor(e){super(e)}run(){super.run()}}class yr extends ye{constructor(e){super(e)}run(){let t=this._binConfig.attribute,i=this._binConfig.startAttr,r=this._binConfig.endAttr,s=this._binConfig.binIdAttr,n=this.inputVars[0].dataset,o=this.outputVar.dataset,l=n.values(t),h=e.bin();null!=this._binConfig?.numBins&&(h=h.thresholds(this._binConfig.numBins));let c=h(l);this._binConfig.actualNumBins=c.length;let d=String(c.length-1).length,u=e=>String(e).padStart(d,"0"),_=this._findBin,p=l.map(e=>_(e,c).x0),f=l.map(e=>_(e,c).x1),g=l.map(e=>{let t=c.indexOf(_(e,c));return u(t)}),y=c.map((e,t)=>u(t));o.addAttr(i,a.Number,p),o.addAttr(r,a.Number,f),o.addAttr(s,a.String,g),o.order(s,y)}_findBin(e,t){for(let i of t)if(i.indexOf(e)>=0)return i}}class mr extends be{constructor(e,t){super(e),this._dataset=t}get dataset(){return this._dataset}}class br extends ye{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof mr),t=this.outputVar.dataset;if(!e)return;let i=e.dataset,r=this._spec;if(!r.value)return void t.load(i.data.slice());let s=$(r);t.load(i.data.filter(e=>s.testTuple(e)))}}function xr(e,t,i){e.dataScope=void 0;let r=Ie(e),s=e;for(let e in i){vr(r,s,i[e],t);let n=dt(s.children[0],!0);for(let e of n)ct(e,r);let a=we(s);for(let e of a)if(e.layout){for(let t of e.layout.refElements)ht(t,r),Xe(t,r._depGraph);e.layout.clearRefElements()}s=s.children[0]}e.dataScope=N(t),r.onChange(xe.CHANNEL,"width",e.children[0])}function vr(e,t,i,r){let s=r.type(i);if(s!=a.String&&s!=a.Date&&s!=a.Integer)throw new Error("Repopulate only works on a string or date attribute: "+i+" is "+s);let n=we(t);for(let e of n){let t=L(e.dataScope?e.dataScope:N(r),i,!0),s=e.children.length-t.length,n=t.length-e.children.length;for(let t=0;t<s;t++)e.removeChildAt(e.children.length-1);let a=e._children.length;for(let t=0;t<n;t++){let i=Fi(e._children[t%a]);e.addChild(i)}e.children.forEach((e,i)=>e.dataScope=t[i])}}class wr extends ye{constructor(e){super(e),this._collection=null,this._area=null,this._repeatAttr=null}run(){if(super.run(),this._area&&this._repeatAttr){let e=this.inputVars[0];if(!e)return;let t=e.dataset;Ie(this._area);return function(e,t,i,r){let s=r.type(i),n=N(r),o=L(n,i,s===a.Number);s!==a.Number&&s!==a.Date||o.sort((e,t)=>e.filters[i]>t.filters[i]?1:-1),1===o.length&&o.push(o[0]);let l=o.length,h=t.refBounds??t.bounds,{left:c,top:d,right:u,bottom:_}=h,p=u-c,f=_-d,g=t.orientation===It,y=[];if(l>0){for(let e=0;e<l;e++)y.push(g?[u,d+e*f/(l-1)]:[c+e*p/(l-1),d]);for(let e=0;e<l;e++)y.push(g?[c,d+(l-1-e)*f/(l-1)]:[c+(l-1-e)*p/(l-1),_])}t.vertices=y;for(let e=0;e<t._vertices.length;e++){let i=e<l?o[e]:o[2*l-1-e];t._vertices.setDataScopeRef(e,i)}let m=t.classId??t.id,b=Math.floor(t._vertices.length/2);for(let e in t.scene._encodings)if(e===m)for(let i of Object.values(t.scene._encodings[e]))1===i._scales.length&&(i._elem2scale={[t.id]:i._scales[0]},i._elemGroups=[[t]]);else if(e===m+"_vAny"){let i=[];for(let e=0;e<t._vertices.length;e++)t._vertices.hasDataScope(e)&&i.push(e);let r=[{parent:t,indices:i}];for(let s of Object.values(t.scene._encodings[e]))if(1===s._scales.length){s._elem2scale={},s._elemGroups=[{type:"vertexIndices",groups:r}];for(let e of i)s._elem2scale[Ae(t,e)]=s._scales[0]}}else if(e.startsWith(m+"_v")){let i=e===m+"_v0",r=i?0:b,s=i?b:t._vertices.length,n=[];for(let e=r;e<s;e++)t._vertices.hasDataScope(e)&&n.push(e);let a=[{parent:t,indices:n}];for(let i of Object.values(t.scene._encodings[e]))if(1===i._scales.length){i._elem2scale={},i._elemGroups=[{type:"vertexIndices",groups:a}];for(let e of n)i._elem2scale[Ae(t,e)]=i._scales[0]}}t.dataScope=n}(0,this._area,this._repeatAttr,t),void(this.needsFullRender=!0)}if(!this._collection||!this._repeatAttr)return;let e=this.inputVars[0];if(!e)return;let t=e.dataset,i=this._collection;Ie(i);i.dataScope=void 0,vr(0,i,this._repeatAttr,t),i.dataScope=N(t);for(let e of dt(i.children[0],!0))e.refreshElementMappings();if(i.layout)for(let e of i.layout.refElements)e instanceof Bi&&(e._elems=i.children.slice());this.needsFullRender=!0}}class Er extends ye{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e.type===xe.AFFIXATION).affixation,t=e.base,i=e.element,r=we(t),s=we(i),n=e.channels,a=e.attribute;if(de(i)&&de(t)){let e=r.map(e=>e.datum[a]);s=s.filter(t=>e.includes(t.datum[a]));let t=(e,t)=>e.datum[a]<t.datum[a]?-1:e.datum[a]>t.datum[a]?1:0;s.sort(t),r.sort(t)}if(n.includes("x")||n.includes("y"))for(let t of n)this._handleXY(t,s,r,e.getElementAnchor(t),e.getBaseAnchor(t),e.getOffset(t));(n.includes("polarRadius")||n.includes("angle"))&&this._handlePolar(s,r,e);let o=Le(i,!0);for(let e of o)le(e)}_handlePolar(e,t,r){let s="polarRadius",n=r.hasChannel(s)?r.getBaseAnchor(s):he.MIDDLE,a=r.hasChannel(s)?r.getElementAnchor(s):he.MIDDLE,o=r.hasChannel("angle")?r.getBaseAnchor("angle"):he.CENTER;r.hasChannel("angle")?r.getElementAnchor("angle"):he.CENTER;let l=r.hasChannel(s)?r.getOffset(s):0,h=r.hasChannel("angle")?r.getOffset("angle"):0;if([i.Arc,i.Ring].indexOf(t[0].type)>=0&&e[0].type==i.SimpleText)for(let r=0;r<e.length;r++){let s=t[r],a=e[r],h=n===he.MIDDLE?(s.outerRadius+s.innerRadius)/2:n===he.TOP?s.outerRadius-5:s.innerRadius+5;if(h+=l,s.type===i.Arc){let e=sr(s.x,s.y,h,s.startAngle),t=sr(s.x,s.y,h,s.endAngle);s.endAngle>=180&&s.endAngle<=360?a._textPath=["M",e[0],e[1],"A",h,h,s.angle,s.angle>=180?1:0,0,t[0],t[1]].join(" "):a._textPath=["M",t[0],t[1],"A",h,h,s.angle,s.angle>=180?1:0,1,e[0],e[1]].join(" ")}else if(s.type===i.Ring){let e=275,t=265,i=350,r=sr(s.x,s.y,h,e),n=sr(s.x,s.y,h,t);a._textPath=["M",n[0],n[1],"A",h,h,i,1,1,r[0],r[1]].join(" ")}a.textPathOffset=o===he.LEFT?"0%":"50%"}else for(let r=0;r<e.length;r++){let s,c,d=t[r],u=e[r];d.type==i.Arc||d.type==i.Ring?(c="left"==o?d.endAngle+h:"center"==o?d.startAngle+d.angle/2+h:d.startAngle+h,s="top"==n?d.outerRadius+l:"bottom"==n?d.innerRadius+l:(d.outerRadius+d.innerRadius)/2+l):d.type==i.Circle&&(c=90,s="top"==n?d.radius+l:"bottom"==n?l:d.radius/2+l),wt(u,d.x-u.x,d.y-s-u.bounds[a]),u._rotate=[90-c,d.x,d.y]}}_handleXY(e,t,r,s,n,a){for(let o=0;o<t.length;o++){let l,h=r[o],c=t[o];if(Wt(h)){l=Ft(h,[he.LEFT,he.TOP].includes(n)?0:[he.CENTER,he.MIDDLE].includes(n)?.5:1)[e]}else l=h.bounds[n]+a;t[0].type===i.SimpleText?(c.anchor["x"==e?0:1]=s,or(c,e,l)):"x"==e?wt(c,l-c.bounds[s],0):wt(c,0,l-c.bounds[s])}}}class Ar extends be{constructor(e,t){super(e),this._affx=t}get affixation(){return this._affx}}class Cr extends ye{constructor(e){super(e)}run(){let e=this.inputVars[0],t=this.outputVar,i=e.attribute,r=t.attribute,s=e.dataset,n=t.dataset,o=this.args,l=null!=o.min?o.min:s.summary(i).min,h=null!=o.max?o.max:s.summary(i).max,c=l,d=[];for(;c<h;)d.push(c),c+=o.interval;d.push(c);let u={},_={};if(o.groupBy)for(let e of s.data){let t=o.groupBy.map(t=>e[t]).join("-");t in u||(u[t]=[],_[t]=o.groupBy.map(t=>e[t])),u[t].push(e[i])}else u[""]=s.data.map(e=>e[i]),_[""]="";let p=[];for(let e in _){let t=Sr(Rr(o.bandwidth),d,u[e]);for(let s of t){let t={};""!==e&&o.groupBy.forEach((i,r)=>t[i]=_[e][r]),t[i]=s[0],t[r]=s[1],p.push(t)}}let f={};if(f[i]=s.type(i),f[r]=a.Number,o.groupBy)for(let e of o.groupBy)f[e]=s.type(e);n.initialize(p,n.url,f)}}function Sr(t,i,r){return i.map(i=>[i,e.mean(r,e=>t(i-e))])}function Rr(e){return t=>Math.abs(t/=e)<=1?.75*(1-t*t)/e:0}class kr extends ye{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof mr);if(!e)return;let t=e.dataset,i=this.outputVar.dataset;this._spec.fn(t,i,this._spec)}}class Tr extends ye{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof mr),t=this.outputVar.dataset;if(!e)return;let i=e.dataset,r=this._spec,s=i.attrs().filter(e=>e!==D),n=r.valueVars?r.valueVars.slice():null,a=r.idVars?r.idVars.slice():null;if(!n&&!a)return void console.warn("unpivot transform requires idVars and/or valueVars to be specified");n||(n=s.filter(e=>!a.includes(e))),a||(a=s.filter(e=>!n.includes(e)));let o=[];for(let e of i.data)for(let t of n){let i={};for(let t of a)i[t]=e[t];i[r.varName]=t,i[r.valueName]=e[t],o.push(i)}t.initialize(o,t.url)}}class Or extends ye{constructor(e){super(e)}run(){super.run();let t=this._outputVars[0].element,i=we(t.parent);for(let t of i){let i=t.layout;if(!i)return;let r=t.children.map(e=>({name:e.id,radius:e.radius,itm:e})),s=r.reduce((e,t)=>e+Math.pow(t.radius,2),0),n=Math.sqrt(s);void 0===i._width&&(i._width=n),void 0===i._height&&(i._height=n);let a=e.hierarchy({name:"root",children:r}).sum(e=>e.radius?e.radius:0).sort((e,t)=>t.value-e.value);e.pack().size([i._width,i._height]).radius(e=>e.value)(a);for(let e of a.children){let t=e.data.itm;wt(t,i._x-a.x+e.x-t.x,i._y-a.y+e.y-t.y)}}let r=Le(t,!0);for(let e of r)le(e)}}class Ir extends ye{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof Be&&e.property==ze.AXIS_PATH_POSITION).element;e instanceof mi?this._runForEncoding(e):e instanceof Bi&&this._runForLayout(e),le(e._title)}_runForEncoding(e){let t=e.channel,i=ae(e.elements);if("x"==t)e._title.x=(e.scale.range[0]+e.scale.range[1])/2,e._title._y=e.orientation==fi?e._pathPos+e.titleOffset:e._pathPos-e.titleOffset;else if("width"==t)e._title.x=i.left+e.scale.rangeExtent/2,e._title._y=e.orientation==fi?e._pathPos+e.titleOffset:e._pathPos-e.titleOffset;else if("y"===t)e._rotateYTitle?(e._title.x=e.orientation==gi?e._pathPos-e.titleOffset:e._pathPos+e.titleOffset,e._title._y=(e.scale.range[0]+e.scale.range[1])/2,e._title._rotate=e.orientation==gi?[-90,e._title._x,e._title._y]:[90,e._title._x,e._title._y]):(e._title.x=e.orientation==gi?e._pathPos-e.titleOffset:e._pathPos+e.titleOffset,e._title._y=d3.min([e.scale.range[0],e.scale.range[1]])-25,e._title._rotate=void 0);else if("height"===t)e._title.x=i.center,e._title._y=(i.top+i.bottom)/2-i.width/2-e.titleOffset,e._title._rotate=e.orientation==gi?[-90,i.center,i.middle]:[90,i.center,i.middle];else if("polarRadius"===t){let[t]=e.origin;e._title.x=t+e.scale.rangeExtent/2,e._title._y=e.orientation==fi?e._pathPos+e.titleOffset:e._pathPos-e.titleOffset,e._rotate&&(e._title._rotate=e._rotate.slice())}else if("polarAngle"===t){let[t,i]=e.origin;e._title.x=t,e._title._y=i-e.radius-e.titleOffset}}_runForLayout(e){let t=e.channel,i=e.elements[0].parent.layout&&e.elements[0].parent.layout.type==fe.STACK?oe(e.elements):ae(e.elements);if("x"==t)e._title.x=i.center,e._title._y=e.orientation==fi?e._pathPos+e.titleOffset:e._pathPos-e.titleOffset;else if("y"===t)e._title.x=i.center,e._title._y=i.middle-i.width/2-e.titleOffset,e._title._rotate=e.orientation==gi?[-90,i.center,i.middle]:[90,i.center,i.middle];else if("angle"===t){let t=e.elements[0].parent.layout;t.type===fe.CLUSTER&&(e._title.x=t.x,e._title._y=t.y)}}}class Nr extends Yi{constructor(e){super(e)}run(){super.run();let t,i=this.vars.find(e=>e.type===xe.ALIGNMENT).alignment,r=i.anchor,s=i.elements;r==he.Top||r==he.LEFT?t=e.min(s.map(e=>e.bounds[r])):r==he.BOTTOM||r==he.RIGHT?t=e.max(s.map(e=>e.bounds[r])):r!=he.CENTER&&r!=he.MIDDLE||(t=e.mean(s.map(e=>e.bounds[r])));for(let e of s){let s=xt(e,i.channel);if(s){let n=t-e.bounds[r];wt(s,"x"===i.channel?n:0,"x"===i.channel?0:n)}}for(let e of s)le(e)}}class Lr extends be{constructor(e,t){super(e),this._aln=t}get alignment(){return this._aln}}class Pr extends ye{constructor(e){super(e)}run(){super.run();let t=this._outputVars[0].element,i=we(t.parent);for(let t of i){let i=t.layout;if(!i)continue;let r=F(t.children[0]);if(!r)continue;let s=r.linkList.map(e=>({source:r.getNode(e.source),target:r.getNode(e.target)})),n=e.forceSimulation(r.nodeList).force("charge",e.forceManyBody().strength(-i._repulsion)).force("link",e.forceLink(s).id(e=>e.id).distance(i._linkDistance)).force("x",e.forceX()).force("y",e.forceY()).force("center",e.forceCenter(i._x,i._y).strength(i._attraction));n.stop(),n.tick(i._iterations);for(let e=0;e<t.children.length;e++){let i=t.children[e],s=r.nodeList[e];wt(i,s.x-i.x,s.y-i.y)}}let r=Le(t,!0);for(let e of r)le(e)}}class Vr extends ye{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=we(e);switch(e.type){case i.Arc:this._updateArcLinks(t);break;case i.BezierCurve:this._updateBezierLinks(t);break;case i.BundledPath:this._updateBundledLinks(t);break;case i.Chord:this._updateChordLinks(t);break;case i.Line:default:this._updateLineLinks(t)}le(e)}_updateArcLinks(e){for(let t of e){let e=t.source.x<t.target.x?t.source:t.target,i=t.source.x<t.target.x?t.target:t.source;t._x=(e.x+i.x)/2,t._y=(e.y+i.y)/2,t._innerRadius=Math.sqrt(Math.pow(e.x-i.x,2)+Math.pow(e.y-i.y,2))/2,t._outerRadius=t._innerRadius+t._thickness;let r=Zt(e.x,e.y,t._x,t._y),s=Zt(i.x,i.y,t._x,t._y);t.direction===Vt.CLOCKWISE&&([r,s]=[s,r]),or(t,"startAngle",r),or(t,"angle",Math.abs(s-r))}}_updateBezierLinks(e){let t=this._inputVars[0].element,i=we(t),r=t.parent.layout;r.type===fe.DIRECTED||r.type===fe.TIDYTREE?this._updateBezierLinksForDirectedGraph(i,e,r):r.type===fe.CLUSTER&&this._updateBezierLinksForClusteredGraph(i,e,r)}_updateBezierLinksForClusteredGraph(t,i,r){const s=r._d3Root.descendants(),n=new Map(s.map(e=>[Mr(e),e])),a=new Map(s.map(e=>[e.data[U],Mr(e)]));if(r.isRadial()){const t=e.linkRadial().angle(e=>e.x).radius(e=>e.y);for(let e of i){let i=e.source,s=e.target,o=i.datum[U],l=s.datum[U],h=n.get(a.get(o)),c=n.get(a.get(l));e._d=Yt(t({source:h,target:c}),r.x,r.y)}}else if(r.orientation===It){const t=e.linkVertical().x(e=>e.x).y(e=>e.y);for(let e of i){let i=e.source,s=e.target,o=i.datum[U],l=s.datum[U],h=n.get(a.get(o)),c=n.get(a.get(l));e._d=Yt(t({source:h,target:c}),r.left-r._x0,r.top)}}else if(r.orientation===Ot){const t=e.linkHorizontal().x(e=>e.y).y(e=>e.x);for(let e of i){let i=e.source,s=e.target,o=i.datum[U],l=s.datum[U],h=n.get(a.get(o)),c=n.get(a.get(l));e._d=Yt(t({source:h,target:c}),r.left,r.top-r._x0)}}}_updateBezierLinksForDirectedGraph(e,t,i){let r={},s={},n={},a={};for(let t of e){s[t.id]=0,r[t.id]=0;let e=t.links.filter(e=>e.source===t),i=t.links.filter(e=>e.target===t);a[t.id]=i.map(e=>e.strokeWidth).reduce((e,t)=>e+t,0),n[t.id]=e.map(e=>e.strokeWidth).reduce((e,t)=>e+t,0)}const o=i.direction===Pt.Left2Right||i.direction===Pt.Right2Left;if(i.spreadLinks){const e=o?e=>e.bounds.y:e=>e.bounds.x,i=[...t].sort((t,i)=>e(t.target)-e(i.target));for(let e of i)e._outLane=r[e.source.id],r[e.source.id]+=e.strokeWidth;const n=[...t].sort((t,i)=>e(t.source)-e(i.source));for(let e of n)e._inLane=s[e.target.id],s[e.target.id]+=e.strokeWidth}for(let e of t){let t,r,s,l,h=e.source,c=e.target;i.spreadLinks?o?(t=h.bounds[e.sourceAnchor[0]]+e.sourceOffset[0],s=c.bounds[e.targetAnchor[0]]+e.targetOffset[0],r=h.bounds[e.sourceAnchor[1]]+e.sourceOffset[1]-n[h.id]/2+e._outLane+e.strokeWidth/2,l=c.bounds[e.targetAnchor[1]]+e.targetOffset[1]-a[c.id]/2+e._inLane+e.strokeWidth/2):(r=h.bounds[e.sourceAnchor[1]]+e.sourceOffset[1],l=c.bounds[e.targetAnchor[1]]+e.targetOffset[1],t=h.bounds[e.sourceAnchor[0]]+e.sourceOffset[0]-n[h.id]/2+e._outLane+e.strokeWidth/2,s=c.bounds[e.targetAnchor[0]]+e.targetOffset[0]-a[c.id]/2+e._inLane+e.strokeWidth/2):(t=h.bounds[e.sourceAnchor[0]]+e.sourceOffset[0],r=h.bounds[e.sourceAnchor[1]]+e.sourceOffset[1],s=c.bounds[e.targetAnchor[0]]+e.targetOffset[0],l=c.bounds[e.targetAnchor[1]]+e.targetOffset[1]),e.orientation===Ot?e.vertices=[[t,r],[(t+s)/2,r],[t,l],[s,l]]:e.orientation===It&&(e.vertices=[[t,r],[t,(r+l)/2],[s,r],[s,l]])}}_updateBundledLinks(t){let i=this._inputVars[0].element.parent.layout;if(i.type!==fe.CLUSTER)throw"Bundled links must work on a cluster layout";let r=i._d3Root;if(!r)return void console.warn("cluster layout was not placed; skipping bundled link routing");let s=r.leaves();const n=new Map(s.map(e=>[Mr(e),e])),a=new Map(s.map(e=>[e.data[U],Mr(e)])),o=e.lineRadial().curve(e.curveBundle.beta(t[0]._strength)).radius(e=>e.y).angle(e=>e.x);for(let e of t){let t=e.source.datum[U],r=e.target.datum[U],s=n.get(a.get(t)),l=n.get(a.get(r)),h=s.path(l);e._d=Yt(o(h),i.x,i.y),e._dirty=!0}}_updateChordLinks(e){for(let t of e){let e=t.source,i=t.target,r=sr(e.x,e.y,e.innerRadius,e.startAngle),s=sr(e.x,e.y,e.innerRadius,e.endAngle),n=sr(i.x,i.y,i.innerRadius,i.startAngle),a=sr(i.x,i.y,i.innerRadius,i.endAngle);t._d=["M",r[0],r[1],"Q",e.x,e.y,a[0],a[1],"A",e.x,e.y,i.angle,i.angle>180?1:0,1,n[0],n[1],"Q",e.x,e.y,s[0],s[1],"A",e.x,e.y,e.angle,e.angle>180?1:0,1,r[0],r[1]].join(" "),t._dirty=!0}}_updateLineLinks(e){for(let t of e){let e=t.source,i=t.target;t.vertices[0].x=e.bounds.x,t.vertices[0].y=e.bounds.y,t.vertices[1].x=i.bounds.x,t.vertices[1].y=i.bounds.y,t._dirty=!0}}}function Mr(e){return`${e.parent?Mr(e.parent)+".":""}${e.data[U]}`}var Br="\0";function Dr(e,t){e[t]?e[t]++:e[t]=1}function Gr(e,t){--e[t]||delete e[t]}function zr(e,t,i,r){var s=""+t,n=""+i;if(!e&&s>n){var a=s;s=n,n=a}return s+""+n+""+(void 0===r?"\0":r)}function jr(e,t){return zr(e,t.v,t.w,t.name)}var Fr=class{_isDirected=!0;_isMultigraph=!1;_isCompound=!1;_label;_defaultNodeLabelFn=()=>{};_defaultEdgeLabelFn=()=>{};_nodes={};_in={};_preds={};_out={};_sucs={};_edgeObjs={};_edgeLabels={};_nodeCount=0;_edgeCount=0;_parent;_children;constructor(e){e&&(this._isDirected=!Object.hasOwn(e,"directed")||e.directed,this._isMultigraph=!!Object.hasOwn(e,"multigraph")&&e.multigraph,this._isCompound=!!Object.hasOwn(e,"compound")&&e.compound),this._isCompound&&(this._parent={},this._children={},this._children[Br]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(e){return this._label=e,this}graph(){return this._label}setDefaultNodeLabel(e){return this._defaultNodeLabelFn=e,"function"!=typeof e&&(this._defaultNodeLabelFn=()=>e),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var e=this;return this.nodes().filter(t=>0===Object.keys(e._in[t]).length)}sinks(){var e=this;return this.nodes().filter(t=>0===Object.keys(e._out[t]).length)}setNodes(e,t){var i=arguments,r=this;return e.forEach(function(e){i.length>1?r.setNode(e,t):r.setNode(e)}),this}setNode(e,t){return Object.hasOwn(this._nodes,e)?(arguments.length>1&&(this._nodes[e]=t),this):(this._nodes[e]=arguments.length>1?t:this._defaultNodeLabelFn(e),this._isCompound&&(this._parent[e]=Br,this._children[e]={},this._children[Br][e]=!0),this._in[e]={},this._preds[e]={},this._out[e]={},this._sucs[e]={},++this._nodeCount,this)}node(e){return this._nodes[e]}hasNode(e){return Object.hasOwn(this._nodes,e)}removeNode(e){var t=this;if(Object.hasOwn(this._nodes,e)){var i=e=>t.removeEdge(t._edgeObjs[e]);delete this._nodes[e],this._isCompound&&(this._removeFromParentsChildList(e),delete this._parent[e],this.children(e).forEach(function(e){t.setParent(e)}),delete this._children[e]),Object.keys(this._in[e]).forEach(i),delete this._in[e],delete this._preds[e],Object.keys(this._out[e]).forEach(i),delete this._out[e],delete this._sucs[e],--this._nodeCount}return this}setParent(e,t){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(void 0===t)t=Br;else{for(var i=t+="";void 0!==i;i=this.parent(i))if(i===e)throw new Error("Setting "+t+" as parent of "+e+" would create a cycle");this.setNode(t)}return this.setNode(e),this._removeFromParentsChildList(e),this._parent[e]=t,this._children[t][e]=!0,this}_removeFromParentsChildList(e){delete this._children[this._parent[e]][e]}parent(e){if(this._isCompound){var t=this._parent[e];if(t!==Br)return t}}children(e=Br){if(this._isCompound){var t=this._children[e];if(t)return Object.keys(t)}else{if(e===Br)return this.nodes();if(this.hasNode(e))return[]}}predecessors(e){var t=this._preds[e];if(t)return Object.keys(t)}successors(e){var t=this._sucs[e];if(t)return Object.keys(t)}neighbors(e){var t=this.predecessors(e);if(t){const r=new Set(t);for(var i of this.successors(e))r.add(i);return Array.from(r.values())}}isLeaf(e){return 0===(this.isDirected()?this.successors(e):this.neighbors(e)).length}filterNodes(e){var t=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});t.setGraph(this.graph());var i=this;Object.entries(this._nodes).forEach(function([i,r]){e(i)&&t.setNode(i,r)}),Object.values(this._edgeObjs).forEach(function(e){t.hasNode(e.v)&&t.hasNode(e.w)&&t.setEdge(e,i.edge(e))});var r={};function s(e){var n=i.parent(e);return void 0===n||t.hasNode(n)?(r[e]=n,n):n in r?r[n]:s(n)}return this._isCompound&&t.nodes().forEach(e=>t.setParent(e,s(e))),t}setDefaultEdgeLabel(e){return this._defaultEdgeLabelFn=e,"function"!=typeof e&&(this._defaultEdgeLabelFn=()=>e),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(e,t){var i=this,r=arguments;return e.reduce(function(e,s){return r.length>1?i.setEdge(e,s,t):i.setEdge(e,s),s}),this}setEdge(){var e,t,i,r,s=!1,n=arguments[0];"object"==typeof n&&null!==n&&"v"in n?(e=n.v,t=n.w,i=n.name,2===arguments.length&&(r=arguments[1],s=!0)):(e=n,t=arguments[1],i=arguments[3],arguments.length>2&&(r=arguments[2],s=!0)),e=""+e,t=""+t,void 0!==i&&(i=""+i);var a=zr(this._isDirected,e,t,i);if(Object.hasOwn(this._edgeLabels,a))return s&&(this._edgeLabels[a]=r),this;if(void 0!==i&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(e),this.setNode(t),this._edgeLabels[a]=s?r:this._defaultEdgeLabelFn(e,t,i);var o=function(e,t,i,r){var s=""+t,n=""+i;if(!e&&s>n){var a=s;s=n,n=a}var o={v:s,w:n};r&&(o.name=r);return o}(this._isDirected,e,t,i);return e=o.v,t=o.w,Object.freeze(o),this._edgeObjs[a]=o,Dr(this._preds[t],e),Dr(this._sucs[e],t),this._in[t][a]=o,this._out[e][a]=o,this._edgeCount++,this}edge(e,t,i){var r=1===arguments.length?jr(this._isDirected,arguments[0]):zr(this._isDirected,e,t,i);return this._edgeLabels[r]}edgeAsObj(){const e=this.edge(...arguments);return"object"!=typeof e?{label:e}:e}hasEdge(e,t,i){var r=1===arguments.length?jr(this._isDirected,arguments[0]):zr(this._isDirected,e,t,i);return Object.hasOwn(this._edgeLabels,r)}removeEdge(e,t,i){var r=1===arguments.length?jr(this._isDirected,arguments[0]):zr(this._isDirected,e,t,i),s=this._edgeObjs[r];return s&&(e=s.v,t=s.w,delete this._edgeLabels[r],delete this._edgeObjs[r],Gr(this._preds[t],e),Gr(this._sucs[e],t),delete this._in[t][r],delete this._out[e][r],this._edgeCount--),this}inEdges(e,t){var i=this._in[e];if(i){var r=Object.values(i);return t?r.filter(e=>e.v===t):r}}outEdges(e,t){var i=this._out[e];if(i){var r=Object.values(i);return t?r.filter(e=>e.w===t):r}}nodeEdges(e,t){var i=this.inEdges(e,t);if(i)return i.concat(this.outEdges(e,t))}},Wr={Graph:Fr,version:"2.2.4"},Ur=Fr,Yr={write:function(e){var t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:Hr(e),edges:Xr(e)};void 0!==e.graph()&&(t.value=structuredClone(e.graph()));return t},read:function(e){var t=new Ur(e.options).setGraph(e.value);return e.nodes.forEach(function(e){t.setNode(e.v,e.value),e.parent&&t.setParent(e.v,e.parent)}),e.edges.forEach(function(e){t.setEdge({v:e.v,w:e.w,name:e.name},e.value)}),t}};function Hr(e){return e.nodes().map(function(t){var i=e.node(t),r=e.parent(t),s={v:t};return void 0!==i&&(s.value=i),void 0!==r&&(s.parent=r),s})}function Xr(e){return e.edges().map(function(t){var i=e.edge(t),r={v:t.v,w:t.w};return void 0!==t.name&&(r.name=t.name),void 0!==i&&(r.value=i),r})}var qr=function(e){var t,i={},r=[];function s(r){Object.hasOwn(i,r)||(i[r]=!0,t.push(r),e.successors(r).forEach(s),e.predecessors(r).forEach(s))}return e.nodes().forEach(function(e){t=[],s(e),t.length&&r.push(t)}),r};var Kr=class{_arr=[];_keyIndices={};size(){return this._arr.length}keys(){return this._arr.map(function(e){return e.key})}has(e){return Object.hasOwn(this._keyIndices,e)}priority(e){var t=this._keyIndices[e];if(void 0!==t)return this._arr[t].priority}min(){if(0===this.size())throw new Error("Queue underflow");return this._arr[0].key}add(e,t){var i=this._keyIndices;if(e=String(e),!Object.hasOwn(i,e)){var r=this._arr,s=r.length;return i[e]=s,r.push({key:e,priority:t}),this._decrease(s),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var e=this._arr.pop();return delete this._keyIndices[e.key],this._heapify(0),e.key}decrease(e,t){var i=this._keyIndices[e];if(t>this._arr[i].priority)throw new Error("New priority is greater than current priority. Key: "+e+" Old: "+this._arr[i].priority+" New: "+t);this._arr[i].priority=t,this._decrease(i)}_heapify(e){var t=this._arr,i=2*e,r=i+1,s=e;i<t.length&&(s=t[i].priority<t[s].priority?i:s,r<t.length&&(s=t[r].priority<t[s].priority?r:s),s!==e&&(this._swap(e,s),this._heapify(s)))}_decrease(e){for(var t,i=this._arr,r=i[e].priority;0!==e&&!(i[t=e>>1].priority<r);)this._swap(e,t),e=t}_swap(e,t){var i=this._arr,r=this._keyIndices,s=i[e],n=i[t];i[e]=n,i[t]=s,r[n.key]=e,r[s.key]=t}},Zr=Kr,$r=function(e,t,i,r){return function(e,t,i,r){var s,n,a={},o=new Zr,l=function(e){var t=e.v!==s?e.v:e.w,r=a[t],l=i(e),h=n.distance+l;if(l<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+e+" Weight: "+l);h<r.distance&&(r.distance=h,r.predecessor=s,o.decrease(t,h))};e.nodes().forEach(function(e){var i=e===t?0:Number.POSITIVE_INFINITY;a[e]={distance:i},o.add(e,i)});for(;o.size()>0&&(s=o.removeMin(),(n=a[s]).distance!==Number.POSITIVE_INFINITY);)r(s).forEach(l);return a}(e,String(t),i||Jr,r||function(t){return e.outEdges(t)})},Jr=()=>1;var Qr=$r,es=function(e,t,i){return e.nodes().reduce(function(r,s){return r[s]=Qr(e,s,t,i),r},{})};var ts=function(e){var t=0,i=[],r={},s=[];function n(a){var o=r[a]={onStack:!0,lowlink:t,index:t++};if(i.push(a),e.successors(a).forEach(function(e){Object.hasOwn(r,e)?r[e].onStack&&(o.lowlink=Math.min(o.lowlink,r[e].index)):(n(e),o.lowlink=Math.min(o.lowlink,r[e].lowlink))}),o.lowlink===o.index){var l,h=[];do{l=i.pop(),r[l].onStack=!1,h.push(l)}while(a!==l);s.push(h)}}return e.nodes().forEach(function(e){Object.hasOwn(r,e)||n(e)}),s};var is=ts,rs=function(e){return is(e).filter(function(t){return t.length>1||1===t.length&&e.hasEdge(t[0],t[0])})};var ss=function(e,t,i){return function(e,t,i){var r={},s=e.nodes();return s.forEach(function(e){r[e]={},r[e][e]={distance:0},s.forEach(function(t){e!==t&&(r[e][t]={distance:Number.POSITIVE_INFINITY})}),i(e).forEach(function(i){var s=i.v===e?i.w:i.v,n=t(i);r[e][s]={distance:n,predecessor:e}})}),s.forEach(function(e){var t=r[e];s.forEach(function(i){var n=r[i];s.forEach(function(i){var r=n[e],s=t[i],a=n[i],o=r.distance+s.distance;o<a.distance&&(a.distance=o,a.predecessor=s.predecessor)})})}),r}(e,t||ns,i||function(t){return e.outEdges(t)})},ns=()=>1;function as(e){var t={},i={},r=[];if(e.sinks().forEach(function s(n){if(Object.hasOwn(i,n))throw new os;Object.hasOwn(t,n)||(i[n]=!0,t[n]=!0,e.predecessors(n).forEach(s),delete i[n],r.push(n))}),Object.keys(t).length!==e.nodeCount())throw new os;return r}class os extends Error{constructor(){super(...arguments)}}var ls=as;as.CycleException=os;var hs=ls;var cs=function(e,t,i){Array.isArray(t)||(t=[t]);var r=e.isDirected()?t=>e.successors(t):t=>e.neighbors(t),s="post"===i?ds:us,n=[],a={};return t.forEach(t=>{if(!e.hasNode(t))throw new Error("Graph does not have node: "+t);s(t,r,a,n)}),n};function ds(e,t,i,r){for(var s=[[e,!1]];s.length>0;){var n=s.pop();n[1]?r.push(n[0]):Object.hasOwn(i,n[0])||(i[n[0]]=!0,s.push([n[0],!0]),_s(t(n[0]),e=>s.push([e,!1])))}}function us(e,t,i,r){for(var s=[e];s.length>0;){var n=s.pop();Object.hasOwn(i,n)||(i[n]=!0,r.push(n),_s(t(n),e=>s.push(e)))}}function _s(e,t){for(var i=e.length;i--;)t(e[i],i,e);return e}var ps=cs;var fs=cs;var gs=Fr,ys=Kr;var ms={Graph:Wr.Graph,json:Yr,alg:{components:qr,dijkstra:$r,dijkstraAll:es,findCycles:rs,floydWarshall:ss,isAcyclic:function(e){try{hs(e)}catch(e){if(e instanceof hs.CycleException)return!1;throw e}return!0},postorder:function(e,t){return ps(e,t,"post")},preorder:function(e,t){return fs(e,t,"pre")},prim:function(e,t){var i,r=new gs,s={},n=new ys;function a(e){var r=e.v===i?e.w:e.v,a=n.priority(r);if(void 0!==a){var o=t(e);o<a&&(s[r]=i,n.decrease(r,o))}}if(0===e.nodeCount())return r;e.nodes().forEach(function(e){n.add(e,Number.POSITIVE_INFINITY),r.setNode(e)}),n.decrease(e.nodes()[0],0);var o=!1;for(;n.size()>0;){if(i=n.removeMin(),Object.hasOwn(s,i))r.setEdge(i,s[i]);else{if(o)throw new Error("Input graph is not connected: "+e);o=!0}e.nodeEdges(i).forEach(a)}return r},tarjan:ts,topsort:ls},version:Wr.version};function bs(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function xs(e,t){if("_next"!==e&&"_prev"!==e)return t}let vs=ms.Graph,ws=class{constructor(){let e={};e._next=e._prev=e,this._sentinel=e}dequeue(){let e=this._sentinel,t=e._prev;if(t!==e)return bs(t),t}enqueue(e){let t=this._sentinel;e._prev&&e._next&&bs(e),e._next=t._next,t._next._prev=e,t._next=e,e._prev=t}toString(){let e=[],t=this._sentinel,i=t._prev;for(;i!==t;)e.push(JSON.stringify(i,xs)),i=i._prev;return"["+e.join(", ")+"]"}};var Es=function(e,t){if(e.nodeCount()<=1)return[];let i=function(e,t){let i=new vs,r=0,s=0;e.nodes().forEach(e=>{i.setNode(e,{v:e,in:0,out:0})}),e.edges().forEach(e=>{let n=i.edge(e.v,e.w)||0,a=t(e),o=n+a;i.setEdge(e.v,e.w,o),s=Math.max(s,i.node(e.v).out+=a),r=Math.max(r,i.node(e.w).in+=a)});let n=function(e){const t=[];for(let i=0;i<e;i++)t.push(i);return t}(s+r+3).map(()=>new ws),a=r+1;return i.nodes().forEach(e=>{Ss(n,a,i.node(e))}),{graph:i,buckets:n,zeroIdx:a}}(e,t||As);return function(e,t,i){let r,s=[],n=t[t.length-1],a=t[0];for(;e.nodeCount();){for(;r=a.dequeue();)Cs(e,t,i,r);for(;r=n.dequeue();)Cs(e,t,i,r);if(e.nodeCount())for(let n=t.length-2;n>0;--n)if(r=t[n].dequeue(),r){s=s.concat(Cs(e,t,i,r,!0));break}}return s}(i.graph,i.buckets,i.zeroIdx).flatMap(t=>e.outEdges(t.v,t.w))};let As=()=>1;function Cs(e,t,i,r,s){let n=s?[]:void 0;return e.inEdges(r.v).forEach(r=>{let a=e.edge(r),o=e.node(r.v);s&&n.push({v:r.v,w:r.w}),o.out-=a,Ss(t,i,o)}),e.outEdges(r.v).forEach(r=>{let s=e.edge(r),n=r.w,a=e.node(n);a.in-=s,Ss(t,i,a)}),e.removeNode(r.v),n}function Ss(e,t,i){i.out?i.in?e[i.out-i.in+t].enqueue(i):e[e.length-1].enqueue(i):e[0].enqueue(i)}let Rs=ms.Graph;var ks={addBorderNode:function(e,t,i,r){let s={width:0,height:0};arguments.length>=4&&(s.rank=i,s.order=r);return Ts(e,"border",s,t)},addDummyNode:Ts,applyWithChunking:Is,asNonCompoundGraph:function(e){let t=new Rs({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(i=>{e.children(i).length||t.setNode(i,e.node(i))}),e.edges().forEach(i=>{t.setEdge(i,e.edge(i))}),t},buildLayerMatrix:function(e){let t=Vs(Ns(e)+1).map(()=>[]);return e.nodes().forEach(i=>{let r=e.node(i),s=r.rank;void 0!==s&&(t[s][r.order]=i)}),t},intersectRect:function(e,t){let i,r,s=e.x,n=e.y,a=t.x-s,o=t.y-n,l=e.width/2,h=e.height/2;if(!a&&!o)throw new Error("Not possible to find intersection inside of the rectangle");Math.abs(o)*l>Math.abs(a)*h?(o<0&&(h=-h),i=h*a/o,r=h):(a<0&&(l=-l),i=l,r=l*o/a);return{x:s+i,y:n+r}},mapValues:function(e,t){let i=t;"string"==typeof t&&(i=e=>e[t]);return Object.entries(e).reduce((e,[t,r])=>(e[t]=i(r,t),e),{})},maxRank:Ns,normalizeRanks:function(e){let t=e.nodes().map(t=>{let i=e.node(t).rank;return void 0===i?Number.MAX_VALUE:i}),i=Is(Math.min,t);e.nodes().forEach(t=>{let r=e.node(t);Object.hasOwn(r,"rank")&&(r.rank-=i)})},notime:function(e,t){return t()},partition:function(e,t){let i={lhs:[],rhs:[]};return e.forEach(e=>{t(e)?i.lhs.push(e):i.rhs.push(e)}),i},pick:function(e,t){const i={};for(const r of t)void 0!==e[r]&&(i[r]=e[r]);return i},predecessorWeights:function(e){let t=e.nodes().map(t=>{let i={};return e.inEdges(t).forEach(t=>{i[t.v]=(i[t.v]||0)+e.edge(t).weight}),i});return Ms(e.nodes(),t)},range:Vs,removeEmptyRanks:function(e){let t=e.nodes().map(t=>e.node(t).rank),i=Is(Math.min,t),r=[];e.nodes().forEach(t=>{let s=e.node(t).rank-i;r[s]||(r[s]=[]),r[s].push(t)});let s=0,n=e.graph().nodeRankFactor;Array.from(r).forEach((t,i)=>{void 0===t&&i%n!==0?--s:void 0!==t&&s&&t.forEach(t=>e.node(t).rank+=s)})},simplify:function(e){let t=(new Rs).setGraph(e.graph());return e.nodes().forEach(i=>t.setNode(i,e.node(i))),e.edges().forEach(i=>{let r=t.edge(i.v,i.w)||{weight:0,minlen:1},s=e.edge(i);t.setEdge(i.v,i.w,{weight:r.weight+s.weight,minlen:Math.max(r.minlen,s.minlen)})}),t},successorWeights:function(e){let t=e.nodes().map(t=>{let i={};return e.outEdges(t).forEach(t=>{i[t.w]=(i[t.w]||0)+e.edge(t).weight}),i});return Ms(e.nodes(),t)},time:function(e,t){let i=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-i)+"ms")}},uniqueId:Ps,zipObject:Ms};function Ts(e,t,i,r){for(var s=r;e.hasNode(s);)s=Ps(r);return i.dummy=t,e.setNode(s,i),s}const Os=65535;function Is(e,t){if(t.length>Os){const i=function(e,t=Os){const i=[];for(let r=0;r<e.length;r+=t){const s=e.slice(r,r+t);i.push(s)}return i}(t);return e.apply(null,i.map(t=>e.apply(null,t)))}return e.apply(null,t)}function Ns(e){const t=e.nodes().map(t=>{let i=e.node(t).rank;return void 0===i?Number.MIN_VALUE:i});return Is(Math.max,t)}let Ls=0;function Ps(e){return e+""+ ++Ls}function Vs(e,t,i=1){null==t&&(t=e,e=0);let r=e=>e<t;i<0&&(r=e=>t<e);const s=[];for(let t=e;r(t);t+=i)s.push(t);return s}function Ms(e,t){return e.reduce((e,i,r)=>(e[i]=t[r],e),{})}let Bs=Es,Ds=ks.uniqueId;var Gs={run:function(e){("greedy"===e.graph().acyclicer?Bs(e,function(e){return t=>e.edge(t).weight}(e)):function(e){let t=[],i={},r={};function s(n){Object.hasOwn(r,n)||(r[n]=!0,i[n]=!0,e.outEdges(n).forEach(e=>{Object.hasOwn(i,e.w)?t.push(e):s(e.w)}),delete i[n])}return e.nodes().forEach(s),t}(e)).forEach(t=>{let i=e.edge(t);e.removeEdge(t),i.forwardName=t.name,i.reversed=!0,e.setEdge(t.w,t.v,i,Ds("rev"))})},undo:function(e){e.edges().forEach(t=>{let i=e.edge(t);if(i.reversed){e.removeEdge(t);let r=i.forwardName;delete i.reversed,delete i.forwardName,e.setEdge(t.w,t.v,i,r)}})}};let zs=ks;var js={run:function(e){e.graph().dummyChains=[],e.edges().forEach(t=>function(e,t){let i,r,s,n=t.v,a=e.node(n).rank,o=t.w,l=e.node(o).rank,h=t.name,c=e.edge(t),d=c.labelRank;if(l===a+1)return;for(e.removeEdge(t),s=0,++a;a<l;++s,++a)c.points=[],r={width:0,height:0,edgeLabel:c,edgeObj:t,rank:a},i=zs.addDummyNode(e,"edge",r,"_d"),a===d&&(r.width=c.width,r.height=c.height,r.dummy="edge-label",r.labelpos=c.labelpos),e.setEdge(n,i,{weight:c.weight},h),0===s&&e.graph().dummyChains.push(i),n=i;e.setEdge(n,o,{weight:c.weight},h)}(e,t))},undo:function(e){e.graph().dummyChains.forEach(t=>{let i,r=e.node(t),s=r.edgeLabel;for(e.setEdge(r.edgeObj,s);r.dummy;)i=e.successors(t)[0],e.removeNode(t),s.points.push({x:r.x,y:r.y}),"edge-label"===r.dummy&&(s.x=r.x,s.y=r.y,s.width=r.width,s.height=r.height),t=i,r=e.node(t)})}};const{applyWithChunking:Fs}=ks;var Ws={longestPath:function(e){var t={};e.sources().forEach(function i(r){var s=e.node(r);if(Object.hasOwn(t,r))return s.rank;t[r]=!0;let n=e.outEdges(r).map(t=>null==t?Number.POSITIVE_INFINITY:i(t.w)-e.edge(t).minlen);var a=Fs(Math.min,n);return a===Number.POSITIVE_INFINITY&&(a=0),s.rank=a})},slack:function(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}};var Us=ms.Graph,Ys=Ws.slack,Hs=function(e){var t,i,r=new Us({directed:!1}),s=e.nodes()[0],n=e.nodeCount();r.setNode(s,{});for(;Xs(r,e)<n;)t=qs(r,e),i=r.hasNode(t.v)?Ys(e,t):-Ys(e,t),Ks(r,e,i);return r};function Xs(e,t){return e.nodes().forEach(function i(r){t.nodeEdges(r).forEach(s=>{var n=s.v,a=r===n?s.w:n;e.hasNode(a)||Ys(t,s)||(e.setNode(a,{}),e.setEdge(r,a,{}),i(a))})}),e.nodeCount()}function qs(e,t){return t.edges().reduce((i,r)=>{let s=Number.POSITIVE_INFINITY;return e.hasNode(r.v)!==e.hasNode(r.w)&&(s=Ys(t,r)),s<i[0]?[s,r]:i},[Number.POSITIVE_INFINITY,null])[1]}function Ks(e,t,i){e.nodes().forEach(e=>t.node(e).rank+=i)}var Zs=Hs,$s=Ws.slack,Js=Ws.longestPath,Qs=ms.alg.preorder,en=ms.alg.postorder,tn=ks.simplify,rn=sn;function sn(e){e=tn(e),Js(e);var t,i=Zs(e);for(on(i),nn(i,e);t=hn(i);)dn(i,e,t,cn(i,e,t))}function nn(e,t){var i=en(e,e.nodes());(i=i.slice(0,i.length-1)).forEach(i=>function(e,t,i){var r=e.node(i),s=r.parent;e.edge(i,s).cutvalue=an(e,t,i)}(e,t,i))}function an(e,t,i){var r=e.node(i).parent,s=!0,n=t.edge(i,r),a=0;return n||(s=!1,n=t.edge(r,i)),a=n.weight,t.nodeEdges(i).forEach(n=>{var o,l,h=n.v===i,c=h?n.w:n.v;if(c!==r){var d=h===s,u=t.edge(n).weight;if(a+=d?u:-u,o=i,l=c,e.hasEdge(o,l)){var _=e.edge(i,c).cutvalue;a+=d?-_:_}}}),a}function on(e,t){arguments.length<2&&(t=e.nodes()[0]),ln(e,{},1,t)}function ln(e,t,i,r,s){var n=i,a=e.node(r);return t[r]=!0,e.neighbors(r).forEach(s=>{Object.hasOwn(t,s)||(i=ln(e,t,i,s,r))}),a.low=n,a.lim=i++,s?a.parent=s:delete a.parent,i}function hn(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function cn(e,t,i){var r=i.v,s=i.w;t.hasEdge(r,s)||(r=i.w,s=i.v);var n=e.node(r),a=e.node(s),o=n,l=!1;n.lim>a.lim&&(o=a,l=!0);var h=t.edges().filter(t=>l===un(e,e.node(t.v),o)&&l!==un(e,e.node(t.w),o));return h.reduce((e,i)=>$s(t,i)<$s(t,e)?i:e)}function dn(e,t,i,r){var s=i.v,n=i.w;e.removeEdge(s,n),e.setEdge(r.v,r.w,{}),on(e),nn(e,t),function(e,t){var i=e.nodes().find(e=>!t.node(e).parent),r=Qs(e,i);(r=r.slice(1)).forEach(i=>{var r=e.node(i).parent,s=t.edge(i,r),n=!1;s||(s=t.edge(r,i),n=!0),t.node(i).rank=t.node(r).rank+(n?s.minlen:-s.minlen)})}(e,t)}function un(e,t,i){return i.low<=t.lim&&t.lim<=i.lim}sn.initLowLimValues=on,sn.initCutValues=nn,sn.calcCutValue=an,sn.leaveEdge=hn,sn.enterEdge=cn,sn.exchangeEdges=dn;var _n=Ws.longestPath,pn=Hs,fn=rn,gn=function(e){var t=e.graph().ranker;if(t instanceof Function)return t(e);switch(e.graph().ranker){case"network-simplex":default:mn(e);break;case"tight-tree":!function(e){_n(e),pn(e)}(e);break;case"longest-path":yn(e);case"none":}};var yn=_n;function mn(e){fn(e)}var bn=function(e){let t=function(e){let t={},i=0;function r(s){let n=i;e.children(s).forEach(r),t[s]={low:n,lim:i++}}return e.children().forEach(r),t}(e);e.graph().dummyChains.forEach(i=>{let r=e.node(i),s=r.edgeObj,n=function(e,t,i,r){let s,n,a=[],o=[],l=Math.min(t[i].low,t[r].low),h=Math.max(t[i].lim,t[r].lim);s=i;do{s=e.parent(s),a.push(s)}while(s&&(t[s].low>l||h>t[s].lim));n=s,s=r;for(;(s=e.parent(s))!==n;)o.push(s);return{path:a.concat(o.reverse()),lca:n}}(e,t,s.v,s.w),a=n.path,o=n.lca,l=0,h=a[l],c=!0;for(;i!==s.w;){if(r=e.node(i),c){for(;(h=a[l])!==o&&e.node(h).maxRank<r.rank;)l++;h===o&&(c=!1)}if(!c){for(;l<a.length-1&&e.node(h=a[l+1]).minRank<=r.rank;)l++;h=a[l]}e.setParent(i,h),i=e.successors(i)[0]}})};let xn=ks;var vn={run:function(e){let t=xn.addDummyNode(e,"root",{},"_root"),i=function(e){var t={};function i(r,s){var n=e.children(r);n&&n.length&&n.forEach(e=>i(e,s+1)),t[r]=s}return e.children().forEach(e=>i(e,1)),t}(e),r=Object.values(i),s=xn.applyWithChunking(Math.max,r)-1,n=2*s+1;e.graph().nestingRoot=t,e.edges().forEach(t=>e.edge(t).minlen*=n);let a=function(e){return e.edges().reduce((t,i)=>t+e.edge(i).weight,0)}(e)+1;e.children().forEach(r=>wn(e,t,n,a,s,i,r)),e.graph().nodeRankFactor=n},cleanup:function(e){var t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(t=>{e.edge(t).nestingEdge&&e.removeEdge(t)})}};function wn(e,t,i,r,s,n,a){let o=e.children(a);if(!o.length)return void(a!==t&&e.setEdge(t,a,{weight:0,minlen:i}));let l=xn.addBorderNode(e,"_bt"),h=xn.addBorderNode(e,"_bb"),c=e.node(a);e.setParent(l,a),c.borderTop=l,e.setParent(h,a),c.borderBottom=h,o.forEach(o=>{wn(e,t,i,r,s,n,o);let c=e.node(o),d=c.borderTop?c.borderTop:o,u=c.borderBottom?c.borderBottom:o,_=c.borderTop?r:2*r,p=d!==u?1:s-n[a]+1;e.setEdge(l,d,{weight:_,minlen:p,nestingEdge:!0}),e.setEdge(u,h,{weight:_,minlen:p,nestingEdge:!0})}),e.parent(a)||e.setEdge(t,l,{weight:0,minlen:s+n[a]})}let En=ks;var An=function(e){e.children().forEach(function t(i){let r=e.children(i),s=e.node(i);if(r.length&&r.forEach(t),Object.hasOwn(s,"minRank")){s.borderLeft=[],s.borderRight=[];for(let t=s.minRank,r=s.maxRank+1;t<r;++t)Cn(e,"borderLeft","_bl",i,s,t),Cn(e,"borderRight","_br",i,s,t)}})};function Cn(e,t,i,r,s,n){let a={width:0,height:0,rank:n,borderType:t},o=s[t][n-1],l=En.addDummyNode(e,"border",a,i);s[t][n]=l,e.setParent(l,r),o&&e.setEdge(o,l,{weight:1})}function Sn(e){e.nodes().forEach(t=>Rn(e.node(t))),e.edges().forEach(t=>Rn(e.edge(t)))}function Rn(e){let t=e.width;e.width=e.height,e.height=t}function kn(e){e.y=-e.y}function Tn(e){let t=e.x;e.x=e.y,e.y=t}let On=ks;var In=function(e){let t={},i=e.nodes().filter(t=>!e.children(t).length),r=i.map(t=>e.node(t).rank),s=On.applyWithChunking(Math.max,r),n=On.range(s+1).map(()=>[]);function a(i){if(t[i])return;t[i]=!0;let r=e.node(i);n[r.rank].push(i),e.successors(i).forEach(a)}return i.sort((t,i)=>e.node(t).rank-e.node(i).rank).forEach(a),n};let Nn=ks.zipObject;function Ln(e,t,i){let r=Nn(i,i.map((e,t)=>t)),s=t.flatMap(t=>e.outEdges(t).map(t=>({pos:r[t.w],weight:e.edge(t).weight})).sort((e,t)=>e.pos-t.pos)),n=1;for(;n<i.length;)n<<=1;let a=2*n-1;n-=1;let o=new Array(a).fill(0),l=0;return s.forEach(e=>{let t=e.pos+n;o[t]+=e.weight;let i=0;for(;t>0;)t%2&&(i+=o[t+1]),t=t-1>>1,o[t]+=e.weight;l+=e.weight*i}),l}let Pn=ks;let Vn=ks;function Mn(e,t,i){let r;for(;t.length&&(r=t[t.length-1]).i<=i;)t.pop(),e.push(r.vs),i++;return i}let Bn=function(e,t=[]){return t.map(t=>{let i=e.inEdges(t);if(i.length){let r=i.reduce((t,i)=>{let r=e.edge(i),s=e.node(i.v);return{sum:t.sum+r.weight*s.order,weight:t.weight+r.weight}},{sum:0,weight:0});return{v:t,barycenter:r.sum/r.weight,weight:r.weight}}return{v:t}})},Dn=function(e,t){let i={};return e.forEach((e,t)=>{let r=i[e.v]={indegree:0,in:[],out:[],vs:[e.v],i:t};void 0!==e.barycenter&&(r.barycenter=e.barycenter,r.weight=e.weight)}),t.edges().forEach(e=>{let t=i[e.v],r=i[e.w];void 0!==t&&void 0!==r&&(r.indegree++,t.out.push(i[e.w]))}),function(e){let t=[];function i(e){return t=>{t.merged||(void 0===t.barycenter||void 0===e.barycenter||t.barycenter>=e.barycenter)&&function(e,t){let i=0,r=0;e.weight&&(i+=e.barycenter*e.weight,r+=e.weight);t.weight&&(i+=t.barycenter*t.weight,r+=t.weight);e.vs=t.vs.concat(e.vs),e.barycenter=i/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}(e,t)}}function r(t){return i=>{i.in.push(t),0===--i.indegree&&e.push(i)}}for(;e.length;){let s=e.pop();t.push(s),s.in.reverse().forEach(i(s)),s.out.forEach(r(s))}return t.filter(e=>!e.merged).map(e=>Pn.pick(e,["vs","i","barycenter","weight"]))}(Object.values(i).filter(e=>!e.indegree))},Gn=function(e,t){let i=Vn.partition(e,e=>Object.hasOwn(e,"barycenter")),r=i.lhs,s=i.rhs.sort((e,t)=>t.i-e.i),n=[],a=0,o=0,l=0;r.sort((h=!!t,(e,t)=>e.barycenter<t.barycenter?-1:e.barycenter>t.barycenter?1:h?t.i-e.i:e.i-t.i)),l=Mn(n,s,l),r.forEach(e=>{l+=e.vs.length,n.push(e.vs),a+=e.barycenter*e.weight,o+=e.weight,l=Mn(n,s,l)});var h;let c={vs:n.flat(!0)};o&&(c.barycenter=a/o,c.weight=o);return c};var zn=function e(t,i,r,s){let n=t.children(i),a=t.node(i),o=a?a.borderLeft:void 0,l=a?a.borderRight:void 0,h={};o&&(n=n.filter(e=>e!==o&&e!==l));let c=Bn(t,n);c.forEach(i=>{if(t.children(i.v).length){let o=e(t,i.v,r,s);h[i.v]=o,Object.hasOwn(o,"barycenter")&&(a=o,void 0!==(n=i).barycenter?(n.barycenter=(n.barycenter*n.weight+a.barycenter*a.weight)/(n.weight+a.weight),n.weight+=a.weight):(n.barycenter=a.barycenter,n.weight=a.weight))}var n,a});let d=Dn(c,r);!function(e,t){e.forEach(e=>{e.vs=e.vs.flatMap(e=>t[e]?t[e].vs:e)})}(d,h);let u=Gn(d,s);if(o&&(u.vs=[o,u.vs,l].flat(!0),t.predecessors(o).length)){let e=t.node(t.predecessors(o)[0]),i=t.node(t.predecessors(l)[0]);Object.hasOwn(u,"barycenter")||(u.barycenter=0,u.weight=0),u.barycenter=(u.barycenter*u.weight+e.order+i.order)/(u.weight+2),u.weight+=2}return u};let jn=ms.Graph,Fn=ks;var Wn=function(e,t,i,r){r||(r=e.nodes());let s=function(e){var t;for(;e.hasNode(t=Fn.uniqueId("_root")););return t}(e),n=new jn({compound:!0}).setGraph({root:s}).setDefaultNodeLabel(t=>e.node(t));return r.forEach(r=>{let a=e.node(r),o=e.parent(r);(a.rank===t||a.minRank<=t&&t<=a.maxRank)&&(n.setNode(r),n.setParent(r,o||s),e[i](r).forEach(t=>{let i=t.v===r?t.w:t.v,s=n.edge(i,r),a=void 0!==s?s.weight:0;n.setEdge(i,r,{weight:e.edge(t).weight+a})}),Object.hasOwn(a,"minRank")&&n.setNode(r,{borderLeft:a.borderLeft[t],borderRight:a.borderRight[t]}))}),n};let Un=In,Yn=function(e,t){let i=0;for(let r=1;r<t.length;++r)i+=Ln(e,t[r-1],t[r]);return i},Hn=zn,Xn=Wn,qn=function(e,t,i){let r,s={};i.forEach(i=>{let n,a,o=e.parent(i);for(;o;){if(n=e.parent(o),n?(a=s[n],s[n]=o):(a=r,r=o),a&&a!==o)return void t.setEdge(a,o);o=n}})},Kn=ms.Graph,Zn=ks;var $n=function e(t,i){if(i&&"function"==typeof i.customOrder)return void i.customOrder(t,e);let r=Zn.maxRank(t),s=Jn(t,Zn.range(1,r+1),"inEdges"),n=Jn(t,Zn.range(r-1,-1,-1),"outEdges"),a=Un(t);if(ea(t,a),i&&i.disableOptimalOrderHeuristic)return;let o,l=Number.POSITIVE_INFINITY;for(let e=0,i=0;i<4;++e,++i){Qn(e%2?s:n,e%4>=2),a=Zn.buildLayerMatrix(t);let r=Yn(t,a);r<l&&(i=0,o=Object.assign({},a),l=r)}ea(t,o)};function Jn(e,t,i){const r=new Map,s=(e,t)=>{r.has(e)||r.set(e,[]),r.get(e).push(t)};for(const t of e.nodes()){const i=e.node(t);if("number"==typeof i.rank&&s(i.rank,t),"number"==typeof i.minRank&&"number"==typeof i.maxRank)for(let e=i.minRank;e<=i.maxRank;e++)e!==i.rank&&s(e,t)}return t.map(function(t){return Xn(e,t,i,r.get(t)||[])})}function Qn(e,t){let i=new Kn;e.forEach(function(e){let r=e.graph().root,s=Hn(e,r,i,t);s.vs.forEach((t,i)=>e.node(t).order=i),qn(e,i,s.vs)})}function ea(e,t){Object.values(t).forEach(t=>t.forEach((t,i)=>e.node(t).order=i))}let ta=ms.Graph,ia=ks;var ra=function(e){let t,i=ia.buildLayerMatrix(e),r=Object.assign(function(e,t){let i={};function r(t,r){let s=0,n=0,a=t.length,o=r[r.length-1];return r.forEach((t,l)=>{let h=function(e,t){if(e.node(t).dummy)return e.predecessors(t).find(t=>e.node(t).dummy)}(e,t),c=h?e.node(h).order:a;(h||t===o)&&(r.slice(n,l+1).forEach(t=>{e.predecessors(t).forEach(r=>{let n=e.node(r),a=n.order;!(a<s||c<a)||n.dummy&&e.node(t).dummy||sa(i,r,t)})}),n=l+1,s=c)}),r}return t.length&&t.reduce(r),i}(e,i),function(e,t){let i={};function r(t,r,s,n,a){let o;ia.range(r,s).forEach(r=>{o=t[r],e.node(o).dummy&&e.predecessors(o).forEach(t=>{let r=e.node(t);r.dummy&&(r.order<n||r.order>a)&&sa(i,t,o)})})}function s(t,i){let s,n=-1,a=0;return i.forEach((o,l)=>{if("border"===e.node(o).dummy){let t=e.predecessors(o);t.length&&(s=e.node(t[0]).order,r(i,a,l,n,s),a=l,n=s)}r(i,a,i.length,s,t.length)}),i}return t.length&&t.reduce(s),i}(e,i)),s={};["u","d"].forEach(n=>{t="u"===n?i:Object.values(i).reverse(),["l","r"].forEach(i=>{"r"===i&&(t=t.map(e=>Object.values(e).reverse()));let a=("u"===n?e.predecessors:e.successors).bind(e),o=function(e,t,i,r){let s={},n={},a={};return t.forEach(e=>{e.forEach((e,t)=>{s[e]=e,n[e]=e,a[e]=t})}),t.forEach(e=>{let t=-1;e.forEach(e=>{let o=r(e);if(o.length){o=o.sort((e,t)=>a[e]-a[t]);let r=(o.length-1)/2;for(let l=Math.floor(r),h=Math.ceil(r);l<=h;++l){let r=o[l];n[e]===e&&t<a[r]&&!na(i,e,r)&&(n[r]=e,n[e]=s[e]=s[r],t=a[r])}}})}),{root:s,align:n}}(0,t,r,a),l=function(e,t,i,r,s){let n={},a=function(e,t,i,r){let s=new ta,n=e.graph(),a=function(e,t,i){return(r,s,n)=>{let a,o=r.node(s),l=r.node(n),h=0;if(h+=o.width/2,Object.hasOwn(o,"labelpos"))switch(o.labelpos.toLowerCase()){case"l":a=-o.width/2;break;case"r":a=o.width/2}if(a&&(h+=i?a:-a),a=0,h+=(o.dummy?t:e)/2,h+=(l.dummy?t:e)/2,h+=l.width/2,Object.hasOwn(l,"labelpos"))switch(l.labelpos.toLowerCase()){case"l":a=l.width/2;break;case"r":a=-l.width/2}return a&&(h+=i?a:-a),a=0,h}}(n.nodesep,n.edgesep,r);return t.forEach(t=>{let r;t.forEach(t=>{let n=i[t];if(s.setNode(n),r){var o=i[r],l=s.edge(o,n);s.setEdge(o,n,Math.max(a(e,t,r),l||0))}r=t})}),s}(e,t,i,s),o=s?"borderLeft":"borderRight";function l(e,t){let i=a.nodes(),r=i.pop(),s={};for(;r;)s[r]?e(r):(s[r]=!0,i.push(r),i=i.concat(t(r))),r=i.pop()}function h(e){n[e]=a.inEdges(e).reduce((e,t)=>Math.max(e,n[t.v]+a.edge(t)),0)}function c(t){let i=a.outEdges(t).reduce((e,t)=>Math.min(e,n[t.w]-a.edge(t)),Number.POSITIVE_INFINITY),r=e.node(t);i!==Number.POSITIVE_INFINITY&&r.borderType!==o&&(n[t]=Math.max(n[t],i))}return l(h,a.predecessors.bind(a)),l(c,a.successors.bind(a)),Object.keys(r).forEach(e=>n[e]=n[i[e]]),n}(e,t,o.root,o.align,"r"===i);"r"===i&&(l=ia.mapValues(l,e=>-e)),s[n+i]=l})});let n=function(e,t){return Object.values(t).reduce((t,i)=>{let r=Number.NEGATIVE_INFINITY,s=Number.POSITIVE_INFINITY;Object.entries(i).forEach(([t,i])=>{let n=function(e,t){return e.node(t).width}(e,t)/2;r=Math.max(i+n,r),s=Math.min(i-n,s)});const n=r-s;return n<t[0]&&(t=[n,i]),t},[Number.POSITIVE_INFINITY,null])[1]}(e,s);return function(e,t){let i=Object.values(t),r=ia.applyWithChunking(Math.min,i),s=ia.applyWithChunking(Math.max,i);["u","d"].forEach(i=>{["l","r"].forEach(n=>{let a=i+n,o=e[a];if(o===t)return;let l=Object.values(o),h=r-ia.applyWithChunking(Math.min,l);"l"!==n&&(h=s-ia.applyWithChunking(Math.max,l)),h&&(e[a]=ia.mapValues(o,e=>e+h))})})}(s,n),function(e,t){return ia.mapValues(e.ul,(i,r)=>{if(t)return e[t.toLowerCase()][r];{let t=Object.values(e).map(e=>e[r]).sort((e,t)=>e-t);return(t[1]+t[2])/2}})}(s,e.graph().align)};function sa(e,t,i){if(t>i){let e=t;t=i,i=e}let r=e[t];r||(e[t]=r={}),r[i]=!0}function na(e,t,i){if(t>i){let e=t;t=i,i=e}return!!e[t]&&Object.hasOwn(e[t],i)}let aa=ks,oa=ra;let la=Gs,ha=js,ca=gn,da=ks.normalizeRanks,ua=bn,_a=ks.removeEmptyRanks,pa=vn,fa=An,ga={adjust:function(e){let t=e.graph().rankdir.toLowerCase();"lr"!==t&&"rl"!==t||Sn(e)},undo:function(e){let t=e.graph().rankdir.toLowerCase();"bt"!==t&&"rl"!==t||function(e){e.nodes().forEach(t=>kn(e.node(t))),e.edges().forEach(t=>{let i=e.edge(t);i.points.forEach(kn),Object.hasOwn(i,"y")&&kn(i)})}(e);"lr"!==t&&"rl"!==t||(!function(e){e.nodes().forEach(t=>Tn(e.node(t))),e.edges().forEach(t=>{let i=e.edge(t);i.points.forEach(Tn),Object.hasOwn(i,"x")&&Tn(i)})}(e),Sn(e))}},ya=$n,ma=function(e){(function(e){let t=aa.buildLayerMatrix(e),i=e.graph().ranksep,r=0;t.forEach(t=>{const s=t.reduce((t,i)=>{const r=e.node(i).height;return t>r?t:r},0);t.forEach(t=>e.node(t).y=r+s/2),r+=s+i})})(e=aa.asNonCompoundGraph(e)),Object.entries(oa(e)).forEach(([t,i])=>e.node(t).x=i)},ba=ks,xa=ms.Graph;var va=function(e,t){let i=t&&t.debugTiming?ba.time:ba.notime;i("layout",()=>{let r=i(" buildLayoutGraph",()=>function(e){let t=new xa({multigraph:!0,compound:!0}),i=Ia(e.graph());return t.setGraph(Object.assign({},Ea,Oa(i,wa),ba.pick(i,Aa))),e.nodes().forEach(i=>{const r=Oa(Ia(e.node(i)),Ca);Object.keys(Sa).forEach(e=>{void 0===r[e]&&(r[e]=Sa[e])}),t.setNode(i,r),t.setParent(i,e.parent(i))}),e.edges().forEach(i=>{let r=Ia(e.edge(i));t.setEdge(i,Object.assign({},ka,Oa(r,Ra),ba.pick(r,Ta)))}),t}(e));i(" runLayout",()=>function(e,t,i){t(" makeSpaceForEdgeLabels",()=>function(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(i=>{let r=e.edge(i);r.minlen*=2,"c"!==r.labelpos.toLowerCase()&&("TB"===t.rankdir||"BT"===t.rankdir?r.width+=r.labeloffset:r.height+=r.labeloffset)})}(e)),t(" removeSelfEdges",()=>function(e){e.edges().forEach(t=>{if(t.v===t.w){var i=e.node(t.v);i.selfEdges||(i.selfEdges=[]),i.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}(e)),t(" acyclic",()=>la.run(e)),t(" nestingGraph.run",()=>pa.run(e)),t(" rank",()=>ca(ba.asNonCompoundGraph(e))),t(" injectEdgeLabelProxies",()=>function(e){e.edges().forEach(t=>{let i=e.edge(t);if(i.width&&i.height){let i=e.node(t.v),r={rank:(e.node(t.w).rank-i.rank)/2+i.rank,e:t};ba.addDummyNode(e,"edge-proxy",r,"_ep")}})}(e)),t(" removeEmptyRanks",()=>_a(e)),t(" nestingGraph.cleanup",()=>pa.cleanup(e)),t(" normalizeRanks",()=>da(e)),t(" assignRankMinMax",()=>function(e){let t=0;e.nodes().forEach(i=>{let r=e.node(i);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=Math.max(t,r.maxRank))}),e.graph().maxRank=t}(e)),t(" removeEdgeLabelProxies",()=>function(e){e.nodes().forEach(t=>{let i=e.node(t);"edge-proxy"===i.dummy&&(e.edge(i.e).labelRank=i.rank,e.removeNode(t))})}(e)),t(" normalize.run",()=>ha.run(e)),t(" parentDummyChains",()=>ua(e)),t(" addBorderSegments",()=>fa(e)),t(" order",()=>ya(e,i)),t(" insertSelfEdges",()=>function(e){var t=ba.buildLayerMatrix(e);t.forEach(t=>{var i=0;t.forEach((t,r)=>{var s=e.node(t);s.order=r+i,(s.selfEdges||[]).forEach(t=>{ba.addDummyNode(e,"selfedge",{width:t.label.width,height:t.label.height,rank:s.rank,order:r+ ++i,e:t.e,label:t.label},"_se")}),delete s.selfEdges})})}(e)),t(" adjustCoordinateSystem",()=>ga.adjust(e)),t(" position",()=>ma(e)),t(" positionSelfEdges",()=>function(e){e.nodes().forEach(t=>{var i=e.node(t);if("selfedge"===i.dummy){var r=e.node(i.e.v),s=r.x+r.width/2,n=r.y,a=i.x-s,o=r.height/2;e.setEdge(i.e,i.label),e.removeNode(t),i.label.points=[{x:s+2*a/3,y:n-o},{x:s+5*a/6,y:n-o},{x:s+a,y:n},{x:s+5*a/6,y:n+o},{x:s+2*a/3,y:n+o}],i.label.x=i.x,i.label.y=i.y}})}(e)),t(" removeBorderNodes",()=>function(e){e.nodes().forEach(t=>{if(e.children(t).length){let i=e.node(t),r=e.node(i.borderTop),s=e.node(i.borderBottom),n=e.node(i.borderLeft[i.borderLeft.length-1]),a=e.node(i.borderRight[i.borderRight.length-1]);i.width=Math.abs(a.x-n.x),i.height=Math.abs(s.y-r.y),i.x=n.x+i.width/2,i.y=r.y+i.height/2}}),e.nodes().forEach(t=>{"border"===e.node(t).dummy&&e.removeNode(t)})}(e)),t(" normalize.undo",()=>ha.undo(e)),t(" fixupEdgeLabelCoords",()=>function(e){e.edges().forEach(t=>{let i=e.edge(t);if(Object.hasOwn(i,"x"))switch("l"!==i.labelpos&&"r"!==i.labelpos||(i.width-=i.labeloffset),i.labelpos){case"l":i.x-=i.width/2+i.labeloffset;break;case"r":i.x+=i.width/2+i.labeloffset}})}(e)),t(" undoCoordinateSystem",()=>ga.undo(e)),t(" translateGraph",()=>function(e){let t=Number.POSITIVE_INFINITY,i=0,r=Number.POSITIVE_INFINITY,s=0,n=e.graph(),a=n.marginx||0,o=n.marginy||0;function l(e){let n=e.x,a=e.y,o=e.width,l=e.height;t=Math.min(t,n-o/2),i=Math.max(i,n+o/2),r=Math.min(r,a-l/2),s=Math.max(s,a+l/2)}e.nodes().forEach(t=>l(e.node(t))),e.edges().forEach(t=>{let i=e.edge(t);Object.hasOwn(i,"x")&&l(i)}),t-=a,r-=o,e.nodes().forEach(i=>{let s=e.node(i);s.x-=t,s.y-=r}),e.edges().forEach(i=>{let s=e.edge(i);s.points.forEach(e=>{e.x-=t,e.y-=r}),Object.hasOwn(s,"x")&&(s.x-=t),Object.hasOwn(s,"y")&&(s.y-=r)}),n.width=i-t+a,n.height=s-r+o}(e)),t(" assignNodeIntersects",()=>function(e){e.edges().forEach(t=>{let i,r,s=e.edge(t),n=e.node(t.v),a=e.node(t.w);s.points?(i=s.points[0],r=s.points[s.points.length-1]):(s.points=[],i=a,r=n),s.points.unshift(ba.intersectRect(n,i)),s.points.push(ba.intersectRect(a,r))})}(e)),t(" reversePoints",()=>function(e){e.edges().forEach(t=>{let i=e.edge(t);i.reversed&&i.points.reverse()})}(e)),t(" acyclic.undo",()=>la.undo(e))}(r,i,t)),i(" updateInputGraph",()=>function(e,t){e.nodes().forEach(i=>{let r=e.node(i),s=t.node(i);r&&(r.x=s.x,r.y=s.y,r.rank=s.rank,t.children(i).length&&(r.width=s.width,r.height=s.height))}),e.edges().forEach(i=>{let r=e.edge(i),s=t.edge(i);r.points=s.points,Object.hasOwn(s,"x")&&(r.x=s.x,r.y=s.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}(e,r))})};let wa=["nodesep","edgesep","ranksep","marginx","marginy"],Ea={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},Aa=["acyclicer","ranker","rankdir","align"],Ca=["width","height","rank"],Sa={width:0,height:0},Ra=["minlen","weight","width","height","labeloffset"],ka={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},Ta=["labelpos"];function Oa(e,t){return ba.mapValues(ba.pick(e,t),Number)}function Ia(e){var t={};return e&&Object.entries(e).forEach(([e,i])=>{"string"==typeof e&&(e=e.toLowerCase()),t[e]=i}),t}let Na=ks,La=ms.Graph;var Pa={graphlib:ms,layout:va,debug:{debugOrdering:function(e){let t=Na.buildLayerMatrix(e),i=new La({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(t=>{i.setNode(t,{label:t}),i.setParent(t,"layer"+e.node(t).rank)}),e.edges().forEach(e=>i.setEdge(e.v,e.w,{},e.name)),t.forEach((e,t)=>{let r="layer"+t;i.setNode(r,{rank:"same"}),e.reduce((e,t)=>(i.setEdge(e,t,{style:"invis"}),t))}),i}},util:{time:ks.time,notime:ks.notime},version:"1.1.8"};class Va extends ye{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=we(e.parent);for(let e of t){let t=e.layout;if(!t)continue;let r=F(e.children[0]);if(!r)continue;var i=new Pa.graphlib.Graph;i.setGraph({edgesep:t.edgeSep,nodesep:t.nodeSep,ranksep:t.rankSep}),i.setDefaultEdgeLabel(function(){return{}}),i.graph().rankdir=this._getDagreDirection(t.direction);let s=new Map;for(let t of e.children){let e=t.datum[U];s.set(e,e+""),i.setNode(e,{label:t.text?t.text:"",width:t.bounds.width,height:t.bounds.height})}for(let e of r.linkList)i.setEdge(e.source,e.target);Pa.layout(i);const n={};let a=d3.min(i.nodes().map(e=>i.node(e).y)),o=d3.min(i.nodes().map(e=>i.node(e).x)),l=t.left-o,h=t.top-a;for(const e of i.nodes())n[e]={x:i.node(e).x+l,y:i.node(e).y+h};for(let t of e.children){let e=t.datum[U];wt(t,n[s.get(e)].x-t.x,n[s.get(e)].y-t.y)}}let r=Le(e,!0);for(let e of r)le(e)}_getDagreDirection(e){switch(e){case Pt.Left2Right:return"LR";case Pt.Right2Left:return"RL";case Pt.Top2Bottom:return"TB";case Pt.Bottom2Top:return"BT"}}}class Ma extends ye{constructor(e){super(e)}run(){super.run();let t=this._outputVars[0].element,i=we(t.parent);for(let t of i){let i=t.layout;if(!i)continue;let r=z(t.children[0]);if(!r)continue;let s=e.hierarchy(r._data),n=Math.max(...t.children.map(e=>e.bounds.width)),a=Math.max(...t.children.map(e=>e.bounds.height)),o=i.orientation==Ot?[i.height,i.width]:[i.width,i.height],l=e.tree().nodeSize([n,a]).size(o)(s);this._apply(l,i,t)}le(t)}_apply(e,t,i){let r,s,n=i.children.filter(t=>t.datum[U]==e.data[U])[0];switch(t.orientation){case Ot:r=e.y+t.left,s=e.x+t.top;break;case It:r=e.x+t.left,s=t.top+e.y}if(wt(n,r-n.x,s-n.y),e.children&&e.children.length>0)for(let r of e.children)this._apply(r,t,i)}}class Ba extends ye{constructor(e){super(e)}run(){super.run();let t=this._outputVars[0].element,r=this._inputVars.filter(e=>e.type===xe.PROPERTY&&e.property===ze.CHILDREN_ORDER)[0].element,s=r.layout,n=s.width?s.width:r.bounds.width,a=s.height?s.height:r.bounds.height,o=void 0===s.top?r.bounds.top:s.top,l=void 0===s.left?r.bounds.left:s.left,h=e.hierarchy(r).sum(e=>e.type===i.Rect?e.width*e.height:0);e.treemap().size([n,a])(h),this._apply(h,l,o);let c=Le(t,!0);for(let e of c)le(e)}_apply(e,t,r){if(e.data.type==i.Collection&&e.children)for(let i of e.children)this._apply(i,t,r);else e.data.type==i.Rect&&(e.data.resize(e.x1-e.x0,e.y1-e.y0),wt(e.data,e.x0+t-e.data.left,e.y0+r-e.data.top))}}class Da extends ye{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=we(e.parent);for(let e of t){if(!e.layout)continue;if(0===e.children.length)continue;let t=z(e.children[0]);if(!t)continue;let r={};for(let t of e.children)r[t.datum[U]]=t;e.children[0].type===i.Rect?this._layoutRects(t.getRoot(),t,r):this._layoutArcs(t.getRoot(),t,r)}le(e)}_layoutArcs(e,t,r){let s=t.getChildren(e);if(0===s.length)return;let n=r[e[U]],a=!n||n.type!=i.Arc&&n.type!=i.Pie?60:n.startAngle;for(let e=0;e<s.length;e++){let n=s[e],o=r[n[U]];if(o.type===i.Arc){let e=Kt(a+o.angle);o.setAngles(a,e),a=e}this._layoutArcs(n,t,r)}}_layoutRects(e,t,i){let r=t.getChildren(e);if(0===r.length)return;let s,n,a=i[e[U]];this._direction,s=a.left,n=a.bottom;for(let e=0;e<r.length;e++){let a=r[e],o=i[a[U]];wt(o,s-o.left,n-o.top),s+=o.width,this._layoutRects(a,t,i)}}}class Ga extends ye{constructor(e){super(e)}run(){super.run();let e=this.outputVar;e.clearResult();let t=this.inputVars.find(e=>void 0!==e.context),i=e.conditionalEncoding,r=t?t.context:void 0,s=Ie(i.responderComponent).state,n=e.result;if(i.evalFunction){i.getResponderPeers().forEach(e=>n[e.id]=!!i.evalFunction(r,s,e))}}}class za extends ye{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=we(e.parent);for(let e of t){let t=e.layout;if(!t)continue;let i=360/e.children.length;for(let[r,s]of e.children.entries()){s._rotate=void 0,s._markRotationOffset=void 0,s._updateBounds();let e=r*i,n=ee(t.x+t.radius,t.y,t.x,t.y,e);switch(wt(s,n.x-s.bounds.x,n.y-s.bounds.y),t.markRotation){case Bt.INWARD:s._markRotationOffset=e+90;break;case Bt.TANGENTIAL_CLOCKWISE:s._markRotationOffset=e;break;case Bt.TANGENTIAL_COUNTERCLOCKWISE:s._markRotationOffset=e-180;break;case Bt.UPRIGHT:break;case Bt.OUTWARD:default:s._markRotationOffset=e-90}}}let i=Le(e,!0);for(let e of i)le(e)}}class ja extends ye{constructor(e){super(e)}run(){super.run();let t=this._outputVars[0].element,i=we(t.parent);for(let r of i){let i=r.layout;if(!i)continue;let s=i._tree??z(r.children[0]);if(!s){console.warn("cluster layout has no tree; skipping placement for",r.id);continue}let n=e.hierarchy(s._data);if(i.isRadial()){n=e.cluster().size([Xt(i.angleExtent),i.radius])(n),i._d3Root=n;const t=new Map(n.descendants().map(e=>[e.data[U],[e.x,e.y]]));for(let e of r.children){let r=e.datum[U];e._rotate=void 0,e._bounds=void 0,wt(e,i.x-e.bounds.x,i.y-t.get(r)[1]-e.bounds.y),e._rotate=[qt(t.get(r)[0]),i.x,i.y]}}else if(i.orientation===It){!i.width||i.width;let s=i.height?i.height:600;n=e.cluster().nodeSize([t.bounds.width+1,s/(n.height+1)])(n),i._d3Root=n;const a=new Map(n.descendants().map(e=>[e.data[U],[e.x,e.y]]));let o=1/0,l=-o;n.each(e=>{e.x>l&&(l=e.x),e.x<o&&(o=e.x)}),i._x0=o;for(let e of r.children){let t=e.datum[U];wt(e,a.get(t)[0]-o+i.left-e.bounds.x,a.get(t)[1]+i.top-e.bounds.y)}}else if(i.orientation===Ot){!i.width||i.width;let s=i.height?i.height:600;n=e.cluster().nodeSize([t.bounds.height,s/(n.height+1)])(n),i._d3Root=n;const a=new Map(n.descendants().map(e=>[e.data[U],[e.x,e.y]]));let o=1/0,l=-o;n.each(e=>{e.x>l&&(l=e.x),e.x<o&&(o=e.x)}),i._x0=o;for(let e of r.children){let t=e.datum[U];wt(e,a.get(t)[1]+i.left-e.bounds.x,a.get(t)[0]-o+i.top-e.bounds.y)}}}let r=Le(t,!0);for(let e of r)le(e)}}class Fa extends ye{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=we(e.parent);for(let e of t){let t=e.layout;if(!t)continue;let i=t.direction===Vt.ANTI_CLOCKWISE?-1:1;for(let[r,s]of e.children.entries()){s._rotate=void 0,s._markRotationOffset=void 0,s._updateBounds();let e=t.startRadius+t.radiusStep*r,n=t.startAngle+i*t.angleStep*r,a=ee(t.x+e,t.y,t.x,t.y,n);switch(wt(s,a.x-s.bounds.x,a.y-s.bounds.y),t.markRotation){case Bt.INWARD:s._markRotationOffset=n+90;break;case Bt.TANGENTIAL_CLOCKWISE:s._markRotationOffset=n;break;case Bt.TANGENTIAL_COUNTERCLOCKWISE:s._markRotationOffset=n-180;break;case Bt.UPRIGHT:break;case Bt.OUTWARD:default:s._markRotationOffset=n-90}}}let i=Le(e,!0);for(let e of i)le(e)}}class Wa extends ye{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=we(e.parent);for(let e of t){let t=e.layout;if(!t)continue;let i=e.children.filter(e=>"hidden"!==e.visibility),r=t.compute(i,t);if(r&&"object"==typeof r)for(let e of i){let t=r[e.id];if(!t||"number"!=typeof t.x||"number"!=typeof t.y)continue;let i=e.refBounds?e.refBounds:e.bounds,s=t.x-i.x,n=t.y-i.y;(s||n)&&wt(e,s,n)}}let i=Le(e,!0);for(let e of i)le(e)}}class Ua extends be{constructor(e,t){super(e),this._cond=t}get context(){return this._cond}}class Ya extends ye{constructor(e,t,i,r){super(e),this._fn=t,this._compnt=i,this._resolveDynamically=r}run(){super.run();let e=this.inputVars.find(e=>e instanceof Ua),t=e?e.context:void 0,r=this._resolveDynamically?function(e){let t=e?e.get("element"):void 0;for(;t&&t.parent&&t.parent.type!==i.Collection;)t=t.parent;return t}(t):this._compnt;if(!r)return;let s=Ie(this._compnt);if(this._fn(void 0,t,s?s.state:void 0,r),s)for(let e of this._outputVars){let t=e.element||e.stateContext;t&&t._scene&&(e.type===xe.CHANNEL?s.onChange(xe.CHANNEL,e.channel,t):e.type===xe.PROPERTY?s.onChange(xe.PROPERTY,e.property,t):e.type===xe.STATE&&s.onChange(xe.STATE,e.key,e.stateContext))}}}class Ha extends be{constructor(e,t,i,r=null){super(e),this._attribute=t,this._dataset=i,this._encoding=r}get attribute(){return this._attribute}get dataset(){return this._dataset}get encoding(){return this._encoding}}class Xa extends ye{constructor(e){super(e)}run(){super.run();let e=this.outputVar,t=this.inputVars.find(e=>e instanceof Ha),i=e.encodings[0].dataTable.type(t.attribute),r={};for(let t of e.encodings){let e=this._computeAttrValues(t,i);Object.assign(r,e)}e.attrValues=r}_computeAttrValues(e,t){if("vertex"===e.element.type)return this._computeVertexIndexAttrValues(e,t);let r=we(e.element),s={};if(e.element.type===i.Area&&["width","height"].indexOf(e.channel)>=0||["fillGradient","strokeGradient"].indexOf(e.channel)>=0)for(let t of r)for(let i=0;i<t._vertices.length;i++)s[Ae(t,i)]=t._vertices.hasDataScope(i)?t._vertices.aggregateDataScopeAttribute(i,e.attribute,e.aggregator):T(t.dataScope,e.attribute,e.aggregator);else switch(t){case a.Boolean:break;case a.Date:for(let t of r)s[t.id]=R(t.dataScope,e.attribute);break;case a.String:try{if("count"==e.aggregator)for(let t of r)s[t.id]=k(t.dataScope,e.attribute).length;else for(let t of r)s[t.id]=R(t.dataScope,e.attribute)}catch(t){throw new Error("Cannot bind "+this.channel+" to "+e.attribute+" : "+t)}break;default:if(e.attribute.startsWith("parent.")||e.attribute.startsWith("child.")){let t=e.dataTable.tree.nodeTable,i=e.attribute.split(".")[0],n=e.attribute.split(".")[1];for(let e of r){let r=R(e.dataScope,i);s[e.id]=R(O(N(t),U,r),n)}}else for(let t of r)s[t.id]=T(t.dataScope,e.attribute,e.aggregator)}return e.attrValues=s,s}_computeVertexIndexAttrValues(e,t){let i={};for(let r of e.elementGroups)for(let s of r.groups)for(let r of s.indices){i[Ae(s.parent,r)]=this._computeVertexIndexValue(s.parent,r,e,t)}return e.attrValues=i,i}_getVertexIndexContext(e,t,i){let r={type:"vertex",parent:e,index:t,_index:t,id:i};return Object.defineProperty(r,"dataScope",{get:()=>e._vertices.hasDataScope(t)?e._vertices.getDataScopeRef(t):e.dataScope}),Object.defineProperty(r,"datum",{get:()=>A(r.dataScope)}),Object.defineProperty(r,"data",{get:()=>E(r.dataScope)}),r}_computeVertexIndexValue(e,t,i,r){if(!e._vertices.hasDataScope(t))return this._computeValue(e.dataScope,i,r);if(i.attribute.startsWith("parent.")||i.attribute.startsWith("child."))return this._computeValue(e._vertices.getDataScopeRef(t),i,r);switch(r){case a.Boolean:return;case a.Date:return e._vertices.getDataScopeAttrVal(t,i.attribute);case a.String:return"count"==i.aggregator?e._vertices.getDataScopeAttributeValues(t,i.attribute).length:e._vertices.getDataScopeAttrVal(t,i.attribute);default:return e._vertices.aggregateDataScopeAttribute(t,i.attribute,i.aggregator)}}_computeValue(e,t,i){switch(i){case a.Boolean:return;case a.Date:return R(e,t.attribute);case a.String:return"count"==t.aggregator?k(e,t.attribute).length:R(e,t.attribute);default:if(t.attribute.startsWith("parent.")||t.attribute.startsWith("child.")){let i=t.dataTable.tree.nodeTable,r=t.attribute.split(".")[0],s=t.attribute.split(".")[1],n=R(e,r);return R(O(N(i),U,n),s)}return T(e,t.attribute,t.aggregator)}}}class qa extends be{constructor(e,t,i){super(e),this._key=t,this._stateContext=i}get key(){return this._key}get stateContext(){return this._stateContext}}class Ka{constructor(){this._variables={},this._operators={},this._edges=[]}toJSON(){const e=this._edges.map(e=>({from:e.fromNode.id,to:e.toNode.id,isDirected:e.isDirected})),t={};for(const e in this._variables)t[e]=Object.values(this._variables[e]).map(e=>{let t={id:e.id,type:e.type,incoming:e.incomingEdges.map(e=>e.id),outgoing:e.outgoingEdges.map(e=>e.id),undirected:e.undirectedEdges.map(e=>e.id)};return"ChannelVar"===e.type?(t.channel=e.channel,t.element=e.element):"BoundsVar"===e.type||"DataScopeVar"===e.type?t.element=e.element:"dataValue"===e.type?(t.scale=e.scale,t.attrValues=e.attrValues):"FieldVar"===e.type?(t.field=e.field,t.dataset=e.dataset):"PropertyVar"===e.type?(t.property=e.property,t.element=e.element):e.type===xe.STATE?t.key=e.key:t.scale=e.scale,t});const i={};for(const e in this._operators)i[e]=Object.values(this._operators[e]).map(e=>{let t={id:e.id,type:e.type,inputVars:e.inputVars.map(e=>e.id),outputVar:e.outputVar?e.outputVar.id:null};return e.type===me.DOMAIN_BUILDER?t.aggregator=e.aggregator:e.type===me.SCALE_BUILDER&&(t.channel=e.channel),t});return{edges:e,variables:t,operators:i}}getVariable(e,...t){if(Object.values(xe).indexOf(e)<0)throw console.log(e),new Error("Variable Type Not Known");let i=this.findVariable(e,t);if(i)return i;switch(e){case xe.CHANNEL:i=new Ve(e,t[0],t[1]),"vertex"!=t[1].type&&"segment"!=t[1].type||this._connectPathElement2Size(t[1],i);break;case xe.PROPERTY:i=new Be(e,t[0],t[1]);break;case xe.STATE:i=new qa(e,t[0],t[1]);break;case xe.ATTRIBUTE:i=new Ha(e,t[0],t[1],t[2]||null);break;case xe.ITEMS:i=new mr(e,t[0]);break;case xe.ATTR_VALUE:i=new qi(e,t[0]);break;case xe.DATASCOPE:i=new Ui(e,t[0]);break;case xe.BOUNDS:i=new Wi(e,t[0]);break;case xe.SCALE:i=new Xi(e,t[0]);break;case xe.AFFIXATION:i=new Ar(e,t[0]);break;case xe.ALIGNMENT:i=new Lr(e,t[0]);break;case xe.EVT_CTX:i=new Ua(e,t[0],t[1]);break;case xe.CONDITION_RESULT:i=new dr(e,t[0])}return e in this._variables||(this._variables[e]={}),this._variables[e][i.id]=i,i}_connectPathElement2Size(e,t){let i=e.parent,r=t.channel,s=this.findVariable(xe.CHANNEL,["x"===r?"width":"height",i]);if(s){let e=s.incomingDataflow;e||(e=this.createOneWayDependency(me.CONDUIT)),this.connect(t,e),this.connect(e,s)}}findIncomingDataflowOperator(e,t){return t.incomingDataflow&&t.incomingDataflow.type===e?t.incomingDataflow:void 0}getIncomingDataflowOperator(e,t){let i=this.findIncomingDataflowOperator(e,t);return i||this.createOneWayDependency(e)}getOutgoingDataflowOperator(e,t){for(let i of t.outgoingEdges)if(i.toNode instanceof ye&&i.toNode.type===e)return i.toNode;return this.createOneWayDependency(e)}createOneWayDependency(e,...t){if(Object.values(me).indexOf(e)<0)throw new Error("Dependency Type Not Known");let i;switch(e){case me.EVAL_BBOX:i=new $i(e);break;case me.AFFIXER:i=new Er(e);break;case me.DATA_EXTRACTOR:i=new Xa(e,t[0]);break;case me.SCALE_BUILDER:i=new Zi(e,t[0]);break;case me.ENCODER:i=new ur(e,t[0]);break;case me.AXIS_PATH_PLACER:i=new Ji(e);break;case me.AXIS_TICKS_PLACER:i=new Qi(e);break;case me.AXIS_LABELS_PLACER:i=new er(e);break;case me.AXIS_TITLE_PLACER:i=new Ir(e);break;case me.LINK_PLACER:i=new Vr(e);break;case me.GRID_LAYOUT:i=new ir(e);break;case me.STACK_LAYOUT:i=new fr(e);break;case me.PACK_LAYOUT:i=new Or(e);break;case me.FORCE_LAYOUT:i=new Pr(e);break;case me.DIRECTED_LAYOUT:i=new Va(e);break;case me.TIDY_TREE_LAYOUT:i=new Ma(e);break;case me.TREEMAP_LAYOUT:i=new Ba(e);break;case me.STRATA_LAYOUT:i=new Da(e);break;case me.CIRCULAR_LAYOUT:i=new za(e);break;case me.CLUSTER_LAYOUT:i=new ja(e);break;case me.SPIRAL_LAYOUT:i=new Fa(e);break;case me.CUSTOM_LAYOUT:i=new Wa(e);break;case me.GRIDLINES_PLACER:i=new _r(e);break;case me.SPIRAL_TRAJECTORY_PLACER:i=new pr(e);break;case me.BIN_TRANSFORMER:i=new yr(e);break;case me.FILTER_TRANSFORMER:i=new br(e);break;case me.KDE_TRANSFORMER:i=new Cr(e);break;case me.CUSTOM_TRANSFORMER:i=new kr(e);break;case me.UNPIVOT_TRANSFORMER:i=new Tr(e);break;case me.REPOPULATE:i=new wr(e);break;case me.TARGET_EVALUATOR:i=new Ga(e);break;case me.TARGET_UPDATER:i=new Ya(e,t[0],t[1],t[2]);break;case me.CONDUIT:default:i=new gr(e)}return e in this._operators||(this._operators[e]={}),this._operators[e][i.id]=i,i}createMultiWayDependency(e){if(Object.values(me).indexOf(e)<0)throw new Error("Dependency Type Not Known");let t;return me.ALIGNER,t=new Nr(e),e in this._operators||(this._operators[e]={}),this._operators[e][t.id]=t,t}connect(e,t,i=!0){if(e instanceof be&&t instanceof ye){if(!t.inputVars.includes(e)){const r=new Hi(e,t,i);return this._edges.push(r),e.outgoingEdges.push(r),t.inputVars.push(e),r}}else if(e instanceof ye&&t instanceof be){if(!e.outputVars.includes(t)){const r=new Hi(e,t,i);return this._edges.push(r),e.outputVars.push(t),t.incomingEdges.push(r),r}}else if(e instanceof be&&t instanceof Yi){if(!t.vars.includes(e)){const i=new Hi(e,t,!1);return this._edges.push(i),t.vars.push(e),t.edges.push(e),e.undirectedEdges.push(i),i}}else{if(!(e instanceof Yi&&t instanceof be))throw new Error("An edge must connect a variable and an operator.");if(!e.vars.includes(t)){const i=new Hi(t,e,!1);return this._edges.push(i),e.vars.push(t),e.edges.push(t),t.undirectedEdges.push(i),i}}}disconnectChannelVarFromBBoxOperator(e){let t=this.getOutgoingDataflowOperator(me.EVAL_BBOX,e),i=e.outgoingEdges.find(i=>i.fromNode===e&&i.toNode===t);i&&this.disconnect(e,t,i)}disconnect(e,t,i){if(e instanceof be&&t instanceof ye){let r=e.outgoingEdges.findIndex(e=>e===i);r>=0&&(this._edges.splice(this._edges.indexOf(i),1),e.outgoingEdges.splice(r,1));let s=t.inputVars.findIndex(t=>t==e);s>=0&&t.inputVars.splice(s,1)}else if(e instanceof ye&&t instanceof be){let r=t.incomingEdges.findIndex(e=>e===i);r>=0&&(this._edges.splice(this._edges.indexOf(i),1),t.incomingEdges.splice(r,1));let s=e.outputVars.findIndex(e=>e===t);s>=0&&e.outputVars.splice(s,1)}}deleteVariable(e){for(let t=e.incomingEdges.length-1;t>=0;t--){let i=e.incomingEdges[t],r=i.fromNode;this.disconnect(r,e,i),r.isIsolated()&&delete this._operators[r.type][r.id]}for(let t=e.outgoingEdges.length-1;t>=0;t--){let i=e.outgoingEdges[t],r=i.toNode;this.disconnect(e,r,i),r.isIsolated()&&delete this._operators[r.type][r.id]}delete this._variables[e.type][e.id]}deleteOperator(e){for(let t=e.outputVars.length-1;t>=0;t--){let i=e.outputVars[t],r=i.incomingEdges.find(t=>t.fromNode===e&&t.toNode===i);this.disconnect(e,i,r),i.isIsolated()&&delete this._variables[i.type][i.id]}for(let t=e.inputVars.length-1;t>=0;t--){let i=e.inputVars[t],r=i.outgoingEdges.find(t=>t.fromNode===i&&t.toNode===e);this.disconnect(i,e,r),i.isIsolated()&&delete this._variables[i.type][i.id]}delete this._operators[e.type][e.id]}addInteraction(e){}_dfs(e,t,i){if(e&&0!==e.outgoingEdges.length)for(let r of e.outgoingEdges)r.isDirected&&(t.push(r.toNode),this._dfs(r.toNode.outputVars[0],t.slice(),i));else i.push(t)}getOperatorsOnPath(e,t,i,...r){let s=this.findVariable(e,r);if(s){for(let e of s.outgoingEdges)if(e.isDirected){let r=e.toNode,s=t.indexOf(r);-1!==s&&t.splice(s,1),t.push(r);for(let e of r.outputVars)switch(e.type){case xe.ITEMS:this.getOperatorsOnPath(e.type,t,i,e.dataset);break;case xe.ATTRIBUTE:this.getOperatorsOnPath(e.type,t,i,e.attribute,e.dataset);break;case xe.DATASCOPE:case xe.BOUNDS:this.getOperatorsOnPath(e.type,t,i,e.element);break;case xe.CHANNEL:this.getOperatorsOnPath(e.type,t,i,e.channel,e.element);break;case xe.PROPERTY:this.getOperatorsOnPath(e.type,t,i,e.property,e.element);break;case xe.STATE:this.getOperatorsOnPath(e.type,t,i,e.key,e.stateContext);break;case xe.SCALE:case xe.ATTR_VALUE:this.getOperatorsOnPath(e.type,t,i,e.encodings[0]);break;case xe.CONDITION_RESULT:this.getOperatorsOnPath(e.type,t,i,e.conditionalEncoding)}}for(let e of s.undirectedEdges)i.push(e.operator)}else console.warn("Unable to find variables matching the described change: ",e,r)}findVariable(e,t){if(!(e in this._variables))return null;let i=Object.values(this._variables[e]);switch(e){case xe.CHANNEL:return i.find(e=>e.channel==t[0]&&ft(e.element)==ft(t[1]));case xe.PROPERTY:return i.find(e=>e.property==t[0]&&e.element==t[1]);case xe.STATE:return i.find(e=>e.key==t[0]&&e.stateContext==t[1]);case xe.AFFIXATION:return i.find(e=>e.affixation==t[0]);case xe.ATTRIBUTE:return t[2]?i.find(e=>e.attribute==t[0]&&e.dataset==t[1]&&e.encoding===t[2]):i.find(e=>e.attribute==t[0]&&e.dataset==t[1]&&!e.encoding);case xe.ITEMS:return i.find(e=>e.dataset==t[0]);case xe.ATTR_VALUE:case xe.SCALE:return i.find(e=>e.encodings.includes(t[0]));case xe.EVT_CTX:return i.find(e=>e.context===t[0]);case xe.CONDITION_RESULT:return i.find(e=>e.conditionalEncoding==t[0]);case xe.DATASCOPE:default:return t[0].classId?i.find(e=>ft(e.element)==ft(t[0])):i.find(e=>e.element.id==t[0].id)}}findVariablesByElement(e){let t={};for(let i in this._variables){let r=Object.values(this._variables[i]).filter(t=>t.element&&ft(t.element)==ft(e));r.length>0&&(t[i]=r)}return t}}class Za{constructor(e={}){this._attribute=e.attribute??null,this._numBins=e.numBins??null}get attribute(){return this._attribute}set attribute(e){this._attribute=e}get numBins(){return this._numBins}set numBins(e){this._numBins=e}get startAttr(){return this._attribute+"_bin_start"}get endAttr(){return this._attribute+"_bin_end"}get binIdAttr(){return this._attribute+"_bin_id"}}class $a{constructor(e={}){this._attribute=e.attribute??null,this._newAttribute=e.newAttribute??null,this._groupBy=e.groupBy??null,this._min=e.min??null,this._max=e.max??null,this._interval=e.interval??null,this._bandwidth=e.bandwidth??null}get attribute(){return this._attribute}set attribute(e){this._attribute=e}get newAttribute(){return this._newAttribute}set newAttribute(e){this._newAttribute=e}get groupBy(){return this._groupBy}set groupBy(e){this._groupBy=e}get min(){return this._min}set min(e){this._min=e}get max(){return this._max}set max(e){this._max=e}get interval(){return this._interval}set interval(e){this._interval=e}get bandwidth(){return this._bandwidth}set bandwidth(e){this._bandwidth=e}}class Ja{constructor(e={}){this._attribute=e.attribute??null,this._type=e.type??null,this._value=e.value??null}get attribute(){return this._attribute}set attribute(e){this._attribute=e}get type(){return this._type}set type(e){this._type=e}get value(){return this._value}set value(e){this._value=e}}class Qa{constructor(e,t){this._fn=e,t&&Object.assign(this,t)}get fn(){return this._fn}}class eo{constructor(e={}){this._idVars=e.idVars??null,this._valueVars=e.valueVars??null,this._varName=e.varName??"attribute",this._valueName=e.valueName??"value"}get idVars(){return this._idVars}set idVars(e){this._idVars=e}get valueVars(){return this._valueVars}set valueVars(e){this._valueVars=e}get varName(){return this._varName}set varName(e){this._varName=e}get valueName(){return this._valueName}set valueName(e){this._valueName=e}}class to extends jt{constructor(e,t){super(t||{}),this._type=i.Trajectory,this._id=this._type+s(),this._collection=e,this._args=t||{},this._samplesPerStep="samplesPerStep"in this._args?this._args.samplesPerStep:12,this._extendPastLast="extendPastLast"in this._args?this._args.extendPastLast:0,"strokeColor"in this.styles||(this.styles.strokeColor="#bbb"),this._points=[]}get type(){return this._type}get id(){return this._id}get collection(){return this._collection}get samplesPerStep(){return this._samplesPerStep}set samplesPerStep(e){this._samplesPerStep=e}get extendPastLast(){return this._extendPastLast}set extendPastLast(e){this._extendPastLast=e}get points(){return this._points}updatePoints(){let e=this._collection?this._collection.layout:void 0,t=this._collection?this._collection.children.length:0;if(!e||0===t)return void(this._points=[]);let i=e.direction===Vt.ANTI_CLOCKWISE?-1:1,r=t-1+this._extendPastLast;if(r<=0){let t=ee(e.x+e.startRadius,e.y,e.x,e.y,e.startAngle);return void(this._points=[t])}let s=Math.max(1,Math.round(r*this._samplesPerStep)),n=[];for(let t=0;t<=s;t++){let a=r*(t/s),o=e.startRadius+e.radiusStep*a,l=e.startAngle+i*e.angleStep*a;n.push(ee(e.x+o,e.y,e.x,e.y,l))}this._points=n}getSVGPathData(){if(0===this._points.length)return"";let e="M "+this._points[0].x+" "+this._points[0].y+" ";for(let t=1;t<this._points.length;t++)e+="L "+this._points[t].x+" "+this._points[t].y+" ";return e}_updateBounds(){if(0===this._points.length)return void(this._bounds=new se(0,0,0,0));let e=this._points.map(e=>e.x),t=this._points.map(e=>e.y),i=Math.min(...e),r=Math.max(...e),s=Math.min(...t),n=Math.max(...t);this._bounds=new se(i,s,r-i,n-s)}}class io extends At{constructor(e){super(),this._itemMap={},this._type=i.Scene,this._id=e&&e.id?e.id:this._type+s(),e&&e.fillColor&&(this.fillColor=e.fillColor),this._encodings={},this._relations=[],this._triggers={},this._condEncodings={},this._stateContext=new ve(this),this._stateContext.__scene__=this,this._depGraph=new Ka,this._renderers=[]}get depGraph(){return this._depGraph}get interactionTriggers(){return this._triggers}getConditionalEncodings(e){return this._condEncodings[e]||[]}_clearInteractionCaches(){for(let e in this._condEncodings)for(let t of this._condEncodings[e])t.clearResponderPeers()}get state(){return this._stateContext}mark(e,i){if(Object.values(t).indexOf(e)<0)throw new Error("Mascot does not allow directly creating a "+e);let r=void 0===i?{}:i;r.type=e;let s=Gi(this,r);return null!==s&&(s._classId=s.id,this.addChild(s),this._itemMap[s.id]=s,Ye(s,this._depGraph),$e(this,s,this._depGraph)),s}glyph(...e){let t=[];for(let i of e)t.push([i.parent,i]);let r=Gi(this,{type:i.Glyph,children:e});if(null!==r){r._classId=r.id;for(let e of t)Ze(e[0],e[1],this._depGraph);Je(r,this._depGraph),$e(this,r,this._depGraph)}return r}composite(){let e=Gi(this,{type:i.Composite});return null!==e&&(e._classId=e.id,this.addChild(e),this._itemMap[e.id]=e,Ke(e,this._depGraph),$e(this,e,this._depGraph)),e}_addAttributeEncoding(e){let t=ft(e.element);t in this._encodings||(this._encodings[t]={}),this._encodings[t][e.channel]=e}get tables(){let e={},t=this.children.filter(e=>e.type===i.Collection);for(let i of t){let t=i.dataScope?v(i.dataScope):null;t&&!(t.id in e)&&(e[t.id]=t)}return e}onChange(e,...t){if(Object.values(xe).indexOf(e)<0)throw new Error("Unknown Variable Type: "+e);let i=[],r=[],s=[];this._depGraph.getOperatorsOnPath(e,i,r,...t);let n=!1;for(let e of i)e.run(),e.needsFullRender&&(n=!0),s=s.concat(e.outputVars.filter(e=>e.type===xe.CHANNEL||e.type===xe.PROPERTY));for(let e of r)e.run();const a={};for(let e of s){let t="vertex"===e.element.type||"segment"===e.element.type?e.element.parent:e.element;t.id in a||(a[t.id]=[]);let i=e.channel||e.property;a[t.id].includes(i)||a[t.id].push(i)}if(n){for(const e of this._renderers)e._render(this);for(const e of this._renderers)e._renderChanges(this,a)}else for(const e of this._renderers)e._renderChanges(this,a);return a}gridlines(e,t,i){let r=i||{},s="rowId"==t?D:t,n=r.element?pt(r.element,e):_t(s,e,this);if(n){n.attribute!==s&&console.warn("Cannot create a "+e+" axis for "+t);let i=[];if("x"==e)for(let e of n.scales)i.push({scale:e,elems:n.getNormalizedElements(e)});else if("width"==e){let e=Ne(n.element),t=n.scales[0];if(e.layout&&e.layout.type==fe.GRID&&e.layout.numCols>1){let r=e.layout.getElementsByCol(!0);for(let e of r)i.push({scale:t,elems:e})}else i.push({scale:n.scales[0],elems:n.getNormalizedElements(n.scales[0])})}else if("y"==e){let e=Ne(n.element);if(e.layout&&e.layout.type==fe.GRID&&e.layout.numRows>1){let t=e.layout.getElementsByRow(!0,n.element);for(let e of t)i.push({scale:n.getScale(e[0]),elems:e})}else i.push({scale:n.scales[0],elems:n.getNormalizedElements(n.scales[0])})}else if("height"==e){let e=Ne(n.element),t=n.scales[0];if(e.layout&&e.layout.type==fe.GRID&&e.layout.numRows>1){let r=e.layout.getElementsByRow(!0,n.element);for(let e of r)i.push({scale:t,elems:e})}else i.push({scale:t,elems:n.getNormalizedElements(t)})}else if("polarRadius"==e||"polarAngle"==e){let e=r.element?r.element:n.element;!("origin"in r)&&n.origin&&(r.origin=n.origin),i.push({scale:n.scales[0],elems:we(e,e.parent)})}for(let e of i){let t=new Ei(n.channel,n.attribute,e.scale,e.elems,r);this.addChild(t),this._itemMap[t.id]=t,n.addRefElement(t),ot(t,this._depGraph),$e(this,t,this._depGraph)}}else{let i=r.element?r.element:ke(this,t);if(!i)return void console.warn("Cannot create "+e+" gridlines for "+t);let s=Te(i.parent);if(!s.layout)return void console.warn("Cannot create "+e+" gridlines for "+t);let n=we(s);for(let i of n){let s=[];i.layout.type==fe.GRID&&i.layout.numRows>1&&"x"==e?s=i.layout.getElementsByRow():i.layout.type==fe.GRID&&i.layout.numCols>1&&"y"==e?s=i.layout.getElementsByCol():s.push(i.children);for(let n of s){let s=new Ei(e,t,null,n,r);this.addChild(s),this._itemMap[s.id]=s,i.layout.addRefElement(s),ot(s,this._depGraph),$e(this,s,this._depGraph)}}}}trajectory(e,t){let i=t||{},r=Te(e);if(!r||!r.layout||r.layout.type!==fe.SPIRAL)return void console.warn("Cannot create a trajectory: element is not inside a collection with a spiral layout");let s=new to(r,i);return this.addChild(s),this._itemMap[s.id]=s,r.layout.addRefElement(s),function(e,t){let i=t.getVariable(xe.BOUNDS,Ne(e.collection)),r=t.getVariable(xe.PROPERTY,ze.TRAJECTORY_POSITION,e),s=t.createOneWayDependency(me.SPIRAL_TRAJECTORY_PLACER);t.connect(i,s),t.connect(s,r),s.run();let n=t.getVariable(xe.BOUNDS,e),a=t.getIncomingDataflowOperator(me.EVAL_BBOX,n);t.connect(r,a),t.connect(a,n)}(s,this._depGraph),$e(this,s,this._depGraph),le(s),this.onChange(xe.PROPERTY,ze.TRAJECTORY_POSITION,s),s}axis(e,t,i){let r=i||{},s="rowId"==t?D:t,n=[],a=r.element?pt(r.element,e):_t(s,e,this);if(a){a.attribute!==s&&console.warn("Cannot create a "+e+" axis for "+s);let t=[];if("x"==e||"width"==e){let e=Ne(r.element?r.element:a.element);if(e.layout&&e.layout.type==fe.GRID&&e.layout.numCols>1){let i=e.layout.getElementsByCell(!0,a.element);for(let e of i)t.push({scale:a.getScale(e[0]),elems:e})}else t.push({scale:a.scales[0],elems:a.getNormalizedElements(a.scales[0])})}else if("y"==e||"height"==e){let e=Ne(r.element?r.element:a.element);if(e.layout&&e.layout.type==fe.GRID&&e.layout.numRows>1){let i=e.layout.getElementsByCell(!0,a.element);for(let e of i)t.push({scale:a.getScale(e[0]),elems:e})}else t.push({scale:a.scales[0],elems:a.getNormalizedElements(a.scales[0])})}else if("polarRadius"==e||"polarAngle"==e){let e=r.element?r.element:a.element;!("origin"in r)&&a.origin&&(r.origin=a.origin),t.push({scale:a.scales[0],elems:we(e,e.parent)})}for(let e of t){let t=Object.assign({},r);t.scale=e.scale,t.elems=e.elems,t.type="axis",t.axisType="encoding",t.enc=a,t.rawArgs=r;let i=Gi(this,t);n.push(i),a.addRefElement(i),at(i,this._depGraph),$e(this,i,this._depGraph),this.onChange(xe.PROPERTY,ze.AXIS_PATH_POSITION,i)}}else{let t=r.element?r.element:ke(this,s);if(!t)return void console.warn("Cannot create a "+e+" axis for "+s);let i=Te(t.parent);if(!i.layout)return void console.warn("Cannot create a "+e+" axis for "+s);let a=we(i);for(let t of a){let i=[];t.layout.type==fe.GRID&&t.layout.numRows>1&&"x"==e?i=t.layout.getElementsByRow():t.layout.type==fe.GRID&&t.layout.numCols>1&&"y"==e?i=t.layout.getElementsByCol():i.push(t.children);for(let a of i){let i=Object.assign({},r);i.elems=a.slice(),i.type="axis",i.axisType="layout",i.channel=e,i.attribute=s;let o=Gi(this,i);n.push(o),t.layout.addRefElement(o),nt(o,this._depGraph),$e(this,o,this._depGraph),this.onChange(xe.PROPERTY,ze.AXIS_PATH_POSITION,o)}}}return n.length>1?n:n[0]}legend(e,t,i){let r=i||{},s="rowId"==t?D:t,n=r.element?pt(r.element,e):_t(s,e,this);if(n){n.attribute!==t&&console.warn("Cannot create a "+e+" legend for "+t);let i=B(n.element).type(t);r.type="legend",r.enc=n,r.attrType=i;let s=Gi(this,r);!function(e,t){let i=t.getVariable(xe.BOUNDS,e),r=t.getVariable(xe.PROPERTY,ze.LEGEND_POSITION,e),s=t.getIncomingDataflowOperator(me.EVAL_BBOX,i);t.connect(r,s),t.connect(s,i)}(s,this._depGraph),$e(this,s,this._depGraph),le(s),this.onChange(xe.PROPERTY,ze.LEGEND_POSITION,s)}else console.warn("Cannot create a "+e+" legend for "+s)}mask(e){let t=Ne(e),i=t||e;i.clipMask||i.createClipMask()}setLayout(e,t){if(e.layout&&(et(e,e.layout,this._depGraph),t.type===fe.TREEMAP)){let t=e.firstChild;for(;t&&t.type===i.Collection&&t.layout;)et(t,t.layout,this._depGraph),t=t.firstChild}if(we(e).forEach(e=>{let i=t?t.clone():t;e._layout=i,i&&(i.group=e)}),tt(e,t,this._depGraph),e.children&&e.children.length>0){let t=Le(e,!0);for(let e of t)this.onChange(xe.CHANNEL,"x",e)}}derive(e,t){let i=e.clone();return t._scene=this,t instanceof Za?(!function(e,t,i,r){let s=r.getVariable(xe.ITEMS,t),n=r.getVariable(xe.ITEMS,i),a=r.createOneWayDependency(me.BIN_TRANSFORMER);r.connect(s,a),r.connect(a,n);let o=r.getVariable(xe.PROPERTY,ze.NUM_BINS,e);r.connect(o,a),a._binConfig=e,a.run()}(t,e,i,this._depGraph),i._binTransform=t):t instanceof $a?function(e,t,i,r){let s=r.getVariable(xe.ATTRIBUTE,e.attribute,t),n=r.getVariable(xe.ATTRIBUTE,e.newAttribute,i),a=r.getVariable(xe.ITEMS,i),o=r.createOneWayDependency(me.KDE_TRANSFORMER);o.args=e,r.connect(s,o),r.connect(o,n),r.connect(o,a),o.run()}(t,e,i,this._depGraph):t instanceof Ja?function(e,t,i,r){let s=r.getVariable(xe.ITEMS,t),n=r.getVariable(xe.ITEMS,i),a=r.createOneWayDependency(me.FILTER_TRANSFORMER);a._spec=e,r.connect(s,a),r.connect(a,n);let o=r.getVariable(xe.PROPERTY,"value",e);r.connect(o,a),a.run()}(t,e,i,this._depGraph):t instanceof Qa?function(e,t,i,r){let s=r.getVariable(xe.ITEMS,t),n=r.getVariable(xe.ITEMS,i),a=r.createOneWayDependency(me.CUSTOM_TRANSFORMER);a._spec=e,r.connect(s,a),r.connect(a,n);for(let t of Object.keys(e)){if(t.startsWith("_"))continue;let i=r.getVariable(xe.PROPERTY,t,e);r.connect(i,a)}a.run()}(t,e,i,this._depGraph):t instanceof eo&&function(e,t,i,r){let s=r.getVariable(xe.ITEMS,t),n=r.getVariable(xe.ITEMS,i),a=r.createOneWayDependency(me.UNPIVOT_TRANSFORMER);a._spec=e,r.connect(s,a),r.connect(a,n);let o=r.getVariable(xe.PROPERTY,"valueVars",e);r.connect(o,a);let l=r.getVariable(xe.PROPERTY,"idVars",e);r.connect(l,a),a.run()}(t,e,i,this._depGraph),i}getElement(e){return this._itemMap[e]}getAxis(e,t){return _t(e,t,this).refElements[0]}}function ro(e,t){return m(t[e.dt],e.attr2value||e.filters||{},e.rowIds)}class so extends _e{constructor(e){super(),this.type=fe.CLUSTER,this._isRadial="radial"in e&&e.radial,this._angleExtent="angleExtent"in e?e.angleExtent:360,this._radius="radius"in e?e.radius:300,this._rootX="x"in e?e.x:300,this._rootY="y"in e?e.y:300,this._orientation="orientation"in e?e.orientation:Ot,this._width="width"in e?e.width:800,this._height="height"in e?e.height:600,this._left="left"in e?e.left:60,this._top="top"in e?e.top:100,this._tree="tree"in e?e.tree:void 0}get radius(){return this._radius}get angleExtent(){return this._angleExtent}get x(){return this._rootX}get y(){return this._rootY}get width(){return this._width}get height(){return this._height}get left(){return this._left}get top(){return this._top}isRadial(){return this._isRadial}get orientation(){return this._orientation}clone(){return new so({radius:this._radius,angleExtent:this._angleExtent,x:this._rootX,y:this._rootY,radial:this._isRadial,orientation:this._orientation,left:this._left,top:this._top,width:this._width,height:this._height,tree:this._tree})}}class no extends _e{constructor(e){super(),this.type=fe.DIRECTED,this._top="top"in e?e.top:0,this._left="left"in e?e.left:0,this._nodeSep="nodeSep"in e?e.nodeSep:100,this._edgeSep="edgeSep"in e?e.edgeSep:50,this._rankSep="rankSep"in e?e.rankSep:50,this._spreadLinks=!("spreadLinks"in e)||e.spreadLinks,this._direction="direction"in e?e.direction:Pt.Top2Bottom}clone(){return new no({top:this._top,left:this._left,nodeSep:this._nodeSep,edgeSep:this._edgeSep,rankSep:this._rankSep,spreadLinks:this._spreadLinks,direction:this._direction})}get top(){return this._top}get left(){return this._left}get nodeSep(){return this._nodeSep}get edgeSep(){return this._edgeSep}get rankSep(){return this._rankSep}get spreadLinks(){return this._spreadLinks}get direction(){return this._direction}}class ao extends _e{constructor(e){super(),this.type=fe.FORCE,this._x="x"in e?e.x:0,this._y="y"in e?e.y:0,this._iterations="iterations"in e?e.iterations:1,this._repulsion="repulsion"in e?e.repulsion:30,this._attraction="attraction"in e?e.attraction:1,this._linkDistance="linkDistance"in e?e.linkDistance:30}clone(){return new ao({x:this._x,y:this._y,iterations:this._iterations,repulsion:this._repulsion,attraction:this._attraction,linkDistance:this._linkDistance})}}class oo extends _e{constructor(e){super(),this.type=fe.PACKING,this._x="x"in e?e.x:400,this._y="y"in e?e.y:400,this._width=e.width,this._height=e.height}clone(){return new oo({x:this._x,y:this._y,width:this._width,height:this._height})}}class lo extends _e{constructor(e){super(),this.type=fe.STACK,this._orientation=e.orientation,this._direction=e.direction,this._left=e.left,this._top=e.top,this._horzCellAlignment="horzCellAlignment"in e&&e.horzCellAlignment?e.horzCellAlignment:he.LEFT,this._vertCellAlignment="vertCellAlignment"in e&&e.vertCellAlignment?e.vertCellAlignment:he.BOTTOM,this._gap="gap"in e?e.gap:0}clone(){let e=new lo({orientation:this._orientation,direction:this._direction,left:this._left,top:this._top});return e._horzCellAlignment=this._horzCellAlignment,e._vertCellAlignment=this._vertCellAlignment,e}get horzCellAlignment(){return this._horzCellAlignment}get vertCellAlignment(){return this._vertCellAlignment}get orientation(){return this._orientation}set horzCellAlignment(e){this._horzCellAlignment=e}set vertCellAlignment(e){this._vertCellAlignment=e}set orientation(e){this._orientation=e}}class ho extends _e{constructor(e){super(),this.type=fe.STRATA,this._direction=e.direction,this._gap="gap"in e?e.gap:0}clone(){return new ho({direction:this._direction,gap:this._gap})}}class co extends _e{constructor(e){super(),this.type=fe.TIDYTREE,this._width="width"in e?e.width:500,this._height="height"in e?e.height:500,this._left="left"in e?e.left:100,this._top="top"in e?e.top:100,this._orientation="orientation"in e?e.orientation:Ot}get width(){return this._width}get height(){return this._height}get top(){return this._top}get left(){return this._left}get orientation(){return this._orientation}clone(){return new co({width:this._width,height:this._height,top:this._top,left:this._left,orientation:this._orientation})}}class uo extends _e{constructor(e){super(),this.type=fe.TREEMAP,this._width=e.width,this._height=e.height,this._left=e.left,this._top=e.top}get width(){return this._width}get height(){return this._height}get top(){return this._top}get left(){return this._left}clone(){return new uo({width:this._width,height:this._height,top:this._top,left:this._left})}}class _o extends _e{constructor(e){super(),e=e||{},this.type=fe.SPIRAL,this._x="x"in e?e.x:100,this._y="y"in e?e.y:100,this._startRadius="startRadius"in e?e.startRadius:0,this._radiusStep="radiusStep"in e?e.radiusStep:8,this._startAngle="startAngle"in e?e.startAngle:90,this._angleStep="angleStep"in e?e.angleStep:40,this._direction="direction"in e?e.direction:Vt.CLOCKWISE,this._markRotation="markRotation"in e?e.markRotation:this._direction===Vt.CLOCKWISE?Bt.TANGENTIAL_CLOCKWISE:Bt.TANGENTIAL_COUNTERCLOCKWISE}get x(){return this._x}get y(){return this._y}get startRadius(){return this._startRadius}set startRadius(e){this._startRadius=e}get radiusStep(){return this._radiusStep}set radiusStep(e){this._radiusStep=e}get startAngle(){return this._startAngle}set startAngle(e){this._startAngle=e}get angleStep(){return this._angleStep}set angleStep(e){this._angleStep=e}get direction(){return this._direction}set direction(e){this._direction=e}get markRotation(){return this._markRotation}set markRotation(e){this._markRotation=e}clone(){return new _o({x:this._x,y:this._y,startRadius:this._startRadius,radiusStep:this._radiusStep,startAngle:this._startAngle,angleStep:this._angleStep,direction:this._direction,markRotation:this._markRotation})}}class po extends _e{constructor(e){super(),this.type=fe.CIRCULAR,this._x="x"in e?e.x:100,this._y="y"in e?e.y:100,this._radius="radius"in e?e.radius:100,this._markRotation="markRotation"in e?e.markRotation:Bt.INWARD}get x(){return this._x}get y(){return this._y}get radius(){return this._radius}get markRotation(){return this._markRotation}set markRotation(e){this._markRotation=e}clone(){return new po({x:this._x,y:this._y,radius:this._radius,markRotation:this._markRotation})}}class fo extends _e{constructor(e={}){if(super(),this.type=fe.CUSTOM,"function"!=typeof e.compute)throw new Error("CustomLayout requires a compute(children, layout) => {[id]: {x, y}} function");this._compute=e.compute,this._params="params"in e?e.params:{}}get compute(){return this._compute}set compute(e){if("function"!=typeof e)throw new Error("CustomLayout.compute must be a function");this._compute=e}get params(){return this._params}set params(e){this._params=e}clone(){return new fo({compute:this._compute,params:this._params})}}function go(e){switch(e.type){case fe.GRID:return function(e){let t=new Li(e.args);"left"in e&&(t._left=e.left);"top"in e&&(t._top=e.top);"cellBounds"in e&&(t._cellBounds=e.cellBounds.map(e=>yo(e)));"grid"in e&&(t._grid=e.grid);return t}(e);case fe.STACK:return function(e){let t=new lo(e.args);return t}(e);case fe.PACKING:return function(e){let t=new oo(e.args);return t}(e);case fe.FORCE:return function(e){return new ao(e.args)}(e);case fe.DIRECTED:return function(e){return new no(e.args)}(e);case fe.TIDYTREE:return function(e){return new co(e.args)}(e);case fe.TREEMAP:return function(e){return new uo(e.args)}(e);case fe.STRATA:return function(e){return new ho(e.args)}(e);case fe.SPIRAL:return function(e){return new _o(e.args)}(e);case fe.CIRCULAR:return function(e){return new po(e.args)}(e);case fe.CLUSTER:return function(e){let t=Object.assign({},e.args);!("x"in t)&&"rootX"in t&&(t.x=t.rootX);!("y"in t)&&"rootY"in t&&(t.y=t.rootY);t.tree&&(t.tree=new G(t.tree.data,t.tree.url));return new so(t)}(e);case fe.CUSTOM:return function(e){return console.warn("CustomLayout.compute cannot be restored from serialized data; set layout.compute manually after deserialization."),new fo({compute:()=>null,params:e.args?e.args.params:{}})}(e);default:return void console.warn("unsupported layout type for deserialization:",e.type)}}function yo(e){return new se(e.x-e.width/2,e.y-e.height/2,e.width,e.height)}function mo(e,t,r){e.type===i.Pie&&(e.type=i.Arc),e.args.type=e.type;let s=Gi(t,e.args);return e.id&&(s._id=e.id),e.classId&&(s._classId=e.classId),e.dataScope&&(s.dataScope=ro(e.dataScope,r)),e.bounds&&(s._bounds=yo(e.bounds)),e.refBounds&&(s._refBounds=yo(e.refBounds)),function(e,t,i,r){if(e.vertices){const i=[];for(let t of e.vertices){const e=bo(t,r);i.push(e)}t.vertices=i}t.vertexCounter=e.vertexCounter,t.segmentCounter=e.segmentCounter,t.curveMode=e.curveMode}(e,s,0,r),s}function bo(e,t){let i={type:"vertex",id:e.id,x:e.x,y:e.y,shape:e.shape,width:e.width,height:e.height,radius:e.radius,fillColor:e.fillColor,opacity:e.opacity,strokeWidth:e.strokeWidth,strokeColor:e.strokeColor};return e.dataScope&&(i.dataScope=ro(e.dataScope,t)),"polarAngle"in e&&(i.polarAngle=e.polarAngle),i}function xo(e){let t={};t.fillColor=e.fillColor;let i=new io(t);console.log("======== deserialization =========");let r={};if(e.tables)for(let t in e.tables){let i=e.tables[t];r[t]=new V(i.data,i.url,i.attributeTypes),r[t]._id=i.id}let s={};if(e.scales)for(let t in e.scales)s[t]=Co(e.scales[t]);i.scales=s,i._pendingLayouts=[],Eo(e,i,i,r),wo(e,i);for(let{group:e,layout:t}of i._pendingLayouts)tt(e,t,i._depGraph);for(let{group:e}of i._pendingLayouts){let t=e.children[0];t&&t.links&&i.onChange(xe.CHANNEL,"x",t)}if(delete i._pendingLayouts,e.encodings){let t={};for(let s of e.encodings){let e=So(s,i,r);t[e.id]=e}for(let e in t){i._addAttributeEncoding(t[e]);let r=t[e]._baseEnc?t[t[e]._baseEnc]:void 0;st(t[e],i._depGraph,r),r?i.onChange(xe.ATTR_VALUE,t[e]):i.onChange(xe.CHANNEL,t[e].channel,t[e].element)}}if(e.axes)for(let t of e.axes){let e=t.args?t.args:{};e.tickValues&&Object.values(r)[0].type(t.attr)===a.Date&&(e.tickValues=e.tickValues.map(e=>new Date(new Date(e).toISOString()))),t.id&&(e.id=t.id),Ao(e,i),i.axis(t.channel,t.attr,e)}if(e.gridlines)for(let t of e.gridlines){let e=t.args?t.args:{};Ao(e,i),i.gridlines(t.channel,t.attr,e)}if(e.legends)for(let t of e.legends)i.legend(t.channel,t.attr,t.args);if(e.trajectories)for(let t of e.trajectories){let e=i._itemMap[t.collectionId];e&&i.trajectory(e,t.args)}return e.bounds&&(i._bounds=yo(e.bounds)),delete i.scales,i}function vo(e,t,r,s){if(e.type===i.Collection){let n=Gi(r,{type:i.Collection,id:e.id});e.classId&&(n._classId=e.classId),t.addChild(n),qe(n,r._depGraph),$e(t,n,r._depGraph),Eo(e,n,r,s)}else if(e.type===i.Glyph){let n=Gi(r,{type:i.Glyph,id:e.id});e.classId&&(n._classId=e.classId),t.addChild(n),Je(n,r._depGraph),$e(t,n,r._depGraph),Eo(e,n,r,s)}else if(e.type===i.Composite){let n=Gi(r,{type:i.Composite,id:e.id});t.addChild(n),r._itemMap[n.id]=n,Ke(n,r._depGraph),$e(t,n,r._depGraph),Eo(e,n,r,s),n._bounds=yo(e.bounds)}else if(e.type===i.Axis){let i=new _i({});t.addChild(i),function(e,t,i,r){e.id&&(t._id=e.id);if(t._children=[],e.labels){let s=new At;Eo(e.labels,s,i,r),t._labels=s,t._children.push(s)}e.path&&(t._path=vo(e.path,t,i,r));if(e.ticks){let s=new At;Eo(e.ticks,s,i,r),t._ticks=s,t._children.push(s)}e.title&&(t._title=vo(e.title,t,i,r))}(e,i,r,s),r._itemMap[i.id]=i}else if(Object.values(ue).includes(e.type)){let i=mo(e,r,s);return r._itemMap[i.id]=i,t.addChild(i),Ye(i,r._depGraph),$e(t,i,r._depGraph),i}}function wo(e,t,i){if(e.children)for(let i of e.children)wo(i,t);else if(Object.values(ue).includes(e.type)){let i=t._itemMap[e.id];e.links&&(i.links=e.links.map(e=>t._itemMap[e])),e.source&&(i.source=t._itemMap[e.source]),e.target&&(i.target=t._itemMap[e.target])}}function Eo(e,t,i,r){if(e.id&&(t._id=e.id),e.classId&&(t._classId=e.classId),e.dataScope&&(t.dataScope=ro(e.dataScope,r)),e.bounds&&(t._bounds=yo(e.bounds)),t._sortBy=e.sortBy,e.children)for(let s of e.children)vo(s,t,i,r);if(e.layout){let r=go(e.layout);r&&(t._layout=r,r.group=t,i._pendingLayouts?i._pendingLayouts.push({group:t,layout:r}):tt(t,r,i._depGraph))}}function Ao(e,t){if("string"!=typeof e.element)return;let i=e.element,r=i.includes("_v_")?"vertex":i.includes("_s_")?"segment":void 0,s=r?i.split("vertex"===r?"_v_":"_s_")[0]:i,n=t._itemMap[s]?ko(i,r,t):void 0;n||console.warn("element not created:",i),e.element=n}function Co(e){let t=new bi(e.type,e.args);return t._id=e.id,t.domain=e.domain,t.range=e.range,t}function So(e,t,i){let r=ko(e.element,e.elementType,t);r||console.warn("element not created:",e.element,e.elementType);let s=e.args?e.args:{};e.table&&(s.table=i[e.table]);let n=new Ai(r,e.channel,e.attr,e.aggregator?e.aggregator:"sum",s);if(n._id=e.id,e.scales&&(n._scales=e.scales.map(e=>t.scales[e])),s.baseEnc&&(n._baseEnc=e.args.baseEnc),e.elemGroups&&(n._elemGroups=e.elemGroups.map(i=>"vertex"===e.elementType?{type:"vertexIndices",groups:Ro(i,t)}:i.map(e=>ko(e,r.type,t)))),e.elem2scale){n._elem2scale={};for(let i in e.elem2scale)n._elem2scale[i]=t.scales[e.elem2scale[i]]}return s.startAngle&&(n.startAngle=s.startAngle),n}function Ro(e,t){let i=[],r=new Map;for(let s of e){let e=ko(s,"vertex",t);if(!e){console.warn("vertex not created:",s);continue}let n=r.get(e.parent);n||(n={parent:e.parent,indices:[]},r.set(e.parent,n),i.push(n)),n.indices.push(e._index)}return i}function ko(e,t,i){if("vertex"===t){let t=e.split("_v_");return i._itemMap[t[0]].vertices.find(t=>t.id===e)}if("segment"===t){let t=e.split("_s_");return i._itemMap[t[0]].segments.find(e=>e._id===parseInt(t[1]))}return i._itemMap[e]}function To(e){let t={};return t.id=e._id,t.data=e._rawData,t.attributeTypes=e._attrTypes,t.url=e.url,t}function Oo(e){let t={};return t.dt=e.dataTable.id,t.attr2value=Object.assign({},e.filters),e.rowIds&&(t.rowIds=e.rowIds.slice()),t}function Io(e){switch(e.type){case fe.GRID:return function(e){let t={args:{}};return t.type=e.type,t.args.numCols=e._numCols,t.args.numRows=e._numRows,t.args.start=e._start,t.args.direction=e._direction,t.args.colGap=e._colGap,t.args.rowGap=e._rowGap,t.args.horzCellAlignment=e._cellHorzAlignment,t.args.vertCellAlignment=e._cellVertAlignment,t.args.rowOffset=e._rowOffset,t.args.colOffset=e._colOffset,t.left=e._left,t.top=e._top,t.group=e.group.id,t}(e);case fe.STACK:return function(e){let t={args:{}};return t.type=e.type,t.args.orientation=e._orientation,t.args.direction=e._direction,t.args.left=e._left,t.args.top=e._top,t.args.horzCellAlignment=e._horzCellAlignment,t.args.vertCellAlignment=e._vertCellAlignment,t.args.gap=e._gap,t.group=e.group.id,t}(e);case fe.PACKING:return function(e){let t={args:{}};return t.type=e.type,t.args.x=e._x,t.args.y=e._y,t.args.width=e._width,t.args.height=e._height,t.group=e.group.id,t}(e);case fe.FORCE:return function(e){let t={args:{}};return t.type=e.type,t.args.x=e._x,t.args.y=e._y,t.args.iterations=e._iterations,t.args.repulsion=e._repulsion,t.args.attraction=e._attraction,t.args.linkDistance=e._linkDistance,t.group=e.group.id,t}(e);case fe.CLUSTER:return function(e){let t={args:{}};t.type=e.type,t.args.radial=e._isRadial,t.args.angleExtent=e._angleExtent,t.args.radius=e._radius,t.args.x=e._rootX,t.args.y=e._rootY,t.args.orientation=e._orientation,t.args.width=e._width,t.args.height=e._height,t.args.left=e._left,t.args.top=e._top,e._tree&&(t.args.tree={data:e._tree._data,url:e._tree.url});return t}(e);case fe.DIRECTED:return function(e){let t={args:{}};return t.type=e.type,t.args.left=e._left,t.args.top=e._top,t.args.width=e._width,t.args.height=e._height,t.args.edgeSep=e._edgeSep,t.args.spreadLinks=e._spreadLinks,t.args.direction=e._direction,t}(e);case fe.TIDYTREE:return function(e){let t={args:{}};return t.type=e.type,t.args.left=e._left,t.args.top=e._top,t.args.width=e._width,t.args.height=e._height,t.args.orientation=e._orientation,t}(e);case fe.TREEMAP:return function(e){let t={args:{}};return t.type=e.type,t.args.left=e._left,t.args.top=e._top,t.args.width=e._width,t.args.height=e._height,t}(e);case fe.STRATA:return function(e){let t={args:{}};return t.type=e.type,t.args.direction=e._direction,t.args.gap=e._gap,t}(e);case fe.SPIRAL:return function(e){let t={args:{}};return t.type=e.type,t.args.x=e._x,t.args.y=e._y,t.args.startRadius=e._startRadius,t.args.radiusStep=e._radiusStep,t.args.startAngle=e._startAngle,t.args.angleStep=e._angleStep,t.args.direction=e._direction,t.args.markRotation=e._markRotation,t.group=e.group.id,t}(e);case fe.CIRCULAR:return function(e){let t={args:{}};return t.type=e.type,t.args.x=e._x,t.args.y=e._y,t.args.radius=e._radius,t.args.markRotation=e._markRotation,t.group=e.group.id,t}(e);case fe.CUSTOM:return function(e){console.warn("CustomLayout's compute function cannot be serialized; only params will be saved. Reattach compute() after deserializing.");let t={args:{}};return t.type=e.type,t.args.params=e.params,t.group=e.group.id,t}(e);default:throw new Error("unknow layout type "+e.type)}}function No(e,t){t.vertices=[];for(let i=0;i<e._vertices.length;i++)t.vertices.push(Lo(e._vertices,i));t.vertexCounter=e.vertexCounter,t.segmentCounter=e.segmentCounter,t.curveMode=e.curveMode}function Lo(e,t){let i={type:"vertex"};return i.id=e._ids[t],i.x=e._xs[t],i.y=e._ys[t],e.hasDataScope(t)&&(i.dataScope=Oo(e.getDataScopeRef(t))),void 0!==e._polarAngles[t]&&(i.polarAngle=e._polarAngles[t]),i.shape=e._shapes[t],i.width=e._widths[t],i.height=e._heights[t],i.radius=e._radii[t],i.fillColor=e._fillColors[t],i.opacity=e._opacities[t],i.strokeWidth=e._strokeWidths[t],i.strokeColor=e._strokeColors[t],i}function Po(e){return e.type===i.Scene?function(e){let t=Bo(e,{});t.fillColor=e.fillColor,t.scales={},t.encodings=[];for(let i in e._encodings)for(let r in e._encodings[i]){let s=e._encodings[i][r];s._forLegend||t.encodings.push(Mo(s));for(let e of s._scales)e.id in t.scales||(t.scales[e.id]=Vo(e))}t.tables={};let r=function(e){let t={};for(let i in e._encodings)for(let r in e._encodings[i]){let s=e._encodings[i][r];s.dataTable.id in t||s._forLegend||(t[s.dataTable.id]=s.dataTable)}for(let r of e.children)if(![i.Axis,i.Legend,i.Gridlines].includes(r.type)){if(r.dataScope){let e=v(r.dataScope);t[e.id]=e;break}if(r.children&&r.children.length>0){let e=r.firstChild;for(;e;){if(e.dataScope){let i=v(e.dataScope);t[i.id]=i;break}e=e.children&&e.children.length>0?e.firstChild:void 0}}}return t}(e);for(let e in r)t.tables[e]=To(r[e]);return console.log("======== serialization ========="),console.log(t),t}(e):[i.Collection,i.Glyph,i.Composite].includes(e.type)?Bo(e,{}):e instanceof _i?Do(e,{}):e instanceof ce?function(e){let t={args:{}};t.type=e.type,t.id=e.id,e.classId&&(t.classId=e.classId),e.dataScope&&(t.dataScope=Oo(e.dataScope)),e.bounds&&(t.bounds=e.bounds.toJSON()),e.refBounds&&(t.refBounds=e.refBounds.toJSON()),e.links&&(t.links=e.links.map(e=>e.id)),e.source&&(t.source=e.source.id),e.target&&(t.target=e.target.id);for(let i in e.styles)i.indexOf("Color")>0&&e.styles[i]instanceof di?t.args[i]=e.styles[i].toJSON():t.args[i]=e.styles[i];switch(void 0!==e.strength&&(t.args.strength=e.strength),e.type){case i.Arc:case i.Pie:!function(e,t){t.args.x=e._x,t.args.y=e._y,t.args.innerRadius=e._innerRadius,t.args.outerRadius=e._outerRadius,t.args.startAngle=e._startAngle,t.args.endAngle=e._endAngle,t.args.direction=e._direction,t.args.thickness=e._thickness}(e,t),No(e,t);break;case i.Area:!function(e,t){t.args.baseline=e._baseline,t.args.orientation=e._orientation}(e,t),No(e,t);break;case i.Circle:!function(e,t){t.args.x=e.x,t.args.y=e.y,t.args.radius=e.radius}(e,t);break;case i.Image:break;case i.Symbol:!function(e,t){t.args.x=e.x,t.args.y=e.y,t.args.width=e.width,t.args.height=e.height,t.args.path=e.path,t.args.viewBox=e.viewBox}(e,t);break;case i.Line:case i.Path:case i.BezierCurve:No(e,t);break;case i.SimpleText:!function(e,t){t.args.x=e._x,t.args.y=e._y,t.args.text=e._text,t.args.anchor=e._anchor,e._backgroundColor&&(t.args.backgroundColor=e._backgroundColor),e._borderWidth&&(t.args.borderWidth=e._borderWidth),e._borderColor&&(t.args.borderColor=e._borderColor)}(e,t);break;case i.Polygon:!function(e,t){t.args.x=e._x,t.args.y=e._y,t.args.radius=e._radius}(e,t),No(e,t);break;case i.Rect:!function(e,t){t.args.width=e.width,t.args.height=e.height,t.args.top=e.top,t.args.left=e.left}(e,t),No(e,t);case i.Ring:}return t}(e):(console.warn("unsupported serialization",e.type),{type:e.type})}function Vo(e){let t={};return t.type=e.type,t.id=e.id,e._args&&(t.args=e._args),t.domain=e.domain,t.range=e.range,t}function Mo(e){let t={};t.id=e._id,t.element=e._elem.id,t.elementType=e._elem.type,t.channel=e._channel,t.attr=e._attribute,t.aggregator=e._aggregator,t.table=e._table.id,t.args={},t.args.includeZero=e._includeZero,t.args.flipScale=e._flipScale,t.args.mapping=e._mapping,t.args.rangeExtent=e._preferredRangeExtent,t.args.domain=e._preferredDomain,t.args.scaleType=e._scaleType,t.args.scheme=e._colorScheme,e._baseEnc&&(t.args.baseEnc=e._baseEnc.id),t.scales=e._scales.map(e=>e.id),t.elemGroups=e._elemGroups.map(e=>"vertexIndices"===e.type?e.groups.flatMap(({parent:e,indices:t})=>t.map(t=>Ae(e,t))):e.map(e=>e.id)),t.elem2scale={};for(let i in e._elem2scale)t.elem2scale[i]=e._elem2scale[i].id;return"angle"==e.channel&&(t.args.startAngle=e.startAngle),t}function Bo(e,t){if(t.id=e.id,t.type=e.type,e.classId&&(t.classId=e.classId),e.dataScope&&(t.dataScope=Oo(e.dataScope)),t.bounds=e.bounds.toJSON(),e._layout&&(t.layout=Io(e._layout)),t.children=[],e.children.length>0)for(let i of e.children)i instanceof _i?Do(i,t):i instanceof Ei?Go(i,t):i instanceof to?jo(i,t):i instanceof Pi?zo(i,t):t.children.push(Po(i));return t.sortBy=e._sortBy,t}function Do(e,t){t.axes??=[];let i={};i.type=e._type,i.id=e._id,i.attr=e._attribute,i.channel=e._channel,i.args={},i.args.orientation=e._orientation,i.args.strokeColor=e._strokeColor,i.args.textColor=e._textColor,i.args.fontSize=e._fontSize,i.args.tickOffset=e._tickOffset,i.args.tickSize=e._tickSize,i.args.tickAnchor=e._tickAnchor,i.args.tickVisible=e._tickVisible,i.args.pathVisible=e._pathVisible,i.args.labelOffset=e._labelOffset,i.args.labelFormat=e._labelFormat,i.args.titleOffset=e._titleOffset,i.args.title=e._titleText,i.args.rotateTitle=e._rotateTitle,i.args.titleVisible=e._showTitle,i.args.labelRotation=e._labelRotation,e._args&&e._args.element&&(i.args.element=e._args.element.id??e._args.element),t.axes.push(i)}function Go(e,t){t.gridlines??=[];let i={};i.type=e._type,i.id=e._id,i.attr=e._attribute,i.channel=e._channel,i.args=function(e){let t=Object.assign({},e);t.element&&(t.element=t.element.id??t.element);return t}(e._args),t.gridlines.push(i)}function zo(e,t){t.legends??=[];let i={};i.type=e._type,i.id=e._id,i.attr=e.attribute,i.channel=e.channel,i.args={},i.args.textColor=e._textColor,i.args.strokeColor=e._strokeColor,i.args.fontSize=e._fontSize,i.args.x=e._x,i.args.y=e._y,i.args.showTitle=e._showTitle,i.args.orientation=e._orientation,i.args.numberFormat=e._numberFormat,void 0!==e._numCols&&(i.args.numCols=e._numCols),void 0!==e._numRows&&(i.args.numRows=e._numRows),t.legends.push(i)}function jo(e,t){t.trajectories??=[];let i={};i.type=e._type,i.id=e._id,i.collectionId=e.collection.id,i.args=e._args,t.trajectories.push(i)}const Fo={canvas:void 0,getContext:function(){return window?(void 0===this.canvas&&(this.canvas=document.createElement("canvas")),this.canvas?this.canvas.getContext("2d"):null):null},getPath2D:function(e){return e?new Path2D(e):new Path2D}};function Wo(e,t,r){if(!e.bounds.contains(t,r))return!1;switch(e.type){case i.Path:case i.Arc:case i.BezierCurve:case i.Line:case i.Area:case i.Pie:case i.Ring:case i.Polygon:case i.BundledPath:case i.Chord:{let i=Fo.getContext(),s=Fo.getPath2D(e.getSVGPathData());return i.lineWidth=Math.max(e.strokeWidth,2.5),i.stroke(s),e.closed||"none"!==e.fillColor?i.isPointInPath(s,t,r):i.isPointInStroke(s,t,r)}case i.Circle:{let i=e.x,s=e.y;if(e.rotation){let t=ee(i,s,e.rotation[1],e.rotation[2],e.rotation[0]);i=t.x,s=t.y}return Math.sqrt(Math.pow(t-i,2)+Math.pow(r-s,2))<=e.radius+e.strokeWidth}case i.Collection:if([i.Arc,i.Pie,i.Polygon,i.Area].indexOf(e.firstChild.type)>=0){let i=e.getSVGPathData();if(""!==i){let s=Fo.getContext(),n=Fo.getPath2D(i);return s.lineWidth=Math.max(e.firstChild.strokeWidth,2.5),s.stroke(n),s.isPointInPath(n,t,r)}}return e.bounds.contains(t,r);default:return e.bounds.contains(t,r)}}function Uo(e,t,i,r){let s=Le(e),n=r?r.map(e=>obj2Predicate(e)):[];for(let e=s.length-1;e>=0;e--){let r=s[e];if(Wo(r,t,i)&&J(r,n))return r}}function Yo(e,t,r,s){let n=s?s.map(e=>obj2Predicate(e)):[];if(!e.children||0==e.children.length)return Wo(e,t,r)&&e.type!==i.Scene?e:void 0;let a=e.children;e.type===i.Scene&&(a=a.slice(),a.sort((e,t)=>Ct(e)?1:Ct(t)?-1:0));for(let e=0;e<a.length;e++){let i=a[e];if(Wo(i,t,r)&&J(i,n))return i}}function Ho(e,t,r){let s=[];if(!e.children||0==e.children.length)return e.bounds.overlap(t)&&e.type!==i.Scene?[e]:[];for(let i=e.children.length-1;i>=0;i--){let r=e.children[i];r.bounds.overlap(t)&&s.push(r)}return s}function Xo(e,t,i,r){let s,n=Le(e),a=r||2,o=Fo.getContext();for(let e of n){if(!(e instanceof Path))continue;let r=Fo.getPath2D(e.getSVGPathData());if(o.lineWidth=Math.max(e.strokeWidth,2*a),o.stroke(r),o.isPointInStroke(r,t,i)){s=e;break}}if(!s)return null;let l=[];for(let e of s.vertices){let t=Math.max(a,e.width,2*e.radius),i=Math.max(a,e.height,2*e.radius);l.push({i:e,b:new se(e.x-t/2,e.y-i/2,t,i)})}for(let e of l)if(e.b.contains(t,i))return e.i;if(s.segments&&s.segments.length>0)for(let e of s.segments){let r=Fo.getPath2D();if(r.moveTo(e.vertex1.x,e.vertex1.y),r.lineTo(e.vertex2.x,e.vertex2.y),o.lineWidth=Math.max(s.strokeWidth,a),o.stroke(r),o.isPointInStroke(r,t,i))return e}return null}function qo(e,t,i){let r=i||2;if(de(e)){let i=[];for(let t of e.vertices){let e=Math.max(r,t.width,2*t.radius),s=Math.max(r,t.height,2*t.radius);i.push({i:t,b:new se(t.x-e/2,t.y-s/2,e,s)})}if(e.type===ItemType.Rect)for(let t of e.segments){let s=Math.max(e.strokeWidth,r);"v"===(t.vertex1.x===t.vertex2.x?"v":"h")?i.push({i:t,b:new se(t.vertex1.x-s/2,d3.min([t.vertex1.y,t.vertex2.y])-s/2,s,Math.abs(t.vertex1.y-t.vertex2.y))}):i.push({i:t,b:new se(d3.min([t.vertex1.x,t.vertex2.x])-s/2,t.vertex1.y-s/2,Math.abs(t.vertex1.x-t.vertex2.x),s)})}for(let e of i)if(e.b.intersects(t))return e.i;return null}if(!isGuide(e)&&e.children&&e.children.length>0){for(let i of e.children)if(i.bounds.intersects(t)){let e=qo(i,t,r);if(e)return e}return null}return null}const Ko="x",Zo="y",$o="xAttr",Jo="yAttr",Qo="xCoords",el="yCoords",tl="xVals",il="yVals",rl="xVal",sl="yVal",nl="selectedRows",al="dx",ol="dy",ll="dxData",hl="dyData",cl="deltaX",dl="deltaY",ul="element";function _l(e,t,i){let r=e.getScale(i),s=r?r.type:null;if("band"===s){let e=r._scale,i=e.bandwidth();return e.domain().filter(r=>{let s=e(r);return s+i/2>t[0]&&s-i/2<t[1]})}if("point"===s){let e=r._scale,i=e.step();return e.domain().filter(r=>{let s=e(r);return s+i/2>t[0]&&s-i/2<t[1]})}let n=t.map(t=>e.getAttrValue(t,i)).sort((e,t)=>e-t);return{min:n[0],max:n[1]}}function pl(e){let t=new Map;for(let r of e)if(r)if(r.type===i.Collection&&r.children&&r.children.length>0){let e=r.children[0],i=msc.getChannelEncodingByElement(e,"x"),s=msc.getChannelEncodingByElement(e,"y"),n=e,a=e;!i&&e.leftSegment&&(i=msc.getChannelEncodingByElement(e.leftSegment,"x"),i&&(n=e.leftSegment)),!s&&e.bottomSegment&&(s=msc.getChannelEncodingByElement(e.bottomSegment,"y"),s&&(a=e.bottomSegment)),t.set(r.id,{element:r,child:e,xEnc:i,yEnc:s,xChild:n,yChild:a,xAttr:i?i.sourceAttribute??i.attribute:void 0,yAttr:s?s.sourceAttribute??s.attribute:void 0})}else if(r.type===i.Area){let e=null,i=null,s=null,n=null;r.anyVertex&&(e=msc.getChannelEncodingByElement(r.anyVertex,"x"),e&&(i=r.anyVertex)),!e&&r.topLeftVertex&&(e=msc.getChannelEncodingByElement(r.topLeftVertex,"x"),e&&(i=r.topLeftVertex)),!e&&r.bottomLeftVertex&&(e=msc.getChannelEncodingByElement(r.bottomLeftVertex,"x"),e&&(i=r.bottomLeftVertex)),s=msc.getChannelEncodingByElement(r,"y")??msc.getChannelEncodingByElement(r,"height"),s&&(n=r),!s&&r.anyVertex&&(s=msc.getChannelEncodingByElement(r.anyVertex,"y"),s&&(n=r.anyVertex)),!s&&r.topLeftVertex&&(s=msc.getChannelEncodingByElement(r.topLeftVertex,"y"),s&&(n=r.topLeftVertex)),t.set(r.id,{element:r,child:r,xEnc:e,yEnc:s,xChild:i,yChild:n,xAttr:e?e.sourceAttribute??e.attribute:void 0,yAttr:s?s.sourceAttribute??s.attribute:void 0})}return t}function fl(t,r,s,n,a){for(let n of t){let t,a="background"===n.source?s:n.source;a=Array.isArray(a)?a:[a];let l="brushX"===n.event?e.brushX():"brushY"===n.event?e.brushY():e.brush();var o;l.on("start",function(i){t=pl(a),o&&a.length>1&&e.select(o).call(l.move,null),o=this}),l.on("brush end",function(i){let r,o;if(i&&i.selection)switch(n.event){case"brushX":r=[i.selection[0],i.selection[1]],o=void 0;break;case"brushY":r=void 0,o=[i.selection[0],i.selection[1]];break;default:r=[i.selection[0][0],i.selection[1][0]],o=[i.selection[0][1],i.selection[1][1]]}else r=void 0,o=void 0;let l=n.eventContext;l.clear(),l.set(Qo,r),l.set(el,o);let h=e.select(this).attr("id").replace("brush-","");t||(t=pl(a));let c=t.get(h),d=c&&c.xAttr&&r?r.map(e=>c.xEnc.getAttrValue(e,c.xChild)).sort((e,t)=>e-t):void 0,u=c&&c.yAttr&&o?o.map(e=>c.yEnc.getAttrValue(e,c.yChild)).sort((e,t)=>e-t):void 0,_=c&&c.xAttr?c.xEnc.dataTable:c&&c.yAttr?c.yEnc.dataTable:void 0,p={};c&&c.xAttr&&r&&(p[c.xAttr]=_l(c.xEnc,r,c.xChild)),c&&c.yAttr&&o&&(p[c.yAttr]=_l(c.yEnc,o,c.yChild));let f=_?_.rows(p):void 0;c&&(l.set($o,c.xAttr),l.set(Jo,c.yAttr),l.set(tl,d),l.set(il,u),l.set(nl,f)),s.onChange(xe.EVT_CTX,l),i&&"end"===i.type&&(t=void 0)});for(let e of a){let t=e.type===i.Axis?e.boundsWithoutTitle:e.bounds,s=[[t.left,t.top],[t.right,t.bottom]];r.append("g").attr("class","brush").attr("id","brush-"+e.id).call(l.extent(s))}}}function gl(t,i,r,s,n){for(let s of t){"background"===s.source||s.source;let t=e.zoom();t.on("zoom",e=>{e.sourceEvent.preventDefault(),e.sourceEvent.stopPropagation();let t=s.eventContext;t.clear();let[n,a]=ie(i.attr("id"),e.sourceEvent.clientX,e.sourceEvent.clientY);t.set(Ko,n),t.set(Zo,a),t.set(cl,e.sourceEvent.deltaX),t.set(dl,e.sourceEvent.deltaY),r.onChange(xe.EVT_CTX,t)}),i.call(t)}}function yl(t,i,r,s,n){for(let s of t){let t="background"===s.source?i.select("#"+r.id):Array.isArray(s.source)?i.selectAll(s.source.map(e=>e.classId?"."+e.classId:"#"+e.id).join(", ")):s.source.classId?i.selectAll("."+s.source.classId):i.select("#"+s.source.id),n=e.drag();n.on("start",e=>{let t=e.sourceEvent.target.__data__;if(!t||"vertex"===t.type||"segment"===t.type){let[s,n]=ie(i.attr("id"),e.sourceEvent.clientX,e.sourceEvent.clientY);const a=Re(r,[]);t=a.find(e=>"vertex"!==e.type&&"segment"!==e.type&&!e.children&&Wo(e,s,n)&&(msc.getChannelEncodingByElement(e,"x")||msc.getChannelEncodingByElement(e,"y"))),t||(t=a.find(e=>{if("vertex"===e.type||"segment"===e.type)return!1;if(e.children)return!1;if(!msc.getChannelEncodingByElement(e,"x")&&!msc.getChannelEncodingByElement(e,"y"))return!1;let t=e.parent?.bounds;return t&&s>=t.left&&s<=t.right&&n>=t.top&&n<=t.bottom}))}s._dragElem=t}),n.on("drag",e=>{let[t,n]=ie(i.attr("id"),e.sourceEvent.clientX,e.sourceEvent.clientY),a=s.eventContext;a.set(Ko,t),a.set(Zo,n),a.set(al,e.dx),a.set(ol,e.dy);let o=s._dragElem;if(a.set("element",o),o){let i=msc.getChannelEncodingByElement(o,"x"),r=msc.getChannelEncodingByElement(o,"y");if(i){let r="log"!==i.getScale(o)?.type;a.set($o,i.attribute),a.set(ll,i.getAttrValue(t-e.dx,o,r)-i.getAttrValue(t,o,r))}if(r){let t="log"!==r.getScale(o)?.type;a.set(Jo,r.attribute),a.set(hl,r.getAttrValue(n-e.dy,o,t)-r.getAttrValue(n,o,t))}}r.onChange(xe.EVT_CTX,a)}),n.on("end",e=>{s._dragElem=void 0;let t=s.eventContext;t.set("element",void 0),r.onChange(xe.EVT_CTX,t)}),t.call(n)}}function ml(e,t,i,r,s){for(let r of e){let e="background"===r.source?t.select("#"+i.id):Array.isArray(r.source)?t.selectAll(r.source.map(e=>e.classId?"."+e.classId:"#"+e.id).join(", ")):r.source.classId?t.selectAll("."+r.source.classId):t.select("#"+r.source.id);const s=e=>{let[s,n]=ie(t.attr("id"),e.clientX,e.clientY),a=r.eventContext;if(a.set(Ko,s),a.set(Zo,n),"background"===r.source){let e=msc.getEncodingsByChannel("x",i)[0],t=msc.getEncodingsByChannel("y",i)[0],r=e?e.attribute:void 0,o=t?t.attribute:void 0,l=r?e.getAttrValue(s):void 0,h=o?t.getAttrValue(n):void 0;a.set($o,r),a.set(Jo,o),a.set(rl,l),a.set(sl,h)}let o=e.target.__data__;a.set(ul,o),i.onChange(xe.EVT_CTX,a)};"background"===r.source?t.on("mousemove",s):e.on("mouseover",s);const n=e=>{let t=r.eventContext;t.set(ul,void 0),i.onChange(xe.EVT_CTX,t)};"background"===r.source?t.on("mouseleave",n):e.on("mouseout",n)}}function bl(e,t,i,r,s){let n=e.filter(e=>e.isKeyboardDriven());n.length>0&&xl(n,t,i);for(let t of e)if(!t.isStateDriven()&&!t.isKeyboardDriven()&&t.isWidgetDriven()){let e=(Array.isArray(t.source)?t.source:[t.source]).map(e=>document.getElementById(e)),r=t.eventContext;for(let s of e)s&&s.addEventListener(t.event,function(){r.set("inputValue",s.value),"checkbox"===s.type&&r.set("checked",s.checked),i.onChange(xe.EVT_CTX,r)})}}function xl(t,i,r,s,n){let a=".mascot-keyboard-"+r.id+"-"+i.attr("id"),o={};for(let e of t){let t=["keydown","keyup"].includes(e.event)?e.event:"keydown";t in o||(o[t]=[]),o[t].push(e)}for(let t in o)e.select(window).on(t+a,null),e.select(window).on(t+a,e=>{for(let i of o[t]){if(void 0!==i.source&&e.key!==i.source)continue;let s=i.eventContext;s.clear(),s.set("event",t),s.set("source",i.source),s.set("key",e.key),s.set("code",e.code),s.set("altKey",e.altKey),s.set("ctrlKey",e.ctrlKey),s.set("metaKey",e.metaKey),s.set("shiftKey",e.shiftKey),s.set("repeat",e.repeat),r.onChange(xe.EVT_CTX,s)}})}function vl(e,t,i,r,s){t.on("wheel",r=>{for(let s of e){r.preventDefault(),r.stopPropagation();let[e,n]=ie(t.attr("id"),r.clientX,r.clientY),a=s.eventContext;a.set("deltaX",r.deltaX),a.set("deltaY",r.deltaY),a.set("x",e),a.set("y",n),i.onChange(xe.EVT_CTX,a)}})}function wl(e,t,i,r,s){t.on("click",r=>{for(let s of e){let[e,n]=ie(t.attr("id"),r.clientX,r.clientY),a=s.eventContext,o=[];s.source.type&&o.push({property:"type",value:s.source.type}),s.source.classId&&o.push({property:"classId",value:s.source.classId});let l=Re(i,o).filter(t=>Wo(t,e,n)),h=l[l.length-1];a.clear(),a.set("x",e),a.set("y",n),a.set("element",h),i.onChange(xe.EVT_CTX,a)}})}function El(e){const t=e.viewBox&&4===e.viewBox.length?e.viewBox:[0,0,24,24],i=t[0],r=t[1],s=t[2]||1,n=t[3]||1,a=e.width/s,o=e.height/n;let l="translate("+e.x+","+e.y+") scale("+a+","+o+") translate("+-i+","+-r+")";return e._markRotationOffset&&(l+=" rotate("+e._markRotationOffset+","+(i+s/2)+","+(r+n/2)+")"),l}function Al(e,t,i){const r=i.querySelector("defs");if(!r)return;const s=e.styles&&e.styles.strokeColor||"#ccc";if(t.removeAttribute("marker-start"),t.removeAttribute("marker-end"),e.startStyle&&"none"!==e.startStyle){const i=e.id+"-marker-start";Cl(r,i,e.startStyle,e.startSize,s),t.setAttribute("marker-start","url(#"+i+")")}if(e.endStyle&&"none"!==e.endStyle){const i=e.id+"-marker-end";Cl(r,i,e.endStyle,e.endSize,s),t.setAttribute("marker-end","url(#"+i+")")}}function Cl(e,t,i,r,s){let n=e.querySelector("#"+t);for(n||(n=document.createElementNS("http://www.w3.org/2000/svg","marker"),e.appendChild(n));n.firstChild;)n.firstChild.remove();n.setAttribute("id",t),n.setAttribute("viewBox","0 0 "+r+" "+r),n.setAttribute("refX",r),n.setAttribute("refY",r/2),n.setAttribute("markerWidth",r/2),n.setAttribute("markerHeight",r/2),n.setAttribute("orient","auto-start-reverse");const a=document.createElementNS("http://www.w3.org/2000/svg","path");"filled"===i?(a.setAttribute("d","M0,0 L"+r+","+r/2+" L0,"+r+" Z"),a.style.fill=s,a.style.stroke="none"):(a.setAttribute("d","M0,0 L"+r+","+r/2+" L0,"+r),a.style.fill="none",a.style.stroke=s,a.style.strokeWidth="2",a.style.strokeLinecap="round",a.style.strokeLinejoin="round"),n.appendChild(a)}function Sl(e){return e.id+"-bg"}function Rl(e){return e.id+"-path"}function kl(e){return!(!e.styles||!e.styles.strokeColor||e.styles.strokeColor.type!==i.PathGradient)}function Tl(e,t,i,r){const s=e.styles.strokeColor.colors,n=e.vertices,a=n.length;if(a<2||s.length!==a)return s.length!==a&&console.warn("Mascot: PathGradient has "+s.length+" colors but the path has "+a+" vertices -- they must match."),void Ol(e,t);const o=e.id+"-strokeGradient";let l=t[o];if(l)r&&delete r[o];else{const r=e.parent?t[e.parent.id]:i;l=document.createElementNS("http://www.w3.org/2000/svg","g"),l.setAttribute("id",o),r.appendChild(l),t[o]=l}const h=i.querySelector("defs"),c=void 0!==e.styles.strokeWidth?e.styles.strokeWidth:1,d=void 0!==e.styles.opacity?e.styles.opacity:1,u=e.closed?a:a-1;for(let e=0;e<u;e++){let i=n[e],u=n[(e+1)%a];const _=o+"-grad"+e;let p=h.querySelector("#"+_);p||(p=document.createElementNS("http://www.w3.org/2000/svg","linearGradient"),p.setAttribute("id",_),p.setAttribute("gradientUnits","userSpaceOnUse"),p.appendChild(document.createElementNS("http://www.w3.org/2000/svg","stop")).setAttribute("offset","0%"),p.appendChild(document.createElementNS("http://www.w3.org/2000/svg","stop")).setAttribute("offset","100%"),h.appendChild(p)),p.setAttribute("x1",i.x),p.setAttribute("y1",i.y),p.setAttribute("x2",u.x),p.setAttribute("y2",u.y),p.children[0].style.stopColor=s[e],p.children[1].style.stopColor=s[(e+1)%a];const f=o+"-seg"+e;let g=t[f];g?r&&delete r[f]:(g=document.createElementNS("http://www.w3.org/2000/svg","path"),g.setAttribute("id",f),l.appendChild(g),t[f]=g),g.setAttribute("d","M "+i.x+" "+i.y+" L "+u.x+" "+u.y),g.style.fill="none",g.style.stroke="url(#"+_+")",g.style.strokeWidth=c,g.style.opacity=d,g.style.strokeLinecap="round"}let _=u;for(;t[o+"-seg"+_];){t[o+"-seg"+_].remove(),delete t[o+"-seg"+_];const e=h.querySelector("#"+o+"-grad"+_);e&&e.remove(),_++}}function Ol(e,t){const i=e.id+"-strokeGradient";if(!(i in t))return;const r=t[i].ownerSVGElement,s=r?r.querySelector("defs"):null;let n=0;for(;t[i+"-seg"+n];){if(t[i+"-seg"+n].remove(),delete t[i+"-seg"+n],s){const e=s.querySelector("#"+i+"-grad"+n);e&&e.remove()}n++}t[i].remove(),delete t[i]}function Il(e){switch(e){case he.TOP:return"text-before-edge";case he.BOTTOM:return"auto";case he.LEFT:return"start";case he.RIGHT:return"end";case he.CENTER:case he.MIDDLE:return"middle";default:return e}}function Nl(e,t,i){let r=e.bounds;for(let s of i)switch(s){case"x":t.setAttribute("x",r.left);break;case"y":t.setAttribute("y",r.top);break;case"width":t.setAttribute("width",r.width);break;case"height":t.setAttribute("height",r.height);break;default:t.style[re[s]]=e[s]}e._dirty=!1}function Ll(e,t,i){for(let r of i)switch(r){case"x":t.setAttribute("cx",e.x);break;case"y":t.setAttribute("cy",e.y);break;case"radius":t.setAttribute("r",e.radius);break;default:t.style[re[r]]=e[r]}e._dirty=!1}function Pl(e,t,i){let r=!1;for(let s of i)switch(s){case"path":t.setAttribute("d",e.path);break;case"x":case"y":case"width":case"height":case"viewBox":r=!0;break;default:t.style[re[s]]=e[s]}if(r){let i=El(e);t.setAttribute("transform",e._rotate?"rotate("+e._rotate.join(" ")+") "+i:i)}e._dirty=!1}function Vl(e,t,r){let s=t[e.id];for(let t of r)switch(t){case"d":case"strength":case"vertices":case"x1":case"y1":case"x2":case"y2":case"angle":case"startAngle":case"endAngle":case"innerRadius":case"outerRadius":case"thickness":case"radius":s.setAttribute("d",e.getSVGPathData());break;case"startStyle":case"startSize":case"endStyle":case"endSize":break;case"strokeColor":s.style.stroke=kl(e)?"none":e.strokeColor;break;default:s.style[re[t]]=e[t]}if(e.vertices){const i=s.ownerSVGElement;kl(e)?i&&Tl(e,t,i):Ol(e,t)}if(e.type===i.Arrow){const t=s.ownerSVGElement;t&&Al(e,s,t)}if(e.vertices&&e.vertices.length>0){let i=e.vertices.filter(e=>void 0!==e.shape);if(i.length>0)for(let r of i){let i=t[e.id+"-vertices-"+r.id];i&&("rect"==r.shape?(i.setAttribute("x",r.x-r.width/2),i.setAttribute("y",r.y-r.height/2),i.setAttribute("width",r.width),i.setAttribute("height",r.height)):"circle"==r.shape&&(i.setAttribute("cx",r.x),i.setAttribute("cy",r.y),i.setAttribute("r",r.radius)),i.style.fill=r.fillColor,i.style.opacity=r.opacity,i.style.strokeWidth=r.strokeWidth,i.style.stroke=r.strokeColor)}}e._dirty=!1}function Ml(e,t,i,r){for(let s of i)switch(s){case"text":t.textContent=e.text,r&&(r.setAttribute("width",e.bounds.width+10),r.setAttribute("height",e.bounds.height+10));break;case"x":t.setAttribute("x",e.x),r&&r.setAttribute("x",e.bounds.left-5);break;case"y":t.setAttribute("y",e.y),r&&r.setAttribute("y",e.bounds.top-5);break;default:t.style[re[s]]=e[s],r&&(r.style[re[s]]=e[s])}e._dirty=!1}function Bl(e,t,i){for(let r of i)switch(r){case"text":{const i=t.querySelector("div");i&&(i.innerHTML=e.text,t.setAttribute("height",i.offsetHeight));break}case"x":t.setAttribute("x",e.x);break;case"y":t.setAttribute("y",e.y);break;case"width":t.setAttribute("width",e.width);break;case"visibility":const i=t.querySelector("div");i&&(i.style.visibility=e.visibility),t.style[re[r]]=e[r];break;default:t.style[re[r]]=e[r]}e._dirty=!1}function Dl(e,t,i){for(let r of i)"gridlinesPosition"===r?t.setAttribute("d",e.getSVGPathData()):t.style[re[r]]=e[r];e._dirty=!1}function Gl(e,t,i){for(let r of i)"trajectoryPosition"===r?t.setAttribute("d",e.getSVGPathData()):t.style[re[r]]=e[r];e._dirty=!1}function zl(e,t,i){let r=t.some(e=>"x"===e||"y"===e);we(e).forEach(e=>{let s=i._compMap[e.id];if(s){if(r)for(let t of e.children)i._renderItem(t,{});if(!1!==e._dirty||!r){for(let i of t)"visibility"===i?s.style.visibility=e.visibility:"opacity"===i&&(s.style.opacity=e.opacity);e._dirty=!1}}})}function jl(e,t){let i=Object.keys(t._compMap).filter(t=>t.startsWith(e.id+"_"));for(let e of i)t._removed[e]=1;t._renderItem(e);for(let e in t._removed)e in t._compMap&&(t._compMap[e].remove(),delete t._compMap[e]);for(let e of i)delete t._removed[e]}class Fl{constructor(e){this._svgId=e,this._svg=document.getElementById(this._svgId),this._compMap={},this._decoMap={},this._lastTriggerEvt=void 0}render(e,t){if(!this._svg&&(this._svg=document.getElementById(this._svgId),!this._svg)){const i=()=>{this._svg=document.getElementById(this._svgId),this._svg?this.render(e,t):console.error("SVGRenderer: SVG element '#"+this._svgId+"' not found after DOMContentLoaded.")};return void("loading"===document.readyState?document.addEventListener("DOMContentLoaded",i,{once:!0}):Promise.resolve().then(i))}let i=t||{};if(!this._svg.querySelector("defs")){const e=document.createElementNS("http://www.w3.org/2000/svg","defs");this._svg.appendChild(e)}this._render(e,i),this._registerEvents(e,i),e._renderers.includes(this)||e._renderers.push(this)}_render(e,t,i){for(let e in this._decoMap)this._decoMap[e].remove(),delete this._decoMap[e];this._removed={};for(let e in this._compMap)this._removed[e]=1;this._renderItem(e,t,i);for(let e in this._removed)this._compMap[e].remove(),delete this._compMap[e]}_registerEvents(t,i){let r=e.select("#"+this._svgId);r.on(".",null);for(let e in t.interactionTriggers){let i=Object.values(t.interactionTriggers[e]);switch(e){case"click":r.on("click",null),wl(i,r,t);break;case"brush":case"brushX":case"brushY":fl(i,r,t);break;case"drag":case"dragX":case"dragY":yl(i,r,t);break;case"hover":ml(i,r,t);break;case"change":case"input":bl(i,r,t);break;case"keydown":case"keyup":xl(i,r,t);break;case"zoom":gl(i,r,t);break;case"scroll":vl(i,r,t)}}}clear(){if(this._svg){for(;this._svg.firstChild;)this._svg.firstChild.remove();e.select("#"+this._svgId).on(".",null),console.log("clearing canvas"),this._compMap={},this._decoMap={}}}_renderItem(e,t,r){if(this._configSVG(e),!e.children&&!1===e._dirty)return;let s=this._compMap[e.id];if(r){const e=r.delay||0,t=r.duration||0;s.style.transition=`all ${t}ms ease ${e}ms`}switch(e.type){case i.Scene:!function(e,t){t.style.background=e.fillColor?e.fillColor:"#fff"}(e,this._svg);break;case i.Circle:!function(e,t){t.setAttribute("cx",e.x),t.setAttribute("cy",e.y),t.setAttribute("r",e.radius)}(e,s);break;case i.Rect:!function(e,t){let i=e.bounds;t.setAttribute("x",i.left),t.setAttribute("y",i.top),t.setAttribute("width",i.width),t.setAttribute("height",i.height)}(e,s);break;case i.Path:case i.BezierCurve:case i.BundledPath:case i.Chord:case i.Polygon:case i.Link:case i.Pie:case i.Line:case i.Area:case i.Ring:case i.Arc:case i.Gridlines:case i.Trajectory:case i.Arrow:!function(e,t,r){t.setAttribute("d",e.getSVGPathData()),e.closed||(t.style.fill="none"),(e.id.includes("axis")||e.id.includes("gridlines"))&&(t.style.shapeRendering="crispEdges"),e.type===i.BundledPath&&(t.style.mixBlendMode="multiply"),e.type===i.Arrow&&r&&Al(e,t,r)}(e,s,this._svg);break;case i.SimpleText:!function(e,t,i){if(t.setAttribute("text-anchor",Il(e.anchor[0])),t.setAttribute("alignment-baseline",Il(e.anchor[1])),t.setAttribute("dominant-baseline",Il(e.anchor[1])),t.setAttribute("x",e.x),t.setAttribute("y",e.y),i){e._updateBounds();let t=e.bounds;i.setAttribute("x",t.left-5),i.setAttribute("y",t.top-5),i.setAttribute("width",t.width+10),i.setAttribute("height",t.height+10),i.setAttribute("rx",5),i.setAttribute("ry",5),i.style.fill=e.backgroundColor,i.style.stroke=e.borderColor,i.style.strokeWidth=e.borderWidth}if(e.textPath){let i=t.querySelector("textPath");i||(i=document.createElementNS("http://www.w3.org/2000/svg","textPath"),t.appendChild(i)),i.setAttribute("href","#"+Rl(e)),i.setAttribute("startOffset",e.textPathOffset),i.textContent=e.text}else t.textContent=e.text}(e,s,this._compMap[Sl(e)]);break;case i.RichText:!function(e,t){for(;t.firstChild;)t.firstChild.remove();t.setAttribute("width",e.width),t.setAttribute("x",e.x),t.setAttribute("y",e.y),t.style.border="1px solid #ddd";let i=document.createElementNS("http://www.w3.org/1999/xhtml","div");i.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),i.style.width="100%",i.style.padding="10px",i.style.backgroundColor="rgba(255, 255, 255, 0.85)",i.style.color="black",i.style.visibility="visible",i.style.boxSizing="border-box",i.style.opacity="1",i.innerHTML=e.text,t.appendChild(i),t.setAttribute("height",i.offsetHeight)}(e,s);break;case i.Image:!function(e,t){t.setAttribute("href",e.src),t.setAttribute("x",e.x),t.setAttribute("y",e.y),t.setAttribute("width",e.width),t.setAttribute("height",e.height)}(e,s);break;case i.Symbol:!function(e,t){t.setAttribute("d",e.path),t.setAttribute("transform",El(e))}(e,s)}if(e._rotate){let t=s.getAttribute("transform"),i=s.getAttribute("data-mascot-rotate");i&&t&&0===t.indexOf(i)&&(t=t.slice(i.length).trim());let r="rotate("+e._rotate.join(" ")+")";s.setAttribute("transform",t?r+" "+t:r),s.setAttribute("data-mascot-rotate",r)}else{let e=s.getAttribute("data-mascot-rotate");if(e){let t=s.getAttribute("transform");if(t&&0===t.indexOf(e)){let i=t.slice(e.length).trim();i?s.setAttribute("transform",i):s.removeAttribute("transform")}s.removeAttribute("data-mascot-rotate")}}if(function(e,t,r){if(!e.styles)return;let s=Object.keys(e.styles);e.type===i.RichText&&(s=s.filter(e=>["textAnchor","fillColor"].indexOf(e)<0));for(let n of s)if(void 0!==e.styles[n])if("strokeColor"===n&&e.styles[n].type==i.PathGradient)t.style.stroke="none";else if(n.indexOf("Color")>0&&e.styles[n].type==i.LinearGradient){const i=r.querySelector("defs"),s=e.styles[n];if(!i.querySelector("#"+s.id)){const e=document.createElementNS("http://www.w3.org/2000/svg","linearGradient");e.setAttribute("id",s.id),e.setAttribute("x1",s.x1+"%"),e.setAttribute("x2",s.x2+"%"),e.setAttribute("y1",s.y1+"%"),e.setAttribute("y2",s.y2+"%");for(let t of s.stops){const i=document.createElementNS("http://www.w3.org/2000/svg","stop");i.setAttribute("offset",t.offset+"%"),i.style.stopColor=t.color,i.style.stopOpacity=t.opacity,e.appendChild(i)}i.appendChild(e)}t.style[re[n]]="url(#"+s.id+")"}else if(t.style[re[n]]=e.styles[n],"visibility"===n)if(e.type===i.SimpleText){if(e.hasBackground()){const t=r.querySelector("#"+Sl(e));t&&(t.style[re[n]]=e.styles[n])}}else if(e.type===i.RichText){const i=t.querySelector("div");i&&(i.style.visibility=e.styles[n])}}(e,s,this._svg),e.vertices&&(kl(e)?Tl(e,this._compMap,this._svg,this._removed):Ol(e,this._compMap)),e.vertices&&e.vertices.length>0&&e.vertices.map(e=>e.shape).filter(e=>void 0!==e).length>0&&this._renderVertices(e),t&&t.bounds?this._renderBounds(e):de(e)&&t&&t.refBounds&&this._renderRefBounds(e),e.clipMask){const t=this._svg.querySelector("defs");let i=t.querySelector("#"+e.id+"-clipPath");i||(i=document.createElementNS("http://www.w3.org/2000/svg","clipPath"),i.setAttribute("id",e.id+"-clipPath"),t.appendChild(i));let r=i.querySelector("rect");r||(r=document.createElementNS("http://www.w3.org/2000/svg","rect"),i.appendChild(r)),r.setAttribute("x",e.clipMask.left),r.setAttribute("y",e.clipMask.top),r.setAttribute("width",e.clipMask.width),r.setAttribute("height",e.clipMask.height),s.setAttribute("clip-path","url(#"+e.id+"-clipPath)");let n=e.id+"-bg",a=s.querySelector("#"+n);a||(a=document.createElementNS("http://www.w3.org/2000/svg","rect"),a.setAttribute("id",n),a.setAttribute("pointer-events","all"),a.setAttribute("fill","transparent"),s.insertBefore(a,s.firstChild)),a.setAttribute("x",e.clipMask.left),a.setAttribute("y",e.clipMask.top),a.setAttribute("width",e.clipMask.width),a.setAttribute("height",e.clipMask.height)}if(e.children){let i=[...e.children].sort((e,t)=>(e.z||0)-(t.z||0));for(let e of i)this._renderItem(e,t,r)}else e._dirty=!1}_renderChanges(e,t){for(let r in t){let s=e.getElement(r);if(s){switch(s.type){case i.Rect:we(s).forEach(e=>{!1!==e._dirty&&Nl(e,this._compMap[e.id],t[r])});break;case i.Circle:we(s).forEach(e=>{!1!==e._dirty&&Ll(e,this._compMap[e.id],t[r])});break;case i.Path:case i.Area:case i.Line:case i.Arrow:case i.BezierCurve:case i.BundledPath:case i.Pie:case i.Arc:case i.Ring:case i.Polygon:case i.Chord:let e=[],n=["x","y","width","height"];for(let i of t[r])n.includes(i)?e.indexOf("d")<0&&e.push("d"):e.push(i);we(s).forEach(t=>{!1!==t._dirty&&Vl(t,this._compMap,e)});break;case i.SimpleText:we(s).forEach(e=>{!1!==e._dirty&&Ml(e,this._compMap[e.id],t[r],this._compMap[Sl(e)])});break;case i.RichText:we(s).forEach(e=>{!1!==e._dirty&&Bl(e,this._compMap[e.id],t[r])});break;case i.Symbol:we(s).forEach(e=>{!1!==e._dirty&&Pl(e,this._compMap[e.id],t[r])});break;case i.Glyph:zl(s,t[r],this);break;case i.Gridlines:!0===s._dirty&&Dl(s,this._compMap[s.id],t[r]);break;case i.Trajectory:!0===s._dirty&&Gl(s,this._compMap[s.id],t[r]);break;case i.Axis:case i.Legend:we(s).forEach(e=>{jl(e,this)});break;case i.Collection:case i.Group:case i.Composite:break;default:console.warn("unsupported element type for update: "+s.type)}t[r].includes("z")&&s.parent&&this._reorderSiblingsByZ(s.parent)}}}_reorderSiblingsByZ(e){let t=this._compMap[e.id];if(!t)return;let i=[...e.children].sort((e,t)=>(e.z||0)-(t.z||0));for(let e of i){let i=this._compMap[e.id];i&&t.appendChild(i)}}_configSVG(e){if(e.id in this._compMap){if(delete this._removed[e.id],e.type===i.SimpleText&&(e.hasBackground()&&delete this._removed[Sl(e)],e.textPath&&delete this._removed[Rl(e)]),e.vertices){let t=e.vertices.filter(e=>void 0!==e.shape);if(t.length>0){delete this._removed[e.id+"-vertices"];for(let i of t)delete this._removed[e.id+"-vertices-"+i.id]}if(kl(e)){let t=e.id+"-strokeGradient";delete this._removed[t];let i=e.closed?e.vertices.length:e.vertices.length-1;for(let e=0;e<i;e++)delete this._removed[t+"-seg"+e]}}}else{let t,r=e.parent;if(t=r&&r.id&&r.id in this._compMap?this._svg.querySelector("#"+r.id):this._svg,e.type===i.SimpleText){if(e.hasBackground()){const i=document.createElementNS("http://www.w3.org/2000/svg","rect");i.setAttribute("id",Sl(e)),t.appendChild(i),this._compMap[Sl(e)]=i}if(e.textPath){const t=this._svg.querySelector("defs"),i=Rl(e);let r=t.querySelector("#"+i);r||(r=document.createElementNS("http://www.w3.org/2000/svg","path"),r.setAttribute("id",i),t.appendChild(r),this._compMap[i]=r),r.setAttribute("d",e.textPath),r.style.fill="none"}}const s=document.createElementNS("http://www.w3.org/2000/svg",this._getSVGElementType(e));t?t.appendChild(s):console.warn("Parent element not found for ",e.id,e.parent?e.parent.id:null),this._compMap[e.id]=s}if(e.type==i.Gridlines||e.type==i.Trajectory){const t=this._compMap[e.id].parentNode;t.insertBefore(this._compMap[e.id],t.firstChild)}this._compMap[e.id].setAttribute("id",e.id),this._compMap[e.id].__data__=e;let t=e.type;e.classId&&(t+=" "+e.classId),e.parent&&e.parent.type===i.Axis&&(t+=e.id.endsWith("_ticks")?" axis_ticks":e.id.endsWith("_labels")?" axis_labels":""),this._compMap[e.id].setAttribute("class",t)}_renderBounds(e){let t=e.bounds;if(e.layout&&"grid"==e.layout.type&&this._renderLayout(e),!(e.id in this._decoMap)){const t=document.createElementNS("http://www.w3.org/2000/svg","rect");t.setAttribute("class","deco"),this._svg.appendChild(t),this._decoMap[e.id]=t}const i=this._decoMap[e.id];i.setAttribute("x",t.left),i.setAttribute("y",t.top),i.setAttribute("width",t.width),i.setAttribute("height",t.height),i.setAttribute("fill","none"),i.setAttribute("stroke","blue"),i.setAttribute("stroke-width","1px"),i.setAttribute("stroke-dasharray","5,5")}_renderRefBounds(e){let t=e.refBounds;if(t){if(!(e.id in this._decoMap)){const t=document.createElementNS("http://www.w3.org/2000/svg","rect");t.setAttribute("class","deco"),this._svg.appendChild(t),this._decoMap[e.id]=t}const i=this._decoMap[e.id];i.setAttribute("x",t.left),i.setAttribute("y",t.top),i.setAttribute("width",t.width),i.setAttribute("height",t.height),i.setAttribute("fill","none"),i.setAttribute("stroke","blue"),i.setAttribute("stroke-width","1px"),i.setAttribute("stroke-dasharray","5,5")}}_renderVertices(e){let t=e.id+"-vertices";if(t in this._compMap)delete this._removed[t];else{let i=e.parent,r=i?i.id:this._svgId;const s=this._svg.querySelector("#"+r),n=document.createElementNS("http://www.w3.org/2000/svg","g");n.setAttribute("id",t),s.appendChild(n),this._compMap[t]=n}if(0===e.vertices.map(e=>e.shape).filter(e=>void 0!==e).length)return void(this._compMap[t].style.visibility="hidden");this._compMap[t].style.visibility="visible";let i=e.vertices.filter(e=>void 0!==e.shape);for(let e of i){let i=t+"-"+e.id;if(i in this._compMap)if(e.shape!==this._compMap[i].tagName){this._compMap[i].remove();const r=document.createElementNS("http://www.w3.org/2000/svg",e.shape);r.setAttribute("id",i),this._compMap[t].appendChild(r),this._compMap[i]=r,delete this._removed[i]}else delete this._removed[i];else{const r=document.createElementNS("http://www.w3.org/2000/svg",e.shape);r.setAttribute("id",i),this._compMap[t].appendChild(r),this._compMap[i]=r}const r=this._compMap[i];"rect"==e.shape?(r.setAttribute("x",e.x-e.width/2),r.setAttribute("y",e.y-e.height/2),r.setAttribute("width",e.width),r.setAttribute("height",e.height)):"circle"==e.shape&&(r.setAttribute("cx",e.x),r.setAttribute("cy",e.y),r.setAttribute("r",e.radius)),r.style.fill=e.fillColor,r.style.opacity=e.opacity,r.style.strokeWidth=e.strokeWidth,r.style.stroke=e.strokeColor}}_renderLayout(e){let t=e.id+"-grid";if(!(t in this._decoMap)){const e=document.createElementNS("http://www.w3.org/2000/svg","g");e.setAttribute("id",t),e.setAttribute("class","deco"),this._svg.appendChild(e),this._decoMap[t]=e}let i=e.layout.cellBounds;e.layout.rowGap;this._decoMap[t].querySelectorAll("rect").forEach(e=>e.remove());for(let e of i){const i=document.createElementNS("http://www.w3.org/2000/svg","rect");i.setAttribute("x",e.left),i.setAttribute("y",e.top),i.setAttribute("width",e.width),i.setAttribute("height",e.height),i.setAttribute("stroke","blue"),i.setAttribute("stroke-width","1px"),i.setAttribute("stroke-dasharray","5,5"),i.setAttribute("fill","none"),this._decoMap[t].appendChild(i)}}_getSVGElementType(e){switch(e.type){case i.Rect:return"rect";case i.Collection:case i.Group:case i.Glyph:case i.Scene:case i.Axis:case i.Legend:case i.Composite:return"g";case i.Area:case i.Path:case i.Polygon:case i.Ring:case i.Pie:case i.Arc:case i.BezierCurve:case i.BundledPath:case i.Chord:case i.Line:case i.Gridlines:case i.Trajectory:case i.Arrow:return"path";case i.Circle:return"circle";case i.SimpleText:return"text";case i.RichText:return"foreignObject";case"vertex":if("circle"==e.shape)return"circle";if("rect"==e.shape)return"rect";throw"argument exception";case"image":return"image";case i.Symbol:return"path"}}}function Wl(e,t){return void 0===e&&void 0===t||void 0!==e&&void 0!==t}function Ul(e,t){const i=Object.keys(e),r=Object.keys(t);return i.length===r.length&&(0===i.length||i.every(e=>r.includes(e)))}function Yl(e,t){if(!Wl(e.layout,t.layout))return console.log("Not both defined or undefined:",e.bounds,t.bounds),!1;let i=e.layout,r=t.layout;if(!i&&!r)return!0;if(i.type!==r.type)return console.log("layout types are different:",i,r),!1;switch(i.type){case fe.GRID:return function(e,t){e._cellBounds.length!==t._cellBounds.length&&console.log("cell bounds length different:",e,t);for(let i=0;i<e._cellBounds;i++)if(!Xl(e._cellBounds[i],t._cellBounds[i]))return console.log("cell bounds not equal:",e,t),!1;for(let i=0;i<e._grid.length;i++)for(let r=0;r<e._grid[i].length;r++)if(e._grid[i][r]!==t._grid[i][r])return console.log("grid not equal",e,t),!1;return e._numCols===t._numCols&&e._numRows===t._numRows&&e._start===t._start&&e._direction===t._direction&&e._rowGap===t._rowGap&&e._colGap===t._colGap&&e._cellHorzAlignment===t._cellHorzAlignment&&e._cellVertAlignment===t._cellVertAlignment&&e._rowOffset===t._rowOffset&&e._colOffset===t._colOffset&&e._left===t._left&&e._top===t._top}(i,r);case fe.STACK:return function(e,t){return e._orientation===t._orientation&&e._direction===t._direction&&e._left===t._left&&e._top===t._top&&e._horzCellAlignment===t._horzCellAlignment&&e._vertCellAlignment===t._vertCellAlignment&&e._gap===t._gap}(i,r);case fe.PACKING:return function(e,t){return e._x===t._x&&e._y===t._y&&e._width===t._width&&e._height===t._height}(i,r);case fe.FORCE:return function(e,t){return e._x===t._x&&e._y===t._y&&e._iterations===t._iterations&&e._repulsion===t._repulsion&&e._attraction===t._attraction&&e._linkDistance===t._linkDistance}(i,r);case fe.DIRECTED:return function(e,t){return e._width===t._width&&e._height===t._height&&e._top===t._top&&e._left===t._left&&e._edgeSep===t._edgeSep&&e._spreadLinks===t._spreadLinks&&e._direction===t._direction}(i,r);case fe.TIDYTREE:return function(e,t){return e._width===t._width&&e._height===t._height&&e._top===t._top&&e._left===t._left&&e._orientation===t._orientation}(i,r);case fe.STRATA:return function(e,t){return e._direction===t._direction&&e._gap===t._gap}(i,r);case fe.TREEMAP:return function(e,t){return e._width===t._width&&e._height===t._height&&e._top===t._top&&e._left===t._left}(i,r);case fe.SPIRAL:return function(e,t){return e._x===t._x&&e._y===t._y&&e._startRadius===t._startRadius&&e._radiusStep===t._radiusStep&&e._startAngle===t._startAngle&&e._angleStep===t._angleStep&&e._direction===t._direction&&e._markRotation===t._markRotation}(i,r);case fe.CIRCULAR:return function(e,t){return e._x===t._x&&e._y===t._y&&e._radius===t._radius&&e._markRotation===t._markRotation}(i,r);default:return!1}}function Hl(e,t){if(!Wl(e.bounds,t.bounds))return console.log("Not both defined or undefined:",e.bounds,t.bounds),!1;let i=e.bounds,r=t.bounds;return!i&&!r||Xl(i,r)}function Xl(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function ql(e,t){if(!Wl(e,t))return console.log("Not both defined or undefined:",e,t),!1;if(e.type!==t.type)return console.log("Different mark types:",e,t),!1;if(e.id!==t.id)return console.log("id not equal:",e,t),!1;if(e.classId!==t.classId)return console.log("class id not equal:",e,t),!1;if(!Zl(e,t))return console.log("DataScopes not equal",e,t),!1;if(!Hl(e,t))return console.log("Bounds not equal",e,t),!1;if(!Wl(e.links,t.links))return console.log("Not both defined or undefined: links ",e.links,t.links),!1;if(!Wl(e.source,t.source))return console.log("Not both defined or undefined: source ",e.source,t.source),!1;if(!Wl(e.target,t.target))return console.log("Not both defined or undefined: links ",e.target,t.target),!1;if(e.links&&t.links&&e.links.length!==t.links.length)return console.log("unequal number of links",e,t),!1;if(e.source&&t.source&&!ql(e.source,t.source))return console.log("different sources",e.source,t.source),!1;if(e.target&&t.target&&!ql(e.target,t.target))return console.log("different targets",e.target,t.target),!1;switch(e.type){case i.Arc:case i.Pie:return Kl(e,t)?e.x===t.x&&e.y===t.y&&e.innerRadius===t.innerRadius&&e.outerRadius===t.outerRadius&&e.startAngle===t.startAngle&&e.endAngle===t.endAngle&&e.direction===t.direction&&e.thickness===t.thickness:(console.log("vertices not equal:",e,t),!1);case i.Area:return Kl(e,t)?e.baseline===t.baseline&&e.orientation===t.orientation:(console.log("vertices not equal:",e,t),!1);case i.Circle:return e.x===t.x&&e.y===t.y&&e.radius===t.radius;case i.Image:return console.warn("not implemented"),!0;case i.Symbol:return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height&&e.path===t.path&&JSON.stringify(e.viewBox)===JSON.stringify(t.viewBox);case i.Line:case i.Path:case i.BezierCurve:return!!Kl(e,t)||(console.log("vertices not equal:",e,t),!1);case i.SimpleText:return e.x===t.x&&e.y===t.y&&e.text===t.text&&e.anchor[0]===t.anchor[0]&&e.anchor[1]===t.anchor[1];case i.Polygon:return Kl(e,t)?e.x===t.x&&e.y===t.y&&e.radius===t.radius:(console.log("vertices not equal:",e,t),!1);case i.Rect:return Kl(e,t)?e.width===t.width&&e.height===t.height&&e.top===t.top&&e.left===t.left:(console.log("vertices not equal:",e,t),!1);case i.Ring:default:return console.warn("not implemented"),!0}}function Kl(e,t){if(e.vertices.length!==t.vertices.length)return console.log("unequal number of vertices:",e,t),!1;for(let i=0;i<e.vertices.length;i++){let r=e.vertices[i],s=t.vertices[i];return r.id!==s.id?(console.log("vertex id not equal:",r,s),!1):r.x!==s.x||r.y!==s.y?(console.log("vertex position not equal:",r,s),!1):Zl(r,s)?r._polarAngle===s._polarAngle&&r.shape===s.shape&&r.width===s.width&&r.height==s.height&&r.radius==s.radius&&r.fillColor==s.fillColor&&r.opacity==s.opacity&&r.strokeWidth==s.strokeWidth&&r.strokeColor==s.strokeColor:(console.log("vertex data scopes not equal:",r.dataScope,s.dataScope),!1)}}function Zl(e,t){if(!Wl(e.dataScope,t.dataScope))return console.log("Not both defined or undefined:",e.dataScope,t.dataScope),!1;if(!e.dataScope&&!t.dataScope)return!0;let i=e.dataScope,r=t.dataScope,s=i.filters||{},n=r.filters||{};if(!Ul(s,n))return!1;for(let e in s)if(s[e]!==n[e])return!1;return i.dataTable.id===r.dataTable.id&&E(i).length===E(r).length}function $l(e,t){return e.type!==t.type&&console.log("Different types:",e.type,t.type),[i.Collection,i.Glyph,i.Composite].includes(e.type)?Jl(e,t):e instanceof ce?ql(e,t):void 0}function Jl(e,t){let i=e.children.filter(e=>!Object.values(r).includes(e.type)),s=t.children.filter(e=>!Object.values(r).includes(e.type));if(i.length!==s.length)return console.log("children length not equal:",i,s),!1;if(e.id!==t.id)return console.log("id not equal:",e,t),!1;if(e.classId!==t.classId)return console.log("class id not equal:",e,t),!1;if(!Zl(e,t))return console.log("DataScopes not equal",e.dataScope,t.dataScope),!1;if(!Hl(e,t))return console.log("Bounds not equal",e,t),!1;if(!Yl(e,t))return console.log("Layouts not equal",e,t),!1;if(!function(e,t){if(!Ul(e,t))return console.log("different keys",e,t),!1;for(let i in e)if(e[i]!==t[i])return!1;return!0}(e._sortBy,t._sortBy))return console.log("SortBy not equal",e,t),!1;for(let e=0;e<i.length;e++)if(!$l(i[e],s[e]))return console.log("Not equal",i[e],s[e]),!1;return!0}function Ql(e,t,r){let s=e.scene,o=r||{};if(o.attribute=o.attribute||D,console.log("------ divide by",o.attribute," ----"),function(e,t,i){if(!e||void 0===t)throw new Error("Incomplete information to do divide. You must specify an element, a categorical data attribute and a data table");t instanceof V&&n(i.attribute,t);if(i.layout&&!(i.layout instanceof _e))throw new Error("Invalid layout: "+i.layout)}(e,t,o),t instanceof G||t instanceof j)throw"Not implemented";if(t instanceof V){let{newMark:r,collection:n}=function(e,t,r,s,n){let o=n.type(r);if(o!=a.String&&o!=a.Date&&o!=a.Integer)throw new Error("Divide only works on a string or date attribute: "+r+" is "+o);if(!eh(t))throw new Error("The "+t.type+" is not dividable");switch(t.type){case i.Line:case i.Path:return;case i.Circle:return function(e,t,r,s,n){let a,o,l,h=we(t),c=r||Nt;if(c!=Nt&&c!=Lt)throw new Error("Unknown orientation: "+c);c===Nt&&h.forEach(r=>{let h=r.dataScope?r.dataScope:N(n),c=L(h,s),d=Gi(e,{type:i.Collection});null==o&&(o=d.id),d._classId=o,d.dataScope=h;let u=r.parent;u.removeChild(r),delete e._itemMap[r.id];let _=360/c.length,p=90;for(let i=0;i<c.length;i++){let s=Gi(e,{type:"arc",innerRadius:0,outerRadius:r.radius,x:r.x,y:r.y,startAngle:Kt(p-_*(i+1)),endAngle:Kt(p-_*i),strokeColor:r.strokeColor,fillColor:r.fillColor,strokeWidth:r.strokeWidth,opacity:r.opacity});l||(l=s.id),s.classId=l,s.dataScope=c[i],s._updateBounds(),s._refBounds=s.bounds.clone(),d.addChild(s),d._layout=new lo({orientation:Nt,direction:Vt.CLOCKWISE}),d._layout.group=d,u.removeChild(r),u.addChild(d),r===t&&(a=d)}});return{newMark:a.children[0],collection:a}}(e,t,s,r,n);case i.Rect:return function(e,t,r,s,n){let a,o=we(t),l=r||Ot;if(l!=Ot&&l!=It)throw new Error("Unknown orientation: "+l);let h={},c=0;for(let e of o){let t=L(e.dataScope?e.dataScope:N(n),s);t.length>c&&(c=t.length),h[e.id]=t}let d,u=Gi(e,{type:"rect",left:t.bounds.left,top:t.bounds.top,width:t.bounds.width,height:t.bounds.height,strokeColor:t.strokeColor,fillColor:t.fillColor,strokeWidth:t.strokeWidth,opacity:t.opacity});u._classId=u.id;for(let r of o){let s=Gi(e,{type:i.Collection});null==d&&(d=s.id),s._classId=d,s.dataScope=r.dataScope?r.dataScope:N(n);let o=r.parent;o.removeChild(r),delete e._itemMap[r.id];let c=h[r.id],_=r.bounds,p=_.left,f=_.top,g=l==Ot?_.width/c.length:_.width,y=l==Ot?_.height:_.height/c.length;for(let e=0;e<c.length;e++){let t=Fi(u);t.dataScope=c[e],t.resize(g,y),t._updateBounds(),t._refBounds=t.bounds.clone(),s.addChild(t)}o.addChild(s),s._layout=new lo({orientation:l,left:p,top:f}),s._layout.group=s,r==t&&(a=s)}return e.removeChild(u),delete e._itemMap[u.id],{newMark:a.children[0],collection:a}}(e,t,s,r,n);case i.Area:return function(e,t,r,s,n){let a,o=we(t),l=r||Ot;if(l!=Ot&&l!=It)throw new Error("Unknown orientation: "+l);let h,c={},d=0;for(let e of o){let t=L(e.dataScope?e.dataScope:N(n),s);t.length>d&&(d=t.length),c[e.id]=t}let u=Object.assign({},t.styles);u.vertices=t.vertices.map(e=>[e.x,e.y]),u.type="area",u.orientation=t.orientation,u.baseline=t.baseline;let _=Gi(e,u);_._classId=_.id;for(let r of o){let s=Gi(e,{type:i.Collection});null==h&&(h=s.id),s._classId=h,s.dataScope=r.dataScope?r.dataScope:N(n);let o=r.parent;o.removeChild(r),delete e._itemMap[r.id];let d=c[r.id],u=r.bounds,p=u.left,f=u.top,g=l==Ot?u.width/d.length:u.width,y=l==Ot?u.height:u.height/d.length;for(let e=0;e<d.length;e++){let t=Fi(_);t.dataScope=d[e],t.resize(g,y),t._updateBounds(),t._refBounds=t.bounds.clone(),s.addChild(t);for(let e=0;e<t.vertices.length;e++){let i=t.vertices[e],s=r.vertices[e];s&&s.dataScope?i.dataScope=I(t.dataScope,s.dataScope):i.dataScope=t.dataScope}}o.addChild(s),s._layout=new lo({orientation:l,left:p,top:f}),s._layout.group=s,r==t&&(a=s)}return e.removeChild(_),delete e._itemMap[_.id],{newMark:a.children[0],collection:a}}(e,t,s,r,n);case i.Ring:return function(e,t,r,s,n){let a,o,l,h=we(t),c=r||Nt;if(c!=Nt&&c!=Lt)throw new Error("Unknown orientation: "+c);c===Nt&&h.forEach(r=>{let h=r.dataScope?r.dataScope:N(n),c=L(h,s),d=Gi(e,{type:i.Collection});null==o&&(o=d.id),d._classId=o,d.dataScope=h;let u=r.parent;u.removeChild(r),delete e._itemMap[r.id];let _=360/c.length,p=90;for(let i=0;i<c.length;i++){let s=Gi(e,{type:"arc",innerRadius:r.innerRadius,outerRadius:r.outerRadius,x:r.x,y:r.y,startAngle:Kt(p-_*(i+1)),endAngle:Kt(p-_*i),strokeColor:r.strokeColor,fillColor:r.fillColor,strokeWidth:r.strokeWidth,opacity:r.opacity});l||(l=s.id),s.classId=l,s.dataScope=c[i],s._updateBounds(),s._refBounds=s.bounds.clone(),d.addChild(s),d._layout=new lo({orientation:Nt,direction:Vt.CLOCKWISE}),d._layout.group=d,u.removeChild(r),u.addChild(d),r===t&&(a=d)}});return{newMark:a.children[0],collection:a}}(e,t,s,r,n);case i.Pie:case i.Arc:return function(e,t,r,s,n){let a,o,l,h=we(t),c=r||Nt;if(c!=Nt&&c!=Lt)throw new Error("Unknown orientation: "+c);c===Nt||h.forEach(r=>{let h=r.dataScope?r.dataScope:N(n),c=L(h,s),d=Gi(e,{type:i.Collection});null==o&&(o=d.id),d._classId=o,d.dataScope=h;let u=r.parent;u.removeChild(r),delete e._itemMap[r.id];for(let i=0;i<c.length;i++){let s=Gi(e,{type:"arc",innerRadius:r.innerRadius+i*(r.outerRadius-r.innerRadius)/c.length,outerRadius:r.innerRadius+(i+1)*(r.outerRadius-r.innerRadius)/c.length,x:r.x,y:r.y,startAngle:r.startAngle,endAngle:r.endAngle,strokeColor:r.strokeColor,fillColor:r.fillColor,strokeWidth:r.strokeWidth,opacity:r.opacity});l||(l=s.id),s.classId=l,s.dataScope=c[i],s._updateBounds(),s._refBounds=s.bounds.clone(),d.addChild(s),d._layout=new lo({orientation:Lt}),d._layout.group=d,u.removeChild(r),u.addChild(d),r===t&&(a=d)}});return{newMark:a.children[0],collection:a}}(e,t,s,r,n)}}(s,e,o.attribute,o.orientation,t);return He(e,s._depGraph),Ye(r,s._depGraph),qe(n,s._depGraph),$e(n,r,s._depGraph),n.parent.type!==i.Scene&&$e(n.parent,n,s._depGraph),s.onChange(xe.CHANNEL,"width",r),{newMark:r,collection:n}}}function eh(e){if([i.Line,i.Circle,i.Rect,i.Area,i.Ring,i.Pie,i.Path].indexOf(e.type)<0)return!1;if(e.type===i.Path&&(e.closed||!e.firstVertex.dataScope))return!1;if(e.dataScope){let t=we(e);for(let e of t)if(C(e.dataScope)>1)return!0;return!1}return!0}function th(e,t){let r=Ie(e),s=t||{};if(console.log("------ classify by",s.attribute," ----"),!ih(e))throw new Error("The "+e.type+" is not classifiable");return function(e,t,r,s){let n=we(t);for(let t of n){let n,a={},o=t.children;for(let e of o){let t=R(e.dataScope,r);t in a||(a[t]=[]),a[t].push(e)}let l=B(o[0]);for(let o in a){let h=Gi(e,{type:i.Collection});t.addChild(h),void 0===n&&(n=h.id),h._classId=n,h.dataScope=O(t.dataScope?t.dataScope:N(l),r,o);for(let e of a[o])h.addChild(e);s&&(h._layout=s.clone(),h._layout.group=h)}}}(r,e,s.attribute,s.layout),Ze(e,e.firstChild.firstChild,r._depGraph),qe(e.firstChild,r._depGraph),$e(e.firstChild,e.firstChild.firstChild,r._depGraph),$e(e,e.firstChild,r._depGraph),r.onChange(xe.CHANNEL,"width",e.firstChild.firstChild),e.firstChild}function ih(e){return e.type===i.Collection&&!(e.children.length<2)}function rh(e,t,r){if(!(t instanceof G||Array.isArray(t)&&t.every(e=>e instanceof G)))throw"Cannot stratify on a non-tree dataset";if(![i.Circle,i.Rect,i.Ring].includes(e.type))throw"Cannot stratify elements that are not rects, circles, or rings";let s=Ie(e),n=r||{},a=n.direction,o=n.size,l=e.parent,h=function(e,t,r,s,n,a){switch(t.type){case i.Circle:case i.Ring:return function(e,t,r,s,n,a){let o,l=r||Mt.OUTWARD,h=n||50;if(l!==Mt.INWARD&&l!==Mt.OUTWARD)throw"Unknown direction to stratify";let c,d=we(t,e),u=Array.isArray(a)?a:[a];if(s){let r=Gi(e,{type:i.Collection});r.dataScope=void 0,null==c&&(c=r.id),r._classId=c;let s=d.map(e=>u[0].getNode(e.datum[U]));sh(e,d,s,u[0],r,t.classId?t.classId:t.id,400,350,l,h),o=r}else d.forEach((r,s)=>{let n=Gi(e,{type:i.Collection});n.dataScope=void 0,null==c&&(c=n.id),n._classId=c;let a=r.parent;nh(r,t.id,l,h,u[s],u[s].getRoot(),n,e,!0),n._layout=new ho({direction:l}),n._layout.group=n,a.addChild(n),r===t&&(o=n)});return o}(e,t,r,s,n,a);case i.Rect:return function(e,t,r,s,n,a){let o,l,h=r||Pt.Top2Bottom,c=n||50;if(!Object.values(Pt).includes(h))throw"Unknown direction to stratify";return we(t).forEach(r=>{let s=Gi(e,{type:i.Collection});s.dataScope=void 0,null==l&&(l=s.id),s._classId=l;let n=r.parent;ah(r,t.id,h,c,a,a.getRoot(),s,e,!0),s._layout=new ho({direction:h}),s._layout.group=s,n.addChild(s),r===t&&(o=s)}),o}(e,t,r,0,n,a)}}(s,e,a,n.startFromLeaf,o,t);return Ze(l,e,s._depGraph),qe(h,s._depGraph),h.children.length>0&&$e(h,h.firstChild,s._depGraph),$e(h.parent,h,s._depGraph),h}function sh(e,t,r,s,n,a,o,l,h,c){let d=r.map(e=>s.getParent(e)).filter((e,t,i)=>i.findIndex(t=>t[U]===e[U])===t);if(d=d.filter(e=>e!==s.getRoot()),0===d.length)return;let u=[];for(let r of d){let d,_,p,f=t.filter(e=>s.getParent(s.getNode(e.datum[U]))===r);if(f[0].type===i.Circle){let e=f.map(e=>te(o,l,e.bounds.x,e.bounds.y)-e.radius),t=f.map(e=>te(o,l,e.bounds.x,e.bounds.y)+e.radius);p=h===Mt.OUTWARD?d3.max(t):d3.min(e)-c;let i=f.map(e=>Zt(e.bounds.x,e.bounds.y,o,l)),r=f.map(e=>Zt(o+te(o,l,e.bounds.x,e.bounds.y),l-e.radius,o,l)),s=i.map((e,t)=>e-r[t]),n=i.map((e,t)=>e+r[t]),a=s.concat(n);d=d3.min(a),_=d3.max(a)}else f[0].type===i.Arc&&(d=360,_=-360,f.forEach(e=>{let t=e.startAngle,i=e.endAngle;i<t&&(i+=360),d=d3.min([d,t]),_=d3.max([_,i])}),d=Kt(d),_=Kt(_),p=h===Mt.OUTWARD?d3.max(f.map(e=>e.outerRadius)):d3.min(f.map(e=>e.innerRadius))-c);let g=Gi(e,{type:"arc",innerRadius:p,outerRadius:p+c,x:o,y:l,startAngle:Kt(d),endAngle:Kt(_),strokeColor:t[0].strokeColor,fillColor:t[0].fillColor,strokeWidth:t[0].strokeWidth,opacity:t[0].opacity});g._updateBounds(),g.dataScope=s.getNodeDataScopeRef(r),g._classId=a,n.addChild(g),u.push(g)}sh(e,u,d,s,n,a,o,l,h,c)}function nh(e,t,r,s,n,a,o,l,h){h&&(e.dataScope=n.getNodeDataScopeRef(a),e._classId=t);let c=n.getChildren(a);if(0===c.length)return;let d=e.type===i.Circle||e.type===i.Ring?60:e.startAngle,u=(e.type===i.Circle||e.type===i.Ring?360:e.angle)/c.length;for(let a=0;a<c.length;a++){let h,_;_=r===Mt.OUTWARD?e.type===i.Circle?e.radius:e.outerRadius:e.type===i.Circle?e.radius-s:e.innerRadius-s,h=Gi(l,360===u?{type:"ring",innerRadius:_,outerRadius:_+s,x:e.x,y:e.y,strokeColor:e.strokeColor,fillColor:e.fillColor,strokeWidth:e.strokeWidth,opacity:e.opacity}:{type:"arc",innerRadius:_,outerRadius:_+s,x:e.x,y:e.y,startAngle:Kt(d+u*a),endAngle:Kt(d+u*(a+1)),strokeColor:e.strokeColor,fillColor:e.fillColor,strokeWidth:e.strokeWidth,opacity:e.opacity}),h._updateBounds(),h.dataScope=n.getNodeDataScopeRef(c[a]),h._classId=t+"_strata",o.addChild(h),nh(h,t,r,s,n,c[a],o,l)}}function ah(e,t,i,r,s,n,a,o,l){l&&(e.dataScope=s.getNodeDataScopeRef(n),e._classId=t,a.addChild(e));let h,c,d,u=s.getChildren(n);if(0!==u.length){h=e.left,c=e.bottom,d=e.width/u.length;for(let n=0;n<u.length;n++){let o=Fi(e);wt(o,h-o.left,c-o.top),o.resize(d,r),o._updateBounds(),h+=d,o.dataScope=s.getNodeDataScopeRef(u[n]),o._classId=t,a.addChild(o),ah(o,t,i,r,s,u[n],a)}}}function oh(e,t){if(e.type==i.Glyph)for(let t of e.children)t._refBounds||(t._refBounds=t.bounds.clone());e.dataScope=N(t)}class lh{constructor(e,t,i){this._elems=e,this._channel=t,this._anchor=i}get elements(){return this._elems}get channel(){return this._channel}get anchor(){return this._anchor}}class hh{constructor(e,t){this._elem=e,this._base=t,this._id=ch(e,t),this._channels={},this._attribute=void 0}get id(){return this._id}get element(){return this._elem}get base(){return this._base}get channels(){return Object.keys(this._channels)}addChannel(e,t){let i={};i.elemAnchor="elementAnchor"in t?t.elementAnchor:"x"==e||"angle"==e?he.CENTER:he.MIDDLE,i.baseAnchor="baseAnchor"in t?t.baseAnchor:"x"==e||"angle"==e?he.CENTER:he.MIDDLE,i.offset="offset"in t?t.offset:0,"attribute"in t&&(this._attribute=t.attribute),this._channels[e]=i}hasChannel(e){return e in this._channels}getElementAnchor(e){return this._channels[e].elemAnchor}getBaseAnchor(e){return this._channels[e].baseAnchor}getOffset(e){return this._channels[e].offset}get attribute(){return this._attribute?this._attribute:D}}function ch(e,t){return(e.classId?e.classId:e.id)+":"+(t.classId?t.classId:t.id)}function dh(e,t,i,r){let s=Ie(e);v(e.dataScope)!==v(t.dataScope)&&console.warn("Affix: elements and base elements are not created from the same table");let n=ch(e,t),a=s._relations.find(e=>e.id===n);a||(a=new hh(e,t),s._relations.push(a)),a.addChannel(i,r||{}),function(e,t){let i=t.getVariable(xe.AFFIXATION,e),r=t.getOutgoingDataflowOperator(me.AFFIXER,i);t.connect(i,r);for(let i of e.channels){let s=t.getVariable(xe.CHANNEL,i,e.element),n=t.getVariable(xe.CHANNEL,i,e.base);t.connect(n,r),t.connect(r,s)}r.run()}(a,s._depGraph)}function uh(e,t,i){let r=Ie(e[0]),s=new lh(e,t,i);!function(e,t){let i=t.createMultiWayDependency(me.ALIGNER),r=t.getVariable(xe.ALIGNMENT,e);t.connect(r,i);for(let r of e.elements){let s=t.getVariable(xe.CHANNEL,e.channel,r);t.connect(s,i)}i.run()}(s,r._depGraph),r._relations.push(s)}function _h(e,t){let i=Ie(e[0]),r={};e.forEach(e=>r[R(e.dataScope,U)]=e);let s=v(t[0].dataScope),n=s.tree?"parent":"source",a=s.tree?"child":"target";for(let t of e)t.links=[];for(let e of t){let t=R(e.dataScope,n),i=R(e.dataScope,a),s=r[t],o=r[i];e.source=s,e.target=o,s.links.push(e),o.links.push(e)}it(e.find(e=>e.links.length>0),i._depGraph),i.onChange(xe.CHANNEL,"x",e[0])}function ph(e,t,i,r){let s=Ie(e);if(e instanceof At)!function(e,t,i,r){e.dataScope&&v(e.dataScope).has(t)?function(e,t,i,r){if(!v(e.dataScope).has(t))return void console.warn("Cannot order collection children by an non-existent attribute",t);let s;if(t===D)s=(e,i)=>parseInt(R(e.dataScope,t).substring(1))-parseInt(R(i.dataScope,t).substring(1));else{switch(v(e.children[0].dataScope).type(t)){case a.Date:break;case a.Number:case a.Integer:s=(e,i)=>T(e.dataScope,t)-T(i.dataScope,t);break;case a.String:s=r?(e,i)=>r.indexOf(R(e.dataScope,t))-r.indexOf(R(i.dataScope,t)):(e,i)=>R(e.dataScope,t)<R(i.dataScope,t)?-1:1}}e.children.sort(s),i&&e.children.reverse()}(e,t,i,r):function(e,t,i){let r;switch(t){case"x":case"y":case"width":case"height":r=(e,i)=>e.bounds[t]-i.bounds[t];break;default:r=(e,i)=>e[t]-i[t]}e._children.sort(r),i&&e.children.reverse()}(e,t,i);e._sortBy={property:t,descending:i,vals:r}}(e,t,i,r),s.onChange(xe.PROPERTY,ze.CHILDREN_ORDER,e);else if(e instanceof jt){let s=we(e);for(let e of s)fh(e,t,i,r)}}function fh(e,t,i,r){e.vertices[0].dataScope&&v(e.vertices[0].dataScope).has(t)?function(e,t,i,r){let s;if(t===D)s=(e,i)=>parseInt(R(e.dataScope,t).substring(1))-parseInt(R(i.dataScope,t).substring(1));else{switch(v(e.vertices[0].dataScope).type(t)){case a.Date:break;case a.Number:case a.Integer:s=(e,i)=>T(e.dataScope,t)-T(i.dataScope,t);break;case a.String:s=r?(e,i)=>r.indexOf(R(e.dataScope,t))-r.indexOf(R(i.dataScope,t)):(e,i)=>R(e.dataScope,t)<R(i.dataScope,t)?-1:1}}e.vertices.sort(s),i&&e.vertices.reverse()}(e,t,i,r):function(e,t,i){let r=(e,i)=>e[t]-i[t];e.vertices.sort(r),i&&e.vertices.reverse()}(e,t,i),e._sortBy={property:t,descending:i,vals:r}}class gh{constructor(e,t,i,r){this._respCompnt=t.object,this._respProps=t.properties||t.channels,this._responderEval=i,this._efxFn=r,this._evtCtx=e,this._evalResult={},this._responderPeers=void 0}get responderComponent(){return this._respCompnt}getResponderPeers(){if(!this._responderPeers){let e=Array.isArray(this._respCompnt)?this._respCompnt:[this._respCompnt];this._responderPeers=e.map(e=>we(e)).flat()}return this._responderPeers}clearResponderPeers(){this._responderPeers=void 0}get responderProperties(){return this._respProps}get eventContext(){return this._evtCtx}get evalResult(){return this._evalResult}set evalResult(e){this._evalResult=e}get evalFunction(){return this._responderEval}get stylingFunction(){return this._efxFn}}function yh(e,t,i,r,s){const n=Ie(t.object===We?e.source:t.object);!function(e,t,i,r,s){if(!("event"in e)||!("source"in e))throw"Source and event must be specified in the trigger";if(!("object"in t))throw"Responder object must be specified";if(Array.isArray(r)){if(!r.every(e=>"function"==typeof e))throw"Updater must be a function";if(s&&!Array.isArray(s))throw"An array of effect setters must be accompanied by an array of animation effects";if(s&&Array.isArray(s)&&s.length!==r.length)throw"the length of effect setters is not equal to the length of animation effects"}else if("function"!=typeof r)throw"Updater must be a function"}(e,t,0,r,s);let a=e.event,o=function(e){return["string"==typeof e.source?e.source:Array.isArray(e.source)?e.source.map(e=>e.classId||e.id).join("_"):"stateVar"===e.source.type?"state:"+e.source.key:e.source.classId?e.source.classId:e.source.id,e.event].join("-")}(e);a=0===a.indexOf("brush")?"brush":0===a.indexOf("drag")?"drag":a,a in n._triggers||(n._triggers[a]={}),o in n._triggers[a]||(n._triggers[a][o]=new Fe(o,e.source,e.event,e.cumulative));let l=n._triggers[a][o].eventContext,h=new gh(l,t,i,r);return o in n._condEncodings||(n._condEncodings[o]=[]),n._condEncodings[o].push(h),function(e,t,i,r,s){let n=t.responderComponent===We,a=n?s.source:t.responderComponent,o=s&&s.source&&"stateVar"===s.source.type?r.getVariable(xe.STATE,s.source.key,s.source.stateContext):r.getVariable(xe.EVT_CTX,e),l=i.properties?i.properties:i.channels;if(t.evalFunction){let e=r.getVariable(xe.CONDITION_RESULT,t),i=r.findIncomingDataflowOperator(me.TARGET_EVALUATOR,e);i||(i=r.createOneWayDependency(me.TARGET_EVALUATOR,t.evalFunction)),r.connect(o,i),r.connect(i,e);for(let t of l){let i=Array.isArray(a)?a:[a];for(let s of i){let i=r.getVariable(xe.CHANNEL,t,s),n=i.incomingDataflow;if(n&&n.type===me.ENCODER&&n.outputVar.channel===t)r.connect(e,n);else if(!n){let n=r.createOneWayDependency(me.ENCODER);r.connect(e,n),r.connect(n,i),n.storeValues(s,t)}}}}else{let e=r.createOneWayDependency(me.TARGET_UPDATER,t.stylingFunction,a,n);for(let t of l){let i;i=a instanceof ve?r.getVariable(xe.STATE,t,a):Object.values(Me).includes(t)?r.getVariable(xe.CHANNEL,t,a):r.getVariable(xe.PROPERTY,De(t),a),r.connect(o,e),r.connect(e,i)}}}(l,h,t,n._depGraph,e),n._triggers[a][o]}function mh(e,t){let i=t||{};switch(e.toLowerCase()){case fe.STACK:return new lo(i);case fe.PACKING:return new oo(i);case fe.FORCE:return new ao(i);case fe.DIRECTED:return new no(i);case fe.TIDYTREE:return new co(i);case fe.TREEMAP:return new uo(i);case fe.CIRCULAR:return new po(i);case fe.CLUSTER:return new so(i);case fe.SPIRAL:return new _o(i);case fe.CUSTOM:return new fo(i);case fe.GRID:default:return new Li(i)}}function bh(e,t,i){switch(e){case"kde":return new $a(t);case"filter":return new Ja(t);case"custom":return new Qa(t,i);case"unpivot":return new eo(t);default:return new Za(t)}}function xh(e){return new io(e)}function vh(e,t){return"path"===e?new ui(t):new di(t)}function wh(e){return new V(e,"")}async function Eh(t){return async function(t){let i=await Y("GET",t),r=e.csvParse(i.trim(),e.autoType);return new V(r,t)}(t)}function Ah(t){return function(t){let i=e.csvParse(t.trim(),e.autoType);return new V(i,"fromString")}(t)}async function Ch(e){return async function(e){let t=await Y("GET",e);return new j(JSON.parse(t),e)}(e)}async function Sh(e){return async function(e){let t=await Y("GET",e);return new G(JSON.parse(t),e)}(e)}function Rh(e,t){return new Fl(t)}function kh(e){return Po(e)}function Th(e){return xo(e)}function Oh(e,t){return function(e,t){return e.fillColor!==t.fillColor?(console.log("fillColor not equal:",e,t),!1):Jl(e,t)}(e,t)}const Ih=D;export{Ih as ROW_ID,We as TRIGGER_ELEMENT,yh as activate,dh as affix,uh as align,oh as attach,ih as canClassify,nr as canDensify,eh as canDivide,Ni as canRepeat,Yo as childHitTest,Ho as childrenHitTestByRect,th as classify,_h as connect,Wo as contains,Eh as csv,Ah as csvString,rr as densify,Th as deserialize,Ql as divide,Ci as encode,Re as findElements,_t as getChannelEncodingByAttribute,pt as getChannelEncodingByElement,ut as getEncodingsByChannel,dt as getEncodingsByElement,Le as getLeafMarks,we as getPeers,vh as gradient,Ch as graphJSON,bt as isDataBound,mt as isDataBoundHorizontally,yt as isDataBoundVertically,Oh as isEqual,de as isMark,Ct as isRefElement,mh as layout,Uo as markHitTest,Xo as markPrimitiveHitTest,qo as markPrimitiveHitTestByRect,ct as removeEncoding,Rh as renderer,Oi as repeat,xr as repopulate,xh as scene,kh as serialize,ph as sortChildren,rh as stratify,wh as table,bh as transform,vt as translate,Sh as treeJSON,ar as update};