mascot-vis 4.3.1 → 4.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/mascot-cjs.cjs +3 -3
- package/dist/mascot-esm.js +3 -3
- package/dist/mascot-umd.js +3 -3
- package/index-new.html +1278 -0
- package/package.json +2 -1
package/dist/mascot-umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* version: 4.
|
|
2
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("d3")):"function"==typeof define&&define.amd?define(["exports","d3"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).msc={},e.d3)}(this,function(e,t){"use strict";function i(e){var t=Object.create(null);return e&&Object.keys(e).forEach(function(i){if("default"!==i){var r=Object.getOwnPropertyDescriptor(e,i);Object.defineProperty(t,i,r.get?r:{enumerable:!0,get:function(){return e[i]}})}}),t.default=e,Object.freeze(t)}var r=i(t);const s=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"}),n=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"}),a=Object.freeze({Axis:"axis",Legend:"legend",Gridlines:"gridlines",Trajectory:"trajectory"});function o(){return Date.now().toString(36)+"_"+Math.random().toString(36).slice(2)}function l(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 h=Object.freeze({Boolean:"boolean",Integer:"integer",Number:"number",Date:"date",String:"string"});function c(e){var t=Object.values(h);for(let i=0;i<e.length;i++){let r=e[i];if(null!=r){for(let e=0;e<t.length;e++)d[t[e]](r)||(t.splice(e,1),e-=1);if(1==t.length)return t[0]}}return t[0]}const d={boolean:function(e){return"true"===e||"false"===e||!0===e||!1===e||"[object Boolean]"==toString.call(e)},integer:function(e){return d.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 u(e,t){let i={};switch(t){case h.Boolean:i.trueCount=e.filter(e=>e).length,i.falseCount=e.filter(e=>!e).length;break;case h.Date:i.min=r.min(e),i.max=r.max(e),i.extent=[i.min,i.max],i.unique=[...new Set(e)];break;case h.String:i.unique=[...new Set(e)];break;default:i.min=r.min(e),i.max=r.max(e),i.extent=[i.min,i.max],i.mean=r.mean(e),i.median=r.median(e),i.unique=[...new Set(e)]}return i}const _="max",p="min",f="avg",g="mean",y="median",m="count",b="percentile 25",x="percentile 75";function v(e,t={},i){return{dataTable:e,filters:Object.assign({},t),rowIds:i?i.slice():void 0}}function w(e){if(e)return v(e.dataTable,e.filters,e.rowIds)}function E(e){return w(e)}function A(e){if(e)return e.dataTable}function C(e){return e&&e.filters||{}}function S(e){return e?e.rowIds&&e.dataTable?e.dataTable.rows({[j]:e.rowIds}):e.dataTable?e.dataTable.rows(e.filters):[]:[]}function k(e){let t=S(e);return t.length>0?t[0]:{}}function R(e){return S(e).length}function T(e,t){return t in C(e)}function O(e,t){let i=C(e);if(t in i)return i[t];let r=S(e);return r.length>0?r[0][t]:void 0}function I(e,t){let i=C(e);return t in i?[i[t]]:Array.from(new Set(S(e).map(e=>e[t])))}function N(e,t,i){let s=S(e).map(e=>e[t]);switch(i){case _:return r.max(s);case p:return r.min(s);case f:case g:return r.mean(s);case y:return r.median(s);case m:return s.length;case b:return r.quantile(s,.25);case x:return r.quantile(s,.75);default:return r.sum(s)}}function L(e,t,i){let r=A(e),s=Object.assign({},C(e),{[t]:i});return v(r,s,D(r,s))}function P(e,t){if(!e)return E(t);if(!t)return E(e);let i=A(e),r=Object.assign({},C(e));for(let[e,i]of Object.entries(C(t)))e in r&&r[e]!==i?console.warn("Conflict in attribute values when merging dataScope:",e,r[e],i):r[e]=i;return v(i,r,D(i,r))}function V(e){return v(e,{},e.data.map(e=>e[j]))}function B(e,t,i=!1){let r=A(e),s=C(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(v(r,Object.assign({},s,{[t]:e}),l.map(e=>e[j])))}return o}function D(e,t){return e.rows(t).map(e=>e[j])}class M{constructor(e,t,i){this._id=n.DataTable+o(),this.initialize(e,t,i)}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]=c(this.data.map(t=>t[e])),"year"==e.toLowerCase()&&this._attrTypes[e]==h.Integer&&(this._attrTypes[e]=h.Date)}this._validate(this.data,this._attrTypes),this._attrSummaries={};for(let e of this._attributes)this._attrSummaries[e]=u(this.data.map(t=>t[e]),this._attrTypes[e]);this._attributes.indexOf(j)<0&&this.addAttr(j,h.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 M(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!==j&&this._rawData.forEach((t,r)=>t[e]=i[r]),this._attrTypes[e]=t,this._attributes.includes(e)||this._attributes.push(e),this._attrSummaries[e]=u(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]===j&&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)||G(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(G(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[j],e)}_getFilterKey(e={}){return Object.entries(e).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>G(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(e,t){let i=r.timeParse(t);for(let t of this.data){let r=t[e];null==r||null==r?(r="",t[e]=new Date(1899,11,31).getTime()):t[e]=i(r).getTime(),this._dateMap.set(t[e],r)}this._attrTypes[e]=h.Date,this._attrSummaries[e]=u(this.data.map(t=>t[e]),h.Date),this._clearDataCaches()}raw(e,t){return this.type(e)===h.Date?this._dateMap.get(t).toString():t}get dimensions(){let e=[];for(let t in this._attrTypes)this._attrTypes[t]!=h.Number&&this._attrTypes[t]!=h.Integer&&t!=M.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]!==h.Number&&this._attrTypes[t]!==h.Integer||t==M.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!=M.RowID&&t.push(i);return t}summarize(){for(let e of this._attributes)this._attrSummaries[e]=u(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 h.Boolean:r=!1;break;case h.Date:r=new Date(1899,11,31).getTime();break;case h.String:r="";break;default:r=0}else switch(s){case h.Boolean:r=n;break;case h.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 h.String:r=n.toString();break;default:r=n}i[e]=r}}}function G(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)&&("min"in e||"max"in e)}function z(e){return e.dataScope?A(e.dataScope):e.parent&&e.parent.dataScope?A(e.parent.dataScope):void 0}const j="mascot_rowId";class F{constructor(e,t){this._id=n.TreeData+o(),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 M(this._nodeList,"nodes"),this._linkTable=new M(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={};X in e||(e[X]="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[X],child:n})}else s[n]=e[n];return this._nodeHash[s[X]]=s,s[X]}getNodeDataScopeRef(e){return L(V(this._nodeTable),j,e[j])}getNode(e){return this._nodeHash[e]}getRoot(){return this._nodeTable.data[0]}getChildren(e){let t=e[X],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[X]==t);i.push(s[n])}return i}getParent(e){let t=e[X],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[X]==t);return r[s]}}}function W(e){return A(e.dataScope).tree}class U{constructor(e,t){this._id=n.NetworkData+o(),this.initialize(e,t)}initialize(e,t){this.url=t,this._nodeTable=new M(e.nodes,this._id+"_nodes"),this._linkTable=new M(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[X]]=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[X],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[X]="root",H(t,this._rawNodes,e),new F(t,this.url)}}function Y(e){return A(e.dataScope).graph}function H(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[X]=t,e.children.push(i)}else for(let t in r){let s={};s[X]=t,e.children.push(s),H(s,r[t],i.slice(1))}}const X="id";function q(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 K{constructor(e,t,i){this._id="predicate_"+o(),this._type=e||Z.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 Z=Object.freeze({POINT:"point",INTERVAL:"interval",LIST:"list"});class $ extends K{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 J extends K{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 Q extends K{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 ee(e){let t,i="attribute"in e?"attribute":"property",r=e[i];switch(e.type){case Z.LIST:t=new J(e.type,i,r);break;case Z.INTERVAL:t=new $(e.type,i,r);break;case Z.POINT:default:t=new Q(e.type,i,r)}return t.value=e.value,t}function te(e,t){for(let i of t)if(!i.testElement(e))return!1;return!0}const ie={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 re(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 se(e,t,i,r){return Math.sqrt(Math.pow(e-i,2)+Math.pow(t-r,2))}function ne(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 ae=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 oe{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 oe(t,i,r-t,s-i)}clone(){return new oe(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 ue.RIGHT:this._x=this.right-e/2;break;case ue.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 ue.TOP:this._y=this.top+e/2;break;case ue.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 le(e){let t=e[0].clone();for(let i=1;i<e.length;i++)t=t.union(e[i]);return t}function he(e){return le(("vertex"==e[0].type||"segment"==e[0].type?e.map(e=>e.parent):e).map(e=>e.refBounds?e.refBounds:e.bounds))}function ce(e){return le(("vertex"==e[0].type||"segment"==e[0].type?e.map(e=>e.parent):e).map(e=>e.bounds))}function de(e){let t=Ce(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)de(e)}const ue=Object.freeze({TOP:"top",LEFT:"left",RIGHT:"right",BOTTOM:"bottom",CENTER:"center",MIDDLE:"middle"});class _e{constructor(e){if(this._dataScopeRef=void 0,this._type="type"in e?e.type:n.Mark,this._id=e.id?e.id:this._type+"_"+o(),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 ae)t in e&&(this.styles[t]=e[t])}get scene(){return Pe(this)}get datum(){return k(this._dataScopeRef)}get data(){return S(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=w(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=E(this._dataScopeRef))}createClipMask(){let e=this._bounds;this._clipMask=new oe(e.left,e.top,e.width,e.height)}get clipMask(){return this._clipMask}}function pe(e){return e instanceof _e&&e.type!==n.Gridlines}const fe=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"});class ge{constructor(){this._refElements=[]}addRefElement(e){this._refElements.push(e)}get refElements(){return this._refElements}clearRefElements(){this._refElements=[]}}function ye(e){return e instanceof ge}const me=Object.freeze({GRID:"grid",STACK:"stack",PACKING:"packing",FORCE:"force",DIRECTED:"directedgraph",TIDYTREE:"tidytree",TREEMAP:"treemap",STRATA:"strata",CIRCULAR:"circular",CLUSTER:"cluster",SPIRAL:"spiral"});function be(e,t){return!!(e.startsWith("h")&&[ue.LEFT,ue.CENTER,ue.RIGHT].indexOf(t)>=0)||(!!(e.startsWith("v")&&[ue.TOP,ue.MIDDLE,ue.BOTTOM].indexOf(t)>=0)||(console.warn("Invalid alignment:",t),!1))}class xe{constructor(e){this._id=e+"_"+o(),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 ve=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",BIN_TRANSFORMER:"binTransformer",FILTER_TRANSFORMER:"filterTransformer",KDE_TRANSFORMER:"kdeTransformer",CUSTOM_TRANSFORMER:"customTransformer",REPOPULATE:"repopulate",TARGET_EVALUATOR:"targetEvaluator",TARGET_UPDATER:"targetUpdater"});class we{constructor(e){this._id="v_"+o(),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 xe)return e.fromNode;return null}isIsolated(){return 0==this._incomings.length&&0==this._outgoings.length}}const Ee=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 Ae 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(Ee.STATE,e,this),this._scene.onChange(Ee.STATE,e,this)),this}}function Ce(e,t){let i=Pe(e);return"vertex"===e.type||"segment"===e.type?function(e,t){let i=Pe(e),r=t||i;if("vertex"===e.type){return Se(e,Oe(r,[{property:"classId",value:e.parent.classId}],!0))}if("segment"===e.type){return Te(e,Oe(r,[{property:"classId",value:e.parent.classId}],!0))}return e.classId?Oe(r,[{property:"classId",value:e.classId}]):[e]}(e,t):e.classId?Oe(t||i,[{property:"classId",value:e.classId}]):[e]}function Se(e,t){if(!e.classId){if(e.dataScope){let i=e.parent;if(!i)throw new Error("vertex has no parent mark");let r=[];if(i.type!==n.Area||e._isAnyVertex)for(let e of t)r=r.concat(e.vertices.filter(e=>e.dataScope));else{let s=i.vertices.indexOf(e)<i.vertices.length/2;for(let e of t){let t=s?e.vertices.slice(0,e.vertices.length/2):e.vertices.slice(e.vertices.length/2);r=r.concat(t.filter(e=>e.dataScope))}}return r}{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 ke(e,t){return e.id+"_v_"+e._vertices._ids[t]}function Re(e,t){let i=e.parent,r=e._index,s=[];if(e.dataScope)if(i.type!==n.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);s.push({parent:e,indices:t})}else{let e=r<i._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,n=[];for(let e=t;e<r;e++)i._vertices.hasDataScope(e)&&n.push(e);s.push({parent:i,indices:n})}}else for(let e of t)s.push({parent:e,indices:[r]});return s}function Te(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 Oe(e,t,i){let r=[];return Le(e,t?t.map(e=>ee(e)):[],r,i),r}function Ie(e,t){let i=e.children.filter(e=>e.type==n.Collection);if(0!==i.length)for(let e of i){let i=e;for(;i&&i.dataScope;){if(T(i.dataScope,t))return i;i=i.children?i.children[0]:void 0}}}function Ne(e){return e.type==n.Collection?e:e.parent?Ne(e.parent):void 0}function Le(e,t,i,r){if(e)if(te(e,t)&&i.push(e),e.vertices&&r)for(let r of e.vertices.concat(e.segments))te(r,t)&&i.push(r);else if(e.children&&e.children.length>0)for(let s of e.children)Le(s,t,i,r)}function Pe(e){let t;if(t=Array.isArray(e)?e[0]:e,t){if(t instanceof Ae)return t.scene;if(t._scene)return t._scene;for(ye(t)&&t.group&&(t=t.group),t.id.startsWith("encoding_")&&(t=t.element);t;){if(t.type==n.Scene)return t;t=t.parent}}}function Ve(e){let t=e;for("vertex"!=t.type&&"segment"!=t.type||(t=t.parent);t.parent&&[n.Collection,n.Glyph].includes(t.parent.type);)t=t.parent;return t}function Be(e,t){let i=[];if(De(e,i),t){let e={};for(let t of i)e[t.classId]=t;return Object.values(e)}return i}function De(e,t){if(pe(e))t.push(e);else if(e.children&&!Object.values(a).includes(e.type))for(let i of e.children)De(i,t)}class Me extends we{constructor(e,t,i){super(e),this._channel=t,this._elem=i}get channel(){return this._channel}get element(){return this._elem}}const Ge=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 ze extends we{constructor(e,t,i){super(e),this._property=t,this._elem=i}get property(){return this._property}get element(){return this._elem}}function je(e){return e in Fe?Fe[e]:e}const Fe=Object.freeze({numCols:"layoutParameter",numRows:"layoutParameter",startCorner:"layoutParameter",direction:"layoutParameter"}),We=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"});function Ue(e){let t=e?Pe(e):void 0;t&&t._clearInteractionCaches&&t._clearInteractionCaches()}function Ye(e,t){if(Ue(e),t.findVariable(Ee.BOUNDS,[e]))return;let i=t.getVariable(Ee.BOUNDS,e),r=t.createOneWayDependency(ve.EVAL_BBOX);switch(t.connect(r,i),e.type){case n.Circle:case n.Polygon:{let i=t.getVariable(Ee.CHANNEL,"x",e),s=t.getVariable(Ee.CHANNEL,"y",e),n=t.getVariable(Ee.CHANNEL,"radius",e),a=t.getVariable(Ee.CHANNEL,"area",e);t.connect(n,r),t.connect(i,r),t.connect(s,r),t.connect(a,r);break}case n.Area:case n.Line:case n.BezierCurve:case n.Path:case n.Image:case n.Symbol:{let i=t.getVariable(Ee.CHANNEL,"x",e),s=t.getVariable(Ee.CHANNEL,"y",e),n=t.getVariable(Ee.CHANNEL,"width",e),a=t.getVariable(Ee.CHANNEL,"height",e);t.connect(i,r),t.connect(s,r),t.connect(n,r),t.connect(a,r);break}case n.Rect:{let i=t.getVariable(Ee.CHANNEL,"x",e),s=t.getVariable(Ee.CHANNEL,"y",e),n=t.getVariable(Ee.CHANNEL,"width",e),a=t.getVariable(Ee.CHANNEL,"height",e),o=t.getVariable(Ee.CHANNEL,"area",e);t.connect(i,r),t.connect(s,r),t.connect(n,r),t.connect(a,r),t.connect(o,r);break}case n.SimpleText:case n.RichText:{let i=t.getVariable(Ee.CHANNEL,"x",e),s=t.getVariable(Ee.CHANNEL,"y",e),n=t.getVariable(Ee.CHANNEL,"text",e);t.connect(i,r),t.connect(s,r),t.connect(n,r);break}case n.Ring:{let i=t.getVariable(Ee.CHANNEL,"x",e),s=t.getVariable(Ee.CHANNEL,"y",e),n=t.getVariable(Ee.CHANNEL,"innerRadius",e),a=t.getVariable(Ee.CHANNEL,"outerRadius",e);t.connect(i,r),t.connect(s,r),t.connect(n,r),t.connect(a,r);break}case n.Pie:case n.Arc:{let i=t.getVariable(Ee.CHANNEL,"x",e),s=t.getVariable(Ee.CHANNEL,"y",e),n=t.getVariable(Ee.CHANNEL,"innerRadius",e),a=t.getVariable(Ee.CHANNEL,"outerRadius",e),o=t.getVariable(Ee.CHANNEL,"startAngle",e),l=t.getVariable(Ee.CHANNEL,"endAngle",e),h=t.getVariable(Ee.CHANNEL,"angle",e),c=t.getVariable(Ee.CHANNEL,"thickness",e);t.connect(i,r),t.connect(s,r),t.connect(n,r),t.connect(a,r),t.connect(o,r),t.connect(l,r),t.connect(h,r),t.connect(c,r);break}}r.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===n.Axis){let i=t.findVariable(Ee.PROPERTY,[We.AXIS_PATH_POSITION,e]).incomingDataflow;console.log(i,e),t.deleteOperator(i),i=t.findVariable(Ee.PROPERTY,[We.AXIS_TICKS_POSITION,e]).incomingDataflow,t.deleteOperator(i),i=t.findVariable(Ee.PROPERTY,[We.AXIS_LABELS_POSITION,e]).incomingDataflow,t.deleteOperator(i),i=t.findVariable(Ee.PROPERTY,[We.AXIS_TITLE_POSITION,e]).incomingDataflow,t.deleteOperator(i)}else if(e.type===n.Gridlines){let i=t.findVariable(Ee.PROPERTY,[We.GRIDLINES_POSITION,e]).incomingDataflow;t.deleteOperator(i)}}function qe(e,t){if(Ue(e),t.findVariable(Ee.BOUNDS,[e]))return;let i=t.getVariable(Ee.BOUNDS,e),r=t.getVariable(Ee.CHANNEL,"x",e),s=t.getVariable(Ee.CHANNEL,"y",e),n=t.getVariable(Ee.CHANNEL,"width",e),a=t.getVariable(Ee.CHANNEL,"height",e),o=t.createOneWayDependency(ve.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(Ee.BOUNDS,e),r=t.getVariable(Ee.CHANNEL,"x",e),s=t.getVariable(Ee.CHANNEL,"y",e),n=t.getVariable(Ee.CHANNEL,"width",e),a=t.getVariable(Ee.CHANNEL,"height",e),o=t.createOneWayDependency(ve.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(Ee.BOUNDS,e),s=i.getVariable(Ee.BOUNDS,t),n=i.getIncomingDataflowOperator(ve.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(Ee.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(Ee.BOUNDS,e),s=i.getVariable(Ee.BOUNDS,t),n=i.getIncomingDataflowOperator(ve.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(Ee.BOUNDS,e),r=t.getVariable(Ee.CHANNEL,"x",e),s=t.getVariable(Ee.CHANNEL,"y",e),n=t.getIncomingDataflowOperator(ve.EVAL_BBOX,i);t.connect(r,n),t.connect(s,n);for(let i of e.children)t.connect(t.getVariable(Ee.BOUNDS,i),n);t.connect(n,i),n.run()}function Qe(e){switch(e){case me.GRID:return ve.GRID_LAYOUT;case me.STACK:return ve.STACK_LAYOUT;case me.PACKING:return ve.PACK_LAYOUT;case me.FORCE:return ve.FORCE_LAYOUT;case me.DIRECTED:return ve.DIRECTED_LAYOUT;case me.TIDYTREE:return ve.TIDY_TREE_LAYOUT;case me.TREEMAP:return ve.TREEMAP_LAYOUT;case me.STRATA:return ve.STRATA_LAYOUT;case me.CIRCULAR:return ve.CIRCULAR_LAYOUT;case me.CLUSTER:return ve.CLUSTER_LAYOUT;case me.SPIRAL:return ve.SPIRAL_LAYOUT}}function et(e,t,i){let r=i.getVariable(Ee.PROPERTY,We.CHILDREN_ORDER,e),s=i.getOutgoingDataflowOperator(Qe(t.type),r);i.deleteOperator(s)}function tt(e,t,i){let r=t?t.type:"none",s=r===me.TREEMAP?Be(e)[0]:e.children[0];if(!s)return;let a=i.getVariable(Ee.CHANNEL,"width",s),o=i.getVariable(Ee.CHANNEL,"height",s),l=i.getVariable(Ee.PROPERTY,We.CHILDREN_ORDER,e),h=i.getVariable(Ee.CHANNEL,"x",s),c=i.getVariable(Ee.CHANNEL,"y",s),d=i.getVariable(Ee.CHANNEL,"visibility",s),u=i.getVariable(Ee.PROPERTY,We.LAYOUT_PARAMETER,t),_=i.getOutgoingDataflowOperator(Qe(r),l);if(i.connect(a,_),i.connect(o,_),i.connect(l,_),i.connect(u,_),i.connect(d,_),i.connect(_,h),i.connect(_,c),i.disconnectChannelVarFromBBoxOperator(a),i.disconnectChannelVarFromBBoxOperator(o),s.type===n.Arc||s.type===n.Pie){let e=i.getVariable(Ee.CHANNEL,"angle",s),t=i.getVariable(Ee.CHANNEL,"thickness",s);i.connect(e,_),i.connect(t,_)}else if(s.type===n.Circle){let e=i.getVariable(Ee.CHANNEL,"area",s),t=i.getVariable(Ee.CHANNEL,"radius",s);i.connect(e,_),i.connect(t,_),i.disconnectChannelVarFromBBoxOperator(e),i.disconnectChannelVarFromBBoxOperator(t)}else if(s.type===n.Rect){let e=i.getVariable(Ee.CHANNEL,"area",s);i.connect(e,_),i.disconnectChannelVarFromBBoxOperator(e)}if(_.run(),s.links&&it(s,i),s.children&&s.children[0]){let e=i.getVariable(Ee.BOUNDS,s.children[0]),t=i.getVariable(Ee.CHANNEL,"x",s).incomingDataflow;t&&i.connect(e,t),i.disconnectChannelVarFromBBoxOperator(e)}}function it(e,t){let i=e.links[0],r=t.getVariable(Ee.CHANNEL,"x",e),s=t.getVariable(Ee.CHANNEL,"x",i),n=t.getVariable(Ee.CHANNEL,"strokeWidth",i),a=t.getVariable(Ee.CHANNEL,"strength",i),o=t.createOneWayDependency(ve.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=z(e),s=r?i.findVariable(Ee.ITEMS,[r]):null;if(s)for(let e of s.outgoingEdges)if(e.isDirected&&e.toNode.type===ve.REPOPULATE)return void i.connect(e.toNode,t)}function st(e,t,i){let r=e.attribute,s=e.channel,a=e.element,o=t.createOneWayDependency(ve.ENCODER);if(["width","height"].includes(e.channel)&&a.type===n.Area){let e=t.getVariable(Ee.PROPERTY,We.BASE_LINE,a);t.connect(e,o)}if(i){let r=t.getVariable(Ee.ATTR_VALUE,i),n=t.getVariable(Ee.SCALE,i),l=t.getVariable(Ee.CHANNEL,s,a);t.connect(n,o),t.connect(o,l),r.addLinkedEncoding(e),n.addLinkedEncoding(e);let h=t.getVariable(Ee.DATASCOPE,e.element),c=r.incomingDataflow;c&&h&&(t.connect(h,c),rt(e.element,h,t)),r.incomingDataflow.run()}else{let i=t.getVariable(Ee.ATTRIBUTE,r,z(a),e),n=t.getVariable(Ee.PROPERTY,We.INCLUDE_ZERO,e),l=t.getVariable(Ee.ATTR_VALUE,e),h=t.getVariable(Ee.DATASCOPE,a),c=t.createOneWayDependency(ve.DATA_EXTRACTOR);t.connect(i,c),t.connect(n,c),t.connect(h,c),t.connect(c,l),rt(a,h,t),c.run();let d=t.getVariable(Ee.PROPERTY,We.RANGE_START,e),u=t.getVariable(Ee.PROPERTY,We.RANGE_EXTENT,e),_=t.getVariable(Ee.PROPERTY,We.FLIP_SCALE,e),p=t.getVariable(Ee.SCALE,e),f=t.createOneWayDependency(ve.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(Ee.CHANNEL,s,a);t.connect(p,o),t.connect(o,g),o.run()}}function nt(e,t){let i=t.getVariable(Ee.PROPERTY,We.AXIS_ORIENTATION,e),r=t.getVariable(Ee.BOUNDS,e.elements[0].parent),s=t.getVariable(Ee.PROPERTY,We.AXIS_PATH_POSITION,e),n=t.createOneWayDependency(ve.AXIS_PATH_PLACER);t.connect(i,n),t.connect(r,n),t.connect(n,s),n.run();let a=t.getVariable(Ee.PROPERTY,We.AXIS_TICK_OFFSET,e),o=t.getVariable(Ee.PROPERTY,We.AXIS_TICK_SIZE,e),l=t.createOneWayDependency(ve.AXIS_TICKS_PLACER),h=t.getVariable(Ee.PROPERTY,We.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(Ee.PROPERTY,We.AXIS_LABEL_OFFSET,e),d=t.getVariable(Ee.PROPERTY,We.AXIS_LABEL_FORMAT,e),u=t.getVariable(Ee.PROPERTY,We.AXIS_FONT_SIZE,e),_=t.createOneWayDependency(ve.AXIS_LABELS_PLACER),p=t.getVariable(Ee.PROPERTY,We.AXIS_LABELS_POSITION,e);t.connect(s,_),t.connect(c,_),t.connect(d,_),t.connect(u,_),t.connect(_,p),_.run();let f=t.getVariable(Ee.PROPERTY,We.AXIS_TITLE_POSITION,e),g=t.createOneWayDependency(ve.AXIS_TITLE_PLACER);t.connect(s,g),t.connect(g,f),g.run();let y=t.getVariable(Ee.BOUNDS,e),m=t.getIncomingDataflowOperator(ve.EVAL_BBOX,y);t.connect(h,m),t.connect(p,m),t.connect(m,y)}function at(e,t){let i=t.getVariable(Ee.PROPERTY,We.AXIS_ORIENTATION,e),r=t.getVariable(Ee.BOUNDS,Ve(e.elements[0])),s=t.getVariable(Ee.PROPERTY,We.AXIS_PATH_POSITION,e),n=t.createOneWayDependency(ve.AXIS_PATH_PLACER);t.connect(i,n),t.connect(r,n),t.connect(n,s),n.run();let a=t.getVariable(Ee.PROPERTY,We.AXIS_TICK_OFFSET,e),o=t.getVariable(Ee.PROPERTY,We.AXIS_TICK_SIZE,e),l=t.createOneWayDependency(ve.AXIS_TICKS_PLACER),h=t.getVariable(Ee.PROPERTY,We.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(Ee.PROPERTY,We.AXIS_LABEL_OFFSET,e),d=t.getVariable(Ee.PROPERTY,We.AXIS_LABEL_FORMAT,e),u=t.getVariable(Ee.PROPERTY,We.AXIS_FONT_SIZE,e),_=t.createOneWayDependency(ve.AXIS_LABELS_PLACER),p=t.getVariable(Ee.PROPERTY,We.AXIS_LABELS_POSITION,e);t.connect(s,_),t.connect(c,_),t.connect(d,_),t.connect(u,_),t.connect(_,p),_.run();let f=t.getVariable(Ee.PROPERTY,We.AXIS_TITLE_POSITION,e),g=t.createOneWayDependency(ve.AXIS_TITLE_PLACER);t.connect(s,g),t.connect(g,f),g.run();let y=t.getVariable(Ee.BOUNDS,e),m=t.getIncomingDataflowOperator(ve.EVAL_BBOX,y);t.connect(h,m),t.connect(p,m),t.connect(m,y)}function ot(e,t){let i=t.getVariable(Ee.BOUNDS,Ve(e.elements[0])),r=t.getVariable(Ee.PROPERTY,We.GRIDLINES_POSITION,e),s=t.createOneWayDependency(ve.GRIDLINES_PLACER);t.connect(i,s),t.connect(s,r),s.run();let n=t.getVariable(Ee.BOUNDS,e),a=t.getIncomingDataflowOperator(ve.EVAL_BBOX,n);t.connect(r,a),t.connect(a,n)}class lt{constructor(){this._id=this.type+o(),this._type=n.Group,this._dataScopeRef=void 0,this._bounds=void 0,this._layout=void 0,this._children=[],this._sortBy={property:j,descending:!1},this._z=0}get id(){return this._id}get type(){return this._type}get datum(){return k(this._dataScopeRef)}get data(){return S(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=w(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=P(e.dataScope,this._dataScopeRef):e.dataScope=this._dataScopeRef}getInternalEncodings(e){if(0==this.children.length)return[];let t=this.children[0],i=this.getScene(),r=Object.keys(i.encodings),s=[];for(;t;){if(t.classId&&s.indexOf(t.classId)<0&&s.push(t.classId),t.type===n.Glyph){t.children.forEach(e=>s.push(e.classId));break}if(!t.children)break;t=t.children[0]}let a=[];for(let t of r){let r=t.split("_");for(let n of s)r[0]==n&&i.encodings[t][e]&&a.push(i.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=Be(this,!0);for(let t of e)this.scene.onChange(Ee.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 oe(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 oe(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 Pe(this)}get sortBy(){return this._sortBy}}function ht(e){return e.type===n.Axis||e.type===n.Legend||e.type===n.Gridlines}class ct extends lt{constructor(e){super(),this._type=n.Collection,this._id=e.id?e.id:this._type+"_"+o(),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=he(this._children);this._clipMask=new oe(e.left,e.top,e.width,e.height)}get clipMask(){return this._clipMask}}class dt extends lt{constructor(e){if(super(),this._type=n.Glyph,this._id=e&&e.id?e.id:this.type+"_"+o(),this._classId=this._id,e&&e.children)for(let t of e.children)this.addChild(t)}get classId(){return this._classId}}const ut=Object.freeze({RowFirst:"rowFirst",ColumnFirst:"columnFirst"}),_t=Object.freeze({TopLeft:"topLeft",TopRight:"topRight",BottomLeft:"bottomLeft",BottomRight:"bottomRight"}),pt="horizontal",ft="vertical",gt="angular",yt="radial",mt={Left2Right:"l2r",Right2Left:"r2l",Top2Bottom:"t2b",Bottom2Top:"b2t"},bt=Object.freeze({CLOCKWISE:"clockwise",ANTI_CLOCKWISE:"anti-clockwise"}),xt=Object.freeze({INWARD:"inward",OUTWARD:"outward"}),vt=Object.freeze({INWARD:"inward",OUTWARD:"outward",TANGENTIAL_CLOCKWISE:"tangentialClockwise",TANGENTIAL_COUNTERCLOCKWISE:"tangentialCounterClockwise",UPRIGHT:"upright"});class wt{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?k(this.dataScope):this.parent.datum}get data(){return this.dataScope?S(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 oe(this.x-this.width/2,this.y-this.height/2,this.width,this.height);case"circle":return new oe(this.x-this.radius,this.y-this.radius,2*this.radius,2*this.radius);default:return new oe(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)}}wt.styles=["vxShape","vxWidth","vxHeight","vxRadius","vxFillColor","vxStrokeColor","vxStrokeWidth","vxOpacity"];class Et{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=w(e)}get datum(){return this.dataScope?k(this.dataScope):this.parent.datum}get data(){return this.dataScope?S(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 At{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):At._isIndex(t)?e.get(Number(t)):e[t],set(e,t,i){if(At._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 wt(this._path,e)),this._refs[e]}at(e){return e<0&&(e=this.length+e),this.get(e)}append(e,t){let[i,r]=At.getCoords(e),s=Array.isArray(e)?void 0:e.dataScope,n=void 0!==t?t:At.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]:At.getCoords(t),a=n[0],o=n[1],l=s||Array.isArray(t)?void 0:t.dataScope,h=s?r:At.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]=At.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=At.propertyArrays[t];return"dataScope"===t?this.getDataScopeRef(e):i?this[i][e]:void 0}setProperty(e,t,i){let r=At.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 S(t)}getDataScopeAttrVal(e,t){let i=this._dataScopeRefs[e];if(i)return O(i,t)}getDataScopeAttributeValues(e,t){let i=this._dataScopeRefs[e];return i?I(i,t):[]}aggregateDataScopeAttribute(e,t,i){return N(this._dataScopeRefs[e],t,i)}_copyDataScopeRef(e){return e?w(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 At.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 At.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 Ct=class extends _e{constructor(e){super(e),this._type="type"in e?e.type:n.Path,this._vertices=new At(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 wt.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 i=At.getCoords(e[t]),r=At.getCoords(e[0]);if(t==e.length-1&&i[0]===r[0]&&i[1]===r[1]&&this.type===n.Path)continue;let s=Array.isArray(e[t])?this.vertexCounter++:At.getId(e[t]),a=this._vertices.append(e[t],s);!Array.isArray(e[t])&&"number"==typeof s&&s>=this.vertexCounter&&(this.vertexCounter=s+1);for(let e of wt.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 Et(a-1,a,this,this.segmentCounter++))}let t=At.getCoords(e[0]),i=At.getCoords(e[e.length-1]);this._vertices.length>1&&(this.closed||t[0]===i[0]&&t[1]===i[1]||this.type===n.Rect)&&(this.closed=!0,"fillColor"in this.styles||(this.styles.fillColor="#fff"),this.segments.push(new Et(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 wt.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 Et(t-1,t,e,e.segmentCounter++));e.closed&&e.segments.push(new Et(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 e=[],t=[];if(this._d){const i=this._d.match(/[a-zA-Z][^a-zA-Z]*/g),r=" ";i.forEach(i=>{let s=i.slice(1).trim().split(r).map(Number);for(let[i,r]of s.entries())i%2==0?e.push(r):t.push(r)})}else e=this._vertices._xs,t=this._vertices._ys;let i=r.min(e),s=r.min(t),a=r.max(e),o=r.max(t),l=a-i,h=o-s;if(this._bounds=new oe(i,s,l,h),this.type===n.Line||this.type===n.Path){let e=this.styles.strokeWidth?this.styles.strokeWidth:1;i===a?this._bounds=new oe(i-e/2,s,a-i+e,o-s):s===o&&(this._bounds=new oe(i,s-e/2,a-i,o-s+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 e=r.path(),t=this._getD3CurveFunction(this.curveMode)(e);t.lineStart();for(let e=0;e<this._vertices.length;e++)t.point(this._vertices._xs[e],this._vertices._ys[e]);return this.closed&&t.point(this._vertices._xs[0],this._vertices._ys[0]),t.lineEnd(),e._}get firstVertex(){return this._vertices[0]}get anyVertex(){return this._anyVertexRef||(this._anyVertexRef=new wt(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(e){switch(e){case Rt.Natural:return r.curveNatural;case Rt.Basis:return r.curveBasis;case Rt.BumpX:return r.curveBumpX;case Rt.BumpY:return r.curveBumpY;case Rt.Linear:return r.curveLinear;case Rt.Step:return r.curveStep;case Rt.CatmullRom:return r.curveCatmullRom;case Rt.Cardinal:return r.curveCardinal;case Rt.Bundle:return r.curveBundle.beta(.5);default:return r.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 St(e,t){const i=ie.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 kt(e){return e instanceof Ct&&e.source&&e.target}const Rt={Natural:"natural",Basis:"basis",BumpX:"bumpX",BumpY:"bumpY",Bundle:"bundle",Linear:"linear",Step:"step",CatmullRom:"CatmullRom",Cardinal:"cardinal"};function Tt(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 Ot extends Ct{constructor(e){super(e),this._type=n.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=It(this._startAngle),this._er=It(this._endAngle),this._direction="direction"in e?e.direction:bt.ANTI_CLOCKWISE;let t=this._x+this._innerRadius*Math.cos(this._sr),i=this._y-this._innerRadius*Math.sin(this._sr),r=this._x+this._innerRadius*Math.cos(this._er),s=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,i],[a,o],[l,h],[r,s]]}get type(){return 0===this._innerRadius?n.Pie:n.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=It(this._startAngle),this._er=It(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 oe(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 It(e){return e*Math.PI/180}function Nt(e){return 180*e/Math.PI}function Lt(e){return(e%360+360)%360}function Pt(e,t,i,r){let s=e-i,n=r-t;return Math.atan2(n,s)*(180/Math.PI)}class Vt extends Ct{constructor(e){super(e),this._type=n.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 Et(this.vertices.length-1,0,this,this.segmentCounter++))}get topLeftVertex(){return this._orientation===pt?this.vertices[0]:this.vertices[this.vertices.length-1]}get bottomLeftVertex(){return this._orientation===pt?this.vertices[this.vertices.length-1]:this.vertices[this.vertices.length/2]}get topRightVertex(){return this._orientation===pt?this.vertices[this.vertices.length/2-1]:this.vertices[0]}get bottomRightVertex(){return this._orientation===pt?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 Bt extends Ct{constructor(e){super(e),this._type=n.BezierCurve,this._orientation="orientation"in e?e.orientation:pt}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 Dt extends _e{constructor(e){super(e),this._type=n.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=re(this._x,this._y,this._rotate[1],this._rotate[2],this._rotate[0]);this._bounds=new oe(e.x-this._radius,e.y-this._radius,2*this._radius,2*this._radius)}else this._bounds=new oe(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 Mt extends _e{constructor(e){super(e),this._type=n.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 oe(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 Gt=class extends _e{constructor(e){super(e),this._type=n.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 oe(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 zt extends Ct{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 jt="filled",Ft="none";class Wt extends Ct{constructor(e={}){const t="x1"in e?e.x1:0,i="y1"in e?e.y1:0,r="x2"in e?e.x2:100,s="y2"in e?e.y2:0,a=[[t,i],...e.controlPoints||[],[r,s]];super({...e,type:n.Arrow,vertices:a}),this._startStyle=e.startStyle??Ft,this._startSize=e.startSize??8,this._endStyle=e.endStyle??jt,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 Ut extends _e{constructor(e){super(e),this._type=n.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:[ue.CENTER,ue.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=ie.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 ue.LEFT:e=this._x;break;case ue.RIGHT:e=this._x-r;break;case ue.CENTER:e=this._x-r/2;break;default:e=this._x}switch(this._anchor[1]){case ue.TOP:t=this._y;break;case ue.BOTTOM:t=this._y-s;break;case ue.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=>re(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 oe(n,o,a-n,l-o)}else this._bounds=new oe(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 Yt extends Ct{constructor(e){super(e),this._type=n.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 Ht extends Ct{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 Xt extends Ct{constructor(e){super(e),this._type=n.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 qt extends _e{constructor(e){super(e),this._type=n.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:[ue.CENTER,ue.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=ie.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 ue.LEFT:e=this._x;break;case ue.RIGHT:e=this._x-r;break;case ue.CENTER:e=this._x-r/2;break;default:e=this._x}switch(this._anchor[1]){case ue.TOP:t=this._y;break;case ue.BOTTOM:t=this._y-s;break;case ue.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=>re(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 oe(n,o,a-n,l-o)}else this._bounds=new oe(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 Kt{constructor(e){let t=e||{};this._stops=[],this.type=n.LinearGradient,this.id=this.type+o(),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 Zt{constructor(e){this.type=n.PathGradient,this.id=this.type+o(),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}}function $t(e,t,i,s){let n,a=e.domain,o=e.range;switch(e.type){case"linear":case"log":{let l=Math.abs(o[0]-o[1]);n="width"==t||"x"==t?45:30;let h,c=Math.max(2,Math.floor(l/n));if("width"==t||"height"==t){let r=!!s&&(s.elements[0].parent.layout&&s.elements[0].parent.layout.type==me.STACK);a[1]=e._scale.invert(r?ce(i)[t]:he(i)[t])}if("log"===e.type){h=[];let t=e._scale.ticks();for(let e of t){let i=Math.log(e)/Math.log(10)+1e-6;Math.abs(i-Math.floor(i))<c/t.length&&h.push(e)}}else h=r.ticks(a[0],a[1],c);return h}case"point":{n="width"==t||"x"==t?80:30;let i=Math.floor(e.rangeExtent/a.length),r=Math.ceil(n/i);return"x"==t?a.filter((e,t)=>t%r==0):a}case"band":{n="width"==t||"x"==t?80:30;let i=Math.floor(e.rangeExtent/a.length),r=Math.max(1,Math.ceil(n/i));return a.filter((e,t)=>t%r==0)}case"time":{n="width"==t||"x"==t?80:30;let e,i,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=[r.timeSeconds,r.timeMinutes,r.timeHours,r.timeDays,r.timeMonths,r.timeYears];for(let t=0;t<h.length-1;t++)if(l>=h[t]&&l<h[t+1])return e=Math.floor(l/h[t]),i=c[t],i(a[0],a[1],e);return l>h[h.length-1]?(e=Math.floor(l/h[h.length-1]),i=c[h.length-1],i(a[0],a[1],e)):[]}default:return[]}}function Jt(e,t){t.removeChild(e)}class Qt extends lt{constructor(e){super(),this._type=n.Axis,this._id=e.id?e.id:this._type+o(),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 lt,this._ticks._id=this._id+"_ticks",this.addChild(this._ticks),this._labels=new lt,this._labels._id=this._id+"_labels",this.addChild(this._labels),this._title=new Ut({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!==n.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 ei="top",ti="bottom",ii="left";function ri(e,t,i){if(e&&e.origin)return e.origin;let r=t[0].parent;if(r.type===n.Polygon)return[r.x,r.y];throw new Error('Mascot: "polarRadius"/"polarAngle" '+i+' 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 si extends Qt{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?ti:ii,this._titleText="title"in r?r.title:this._encoding.sourceAttribute??this._encoding.attribute,this._path="angle"===this._channel||"polarAngle"===this._channel?new Dt({strokeColor:this._strokeColor,id:this._id+"_path"}):new Ct({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)!==h.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 ri(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(e){"tickValues"in e?(this._tickValues=e.tickValues,this._labelValues="labelValues"in e?e.labelValues:e.tickValues):(this._tickValues=$t(this._scale,this._channel,this._elems,this),this._labelValues="labelValues"in e?e.labelValues:this._tickValues),this._ticks.removeAll();for(let e=0;e<this._tickValues.length;e++){let t=new Ct({strokeColor:this._strokeColor,id:this._id+"_tick"+e});this._tickVisible||(t.visibility="hidden"),this._ticks.addChild(t)}this._labels.removeAll();let t,i=this._encoding.dataTable.type(this._attribute);if("labelValues"in e)t=function(e){return e};else switch(i){case h.Date:t=r.utcFormat(this._labelFormat);break;case h.String:t=function(e){return e};break;default:t=r.format(this._labelFormat)}for(let[e,i]of this._labelValues.entries()){let r=new Ut({text:t(i),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 ni{constructor(e,t){switch(this._id="scale_"+o(),this._type=e,t&&(this._args=t),e){case"linear":this._scale=r.scaleLinear();break;case"point":this._scale=r.scalePoint();break;case"band":this._scale=r.scaleBand().padding(0);break;case"ordinal":this._scale=r.scaleOrdinal();break;case"ordinalColor":this._scale=r.scaleOrdinal(r[t.scheme]);break;case"power":this._scale=r.scalePow().exponent(2);break;case"sqrt":this._scale=r.scalePow().exponent(.5);break;case"log":this._scale=r.scaleLog();break;case"identity":case"time":this._scale=r.scaleTime();break;case"sequentialColor":t.scheme?this._scale=r.scaleSequential(r[t.scheme]):this._scale=r.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(e,t){let i=r.min(this._scale.range()),s=r.max(this._scale.range()),n=e;if(t||(n=r.max([i,r.min([e,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 ai(e){if(e.scaleType)return new ni(e.scaleType);if(e._baseEnc&&e._baseEnc.scales.length>0){let t=e._baseEnc.scales[0];return new ni(t.type,t._args)}if("text"===e.channel||"src"===e.channel||"path"===e.channel)return new ni("ordinal");switch(e.dataTable.type(e.attribute)){case h.Boolean:break;case h.Date:return new ni("time");case h.String:if("count"==e.aggregator)return new ni("linear");if(e.channel.indexOf("Color")>=0||"fillGradient"===e.channel||"strokeGradient"===e.channel){let t={};return t.scheme=e.colorScheme?e.colorScheme:"schemeCategory10",new ni("ordinalColor",t)}return new ni("point");default:return["strokeColor","fillColor","fillGradient","strokeGradient"].indexOf(e.channel)>=0?e.mapping?new ni("linear"):new ni("sequentialColor",{scheme:e.colorScheme}):new ni("linear")}}const oi=["schemeBrBG","schemePRGn","schemePiYG","schemePuOr","schemeRdBu","schemeRdGy","schemeRdYlBu","schemeRdYlGn","schemeSpectral"],li=["schemeBlues","schemeGreens","schemeGreys","schemeOranges","schemePurples","schemeReds","schemeBuGn","schemeBuPu","schemeGnBu","schemeOrRd","schemePuBuGn","schemePuBu","schemePuRd","schemeRdPu","schemeYlGnBu","schemeYlGn","schemeYlOrBr","schemeYlOrRd"];function hi(e,t){let i=t||Pe(e.element);delete i._encodings[_i(e.element)][e.channel],console.log("remove encoding",e.channel,e.attribute),function(e,t){let i=t.findVariable(Ee.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)Jt(t,i),Xe(t,i._depGraph);e.clearRefElements()}function ci(e,t){let i=e.scene._encodings[_i(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 di(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 ui(e,t){let i=e.scene._encodings[_i(e)];return i&&i[t]?i[t]:null}function _i(e){if(Array.isArray(e))return e.map(e=>_i(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===n.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 pi(e,t){if(0==e.children.length)return[];let i=Pe(e),r=e.type===n.Composite?e.children:[e.children[0]],s=Object.keys(i._encodings),a=[];for(let e of r){let t=e;for(;t;){if(t.classId&&a.indexOf(t.classId)<0&&a.push(t.classId),t.type===n.Glyph){t.children.forEach(e=>a.push(e.classId));break}if(!t.children)break;t=t.children[0]}}let o=[];for(let e of s)for(let r of a)0===e.indexOf(r)&&i._encodings[e][t]&&o.push(i._encodings[e][t]);return o}function fi(e){let t=ui(e,"y"),i=ui(e,"height");return t||i&&i.scales[0].domain[0]<0}function gi(e){let t=ui(e,"x"),i=ui(e,"width");return t||i&&i.scales[0].domain[0]<0}class yi extends Ct{constructor(e,t,i,r,s){super(s),this._type=n.Gridlines,this._id=this._type+o(),this._attribute=t,this._channel=e,this._scale=i,this._elems=r,this._args=s,"strokeColor"in s||(this.styles.strokeColor="#ddd"),"opacity"in s||(this.styles.opacity=.5),this.updateValues(),this._lines=[]}updateValues(){"values"in this._args?this._values=this._args.values:this._scale?this._values=$t(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 oe(e.x-e.r,e.y-e.y,2*e.r,2*e.r));this._bounds=le(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 oe(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 ri(this._args,this._elems,"gridlines")}get lines(){return this._lines}set lines(e){this._lines=e}}class mi{constructor(e,t,i,r,s){this._id="encoding_"+o(),this._elem=e,this._channel=t,this._attribute=i,this._table=s.table,this._aggregator=r,this._includeZero=s.includeZero,this._flipScale=s.flipScale,this._mapping=s.mapping,this._preferredRangeExtent=s.rangeExtent,this._preferredRangeStart=s.rangeStart,this._preferredDomain=s.domain,this._preferredRange=s.range,this._preferredOrigin=s.origin,this._scaleType=s.scaleType,this._colorScheme=s.scheme,this._forLegend=s.forLegend,this._sourceAttribute=s.sourceAttribute??null,s.shareScale&&(this._baseEnc=s.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=Ve(this._elem),i=Ce(this._elem.parent);if("x"!==this._channel&&"y"!==this._channel||!t.layout||t.layout.type!=me.GRID)e=gi(this._elem.parent)||fi(this._elem.parent)?i.map(e=>Re(this._elem,[e])):[Re(this._elem,i)];else{e=("x"===this._channel?t.layout.getElementsByCol(!0,this._elem.parent):t.layout.getElementsByRow(!0,this._elem.parent)).map(e=>Re(this._elem,e))}for(let t of e)this._createScaleForVertexIndices(t)}else if("x"===this._channel||"y"===this._channel){let e=this._elem,t=Ve(e);if(t.layout&&t.layout.type==me.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=Ce(this._elem);this._createScaleForElems(e)}}else if("angle"===this._channel){let e=Ce(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=Ce(this._elem);this._createScaleForElems(e)}}_createScaleForElems(e){this._elemGroups.push(e);var t=ai(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=ai(this);this._scales.push(t);for(let i of e)for(let e of i.indices)this._elem2scale[ke(i.parent,e)]=t}refreshElementMappings(){if(1===this._scales.length)if(this._elem2scale={},"vertex"===this._elem.type){let e=Ce(this._elem.parent),t=Re(this._elem,e);this._elemGroups=[{type:"vertexIndices",groups:t}];for(let e of t)for(let t of e.indices)this._elem2scale[ke(e.parent,t)]=this._scales[0]}else{let e=Ce(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(e,t,i){let s=(t?this.getScale(t):this._scales[0]).invert(e,i),n=this._attribute;if(this.dataTable.type(n)===h.Date){const e=this.dataTable.values(n).slice().sort((e,t)=>e-t);let t=r.bisectLeft(e,s);return t=Math.min(t,e.length-1),t>0&&Math.abs(e[t-1]-s)<Math.abs(e[t]-s)&&t--,e[t]}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 si?(t._attribute=e,t.createTicksLabels({}),t._titleText&&(t._titleText=this._sourceAttribute??e)):t instanceof yi&&(t._attribute=e,t.updateValues());const i=this._elem.scene._depGraph.getVariable(Ee.ATTRIBUTE,t,this.dataTable,this);i&&(i._attribute=e,this._elem.scene.onChange(Ee.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(e){let t=this.getScale(e);return r.min(t.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 si&&e.createTicksLabels({});this._elem.scene.onChange(Ee.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 si&&e.createTicksLabels({});this._elem.scene.onChange(Ee.PROPERTY,We.RANGE_EXTENT,this)}set includeZero(e){this._includeZero=e;for(let e of this._refElements)e instanceof si&&e.createTicksLabels({});this._elem.scene.onChange(Ee.PROPERTY,We.INCLUDE_ZERO,this)}get includeZero(){return this._includeZero}set flipScale(e){this._flipScale=e,this._elem.scene.onChange(Ee.PROPERTY,We.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(e,t,i,s){let n=s||this._elem,a=this.getDomain(n),o=r.min(a),l=r.max(a),h="log"!==this._scales[0].type,c=this.getAttrValue(t,n,h),d=o-(c-o)*e*i,u=l+(l-c)*e*i;d!==u&&(!h&&d<=0||(this.domain=[d,u]))}}function bi(e,t){let i=function(e){let t=e.parent,i=[];for(;t.type!==n.Scene;)i.push(t),t=t.parent;return i}(e);for(let e of i)if(ui(e,t))return!1;return i.length>=2?i[i.length-2]:e}function xi(e,t,i){switch(e.type){case n.Rect:case n.Path:case n.Line:case n.Area:!function(e,t,i){for(let r of e.vertices)vi(r,t,i);e._updateBounds(),e._refBounds&&e._refBounds.translate(t,i)}(e,t,i),0===t&&0===i||(e._dirty=!0);break;case n.Group:case n.Collection:case n.Glyph:!function(e,t,i){for(let r of e.children)xi(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,i);break;case"segment":!function(e,t,i){vi(e.vertex1,t,i),vi(e.vertex2,t,i)}(e,t,i),0===t&&0===i||(e.parent._dirty=!0);break;case"vertex":vi(e,t,i),0===t&&0===i||(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,i),0===t&&0===i||(e._dirty=!0)}}function vi(e,t,i){e.x+=t,e.y+=i}function wi(e,t,i,r={}){let s={channel:t,attribute:i,...r};if("rowId"===s.attribute&&(s.attribute=j),function(e,t,i){if(!e||!t||!i)throw new Error("encode(elem, channel, attribute) — all three arguments are required");if(!Object.values(Ge).includes(t))throw new Error(`Unknown channel "${t}"`);let r=z(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,i),s.shareScale){let e=s.shareScale;if(e.channel!=s.channel&&e.channel.indexOf("Color")<0&&s.channel.indexOf("Color")<0)throw new Error("Cannot share scales between "+e.channel+" and "+s.channel+" encodings");s.scheme=s.shareScale.colorScheme}!function(e){let t;"vertex"===e.type&&e.parent.type===n.Area?t=e.parent:e.type===n.Area&&(t=e),t&&!t._refBounds&&Ce(t).forEach(e=>e._refBounds=e.bounds.clone())}(e);let a=s.aggregator?s.aggregator:"sum";s.table=z(e);let o=new mi(e,s.channel,s.attribute,a,s),l=e.scene;return l._addAttributeEncoding(o),st(o,l._depGraph,s.shareScale),s.shareScale?l.onChange(Ee.ATTR_VALUE,o):l.onChange(Ee.CHANNEL,s.channel,e),o}function Ei(e,t,i,r){for(let s=t;s<i;s++)e._vertices._xs[s]=r;e._dirty=!0}function Ai(e,t,i,r){for(let s=t;s<i;s++)e._vertices._xs[s]=r(s);e._dirty=!0}function Ci(e,t,i,r){for(let s=t;s<i;s++)e._vertices._ys[s]=r;e._dirty=!0}function Si(e,t,i,r){for(let s=t;s<i;s++)e._vertices._ys[s]=r(s);e._dirty=!0}function ki(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 M(i,"from count");return Ri(e,r)}(e,t):function(e){if(!e||"object"!=typeof e||Array.isArray(e))return!1;if(e instanceof M||e instanceof F||e instanceof U)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 M(r,"from group counts");return Ri(e,s,i)}(e,t,i):Ri(e,t,i)}function Ri(e,t,i){let r=Pe(e),s=i||{};if(s.attribute=s.attribute||j,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 F||t instanceof U){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 M&&l(i.attribute,t);if(i.layout&&!(i.layout instanceof ge))throw new Error("Invalid layout: "+i.layout)}(e,t,s),t instanceof F||t instanceof U){let i=e[0].parent,s=e[1].parent,[a,o]=function(e,t,i,r){let s=t.dataScope?t.dataScope:V(r.nodeTable),a=B(s,X),o=Bi(e,{type:n.Collection}),l=Bi(e,{type:n.Collection}),h={};l.dataScope=s,l.addChild(t);for(let e=1;e<a.length;e++){let e=Gi(t);l.addChild(e)}l.children.forEach((e,t)=>{e.dataScope=a[t],e.links=[],h[O(e.dataScope,X)]=e});let c=i.dataScope?i.dataScope:V(r.linkTable),d=B(c,j);o.dataScope=c,o.addChild(i);for(let e=1;e<d.length;e++){let e=Gi(i);o.addChild(e)}o.children.forEach((e,t)=>e.dataScope=d[t]);let u=r instanceof F?"parent":"source",_=r instanceof F?"child":"target";for(let e of o.children){let t=O(e.dataScope,u),i=O(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]}(r,e[0],e[1],t);return Ze(i,e[0],r._depGraph),Ze(s,e[1],r._depGraph),qe(a,r._depGraph),qe(o,r._depGraph),$e(a,e[0],r._depGraph),$e(a.parent,a,r._depGraph),$e(o,e[1],r._depGraph),$e(o.parent,o,r._depGraph),[a,o]}if(t instanceof M){let i=e.parent,a=function(e,t,i,r){let s=r.type(i);if(s!=h.String&&s!=h.Date&&s!=h.Integer)throw new Error("Repeat only works on a string or date attribute: "+i+" is "+s);if(!function(e){if(Array.isArray(e)){if(1===e.length)return Ti(e[0]);for(let t of e)if(!pe(t)||t.dataScope)return!1;return!0}return Ti(e)}(t))throw new Error("The "+t.type+" is not repeatable");return function(e,t,i,r){let s=t.dataScope?t.dataScope:V(r),a=B(s,i),o=Bi(e,{type:n.Collection});o.dataScope=s,o.addChild(t),t._refBounds||(t._refBounds=t.bounds.clone());for(let e=1;e<a.length;e++){let e=Gi(t);o.addChild(e)}return o.children.forEach((e,t)=>e.dataScope=a[t]),o}(e,t,i,r)}(r,e,s.attribute,t);return Ze(i,e,r._depGraph),qe(a,r._depGraph),$e(a,e,r._depGraph),$e(a.parent,a,r._depGraph),function(e,t,i,r){let s=r.getVariable(Ee.ITEMS,i),n=r.createOneWayDependency(ve.REPOPULATE);n._collection=e,n._repeatAttr=t,r.connect(s,n);let a=e.children[0],o=new Set([a,...Be(a)]);for(let e of o)r.connect(n,r.getVariable(Ee.DATASCOPE,e))}(a,s.attribute,t,r._depGraph),s.layout&&(a.layout=s.layout),a}}function Ti(e){return!(!pe(e)&&e.type!=n.Glyph||e.dataScope)||e.type===n.Collection&&R(e.firstChild.dataScope)>1}class Oi extends ge{constructor(e){super(),this.type=me.GRID,this._numCols=e.numCols,this._numRows=e.numRows,this._start="start"in e?e.start:_t.TopLeft,this._direction="direction"in e?e.direction:ut.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&&be("h",e.horzCellAlignment)?e.horzCellAlignment:ue.LEFT,this._cellVertAlignment="vertCellAlignment"in e&&be("v",e.vertCellAlignment)?e.vertCellAlignment:ue.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 Oi({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(Be(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(Be(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=Be(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=>Se(t,e))):"segment"===t.type?(i=e.map(e=>e.filter(e=>e.classId===t.parent.classId)),i=i.map(e=>Te(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 ut.RowFirst:t=Math.floor(e/this.numCols),i=e%this.numCols;break;case ut.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 Ii extends lt{constructor(e,t){super(),this._type=n.Axis,this._id=this._type+o(),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:ft,this._numberFormat=t.numberFormat?t.numberFormat:""}get attribute(){return this._enc.attribute}get channel(){return this._enc.channel}get attributeType(){return z(this._enc.element).getFieldType(this.attribute)}get orientation(){return this._orientation}get textColor(){return this._textColor}}class Ni extends Ii{constructor(e,t){super(e,t),"numCols"in t||"numRows"in t?(this._numCols=t.numCols,this._numRows=t.numRows):this._orientation===ft?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 M(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 Ct&&n.closed&&"strokeColor"!==this._enc.channel?n.strokeWidth:0;if(this._orientation===ft){let i=0;this._showTitle&&(this.addChild(new Ut({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=ki(e.glyph(o,l),r);wi(l,"text","category",{forLegend:!0}),wi(o,"fillColor","category",{shareScale:this._enc,forLegend:!0}),h.layout=new Oi({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=ki(e.glyph(t,i),r);wi(i,"text","category",{forLegend:!0}),wi(t,"fillColor","category",{shareScale:this._enc,forLegend:!0}),o.layout=new Oi({numCols:this._numCols,numRows:this._numRows,colGap:15}),this.addChild(o)}}}class Li extends Ii{constructor(e,t){super(e,t),this._initialize()}_initialize(){let e,t,i,s=this._enc.element.scene,n=this._enc.attribute;if(this._orientation==ft?(e=15,t=300):(e=300,t=15),this._showTitle){let t=s.mark("text",{fillColor:this._textColor,text:n,x:this._x+e/2,y:this._y,anchor:["center","middle"]});this.addChild(t),i=20}else i=0;let a,o=s.mark("rect",{top:this._y+i,left:this._x,width:e,height:t,strokeWidth:0,opacity:this._enc.element.opacity}),l=Object.values(this._enc.attrValues),c=[r.min(l),r.max(l)],d=this._enc.mapping,u=[],_=[],p=r.format(this._numberFormat);if(d){let r=Object.keys(d).map(e=>parseFloat(e)).sort((e,t)=>e-t);this._orientation==ft?(a=new Kt({x1:0,y1:100,x2:0,y2:0}),r.forEach(r=>{let n=(r-c[0])/(c[1]-c[0]);a.addStop(100*n,d[r],1);let o=s.mark("line",{x1:this._x+e,x2:this._x+e+5,y1:this._y+t-n*t+i,y2:this._y+t-n*t+i,strokeColor:this._strokeColor});_.push(o);let l=s.mark("text",{fillColor:this._textColor,text:this._numberFormat?p(r):r.toFixed(0),x:this._x+e+5+5,y:this._y+t-n*t+i,anchor:["left","middle"]});u.push(l)})):(a=new Kt({x1:0,y1:0,x2:100,y2:0}),r.forEach(r=>{let n=(r-c[0])/(c[1]-c[0]);a.addStop(100*n,d[r],1);let o=s.mark("line",{x1:this._x+n*e,x2:this._x+n*e,y1:this._y+20-5+i,y2:this._y+t+5+i,strokeColor:this._strokeColor});_.push(o);let l=s.mark("text",{fillColor:this._textColor,text:this._numberFormat?p(r):r.toFixed(0),x:this._x+n*e,y:this._y+t+5+i,anchor:["center","top"]});u.push(l)}))}else{let r=this._enc.scales[0].domain,o=z(this._enc.element),l=o.type(n),c=[],d=l===h.Date?o.getUniqueFieldValues(n):[...new Set(Object.values(this._enc.attrValues))];if(d.length<=10)c=d,c.sort((e,t)=>e-t);else if(l===h.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 e=(r[1]-r[0])/9;for(let t=0;t<10;t++)c.push(r[0]+t*e)}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==ft?(a=new Kt({x1:0,y1:100,x2:0,y2:0}),c.forEach(c=>{let d=(c-r[0])/(r[1]-r[0]);a.addStop(100*d,this._enc.scales[0].map(c),1);let f=s.mark("line",{x1:this._x+e,x2:this._x+e+5,y1:this._y+t-d*t+i,y2:this._y+t-d*t+i,strokeColor:this._strokeColor});_.push(f);let g=s.mark("text",{fillColor:this._textColor,text:l===h.Date?o.raw(n,c):this._numberFormat?p(c):c,x:this._x+e+5+5,y:this._y+t-d*t+i,anchor:["left","middle"]});u.push(g)})):(a=new Kt({x1:0,y1:0,x2:100,y2:0}),c.forEach(c=>{let d=(c-r[0])/(r[1]-r[0]);a.addStop(100*d,this._enc.scales[0].map(c),1);let p=s.mark("line",{x1:this._x+d*e,x2:this._x+d*e,y1:this._y+t+i,y2:this._y+t+5+i,strokeColor:this._strokeColor});_.push(p);let f=s.mark("text",{fillColor:this._textColor,text:l===h.Date?o.raw(n,c):c,x:this._x+d*e,y:this._y+t+5+i,anchor:["center","top"]});u.push(f)}))}o.styles.fillColor=a,this.addChild(o);for(let e of u)this.addChild(e);for(let e of _)this.addChild(e)}}class Pi extends Qt{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?ti:ii,this._titleText="title"in r?r.title:this._attribute,this._path="angle"===this._channel?new Dt({strokeColor:this._strokeColor,id:this._id+"_path"}):new Ct({strokeColor:this._strokeColor,id:this._id+"_path"}),this._pathVisible||(this._path.visibility="hidden"),this.addChild(this._path),this.createTicksLabels(r),A(this._elems[0].dataScope).type(this._attribute)!==h.Date||"labelFormat"in r||(this._labelFormat="%m/%d/%y")}get elements(){if(this.layout.type===me.CLUSTER){const e=new Map(this._elems.map(e=>[e.datum[X],e]));return this.layout._d3Root.leaves().map(t=>e.get(t.data[X]))}return this._elems}get layout(){return this._elems[0].parent.layout}createTicksLabels(e){"tickValues"in e?(this._tickValues=e.tickValues,this._labelValues=e.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 Ct({strokeColor:this._strokeColor,id:this._id+"_tick"+e});this._tickVisible||(t.visibility="hidden"),this._ticks.addChild(t)}let t;switch(this._labels.removeAll(),A(this._elems[0].dataScope).type(this._labelAttribute?this._labelAttribute:this._attribute)){case h.Date:t=r.timeFormat(this._labelFormat);break;case h.String:t=function(e){return e};break;default:t=r.format(this._labelFormat)}for(let[e,i]of this._labelValues.entries()){let r=new Ut({text:t(i),fontSize:this._fontSize,fillColor:this._textColor,id:this._id+"_label"+e});this._labels.addChild(r)}this._title._text=this._titleText}}class Vi extends lt{constructor(e){super(),this._type=n.Composite,this._id=e&&e.id?e.id:this._type+o()}addChild(e){let t=e.parent;super.addChild(e);let i=Pe(e)._depGraph;t&&Ze(t,e,i),$e(this,e,i)}}function Bi(e,t){let i;switch(t.type){case"collection":i=Mi(t);break;case"glyph":i=function(e){let t=new dt(e);return t}(t);break;case"axis":i=function(e){if("encoding"===e.axisType){return new si(e.enc,e.scale,e.elems,e)}if("layout"===e.axisType){return new Pi(e.elems,e.channel,e.attribute,e)}}(t);break;case"legend":i=function(e){let t="string"===e.attrType?new Ni(e.enc,e):new Li(e.enc,e);return t}(t);break;case"composite":i=function(e){let t=new Vi(e);return t}(t);break;default:i=Di(t)}return e.addChild(i),e._itemMap[i.id]=i,i}function Di(e){let t=null;switch(e.type){case n.Circle:t=new Dt(e);break;case n.Line:var i="x1"in e?e.x1:0,r="y1"in e?e.y1:0,s="x2"in e?e.x2:100,a="y2"in e?e.y2:100;e.vertices=[[i,r],[s,a]],t=new zt(e);break;case n.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 Ht(e);break;case n.SimpleText:t=new Ut(e);break;case n.RichText:t=new qt(e);break;case n.Image:t=new Mt(e);break;case n.Symbol:t=new Gt(e);break;case n.BundledPath:case n.Chord:case n.Path:t=new Ct(e);break;case n.Arrow:t=new Wt(e);break;case n.Area:t=new Vt(e);break;case n.Ring:t=new Xt(e);break;case n.Arc:t=new Ot(e);break;case n.BezierCurve:"vertices"in e||(e.vertices=[[0,100],[20,120],[80,180],[100,200]]),t=new Bt(e);break;case n.Polygon:t=new Yt(e)}return t&&t._updateBounds(),t}function Mi(e){return new ct(e)}function Gi(e){switch(e.type){case n.Collection:return function(e){let t=Mi({});for(let i=0;i<e.children.length;i++){let r=e.children[i];t.addChild(Gi(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 n.Glyph:return function(e){let t=new dt;for(let i of e.children)t.addChild(Gi(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=Di({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 zi extends we{constructor(e,t){super(e),this._elem=t}get element(){return this._elem}}class ji extends we{constructor(e,t){super(e),this._item=t}get element(){return this._item}}class Fi{constructor(e){this._id=e+"_"+o(),this._type=e,this._vars=[],this._edges=[]}get vars(){return this._vars}get edges(){return this._edges}run(){console.log("-",this._type)}}class Wi{constructor(e,t,i=!0){this._id="e_"+o(),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 xe||this._fromNode instanceof Fi?this._fromNode:this._toNode}}class Ui extends we{constructor(e,t){super(e),this._encs={},this._encs[t.channel+"_"+_i(t.element)]=t,this._initialized=!1}addLinkedEncoding(e){this._encs[e.channel+"_"+_i(e.element)]=e}getEncoding(e,t){let i=e+"_"+_i(t);return this._encs[i]}get encodings(){return Object.values(this._encs)}get initialized(){return this._initialized}set initialized(e){this._initialized=e}}class Yi extends we{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 Hi(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 Xi extends xe{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof Yi),t=this.outputVar,i=t.encodings,r=i[0],s=r.channel,a=r.attribute,o=e.encodings[0].dataTable.type(e.encodings[0].attribute),l=Object.values(e.attrValues);if("angle"===r.channel&&[n.Arc,n.Pie].indexOf(r.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=r._preferredDomain?r._preferredDomain:t.dataTable.tree?[0,t.dataTable.tree.getRoot()[a]]:this._getDomainForNumbers(i),console.log("domain for",a,e.domain)}else{let t;t=r._preferredDomain?r._preferredDomain:o==h.String||"text"===e.encodings[0].channel?this._getDomainForStrings(l):this._getDomainForNumbers(l);for(let i of e.encodings)for(let e of i.scales)e.domain=t.slice()}for(let e=0;e<r.scales.length;e++){let n=r.scales[e],a=r.getElements(n),o=this._buildRange(s,a,r,t);if(o)for(let t of i)t.scales[e].range=o}t.initialized=!0}_getDomainForNumbers(e){let t=this.outputVar.encodings[0],i=[r.min(e),r.max(e)];if(t.includeZero&&i[0]>0&&(i=[0,r.max(e)]),t.mapping)i=Object.keys(t.mapping),i=i.map(e=>parseFloat(e)),i.sort((e,t)=>e-t);else if("sequentialColor"===t.scales[0].type){if(i[0]<0&&i[1]>0){let e=Math.max(Math.abs(i[0]),Math.abs(i[1]));i=[-e,e]}}else if("angle"===t.channel){i=[0,Object.values(e).reduce((e,t)=>e+t,0)]}return i}_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(e,t){if(t.mapping){return t.scales[0].domain.map(e=>t.mapping[e+""])}if("sequentialColor"===t.scales[0].type){let e=this.outputVar,i=t.scales[0].domain;for(let s of e.encodings)if(!t.colorScheme)for(let e of s.scales){let t=e.domain;e._scale=r.scaleSequential(i[0]<0&&i[1]>0?r.interpolatePuOr:r.interpolateTurbo),e._scale.domain(t)}}if((oi.indexOf(t.colorScheme)>=0||li.indexOf(t.colorScheme)>=0)&&"ordinalColor"===t.scales[0].type){let e=this.outputVar,i=t.scales[0].domain;for(let s of e.encodings)for(let e of s.scales){let s=e.domain;e._scale=r.scaleOrdinal(r[t.colorScheme][i.length]),e._scale.domain(s)}}}_buildSizeRange(e,t,i){let r,s;if(r=0,"vertexIndices"===e.type){let r=ke(e.groups[0].parent,e.groups[0].indices[0]);return s=i.initialized?t._elem2scale[r].rangeExtent:t._preferredRangeExtent?t._preferredRangeExtent:Math.max(...this._getVertexIndexSizeValues(e,t.channel)),[0,0+s]}return s=i.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?Hi(e.parent):"area"===t.channel?e.type===n.Circle?Math.PI*Math.pow(e.radius,2):e.width*e.height:"fontSize"===t.channel?parseFloat(e.fontSize):e.refBounds[t.channel])),[0,0+s]}_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?Hi(r.parent):"width"===t?e._widths[s]:"height"===t?e._heights[s]:0)}return i}_buildXRange(e,t,i){let s,n,a=t.scales[0].type;if("vertexIndices"===e.type){let a=e.groups[0].parent,o=ke(a,e.groups[0].indices[0]),l=a.refBounds?a.refBounds:a.bounds;return s=i.initialized?r.min(t._elem2scale[o].range):l.left,n=i.initialized?t._elem2scale[o].rangeExtent:t._preferredRangeExtent?t._preferredRangeExtent:l.width,t.flipScale?[s+n,s]:[s,s+n]}switch(e[0].type){case"vertex":case"segment":var o=e[0].parent.refBounds?e[0].parent.refBounds:e[0].parent.bounds;s=i.initialized?t.getRangeStart(e[0]):o.left,n=i.initialized?t.getRangeExtent(e[0]):t._preferredRangeExtent?t._preferredRangeExtent:o.width;break;default:s=i.initialized?t.getRangeStart(e[0]):t._preferredRangeStart?t._preferredRangeStart:Ve(e[0]).bounds.left+e[0].bounds.width/2,n="band"===a?e[0].bounds.width*t.scales[0].domain.length:i.initialized?t.getRangeExtent(e[0]):t._preferredRangeExtent?t._preferredRangeExtent:r.max([450,r.max(e.map(e=>e.bounds.x))-r.min(e.map(e=>e.bounds.x))])}return t.flipScale?[s+n,s]:[s,s+n]}_buildYRange(e,t,i){let s,n;if(t.scales[0].type,"vertexIndices"===e.type){let a=e.groups[0].parent,o=ke(a,e.groups[0].indices[0]),l=a.refBounds?a.refBounds:a.bounds;return s=i.initialized?r.min(t._elem2scale[o].range):l.top,n=i.initialized?t._elem2scale[o].rangeExtent:t._preferredRangeExtent?t._preferredRangeExtent:l.height,t.flipScale?[s,s+n]:[s+n,s]}switch(e[0].type){case"vertex":case"segment":var a=e[0].parent.refBounds?e[0].parent.refBounds:e[0].parent.bounds;s=i.initialized?t.getRangeStart(e[0]):a.top,n=i.initialized?t.getRangeExtent(e[0]):t._preferredRangeExtent?t._preferredRangeExtent:a.height;break;default:s=i.initialized?t.getRangeStart(e[0]):Ve(e[0]).bounds.top+e[0].bounds.height/2,n=i.initialized?t.getRangeExtent(e[0]):t._preferredRangeExtent?t._preferredRangeExtent:450}return t.flipScale?[s,s+n]:[s+n,s]}}class qi extends xe{constructor(e){super(e)}run(){super.run()}}class Ki extends xe{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof ze&&e.property==We.AXIS_ORIENTATION).element;e.createTicksLabels(e._args),e instanceof si?this._runForEncoding(e):e instanceof Pi&&this._runForLayout(e),de(e._path)}_runForLayout(e){let t=e.channel,i=e.elements[0].parent.layout&&e.elements[0].parent.layout.type==me.STACK?ce(e.elements):he(e.elements),r=[];if("x"===t){let t=e.orientation===ei?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===ii?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===me.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==me.STACK?ce(i):he(i),s=[],n=Ve(i[0]);if(n&&n.clipMask&&(r=n.clipMask),"x"===t){let t,n,a=ui(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===ei?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===ei?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=ui(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===ii?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===ii?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 Zi extends xe{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof ze&&e.property==We.AXIS_PATH_POSITION).element;e instanceof si?this._runForEncoding(e):e instanceof Pi&&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();de(e._ticks)}_runForLayout(e){let t=e.channel;if("x"==t){let t=e.orientation==ti?e._pathPos+e.tickOffset:e._pathPos-e.tickOffset,i=e.orientation==ti?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==ii?e._pathPos-e.tickOffset:e._pathPos+e.tickOffset,i=e.orientation==ii?-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===me.CLUSTER){let i=t._d3Root.leaves();const r=new Map(i.map(e=>[e.data[X],[e.x,e.y]]));for(let[i,s]of e._ticks.children.entries()){let n=e.elements[i].datum[X],a=Nt(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,i=he(e.elements);if("x"==t){let t=e.orientation==ti?e._pathPos+e.tickOffset:e._pathPos-e.tickOffset,i=e.orientation==ti?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==ti?e._pathPos+e.tickOffset:e._pathPos-e.tickOffset,r=e.orientation==ti?e.tickSize:-e.tickSize;if(!!(e.isFlipped()||e.elements[0].type===n.Area&&"right"===e.elements[0].baseline))for(let[s,n]of e._ticks.children.entries())n.vertices=[[i.left+e.scale.rangeExtent-e.scale.map(e._tickValues[s]),t],[i.left+e.scale.rangeExtent-e.scale.map(e._tickValues[s]),t+r]];else for(let[s,n]of e._ticks.children.entries())n.vertices=[[e.scale.map(e._tickValues[s])+i.left,t],[e.scale.map(e._tickValues[s])+i.left,t+r]]}else if("y"===t){let t=e.orientation==ii?e._pathPos-e.tickOffset:e._pathPos+e.tickOffset,i=e.orientation==ii?-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==ii?e._pathPos-e.tickOffset:e._pathPos+e.tickOffset,r=e.orientation==ii?-e.tickSize:e.tickSize;if(!!(e.isFlipped()||e.elements[0].type===n.Area&&"top"===e.elements[0].baseline))for(let[s,n]of e._ticks.children.entries())n.vertices=[[t,i.top+e.scale.map(e._tickValues[s])],[t+r,i.top+e.scale.map(e._tickValues[s])]];else for(let[s,n]of e._ticks.children.entries()){let a=i.bottom-e.scale.map(e._tickValues[s]);n.vertices=[[t,a],[t+r,a]]}}else if("polarRadius"===t){let t=e.orientation==ti?e._pathPos+e.tickOffset:e._pathPos-e.tickOffset,i=e.orientation==ti?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 $i extends xe{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof ze&&e.property==We.AXIS_PATH_POSITION).element;e instanceof si?this._runForEncoding(e):e instanceof Pi&&this._runForLayout(e);for(let t of e._labels.children)t._updateBounds();de(e._labels)}_runForLayout(e){let t=e.channel;if("x"==t){let t=e.orientation==ti?e.labelOffset:-e.labelOffset,i=e.orientation==ti?[ue.CENTER,ue.TOP]:[ue.CENTER,ue.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=[ue.RIGHT,ue.MIDDLE])}}else if("y"===t){let t=e.orientation==ii?-e.labelOffset:e.labelOffset,i=e.orientation==ii?[ue.RIGHT,ue.MIDDLE]:[ue.LEFT,ue.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==ue.MIDDLE?n.y:n[e.tickAnchor],s._anchor=i,e._labelRotation&&(s._rotate=[e._labelRotation,s.x,s.y],s._anchor=[ue.RIGHT,i[1]])}}else if("angle"===t){let t=e.elements[0].parent.layout;if(t.type===me.CLUSTER){let i=t._d3Root.leaves();const r=new Map(i.map(e=>[e.data[X],[e.x,e.y]]));let s=5;for(let[i,n]of e._labels.children.entries()){let a=e.elements[i].datum[X];if(r.get(a)[0]<Math.PI){let o=Nt(r.get(a)[0])-90;n._anchor=[ue.LEFT,ue.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=Nt(r.get(a)[0])+90;n._anchor=[ue.RIGHT,ue.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,i=he(e.elements);if("x"==t){let t=e.orientation==ti?e.labelOffset:-e.labelOffset,i=e.orientation==ti?[ue.CENTER,ue.TOP]:[ue.CENTER,ue.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=[ue.RIGHT,i[1]])}else if("width"===t){let t=e.orientation==ti?e.labelOffset:-e.labelOffset,r=e.orientation==ti?[ue.CENTER,ue.TOP]:[ue.CENTER,ue.BOTTOM],s=!!(e.isFlipped()||e.elements[0].type===n.Area&&"right"===e.elements[0].baseline);for(let[n,a]of e._labels.children.entries())a.x=s?i.left+e.scale.rangeExtent-e.scale.map(e.labelValues[n]):e.scale.map(e.labelValues[n])+i.left,a._y=e._pathPos+t,a._anchor=r,e._labelRotation&&(a._rotate=[e._labelRotation,a.x,a.y],a._anchor=[ue.RIGHT,r[1]])}else if("y"===t){let t=e.orientation==ii?-e.labelOffset:e.labelOffset,i=e.orientation==ii?[ue.RIGHT,ue.MIDDLE]:[ue.LEFT,ue.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=[ue.RIGHT,i[1]])}else if("height"===t){let t=e.orientation==ii?-e.labelOffset:e.labelOffset,r=e.orientation==ii?[ue.RIGHT,ue.MIDDLE]:[ue.LEFT,ue.MIDDLE],s=e.elements[0].type===n.Area&&"top"===e.elements[0].baseline;for(let[n,a]of e._labels.children.entries())a.x=e._pathPos+t,a._y=s?i.top+e.scale.map(e.labelValues[n]):i.bottom-e.scale.map(e.labelValues[n]),a._anchor=r,e._labelRotation&&(a._rotate=[e._labelRotation,a.x,a.y],a._anchor=[ue.RIGHT,r[1]])}else if("polarRadius"==t){let t=e.orientation==ti?e.labelOffset:-e.labelOffset,i=e.orientation==ti?[ue.CENTER,ue.TOP]:[ue.CENTER,ue.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=[ue.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=[ue.CENTER,ue.MIDDLE],e._labelRotation&&(n._rotate=[e._labelRotation,n.x,n.y])}}}}function Ji(e,t){let i=e.getElements(t);return i&&"vertexIndices"===i.type?i.groups[0].parent:i[0]}class Qi extends xe{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=Ce(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=Be(e,!0);for(let e of i)de(e)}placeElements(e,t,i){let r=pi(e,"x"),s=pi(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 ue.LEFT:n=s.left-r.refBounds.left;break;case ue.CENTER:n=s.x-r.refBounds.x;break;case ue.RIGHT:n=s.right-r.refBounds.right}switch(t._cellVertAlignment){case ue.TOP:a=s.top-r.refBounds.top;break;case ue.MIDDLE:a=s.y-r.refBounds.y;break;case ue.BOTTOM:a=s.bottom-r.refBounds.bottom}xi(r,n,a)}if(r.length>0)for(let e of r)for(let i of e.scales){let r=Ji(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=Ji(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 ut.RowFirst:r=Math.floor(a/s),o=a%s;break;case ut.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 oe(o,c,l,h)}}}function er(e,t,i,r){return[i*Math.cos(It(r))+e,t-i*Math.sin(It(r))]}function tr(e){if([n.Line,n.Circle,n.Rect,n.Area].indexOf(e.type)<0)return!1;if(e.dataScope){let t=Ce(e,e.scene);for(let e of t)if(R(e.dataScope)>1)return!0;return!1}return!0}function ir(e,t,i,r){switch(t){case"x":sr(e,i);break;case"y":nr(e,i);break;case"width":!function(e,t){e.resize(t,e.height)}(e,i);break;case"height":!function(e,t){e.resize(e.width,t)}(e,i);break;case"radius":e.radius=i;break;case"strength":e._strength=i;break;case"area":e.type===n.Circle?e.radius=Math.sqrt(i/Math.PI):e.type===n.Rect&&e.resize(Math.sqrt(i),Math.sqrt(i)),e._updateBounds();break;case"text":e._text=i;break;case"curveMode":e.curveMode=i;break;case"baseline":e.baseline=i;break;case"angle":[n.Arc,n.Pie].includes(e.type)&&function(e,t){e._endAngle=Lt(e._startAngle+t),e._sr=It(e._startAngle),e._er=It(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,i);break;case"startAngle":!function(e,t){let i=e.angle;e._startAngle=t,e._endAngle=Lt(e._startAngle+i),e._sr=It(e._startAngle),e._er=It(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,i);break;case"thickness":!function(e,t){rr(e,e._innerRadius+t)}(e,i);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,i);break;case"outerRadius":rr(e,i);break;case"polarAngle":
|
|
1
|
+
/* version: 4.4.1 */
|
|
2
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("d3")):"function"==typeof define&&define.amd?define(["exports","d3"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).msc={},e.d3)}(this,function(e,t){"use strict";function i(e){var t=Object.create(null);return e&&Object.keys(e).forEach(function(i){if("default"!==i){var r=Object.getOwnPropertyDescriptor(e,i);Object.defineProperty(t,i,r.get?r:{enumerable:!0,get:function(){return e[i]}})}}),t.default=e,Object.freeze(t)}var r=i(t);const s=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"}),n=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"}),a=Object.freeze({Axis:"axis",Legend:"legend",Gridlines:"gridlines",Trajectory:"trajectory"});function o(){return Date.now().toString(36)+"_"+Math.random().toString(36).slice(2)}function l(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 h=Object.freeze({Boolean:"boolean",Integer:"integer",Number:"number",Date:"date",String:"string"});function c(e){var t=Object.values(h);for(let i=0;i<e.length;i++){let r=e[i];if(null!=r){for(let e=0;e<t.length;e++)d[t[e]](r)||(t.splice(e,1),e-=1);if(1==t.length)return t[0]}}return t[0]}const d={boolean:function(e){return"true"===e||"false"===e||!0===e||!1===e||"[object Boolean]"==toString.call(e)},integer:function(e){return d.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 u(e,t){let i={};switch(t){case h.Boolean:i.trueCount=e.filter(e=>e).length,i.falseCount=e.filter(e=>!e).length;break;case h.Date:i.min=r.min(e),i.max=r.max(e),i.extent=[i.min,i.max],i.unique=[...new Set(e)];break;case h.String:i.unique=[...new Set(e)];break;default:i.min=r.min(e),i.max=r.max(e),i.extent=[i.min,i.max],i.mean=r.mean(e),i.median=r.median(e),i.unique=[...new Set(e)]}return i}const _="max",p="min",f="avg",g="mean",y="median",m="count",b="percentile 25",x="percentile 75";function v(e,t={},i){return{dataTable:e,filters:Object.assign({},t),rowIds:i?i.slice():void 0}}function w(e){if(e)return v(e.dataTable,e.filters,e.rowIds)}function E(e){return w(e)}function A(e){if(e)return e.dataTable}function C(e){return e&&e.filters||{}}function S(e){return e?e.rowIds&&e.dataTable?e.dataTable.rows({[j]:e.rowIds}):e.dataTable?e.dataTable.rows(e.filters):[]:[]}function R(e){let t=S(e);return t.length>0?t[0]:{}}function k(e){return S(e).length}function T(e,t){return t in C(e)}function O(e,t){let i=C(e);if(t in i)return i[t];let r=S(e);return r.length>0?r[0][t]:void 0}function I(e,t){let i=C(e);return t in i?[i[t]]:Array.from(new Set(S(e).map(e=>e[t])))}function N(e,t,i){let s=S(e).map(e=>e[t]);switch(i){case _:return r.max(s);case p:return r.min(s);case f:case g:return r.mean(s);case y:return r.median(s);case m:return s.length;case b:return r.quantile(s,.25);case x:return r.quantile(s,.75);default:return r.sum(s)}}function L(e,t,i){let r=A(e),s=Object.assign({},C(e),{[t]:i});return v(r,s,M(r,s))}function P(e,t){if(!e)return E(t);if(!t)return E(e);let i=A(e),r=Object.assign({},C(e));for(let[e,i]of Object.entries(C(t)))e in r&&r[e]!==i?console.warn("Conflict in attribute values when merging dataScope:",e,r[e],i):r[e]=i;return v(i,r,M(i,r))}function V(e){return v(e,{},e.data.map(e=>e[j]))}function B(e,t,i=!1){let r=A(e),s=C(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(v(r,Object.assign({},s,{[t]:e}),l.map(e=>e[j])))}return o}function M(e,t){return e.rows(t).map(e=>e[j])}class D{constructor(e,t,i){this._id=n.DataTable+o(),this.initialize(e,t,i)}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]=c(this.data.map(t=>t[e])),"year"==e.toLowerCase()&&this._attrTypes[e]==h.Integer&&(this._attrTypes[e]=h.Date)}this._validate(this.data,this._attrTypes),this._attrSummaries={};for(let e of this._attributes)this._attrSummaries[e]=u(this.data.map(t=>t[e]),this._attrTypes[e]);this._attributes.indexOf(j)<0&&this.addAttr(j,h.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 D(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!==j&&this._rawData.forEach((t,r)=>t[e]=i[r]),this._attrTypes[e]=t,this._attributes.includes(e)||this._attributes.push(e),this._attrSummaries[e]=u(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]===j&&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)||G(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(G(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[j],e)}_getFilterKey(e={}){return Object.entries(e).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>G(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(e,t){let i=r.timeParse(t);for(let t of this.data){let r=t[e];null==r||null==r?(r="",t[e]=new Date(1899,11,31).getTime()):t[e]=i(r).getTime(),this._dateMap.set(t[e],r)}this._attrTypes[e]=h.Date,this._attrSummaries[e]=u(this.data.map(t=>t[e]),h.Date),this._clearDataCaches()}raw(e,t){return this.type(e)===h.Date?this._dateMap.get(t).toString():t}get dimensions(){let e=[];for(let t in this._attrTypes)this._attrTypes[t]!=h.Number&&this._attrTypes[t]!=h.Integer&&t!=D.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]!==h.Number&&this._attrTypes[t]!==h.Integer||t==D.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!=D.RowID&&t.push(i);return t}summarize(){for(let e of this._attributes)this._attrSummaries[e]=u(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 h.Boolean:r=!1;break;case h.Date:r=new Date(1899,11,31).getTime();break;case h.String:r="";break;default:r=0}else switch(s){case h.Boolean:r=n;break;case h.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 h.String:r=n.toString();break;default:r=n}i[e]=r}}}function G(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)&&("min"in e||"max"in e)}function z(e){return e.dataScope?A(e.dataScope):e.parent&&e.parent.dataScope?A(e.parent.dataScope):void 0}const j="mascot_rowId";class F{constructor(e,t){this._id=n.TreeData+o(),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 D(this._nodeList,"nodes"),this._linkTable=new D(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={};X in e||(e[X]="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[X],child:n})}else s[n]=e[n];return this._nodeHash[s[X]]=s,s[X]}getNodeDataScopeRef(e){return L(V(this._nodeTable),j,e[j])}getNode(e){return this._nodeHash[e]}getRoot(){return this._nodeTable.data[0]}getChildren(e){let t=e[X],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[X]==t);i.push(s[n])}return i}getParent(e){let t=e[X],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[X]==t);return r[s]}}}function W(e){return A(e.dataScope).tree}class U{constructor(e,t){this._id=n.NetworkData+o(),this.initialize(e,t)}initialize(e,t){this.url=t,this._nodeTable=new D(e.nodes,this._id+"_nodes"),this._linkTable=new D(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[X]]=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[X],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[X]="root",H(t,this._rawNodes,e),new F(t,this.url)}}function Y(e){return A(e.dataScope).graph}function H(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[X]=t,e.children.push(i)}else for(let t in r){let s={};s[X]=t,e.children.push(s),H(s,r[t],i.slice(1))}}const X="id";function q(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 K{constructor(e,t,i){this._id="predicate_"+o(),this._type=e||Z.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 Z=Object.freeze({POINT:"point",INTERVAL:"interval",LIST:"list"});class $ extends K{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 J extends K{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 Q extends K{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 ee(e){let t,i="attribute"in e?"attribute":"property",r=e[i];switch(e.type){case Z.LIST:t=new J(e.type,i,r);break;case Z.INTERVAL:t=new $(e.type,i,r);break;case Z.POINT:default:t=new Q(e.type,i,r)}return t.value=e.value,t}function te(e,t){for(let i of t)if(!i.testElement(e))return!1;return!0}const ie={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 re(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 se(e,t,i,r){return Math.sqrt(Math.pow(e-i,2)+Math.pow(t-r,2))}function ne(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 ae=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 oe{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 oe(t,i,r-t,s-i)}clone(){return new oe(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 ue.RIGHT:this._x=this.right-e/2;break;case ue.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 ue.TOP:this._y=this.top+e/2;break;case ue.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 le(e){let t=e[0].clone();for(let i=1;i<e.length;i++)t=t.union(e[i]);return t}function he(e){return le(("vertex"==e[0].type||"segment"==e[0].type?e.map(e=>e.parent):e).map(e=>e.refBounds?e.refBounds:e.bounds))}function ce(e){return le(("vertex"==e[0].type||"segment"==e[0].type?e.map(e=>e.parent):e).map(e=>e.bounds))}function de(e){let t=Ce(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)de(e)}const ue=Object.freeze({TOP:"top",LEFT:"left",RIGHT:"right",BOTTOM:"bottom",CENTER:"center",MIDDLE:"middle"});class _e{constructor(e){if(this._dataScopeRef=void 0,this._type="type"in e?e.type:n.Mark,this._id=e.id?e.id:this._type+"_"+o(),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 ae)t in e&&(this.styles[t]=e[t])}get scene(){return Pe(this)}get datum(){return R(this._dataScopeRef)}get data(){return S(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=w(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=E(this._dataScopeRef))}createClipMask(){let e=this._bounds;this._clipMask=new oe(e.left,e.top,e.width,e.height)}get clipMask(){return this._clipMask}}function pe(e){return e instanceof _e&&e.type!==n.Gridlines}const fe=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 ge{constructor(){this._refElements=[]}addRefElement(e){this._refElements.push(e)}get refElements(){return this._refElements}clearRefElements(){this._refElements=[]}}function ye(e){return e instanceof ge}const me=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 be(e,t){return!!(e.startsWith("h")&&[ue.LEFT,ue.CENTER,ue.RIGHT].indexOf(t)>=0)||(!!(e.startsWith("v")&&[ue.TOP,ue.MIDDLE,ue.BOTTOM].indexOf(t)>=0)||(console.warn("Invalid alignment:",t),!1))}class xe{constructor(e){this._id=e+"_"+o(),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 ve=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 we{constructor(e){this._id="v_"+o(),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 xe)return e.fromNode;return null}isIsolated(){return 0==this._incomings.length&&0==this._outgoings.length}}const Ee=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 Ae 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(Ee.STATE,e,this),this._scene.onChange(Ee.STATE,e,this)),this}}function Ce(e,t){let i=Pe(e);return"vertex"===e.type||"segment"===e.type?function(e,t){let i=Pe(e),r=t||i;if("vertex"===e.type){return Se(e,Oe(r,[{property:"classId",value:e.parent.classId}],!0))}if("segment"===e.type){return Te(e,Oe(r,[{property:"classId",value:e.parent.classId}],!0))}return e.classId?Oe(r,[{property:"classId",value:e.classId}]):[e]}(e,t):e.classId?Oe(t||i,[{property:"classId",value:e.classId}]):[e]}function Se(e,t){if(!e.classId){if(e.dataScope){let i=e.parent;if(!i)throw new Error("vertex has no parent mark");let r=[];if(i.type!==n.Area||e._isAnyVertex)for(let e of t)r=r.concat(e.vertices.filter(e=>e.dataScope));else{let s=i.vertices.indexOf(e)<i.vertices.length/2;for(let e of t){let t=s?e.vertices.slice(0,e.vertices.length/2):e.vertices.slice(e.vertices.length/2);r=r.concat(t.filter(e=>e.dataScope))}}return r}{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 Re(e,t){return e.id+"_v_"+e._vertices._ids[t]}function ke(e,t){let i=e.parent,r=e._index,s=[];if(e.dataScope)if(i.type!==n.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);s.push({parent:e,indices:t})}else{let e=r<i._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,n=[];for(let e=t;e<r;e++)i._vertices.hasDataScope(e)&&n.push(e);s.push({parent:i,indices:n})}}else for(let e of t)s.push({parent:e,indices:[r]});return s}function Te(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 Oe(e,t,i){let r=[];return Le(e,t?t.map(e=>ee(e)):[],r,i),r}function Ie(e,t){let i=e.children.filter(e=>e.type==n.Collection);if(0!==i.length)for(let e of i){let i=e;for(;i&&i.dataScope;){if(T(i.dataScope,t))return i;i=i.children?i.children[0]:void 0}}}function Ne(e){return e.type==n.Collection?e:e.parent?Ne(e.parent):void 0}function Le(e,t,i,r){if(e)if(te(e,t)&&i.push(e),e.vertices&&r)for(let r of e.vertices.concat(e.segments))te(r,t)&&i.push(r);else if(e.children&&e.children.length>0)for(let s of e.children)Le(s,t,i,r)}function Pe(e){let t;if(t=Array.isArray(e)?e[0]:e,t){if(t instanceof Ae)return t.scene;if(t._scene)return t._scene;for(ye(t)&&t.group&&(t=t.group),t.id.startsWith("encoding_")&&(t=t.element);t;){if(t.type==n.Scene)return t;t=t.parent}}}function Ve(e){let t=e;for("vertex"!=t.type&&"segment"!=t.type||(t=t.parent);t.parent&&[n.Collection,n.Glyph].includes(t.parent.type);)t=t.parent;return t}function Be(e,t){let i=[];if(Me(e,i),t){let e={};for(let t of i)e[t.classId]=t;return Object.values(e)}return i}function Me(e,t){if(pe(e))t.push(e);else if(e.children&&!Object.values(a).includes(e.type))for(let i of e.children)Me(i,t)}class De extends we{constructor(e,t,i){super(e),this._channel=t,this._elem=i}get channel(){return this._channel}get element(){return this._elem}}const Ge=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 ze extends we{constructor(e,t,i){super(e),this._property=t,this._elem=i}get property(){return this._property}get element(){return this._elem}}function je(e){return e in Fe?Fe[e]:e}const Fe=Object.freeze({numCols:"layoutParameter",numRows:"layoutParameter",startCorner:"layoutParameter",direction:"layoutParameter",params:"layoutParameter"}),We=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 Ue{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 Ye{constructor(e,t,i,r){this._id=e,this._event=i,this._source=t,this._evtCtx=new Ue,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 He=Symbol("msc.TRIGGER_ELEMENT");function Xe(e){let t=e?Pe(e):void 0;t&&t._clearInteractionCaches&&t._clearInteractionCaches()}function qe(e,t){if(Xe(e),t.findVariable(Ee.BOUNDS,[e]))return;let i=t.getVariable(Ee.BOUNDS,e),r=t.createOneWayDependency(ve.EVAL_BBOX);switch(t.connect(r,i),e.type){case n.Circle:case n.Polygon:{let i=t.getVariable(Ee.CHANNEL,"x",e),s=t.getVariable(Ee.CHANNEL,"y",e),n=t.getVariable(Ee.CHANNEL,"radius",e),a=t.getVariable(Ee.CHANNEL,"area",e);t.connect(n,r),t.connect(i,r),t.connect(s,r),t.connect(a,r);break}case n.Area:case n.Line:case n.BezierCurve:case n.Path:case n.Image:case n.Symbol:{let i=t.getVariable(Ee.CHANNEL,"x",e),s=t.getVariable(Ee.CHANNEL,"y",e),n=t.getVariable(Ee.CHANNEL,"width",e),a=t.getVariable(Ee.CHANNEL,"height",e);t.connect(i,r),t.connect(s,r),t.connect(n,r),t.connect(a,r);break}case n.Rect:{let i=t.getVariable(Ee.CHANNEL,"x",e),s=t.getVariable(Ee.CHANNEL,"y",e),n=t.getVariable(Ee.CHANNEL,"width",e),a=t.getVariable(Ee.CHANNEL,"height",e),o=t.getVariable(Ee.CHANNEL,"area",e);t.connect(i,r),t.connect(s,r),t.connect(n,r),t.connect(a,r),t.connect(o,r);break}case n.SimpleText:case n.RichText:{let i=t.getVariable(Ee.CHANNEL,"x",e),s=t.getVariable(Ee.CHANNEL,"y",e),n=t.getVariable(Ee.CHANNEL,"text",e);t.connect(i,r),t.connect(s,r),t.connect(n,r);break}case n.Ring:{let i=t.getVariable(Ee.CHANNEL,"x",e),s=t.getVariable(Ee.CHANNEL,"y",e),n=t.getVariable(Ee.CHANNEL,"innerRadius",e),a=t.getVariable(Ee.CHANNEL,"outerRadius",e);t.connect(i,r),t.connect(s,r),t.connect(n,r),t.connect(a,r);break}case n.Pie:case n.Arc:{let i=t.getVariable(Ee.CHANNEL,"x",e),s=t.getVariable(Ee.CHANNEL,"y",e),n=t.getVariable(Ee.CHANNEL,"innerRadius",e),a=t.getVariable(Ee.CHANNEL,"outerRadius",e),o=t.getVariable(Ee.CHANNEL,"startAngle",e),l=t.getVariable(Ee.CHANNEL,"endAngle",e),h=t.getVariable(Ee.CHANNEL,"angle",e),c=t.getVariable(Ee.CHANNEL,"thickness",e);t.connect(i,r),t.connect(s,r),t.connect(n,r),t.connect(a,r),t.connect(o,r),t.connect(l,r),t.connect(h,r),t.connect(c,r);break}}r.run()}function Ke(e,t){Xe(e);let i=t.findVariablesByElement(e);for(let e in i){let r=i[e];for(let e of r)t.deleteVariable(e)}}function Ze(e,t){if(e.type===n.Axis){let i=t.findVariable(Ee.PROPERTY,[We.AXIS_PATH_POSITION,e]).incomingDataflow;console.log(i,e),t.deleteOperator(i),i=t.findVariable(Ee.PROPERTY,[We.AXIS_TICKS_POSITION,e]).incomingDataflow,t.deleteOperator(i),i=t.findVariable(Ee.PROPERTY,[We.AXIS_LABELS_POSITION,e]).incomingDataflow,t.deleteOperator(i),i=t.findVariable(Ee.PROPERTY,[We.AXIS_TITLE_POSITION,e]).incomingDataflow,t.deleteOperator(i)}else if(e.type===n.Gridlines){let i=t.findVariable(Ee.PROPERTY,[We.GRIDLINES_POSITION,e]).incomingDataflow;t.deleteOperator(i)}}function $e(e,t){if(Xe(e),t.findVariable(Ee.BOUNDS,[e]))return;let i=t.getVariable(Ee.BOUNDS,e),r=t.getVariable(Ee.CHANNEL,"x",e),s=t.getVariable(Ee.CHANNEL,"y",e),n=t.getVariable(Ee.CHANNEL,"width",e),a=t.getVariable(Ee.CHANNEL,"height",e),o=t.createOneWayDependency(ve.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 Je(e,t){Xe(e);let i=t.getVariable(Ee.BOUNDS,e),r=t.getVariable(Ee.CHANNEL,"x",e),s=t.getVariable(Ee.CHANNEL,"y",e),n=t.getVariable(Ee.CHANNEL,"width",e),a=t.getVariable(Ee.CHANNEL,"height",e),o=t.createOneWayDependency(ve.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 Qe(e,t,i){Xe(e);let r=i.getVariable(Ee.BOUNDS,e),s=i.getVariable(Ee.BOUNDS,t),n=i.getIncomingDataflowOperator(ve.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(Ee.CHANNEL,"x",t),s=i.getIncomingDataflowOperator(it(e.layout.type),r);s&&i.deleteOperator(s)}}function et(e,t,i){Xe(e);let r=i.getVariable(Ee.BOUNDS,e),s=i.getVariable(Ee.BOUNDS,t),n=i.getIncomingDataflowOperator(ve.EVAL_BBOX,r);i.connect(s,n),i.connect(n,r),e.layout&&st(e,e.layout,i)}function tt(e,t){Xe(e);let i=t.getVariable(Ee.BOUNDS,e),r=t.getVariable(Ee.CHANNEL,"x",e),s=t.getVariable(Ee.CHANNEL,"y",e),n=t.getIncomingDataflowOperator(ve.EVAL_BBOX,i);t.connect(r,n),t.connect(s,n);for(let i of e.children)t.connect(t.getVariable(Ee.BOUNDS,i),n);t.connect(n,i),n.run()}function it(e){switch(e){case me.GRID:return ve.GRID_LAYOUT;case me.STACK:return ve.STACK_LAYOUT;case me.PACKING:return ve.PACK_LAYOUT;case me.FORCE:return ve.FORCE_LAYOUT;case me.DIRECTED:return ve.DIRECTED_LAYOUT;case me.TIDYTREE:return ve.TIDY_TREE_LAYOUT;case me.TREEMAP:return ve.TREEMAP_LAYOUT;case me.STRATA:return ve.STRATA_LAYOUT;case me.CIRCULAR:return ve.CIRCULAR_LAYOUT;case me.CLUSTER:return ve.CLUSTER_LAYOUT;case me.SPIRAL:return ve.SPIRAL_LAYOUT;case me.CUSTOM:return ve.CUSTOM_LAYOUT}}function rt(e,t,i){let r=i.getVariable(Ee.PROPERTY,We.CHILDREN_ORDER,e),s=i.getOutgoingDataflowOperator(it(t.type),r);i.deleteOperator(s)}function st(e,t,i){let r=t?t.type:"none",s=r===me.TREEMAP?Be(e)[0]:e.children[0];if(!s)return;let a=i.getVariable(Ee.CHANNEL,"width",s),o=i.getVariable(Ee.CHANNEL,"height",s),l=i.getVariable(Ee.PROPERTY,We.CHILDREN_ORDER,e),h=i.getVariable(Ee.CHANNEL,"x",s),c=i.getVariable(Ee.CHANNEL,"y",s),d=i.getVariable(Ee.CHANNEL,"visibility",s),u=i.getVariable(Ee.PROPERTY,We.LAYOUT_PARAMETER,t),_=i.getOutgoingDataflowOperator(it(r),l);if(i.connect(a,_),i.connect(o,_),i.connect(l,_),i.connect(u,_),i.connect(d,_),i.connect(_,h),i.connect(_,c),i.disconnectChannelVarFromBBoxOperator(a),i.disconnectChannelVarFromBBoxOperator(o),s.type===n.Arc||s.type===n.Pie){let e=i.getVariable(Ee.CHANNEL,"angle",s),t=i.getVariable(Ee.CHANNEL,"thickness",s);i.connect(e,_),i.connect(t,_)}else if(s.type===n.Circle){let e=i.getVariable(Ee.CHANNEL,"area",s),t=i.getVariable(Ee.CHANNEL,"radius",s);i.connect(e,_),i.connect(t,_),i.disconnectChannelVarFromBBoxOperator(e),i.disconnectChannelVarFromBBoxOperator(t)}else if(s.type===n.Rect){let e=i.getVariable(Ee.CHANNEL,"area",s);i.connect(e,_),i.disconnectChannelVarFromBBoxOperator(e)}if(_.run(),s.links&&nt(s,i),s.children&&s.children[0]){let e=i.getVariable(Ee.BOUNDS,s.children[0]),t=i.getVariable(Ee.CHANNEL,"x",s).incomingDataflow;t&&i.connect(e,t),i.disconnectChannelVarFromBBoxOperator(e)}}function nt(e,t){let i=e.links[0],r=t.getVariable(Ee.CHANNEL,"x",e),s=t.getVariable(Ee.CHANNEL,"x",i),n=t.getVariable(Ee.CHANNEL,"strokeWidth",i),a=t.getVariable(Ee.CHANNEL,"strength",i),o=t.createOneWayDependency(ve.LINK_PLACER);t.connect(r,o),t.connect(n,o),t.connect(a,o),t.connect(o,s)}function at(e,t,i){if(!e||"segment"!==e.type)return;let r=z(e),s=r?i.findVariable(Ee.ITEMS,[r]):null;if(s)for(let e of s.outgoingEdges)if(e.isDirected&&e.toNode.type===ve.REPOPULATE)return void i.connect(e.toNode,t)}function ot(e,t,i){let r=e.attribute,s=e.channel,a=e.element,o=t.createOneWayDependency(ve.ENCODER);if(["width","height"].includes(e.channel)&&a.type===n.Area){let e=t.getVariable(Ee.PROPERTY,We.BASE_LINE,a);t.connect(e,o)}if(i){let r=t.getVariable(Ee.ATTR_VALUE,i),n=t.getVariable(Ee.SCALE,i),l=t.getVariable(Ee.CHANNEL,s,a);t.connect(n,o),t.connect(o,l),r.addLinkedEncoding(e),n.addLinkedEncoding(e);let h=t.getVariable(Ee.DATASCOPE,e.element),c=r.incomingDataflow;c&&h&&(t.connect(h,c),at(e.element,h,t)),r.incomingDataflow.run()}else{let i=t.getVariable(Ee.ATTRIBUTE,r,z(a),e),n=t.getVariable(Ee.PROPERTY,We.INCLUDE_ZERO,e),l=t.getVariable(Ee.ATTR_VALUE,e),h=t.getVariable(Ee.DATASCOPE,a),c=t.createOneWayDependency(ve.DATA_EXTRACTOR);t.connect(i,c),t.connect(n,c),t.connect(h,c),t.connect(c,l),at(a,h,t),c.run();let d=t.getVariable(Ee.PROPERTY,We.RANGE_START,e),u=t.getVariable(Ee.PROPERTY,We.RANGE_EXTENT,e),_=t.getVariable(Ee.PROPERTY,We.FLIP_SCALE,e),p=t.getVariable(Ee.SCALE,e),f=t.createOneWayDependency(ve.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(Ee.CHANNEL,s,a);t.connect(p,o),t.connect(o,g),o.run()}}function lt(e,t){let i=t.getVariable(Ee.PROPERTY,We.AXIS_ORIENTATION,e),r=t.getVariable(Ee.BOUNDS,e.elements[0].parent),s=t.getVariable(Ee.PROPERTY,We.AXIS_PATH_POSITION,e),n=t.createOneWayDependency(ve.AXIS_PATH_PLACER);t.connect(i,n),t.connect(r,n),t.connect(n,s),n.run();let a=t.getVariable(Ee.PROPERTY,We.AXIS_TICK_OFFSET,e),o=t.getVariable(Ee.PROPERTY,We.AXIS_TICK_SIZE,e),l=t.createOneWayDependency(ve.AXIS_TICKS_PLACER),h=t.getVariable(Ee.PROPERTY,We.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(Ee.PROPERTY,We.AXIS_LABEL_OFFSET,e),d=t.getVariable(Ee.PROPERTY,We.AXIS_LABEL_FORMAT,e),u=t.getVariable(Ee.PROPERTY,We.AXIS_FONT_SIZE,e),_=t.createOneWayDependency(ve.AXIS_LABELS_PLACER),p=t.getVariable(Ee.PROPERTY,We.AXIS_LABELS_POSITION,e);t.connect(s,_),t.connect(c,_),t.connect(d,_),t.connect(u,_),t.connect(_,p),_.run();let f=t.getVariable(Ee.PROPERTY,We.AXIS_TITLE_POSITION,e),g=t.createOneWayDependency(ve.AXIS_TITLE_PLACER);t.connect(s,g),t.connect(g,f),g.run();let y=t.getVariable(Ee.BOUNDS,e),m=t.getIncomingDataflowOperator(ve.EVAL_BBOX,y);t.connect(h,m),t.connect(p,m),t.connect(m,y)}function ht(e,t){let i=t.getVariable(Ee.PROPERTY,We.AXIS_ORIENTATION,e),r=t.getVariable(Ee.BOUNDS,Ve(e.elements[0])),s=t.getVariable(Ee.PROPERTY,We.AXIS_PATH_POSITION,e),n=t.createOneWayDependency(ve.AXIS_PATH_PLACER);t.connect(i,n),t.connect(r,n),t.connect(n,s),n.run();let a=t.getVariable(Ee.PROPERTY,We.AXIS_TICK_OFFSET,e),o=t.getVariable(Ee.PROPERTY,We.AXIS_TICK_SIZE,e),l=t.createOneWayDependency(ve.AXIS_TICKS_PLACER),h=t.getVariable(Ee.PROPERTY,We.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(Ee.PROPERTY,We.AXIS_LABEL_OFFSET,e),d=t.getVariable(Ee.PROPERTY,We.AXIS_LABEL_FORMAT,e),u=t.getVariable(Ee.PROPERTY,We.AXIS_FONT_SIZE,e),_=t.createOneWayDependency(ve.AXIS_LABELS_PLACER),p=t.getVariable(Ee.PROPERTY,We.AXIS_LABELS_POSITION,e);t.connect(s,_),t.connect(c,_),t.connect(d,_),t.connect(u,_),t.connect(_,p),_.run();let f=t.getVariable(Ee.PROPERTY,We.AXIS_TITLE_POSITION,e),g=t.createOneWayDependency(ve.AXIS_TITLE_PLACER);t.connect(s,g),t.connect(g,f),g.run();let y=t.getVariable(Ee.BOUNDS,e),m=t.getIncomingDataflowOperator(ve.EVAL_BBOX,y);t.connect(h,m),t.connect(p,m),t.connect(m,y)}function ct(e,t){let i=t.getVariable(Ee.BOUNDS,Ve(e.elements[0])),r=t.getVariable(Ee.PROPERTY,We.GRIDLINES_POSITION,e),s=t.createOneWayDependency(ve.GRIDLINES_PLACER);t.connect(i,s),t.connect(s,r),s.run();let n=t.getVariable(Ee.BOUNDS,e),a=t.getIncomingDataflowOperator(ve.EVAL_BBOX,n);t.connect(r,a),t.connect(a,n)}function dt(e,t,i,s){let n,a=e.domain,o=e.range;switch(e.type){case"linear":case"log":{let l=Math.abs(o[0]-o[1]);n="width"==t||"x"==t?45:30;let h,c=Math.max(2,Math.floor(l/n));if("width"==t||"height"==t){let r=!!s&&(s.elements[0].parent.layout&&s.elements[0].parent.layout.type==me.STACK);a[1]=e._scale.invert(r?ce(i)[t]:he(i)[t])}if("log"===e.type){h=[];let t=e._scale.ticks();for(let e of t){let i=Math.log(e)/Math.log(10)+1e-6;Math.abs(i-Math.floor(i))<c/t.length&&h.push(e)}}else h=r.ticks(a[0],a[1],c);return h}case"point":{n="width"==t||"x"==t?80:30;let i=Math.floor(e.rangeExtent/a.length),r=Math.ceil(n/i);return"x"==t?a.filter((e,t)=>t%r==0):a}case"band":{n="width"==t||"x"==t?80:30;let i=Math.floor(e.rangeExtent/a.length),r=Math.max(1,Math.ceil(n/i));return a.filter((e,t)=>t%r==0)}case"time":{n="width"==t||"x"==t?80:30;let e,i,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=[r.timeSeconds,r.timeMinutes,r.timeHours,r.timeDays,r.timeMonths,r.timeYears];for(let t=0;t<h.length-1;t++)if(l>=h[t]&&l<h[t+1])return e=Math.floor(l/h[t]),i=c[t],i(a[0],a[1],e);return l>h[h.length-1]?(e=Math.floor(l/h[h.length-1]),i=c[h.length-1],i(a[0],a[1],e)):[]}default:return[]}}function ut(e,t){t.removeChild(e)}function _t(e,t){let i=t||Pe(e.element);delete i._encodings[yt(e.element)][e.channel],console.log("remove encoding",e.channel,e.attribute),function(e,t){let i=t.findVariable(Ee.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)ut(t,i),Ze(t,i._depGraph);e.clearRefElements()}function pt(e,t){if(!e||!e.scene)return[];let i=e.scene._encodings[yt(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 ft(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 gt(e,t){if(!e||!e.scene)return null;let i=e.scene._encodings[yt(e)];return i&&i[t]?i[t]:null}function yt(e){if(Array.isArray(e))return e.map(e=>yt(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===n.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 mt(e,t){if(0==e.children.length)return[];let i=Pe(e),r=e.type===n.Composite?e.children:[e.children[0]],s=Object.keys(i._encodings),a=[];for(let e of r){let t=e;for(;t;){if(t.classId&&a.indexOf(t.classId)<0&&a.push(t.classId),t.type===n.Glyph){t.children.forEach(e=>a.push(e.classId));break}if(!t.children)break;t=t.children[0]}}let o=[];for(let e of s)for(let r of a)0===e.indexOf(r)&&i._encodings[e][t]&&o.push(i._encodings[e][t]);return o}function bt(e){let t=gt(e,"y"),i=gt(e,"height");return t||i&&i.scales[0].domain[0]<0}function xt(e){let t=gt(e,"x"),i=gt(e,"width");return t||i&&i.scales[0].domain[0]<0}function vt(e,t){let i=function(e){let t=e.parent,i=[];for(;t.type!==n.Scene;)i.push(t),t=t.parent;return i}(e);for(let e of i)if(gt(e,t))return!1;return i.length>=2?i[i.length-2]:e}function wt(e,t,i){Et(e,t,i);let r=Pe(e);if(!r)return;let s=Be(e,!0);for(let e of s)de(e);for(let e of s)r.onChange(Ee.CHANNEL,"x",e)}function Et(e,t,i){switch(e.type){case n.Rect:case n.Path:case n.Line:case n.Area:!function(e,t,i){for(let r of e.vertices)At(r,t,i);e._updateBounds(),e._refBounds&&e._refBounds.translate(t,i)}(e,t,i),0===t&&0===i||(e._dirty=!0);break;case n.Group:case n.Collection:case n.Glyph:!function(e,t,i){for(let r of e.children)Et(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,i);break;case"segment":!function(e,t,i){At(e.vertex1,t,i),At(e.vertex2,t,i)}(e,t,i),0===t&&0===i||(e.parent._dirty=!0);break;case"vertex":At(e,t,i),0===t&&0===i||(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,i),0===t&&0===i||(e._dirty=!0)}}function At(e,t,i){e.x+=t,e.y+=i}class Ct{constructor(){this._id=this.type+o(),this._type=n.Group,this._dataScopeRef=void 0,this._bounds=void 0,this._layout=void 0,this._children=[],this._sortBy={property:j,descending:!1},this._z=0}get id(){return this._id}get type(){return this._type}get datum(){return R(this._dataScopeRef)}get data(){return S(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=w(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=P(e.dataScope,this._dataScopeRef):e.dataScope=this._dataScopeRef}getInternalEncodings(e){if(0==this.children.length)return[];let t=this.children[0],i=this.getScene(),r=Object.keys(i.encodings),s=[];for(;t;){if(t.classId&&s.indexOf(t.classId)<0&&s.push(t.classId),t.type===n.Glyph){t.children.forEach(e=>s.push(e.classId));break}if(!t.children)break;t=t.children[0]}let a=[];for(let t of r){let r=t.split("_");for(let n of s)r[0]==n&&i.encodings[t][e]&&a.push(i.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),st(this,e,this.scene._depGraph),this.children&&this.children.length>0){let e=Be(this,!0);for(let t of e)this.scene.onChange(Ee.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 oe(t,i,r-t,s-i)}get x(){return this.bounds.x}get y(){return this.bounds.y}set x(e){wt(this,e-this.bounds.x,0)}set y(e){wt(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 oe(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 Pe(this)}get sortBy(){return this._sortBy}}function St(e){return e.type===n.Axis||e.type===n.Legend||e.type===n.Gridlines}class Rt extends Ct{constructor(e){super(),this._type=n.Collection,this._id=e.id?e.id:this._type+"_"+o(),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=he(this._children);this._clipMask=new oe(e.left,e.top,e.width,e.height)}get clipMask(){return this._clipMask}}class kt extends Ct{constructor(e){if(super(),this._type=n.Glyph,this._id=e&&e.id?e.id:this.type+"_"+o(),this._classId=this._id,e&&e.children)for(let t of e.children)this.addChild(t)}get classId(){return this._classId}}const Tt=Object.freeze({RowFirst:"rowFirst",ColumnFirst:"columnFirst"}),Ot=Object.freeze({TopLeft:"topLeft",TopRight:"topRight",BottomLeft:"bottomLeft",BottomRight:"bottomRight"}),It="horizontal",Nt="vertical",Lt="angular",Pt="radial",Vt={Left2Right:"l2r",Right2Left:"r2l",Top2Bottom:"t2b",Bottom2Top:"b2t"},Bt=Object.freeze({CLOCKWISE:"clockwise",ANTI_CLOCKWISE:"anti-clockwise"}),Mt=Object.freeze({INWARD:"inward",OUTWARD:"outward"}),Dt=Object.freeze({INWARD:"inward",OUTWARD:"outward",TANGENTIAL_CLOCKWISE:"tangentialClockwise",TANGENTIAL_COUNTERCLOCKWISE:"tangentialCounterClockwise",UPRIGHT:"upright"});class Gt{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?R(this.dataScope):this.parent.datum}get data(){return this.dataScope?S(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 oe(this.x-this.width/2,this.y-this.height/2,this.width,this.height);case"circle":return new oe(this.x-this.radius,this.y-this.radius,2*this.radius,2*this.radius);default:return new oe(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)}}Gt.styles=["vxShape","vxWidth","vxHeight","vxRadius","vxFillColor","vxStrokeColor","vxStrokeWidth","vxOpacity"];class zt{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=w(e)}get datum(){return this.dataScope?R(this.dataScope):this.parent.datum}get data(){return this.dataScope?S(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 jt{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):jt._isIndex(t)?e.get(Number(t)):e[t],set(e,t,i){if(jt._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 Gt(this._path,e)),this._refs[e]}at(e){return e<0&&(e=this.length+e),this.get(e)}append(e,t){let[i,r]=jt.getCoords(e),s=Array.isArray(e)?void 0:e.dataScope,n=void 0!==t?t:jt.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]:jt.getCoords(t),a=n[0],o=n[1],l=s||Array.isArray(t)?void 0:t.dataScope,h=s?r:jt.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]=jt.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=jt.propertyArrays[t];return"dataScope"===t?this.getDataScopeRef(e):i?this[i][e]:void 0}setProperty(e,t,i){let r=jt.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 S(t)}getDataScopeAttrVal(e,t){let i=this._dataScopeRefs[e];if(i)return O(i,t)}getDataScopeAttributeValues(e,t){let i=this._dataScopeRefs[e];return i?I(i,t):[]}aggregateDataScopeAttribute(e,t,i){return N(this._dataScopeRefs[e],t,i)}_copyDataScopeRef(e){return e?w(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 jt.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 jt.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 Ft=class extends _e{constructor(e){super(e),this._type="type"in e?e.type:n.Path,this._vertices=new jt(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 Gt.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 i=jt.getCoords(e[t]),r=jt.getCoords(e[0]);if(t==e.length-1&&i[0]===r[0]&&i[1]===r[1]&&this.type===n.Path)continue;let s=Array.isArray(e[t])?this.vertexCounter++:jt.getId(e[t]),a=this._vertices.append(e[t],s);!Array.isArray(e[t])&&"number"==typeof s&&s>=this.vertexCounter&&(this.vertexCounter=s+1);for(let i of Gt.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 zt(a-1,a,this,this.segmentCounter++))}let t=jt.getCoords(e[0]),i=jt.getCoords(e[e.length-1]);this._vertices.length>1&&(this.closed||t[0]===i[0]&&t[1]===i[1]||this.type===n.Rect)&&(this.closed=!0,"fillColor"in this.styles||(this.styles.fillColor="#fff"),this.segments.push(new zt(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 Gt.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 zt(t-1,t,e,e.segmentCounter++));e.closed&&e.segments.push(new zt(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){wt(this,e-this.bounds.x,0)}set y(e){wt(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 e=[],t=[];if(this._d){const i=this._d.match(/[a-zA-Z][^a-zA-Z]*/g),r=" ";i.forEach(i=>{let s=i.slice(1).trim().split(r).map(Number);for(let[i,r]of s.entries())i%2==0?e.push(r):t.push(r)})}else e=this._vertices._xs,t=this._vertices._ys;let i=r.min(e),s=r.min(t),a=r.max(e),o=r.max(t),l=a-i,h=o-s;if(this._bounds=new oe(i,s,l,h),this.type===n.Line||this.type===n.Path){let e=this.styles.strokeWidth?this.styles.strokeWidth:1;i===a?this._bounds=new oe(i-e/2,s,a-i+e,o-s):s===o&&(this._bounds=new oe(i,s-e/2,a-i,o-s+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 e=r.path(),t=this._getD3CurveFunction(this.curveMode)(e);t.lineStart();for(let e=0;e<this._vertices.length;e++)t.point(this._vertices._xs[e],this._vertices._ys[e]);return this.closed&&t.point(this._vertices._xs[0],this._vertices._ys[0]),t.lineEnd(),e._}get firstVertex(){return this._vertices[0]}get anyVertex(){return this._anyVertexRef||(this._anyVertexRef=new Gt(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(e){switch(e){case Yt.Natural:return r.curveNatural;case Yt.Basis:return r.curveBasis;case Yt.BumpX:return r.curveBumpX;case Yt.BumpY:return r.curveBumpY;case Yt.Linear:return r.curveLinear;case Yt.Step:return r.curveStep;case Yt.CatmullRom:return r.curveCatmullRom;case Yt.Cardinal:return r.curveCardinal;case Yt.Bundle:return r.curveBundle.beta(.5);default:return r.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=ie.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 Ut(e){return e instanceof Ft&&e.source&&e.target}const Yt={Natural:"natural",Basis:"basis",BumpX:"bumpX",BumpY:"bumpY",Bundle:"bundle",Linear:"linear",Step:"step",CatmullRom:"CatmullRom",Cardinal:"cardinal"};function Ht(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 Xt extends Ft{constructor(e){super(e),this._type=n.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=qt(this._startAngle),this._er=qt(this._endAngle),this._direction="direction"in e?e.direction:Bt.ANTI_CLOCKWISE;let t=this._x+this._innerRadius*Math.cos(this._sr),i=this._y-this._innerRadius*Math.sin(this._sr),r=this._x+this._innerRadius*Math.cos(this._er),s=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,i],[a,o],[l,h],[r,s]]}get type(){return 0===this._innerRadius?n.Pie:n.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=qt(this._startAngle),this._er=qt(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 oe(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 qt(e){return e*Math.PI/180}function Kt(e){return 180*e/Math.PI}function Zt(e){return(e%360+360)%360}function $t(e,t,i,r){let s=e-i,n=r-t;return Math.atan2(n,s)*(180/Math.PI)}class Jt extends Ft{constructor(e){super(e),this._type=n.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 zt(this.vertices.length-1,0,this,this.segmentCounter++))}get topLeftVertex(){return this._orientation===It?this.vertices[0]:this.vertices[this.vertices.length-1]}get bottomLeftVertex(){return this._orientation===It?this.vertices[this.vertices.length-1]:this.vertices[this.vertices.length/2]}get topRightVertex(){return this._orientation===It?this.vertices[this.vertices.length/2-1]:this.vertices[0]}get bottomRightVertex(){return this._orientation===It?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 Qt extends Ft{constructor(e){super(e),this._type=n.BezierCurve,this._orientation="orientation"in e?e.orientation:It}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 ei extends _e{constructor(e){super(e),this._type=n.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=re(this._x,this._y,this._rotate[1],this._rotate[2],this._rotate[0]);this._bounds=new oe(e.x-this._radius,e.y-this._radius,2*this._radius,2*this._radius)}else this._bounds=new oe(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 ti extends _e{constructor(e){super(e),this._type=n.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 oe(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 ii=class extends _e{constructor(e){super(e),this._type=n.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 oe(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 ri extends Ft{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 si="filled",ni="none";class ai extends Ft{constructor(e={}){const t="x1"in e?e.x1:0,i="y1"in e?e.y1:0,r="x2"in e?e.x2:100,s="y2"in e?e.y2:0,a=[[t,i],...e.controlPoints||[],[r,s]];super({...e,type:n.Arrow,vertices:a}),this._startStyle=e.startStyle??ni,this._startSize=e.startSize??8,this._endStyle=e.endStyle??si,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 oi extends _e{constructor(e){super(e),this._type=n.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:[ue.CENTER,ue.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=ie.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 ue.LEFT:e=this._x;break;case ue.RIGHT:e=this._x-r;break;case ue.CENTER:e=this._x-r/2;break;default:e=this._x}switch(this._anchor[1]){case ue.TOP:t=this._y;break;case ue.BOTTOM:t=this._y-s;break;case ue.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=>re(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 oe(n,o,a-n,l-o)}else this._bounds=new oe(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 li extends Ft{constructor(e){super(e),this._type=n.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 hi extends Ft{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 ci extends Ft{constructor(e){super(e),this._type=n.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 di extends _e{constructor(e){super(e),this._type=n.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:[ue.CENTER,ue.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=ie.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 ue.LEFT:e=this._x;break;case ue.RIGHT:e=this._x-r;break;case ue.CENTER:e=this._x-r/2;break;default:e=this._x}switch(this._anchor[1]){case ue.TOP:t=this._y;break;case ue.BOTTOM:t=this._y-s;break;case ue.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=>re(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 oe(n,o,a-n,l-o)}else this._bounds=new oe(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 ui{constructor(e){let t=e||{};this._stops=[],this.type=n.LinearGradient,this.id=this.type+o(),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 _i{constructor(e){this.type=n.PathGradient,this.id=this.type+o(),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 pi extends Ct{constructor(e){super(),this._type=n.Axis,this._id=e.id?e.id:this._type+o(),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 Ct,this._ticks._id=this._id+"_ticks",this.addChild(this._ticks),this._labels=new Ct,this._labels._id=this._id+"_labels",this.addChild(this._labels),this._title=new oi({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!==n.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 fi="top",gi="bottom",yi="left";function mi(e,t,i){if(e&&e.origin)return e.origin;let r=t[0].parent;if(r.type===n.Polygon)return[r.x,r.y];throw new Error('Mascot: "polarRadius"/"polarAngle" '+i+' 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 bi extends pi{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?gi:yi,this._titleText="title"in r?r.title:this._encoding.sourceAttribute??this._encoding.attribute,this._path="angle"===this._channel||"polarAngle"===this._channel?new ei({strokeColor:this._strokeColor,id:this._id+"_path"}):new Ft({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)!==h.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 mi(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(e){"tickValues"in e?(this._tickValues=e.tickValues,this._labelValues="labelValues"in e?e.labelValues:e.tickValues):(this._tickValues=dt(this._scale,this._channel,this._elems,this),this._labelValues="labelValues"in e?e.labelValues:this._tickValues),this._ticks.removeAll();for(let e=0;e<this._tickValues.length;e++){let t=new Ft({strokeColor:this._strokeColor,id:this._id+"_tick"+e});this._tickVisible||(t.visibility="hidden"),this._ticks.addChild(t)}this._labels.removeAll();let t,i=this._encoding.dataTable.type(this._attribute);if("labelValues"in e)t=function(e){return e};else switch(i){case h.Date:t=r.utcFormat(this._labelFormat);break;case h.String:t=function(e){return e};break;default:t=r.format(this._labelFormat)}for(let[e,i]of this._labelValues.entries()){let r=new oi({text:t(i),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 xi{constructor(e,t){switch(this._id="scale_"+o(),this._type=e,t&&(this._args=t),e){case"linear":this._scale=r.scaleLinear();break;case"point":this._scale=r.scalePoint();break;case"band":this._scale=r.scaleBand().padding(0);break;case"ordinal":this._scale=r.scaleOrdinal();break;case"ordinalColor":this._scale=r.scaleOrdinal(r[t.scheme]);break;case"power":this._scale=r.scalePow().exponent(2);break;case"sqrt":this._scale=r.scalePow().exponent(.5);break;case"log":this._scale=r.scaleLog();break;case"identity":case"time":this._scale=r.scaleTime();break;case"sequentialColor":t.scheme?this._scale=r.scaleSequential(r[t.scheme]):this._scale=r.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(e,t){let i=r.min(this._scale.range()),s=r.max(this._scale.range()),n=e;if(t||(n=r.max([i,r.min([e,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 vi(e){if(e.scaleType)return new xi(e.scaleType);if(e._baseEnc&&e._baseEnc.scales.length>0){let t=e._baseEnc.scales[0];return new xi(t.type,t._args)}if("text"===e.channel||"src"===e.channel||"path"===e.channel)return new xi("ordinal");switch(e.dataTable.type(e.attribute)){case h.Boolean:break;case h.Date:return new xi("time");case h.String:if("count"==e.aggregator)return new xi("linear");if(e.channel.indexOf("Color")>=0||"fillGradient"===e.channel||"strokeGradient"===e.channel){let t={};return t.scheme=e.colorScheme?e.colorScheme:"schemeCategory10",new xi("ordinalColor",t)}return new xi("point");default:return["strokeColor","fillColor","fillGradient","strokeGradient"].indexOf(e.channel)>=0?e.mapping?new xi("linear"):new xi("sequentialColor",{scheme:e.colorScheme}):new xi("linear")}}const wi=["schemeBrBG","schemePRGn","schemePiYG","schemePuOr","schemeRdBu","schemeRdGy","schemeRdYlBu","schemeRdYlGn","schemeSpectral"],Ei=["schemeBlues","schemeGreens","schemeGreys","schemeOranges","schemePurples","schemeReds","schemeBuGn","schemeBuPu","schemeGnBu","schemeOrRd","schemePuBuGn","schemePuBu","schemePuRd","schemeRdPu","schemeYlGnBu","schemeYlGn","schemeYlOrBr","schemeYlOrRd"];class Ai extends Ft{constructor(e,t,i,r,s){super(s),this._type=n.Gridlines,this._id=this._type+o(),this._attribute=t,this._channel=e,this._scale=i,this._elems=r,this._args=s,"strokeColor"in s||(this.styles.strokeColor="#ddd"),"opacity"in s||(this.styles.opacity=.5),this.updateValues(),this._lines=[]}updateValues(){"values"in this._args?this._values=this._args.values:this._scale?this._values=dt(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 oe(e.x-e.r,e.y-e.y,2*e.r,2*e.r));this._bounds=le(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 oe(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 mi(this._args,this._elems,"gridlines")}get lines(){return this._lines}set lines(e){this._lines=e}}class Ci{constructor(e,t,i,r,s){this._id="encoding_"+o(),this._elem=e,this._channel=t,this._attribute=i,this._table=s.table,this._aggregator=r,this._includeZero=s.includeZero,this._flipScale=s.flipScale,this._mapping=s.mapping,this._preferredRangeExtent=s.rangeExtent,this._preferredRangeStart=s.rangeStart,this._preferredDomain=s.domain,this._preferredRange=s.range,this._preferredOrigin=s.origin,this._scaleType=s.scaleType,this._colorScheme=s.scheme,this._forLegend=s.forLegend,this._sourceAttribute=s.sourceAttribute??null,s.shareScale&&(this._baseEnc=s.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=Ve(this._elem),i=Ce(this._elem.parent);if("x"!==this._channel&&"y"!==this._channel||!t.layout||t.layout.type!=me.GRID)e=xt(this._elem.parent)||bt(this._elem.parent)?i.map(e=>ke(this._elem,[e])):[ke(this._elem,i)];else{e=("x"===this._channel?t.layout.getElementsByCol(!0,this._elem.parent):t.layout.getElementsByRow(!0,this._elem.parent)).map(e=>ke(this._elem,e))}for(let t of e)this._createScaleForVertexIndices(t)}else if("x"===this._channel||"y"===this._channel){let e=this._elem,t=Ve(e);if(t.layout&&t.layout.type==me.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=Ce(this._elem);this._createScaleForElems(e)}}else if("angle"===this._channel){let e=Ce(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=Ce(this._elem);this._createScaleForElems(e)}}_createScaleForElems(e){this._elemGroups.push(e);var t=vi(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=vi(this);this._scales.push(t);for(let i of e)for(let e of i.indices)this._elem2scale[Re(i.parent,e)]=t}refreshElementMappings(){if(1===this._scales.length)if(this._elem2scale={},"vertex"===this._elem.type){let e=Ce(this._elem.parent),t=ke(this._elem,e);this._elemGroups=[{type:"vertexIndices",groups:t}];for(let e of t)for(let t of e.indices)this._elem2scale[Re(e.parent,t)]=this._scales[0]}else{let e=Ce(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(e,t,i){let s=(t?this.getScale(t):this._scales[0]).invert(e,i),n=this._attribute;if(this.dataTable.type(n)===h.Date){const e=this.dataTable.values(n).slice().sort((e,t)=>e-t);let t=r.bisectLeft(e,s);return t=Math.min(t,e.length-1),t>0&&Math.abs(e[t-1]-s)<Math.abs(e[t]-s)&&t--,e[t]}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 bi?(t._attribute=e,t.createTicksLabels({}),t._titleText&&(t._titleText=this._sourceAttribute??e)):t instanceof Ai&&(t._attribute=e,t.updateValues());const i=this._elem.scene._depGraph.getVariable(Ee.ATTRIBUTE,t,this.dataTable,this);i&&(i._attribute=e,this._elem.scene.onChange(Ee.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(e){let t=this.getScale(e);return r.min(t.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 bi&&e.createTicksLabels({});this._elem.scene.onChange(Ee.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 bi&&e.createTicksLabels({});this._elem.scene.onChange(Ee.PROPERTY,We.RANGE_EXTENT,this)}set includeZero(e){this._includeZero=e;for(let e of this._refElements)e instanceof bi&&e.createTicksLabels({});this._elem.scene.onChange(Ee.PROPERTY,We.INCLUDE_ZERO,this)}get includeZero(){return this._includeZero}set flipScale(e){this._flipScale=e,this._elem.scene.onChange(Ee.PROPERTY,We.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(e,t,i,s){let n=s||this._elem,a=this.getDomain(n),o=r.min(a),l=r.max(a),h="log"!==this._scales[0].type,c=this.getAttrValue(t,n,h),d=o-(c-o)*e*i,u=l+(l-c)*e*i;d!==u&&(!h&&d<=0||(this.domain=[d,u]))}}function Si(e,t,i,r={}){let s={channel:t,attribute:i,...r};if("rowId"===s.attribute&&(s.attribute=j),function(e,t,i){if(!e||!t||!i)throw new Error("encode(elem, channel, attribute) — all three arguments are required");if(!Object.values(Ge).includes(t))throw new Error(`Unknown channel "${t}"`);let r=z(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,i),s.shareScale){let e=s.shareScale;if(e.channel!=s.channel&&e.channel.indexOf("Color")<0&&s.channel.indexOf("Color")<0)throw new Error("Cannot share scales between "+e.channel+" and "+s.channel+" encodings");s.scheme=s.shareScale.colorScheme}!function(e){let t;"vertex"===e.type&&e.parent.type===n.Area?t=e.parent:e.type===n.Area&&(t=e),t&&!t._refBounds&&Ce(t).forEach(e=>e._refBounds=e.bounds.clone())}(e);let a=s.aggregator?s.aggregator:"sum";s.table=z(e);let o=new Ci(e,s.channel,s.attribute,a,s),l=e.scene;return l._addAttributeEncoding(o),ot(o,l._depGraph,s.shareScale),s.shareScale?l.onChange(Ee.ATTR_VALUE,o):l.onChange(Ee.CHANNEL,s.channel,e),o}function Ri(e,t,i,r){for(let s=t;s<i;s++)e._vertices._xs[s]=r;e._dirty=!0}function ki(e,t,i,r){for(let s=t;s<i;s++)e._vertices._xs[s]=r(s);e._dirty=!0}function Ti(e,t,i,r){for(let s=t;s<i;s++)e._vertices._ys[s]=r;e._dirty=!0}function Oi(e,t,i,r){for(let s=t;s<i;s++)e._vertices._ys[s]=r(s);e._dirty=!0}function Ii(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 D(i,"from count");return Ni(e,r)}(e,t):function(e){if(!e||"object"!=typeof e||Array.isArray(e))return!1;if(e instanceof D||e instanceof F||e instanceof U)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 D(r,"from group counts");return Ni(e,s,i)}(e,t,i):Ni(e,t,i)}function Ni(e,t,i){let r=Pe(e),s=i||{};if(s.attribute=s.attribute||j,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 F||t instanceof U){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 D&&l(i.attribute,t);if(i.layout&&!(i.layout instanceof ge))throw new Error("Invalid layout: "+i.layout)}(e,t,s),t instanceof F||t instanceof U){let i=e[0].parent,s=e[1].parent,[a,o]=function(e,t,i,r){let s=t.dataScope?t.dataScope:V(r.nodeTable),a=B(s,X),o=zi(e,{type:n.Collection}),l=zi(e,{type:n.Collection}),h={};l.dataScope=s,l.addChild(t);for(let e=1;e<a.length;e++){let e=Wi(t);l.addChild(e)}l.children.forEach((e,t)=>{e.dataScope=a[t],e.links=[],h[O(e.dataScope,X)]=e});let c=i.dataScope?i.dataScope:V(r.linkTable),d=B(c,j);o.dataScope=c,o.addChild(i);for(let e=1;e<d.length;e++){let e=Wi(i);o.addChild(e)}o.children.forEach((e,t)=>e.dataScope=d[t]);let u=r instanceof F?"parent":"source",_=r instanceof F?"child":"target";for(let e of o.children){let t=O(e.dataScope,u),i=O(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]}(r,e[0],e[1],t);return Qe(i,e[0],r._depGraph),Qe(s,e[1],r._depGraph),$e(a,r._depGraph),$e(o,r._depGraph),et(a,e[0],r._depGraph),et(a.parent,a,r._depGraph),et(o,e[1],r._depGraph),et(o.parent,o,r._depGraph),[a,o]}if(t instanceof D){let i=e.parent,a=function(e,t,i,r){let s=r.type(i);if(s!=h.String&&s!=h.Date&&s!=h.Integer)throw new Error("Repeat only works on a string or date attribute: "+i+" is "+s);if(!function(e){if(Array.isArray(e)){if(1===e.length)return Li(e[0]);for(let t of e)if(!pe(t)||t.dataScope)return!1;return!0}return Li(e)}(t))throw new Error("The "+t.type+" is not repeatable");return function(e,t,i,r){let s=t.dataScope?t.dataScope:V(r),a=B(s,i),o=zi(e,{type:n.Collection});o.dataScope=s,o.addChild(t),t._refBounds||(t._refBounds=t.bounds.clone());for(let e=1;e<a.length;e++){let e=Wi(t);o.addChild(e)}return o.children.forEach((e,t)=>e.dataScope=a[t]),o}(e,t,i,r)}(r,e,s.attribute,t);return Qe(i,e,r._depGraph),$e(a,r._depGraph),et(a,e,r._depGraph),et(a.parent,a,r._depGraph),function(e,t,i,r){let s=r.getVariable(Ee.ITEMS,i),n=r.createOneWayDependency(ve.REPOPULATE);n._collection=e,n._repeatAttr=t,r.connect(s,n);let a=e.children[0],o=new Set([a,...Be(a)]);for(let e of o)r.connect(n,r.getVariable(Ee.DATASCOPE,e))}(a,s.attribute,t,r._depGraph),s.layout&&(a.layout=s.layout),a}}function Li(e){return!(!pe(e)&&e.type!=n.Glyph||e.dataScope)||e.type===n.Collection&&k(e.firstChild.dataScope)>1}class Pi extends ge{constructor(e){super(),this.type=me.GRID,this._numCols=e.numCols,this._numRows=e.numRows,this._start="start"in e?e.start:Ot.TopLeft,this._direction="direction"in e?e.direction:Tt.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&&be("h",e.horzCellAlignment)?e.horzCellAlignment:ue.LEFT,this._cellVertAlignment="vertCellAlignment"in e&&be("v",e.vertCellAlignment)?e.vertCellAlignment:ue.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 Pi({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(Be(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(Be(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=Be(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=>Se(t,e))):"segment"===t.type?(i=e.map(e=>e.filter(e=>e.classId===t.parent.classId)),i=i.map(e=>Te(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 Tt.RowFirst:t=Math.floor(e/this.numCols),i=e%this.numCols;break;case Tt.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 Vi extends Ct{constructor(e,t){super(),this._type=n.Legend,this._id=this._type+o(),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:Nt,this._numberFormat=t.numberFormat?t.numberFormat:""}get attribute(){return this._enc.attribute}get channel(){return this._enc.channel}get attributeType(){return z(this._enc.element).getFieldType(this.attribute)}get orientation(){return this._orientation}get textColor(){return this._textColor}}class Bi extends Vi{constructor(e,t){super(e,t),"numCols"in t||"numRows"in t?(this._numCols=t.numCols,this._numRows=t.numRows):this._orientation===Nt?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 D(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 Ft&&n.closed&&"strokeColor"!==this._enc.channel?n.strokeWidth:0;if(this._orientation===Nt){let i=0;this._showTitle&&(this.addChild(new oi({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=Ii(e.glyph(o,l),r);Si(l,"text","category",{forLegend:!0}),Si(o,"fillColor","category",{shareScale:this._enc,forLegend:!0}),h.layout=new Pi({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=Ii(e.glyph(t,i),r);Si(i,"text","category",{forLegend:!0}),Si(t,"fillColor","category",{shareScale:this._enc,forLegend:!0}),o.layout=new Pi({numCols:this._numCols,numRows:this._numRows,colGap:15}),this.addChild(o)}}}class Mi extends Vi{constructor(e,t){super(e,t),this._initialize()}_initialize(){let e,t,i,s=this._enc.element.scene,n=this._enc.attribute;if(this._orientation==Nt?(e=15,t=300):(e=300,t=15),this._showTitle){let t=s.mark("text",{fillColor:this._textColor,text:n,x:this._x+e/2,y:this._y,anchor:["center","middle"]});this.addChild(t),i=20}else i=0;let a,o=s.mark("rect",{top:this._y+i,left:this._x,width:e,height:t,strokeWidth:0,opacity:this._enc.element.opacity}),l=Object.values(this._enc.attrValues),c=[r.min(l),r.max(l)],d=this._enc.mapping,u=[],_=[],p=r.format(this._numberFormat);if(d){let r=Object.keys(d).map(e=>parseFloat(e)).sort((e,t)=>e-t);this._orientation==Nt?(a=new ui({x1:0,y1:100,x2:0,y2:0}),r.forEach(r=>{let n=(r-c[0])/(c[1]-c[0]);a.addStop(100*n,d[r],1);let o=s.mark("line",{x1:this._x+e,x2:this._x+e+5,y1:this._y+t-n*t+i,y2:this._y+t-n*t+i,strokeColor:this._strokeColor});_.push(o);let l=s.mark("text",{fillColor:this._textColor,text:this._numberFormat?p(r):r.toFixed(0),x:this._x+e+5+5,y:this._y+t-n*t+i,anchor:["left","middle"]});u.push(l)})):(a=new ui({x1:0,y1:0,x2:100,y2:0}),r.forEach(r=>{let n=(r-c[0])/(c[1]-c[0]);a.addStop(100*n,d[r],1);let o=s.mark("line",{x1:this._x+n*e,x2:this._x+n*e,y1:this._y+20-5+i,y2:this._y+t+5+i,strokeColor:this._strokeColor});_.push(o);let l=s.mark("text",{fillColor:this._textColor,text:this._numberFormat?p(r):r.toFixed(0),x:this._x+n*e,y:this._y+t+5+i,anchor:["center","top"]});u.push(l)}))}else{let r=this._enc.scales[0].domain,o=z(this._enc.element),l=o.type(n),c=[],d=l===h.Date?o.getUniqueFieldValues(n):[...new Set(Object.values(this._enc.attrValues))];if(d.length<=10)c=d,c.sort((e,t)=>e-t);else if(l===h.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 e=(r[1]-r[0])/9;for(let t=0;t<10;t++)c.push(r[0]+t*e)}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==Nt?(a=new ui({x1:0,y1:100,x2:0,y2:0}),c.forEach(c=>{let d=(c-r[0])/(r[1]-r[0]);a.addStop(100*d,this._enc.scales[0].map(c),1);let f=s.mark("line",{x1:this._x+e,x2:this._x+e+5,y1:this._y+t-d*t+i,y2:this._y+t-d*t+i,strokeColor:this._strokeColor});_.push(f);let g=s.mark("text",{fillColor:this._textColor,text:l===h.Date?o.raw(n,c):this._numberFormat?p(c):c,x:this._x+e+5+5,y:this._y+t-d*t+i,anchor:["left","middle"]});u.push(g)})):(a=new ui({x1:0,y1:0,x2:100,y2:0}),c.forEach(c=>{let d=(c-r[0])/(r[1]-r[0]);a.addStop(100*d,this._enc.scales[0].map(c),1);let p=s.mark("line",{x1:this._x+d*e,x2:this._x+d*e,y1:this._y+t+i,y2:this._y+t+5+i,strokeColor:this._strokeColor});_.push(p);let f=s.mark("text",{fillColor:this._textColor,text:l===h.Date?o.raw(n,c):c,x:this._x+d*e,y:this._y+t+5+i,anchor:["center","top"]});u.push(f)}))}o.styles.fillColor=a,this.addChild(o);for(let e of u)this.addChild(e);for(let e of _)this.addChild(e)}}class Di extends pi{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?gi:yi,this._titleText="title"in r?r.title:this._attribute,this._path="angle"===this._channel?new ei({strokeColor:this._strokeColor,id:this._id+"_path"}):new Ft({strokeColor:this._strokeColor,id:this._id+"_path"}),this._pathVisible||(this._path.visibility="hidden"),this.addChild(this._path),this.createTicksLabels(r),A(this._elems[0].dataScope).type(this._attribute)!==h.Date||"labelFormat"in r||(this._labelFormat="%m/%d/%y")}get elements(){if(this.layout.type===me.CLUSTER){const e=new Map(this._elems.map(e=>[e.datum[X],e]));return this.layout._d3Root.leaves().map(t=>e.get(t.data[X]))}return this._elems}get layout(){return this._elems[0].parent.layout}createTicksLabels(e){"tickValues"in e?(this._tickValues=e.tickValues,this._labelValues=e.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 Ft({strokeColor:this._strokeColor,id:this._id+"_tick"+e});this._tickVisible||(t.visibility="hidden"),this._ticks.addChild(t)}let t;switch(this._labels.removeAll(),A(this._elems[0].dataScope).type(this._labelAttribute?this._labelAttribute:this._attribute)){case h.Date:t=r.timeFormat(this._labelFormat);break;case h.String:t=function(e){return e};break;default:t=r.format(this._labelFormat)}for(let[e,i]of this._labelValues.entries()){let r=new oi({text:t(i),fontSize:this._fontSize,fillColor:this._textColor,id:this._id+"_label"+e});this._labels.addChild(r)}this._title._text=this._titleText}}class Gi extends Ct{constructor(e){super(),this._type=n.Composite,this._id=e&&e.id?e.id:this._type+o()}addChild(e){let t=e.parent;super.addChild(e);let i=Pe(e)._depGraph;t&&Qe(t,e,i),et(this,e,i)}}function zi(e,t){let i;switch(t.type){case"collection":i=Fi(t);break;case"glyph":i=function(e){let t=new kt(e);return t}(t);break;case"axis":i=function(e){if("encoding"===e.axisType){return new bi(e.enc,e.scale,e.elems,e)}if("layout"===e.axisType){return new Di(e.elems,e.channel,e.attribute,e)}}(t);break;case"legend":i=function(e){let t="string"===e.attrType?new Bi(e.enc,e):new Mi(e.enc,e);return t}(t);break;case"composite":i=function(e){let t=new Gi(e);return t}(t);break;default:i=ji(t)}return e.addChild(i),e._itemMap[i.id]=i,i}function ji(e){let t=null;switch(e.type){case n.Circle:t=new ei(e);break;case n.Line:var i="x1"in e?e.x1:0,r="y1"in e?e.y1:0,s="x2"in e?e.x2:100,a="y2"in e?e.y2:100;e.vertices=[[i,r],[s,a]],t=new ri(e);break;case n.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 hi(e);break;case n.SimpleText:t=new oi(e);break;case n.RichText:t=new di(e);break;case n.Image:t=new ti(e);break;case n.Symbol:t=new ii(e);break;case n.BundledPath:case n.Chord:case n.Path:t=new Ft(e);break;case n.Arrow:t=new ai(e);break;case n.Area:t=new Jt(e);break;case n.Ring:t=new ci(e);break;case n.Arc:t=new Xt(e);break;case n.BezierCurve:"vertices"in e||(e.vertices=[[0,100],[20,120],[80,180],[100,200]]),t=new Qt(e);break;case n.Polygon:t=new li(e)}return t&&t._updateBounds(),t}function Fi(e){return new Rt(e)}function Wi(e){switch(e.type){case n.Collection:return function(e){let t=Fi({});for(let i=0;i<e.children.length;i++){let r=e.children[i];t.addChild(Wi(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 n.Glyph:return function(e){let t=new kt;for(let i of e.children)t.addChild(Wi(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=ji({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 Ui extends we{constructor(e,t){super(e),this._elem=t}get element(){return this._elem}}class Yi extends we{constructor(e,t){super(e),this._item=t}get element(){return this._item}}class Hi{constructor(e){this._id=e+"_"+o(),this._type=e,this._vars=[],this._edges=[]}get vars(){return this._vars}get edges(){return this._edges}run(){console.log("-",this._type)}}class Xi{constructor(e,t,i=!0){this._id="e_"+o(),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 xe||this._fromNode instanceof Hi?this._fromNode:this._toNode}}class qi extends we{constructor(e,t){super(e),this._encs={},this._encs[t.channel+"_"+yt(t.element)]=t,this._initialized=!1}addLinkedEncoding(e){this._encs[e.channel+"_"+yt(e.element)]=e}getEncoding(e,t){let i=e+"_"+yt(t);return this._encs[i]}get encodings(){return Object.values(this._encs)}get initialized(){return this._initialized}set initialized(e){this._initialized=e}}class Ki extends we{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 Zi(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 $i extends xe{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof Ki),t=this.outputVar,i=t.encodings,r=i[0],s=r.channel,a=r.attribute,o=e.encodings[0].dataTable.type(e.encodings[0].attribute),l=Object.values(e.attrValues);if("angle"===r.channel&&[n.Arc,n.Pie].indexOf(r.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=r._preferredDomain?r._preferredDomain:t.dataTable.tree?[0,t.dataTable.tree.getRoot()[a]]:this._getDomainForNumbers(i),console.log("domain for",a,e.domain)}else{let t;t=r._preferredDomain?r._preferredDomain:o==h.String||"text"===e.encodings[0].channel?this._getDomainForStrings(l):this._getDomainForNumbers(l);for(let i of e.encodings)for(let e of i.scales)e.domain=t.slice()}for(let e=0;e<r.scales.length;e++){let n=r.scales[e],a=r.getElements(n),o=this._buildRange(s,a,r,t);if(o)for(let t of i)t.scales[e].range=o}t.initialized=!0}_getDomainForNumbers(e){let t=this.outputVar.encodings[0],i=[r.min(e),r.max(e)];if(t.includeZero&&i[0]>0&&(i=[0,r.max(e)]),t.mapping)i=Object.keys(t.mapping),i=i.map(e=>parseFloat(e)),i.sort((e,t)=>e-t);else if("sequentialColor"===t.scales[0].type){if(i[0]<0&&i[1]>0){let e=Math.max(Math.abs(i[0]),Math.abs(i[1]));i=[-e,e]}}else if("angle"===t.channel){i=[0,Object.values(e).reduce((e,t)=>e+t,0)]}return i}_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(e,t){if(t.mapping){return t.scales[0].domain.map(e=>t.mapping[e+""])}if("sequentialColor"===t.scales[0].type){let e=this.outputVar,i=t.scales[0].domain;for(let s of e.encodings)if(!t.colorScheme)for(let e of s.scales){let t=e.domain;e._scale=r.scaleSequential(i[0]<0&&i[1]>0?r.interpolatePuOr:r.interpolateTurbo),e._scale.domain(t)}}if((wi.indexOf(t.colorScheme)>=0||Ei.indexOf(t.colorScheme)>=0)&&"ordinalColor"===t.scales[0].type){let e=this.outputVar,i=t.scales[0].domain;for(let s of e.encodings)for(let e of s.scales){let s=e.domain;e._scale=r.scaleOrdinal(r[t.colorScheme][i.length]),e._scale.domain(s)}}}_buildSizeRange(e,t,i){let r,s;if(r=0,"vertexIndices"===e.type){let r=Re(e.groups[0].parent,e.groups[0].indices[0]);return s=i.initialized?t._elem2scale[r].rangeExtent:t._preferredRangeExtent?t._preferredRangeExtent:Math.max(...this._getVertexIndexSizeValues(e,t.channel)),[0,0+s]}return s=i.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?Zi(e.parent):"area"===t.channel?e.type===n.Circle?Math.PI*Math.pow(e.radius,2):e.width*e.height:"fontSize"===t.channel?parseFloat(e.fontSize):e.refBounds[t.channel])),[0,0+s]}_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?Zi(r.parent):"width"===t?e._widths[s]:"height"===t?e._heights[s]:0)}return i}_buildXRange(e,t,i){let s,n,a=t.scales[0].type;if("vertexIndices"===e.type){let a=e.groups[0].parent,o=Re(a,e.groups[0].indices[0]),l=a.refBounds?a.refBounds:a.bounds;return s=i.initialized?r.min(t._elem2scale[o].range):l.left,n=i.initialized?t._elem2scale[o].rangeExtent:t._preferredRangeExtent?t._preferredRangeExtent:l.width,t.flipScale?[s+n,s]:[s,s+n]}switch(e[0].type){case"vertex":case"segment":var o=e[0].parent.refBounds?e[0].parent.refBounds:e[0].parent.bounds;s=i.initialized?t.getRangeStart(e[0]):o.left,n=i.initialized?t.getRangeExtent(e[0]):t._preferredRangeExtent?t._preferredRangeExtent:o.width;break;default:s=i.initialized?t.getRangeStart(e[0]):t._preferredRangeStart?t._preferredRangeStart:Ve(e[0]).bounds.left+e[0].bounds.width/2,n="band"===a?e[0].bounds.width*t.scales[0].domain.length:i.initialized?t.getRangeExtent(e[0]):t._preferredRangeExtent?t._preferredRangeExtent:r.max([450,r.max(e.map(e=>e.bounds.x))-r.min(e.map(e=>e.bounds.x))])}return t.flipScale?[s+n,s]:[s,s+n]}_buildYRange(e,t,i){let s,n;if(t.scales[0].type,"vertexIndices"===e.type){let a=e.groups[0].parent,o=Re(a,e.groups[0].indices[0]),l=a.refBounds?a.refBounds:a.bounds;return s=i.initialized?r.min(t._elem2scale[o].range):l.top,n=i.initialized?t._elem2scale[o].rangeExtent:t._preferredRangeExtent?t._preferredRangeExtent:l.height,t.flipScale?[s,s+n]:[s+n,s]}switch(e[0].type){case"vertex":case"segment":var a=e[0].parent.refBounds?e[0].parent.refBounds:e[0].parent.bounds;s=i.initialized?t.getRangeStart(e[0]):a.top,n=i.initialized?t.getRangeExtent(e[0]):t._preferredRangeExtent?t._preferredRangeExtent:a.height;break;default:s=i.initialized?t.getRangeStart(e[0]):Ve(e[0]).bounds.top+e[0].bounds.height/2,n=i.initialized?t.getRangeExtent(e[0]):t._preferredRangeExtent?t._preferredRangeExtent:450}return t.flipScale?[s,s+n]:[s+n,s]}}class Ji extends xe{constructor(e){super(e)}run(){super.run()}}class Qi extends xe{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof ze&&e.property==We.AXIS_ORIENTATION).element;e.createTicksLabels(e._args),e instanceof bi?this._runForEncoding(e):e instanceof Di&&this._runForLayout(e),de(e._path)}_runForLayout(e){let t=e.channel,i=e.elements[0].parent.layout&&e.elements[0].parent.layout.type==me.STACK?ce(e.elements):he(e.elements),r=[];if("x"===t){let t=e.orientation===fi?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===yi?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===me.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==me.STACK?ce(i):he(i),s=[],n=Ve(i[0]);if(n&&n.clipMask&&(r=n.clipMask),"x"===t){let t,n,a=gt(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===fi?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===fi?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=gt(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===yi?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===yi?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 er extends xe{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof ze&&e.property==We.AXIS_PATH_POSITION).element;e instanceof bi?this._runForEncoding(e):e instanceof Di&&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();de(e._ticks)}_runForLayout(e){let t=e.channel;if("x"==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=[[n,t],[n,t+i]]}}else if("y"===t){let t=e.orientation==yi?e._pathPos-e.tickOffset:e._pathPos+e.tickOffset,i=e.orientation==yi?-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===me.CLUSTER){let i=t._d3Root.leaves();const r=new Map(i.map(e=>[e.data[X],[e.x,e.y]]));for(let[i,s]of e._ticks.children.entries()){let n=e.elements[i].datum[X],a=Kt(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,i=he(e.elements);if("x"==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=[[e.scale.map(e._tickValues[r]),t],[e.scale.map(e._tickValues[r]),t+i]]}else if("width"==t){let t=e.orientation==gi?e._pathPos+e.tickOffset:e._pathPos-e.tickOffset,r=e.orientation==gi?e.tickSize:-e.tickSize;if(!!(e.isFlipped()||e.elements[0].type===n.Area&&"right"===e.elements[0].baseline))for(let[s,n]of e._ticks.children.entries())n.vertices=[[i.left+e.scale.rangeExtent-e.scale.map(e._tickValues[s]),t],[i.left+e.scale.rangeExtent-e.scale.map(e._tickValues[s]),t+r]];else for(let[s,n]of e._ticks.children.entries())n.vertices=[[e.scale.map(e._tickValues[s])+i.left,t],[e.scale.map(e._tickValues[s])+i.left,t+r]]}else if("y"===t){let t=e.orientation==yi?e._pathPos-e.tickOffset:e._pathPos+e.tickOffset,i=e.orientation==yi?-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==yi?e._pathPos-e.tickOffset:e._pathPos+e.tickOffset,r=e.orientation==yi?-e.tickSize:e.tickSize;if(!!(e.isFlipped()||e.elements[0].type===n.Area&&"top"===e.elements[0].baseline))for(let[s,n]of e._ticks.children.entries())n.vertices=[[t,i.top+e.scale.map(e._tickValues[s])],[t+r,i.top+e.scale.map(e._tickValues[s])]];else for(let[s,n]of e._ticks.children.entries()){let a=i.bottom-e.scale.map(e._tickValues[s]);n.vertices=[[t,a],[t+r,a]]}}else if("polarRadius"===t){let t=e.orientation==gi?e._pathPos+e.tickOffset:e._pathPos-e.tickOffset,i=e.orientation==gi?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 tr extends xe{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof ze&&e.property==We.AXIS_PATH_POSITION).element;e instanceof bi?this._runForEncoding(e):e instanceof Di&&this._runForLayout(e);for(let t of e._labels.children)t._updateBounds();de(e._labels)}_runForLayout(e){let t=e.channel;if("x"==t){let t=e.orientation==gi?e.labelOffset:-e.labelOffset,i=e.orientation==gi?[ue.CENTER,ue.TOP]:[ue.CENTER,ue.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=[ue.RIGHT,ue.MIDDLE])}}else if("y"===t){let t=e.orientation==yi?-e.labelOffset:e.labelOffset,i=e.orientation==yi?[ue.RIGHT,ue.MIDDLE]:[ue.LEFT,ue.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==ue.MIDDLE?n.y:n[e.tickAnchor],s._anchor=i,e._labelRotation&&(s._rotate=[e._labelRotation,s.x,s.y],s._anchor=[ue.RIGHT,i[1]])}}else if("angle"===t){let t=e.elements[0].parent.layout;if(t.type===me.CLUSTER){let i=t._d3Root.leaves();const r=new Map(i.map(e=>[e.data[X],[e.x,e.y]]));let s=5;for(let[i,n]of e._labels.children.entries()){let a=e.elements[i].datum[X];if(r.get(a)[0]<Math.PI){let o=Kt(r.get(a)[0])-90;n._anchor=[ue.LEFT,ue.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=Kt(r.get(a)[0])+90;n._anchor=[ue.RIGHT,ue.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,i=he(e.elements);if("x"==t){let t=e.orientation==gi?e.labelOffset:-e.labelOffset,i=e.orientation==gi?[ue.CENTER,ue.TOP]:[ue.CENTER,ue.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=[ue.RIGHT,i[1]])}else if("width"===t){let t=e.orientation==gi?e.labelOffset:-e.labelOffset,r=e.orientation==gi?[ue.CENTER,ue.TOP]:[ue.CENTER,ue.BOTTOM],s=!!(e.isFlipped()||e.elements[0].type===n.Area&&"right"===e.elements[0].baseline);for(let[n,a]of e._labels.children.entries())a.x=s?i.left+e.scale.rangeExtent-e.scale.map(e.labelValues[n]):e.scale.map(e.labelValues[n])+i.left,a._y=e._pathPos+t,a._anchor=r,e._labelRotation&&(a._rotate=[e._labelRotation,a.x,a.y],a._anchor=[ue.RIGHT,r[1]])}else if("y"===t){let t=e.orientation==yi?-e.labelOffset:e.labelOffset,i=e.orientation==yi?[ue.RIGHT,ue.MIDDLE]:[ue.LEFT,ue.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=[ue.RIGHT,i[1]])}else if("height"===t){let t=e.orientation==yi?-e.labelOffset:e.labelOffset,r=e.orientation==yi?[ue.RIGHT,ue.MIDDLE]:[ue.LEFT,ue.MIDDLE],s=e.elements[0].type===n.Area&&"top"===e.elements[0].baseline;for(let[n,a]of e._labels.children.entries())a.x=e._pathPos+t,a._y=s?i.top+e.scale.map(e.labelValues[n]):i.bottom-e.scale.map(e.labelValues[n]),a._anchor=r,e._labelRotation&&(a._rotate=[e._labelRotation,a.x,a.y],a._anchor=[ue.RIGHT,r[1]])}else if("polarRadius"==t){let t=e.orientation==gi?e.labelOffset:-e.labelOffset,i=e.orientation==gi?[ue.CENTER,ue.TOP]:[ue.CENTER,ue.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=[ue.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=[ue.CENTER,ue.MIDDLE],e._labelRotation&&(n._rotate=[e._labelRotation,n.x,n.y])}}}}function ir(e,t){let i=e.getElements(t);return i&&"vertexIndices"===i.type?i.groups[0].parent:i[0]}class rr extends xe{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=Ce(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=Be(e,!0);for(let e of i)de(e)}placeElements(e,t,i){let r=mt(e,"x"),s=mt(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 ue.LEFT:n=s.left-r.refBounds.left;break;case ue.CENTER:n=s.x-r.refBounds.x;break;case ue.RIGHT:n=s.right-r.refBounds.right}switch(t._cellVertAlignment){case ue.TOP:a=s.top-r.refBounds.top;break;case ue.MIDDLE:a=s.y-r.refBounds.y;break;case ue.BOTTOM:a=s.bottom-r.refBounds.bottom}Et(r,n,a)}if(r.length>0)for(let e of r)for(let i of e.scales){let r=ir(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=ir(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 Tt.RowFirst:r=Math.floor(a/s),o=a%s;break;case Tt.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 oe(o,c,l,h)}}}function sr(e,t,i,r){return[i*Math.cos(qt(r))+e,t-i*Math.sin(qt(r))]}function nr(e){if([n.Line,n.Circle,n.Rect,n.Area].indexOf(e.type)<0)return!1;if(e.dataScope){let t=Ce(e,e.scene);for(let e of t)if(k(e.dataScope)>1)return!0;return!1}return!0}function ar(e,t,i,r){switch(t){case"x":lr(e,i);break;case"y":hr(e,i);break;case"width":!function(e,t){e.resize(t,e.height)}(e,i);break;case"height":!function(e,t){e.resize(e.width,t)}(e,i);break;case"radius":e.radius=i;break;case"strength":e._strength=i;break;case"area":e.type===n.Circle?e.radius=Math.sqrt(i/Math.PI):e.type===n.Rect&&e.resize(Math.sqrt(i),Math.sqrt(i)),e._updateBounds();break;case"text":e._text=i;break;case"curveMode":e.curveMode=i;break;case"baseline":e.baseline=i;break;case"angle":[n.Arc,n.Pie].includes(e.type)&&function(e,t){e._endAngle=Zt(e._startAngle+t),e._sr=qt(e._startAngle),e._er=qt(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,i);break;case"startAngle":!function(e,t){let i=e.angle;e._startAngle=t,e._endAngle=Zt(e._startAngle+i),e._sr=qt(e._startAngle),e._er=qt(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,i);break;case"thickness":!function(e,t){or(e,e._innerRadius+t)}(e,i);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,i);break;case"outerRadius":or(e,i);break;case"polarAngle":
|
|
3
3
|
// as the vertex-level version of this pairing, polarAngle must be
|
|
4
|
-
e.polarAngle=i;break;case"polarRadius":{let t=er(r&&r._preferredOrigin?r._preferredOrigin[0]:e.parent.x,r&&r._preferredOrigin?r._preferredOrigin[1]:e.parent.y,i,e.polarAngle);sr(e,t[0]),nr(e,t[1]);break}case"visibility":e.visibility=i;break;case"src":e.src=i;break;case"path":e.path=i;break;case"vxOpacity":if(e instanceof lt)for(let r of e.children)ir(r,t,i);else e.vxOpacity=i;break;default:if("vertex"===e.type)e[t]=i;else if(e instanceof lt)for(let r of e.children)ir(r,t,i);else{if(e.styles[t]==i)return;e.styles[t]=i}}"vertex"===e.type?e.parent._dirty=!0:e._dirty=!0}function rr(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 sr(e,t){"vertex"==e.type?e.x=t:xi(e,t-e.x,0)}function nr(e,t){"vertex"==e.type?e.y=t:xi(e,0,t-e.y)}class ar extends we{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 or extends xe{constructor(e){super(e)}storeValues(e,t){this._storedValues={};let i=Ce(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 Ui),t=this.outputVar,i=e?e.getEncoding(t.channel,t.element):null,r=t.channel,s=this.inputVars.filter(e=>e instanceof ar),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 de(t.element.parent);let l=Ce(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){de(["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=ke(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 oe(r.flipScale?i.range[1]:i.range[0],s.top,i.rangeExtent,s.height):"y"===t&&(e._refBounds=new oe(s.left,r.flipScale?i.range[0]:i.range[1],s.width,i.rangeExtent))}_updateRefBounds(e,t,i){switch(this.outputVar.channel){case"width":e._refBounds.setWidth(t.rangeExtent);break;case"height":e._refBounds.setHeight(t.rangeExtent);break;case"radius":e._refBounds.setWidth(2*t.rangeExtent,ue.CENTER),e._refBounds.setHeight(2*t.rangeExtent,ue.MIDDLE);break;case"x":if("vertex"==e.type||"segment"==e.type){let r=e.parent._refBounds;e.parent._refBounds=new oe(i.flipScale?t.range[1]:t.range[0],r.top,t.rangeExtent,r.height)}else if(e._refBounds)if("band"===t.type){let r=t.map(i.attrValues[e.id]),s=e._refBounds;e._refBounds=new oe(r-e.width/2,s.top,e.width,s.height)}else{let r=e.parent;for(;r&&(!r.layout||r.layout.type!==me.GRID);)r=r.parent;if(r){let r=e._refBounds;e._refBounds=new oe(i.flipScale?t.range[1]:t.range[0],r.top,t.rangeExtent,r.height)}}break;case"y":if("vertex"==e.type||"segment"==e.type){let r=e.parent._refBounds;e.parent._refBounds=new oe(r.left,i.flipScale?t.range[0]:t.range[1],r.width,t.rangeExtent)}else if(e._refBounds){let s=e.parent;for(;s&&(!s.layout||s.layout.type!==me.GRID);)s=s.parent;if(s){let s=e._refBounds,n=r.min(t.range);e._refBounds=new oe(s.left,i.flipScale?t.range[0]:n,s.width,t.rangeExtent)}}}}_doMapping(e,t,i,r){switch(this.outputVar.channel){case"width":t.domain[0]<0&&e instanceof Ht?function(e,t,i){let r=e.refBounds.left+t.map(0),s=e.refBounds.left+t.map(i[e.id]);xi(e.leftSegment,r-e.leftSegment.x,0),xi(e.rightSegment,s-e.rightSegment.x,0)}(e,t,i):t.domain[0]<0&&e instanceof Vt||(e.type===n.Area?function(e,t,i){let r=e.baseline;if(e.orientation===ft){let s=e._vertices.length/2;switch(r){case"left":Ei(e,s,e._vertices.length,e.refBounds.left),Ai(e,0,s,r=>e.refBounds.left+t.map(i[ke(e,r)]));break;case"right":Ai(e,s,e._vertices.length,r=>e.refBounds.right-t.map(i[ke(e,r)])),Ei(e,0,s,e.refBounds.right);break;case"center":console.log("center"),Ai(e,s,e._vertices.length,r=>e.refBounds.center-t.map(i[ke(e,r)])/2),Ai(e,0,s,r=>e.refBounds.center+t.map(i[ke(e,r)])/2)}}}(e,t,i):this._doStandardMapping(e,t,i,r));break;case"height":t.domain[0]<0&&e instanceof Ht?function(e,t,i){let r=e.refBounds.bottom-t.map(0),s=e.refBounds.bottom-t.map(i[e.id]);xi(e.bottomSegment,0,r-e.bottomSegment.y),xi(e.topSegment,0,s-e.topSegment.y)}(e,t,i):t.domain[0]<0&&e instanceof Vt?function(e,t,i){let r=e._vertices.length/2;Si(e,0,r,r=>e.refBounds.bottom-t.map(i[ke(e,r)])),Ci(e,r,e._vertices.length,e.refBounds.bottom-t.map(0))}(e,t,i):e.type===n.Area?function(e,t,i){let r=e.baseline;if(e.orientation===pt){let s=e._vertices.length/2;switch(r){case"top":Si(e,s,e._vertices.length,r=>e.refBounds.top+t.map(i[ke(e,r)])),Ci(e,0,s,e.refBounds.top);break;case"middle":Si(e,0,s,r=>e.refBounds.middle-t.map(i[ke(e,r)])/2),Si(e,s,e._vertices.length,r=>e.refBounds.middle+t.map(i[ke(e,r)])/2);break;default:Si(e,0,s,r=>e.refBounds.bottom-t.map(i[ke(e,r)])),Ci(e,s,e._vertices.length,e.refBounds.bottom)}}}(e,t,i):this._doStandardMapping(e,t,i,r);break;case"text":this._doTextMapping(e,i);break;case"fillGradient":!function(e,t,i,r){let s=e._vertices._ids.map((t,r)=>i[ke(e,r)]),n=d3.min(s),a=d3.max(s),o="horizontal"===e.orientation?new Kt({x1:0,y1:100,x2:0,y2:0}):new Kt({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,i,r);break;case"strokeGradient":!function(e,t,i){let r=[];for(let s=0;s<e._vertices.length;s++)r.push(t.map(i[ke(e,s)]));e.strokeColor=new Zt(r)}(e,t,i);break;default:this._doStandardMapping(e,t,i,r)}}_doTextMapping(e,t){ir(e,this.outputVar.channel,t[e.id])}_doStandardMapping(e,t,i,r){let s=this.outputVar.channel,n=t.map(i[e.id]);ir(e,s,n,r),e instanceof Ct&&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),ir(t,i,s)}}class lr extends xe{constructor(e){super(e)}run(){let e=this.outputVar.element;e.updateValues(),e.scale?this._runForEncoding(e):this._runForLayout(e),de(e)}_runForLayout(e){let t=e.channel,i=he(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=he(e.elements),r=[];if("x"===t){let t,s,n=ui(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=ui(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 hr extends xe{constructor(e){super(e)}run(){let e=this.outputVar.element;e.updatePoints(),e._dirty=!0,de(e)}}class cr extends xe{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=Be(e)[0],i=Ce(e.parent);for(let e of i){let i=e.layout;if(!i)return;switch(t.type){case n.Rect:case n.Circle:case n.Image:case n.Symbol:this._stackRects(e,i);break;case n.Area:e.children[0].orientation===pt?this._stackAreasVert(e,i):this._stackAreasHorz(e,i);break;case n.Arc:case n.Pie:t.parent.classId===e.classId&&this._stackArcs(e,i)}}de(t)}_stackArcs(e,t){if(t.orientation===gt){let t=90;if((this._direction?this._direction:bt.Clockwise)===bt.Clockwise)for(let i of e.children){let e=Lt(t-i.angle);ir(i,"startAngle",e),t=e}else for(let i of e.children){let e=Lt(t+i.angle);ir(i,"startAngle",e),t=e}}else if(t.orientation===yt){let t=d3.min(e.children.map(e=>e.innerRadius));for(let i of e.children){let e=i.outerRadius-i.innerRadius;ir(i,"innerRadius",t),ir(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===ue.TOP?r.top:r.bottom,n=t.vertCellAlignment===ue.TOP?1:-1;if(0===i.length)return;t.vertCellAlignment===ue.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;xi(i,0,h-i.y),xi(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===ue.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;xi(i,0,n-r.bottom),xi(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==ft)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,xi(r,s,n),r._updateBounds();let a=0,o=0;if(!gi(r))switch(t._horzCellAlignment){case ue.LEFT:a=l-r.bounds.left;break;case ue.CENTER:a=l+c/2-r.bounds.x;break;case ue.RIGHT:a=l+c-r.bounds.right}xi(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,xi(r,s,n),r._updateBounds();let a=0,o=0;if(!fi(r))switch(t._vertCellAlignment){case ue.TOP:o=h-r.bounds.top;break;case ue.MIDDLE:o=h+d/2-r.bounds.y;break;case ue.BOTTOM:o=h+d-r.bounds.bottom}xi(r,a,o)}}}class dr extends xe{constructor(e){super(e)}run(){super.run()}}class ur extends xe{constructor(e){super(e)}run(){let e=this._binConfig.attribute,t=this._binConfig.startAttr,i=this._binConfig.endAttr,s=this._binConfig.binIdAttr,n=this.inputVars[0].dataset,a=this.outputVar.dataset,o=n.values(e),l=r.bin();null!=this._binConfig?.numBins&&(l=l.thresholds(this._binConfig.numBins));let c=l(o);this._binConfig.actualNumBins=c.length;let d=String(c.length-1).length,u=e=>String(e).padStart(d,"0"),_=this._findBin,p=o.map(e=>_(e,c).x0),f=o.map(e=>_(e,c).x1),g=o.map(e=>{let t=c.indexOf(_(e,c));return u(t)}),y=c.map((e,t)=>u(t));a.addAttr(t,h.Number,p),a.addAttr(i,h.Number,f),a.addAttr(s,h.String,g),a.order(s,y)}_findBin(e,t){for(let i of t)if(i.indexOf(e)>=0)return i}}class _r extends we{constructor(e,t){super(e),this._dataset=t}get dataset(){return this._dataset}}class pr extends xe{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof _r),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=ee(r);t.load(i.data.filter(e=>s.testTuple(e)))}}function fr(e,t,i,r){let s=r.type(i);if(s!=h.String&&s!=h.Date&&s!=h.Integer)throw new Error("Repopulate only works on a string or date attribute: "+i+" is "+s);let n=Ce(t);for(let e of n){let t=B(e.dataScope?e.dataScope:V(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=Gi(e._children[t%a]);e.addChild(i)}e.children.forEach((e,i)=>e.dataScope=t[i])}}class gr extends xe{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;Pe(this._area);return function(e,t,i,r){let s=r.type(i),n=V(r),a=B(n,i,s===h.Number);s!==h.Number&&s!==h.Date||a.sort((e,t)=>e.filters[i]>t.filters[i]?1:-1),1===a.length&&a.push(a[0]);let o=a.length,l=t.refBounds??t.bounds,{left:c,top:d,right:u,bottom:_}=l,p=u-c,f=_-d,g=t.orientation===ft,y=[];if(o>0){for(let e=0;e<o;e++)y.push(g?[u,d+e*f/(o-1)]:[c+e*p/(o-1),d]);for(let e=0;e<o;e++)y.push(g?[c,d+(o-1-e)*f/(o-1)]:[c+(o-1-e)*p/(o-1),_])}t.vertices=y;for(let e=0;e<t._vertices.length;e++){let i=e<o?a[e]:a[2*o-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[ke(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[ke(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;Pe(i);i.dataScope=void 0,fr(0,i,this._repeatAttr,t),i.dataScope=V(t);for(let e of ci(i.children[0],!0))e.refreshElementMappings();if(i.layout)for(let e of i.layout.refElements)e instanceof Pi&&(e._elems=i.children.slice());this.needsFullRender=!0}}class yr extends xe{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e.type===Ee.AFFIXATION).affixation,t=e.base,i=e.element,r=Ce(t),s=Ce(i),n=e.channels,a=e.attribute;if(pe(i)&&pe(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=Be(i,!0);for(let e of o)de(e)}_handlePolar(e,t,i){let r="polarRadius",s=i.hasChannel(r)?i.getBaseAnchor(r):ue.MIDDLE,a=i.hasChannel(r)?i.getElementAnchor(r):ue.MIDDLE,o=i.hasChannel("angle")?i.getBaseAnchor("angle"):ue.CENTER;i.hasChannel("angle")?i.getElementAnchor("angle"):ue.CENTER;let l=i.hasChannel(r)?i.getOffset(r):0,h=i.hasChannel("angle")?i.getOffset("angle"):0;if([n.Arc,n.Ring].indexOf(t[0].type)>=0&&e[0].type==n.SimpleText)for(let i=0;i<e.length;i++){let r=t[i],a=e[i],h=s===ue.MIDDLE?(r.outerRadius+r.innerRadius)/2:s===ue.TOP?r.outerRadius-5:r.innerRadius+5;if(h+=l,r.type===n.Arc){let e=er(r.x,r.y,h,r.startAngle),t=er(r.x,r.y,h,r.endAngle);r.endAngle>=180&&r.endAngle<=360?a._textPath=["M",e[0],e[1],"A",h,h,r.angle,r.angle>=180?1:0,0,t[0],t[1]].join(" "):a._textPath=["M",t[0],t[1],"A",h,h,r.angle,r.angle>=180?1:0,1,e[0],e[1]].join(" ")}else if(r.type===n.Ring){let e=275,t=265,i=350,s=er(r.x,r.y,h,e),n=er(r.x,r.y,h,t);a._textPath=["M",n[0],n[1],"A",h,h,i,1,1,s[0],s[1]].join(" ")}a.textPathOffset=o===ue.LEFT?"0%":"50%"}else for(let i=0;i<e.length;i++){let r,c,d=t[i],u=e[i];d.type==n.Arc||d.type==n.Ring?(c="left"==o?d.endAngle+h:"center"==o?d.startAngle+d.angle/2+h:d.startAngle+h,r="top"==s?d.outerRadius+l:"bottom"==s?d.innerRadius+l:(d.outerRadius+d.innerRadius)/2+l):d.type==n.Circle&&(c=90,r="top"==s?d.radius+l:"bottom"==s?l:d.radius/2+l),xi(u,d.x-u.x,d.y-r-u.bounds[a]),u._rotate=[90-c,d.x,d.y]}}_handleXY(e,t,i,r,s,a){for(let o=0;o<t.length;o++){let l,h=i[o],c=t[o];if(kt(h)){l=St(h,[ue.LEFT,ue.TOP].includes(s)?0:[ue.CENTER,ue.MIDDLE].includes(s)?.5:1)[e]}else l=h.bounds[s]+a;t[0].type===n.SimpleText?(c.anchor["x"==e?0:1]=r,ir(c,e,l)):"x"==e?xi(c,l-c.bounds[r],0):xi(c,0,l-c.bounds[r])}}}class mr extends we{constructor(e,t){super(e),this._affx=t}get affixation(){return this._affx}}class br extends xe{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,a=this.args,o=null!=a.min?a.min:s.summary(i).min,l=null!=a.max?a.max:s.summary(i).max,c=o,d=[];for(;c<l;)d.push(c),c+=a.interval;d.push(c);let u={},_={};if(a.groupBy)for(let e of s.data){let t=a.groupBy.map(t=>e[t]).join("-");t in u||(u[t]=[],_[t]=a.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=xr(vr(a.bandwidth),d,u[e]);for(let s of t){let t={};""!==e&&a.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]=h.Number,a.groupBy)for(let e of a.groupBy)f[e]=s.type(e);n.initialize(p,n.url,f)}}function xr(e,t,i){return t.map(t=>[t,r.mean(i,i=>e(t-i))])}function vr(e){return t=>Math.abs(t/=e)<=1?.75*(1-t*t)/e:0}class wr extends xe{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof _r);if(!e)return;let t=e.dataset,i=this.outputVar.dataset;this._spec.fn(t,i,this._spec)}}class Er extends xe{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=Ce(e.parent);for(let e of t){let t=e.layout;if(!t)return;let i=e.children.map(e=>({name:e.id,radius:e.radius,itm:e})),s=i.reduce((e,t)=>e+Math.pow(t.radius,2),0),n=Math.sqrt(s);void 0===t._width&&(t._width=n),void 0===t._height&&(t._height=n);let a=r.hierarchy({name:"root",children:i}).sum(e=>e.radius?e.radius:0).sort((e,t)=>t.value-e.value);r.pack().size([t._width,t._height]).radius(e=>e.value)(a);for(let e of a.children){let i=e.data.itm;xi(i,t._x-a.x+e.x-i.x,t._y-a.y+e.y-i.y)}}let i=Be(e,!0);for(let e of i)de(e)}}class Ar extends xe{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof ze&&e.property==We.AXIS_PATH_POSITION).element;e instanceof si?this._runForEncoding(e):e instanceof Pi&&this._runForLayout(e),de(e._title)}_runForEncoding(e){let t=e.channel,i=he(e.elements);if("x"==t)e._title.x=(e.scale.range[0]+e.scale.range[1])/2,e._title._y=e.orientation==ti?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==ti?e._pathPos+e.titleOffset:e._pathPos-e.titleOffset;else if("y"===t)e._rotateYTitle?(e._title.x=e.orientation==ii?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==ii?[-90,e._title._x,e._title._y]:[90,e._title._x,e._title._y]):(e._title.x=e.orientation==ii?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==ii?[-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==ti?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==me.STACK?ce(e.elements):he(e.elements);if("x"==t)e._title.x=i.center,e._title._y=e.orientation==ti?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==ii?[-90,i.center,i.middle]:[90,i.center,i.middle];else if("angle"===t){let t=e.elements[0].parent.layout;t.type===me.CLUSTER&&(e._title.x=t.x,e._title._y=t.y)}}}class Cr extends Fi{constructor(e){super(e)}run(){super.run();let e,t=this.vars.find(e=>e.type===Ee.ALIGNMENT).alignment,i=t.anchor,s=t.elements;i==ue.Top||i==ue.LEFT?e=r.min(s.map(e=>e.bounds[i])):i==ue.BOTTOM||i==ue.RIGHT?e=r.max(s.map(e=>e.bounds[i])):i!=ue.CENTER&&i!=ue.MIDDLE||(e=r.mean(s.map(e=>e.bounds[i])));for(let r of s){let s=bi(r,t.channel);if(s){let n=e-r.bounds[i];xi(s,"x"===t.channel?n:0,"x"===t.channel?0:n)}}for(let e of s)de(e)}}class Sr extends we{constructor(e,t){super(e),this._aln=t}get alignment(){return this._aln}}class kr extends xe{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=Ce(e.parent);for(let e of t){let t=e.layout;if(!t)continue;let i=Y(e.children[0]);if(!i)continue;let s=i.linkList.map(e=>({source:i.getNode(e.source),target:i.getNode(e.target)})),n=r.forceSimulation(i.nodeList).force("charge",r.forceManyBody().strength(-t._repulsion)).force("link",r.forceLink(s).id(e=>e.id).distance(t._linkDistance)).force("x",r.forceX()).force("y",r.forceY()).force("center",r.forceCenter(t._x,t._y).strength(t._attraction));n.stop(),n.tick(t._iterations);for(let t=0;t<e.children.length;t++){let r=e.children[t],s=i.nodeList[t];xi(r,s.x-r.x,s.y-r.y)}}let i=Be(e,!0);for(let e of i)de(e)}}class Rr extends xe{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=Ce(e);switch(e.type){case n.Arc:this._updateArcLinks(t);break;case n.BezierCurve:this._updateBezierLinks(t);break;case n.BundledPath:this._updateBundledLinks(t);break;case n.Chord:this._updateChordLinks(t);break;case n.Line:default:this._updateLineLinks(t)}de(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=Pt(e.x,e.y,t._x,t._y),s=Pt(i.x,i.y,t._x,t._y);t.direction===bt.CLOCKWISE&&([r,s]=[s,r]),ir(t,"startAngle",r),ir(t,"angle",Math.abs(s-r))}}_updateBezierLinks(e){let t=this._inputVars[0].element,i=Ce(t),r=t.parent.layout;r.type===me.DIRECTED||r.type===me.TIDYTREE?this._updateBezierLinksForDirectedGraph(i,e,r):r.type===me.CLUSTER&&this._updateBezierLinksForClusteredGraph(i,e,r)}_updateBezierLinksForClusteredGraph(e,t,i){const s=i._d3Root.descendants(),n=new Map(s.map(e=>[Tr(e),e])),a=new Map(s.map(e=>[e.data[X],Tr(e)]));if(i.isRadial()){const e=r.linkRadial().angle(e=>e.x).radius(e=>e.y);for(let r of t){let t=r.source,s=r.target,o=t.datum[X],l=s.datum[X],h=n.get(a.get(o)),c=n.get(a.get(l));r._d=Tt(e({source:h,target:c}),i.x,i.y)}}else if(i.orientation===ft){const e=r.linkVertical().x(e=>e.x).y(e=>e.y);for(let r of t){let t=r.source,s=r.target,o=t.datum[X],l=s.datum[X],h=n.get(a.get(o)),c=n.get(a.get(l));r._d=Tt(e({source:h,target:c}),i.left-i._x0,i.top)}}else if(i.orientation===pt){const e=r.linkHorizontal().x(e=>e.y).y(e=>e.x);for(let r of t){let t=r.source,s=r.target,o=t.datum[X],l=s.datum[X],h=n.get(a.get(o)),c=n.get(a.get(l));r._d=Tt(e({source:h,target:c}),i.left,i.top-i._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===mt.Left2Right||i.direction===mt.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===pt?e.vertices=[[t,r],[(t+s)/2,r],[t,l],[s,l]]:e.orientation===ft&&(e.vertices=[[t,r],[t,(r+l)/2],[s,r],[s,l]])}}_updateBundledLinks(e){let t=this._inputVars[0].element.parent.layout;if(t.type!==me.CLUSTER)throw"Bundled links must work on a cluster layout";let i=t._d3Root.leaves();const s=new Map(i.map(e=>[Tr(e),e])),n=new Map(i.map(e=>[e.data[X],Tr(e)])),a=r.lineRadial().curve(r.curveBundle.beta(e[0]._strength)).radius(e=>e.y).angle(e=>e.x);for(let i of e){let e=i.source.datum[X],r=i.target.datum[X],o=s.get(n.get(e)),l=s.get(n.get(r));(o.outgoing??=[]).push([o,l]),l.incoming??=[];let h=o.path(l);i._d=Tt(a(h),t.x,t.y),i._dirty=!0}}_updateChordLinks(e){for(let t of e){let e=t.source,i=t.target,r=er(e.x,e.y,e.innerRadius,e.startAngle),s=er(e.x,e.y,e.innerRadius,e.endAngle),n=er(i.x,i.y,i.innerRadius,i.startAngle),a=er(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 Tr(e){return`${e.parent?Tr(e.parent)+".":""}${e.data[X]}`}var Or="\0";function Ir(e,t){e[t]?e[t]++:e[t]=1}function Nr(e,t){--e[t]||delete e[t]}function Lr(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 Pr(e,t){return Lr(e,t.v,t.w,t.name)}var Vr=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[Or]={})}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]=Or,this._children[e]={},this._children[Or][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=Or;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!==Or)return t}}children(e=Or){if(this._isCompound){var t=this._children[e];if(t)return Object.keys(t)}else{if(e===Or)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=Lr(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,Ir(this._preds[t],e),Ir(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?Pr(this._isDirected,arguments[0]):Lr(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?Pr(this._isDirected,arguments[0]):Lr(this._isDirected,e,t,i);return Object.hasOwn(this._edgeLabels,r)}removeEdge(e,t,i){var r=1===arguments.length?Pr(this._isDirected,arguments[0]):Lr(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],Nr(this._preds[t],e),Nr(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))}},Br={Graph:Vr,version:"2.2.4"},Dr=Vr,Mr={write:function(e){var t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:Gr(e),edges:zr(e)};void 0!==e.graph()&&(t.value=structuredClone(e.graph()));return t},read:function(e){var t=new Dr(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 Gr(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 zr(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 jr=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 Fr=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}},Wr=Fr,Ur=function(e,t,i,r){return function(e,t,i,r){var s,n,a={},o=new Wr,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||Yr,r||function(t){return e.outEdges(t)})},Yr=()=>1;var Hr=Ur,Xr=function(e,t,i){return e.nodes().reduce(function(r,s){return r[s]=Hr(e,s,t,i),r},{})};var qr=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 Kr=qr,Zr=function(e){return Kr(e).filter(function(t){return t.length>1||1===t.length&&e.hasEdge(t[0],t[0])})};var $r=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||Jr,i||function(t){return e.outEdges(t)})},Jr=()=>1;function Qr(e){var t={},i={},r=[];if(e.sinks().forEach(function s(n){if(Object.hasOwn(i,n))throw new es;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 es;return r}class es extends Error{constructor(){super(...arguments)}}var ts=Qr;Qr.CycleException=es;var is=ts;var rs=function(e,t,i){Array.isArray(t)||(t=[t]);var r=e.isDirected()?t=>e.successors(t):t=>e.neighbors(t),s="post"===i?ss:ns,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 ss(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]),as(t(n[0]),e=>s.push([e,!1])))}}function ns(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),as(t(n),e=>s.push(e)))}}function as(e,t){for(var i=e.length;i--;)t(e[i],i,e);return e}var os=rs;var ls=rs;var hs=Vr,cs=Fr;var ds={Graph:Br.Graph,json:Mr,alg:{components:jr,dijkstra:Ur,dijkstraAll:Xr,findCycles:Zr,floydWarshall:$r,isAcyclic:function(e){try{is(e)}catch(e){if(e instanceof is.CycleException)return!1;throw e}return!0},postorder:function(e,t){return os(e,t,"post")},preorder:function(e,t){return ls(e,t,"pre")},prim:function(e,t){var i,r=new hs,s={},n=new cs;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:qr,topsort:ts},version:Br.version};function us(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function _s(e,t){if("_next"!==e&&"_prev"!==e)return t}let ps=ds.Graph,fs=class{constructor(){let e={};e._next=e._prev=e,this._sentinel=e}dequeue(){let e=this._sentinel,t=e._prev;if(t!==e)return us(t),t}enqueue(e){let t=this._sentinel;e._prev&&e._next&&us(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,_s)),i=i._prev;return"["+e.join(", ")+"]"}};var gs=function(e,t){if(e.nodeCount()<=1)return[];let i=function(e,t){let i=new ps,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 fs),a=r+1;return i.nodes().forEach(e=>{bs(n,a,i.node(e))}),{graph:i,buckets:n,zeroIdx:a}}(e,t||ys);return function(e,t,i){let r,s=[],n=t[t.length-1],a=t[0];for(;e.nodeCount();){for(;r=a.dequeue();)ms(e,t,i,r);for(;r=n.dequeue();)ms(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(ms(e,t,i,r,!0));break}}return s}(i.graph,i.buckets,i.zeroIdx).flatMap(t=>e.outEdges(t.v,t.w))};let ys=()=>1;function ms(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,bs(t,i,o)}),e.outEdges(r.v).forEach(r=>{let s=e.edge(r),n=r.w,a=e.node(n);a.in-=s,bs(t,i,a)}),e.removeNode(r.v),n}function bs(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 xs=ds.Graph;var vs={addBorderNode:function(e,t,i,r){let s={width:0,height:0};arguments.length>=4&&(s.rank=i,s.order=r);return ws(e,"border",s,t)},addDummyNode:ws,applyWithChunking:As,asNonCompoundGraph:function(e){let t=new xs({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=Rs(Cs(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:Cs,normalizeRanks:function(e){let t=e.nodes().map(t=>{let i=e.node(t).rank;return void 0===i?Number.MAX_VALUE:i}),i=As(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 Ts(e.nodes(),t)},range:Rs,removeEmptyRanks:function(e){let t=e.nodes().map(t=>e.node(t).rank),i=As(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 xs).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 Ts(e.nodes(),t)},time:function(e,t){let i=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-i)+"ms")}},uniqueId:ks,zipObject:Ts};function ws(e,t,i,r){for(var s=r;e.hasNode(s);)s=ks(r);return i.dummy=t,e.setNode(s,i),s}const Es=65535;function As(e,t){if(t.length>Es){const i=function(e,t=Es){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 Cs(e){const t=e.nodes().map(t=>{let i=e.node(t).rank;return void 0===i?Number.MIN_VALUE:i});return As(Math.max,t)}let Ss=0;function ks(e){return e+""+ ++Ss}function Rs(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 Ts(e,t){return e.reduce((e,i,r)=>(e[i]=t[r],e),{})}let Os=gs,Is=vs.uniqueId;var Ns={run:function(e){("greedy"===e.graph().acyclicer?Os(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,Is("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 Ls=vs;var Ps={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=Ls.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:Vs}=vs;var Bs={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=Vs(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 Ds=ds.Graph,Ms=Bs.slack,Gs=function(e){var t,i,r=new Ds({directed:!1}),s=e.nodes()[0],n=e.nodeCount();r.setNode(s,{});for(;zs(r,e)<n;)t=js(r,e),i=r.hasNode(t.v)?Ms(e,t):-Ms(e,t),Fs(r,e,i);return r};function zs(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)||Ms(t,s)||(e.setNode(a,{}),e.setEdge(r,a,{}),i(a))})}),e.nodeCount()}function js(e,t){return t.edges().reduce((i,r)=>{let s=Number.POSITIVE_INFINITY;return e.hasNode(r.v)!==e.hasNode(r.w)&&(s=Ms(t,r)),s<i[0]?[s,r]:i},[Number.POSITIVE_INFINITY,null])[1]}function Fs(e,t,i){e.nodes().forEach(e=>t.node(e).rank+=i)}var Ws=Gs,Us=Bs.slack,Ys=Bs.longestPath,Hs=ds.alg.preorder,Xs=ds.alg.postorder,qs=vs.simplify,Ks=Zs;function Zs(e){e=qs(e),Ys(e);var t,i=Ws(e);for(Qs(i),$s(i,e);t=tn(i);)sn(i,e,t,rn(i,e,t))}function $s(e,t){var i=Xs(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=Js(e,t,i)}(e,t,i))}function Js(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 Qs(e,t){arguments.length<2&&(t=e.nodes()[0]),en(e,{},1,t)}function en(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=en(e,t,i,s,r))}),a.low=n,a.lim=i++,s?a.parent=s:delete a.parent,i}function tn(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function rn(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===nn(e,e.node(t.v),o)&&l!==nn(e,e.node(t.w),o));return h.reduce((e,i)=>Us(t,i)<Us(t,e)?i:e)}function sn(e,t,i,r){var s=i.v,n=i.w;e.removeEdge(s,n),e.setEdge(r.v,r.w,{}),Qs(e),$s(e,t),function(e,t){var i=e.nodes().find(e=>!t.node(e).parent),r=Hs(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 nn(e,t,i){return i.low<=t.lim&&t.lim<=i.lim}Zs.initLowLimValues=Qs,Zs.initCutValues=$s,Zs.calcCutValue=Js,Zs.leaveEdge=tn,Zs.enterEdge=rn,Zs.exchangeEdges=sn;var an=Bs.longestPath,on=Gs,ln=Ks,hn=function(e){var t=e.graph().ranker;if(t instanceof Function)return t(e);switch(e.graph().ranker){case"network-simplex":default:dn(e);break;case"tight-tree":!function(e){an(e),on(e)}(e);break;case"longest-path":cn(e);case"none":}};var cn=an;function dn(e){ln(e)}var un=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 _n=vs;var pn={run:function(e){let t=_n.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=_n.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=>fn(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 fn(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=_n.addBorderNode(e,"_bt"),h=_n.addBorderNode(e,"_bb"),c=e.node(a);e.setParent(l,a),c.borderTop=l,e.setParent(h,a),c.borderBottom=h,o.forEach(o=>{fn(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 gn=vs;var yn=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)mn(e,"borderLeft","_bl",i,s,t),mn(e,"borderRight","_br",i,s,t)}})};function mn(e,t,i,r,s,n){let a={width:0,height:0,rank:n,borderType:t},o=s[t][n-1],l=gn.addDummyNode(e,"border",a,i);s[t][n]=l,e.setParent(l,r),o&&e.setEdge(o,l,{weight:1})}function bn(e){e.nodes().forEach(t=>xn(e.node(t))),e.edges().forEach(t=>xn(e.edge(t)))}function xn(e){let t=e.width;e.width=e.height,e.height=t}function vn(e){e.y=-e.y}function wn(e){let t=e.x;e.x=e.y,e.y=t}let En=vs;var An=function(e){let t={},i=e.nodes().filter(t=>!e.children(t).length),r=i.map(t=>e.node(t).rank),s=En.applyWithChunking(Math.max,r),n=En.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 Cn=vs.zipObject;function Sn(e,t,i){let r=Cn(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 kn=vs;let Rn=vs;function Tn(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 On=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}})},In=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=>kn.pick(e,["vs","i","barycenter","weight"]))}(Object.values(i).filter(e=>!e.indegree))},Nn=function(e,t){let i=Rn.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=Tn(n,s,l),r.forEach(e=>{l+=e.vs.length,n.push(e.vs),a+=e.barycenter*e.weight,o+=e.weight,l=Tn(n,s,l)});var h;let c={vs:n.flat(!0)};o&&(c.barycenter=a/o,c.weight=o);return c};var Ln=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=On(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=In(c,r);!function(e,t){e.forEach(e=>{e.vs=e.vs.flatMap(e=>t[e]?t[e].vs:e)})}(d,h);let u=Nn(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 Pn=ds.Graph,Vn=vs;var Bn=function(e,t,i,r){r||(r=e.nodes());let s=function(e){var t;for(;e.hasNode(t=Vn.uniqueId("_root")););return t}(e),n=new Pn({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 Dn=An,Mn=function(e,t){let i=0;for(let r=1;r<t.length;++r)i+=Sn(e,t[r-1],t[r]);return i},Gn=Ln,zn=Bn,jn=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}})},Fn=ds.Graph,Wn=vs;var Un=function e(t,i){if(i&&"function"==typeof i.customOrder)return void i.customOrder(t,e);let r=Wn.maxRank(t),s=Yn(t,Wn.range(1,r+1),"inEdges"),n=Yn(t,Wn.range(r-1,-1,-1),"outEdges"),a=Dn(t);if(Xn(t,a),i&&i.disableOptimalOrderHeuristic)return;let o,l=Number.POSITIVE_INFINITY;for(let e=0,i=0;i<4;++e,++i){Hn(e%2?s:n,e%4>=2),a=Wn.buildLayerMatrix(t);let r=Mn(t,a);r<l&&(i=0,o=Object.assign({},a),l=r)}Xn(t,o)};function Yn(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 zn(e,t,i,r.get(t)||[])})}function Hn(e,t){let i=new Fn;e.forEach(function(e){let r=e.graph().root,s=Gn(e,r,i,t);s.vs.forEach((t,i)=>e.node(t).order=i),jn(e,i,s.vs)})}function Xn(e,t){Object.values(t).forEach(t=>t.forEach((t,i)=>e.node(t).order=i))}let qn=ds.Graph,Kn=vs;var Zn=function(e){let t,i=Kn.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||$n(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;Kn.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)&&$n(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]&&!Jn(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 qn,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=Kn.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=Kn.applyWithChunking(Math.min,i),s=Kn.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-Kn.applyWithChunking(Math.min,l);"l"!==n&&(h=s-Kn.applyWithChunking(Math.max,l)),h&&(e[a]=Kn.mapValues(o,e=>e+h))})})}(s,n),function(e,t){return Kn.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 $n(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 Jn(e,t,i){if(t>i){let e=t;t=i,i=e}return!!e[t]&&Object.hasOwn(e[t],i)}let Qn=vs,ea=Zn;let ta=Ns,ia=Ps,ra=hn,sa=vs.normalizeRanks,na=un,aa=vs.removeEmptyRanks,oa=pn,la=yn,ha={adjust:function(e){let t=e.graph().rankdir.toLowerCase();"lr"!==t&&"rl"!==t||bn(e)},undo:function(e){let t=e.graph().rankdir.toLowerCase();"bt"!==t&&"rl"!==t||function(e){e.nodes().forEach(t=>vn(e.node(t))),e.edges().forEach(t=>{let i=e.edge(t);i.points.forEach(vn),Object.hasOwn(i,"y")&&vn(i)})}(e);"lr"!==t&&"rl"!==t||(!function(e){e.nodes().forEach(t=>wn(e.node(t))),e.edges().forEach(t=>{let i=e.edge(t);i.points.forEach(wn),Object.hasOwn(i,"x")&&wn(i)})}(e),bn(e))}},ca=Un,da=function(e){(function(e){let t=Qn.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=Qn.asNonCompoundGraph(e)),Object.entries(ea(e)).forEach(([t,i])=>e.node(t).x=i)},ua=vs,_a=ds.Graph;var pa=function(e,t){let i=t&&t.debugTiming?ua.time:ua.notime;i("layout",()=>{let r=i(" buildLayoutGraph",()=>function(e){let t=new _a({multigraph:!0,compound:!0}),i=Aa(e.graph());return t.setGraph(Object.assign({},ga,Ea(i,fa),ua.pick(i,ya))),e.nodes().forEach(i=>{const r=Ea(Aa(e.node(i)),ma);Object.keys(ba).forEach(e=>{void 0===r[e]&&(r[e]=ba[e])}),t.setNode(i,r),t.setParent(i,e.parent(i))}),e.edges().forEach(i=>{let r=Aa(e.edge(i));t.setEdge(i,Object.assign({},va,Ea(r,xa),ua.pick(r,wa)))}),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",()=>ta.run(e)),t(" nestingGraph.run",()=>oa.run(e)),t(" rank",()=>ra(ua.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};ua.addDummyNode(e,"edge-proxy",r,"_ep")}})}(e)),t(" removeEmptyRanks",()=>aa(e)),t(" nestingGraph.cleanup",()=>oa.cleanup(e)),t(" normalizeRanks",()=>sa(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",()=>ia.run(e)),t(" parentDummyChains",()=>na(e)),t(" addBorderSegments",()=>la(e)),t(" order",()=>ca(e,i)),t(" insertSelfEdges",()=>function(e){var t=ua.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=>{ua.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",()=>ha.adjust(e)),t(" position",()=>da(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",()=>ia.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",()=>ha.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(ua.intersectRect(n,i)),s.points.push(ua.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",()=>ta.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 fa=["nodesep","edgesep","ranksep","marginx","marginy"],ga={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},ya=["acyclicer","ranker","rankdir","align"],ma=["width","height","rank"],ba={width:0,height:0},xa=["minlen","weight","width","height","labeloffset"],va={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},wa=["labelpos"];function Ea(e,t){return ua.mapValues(ua.pick(e,t),Number)}function Aa(e){var t={};return e&&Object.entries(e).forEach(([e,i])=>{"string"==typeof e&&(e=e.toLowerCase()),t[e]=i}),t}let Ca=vs,Sa=ds.Graph;var ka={graphlib:ds,layout:pa,debug:{debugOrdering:function(e){let t=Ca.buildLayerMatrix(e),i=new Sa({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:vs.time,notime:vs.notime},version:"1.1.8"};class Ra extends xe{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=Ce(e.parent);for(let e of t){let t=e.layout;if(!t)continue;let r=Y(e.children[0]);if(!r)continue;var i=new ka.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[X];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);ka.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[X];xi(t,n[s.get(e)].x-t.x,n[s.get(e)].y-t.y)}}let r=Be(e,!0);for(let e of r)de(e)}_getDagreDirection(e){switch(e){case mt.Left2Right:return"LR";case mt.Right2Left:return"RL";case mt.Top2Bottom:return"TB";case mt.Bottom2Top:return"BT"}}}class Ta extends xe{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=Ce(e.parent);for(let e of t){let t=e.layout;if(!t)continue;let i=W(e.children[0]);if(!i)continue;let s=r.hierarchy(i._data),n=Math.max(...e.children.map(e=>e.bounds.width)),a=Math.max(...e.children.map(e=>e.bounds.height)),o=t.orientation==pt?[t.height,t.width]:[t.width,t.height],l=r.tree().nodeSize([n,a]).size(o)(s);this._apply(l,t,e)}de(e)}_apply(e,t,i){let r,s,n=i.children.filter(t=>t.datum[X]==e.data[X])[0];switch(t.orientation){case pt:r=e.y+t.left,s=e.x+t.top;break;case ft:r=e.x+t.left,s=t.top+e.y}if(xi(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 Oa extends xe{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=this._inputVars.filter(e=>e.type===Ee.PROPERTY&&e.property===We.CHILDREN_ORDER)[0].element,i=t.layout,s=i.width?i.width:t.bounds.width,a=i.height?i.height:t.bounds.height,o=void 0===i.top?t.bounds.top:i.top,l=void 0===i.left?t.bounds.left:i.left,h=r.hierarchy(t).sum(e=>e.type===n.Rect?e.width*e.height:0);r.treemap().size([s,a])(h),this._apply(h,l,o);let c=Be(e,!0);for(let e of c)de(e)}_apply(e,t,i){if(e.data.type==n.Collection&&e.children)for(let r of e.children)this._apply(r,t,i);else e.data.type==n.Rect&&(e.data.resize(e.x1-e.x0,e.y1-e.y0),xi(e.data,e.x0+t-e.data.left,e.y0+i-e.data.top))}}class Ia extends xe{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=Ce(e.parent);for(let e of t){if(!e.layout)continue;if(0===e.children.length)continue;let t=W(e.children[0]);if(!t)continue;let i={};for(let t of e.children)i[t.datum[X]]=t;e.children[0].type===n.Rect?this._layoutRects(t.getRoot(),t,i):this._layoutArcs(t.getRoot(),t,i)}de(e)}_layoutArcs(e,t,i){let r=t.getChildren(e);if(0===r.length)return;let s=i[e[X]],a=!s||s.type!=n.Arc&&s.type!=n.Pie?60:s.startAngle;for(let e=0;e<r.length;e++){let s=r[e],o=i[s[X]];if(o.type===n.Arc){let e=Lt(a+o.angle);o.setAngles(a,e),a=e}this._layoutArcs(s,t,i)}}_layoutRects(e,t,i){let r=t.getChildren(e);if(0===r.length)return;let s,n,a=i[e[X]];this._direction,s=a.left,n=a.bottom;for(let e=0;e<r.length;e++){let a=r[e],o=i[a[X]];xi(o,s-o.left,n-o.top),s+=o.width,this._layoutRects(a,t,i)}}}class Na extends xe{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=Pe(i.responderComponent).state,n=e.result;if(i.evalFunction){i.getResponderPeers().forEach(e=>n[e.id]=!!i.evalFunction(r,s,e))}}}class La extends xe{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=Ce(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=re(t.x+t.radius,t.y,t.x,t.y,e);switch(xi(s,n.x-s.bounds.x,n.y-s.bounds.y),t.markRotation){case vt.INWARD:s._markRotationOffset=e+90;break;case vt.TANGENTIAL_CLOCKWISE:s._markRotationOffset=e;break;case vt.TANGENTIAL_COUNTERCLOCKWISE:s._markRotationOffset=e-180;break;case vt.UPRIGHT:break;case vt.OUTWARD:default:s._markRotationOffset=e-90}}}let i=Be(e,!0);for(let e of i)de(e)}}class Pa extends xe{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=Ce(e.parent);for(let i of t){let t=i.layout;if(!t)continue;let s=t._tree?t._tree._data:W(i.children[0])._data,n=r.hierarchy(s);if(t.isRadial()){n=r.cluster().size([It(t.angleExtent),t.radius])(n),t._d3Root=n;const e=new Map(n.descendants().map(e=>[e.data[X],[e.x,e.y]]));for(let r of i.children){let i=r.datum[X];xi(r,t.x-r.bounds.x,t.y-e.get(i)[1]-r.bounds.y),r._rotate=[Nt(e.get(i)[0]),t.x,t.y]}}else if(t.orientation===ft){!t.width||t.width;let s=t.height?t.height:600;n=r.cluster().nodeSize([e.bounds.width+1,s/(n.height+1)])(n),t._d3Root=n;const a=new Map(n.descendants().map(e=>[e.data[X],[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)}),t._x0=o;for(let e of i.children){let i=e.datum[X];xi(e,a.get(i)[0]-o+t.left-e.bounds.x,a.get(i)[1]+t.top-e.bounds.y)}}else if(t.orientation===pt){!t.width||t.width;let s=t.height?t.height:600;n=r.cluster().nodeSize([e.bounds.height,s/(n.height+1)])(n),t._d3Root=n;const a=new Map(n.descendants().map(e=>[e.data[X],[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)}),t._x0=o;for(let e of i.children){let i=e.datum[X];xi(e,a.get(i)[1]+t.left-e.bounds.x,a.get(i)[0]-o+t.top-e.bounds.y)}}}let i=Be(e,!0);for(let e of i)de(e)}}class Va extends xe{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=Ce(e.parent);for(let e of t){let t=e.layout;if(!t)continue;let i=t.direction===bt.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=re(t.x+e,t.y,t.x,t.y,n);switch(xi(s,a.x-s.bounds.x,a.y-s.bounds.y),t.markRotation){case vt.INWARD:s._markRotationOffset=n+90;break;case vt.TANGENTIAL_CLOCKWISE:s._markRotationOffset=n;break;case vt.TANGENTIAL_COUNTERCLOCKWISE:s._markRotationOffset=n-180;break;case vt.UPRIGHT:break;case vt.OUTWARD:default:s._markRotationOffset=n-90}}}let i=Be(e,!0);for(let e of i)de(e)}}class Ba extends we{constructor(e,t){super(e),this._cond=t}get context(){return this._cond}}class Da extends xe{constructor(e,t,i){super(e),this._fn=t,this._compnt=i}run(){super.run();let e=this.inputVars.find(e=>e instanceof Ba),t=e?e.context:void 0,i=Pe(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===Ee.CHANNEL?i.onChange(Ee.CHANNEL,e.channel,t):e.type===Ee.PROPERTY?i.onChange(Ee.PROPERTY,e.property,t):e.type===Ee.STATE&&i.onChange(Ee.STATE,e.key,e.stateContext))}}}class Ma extends we{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 Ga extends xe{constructor(e){super(e)}run(){super.run();let e=this.outputVar,t=this.inputVars.find(e=>e instanceof Ma),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 i=Ce(e.element),r={};if(e.element.type===n.Area&&["width","height"].indexOf(e.channel)>=0||["fillGradient","strokeGradient"].indexOf(e.channel)>=0)for(let t of i)for(let i=0;i<t._vertices.length;i++)r[ke(t,i)]=t._vertices.hasDataScope(i)?t._vertices.aggregateDataScopeAttribute(i,e.attribute,e.aggregator):N(t.dataScope,e.attribute,e.aggregator);else switch(t){case h.Boolean:break;case h.Date:for(let t of i)r[t.id]=O(t.dataScope,e.attribute);break;case h.String:try{if("count"==e.aggregator)for(let t of i)r[t.id]=I(t.dataScope,e.attribute).length;else for(let t of i)r[t.id]=O(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,s=e.attribute.split(".")[0],n=e.attribute.split(".")[1];for(let e of i){let i=O(e.dataScope,s);r[e.id]=O(L(V(t),X,i),n)}}else for(let t of i)r[t.id]=N(t.dataScope,e.attribute,e.aggregator)}return e.attrValues=r,r}_computeVertexIndexAttrValues(e,t){let i={};for(let r of e.elementGroups)for(let s of r.groups)for(let r of s.indices){i[ke(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:()=>k(r.dataScope)}),Object.defineProperty(r,"data",{get:()=>S(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 h.Boolean:return;case h.Date:return e._vertices.getDataScopeAttrVal(t,i.attribute);case h.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 h.Boolean:return;case h.Date:return O(e,t.attribute);case h.String:return"count"==t.aggregator?I(e,t.attribute).length:O(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=O(e,r);return O(L(V(i),X,n),s)}return N(e,t.attribute,t.aggregator)}}}class za extends we{constructor(e,t,i){super(e),this._key=t,this._stateContext=i}get key(){return this._key}get stateContext(){return this._stateContext}}class ja{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===Ee.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===ve.DOMAIN_BUILDER?t.aggregator=e.aggregator:e.type===ve.SCALE_BUILDER&&(t.channel=e.channel),t});return{edges:e,variables:t,operators:i}}getVariable(e,...t){if(Object.values(Ee).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 Ee.CHANNEL:i=new Me(e,t[0],t[1]),"vertex"!=t[1].type&&"segment"!=t[1].type||this._connectPathElement2Size(t[1],i);break;case Ee.PROPERTY:i=new ze(e,t[0],t[1]);break;case Ee.STATE:i=new za(e,t[0],t[1]);break;case Ee.ATTRIBUTE:i=new Ma(e,t[0],t[1],t[2]||null);break;case Ee.ITEMS:i=new _r(e,t[0]);break;case Ee.ATTR_VALUE:i=new Yi(e,t[0]);break;case Ee.DATASCOPE:i=new ji(e,t[0]);break;case Ee.BOUNDS:i=new zi(e,t[0]);break;case Ee.SCALE:i=new Ui(e,t[0]);break;case Ee.AFFIXATION:i=new mr(e,t[0]);break;case Ee.ALIGNMENT:i=new Sr(e,t[0]);break;case Ee.EVT_CTX:i=new Ba(e,t[0],t[1]);break;case Ee.CONDITION_RESULT:i=new ar(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(Ee.CHANNEL,["x"===r?"width":"height",i]);if(s){let e=s.incomingDataflow;e||(e=this.createOneWayDependency(ve.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 xe&&i.toNode.type===e)return i.toNode;return this.createOneWayDependency(e)}createOneWayDependency(e,...t){if(Object.values(ve).indexOf(e)<0)throw new Error("Dependency Type Not Known");let i;switch(e){case ve.EVAL_BBOX:i=new qi(e);break;case ve.AFFIXER:i=new yr(e);break;case ve.DATA_EXTRACTOR:i=new Ga(e,t[0]);break;case ve.SCALE_BUILDER:i=new Xi(e,t[0]);break;case ve.ENCODER:i=new or(e,t[0]);break;case ve.AXIS_PATH_PLACER:i=new Ki(e);break;case ve.AXIS_TICKS_PLACER:i=new Zi(e);break;case ve.AXIS_LABELS_PLACER:i=new $i(e);break;case ve.AXIS_TITLE_PLACER:i=new Ar(e);break;case ve.LINK_PLACER:i=new Rr(e);break;case ve.GRID_LAYOUT:i=new Qi(e);break;case ve.STACK_LAYOUT:i=new cr(e);break;case ve.PACK_LAYOUT:i=new Er(e);break;case ve.FORCE_LAYOUT:i=new kr(e);break;case ve.DIRECTED_LAYOUT:i=new Ra(e);break;case ve.TIDY_TREE_LAYOUT:i=new Ta(e);break;case ve.TREEMAP_LAYOUT:i=new Oa(e);break;case ve.STRATA_LAYOUT:i=new Ia(e);break;case ve.CIRCULAR_LAYOUT:i=new La(e);break;case ve.CLUSTER_LAYOUT:i=new Pa(e);break;case ve.SPIRAL_LAYOUT:i=new Va(e);break;case ve.GRIDLINES_PLACER:i=new lr(e);break;case ve.SPIRAL_TRAJECTORY_PLACER:i=new hr(e);break;case ve.BIN_TRANSFORMER:i=new ur(e);break;case ve.FILTER_TRANSFORMER:i=new pr(e);break;case ve.KDE_TRANSFORMER:i=new br(e);break;case ve.CUSTOM_TRANSFORMER:i=new wr(e);break;case ve.REPOPULATE:i=new gr(e);break;case ve.TARGET_EVALUATOR:i=new Na(e);break;case ve.TARGET_UPDATER:i=new Da(e,t[0],t[1]);break;case ve.CONDUIT:default:i=new dr(e)}return e in this._operators||(this._operators[e]={}),this._operators[e][i.id]=i,i}createMultiWayDependency(e){if(Object.values(ve).indexOf(e)<0)throw new Error("Dependency Type Not Known");let t;return ve.ALIGNER,t=new Cr(e),e in this._operators||(this._operators[e]={}),this._operators[e][t.id]=t,t}connect(e,t,i=!0){if(e instanceof we&&t instanceof xe){if(!t.inputVars.includes(e)){const r=new Wi(e,t,i);return this._edges.push(r),e.outgoingEdges.push(r),t.inputVars.push(e),r}}else if(e instanceof xe&&t instanceof we){if(!e.outputVars.includes(t)){const r=new Wi(e,t,i);return this._edges.push(r),e.outputVars.push(t),t.incomingEdges.push(r),r}}else if(e instanceof we&&t instanceof Fi){if(!t.vars.includes(e)){const i=new Wi(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 Fi&&t instanceof we))throw new Error("An edge must connect a variable and an operator.");if(!e.vars.includes(t)){const i=new Wi(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(ve.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 we&&t instanceof xe){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 xe&&t instanceof we){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 Ee.ITEMS:this.getOperatorsOnPath(e.type,t,i,e.dataset);break;case Ee.ATTRIBUTE:this.getOperatorsOnPath(e.type,t,i,e.attribute,e.dataset);break;case Ee.DATASCOPE:case Ee.BOUNDS:this.getOperatorsOnPath(e.type,t,i,e.element);break;case Ee.CHANNEL:this.getOperatorsOnPath(e.type,t,i,e.channel,e.element);break;case Ee.PROPERTY:this.getOperatorsOnPath(e.type,t,i,e.property,e.element);break;case Ee.STATE:this.getOperatorsOnPath(e.type,t,i,e.key,e.stateContext);break;case Ee.SCALE:case Ee.ATTR_VALUE:this.getOperatorsOnPath(e.type,t,i,e.encodings[0]);break;case Ee.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 Ee.CHANNEL:return i.find(e=>e.channel==t[0]&&_i(e.element)==_i(t[1]));case Ee.PROPERTY:return i.find(e=>e.property==t[0]&&e.element==t[1]);case Ee.STATE:return i.find(e=>e.key==t[0]&&e.stateContext==t[1]);case Ee.AFFIXATION:return i.find(e=>e.affixation==t[0]);case Ee.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 Ee.ITEMS:return i.find(e=>e.dataset==t[0]);case Ee.ATTR_VALUE:case Ee.SCALE:return i.find(e=>e.encodings.includes(t[0]));case Ee.EVT_CTX:return i.find(e=>e.context===t[0]);case Ee.CONDITION_RESULT:return i.find(e=>e.conditionalEncoding==t[0]);case Ee.DATASCOPE:default:return t[0].classId?i.find(e=>_i(e.element)==_i(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&&_i(t.element)==_i(e));r.length>0&&(t[i]=r)}return t}}class Fa{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 Wa{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 Ua{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 Ya{constructor(e,t){this._fn=e,t&&Object.assign(this,t)}get fn(){return this._fn}}class Ha extends Ct{constructor(e,t){super(t||{}),this._type=n.Trajectory,this._id=this._type+o(),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===bt.ANTI_CLOCKWISE?-1:1,r=t-1+this._extendPastLast;if(r<=0){let t=re(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(re(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 oe(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 oe(i,s,r-i,n-s)}}class Xa extends lt{constructor(e){super(),this._itemMap={},this._type=n.Scene,this._id=e&&e.id?e.id:this._type+o(),e&&e.fillColor&&(this.fillColor=e.fillColor),this._encodings={},this._relations=[],this._triggers={},this._condEncodings={},this._stateContext=new Ae(this),this._stateContext.__scene__=this,this._depGraph=new ja,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,t){if(Object.values(s).indexOf(e)<0)throw new Error("Mascot does not allow directly creating a "+e);let i=void 0===t?{}:t;i.type=e;let r=Bi(this,i);return null!==r&&(r._classId=r.id,this.addChild(r),this._itemMap[r.id]=r,Ye(r,this._depGraph),$e(this,r,this._depGraph)),r}glyph(...e){let t=[];for(let i of e)t.push([i.parent,i]);let i=Bi(this,{type:n.Glyph,children:e});if(null!==i){i._classId=i.id;for(let e of t)Ze(e[0],e[1],this._depGraph);Je(i,this._depGraph),$e(this,i,this._depGraph)}return i}composite(){let e=Bi(this,{type:n.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=_i(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===n.Collection);for(let i of t){let t=i.dataScope?A(i.dataScope):null;t&&!(t.id in e)&&(e[t.id]=t)}return e}onChange(e,...t){if(Object.values(Ee).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===Ee.CHANNEL||e.type===Ee.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?j:t,n=r.element?ui(r.element,e):di(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=Ve(n.element),t=n.scales[0];if(e.layout&&e.layout.type==me.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=Ve(n.element);if(e.layout&&e.layout.type==me.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=Ve(n.element),t=n.scales[0];if(e.layout&&e.layout.type==me.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:Ce(e,e.parent)})}for(let e of i){let t=new yi(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:Ie(this,t);if(!i)return void console.warn("Cannot create "+e+" gridlines for "+t);let s=Ne(i.parent);if(!s.layout)return void console.warn("Cannot create "+e+" gridlines for "+t);let n=Ce(s);for(let i of n){let s=[];i.layout.type==me.GRID&&i.layout.numRows>1&&"x"==e?s=i.layout.getElementsByRow():i.layout.type==me.GRID&&i.layout.numCols>1&&"y"==e?s=i.layout.getElementsByCol():s.push(i.children);for(let n of s){let s=new yi(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=Ne(e);if(!r||!r.layout||r.layout.type!==me.SPIRAL)return void console.warn("Cannot create a trajectory: element is not inside a collection with a spiral layout");let s=new Ha(r,i);return this.addChild(s),this._itemMap[s.id]=s,r.layout.addRefElement(s),function(e,t){let i=t.getVariable(Ee.BOUNDS,Ve(e.collection)),r=t.getVariable(Ee.PROPERTY,We.TRAJECTORY_POSITION,e),s=t.createOneWayDependency(ve.SPIRAL_TRAJECTORY_PLACER);t.connect(i,s),t.connect(s,r),s.run();let n=t.getVariable(Ee.BOUNDS,e),a=t.getIncomingDataflowOperator(ve.EVAL_BBOX,n);t.connect(r,a),t.connect(a,n)}(s,this._depGraph),$e(this,s,this._depGraph),de(s),this.onChange(Ee.PROPERTY,We.TRAJECTORY_POSITION,s),s}axis(e,t,i){let r=i||{},s="rowId"==t?j:t,n=[],a=r.element?ui(r.element,e):di(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=Ve(r.element?r.element:a.element);if(e.layout&&e.layout.type==me.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=Ve(r.element?r.element:a.element);if(e.layout&&e.layout.type==me.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:Ce(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=Bi(this,t);n.push(i),a.addRefElement(i),at(i,this._depGraph),$e(this,i,this._depGraph),this.onChange(Ee.PROPERTY,We.AXIS_PATH_POSITION,i)}}else{let t=r.element?r.element:Ie(this,s);if(!t)return void console.warn("Cannot create a "+e+" axis for "+s);let i=Ne(t.parent);if(!i.layout)return void console.warn("Cannot create a "+e+" axis for "+s);let a=Ce(i);for(let t of a){let i=[];t.layout.type==me.GRID&&t.layout.numRows>1&&"x"==e?i=t.layout.getElementsByRow():t.layout.type==me.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=Bi(this,i);n.push(o),t.layout.addRefElement(o),nt(o,this._depGraph),$e(this,o,this._depGraph),this.onChange(Ee.PROPERTY,We.AXIS_PATH_POSITION,o)}}}return n.length>1?n:n[0]}legend(e,t,i){let r=i||{},s="rowId"==t?j:t,n=r.element?ui(r.element,e):di(s,e,this);if(n){n.attribute!==t&&console.warn("Cannot create a "+e+" legend for "+t);let i=z(n.element).type(t);r.type="legend",r.enc=n,r.attrType=i;let s=Bi(this,r);!function(e,t){let i=t.getVariable(Ee.BOUNDS,e),r=t.getVariable(Ee.PROPERTY,We.LEGEND_POSITION,e),s=t.getIncomingDataflowOperator(ve.EVAL_BBOX,i);t.connect(r,s),t.connect(s,i)}(s,this._depGraph),$e(this,s,this._depGraph),de(s),this.onChange(Ee.PROPERTY,We.LEGEND_POSITION,s)}else console.warn("Cannot create a "+e+" legend for "+s)}mask(e){let t=Ve(e),i=t||e;i.clipMask||i.createClipMask()}setLayout(e,t){if(e.layout&&(et(e,e.layout,this._depGraph),t.type===me.TREEMAP)){let t=e.firstChild;for(;t&&t.type===n.Collection&&t.layout;)et(t,t.layout,this._depGraph),t=t.firstChild}if(Ce(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=Be(e,!0);for(let e of t)this.onChange(Ee.CHANNEL,"x",e)}}derive(e,t){let i=e.clone();return t._scene=this,t instanceof Fa?(!function(e,t,i,r){let s=r.getVariable(Ee.ITEMS,t),n=r.getVariable(Ee.ITEMS,i),a=r.createOneWayDependency(ve.BIN_TRANSFORMER);r.connect(s,a),r.connect(a,n);let o=r.getVariable(Ee.PROPERTY,We.NUM_BINS,e);r.connect(o,a),a._binConfig=e,a.run()}(t,e,i,this._depGraph),i._binTransform=t):t instanceof Wa?function(e,t,i,r){let s=r.getVariable(Ee.ATTRIBUTE,e.attribute,t),n=r.getVariable(Ee.ATTRIBUTE,e.newAttribute,i),a=r.getVariable(Ee.ITEMS,i),o=r.createOneWayDependency(ve.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 Ua?function(e,t,i,r){let s=r.getVariable(Ee.ITEMS,t),n=r.getVariable(Ee.ITEMS,i),a=r.createOneWayDependency(ve.FILTER_TRANSFORMER);a._spec=e,r.connect(s,a),r.connect(a,n);let o=r.getVariable(Ee.PROPERTY,"value",e);r.connect(o,a),a.run()}(t,e,i,this._depGraph):t instanceof Ya&&function(e,t,i,r){let s=r.getVariable(Ee.ITEMS,t),n=r.getVariable(Ee.ITEMS,i),a=r.createOneWayDependency(ve.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(Ee.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 di(e,t,this).refElements[0]}}function qa(e,t){return v(t[e.dt],e.attr2value||e.filters||{},e.rowIds)}class Ka extends ge{constructor(e){super(),this.type=me.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:mt.Top2Bottom}clone(){return new Ka({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 Za extends ge{constructor(e){super(),this.type=me.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 Za({x:this._x,y:this._y,iterations:this._iterations,repulsion:this._repulsion,attraction:this._attraction,linkDistance:this._linkDistance})}}class $a extends ge{constructor(e){super(),this.type=me.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 $a({x:this._x,y:this._y,width:this._width,height:this._height})}}class Ja extends ge{constructor(e){super(),this.type=me.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:ue.LEFT,this._vertCellAlignment="vertCellAlignment"in e&&e.vertCellAlignment?e.vertCellAlignment:ue.BOTTOM,this._gap="gap"in e?e.gap:0}clone(){let e=new Ja({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 ge{constructor(e){super(),this.type=me.STRATA,this._direction=e.direction,this._gap="gap"in e?e.gap:0}clone(){return new Qa({direction:this._direction,gap:this._gap})}}class eo extends ge{constructor(e){super(),this.type=me.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:pt}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 eo({width:this._width,height:this._height,top:this._top,left:this._left,orientation:this._orientation})}}class to extends ge{constructor(e){super(),this.type=me.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 to({width:this._width,height:this._height,top:this._top,left:this._left})}}class io extends ge{constructor(e){super(),e=e||{},this.type=me.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:bt.CLOCKWISE,this._markRotation="markRotation"in e?e.markRotation:this._direction===bt.CLOCKWISE?vt.TANGENTIAL_CLOCKWISE:vt.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 io({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 ro extends ge{constructor(e){super(),this.type=me.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:vt.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 ro({x:this._x,y:this._y,radius:this._radius,markRotation:this._markRotation})}}function so(e){switch(e.type){case me.GRID:return function(e){let t=new Oi(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=>no(e)));"grid"in e&&(t._grid=e.grid);return t}(e);case me.STACK:return function(e){let t=new Ja(e.args);return t}(e);case me.PACKING:return function(e){let t=new $a(e.args);return t}(e);case me.FORCE:return function(e){return new Za(e.args)}(e);case me.DIRECTED:return function(e){return new Ka(e.args)}(e);case me.TIDYTREE:return function(e){return new eo(e.args)}(e);case me.TREEMAP:return function(e){return new to(e.args)}(e);case me.STRATA:return function(e){return new Qa(e.args)}(e);case me.SPIRAL:return function(e){return new io(e.args)}(e);case me.CIRCULAR:return function(e){return new ro(e.args)}(e);default:return void console.warn("unsupported layout type for deserialization:",e.type)}}function no(e){return new oe(e.x-e.width/2,e.y-e.height/2,e.width,e.height)}function ao(e,t,i){e.type===n.Pie&&(e.type=n.Arc),e.args.type=e.type;let r=Bi(t,e.args);return e.id&&(r._id=e.id),e.classId&&(r._classId=e.classId),e.dataScope&&(r.dataScope=qa(e.dataScope,i)),e.bounds&&(r._bounds=no(e.bounds)),e.refBounds&&(r._refBounds=no(e.refBounds)),function(e,t,i,r){if(e.vertices){const i=[];for(let t of e.vertices){const e=oo(t,r);i.push(e)}t.vertices=i}t.vertexCounter=e.vertexCounter,t.segmentCounter=e.segmentCounter,t.curveMode=e.curveMode}(e,r,0,i),r}function oo(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=qa(e.dataScope,t)),"polarAngle"in e&&(i.polarAngle=e.polarAngle),i}function lo(e){let t={};t.fillColor=e.fillColor;let i=new Xa(t);console.log("======== deserialization =========");let r={};if(e.tables)for(let t in e.tables){let i=e.tables[t];r[t]=new M(i.data,i.url,i.attributeTypes),r[t]._id=i.id}let s={};if(e.scales)for(let t in e.scales)s[t]=_o(e.scales[t]);if(i.scales=s,uo(e,i,i,r),co(e,i),e.encodings){let t={};for(let s of e.encodings){let e=po(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(Ee.ATTR_VALUE,t[e]):i.onChange(Ee.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)===h.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);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=no(e.bounds)),delete i.scales,i}function ho(e,t,i,r){if(e.type===n.Collection){let s=Bi(i,{type:n.Collection,id:e.id});e.classId&&(s._classId=e.classId),t.addChild(s),qe(s,i._depGraph),$e(t,s,i._depGraph),uo(e,s,i,r)}else if(e.type===n.Glyph){let s=Bi(i,{type:n.Glyph,id:e.id});e.classId&&(s._classId=e.classId),t.addChild(s),Je(s,i._depGraph),$e(t,s,i._depGraph),uo(e,s,i,r)}else if(e.type===n.Composite){let s=Bi(i,{type:n.Composite,id:e.id});t.addChild(s),i._itemMap[s.id]=s,Ke(s,i._depGraph),$e(t,s,i._depGraph),uo(e,s,i,r),s._bounds=no(e.bounds)}else if(e.type===n.Axis){let s=new Qt({});t.addChild(s),function(e,t,i,r){e.id&&(t._id=e.id);if(t._children=[],e.labels){let s=new lt;uo(e.labels,s,i,r),t._labels=s,t._children.push(s)}e.path&&(t._path=ho(e.path,t,i,r));if(e.ticks){let s=new lt;uo(e.ticks,s,i,r),t._ticks=s,t._children.push(s)}e.title&&(t._title=ho(e.title,t,i,r))}(e,s,i,r),i._itemMap[s.id]=s}else if(Object.values(fe).includes(e.type)){let s=ao(e,i,r);return i._itemMap[s.id]=s,t.addChild(s),Ye(s,i._depGraph),$e(t,s,i._depGraph),s}}function co(e,t,i){if(e.children)for(let i of e.children)co(i,t);else if(Object.values(fe).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 uo(e,t,i,r){if(e.id&&(t._id=e.id),e.classId&&(t._classId=e.classId),e.dataScope&&(t.dataScope=qa(e.dataScope,r)),e.bounds&&(t._bounds=no(e.bounds)),t._sortBy=e.sortBy,e.children)for(let s of e.children)ho(s,t,i,r);e.layout&&(t._layout=so(e.layout),t._layout.group=t,tt(t,t._layout,i._depGraph))}function _o(e){let t=new ni(e.type,e.args);return t._id=e.id,t.domain=e.domain,t.range=e.range,t}function po(e,t,i){let r=fo(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 mi(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=>fo(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 fo(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 go(e){let t={};return t.id=e._id,t.data=e._rawData,t.attributeTypes=e._attrTypes,t.url=e.url,t}function yo(e){let t={};return t.dt=e.dataTable.id,t.attr2value=Object.assign({},e.filters),e.rowIds&&(t.rowIds=e.rowIds.slice()),t}function mo(e,t){t.vertices=[];for(let i=0;i<e._vertices.length;i++)t.vertices.push(bo(e._vertices,i));t.vertexCounter=e.vertexCounter,t.segmentCounter=e.segmentCounter,t.curveMode=e.curveMode}function bo(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=yo(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 xo(e){return e.type===n.Scene?function(e){let t=Eo(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(wo(s));for(let e of s._scales)e.id in t.scales||(t.scales[e.id]=vo(e))}t.tables={};let i=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 i of e.children)if(![n.Axis,n.Legend,n.Gridlines].includes(i.type)){if(i.dataScope){let e=A(i.dataScope);t[e.id]=e;break}if(i.children&&i.children.length>0){let e=i.firstChild;for(;e;){if(e.dataScope){let i=A(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 i)t.tables[e]=go(i[e]);return console.log("======== serialization ========="),console.log(t),t}(e):[n.Collection,n.Glyph,n.Composite].includes(e.type)?Eo(e,{}):e instanceof Qt?Ao(e,{}):e instanceof _e?function(e){let t={args:{}};t.type=e.type,t.id=e.id,e.classId&&(t.classId=e.classId),e.dataScope&&(t.dataScope=yo(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 Kt?t.args[i]=e.styles[i].toJSON():t.args[i]=e.styles[i];switch(e.type){case n.Arc:case n.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),mo(e,t);break;case n.Area:!function(e,t){t.args.baseline=e._baseline,t.args.orientation=e._orientation}(e,t),mo(e,t);break;case n.Circle:!function(e,t){t.args.x=e.x,t.args.y=e.y,t.args.radius=e.radius}(e,t);break;case n.Image:break;case n.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 n.Line:case n.Path:case n.BezierCurve:mo(e,t);break;case n.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 n.Polygon:!function(e,t){t.args.x=e._x,t.args.y=e._y,t.args.radius=e._radius}(e,t),mo(e,t);break;case n.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),mo(e,t);case n.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 wo(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 Eo(e,t){if(t.id=e.id,t.type=e.type,e.classId&&(t.classId=e.classId),e.dataScope&&(t.dataScope=yo(e.dataScope)),t.bounds=e.bounds.toJSON(),e._layout&&(t.layout=function(e){switch(e.type){case me.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 me.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 me.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 me.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 me.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 me.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 me.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 me.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 me.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 me.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 me.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);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 Qt?Ao(i,t):i instanceof yi?Co(i,t):i instanceof Ha?So(i,t):t.children.push(xo(i));return t.sortBy=e._sortBy,t}function Ao(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 Co(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)}function So(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 ko={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 Ro(e,t,i){if(!e.bounds.contains(t,i))return!1;switch(e.type){case n.Path:case n.Arc:case n.BezierCurve:case n.Line:{let r=ko.getContext(),s=ko.getPath2D(e.getSVGPathData());return r.lineWidth=Math.max(e.strokeWidth,2.5),r.stroke(s),e.closed||"none"!==e.fillColor?r.isPointInPath(s,t,i):r.isPointInStroke(s,t,i)}case n.Circle:{let r=e.x,s=e.y;if(e.rotation){let t=re(r,s,e.rotation[1],e.rotation[2],e.rotation[0]);r=t.x,s=t.y}return Math.sqrt(Math.pow(t-r,2)+Math.pow(i-s,2))<=e.radius+e.strokeWidth}case n.Collection:if([n.Arc,n.Pie,n.Polygon,n.Area].indexOf(e.firstChild.type)>=0){let r=e.getSVGPathData();if(""!==r){let s=ko.getContext(),n=ko.getPath2D(r);return s.lineWidth=Math.max(e.firstChild.strokeWidth,2.5),s.stroke(n),s.isPointInPath(n,t,i)}}return e.bounds.contains(t,i);default:return e.bounds.contains(t,i)}}const To="x",Oo="y",Io="xAttr",No="yAttr",Lo="xCoords",Po="yCoords",Vo="xVals",Bo="yVals",Do="xVal",Mo="yVal",Go="selectedRows",zo="dx",jo="dy",Fo="dxData",Wo="dyData",Uo="deltaX",Yo="deltaY",Ho="element";function Xo(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 qo(e){let t=new Map;for(let i of e)if(i)if(i.type===n.Collection&&i.children&&i.children.length>0){let e=i.children[0],r=msc.getChannelEncodingByElement(e,"x"),s=msc.getChannelEncodingByElement(e,"y"),n=e,a=e;!r&&e.leftSegment&&(r=msc.getChannelEncodingByElement(e.leftSegment,"x"),r&&(n=e.leftSegment)),!s&&e.bottomSegment&&(s=msc.getChannelEncodingByElement(e.bottomSegment,"y"),s&&(a=e.bottomSegment)),t.set(i.id,{element:i,child:e,xEnc:r,yEnc:s,xChild:n,yChild:a,xAttr:r?r.sourceAttribute??r.attribute:void 0,yAttr:s?s.sourceAttribute??s.attribute:void 0})}else if(i.type===n.Area){let e=null,r=null,s=null,n=null;i.anyVertex&&(e=msc.getChannelEncodingByElement(i.anyVertex,"x"),e&&(r=i.anyVertex)),!e&&i.topLeftVertex&&(e=msc.getChannelEncodingByElement(i.topLeftVertex,"x"),e&&(r=i.topLeftVertex)),!e&&i.bottomLeftVertex&&(e=msc.getChannelEncodingByElement(i.bottomLeftVertex,"x"),e&&(r=i.bottomLeftVertex)),s=msc.getChannelEncodingByElement(i,"y")??msc.getChannelEncodingByElement(i,"height"),s&&(n=i),!s&&i.anyVertex&&(s=msc.getChannelEncodingByElement(i.anyVertex,"y"),s&&(n=i.anyVertex)),!s&&i.topLeftVertex&&(s=msc.getChannelEncodingByElement(i.topLeftVertex,"y"),s&&(n=i.topLeftVertex)),t.set(i.id,{element:i,child:i,xEnc:e,yEnc:s,xChild:r,yChild:n,xAttr:e?e.sourceAttribute??e.attribute:void 0,yAttr:s?s.sourceAttribute??s.attribute:void 0})}return t}function Ko(e,t,i,s,a){for(let s of e){let e,a="background"===s.source?i:s.source;a=Array.isArray(a)?a:[a];let l="brushX"===s.event?r.brushX():"brushY"===s.event?r.brushY():r.brush();var o;l.on("start",function(t){e=qo(a),o&&a.length>1&&r.select(o).call(l.move,null),o=this}),l.on("brush end",function(t){let n,o;if(t&&t.selection)switch(s.event){case"brushX":n=[t.selection[0],t.selection[1]],o=void 0;break;case"brushY":n=void 0,o=[t.selection[0],t.selection[1]];break;default:n=[t.selection[0][0],t.selection[1][0]],o=[t.selection[0][1],t.selection[1][1]]}else n=void 0,o=void 0;let l=s.eventContext;l.clear(),l.set(Lo,n),l.set(Po,o);let h=r.select(this).attr("id").replace("brush-","");e||(e=qo(a));let c=e.get(h),d=c&&c.xAttr&&n?n.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&&n&&(p[c.xAttr]=Xo(c.xEnc,n,c.xChild)),c&&c.yAttr&&o&&(p[c.yAttr]=Xo(c.yEnc,o,c.yChild));let f=_?_.rows(p):void 0;c&&(l.set(Io,c.xAttr),l.set(No,c.yAttr),l.set(Vo,d),l.set(Bo,u),l.set(Go,f)),i.onChange(Ee.EVT_CTX,l),t&&"end"===t.type&&(e=void 0)});for(let e of a){let i=e.type===n.Axis?e.boundsWithoutTitle:e.bounds,r=[[i.left,i.top],[i.right,i.bottom]];t.append("g").attr("class","brush").attr("id","brush-"+e.id).call(l.extent(r))}}}function Zo(e,t,i,s,n){for(let s of e){"background"===s.source||s.source;let e=r.zoom();e.on("zoom",e=>{e.sourceEvent.preventDefault(),e.sourceEvent.stopPropagation();let r=s.eventContext;r.clear();let[n,a]=ne(t.attr("id"),e.sourceEvent.clientX,e.sourceEvent.clientY);r.set(To,n),r.set(Oo,a),r.set(Uo,e.sourceEvent.deltaX),r.set(Yo,e.sourceEvent.deltaY),i.onChange(Ee.EVT_CTX,r)}),t.call(e)}}function $o(e,t,i,s,n){for(let s of e){let e="background"===s.source?t.select("#"+i.id):Array.isArray(s.source)?t.selectAll(s.source.map(e=>e.classId?"."+e.classId:"#"+e.id).join(", ")):s.source.classId?t.selectAll("."+s.source.classId):t.select("#"+s.source.id),n=r.drag();n.on("start",e=>{let r=e.sourceEvent.target.__data__;if(!r||!msc.getChannelEncodingByElement(r,"x")&&!msc.getChannelEncodingByElement(r,"y")){let[s,n]=ne(t.attr("id"),e.sourceEvent.clientX,e.sourceEvent.clientY);const a=Oe(i,[]);r=a.find(e=>"vertex"!==e.type&&"segment"!==e.type&&!e.children&&Ro(e,s,n)&&(msc.getChannelEncodingByElement(e,"x")||msc.getChannelEncodingByElement(e,"y"))),r||(r=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=r}),n.on("drag",e=>{let[r,n]=ne(t.attr("id"),e.sourceEvent.clientX,e.sourceEvent.clientY),a=s.eventContext;a.set(To,r),a.set(Oo,n),a.set(zo,e.dx),a.set(jo,e.dy);let o=s._dragElem;if(a.set("element",o),o){let t=msc.getChannelEncodingByElement(o,"x"),i=msc.getChannelEncodingByElement(o,"y");if(t){let i="log"!==t.getScale(o)?.type;a.set(Io,t.attribute),a.set(Fo,t.getAttrValue(r-e.dx,o,i)-t.getAttrValue(r,o,i))}if(i){let t="log"!==i.getScale(o)?.type;a.set(No,i.attribute),a.set(Wo,i.getAttrValue(n-e.dy,o,t)-i.getAttrValue(n,o,t))}}i.onChange(Ee.EVT_CTX,a)}),n.on("end",e=>{s._dragElem=void 0;let t=s.eventContext;t.set("element",void 0),i.onChange(Ee.EVT_CTX,t)}),e.call(n)}}function Jo(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]=ne(t.attr("id"),e.clientX,e.clientY),a=r.eventContext;if(a.set(To,s),a.set(Oo,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(Io,r),a.set(No,o),a.set(Do,l),a.set(Mo,h)}let o=e.target.__data__;a.set(Ho,o),i.onChange(Ee.EVT_CTX,a)};"background"===r.source?t.on("mousemove",s):e.on("mouseover",s);const n=e=>{let t=r.eventContext;t.set(Ho,void 0),i.onChange(Ee.EVT_CTX,t)};"background"===r.source?t.on("mouseleave",n):e.on("mouseout",n)}}function Qo(e,t,i,r,s){let n=e.filter(e=>e.isKeyboardDriven());n.length>0&&el(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(Ee.EVT_CTX,r)})}}function el(e,t,i,s,n){let a=".mascot-keyboard-"+i.id+"-"+t.attr("id"),o={};for(let t of e){let e=["keydown","keyup"].includes(t.event)?t.event:"keydown";e in o||(o[e]=[]),o[e].push(t)}for(let e in o)r.select(window).on(e+a,null),r.select(window).on(e+a,t=>{for(let r of o[e]){if(void 0!==r.source&&t.key!==r.source)continue;let s=r.eventContext;s.clear(),s.set("event",e),s.set("source",r.source),s.set("key",t.key),s.set("code",t.code),s.set("altKey",t.altKey),s.set("ctrlKey",t.ctrlKey),s.set("metaKey",t.metaKey),s.set("shiftKey",t.shiftKey),s.set("repeat",t.repeat),i.onChange(Ee.EVT_CTX,s)}})}function tl(e,t,i,r,s){t.on("wheel",r=>{for(let s of e){r.preventDefault(),r.stopPropagation();let[e,n]=ne(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(Ee.EVT_CTX,a)}})}function il(e,t,i,r,s){t.on("click",r=>{for(let s of e){let[e,n]=ne(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=Oe(i,o).filter(t=>Ro(t,e,n))[0];a.clear(),a.set("x",e),a.set("y",n),a.set("element",l),i.onChange(Ee.EVT_CTX,a)}})}function rl(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 sl(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";nl(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";nl(r,i,e.endStyle,e.endSize,s),t.setAttribute("marker-end","url(#"+i+")")}}function nl(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 al(e){return e.id+"-bg"}function ol(e){return e.id+"-path"}function ll(e){return!(!e.styles||!e.styles.strokeColor||e.styles.strokeColor.type!==n.PathGradient)}function hl(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 cl(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 cl(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 dl(e){switch(e){case ue.TOP:return"text-before-edge";case ue.BOTTOM:return"auto";case ue.LEFT:return"start";case ue.RIGHT:return"end";case ue.CENTER:case ue.MIDDLE:return"middle";default:return e}}function ul(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[ae[s]]=e[s]}e._dirty=!1}function _l(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[ae[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[ae[s]]=e[s]}if(r){let i=rl(e);t.setAttribute("transform",e._rotate?"rotate("+e._rotate.join(" ")+") "+i:i)}e._dirty=!1}function fl(e,t,i){let r=t[e.id];for(let t of i)switch(t){case"d":case"strength":case"vertices":case"x1":case"y1":case"x2":case"y2":r.setAttribute("d",e.getSVGPathData());break;case"startStyle":case"startSize":case"endStyle":case"endSize":break;case"strokeColor":r.style.stroke=ll(e)?"none":e.strokeColor;break;default:r.style[ae[t]]=e[t]}if(e.vertices){const i=r.ownerSVGElement;ll(e)?i&&hl(e,t,i):cl(e,t)}if(e.type===n.Arrow){const t=r.ownerSVGElement;t&&sl(e,r,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 gl(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[ae[s]]=e[s],r&&(r.style[ae[s]]=e[s])}e._dirty=!1}function yl(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[ae[r]]=e[r];break;default:t.style[ae[r]]=e[r]}e._dirty=!1}function ml(e,t,i){for(let r of i)"gridlinesPosition"===r?t.setAttribute("d",e.getSVGPathData()):t.style[ae[r]]=e[r];e._dirty=!1}function bl(e,t,i){for(let r of i)"trajectoryPosition"===r?t.setAttribute("d",e.getSVGPathData()):t.style[ae[r]]=e[r];e._dirty=!1}function xl(e,t,i){let r=t.some(e=>"x"===e||"y"===e);Ce(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 vl(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 wl{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(e,t){let i=r.select("#"+this._svgId);i.on(".",null);for(let t in e.interactionTriggers){let r=Object.values(e.interactionTriggers[t]);switch(t){case"click":i.on("click",null),il(r,i,e);break;case"brush":case"brushX":case"brushY":Ko(r,i,e);break;case"drag":case"dragX":case"dragY":$o(r,i,e);break;case"hover":Jo(r,i,e);break;case"change":case"input":Qo(r,i,e);break;case"keydown":case"keyup":el(r,i,e);break;case"zoom":Zo(r,i,e);break;case"scroll":tl(r,i,e)}}}clear(){if(this._svg){for(;this._svg.firstChild;)this._svg.firstChild.remove();r.select("#"+this._svgId).on(".",null),console.log("clearing canvas"),this._compMap={},this._decoMap={}}}_renderItem(e,t,i){if(this._configSVG(e),!e.children&&!1===e._dirty)return;let r=this._compMap[e.id];if(i){const e=i.delay||0,t=i.duration||0;r.style.transition=`all ${t}ms ease ${e}ms`}switch(e.type){case n.Scene:!function(e,t){t.style.background=e.fillColor?e.fillColor:"#fff"}(e,this._svg);break;case n.Circle:!function(e,t){t.setAttribute("cx",e.x),t.setAttribute("cy",e.y),t.setAttribute("r",e.radius)}(e,r);break;case n.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,r);break;case n.Path:case n.BezierCurve:case n.BundledPath:case n.Chord:case n.Polygon:case n.Link:case n.Pie:case n.Line:case n.Area:case n.Ring:case n.Arc:case n.Gridlines:case n.Trajectory:case n.Arrow:!function(e,t,i){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===n.BundledPath&&(t.style.mixBlendMode="multiply"),e.type===n.Arrow&&i&&sl(e,t,i)}(e,r,this._svg);break;case n.SimpleText:!function(e,t,i){if(t.setAttribute("text-anchor",dl(e.anchor[0])),t.setAttribute("alignment-baseline",dl(e.anchor[1])),t.setAttribute("dominant-baseline",dl(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","#"+ol(e)),i.setAttribute("startOffset",e.textPathOffset),i.textContent=e.text}else t.textContent=e.text}(e,r,this._compMap[al(e)]);break;case n.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,r);break;case n.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,r);break;case n.Symbol:!function(e,t){t.setAttribute("d",e.path),t.setAttribute("transform",rl(e))}(e,r)}if(e._rotate){let t=r.getAttribute("transform"),i=r.getAttribute("data-mascot-rotate");i&&t&&0===t.indexOf(i)&&(t=t.slice(i.length).trim());let s="rotate("+e._rotate.join(" ")+")";r.setAttribute("transform",t?s+" "+t:s),r.setAttribute("data-mascot-rotate",s)}else{let e=r.getAttribute("data-mascot-rotate");if(e){let t=r.getAttribute("transform");if(t&&0===t.indexOf(e)){let i=t.slice(e.length).trim();i?r.setAttribute("transform",i):r.removeAttribute("transform")}r.removeAttribute("data-mascot-rotate")}}if(function(e,t,i){if(!e.styles)return;let r=Object.keys(e.styles);e.type===n.RichText&&(r=r.filter(e=>["textAnchor","fillColor"].indexOf(e)<0));for(let s of r)if(void 0!==e.styles[s])if("strokeColor"===s&&e.styles[s].type==n.PathGradient)t.style.stroke="none";else if(s.indexOf("Color")>0&&e.styles[s].type==n.LinearGradient){const r=i.querySelector("defs"),n=e.styles[s];if(!r.querySelector("#"+n.id)){const e=document.createElementNS("http://www.w3.org/2000/svg","linearGradient");e.setAttribute("id",n.id),e.setAttribute("x1",n.x1+"%"),e.setAttribute("x2",n.x2+"%"),e.setAttribute("y1",n.y1+"%"),e.setAttribute("y2",n.y2+"%");for(let t of n.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)}r.appendChild(e)}t.style[ae[s]]="url(#"+n.id+")"}else if(t.style[ae[s]]=e.styles[s],"visibility"===s)if(e.type===n.SimpleText){if(e.hasBackground()){const t=i.querySelector("#"+al(e));t&&(t.style[ae[s]]=e.styles[s])}}else if(e.type===n.RichText){const i=t.querySelector("div");i&&(i.style.visibility=e.styles[s])}}(e,r,this._svg),e.vertices&&(ll(e)?hl(e,this._compMap,this._svg,this._removed):cl(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):pe(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 s=i.querySelector("rect");s||(s=document.createElementNS("http://www.w3.org/2000/svg","rect"),i.appendChild(s)),s.setAttribute("x",e.clipMask.left),s.setAttribute("y",e.clipMask.top),s.setAttribute("width",e.clipMask.width),s.setAttribute("height",e.clipMask.height),r.setAttribute("clip-path","url(#"+e.id+"-clipPath)");let n=e.id+"-bg",a=r.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"),r.insertBefore(a,r.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 r=[...e.children].sort((e,t)=>(e.z||0)-(t.z||0));for(let e of r)this._renderItem(e,t,i)}else e._dirty=!1}_renderChanges(e,t){for(let i in t){let r=e.getElement(i);if(r){switch(r.type){case n.Rect:Ce(r).forEach(e=>{!1!==e._dirty&&ul(e,this._compMap[e.id],t[i])});break;case n.Circle:Ce(r).forEach(e=>{!1!==e._dirty&&_l(e,this._compMap[e.id],t[i])});break;case n.Path:case n.Area:case n.Line:case n.Arrow:case n.BezierCurve:case n.BundledPath:let e=[],s=["x","y","width","height"];for(let r of t[i])s.includes(r)?e.indexOf("d")<0&&e.push("d"):e.push(r);Ce(r).forEach(t=>{!1!==t._dirty&&fl(t,this._compMap,e)});break;case n.SimpleText:Ce(r).forEach(e=>{!1!==e._dirty&&gl(e,this._compMap[e.id],t[i],this._compMap[al(e)])});break;case n.RichText:Ce(r).forEach(e=>{!1!==e._dirty&&yl(e,this._compMap[e.id],t[i])});break;case n.Symbol:Ce(r).forEach(e=>{!1!==e._dirty&&pl(e,this._compMap[e.id],t[i])});break;case n.Glyph:xl(r,t[i],this);break;case n.Gridlines:!0===r._dirty&&ml(r,this._compMap[r.id],t[i]);break;case n.Trajectory:!0===r._dirty&&bl(r,this._compMap[r.id],t[i]);break;case n.Axis:Ce(r).forEach(e=>{vl(e,this)});break;case n.Collection:case n.Group:case n.Composite:break;default:console.warn("unsupported element type for update: "+r.type)}t[i].includes("z")&&r.parent&&this._reorderSiblingsByZ(r.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===n.SimpleText&&(e.hasBackground()&&delete this._removed[al(e)],e.textPath&&delete this._removed[ol(e)]);else{let t,i=e.parent;if(t=i&&i.id&&i.id in this._compMap?this._svg.querySelector("#"+i.id):this._svg,e.type===n.SimpleText){if(e.hasBackground()){const i=document.createElementNS("http://www.w3.org/2000/svg","rect");i.setAttribute("id",al(e)),t.appendChild(i),this._compMap[al(e)]=i}if(e.textPath){const t=this._svg.querySelector("defs"),i=ol(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 r=document.createElementNS("http://www.w3.org/2000/svg",this._getSVGElementType(e));t?t.appendChild(r):console.warn("Parent element not found for ",e.id,e.parent?e.parent.id:null),this._compMap[e.id]=r}if(e.type==n.Gridlines||e.type==n.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===n.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 n.Rect:return"rect";case n.Collection:case n.Group:case n.Glyph:case n.Scene:case n.Axis:case n.Legend:case n.Composite:return"g";case n.Area:case n.Path:case n.Polygon:case n.Ring:case n.Pie:case n.Arc:case n.BezierCurve:case n.BundledPath:case n.Chord:case n.Line:case n.Gridlines:case n.Trajectory:case n.Arrow:return"path";case n.Circle:return"circle";case n.SimpleText:return"text";case n.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 n.Symbol:return"path"}}}function El(e,t){return void 0===e&&void 0===t||void 0!==e&&void 0!==t}function Al(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 Cl(e,t){if(!El(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 me.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(!kl(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 me.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 me.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 me.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 me.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 me.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 me.STRATA:return function(e,t){return e._direction===t._direction&&e._gap===t._gap}(i,r);case me.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 me.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 me.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 Sl(e,t){if(!El(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||kl(i,r)}function kl(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Rl(e,t){if(!El(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(!Ol(e,t))return console.log("DataScopes not equal",e,t),!1;if(!Sl(e,t))return console.log("Bounds not equal",e,t),!1;if(!El(e.links,t.links))return console.log("Not both defined or undefined: links ",e.links,t.links),!1;if(!El(e.source,t.source))return console.log("Not both defined or undefined: source ",e.source,t.source),!1;if(!El(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&&!Rl(e.source,t.source))return console.log("different sources",e.source,t.source),!1;if(e.target&&t.target&&!Rl(e.target,t.target))return console.log("different targets",e.target,t.target),!1;switch(e.type){case n.Arc:case n.Pie:return Tl(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 n.Area:return Tl(e,t)?e.baseline===t.baseline&&e.orientation===t.orientation:(console.log("vertices not equal:",e,t),!1);case n.Circle:return e.x===t.x&&e.y===t.y&&e.radius===t.radius;case n.Image:return console.warn("not implemented"),!0;case n.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 n.Line:case n.Path:case n.BezierCurve:return!!Tl(e,t)||(console.log("vertices not equal:",e,t),!1);case n.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 n.Polygon:return Tl(e,t)?e.x===t.x&&e.y===t.y&&e.radius===t.radius:(console.log("vertices not equal:",e,t),!1);case n.Rect:return Tl(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 n.Ring:default:return console.warn("not implemented"),!0}}function Tl(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):Ol(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 Ol(e,t){if(!El(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(!Al(s,n))return!1;for(let e in s)if(s[e]!==n[e])return!1;return i.dataTable.id===r.dataTable.id&&S(i).length===S(r).length}function Il(e,t){return e.type!==t.type&&console.log("Different types:",e.type,t.type),[n.Collection,n.Glyph,n.Composite].includes(e.type)?Nl(e,t):e instanceof _e?Rl(e,t):void 0}function Nl(e,t){let i=e.children.filter(e=>!Object.values(a).includes(e.type)),r=t.children.filter(e=>!Object.values(a).includes(e.type));if(i.length!==r.length)return console.log("children length not equal:",i,r),!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(!Ol(e,t))return console.log("DataScopes not equal",e.dataScope,t.dataScope),!1;if(!Sl(e,t))return console.log("Bounds not equal",e,t),!1;if(!Cl(e,t))return console.log("Layouts not equal",e,t),!1;if(!function(e,t){if(!Al(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(!Il(i[e],r[e]))return console.log("Not equal",i[e],r[e]),!1;return!0}class Ll extends ge{constructor(e){super(),this.type=me.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:pt,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 Ll({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 Pl(e){if([n.Line,n.Circle,n.Rect,n.Area,n.Ring,n.Pie,n.Path].indexOf(e.type)<0)return!1;if(e.type===n.Path&&(e.closed||!e.firstVertex.dataScope))return!1;if(e.dataScope){let t=Ce(e);for(let e of t)if(R(e.dataScope)>1)return!0;return!1}return!0}function Vl(e){return e.type===n.Collection&&!(e.children.length<2)}function Bl(e,t,i,r,s,a,o,l,h,c){let d=i.map(e=>r.getParent(e)).filter((e,t,i)=>i.findIndex(t=>t[X]===e[X])===t);if(d=d.filter(e=>e!==r.getRoot()),0===d.length)return;let u=[];for(let i of d){let d,_,p,f=t.filter(e=>r.getParent(r.getNode(e.datum[X]))===i);if(f[0].type===n.Circle){let e=f.map(e=>se(o,l,e.bounds.x,e.bounds.y)-e.radius),t=f.map(e=>se(o,l,e.bounds.x,e.bounds.y)+e.radius);p=h===xt.OUTWARD?d3.max(t):d3.min(e)-c;let i=f.map(e=>Pt(e.bounds.x,e.bounds.y,o,l)),r=f.map(e=>Pt(o+se(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===n.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=Lt(d),_=Lt(_),p=h===xt.OUTWARD?d3.max(f.map(e=>e.outerRadius)):d3.min(f.map(e=>e.innerRadius))-c);let g=Bi(e,{type:"arc",innerRadius:p,outerRadius:p+c,x:o,y:l,startAngle:Lt(d),endAngle:Lt(_),strokeColor:t[0].strokeColor,fillColor:t[0].fillColor,strokeWidth:t[0].strokeWidth,opacity:t[0].opacity});g._updateBounds(),g.dataScope=r.getNodeDataScopeRef(i),g._classId=a,s.addChild(g),u.push(g)}Bl(e,u,d,r,s,a,o,l,h,c)}function Dl(e,t,i,r,s,a,o,l,h){h&&(e.dataScope=s.getNodeDataScopeRef(a),e._classId=t);let c=s.getChildren(a);if(0===c.length)return;let d=e.type===n.Circle||e.type===n.Ring?60:e.startAngle,u=(e.type===n.Circle||e.type===n.Ring?360:e.angle)/c.length;for(let a=0;a<c.length;a++){let h,_;_=i===xt.OUTWARD?e.type===n.Circle?e.radius:e.outerRadius:e.type===n.Circle?e.radius-r:e.innerRadius-r,h=Bi(l,360===u?{type:"ring",innerRadius:_,outerRadius:_+r,x:e.x,y:e.y,strokeColor:e.strokeColor,fillColor:e.fillColor,strokeWidth:e.strokeWidth,opacity:e.opacity}:{type:"arc",innerRadius:_,outerRadius:_+r,x:e.x,y:e.y,startAngle:Lt(d+u*a),endAngle:Lt(d+u*(a+1)),strokeColor:e.strokeColor,fillColor:e.fillColor,strokeWidth:e.strokeWidth,opacity:e.opacity}),h._updateBounds(),h.dataScope=s.getNodeDataScopeRef(c[a]),h._classId=t+"_strata",o.addChild(h),Dl(h,t,i,r,s,c[a],o,l)}}function Ml(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=Gi(e);xi(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),Ml(o,t,i,r,s,u[n],a)}}}class Gl{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 zl{constructor(e,t){this._elem=e,this._base=t,this._id=jl(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?ue.CENTER:ue.MIDDLE,i.baseAnchor="baseAnchor"in t?t.baseAnchor:"x"==e||"angle"==e?ue.CENTER:ue.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:j}}function jl(e,t){return(e.classId?e.classId:e.id)+":"+(t.classId?t.classId:t.id)}function Fl(e,t,i,r){e.vertices[0].dataScope&&A(e.vertices[0].dataScope).has(t)?function(e,t,i,r){let s;if(t===j)s=(e,i)=>parseInt(O(e.dataScope,t).substring(1))-parseInt(O(i.dataScope,t).substring(1));else{switch(A(e.vertices[0].dataScope).type(t)){case h.Date:break;case h.Number:case h.Integer:s=(e,i)=>N(e.dataScope,t)-N(i.dataScope,t);break;case h.String:s=r?(e,i)=>r.indexOf(O(e.dataScope,t))-r.indexOf(O(i.dataScope,t)):(e,i)=>O(e.dataScope,t)<O(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 Ul{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=>Ce(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 Yl{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}}const Hl=j;e.ROW_ID=Hl,e.activate=function(e,t,i,r,s){const n=Pe(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 Yl(o,e.source,e.event,e.cumulative));let l=n._triggers[a][o].eventContext,h=new Ul(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(Ee.STATE,s.source.key,s.source.stateContext):r.getVariable(Ee.EVT_CTX,e),o=i.properties?i.properties:i.channels;if(t.evalFunction){let e=r.getVariable(Ee.CONDITION_RESULT,t),i=r.findIncomingDataflowOperator(ve.TARGET_EVALUATOR,e);i||(i=r.createOneWayDependency(ve.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(Ee.CHANNEL,t,s),n=i.incomingDataflow;if(n&&n.type===ve.ENCODER&&n.outputVar.channel===t)r.connect(e,n);else if(!n){let n=r.createOneWayDependency(ve.ENCODER);r.connect(e,n),r.connect(n,i),n.storeValues(s,t)}}}}else{let e=r.createOneWayDependency(ve.TARGET_UPDATER,t.stylingFunction,n);for(let t of o){let i;i=n instanceof Ae?r.getVariable(Ee.STATE,t,n):Object.values(Ge).includes(t)?r.getVariable(Ee.CHANNEL,t,n):r.getVariable(Ee.PROPERTY,je(t),n),r.connect(a,e),r.connect(e,i)}}}(l,h,t,n._depGraph,e),n._triggers[a][o]},e.affix=function(e,t,i,r){let s=Pe(e);A(e.dataScope)!==A(t.dataScope)&&console.warn("Affix: elements and base elements are not created from the same table");let n=jl(e,t),a=s._relations.find(e=>e.id===n);a||(a=new zl(e,t),s._relations.push(a)),a.addChannel(i,r||{}),function(e,t){let i=t.getVariable(Ee.AFFIXATION,e),r=t.getOutgoingDataflowOperator(ve.AFFIXER,i);t.connect(i,r);for(let i of e.channels){let s=t.getVariable(Ee.CHANNEL,i,e.element),n=t.getVariable(Ee.CHANNEL,i,e.base);t.connect(n,r),t.connect(r,s)}r.run()}(a,s._depGraph)},e.align=function(e,t,i){let r=Pe(e[0]),s=new Gl(e,t,i);!function(e,t){let i=t.createMultiWayDependency(ve.ALIGNER),r=t.getVariable(Ee.ALIGNMENT,e);t.connect(r,i);for(let r of e.elements){let s=t.getVariable(Ee.CHANNEL,e.channel,r);t.connect(s,i)}i.run()}(s,r._depGraph),r._relations.push(s)},e.attach=function(e,t){if(e.type==n.Glyph)for(let t of e.children)t._refBounds||(t._refBounds=t.bounds.clone());e.dataScope=V(t)},e.canClassify=Vl,e.canDensify=tr,e.canDivide=Pl,e.canRepeat=Ti,e.childHitTest=function(e,t,i,r){let s=r?r.map(e=>obj2Predicate(e)):[];if(!e.children||0==e.children.length)return Ro(e,t,i)&&e.type!==n.Scene?e:void 0;let a=e.children;e.type===n.Scene&&(a=a.slice(),a.sort((e,t)=>ht(e)?1:ht(t)?-1:0));for(let e=0;e<a.length;e++){let r=a[e];if(Ro(r,t,i)&&te(r,s))return r}},e.childrenHitTestByRect=function(e,t,i){let r=[];if(!e.children||0==e.children.length)return e.bounds.overlap(t)&&e.type!==n.Scene?[e]:[];for(let i=e.children.length-1;i>=0;i--){let s=e.children[i];s.bounds.overlap(t)&&r.push(s)}return r},e.classify=function(e,t){let i=Pe(e),r=t||{};if(console.log("------ classify by",r.attribute," ----"),!Vl(e))throw new Error("The "+e.type+" is not classifiable");return function(e,t,i,r){let s=Ce(t);for(let t of s){let s,a={},o=t.children;for(let e of o){let t=O(e.dataScope,i);t in a||(a[t]=[]),a[t].push(e)}let l=z(o[0]);for(let o in a){let h=Bi(e,{type:n.Collection});t.addChild(h),void 0===s&&(s=h.id),h._classId=s,h.dataScope=L(t.dataScope?t.dataScope:V(l),i,o);for(let e of a[o])h.addChild(e);r&&(h._layout=r.clone(),h._layout.group=h)}}}(i,e,r.attribute,r.layout),Ze(e,e.firstChild.firstChild,i._depGraph),qe(e.firstChild,i._depGraph),$e(e.firstChild,e.firstChild.firstChild,i._depGraph),$e(e,e.firstChild,i._depGraph),i.onChange(Ee.CHANNEL,"width",e.firstChild.firstChild),e.firstChild},e.connect=function(e,t){let i=Pe(e[0]),r={};e.forEach(e=>r[O(e.dataScope,X)]=e);let s=A(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=O(e.dataScope,n),i=O(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(Ee.CHANNEL,"x",e[0])},e.contains=Ro,e.csv=async function(e){return async function(e){let t=await q("GET",e),i=r.csvParse(t.trim(),r.autoType);return new M(i,e)}(e)},e.csvString=function(e){return function(e){let t=r.csvParse(e.trim(),r.autoType);return new M(t,"fromString")}(e)},e.densify=function(e,t,i){let r=e.scene,s=i||{};if(s.attribute=s.attribute||j,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 M&&l(i.attribute,t)}(e,t,s),t instanceof F||t instanceof U)throw"Not implemented";if(t instanceof M){let i=function(e,t,i,r,s){let a=s.type(i);if(a!=h.String&&a!=h.Date&&a!=h.Number&&a!=h.Integer)throw new Error("Densify only works on a string or date attribute: "+i+" is "+a);if(!tr(t))throw new Error("The "+t.type+" is not dividable");switch(t.type){case n.Line:return function(e,t,i,r){let s,n,a=Ce(t);for(let o of a){let a=o.dataScope?o.dataScope:V(r),l=B(a,i,!1);1===l.length&&l.push(l[0]);let h=Object.assign({},o.styles);for(let e of wt.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=Bi(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,i,s);case n.Circle:return function(e,t,i,r){let s,n,a=Ce(t),o=r.type(i);for(let l of a){let a=l.dataScope?l.dataScope:V(r),c=B(a,i,o==h.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=er(l.x,l.y,l.radius,f[e]);p.push(i)}let y=Object.assign({},l.styles);y.vertices=p,y.type="polygon",y.x=l.x,y.y=l.y,y.radius=l.radius;let m=Bi(e,y);n||(n=m.id),m._classId=n,m.dataScope=a;let b=l.parent;b.addChild(m),b.removeChild(l);for(let e=0;e<m._vertices.length;e++)m._vertices.setProperty(e,"polarAngle",f[e]),m._vertices.setDataScopeRef(e,c[e]);l===t&&(s=m)}return s}(e,t,i,s);case n.Rect:return function(e,t,i,r,s){let n,a,o=Ce(t),l=i||pt;if(l!=pt&&l!=ft)throw new Error("Unknown orientation: "+l);for(let i of o){let o=s.type(r),c=i.dataScope?i.dataScope:V(s),d=B(c,r,o==h.Number);1===d.length&&d.push(d[0]),o!=h.Number&&o!=h.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(l==ft?[f,p+e*b/(d.length-1)]:[_+e*m/(d.length-1),p]);for(let e=0;e<d.length;e++)y.push(l==ft?[_,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=Bi(e,u);a||(a=x.id),x._classId=a,x.dataScope=c,x.orientation=l,x.baseline=l===pt?ue.BOTTOM:ue.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,r,i,s)}}(r,e,s.attribute,s.orientation,t);return He(e,r._depGraph),Ye(i,r._depGraph),i.parent.type!==n.Scene&&$e(i.parent,i,r._depGraph),function(e,t,i){let r=i.findVariable(Ee.ITEMS,[t]);if(!r)return;let s=null;for(let e of r.outgoingEdges)if(e.isDirected&&e.toNode.type===ve.REPOPULATE){s=e.toNode;break}if(!s)return;let n=i.getVariable(Ee.DATASCOPE,e);if(i.connect(s,n),e._vertices&&e._vertices.length>0){let t=e.vertices[0],r=i.getVariable(Ee.DATASCOPE,t);i.connect(s,r)}}(i,t,r._depGraph),i.type===n.Area&&function(e,t,i,r){let s=r.findVariable(Ee.ITEMS,[i]);if(!s)return;for(let e of s.outgoingEdges)if(e.isDirected&&e.toNode.type===ve.REPOPULATE)return;let n=r.createOneWayDependency(ve.REPOPULATE);n._area=e,n._repeatAttr=t,r.connect(s,n);let a=r.getVariable(Ee.DATASCOPE,e);if(r.connect(n,a),e._vertices&&e._vertices.length>0){let t=r.getVariable(Ee.DATASCOPE,e.vertices[0]);r.connect(n,t)}}(i,s.attribute,t,r._depGraph),r.onChange(Ee.CHANNEL,"width",i),i}},e.deserialize=function(e){return lo(e)},e.divide=function(e,t,i){let r=e.scene,s=i||{};if(s.attribute=s.attribute||j,console.log("------ divide by",s.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 M&&l(i.attribute,t);if(i.layout&&!(i.layout instanceof ge))throw new Error("Invalid layout: "+i.layout)}(e,t,s),t instanceof F||t instanceof U)throw"Not implemented";if(t instanceof M){let{newMark:i,collection:a}=function(e,t,i,r,s){let a=s.type(i);if(a!=h.String&&a!=h.Date&&a!=h.Integer)throw new Error("Divide only works on a string or date attribute: "+i+" is "+a);if(!Pl(t))throw new Error("The "+t.type+" is not dividable");switch(t.type){case n.Line:case n.Path:return;case n.Circle:return function(e,t,i,r,s){let a,o,l,h=Ce(t),c=i||gt;if(c!=gt&&c!=yt)throw new Error("Unknown orientation: "+c);c===gt&&h.forEach(i=>{let h=i.dataScope?i.dataScope:V(s),c=B(h,r),d=Bi(e,{type:n.Collection});null==o&&(o=d.id),d._classId=o,d.dataScope=h;let u=i.parent;u.removeChild(i),delete e._itemMap[i.id];let _=360/c.length,p=90;for(let r=0;r<c.length;r++){let s=Bi(e,{type:"arc",innerRadius:0,outerRadius:i.radius,x:i.x,y:i.y,startAngle:Lt(p-_*(r+1)),endAngle:Lt(p-_*r),strokeColor:i.strokeColor,fillColor:i.fillColor,strokeWidth:i.strokeWidth,opacity:i.opacity});l||(l=s.id),s.classId=l,s.dataScope=c[r],s._updateBounds(),s._refBounds=s.bounds.clone(),d.addChild(s),d._layout=new Ja({orientation:gt,direction:bt.CLOCKWISE}),d._layout.group=d,u.removeChild(i),u.addChild(d),i===t&&(a=d)}});return{newMark:a.children[0],collection:a}}(e,t,r,i,s);case n.Rect:return function(e,t,i,r,s){let a,o=Ce(t),l=i||pt;if(l!=pt&&l!=ft)throw new Error("Unknown orientation: "+l);let h={},c=0;for(let e of o){let t=B(e.dataScope?e.dataScope:V(s),r);t.length>c&&(c=t.length),h[e.id]=t}let d,u=Bi(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 i of o){let r=Bi(e,{type:n.Collection});null==d&&(d=r.id),r._classId=d,r.dataScope=i.dataScope?i.dataScope:V(s);let o=i.parent;o.removeChild(i),delete e._itemMap[i.id];let c=h[i.id],_=i.bounds,p=_.left,f=_.top,g=l==pt?_.width/c.length:_.width,y=l==pt?_.height:_.height/c.length;for(let e=0;e<c.length;e++){let t=Gi(u);t.dataScope=c[e],t.resize(g,y),t._updateBounds(),t._refBounds=t.bounds.clone(),r.addChild(t)}o.addChild(r),r._layout=new Ja({orientation:l,left:p,top:f}),r._layout.group=r,i==t&&(a=r)}return e.removeChild(u),delete e._itemMap[u.id],{newMark:a.children[0],collection:a}}(e,t,r,i,s);case n.Area:return function(e,t,i,r,s){let a,o=Ce(t),l=i||pt;if(l!=pt&&l!=ft)throw new Error("Unknown orientation: "+l);let h,c={},d=0;for(let e of o){let t=B(e.dataScope?e.dataScope:V(s),r);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 _=Bi(e,u);_._classId=_.id;for(let i of o){let r=Bi(e,{type:n.Collection});null==h&&(h=r.id),r._classId=h,r.dataScope=i.dataScope?i.dataScope:V(s);let o=i.parent;o.removeChild(i),delete e._itemMap[i.id];let d=c[i.id],u=i.bounds,p=u.left,f=u.top,g=l==pt?u.width/d.length:u.width,y=l==pt?u.height:u.height/d.length;for(let e=0;e<d.length;e++){let t=Gi(_);t.dataScope=d[e],t.resize(g,y),t._updateBounds(),t._refBounds=t.bounds.clone(),r.addChild(t);for(let e=0;e<t.vertices.length;e++){let r=t.vertices[e],s=i.vertices[e];s&&s.dataScope?r.dataScope=P(t.dataScope,s.dataScope):r.dataScope=t.dataScope}}o.addChild(r),r._layout=new Ja({orientation:l,left:p,top:f}),r._layout.group=r,i==t&&(a=r)}return e.removeChild(_),delete e._itemMap[_.id],{newMark:a.children[0],collection:a}}(e,t,r,i,s);case n.Ring:return function(e,t,i,r,s){let a,o,l,h=Ce(t),c=i||gt;if(c!=gt&&c!=yt)throw new Error("Unknown orientation: "+c);c===gt&&h.forEach(i=>{let h=i.dataScope?i.dataScope:V(s),c=B(h,r),d=Bi(e,{type:n.Collection});null==o&&(o=d.id),d._classId=o,d.dataScope=h;let u=i.parent;u.removeChild(i),delete e._itemMap[i.id];let _=360/c.length,p=90;for(let r=0;r<c.length;r++){let s=Bi(e,{type:"arc",innerRadius:i.innerRadius,outerRadius:i.outerRadius,x:i.x,y:i.y,startAngle:Lt(p-_*(r+1)),endAngle:Lt(p-_*r),strokeColor:i.strokeColor,fillColor:i.fillColor,strokeWidth:i.strokeWidth,opacity:i.opacity});l||(l=s.id),s.classId=l,s.dataScope=c[r],s._updateBounds(),s._refBounds=s.bounds.clone(),d.addChild(s),d._layout=new Ja({orientation:gt,direction:bt.CLOCKWISE}),d._layout.group=d,u.removeChild(i),u.addChild(d),i===t&&(a=d)}});return{newMark:a.children[0],collection:a}}(e,t,r,i,s);case n.Pie:case n.Arc:return function(e,t,i,r,s){let a,o,l,h=Ce(t),c=i||gt;if(c!=gt&&c!=yt)throw new Error("Unknown orientation: "+c);c===gt||h.forEach(i=>{let h=i.dataScope?i.dataScope:V(s),c=B(h,r),d=Bi(e,{type:n.Collection});null==o&&(o=d.id),d._classId=o,d.dataScope=h;let u=i.parent;u.removeChild(i),delete e._itemMap[i.id];for(let r=0;r<c.length;r++){let s=Bi(e,{type:"arc",innerRadius:i.innerRadius+r*(i.outerRadius-i.innerRadius)/c.length,outerRadius:i.innerRadius+(r+1)*(i.outerRadius-i.innerRadius)/c.length,x:i.x,y:i.y,startAngle:i.startAngle,endAngle:i.endAngle,strokeColor:i.strokeColor,fillColor:i.fillColor,strokeWidth:i.strokeWidth,opacity:i.opacity});l||(l=s.id),s.classId=l,s.dataScope=c[r],s._updateBounds(),s._refBounds=s.bounds.clone(),d.addChild(s),d._layout=new Ja({orientation:yt}),d._layout.group=d,u.removeChild(i),u.addChild(d),i===t&&(a=d)}});return{newMark:a.children[0],collection:a}}(e,t,r,i,s)}}(r,e,s.attribute,s.orientation,t);return He(e,r._depGraph),Ye(i,r._depGraph),qe(a,r._depGraph),$e(a,i,r._depGraph),a.parent.type!==n.Scene&&$e(a.parent,a,r._depGraph),r.onChange(Ee.CHANNEL,"width",i),{newMark:i,collection:a}}},e.encode=wi,e.findElements=Oe,e.getChannelEncodingByAttribute=di,e.getChannelEncodingByElement=ui,e.getEncodingsByChannel=function(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},e.getEncodingsByElement=ci,e.getLeafMarks=Be,e.getPeers=Ce,e.gradient=function(e,t){return"path"===e?new Zt(t):new Kt(t)},e.graphJSON=async function(e){return async function(e){let t=await q("GET",e);return new U(JSON.parse(t),e)}(e)},e.isDataBound=function(e,t){return"x"===t||"width"===t?gi(e):"y"===t||"height"===t?fi(e):null!==ui(e,t)},e.isDataBoundHorizontally=gi,e.isDataBoundVertically=fi,e.isEqual=function(e,t){return function(e,t){return e.fillColor!==t.fillColor?(console.log("fillColor not equal:",e,t),!1):Nl(e,t)}(e,t)},e.isMark=pe,e.isRefElement=ht,e.layout=function(e,t){let i=t||{};switch(e.toLowerCase()){case me.STACK:return new Ja(i);case me.PACKING:return new $a(i);case me.FORCE:return new Za(i);case me.DIRECTED:return new Ka(i);case me.TIDYTREE:return new eo(i);case me.TREEMAP:return new to(i);case me.CIRCULAR:return new ro(i);case me.CLUSTER:return new Ll(i);case me.SPIRAL:return new io(i);case me.GRID:default:return new Oi(i)}},e.markHitTest=function(e,t,i,r){let s=Be(e),n=r?r.map(e=>obj2Predicate(e)):[];for(let e=s.length-1;e>=0;e--){let r=s[e];if(Ro(r,t,i)&&te(r,n))return r}},e.markPrimitiveHitTest=function(e,t,i,r){let s,n=Be(e),a=r||2,o=ko.getContext();for(let e of n){if(!(e instanceof Path))continue;let r=ko.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 oe(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=ko.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},e.markPrimitiveHitTestByRect=function e(t,i,r){let s=r||2;if(pe(t)){let e=[];for(let i of t.vertices){let t=Math.max(s,i.width,2*i.radius),r=Math.max(s,i.height,2*i.radius);e.push({i:i,b:new oe(i.x-t/2,i.y-r/2,t,r)})}if(t.type===ItemType.Rect)for(let i of t.segments){let r=Math.max(t.strokeWidth,s);"v"===(i.vertex1.x===i.vertex2.x?"v":"h")?e.push({i:i,b:new oe(i.vertex1.x-r/2,d3.min([i.vertex1.y,i.vertex2.y])-r/2,r,Math.abs(i.vertex1.y-i.vertex2.y))}):e.push({i:i,b:new oe(d3.min([i.vertex1.x,i.vertex2.x])-r/2,i.vertex1.y-r/2,Math.abs(i.vertex1.x-i.vertex2.x),r)})}for(let t of e)if(t.b.intersects(i))return t.i;return null}if(!isGuide(t)&&t.children&&t.children.length>0){for(let r of t.children)if(r.bounds.intersects(i)){let t=e(r,i,s);if(t)return t}return null}return null},e.removeEncoding=hi,e.renderer=function(e,t){return new wl(t)},e.repeat=ki,e.repopulate=function(e,t,i){e.dataScope=void 0;let r=Pe(e),s=e;for(let e in i){fr(r,s,i[e],t);let n=ci(s.children[0],!0);for(let e of n)hi(e,r);let a=Ce(s);for(let e of a)if(e.layout){for(let t of e.layout.refElements)Jt(t,r),Xe(t,r._depGraph);e.layout.clearRefElements()}s=s.children[0]}e.dataScope=V(t),r.onChange(Ee.CHANNEL,"width",e.children[0])},e.scene=function(e){return new Xa(e)},e.serialize=function(e){return xo(e)},e.sortChildren=function(e,t,i,r){let s=Pe(e);if(e instanceof lt)!function(e,t,i,r){e.dataScope&&A(e.dataScope).has(t)?function(e,t,i,r){if(!A(e.dataScope).has(t))return void console.warn("Cannot order collection children by an non-existent attribute",t);let s;if(t===j)s=(e,i)=>parseInt(O(e.dataScope,t).substring(1))-parseInt(O(i.dataScope,t).substring(1));else{switch(A(e.children[0].dataScope).type(t)){case h.Date:break;case h.Number:case h.Integer:s=(e,i)=>N(e.dataScope,t)-N(i.dataScope,t);break;case h.String:s=r?(e,i)=>r.indexOf(O(e.dataScope,t))-r.indexOf(O(i.dataScope,t)):(e,i)=>O(e.dataScope,t)<O(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(Ee.PROPERTY,We.CHILDREN_ORDER,e);else if(e instanceof Ct){let s=Ce(e);for(let e of s)Fl(e,t,i,r)}},e.stratify=function(e,t,i){if(!(t instanceof F||Array.isArray(t)&&t.every(e=>e instanceof F)))throw"Cannot stratify on a non-tree dataset";if(![n.Circle,n.Rect,n.Ring].includes(e.type))throw"Cannot stratify elements that are not rects, circles, or rings";let r=Pe(e),s=i||{},a=s.direction,o=s.size,l=e.parent,h=function(e,t,i,r,s,a){switch(t.type){case n.Circle:case n.Ring:return function(e,t,i,r,s,a){let o,l=i||xt.OUTWARD,h=s||50;if(l!==xt.INWARD&&l!==xt.OUTWARD)throw"Unknown direction to stratify";let c,d=Ce(t,e),u=Array.isArray(a)?a:[a];if(r){let i=Bi(e,{type:n.Collection});i.dataScope=void 0,null==c&&(c=i.id),i._classId=c;let r=d.map(e=>u[0].getNode(e.datum[X]));Bl(e,d,r,u[0],i,t.classId?t.classId:t.id,400,350,l,h),o=i}else d.forEach((i,r)=>{let s=Bi(e,{type:n.Collection});s.dataScope=void 0,null==c&&(c=s.id),s._classId=c;let a=i.parent;Dl(i,t.id,l,h,u[r],u[r].getRoot(),s,e,!0),s._layout=new Qa({direction:l}),s._layout.group=s,a.addChild(s),i===t&&(o=s)});return o}(e,t,i,r,s,a);case n.Rect:return function(e,t,i,r,s,a){let o,l,h=i||mt.Top2Bottom,c=s||50;if(!Object.values(mt).includes(h))throw"Unknown direction to stratify";return Ce(t).forEach(i=>{let r=Bi(e,{type:n.Collection});r.dataScope=void 0,null==l&&(l=r.id),r._classId=l;let s=i.parent;Ml(i,t.id,h,c,a,a.getRoot(),r,e,!0),r._layout=new Qa({direction:h}),r._layout.group=r,s.addChild(r),i===t&&(o=r)}),o}(e,t,i,0,s,a)}}(r,e,a,s.startFromLeaf,o,t);return Ze(l,e,r._depGraph),qe(h,r._depGraph),h.children.length>0&&$e(h,h.firstChild,r._depGraph),$e(h.parent,h,r._depGraph),h},e.table=function(e){return new M(e,"")},e.transform=function(e,t,i){switch(e){case"kde":return new Wa(t);case"filter":return new Ua(t);case"custom":return new Ya(t,i);default:return new Fa(t)}},e.translate=function(e,t,i){xi(e,t,i);let r=Pe(e);if(!r)return;let s=Be(e,!0);for(let e of s)de(e);for(let e of s)r.onChange(Ee.CHANNEL,"x",e)},e.treeJSON=async function(e){return async function(e){let t=await q("GET",e);return new F(JSON.parse(t),e)}(e)},e.update=function(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(ye(e)){let i=e.group?[e.group]:[],r=[];for(let e of i)r=r.concat(Ce(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=Pe(e);if(s)for(let e of i)e.firstChild&&s.onChange(Ee.CHANNEL,"width",e.firstChild);return}let i=Ce(e),r=Pe(e);for(const[s,n]of Object.entries(t))if("layout"!==s)for(let e of i)ir(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(Ge).includes(i)?r.onChange(Ee.CHANNEL,i,e):r.onChange(Ee.PROPERTY,i,e)))}});
|
|
4
|
+
e.polarAngle=i;break;case"polarRadius":{let t=sr(r&&r._preferredOrigin?r._preferredOrigin[0]:e.parent.x,r&&r._preferredOrigin?r._preferredOrigin[1]:e.parent.y,i,e.polarAngle);lr(e,t[0]),hr(e,t[1]);break}case"visibility":e.visibility=i;break;case"src":e.src=i;break;case"path":e.path=i;break;case"vxOpacity":if(e instanceof Ct)for(let r of e.children)ar(r,t,i);else e.vxOpacity=i;break;default:if("vertex"===e.type)e[t]=i;else if(e instanceof Ct)for(let r of e.children)ar(r,t,i);else{if(e.styles[t]==i)return;e.styles[t]=i}}"vertex"===e.type?e.parent._dirty=!0:e._dirty=!0}function or(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 lr(e,t){"vertex"==e.type?e.x=t:Et(e,t-e.x,0)}function hr(e,t){"vertex"==e.type?e.y=t:Et(e,0,t-e.y)}class cr extends we{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 dr extends xe{constructor(e){super(e)}storeValues(e,t){this._storedValues={};let i=Ce(e);for(let e of i)this._storedValues[e.id]=e[t]}_restoreValue(e,t){let i=this._storedValues[e.id];e[t]!==i&&ar(e,t,i)}run(){super.run();let e=this.inputVars.find(e=>e instanceof qi),t=this.outputVar,i=e?e.getEncoding(t.channel,t.element):null,r=t.channel,s=this.inputVars.filter(e=>e instanceof cr),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 de(t.element.parent);let l=Ce(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){de(["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=Re(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 oe(r.flipScale?i.range[1]:i.range[0],s.top,i.rangeExtent,s.height):"y"===t&&(e._refBounds=new oe(s.left,r.flipScale?i.range[0]:i.range[1],s.width,i.rangeExtent))}_updateRefBounds(e,t,i){switch(this.outputVar.channel){case"width":e._refBounds.setWidth(t.rangeExtent);break;case"height":e._refBounds.setHeight(t.rangeExtent);break;case"radius":e._refBounds.setWidth(2*t.rangeExtent,ue.CENTER),e._refBounds.setHeight(2*t.rangeExtent,ue.MIDDLE);break;case"x":if("vertex"==e.type||"segment"==e.type){let r=e.parent._refBounds;e.parent._refBounds=new oe(i.flipScale?t.range[1]:t.range[0],r.top,t.rangeExtent,r.height)}else if(e._refBounds)if("band"===t.type){let r=t.map(i.attrValues[e.id]),s=e._refBounds;e._refBounds=new oe(r-e.width/2,s.top,e.width,s.height)}else{let r=e.parent;for(;r&&(!r.layout||r.layout.type!==me.GRID);)r=r.parent;if(r){let r=e._refBounds;e._refBounds=new oe(i.flipScale?t.range[1]:t.range[0],r.top,t.rangeExtent,r.height)}}break;case"y":if("vertex"==e.type||"segment"==e.type){let r=e.parent._refBounds;e.parent._refBounds=new oe(r.left,i.flipScale?t.range[0]:t.range[1],r.width,t.rangeExtent)}else if(e._refBounds){let s=e.parent;for(;s&&(!s.layout||s.layout.type!==me.GRID);)s=s.parent;if(s){let s=e._refBounds,n=r.min(t.range);e._refBounds=new oe(s.left,i.flipScale?t.range[0]:n,s.width,t.rangeExtent)}}}}_doMapping(e,t,i,r){switch(this.outputVar.channel){case"width":t.domain[0]<0&&e instanceof hi?function(e,t,i){let r=e.refBounds.left+t.map(0),s=e.refBounds.left+t.map(i[e.id]);Et(e.leftSegment,r-e.leftSegment.x,0),Et(e.rightSegment,s-e.rightSegment.x,0)}(e,t,i):t.domain[0]<0&&e instanceof Jt||(e.type===n.Area?function(e,t,i){let r=e.baseline;if(e.orientation===Nt){let s=e._vertices.length/2;switch(r){case"left":Ri(e,s,e._vertices.length,e.refBounds.left),ki(e,0,s,r=>e.refBounds.left+t.map(i[Re(e,r)]));break;case"right":ki(e,s,e._vertices.length,r=>e.refBounds.right-t.map(i[Re(e,r)])),Ri(e,0,s,e.refBounds.right);break;case"center":console.log("center"),ki(e,s,e._vertices.length,r=>e.refBounds.center-t.map(i[Re(e,r)])/2),ki(e,0,s,r=>e.refBounds.center+t.map(i[Re(e,r)])/2)}}}(e,t,i):this._doStandardMapping(e,t,i,r));break;case"height":t.domain[0]<0&&e instanceof hi?function(e,t,i){let r=e.refBounds.bottom-t.map(0),s=e.refBounds.bottom-t.map(i[e.id]);Et(e.bottomSegment,0,r-e.bottomSegment.y),Et(e.topSegment,0,s-e.topSegment.y)}(e,t,i):t.domain[0]<0&&e instanceof Jt?function(e,t,i){let r=e._vertices.length/2;Oi(e,0,r,r=>e.refBounds.bottom-t.map(i[Re(e,r)])),Ti(e,r,e._vertices.length,e.refBounds.bottom-t.map(0))}(e,t,i):e.type===n.Area?function(e,t,i){let r=e.baseline;if(e.orientation===It){let s=e._vertices.length/2;switch(r){case"top":Oi(e,s,e._vertices.length,r=>e.refBounds.top+t.map(i[Re(e,r)])),Ti(e,0,s,e.refBounds.top);break;case"middle":Oi(e,0,s,r=>e.refBounds.middle-t.map(i[Re(e,r)])/2),Oi(e,s,e._vertices.length,r=>e.refBounds.middle+t.map(i[Re(e,r)])/2);break;default:Oi(e,0,s,r=>e.refBounds.bottom-t.map(i[Re(e,r)])),Ti(e,s,e._vertices.length,e.refBounds.bottom)}}}(e,t,i):this._doStandardMapping(e,t,i,r);break;case"text":this._doTextMapping(e,i);break;case"fillGradient":!function(e,t,i,r){let s=e._vertices._ids.map((t,r)=>i[Re(e,r)]),n=d3.min(s),a=d3.max(s),o="horizontal"===e.orientation?new ui({x1:0,y1:100,x2:0,y2:0}):new ui({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,i,r);break;case"strokeGradient":!function(e,t,i){let r=[];for(let s=0;s<e._vertices.length;s++)r.push(t.map(i[Re(e,s)]));e.strokeColor=new _i(r)}(e,t,i);break;default:this._doStandardMapping(e,t,i,r)}}_doTextMapping(e,t){ar(e,this.outputVar.channel,t[e.id])}_doStandardMapping(e,t,i,r){let s=this.outputVar.channel,n=t.map(i[e.id]);ar(e,s,n,r),e instanceof Ft&&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),ar(t,i,s)}}class ur extends xe{constructor(e){super(e)}run(){let e=this.outputVar.element;e.updateValues(),e.scale?this._runForEncoding(e):this._runForLayout(e),de(e)}_runForLayout(e){let t=e.channel,i=he(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=he(e.elements),r=[];if("x"===t){let t,s,n=gt(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=gt(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 _r extends xe{constructor(e){super(e)}run(){let e=this.outputVar.element;e.updatePoints(),e._dirty=!0,de(e)}}class pr extends xe{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=Be(e)[0],i=Ce(e.parent);for(let e of i){let i=e.layout;if(!i)return;switch(t.type){case n.Rect:case n.Circle:case n.Image:case n.Symbol:this._stackRects(e,i);break;case n.Area:e.children[0].orientation===It?this._stackAreasVert(e,i):this._stackAreasHorz(e,i);break;case n.Arc:case n.Pie:t.parent.classId===e.classId&&this._stackArcs(e,i)}}de(t)}_stackArcs(e,t){if(t.orientation===Lt){let t=90;if((this._direction?this._direction:Bt.Clockwise)===Bt.Clockwise)for(let i of e.children){let e=Zt(t-i.angle);ar(i,"startAngle",e),t=e}else for(let i of e.children){let e=Zt(t+i.angle);ar(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;ar(i,"innerRadius",t),ar(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===ue.TOP?r.top:r.bottom,n=t.vertCellAlignment===ue.TOP?1:-1;if(0===i.length)return;t.vertCellAlignment===ue.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;Et(i,0,h-i.y),Et(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===ue.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;Et(i,0,n-r.bottom),Et(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==Nt)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,Et(r,s,n),r._updateBounds();let a=0,o=0;if(!xt(r))switch(t._horzCellAlignment){case ue.LEFT:a=l-r.bounds.left;break;case ue.CENTER:a=l+c/2-r.bounds.x;break;case ue.RIGHT:a=l+c-r.bounds.right}Et(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,Et(r,s,n),r._updateBounds();let a=0,o=0;if(!bt(r))switch(t._vertCellAlignment){case ue.TOP:o=h-r.bounds.top;break;case ue.MIDDLE:o=h+d/2-r.bounds.y;break;case ue.BOTTOM:o=h+d-r.bounds.bottom}Et(r,a,o)}}}class fr extends xe{constructor(e){super(e)}run(){super.run()}}class gr extends xe{constructor(e){super(e)}run(){let e=this._binConfig.attribute,t=this._binConfig.startAttr,i=this._binConfig.endAttr,s=this._binConfig.binIdAttr,n=this.inputVars[0].dataset,a=this.outputVar.dataset,o=n.values(e),l=r.bin();null!=this._binConfig?.numBins&&(l=l.thresholds(this._binConfig.numBins));let c=l(o);this._binConfig.actualNumBins=c.length;let d=String(c.length-1).length,u=e=>String(e).padStart(d,"0"),_=this._findBin,p=o.map(e=>_(e,c).x0),f=o.map(e=>_(e,c).x1),g=o.map(e=>{let t=c.indexOf(_(e,c));return u(t)}),y=c.map((e,t)=>u(t));a.addAttr(t,h.Number,p),a.addAttr(i,h.Number,f),a.addAttr(s,h.String,g),a.order(s,y)}_findBin(e,t){for(let i of t)if(i.indexOf(e)>=0)return i}}class yr extends we{constructor(e,t){super(e),this._dataset=t}get dataset(){return this._dataset}}class mr extends xe{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof yr),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=ee(r);t.load(i.data.filter(e=>s.testTuple(e)))}}function br(e,t,i,r){let s=r.type(i);if(s!=h.String&&s!=h.Date&&s!=h.Integer)throw new Error("Repopulate only works on a string or date attribute: "+i+" is "+s);let n=Ce(t);for(let e of n){let t=B(e.dataScope?e.dataScope:V(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=Wi(e._children[t%a]);e.addChild(i)}e.children.forEach((e,i)=>e.dataScope=t[i])}}class xr extends xe{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;Pe(this._area);return function(e,t,i,r){let s=r.type(i),n=V(r),a=B(n,i,s===h.Number);s!==h.Number&&s!==h.Date||a.sort((e,t)=>e.filters[i]>t.filters[i]?1:-1),1===a.length&&a.push(a[0]);let o=a.length,l=t.refBounds??t.bounds,{left:c,top:d,right:u,bottom:_}=l,p=u-c,f=_-d,g=t.orientation===Nt,y=[];if(o>0){for(let e=0;e<o;e++)y.push(g?[u,d+e*f/(o-1)]:[c+e*p/(o-1),d]);for(let e=0;e<o;e++)y.push(g?[c,d+(o-1-e)*f/(o-1)]:[c+(o-1-e)*p/(o-1),_])}t.vertices=y;for(let e=0;e<t._vertices.length;e++){let i=e<o?a[e]:a[2*o-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[Re(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[Re(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;Pe(i);i.dataScope=void 0,br(0,i,this._repeatAttr,t),i.dataScope=V(t);for(let e of pt(i.children[0],!0))e.refreshElementMappings();if(i.layout)for(let e of i.layout.refElements)e instanceof Di&&(e._elems=i.children.slice());this.needsFullRender=!0}}class vr extends xe{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e.type===Ee.AFFIXATION).affixation,t=e.base,i=e.element,r=Ce(t),s=Ce(i),n=e.channels,a=e.attribute;if(s.length!==r.length)throw new Error(`affix: cannot pair ${s.length} ${i.type} element(s) with ${r.length} ${t.type} base element(s); the element and the base must have the same number of instances. Check that the base is the element that repeats once per affixed element (for example, the collection returned by divide() rather than the outer collection returned by repeat()).`);if(pe(i)&&pe(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=Be(i,!0);for(let e of o)de(e)}_handlePolar(e,t,i){let r="polarRadius",s=i.hasChannel(r)?i.getBaseAnchor(r):ue.MIDDLE,a=i.hasChannel(r)?i.getElementAnchor(r):ue.MIDDLE,o=i.hasChannel("angle")?i.getBaseAnchor("angle"):ue.CENTER;i.hasChannel("angle")?i.getElementAnchor("angle"):ue.CENTER;let l=i.hasChannel(r)?i.getOffset(r):0,h=i.hasChannel("angle")?i.getOffset("angle"):0;if([n.Arc,n.Ring].indexOf(t[0].type)>=0&&e[0].type==n.SimpleText)for(let i=0;i<e.length;i++){let r=t[i],a=e[i],h=s===ue.MIDDLE?(r.outerRadius+r.innerRadius)/2:s===ue.TOP?r.outerRadius-5:r.innerRadius+5;if(h+=l,r.type===n.Arc){let e=sr(r.x,r.y,h,r.startAngle),t=sr(r.x,r.y,h,r.endAngle);r.endAngle>=180&&r.endAngle<=360?a._textPath=["M",e[0],e[1],"A",h,h,r.angle,r.angle>=180?1:0,0,t[0],t[1]].join(" "):a._textPath=["M",t[0],t[1],"A",h,h,r.angle,r.angle>=180?1:0,1,e[0],e[1]].join(" ")}else if(r.type===n.Ring){let e=275,t=265,i=350,s=sr(r.x,r.y,h,e),n=sr(r.x,r.y,h,t);a._textPath=["M",n[0],n[1],"A",h,h,i,1,1,s[0],s[1]].join(" ")}a.textPathOffset=o===ue.LEFT?"0%":"50%"}else for(let i=0;i<e.length;i++){let r,c,d=t[i],u=e[i];d.type==n.Arc||d.type==n.Ring?(c="left"==o?d.endAngle+h:"center"==o?d.startAngle+d.angle/2+h:d.startAngle+h,r="top"==s?d.outerRadius+l:"bottom"==s?d.innerRadius+l:(d.outerRadius+d.innerRadius)/2+l):d.type==n.Circle&&(c=90,r="top"==s?d.radius+l:"bottom"==s?l:d.radius/2+l),Et(u,d.x-u.x,d.y-r-u.bounds[a]),u._rotate=[90-c,d.x,d.y]}}_handleXY(e,t,i,r,s,a){for(let o=0;o<t.length;o++){let l,h=i[o],c=t[o];if(Ut(h)){l=Wt(h,[ue.LEFT,ue.TOP].includes(s)?0:[ue.CENTER,ue.MIDDLE].includes(s)?.5:1)[e]}else l=h.bounds[s]+a;t[0].type===n.SimpleText?(c.anchor["x"==e?0:1]=r,ar(c,e,l)):"x"==e?Et(c,l-c.bounds[r],0):Et(c,0,l-c.bounds[r])}}}class wr extends we{constructor(e,t){super(e),this._affx=t}get affixation(){return this._affx}}class Er extends xe{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,a=this.args,o=null!=a.min?a.min:s.summary(i).min,l=null!=a.max?a.max:s.summary(i).max,c=o,d=[];for(;c<l;)d.push(c),c+=a.interval;d.push(c);let u={},_={};if(a.groupBy)for(let e of s.data){let t=a.groupBy.map(t=>e[t]).join("-");t in u||(u[t]=[],_[t]=a.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=Ar(Cr(a.bandwidth),d,u[e]);for(let s of t){let t={};""!==e&&a.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]=h.Number,a.groupBy)for(let e of a.groupBy)f[e]=s.type(e);n.initialize(p,n.url,f)}}function Ar(e,t,i){return t.map(t=>[t,r.mean(i,i=>e(t-i))])}function Cr(e){return t=>Math.abs(t/=e)<=1?.75*(1-t*t)/e:0}class Sr extends xe{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof yr);if(!e)return;let t=e.dataset,i=this.outputVar.dataset;this._spec.fn(t,i,this._spec)}}class Rr extends xe{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof yr),t=this.outputVar.dataset;if(!e)return;let i=e.dataset,r=this._spec,s=i.attrs().filter(e=>e!==j),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 kr extends xe{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=Ce(e.parent);for(let e of t){let t=e.layout;if(!t)return;let i=e.children.map(e=>({name:e.id,radius:e.radius,itm:e})),s=i.reduce((e,t)=>e+Math.pow(t.radius,2),0),n=Math.sqrt(s);void 0===t._width&&(t._width=n),void 0===t._height&&(t._height=n);let a=r.hierarchy({name:"root",children:i}).sum(e=>e.radius?e.radius:0).sort((e,t)=>t.value-e.value);r.pack().size([t._width,t._height]).radius(e=>e.value)(a);for(let e of a.children){let i=e.data.itm;Et(i,t._x-a.x+e.x-i.x,t._y-a.y+e.y-i.y)}}let i=Be(e,!0);for(let e of i)de(e)}}class Tr extends xe{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof ze&&e.property==We.AXIS_PATH_POSITION).element;e instanceof bi?this._runForEncoding(e):e instanceof Di&&this._runForLayout(e),de(e._title)}_runForEncoding(e){let t=e.channel,i=he(e.elements);if("x"==t)e._title.x=(e.scale.range[0]+e.scale.range[1])/2,e._title._y=e.orientation==gi?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==gi?e._pathPos+e.titleOffset:e._pathPos-e.titleOffset;else if("y"===t)e._rotateYTitle?(e._title.x=e.orientation==yi?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==yi?[-90,e._title._x,e._title._y]:[90,e._title._x,e._title._y]):(e._title.x=e.orientation==yi?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==yi?[-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==gi?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==me.STACK?ce(e.elements):he(e.elements);if("x"==t)e._title.x=i.center,e._title._y=e.orientation==gi?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==yi?[-90,i.center,i.middle]:[90,i.center,i.middle];else if("angle"===t){let t=e.elements[0].parent.layout;t.type===me.CLUSTER&&(e._title.x=t.x,e._title._y=t.y)}}}class Or extends Hi{constructor(e){super(e)}run(){super.run();let e,t=this.vars.find(e=>e.type===Ee.ALIGNMENT).alignment,i=t.anchor,s=t.elements;i==ue.Top||i==ue.LEFT?e=r.min(s.map(e=>e.bounds[i])):i==ue.BOTTOM||i==ue.RIGHT?e=r.max(s.map(e=>e.bounds[i])):i!=ue.CENTER&&i!=ue.MIDDLE||(e=r.mean(s.map(e=>e.bounds[i])));for(let r of s){let s=vt(r,t.channel);if(s){let n=e-r.bounds[i];Et(s,"x"===t.channel?n:0,"x"===t.channel?0:n)}}for(let e of s)de(e)}}class Ir extends we{constructor(e,t){super(e),this._aln=t}get alignment(){return this._aln}}class Nr extends xe{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=Ce(e.parent);for(let e of t){let t=e.layout;if(!t)continue;let i=Y(e.children[0]);if(!i)continue;let s=i.linkList.map(e=>({source:i.getNode(e.source),target:i.getNode(e.target)})),n=r.forceSimulation(i.nodeList).force("charge",r.forceManyBody().strength(-t._repulsion)).force("link",r.forceLink(s).id(e=>e.id).distance(t._linkDistance)).force("x",r.forceX()).force("y",r.forceY()).force("center",r.forceCenter(t._x,t._y).strength(t._attraction));n.stop(),n.tick(t._iterations);for(let t=0;t<e.children.length;t++){let r=e.children[t],s=i.nodeList[t];Et(r,s.x-r.x,s.y-r.y)}}let i=Be(e,!0);for(let e of i)de(e)}}class Lr extends xe{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=Ce(e);switch(e.type){case n.Arc:this._updateArcLinks(t);break;case n.BezierCurve:this._updateBezierLinks(t);break;case n.BundledPath:this._updateBundledLinks(t);break;case n.Chord:this._updateChordLinks(t);break;case n.Line:default:this._updateLineLinks(t)}de(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=$t(e.x,e.y,t._x,t._y),s=$t(i.x,i.y,t._x,t._y);t.direction===Bt.CLOCKWISE&&([r,s]=[s,r]),ar(t,"startAngle",r),ar(t,"angle",Math.abs(s-r))}}_updateBezierLinks(e){let t=this._inputVars[0].element,i=Ce(t),r=t.parent.layout;r.type===me.DIRECTED||r.type===me.TIDYTREE?this._updateBezierLinksForDirectedGraph(i,e,r):r.type===me.CLUSTER&&this._updateBezierLinksForClusteredGraph(i,e,r)}_updateBezierLinksForClusteredGraph(e,t,i){const s=i._d3Root.descendants(),n=new Map(s.map(e=>[Pr(e),e])),a=new Map(s.map(e=>[e.data[X],Pr(e)]));if(i.isRadial()){const e=r.linkRadial().angle(e=>e.x).radius(e=>e.y);for(let r of t){let t=r.source,s=r.target,o=t.datum[X],l=s.datum[X],h=n.get(a.get(o)),c=n.get(a.get(l));r._d=Ht(e({source:h,target:c}),i.x,i.y)}}else if(i.orientation===Nt){const e=r.linkVertical().x(e=>e.x).y(e=>e.y);for(let r of t){let t=r.source,s=r.target,o=t.datum[X],l=s.datum[X],h=n.get(a.get(o)),c=n.get(a.get(l));r._d=Ht(e({source:h,target:c}),i.left-i._x0,i.top)}}else if(i.orientation===It){const e=r.linkHorizontal().x(e=>e.y).y(e=>e.x);for(let r of t){let t=r.source,s=r.target,o=t.datum[X],l=s.datum[X],h=n.get(a.get(o)),c=n.get(a.get(l));r._d=Ht(e({source:h,target:c}),i.left,i.top-i._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===Vt.Left2Right||i.direction===Vt.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===It?e.vertices=[[t,r],[(t+s)/2,r],[t,l],[s,l]]:e.orientation===Nt&&(e.vertices=[[t,r],[t,(r+l)/2],[s,r],[s,l]])}}_updateBundledLinks(e){let t=this._inputVars[0].element.parent.layout;if(t.type!==me.CLUSTER)throw"Bundled links must work on a cluster layout";let i=t._d3Root;if(!i)return void console.warn("cluster layout was not placed; skipping bundled link routing");let s=i.leaves();const n=new Map(s.map(e=>[Pr(e),e])),a=new Map(s.map(e=>[e.data[X],Pr(e)])),o=r.lineRadial().curve(r.curveBundle.beta(e[0]._strength)).radius(e=>e.y).angle(e=>e.x);for(let i of e){let e=i.source.datum[X],r=i.target.datum[X],s=n.get(a.get(e)),l=n.get(a.get(r)),h=s.path(l);i._d=Ht(o(h),t.x,t.y),i._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 Pr(e){return`${e.parent?Pr(e.parent)+".":""}${e.data[X]}`}var Vr="\0";function Br(e,t){e[t]?e[t]++:e[t]=1}function Mr(e,t){--e[t]||delete e[t]}function Dr(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 Gr(e,t){return Dr(e,t.v,t.w,t.name)}var zr=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[Vr]={})}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]=Vr,this._children[e]={},this._children[Vr][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=Vr;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!==Vr)return t}}children(e=Vr){if(this._isCompound){var t=this._children[e];if(t)return Object.keys(t)}else{if(e===Vr)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=Dr(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,Br(this._preds[t],e),Br(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?Gr(this._isDirected,arguments[0]):Dr(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?Gr(this._isDirected,arguments[0]):Dr(this._isDirected,e,t,i);return Object.hasOwn(this._edgeLabels,r)}removeEdge(e,t,i){var r=1===arguments.length?Gr(this._isDirected,arguments[0]):Dr(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],Mr(this._preds[t],e),Mr(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))}},jr={Graph:zr,version:"2.2.4"},Fr=zr,Wr={write:function(e){var t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:Ur(e),edges:Yr(e)};void 0!==e.graph()&&(t.value=structuredClone(e.graph()));return t},read:function(e){var t=new Fr(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 Ur(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 Yr(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 Hr=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 Xr=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}},qr=Xr,Kr=function(e,t,i,r){return function(e,t,i,r){var s,n,a={},o=new qr,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||Zr,r||function(t){return e.outEdges(t)})},Zr=()=>1;var $r=Kr,Jr=function(e,t,i){return e.nodes().reduce(function(r,s){return r[s]=$r(e,s,t,i),r},{})};var Qr=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 es=Qr,ts=function(e){return es(e).filter(function(t){return t.length>1||1===t.length&&e.hasEdge(t[0],t[0])})};var is=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||rs,i||function(t){return e.outEdges(t)})},rs=()=>1;function ss(e){var t={},i={},r=[];if(e.sinks().forEach(function s(n){if(Object.hasOwn(i,n))throw new ns;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 ns;return r}class ns extends Error{constructor(){super(...arguments)}}var as=ss;ss.CycleException=ns;var os=as;var ls=function(e,t,i){Array.isArray(t)||(t=[t]);var r=e.isDirected()?t=>e.successors(t):t=>e.neighbors(t),s="post"===i?hs:cs,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 hs(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]),ds(t(n[0]),e=>s.push([e,!1])))}}function cs(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),ds(t(n),e=>s.push(e)))}}function ds(e,t){for(var i=e.length;i--;)t(e[i],i,e);return e}var us=ls;var _s=ls;var ps=zr,fs=Xr;var gs={Graph:jr.Graph,json:Wr,alg:{components:Hr,dijkstra:Kr,dijkstraAll:Jr,findCycles:ts,floydWarshall:is,isAcyclic:function(e){try{os(e)}catch(e){if(e instanceof os.CycleException)return!1;throw e}return!0},postorder:function(e,t){return us(e,t,"post")},preorder:function(e,t){return _s(e,t,"pre")},prim:function(e,t){var i,r=new ps,s={},n=new fs;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:Qr,topsort:as},version:jr.version};function ys(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function ms(e,t){if("_next"!==e&&"_prev"!==e)return t}let bs=gs.Graph,xs=class{constructor(){let e={};e._next=e._prev=e,this._sentinel=e}dequeue(){let e=this._sentinel,t=e._prev;if(t!==e)return ys(t),t}enqueue(e){let t=this._sentinel;e._prev&&e._next&&ys(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,ms)),i=i._prev;return"["+e.join(", ")+"]"}};var vs=function(e,t){if(e.nodeCount()<=1)return[];let i=function(e,t){let i=new bs,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 xs),a=r+1;return i.nodes().forEach(e=>{As(n,a,i.node(e))}),{graph:i,buckets:n,zeroIdx:a}}(e,t||ws);return function(e,t,i){let r,s=[],n=t[t.length-1],a=t[0];for(;e.nodeCount();){for(;r=a.dequeue();)Es(e,t,i,r);for(;r=n.dequeue();)Es(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(Es(e,t,i,r,!0));break}}return s}(i.graph,i.buckets,i.zeroIdx).flatMap(t=>e.outEdges(t.v,t.w))};let ws=()=>1;function Es(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,As(t,i,o)}),e.outEdges(r.v).forEach(r=>{let s=e.edge(r),n=r.w,a=e.node(n);a.in-=s,As(t,i,a)}),e.removeNode(r.v),n}function As(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 Cs=gs.Graph;var Ss={addBorderNode:function(e,t,i,r){let s={width:0,height:0};arguments.length>=4&&(s.rank=i,s.order=r);return Rs(e,"border",s,t)},addDummyNode:Rs,applyWithChunking:Ts,asNonCompoundGraph:function(e){let t=new Cs({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=Ls(Os(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:Os,normalizeRanks:function(e){let t=e.nodes().map(t=>{let i=e.node(t).rank;return void 0===i?Number.MAX_VALUE:i}),i=Ts(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 Ps(e.nodes(),t)},range:Ls,removeEmptyRanks:function(e){let t=e.nodes().map(t=>e.node(t).rank),i=Ts(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 Cs).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 Ps(e.nodes(),t)},time:function(e,t){let i=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-i)+"ms")}},uniqueId:Ns,zipObject:Ps};function Rs(e,t,i,r){for(var s=r;e.hasNode(s);)s=Ns(r);return i.dummy=t,e.setNode(s,i),s}const ks=65535;function Ts(e,t){if(t.length>ks){const i=function(e,t=ks){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 Os(e){const t=e.nodes().map(t=>{let i=e.node(t).rank;return void 0===i?Number.MIN_VALUE:i});return Ts(Math.max,t)}let Is=0;function Ns(e){return e+""+ ++Is}function Ls(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 Ps(e,t){return e.reduce((e,i,r)=>(e[i]=t[r],e),{})}let Vs=vs,Bs=Ss.uniqueId;var Ms={run:function(e){("greedy"===e.graph().acyclicer?Vs(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,Bs("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 Ds=Ss;var Gs={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=Ds.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:zs}=Ss;var js={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=zs(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 Fs=gs.Graph,Ws=js.slack,Us=function(e){var t,i,r=new Fs({directed:!1}),s=e.nodes()[0],n=e.nodeCount();r.setNode(s,{});for(;Ys(r,e)<n;)t=Hs(r,e),i=r.hasNode(t.v)?Ws(e,t):-Ws(e,t),Xs(r,e,i);return r};function Ys(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)||Ws(t,s)||(e.setNode(a,{}),e.setEdge(r,a,{}),i(a))})}),e.nodeCount()}function Hs(e,t){return t.edges().reduce((i,r)=>{let s=Number.POSITIVE_INFINITY;return e.hasNode(r.v)!==e.hasNode(r.w)&&(s=Ws(t,r)),s<i[0]?[s,r]:i},[Number.POSITIVE_INFINITY,null])[1]}function Xs(e,t,i){e.nodes().forEach(e=>t.node(e).rank+=i)}var qs=Us,Ks=js.slack,Zs=js.longestPath,$s=gs.alg.preorder,Js=gs.alg.postorder,Qs=Ss.simplify,en=tn;function tn(e){e=Qs(e),Zs(e);var t,i=qs(e);for(nn(i),rn(i,e);t=on(i);)hn(i,e,t,ln(i,e,t))}function rn(e,t){var i=Js(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=sn(e,t,i)}(e,t,i))}function sn(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 nn(e,t){arguments.length<2&&(t=e.nodes()[0]),an(e,{},1,t)}function an(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=an(e,t,i,s,r))}),a.low=n,a.lim=i++,s?a.parent=s:delete a.parent,i}function on(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function ln(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===cn(e,e.node(t.v),o)&&l!==cn(e,e.node(t.w),o));return h.reduce((e,i)=>Ks(t,i)<Ks(t,e)?i:e)}function hn(e,t,i,r){var s=i.v,n=i.w;e.removeEdge(s,n),e.setEdge(r.v,r.w,{}),nn(e),rn(e,t),function(e,t){var i=e.nodes().find(e=>!t.node(e).parent),r=$s(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 cn(e,t,i){return i.low<=t.lim&&t.lim<=i.lim}tn.initLowLimValues=nn,tn.initCutValues=rn,tn.calcCutValue=sn,tn.leaveEdge=on,tn.enterEdge=ln,tn.exchangeEdges=hn;var dn=js.longestPath,un=Us,_n=en,pn=function(e){var t=e.graph().ranker;if(t instanceof Function)return t(e);switch(e.graph().ranker){case"network-simplex":default:gn(e);break;case"tight-tree":!function(e){dn(e),un(e)}(e);break;case"longest-path":fn(e);case"none":}};var fn=dn;function gn(e){_n(e)}var yn=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 mn=Ss;var bn={run:function(e){let t=mn.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=mn.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=>xn(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 xn(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=mn.addBorderNode(e,"_bt"),h=mn.addBorderNode(e,"_bb"),c=e.node(a);e.setParent(l,a),c.borderTop=l,e.setParent(h,a),c.borderBottom=h,o.forEach(o=>{xn(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 vn=Ss;var wn=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)En(e,"borderLeft","_bl",i,s,t),En(e,"borderRight","_br",i,s,t)}})};function En(e,t,i,r,s,n){let a={width:0,height:0,rank:n,borderType:t},o=s[t][n-1],l=vn.addDummyNode(e,"border",a,i);s[t][n]=l,e.setParent(l,r),o&&e.setEdge(o,l,{weight:1})}function An(e){e.nodes().forEach(t=>Cn(e.node(t))),e.edges().forEach(t=>Cn(e.edge(t)))}function Cn(e){let t=e.width;e.width=e.height,e.height=t}function Sn(e){e.y=-e.y}function Rn(e){let t=e.x;e.x=e.y,e.y=t}let kn=Ss;var Tn=function(e){let t={},i=e.nodes().filter(t=>!e.children(t).length),r=i.map(t=>e.node(t).rank),s=kn.applyWithChunking(Math.max,r),n=kn.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 On=Ss.zipObject;function In(e,t,i){let r=On(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 Nn=Ss;let Ln=Ss;function Pn(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 Vn=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}})},Bn=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=>Nn.pick(e,["vs","i","barycenter","weight"]))}(Object.values(i).filter(e=>!e.indegree))},Mn=function(e,t){let i=Ln.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=Pn(n,s,l),r.forEach(e=>{l+=e.vs.length,n.push(e.vs),a+=e.barycenter*e.weight,o+=e.weight,l=Pn(n,s,l)});var h;let c={vs:n.flat(!0)};o&&(c.barycenter=a/o,c.weight=o);return c};var Dn=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=Vn(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=Bn(c,r);!function(e,t){e.forEach(e=>{e.vs=e.vs.flatMap(e=>t[e]?t[e].vs:e)})}(d,h);let u=Mn(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 Gn=gs.Graph,zn=Ss;var jn=function(e,t,i,r){r||(r=e.nodes());let s=function(e){var t;for(;e.hasNode(t=zn.uniqueId("_root")););return t}(e),n=new Gn({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 Fn=Tn,Wn=function(e,t){let i=0;for(let r=1;r<t.length;++r)i+=In(e,t[r-1],t[r]);return i},Un=Dn,Yn=jn,Hn=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}})},Xn=gs.Graph,qn=Ss;var Kn=function e(t,i){if(i&&"function"==typeof i.customOrder)return void i.customOrder(t,e);let r=qn.maxRank(t),s=Zn(t,qn.range(1,r+1),"inEdges"),n=Zn(t,qn.range(r-1,-1,-1),"outEdges"),a=Fn(t);if(Jn(t,a),i&&i.disableOptimalOrderHeuristic)return;let o,l=Number.POSITIVE_INFINITY;for(let e=0,i=0;i<4;++e,++i){$n(e%2?s:n,e%4>=2),a=qn.buildLayerMatrix(t);let r=Wn(t,a);r<l&&(i=0,o=Object.assign({},a),l=r)}Jn(t,o)};function Zn(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 Yn(e,t,i,r.get(t)||[])})}function $n(e,t){let i=new Xn;e.forEach(function(e){let r=e.graph().root,s=Un(e,r,i,t);s.vs.forEach((t,i)=>e.node(t).order=i),Hn(e,i,s.vs)})}function Jn(e,t){Object.values(t).forEach(t=>t.forEach((t,i)=>e.node(t).order=i))}let Qn=gs.Graph,ea=Ss;var ta=function(e){let t,i=ea.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||ia(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;ea.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)&&ia(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]&&!ra(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 Qn,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=ea.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=ea.applyWithChunking(Math.min,i),s=ea.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-ea.applyWithChunking(Math.min,l);"l"!==n&&(h=s-ea.applyWithChunking(Math.max,l)),h&&(e[a]=ea.mapValues(o,e=>e+h))})})}(s,n),function(e,t){return ea.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 ia(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 ra(e,t,i){if(t>i){let e=t;t=i,i=e}return!!e[t]&&Object.hasOwn(e[t],i)}let sa=Ss,na=ta;let aa=Ms,oa=Gs,la=pn,ha=Ss.normalizeRanks,ca=yn,da=Ss.removeEmptyRanks,ua=bn,_a=wn,pa={adjust:function(e){let t=e.graph().rankdir.toLowerCase();"lr"!==t&&"rl"!==t||An(e)},undo:function(e){let t=e.graph().rankdir.toLowerCase();"bt"!==t&&"rl"!==t||function(e){e.nodes().forEach(t=>Sn(e.node(t))),e.edges().forEach(t=>{let i=e.edge(t);i.points.forEach(Sn),Object.hasOwn(i,"y")&&Sn(i)})}(e);"lr"!==t&&"rl"!==t||(!function(e){e.nodes().forEach(t=>Rn(e.node(t))),e.edges().forEach(t=>{let i=e.edge(t);i.points.forEach(Rn),Object.hasOwn(i,"x")&&Rn(i)})}(e),An(e))}},fa=Kn,ga=function(e){(function(e){let t=sa.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=sa.asNonCompoundGraph(e)),Object.entries(na(e)).forEach(([t,i])=>e.node(t).x=i)},ya=Ss,ma=gs.Graph;var ba=function(e,t){let i=t&&t.debugTiming?ya.time:ya.notime;i("layout",()=>{let r=i(" buildLayoutGraph",()=>function(e){let t=new ma({multigraph:!0,compound:!0}),i=Ta(e.graph());return t.setGraph(Object.assign({},va,ka(i,xa),ya.pick(i,wa))),e.nodes().forEach(i=>{const r=ka(Ta(e.node(i)),Ea);Object.keys(Aa).forEach(e=>{void 0===r[e]&&(r[e]=Aa[e])}),t.setNode(i,r),t.setParent(i,e.parent(i))}),e.edges().forEach(i=>{let r=Ta(e.edge(i));t.setEdge(i,Object.assign({},Sa,ka(r,Ca),ya.pick(r,Ra)))}),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",()=>aa.run(e)),t(" nestingGraph.run",()=>ua.run(e)),t(" rank",()=>la(ya.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};ya.addDummyNode(e,"edge-proxy",r,"_ep")}})}(e)),t(" removeEmptyRanks",()=>da(e)),t(" nestingGraph.cleanup",()=>ua.cleanup(e)),t(" normalizeRanks",()=>ha(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",()=>oa.run(e)),t(" parentDummyChains",()=>ca(e)),t(" addBorderSegments",()=>_a(e)),t(" order",()=>fa(e,i)),t(" insertSelfEdges",()=>function(e){var t=ya.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=>{ya.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",()=>pa.adjust(e)),t(" position",()=>ga(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",()=>oa.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",()=>pa.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(ya.intersectRect(n,i)),s.points.push(ya.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",()=>aa.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 xa=["nodesep","edgesep","ranksep","marginx","marginy"],va={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},wa=["acyclicer","ranker","rankdir","align"],Ea=["width","height","rank"],Aa={width:0,height:0},Ca=["minlen","weight","width","height","labeloffset"],Sa={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},Ra=["labelpos"];function ka(e,t){return ya.mapValues(ya.pick(e,t),Number)}function Ta(e){var t={};return e&&Object.entries(e).forEach(([e,i])=>{"string"==typeof e&&(e=e.toLowerCase()),t[e]=i}),t}let Oa=Ss,Ia=gs.Graph;var Na={graphlib:gs,layout:ba,debug:{debugOrdering:function(e){let t=Oa.buildLayerMatrix(e),i=new Ia({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:Ss.time,notime:Ss.notime},version:"1.1.8"};class La extends xe{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=Ce(e.parent);for(let e of t){let t=e.layout;if(!t)continue;let r=Y(e.children[0]);if(!r)continue;var i=new Na.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[X];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);Na.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[X];Et(t,n[s.get(e)].x-t.x,n[s.get(e)].y-t.y)}}let r=Be(e,!0);for(let e of r)de(e)}_getDagreDirection(e){switch(e){case Vt.Left2Right:return"LR";case Vt.Right2Left:return"RL";case Vt.Top2Bottom:return"TB";case Vt.Bottom2Top:return"BT"}}}class Pa extends xe{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=Ce(e.parent);for(let e of t){let t=e.layout;if(!t)continue;let i=W(e.children[0]);if(!i)continue;let s=r.hierarchy(i._data),n=Math.max(...e.children.map(e=>e.bounds.width)),a=Math.max(...e.children.map(e=>e.bounds.height)),o=t.orientation==It?[t.height,t.width]:[t.width,t.height],l=r.tree().nodeSize([n,a]).size(o)(s);this._apply(l,t,e)}de(e)}_apply(e,t,i){let r,s,n=i.children.filter(t=>t.datum[X]==e.data[X])[0];switch(t.orientation){case It:r=e.y+t.left,s=e.x+t.top;break;case Nt:r=e.x+t.left,s=t.top+e.y}if(Et(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 Va extends xe{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=this._inputVars.filter(e=>e.type===Ee.PROPERTY&&e.property===We.CHILDREN_ORDER)[0].element,i=t.layout,s=i.width?i.width:t.bounds.width,a=i.height?i.height:t.bounds.height,o=void 0===i.top?t.bounds.top:i.top,l=void 0===i.left?t.bounds.left:i.left,h=r.hierarchy(t).sum(e=>e.type===n.Rect?e.width*e.height:0);r.treemap().size([s,a])(h),this._apply(h,l,o);let c=Be(e,!0);for(let e of c)de(e)}_apply(e,t,i){if(e.data.type==n.Collection&&e.children)for(let r of e.children)this._apply(r,t,i);else e.data.type==n.Rect&&(e.data.resize(e.x1-e.x0,e.y1-e.y0),Et(e.data,e.x0+t-e.data.left,e.y0+i-e.data.top))}}class Ba extends xe{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=Ce(e.parent);for(let e of t){if(!e.layout)continue;if(0===e.children.length)continue;let t=W(e.children[0]);if(!t)continue;let i={};for(let t of e.children)i[t.datum[X]]=t;e.children[0].type===n.Rect?this._layoutRects(t.getRoot(),t,i):this._layoutArcs(t.getRoot(),t,i)}de(e)}_layoutArcs(e,t,i){let r=t.getChildren(e);if(0===r.length)return;let s=i[e[X]],a=!s||s.type!=n.Arc&&s.type!=n.Pie?60:s.startAngle;for(let e=0;e<r.length;e++){let s=r[e],o=i[s[X]];if(o.type===n.Arc){let e=Zt(a+o.angle);o.setAngles(a,e),a=e}this._layoutArcs(s,t,i)}}_layoutRects(e,t,i){let r=t.getChildren(e);if(0===r.length)return;let s,n,a=i[e[X]];this._direction,s=a.left,n=a.bottom;for(let e=0;e<r.length;e++){let a=r[e],o=i[a[X]];Et(o,s-o.left,n-o.top),s+=o.width,this._layoutRects(a,t,i)}}}class Ma extends xe{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=Pe(i.responderComponent).state,n=e.result;if(i.evalFunction){i.getResponderPeers().forEach(e=>n[e.id]=!!i.evalFunction(r,s,e))}}}class Da extends xe{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=Ce(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=re(t.x+t.radius,t.y,t.x,t.y,e);switch(Et(s,n.x-s.bounds.x,n.y-s.bounds.y),t.markRotation){case Dt.INWARD:s._markRotationOffset=e+90;break;case Dt.TANGENTIAL_CLOCKWISE:s._markRotationOffset=e;break;case Dt.TANGENTIAL_COUNTERCLOCKWISE:s._markRotationOffset=e-180;break;case Dt.UPRIGHT:break;case Dt.OUTWARD:default:s._markRotationOffset=e-90}}}let i=Be(e,!0);for(let e of i)de(e)}}class Ga extends xe{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=Ce(e.parent);for(let i of t){let t=i.layout;if(!t)continue;let s=t._tree??W(i.children[0]);if(!s){console.warn("cluster layout has no tree; skipping placement for",i.id);continue}let n=r.hierarchy(s._data);if(t.isRadial()){n=r.cluster().size([qt(t.angleExtent),t.radius])(n),t._d3Root=n;const e=new Map(n.descendants().map(e=>[e.data[X],[e.x,e.y]]));for(let r of i.children){let i=r.datum[X];r._rotate=void 0,r._bounds=void 0,Et(r,t.x-r.bounds.x,t.y-e.get(i)[1]-r.bounds.y),r._rotate=[Kt(e.get(i)[0]),t.x,t.y]}}else if(t.orientation===Nt){!t.width||t.width;let s=t.height?t.height:600;n=r.cluster().nodeSize([e.bounds.width+1,s/(n.height+1)])(n),t._d3Root=n;const a=new Map(n.descendants().map(e=>[e.data[X],[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)}),t._x0=o;for(let e of i.children){let i=e.datum[X];Et(e,a.get(i)[0]-o+t.left-e.bounds.x,a.get(i)[1]+t.top-e.bounds.y)}}else if(t.orientation===It){!t.width||t.width;let s=t.height?t.height:600;n=r.cluster().nodeSize([e.bounds.height,s/(n.height+1)])(n),t._d3Root=n;const a=new Map(n.descendants().map(e=>[e.data[X],[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)}),t._x0=o;for(let e of i.children){let i=e.datum[X];Et(e,a.get(i)[1]+t.left-e.bounds.x,a.get(i)[0]-o+t.top-e.bounds.y)}}}let i=Be(e,!0);for(let e of i)de(e)}}class za extends xe{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=Ce(e.parent);for(let e of t){let t=e.layout;if(!t)continue;let i=t.direction===Bt.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=re(t.x+e,t.y,t.x,t.y,n);switch(Et(s,a.x-s.bounds.x,a.y-s.bounds.y),t.markRotation){case Dt.INWARD:s._markRotationOffset=n+90;break;case Dt.TANGENTIAL_CLOCKWISE:s._markRotationOffset=n;break;case Dt.TANGENTIAL_COUNTERCLOCKWISE:s._markRotationOffset=n-180;break;case Dt.UPRIGHT:break;case Dt.OUTWARD:default:s._markRotationOffset=n-90}}}let i=Be(e,!0);for(let e of i)de(e)}}class ja extends xe{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=Ce(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)&&Et(e,s,n)}}let i=Be(e,!0);for(let e of i)de(e)}}class Fa extends we{constructor(e,t){super(e),this._cond=t}get context(){return this._cond}}class Wa extends xe{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 Fa),t=e?e.context:void 0,i=this._resolveDynamically?function(e){let t=e?e.get("element"):void 0;for(;t&&t.parent&&t.parent.type!==n.Collection;)t=t.parent;return t}(t):this._compnt;if(!i)return;let r=Pe(this._compnt);if(this._fn(void 0,t,r?r.state:void 0,i),r)for(let e of this._outputVars){let t=e.element||e.stateContext;t&&t._scene&&(e.type===Ee.CHANNEL?r.onChange(Ee.CHANNEL,e.channel,t):e.type===Ee.PROPERTY?r.onChange(Ee.PROPERTY,e.property,t):e.type===Ee.STATE&&r.onChange(Ee.STATE,e.key,e.stateContext))}}}class Ua extends we{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 Ya extends xe{constructor(e){super(e)}run(){super.run();let e=this.outputVar,t=this.inputVars.find(e=>e instanceof Ua),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 i=Ce(e.element),r={};if(e.element.type===n.Area&&["width","height"].indexOf(e.channel)>=0||["fillGradient","strokeGradient"].indexOf(e.channel)>=0)for(let t of i)for(let i=0;i<t._vertices.length;i++)r[Re(t,i)]=t._vertices.hasDataScope(i)?t._vertices.aggregateDataScopeAttribute(i,e.attribute,e.aggregator):N(t.dataScope,e.attribute,e.aggregator);else switch(t){case h.Boolean:break;case h.Date:for(let t of i)r[t.id]=O(t.dataScope,e.attribute);break;case h.String:try{if("count"==e.aggregator)for(let t of i)r[t.id]=I(t.dataScope,e.attribute).length;else for(let t of i)r[t.id]=O(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,s=e.attribute.split(".")[0],n=e.attribute.split(".")[1];for(let e of i){let i=O(e.dataScope,s);r[e.id]=O(L(V(t),X,i),n)}}else for(let t of i)r[t.id]=N(t.dataScope,e.attribute,e.aggregator)}return e.attrValues=r,r}_computeVertexIndexAttrValues(e,t){let i={};for(let r of e.elementGroups)for(let s of r.groups)for(let r of s.indices){i[Re(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:()=>R(r.dataScope)}),Object.defineProperty(r,"data",{get:()=>S(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 h.Boolean:return;case h.Date:return e._vertices.getDataScopeAttrVal(t,i.attribute);case h.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 h.Boolean:return;case h.Date:return O(e,t.attribute);case h.String:return"count"==t.aggregator?I(e,t.attribute).length:O(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=O(e,r);return O(L(V(i),X,n),s)}return N(e,t.attribute,t.aggregator)}}}class Ha extends we{constructor(e,t,i){super(e),this._key=t,this._stateContext=i}get key(){return this._key}get stateContext(){return this._stateContext}}class Xa{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===Ee.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===ve.DOMAIN_BUILDER?t.aggregator=e.aggregator:e.type===ve.SCALE_BUILDER&&(t.channel=e.channel),t});return{edges:e,variables:t,operators:i}}getVariable(e,...t){if(Object.values(Ee).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 Ee.CHANNEL:i=new De(e,t[0],t[1]),"vertex"!=t[1].type&&"segment"!=t[1].type||this._connectPathElement2Size(t[1],i);break;case Ee.PROPERTY:i=new ze(e,t[0],t[1]);break;case Ee.STATE:i=new Ha(e,t[0],t[1]);break;case Ee.ATTRIBUTE:i=new Ua(e,t[0],t[1],t[2]||null);break;case Ee.ITEMS:i=new yr(e,t[0]);break;case Ee.ATTR_VALUE:i=new Ki(e,t[0]);break;case Ee.DATASCOPE:i=new Yi(e,t[0]);break;case Ee.BOUNDS:i=new Ui(e,t[0]);break;case Ee.SCALE:i=new qi(e,t[0]);break;case Ee.AFFIXATION:i=new wr(e,t[0]);break;case Ee.ALIGNMENT:i=new Ir(e,t[0]);break;case Ee.EVT_CTX:i=new Fa(e,t[0],t[1]);break;case Ee.CONDITION_RESULT:i=new cr(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(Ee.CHANNEL,["x"===r?"width":"height",i]);if(s){let e=s.incomingDataflow;e||(e=this.createOneWayDependency(ve.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 xe&&i.toNode.type===e)return i.toNode;return this.createOneWayDependency(e)}createOneWayDependency(e,...t){if(Object.values(ve).indexOf(e)<0)throw new Error("Dependency Type Not Known");let i;switch(e){case ve.EVAL_BBOX:i=new Ji(e);break;case ve.AFFIXER:i=new vr(e);break;case ve.DATA_EXTRACTOR:i=new Ya(e,t[0]);break;case ve.SCALE_BUILDER:i=new $i(e,t[0]);break;case ve.ENCODER:i=new dr(e,t[0]);break;case ve.AXIS_PATH_PLACER:i=new Qi(e);break;case ve.AXIS_TICKS_PLACER:i=new er(e);break;case ve.AXIS_LABELS_PLACER:i=new tr(e);break;case ve.AXIS_TITLE_PLACER:i=new Tr(e);break;case ve.LINK_PLACER:i=new Lr(e);break;case ve.GRID_LAYOUT:i=new rr(e);break;case ve.STACK_LAYOUT:i=new pr(e);break;case ve.PACK_LAYOUT:i=new kr(e);break;case ve.FORCE_LAYOUT:i=new Nr(e);break;case ve.DIRECTED_LAYOUT:i=new La(e);break;case ve.TIDY_TREE_LAYOUT:i=new Pa(e);break;case ve.TREEMAP_LAYOUT:i=new Va(e);break;case ve.STRATA_LAYOUT:i=new Ba(e);break;case ve.CIRCULAR_LAYOUT:i=new Da(e);break;case ve.CLUSTER_LAYOUT:i=new Ga(e);break;case ve.SPIRAL_LAYOUT:i=new za(e);break;case ve.CUSTOM_LAYOUT:i=new ja(e);break;case ve.GRIDLINES_PLACER:i=new ur(e);break;case ve.SPIRAL_TRAJECTORY_PLACER:i=new _r(e);break;case ve.BIN_TRANSFORMER:i=new gr(e);break;case ve.FILTER_TRANSFORMER:i=new mr(e);break;case ve.KDE_TRANSFORMER:i=new Er(e);break;case ve.CUSTOM_TRANSFORMER:i=new Sr(e);break;case ve.UNPIVOT_TRANSFORMER:i=new Rr(e);break;case ve.REPOPULATE:i=new xr(e);break;case ve.TARGET_EVALUATOR:i=new Ma(e);break;case ve.TARGET_UPDATER:i=new Wa(e,t[0],t[1],t[2]);break;case ve.CONDUIT:default:i=new fr(e)}return e in this._operators||(this._operators[e]={}),this._operators[e][i.id]=i,i}createMultiWayDependency(e){if(Object.values(ve).indexOf(e)<0)throw new Error("Dependency Type Not Known");let t;return ve.ALIGNER,t=new Or(e),e in this._operators||(this._operators[e]={}),this._operators[e][t.id]=t,t}connect(e,t,i=!0){if(e instanceof we&&t instanceof xe){if(!t.inputVars.includes(e)){const r=new Xi(e,t,i);return this._edges.push(r),e.outgoingEdges.push(r),t.inputVars.push(e),r}}else if(e instanceof xe&&t instanceof we){if(!e.outputVars.includes(t)){const r=new Xi(e,t,i);return this._edges.push(r),e.outputVars.push(t),t.incomingEdges.push(r),r}}else if(e instanceof we&&t instanceof Hi){if(!t.vars.includes(e)){const i=new Xi(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 Hi&&t instanceof we))throw new Error("An edge must connect a variable and an operator.");if(!e.vars.includes(t)){const i=new Xi(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(ve.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 we&&t instanceof xe){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 xe&&t instanceof we){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 Ee.ITEMS:this.getOperatorsOnPath(e.type,t,i,e.dataset);break;case Ee.ATTRIBUTE:this.getOperatorsOnPath(e.type,t,i,e.attribute,e.dataset);break;case Ee.DATASCOPE:case Ee.BOUNDS:this.getOperatorsOnPath(e.type,t,i,e.element);break;case Ee.CHANNEL:this.getOperatorsOnPath(e.type,t,i,e.channel,e.element);break;case Ee.PROPERTY:this.getOperatorsOnPath(e.type,t,i,e.property,e.element);break;case Ee.STATE:this.getOperatorsOnPath(e.type,t,i,e.key,e.stateContext);break;case Ee.SCALE:case Ee.ATTR_VALUE:this.getOperatorsOnPath(e.type,t,i,e.encodings[0]);break;case Ee.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 Ee.CHANNEL:return i.find(e=>e.channel==t[0]&&yt(e.element)==yt(t[1]));case Ee.PROPERTY:return i.find(e=>e.property==t[0]&&e.element==t[1]);case Ee.STATE:return i.find(e=>e.key==t[0]&&e.stateContext==t[1]);case Ee.AFFIXATION:return i.find(e=>e.affixation==t[0]);case Ee.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 Ee.ITEMS:return i.find(e=>e.dataset==t[0]);case Ee.ATTR_VALUE:case Ee.SCALE:return i.find(e=>e.encodings.includes(t[0]));case Ee.EVT_CTX:return i.find(e=>e.context===t[0]);case Ee.CONDITION_RESULT:return i.find(e=>e.conditionalEncoding==t[0]);case Ee.DATASCOPE:default:return t[0].classId?i.find(e=>yt(e.element)==yt(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&&yt(t.element)==yt(e));r.length>0&&(t[i]=r)}return t}}class qa{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 Ka{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 $a{constructor(e,t){this._fn=e,t&&Object.assign(this,t)}get fn(){return this._fn}}class Ja{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 Qa extends Ft{constructor(e,t){super(t||{}),this._type=n.Trajectory,this._id=this._type+o(),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===Bt.ANTI_CLOCKWISE?-1:1,r=t-1+this._extendPastLast;if(r<=0){let t=re(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(re(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 oe(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 oe(i,s,r-i,n-s)}}class eo extends Ct{constructor(e){super(),this._itemMap={},this._type=n.Scene,this._id=e&&e.id?e.id:this._type+o(),e&&e.fillColor&&(this.fillColor=e.fillColor),this._encodings={},this._relations=[],this._triggers={},this._condEncodings={},this._stateContext=new Ae(this),this._stateContext.__scene__=this,this._depGraph=new Xa,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,t){if(Object.values(s).indexOf(e)<0)throw new Error("Mascot does not allow directly creating a "+e);let i=void 0===t?{}:t;i.type=e;let r=zi(this,i);return null!==r&&(r._classId=r.id,this.addChild(r),this._itemMap[r.id]=r,qe(r,this._depGraph),et(this,r,this._depGraph)),r}glyph(...e){let t=[];for(let i of e)t.push([i.parent,i]);let i=zi(this,{type:n.Glyph,children:e});if(null!==i){i._classId=i.id;for(let e of t)Qe(e[0],e[1],this._depGraph);tt(i,this._depGraph),et(this,i,this._depGraph)}return i}composite(){let e=zi(this,{type:n.Composite});return null!==e&&(e._classId=e.id,this.addChild(e),this._itemMap[e.id]=e,Je(e,this._depGraph),et(this,e,this._depGraph)),e}_addAttributeEncoding(e){let t=yt(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===n.Collection);for(let i of t){let t=i.dataScope?A(i.dataScope):null;t&&!(t.id in e)&&(e[t.id]=t)}return e}onChange(e,...t){if(Object.values(Ee).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===Ee.CHANNEL||e.type===Ee.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?j:t,n=r.element?gt(r.element,e):ft(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=Ve(n.element),t=n.scales[0];if(e.layout&&e.layout.type==me.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=Ve(n.element);if(e.layout&&e.layout.type==me.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=Ve(n.element),t=n.scales[0];if(e.layout&&e.layout.type==me.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:Ce(e,e.parent)})}for(let e of i){let t=new Ai(n.channel,n.attribute,e.scale,e.elems,r);this.addChild(t),this._itemMap[t.id]=t,n.addRefElement(t),ct(t,this._depGraph),et(this,t,this._depGraph)}}else{let i=r.element?r.element:Ie(this,t);if(!i)return void console.warn("Cannot create "+e+" gridlines for "+t);let s=Ne(i.parent);if(!s.layout)return void console.warn("Cannot create "+e+" gridlines for "+t);let n=Ce(s);for(let i of n){let s=[];i.layout.type==me.GRID&&i.layout.numRows>1&&"x"==e?s=i.layout.getElementsByRow():i.layout.type==me.GRID&&i.layout.numCols>1&&"y"==e?s=i.layout.getElementsByCol():s.push(i.children);for(let n of s){let s=new Ai(e,t,null,n,r);this.addChild(s),this._itemMap[s.id]=s,i.layout.addRefElement(s),ct(s,this._depGraph),et(this,s,this._depGraph)}}}}trajectory(e,t){let i=t||{},r=Ne(e);if(!r||!r.layout||r.layout.type!==me.SPIRAL)return void console.warn("Cannot create a trajectory: element is not inside a collection with a spiral layout");let s=new Qa(r,i);return this.addChild(s),this._itemMap[s.id]=s,r.layout.addRefElement(s),function(e,t){let i=t.getVariable(Ee.BOUNDS,Ve(e.collection)),r=t.getVariable(Ee.PROPERTY,We.TRAJECTORY_POSITION,e),s=t.createOneWayDependency(ve.SPIRAL_TRAJECTORY_PLACER);t.connect(i,s),t.connect(s,r),s.run();let n=t.getVariable(Ee.BOUNDS,e),a=t.getIncomingDataflowOperator(ve.EVAL_BBOX,n);t.connect(r,a),t.connect(a,n)}(s,this._depGraph),et(this,s,this._depGraph),de(s),this.onChange(Ee.PROPERTY,We.TRAJECTORY_POSITION,s),s}axis(e,t,i){let r=i||{},s="rowId"==t?j:t,n=[],a=r.element?gt(r.element,e):ft(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=Ve(r.element?r.element:a.element);if(e.layout&&e.layout.type==me.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=Ve(r.element?r.element:a.element);if(e.layout&&e.layout.type==me.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:Ce(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=zi(this,t);n.push(i),a.addRefElement(i),ht(i,this._depGraph),et(this,i,this._depGraph),this.onChange(Ee.PROPERTY,We.AXIS_PATH_POSITION,i)}}else{let t=r.element?r.element:Ie(this,s);if(!t)return void console.warn("Cannot create a "+e+" axis for "+s);let i=Ne(t.parent);if(!i.layout)return void console.warn("Cannot create a "+e+" axis for "+s);let a=Ce(i);for(let t of a){let i=[];t.layout.type==me.GRID&&t.layout.numRows>1&&"x"==e?i=t.layout.getElementsByRow():t.layout.type==me.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=zi(this,i);n.push(o),t.layout.addRefElement(o),lt(o,this._depGraph),et(this,o,this._depGraph),this.onChange(Ee.PROPERTY,We.AXIS_PATH_POSITION,o)}}}return n.length>1?n:n[0]}legend(e,t,i){let r=i||{},s="rowId"==t?j:t,n=r.element?gt(r.element,e):ft(s,e,this);if(n){n.attribute!==t&&console.warn("Cannot create a "+e+" legend for "+t);let i=z(n.element).type(t);r.type="legend",r.enc=n,r.attrType=i;let s=zi(this,r);!function(e,t){let i=t.getVariable(Ee.BOUNDS,e),r=t.getVariable(Ee.PROPERTY,We.LEGEND_POSITION,e),s=t.getIncomingDataflowOperator(ve.EVAL_BBOX,i);t.connect(r,s),t.connect(s,i)}(s,this._depGraph),et(this,s,this._depGraph),de(s),this.onChange(Ee.PROPERTY,We.LEGEND_POSITION,s)}else console.warn("Cannot create a "+e+" legend for "+s)}mask(e){let t=Ve(e),i=t||e;i.clipMask||i.createClipMask()}setLayout(e,t){if(e.layout&&(rt(e,e.layout,this._depGraph),t.type===me.TREEMAP)){let t=e.firstChild;for(;t&&t.type===n.Collection&&t.layout;)rt(t,t.layout,this._depGraph),t=t.firstChild}if(Ce(e).forEach(e=>{let i=t?t.clone():t;e._layout=i,i&&(i.group=e)}),st(e,t,this._depGraph),e.children&&e.children.length>0){let t=Be(e,!0);for(let e of t)this.onChange(Ee.CHANNEL,"x",e)}}derive(e,t){let i=e.clone();return t._scene=this,t instanceof qa?(!function(e,t,i,r){let s=r.getVariable(Ee.ITEMS,t),n=r.getVariable(Ee.ITEMS,i),a=r.createOneWayDependency(ve.BIN_TRANSFORMER);r.connect(s,a),r.connect(a,n);let o=r.getVariable(Ee.PROPERTY,We.NUM_BINS,e);r.connect(o,a),a._binConfig=e,a.run()}(t,e,i,this._depGraph),i._binTransform=t):t instanceof Ka?function(e,t,i,r){let s=r.getVariable(Ee.ATTRIBUTE,e.attribute,t),n=r.getVariable(Ee.ATTRIBUTE,e.newAttribute,i),a=r.getVariable(Ee.ITEMS,i),o=r.createOneWayDependency(ve.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(Ee.ITEMS,t),n=r.getVariable(Ee.ITEMS,i),a=r.createOneWayDependency(ve.FILTER_TRANSFORMER);a._spec=e,r.connect(s,a),r.connect(a,n);let o=r.getVariable(Ee.PROPERTY,"value",e);r.connect(o,a),a.run()}(t,e,i,this._depGraph):t instanceof $a?function(e,t,i,r){let s=r.getVariable(Ee.ITEMS,t),n=r.getVariable(Ee.ITEMS,i),a=r.createOneWayDependency(ve.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(Ee.PROPERTY,t,e);r.connect(i,a)}a.run()}(t,e,i,this._depGraph):t instanceof Ja&&function(e,t,i,r){let s=r.getVariable(Ee.ITEMS,t),n=r.getVariable(Ee.ITEMS,i),a=r.createOneWayDependency(ve.UNPIVOT_TRANSFORMER);a._spec=e,r.connect(s,a),r.connect(a,n);let o=r.getVariable(Ee.PROPERTY,"valueVars",e);r.connect(o,a);let l=r.getVariable(Ee.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 ft(e,t,this).refElements[0]}}function to(e,t){return v(t[e.dt],e.attr2value||e.filters||{},e.rowIds)}class io extends ge{constructor(e){super(),this.type=me.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:It,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 io({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 ro extends ge{constructor(e){super(),this.type=me.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:Vt.Top2Bottom}clone(){return new ro({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 so extends ge{constructor(e){super(),this.type=me.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 so({x:this._x,y:this._y,iterations:this._iterations,repulsion:this._repulsion,attraction:this._attraction,linkDistance:this._linkDistance})}}class no extends ge{constructor(e){super(),this.type=me.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 no({x:this._x,y:this._y,width:this._width,height:this._height})}}class ao extends ge{constructor(e){super(),this.type=me.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:ue.LEFT,this._vertCellAlignment="vertCellAlignment"in e&&e.vertCellAlignment?e.vertCellAlignment:ue.BOTTOM,this._gap="gap"in e?e.gap:0}clone(){let e=new ao({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 oo extends ge{constructor(e){super(),this.type=me.STRATA,this._direction=e.direction,this._gap="gap"in e?e.gap:0}clone(){return new oo({direction:this._direction,gap:this._gap})}}class lo extends ge{constructor(e){super(),this.type=me.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:It}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 lo({width:this._width,height:this._height,top:this._top,left:this._left,orientation:this._orientation})}}class ho extends ge{constructor(e){super(),this.type=me.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 ho({width:this._width,height:this._height,top:this._top,left:this._left})}}class co extends ge{constructor(e){super(),e=e||{},this.type=me.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:Bt.CLOCKWISE,this._markRotation="markRotation"in e?e.markRotation:this._direction===Bt.CLOCKWISE?Dt.TANGENTIAL_CLOCKWISE:Dt.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 co({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 uo extends ge{constructor(e){super(),this.type=me.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:Dt.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 uo({x:this._x,y:this._y,radius:this._radius,markRotation:this._markRotation})}}class _o extends ge{constructor(e={}){if(super(),this.type=me.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 _o({compute:this._compute,params:this._params})}}function po(e){switch(e.type){case me.GRID:return function(e){let t=new Pi(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=>fo(e)));"grid"in e&&(t._grid=e.grid);return t}(e);case me.STACK:return function(e){let t=new ao(e.args);return t}(e);case me.PACKING:return function(e){let t=new no(e.args);return t}(e);case me.FORCE:return function(e){return new so(e.args)}(e);case me.DIRECTED:return function(e){return new ro(e.args)}(e);case me.TIDYTREE:return function(e){return new lo(e.args)}(e);case me.TREEMAP:return function(e){return new ho(e.args)}(e);case me.STRATA:return function(e){return new oo(e.args)}(e);case me.SPIRAL:return function(e){return new co(e.args)}(e);case me.CIRCULAR:return function(e){return new uo(e.args)}(e);case me.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 F(t.tree.data,t.tree.url));return new io(t)}(e);case me.CUSTOM:return function(e){return console.warn("CustomLayout.compute cannot be restored from serialized data; set layout.compute manually after deserialization."),new _o({compute:()=>null,params:e.args?e.args.params:{}})}(e);default:return void console.warn("unsupported layout type for deserialization:",e.type)}}function fo(e){return new oe(e.x-e.width/2,e.y-e.height/2,e.width,e.height)}function go(e,t,i){e.type===n.Pie&&(e.type=n.Arc),e.args.type=e.type;let r=zi(t,e.args);return e.id&&(r._id=e.id),e.classId&&(r._classId=e.classId),e.dataScope&&(r.dataScope=to(e.dataScope,i)),e.bounds&&(r._bounds=fo(e.bounds)),e.refBounds&&(r._refBounds=fo(e.refBounds)),function(e,t,i,r){if(e.vertices){const i=[];for(let t of e.vertices){const e=yo(t,r);i.push(e)}t.vertices=i}t.vertexCounter=e.vertexCounter,t.segmentCounter=e.segmentCounter,t.curveMode=e.curveMode}(e,r,0,i),r}function yo(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=to(e.dataScope,t)),"polarAngle"in e&&(i.polarAngle=e.polarAngle),i}function mo(e){let t={};t.fillColor=e.fillColor;let i=new eo(t);console.log("======== deserialization =========");let r={};if(e.tables)for(let t in e.tables){let i=e.tables[t];r[t]=new D(i.data,i.url,i.attributeTypes),r[t]._id=i.id}let s={};if(e.scales)for(let t in e.scales)s[t]=Eo(e.scales[t]);i.scales=s,i._pendingLayouts=[],vo(e,i,i,r),xo(e,i);for(let{group:e,layout:t}of i._pendingLayouts)st(e,t,i._depGraph);for(let{group:e}of i._pendingLayouts){let t=e.children[0];t&&t.links&&i.onChange(Ee.CHANNEL,"x",t)}if(delete i._pendingLayouts,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;ot(t[e],i._depGraph,r),r?i.onChange(Ee.ATTR_VALUE,t[e]):i.onChange(Ee.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)===h.Date&&(e.tickValues=e.tickValues.map(e=>new Date(new Date(e).toISOString()))),t.id&&(e.id=t.id),wo(e,i),i.axis(t.channel,t.attr,e)}if(e.gridlines)for(let t of e.gridlines){let e=t.args?t.args:{};wo(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=fo(e.bounds)),delete i.scales,i}function bo(e,t,i,r){if(e.type===n.Collection){let s=zi(i,{type:n.Collection,id:e.id});e.classId&&(s._classId=e.classId),t.addChild(s),$e(s,i._depGraph),et(t,s,i._depGraph),vo(e,s,i,r)}else if(e.type===n.Glyph){let s=zi(i,{type:n.Glyph,id:e.id});e.classId&&(s._classId=e.classId),t.addChild(s),tt(s,i._depGraph),et(t,s,i._depGraph),vo(e,s,i,r)}else if(e.type===n.Composite){let s=zi(i,{type:n.Composite,id:e.id});t.addChild(s),i._itemMap[s.id]=s,Je(s,i._depGraph),et(t,s,i._depGraph),vo(e,s,i,r),s._bounds=fo(e.bounds)}else if(e.type===n.Axis){let s=new pi({});t.addChild(s),function(e,t,i,r){e.id&&(t._id=e.id);if(t._children=[],e.labels){let s=new Ct;vo(e.labels,s,i,r),t._labels=s,t._children.push(s)}e.path&&(t._path=bo(e.path,t,i,r));if(e.ticks){let s=new Ct;vo(e.ticks,s,i,r),t._ticks=s,t._children.push(s)}e.title&&(t._title=bo(e.title,t,i,r))}(e,s,i,r),i._itemMap[s.id]=s}else if(Object.values(fe).includes(e.type)){let s=go(e,i,r);return i._itemMap[s.id]=s,t.addChild(s),qe(s,i._depGraph),et(t,s,i._depGraph),s}}function xo(e,t,i){if(e.children)for(let i of e.children)xo(i,t);else if(Object.values(fe).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 vo(e,t,i,r){if(e.id&&(t._id=e.id),e.classId&&(t._classId=e.classId),e.dataScope&&(t.dataScope=to(e.dataScope,r)),e.bounds&&(t._bounds=fo(e.bounds)),t._sortBy=e.sortBy,e.children)for(let s of e.children)bo(s,t,i,r);if(e.layout){let r=po(e.layout);r&&(t._layout=r,r.group=t,i._pendingLayouts?i._pendingLayouts.push({group:t,layout:r}):st(t,r,i._depGraph))}}function wo(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]?So(i,r,t):void 0;n||console.warn("element not created:",i),e.element=n}function Eo(e){let t=new xi(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=So(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 Ci(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:Co(i,t)}:i.map(e=>So(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 Co(e,t){let i=[],r=new Map;for(let s of e){let e=So(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 So(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 Ro(e){let t={};return t.id=e._id,t.data=e._rawData,t.attributeTypes=e._attrTypes,t.url=e.url,t}function ko(e){let t={};return t.dt=e.dataTable.id,t.attr2value=Object.assign({},e.filters),e.rowIds&&(t.rowIds=e.rowIds.slice()),t}function To(e){switch(e.type){case me.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 me.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 me.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 me.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 me.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 me.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 me.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 me.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 me.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 me.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 me.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 me.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 Oo(e,t){t.vertices=[];for(let i=0;i<e._vertices.length;i++)t.vertices.push(Io(e._vertices,i));t.vertexCounter=e.vertexCounter,t.segmentCounter=e.segmentCounter,t.curveMode=e.curveMode}function Io(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=ko(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 No(e){return e.type===n.Scene?function(e){let t=Vo(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(Po(s));for(let e of s._scales)e.id in t.scales||(t.scales[e.id]=Lo(e))}t.tables={};let i=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 i of e.children)if(![n.Axis,n.Legend,n.Gridlines].includes(i.type)){if(i.dataScope){let e=A(i.dataScope);t[e.id]=e;break}if(i.children&&i.children.length>0){let e=i.firstChild;for(;e;){if(e.dataScope){let i=A(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 i)t.tables[e]=Ro(i[e]);return console.log("======== serialization ========="),console.log(t),t}(e):[n.Collection,n.Glyph,n.Composite].includes(e.type)?Vo(e,{}):e instanceof pi?Bo(e,{}):e instanceof _e?function(e){let t={args:{}};t.type=e.type,t.id=e.id,e.classId&&(t.classId=e.classId),e.dataScope&&(t.dataScope=ko(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 ui?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 n.Arc:case n.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),Oo(e,t);break;case n.Area:!function(e,t){t.args.baseline=e._baseline,t.args.orientation=e._orientation}(e,t),Oo(e,t);break;case n.Circle:!function(e,t){t.args.x=e.x,t.args.y=e.y,t.args.radius=e.radius}(e,t);break;case n.Image:break;case n.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 n.Line:case n.Path:case n.BezierCurve:Oo(e,t);break;case n.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 n.Polygon:!function(e,t){t.args.x=e._x,t.args.y=e._y,t.args.radius=e._radius}(e,t),Oo(e,t);break;case n.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),Oo(e,t);case n.Ring:}return t}(e):(console.warn("unsupported serialization",e.type),{type:e.type})}function Lo(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 Po(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=>Re(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 Vo(e,t){if(t.id=e.id,t.type=e.type,e.classId&&(t.classId=e.classId),e.dataScope&&(t.dataScope=ko(e.dataScope)),t.bounds=e.bounds.toJSON(),e._layout&&(t.layout=To(e._layout)),t.children=[],e.children.length>0)for(let i of e.children)i instanceof pi?Bo(i,t):i instanceof Ai?Mo(i,t):i instanceof Qa?Go(i,t):i instanceof Vi?Do(i,t):t.children.push(No(i));return t.sortBy=e._sortBy,t}function Bo(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 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=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 Do(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 Go(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 zo={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 jo(e,t,i){if(!e.bounds.contains(t,i))return!1;switch(e.type){case n.Path:case n.Arc:case n.BezierCurve:case n.Line:case n.Area:case n.Pie:case n.Ring:case n.Polygon:case n.BundledPath:case n.Chord:{let r=zo.getContext(),s=zo.getPath2D(e.getSVGPathData());return r.lineWidth=Math.max(e.strokeWidth,2.5),r.stroke(s),e.closed||"none"!==e.fillColor?r.isPointInPath(s,t,i):r.isPointInStroke(s,t,i)}case n.Circle:{let r=e.x,s=e.y;if(e.rotation){let t=re(r,s,e.rotation[1],e.rotation[2],e.rotation[0]);r=t.x,s=t.y}return Math.sqrt(Math.pow(t-r,2)+Math.pow(i-s,2))<=e.radius+e.strokeWidth}case n.Collection:if([n.Arc,n.Pie,n.Polygon,n.Area].indexOf(e.firstChild.type)>=0){let r=e.getSVGPathData();if(""!==r){let s=zo.getContext(),n=zo.getPath2D(r);return s.lineWidth=Math.max(e.firstChild.strokeWidth,2.5),s.stroke(n),s.isPointInPath(n,t,i)}}return e.bounds.contains(t,i);default:return e.bounds.contains(t,i)}}const Fo="x",Wo="y",Uo="xAttr",Yo="yAttr",Ho="xCoords",Xo="yCoords",qo="xVals",Ko="yVals",Zo="xVal",$o="yVal",Jo="selectedRows",Qo="dx",el="dy",tl="dxData",il="dyData",rl="deltaX",sl="deltaY",nl="element";function al(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 ol(e){let t=new Map;for(let i of e)if(i)if(i.type===n.Collection&&i.children&&i.children.length>0){let e=i.children[0],r=msc.getChannelEncodingByElement(e,"x"),s=msc.getChannelEncodingByElement(e,"y"),n=e,a=e;!r&&e.leftSegment&&(r=msc.getChannelEncodingByElement(e.leftSegment,"x"),r&&(n=e.leftSegment)),!s&&e.bottomSegment&&(s=msc.getChannelEncodingByElement(e.bottomSegment,"y"),s&&(a=e.bottomSegment)),t.set(i.id,{element:i,child:e,xEnc:r,yEnc:s,xChild:n,yChild:a,xAttr:r?r.sourceAttribute??r.attribute:void 0,yAttr:s?s.sourceAttribute??s.attribute:void 0})}else if(i.type===n.Area){let e=null,r=null,s=null,n=null;i.anyVertex&&(e=msc.getChannelEncodingByElement(i.anyVertex,"x"),e&&(r=i.anyVertex)),!e&&i.topLeftVertex&&(e=msc.getChannelEncodingByElement(i.topLeftVertex,"x"),e&&(r=i.topLeftVertex)),!e&&i.bottomLeftVertex&&(e=msc.getChannelEncodingByElement(i.bottomLeftVertex,"x"),e&&(r=i.bottomLeftVertex)),s=msc.getChannelEncodingByElement(i,"y")??msc.getChannelEncodingByElement(i,"height"),s&&(n=i),!s&&i.anyVertex&&(s=msc.getChannelEncodingByElement(i.anyVertex,"y"),s&&(n=i.anyVertex)),!s&&i.topLeftVertex&&(s=msc.getChannelEncodingByElement(i.topLeftVertex,"y"),s&&(n=i.topLeftVertex)),t.set(i.id,{element:i,child:i,xEnc:e,yEnc:s,xChild:r,yChild:n,xAttr:e?e.sourceAttribute??e.attribute:void 0,yAttr:s?s.sourceAttribute??s.attribute:void 0})}return t}function ll(e,t,i,s,a){for(let s of e){let e,a="background"===s.source?i:s.source;a=Array.isArray(a)?a:[a];let l="brushX"===s.event?r.brushX():"brushY"===s.event?r.brushY():r.brush();var o;l.on("start",function(t){e=ol(a),o&&a.length>1&&r.select(o).call(l.move,null),o=this}),l.on("brush end",function(t){let n,o;if(t&&t.selection)switch(s.event){case"brushX":n=[t.selection[0],t.selection[1]],o=void 0;break;case"brushY":n=void 0,o=[t.selection[0],t.selection[1]];break;default:n=[t.selection[0][0],t.selection[1][0]],o=[t.selection[0][1],t.selection[1][1]]}else n=void 0,o=void 0;let l=s.eventContext;l.clear(),l.set(Ho,n),l.set(Xo,o);let h=r.select(this).attr("id").replace("brush-","");e||(e=ol(a));let c=e.get(h),d=c&&c.xAttr&&n?n.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&&n&&(p[c.xAttr]=al(c.xEnc,n,c.xChild)),c&&c.yAttr&&o&&(p[c.yAttr]=al(c.yEnc,o,c.yChild));let f=_?_.rows(p):void 0;c&&(l.set(Uo,c.xAttr),l.set(Yo,c.yAttr),l.set(qo,d),l.set(Ko,u),l.set(Jo,f)),i.onChange(Ee.EVT_CTX,l),t&&"end"===t.type&&(e=void 0)});for(let e of a){let i=e.type===n.Axis?e.boundsWithoutTitle:e.bounds,r=[[i.left,i.top],[i.right,i.bottom]];t.append("g").attr("class","brush").attr("id","brush-"+e.id).call(l.extent(r))}}}function hl(e,t,i,s,n){for(let s of e){"background"===s.source||s.source;let e=r.zoom();e.on("zoom",e=>{e.sourceEvent.preventDefault(),e.sourceEvent.stopPropagation();let r=s.eventContext;r.clear();let[n,a]=ne(t.attr("id"),e.sourceEvent.clientX,e.sourceEvent.clientY);r.set(Fo,n),r.set(Wo,a),r.set(rl,e.sourceEvent.deltaX),r.set(sl,e.sourceEvent.deltaY),i.onChange(Ee.EVT_CTX,r)}),t.call(e)}}function cl(e,t,i,s,n){for(let s of e){let e="background"===s.source?t.select("#"+i.id):Array.isArray(s.source)?t.selectAll(s.source.map(e=>e.classId?"."+e.classId:"#"+e.id).join(", ")):s.source.classId?t.selectAll("."+s.source.classId):t.select("#"+s.source.id),n=r.drag();n.on("start",e=>{let r=e.sourceEvent.target.__data__;if(!r||"vertex"===r.type||"segment"===r.type){let[s,n]=ne(t.attr("id"),e.sourceEvent.clientX,e.sourceEvent.clientY);const a=Oe(i,[]);r=a.find(e=>"vertex"!==e.type&&"segment"!==e.type&&!e.children&&jo(e,s,n)&&(msc.getChannelEncodingByElement(e,"x")||msc.getChannelEncodingByElement(e,"y"))),r||(r=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=r}),n.on("drag",e=>{let[r,n]=ne(t.attr("id"),e.sourceEvent.clientX,e.sourceEvent.clientY),a=s.eventContext;a.set(Fo,r),a.set(Wo,n),a.set(Qo,e.dx),a.set(el,e.dy);let o=s._dragElem;if(a.set("element",o),o){let t=msc.getChannelEncodingByElement(o,"x"),i=msc.getChannelEncodingByElement(o,"y");if(t){let i="log"!==t.getScale(o)?.type;a.set(Uo,t.attribute),a.set(tl,t.getAttrValue(r-e.dx,o,i)-t.getAttrValue(r,o,i))}if(i){let t="log"!==i.getScale(o)?.type;a.set(Yo,i.attribute),a.set(il,i.getAttrValue(n-e.dy,o,t)-i.getAttrValue(n,o,t))}}i.onChange(Ee.EVT_CTX,a)}),n.on("end",e=>{s._dragElem=void 0;let t=s.eventContext;t.set("element",void 0),i.onChange(Ee.EVT_CTX,t)}),e.call(n)}}function dl(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]=ne(t.attr("id"),e.clientX,e.clientY),a=r.eventContext;if(a.set(Fo,s),a.set(Wo,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(Uo,r),a.set(Yo,o),a.set(Zo,l),a.set($o,h)}let o=e.target.__data__;a.set(nl,o),i.onChange(Ee.EVT_CTX,a)};"background"===r.source?t.on("mousemove",s):e.on("mouseover",s);const n=e=>{let t=r.eventContext;t.set(nl,void 0),i.onChange(Ee.EVT_CTX,t)};"background"===r.source?t.on("mouseleave",n):e.on("mouseout",n)}}function ul(e,t,i,r,s){let n=e.filter(e=>e.isKeyboardDriven());n.length>0&&_l(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(Ee.EVT_CTX,r)})}}function _l(e,t,i,s,n){let a=".mascot-keyboard-"+i.id+"-"+t.attr("id"),o={};for(let t of e){let e=["keydown","keyup"].includes(t.event)?t.event:"keydown";e in o||(o[e]=[]),o[e].push(t)}for(let e in o)r.select(window).on(e+a,null),r.select(window).on(e+a,t=>{for(let r of o[e]){if(void 0!==r.source&&t.key!==r.source)continue;let s=r.eventContext;s.clear(),s.set("event",e),s.set("source",r.source),s.set("key",t.key),s.set("code",t.code),s.set("altKey",t.altKey),s.set("ctrlKey",t.ctrlKey),s.set("metaKey",t.metaKey),s.set("shiftKey",t.shiftKey),s.set("repeat",t.repeat),i.onChange(Ee.EVT_CTX,s)}})}function pl(e,t,i,r,s){t.on("wheel",r=>{for(let s of e){r.preventDefault(),r.stopPropagation();let[e,n]=ne(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(Ee.EVT_CTX,a)}})}function fl(e,t,i,r,s){t.on("click",r=>{for(let s of e){let[e,n]=ne(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=Oe(i,o).filter(t=>jo(t,e,n)),h=l[l.length-1];a.clear(),a.set("x",e),a.set("y",n),a.set("element",h),i.onChange(Ee.EVT_CTX,a)}})}function gl(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 yl(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";ml(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";ml(r,i,e.endStyle,e.endSize,s),t.setAttribute("marker-end","url(#"+i+")")}}function ml(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 bl(e){return e.id+"-bg"}function xl(e){return e.id+"-path"}function vl(e){return!(!e.styles||!e.styles.strokeColor||e.styles.strokeColor.type!==n.PathGradient)}function wl(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 El(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 El(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 Al(e){switch(e){case ue.TOP:return"text-before-edge";case ue.BOTTOM:return"auto";case ue.LEFT:return"start";case ue.RIGHT:return"end";case ue.CENTER:case ue.MIDDLE:return"middle";default:return e}}function Cl(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[ae[s]]=e[s]}e._dirty=!1}function Sl(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[ae[r]]=e[r]}e._dirty=!1}function Rl(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[ae[s]]=e[s]}if(r){let i=gl(e);t.setAttribute("transform",e._rotate?"rotate("+e._rotate.join(" ")+") "+i:i)}e._dirty=!1}function kl(e,t,i){let r=t[e.id];for(let t of i)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":r.setAttribute("d",e.getSVGPathData());break;case"startStyle":case"startSize":case"endStyle":case"endSize":break;case"strokeColor":r.style.stroke=vl(e)?"none":e.strokeColor;break;default:r.style[ae[t]]=e[t]}if(e.vertices){const i=r.ownerSVGElement;vl(e)?i&&wl(e,t,i):El(e,t)}if(e.type===n.Arrow){const t=r.ownerSVGElement;t&&yl(e,r,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 Tl(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[ae[s]]=e[s],r&&(r.style[ae[s]]=e[s])}e._dirty=!1}function Ol(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[ae[r]]=e[r];break;default:t.style[ae[r]]=e[r]}e._dirty=!1}function Il(e,t,i){for(let r of i)"gridlinesPosition"===r?t.setAttribute("d",e.getSVGPathData()):t.style[ae[r]]=e[r];e._dirty=!1}function Nl(e,t,i){for(let r of i)"trajectoryPosition"===r?t.setAttribute("d",e.getSVGPathData()):t.style[ae[r]]=e[r];e._dirty=!1}function Ll(e,t,i){let r=t.some(e=>"x"===e||"y"===e);Ce(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 Pl(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 Vl{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(e,t){let i=r.select("#"+this._svgId);i.on(".",null);for(let t in e.interactionTriggers){let r=Object.values(e.interactionTriggers[t]);switch(t){case"click":i.on("click",null),fl(r,i,e);break;case"brush":case"brushX":case"brushY":ll(r,i,e);break;case"drag":case"dragX":case"dragY":cl(r,i,e);break;case"hover":dl(r,i,e);break;case"change":case"input":ul(r,i,e);break;case"keydown":case"keyup":_l(r,i,e);break;case"zoom":hl(r,i,e);break;case"scroll":pl(r,i,e)}}}clear(){if(this._svg){for(;this._svg.firstChild;)this._svg.firstChild.remove();r.select("#"+this._svgId).on(".",null),console.log("clearing canvas"),this._compMap={},this._decoMap={}}}_renderItem(e,t,i){if(this._configSVG(e),!e.children&&!1===e._dirty)return;let r=this._compMap[e.id];if(i){const e=i.delay||0,t=i.duration||0;r.style.transition=`all ${t}ms ease ${e}ms`}switch(e.type){case n.Scene:!function(e,t){t.style.background=e.fillColor?e.fillColor:"#fff"}(e,this._svg);break;case n.Circle:!function(e,t){t.setAttribute("cx",e.x),t.setAttribute("cy",e.y),t.setAttribute("r",e.radius)}(e,r);break;case n.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,r);break;case n.Path:case n.BezierCurve:case n.BundledPath:case n.Chord:case n.Polygon:case n.Link:case n.Pie:case n.Line:case n.Area:case n.Ring:case n.Arc:case n.Gridlines:case n.Trajectory:case n.Arrow:!function(e,t,i){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===n.BundledPath&&(t.style.mixBlendMode="multiply"),e.type===n.Arrow&&i&&yl(e,t,i)}(e,r,this._svg);break;case n.SimpleText:!function(e,t,i){if(t.setAttribute("text-anchor",Al(e.anchor[0])),t.setAttribute("alignment-baseline",Al(e.anchor[1])),t.setAttribute("dominant-baseline",Al(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","#"+xl(e)),i.setAttribute("startOffset",e.textPathOffset),i.textContent=e.text}else t.textContent=e.text}(e,r,this._compMap[bl(e)]);break;case n.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,r);break;case n.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,r);break;case n.Symbol:!function(e,t){t.setAttribute("d",e.path),t.setAttribute("transform",gl(e))}(e,r)}if(e._rotate){let t=r.getAttribute("transform"),i=r.getAttribute("data-mascot-rotate");i&&t&&0===t.indexOf(i)&&(t=t.slice(i.length).trim());let s="rotate("+e._rotate.join(" ")+")";r.setAttribute("transform",t?s+" "+t:s),r.setAttribute("data-mascot-rotate",s)}else{let e=r.getAttribute("data-mascot-rotate");if(e){let t=r.getAttribute("transform");if(t&&0===t.indexOf(e)){let i=t.slice(e.length).trim();i?r.setAttribute("transform",i):r.removeAttribute("transform")}r.removeAttribute("data-mascot-rotate")}}if(function(e,t,i){if(!e.styles)return;let r=Object.keys(e.styles);e.type===n.RichText&&(r=r.filter(e=>["textAnchor","fillColor"].indexOf(e)<0));for(let s of r)if(void 0!==e.styles[s])if("strokeColor"===s&&e.styles[s].type==n.PathGradient)t.style.stroke="none";else if(s.indexOf("Color")>0&&e.styles[s].type==n.LinearGradient){const r=i.querySelector("defs"),n=e.styles[s];if(!r.querySelector("#"+n.id)){const e=document.createElementNS("http://www.w3.org/2000/svg","linearGradient");e.setAttribute("id",n.id),e.setAttribute("x1",n.x1+"%"),e.setAttribute("x2",n.x2+"%"),e.setAttribute("y1",n.y1+"%"),e.setAttribute("y2",n.y2+"%");for(let t of n.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)}r.appendChild(e)}t.style[ae[s]]="url(#"+n.id+")"}else if(t.style[ae[s]]=e.styles[s],"visibility"===s)if(e.type===n.SimpleText){if(e.hasBackground()){const t=i.querySelector("#"+bl(e));t&&(t.style[ae[s]]=e.styles[s])}}else if(e.type===n.RichText){const i=t.querySelector("div");i&&(i.style.visibility=e.styles[s])}}(e,r,this._svg),e.vertices&&(vl(e)?wl(e,this._compMap,this._svg,this._removed):El(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):pe(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 s=i.querySelector("rect");s||(s=document.createElementNS("http://www.w3.org/2000/svg","rect"),i.appendChild(s)),s.setAttribute("x",e.clipMask.left),s.setAttribute("y",e.clipMask.top),s.setAttribute("width",e.clipMask.width),s.setAttribute("height",e.clipMask.height),r.setAttribute("clip-path","url(#"+e.id+"-clipPath)");let n=e.id+"-bg",a=r.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"),r.insertBefore(a,r.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 r=[...e.children].sort((e,t)=>(e.z||0)-(t.z||0));for(let e of r)this._renderItem(e,t,i)}else e._dirty=!1}_renderChanges(e,t){for(let i in t){let r=e.getElement(i);if(r){switch(r.type){case n.Rect:Ce(r).forEach(e=>{!1!==e._dirty&&Cl(e,this._compMap[e.id],t[i])});break;case n.Circle:Ce(r).forEach(e=>{!1!==e._dirty&&Sl(e,this._compMap[e.id],t[i])});break;case n.Path:case n.Area:case n.Line:case n.Arrow:case n.BezierCurve:case n.BundledPath:case n.Pie:case n.Arc:case n.Ring:case n.Polygon:case n.Chord:let e=[],s=["x","y","width","height"];for(let r of t[i])s.includes(r)?e.indexOf("d")<0&&e.push("d"):e.push(r);Ce(r).forEach(t=>{!1!==t._dirty&&kl(t,this._compMap,e)});break;case n.SimpleText:Ce(r).forEach(e=>{!1!==e._dirty&&Tl(e,this._compMap[e.id],t[i],this._compMap[bl(e)])});break;case n.RichText:Ce(r).forEach(e=>{!1!==e._dirty&&Ol(e,this._compMap[e.id],t[i])});break;case n.Symbol:Ce(r).forEach(e=>{!1!==e._dirty&&Rl(e,this._compMap[e.id],t[i])});break;case n.Glyph:Ll(r,t[i],this);break;case n.Gridlines:!0===r._dirty&&Il(r,this._compMap[r.id],t[i]);break;case n.Trajectory:!0===r._dirty&&Nl(r,this._compMap[r.id],t[i]);break;case n.Axis:case n.Legend:Ce(r).forEach(e=>{Pl(e,this)});break;case n.Collection:case n.Group:case n.Composite:break;default:console.warn("unsupported element type for update: "+r.type)}t[i].includes("z")&&r.parent&&this._reorderSiblingsByZ(r.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===n.SimpleText&&(e.hasBackground()&&delete this._removed[bl(e)],e.textPath&&delete this._removed[xl(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(vl(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,i=e.parent;if(t=i&&i.id&&i.id in this._compMap?this._svg.querySelector("#"+i.id):this._svg,e.type===n.SimpleText){if(e.hasBackground()){const i=document.createElementNS("http://www.w3.org/2000/svg","rect");i.setAttribute("id",bl(e)),t.appendChild(i),this._compMap[bl(e)]=i}if(e.textPath){const t=this._svg.querySelector("defs"),i=xl(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 r=document.createElementNS("http://www.w3.org/2000/svg",this._getSVGElementType(e));t?t.appendChild(r):console.warn("Parent element not found for ",e.id,e.parent?e.parent.id:null),this._compMap[e.id]=r}if(e.type==n.Gridlines||e.type==n.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===n.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 n.Rect:return"rect";case n.Collection:case n.Group:case n.Glyph:case n.Scene:case n.Axis:case n.Legend:case n.Composite:return"g";case n.Area:case n.Path:case n.Polygon:case n.Ring:case n.Pie:case n.Arc:case n.BezierCurve:case n.BundledPath:case n.Chord:case n.Line:case n.Gridlines:case n.Trajectory:case n.Arrow:return"path";case n.Circle:return"circle";case n.SimpleText:return"text";case n.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 n.Symbol:return"path"}}}function Bl(e,t){return void 0===e&&void 0===t||void 0!==e&&void 0!==t}function Ml(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 Dl(e,t){if(!Bl(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 me.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(!zl(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 me.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 me.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 me.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 me.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 me.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 me.STRATA:return function(e,t){return e._direction===t._direction&&e._gap===t._gap}(i,r);case me.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 me.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 me.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 Gl(e,t){if(!Bl(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||zl(i,r)}function zl(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function jl(e,t){if(!Bl(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(!Wl(e,t))return console.log("DataScopes not equal",e,t),!1;if(!Gl(e,t))return console.log("Bounds not equal",e,t),!1;if(!Bl(e.links,t.links))return console.log("Not both defined or undefined: links ",e.links,t.links),!1;if(!Bl(e.source,t.source))return console.log("Not both defined or undefined: source ",e.source,t.source),!1;if(!Bl(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&&!jl(e.source,t.source))return console.log("different sources",e.source,t.source),!1;if(e.target&&t.target&&!jl(e.target,t.target))return console.log("different targets",e.target,t.target),!1;switch(e.type){case n.Arc:case n.Pie:return Fl(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 n.Area:return Fl(e,t)?e.baseline===t.baseline&&e.orientation===t.orientation:(console.log("vertices not equal:",e,t),!1);case n.Circle:return e.x===t.x&&e.y===t.y&&e.radius===t.radius;case n.Image:return console.warn("not implemented"),!0;case n.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 n.Line:case n.Path:case n.BezierCurve:return!!Fl(e,t)||(console.log("vertices not equal:",e,t),!1);case n.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 n.Polygon:return Fl(e,t)?e.x===t.x&&e.y===t.y&&e.radius===t.radius:(console.log("vertices not equal:",e,t),!1);case n.Rect:return Fl(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 n.Ring:default:return console.warn("not implemented"),!0}}function Fl(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):Wl(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 Wl(e,t){if(!Bl(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(!Ml(s,n))return!1;for(let e in s)if(s[e]!==n[e])return!1;return i.dataTable.id===r.dataTable.id&&S(i).length===S(r).length}function Ul(e,t){return e.type!==t.type&&console.log("Different types:",e.type,t.type),[n.Collection,n.Glyph,n.Composite].includes(e.type)?Yl(e,t):e instanceof _e?jl(e,t):void 0}function Yl(e,t){let i=e.children.filter(e=>!Object.values(a).includes(e.type)),r=t.children.filter(e=>!Object.values(a).includes(e.type));if(i.length!==r.length)return console.log("children length not equal:",i,r),!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(!Wl(e,t))return console.log("DataScopes not equal",e.dataScope,t.dataScope),!1;if(!Gl(e,t))return console.log("Bounds not equal",e,t),!1;if(!Dl(e,t))return console.log("Layouts not equal",e,t),!1;if(!function(e,t){if(!Ml(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(!Ul(i[e],r[e]))return console.log("Not equal",i[e],r[e]),!1;return!0}function Hl(e){if([n.Line,n.Circle,n.Rect,n.Area,n.Ring,n.Pie,n.Path].indexOf(e.type)<0)return!1;if(e.type===n.Path&&(e.closed||!e.firstVertex.dataScope))return!1;if(e.dataScope){let t=Ce(e);for(let e of t)if(k(e.dataScope)>1)return!0;return!1}return!0}function Xl(e){return e.type===n.Collection&&!(e.children.length<2)}function ql(e,t,i,r,s,a,o,l,h,c){let d=i.map(e=>r.getParent(e)).filter((e,t,i)=>i.findIndex(t=>t[X]===e[X])===t);if(d=d.filter(e=>e!==r.getRoot()),0===d.length)return;let u=[];for(let i of d){let d,_,p,f=t.filter(e=>r.getParent(r.getNode(e.datum[X]))===i);if(f[0].type===n.Circle){let e=f.map(e=>se(o,l,e.bounds.x,e.bounds.y)-e.radius),t=f.map(e=>se(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=>$t(e.bounds.x,e.bounds.y,o,l)),r=f.map(e=>$t(o+se(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===n.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=Zt(d),_=Zt(_),p=h===Mt.OUTWARD?d3.max(f.map(e=>e.outerRadius)):d3.min(f.map(e=>e.innerRadius))-c);let g=zi(e,{type:"arc",innerRadius:p,outerRadius:p+c,x:o,y:l,startAngle:Zt(d),endAngle:Zt(_),strokeColor:t[0].strokeColor,fillColor:t[0].fillColor,strokeWidth:t[0].strokeWidth,opacity:t[0].opacity});g._updateBounds(),g.dataScope=r.getNodeDataScopeRef(i),g._classId=a,s.addChild(g),u.push(g)}ql(e,u,d,r,s,a,o,l,h,c)}function Kl(e,t,i,r,s,a,o,l,h){h&&(e.dataScope=s.getNodeDataScopeRef(a),e._classId=t);let c=s.getChildren(a);if(0===c.length)return;let d=e.type===n.Circle||e.type===n.Ring?60:e.startAngle,u=(e.type===n.Circle||e.type===n.Ring?360:e.angle)/c.length;for(let a=0;a<c.length;a++){let h,_;_=i===Mt.OUTWARD?e.type===n.Circle?e.radius:e.outerRadius:e.type===n.Circle?e.radius-r:e.innerRadius-r,h=zi(l,360===u?{type:"ring",innerRadius:_,outerRadius:_+r,x:e.x,y:e.y,strokeColor:e.strokeColor,fillColor:e.fillColor,strokeWidth:e.strokeWidth,opacity:e.opacity}:{type:"arc",innerRadius:_,outerRadius:_+r,x:e.x,y:e.y,startAngle:Zt(d+u*a),endAngle:Zt(d+u*(a+1)),strokeColor:e.strokeColor,fillColor:e.fillColor,strokeWidth:e.strokeWidth,opacity:e.opacity}),h._updateBounds(),h.dataScope=s.getNodeDataScopeRef(c[a]),h._classId=t+"_strata",o.addChild(h),Kl(h,t,i,r,s,c[a],o,l)}}function Zl(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=Wi(e);Et(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),Zl(o,t,i,r,s,u[n],a)}}}class $l{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 Jl{constructor(e,t){this._elem=e,this._base=t,this._id=Ql(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?ue.CENTER:ue.MIDDLE,i.baseAnchor="baseAnchor"in t?t.baseAnchor:"x"==e||"angle"==e?ue.CENTER:ue.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:j}}function Ql(e,t){return(e.classId?e.classId:e.id)+":"+(t.classId?t.classId:t.id)}function eh(e,t,i,r){e.vertices[0].dataScope&&A(e.vertices[0].dataScope).has(t)?function(e,t,i,r){let s;if(t===j)s=(e,i)=>parseInt(O(e.dataScope,t).substring(1))-parseInt(O(i.dataScope,t).substring(1));else{switch(A(e.vertices[0].dataScope).type(t)){case h.Date:break;case h.Number:case h.Integer:s=(e,i)=>N(e.dataScope,t)-N(i.dataScope,t);break;case h.String:s=r?(e,i)=>r.indexOf(O(e.dataScope,t))-r.indexOf(O(i.dataScope,t)):(e,i)=>O(e.dataScope,t)<O(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 th{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=>Ce(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}}const ih=j;e.ROW_ID=ih,e.TRIGGER_ELEMENT=He,e.activate=function(e,t,i,r,s){const n=Pe(t.object===He?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 Ye(o,e.source,e.event,e.cumulative));let l=n._triggers[a][o].eventContext,h=new th(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===He,a=n?s.source:t.responderComponent,o=s&&s.source&&"stateVar"===s.source.type?r.getVariable(Ee.STATE,s.source.key,s.source.stateContext):r.getVariable(Ee.EVT_CTX,e),l=i.properties?i.properties:i.channels;if(t.evalFunction){let e=r.getVariable(Ee.CONDITION_RESULT,t),i=r.findIncomingDataflowOperator(ve.TARGET_EVALUATOR,e);i||(i=r.createOneWayDependency(ve.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(Ee.CHANNEL,t,s),n=i.incomingDataflow;if(n&&n.type===ve.ENCODER&&n.outputVar.channel===t)r.connect(e,n);else if(!n){let n=r.createOneWayDependency(ve.ENCODER);r.connect(e,n),r.connect(n,i),n.storeValues(s,t)}}}}else{let e=r.createOneWayDependency(ve.TARGET_UPDATER,t.stylingFunction,a,n);for(let t of l){let i;i=a instanceof Ae?r.getVariable(Ee.STATE,t,a):Object.values(Ge).includes(t)?r.getVariable(Ee.CHANNEL,t,a):r.getVariable(Ee.PROPERTY,je(t),a),r.connect(o,e),r.connect(e,i)}}}(l,h,t,n._depGraph,e),n._triggers[a][o]},e.affix=function(e,t,i,r){let s=Pe(e);A(e.dataScope)!==A(t.dataScope)&&console.warn("Affix: elements and base elements are not created from the same table");let n=Ql(e,t),a=s._relations.find(e=>e.id===n);a||(a=new Jl(e,t),s._relations.push(a)),a.addChannel(i,r||{}),function(e,t){let i=t.getVariable(Ee.AFFIXATION,e),r=t.getOutgoingDataflowOperator(ve.AFFIXER,i);t.connect(i,r);for(let i of e.channels){let s=t.getVariable(Ee.CHANNEL,i,e.element),n=t.getVariable(Ee.CHANNEL,i,e.base);t.connect(n,r),t.connect(r,s)}r.run()}(a,s._depGraph)},e.align=function(e,t,i){let r=Pe(e[0]),s=new $l(e,t,i);!function(e,t){let i=t.createMultiWayDependency(ve.ALIGNER),r=t.getVariable(Ee.ALIGNMENT,e);t.connect(r,i);for(let r of e.elements){let s=t.getVariable(Ee.CHANNEL,e.channel,r);t.connect(s,i)}i.run()}(s,r._depGraph),r._relations.push(s)},e.attach=function(e,t){if(e.type==n.Glyph)for(let t of e.children)t._refBounds||(t._refBounds=t.bounds.clone());e.dataScope=V(t)},e.canClassify=Xl,e.canDensify=nr,e.canDivide=Hl,e.canRepeat=Li,e.childHitTest=function(e,t,i,r){let s=r?r.map(e=>obj2Predicate(e)):[];if(!e.children||0==e.children.length)return jo(e,t,i)&&e.type!==n.Scene?e:void 0;let a=e.children;e.type===n.Scene&&(a=a.slice(),a.sort((e,t)=>St(e)?1:St(t)?-1:0));for(let e=0;e<a.length;e++){let r=a[e];if(jo(r,t,i)&&te(r,s))return r}},e.childrenHitTestByRect=function(e,t,i){let r=[];if(!e.children||0==e.children.length)return e.bounds.overlap(t)&&e.type!==n.Scene?[e]:[];for(let i=e.children.length-1;i>=0;i--){let s=e.children[i];s.bounds.overlap(t)&&r.push(s)}return r},e.classify=function(e,t){let i=Pe(e),r=t||{};if(console.log("------ classify by",r.attribute," ----"),!Xl(e))throw new Error("The "+e.type+" is not classifiable");return function(e,t,i,r){let s=Ce(t);for(let t of s){let s,a={},o=t.children;for(let e of o){let t=O(e.dataScope,i);t in a||(a[t]=[]),a[t].push(e)}let l=z(o[0]);for(let o in a){let h=zi(e,{type:n.Collection});t.addChild(h),void 0===s&&(s=h.id),h._classId=s,h.dataScope=L(t.dataScope?t.dataScope:V(l),i,o);for(let e of a[o])h.addChild(e);r&&(h._layout=r.clone(),h._layout.group=h)}}}(i,e,r.attribute,r.layout),Qe(e,e.firstChild.firstChild,i._depGraph),$e(e.firstChild,i._depGraph),et(e.firstChild,e.firstChild.firstChild,i._depGraph),et(e,e.firstChild,i._depGraph),i.onChange(Ee.CHANNEL,"width",e.firstChild.firstChild),e.firstChild},e.connect=function(e,t){let i=Pe(e[0]),r={};e.forEach(e=>r[O(e.dataScope,X)]=e);let s=A(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=O(e.dataScope,n),i=O(e.dataScope,a),s=r[t],o=r[i];e.source=s,e.target=o,s.links.push(e),o.links.push(e)}nt(e.find(e=>e.links.length>0),i._depGraph),i.onChange(Ee.CHANNEL,"x",e[0])},e.contains=jo,e.csv=async function(e){return async function(e){let t=await q("GET",e),i=r.csvParse(t.trim(),r.autoType);return new D(i,e)}(e)},e.csvString=function(e){return function(e){let t=r.csvParse(e.trim(),r.autoType);return new D(t,"fromString")}(e)},e.densify=function(e,t,i){let r=e.scene,s=i||{};if(s.attribute=s.attribute||j,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 D&&l(i.attribute,t)}(e,t,s),t instanceof F||t instanceof U)throw"Not implemented";if(t instanceof D){let i=function(e,t,i,r,s){let a=s.type(i);if(a!=h.String&&a!=h.Date&&a!=h.Number&&a!=h.Integer)throw new Error("Densify only works on a string or date attribute: "+i+" is "+a);if(!nr(t))throw new Error("The "+t.type+" is not dividable");switch(t.type){case n.Line:return function(e,t,i,r){let s,n,a=Ce(t);for(let o of a){let a=o.dataScope?o.dataScope:V(r),l=B(a,i,!1);1===l.length&&l.push(l[0]);let h=Object.assign({},o.styles);for(let e of Gt.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=zi(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,i,s);case n.Circle:return function(e,t,i,r){let s,n,a=Ce(t),o=r.type(i);for(let l of a){let a=l.dataScope?l.dataScope:V(r),c=B(a,i,o==h.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(l.x,l.y,l.radius,f[e]);p.push(i)}let y=Object.assign({},l.styles);y.vertices=p,y.type="polygon",y.x=l.x,y.y=l.y,y.radius=l.radius;let m=zi(e,y);n||(n=m.id),m._classId=n,m.dataScope=a;let b=l.parent;b.addChild(m),b.removeChild(l);for(let e=0;e<m._vertices.length;e++)m._vertices.setProperty(e,"polarAngle",f[e]),m._vertices.setDataScopeRef(e,c[e]);l===t&&(s=m)}return s}(e,t,i,s);case n.Rect:return function(e,t,i,r,s){let n,a,o=Ce(t),l=i||It;if(l!=It&&l!=Nt)throw new Error("Unknown orientation: "+l);for(let i of o){let o=s.type(r),c=i.dataScope?i.dataScope:V(s),d=B(c,r,o==h.Number);1===d.length&&d.push(d[0]),o!=h.Number&&o!=h.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(l==Nt?[f,p+e*b/(d.length-1)]:[_+e*m/(d.length-1),p]);for(let e=0;e<d.length;e++)y.push(l==Nt?[_,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=zi(e,u);a||(a=x.id),x._classId=a,x.dataScope=c,x.orientation=l,x.baseline=l===It?ue.BOTTOM:ue.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,r,i,s)}}(r,e,s.attribute,s.orientation,t);return Ke(e,r._depGraph),qe(i,r._depGraph),i.parent.type!==n.Scene&&et(i.parent,i,r._depGraph),function(e,t,i){let r=i.findVariable(Ee.ITEMS,[t]);if(!r)return;let s=null;for(let e of r.outgoingEdges)if(e.isDirected&&e.toNode.type===ve.REPOPULATE){s=e.toNode;break}if(!s)return;let n=i.getVariable(Ee.DATASCOPE,e);if(i.connect(s,n),e._vertices&&e._vertices.length>0){let t=e.vertices[0],r=i.getVariable(Ee.DATASCOPE,t);i.connect(s,r)}}(i,t,r._depGraph),i.type===n.Area&&function(e,t,i,r){let s=r.findVariable(Ee.ITEMS,[i]);if(!s)return;for(let e of s.outgoingEdges)if(e.isDirected&&e.toNode.type===ve.REPOPULATE)return;let n=r.createOneWayDependency(ve.REPOPULATE);n._area=e,n._repeatAttr=t,r.connect(s,n);let a=r.getVariable(Ee.DATASCOPE,e);if(r.connect(n,a),e._vertices&&e._vertices.length>0){let t=r.getVariable(Ee.DATASCOPE,e.vertices[0]);r.connect(n,t)}}(i,s.attribute,t,r._depGraph),r.onChange(Ee.CHANNEL,"width",i),i}},e.deserialize=function(e){return mo(e)},e.divide=function(e,t,i){let r=e.scene,s=i||{};if(s.attribute=s.attribute||j,console.log("------ divide by",s.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 D&&l(i.attribute,t);if(i.layout&&!(i.layout instanceof ge))throw new Error("Invalid layout: "+i.layout)}(e,t,s),t instanceof F||t instanceof U)throw"Not implemented";if(t instanceof D){let{newMark:i,collection:a}=function(e,t,i,r,s){let a=s.type(i);if(a!=h.String&&a!=h.Date&&a!=h.Integer)throw new Error("Divide only works on a string or date attribute: "+i+" is "+a);if(!Hl(t))throw new Error("The "+t.type+" is not dividable");switch(t.type){case n.Line:case n.Path:return;case n.Circle:return function(e,t,i,r,s){let a,o,l,h=Ce(t),c=i||Lt;if(c!=Lt&&c!=Pt)throw new Error("Unknown orientation: "+c);c===Lt&&h.forEach(i=>{let h=i.dataScope?i.dataScope:V(s),c=B(h,r),d=zi(e,{type:n.Collection});null==o&&(o=d.id),d._classId=o,d.dataScope=h;let u=i.parent;u.removeChild(i),delete e._itemMap[i.id];let _=360/c.length,p=90;for(let r=0;r<c.length;r++){let s=zi(e,{type:"arc",innerRadius:0,outerRadius:i.radius,x:i.x,y:i.y,startAngle:Zt(p-_*(r+1)),endAngle:Zt(p-_*r),strokeColor:i.strokeColor,fillColor:i.fillColor,strokeWidth:i.strokeWidth,opacity:i.opacity});l||(l=s.id),s.classId=l,s.dataScope=c[r],s._updateBounds(),s._refBounds=s.bounds.clone(),d.addChild(s),d._layout=new ao({orientation:Lt,direction:Bt.CLOCKWISE}),d._layout.group=d,u.removeChild(i),u.addChild(d),i===t&&(a=d)}});return{newMark:a.children[0],collection:a}}(e,t,r,i,s);case n.Rect:return function(e,t,i,r,s){let a,o=Ce(t),l=i||It;if(l!=It&&l!=Nt)throw new Error("Unknown orientation: "+l);let h={},c=0;for(let e of o){let t=B(e.dataScope?e.dataScope:V(s),r);t.length>c&&(c=t.length),h[e.id]=t}let d,u=zi(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 i of o){let r=zi(e,{type:n.Collection});null==d&&(d=r.id),r._classId=d,r.dataScope=i.dataScope?i.dataScope:V(s);let o=i.parent;o.removeChild(i),delete e._itemMap[i.id];let c=h[i.id],_=i.bounds,p=_.left,f=_.top,g=l==It?_.width/c.length:_.width,y=l==It?_.height:_.height/c.length;for(let e=0;e<c.length;e++){let t=Wi(u);t.dataScope=c[e],t.resize(g,y),t._updateBounds(),t._refBounds=t.bounds.clone(),r.addChild(t)}o.addChild(r),r._layout=new ao({orientation:l,left:p,top:f}),r._layout.group=r,i==t&&(a=r)}return e.removeChild(u),delete e._itemMap[u.id],{newMark:a.children[0],collection:a}}(e,t,r,i,s);case n.Area:return function(e,t,i,r,s){let a,o=Ce(t),l=i||It;if(l!=It&&l!=Nt)throw new Error("Unknown orientation: "+l);let h,c={},d=0;for(let e of o){let t=B(e.dataScope?e.dataScope:V(s),r);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 _=zi(e,u);_._classId=_.id;for(let i of o){let r=zi(e,{type:n.Collection});null==h&&(h=r.id),r._classId=h,r.dataScope=i.dataScope?i.dataScope:V(s);let o=i.parent;o.removeChild(i),delete e._itemMap[i.id];let d=c[i.id],u=i.bounds,p=u.left,f=u.top,g=l==It?u.width/d.length:u.width,y=l==It?u.height:u.height/d.length;for(let e=0;e<d.length;e++){let t=Wi(_);t.dataScope=d[e],t.resize(g,y),t._updateBounds(),t._refBounds=t.bounds.clone(),r.addChild(t);for(let e=0;e<t.vertices.length;e++){let r=t.vertices[e],s=i.vertices[e];s&&s.dataScope?r.dataScope=P(t.dataScope,s.dataScope):r.dataScope=t.dataScope}}o.addChild(r),r._layout=new ao({orientation:l,left:p,top:f}),r._layout.group=r,i==t&&(a=r)}return e.removeChild(_),delete e._itemMap[_.id],{newMark:a.children[0],collection:a}}(e,t,r,i,s);case n.Ring:return function(e,t,i,r,s){let a,o,l,h=Ce(t),c=i||Lt;if(c!=Lt&&c!=Pt)throw new Error("Unknown orientation: "+c);c===Lt&&h.forEach(i=>{let h=i.dataScope?i.dataScope:V(s),c=B(h,r),d=zi(e,{type:n.Collection});null==o&&(o=d.id),d._classId=o,d.dataScope=h;let u=i.parent;u.removeChild(i),delete e._itemMap[i.id];let _=360/c.length,p=90;for(let r=0;r<c.length;r++){let s=zi(e,{type:"arc",innerRadius:i.innerRadius,outerRadius:i.outerRadius,x:i.x,y:i.y,startAngle:Zt(p-_*(r+1)),endAngle:Zt(p-_*r),strokeColor:i.strokeColor,fillColor:i.fillColor,strokeWidth:i.strokeWidth,opacity:i.opacity});l||(l=s.id),s.classId=l,s.dataScope=c[r],s._updateBounds(),s._refBounds=s.bounds.clone(),d.addChild(s),d._layout=new ao({orientation:Lt,direction:Bt.CLOCKWISE}),d._layout.group=d,u.removeChild(i),u.addChild(d),i===t&&(a=d)}});return{newMark:a.children[0],collection:a}}(e,t,r,i,s);case n.Pie:case n.Arc:return function(e,t,i,r,s){let a,o,l,h=Ce(t),c=i||Lt;if(c!=Lt&&c!=Pt)throw new Error("Unknown orientation: "+c);c===Lt||h.forEach(i=>{let h=i.dataScope?i.dataScope:V(s),c=B(h,r),d=zi(e,{type:n.Collection});null==o&&(o=d.id),d._classId=o,d.dataScope=h;let u=i.parent;u.removeChild(i),delete e._itemMap[i.id];for(let r=0;r<c.length;r++){let s=zi(e,{type:"arc",innerRadius:i.innerRadius+r*(i.outerRadius-i.innerRadius)/c.length,outerRadius:i.innerRadius+(r+1)*(i.outerRadius-i.innerRadius)/c.length,x:i.x,y:i.y,startAngle:i.startAngle,endAngle:i.endAngle,strokeColor:i.strokeColor,fillColor:i.fillColor,strokeWidth:i.strokeWidth,opacity:i.opacity});l||(l=s.id),s.classId=l,s.dataScope=c[r],s._updateBounds(),s._refBounds=s.bounds.clone(),d.addChild(s),d._layout=new ao({orientation:Pt}),d._layout.group=d,u.removeChild(i),u.addChild(d),i===t&&(a=d)}});return{newMark:a.children[0],collection:a}}(e,t,r,i,s)}}(r,e,s.attribute,s.orientation,t);return Ke(e,r._depGraph),qe(i,r._depGraph),$e(a,r._depGraph),et(a,i,r._depGraph),a.parent.type!==n.Scene&&et(a.parent,a,r._depGraph),r.onChange(Ee.CHANNEL,"width",i),{newMark:i,collection:a}}},e.encode=Si,e.findElements=Oe,e.getChannelEncodingByAttribute=ft,e.getChannelEncodingByElement=gt,e.getEncodingsByChannel=function(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},e.getEncodingsByElement=pt,e.getLeafMarks=Be,e.getPeers=Ce,e.gradient=function(e,t){return"path"===e?new _i(t):new ui(t)},e.graphJSON=async function(e){return async function(e){let t=await q("GET",e);return new U(JSON.parse(t),e)}(e)},e.isDataBound=function(e,t){return"x"===t||"width"===t?xt(e):"y"===t||"height"===t?bt(e):null!==gt(e,t)},e.isDataBoundHorizontally=xt,e.isDataBoundVertically=bt,e.isEqual=function(e,t){return function(e,t){return e.fillColor!==t.fillColor?(console.log("fillColor not equal:",e,t),!1):Yl(e,t)}(e,t)},e.isMark=pe,e.isRefElement=St,e.layout=function(e,t){let i=t||{};switch(e.toLowerCase()){case me.STACK:return new ao(i);case me.PACKING:return new no(i);case me.FORCE:return new so(i);case me.DIRECTED:return new ro(i);case me.TIDYTREE:return new lo(i);case me.TREEMAP:return new ho(i);case me.CIRCULAR:return new uo(i);case me.CLUSTER:return new io(i);case me.SPIRAL:return new co(i);case me.CUSTOM:return new _o(i);case me.GRID:default:return new Pi(i)}},e.markHitTest=function(e,t,i,r){let s=Be(e),n=r?r.map(e=>obj2Predicate(e)):[];for(let e=s.length-1;e>=0;e--){let r=s[e];if(jo(r,t,i)&&te(r,n))return r}},e.markPrimitiveHitTest=function(e,t,i,r){let s,n=Be(e),a=r||2,o=zo.getContext();for(let e of n){if(!(e instanceof Path))continue;let r=zo.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 oe(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=zo.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},e.markPrimitiveHitTestByRect=function e(t,i,r){let s=r||2;if(pe(t)){let e=[];for(let i of t.vertices){let t=Math.max(s,i.width,2*i.radius),r=Math.max(s,i.height,2*i.radius);e.push({i:i,b:new oe(i.x-t/2,i.y-r/2,t,r)})}if(t.type===ItemType.Rect)for(let i of t.segments){let r=Math.max(t.strokeWidth,s);"v"===(i.vertex1.x===i.vertex2.x?"v":"h")?e.push({i:i,b:new oe(i.vertex1.x-r/2,d3.min([i.vertex1.y,i.vertex2.y])-r/2,r,Math.abs(i.vertex1.y-i.vertex2.y))}):e.push({i:i,b:new oe(d3.min([i.vertex1.x,i.vertex2.x])-r/2,i.vertex1.y-r/2,Math.abs(i.vertex1.x-i.vertex2.x),r)})}for(let t of e)if(t.b.intersects(i))return t.i;return null}if(!isGuide(t)&&t.children&&t.children.length>0){for(let r of t.children)if(r.bounds.intersects(i)){let t=e(r,i,s);if(t)return t}return null}return null},e.removeEncoding=_t,e.renderer=function(e,t){return new Vl(t)},e.repeat=Ii,e.repopulate=function(e,t,i){e.dataScope=void 0;let r=Pe(e),s=e;for(let e in i){br(r,s,i[e],t);let n=pt(s.children[0],!0);for(let e of n)_t(e,r);let a=Ce(s);for(let e of a)if(e.layout){for(let t of e.layout.refElements)ut(t,r),Ze(t,r._depGraph);e.layout.clearRefElements()}s=s.children[0]}e.dataScope=V(t),r.onChange(Ee.CHANNEL,"width",e.children[0])},e.scene=function(e){return new eo(e)},e.serialize=function(e){return No(e)},e.sortChildren=function(e,t,i,r){let s=Pe(e);if(e instanceof Ct)!function(e,t,i,r){e.dataScope&&A(e.dataScope).has(t)?function(e,t,i,r){if(!A(e.dataScope).has(t))return void console.warn("Cannot order collection children by an non-existent attribute",t);let s;if(t===j)s=(e,i)=>parseInt(O(e.dataScope,t).substring(1))-parseInt(O(i.dataScope,t).substring(1));else{switch(A(e.children[0].dataScope).type(t)){case h.Date:break;case h.Number:case h.Integer:s=(e,i)=>N(e.dataScope,t)-N(i.dataScope,t);break;case h.String:s=r?(e,i)=>r.indexOf(O(e.dataScope,t))-r.indexOf(O(i.dataScope,t)):(e,i)=>O(e.dataScope,t)<O(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(Ee.PROPERTY,We.CHILDREN_ORDER,e);else if(e instanceof Ft){let s=Ce(e);for(let e of s)eh(e,t,i,r)}},e.stratify=function(e,t,i){if(!(t instanceof F||Array.isArray(t)&&t.every(e=>e instanceof F)))throw"Cannot stratify on a non-tree dataset";if(![n.Circle,n.Rect,n.Ring].includes(e.type))throw"Cannot stratify elements that are not rects, circles, or rings";let r=Pe(e),s=i||{},a=s.direction,o=s.size,l=e.parent,h=function(e,t,i,r,s,a){switch(t.type){case n.Circle:case n.Ring:return function(e,t,i,r,s,a){let o,l=i||Mt.OUTWARD,h=s||50;if(l!==Mt.INWARD&&l!==Mt.OUTWARD)throw"Unknown direction to stratify";let c,d=Ce(t,e),u=Array.isArray(a)?a:[a];if(r){let i=zi(e,{type:n.Collection});i.dataScope=void 0,null==c&&(c=i.id),i._classId=c;let r=d.map(e=>u[0].getNode(e.datum[X]));ql(e,d,r,u[0],i,t.classId?t.classId:t.id,400,350,l,h),o=i}else d.forEach((i,r)=>{let s=zi(e,{type:n.Collection});s.dataScope=void 0,null==c&&(c=s.id),s._classId=c;let a=i.parent;Kl(i,t.id,l,h,u[r],u[r].getRoot(),s,e,!0),s._layout=new oo({direction:l}),s._layout.group=s,a.addChild(s),i===t&&(o=s)});return o}(e,t,i,r,s,a);case n.Rect:return function(e,t,i,r,s,a){let o,l,h=i||Vt.Top2Bottom,c=s||50;if(!Object.values(Vt).includes(h))throw"Unknown direction to stratify";return Ce(t).forEach(i=>{let r=zi(e,{type:n.Collection});r.dataScope=void 0,null==l&&(l=r.id),r._classId=l;let s=i.parent;Zl(i,t.id,h,c,a,a.getRoot(),r,e,!0),r._layout=new oo({direction:h}),r._layout.group=r,s.addChild(r),i===t&&(o=r)}),o}(e,t,i,0,s,a)}}(r,e,a,s.startFromLeaf,o,t);return Qe(l,e,r._depGraph),$e(h,r._depGraph),h.children.length>0&&et(h,h.firstChild,r._depGraph),et(h.parent,h,r._depGraph),h},e.table=function(e){return new D(e,"")},e.transform=function(e,t,i){switch(e){case"kde":return new Ka(t);case"filter":return new Za(t);case"custom":return new $a(t,i);case"unpivot":return new Ja(t);default:return new qa(t)}},e.translate=wt,e.treeJSON=async function(e){return async function(e){let t=await q("GET",e);return new F(JSON.parse(t),e)}(e)},e.update=function(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(ye(e)){let i=e.group?[e.group]:[],r=[];for(let e of i)r=r.concat(Ce(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=Pe(e);if(s)for(let e of i)e.firstChild&&s.onChange(Ee.CHANNEL,"width",e.firstChild);return}let i=Ce(e),r=Pe(e);for(const[s,n]of Object.entries(t))if("layout"!==s)for(let e of i)ar(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(Ge).includes(i)?r.onChange(Ee.CHANNEL,i,e):r.onChange(Ee.PROPERTY,i,e)))}});
|