mascot-vis 3.0.3 → 3.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
- // version: 3.0.3
2
- import*as e from"d3";const t={canvas:void 0,getCanvas:function(){return window?(void 0===this.canvas&&(this.canvas=document.createElement("canvas")),this.canvas):null},getContext:function(){var e=this.getCanvas();return e?e.getContext("2d"):null}};class r{constructor(e,t,r){this._id="predicate_"+It(),this._type=e||n.POINT,this._variableType=t,this._variableName=r,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 n=Object.freeze({POINT:"point",INTERVAL:"interval",LIST:"list"});class i extends r{constructor(e,t,r){super(e,t,r)}testElement(e){let t;if("attribute"==this._variableType){if(!e.dataScope)return!1;t=e.dataScope.getAttributeValue(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 s extends r{constructor(e,t,r){super(e,t,r)}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=e.dataScope.getAttributeValue(this._variableName);return this._value.indexOf(t)>=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 a extends r{constructor(e,t,r){super(e,t,r)}testElement(e){if("attribute"==this._variableType){if(!e.dataScope)return!1;return e.dataScope.getAttributeValue(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}}function o(e){let t,r="attribute"in e?"attribute":"property",o=e[r];switch(e.type){case n.LIST:t=new s(e.type,r,o);break;case n.INTERVAL:t=new i(e.type,r,o);break;case n.POINT:default:t=new a(e.type,r,o)}return e.value&&(t.value=e.value),t}function l(e,t){for(let r of t){if(!o(r).testElement(e))return!1}return!0}class u{constructor(e,t,r,n){this._x=e+r/2,this._y=t+n/2,this._width=r,this._height=n}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=Math.min(this.left,e.left),r=Math.min(this.top,e.top),n=Math.max(this.right,e.right),i=Math.max(this.bottom,e.bottom);return new u(t,r,n-t,i-r)}clone(){return new u(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 p.RIGHT:this._x=this.right-e/2;break;case p.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 p.TOP:this._y=this.top+e/2;break;case p.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}overlap(e){return!(this.right<e.left||this.bottom<e.top||this.left>e.right||this.top>e.bottom)}}function c(e){let t=e[0].clone();for(let r=1;r<e.length;r++)t=t.union(e[r]);return t}function h(e){return c(("vertex"==e[0].type||"segment"==e[0].type?e.map((e=>e.parent)):e).map((e=>e.refBounds?e.refBounds:e.bounds)))}function d(e){return c(("vertex"==e[0].type||"segment"==e[0].type?e.map((e=>e.parent)):e).map((e=>e.bounds)))}function f(e){let t=S(e);for(let e of t)e._updateBounds();let r=[];for(let e of t)e.parent&&!r.includes(e.parent)&&r.push(e.parent);for(let e of r)f(e)}const p=Object.freeze({TOP:"top",LEFT:"left",RIGHT:"right",BOTTOM:"bottom",CENTER:"center",MIDDLE:"middle"});function _(e){return e.id+"-bg"}function g(e){return e.id+"-path"}function y(e){switch(e){case p.TOP:return"text-before-edge";case p.BOTTOM:return"auto";case p.LEFT:return"start";case p.RIGHT:return"end";case p.CENTER:case p.MIDDLE:return"middle";default:return e}}const m=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"});class b{constructor(e){let t=e||{};this._stops=[],this.type=Tt.LinearGradient,this.id=this.type+It(),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,r){this._stops.push({offset:e,color:t,opacity:r})}get stops(){return this._stops}}class v{constructor(e){if(this._dataScope=void 0,this._type="type"in e?e.type:Tt.Mark,this._id=e.id?e.id:this._type+"_"+It(),this._classId=void 0,this._bounds=void 0,this._rotate=void 0,this._refBounds=void 0,this._styles={},void 0!==e)for(let t in m)t in e&&(this.styles[t]=e[t])}get scene(){return P(this)}set strokeColor(e){this.styles.strokeColor=e}get strokeColor(){return this.styles.strokeColor}set strokeWidth(e){this.styles.strokeWidth=e}get strokeWidth(){return this.styles.strokeWidth}set strokeDash(e){this.styles.strokeDash=e}get strokeDash(){return this.styles.strokeDash}set fillColor(e){this.styles.fillColor=e}get fillColor(){return this.styles.fillColor}get rotation(){return this._rotate}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}contains(e,r){if(!this.bounds)return!1;if(!this.bounds.contains(e,r))return!1;switch(this.type){case Tt.Rect:case Tt.PointText:return!0;case Tt.Circle:return Math.sqrt(Math.pow(e-this.x,2)+Math.pow(r-this.y,2))<=this.radius+this.strokeWidth;case Tt.Path:{let n=t.getContext(),i=new Path2D(this.getSVGPathData());return n.lineWidth=Math.max(this.strokeWidth,2.5),n.stroke(i),this.closed?n.isPointInPath(i,e,r):n.isPointInStroke(i,e,r)}case Tt.Line:{let n=t.getContext(),i=new Path2D(this.getSVGPathData());return n.lineWidth=Math.max(this.strokeWidth,2.5),n.stroke(i),n.isPointInStroke(i,e,r)}default:{let n=t.getContext(),i=new Path2D(this.getSVGPathData());return n.isPointInPath(i,e,r)}}}set dataScope(e){this._dataScope=e}get dataScope(){return this._dataScope}get styles(){return this._styles}set styles(e){this._styles=e}set visibility(e){this.styles.visibility=e}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}copyPropertiesTo(e){e.styles=Object.assign({},this.styles),this._dataScope&&(e._dataScope=this._dataScope.clone())}}function x(e){return e instanceof v&&e.type!==Tt.Gridlines}const E=Object.freeze({Area:"area",Rect:"rect",Ellipse:"ellipse",Circle:"circle",Pie:"pie",Ring:"ring",Arc:"arc",Line:"line",Path:"path",Image:"image",PointText:"text",Polygon:"polygon",BezierCurve:"bezierCurve"});function w(e,t,r){const n=document.getElementById(e),i=n.createSVGPoint();i.x=t,i.y=r;const s=i.matrixTransform(n.getScreenCTM().inverse());return[s.x,s.y]}function A(e,t,r,n){return Math.sqrt(Math.pow(e-r,2)+Math.pow(t-n,2))}function C(e,t,r,n,i){const s=i*Math.PI/180,a=e-r,o=t-n;return{x:a*Math.cos(s)-o*Math.sin(s)+r,y:a*Math.sin(s)+o*Math.cos(s)+n}}const R={svg:void 0,getSVG:function(){return window?(void 0===this.svg&&(this.svg=document.createElement("svg")),this.svg):null}},k={canvas:void 0,getCanvas:function(){return window?(void 0===this.canvas&&(this.canvas=document.createElement("canvas")),this.canvas):null},getContext:function(){var e=this.getCanvas();return e?e.getContext("2d"):null}};function S(e,t){let r=P(e),n=t||r;if("vertex"===e.type){return T(e,I(n,[{property:"classId",value:e.parent.classId}]))}if("segment"===e.type){return O(e,I(n,[{property:"classId",value:e.parent.classId}]))}return e.classId?I(n,[{property:"classId",value:e.classId}]):[e]}function T(e,t){if(!e.classId){if(e.dataScope){let r=e.parent;if(!r)throw new Error("vertex has no parent mark");let n=[];if(r.type===Tt.Area){let i=r.vertices.indexOf(e)<r.vertices.length/2;for(let e of t){let t=i?e.vertices.slice(0,e.vertices.length/2):e.vertices.slice(e.vertices.length/2);n=n.concat(t.filter((e=>e.dataScope)))}}else for(let e of t)n=n.concat(e.vertices.filter((e=>e.dataScope)));return n}{let r=e.parent;if(!r)throw new Error("vertex has no parent mark");let n=r.vertices.indexOf(e),i=[];for(let e of t)i.push(e.vertices[n]);return i}}}function O(e,t){if(e.dataScope){if(!e.parent)throw new Error("segment has no parent mark");let r=[];for(let e of t)r=r.concat(e.segments);return r}{let r=e.parent;if(!r)throw new Error("segment has no parent mark");let n=r.segments.indexOf(e),i=[];for(let e of t)i.push(e.segments[n]);return i}}function I(e,t){let r=[];return V(e,t,r),r}function N(e,t){let r=e.children.filter((e=>e.type==Tt.Collection));if(0!==r.length)for(let e of r){let r=e;for(;r&&r.dataScope;){if(r.dataScope.hasAttribute(t))return r;r=r.children?r.children[0]:void 0}}}function L(e){return e.type==Tt.Collection?e:e.parent?L(e.parent):void 0}function V(e,t,r){if(e&&"axis"!=e.type&&"legend"!=e.type&&"gridlines"!=e.type)if(l(e,t)&&r.push(e),e.vertices)for(let n of e.vertices.concat(e.segments))l(n,t)&&r.push(n);else if(e.children&&e.children.length>0)for(let n of e.children)V(n,t,r)}function P(e){let t=e;for(;t;){if(t.type==Tt.Scene)return t;t=t.parent}}function D(e){let t=e;for("vertex"!=t.type&&"segment"!=t.type||(t=t.parent);t.parent&&[Tt.Collection,Tt.Glyph].includes(t.parent.type);)t=t.parent;return t}function B(e,t,r,n){let i=I(e,[{property:"type",value:t}]);for(let e of i)if(M(e,r,n))return e}function M(e,r,n){switch(e.type){case Tt.Path:case Tt.Arc:case Tt.BezierCurve:case Tt.Line:{let i=t.getContext(),s=new Path2D(e.getSVGPathData());return i.lineWidth=Math.max(e.strokeWidth,2.5),i.stroke(s),e.closed?i.isPointInPath(s,r,n):i.isPointInStroke(s,r,n)}case Tt.Circle:{let t=e.x,i=e.y;if(e.rotation){let r=C(t,i,e.rotation[1],e.rotation[2],e.rotation[0]);t=r.x,i=r.y}return Math.sqrt(Math.pow(r-t,2)+Math.pow(n-i,2))<=e.radius+e.strokeWidth}default:return e.bounds.contains(r,n)}}function G(e,t){let r=[];if(j(e,r),t){let e={};for(let t of r)e[t.classId]=t;return Object.values(e)}return r}function j(e,t){if(x(e))t.push(e);else if(e.type==Tt.Collection&&e.children)for(let r of e.children)j(r,t);else if(e.type==Tt.Glyph&&e.children)for(let r of e.children)j(r,t);else if(e.type==Tt.Composite&&e.children)for(let r of e.children)j(r,t)}class z{constructor(){this._refElements=[]}addRefElement(e){this._refElements.push(e)}get refElements(){return this._refElements}clearRefElements(){this._refElements=[]}}const F=Object.freeze({GRID:"grid",STACK:"stack",PACKING:"packing",FORCE:"force",DIRECTED:"directedgraph",TIDYTREE:"tidytree",TREEMAP:"treemap",STRATA:"strata",CIRCULAR:"circular",CLUSTER:"cluster"});function U(e,t){return!!(e.startsWith("h")&&[p.LEFT,p.CENTER,p.RIGHT].indexOf(t)>=0)||(!!(e.startsWith("v")&&[p.TOP,p.MIDDLE,p.BOTTOM].indexOf(t)>=0)||(console.warn("Invalid alignment:",t),!1))}class H{constructor(e){this._id=e+"_"+It(),this._type=e,this._inputVars=[],this._outputVars=[]}run(){console.log("-",this._type,this.outputVar.element?this.outputVar.element.type:"",this.outputVar.channel?this.outputVar.channel:"")}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 W=Object.freeze({CONDUIT:"conduit",ENCODER:"encoder",LAYOUT:"layout",LINK_PLACER:"linkRouter",CONSTRAINT:"constraint",EVAL_BBOX:"evalBBox",EVAL_REFBOUNDS:"evalRefBounds",AFFIXER:"affixer",ALIGNER:"aligner",DOMAIN_BUILDER:"domainBuilder",SCALE_BUILDER:"scaleBuilder",AXIS_PATH_PLACER:"axisPathPlacer",AXIS_TICKS_PLACER:"axisTicksPlacer",AXIS_LABELS_PLACER:"axisLabelsPlacer",AXIS_TITLE_PLACER:"axisTitlePlacer",GRIDLINES_PLACER:"gridlinesPlacer",GRID_LAYOUT:"gridLayout",STACK_LAYOUT:"stackLayout",PACK_LAYOUT:"packLayout",FORCE_LAYOUT:"forceLayout",DIRECTED_LAYOUT:"directedLayout",TIDY_TREE_LAYOUT:"tidyTreeLayout",TREEMAP_LAYOUT:"treemapLayout",STRATA_LAYOUT:"strataLayout",CIRCULAR_LAYOUT:"circularLayout",CLUSTER_LAYOUT:"clusterLayout",BIN_TRANSFORMER:"binTransformer",FILTER_TRANSFORMER:"filterTransformer",KDE_TRANSFORMER:"kdeTransformer",TARGET_EVALUATOR:"targetEvaluator"});class Y{constructor(e){this._id="v_"+It(),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 H)return e.fromNode;return null}isIsolated(){return 0==this._incomings.length&&0==this._outgoings.length}}const X=Object.freeze({CHANNEL:"channel",PROPERTY:"property",ATTRIBUTE:"attribute",ITEMS:"items",DATASCOPE:"datascope",DOMAIN:"domain",BOUNDS:"bounds",ORDER:"order",SCALE:"scale",COND_ENCODING:"condEncoding",AFFIXATION:"affixation",ALIGNMENT:"alignment",TRIGGER:"trigger"});class q extends Y{constructor(e,t){super(e),this._condEnc=t}get condEncoding(){return this._condEnc}}const K=Object.freeze({RowFirst:"rowFirst",ColumnFirst:"columnFirst"}),Z=Object.freeze({TopLeft:"topLeft",TopRight:"topRight",BottomLeft:"bottomLeft",BottomRight:"bottomRight"}),$={HORIZONTAL:"horizontal",VERTICAL:"vertical",ANGULAR:"angular",RADIAL:"radial"},J={Left2Right:"l2r",Right2Left:"r2l",Top2Bottom:"t2b",Bottom2Top:"b2t"},Q=Object.freeze({CLOCKWISE:"clockwise",ANTI_CLOCKWISE:"anti-clockwise"}),ee=Object.freeze({INWARD:"inward",OUTWARD:"outward"});class te{constructor(e,t,r,n){this.type="vertex",this._id=n,this._x=e,this._y=t,this._dataScope=void 0,this.parent=r,this.shape=void 0,this.width=0,this.height=0,this.radius=0,this.fillColor="#555",this.opacity=1,this.strokeWidth=0,this.strokeColor="#aaa",this._polarAngle=void 0}get dataScope(){return this._dataScope}set dataScope(e){this._dataScope=e}get bounds(){switch(this.shape){case"rect":return new u(this.x-this.width/2,this.y-this.height/2,this.width,this.height);case"circle":return new u(this.x-this.radius,this.y-this.radius,2*this.radius,2*this.radius);default:return new u(this.x-.5,this.y-.5,1,1)}}get id(){return this.parent.id+"_v_"+this._id}_clone(e){let t=new te(this.x,this.y,e,this._id);return this._dataScope&&(t._dataScope=this._dataScope.clone()),t.shape=this.shape,t.width=this.width,t.height=this.height,t.radius=this.radius,t.fillColor=this.fillColor,t.opacity=this.opacity,t.strokeWidth=this.strokeWidth,t.strokeColor=this.strokeColor,t}get polarAngle(){return this._polarAngle}get scene(){return this.parent.scene}get x(){return this._x}get y(){return this._y}}te.styles=["vxShape","vxWidth","vxHeight","vxRadius","vxFillColor","vxStrokeColor","vxStrokeWidth","vxOpacity"];class re{constructor(e,t,r,n){this.type="segment",this._id=n,this.vertex1=e,this.vertex2=t,this.dataScope=void 0,this.parent=r}get id(){return this.parent.id+"_s_"+this._id}get x(){return(this.vertex1.x+this.vertex2.x)/2}get y(){return(this.vertex1.y+this.vertex2.y)/2}get scene(){return this.parent.scene}}class ne extends v{constructor(e){super(e),this._type="type"in e?e.type:Tt.Path,this.vertices=[],this.vertexCounter=0,this._sortBy={},this.segmentCounter=0,this.segments=[],this.anchor=void 0,this.closed=!1,this.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 te.styles)t in e&&(this["_"+t]=e[t]);"vertices"in e&&this._setVertices(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")}_setVertices(e){let t;this.vertices=[],this.segments=[],this.vertexCounter=0,this.segmentCounter=0;for(let r=0;r<e.length;r++)if(r!=e.length-1||e[r][0]!==e[0][0]||e[r][1]!==e[0][1]||this.type!==Tt.Path){t=new te(e[r][0],e[r][1],this,this.vertexCounter++);for(let e of te.styles)if(this[e]){let r=e.replace("vx","");t[r[0].toLowerCase()+r.slice(1)]=this[e]}this.vertices.push(t),r>0&&this.segments.push(new re(this.vertices[r-1],this.vertices[r],this,this.segmentCounter++))}let r=e[0],n=e[e.length-1];(r[0]===n[0]&&r[1]===n[1]||this.type===Tt.Rect)&&(this.closed=!0,"fillColor"in this.styles||(this.styles.fillColor="#fff"),this.segments.push(new re(this.vertices[this.vertices.length-1],this.vertices[0],this,this.segmentCounter++)))}copyPropertiesTo(e){e.attrs=Object.assign({},this.attrs),e.styles=Object.assign({},this.styles);for(let t of te.styles)this["_"+t]&&(e["_"+t]=this["_"+t]);this._dataScope&&(e._dataScope=this._dataScope.clone()),e.closed=this.closed,e.curveMode=this.curveMode,e.vertices=[],e.segments=[];for(let t of this.vertices)e.vertices.push(t._clone(e));e.segmentCounter=0;for(let t=1;t<e.vertices.length;t++)e.segments.push(new re(e.vertices[t-1],e.vertices[t],e,e.segmentCounter++));e.closed&&e.segments.push(new re(e.vertices[e.vertices.length-1],e.vertices[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}get strokeColor(){return this.styles.strokeColor}get strokeWidth(){return this.styles.strokeWidth}get fillColor(){return this.styles.fillColor}set fillColor(e){this.styles.fillColor=e}get strokeDash(){return this.styles.strokeDash}set strokeDash(e){this.styles.strokeDash=e}resize(e,t,r,n){let i=this.bounds,s=0===i.width?1:i.width,a=0===i.height?1:i.height;if("right"===r)for(let t of this.vertices)t._x=i.right-e/s*(i.right-t.x);else for(let t of this.vertices)t._x=i.left+e/s*(t.x-i.left);if("top"===n)for(let e of this.vertices)e._y=i.top+t/a*(e.y-i.top);else for(let e of this.vertices)e._y=i.bottom-t/a*(i.bottom-e.y);this._updateBounds()}_updateBounds(){let e=[],t=[];if(this._d){const r=this._d.match(/[a-zA-Z][^a-zA-Z]*/g),n=" ";r.forEach((r=>{let i=r.slice(1).trim().split(n).map(Number);for(let[r,n]of i.entries())r%2==0?e.push(n):t.push(n)}))}else e=this.vertices.map((e=>e.x)),t=this.vertices.map((e=>e.y));let r=Math.min(...e),n=Math.min(...t),i=Math.max(...e),s=Math.max(...t),a=i-r,o=s-n;if(this._bounds=new u(r,n,a,o),this.type===Tt.Line||this.type===Tt.Path){let e=this.styles.strokeWidth?this.styles.strokeWidth:1;r===i?this._bounds=new u(r-e/2,n,i-r+e,s-n):n===s&&(this._bounds=new u(r,n-e/2,i-r,s-n+e))}}addVertex(e,t,r){let n=new te(e,t,this,this.vertexCounter++);this.vertices.splice(r,0,n)}sortVertices(e,t){this.vertices.sort(((t,r)=>t[e]-r[e])),t&&this.vertices.reverse();for(let e=0;e<this.segments.length;e++){let t=this.segments[e];t.vertex1=this.vertices[e],t.vertex2=this.vertices[(e+1)%this.vertices.length]}}sortVerticesByData(e,t,r){let n;n=r?(t,n)=>r.indexOf(t.dataScope.getValue(e))-r.indexOf(n.dataScope.getAttributeValue(e)):(t,r)=>t.dataScope.getAttributeValue(e)<r.dataScope.getAttributeValue(e)?-1:1,this.vertices.sort(n),t&&this.vertices.reverse();for(let e=0;e<this.segments.length;e++){let t=this.segments[e];t.vertex1=this.vertices[e],t.vertex2=this.vertices[(e+1)%this.vertices.length]}}getSVGPathData(){if(this._d)return this._d;let t=e.path(),r=this._getD3CurveFunction(this.curveMode)(t);r.lineStart();for(let e of this.vertices)r.point(e.x,e.y);return this.closed&&r.point(this.vertices[0].x,this.vertices[0].y),r.lineEnd(),t._}get firstVertex(){return this.vertices[0]}get firstSegment(){return this.segments[0]}get lastVertex(){return this.vertices[this.vertices.length-1]}get lastSegment(){return this.segments[this.segments.length-1]}_getD3CurveFunction(t){switch(t){case ae.Natural:return e.curveNatural;case ae.Basis:return e.curveBasis;case ae.BumpX:return e.curveBumpX;case ae.BumpY:return e.curveBumpY;case ae.Linear:return e.curveLinear;case ae.Step:return e.curveStep;case ae.CatmullRom:return e.curveCatmullRom;case ae.Cardinal:return e.curveCardinal;case ae.Bundle:return e.curveBundle.beta(.5);default:return e.curveLinear}}get vxShape(){return this._vxShape}get vxWidth(){return this._vxWidth}get vxHeight(){return this._vxHeight}get vxRadius(){return this._vxRadius}get vxFillColor(){return this._vxFillColor}get vxStrokeColor(){return this._vxStrokeColor}get vxStrokeWidth(){return this._vxStrokeWidth}get vxOpacity(){return this._vxOpacity}get sourceAnchor(){return this._sourceAnchor}get targetAnchor(){return this._targetAnchor}get sourceOffset(){return this._sourceOffset}get targetOffset(){return this._targetOffset}}function ie(e,t){const r=R.getSVG();let n=document.createElementNS("http://www.w3.org/2000/svg","path");n.setAttribute("d",e.getSVGPathData()),r.appendChild(n);let i=n.getTotalLength();return n.getPointAtLength(i*t)}function se(e){return e instanceof ne&&e.source&&e.target}const ae={Natural:"natural",Basis:"basis",BumpX:"bumpX",BumpY:"bumpY",Bundle:"bundle",Linear:"linear",Step:"step",CatmullRom:"CatmullRom",Cardinal:"cardinal"};function oe(e,t,r){const n=e.match(/[a-zA-Z][^a-zA-Z]*/g),i=",";return n.map((e=>{const n=e[0],s=e.slice(1).trim();if("M"===n||"L"===n||"T"===n){const[e,a]=s.split(i).map(Number);return`${n}${e+t} ${a+r}`}if("C"===n){const e=s.split(i).map(Number);return`${n}${e[0]+t} ${e[1]+r} ${e[2]+t} ${e[3]+r} ${e[4]+t} ${e[5]+r}`}if("Q"===n){const e=s.split(i).map(Number);return`${n}${e[0]+t} ${e[1]+r} ${e[2]+t} ${e[3]+r}`}if("A"===n){const e=s.split(i).map(Number);return`${n}${e[0]} ${e[1]} ${e[2]} ${e[3]} ${e[4]} ${e[5]+t} ${e[6]+r}`}return"Z"===n||"z"===n?n:e})).join(" ")}class le extends ne{constructor(e){super(e),this._type=Tt.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=ue(this._startAngle),this._er=ue(this._endAngle),this._direction="direction"in e?e.direction:Q.ANTI_CLOCKWISE;let t=this._x+this._innerRadius*Math.cos(this._sr),r=this._y-this._innerRadius*Math.sin(this._sr),n=this._x+this._innerRadius*Math.cos(this._er),i=this._y-this._innerRadius*Math.sin(this._er),s=this._x+this._outerRadius*Math.cos(this._sr),a=this._y-this._outerRadius*Math.sin(this._sr),o=this._x+this._outerRadius*Math.cos(this._er),l=this._y-this._outerRadius*Math.sin(this._er);this._setVertices([[t,r],[s,a],[o,l],[n,i]])}get type(){return 0===this._innerRadius?Tt.Pie:Tt.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=ue(this._startAngle),this._er=ue(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)}_updateBounds(){let e=this.vertices.map((e=>e.x)),t=this.vertices.map((e=>e.y)),r=Math.min(...e),n=Math.min(...t),i=Math.max(...e)-r,s=Math.max(...t)-n;this._bounds=new u(r,n,i,s)}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 ue(e){return e*Math.PI/180}function ce(e){return 180*e/Math.PI}function he(e){return(e%360+360)%360}function de(e,t,r,n){let i=e-r,s=n-t;return Math.atan2(s,i)*(180/Math.PI)}class fe{constructor(e){this._attr2value={},this._dt=e,this._tuples=this._dt.data}isFullTable(){return 0===Object.keys(this._attr2value).length}isEmpty(){return 0==this._tuples.length}get numTuples(){return this._tuples.length}get attributes(){return Object.keys(this._attr2value)}get dataTable(){return this._dt}get filters(){return this._attr2value}merge(e){let t=new fe(this._dt);for(let e in this._attr2value)t=t.cross(e,this._attr2value[e]);for(let r in e._attr2value)t=t.cross(r,e._attr2value[r]);return t}cross(e,t){if(e in this._attr2value&&this._attr2value[e]!==t)return console.warn("Conflict in attribute values when merging dataScope:",e,this._attr2value[e],t),this;let r=this.clone();return r._attr2value[e]=t,r._updateTuples(e,t),r}clone(){let e=new fe(this._dt);return e._attr2value=Object.assign({},this._attr2value),e._tuples=this._tuples.map((e=>e)),e}getAttributeValue(e){let t=this.getAttributeValues(e);return t.length,t[0]}getAttributeValues(e){let t=this._tuples.map((t=>t[e]));return t=[...new Set(t)],t}getUniqueAttributeValues(e){let t=this._tuples.map((t=>t[e]));return[...new Set(t)]}hasAttribute(e){return e in this._attr2value}getAttributeType(e){return this._dt.getAttributeType(e)}aggregateNumericalAttribute(t,r){let n=this._tuples.map((e=>e[t]));switch(r){case _e.Max:return Math.max(...n);case _e.Min:return Math.min(...n);case _e.Avg:case _e.Mean:return e.mean(n);case _e.Median:return e.median(n);case _e.Count:return n.length;case _e.Percentile25:return e.quantile(n,.25);case _e.Percentile75:return e.quantile(n,.75);case _e.Sum:default:return e.sum(n)}}_updateTuples(e,t){this._tuples=this._tuples.filter((r=>r[e]==t))}get tuples(){return this._tuples}}function pe(e){return"vertex"==e.type||"segment"==e.type?e.dataScope?e.dataScope:e.parent.dataScope:e.dataScope}const _e={Max:"max",Min:"min",Avg:"avg",Median:"median",Sum:"sum",Count:"count",Mean:"mean",Percentile25:"percentile 25",Percentile75:"percentile 75"};class ge{constructor(e,t){this._id=Tt.TreeData+It(),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 Nt(this._nodeList,"nodes"),this._linkTable=new Nt(this._linkList,"links"),this._nodeTable.tree=this,this._linkTable.tree=this}get nodeTable(){return this._nodeTable}get linkTable(){return this._linkTable}_traverse(e,t,r,n=0){let i={};xe in e||(e[xe]="n"+t.length),t.push(i),e._depth=n;for(let s in e)if("children"==s&&e[s]&&e[s].length>0)for(let i of e[s]){let s=this._traverse(i,t,r,n+1);r.push({parent:e[xe],child:s})}else i[s]=e[s];return this._nodeHash[i[xe]]=i,i[xe]}getNodeDataScope(e){return new fe(this._nodeTable).cross(Vt,e[Vt])}getNode(e){return this._nodeHash[e]}getRoot(){return this._nodeTable.data[0]}getChildren(e){let t=e[xe],r=[],n=this._linkTable.data,i=this._nodeTable.data;for(let e in n)if(n[e].parent==t){let t=n[e].child,s=i.findIndex((e=>e[xe]==t));r.push(i[s])}return r}getParent(e){let t=e[xe],r=this._linkTable.data,n=this._nodeTable.data;for(let e in r)if(r[e].child==t){let t=r[e].parent,i=n.findIndex((e=>e[xe]==t));return n[i]}}}function ye(e){return e.dataScope._dt.tree}class me{constructor(e,t){this._id=Tt.NetworkData+It(),this.initialize(e,t)}initialize(e,t){this.url=t,this._nodeTable=new Nt(e.nodes,this._id+"_nodes"),this._linkTable=new Nt(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[xe]]=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[xe],r=this._rawLinks,n=[];for(let e in r)r[e].target!==t&&r[e].source!==t||n.push(r[e]);return n}buildNodeHierarchy(e){let t={};return t[xe]="root",ve(t,this._rawNodes,e),new ge(t,this.url)}}function be(e){return e.dataScope._dt.graph}function ve(e,t,r){if(0===t.length||0===r.length)return;"children"in e||(e.children=[]);let n={};for(let e of t){let t=e[r[0]];t in n||(n[t]=[]),n[t].push(e)}if(1===r.length)for(let t in n){let r={children:n[t]};r[xe]=t,e.children.push(r)}else for(let t in n){let i={};i[xe]=t,e.children.push(i),ve(i,n[t],r.slice(1))}}const xe="id";function Ee(e,t){if(t.hasAttribute(e))return!0;if(t.tree&&t.tree.nodeTable.hasAttribute(e.split(".")[1]))return!0;throw new Error(["Attribute",e,"does not exist in the table",t.name].join(" "))}const we=Object.freeze({Boolean:"boolean",Integer:"integer",Number:"number",Date:"date",String:"string"});function Ae(e){var t=Object.values(we);for(let r=0;r<e.length;r++){let n=e[r];if(null!=n){for(let e=0;e<t.length;e++)Ce[t[e]](n)||(t.splice(e,1),e-=1);if(1==t.length)return t[0]}}return t[0]}const Ce={boolean:function(e){return"true"===e||"false"===e||!0===e||!1===e||"[object Boolean]"==toString.call(e)},integer:function(e){return Ce.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 Re(t,r){let n={};switch(r){case we.Boolean:n.trueCount=t.filter((e=>e)).length,n.falseCount=t.filter((e=>!e)).length;break;case we.Date:n.min=e.min(t),n.max=e.max(t),n.extent=[n.min,n.max],n.unique=[...new Set(t)];break;case we.String:n.unique=[...new Set(t)];break;default:n.min=e.min(t),n.max=e.max(t),n.extent=[n.min,n.max],n.mean=e.mean(t),n.median=e.median(t),n.unique=[...new Set(t)]}return n}function ke(e,t,r,n,i){let s=i.getAttributeType(r);if(s!=we.String&&s!=we.Date&&s!=we.Number&&s!=we.Integer)throw new Error("Densify only works on a string or date attribute: "+r+" is "+s);if(!function(e){if([Tt.Line,Tt.Circle,Tt.Rect,Tt.Area].indexOf(e.type)<0)return!1;if(e.dataScope){let t=S(e,e.scene);for(let e of t)if(e.dataScope.numTuples>1)return!0;return!1}return!0}(t))throw new Error("The "+t.type+" is not dividable");switch(t.type){case Tt.Line:return function(e,t,r){let n,i,s=S(e);for(let a of s){let s=a.dataScope?a.dataScope:new fe(r),o=r.getUniqueAttributeValues(t).map((e=>s.cross(t,e)));o=o.filter((e=>!e.isEmpty())),1===o.length&&o.push(o[0].clone());let l=Object.assign({},a.styles);for(let e of te.styles)a[e]&&(l[e]=a[e]);let u=a.vertices[0].x,c=a.vertices[0].y,h=[],d=a.vertices[1].x-u,f=a.vertices[1].y-c;for(let e=0;e<o.length;e++)h.push([u+e*d/(o.length-1),c+e*f/(o.length-1)]);l.vertices=h,l.type="path";let p=At(l);i||(i=p.id),p._classId=i,p.dataScope=s,p._updateBounds(),p._refBounds=p.bounds.clone();let _=a.parent;_.addChild(p),_.removeChild(a);for(let[e,t]of p.vertices.entries())t.dataScope?t.dataScope=t.dataScope.merge(o[e]):t.dataScope=o[e];a==e&&(n=p)}return n}(t,r,i);case Tt.Circle:return function(e,t,r,n,i){let s,a,o=S(e),l=r.getAttributeType(t);for(let u of o){let o=u.dataScope?u.dataScope:new fe(r),c=r.getUniqueAttributeValues(t).map((e=>o.cross(t,e)));c=l==we.Number?c:c.filter((e=>!e.isEmpty()));let h=c.length;if(h<3)throw new Error("INSUFFICIENT_DATA_SCOPES");let d=n||90,f=360/h,p=[],_=[],g="clockwise"==(i||"clockwise")?-1:1;for(let e=0;e<c.length;e++){let t=d+g*e*f;_[e]=t;let r=Se(u.x,u.y,u.radius,_[e]);p.push(r)}let y=Object.assign({},u.styles);y.vertices=p,y.type="polygon",y.x=u.x,y.y=u.y,y.radius=u.radius;let m=At(y);a||(a=m.id),m._classId=a,m.dataScope=o;let b=u.parent;b.addChild(m),b.removeChild(u);for(let[e,t]of m.vertices.entries())t._polarAngle=_[e],e>=c.length?t.dataScope=o.merge(c[2*c.length-1-e]):t.dataScope=o.merge(c[e]);u===e&&(s=m)}return s}(t,r,i);case Tt.Rect:return function(e,t,r,n){let i,s,a=S(e),o=t||$.HORIZONTAL;if(o!=$.HORIZONTAL&&o!=$.VERTICAL)throw new Error("Unknown orientation: "+o);for(let t of a){let a=n.getAttributeType(r),l=t.dataScope?t.dataScope:new fe(n),u=n.getUniqueAttributeValues(r).map((e=>l.cross(r,e)));u=a==we.Number?u:u.filter((e=>!e.isEmpty())),1===u.length&&u.push(u[0].clone()),a!=we.Number&&a!=we.Date||u.sort(((e,t)=>e._attr2value[r]>t._attr2value[r]?1:-1));let c=Object.assign({},t.styles),h=t.vertices[0].x,d=t.vertices[0].y,f=t.vertices[t.vertices.length-2].x,_=t.vertices[t.vertices.length-2].y,g=[],y=f-h,m=_-d;for(let e=0;e<u.length;e++)g.push(o==$.VERTICAL?[f,d+e*m/(u.length-1)]:[h+e*y/(u.length-1),d]);for(let e=0;e<u.length;e++)g.push(o==$.VERTICAL?[h,d+(u.length-1-e)*m/(u.length-1)]:[h+(u.length-1-e)*y/(u.length-1),_]);c.vertices=g,c.type="area";let b=At(c);s||(s=b.id),b._classId=s,b.dataScope=l,b.orientation=o,b.baseline=o===$.HORIZONTAL?p.BOTTOM:p.LEFT;let v=t.parent;v.addChild(b),v.removeChild(t);for(let[e,t]of b.vertices.entries())e>=u.length?t.dataScope=l.merge(u[2*u.length-1-e]):t.dataScope=l.merge(u[e]);t===e&&(i=b)}return i}(t,n,r,i)}}function Se(e,t,r,n){return[r*Math.cos(ue(n))+e,t-r*Math.sin(ue(n))]}class Te extends Y{constructor(e,t,r){super(e),this._channel=t,this._elem=r}get channel(){return this._channel}get element(){return this._elem}}const Oe=Object.freeze({X:"x",Y:"y",WIDTH:"width",HEIGHT:"height",RADIUS:"radius",FILLCOLOR:"fillColor",STROKECOLOR:"strokeColor",FILLGRADIENT:"fillGradient",TEXT:"text",ANGLE:"angle",THICKNESS:"thickness",AREA:"area",FONTSIZE:"fontSize",RADIALDISTANCE:"radialDistance",STROKEWIDTH:"strokeWidth",OPACITY:"opacity",VISIBILITY:"visibility",STRENGTH:"strength"});function Ie(e,t){delete t._encodings[Pe(e.element)][e.channel]}function Ne(e,t){let r=e.scene._encodings[Pe(e)],n=[];if(r&&(n=n.concat(Object.values(r))),t){let t=e.scene;for(let r in t._encodings){let i=r.split("_");i.pop(),i.join("_")===e.classId&&(n=n.concat(Object.values(t._encodings[r])))}}return n}function Le(e,t,r){for(let n in r._encodings){let i=r._encodings[n];if(i[t]&&i[t].attribute==e)return i[t]}return null}function Ve(e,t){let r=e.scene._encodings[Pe(e)];return r&&r[t]?r[t]:null}function Pe(e){if(e.classId)return e.classId;if("vertex"==e.type&&e.dataScope){if(e.parent.type===Tt.Area){let t=e.parent.vertices.indexOf(e)<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.parent.vertices.indexOf(e):"segment"==e.type&&e.dataScope?e.parent.classId+"_s":"segment"==e.type?e.parent.classId+"_s"+e.parent.segments.indexOf(e):null}function De(e,t){if(0==e.children.length)return[];let r=P(e),n=e.type===Tt.Composite?e.children:[e.children[0]],i=Object.keys(r._encodings),s=[];for(let e of n){let t=e;for(;t;){if(t.classId&&s.indexOf(t.classId)<0&&s.push(t.classId),t.type===Tt.Glyph){t.children.forEach((e=>s.push(e.classId)));break}if(!t.children)break;t=t.children[0]}}let a=[];for(let e of i)for(let n of s)0===e.indexOf(n)&&r._encodings[e][t]&&a.push(r._encodings[e][t]);return a}function Be(e){let t=Ve(e,"y"),r=Ve(e,"height");return t||r&&r.scales[0].domain[0]<0}function Me(e){let t=Ve(e,"x"),r=Ve(e,"width");return t||r&&r.scales[0].domain[0]<0}function Ge(e,t){let r=function(e){let t=e.parent,r=[];for(;t.type!==Tt.Scene;)r.push(t),t=t.parent;return r}(e);for(let e of r)if(Ve(e,t))return!1;return r.length>=2?r[r.length-2]:e}function je(e,t,r){switch(e.type){case Tt.Rect:case Tt.Path:case Tt.Line:case Tt.Area:!function(e,t,r){for(let n of e.vertices)ze(n,t,r);e._updateBounds(),e._refBounds&&e._refBounds.translate(t,r)}(e,t,r);break;case Tt.Group:case Tt.Collection:case Tt.Glyph:!function(e,t,r){for(let n of e.children)je(n,t,r);e._layout&&(void 0!==e._layout._left&&(e._layout._left+=t),void 0!==e._layout._top&&(e._layout._top+=r),e._layout._cellBounds&&e._layout._cellBounds.forEach((e=>e.translate(t,r))))}(e,t,r);break;case"segment":!function(e,t,r){ze(e.vertex1,t,r),ze(e.vertex2,t,r)}(e,t,r);break;default:!function(e,t,r){e._x+=t,e._y+=r,e._refBounds&&e._refBounds.translate(t,r)}(e,t,r)}}function ze(e,t,r){e._x+=t,e._y+=r}function Fe(e,t,r){switch(t){case"x":He(e,r);break;case"y":We(e,r);break;case"width":!function(e,t){e.resize(t,e.height)}(e,r);break;case"height":!function(e,t){e.resize(e.width,t)}(e,r);break;case"radius":e.radius=r;break;case"strength":e._strength=r;break;case"area":e.type===Tt.Circle?e.radius=Math.sqrt(r/Math.PI):e.type===Tt.Rect&&e.resize(Math.sqrt(r),Math.sqrt(r)),e._updateBounds();break;case"text":e._text=r;break;case"curveMode":e.curveMode=r;break;case"baseline":e.baseline=r;break;case"angle":[Tt.Arc,Tt.Pie].includes(e.type)&&function(e,t){e._endAngle=he(e._startAngle+t),e._sr=ue(e._startAngle),e._er=ue(e._endAngle),e.vertices[0]._x=e._x+e._innerRadius*Math.cos(e._sr),e.vertices[0]._y=e._y-e._innerRadius*Math.sin(e._sr),e.vertices[1]._x=e._x+e._outerRadius*Math.cos(e._sr),e.vertices[1]._y=e._y-e._outerRadius*Math.sin(e._sr),e.vertices[2]._x=e._x+e._outerRadius*Math.cos(e._er),e.vertices[2]._y=e._y-e._outerRadius*Math.sin(e._er),e.vertices[3]._x=e._x+e._innerRadius*Math.cos(e._er),e.vertices[3]._y=e._y-e._innerRadius*Math.sin(e._er)}(e,r);break;case"startAngle":!function(e,t){let r=e.angle;e._startAngle=t,e._endAngle=he(e._startAngle+r),e._sr=ue(e._startAngle),e._er=ue(e._endAngle),e.vertices[0]._x=e._x+e._innerRadius*Math.cos(e._sr),e.vertices[0]._y=e._y-e._innerRadius*Math.sin(e._sr),e.vertices[1]._x=e._x+e._outerRadius*Math.cos(e._sr),e.vertices[1]._y=e._y-e._outerRadius*Math.sin(e._sr),e.vertices[2]._x=e._x+e._outerRadius*Math.cos(e._er),e.vertices[2]._y=e._y-e._outerRadius*Math.sin(e._er),e.vertices[3]._x=e._x+e._innerRadius*Math.cos(e._er),e.vertices[3]._y=e._y-e._innerRadius*Math.sin(e._er)}(e,r);break;case"thickness":!function(e,t){Ue(e,e._innerRadius+t)}(e,r);break;case"innerRadius":!function(e,t){e._innerRadius=t,e.vertices[0]._x=e._x+e._innerRadius*Math.cos(e._sr),e.vertices[0]._y=e._y-e._innerRadius*Math.sin(e._sr),e.vertices[3]._x=e._x+e._innerRadius*Math.cos(e._er),e.vertices[3]._y=e._y-e._innerRadius*Math.sin(e._er)}(e,r);break;case"outerRadius":Ue(e,r);break;case"radialDistance":{let t=Se(e.parent.x,e.parent.y,r,e.polarAngle);He(e,t[0]),We(e,t[1]);break}case"visibility":e.visibility=r;break;default:if("vertex"===e.type)e[t]=r;else if(e instanceof pt)for(let n of e.children)Fe(n,t,r);else e.styles[t]=r}}function Ue(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 He(e,t){"vertex"==e.type?e._x=t:je(e,t-e.x,0)}function We(e,t){"vertex"==e.type?e._y=t:je(e,0,t-e.y)}class Ye extends ne{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}resize(e,t,r,n){e!==this.width&&("right"===r?(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"===n?(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))}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 Xe extends ne{constructor(e){super(e),this._type=Tt.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 re(this.vertices[this.vertices.length-1],this.vertices[0],this,this.segmentCounter++))}get topLeftVertex(){return this._orientation===$.HORIZONTAL?this.vertices[0]:this.vertices[this.vertices.length-1]}get bottomLeftVertex(){return this._orientation===$.HORIZONTAL?this.vertices[this.vertices.length-1]:this.vertices[this.vertices.length/2]}get topRightVertex(){return this._orientation===$.HORIZONTAL?this.vertices[this.vertices.length/2-1]:this.vertices[0]}get bottomRightVertex(){return this._orientation===$.HORIZONTAL?this.vertices[this.vertices.length/2]:this.vertices[this.vertices.length/2-1]}get baseline(){return this._baseline}set baseline(e){this._baseline=e}get orientation(){return this._orientation}set orientation(e){this._orientation=e}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 qe extends Y{constructor(e,t){super(e),this._encs=[t],this._initialized=!1}addLinkedEncoding(e){this._encs.push(e)}get encodings(){return this._encs}get initialized(){return this._initialized}set initialized(e){this._initialized=e}}class Ke{constructor(e,t){this._event=t,this._type=e}get event(){return this._event}get type(){return this._type}}const Ze=Object.freeze({ELEMENT:"element",MOUSE:"mouse",ATTRIBUTE:"attribute",WIDGET:"widget",KEYBOARD:"keyboard"});Object.freeze({INPUT:"input",HOVER:"hover",BRUSH:"brush",BRUSH_X:"brushX",BRUSH_Y:"brushY",CLICK:"click"});class $e extends H{constructor(e){super(e)}storeValues(e,t){this._storedValues={};let r=S(e);for(let e of r)this._storedValues[e.id]=e[t]}_restoreValues(e){let t=this.outputVar.channel;e.forEach((e=>{e.styles[t]=this._storedValues[e.id]}))}run(){super.run();let e=this.inputVars.find((e=>e instanceof qe)),t=this.outputVar,r=S(t.element);if(e){let r=e.encodings.find((e=>e.channel==t.channel&&Pe(e.element)==Pe(t.element)));for(let e of r.scales){let t=r.getElements(e);this._doMapping(t,e,r.attrValues,r),this._updateRefBounds(t,e,r)}}else this._restoreValues(r);let n=this._getUsableCondEncodings();n.length>0&&this._doCondEncoding(r,n.map((e=>e.condEncoding))),f(["vertex","segment"].includes(t.element.type)?t.element.parent:t.element)}_updateRefBounds(e,t,r){switch(this.outputVar.channel){case"width":e.forEach((e=>{e._refBounds.setWidth(t.rangeExtent)}));break;case"height":e.forEach((e=>{e._refBounds.setHeight(t.rangeExtent)}));break;case"radius":e.forEach((e=>{e._refBounds.setWidth(2*t.rangeExtent,p.CENTER),e._refBounds.setHeight(2*t.rangeExtent,p.MIDDLE)}));break;case"x":"vertex"!=e[0].type&&"segment"!=e[0].type||e.forEach((e=>{let n=e.parent._refBounds;e.parent._refBounds=new u(r.flipScale?t.range[1]:t.range[0],n.top,t.rangeExtent,n.height)}));break;case"y":"vertex"!=e[0].type&&"segment"!=e[0].type||e.forEach((e=>{let n=e.parent._refBounds;e.parent._refBounds=new u(n.left,r.flipScale?t.range[0]:t.range[1],n.width,t.rangeExtent)}))}}_doMapping(e,t,r,n){switch(this.outputVar.channel){case"width":t.domain[0]<0&&e[0]instanceof Ye?function(e,t,r){for(let n=0;n<e.length;n++){let i=e[n],s=i.refBounds.left+t.map(0),a=i.refBounds.left+t.map(r[i.id]);je(i.leftSegment,s-i.leftSegment.x,0),je(i.rightSegment,a-i.rightSegment.x,0)}}(e,t,r):t.domain[0]<0&&e[0]instanceof Xe||(e[0].type===Tt.Area?function(e,t,r){let n=e[0].baseline;if(e[0].orientation===$.VERTICAL)switch(n){case"left":for(let n of e)S(n.topLeftVertex,n).forEach((e=>Fe(e,"x",n.refBounds.left))),S(n.topRightVertex,n).forEach((e=>Fe(e,"x",n.refBounds.left+t.map(r[e.id]))));break;case"right":for(let n of e)S(n.topLeftVertex,n).forEach((e=>Fe(e,"x",n.refBounds.right-t.map(r[e.id])))),S(n.topRightVertex,n).forEach((e=>Fe(e,"x",n.refBounds.right)));break;case"center":console.log("center");for(let n of e)S(n.topLeftVertex,n).forEach((e=>Fe(e,"x",n.refBounds.center-t.map(r[e.id])/2))),S(n.topRightVertex,n).forEach((e=>Fe(e,"x",n.refBounds.center+t.map(r[e.id])/2)))}}(e,t,r):this._doStandardMapping(e,t,r));break;case"height":t.domain[0]<0&&e[0]instanceof Ye?function(e,t,r){for(let n=0;n<e.length;n++){let i=e[n],s=i.refBounds.bottom-t.map(0),a=i.refBounds.bottom-t.map(r[i.id]);je(i.bottomSegment,0,s-i.bottomSegment.y),je(i.topSegment,0,a-i.topSegment.y)}}(e,t,r):t.domain[0]<0&&e[0]instanceof Xe?function(e,t,r){for(let n of e){let e=T(n.topLeftVertex,[n]);for(let i of e)Fe(i,"y",n.refBounds.bottom-t.map(r[i.id]));T(n.bottomLeftVertex,[n]).forEach((e=>Fe(e,"y",n.refBounds.bottom-t.map(0))))}}(e,t,r):e[0].type===Tt.Area?function(e,t,r){let n=e[0].baseline;if(e[0].orientation===$.HORIZONTAL)switch(n){case"bottom":for(let n of e)S(n.topLeftVertex,n).forEach((e=>Fe(e,"y",n.refBounds.bottom-t.map(r[e.id])))),S(n.bottomLeftVertex,n).forEach((e=>Fe(e,"y",n.refBounds.bottom)));break;case"top":for(let n of e)S(n.bottomLeftVertex,n).forEach((e=>Fe(e,"y",n.refBounds.top+t.map(r[e.id])))),S(n.topLeftVertex,n).forEach((e=>Fe(e,"y",n.refBounds.top)));break;case"middle":for(let n of e)S(n.topLeftVertex,n).forEach((e=>Fe(e,"y",n.refBounds.middle-t.map(r[e.id])/2))),S(n.bottomLeftVertex,n).forEach((e=>Fe(e,"y",n.refBounds.middle+t.map(r[e.id])/2)))}}(e,t,r):this._doStandardMapping(e,t,r);break;case"text":this._doTextMapping(e,r);break;case"fillGradient":!function(e,t,r,n){for(let i of e){let e=i.vertices.map((e=>r[e.id])),s=Math.min(...e),a=Math.max(...e),o="horizontal"===i.orientation?new b({x1:0,y1:100,x2:0,y2:0}):new b({x1:0,y1:0,x2:100,y2:0});if(o.addStop(0,t.map(s),1),n._mapping){let e=Object.keys(n._mapping).map((e=>parseFloat(e))).sort();for(let r of e)r>s&&r<a&&o.addStop(100*(r-s)/(a-s),t.map(r),1)}else"divergingColor"===t.type&&o.addStop(100*-s/(a-s),t.map(0),1);"sequentialColor"===t.type&&o.addStop(100*-s/(a-s),t.map(0),1),o.addStop(100,t.map(a),1),i.fillColor=o}}(e,t,r,n);break;default:this._doStandardMapping(e,t,r)}}_doTextMapping(e,t){let r=this.outputVar.channel;e.forEach((e=>{Fe(e,r,t[e.id])}))}_doStandardMapping(e,t,r){let n=this.outputVar.channel;e.forEach((e=>{let i=t.map(r[e.id]);Fe(e,n,i),e instanceof ne&&e.firstVertex&&e.firstVertex.shape&&"strokeColor"===n&&e.vertices.forEach((e=>e.fillColor=i))}))}_doCondEncoding(e,t){for(let r of e){let e=t.map((e=>e.evalResult[r.id])).every((e=>e||void 0===e));t[0]._efxFn(e,t[0].trigger.elements[0],r,t[0].trigger.mouseEvent)}}_updateElement(e,t,r,n){let i;"object"==typeof n&&e.triggerElement?"property"in n?i=e.triggerElement[n.property]:"attribute"in n&&(i=e.triggerElement.dataScope.getAttributeValue(n.attribute)):i=n,["x","y"].includes(r)&&"offset"in n&&(i+=n.offset),Fe(t,r,i)}_getUsableCondEncodings(){return this.inputVars.filter((e=>e instanceof q))}}class Je extends Y{constructor(e,t,r){super(e),this._property=t,this._elem=r}get property(){return this._property}get element(){return this._elem}}const Qe=Object.freeze({AXIS_ORIENTATION:"axisOrientation",AXIS_PATH_POSITION:"axisPathPosition",AXIS_TICK_SIZE:"axisTickSize",AXIS_TICK_OFFSET:"axisTickOffset",AXIS_TICKS_POSITION:"axisTicksPosition",AXIS_LABELS_POSITION:"axisLabelsPosition",AXIS_TITLE_POSITION:"axisTitlePosition",AXIS_LABEL_OFFSET:"axisLabelOffset",AXIS_LABEL_FORMAT:"axisLabelFormat",AXIS_FONT_SIZE:"axisFontSize",LEGEND_POSITION:"legendPosition",GRIDLINES_POSITION:"gridlinesPosition",INCLUDE_ZERO:"includeZero",FLIP_SCALE:"flipScale",RANGE_START:"rangeStart",RANGE_EXTENT:"rangeExtent",BASE_LINE:"baseline"});function et(e,t){let r=t.getVariable(X.BOUNDS,e),n=t.createOneWayDependency(W.EVAL_BBOX);switch(t.connect(n,r),e.type){case Tt.Circle:case Tt.Polygon:{let r=t.getVariable(X.CHANNEL,"x",e),i=t.getVariable(X.CHANNEL,"y",e),s=t.getVariable(X.CHANNEL,"radius",e),a=t.getVariable(X.CHANNEL,"area",e);t.connect(s,n),t.connect(r,n),t.connect(i,n),t.connect(a,n);break}case Tt.Area:case Tt.Line:case Tt.BezierCurve:case Tt.Path:case Tt.Image:{let r=t.getVariable(X.CHANNEL,"x",e),i=t.getVariable(X.CHANNEL,"y",e),s=t.getVariable(X.CHANNEL,"width",e),a=t.getVariable(X.CHANNEL,"height",e);t.connect(r,n),t.connect(i,n),t.connect(s,n),t.connect(a,n);break}case Tt.Rect:{let r=t.getVariable(X.CHANNEL,"x",e),i=t.getVariable(X.CHANNEL,"y",e),s=t.getVariable(X.CHANNEL,"width",e),a=t.getVariable(X.CHANNEL,"height",e),o=t.getVariable(X.CHANNEL,"area",e);t.connect(r,n),t.connect(i,n),t.connect(s,n),t.connect(a,n),t.connect(o,n);break}case Tt.PointText:{let r=t.getVariable(X.CHANNEL,"x",e),i=t.getVariable(X.CHANNEL,"y",e),s=t.getVariable(X.CHANNEL,"text",e);t.connect(r,n),t.connect(i,n),t.connect(s,n);break}case Tt.Ring:{let r=t.getVariable(X.CHANNEL,"x",e),i=t.getVariable(X.CHANNEL,"y",e),s=t.getVariable(X.CHANNEL,"innerRadius",e),a=t.getVariable(X.CHANNEL,"outerRadius",e);t.connect(r,n),t.connect(i,n),t.connect(s,n),t.connect(a,n);break}case Tt.Pie:case Tt.Arc:{let r=t.getVariable(X.CHANNEL,"x",e),i=t.getVariable(X.CHANNEL,"y",e),s=t.getVariable(X.CHANNEL,"innerRadius",e),a=t.getVariable(X.CHANNEL,"outerRadius",e),o=t.getVariable(X.CHANNEL,"startAngle",e),l=t.getVariable(X.CHANNEL,"endAngle",e),u=t.getVariable(X.CHANNEL,"angle",e),c=t.getVariable(X.CHANNEL,"thickness",e);t.connect(r,n),t.connect(i,n),t.connect(s,n),t.connect(a,n),t.connect(o,n),t.connect(l,n),t.connect(u,n),t.connect(c,n);break}}n.run()}function tt(e,t){let r=t.findVariablesByElement(e);for(let e in r){let n=r[e];for(let e of n)t.deleteVariable(e)}}function rt(e,t){let r=t.findVariable(X.CHANNEL,[e.channel,e.element]);r||console.warn("cannot find encoding to remove from the dep graph");let n=r.incomingDataflow;t.deleteOperator(n)}function nt(e,t){if(e.type===Tt.Axis){let r=t.findVariable(X.PROPERTY,[Qe.AXIS_PATH_POSITION,e]).incomingDataflow;t.deleteOperator(r),r=t.findVariable(X.PROPERTY,[Qe.AXIS_TICKS_POSITION,e]).incomingDataflow,t.deleteOperator(r),r=t.findVariable(X.PROPERTY,[Qe.AXIS_LABELS_POSITION,e]).incomingDataflow,t.deleteOperator(r)}else if(e.type===Tt.Gridlines){let r=t.findVariable(X.PROPERTY,[Qe.GRIDLINES_POSITION,e]).incomingDataflow;t.deleteOperator(r)}}function it(e,t){let r=t.getVariable(X.BOUNDS,e),n=t.getVariable(X.CHANNEL,"x",e),i=t.getVariable(X.CHANNEL,"y",e),s=t.getVariable(X.CHANNEL,"width",e),a=t.getVariable(X.CHANNEL,"height",e),o=t.createOneWayDependency(W.EVAL_BBOX);t.connect(n,o),t.connect(i,o),t.connect(s,o),t.connect(a,o),t.connect(o,r),o.run()}function st(e,t,r){let n=r.getVariable(X.BOUNDS,e),i=r.getVariable(X.BOUNDS,t),s=r.getIncomingDataflowOperator(W.EVAL_BBOX,n),a=i.outgoingEdges.find((e=>e.fromNode===i&&e.toNode===s));if(a&&r.disconnect(i,s,a),e.layout){let n=r.getVariable(X.CHANNEL,"x",t),i=r.getIncomingDataflowOperator(ot(e.layout.type),n);i&&r.deleteOperator(i)}}function at(e,t,r){let n=r.getVariable(X.BOUNDS,e),i=r.getVariable(X.BOUNDS,t),s=r.getIncomingDataflowOperator(W.EVAL_BBOX,n);r.connect(i,s),r.connect(s,n),e.layout&&ut(e,e.layout,r)}function ot(e){switch(e){case F.GRID:return W.GRID_LAYOUT;case F.STACK:return W.STACK_LAYOUT;case F.PACKING:return W.PACK_LAYOUT;case F.FORCE:return W.FORCE_LAYOUT;case F.DIRECTED:return W.DIRECTED_LAYOUT;case F.TIDYTREE:return W.TIDY_TREE_LAYOUT;case F.TREEMAP:return W.TREEMAP_LAYOUT;case F.STRATA:return W.STRATA_LAYOUT;case F.CIRCULAR:return W.CIRCULAR_LAYOUT;case F.CLUSTER:return W.CLUSTER_LAYOUT}}function lt(e,t,r){let n=r.getVariable(X.ORDER,e),i=r.getOutgoingDataflowOperator(ot(t.type),n);r.deleteOperator(i)}function ut(e,t,r){let n=t?t.type:"none",i=n===F.TREEMAP?G(e)[0]:e.children[0];if(!i)return;let s=r.getVariable(X.CHANNEL,"width",i),a=r.getVariable(X.CHANNEL,"height",i),o=r.getVariable(X.ORDER,e),l=r.getVariable(X.CHANNEL,"x",i),u=r.getVariable(X.CHANNEL,"y",i),c=r.getOutgoingDataflowOperator(ot(n),o);if(r.connect(s,c),r.connect(a,c),r.connect(o,c),r.connect(c,l),r.connect(c,u),r.disconnectChannelVarFromBBoxOperator(s),r.disconnectChannelVarFromBBoxOperator(a),i.type===Tt.Arc||i.type===Tt.Pie){let e=r.getVariable(X.CHANNEL,"angle",i),t=r.getVariable(X.CHANNEL,"thickness",i);r.connect(e,c),r.connect(t,c)}else if(i.type===Tt.Circle){let e=r.getVariable(X.CHANNEL,"area",i),t=r.getVariable(X.CHANNEL,"radius",i);r.connect(e,c),r.connect(t,c),r.disconnectChannelVarFromBBoxOperator(e),r.disconnectChannelVarFromBBoxOperator(t)}else if(i.type===Tt.Rect){let e=r.getVariable(X.CHANNEL,"area",i);r.connect(e,c),r.disconnectChannelVarFromBBoxOperator(e)}if(c.run(),i.links&&ct(i,r),i.children&&i.children[0]){let e=r.getVariable(X.BOUNDS,i.children[0]),t=r.getVariable(X.CHANNEL,"x",i).incomingDataflow;t&&r.connect(e,t),r.disconnectChannelVarFromBBoxOperator(e)}}function ct(e,t){let r=e.links[0],n=t.getVariable(X.CHANNEL,"x",e),i=t.getVariable(X.CHANNEL,"x",r),s=t.getVariable(X.CHANNEL,"strokeWidth",r),a=t.getVariable(X.CHANNEL,"strength",r),o=t.createOneWayDependency(W.LINK_PLACER);t.connect(n,o),t.connect(s,o),t.connect(a,o),t.connect(o,i)}function ht(e,t){let r=t.getVariable(X.PROPERTY,Qe.AXIS_ORIENTATION,e),n=t.getVariable(X.BOUNDS,e.elements[0].parent),i=t.getVariable(X.PROPERTY,Qe.AXIS_PATH_POSITION,e),s=t.createOneWayDependency(W.AXIS_PATH_PLACER);t.connect(r,s),t.connect(n,s),t.connect(s,i),s.run();let a=t.getVariable(X.PROPERTY,Qe.AXIS_TICK_OFFSET,e),o=t.getVariable(X.PROPERTY,Qe.AXIS_TICK_SIZE,e),l=t.createOneWayDependency(W.AXIS_TICKS_PLACER),u=t.getVariable(X.PROPERTY,Qe.AXIS_TICKS_POSITION,e);t.connect(i,l),t.connect(a,l),t.connect(o,l),t.connect(l,u),l.run();let c=t.getVariable(X.PROPERTY,Qe.AXIS_LABEL_OFFSET,e),h=t.getVariable(X.PROPERTY,Qe.AXIS_LABEL_FORMAT,e),d=t.getVariable(X.PROPERTY,Qe.AXIS_FONT_SIZE,e),f=t.createOneWayDependency(W.AXIS_LABELS_PLACER),p=t.getVariable(X.PROPERTY,Qe.AXIS_LABELS_POSITION,e);t.connect(i,f),t.connect(c,f),t.connect(h,f),t.connect(d,f),t.connect(f,p),f.run();let _=t.getVariable(X.PROPERTY,Qe.AXIS_TITLE_POSITION,e),g=t.createOneWayDependency(W.AXIS_TITLE_PLACER);t.connect(i,g),t.connect(g,_),g.run();let y=t.getVariable(X.BOUNDS,e),m=t.getIncomingDataflowOperator(W.EVAL_BBOX,y);t.connect(u,m),t.connect(p,m),t.connect(m,y)}function dt(e,t){let r=t.getVariable(X.PROPERTY,Qe.AXIS_ORIENTATION,e),n=t.getVariable(X.BOUNDS,D(e.elements[0])),i=t.getVariable(X.PROPERTY,Qe.AXIS_PATH_POSITION,e),s=t.createOneWayDependency(W.AXIS_PATH_PLACER);t.connect(r,s),t.connect(n,s),t.connect(s,i),s.run();let a=t.getVariable(X.PROPERTY,Qe.AXIS_TICK_OFFSET,e),o=t.getVariable(X.PROPERTY,Qe.AXIS_TICK_SIZE,e),l=t.createOneWayDependency(W.AXIS_TICKS_PLACER),u=t.getVariable(X.PROPERTY,Qe.AXIS_TICKS_POSITION,e);t.connect(i,l),t.connect(a,l),t.connect(o,l),t.connect(l,u),l.run();let c=t.getVariable(X.PROPERTY,Qe.AXIS_LABEL_OFFSET,e),h=t.getVariable(X.PROPERTY,Qe.AXIS_LABEL_FORMAT,e),d=t.getVariable(X.PROPERTY,Qe.AXIS_FONT_SIZE,e),f=t.createOneWayDependency(W.AXIS_LABELS_PLACER),p=t.getVariable(X.PROPERTY,Qe.AXIS_LABELS_POSITION,e);t.connect(i,f),t.connect(c,f),t.connect(h,f),t.connect(d,f),t.connect(f,p),f.run();let _=t.getVariable(X.PROPERTY,Qe.AXIS_TITLE_POSITION,e),g=t.createOneWayDependency(W.AXIS_TITLE_PLACER);t.connect(i,g),t.connect(g,_),g.run();let y=t.getVariable(X.BOUNDS,e),m=t.getIncomingDataflowOperator(W.EVAL_BBOX,y);t.connect(u,m),t.connect(p,m),t.connect(m,y)}function ft(e,t){let r=t.getVariable(X.BOUNDS,D(e.elements[0])),n=t.getVariable(X.PROPERTY,Qe.GRIDLINES_POSITION,e),i=t.createOneWayDependency(W.GRIDLINES_PLACER);t.connect(r,i),t.connect(i,n),i.run();let s=t.getVariable(X.BOUNDS,e),a=t.getIncomingDataflowOperator(W.EVAL_BBOX,s);t.connect(n,a),t.connect(a,s)}class pt{constructor(){this._id=this.type+It(),this._type=Tt.Group,this._dataScope=void 0,this._bounds=void 0,this._layout=void 0,this._children=[],this._sortBy={}}get id(){return this._id}get type(){return this._type}contains(e,t){return this.bounds.contains(e,t)}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._dataScope}set dataScope(e){if(this._dataScope=e,void 0===e)for(let t of this.children)t.dataScope=e;else for(let t of this.children)t.dataScope?t.dataScope=t.dataScope.merge(e):t.dataScope=e}getInternalEncodings(e){if(0==this.children.length)return[];let t=this.children[0],r=this.getScene(),n=Object.keys(r.encodings),i=[];for(;t;){if(t.classId&&i.indexOf(t.classId)<0&&i.push(t.classId),t.type===Tt.Glyph){t.children.forEach((e=>i.push(e.classId)));break}if(!t.children)break;t=t.children[0]}let s=[];for(let t of n){let n=t.split("_");for(let a of i)n[0]==a&&r.encodings[t][e]&&s.push(r.encodings[t][e])}return s}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),ut(this,e,this.scene._depGraph),this.children&&this.children.length>0){let e=G(this,!0);for(let t of e)this.scene.onChange(X.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=Math.min(...e.map((e=>e.left))),r=Math.min(...e.map((e=>e.top))),n=Math.max(...e.map((e=>e.right))),i=Math.max(...e.map((e=>e.bottom)));return new u(t,r,n-t,i-r)}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 u(0,0,0,0)}set visibility(e){this._visibility="hidden"==e?e:"visible";for(let t of this.children)t.visibility=e}get visibility(){return this._visibility?this._visibility:"visible"}get scene(){return P(this)}}class _t extends pt{constructor(){super(),this._type=Tt.Collection,this._id=this.type+"_"+It(),this._classId=this.id,this._childrenOrder=void 0}get classId(){return this._classId}contains(e,r){if([Tt.Arc,Tt.Pie,Tt.Polygon,Tt.Area].indexOf(this.firstChild.type)>=0){let n=this.getSVGPathData();if(""!==n){let i=t.getContext(),s=new Path2D(n);return i.lineWidth=Math.max(this.strokeWidth,2.5),i.stroke(s),i.isPointInPath(s,e,r)}}return this._bounds.contains(e,r)}getSVGPathData(){let e="";for(let t of this.children)if(t.getSVGPathData)e+=t.getSVGPathData();else if(t.bounds){let r=t.bounds;e+=["M",r.left,r.top].join(" "),e+=["L",r.right,r.top].join(" "),e+=["L",r.right,r.bottom].join(" "),e+=["L",r.left,r.bottom,"Z"].join(" ")}return e}}class gt extends pt{constructor(e){if(super(),this._type=Tt.Glyph,this._id=this.type+"_"+It(),this._classId=this._id,e)for(let t of e)this.addChild(t)}get classId(){return this._classId}}class yt extends ne{constructor(e){super(e),this._type=Tt.BezierCurve,this._orientation="orientation"in e?e.orientation:$.HORIZONTAL}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 mt extends v{constructor(e){super(e),this._type=Tt.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")}get x(){return this._x}get y(){return this._y}get radius(){return this._radius}set radius(e){this._radius=e}get area(){return Math.PI*Math.pow(this._radius,2)}_updateBounds(){if(this._rotate){let e=C(this._x,this._y,this._rotate[1],this._rotate[2],this._rotate[0]);this._bounds=new u(e.x-this._radius,e.y-this._radius,2*this._radius,2*this._radius)}else this._bounds=new u(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 bt extends v{constructor(e){super(e),this._type=Tt.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}get width(){return this._width}set width(e){this._width=e,this._updateBounds()}get height(){return this._height}set height(e){this._height=e,this._updateBounds()}get x(){return this._x}set x(e){this._x=e,this._updateBounds()}get y(){return this._y}set y(e){this._y=e,this._updateBounds()}get bounds(){return this._bounds||this._updateBounds(),this._bounds}_updateBounds(){this._bounds=new u(this._x,this._y,this._width,this._height)}copyPropertiesTo(e){e.attrs=Object.assign({},this.attrs),e.styles=Object.assign({},this.styles),this._dataScope&&(e._dataScope=this._dataScope.clone()),e.x=this._x,e.y=this._y,e.width=this._width,e.height=this._height,e.src=this._src}}class vt extends ne{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}set y(e){let t=e-this.y;this.vertices[0]._y+=t,this.vertices[1]._y+=t}set x1(e){this.vertices[0]._x=e}set x2(e){this.vertices[1]._x=e}set y1(e){this.vertices[0]._y=e}set y2(e){this.vertices[1]._y=e}}class xt extends v{constructor(e){super(e),this._type=Tt.PointText,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:[p.CENTER,p.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,r=function(e,t,r){let n=k.getContext();n.font=t;let i=n.measureText(e);return i.fontBoundingBoxAscent?{width:i.width,height:i.fontBoundingBoxAscent+i.fontBoundingBoxDescent}:i.actualBoundingBoxAscent?{width:i.width,height:i.actualBoundingBoxAscent+i.actualBoundingBoxDescent}:{width:i.width,height:r}}(this._text,[this.fontWeight,this.fontSize,this.fontFamily].join(" "),parseFloat(this.fontSize)),n=r.width,i=r.height;switch(this._anchor[0]){case p.LEFT:e=this._x;break;case p.RIGHT:e=this._x-n;break;case p.CENTER:e=this._x-n/2;break;default:e=this._x}switch(this._anchor[1]){case p.TOP:t=this._y;break;case p.BOTTOM:t=this._y-i;break;case p.MIDDLE:default:t=this._y-i/2}if(this._rotate&&3===this._rotate.length){let r=[{x:e,y:t},{x:e+n,y:t},{x:e,y:t+i},{x:e+n,y:t+i}].map((e=>C(e.x,e.y,this._rotate[1],this._rotate[2],this._rotate[0]))),s=Math.min(...r.map((e=>e.x))),a=Math.max(...r.map((e=>e.x))),o=Math.min(...r.map((e=>e.y))),l=Math.max(...r.map((e=>e.y)));this._bounds=new u(s,o,a-s,l-o)}else this._bounds=new u(e,t,n,i)}get x(){return this._x}get y(){return this._y}get text(){return this._text}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}get textPathOffset(){return this._textPathOffset}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._dataScope&&(e._dataScope=this._dataScope.clone()),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 Et extends ne{constructor(e){super(e),this._type=Tt.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}copyPropertiesTo(e){super.copyPropertiesTo(e),e._x=this._x,e._y=this._y,e._radius=this._radius}}class wt extends ne{constructor(e){super(e),this._type=Tt.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(" ")}}function At(e){let t=null;switch(e.type){case Tt.Circle:t=new mt(e);break;case Tt.Line:var r="x1"in e?e.x1:0,n="y1"in e?e.y1:0,i="x2"in e?e.x2:100,s="y2"in e?e.y2:100;e.vertices=[[r,n],[i,s]],t=new vt(e);break;case Tt.Rect:var a="top"in e?e.top:0,o="left"in e?e.left:0,l="width"in e?e.width:50,u="height"in e?e.height:30;e.vertices=[[o,a],[o+l,a],[o+l,a+u],[o,a+u]],t=new Ye(e);break;case Tt.PointText:t=new xt(e);break;case Tt.Image:t=new bt(e);break;case Tt.BundledPath:case Tt.Chord:case Tt.Path:t=new ne(e);break;case Tt.Area:t=new Xe(e);break;case Tt.Ring:t=new wt(e);break;case Tt.Arc:t=new le(e);break;case Tt.BezierCurve:"vertices"in e||(e.vertices=[[0,100],[20,120],[80,180],[100,200]]),t=new yt(e);break;case Tt.Polygon:t=new Et(e)}return t&&t._updateBounds(),t}function Ct(e){let t=new _t;return e.addChild(t),e._itemMap[t.id]=t,t}function Rt(e){return new gt(e)}function kt(e){switch(e.type){case Tt.Collection:return function(e){let t=Ct(e.scene);for(let r=0;r<e.children.length;r++){let n=e.children[r];t.addChild(kt(n))}if(t._classId=e.classId,e._layout){let r=e._layout.clone();t._layout=r,r.group=t}return t._updateBounds(),t}(e);case Tt.Glyph:return function(e){let t=new gt;for(let r of e.children)t.addChild(kt(r));t._classId=e.classId,e._dataScope&&(t.dataScope=e._dataScope.clone());return t}(e);default:return function(e){let t=At({type:e.type});e.copyPropertiesTo(t),t._classId=e.classId,t._bounds=e.bounds.clone(),e._refBounds||(e._refBounds=e.bounds.clone());t._refBounds=e._refBounds.clone(),e.dataScope&&(t._dataScope=e.dataScope.clone());if(e.vertices)for(let r=0;r<e.vertices.length;r++)e.vertices[r].dataScope&&(t.vertices[r]._dataScope=e.vertices[r].dataScope.clone());return t}(e)}}const St=Object.freeze({Rect:"rect",Circle:"circle",Line:"line",Ring:"ring",Path:"path",Image:"image",PointText:"text",Arc:"arc",BezierCurve:"bezierCurve",BundledPath:"bundledPath",Chord:"chord"}),Tt=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",PointText:"text",Collection:"collection",Group:"group",Composite:"composite",Scene:"scene",Axis:"axis",Glyph:"glyph",Legend:"legend",Polygon:"polygon",Gridlines:"gridlines",LinearGradient:"LinearGradient",Link:"link",DataTable:"datatable",Layout:"layout",NetworkData:"networkdata",TreeData:"treedata"}),Ot=Object.freeze({Axis:"axis",Legend:"legend",Gridlines:"gridlines"});function It(){return Date.now().toString(36)+"_"+Math.random().toString(36).slice(2)}class Nt{constructor(e,t,r){this._id=Tt.DataTable+It(),this.initialize(e,t,r)}initialize(e,t,r){if(this.url=t,this._rawData=JSON.parse(JSON.stringify(e)),this._data=e,this._dateMap=new Map,this._attributes=0===this._data.length?[]:Object.keys(this._data[0]),this._newAttribute=0,r)this._attrTypes=r;else{this._attrTypes={};for(let e of this._attributes)this._attrTypes[e]=Ae(this.data.map((t=>t[e]))),"year"==e.toLowerCase()&&this._attrTypes[e]==we.Integer&&(this._attrTypes[e]=we.Date)}this._validate(this.data,this._attrTypes),this._attrSummaries={};for(let e of this._attributes)this._attrSummaries[e]=Re(this.data.map((t=>t[e])),this._attrTypes[e]);this._attributes.indexOf(Vt)<0&&this._addAttribute(Vt,we.String,this.data.map(((e,t)=>"r"+t)))}clone(){let e=[];for(let t of this._data)e.push(Object.assign({},t));let t=new Nt(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("/"),r=e.substring(t);0!==r.indexOf("\\")&&0!==r.indexOf("/")||(r=r.substring(1));return r}(this.url):this.id}get data(){return this._data}getEncodableAttributes(e){switch(e){case"x":case"y":case"width":case"height":case"radius":case"fillColor":case"strokeColor":case"text":return this.numericAttributes.concat(this.nonNumericAttributes);default:return this.numericAttributes}}_addAttribute(e,t,r){this._data.forEach(((t,n)=>t[e]=r[n])),e!==Vt&&this._rawData.forEach(((t,n)=>t[e]=r[n])),this._attrTypes[e]=t,this._attributes.push(e),this._attrSummaries[e]=Re(r,t)}getAttributeType(e){return this._attrTypes[e]}get attributes(){return this._attributes}getAttributeSummary(e){return this._attrSummaries[e]}getAttributeValues(e){return this.data.map((t=>t[e]))}getUniqueAttributeValues(e){return this._attrSummaries[e].unique}orderAttributeValues(e,t){this._attrSummaries[e].unique=t}getRowCount(){return this.data.length}hasAttribute(e){return this._attributes.indexOf(e)>=0}parseAttributeAsDate(t,r){let n=e.timeParse(r);for(let e of this.data){let r=e[t];null==r||null==r?(r="",e[t]=new Date(1899,11,31).getTime()):e[t]=n(r).getTime(),this._dateMap.set(e[t],r)}this._attrTypes[t]=we.Date,this._attrSummaries[t]=Re(this.data.map((e=>e[t])),we.Date)}getRawValue(e,t){return this.getAttributeType(e)===we.Date?this._dateMap.get(t).toString():t}get nonNumericAttributes(){let e=[];for(let t in this._attrTypes)this._attrTypes[t]!=we.Number&&this._attrTypes[t]!=we.Integer&&t!=Nt.RowID&&e.push(t);return e.sort(((e,t)=>this.getUniqueAttributeValues(e).length-this.getUniqueAttributeValues(t).length)),e}get numericAttributes(){let e=[];for(let t in this._attrTypes)this._attrTypes[t]!==we.Number&&this._attrTypes[t]!==we.Integer||t==Nt.RowID||e.push(t);return e}getAttributesByType(e){let t=[];for(let r in this._attrTypes)this._attrTypes[r]===e&&r!=Nt.RowID&&t.push(r);return t}summarize(){for(let e of this._attributes)this._attrSummaries[e]=Re(this.data.map((t=>t[e])),this._attrTypes[e])}_validate(e,t){for(let r of e)for(let e in t){let n,i=t[e],s=r[e];if(null==r[e]||null==r[e])switch(i){case we.Boolean:n=!1;break;case we.Date:n=new Date(1899,11,31).getTime();break;case we.String:n="";break;default:n=0}else switch(i){case we.Boolean:n=s;break;case we.Date:n=Number.isInteger(s)?new Date(s,0).getTime():new Date(s+"").getTime(),this._dateMap.set(n,s);break;case we.String:n=s.toString();break;default:n=s}r[e]=n}}}function Lt(e){let t=pe(e);if(t)return t.dataTable}const Vt="mascot_rowId";function Pt(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 Dt extends Y{constructor(e,t){super(e),this._elem=t}get element(){return this._elem}}class Bt extends Y{constructor(e,t){super(e),this._item=t}get element(){return this._item}}class Mt{constructor(e){this._id=e+"_"+It(),this._type=e,this._vars=[],this._edges=[]}get vars(){return this._vars}get edges(){return this._edges}run(){console.log("-",this._type)}}class Gt{constructor(e,t,r=!0){this._id="e_"+It(),this._fromNode=e,this._toNode=t,this._isDirected=r}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 H||this._fromNode instanceof Mt?this._fromNode:this._toNode}}class jt extends Y{constructor(e,t,r){super(e),this._attribute=t,this._dataset=r}get attribute(){return this._attribute}get dataset(){return this._dataset}}class zt extends Y{constructor(e,t){super(e),this._encs=[t]}addLinkedEncoding(e){this._encs.push(e)}get encodings(){return this._encs}}class Ft extends H{constructor(e){super(e)}run(){super.run();let e=this.outputVar,t=e.encodings[0],r=this.inputVars.find((e=>e instanceof jt)).attribute,n=e.encodings[0].dataTable.getAttributeType(e.encodings[0].attribute),i=[];for(let t of e.encodings){let e=this._computeAttrValues(t,n);i=i.concat(e)}if("angle"===t.channel&&[Tt.Arc,Tt.Pie].indexOf(t.element.type)>=0)for(let n of e.encodings)for(let e of n.scales){let i=n.getElements(e).map((e=>n.attrValues[e.id]));e.domain=t._preferredDomain?t._preferredDomain:n.dataTable.tree?[0,n.dataTable.tree.getRoot()[r]]:this._getDomainForNumbers(i),console.log("domain for",r,e.domain)}else{let s;s=n==we.String||"text"===e.encodings[0].channel?this._getDomainForStrings(i):this._getDomainForNumbers(i);for(let r of e.encodings)for(let e of r.scales)e.domain=t._preferredDomain?t._preferredDomain:s.slice();console.log("domain for",r,s)}}_getDomainForNumbers(e){let t=this.outputVar.encodings[0],r=[Math.min(...e),Math.max(...e)];if(t.includeZero&&r[0]>0&&(r=[0,Math.max(...e)]),t.mapping)r=Object.keys(t.mapping),r=r.map((e=>parseFloat(e))),r.sort(((e,t)=>e-t));else if("sequentialColor"===t.scales[0].type){if(r[0]<0&&r[1]>0){let e=Math.max(Math.abs(r[0]),Math.abs(r[1]));r=[-e,e]}}else if("angle"===t.channel){r=[0,Object.values(e).reduce(((e,t)=>e+t),0)]}return r}_getDomainForStrings(e){let t,r=this.outputVar,n=r.encodings[0];return t="count"==r.encodings[0].aggregator?[0,Math.max(...e)]:Array.from(new Set(e)),n.mapping&&(t=Object.keys(n.mapping)),t}_computeAttrValues(e,t){let r=S(e.element),n={};if(e.element.type===Tt.Area&&["width","height","fillGradient"].indexOf(e.channel)>=0)for(let t of r)for(let r of t.vertices)n[r.id]=pe(r).aggregateNumericalAttribute(e.attribute,e.aggregator);else switch(t){case we.Boolean:break;case we.Date:for(let t of r)n[t.id]=pe(t).getAttributeValue(e.attribute);break;case we.String:try{if("count"==e.aggregator)for(let t of r)n[t.id]=pe(t).getAttributeValues(e.attribute).length;else for(let t of r)n[t.id]=pe(t).getAttributeValue(e.attribute)}catch(t){throw new Error("Cannot bind "+this.channel+" to "+e.attribute+" : "+t)}break;default:if(e.attribute.startsWith("parent.")||e.attribute.startsWith("child.")){let t=e.dataTable.tree.nodeTable,i=e.attribute.split(".")[0],s=e.attribute.split(".")[1];for(let e of r){let r=pe(e).getAttributeValue(i);n[e.id]=new fe(t).cross(xe,r).getAttributeValue(s)}}else for(let t of r)n[t.id]=pe(t).aggregateNumericalAttribute(e.attribute,e.aggregator)}return e.attrValues=n,Object.values(n)}}class Ut{constructor(t,r){switch(this._id="scale_"+It(),this._type=t,r&&(this._args=r),t){case"linear":this._scale=e.scaleLinear();break;case"point":this._scale=e.scalePoint();break;case"ordinal":this._scale=e.scaleOrdinal();break;case"ordinalColor":this._scale=e.scaleOrdinal(e[r.scheme]);break;case"power":this._scale=e.scalePow().exponent(2);break;case"sqrt":this._scale=e.scalePow().exponent(.5);break;case"log":this._scale=e.scaleLog();break;case"identity":case"time":this._scale=e.scaleTime();break;case"sequentialColor":r.scheme?this._scale=e.scaleSequential(e[r.scheme]):this._scale=e.scaleSequential()}}get id(){return this._id}get domain(){return this._scale.domain()}set domain(e){this._scale.domain(e)}get range(){return this._scale.range()}set range(e){this._scale.range(e)}get rangeExtent(){let e=this._scale.range();return Math.abs(e[1]-e[0])}set rangeExtent(e){let t=this._scale.range();t[0]<t[1]?this._scale.range([t[0],t[0]+e]):this._scale.range([t[1]+e,t[1]])}get type(){return this._type}map(e){return this._scale(e)}}const Ht=["schemeBrBG","schemePRGn","schemePiYG","schemePuOr","schemeRdBu","schemeRdGy","schemeRdYlBu","schemeRdYlGn","schemeSpectral"],Wt=["schemeBlues","schemeGreens","schemeGreys","schemeOranges","schemePurples","schemeReds","schemeBuGn","schemeBuPu","schemeGnBu","schemeOrRd","schemePuBuGn","schemePuBu","schemePuRd","schemeRdPu","schemeYlGnBu","schemeYlGn","schemeYlOrBr","schemeYlOrRd"];class Yt extends H{constructor(e){super(e)}run(){super.run();let e=this.outputVar,t=e.encodings,r=t[0],n=r.channel;for(let i=0;i<r.scales.length;i++){let s=r.scales[i],a=r.getElements(s),o=this._buildRange(n,a,r,e);if(o)for(let e of t)e.scales[i].range=o;console.log("range",r.scales[i].range)}e.initialized=!0}_buildRange(e,t,r,n){return"x"===e?this._buildXRange(t,r,n):"y"===e?this._buildYRange(t,r,n):["width","height","radius","area","fontSize","radialDistance","strokeWidth"].includes(e)?this._buildSizeRange(t,r,n):e.indexOf("Color")>0||"fillGradient"===e?this._buildColorRange(t,r):"angle"===e?this._buildAngleRange(t,r):"thickness"===e?this._buildThicknessRange(t,r,n):void 0}_buildThicknessRange(e,t,r){let n=e.map((e=>e.outerRadius-e.innerRadius));return[0,r.initialized?t.getRangeExtent(e[0]):t._preferredRangeExtent?t._preferredRangeExtent:Math.max(...n)]}_buildAngleRange(e,t){return[0,360]}_buildColorRange(t,r){if(r.mapping){return r.scales[0].domain.map((e=>r.mapping[e+""]))}if("sequentialColor"===r.scales[0].type){let t=this.outputVar,n=r.scales[0].domain;for(let i of t.encodings)if(!r.colorScheme)for(let t of i.scales){let r=t.domain;t._scale=e.scaleSequential(n[0]<0&&n[1]>0?e.interpolatePuOr:e.interpolateTurbo),t._scale.domain(r)}}if((Ht.indexOf(r.colorScheme)>=0||Wt.indexOf(r.colorScheme)>=0)&&"ordinalColor"===r.scales[0].type){let t=this.outputVar,n=r.scales[0].domain;for(let i of t.encodings)for(let t of i.scales){let i=t.domain;t._scale=e.scaleOrdinal(e[r.colorScheme][n.length]),t._scale.domain(i)}}}_buildSizeRange(e,t,r){let n,i;return n=0,i=r.initialized?t.getRangeExtent(e[0]):t._preferredRangeExtent?t._preferredRangeExtent:Math.max(...e.map((e=>"radius"===t.channel?e.refBounds.width/2:"strokeWidth"===t.channel?e.strokeWidth:"radialDistance"===t.channel?e.parent.radius:"area"===t.channel?e.type===Tt.Circle?Math.PI*Math.pow(e.radius,2):e.width*e.height:"fontSize"===t.channel?parseFloat(e.fontSize):e.refBounds[t.channel]))),[0,0+i]}_buildXRange(e,t,r){let n,i;switch(t.scales[0].type,e[0].type){case"vertex":case"segment":var s=e[0].parent.refBounds?e[0].parent.refBounds:e[0].parent.bounds;n=r.initialized?t.getRangeStart(e[0]):s.left,i=r.initialized?t.getRangeExtent(e[0]):t._preferredRangeExtent?t._preferredRangeExtent:s.width;break;default:n=r.initialized?t.getRangeStart(e[0]):D(e[0]).bounds.left+e[0].bounds.width/2,i=r.initialized?t.getRangeExtent(e[0]):t._preferredRangeExtent?t._preferredRangeExtent:450}return t.flipScale?[n+i,n]:[n,n+i]}_buildYRange(e,t,r){let n,i;switch(t.scales[0].type,e[0].type){case"vertex":case"segment":var s=e[0].parent.refBounds?e[0].parent.refBounds:e[0].parent.bounds;n=r.initialized?t.getRangeStart(e[0]):s.top,i=r.initialized?t.getRangeExtent(e[0]):t._preferredRangeExtent?t._preferredRangeExtent:s.height;break;default:n=r.initialized?t.getRangeStart(e[0]):D(e[0]).bounds.top+e[0].bounds.height/2,i=r.initialized?t.getRangeExtent(e[0]):t._preferredRangeExtent?t._preferredRangeExtent:450}return t.flipScale?[n,n+i]:[n+i,n]}}class Xt extends H{constructor(e){super(e)}run(){super.run()}}class qt extends pt{constructor(e){super(),this._type=Tt.Axis,this._id=this._type+It(),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._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 pt,this._ticks._id=this._id+"_ticks",this.addChild(this._ticks),this._labels=new pt,this._labels._id=this._id+"_labels",this.addChild(this._labels),this._title=new xt({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}get pathPos(){return this._pathPos}get attribute(){return this._attribute}get channel(){return this._channel}get orientation(){return this._orientation}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 tickValues(){return this._tickValues}get labelValues(){return this._labelValues}get titleOffset(){return this._titleOffset}get boundsWithoutTitle(){let e=this.children.filter((e=>e.type!==Tt.PointText)),t=e[0].bounds.clone();for(let r=1;r<e.length;r++)"hidden"!=e[r].visibility&&(t=t.union(e[r].bounds));return t}}const Kt="top",Zt="bottom",$t="left";function Jt(t,r,n,i){let s,a=t.domain,o=t.range;switch(t.type){case"linear":case"log":{let l=Math.abs(o[0]-o[1]);s="width"==r||"x"==r?45:30;let u,c=Math.max(2,Math.floor(l/s));if("width"==r||"height"==r){let e=!!i&&(i.elements[0].parent.layout&&i.elements[0].parent.layout.type==F.STACK);a[1]=t._scale.invert(e?d(n)[r]:h(n)[r])}if("log"===t.type){u=[];let e=t._scale.ticks();for(let t of e){let r=Math.log(t)/Math.log(10)+1e-6;Math.abs(r-Math.floor(r))<c/e.length&&u.push(t)}}else u=e.ticks(a[0],a[1],c);return u}case"point":{s="width"==r||"x"==r?80:30;let e=Math.floor(t.rangeExtent/a.length),n=Math.ceil(s/e);return"x"==r?a.filter(((e,t)=>t%n==0)):a}case"time":{s="width"==r||"x"==r?80:30;let t,n,i=Math.floor((o[1]-o[0])/s),l=Math.ceil((a[1]-a[0])/i)/1e3,u=[1,60,3600,86400,2628003,31536e3],c=[e.timeSeconds,e.timeMinutes,e.timeHours,e.timeDays,e.timeMonths,e.timeYears];for(let e=0;e<u.length-1;e++)if(l>=u[e]&&l<u[e+1])return t=Math.floor(l/u[e]),n=c[e],n(a[0],a[1],t);return l>u[u.length-1]?(t=Math.floor(l/u[u.length-1]),n=c[u.length-1],n(a[0],a[1],t)):[]}default:return[]}}function Qt(e,t){t.removeChild(e)}class er extends qt{constructor(e,t,r,n){super(n),this._encoding=e,this._attribute=this._encoding.attribute,this._channel=this._encoding.channel,this._scale=t,this._elems=r,this._flip="flip"in n&&n.flip,this._posArg="x"==this._channel||"width"==this._channel?n.pathY:n.pathX,this._orientation="orientation"in n?n.orientation:"x"===this._channel||"width"==this._channel?Zt:$t,this._titleText="title"in n?n.title:this._encoding.attribute,this._path="angle"===this._channel?new mt({strokeColor:this._strokeColor,id:this._id+"_path"}):new ne({strokeColor:this._strokeColor,id:this._id+"_path"}),this._pathVisible||(this._path.visibility="hidden"),this.addChild(this._path),this.createTicksLabels(n),e.dataTable.getAttributeType(this._attribute)!==we.Date||"labelFormat"in n||(this._labelFormat="%m/%d/%y"),"radialDistance"===this._channel&&"rotation"in n&&(this._rotate=[-n.rotation,this._elems[0].parent.x,this._elems[0].parent.y])}isFlipped(){return this._flip}get elements(){return this._elems}get scale(){return this._scale}createTicksLabels(t){"tickValues"in t?(this._tickValues=t.tickValues,this._labelValues=t.tickValues):(this._tickValues=Jt(this._scale,this._channel,this._elems,this),this._labelValues=this._tickValues),this._ticks.removeAll();for(let e=0;e<this._tickValues.length;e++){let t=new ne({strokeColor:this._strokeColor,id:this._id+"_tick"+e});this._tickVisible||(t.visibility="hidden"),this._ticks.addChild(t)}let r;switch(this._labels.removeAll(),this._encoding.dataTable.getAttributeType(this._attribute)){case we.Date:r=e.timeFormat(this._labelFormat);break;case we.String:r=function(e){return e};break;default:r=e.format(this._labelFormat)}for(let[e,t]of this._labelValues.entries()){let n=new xt({text:r(t),fontSize:this._fontSize,fillColor:this._textColor,id:this._id+"_label"+e});this._labels.addChild(n)}this._title._text=this._titleText}}class tr extends qt{constructor(e,t,r,n){super(n),this._elems=e,this._attribute=r,this._channel=t,this._posArg="x"==this._channel||"width"==this._channel?n.pathY:n.pathX,this._labelAttribute=n.labelAttribute,this._orientation="orientation"in n?n.orientation:"x"===this._channel||"width"==this._channel?Zt:$t,this._titleText="title"in n?n.title:this._attribute,this._path="angle"===this._channel?new mt({strokeColor:this._strokeColor,id:this._id+"_path"}):new ne({strokeColor:this._strokeColor,id:this._id+"_path"}),this._pathVisible||(this._path.visibility="hidden"),this.addChild(this._path),this.createTicksLabels(n),this._elems[0].dataScope.dataTable.getAttributeType(this._attribute)!==we.Date||"labelFormat"in n||(this._labelFormat="%m/%d/%y")}get elements(){if(this.layout.type===F.CLUSTER){const e=new Map(this._elems.map((e=>[e.dataScope.getAttributeValue(xe),e])));return this.layout._d3Root.leaves().map((t=>e.get(t.data[xe])))}return this._elems}get layout(){return this._elems[0].parent.layout}createTicksLabels(t){"tickValues"in t?(this._tickValues=t.tickValues,this._labelValues=t.tickValues):(this._tickValues=this.elements.map((e=>e.dataScope.getAttributeValue(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 ne({strokeColor:this._strokeColor,id:this._id+"_tick"+e});this._tickVisible||(t.visibility="hidden"),this._ticks.addChild(t)}let r;switch(this._labels.removeAll(),this._elems[0].dataScope.dataTable.getAttributeType(this._labelAttribute?this._labelAttribute:this._attribute)){case we.Date:r=e.timeFormat(this._labelFormat);break;case we.String:r=function(e){return e};break;default:r=e.format(this._labelFormat)}for(let[e,t]of this._labelValues.entries()){let n=new xt({text:r(t),fontSize:this._fontSize,fillColor:this._textColor,id:this._id+"_label"+e});this._labels.addChild(n)}this._title._text=this._titleText}}class rr extends H{constructor(e){super(e)}run(){let e=this.inputVars.find((e=>e instanceof Je&&e.property==Qe.AXIS_ORIENTATION)).element;e instanceof er?this._runForEncoding(e):e instanceof tr&&this._runForLayout(e),f(e._path)}_runForLayout(e){let t=e.channel,r=e.elements[0].parent.layout&&e.elements[0].parent.layout.type==F.STACK?d(e.elements):h(e.elements),n=[];if("x"===t){let t=e.orientation===Kt?r.top-2:r.bottom+2;e._pathPos=e._posArg?e._posArg:t,n.push([r.left,e._pathPos]),n.push([r.right,e._pathPos]),e._path._setVertices(n)}else if("y"===t){let t=e.orientation===$t?r.left-2:r.right+2;e._pathPos=e._posArg?e._posArg:t,n.push([e._pathPos,r.top]),n.push([e._pathPos,r.bottom]),e._path._setVertices(n)}else if("angle"===t){let t=e.elements[0].parent.layout;t.type===F.CLUSTER&&(e._path._x=t.x,e._path._y=t.y,e._path._radius=t.radius)}}_runForEncoding(e){let t=e.channel,r=e.elements[0].parent.layout&&e.elements[0].parent.layout.type==F.STACK?d(e.elements):h(e.elements),n=[];if("x"===t){let t=e.orientation===Kt?r.top-2:r.bottom+2;e._pathPos=e._posArg?e._posArg:t,n.push([e.scale.range[0],e._pathPos]),n.push([e.scale.range[1],e._pathPos])}else if("width"===t){let t=e.orientation===Kt?r.top-2:r.bottom+2;e._pathPos=e._posArg?e._posArg:t,n.push([r.left,e._pathPos]),n.push([r.right,e._pathPos])}else if("radialDistance"===t){let t=e.elements[0].parent,r=t.y;e._pathPos=e._posArg?e._posArg:r,n.push([e.scale.range[0]+t.x,e._pathPos]),n.push([e.scale.range[1]+t.x,e._pathPos])}else if("y"===t){let t=e.orientation===$t?r.left-2:r.right+2;e._pathPos=e._posArg?e._posArg:t,n.push([e._pathPos,e.scale.range[0]]),n.push([e._pathPos,e.scale.range[1]])}else if("height"===t){let t=e.orientation===$t?r.left-2:r.right+2;e._pathPos=e._posArg?e._posArg:t,n.push([e._pathPos,r.bottom]),n.push([e._pathPos,r.top])}e._path._setVertices(n)}}class nr extends H{constructor(e){super(e)}run(){let e=this.inputVars.find((e=>e instanceof Je&&e.property==Qe.AXIS_PATH_POSITION)).element;e instanceof er?this._runForEncoding(e):e instanceof tr&&this._runForLayout(e);for(let t of e._ticks.children)t._updateBounds();f(e._ticks)}_runForLayout(e){let t=e.channel;if("x"==t){let t=e.orientation==Zt?e.pathPos+e.tickOffset:e.pathPos-e.tickOffset,r=e.orientation==Zt?e.tickSize:-e.tickSize;for(let[n,i]of e._ticks.children.entries()){let s=e.elements[n].bounds[e.tickAnchor];i._setVertices([[s,t],[s,t+r]])}}else if("y"===t){let t=e.orientation==$t?e.pathPos-e.tickOffset:e.pathPos+e.tickOffset,r=e.orientation==$t?-e.tickSize:e.tickSize;for(let[n,i]of e._ticks.children.entries()){let s=e.elements[n].bounds[e.tickAnchor];i._setVertices([[t,s],[t+r,s]])}}else if("angle"===t){let t=e.elements[0].parent.layout;if(t.type===F.CLUSTER){let r=t._d3Root.leaves();const n=new Map(r.map((e=>[e.data[xe],[e.x,e.y]])));for(let[r,i]of e._ticks.children.entries()){let s=e.elements[r].dataScope.getAttributeValue(xe),a=ce(n.get(s)[0])-90;i._setVertices([[t.x+n.get(s)[1]+e.elements[r].bounds.width/2,t.y],[t.x+n.get(s)[1]+e.elements[r].bounds.width/2+e.tickSize,t.y]]),i._rotate=[a,t.x,t.y]}}}}_runForEncoding(e){let t=e.channel,r=h(e.elements);if("x"==t){let t=e.orientation==Zt?e.pathPos+e.tickOffset:e.pathPos-e.tickOffset,r=e.orientation==Zt?e.tickSize:-e.tickSize;for(let[n,i]of e._ticks.children.entries())i._setVertices([[e.scale.map(e._tickValues[n]),t],[e.scale.map(e._tickValues[n]),t+r]])}else if("width"==t){let t=e.orientation==Zt?e.pathPos+e.tickOffset:e.pathPos-e.tickOffset,n=e.orientation==Zt?e.tickSize:-e.tickSize;if(!!(e.isFlipped()||e.elements[0].type===Tt.Area&&"right"===e.elements[0].baseline))for(let[i,s]of e._ticks.children.entries())s._setVertices([[r.left+e.scale.rangeExtent-e.scale.map(e._tickValues[i]),t],[r.left+e.scale.rangeExtent-e.scale.map(e._tickValues[i]),t+n]]);else for(let[i,s]of e._ticks.children.entries())s._setVertices([[e.scale.map(e._tickValues[i])+r.left,t],[e.scale.map(e._tickValues[i])+r.left,t+n]])}else if("y"===t){let t=e.orientation==$t?e.pathPos-e.tickOffset:e.pathPos+e.tickOffset,r=e.orientation==$t?-e.tickSize:e.tickSize;for(let[n,i]of e._ticks.children.entries())i._setVertices([[t,e.scale.map(e._tickValues[n])],[t+r,e.scale.map(e._tickValues[n])]])}else if("height"===t){let t=e.orientation==$t?e.pathPos-e.tickOffset:e.pathPos+e.tickOffset,n=e.orientation==$t?-e.tickSize:e.tickSize;if(!!(e.isFlipped()||e.elements[0].type===Tt.Area&&"top"===e.elements[0].baseline))for(let[i,s]of e._ticks.children.entries())s._setVertices([[t,r.top+e.scale.map(e._tickValues[i])],[t+n,r.top+e.scale.map(e._tickValues[i])]]);else for(let[i,s]of e._ticks.children.entries()){let a=r.bottom-e.scale.map(e._tickValues[i]);s._setVertices([[t,a],[t+n,a]])}}else if("radialDistance"===t){let t=e.orientation==Zt?e.pathPos+e.tickOffset:e.pathPos-e.tickOffset,r=e.orientation==Zt?e.tickSize:-e.tickSize,n=e.elements[0].parent;for(let[i,s]of e._ticks.children.entries())s._setVertices([[n.x+e.scale.map(e._tickValues[i]),t],[n.x+e.scale.map(e._tickValues[i]),t+r]])}}}class ir extends H{constructor(e){super(e)}run(){let e=this.inputVars.find((e=>e instanceof Je&&e.property==Qe.AXIS_PATH_POSITION)).element;e instanceof er?this._runForEncoding(e):e instanceof tr&&this._runForLayout(e);for(let t of e._labels.children)t._updateBounds();f(e._labels)}_runForLayout(e){let t=e.channel;if("x"==t){let t=e.orientation==Zt?e.labelOffset:-e.labelOffset,r=e.orientation==Zt?[p.CENTER,p.TOP]:[p.CENTER,p.BOTTOM];for(let[n,i]of e._labels.children.entries()){let s=e.elements[n].bounds;i._x=s[e.tickAnchor],i._y=e.pathPos+t,i._anchor=r,e._labelRotation&&(i._rotate=[e._labelRotation,i.x,i.y],i._anchor=[p.RIGHT,p.MIDDLE])}}else if("y"===t){let t=e.orientation==$t?-e.labelOffset:e.labelOffset,r=e.orientation==$t?[p.RIGHT,p.MIDDLE]:[p.LEFT,p.MIDDLE];for(let[n,i]of e._labels.children.entries()){let s=e.elements[n].bounds;i._x=e.pathPos+t,i._y=e.tickAnchor==p.MIDDLE?s.y:s[e.tickAnchor],i._anchor=r,e._labelRotation&&(i._rotate=[e._labelRotation,i.x,i.y],i._anchor=[p.RIGHT,r[1]])}}else if("angle"===t){let t=e.elements[0].parent.layout;if(t.type===F.CLUSTER){let r=t._d3Root.leaves();const n=new Map(r.map((e=>[e.data[xe],[e.x,e.y]])));let i=5;for(let[r,s]of e._labels.children.entries()){let a=e.elements[r].dataScope.getAttributeValue(xe);if(n.get(a)[0]<Math.PI){let o=ce(n.get(a)[0])-90;s._anchor=[p.LEFT,p.MIDDLE],s._x=t.x+n.get(a)[1]+e.elements[r].bounds.width/2+i,s._y=t.y,s._rotate=[o,t.x,t.y]}else{let o=ce(n.get(a)[0])+90;s._anchor=[p.RIGHT,p.MIDDLE],s._x=t.x-n.get(a)[1]-e.elements[r].bounds.width/2-i,s._y=t.y,s._rotate=[o,t.x,t.y]}}}}}_runForEncoding(e){let t=e.channel,r=h(e.elements);if("x"==t){let t=e.orientation==Zt?e.labelOffset:-e.labelOffset,r=e.orientation==Zt?[p.CENTER,p.TOP]:[p.CENTER,p.BOTTOM];for(let[n,i]of e._labels.children.entries())i._x=e.scale.map(e.labelValues[n]),i._y=e.pathPos+t,i._anchor=r,e._labelRotation&&(i._rotate=[e._labelRotation,i.x,i.y],i._anchor=[p.RIGHT,r[1]])}else if("width"===t){let t=e.orientation==Zt?e.labelOffset:-e.labelOffset,n=e.orientation==Zt?[p.CENTER,p.TOP]:[p.CENTER,p.BOTTOM],i=!!(e.isFlipped()||e.elements[0].type===Tt.Area&&"right"===e.elements[0].baseline);for(let[s,a]of e._labels.children.entries())a._x=i?r.left+e.scale.rangeExtent-e.scale.map(e.labelValues[s]):e.scale.map(e.labelValues[s])+r.left,a._y=e.pathPos+t,a._anchor=n,e._labelRotation&&(a._rotate=[e._labelRotation,a.x,a.y],a._anchor=[p.RIGHT,n[1]])}else if("y"===t){let t=e.orientation==$t?-e.labelOffset:e.labelOffset,r=e.orientation==$t?[p.RIGHT,p.MIDDLE]:[p.LEFT,p.MIDDLE];for(let[n,i]of e._labels.children.entries())i._x=e.pathPos+t,i._y=e.scale.map(e.labelValues[n]),i._anchor=r,e._labelRotation&&(i._rotate=[e._labelRotation,i.x,i.y],i._anchor=[p.RIGHT,r[1]])}else if("height"===t){let t=e.orientation==$t?-e.labelOffset:e.labelOffset,n=e.orientation==$t?[p.RIGHT,p.MIDDLE]:[p.LEFT,p.MIDDLE],i=e.elements[0].type===Tt.Area&&"top"===e.elements[0].baseline;for(let[s,a]of e._labels.children.entries())a._x=e.pathPos+t,a._y=i?r.top+e.scale.map(e.labelValues[s]):r.bottom-e.scale.map(e.labelValues[s]),a._anchor=n,e._labelRotation&&(a._rotate=[e._labelRotation,a.x,a.y],a._anchor=[p.RIGHT,n[1]])}else if("radialDistance"==t){let t=e.orientation==Zt?e.labelOffset:-e.labelOffset,r=e.orientation==Zt?[p.CENTER,p.TOP]:[p.CENTER,p.BOTTOM],n=e.elements[0].parent;for(let[i,s]of e._labels.children.entries())s._x=n.x+e.scale.map(e.labelValues[i]),s._y=e.pathPos+t,s._anchor=r,e._labelRotation&&(s._rotate=[e._labelRotation,s.x,s.y],s._anchor=[p.RIGHT,r[1]])}}}class sr extends H{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=S(e.parent);for(let e of t){let t=e.layout;if(!t)return;this.fillGrid(e,t),this.computeCellBounds(e,t),this.placeElements(e,t)}let r=G(e,!0);for(let e of r)f(e)}placeElements(e,t){let r=De(e,"x"),n=De(e,"y");for(let r=0;r<e.children.length;r++){let n=e.children[r],i=t.cellBounds[r],s=0,a=0;switch(t._cellHorzAlignment){case p.LEFT:s=i.left-n.refBounds.left;break;case p.CENTER:s=i.x-n.refBounds.x;break;case p.RIGHT:s=i.right-n.refBounds.right}switch(t._cellVertAlignment){case p.TOP:a=i.top-n.refBounds.top;break;case p.MIDDLE:a=i.y-n.refBounds.y;break;case p.BOTTOM:a=i.bottom-n.refBounds.bottom}je(n,s,a)}if(r.length>0)for(let e of r)for(let r of e.scales){let n=e.getElements(r)[0],i=t.getIndex(n);if(i<0)continue;let s="point"===r.type?t.cellBounds[i].left+n.bounds.width/2:t.cellBounds[i].left,a=s+r.rangeExtent;r.range=r.range[0]<r.range[1]?[s,a]:[a,s]}if(n.length>0)for(let e of n)for(let r of e.scales){let n=e.getElements(r)[0],i=t.getIndex(n);if(i<0)continue;let s="point"===r.type?t.cellBounds[i].top+e.getElements(r)[0].bounds.height/2:t.cellBounds[i].top,a=s+r.rangeExtent;r.range=r.range[0]<r.range[1]?[s,a]:[a,s]}}fillGrid(e,t){t._grid=new Array(t.numRows).fill(null).map((()=>new Array(t.numCols).fill(null)));for(let r=0;r<e.children.length;r++){let e=t.getRowCol(r);t._grid[e.row][e.col]=r}}computeCellBounds(e,t){let r=e.children.map((e=>e.refBounds?e.refBounds:e.bounds)),n=t._colGap,i=t._rowGap;if(void 0===t._left){let e=r.map((e=>e.left)),n=r.map((e=>e.top));t._left=Math.min(...e),t._top=Math.min(...n)}let s=r.map((e=>e.width)),a=r.map((e=>e.height)),o=Math.max(...s),l=Math.max(...a);t._cellBounds=new Array(e.children.length).fill(null);for(let r=0;r<t.numRows;r++)for(let s=0;s<t.numCols;s++){let a=t._grid[r][s];a>=e.children.length||(t._cellBounds[a]=new u(t._left+(o+n)*s+0,t._top+(l+i)*r,o,l))}}}class ar extends H{constructor(e){super(e)}run(){let e=this.outputVar.element;e.scale?this._runForEncoding(e):this._runForLayout(e),f(e)}_runForLayout(e){let t=e.channel,r=h(e.elements),n=[];if("x"===t)for(let t=0;t<e.values.length;t++){let i=e.elements[t].refBounds;n.push({x1:i.x,y1:r.bottom,x2:i.x,y2:r.top})}else if("y"===t)for(let t=0;t<e.values.length;t++){let i=e.elements[t].refBounds;n.push({x1:r.left,y1:i.y,x2:r.right,y2:i.y})}e.lines=n}_runForEncoding(e){let t=e.channel,r=h(e.elements),n=[];if("x"===t)for(let t of e.values)n.push({x1:e.scale.map(t),y1:r.bottom,x2:e.scale.map(t),y2:r.top});else if("width"===t)for(let t of e.values)n.push({x1:e.scale.map(t)+r.left,y1:r.bottom,x2:e.scale.map(t)+r.left,y2:r.top});else if("y"===t)for(let t of e.values)n.push({x1:r.left,y1:e.scale.map(t),x2:r.right,y2:e.scale.map(t)});else if("height"===t)for(let t of e.values)n.push({x1:r.left,y1:r.bottom-e.scale.map(t),x2:r.right,y2:r.bottom-e.scale.map(t)});else if("radialDistance"===t){let t=e.elements[0].parent;for(let r=0;r<e.values.length;r++)n.push({x:t.x,y:t.y,r:e.scale.map(e.values[r])})}e.lines=n}}class or extends H{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=G(e)[0],r=S(e.parent);for(let e of r){let r=e.layout;if(!r)return;switch(t.type){case Tt.Rect:case Tt.Circle:case Tt.Image:this._stackRects(e,r);break;case Tt.Area:e.children[0].orientation===$.HORIZONTAL?this._stackAreasVert(e,r):this._stackAreasHorz(e,r);break;case Tt.Arc:case Tt.Pie:t.parent.classId===e.classId&&this._stackArcs(e,r)}}f(t)}_stackArcs(e,t){if(t.orientation===$.ANGULAR){let t=90;if((this._direction?this._direction:Q.Clockwise)===Q.Clockwise)for(let r of e.children){let e=he(t-r.angle);Fe(r,"startAngle",e),t=e}else for(let r of e.children){let e=he(t+r.angle);Fe(r,"startAngle",e),t=e}}else if(t.orientation===$.RADIAL){let t=Math.min(...e.children.map((e=>e.innerRadius)));for(let r of e.children){let e=r.outerRadius-r.innerRadius;Fe(r,"innerRadius",t),Fe(r,"outerRadius",t+e),t=r._outerRadius}}}_stackAreasVert(e,t){let r=e.children,n=e.bounds,i=t.vertCellAlignment===p.TOP?n.top:n.bottom,s=t.vertCellAlignment===p.TOP?1:-1,a=r[0].vertices.length/2,o=new Array(a).fill(0);for(let e of r){for(let t=0;t<a;t++){let r=e.vertices[t],n=e.vertices[2*a-t-1],l=Math.abs(r.y-n.y),u=i+o[t]*s,c=i+(o[t]+l)*s;je(r,0,u-r.y),je(n,0,c-n.y),o[t]+=l}let t=e.bounds.bottom;e._updateBounds(),e._refBounds.translate(0,e.bounds.bottom-t)}if(t.vertCellAlignment===p.MIDDLE)for(let e of r){for(let t=0;t<a;t++){let r=e.vertices[t],i=e.vertices[2*a-t-1],s=n.middle+o[t]/2;je(r,0,s-n.bottom),je(i,0,s-n.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 r=t._orientation,n=e.children.map((e=>e.bounds)),i=n.map((e=>e.left)),s=n.map((e=>e.top)),a=n.map((e=>e.width)),o=n.map((e=>e.height)),l=null==t._left?Math.min(...i):t._left,u=null==t._top?Math.min(...s):t._top,c=Math.max(...a),h=Math.max(...o);if(r==$.VERTICAL)for(let r=0;r<e.children.length;r++){let n=e.children[r],i=0,s=u+n.bounds.height/2-n.bounds.y;u+=n.bounds.height+t._gap,je(n,i,s),n._updateBounds();let a=0,o=0;if(!Me(n))switch(t._horzCellAlignment){case p.LEFT:a=l-n.bounds.left;break;case p.CENTER:a=l+c/2-n.bounds.x;break;case p.RIGHT:a=l+c-n.bounds.right}je(n,a,o)}else for(let r=0;r<e.children.length;r++){let n=e.children[r],i=l+n.bounds.width/2-n.bounds.x,s=0;l+=n.bounds.width+t._gap,je(n,i,s),n._updateBounds();let a=0,o=0;if(!Be(n))switch(t._vertCellAlignment){case p.TOP:o=u-n.bounds.top;break;case p.MIDDLE:o=u+h/2-n.bounds.y;break;case p.BOTTOM:o=u+h-n.bounds.bottom}je(n,a,o)}}}class lr extends H{constructor(e){super(e)}run(){super.run()}}class ur extends H{constructor(e){super(e)}run(){let t=this.inputVars[0],r=this.outputVar,n=t.attribute,i=r.attribute,s=t.dataset,a=r.dataset,o=s.getAttributeValues(n),l=e.bin()(o),u=this._findBin,c=o.map((e=>{let t=u(e,l);return(t.x0+t.x1)/2+""})),h=l.map((e=>(e.x0+e.x1)/2+""));a._addAttribute(i,we.String,c),a.orderAttributeValues(i,h)}_findBin(e,t){for(let r of t)if(r.indexOf(e)>=0)return r}}class cr extends H{constructor(e){super(e)}run(){let e=this.outputVar,t=e.dataset,r=e.predicate,n=[];for(let[e,i]of t.data.entries())r.testTuple(i)||n.push(e);n.sort(((e,t)=>t-e)),n.forEach((e=>{e>=0&&e<t.data.length&&(t._data.splice(e,1),t._rawData.splice(e,1))}));for(let e of t._attributes)t._attrSummaries[e]=Re(t.data.map((t=>t[e])),t._attrTypes[e])}}class hr extends Y{constructor(e,t,r){super(e),this._dataset=r,this._predicate=t}get dataset(){return this._dataset}get predicate(){return this._predicate}}class dr extends Y{constructor(e,t){super(e),this._group=t}get element(){return this._group}}class fr extends H{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find((e=>e.type===X.AFFIXATION)).affixation,t=e.base,r=e.element,n=S(t),i=S(r),s=e.channels,a=e.attribute;if(x(r)&&x(t)){let e=n.map((e=>e.dataScope.getAttributeValue(a)));i=i.filter((t=>e.includes(t.dataScope.getAttributeValue(a))));let t=(e,t)=>e.dataScope.getAttributeValue(a)<t.dataScope.getAttributeValue(a)?-1:e.dataScope.getAttributeValue(a)>t.dataScope.getAttributeValue(a)?1:0;i.sort(t),n.sort(t)}if(s.includes("x")||s.includes("y"))for(let t of s)this._handleXY(t,i,n,e.getElementAnchor(t),e.getBaseAnchor(t),e.getOffset(t));(s.includes("radialDistance")||s.includes("angle"))&&this._handlePolar(i,n,e);let o=G(r,!0);for(let e of o)f(e)}_handlePolar(e,t,r){let n=r.hasChannel("radialDistance")?r.getBaseAnchor("radialDistance"):p.MIDDLE,i=r.hasChannel("radialDistance")?r.getElementAnchor("radialDistance"):p.MIDDLE,s=r.hasChannel("angle")?r.getBaseAnchor("angle"):p.CENTER;r.hasChannel("angle")?r.getElementAnchor("angle"):p.CENTER;let a=r.hasChannel("radialDistance")?r.getOffset("radialDistance"):0,o=r.hasChannel("angle")?r.getOffset("angle"):0;if([Tt.Arc,Tt.Ring].indexOf(t[0].type)>=0&&e[0].type==Tt.PointText)for(let r=0;r<e.length;r++){let i=t[r],o=e[r],l=n===p.MIDDLE?(i.outerRadius+i.innerRadius)/2:n===p.TOP?i.outerRadius-5:i.innerRadius+5;if(l+=a,i.type===Tt.Arc){let e=Se(i.x,i.y,l,i.startAngle),t=Se(i.x,i.y,l,i.endAngle);i.endAngle>=180&&i.endAngle<=360?o._textPath=["M",e[0],e[1],"A",l,l,i.angle,i.angle>=180?1:0,0,t[0],t[1]].join(" "):o._textPath=["M",t[0],t[1],"A",l,l,i.angle,i.angle>=180?1:0,1,e[0],e[1]].join(" ")}else if(i.type===Tt.Ring){let e=275,t=265,r=350,n=Se(i.x,i.y,l,e),s=Se(i.x,i.y,l,t);o._textPath=["M",s[0],s[1],"A",l,l,r,1,1,n[0],n[1]].join(" ")}o._textPathOffset=s===p.LEFT?"0%":"50%"}else for(let r=0;r<e.length;r++){let l,u,c=t[r],h=e[r];c.type==Tt.Arc||c.type==Tt.Ring?(u="left"==s?c.endAngle+o:"center"==s?c.startAngle+c.angle/2+o:c.startAngle+o,l="top"==n?c.outerRadius+a:"bottom"==n?c.innerRadius+a:(c.outerRadius+c.innerRadius)/2+a):c.type==Tt.Circle&&(u=90,l="top"==n?c.radius+a:"bottom"==n?a:c.radius/2+a),je(h,c.x-h.x,c.y-l-h.bounds[i]),h._rotate=[90-u,c.x,c.y]}}_handleXY(e,t,r,n,i,s){for(let a=0;a<t.length;a++){let o,l=r[a],u=t[a];if(se(l)){o=ie(l,[p.LEFT,p.TOP].includes(i)?0:[p.CENTER,p.MIDDLE].includes(i)?.5:1)[e]}else o=l.bounds[i]+s;t[0].type===Tt.PointText?(u.anchor["x"==e?0:1]=n,Fe(u,e,o)):"x"==e?je(u,o-u.bounds[n],0):je(u,0,o-u.bounds[n])}}}class pr extends Y{constructor(e,t){super(e),this._affx=t}get affixation(){return this._affx}}class _r extends H{constructor(e){super(e)}run(){let e=this.inputVars[0],t=this.outputVar,r=e.attribute,n=t.attribute,i=e.dataset,s=t.dataset,a=this.args,o="min"in a?a.min:i.getAttributeSummary(r).min,l="max"in a?a.max:i.getAttributeSummary(r).max,u=o,c=[];for(;u<l;)c.push(u),u+=a.interval;c.push(u);let h={},d={};if(a.groupBy)for(let e of i.data){let t=a.groupBy.map((t=>e[t])).join("-");t in h||(h[t]=[],d[t]=a.groupBy.map((t=>e[t]))),h[t].push(e[r])}else h[""]=i.data.map((e=>e[r])),d[""]="";let f=[];for(let e in d){let t=gr(yr(a.bandwidth),c,h[e]);for(let i of t){let t={};""!==e&&a.groupBy.forEach(((r,n)=>t[r]=d[e][n])),t[r]=i[0],t[n]=i[1],f.push(t)}}let p={};if(p[r]=i.getAttributeType(r),p[n]=we.Number,a.groupBy)for(let e of a.groupBy)p[e]=i.getAttributeType(e);s.initialize(f,s.url,p)}}function gr(t,r,n){return r.map((r=>[r,e.mean(n,(e=>t(r-e)))]))}function yr(e){return t=>Math.abs(t/=e)<=1?.75*(1-t*t)/e:0}class mr extends H{constructor(e){super(e)}run(){super.run();let t=this._outputVars[0].element,r=S(t.parent);for(let t of r){let r=t.layout;if(!r)return;let n=t.children.map((e=>({name:e.id,radius:e.radius,itm:e}))),i=n.reduce(((e,t)=>e+Math.pow(t.radius,2)),0),s=Math.sqrt(i);void 0===r._width&&(r._width=s),void 0===r._height&&(r._height=s);let a=e.hierarchy({name:"root",children:n}).sum((e=>e.radius?e.radius:0)).sort(((e,t)=>t.value-e.value));e.pack().size([r._width,r._height]).radius((e=>e.value))(a);for(let e of a.children){let t=e.data.itm;je(t,r._x-a.x+e.x-t.x,r._y-a.y+e.y-t.y)}}let n=G(t,!0);for(let e of n)f(e)}}class br extends H{constructor(e){super(e)}run(){let e=this.inputVars.find((e=>e instanceof Je&&e.property==Qe.AXIS_PATH_POSITION)).element;e instanceof er?this._runForEncoding(e):e instanceof tr&&this._runForLayout(e),f(e._title)}_runForEncoding(e){let t=e.channel,r=h(e.elements);if("x"==t)e._title._x=(e.scale.range[0]+e.scale.range[1])/2,e._title._y=e.orientation==Zt?e.pathPos+e.titleOffset:e.pathPos-e.titleOffset;else if("width"==t)e._title._x=r.left+e.scale.rangeExtent/2,e._title._y=e.orientation==Zt?e.pathPos+e.titleOffset:e.pathPos-e.titleOffset;else if("y"===t)e._rotateYTitle?(e._title._x=e.orientation==$t?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==$t?[-90,e._title._x,e._title._y]:[90,e._title._x,e._title._y]):(e._title._x=e.orientation==$t?e.pathPos-e.titleOffset:e.pathPos+e.titleOffset,e._title._y=Math.min(e.scale.range[0],e.scale.range[1])-25,e._title._rotate=void 0);else if("height"===t)e._title._x=r.center,e._title._y=(r.top+r.bottom)/2-r.width/2-e.titleOffset,e._title._rotate=e.orientation==$t?[-90,r.center,r.middle]:[90,r.center,r.middle];else if("radialDistance"===t){let t=e.elements[0].parent;e._title._x=t.x+e.scale.rangeExtent/2,e._title._y=e.orientation==Zt?e.pathPos+e.titleOffset:e.pathPos-e.titleOffset,e._rotate&&(e._title._rotate=e._rotate.slice())}}_runForLayout(e){let t=e.channel,r=e.elements[0].parent.layout&&e.elements[0].parent.layout.type==F.STACK?d(e.elements):h(e.elements);if("x"==t)e._title._x=r.center,e._title._y=e.orientation==Zt?e.pathPos+e.titleOffset:e.pathPos-e.titleOffset;else if("y"===t)e._title._x=r.center,e._title._y=r.middle-r.width/2-e.titleOffset,e._title._rotate=e.orientation==$t?[-90,r.center,r.middle]:[90,r.center,r.middle];else if("angle"===t){let t=e.elements[0].parent.layout;t.type===F.CLUSTER&&(e._title._x=t.x,e._title._y=t.y)}}}class vr extends Mt{constructor(e){super(e)}run(){super.run();let t,r=this.vars.find((e=>e.type===X.ALIGNMENT)).alignment,n=r.anchor,i=r.elements;n==p.Top||n==p.LEFT?t=Math.min(...i.map((e=>e.bounds[n]))):n==p.BOTTOM||n==p.RIGHT?t=Math.max(...i.map((e=>e.bounds[n]))):n!=p.CENTER&&n!=p.MIDDLE||(t=e.mean(i.map((e=>e.bounds[n]))));for(let e of i){let i=Ge(e,r.channel);if(i){let s=t-e.bounds[n];je(i,"x"===r.channel?s:0,"x"===r.channel?0:s)}}for(let e of i)f(e)}}class xr extends Y{constructor(e,t){super(e),this._aln=t}get alignment(){return this._aln}}class Er extends H{constructor(e){super(e)}run(){super.run();let t=this._outputVars[0].element,r=S(t.parent);for(let t of r){let r=t.layout;if(!r)continue;let n=be(t.children[0]);if(!n)continue;let i=n.linkList.map((e=>({source:n.getNode(e.source),target:n.getNode(e.target)}))),s=e.forceSimulation(n.nodeList).force("charge",e.forceManyBody().strength(-r._repulsion)).force("link",e.forceLink(i).id((e=>e.id)).distance(r._linkDistance)).force("x",e.forceX()).force("y",e.forceY()).force("center",e.forceCenter(r._x,r._y).strength(r._attraction));s.stop(),s.tick(r._iterations);for(let e=0;e<t.children.length;e++){let r=t.children[e],i=n.nodeList[e];je(r,i.x-r.x,i.y-r.y)}}let n=G(t,!0);for(let e of n)f(e)}}class wr extends H{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=S(e);switch(e.type){case Tt.Arc:this._updateArcLinks(t);break;case Tt.BezierCurve:this._updateBezierLinks(t);break;case Tt.BundledPath:this._updateBundledLinks(t);break;case Tt.Chord:this._updateChordLinks(t);break;case Tt.Line:default:this._updateLineLinks(t)}f(e)}_updateArcLinks(e){for(let t of e){let e=t.source.x<t.target.x?t.source:t.target,r=t.source.x<t.target.x?t.target:t.source;t._x=(e.x+r.x)/2,t._y=(e.y+r.y)/2,t._innerRadius=Math.sqrt(Math.pow(e.x-r.x,2)+Math.pow(e.y-r.y,2))/2,t._outerRadius=t._innerRadius+t._thickness;let n=de(e.x,e.y,t._x,t._y),i=de(r.x,r.y,t._x,t._y);t.direction===Q.CLOCKWISE&&([n,i]=[i,n]),Fe(t,"startAngle",n),Fe(t,"angle",Math.abs(i-n))}}_updateBezierLinks(e){let t=this._inputVars[0].element,r=S(t),n=t.parent.layout;n.type===F.DIRECTED||n.type===F.TIDYTREE?this._updateBezierLinksForDirectedGraph(r,e,n):n.type===F.CLUSTER&&this._updateBezierLinksForClusteredGraph(r,e,n)}_updateBezierLinksForClusteredGraph(t,r,n){const i=n._d3Root.descendants(),s=new Map(i.map((e=>[Ar(e),e]))),a=new Map(i.map((e=>[e.data[xe],Ar(e)])));if(n.isRadial()){const t=e.linkRadial().angle((e=>e.x)).radius((e=>e.y));for(let e of r){let r=e.source,i=e.target,o=r.dataScope.getAttributeValue(xe),l=i.dataScope.getAttributeValue(xe),u=s.get(a.get(o)),c=s.get(a.get(l));e._d=oe(t({source:u,target:c}),n.x,n.y)}}else if(n.orientation===$.VERTICAL){const t=e.linkVertical().x((e=>e.x)).y((e=>e.y));for(let e of r){let r=e.source,i=e.target,o=r.dataScope.getAttributeValue(xe),l=i.dataScope.getAttributeValue(xe),u=s.get(a.get(o)),c=s.get(a.get(l));e._d=oe(t({source:u,target:c}),n.left-n._x0,n.top)}}else if(n.orientation===$.HORIZONTAL){const t=e.linkHorizontal().x((e=>e.y)).y((e=>e.x));for(let e of r){let r=e.source,i=e.target,o=r.dataScope.getAttributeValue(xe),l=i.dataScope.getAttributeValue(xe),u=s.get(a.get(o)),c=s.get(a.get(l));e._d=oe(t({source:u,target:c}),n.left,n.top-n._x0)}}}_updateBezierLinksForDirectedGraph(e,t,r){let n={},i={},s={},a={};for(let t of e){i[t.id]=0,n[t.id]=0;let e=t.links.filter((e=>e.source===t)),r=t.links.filter((e=>e.target===t));a[t.id]=r.map((e=>e.strokeWidth)).reduce(((e,t)=>e+t),0),s[t.id]=e.map((e=>e.strokeWidth)).reduce(((e,t)=>e+t),0)}r.spreadLinks&&("LR"===r.direction||"RL"===r.direction?t.sort(((e,t)=>de(e.target.bounds.x,e.target.bounds.y,e.source.bounds.x,e.source.bounds.y)-de(t.target.bounds.x,t.target.bounds.y,t.source.bounds.x,t.source.bounds.y))):t.sort(((e,t)=>de(t.target.bounds.x,t.target.bounds.y,t.source.bounds.x,t.source.bounds.y)-de(e.target.bounds.x,e.target.bounds.y,e.source.bounds.x,e.source.bounds.y))));for(let e of t){let t,o,l,u,c=e.source,h=e.target;r.spreadLinks?"LR"===r.direction||"RL"===r.direction?(t=c.bounds[e.sourceAnchor[0]]+e.sourceOffset[0],l=h.bounds[e.targetAnchor[0]]+e.targetOffset[0],o=c.bounds[e.sourceAnchor[1]]+e.sourceOffset[1]-s[c.id]/2+n[c.id]+e.strokeWidth/2,u=h.bounds[e.targetAnchor[1]]+e.targetOffset[1]-a[h.id]/2+i[h.id]+e.strokeWidth/2,n[c.id]+=e.strokeWidth,i[h.id]+=e.strokeWidth):(o=c.bounds[e.sourceAnchor[1]]+e.sourceOffset[1],u=h.bounds[e.targetAnchor[1]]+e.targetOffset[1],t=c.bounds[e.sourceAnchor[0]]+e.sourceOffset[0]-s[c.id]/2+n[c.id]+e.strokeWidth/2,l=h.bounds[e.targetAnchor[0]]+e.targetOffset[0]-a[h.id]/2+i[h.id]+e.strokeWidth/2,n[c.id]+=e.strokeWidth,i[h.id]+=e.strokeWidth):(t=c.bounds[e.sourceAnchor[0]]+e.sourceOffset[0],o=c.bounds[e.sourceAnchor[1]]+e.sourceOffset[1],l=h.bounds[e.targetAnchor[0]]+e.targetOffset[0],u=h.bounds[e.targetAnchor[1]]+e.targetOffset[1]),e.orientation===$.HORIZONTAL?e._setVertices([[t,o],[(t+l)/2,o],[t,u],[l,u]]):e.orientation===$.VERTICAL&&e._setVertices([[t,o],[t,(o+u)/2],[l,o],[l,u]])}}_updateBundledLinks(t){let r=this._inputVars[0].element.parent.layout;if(r.type!==F.CLUSTER)throw"Bundled links must work on a cluster layout";let n=r._d3Root.leaves();const i=new Map(n.map((e=>[Ar(e),e]))),s=new Map(n.map((e=>[e.data[xe],Ar(e)]))),a=e.lineRadial().curve(e.curveBundle.beta(t[0]._strength)).radius((e=>e.y)).angle((e=>e.x));for(let e of t){let t=e.source.dataScope.getAttributeValue(xe),n=e.target.dataScope.getAttributeValue(xe),o=i.get(s.get(t)),l=i.get(s.get(n));(o.outgoing??=[]).push([o,l]),l.incoming??=[];let u=o.path(l);e._d=oe(a(u),r.x,r.y)}}_updateChordLinks(e){for(let t of e){let e=t.source,r=t.target,n=Se(e.x,e.y,e.innerRadius,e.startAngle),i=Se(e.x,e.y,e.innerRadius,e.endAngle),s=Se(r.x,r.y,r.innerRadius,r.startAngle),a=Se(r.x,r.y,r.innerRadius,r.endAngle);t._d=["M",n[0],n[1],"Q",e.x,e.y,a[0],a[1],"A",e.x,e.y,r.angle,r.angle>180?1:0,1,s[0],s[1],"Q",e.x,e.y,i[0],i[1],"A",e.x,e.y,e.angle,e.angle>180?1:0,1,n[0],n[1]].join(" ")}}_updateLineLinks(e){for(let t of e){let e=t.source,r=t.target;t.vertices[0]._x=e.bounds.x,t.vertices[0]._y=e.bounds.y,t.vertices[1]._x=r.bounds.x,t.vertices[1]._y=r.bounds.y}}}function Ar(e){return`${e.parent?Ar(e.parent)+".":""}${e.data[xe]}`}var Cr,Rr,kr,Sr,Tr,Or,Ir,Nr,Lr,Vr,Pr,Dr,Br,Mr,Gr,jr,zr,Fr,Ur,Hr,Wr,Yr,Xr,qr,Kr,Zr,$r,Jr,Qr,en,tn,rn,nn,sn,an,on,ln,un,cn,hn,dn,fn,pn,_n,gn,yn,mn,bn,vn,xn,En,wn,An,Cn,Rn,kn,Sn,Tn,On,In,Nn,Ln,Vn,Pn,Dn,Bn,Mn,Gn,jn,zn,Fn,Un,Hn,Wn,Yn,Xn,qn,Kn,Zn,$n,Jn,Qn,ei,ti,ri,ni,ii,si,ai,oi,li,ui,ci,hi,di,fi,pi,_i,gi,yi,mi,bi,vi,xi,Ei,wi,Ai,Ci,Ri="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function ki(){if(Sr)return kr;return Sr=1,kr=function(e,t){return e===t||e!=e&&t!=t}}function Si(){if(Or)return Tr;Or=1;var e=ki();return Tr=function(t,r){for(var n=t.length;n--;)if(e(t[n][0],r))return n;return-1}}function Ti(){if(jr)return Gr;jr=1;var e=Rr?Cr:(Rr=1,Cr=function(){this.__data__=[],this.size=0}),t=function(){if(Nr)return Ir;Nr=1;var e=Si(),t=Array.prototype.splice;return Ir=function(r){var n=this.__data__,i=e(n,r);return!(i<0||(i==n.length-1?n.pop():t.call(n,i,1),--this.size,0))}}(),r=function(){if(Vr)return Lr;Vr=1;var e=Si();return Lr=function(t){var r=this.__data__,n=e(r,t);return n<0?void 0:r[n][1]}}(),n=function(){if(Dr)return Pr;Dr=1;var e=Si();return Pr=function(t){return e(this.__data__,t)>-1}}(),i=function(){if(Mr)return Br;Mr=1;var e=Si();return Br=function(t,r){var n=this.__data__,i=e(n,t);return i<0?(++this.size,n.push([t,r])):n[i][1]=r,this}}();function s(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}return s.prototype.clear=e,s.prototype.delete=t,s.prototype.get=r,s.prototype.has=n,s.prototype.set=i,Gr=s}function Oi(){if(Zr)return Kr;Zr=1;var e="object"==typeof Ri&&Ri&&Ri.Object===Object&&Ri;return Kr=e}function Ii(){if(Jr)return $r;Jr=1;var e=Oi(),t="object"==typeof self&&self&&self.Object===Object&&self,r=e||t||Function("return this")();return $r=r}function Ni(){if(en)return Qr;en=1;var e=Ii().Symbol;return Qr=e}function Li(){if(on)return an;on=1;var e=Ni(),t=function(){if(rn)return tn;rn=1;var e=Ni(),t=Object.prototype,r=t.hasOwnProperty,n=t.toString,i=e?e.toStringTag:void 0;return tn=
1
+ // version: 3.0.5
2
+ import*as e from"d3";const t={canvas:void 0,getCanvas:function(){return window?(void 0===this.canvas&&(this.canvas=document.createElement("canvas")),this.canvas):null},getContext:function(){var e=this.getCanvas();return e?e.getContext("2d"):null}};class r{constructor(e,t,r){this._id="predicate_"+It(),this._type=e||n.POINT,this._variableType=t,this._variableName=r,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 n=Object.freeze({POINT:"point",INTERVAL:"interval",LIST:"list"});class i extends r{constructor(e,t,r){super(e,t,r)}testElement(e){let t;if("attribute"==this._variableType){if(!e.dataScope)return!1;t=e.dataScope.getAttributeValue(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 s extends r{constructor(e,t,r){super(e,t,r)}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=e.dataScope.getAttributeValues(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 a extends r{constructor(e,t,r){super(e,t,r)}testElement(e){if("attribute"==this._variableType){if(!e.dataScope)return!1;return e.dataScope.getAttributeValue(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}}function o(e){let t,r="attribute"in e?"attribute":"property",o=e[r];switch(e.type){case n.LIST:t=new s(e.type,r,o);break;case n.INTERVAL:t=new i(e.type,r,o);break;case n.POINT:default:t=new a(e.type,r,o)}return t.value=e.value,t}function l(e,t){for(let r of t)if(!r.testElement(e))return!1;return!0}class u{constructor(e,t,r,n){this._x=e+r/2,this._y=t+n/2,this._width=r,this._height=n}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=Math.min(this.left,e.left),r=Math.min(this.top,e.top),n=Math.max(this.right,e.right),i=Math.max(this.bottom,e.bottom);return new u(t,r,n-t,i-r)}clone(){return new u(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 p.RIGHT:this._x=this.right-e/2;break;case p.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 p.TOP:this._y=this.top+e/2;break;case p.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}overlap(e){return!(this.right<e.left||this.bottom<e.top||this.left>e.right||this.top>e.bottom)}}function c(e){let t=e[0].clone();for(let r=1;r<e.length;r++)t=t.union(e[r]);return t}function h(e){return c(("vertex"==e[0].type||"segment"==e[0].type?e.map((e=>e.parent)):e).map((e=>e.refBounds?e.refBounds:e.bounds)))}function d(e){return c(("vertex"==e[0].type||"segment"==e[0].type?e.map((e=>e.parent)):e).map((e=>e.bounds)))}function f(e){let t=S(e);for(let e of t)e._updateBounds();let r=[];for(let e of t)e.parent&&!r.includes(e.parent)&&r.push(e.parent);for(let e of r)f(e)}const p=Object.freeze({TOP:"top",LEFT:"left",RIGHT:"right",BOTTOM:"bottom",CENTER:"center",MIDDLE:"middle"});function _(e){return e.id+"-bg"}function g(e){return e.id+"-path"}function y(e){switch(e){case p.TOP:return"text-before-edge";case p.BOTTOM:return"auto";case p.LEFT:return"start";case p.RIGHT:return"end";case p.CENTER:case p.MIDDLE:return"middle";default:return e}}const m=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"});class b{constructor(e){let t=e||{};this._stops=[],this.type=Tt.LinearGradient,this.id=this.type+It(),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,r){this._stops.push({offset:e,color:t,opacity:r})}get stops(){return this._stops}}class v{constructor(e){if(this._dataScope=void 0,this._type="type"in e?e.type:Tt.Mark,this._id=e.id?e.id:this._type+"_"+It(),this._classId=void 0,this._bounds=void 0,this._rotate=void 0,this._refBounds=void 0,this._styles={},void 0!==e)for(let t in m)t in e&&(this.styles[t]=e[t])}get scene(){return P(this)}set strokeColor(e){this.styles.strokeColor=e}get strokeColor(){return this.styles.strokeColor}set strokeWidth(e){this.styles.strokeWidth=e}get strokeWidth(){return this.styles.strokeWidth}set strokeDash(e){this.styles.strokeDash=e}get strokeDash(){return this.styles.strokeDash}set fillColor(e){this.styles.fillColor=e}get fillColor(){return this.styles.fillColor}get rotation(){return this._rotate}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}contains(e,r){if(!this.bounds)return!1;if(!this.bounds.contains(e,r))return!1;switch(this.type){case Tt.Rect:case Tt.PointText:return!0;case Tt.Circle:return Math.sqrt(Math.pow(e-this.x,2)+Math.pow(r-this.y,2))<=this.radius+this.strokeWidth;case Tt.Path:{let n=t.getContext(),i=new Path2D(this.getSVGPathData());return n.lineWidth=Math.max(this.strokeWidth,2.5),n.stroke(i),this.closed?n.isPointInPath(i,e,r):n.isPointInStroke(i,e,r)}case Tt.Line:{let n=t.getContext(),i=new Path2D(this.getSVGPathData());return n.lineWidth=Math.max(this.strokeWidth,2.5),n.stroke(i),n.isPointInStroke(i,e,r)}default:{let n=t.getContext(),i=new Path2D(this.getSVGPathData());return n.isPointInPath(i,e,r)}}}set dataScope(e){this._dataScope=e}get dataScope(){return this._dataScope}get styles(){return this._styles}set styles(e){this._styles=e}set visibility(e){this.styles.visibility=e}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}copyPropertiesTo(e){e.styles=Object.assign({},this.styles),this._dataScope&&(e._dataScope=this._dataScope.clone())}}function x(e){return e instanceof v&&e.type!==Tt.Gridlines}const E=Object.freeze({Area:"area",Rect:"rect",Ellipse:"ellipse",Circle:"circle",Pie:"pie",Ring:"ring",Arc:"arc",Line:"line",Path:"path",Image:"image",PointText:"text",Polygon:"polygon",BezierCurve:"bezierCurve"});function w(e,t,r){const n=document.getElementById(e),i=n.createSVGPoint();i.x=t,i.y=r;const s=i.matrixTransform(n.getScreenCTM().inverse());return[s.x,s.y]}function A(e,t,r,n){return Math.sqrt(Math.pow(e-r,2)+Math.pow(t-n,2))}function C(e,t,r,n,i){const s=i*Math.PI/180,a=e-r,o=t-n;return{x:a*Math.cos(s)-o*Math.sin(s)+r,y:a*Math.sin(s)+o*Math.cos(s)+n}}const R={svg:void 0,getSVG:function(){return window?(void 0===this.svg&&(this.svg=document.createElement("svg")),this.svg):null}},k={canvas:void 0,getCanvas:function(){return window?(void 0===this.canvas&&(this.canvas=document.createElement("canvas")),this.canvas):null},getContext:function(){var e=this.getCanvas();return e?e.getContext("2d"):null}};function S(e,t){let r=P(e),n=t||r;if("vertex"===e.type){return T(e,I(n,[{property:"classId",value:e.parent.classId}]))}if("segment"===e.type){return O(e,I(n,[{property:"classId",value:e.parent.classId}]))}return e.classId?I(n,[{property:"classId",value:e.classId}]):[e]}function T(e,t){if(!e.classId){if(e.dataScope){let r=e.parent;if(!r)throw new Error("vertex has no parent mark");let n=[];if(r.type===Tt.Area){let i=r.vertices.indexOf(e)<r.vertices.length/2;for(let e of t){let t=i?e.vertices.slice(0,e.vertices.length/2):e.vertices.slice(e.vertices.length/2);n=n.concat(t.filter((e=>e.dataScope)))}}else for(let e of t)n=n.concat(e.vertices.filter((e=>e.dataScope)));return n}{let r=e.parent;if(!r)throw new Error("vertex has no parent mark");let n=r.vertices.indexOf(e),i=[];for(let e of t)i.push(e.vertices[n]);return i}}}function O(e,t){if(e.dataScope){if(!e.parent)throw new Error("segment has no parent mark");let r=[];for(let e of t)r=r.concat(e.segments);return r}{let r=e.parent;if(!r)throw new Error("segment has no parent mark");let n=r.segments.indexOf(e),i=[];for(let e of t)i.push(e.segments[n]);return i}}function I(e,t){let r=[];return V(e,t.map((e=>o(e))),r),r}function N(e,t){let r=e.children.filter((e=>e.type==Tt.Collection));if(0!==r.length)for(let e of r){let r=e;for(;r&&r.dataScope;){if(r.dataScope.hasAttribute(t))return r;r=r.children?r.children[0]:void 0}}}function L(e){return e.type==Tt.Collection?e:e.parent?L(e.parent):void 0}function V(e,t,r){if(e&&"axis"!=e.type&&"legend"!=e.type&&"gridlines"!=e.type)if(l(e,t)&&r.push(e),e.vertices)for(let n of e.vertices.concat(e.segments))l(n,t)&&r.push(n);else if(e.children&&e.children.length>0)for(let n of e.children)V(n,t,r)}function P(e){let t=e;for(;t;){if(t.type==Tt.Scene)return t;t=t.parent}}function D(e){let t=e;for("vertex"!=t.type&&"segment"!=t.type||(t=t.parent);t.parent&&[Tt.Collection,Tt.Glyph].includes(t.parent.type);)t=t.parent;return t}function B(e,t,r,n,i){let s=[];n&&s.push({property:"type",value:n}),i&&s.push({property:"classId",value:i});let a=I(e,s);for(let e of a)if(M(e,t,r))return e}function M(e,r,n){switch(e.type){case Tt.Path:case Tt.Arc:case Tt.BezierCurve:case Tt.Line:{let i=t.getContext(),s=new Path2D(e.getSVGPathData());return i.lineWidth=Math.max(e.strokeWidth,2.5),i.stroke(s),e.closed?i.isPointInPath(s,r,n):i.isPointInStroke(s,r,n)}case Tt.Circle:{let t=e.x,i=e.y;if(e.rotation){let r=C(t,i,e.rotation[1],e.rotation[2],e.rotation[0]);t=r.x,i=r.y}return Math.sqrt(Math.pow(r-t,2)+Math.pow(n-i,2))<=e.radius+e.strokeWidth}default:return e.bounds.contains(r,n)}}function G(e,t){let r=[];if(j(e,r),t){let e={};for(let t of r)e[t.classId]=t;return Object.values(e)}return r}function j(e,t){if(x(e))t.push(e);else if(e.type==Tt.Collection&&e.children)for(let r of e.children)j(r,t);else if(e.type==Tt.Glyph&&e.children)for(let r of e.children)j(r,t);else if(e.type==Tt.Composite&&e.children)for(let r of e.children)j(r,t)}class z{constructor(){this._refElements=[]}addRefElement(e){this._refElements.push(e)}get refElements(){return this._refElements}clearRefElements(){this._refElements=[]}}const F=Object.freeze({GRID:"grid",STACK:"stack",PACKING:"packing",FORCE:"force",DIRECTED:"directedgraph",TIDYTREE:"tidytree",TREEMAP:"treemap",STRATA:"strata",CIRCULAR:"circular",CLUSTER:"cluster"});function U(e,t){return!!(e.startsWith("h")&&[p.LEFT,p.CENTER,p.RIGHT].indexOf(t)>=0)||(!!(e.startsWith("v")&&[p.TOP,p.MIDDLE,p.BOTTOM].indexOf(t)>=0)||(console.warn("Invalid alignment:",t),!1))}class H{constructor(e){this._id=e+"_"+It(),this._type=e,this._inputVars=[],this._outputVars=[]}run(){console.log("-",this._type,this.outputVar.element?this.outputVar.element.type:"",this.outputVar.channel?this.outputVar.channel:"")}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 W=Object.freeze({CONDUIT:"conduit",ENCODER:"encoder",LAYOUT:"layout",LINK_PLACER:"linkRouter",CONSTRAINT:"constraint",EVAL_BBOX:"evalBBox",EVAL_REFBOUNDS:"evalRefBounds",AFFIXER:"affixer",ALIGNER:"aligner",DOMAIN_BUILDER:"domainBuilder",SCALE_BUILDER:"scaleBuilder",AXIS_PATH_PLACER:"axisPathPlacer",AXIS_TICKS_PLACER:"axisTicksPlacer",AXIS_LABELS_PLACER:"axisLabelsPlacer",AXIS_TITLE_PLACER:"axisTitlePlacer",GRIDLINES_PLACER:"gridlinesPlacer",GRID_LAYOUT:"gridLayout",STACK_LAYOUT:"stackLayout",PACK_LAYOUT:"packLayout",FORCE_LAYOUT:"forceLayout",DIRECTED_LAYOUT:"directedLayout",TIDY_TREE_LAYOUT:"tidyTreeLayout",TREEMAP_LAYOUT:"treemapLayout",STRATA_LAYOUT:"strataLayout",CIRCULAR_LAYOUT:"circularLayout",CLUSTER_LAYOUT:"clusterLayout",BIN_TRANSFORMER:"binTransformer",FILTER_TRANSFORMER:"filterTransformer",KDE_TRANSFORMER:"kdeTransformer",TARGET_EVALUATOR:"targetEvaluator"});class Y{constructor(e){this._id="v_"+It(),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 H)return e.fromNode;return null}isIsolated(){return 0==this._incomings.length&&0==this._outgoings.length}}const X=Object.freeze({CHANNEL:"channel",PROPERTY:"property",ATTRIBUTE:"attribute",ITEMS:"items",DATASCOPE:"datascope",DOMAIN:"domain",BOUNDS:"bounds",ORDER:"order",SCALE:"scale",COND_ENCODING:"condEncoding",AFFIXATION:"affixation",ALIGNMENT:"alignment",TRIGGER:"trigger"});class q extends Y{constructor(e,t){super(e),this._condEnc=t}get condEncoding(){return this._condEnc}}const K=Object.freeze({RowFirst:"rowFirst",ColumnFirst:"columnFirst"}),Z=Object.freeze({TopLeft:"topLeft",TopRight:"topRight",BottomLeft:"bottomLeft",BottomRight:"bottomRight"}),$={HORIZONTAL:"horizontal",VERTICAL:"vertical",ANGULAR:"angular",RADIAL:"radial"},J={Left2Right:"l2r",Right2Left:"r2l",Top2Bottom:"t2b",Bottom2Top:"b2t"},Q=Object.freeze({CLOCKWISE:"clockwise",ANTI_CLOCKWISE:"anti-clockwise"}),ee=Object.freeze({INWARD:"inward",OUTWARD:"outward"});class te{constructor(e,t,r,n){this.type="vertex",this._id=n,this._x=e,this._y=t,this._dataScope=void 0,this.parent=r,this.shape=void 0,this.width=0,this.height=0,this.radius=0,this.fillColor="#555",this.opacity=1,this.strokeWidth=0,this.strokeColor="#aaa",this._polarAngle=void 0}get dataScope(){return this._dataScope}set dataScope(e){this._dataScope=e}get bounds(){switch(this.shape){case"rect":return new u(this.x-this.width/2,this.y-this.height/2,this.width,this.height);case"circle":return new u(this.x-this.radius,this.y-this.radius,2*this.radius,2*this.radius);default:return new u(this.x-.5,this.y-.5,1,1)}}get id(){return this.parent.id+"_v_"+this._id}_clone(e){let t=new te(this.x,this.y,e,this._id);return this._dataScope&&(t._dataScope=this._dataScope.clone()),t.shape=this.shape,t.width=this.width,t.height=this.height,t.radius=this.radius,t.fillColor=this.fillColor,t.opacity=this.opacity,t.strokeWidth=this.strokeWidth,t.strokeColor=this.strokeColor,t}get polarAngle(){return this._polarAngle}get scene(){return this.parent.scene}get x(){return this._x}get y(){return this._y}}te.styles=["vxShape","vxWidth","vxHeight","vxRadius","vxFillColor","vxStrokeColor","vxStrokeWidth","vxOpacity"];class re{constructor(e,t,r,n){this.type="segment",this._id=n,this.vertex1=e,this.vertex2=t,this.dataScope=void 0,this.parent=r}get id(){return this.parent.id+"_s_"+this._id}get x(){return(this.vertex1.x+this.vertex2.x)/2}get y(){return(this.vertex1.y+this.vertex2.y)/2}get scene(){return this.parent.scene}}class ne extends v{constructor(e){super(e),this._type="type"in e?e.type:Tt.Path,this.vertices=[],this.vertexCounter=0,this._sortBy={},this.segmentCounter=0,this.segments=[],this.anchor=void 0,this.closed=!1,this.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 te.styles)t in e&&(this["_"+t]=e[t]);"vertices"in e&&this._setVertices(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")}_setVertices(e){let t;this.vertices=[],this.segments=[],this.vertexCounter=0,this.segmentCounter=0;for(let r=0;r<e.length;r++)if(r!=e.length-1||e[r][0]!==e[0][0]||e[r][1]!==e[0][1]||this.type!==Tt.Path){t=new te(e[r][0],e[r][1],this,this.vertexCounter++);for(let e of te.styles)if(this[e]){let r=e.replace("vx","");t[r[0].toLowerCase()+r.slice(1)]=this[e]}this.vertices.push(t),r>0&&this.segments.push(new re(this.vertices[r-1],this.vertices[r],this,this.segmentCounter++))}let r=e[0],n=e[e.length-1];(r[0]===n[0]&&r[1]===n[1]||this.type===Tt.Rect)&&(this.closed=!0,"fillColor"in this.styles||(this.styles.fillColor="#fff"),this.segments.push(new re(this.vertices[this.vertices.length-1],this.vertices[0],this,this.segmentCounter++)))}copyPropertiesTo(e){e.attrs=Object.assign({},this.attrs),e.styles=Object.assign({},this.styles);for(let t of te.styles)this["_"+t]&&(e["_"+t]=this["_"+t]);this._dataScope&&(e._dataScope=this._dataScope.clone()),e.closed=this.closed,e.curveMode=this.curveMode,e.vertices=[],e.segments=[];for(let t of this.vertices)e.vertices.push(t._clone(e));e.segmentCounter=0;for(let t=1;t<e.vertices.length;t++)e.segments.push(new re(e.vertices[t-1],e.vertices[t],e,e.segmentCounter++));e.closed&&e.segments.push(new re(e.vertices[e.vertices.length-1],e.vertices[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}get strokeColor(){return this.styles.strokeColor}get strokeWidth(){return this.styles.strokeWidth}get fillColor(){return this.styles.fillColor}set fillColor(e){this.styles.fillColor=e}get strokeDash(){return this.styles.strokeDash}set strokeDash(e){this.styles.strokeDash=e}resize(e,t,r,n){let i=this.bounds,s=0===i.width?1:i.width,a=0===i.height?1:i.height;if("right"===r)for(let t of this.vertices)t._x=i.right-e/s*(i.right-t.x);else for(let t of this.vertices)t._x=i.left+e/s*(t.x-i.left);if("top"===n)for(let e of this.vertices)e._y=i.top+t/a*(e.y-i.top);else for(let e of this.vertices)e._y=i.bottom-t/a*(i.bottom-e.y);this._updateBounds()}_updateBounds(){let e=[],t=[];if(this._d){const r=this._d.match(/[a-zA-Z][^a-zA-Z]*/g),n=" ";r.forEach((r=>{let i=r.slice(1).trim().split(n).map(Number);for(let[r,n]of i.entries())r%2==0?e.push(n):t.push(n)}))}else e=this.vertices.map((e=>e.x)),t=this.vertices.map((e=>e.y));let r=Math.min(...e),n=Math.min(...t),i=Math.max(...e),s=Math.max(...t),a=i-r,o=s-n;if(this._bounds=new u(r,n,a,o),this.type===Tt.Line||this.type===Tt.Path){let e=this.styles.strokeWidth?this.styles.strokeWidth:1;r===i?this._bounds=new u(r-e/2,n,i-r+e,s-n):n===s&&(this._bounds=new u(r,n-e/2,i-r,s-n+e))}}addVertex(e,t,r){let n=new te(e,t,this,this.vertexCounter++);this.vertices.splice(r,0,n)}sortVertices(e,t){this.vertices.sort(((t,r)=>t[e]-r[e])),t&&this.vertices.reverse();for(let e=0;e<this.segments.length;e++){let t=this.segments[e];t.vertex1=this.vertices[e],t.vertex2=this.vertices[(e+1)%this.vertices.length]}}sortVerticesByData(e,t,r){let n;n=r?(t,n)=>r.indexOf(t.dataScope.getValue(e))-r.indexOf(n.dataScope.getAttributeValue(e)):(t,r)=>t.dataScope.getAttributeValue(e)<r.dataScope.getAttributeValue(e)?-1:1,this.vertices.sort(n),t&&this.vertices.reverse();for(let e=0;e<this.segments.length;e++){let t=this.segments[e];t.vertex1=this.vertices[e],t.vertex2=this.vertices[(e+1)%this.vertices.length]}}getSVGPathData(){if(this._d)return this._d;let t=e.path(),r=this._getD3CurveFunction(this.curveMode)(t);r.lineStart();for(let e of this.vertices)r.point(e.x,e.y);return this.closed&&r.point(this.vertices[0].x,this.vertices[0].y),r.lineEnd(),t._}get firstVertex(){return this.vertices[0]}get firstSegment(){return this.segments[0]}get lastVertex(){return this.vertices[this.vertices.length-1]}get lastSegment(){return this.segments[this.segments.length-1]}_getD3CurveFunction(t){switch(t){case ae.Natural:return e.curveNatural;case ae.Basis:return e.curveBasis;case ae.BumpX:return e.curveBumpX;case ae.BumpY:return e.curveBumpY;case ae.Linear:return e.curveLinear;case ae.Step:return e.curveStep;case ae.CatmullRom:return e.curveCatmullRom;case ae.Cardinal:return e.curveCardinal;case ae.Bundle:return e.curveBundle.beta(.5);default:return e.curveLinear}}get vxShape(){return this._vxShape}get vxWidth(){return this._vxWidth}get vxHeight(){return this._vxHeight}get vxRadius(){return this._vxRadius}get vxFillColor(){return this._vxFillColor}get vxStrokeColor(){return this._vxStrokeColor}get vxStrokeWidth(){return this._vxStrokeWidth}get vxOpacity(){return this._vxOpacity}get sourceAnchor(){return this._sourceAnchor}get targetAnchor(){return this._targetAnchor}get sourceOffset(){return this._sourceOffset}get targetOffset(){return this._targetOffset}}function ie(e,t){const r=R.getSVG();let n=document.createElementNS("http://www.w3.org/2000/svg","path");n.setAttribute("d",e.getSVGPathData()),r.appendChild(n);let i=n.getTotalLength();return n.getPointAtLength(i*t)}function se(e){return e instanceof ne&&e.source&&e.target}const ae={Natural:"natural",Basis:"basis",BumpX:"bumpX",BumpY:"bumpY",Bundle:"bundle",Linear:"linear",Step:"step",CatmullRom:"CatmullRom",Cardinal:"cardinal"};function oe(e,t,r){const n=e.match(/[a-zA-Z][^a-zA-Z]*/g),i=",";return n.map((e=>{const n=e[0],s=e.slice(1).trim();if("M"===n||"L"===n||"T"===n){const[e,a]=s.split(i).map(Number);return`${n}${e+t} ${a+r}`}if("C"===n){const e=s.split(i).map(Number);return`${n}${e[0]+t} ${e[1]+r} ${e[2]+t} ${e[3]+r} ${e[4]+t} ${e[5]+r}`}if("Q"===n){const e=s.split(i).map(Number);return`${n}${e[0]+t} ${e[1]+r} ${e[2]+t} ${e[3]+r}`}if("A"===n){const e=s.split(i).map(Number);return`${n}${e[0]} ${e[1]} ${e[2]} ${e[3]} ${e[4]} ${e[5]+t} ${e[6]+r}`}return"Z"===n||"z"===n?n:e})).join(" ")}class le extends ne{constructor(e){super(e),this._type=Tt.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=ue(this._startAngle),this._er=ue(this._endAngle),this._direction="direction"in e?e.direction:Q.ANTI_CLOCKWISE;let t=this._x+this._innerRadius*Math.cos(this._sr),r=this._y-this._innerRadius*Math.sin(this._sr),n=this._x+this._innerRadius*Math.cos(this._er),i=this._y-this._innerRadius*Math.sin(this._er),s=this._x+this._outerRadius*Math.cos(this._sr),a=this._y-this._outerRadius*Math.sin(this._sr),o=this._x+this._outerRadius*Math.cos(this._er),l=this._y-this._outerRadius*Math.sin(this._er);this._setVertices([[t,r],[s,a],[o,l],[n,i]])}get type(){return 0===this._innerRadius?Tt.Pie:Tt.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=ue(this._startAngle),this._er=ue(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)}_updateBounds(){let e=this.vertices.map((e=>e.x)),t=this.vertices.map((e=>e.y)),r=Math.min(...e),n=Math.min(...t),i=Math.max(...e)-r,s=Math.max(...t)-n;this._bounds=new u(r,n,i,s)}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 ue(e){return e*Math.PI/180}function ce(e){return 180*e/Math.PI}function he(e){return(e%360+360)%360}function de(e,t,r,n){let i=e-r,s=n-t;return Math.atan2(s,i)*(180/Math.PI)}class fe{constructor(e){this._attr2value={},this._dt=e,this._tuples=this._dt.data}isFullTable(){return 0===Object.keys(this._attr2value).length}isEmpty(){return 0==this._tuples.length}get numTuples(){return this._tuples.length}get attributes(){return Object.keys(this._attr2value)}get dataTable(){return this._dt}get filters(){return this._attr2value}merge(e){let t=new fe(this._dt);for(let e in this._attr2value)t=t.cross(e,this._attr2value[e]);for(let r in e._attr2value)t=t.cross(r,e._attr2value[r]);return t}cross(e,t){if(e in this._attr2value&&this._attr2value[e]!==t)return console.warn("Conflict in attribute values when merging dataScope:",e,this._attr2value[e],t),this;let r=this.clone();return r._attr2value[e]=t,r._updateTuples(e,t),r}clone(){let e=new fe(this._dt);return e._attr2value=Object.assign({},this._attr2value),e._tuples=this._tuples.map((e=>e)),e}getAttributeValue(e){let t=this.getAttributeValues(e);return t.length,t[0]}getAttributeValues(e){let t=this._tuples.map((t=>t[e]));return t=[...new Set(t)],t}getUniqueAttributeValues(e){let t=this._tuples.map((t=>t[e]));return[...new Set(t)]}hasAttribute(e){return e in this._attr2value}getAttributeType(e){return this._dt.getAttributeType(e)}aggregateNumericalAttribute(t,r){let n=this._tuples.map((e=>e[t]));switch(r){case _e.Max:return Math.max(...n);case _e.Min:return Math.min(...n);case _e.Avg:case _e.Mean:return e.mean(n);case _e.Median:return e.median(n);case _e.Count:return n.length;case _e.Percentile25:return e.quantile(n,.25);case _e.Percentile75:return e.quantile(n,.75);case _e.Sum:default:return e.sum(n)}}_updateTuples(e,t){this._tuples=this._tuples.filter((r=>r[e]==t))}get tuples(){return this._tuples}}function pe(e){return"vertex"==e.type||"segment"==e.type?e.dataScope?e.dataScope:e.parent.dataScope:e.dataScope}const _e={Max:"max",Min:"min",Avg:"avg",Median:"median",Sum:"sum",Count:"count",Mean:"mean",Percentile25:"percentile 25",Percentile75:"percentile 75"};class ge{constructor(e,t){this._id=Tt.TreeData+It(),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 Nt(this._nodeList,"nodes"),this._linkTable=new Nt(this._linkList,"links"),this._nodeTable.tree=this,this._linkTable.tree=this}get nodeTable(){return this._nodeTable}get linkTable(){return this._linkTable}_traverse(e,t,r,n=0){let i={};xe in e||(e[xe]="n"+t.length),t.push(i),e._depth=n;for(let s in e)if("children"==s&&e[s]&&e[s].length>0)for(let i of e[s]){let s=this._traverse(i,t,r,n+1);r.push({parent:e[xe],child:s})}else i[s]=e[s];return this._nodeHash[i[xe]]=i,i[xe]}getNodeDataScope(e){return new fe(this._nodeTable).cross(Vt,e[Vt])}getNode(e){return this._nodeHash[e]}getRoot(){return this._nodeTable.data[0]}getChildren(e){let t=e[xe],r=[],n=this._linkTable.data,i=this._nodeTable.data;for(let e in n)if(n[e].parent==t){let t=n[e].child,s=i.findIndex((e=>e[xe]==t));r.push(i[s])}return r}getParent(e){let t=e[xe],r=this._linkTable.data,n=this._nodeTable.data;for(let e in r)if(r[e].child==t){let t=r[e].parent,i=n.findIndex((e=>e[xe]==t));return n[i]}}}function ye(e){return e.dataScope._dt.tree}class me{constructor(e,t){this._id=Tt.NetworkData+It(),this.initialize(e,t)}initialize(e,t){this.url=t,this._nodeTable=new Nt(e.nodes,this._id+"_nodes"),this._linkTable=new Nt(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[xe]]=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[xe],r=this._rawLinks,n=[];for(let e in r)r[e].target!==t&&r[e].source!==t||n.push(r[e]);return n}buildNodeHierarchy(e){let t={};return t[xe]="root",ve(t,this._rawNodes,e),new ge(t,this.url)}}function be(e){return e.dataScope._dt.graph}function ve(e,t,r){if(0===t.length||0===r.length)return;"children"in e||(e.children=[]);let n={};for(let e of t){let t=e[r[0]];t in n||(n[t]=[]),n[t].push(e)}if(1===r.length)for(let t in n){let r={children:n[t]};r[xe]=t,e.children.push(r)}else for(let t in n){let i={};i[xe]=t,e.children.push(i),ve(i,n[t],r.slice(1))}}const xe="id";function Ee(e,t){if(t.hasAttribute(e))return!0;if(t.tree&&t.tree.nodeTable.hasAttribute(e.split(".")[1]))return!0;throw new Error(["Attribute",e,"does not exist in the table",t.name].join(" "))}const we=Object.freeze({Boolean:"boolean",Integer:"integer",Number:"number",Date:"date",String:"string"});function Ae(e){var t=Object.values(we);for(let r=0;r<e.length;r++){let n=e[r];if(null!=n){for(let e=0;e<t.length;e++)Ce[t[e]](n)||(t.splice(e,1),e-=1);if(1==t.length)return t[0]}}return t[0]}const Ce={boolean:function(e){return"true"===e||"false"===e||!0===e||!1===e||"[object Boolean]"==toString.call(e)},integer:function(e){return Ce.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 Re(t,r){let n={};switch(r){case we.Boolean:n.trueCount=t.filter((e=>e)).length,n.falseCount=t.filter((e=>!e)).length;break;case we.Date:n.min=e.min(t),n.max=e.max(t),n.extent=[n.min,n.max],n.unique=[...new Set(t)];break;case we.String:n.unique=[...new Set(t)];break;default:n.min=e.min(t),n.max=e.max(t),n.extent=[n.min,n.max],n.mean=e.mean(t),n.median=e.median(t),n.unique=[...new Set(t)]}return n}function ke(e,t,r,n,i){let s=i.getAttributeType(r);if(s!=we.String&&s!=we.Date&&s!=we.Number&&s!=we.Integer)throw new Error("Densify only works on a string or date attribute: "+r+" is "+s);if(!function(e){if([Tt.Line,Tt.Circle,Tt.Rect,Tt.Area].indexOf(e.type)<0)return!1;if(e.dataScope){let t=S(e,e.scene);for(let e of t)if(e.dataScope.numTuples>1)return!0;return!1}return!0}(t))throw new Error("The "+t.type+" is not dividable");switch(t.type){case Tt.Line:return function(e,t,r){let n,i,s=S(e);for(let a of s){let s=a.dataScope?a.dataScope:new fe(r),o=r.getUniqueAttributeValues(t).map((e=>s.cross(t,e)));o=o.filter((e=>!e.isEmpty())),1===o.length&&o.push(o[0].clone());let l=Object.assign({},a.styles);for(let e of te.styles)a[e]&&(l[e]=a[e]);let u=a.vertices[0].x,c=a.vertices[0].y,h=[],d=a.vertices[1].x-u,f=a.vertices[1].y-c;for(let e=0;e<o.length;e++)h.push([u+e*d/(o.length-1),c+e*f/(o.length-1)]);l.vertices=h,l.type="path";let p=At(l);i||(i=p.id),p._classId=i,p.dataScope=s,p._updateBounds(),p._refBounds=p.bounds.clone();let _=a.parent;_.addChild(p),_.removeChild(a);for(let[e,t]of p.vertices.entries())t.dataScope?t.dataScope=t.dataScope.merge(o[e]):t.dataScope=o[e];a==e&&(n=p)}return n}(t,r,i);case Tt.Circle:return function(e,t,r,n,i){let s,a,o=S(e),l=r.getAttributeType(t);for(let u of o){let o=u.dataScope?u.dataScope:new fe(r),c=r.getUniqueAttributeValues(t).map((e=>o.cross(t,e)));c=l==we.Number?c:c.filter((e=>!e.isEmpty()));let h=c.length;if(h<3)throw new Error("INSUFFICIENT_DATA_SCOPES");let d=n||90,f=360/h,p=[],_=[],g="clockwise"==(i||"clockwise")?-1:1;for(let e=0;e<c.length;e++){let t=d+g*e*f;_[e]=t;let r=Se(u.x,u.y,u.radius,_[e]);p.push(r)}let y=Object.assign({},u.styles);y.vertices=p,y.type="polygon",y.x=u.x,y.y=u.y,y.radius=u.radius;let m=At(y);a||(a=m.id),m._classId=a,m.dataScope=o;let b=u.parent;b.addChild(m),b.removeChild(u);for(let[e,t]of m.vertices.entries())t._polarAngle=_[e],e>=c.length?t.dataScope=o.merge(c[2*c.length-1-e]):t.dataScope=o.merge(c[e]);u===e&&(s=m)}return s}(t,r,i);case Tt.Rect:return function(e,t,r,n){let i,s,a=S(e),o=t||$.HORIZONTAL;if(o!=$.HORIZONTAL&&o!=$.VERTICAL)throw new Error("Unknown orientation: "+o);for(let t of a){let a=n.getAttributeType(r),l=t.dataScope?t.dataScope:new fe(n),u=n.getUniqueAttributeValues(r).map((e=>l.cross(r,e)));u=a==we.Number?u:u.filter((e=>!e.isEmpty())),1===u.length&&u.push(u[0].clone()),a!=we.Number&&a!=we.Date||u.sort(((e,t)=>e._attr2value[r]>t._attr2value[r]?1:-1));let c=Object.assign({},t.styles),h=t.vertices[0].x,d=t.vertices[0].y,f=t.vertices[t.vertices.length-2].x,_=t.vertices[t.vertices.length-2].y,g=[],y=f-h,m=_-d;for(let e=0;e<u.length;e++)g.push(o==$.VERTICAL?[f,d+e*m/(u.length-1)]:[h+e*y/(u.length-1),d]);for(let e=0;e<u.length;e++)g.push(o==$.VERTICAL?[h,d+(u.length-1-e)*m/(u.length-1)]:[h+(u.length-1-e)*y/(u.length-1),_]);c.vertices=g,c.type="area";let b=At(c);s||(s=b.id),b._classId=s,b.dataScope=l,b.orientation=o,b.baseline=o===$.HORIZONTAL?p.BOTTOM:p.LEFT;let v=t.parent;v.addChild(b),v.removeChild(t);for(let[e,t]of b.vertices.entries())e>=u.length?t.dataScope=l.merge(u[2*u.length-1-e]):t.dataScope=l.merge(u[e]);t===e&&(i=b)}return i}(t,n,r,i)}}function Se(e,t,r,n){return[r*Math.cos(ue(n))+e,t-r*Math.sin(ue(n))]}class Te extends Y{constructor(e,t,r){super(e),this._channel=t,this._elem=r}get channel(){return this._channel}get element(){return this._elem}}const Oe=Object.freeze({X:"x",Y:"y",WIDTH:"width",HEIGHT:"height",RADIUS:"radius",FILLCOLOR:"fillColor",STROKECOLOR:"strokeColor",FILLGRADIENT:"fillGradient",TEXT:"text",ANGLE:"angle",THICKNESS:"thickness",AREA:"area",FONTSIZE:"fontSize",RADIALDISTANCE:"radialDistance",STROKEWIDTH:"strokeWidth",OPACITY:"opacity",VISIBILITY:"visibility",STRENGTH:"strength",SRC:"src"});function Ie(e,t){delete t._encodings[Pe(e.element)][e.channel]}function Ne(e,t){let r=e.scene._encodings[Pe(e)],n=[];if(r&&(n=n.concat(Object.values(r))),t){let t=e.scene;for(let r in t._encodings){let i=r.split("_");i.pop(),i.join("_")===e.classId&&(n=n.concat(Object.values(t._encodings[r])))}}return n}function Le(e,t,r){for(let n in r._encodings){let i=r._encodings[n];if(i[t]&&i[t].attribute==e)return i[t]}return null}function Ve(e,t){let r=e.scene._encodings[Pe(e)];return r&&r[t]?r[t]:null}function Pe(e){if(e.classId)return e.classId;if("vertex"==e.type&&e.dataScope){if(e.parent.type===Tt.Area){let t=e.parent.vertices.indexOf(e)<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.parent.vertices.indexOf(e):"segment"==e.type&&e.dataScope?e.parent.classId+"_s":"segment"==e.type?e.parent.classId+"_s"+e.parent.segments.indexOf(e):null}function De(e,t){if(0==e.children.length)return[];let r=P(e),n=e.type===Tt.Composite?e.children:[e.children[0]],i=Object.keys(r._encodings),s=[];for(let e of n){let t=e;for(;t;){if(t.classId&&s.indexOf(t.classId)<0&&s.push(t.classId),t.type===Tt.Glyph){t.children.forEach((e=>s.push(e.classId)));break}if(!t.children)break;t=t.children[0]}}let a=[];for(let e of i)for(let n of s)0===e.indexOf(n)&&r._encodings[e][t]&&a.push(r._encodings[e][t]);return a}function Be(e){let t=Ve(e,"y"),r=Ve(e,"height");return t||r&&r.scales[0].domain[0]<0}function Me(e){let t=Ve(e,"x"),r=Ve(e,"width");return t||r&&r.scales[0].domain[0]<0}function Ge(e,t){let r=function(e){let t=e.parent,r=[];for(;t.type!==Tt.Scene;)r.push(t),t=t.parent;return r}(e);for(let e of r)if(Ve(e,t))return!1;return r.length>=2?r[r.length-2]:e}function je(e,t,r){switch(e.type){case Tt.Rect:case Tt.Path:case Tt.Line:case Tt.Area:!function(e,t,r){for(let n of e.vertices)ze(n,t,r);e._updateBounds(),e._refBounds&&e._refBounds.translate(t,r)}(e,t,r);break;case Tt.Group:case Tt.Collection:case Tt.Glyph:!function(e,t,r){for(let n of e.children)je(n,t,r);e._layout&&(void 0!==e._layout._left&&(e._layout._left+=t),void 0!==e._layout._top&&(e._layout._top+=r),e._layout._cellBounds&&e._layout._cellBounds.forEach((e=>e.translate(t,r))))}(e,t,r);break;case"segment":!function(e,t,r){ze(e.vertex1,t,r),ze(e.vertex2,t,r)}(e,t,r);break;default:!function(e,t,r){e._x+=t,e._y+=r,e._updateBounds(),e._refBounds&&e._refBounds.translate(t,r)}(e,t,r)}}function ze(e,t,r){e._x+=t,e._y+=r}function Fe(e,t,r){switch(t){case"x":He(e,r);break;case"y":We(e,r);break;case"width":!function(e,t){e.resize(t,e.height)}(e,r);break;case"height":!function(e,t){e.resize(e.width,t)}(e,r);break;case"radius":e.radius=r;break;case"strength":e._strength=r;break;case"area":e.type===Tt.Circle?e.radius=Math.sqrt(r/Math.PI):e.type===Tt.Rect&&e.resize(Math.sqrt(r),Math.sqrt(r)),e._updateBounds();break;case"text":e._text=r;break;case"curveMode":e.curveMode=r;break;case"baseline":e.baseline=r;break;case"angle":[Tt.Arc,Tt.Pie].includes(e.type)&&function(e,t){e._endAngle=he(e._startAngle+t),e._sr=ue(e._startAngle),e._er=ue(e._endAngle),e.vertices[0]._x=e._x+e._innerRadius*Math.cos(e._sr),e.vertices[0]._y=e._y-e._innerRadius*Math.sin(e._sr),e.vertices[1]._x=e._x+e._outerRadius*Math.cos(e._sr),e.vertices[1]._y=e._y-e._outerRadius*Math.sin(e._sr),e.vertices[2]._x=e._x+e._outerRadius*Math.cos(e._er),e.vertices[2]._y=e._y-e._outerRadius*Math.sin(e._er),e.vertices[3]._x=e._x+e._innerRadius*Math.cos(e._er),e.vertices[3]._y=e._y-e._innerRadius*Math.sin(e._er)}(e,r);break;case"startAngle":!function(e,t){let r=e.angle;e._startAngle=t,e._endAngle=he(e._startAngle+r),e._sr=ue(e._startAngle),e._er=ue(e._endAngle),e.vertices[0]._x=e._x+e._innerRadius*Math.cos(e._sr),e.vertices[0]._y=e._y-e._innerRadius*Math.sin(e._sr),e.vertices[1]._x=e._x+e._outerRadius*Math.cos(e._sr),e.vertices[1]._y=e._y-e._outerRadius*Math.sin(e._sr),e.vertices[2]._x=e._x+e._outerRadius*Math.cos(e._er),e.vertices[2]._y=e._y-e._outerRadius*Math.sin(e._er),e.vertices[3]._x=e._x+e._innerRadius*Math.cos(e._er),e.vertices[3]._y=e._y-e._innerRadius*Math.sin(e._er)}(e,r);break;case"thickness":!function(e,t){Ue(e,e._innerRadius+t)}(e,r);break;case"innerRadius":!function(e,t){e._innerRadius=t,e.vertices[0]._x=e._x+e._innerRadius*Math.cos(e._sr),e.vertices[0]._y=e._y-e._innerRadius*Math.sin(e._sr),e.vertices[3]._x=e._x+e._innerRadius*Math.cos(e._er),e.vertices[3]._y=e._y-e._innerRadius*Math.sin(e._er)}(e,r);break;case"outerRadius":Ue(e,r);break;case"radialDistance":{let t=Se(e.parent.x,e.parent.y,r,e.polarAngle);He(e,t[0]),We(e,t[1]);break}case"visibility":e.visibility=r;break;case"src":e.src=r;break;default:if("vertex"===e.type)e[t]=r;else if(e instanceof pt)for(let n of e.children)Fe(n,t,r);else e.styles[t]=r}}function Ue(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 He(e,t){"vertex"==e.type?e._x=t:je(e,t-e.x,0)}function We(e,t){"vertex"==e.type?e._y=t:je(e,0,t-e.y)}class Ye extends ne{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}resize(e,t,r,n){e!==this.width&&("right"===r?(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"===n?(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))}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 Xe extends ne{constructor(e){super(e),this._type=Tt.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 re(this.vertices[this.vertices.length-1],this.vertices[0],this,this.segmentCounter++))}get topLeftVertex(){return this._orientation===$.HORIZONTAL?this.vertices[0]:this.vertices[this.vertices.length-1]}get bottomLeftVertex(){return this._orientation===$.HORIZONTAL?this.vertices[this.vertices.length-1]:this.vertices[this.vertices.length/2]}get topRightVertex(){return this._orientation===$.HORIZONTAL?this.vertices[this.vertices.length/2-1]:this.vertices[0]}get bottomRightVertex(){return this._orientation===$.HORIZONTAL?this.vertices[this.vertices.length/2]:this.vertices[this.vertices.length/2-1]}get baseline(){return this._baseline}set baseline(e){this._baseline=e}get orientation(){return this._orientation}set orientation(e){this._orientation=e}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 qe extends Y{constructor(e,t){super(e),this._encs=[t],this._initialized=!1}addLinkedEncoding(e){this._encs.push(e)}get encodings(){return this._encs}get initialized(){return this._initialized}set initialized(e){this._initialized=e}}class Ke{constructor(e,t){this._event=t,this._type=e}get event(){return this._event}get type(){return this._type}}const Ze=Object.freeze({ELEMENT:"element",MOUSE:"mouse",ATTRIBUTE:"attribute",WIDGET:"widget",KEYBOARD:"keyboard"});Object.freeze({INPUT:"input",HOVER:"hover",BRUSH:"brush",BRUSH_X:"brushX",BRUSH_Y:"brushY",CLICK:"click"});class $e extends H{constructor(e){super(e)}storeValues(e,t){this._storedValues={};let r=S(e);for(let e of r)this._storedValues[e.id]=e[t]}_restoreValues(e){let t=this.outputVar.channel;e.forEach((e=>{e.styles[t]=this._storedValues[e.id]}))}run(){super.run();let e=this.inputVars.find((e=>e instanceof qe)),t=this.outputVar,r=S(t.element);if(e){let r=e.encodings.find((e=>e.channel==t.channel&&Pe(e.element)==Pe(t.element)));for(let e of r.scales){let t=r.getElements(e);this._doMapping(t,e,r.attrValues,r),this._updateRefBounds(t,e,r)}}else this._restoreValues(r);let n=this._getUsableCondEncodings();n.length>0&&this._doCondEncoding(r,n.map((e=>e.condEncoding))),f(["vertex","segment"].includes(t.element.type)?t.element.parent:t.element)}_updateRefBounds(e,t,r){switch(this.outputVar.channel){case"width":e.forEach((e=>{e._refBounds.setWidth(t.rangeExtent)}));break;case"height":e.forEach((e=>{e._refBounds.setHeight(t.rangeExtent)}));break;case"radius":e.forEach((e=>{e._refBounds.setWidth(2*t.rangeExtent,p.CENTER),e._refBounds.setHeight(2*t.rangeExtent,p.MIDDLE)}));break;case"x":"vertex"!=e[0].type&&"segment"!=e[0].type||e.forEach((e=>{let n=e.parent._refBounds;e.parent._refBounds=new u(r.flipScale?t.range[1]:t.range[0],n.top,t.rangeExtent,n.height)}));break;case"y":"vertex"!=e[0].type&&"segment"!=e[0].type||e.forEach((e=>{let n=e.parent._refBounds;e.parent._refBounds=new u(n.left,r.flipScale?t.range[0]:t.range[1],n.width,t.rangeExtent)}))}}_doMapping(e,t,r,n){switch(this.outputVar.channel){case"width":t.domain[0]<0&&e[0]instanceof Ye?function(e,t,r){for(let n=0;n<e.length;n++){let i=e[n],s=i.refBounds.left+t.map(0),a=i.refBounds.left+t.map(r[i.id]);je(i.leftSegment,s-i.leftSegment.x,0),je(i.rightSegment,a-i.rightSegment.x,0)}}(e,t,r):t.domain[0]<0&&e[0]instanceof Xe||(e[0].type===Tt.Area?function(e,t,r){let n=e[0].baseline;if(e[0].orientation===$.VERTICAL)switch(n){case"left":for(let n of e)S(n.topLeftVertex,n).forEach((e=>Fe(e,"x",n.refBounds.left))),S(n.topRightVertex,n).forEach((e=>Fe(e,"x",n.refBounds.left+t.map(r[e.id]))));break;case"right":for(let n of e)S(n.topLeftVertex,n).forEach((e=>Fe(e,"x",n.refBounds.right-t.map(r[e.id])))),S(n.topRightVertex,n).forEach((e=>Fe(e,"x",n.refBounds.right)));break;case"center":console.log("center");for(let n of e)S(n.topLeftVertex,n).forEach((e=>Fe(e,"x",n.refBounds.center-t.map(r[e.id])/2))),S(n.topRightVertex,n).forEach((e=>Fe(e,"x",n.refBounds.center+t.map(r[e.id])/2)))}}(e,t,r):this._doStandardMapping(e,t,r));break;case"height":t.domain[0]<0&&e[0]instanceof Ye?function(e,t,r){for(let n=0;n<e.length;n++){let i=e[n],s=i.refBounds.bottom-t.map(0),a=i.refBounds.bottom-t.map(r[i.id]);je(i.bottomSegment,0,s-i.bottomSegment.y),je(i.topSegment,0,a-i.topSegment.y)}}(e,t,r):t.domain[0]<0&&e[0]instanceof Xe?function(e,t,r){for(let n of e){let e=T(n.topLeftVertex,[n]);for(let i of e)Fe(i,"y",n.refBounds.bottom-t.map(r[i.id]));T(n.bottomLeftVertex,[n]).forEach((e=>Fe(e,"y",n.refBounds.bottom-t.map(0))))}}(e,t,r):e[0].type===Tt.Area?function(e,t,r){let n=e[0].baseline;if(e[0].orientation===$.HORIZONTAL)switch(n){case"bottom":for(let n of e)S(n.topLeftVertex,n).forEach((e=>Fe(e,"y",n.refBounds.bottom-t.map(r[e.id])))),S(n.bottomLeftVertex,n).forEach((e=>Fe(e,"y",n.refBounds.bottom)));break;case"top":for(let n of e)S(n.bottomLeftVertex,n).forEach((e=>Fe(e,"y",n.refBounds.top+t.map(r[e.id])))),S(n.topLeftVertex,n).forEach((e=>Fe(e,"y",n.refBounds.top)));break;case"middle":for(let n of e)S(n.topLeftVertex,n).forEach((e=>Fe(e,"y",n.refBounds.middle-t.map(r[e.id])/2))),S(n.bottomLeftVertex,n).forEach((e=>Fe(e,"y",n.refBounds.middle+t.map(r[e.id])/2)))}}(e,t,r):this._doStandardMapping(e,t,r);break;case"text":this._doTextMapping(e,r);break;case"fillGradient":!function(e,t,r,n){for(let i of e){let e=i.vertices.map((e=>r[e.id])),s=Math.min(...e),a=Math.max(...e),o="horizontal"===i.orientation?new b({x1:0,y1:100,x2:0,y2:0}):new b({x1:0,y1:0,x2:100,y2:0});if(o.addStop(0,t.map(s),1),n._mapping){let e=Object.keys(n._mapping).map((e=>parseFloat(e))).sort();for(let r of e)r>s&&r<a&&o.addStop(100*(r-s)/(a-s),t.map(r),1)}else"divergingColor"===t.type&&o.addStop(100*-s/(a-s),t.map(0),1);"sequentialColor"===t.type&&o.addStop(100*-s/(a-s),t.map(0),1),o.addStop(100,t.map(a),1),i.fillColor=o}}(e,t,r,n);break;default:this._doStandardMapping(e,t,r)}}_doTextMapping(e,t){let r=this.outputVar.channel;e.forEach((e=>{Fe(e,r,t[e.id])}))}_doStandardMapping(e,t,r){let n=this.outputVar.channel;e.forEach((e=>{let i=t.map(r[e.id]);Fe(e,n,i),e instanceof ne&&e.firstVertex&&e.firstVertex.shape&&"strokeColor"===n&&e.vertices.forEach((e=>e.fillColor=i))}))}_doCondEncoding(e,t){for(let r of e){let e=t.map((e=>e.evalResult[r.id])).every((e=>e||void 0===e));t[0]._efxFn(e,t[0].trigger.elements[0],r,t[0].trigger.mouseEvent)}}_updateElement(e,t,r,n){let i;"object"==typeof n&&e.triggerElement?"property"in n?i=e.triggerElement[n.property]:"attribute"in n&&(i=e.triggerElement.dataScope.getAttributeValue(n.attribute)):i=n,["x","y"].includes(r)&&"offset"in n&&(i+=n.offset),Fe(t,r,i)}_getUsableCondEncodings(){return this.inputVars.filter((e=>e instanceof q))}}class Je extends Y{constructor(e,t,r){super(e),this._property=t,this._elem=r}get property(){return this._property}get element(){return this._elem}}const Qe=Object.freeze({AXIS_ORIENTATION:"axisOrientation",AXIS_PATH_POSITION:"axisPathPosition",AXIS_TICK_SIZE:"axisTickSize",AXIS_TICK_OFFSET:"axisTickOffset",AXIS_TICKS_POSITION:"axisTicksPosition",AXIS_LABELS_POSITION:"axisLabelsPosition",AXIS_TITLE_POSITION:"axisTitlePosition",AXIS_LABEL_OFFSET:"axisLabelOffset",AXIS_LABEL_FORMAT:"axisLabelFormat",AXIS_FONT_SIZE:"axisFontSize",LEGEND_POSITION:"legendPosition",GRIDLINES_POSITION:"gridlinesPosition",INCLUDE_ZERO:"includeZero",FLIP_SCALE:"flipScale",RANGE_START:"rangeStart",RANGE_EXTENT:"rangeExtent",BASE_LINE:"baseline"});function et(e,t){let r=t.getVariable(X.BOUNDS,e),n=t.createOneWayDependency(W.EVAL_BBOX);switch(t.connect(n,r),e.type){case Tt.Circle:case Tt.Polygon:{let r=t.getVariable(X.CHANNEL,"x",e),i=t.getVariable(X.CHANNEL,"y",e),s=t.getVariable(X.CHANNEL,"radius",e),a=t.getVariable(X.CHANNEL,"area",e);t.connect(s,n),t.connect(r,n),t.connect(i,n),t.connect(a,n);break}case Tt.Area:case Tt.Line:case Tt.BezierCurve:case Tt.Path:case Tt.Image:{let r=t.getVariable(X.CHANNEL,"x",e),i=t.getVariable(X.CHANNEL,"y",e),s=t.getVariable(X.CHANNEL,"width",e),a=t.getVariable(X.CHANNEL,"height",e);t.connect(r,n),t.connect(i,n),t.connect(s,n),t.connect(a,n);break}case Tt.Rect:{let r=t.getVariable(X.CHANNEL,"x",e),i=t.getVariable(X.CHANNEL,"y",e),s=t.getVariable(X.CHANNEL,"width",e),a=t.getVariable(X.CHANNEL,"height",e),o=t.getVariable(X.CHANNEL,"area",e);t.connect(r,n),t.connect(i,n),t.connect(s,n),t.connect(a,n),t.connect(o,n);break}case Tt.PointText:{let r=t.getVariable(X.CHANNEL,"x",e),i=t.getVariable(X.CHANNEL,"y",e),s=t.getVariable(X.CHANNEL,"text",e);t.connect(r,n),t.connect(i,n),t.connect(s,n);break}case Tt.Ring:{let r=t.getVariable(X.CHANNEL,"x",e),i=t.getVariable(X.CHANNEL,"y",e),s=t.getVariable(X.CHANNEL,"innerRadius",e),a=t.getVariable(X.CHANNEL,"outerRadius",e);t.connect(r,n),t.connect(i,n),t.connect(s,n),t.connect(a,n);break}case Tt.Pie:case Tt.Arc:{let r=t.getVariable(X.CHANNEL,"x",e),i=t.getVariable(X.CHANNEL,"y",e),s=t.getVariable(X.CHANNEL,"innerRadius",e),a=t.getVariable(X.CHANNEL,"outerRadius",e),o=t.getVariable(X.CHANNEL,"startAngle",e),l=t.getVariable(X.CHANNEL,"endAngle",e),u=t.getVariable(X.CHANNEL,"angle",e),c=t.getVariable(X.CHANNEL,"thickness",e);t.connect(r,n),t.connect(i,n),t.connect(s,n),t.connect(a,n),t.connect(o,n),t.connect(l,n),t.connect(u,n),t.connect(c,n);break}}n.run()}function tt(e,t){let r=t.findVariablesByElement(e);for(let e in r){let n=r[e];for(let e of n)t.deleteVariable(e)}}function rt(e,t){let r=t.findVariable(X.CHANNEL,[e.channel,e.element]);r||console.warn("cannot find encoding to remove from the dep graph");let n=r.incomingDataflow;t.deleteOperator(n)}function nt(e,t){if(e.type===Tt.Axis){let r=t.findVariable(X.PROPERTY,[Qe.AXIS_PATH_POSITION,e]).incomingDataflow;t.deleteOperator(r),r=t.findVariable(X.PROPERTY,[Qe.AXIS_TICKS_POSITION,e]).incomingDataflow,t.deleteOperator(r),r=t.findVariable(X.PROPERTY,[Qe.AXIS_LABELS_POSITION,e]).incomingDataflow,t.deleteOperator(r)}else if(e.type===Tt.Gridlines){let r=t.findVariable(X.PROPERTY,[Qe.GRIDLINES_POSITION,e]).incomingDataflow;t.deleteOperator(r)}}function it(e,t){let r=t.getVariable(X.BOUNDS,e),n=t.getVariable(X.CHANNEL,"x",e),i=t.getVariable(X.CHANNEL,"y",e),s=t.getVariable(X.CHANNEL,"width",e),a=t.getVariable(X.CHANNEL,"height",e),o=t.createOneWayDependency(W.EVAL_BBOX);t.connect(n,o),t.connect(i,o),t.connect(s,o),t.connect(a,o),t.connect(o,r),o.run()}function st(e,t,r){let n=r.getVariable(X.BOUNDS,e),i=r.getVariable(X.BOUNDS,t),s=r.getIncomingDataflowOperator(W.EVAL_BBOX,n),a=i.outgoingEdges.find((e=>e.fromNode===i&&e.toNode===s));if(a&&r.disconnect(i,s,a),e.layout){let n=r.getVariable(X.CHANNEL,"x",t),i=r.getIncomingDataflowOperator(ot(e.layout.type),n);i&&r.deleteOperator(i)}}function at(e,t,r){let n=r.getVariable(X.BOUNDS,e),i=r.getVariable(X.BOUNDS,t),s=r.getIncomingDataflowOperator(W.EVAL_BBOX,n);r.connect(i,s),r.connect(s,n),e.layout&&ut(e,e.layout,r)}function ot(e){switch(e){case F.GRID:return W.GRID_LAYOUT;case F.STACK:return W.STACK_LAYOUT;case F.PACKING:return W.PACK_LAYOUT;case F.FORCE:return W.FORCE_LAYOUT;case F.DIRECTED:return W.DIRECTED_LAYOUT;case F.TIDYTREE:return W.TIDY_TREE_LAYOUT;case F.TREEMAP:return W.TREEMAP_LAYOUT;case F.STRATA:return W.STRATA_LAYOUT;case F.CIRCULAR:return W.CIRCULAR_LAYOUT;case F.CLUSTER:return W.CLUSTER_LAYOUT}}function lt(e,t,r){let n=r.getVariable(X.ORDER,e),i=r.getOutgoingDataflowOperator(ot(t.type),n);r.deleteOperator(i)}function ut(e,t,r){let n=t?t.type:"none",i=n===F.TREEMAP?G(e)[0]:e.children[0];if(!i)return;let s=r.getVariable(X.CHANNEL,"width",i),a=r.getVariable(X.CHANNEL,"height",i),o=r.getVariable(X.ORDER,e),l=r.getVariable(X.CHANNEL,"x",i),u=r.getVariable(X.CHANNEL,"y",i),c=r.getOutgoingDataflowOperator(ot(n),o);if(r.connect(s,c),r.connect(a,c),r.connect(o,c),r.connect(c,l),r.connect(c,u),r.disconnectChannelVarFromBBoxOperator(s),r.disconnectChannelVarFromBBoxOperator(a),i.type===Tt.Arc||i.type===Tt.Pie){let e=r.getVariable(X.CHANNEL,"angle",i),t=r.getVariable(X.CHANNEL,"thickness",i);r.connect(e,c),r.connect(t,c)}else if(i.type===Tt.Circle){let e=r.getVariable(X.CHANNEL,"area",i),t=r.getVariable(X.CHANNEL,"radius",i);r.connect(e,c),r.connect(t,c),r.disconnectChannelVarFromBBoxOperator(e),r.disconnectChannelVarFromBBoxOperator(t)}else if(i.type===Tt.Rect){let e=r.getVariable(X.CHANNEL,"area",i);r.connect(e,c),r.disconnectChannelVarFromBBoxOperator(e)}if(c.run(),i.links&&ct(i,r),i.children&&i.children[0]){let e=r.getVariable(X.BOUNDS,i.children[0]),t=r.getVariable(X.CHANNEL,"x",i).incomingDataflow;t&&r.connect(e,t),r.disconnectChannelVarFromBBoxOperator(e)}}function ct(e,t){let r=e.links[0],n=t.getVariable(X.CHANNEL,"x",e),i=t.getVariable(X.CHANNEL,"x",r),s=t.getVariable(X.CHANNEL,"strokeWidth",r),a=t.getVariable(X.CHANNEL,"strength",r),o=t.createOneWayDependency(W.LINK_PLACER);t.connect(n,o),t.connect(s,o),t.connect(a,o),t.connect(o,i)}function ht(e,t){let r=t.getVariable(X.PROPERTY,Qe.AXIS_ORIENTATION,e),n=t.getVariable(X.BOUNDS,e.elements[0].parent),i=t.getVariable(X.PROPERTY,Qe.AXIS_PATH_POSITION,e),s=t.createOneWayDependency(W.AXIS_PATH_PLACER);t.connect(r,s),t.connect(n,s),t.connect(s,i),s.run();let a=t.getVariable(X.PROPERTY,Qe.AXIS_TICK_OFFSET,e),o=t.getVariable(X.PROPERTY,Qe.AXIS_TICK_SIZE,e),l=t.createOneWayDependency(W.AXIS_TICKS_PLACER),u=t.getVariable(X.PROPERTY,Qe.AXIS_TICKS_POSITION,e);t.connect(i,l),t.connect(a,l),t.connect(o,l),t.connect(l,u),l.run();let c=t.getVariable(X.PROPERTY,Qe.AXIS_LABEL_OFFSET,e),h=t.getVariable(X.PROPERTY,Qe.AXIS_LABEL_FORMAT,e),d=t.getVariable(X.PROPERTY,Qe.AXIS_FONT_SIZE,e),f=t.createOneWayDependency(W.AXIS_LABELS_PLACER),p=t.getVariable(X.PROPERTY,Qe.AXIS_LABELS_POSITION,e);t.connect(i,f),t.connect(c,f),t.connect(h,f),t.connect(d,f),t.connect(f,p),f.run();let _=t.getVariable(X.PROPERTY,Qe.AXIS_TITLE_POSITION,e),g=t.createOneWayDependency(W.AXIS_TITLE_PLACER);t.connect(i,g),t.connect(g,_),g.run();let y=t.getVariable(X.BOUNDS,e),m=t.getIncomingDataflowOperator(W.EVAL_BBOX,y);t.connect(u,m),t.connect(p,m),t.connect(m,y)}function dt(e,t){let r=t.getVariable(X.PROPERTY,Qe.AXIS_ORIENTATION,e),n=t.getVariable(X.BOUNDS,D(e.elements[0])),i=t.getVariable(X.PROPERTY,Qe.AXIS_PATH_POSITION,e),s=t.createOneWayDependency(W.AXIS_PATH_PLACER);t.connect(r,s),t.connect(n,s),t.connect(s,i),s.run();let a=t.getVariable(X.PROPERTY,Qe.AXIS_TICK_OFFSET,e),o=t.getVariable(X.PROPERTY,Qe.AXIS_TICK_SIZE,e),l=t.createOneWayDependency(W.AXIS_TICKS_PLACER),u=t.getVariable(X.PROPERTY,Qe.AXIS_TICKS_POSITION,e);t.connect(i,l),t.connect(a,l),t.connect(o,l),t.connect(l,u),l.run();let c=t.getVariable(X.PROPERTY,Qe.AXIS_LABEL_OFFSET,e),h=t.getVariable(X.PROPERTY,Qe.AXIS_LABEL_FORMAT,e),d=t.getVariable(X.PROPERTY,Qe.AXIS_FONT_SIZE,e),f=t.createOneWayDependency(W.AXIS_LABELS_PLACER),p=t.getVariable(X.PROPERTY,Qe.AXIS_LABELS_POSITION,e);t.connect(i,f),t.connect(c,f),t.connect(h,f),t.connect(d,f),t.connect(f,p),f.run();let _=t.getVariable(X.PROPERTY,Qe.AXIS_TITLE_POSITION,e),g=t.createOneWayDependency(W.AXIS_TITLE_PLACER);t.connect(i,g),t.connect(g,_),g.run();let y=t.getVariable(X.BOUNDS,e),m=t.getIncomingDataflowOperator(W.EVAL_BBOX,y);t.connect(u,m),t.connect(p,m),t.connect(m,y)}function ft(e,t){let r=t.getVariable(X.BOUNDS,D(e.elements[0])),n=t.getVariable(X.PROPERTY,Qe.GRIDLINES_POSITION,e),i=t.createOneWayDependency(W.GRIDLINES_PLACER);t.connect(r,i),t.connect(i,n),i.run();let s=t.getVariable(X.BOUNDS,e),a=t.getIncomingDataflowOperator(W.EVAL_BBOX,s);t.connect(n,a),t.connect(a,s)}class pt{constructor(){this._id=this.type+It(),this._type=Tt.Group,this._dataScope=void 0,this._bounds=void 0,this._layout=void 0,this._children=[],this._sortBy={}}get id(){return this._id}get type(){return this._type}contains(e,t){return this.bounds.contains(e,t)}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._dataScope}set dataScope(e){if(this._dataScope=e,void 0===e)for(let t of this.children)t.dataScope=e;else for(let t of this.children)t.dataScope?t.dataScope=t.dataScope.merge(e):t.dataScope=e}getInternalEncodings(e){if(0==this.children.length)return[];let t=this.children[0],r=this.getScene(),n=Object.keys(r.encodings),i=[];for(;t;){if(t.classId&&i.indexOf(t.classId)<0&&i.push(t.classId),t.type===Tt.Glyph){t.children.forEach((e=>i.push(e.classId)));break}if(!t.children)break;t=t.children[0]}let s=[];for(let t of n){let n=t.split("_");for(let a of i)n[0]==a&&r.encodings[t][e]&&s.push(r.encodings[t][e])}return s}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),ut(this,e,this.scene._depGraph),this.children&&this.children.length>0){let e=G(this,!0);for(let t of e)this.scene.onChange(X.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=Math.min(...e.map((e=>e.left))),r=Math.min(...e.map((e=>e.top))),n=Math.max(...e.map((e=>e.right))),i=Math.max(...e.map((e=>e.bottom)));return new u(t,r,n-t,i-r)}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 u(0,0,0,0)}set visibility(e){this._visibility="hidden"==e?e:"visible";for(let t of this.children)t.visibility=e}get visibility(){return this._visibility?this._visibility:"visible"}get scene(){return P(this)}}class _t extends pt{constructor(){super(),this._type=Tt.Collection,this._id=this.type+"_"+It(),this._classId=this.id,this._childrenOrder=void 0}get classId(){return this._classId}contains(e,r){if([Tt.Arc,Tt.Pie,Tt.Polygon,Tt.Area].indexOf(this.firstChild.type)>=0){let n=this.getSVGPathData();if(""!==n){let i=t.getContext(),s=new Path2D(n);return i.lineWidth=Math.max(this.strokeWidth,2.5),i.stroke(s),i.isPointInPath(s,e,r)}}return this._bounds.contains(e,r)}getSVGPathData(){let e="";for(let t of this.children)if(t.getSVGPathData)e+=t.getSVGPathData();else if(t.bounds){let r=t.bounds;e+=["M",r.left,r.top].join(" "),e+=["L",r.right,r.top].join(" "),e+=["L",r.right,r.bottom].join(" "),e+=["L",r.left,r.bottom,"Z"].join(" ")}return e}}class gt extends pt{constructor(e){if(super(),this._type=Tt.Glyph,this._id=this.type+"_"+It(),this._classId=this._id,e)for(let t of e)this.addChild(t)}get classId(){return this._classId}}class yt extends ne{constructor(e){super(e),this._type=Tt.BezierCurve,this._orientation="orientation"in e?e.orientation:$.HORIZONTAL}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 mt extends v{constructor(e){super(e),this._type=Tt.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")}get x(){return this._x}get y(){return this._y}get radius(){return this._radius}set radius(e){this._radius=e}get area(){return Math.PI*Math.pow(this._radius,2)}_updateBounds(){if(this._rotate){let e=C(this._x,this._y,this._rotate[1],this._rotate[2],this._rotate[0]);this._bounds=new u(e.x-this._radius,e.y-this._radius,2*this._radius,2*this._radius)}else this._bounds=new u(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 bt extends v{constructor(e){super(e),this._type=Tt.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}get width(){return this._width}set width(e){this._width=e,this._updateBounds()}get height(){return this._height}set height(e){this._height=e,this._updateBounds()}resize(e,t){this._width=e,this._height=t,this._updateBounds()}get x(){return this._x}set x(e){this._x=e,this._updateBounds()}get y(){return this._y}set y(e){this._y=e,this._updateBounds()}get bounds(){return this._bounds||this._updateBounds(),this._bounds}_updateBounds(){this._bounds=new u(this._x,this._y,this._width,this._height)}copyPropertiesTo(e){e.attrs=Object.assign({},this.attrs),e.styles=Object.assign({},this.styles),this._dataScope&&(e._dataScope=this._dataScope.clone()),e.x=this._x,e.y=this._y,e.width=this._width,e.height=this._height,e.src=this._src}}class vt extends ne{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}set y(e){let t=e-this.y;this.vertices[0]._y+=t,this.vertices[1]._y+=t}set x1(e){this.vertices[0]._x=e}set x2(e){this.vertices[1]._x=e}set y1(e){this.vertices[0]._y=e}set y2(e){this.vertices[1]._y=e}}class xt extends v{constructor(e){super(e),this._type=Tt.PointText,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:[p.CENTER,p.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,r=function(e,t,r){let n=k.getContext();n.font=t;let i=n.measureText(e);return i.fontBoundingBoxAscent?{width:i.width,height:i.fontBoundingBoxAscent+i.fontBoundingBoxDescent}:i.actualBoundingBoxAscent?{width:i.width,height:i.actualBoundingBoxAscent+i.actualBoundingBoxDescent}:{width:i.width,height:r}}(this._text,[this.fontWeight,this.fontSize,this.fontFamily].join(" "),parseFloat(this.fontSize)),n=r.width,i=r.height;switch(this._anchor[0]){case p.LEFT:e=this._x;break;case p.RIGHT:e=this._x-n;break;case p.CENTER:e=this._x-n/2;break;default:e=this._x}switch(this._anchor[1]){case p.TOP:t=this._y;break;case p.BOTTOM:t=this._y-i;break;case p.MIDDLE:default:t=this._y-i/2}if(this._rotate&&3===this._rotate.length){let r=[{x:e,y:t},{x:e+n,y:t},{x:e,y:t+i},{x:e+n,y:t+i}].map((e=>C(e.x,e.y,this._rotate[1],this._rotate[2],this._rotate[0]))),s=Math.min(...r.map((e=>e.x))),a=Math.max(...r.map((e=>e.x))),o=Math.min(...r.map((e=>e.y))),l=Math.max(...r.map((e=>e.y)));this._bounds=new u(s,o,a-s,l-o)}else this._bounds=new u(e,t,n,i)}get x(){return this._x}get y(){return this._y}get text(){return this._text}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}get textPathOffset(){return this._textPathOffset}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._dataScope&&(e._dataScope=this._dataScope.clone()),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 Et extends ne{constructor(e){super(e),this._type=Tt.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}copyPropertiesTo(e){super.copyPropertiesTo(e),e._x=this._x,e._y=this._y,e._radius=this._radius}}class wt extends ne{constructor(e){super(e),this._type=Tt.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(" ")}}function At(e){let t=null;switch(e.type){case Tt.Circle:t=new mt(e);break;case Tt.Line:var r="x1"in e?e.x1:0,n="y1"in e?e.y1:0,i="x2"in e?e.x2:100,s="y2"in e?e.y2:100;e.vertices=[[r,n],[i,s]],t=new vt(e);break;case Tt.Rect:var a="top"in e?e.top:0,o="left"in e?e.left:0,l="width"in e?e.width:50,u="height"in e?e.height:30;e.vertices=[[o,a],[o+l,a],[o+l,a+u],[o,a+u]],t=new Ye(e);break;case Tt.PointText:t=new xt(e);break;case Tt.Image:t=new bt(e);break;case Tt.BundledPath:case Tt.Chord:case Tt.Path:t=new ne(e);break;case Tt.Area:t=new Xe(e);break;case Tt.Ring:t=new wt(e);break;case Tt.Arc:t=new le(e);break;case Tt.BezierCurve:"vertices"in e||(e.vertices=[[0,100],[20,120],[80,180],[100,200]]),t=new yt(e);break;case Tt.Polygon:t=new Et(e)}return t&&t._updateBounds(),t}function Ct(e){let t=new _t;return e.addChild(t),e._itemMap[t.id]=t,t}function Rt(e){return new gt(e)}function kt(e){switch(e.type){case Tt.Collection:return function(e){let t=Ct(e.scene);for(let r=0;r<e.children.length;r++){let n=e.children[r];t.addChild(kt(n))}if(t._classId=e.classId,e._layout){let r=e._layout.clone();t._layout=r,r.group=t}return t._updateBounds(),t}(e);case Tt.Glyph:return function(e){let t=new gt;for(let r of e.children)t.addChild(kt(r));t._classId=e.classId,e._dataScope&&(t.dataScope=e._dataScope.clone());return t}(e);default:return function(e){let t=At({type:e.type});e.copyPropertiesTo(t),t._classId=e.classId,t._bounds=e.bounds.clone(),e._refBounds||(e._refBounds=e.bounds.clone());t._refBounds=e._refBounds.clone(),e.dataScope&&(t._dataScope=e.dataScope.clone());if(e.vertices)for(let r=0;r<e.vertices.length;r++)e.vertices[r].dataScope&&(t.vertices[r]._dataScope=e.vertices[r].dataScope.clone());return t}(e)}}const St=Object.freeze({Rect:"rect",Circle:"circle",Line:"line",Ring:"ring",Path:"path",Image:"image",PointText:"text",Arc:"arc",BezierCurve:"bezierCurve",BundledPath:"bundledPath",Chord:"chord"}),Tt=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",PointText:"text",Collection:"collection",Group:"group",Composite:"composite",Scene:"scene",Axis:"axis",Glyph:"glyph",Legend:"legend",Polygon:"polygon",Gridlines:"gridlines",LinearGradient:"LinearGradient",Link:"link",DataTable:"datatable",Layout:"layout",NetworkData:"networkdata",TreeData:"treedata"}),Ot=Object.freeze({Axis:"axis",Legend:"legend",Gridlines:"gridlines"});function It(){return Date.now().toString(36)+"_"+Math.random().toString(36).slice(2)}class Nt{constructor(e,t,r){this._id=Tt.DataTable+It(),this.initialize(e,t,r)}initialize(e,t,r){if(this.url=t,this._rawData=JSON.parse(JSON.stringify(e)),this._data=e,this._dateMap=new Map,this._attributes=0===this._data.length?[]:Object.keys(this._data[0]),this._newAttribute=0,r)this._attrTypes=r;else{this._attrTypes={};for(let e of this._attributes)this._attrTypes[e]=Ae(this.data.map((t=>t[e]))),"year"==e.toLowerCase()&&this._attrTypes[e]==we.Integer&&(this._attrTypes[e]=we.Date)}this._validate(this.data,this._attrTypes),this._attrSummaries={};for(let e of this._attributes)this._attrSummaries[e]=Re(this.data.map((t=>t[e])),this._attrTypes[e]);this._attributes.indexOf(Vt)<0&&this._addAttribute(Vt,we.String,this.data.map(((e,t)=>"r"+t)))}clone(){let e=[];for(let t of this._data)e.push(Object.assign({},t));let t=new Nt(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("/"),r=e.substring(t);0!==r.indexOf("\\")&&0!==r.indexOf("/")||(r=r.substring(1));return r}(this.url):this.id}get data(){return this._data}getEncodableAttributes(e){switch(e){case"x":case"y":case"width":case"height":case"radius":case"fillColor":case"strokeColor":case"text":return this.numericAttributes.concat(this.nonNumericAttributes);default:return this.numericAttributes}}_addAttribute(e,t,r){this._data.forEach(((t,n)=>t[e]=r[n])),e!==Vt&&this._rawData.forEach(((t,n)=>t[e]=r[n])),this._attrTypes[e]=t,this._attributes.push(e),this._attrSummaries[e]=Re(r,t)}getAttributeType(e){return this._attrTypes[e]}get attributes(){return this._attributes}getAttributeSummary(e){return this._attrSummaries[e]}getAttributeValues(e){return this.data.map((t=>t[e]))}getUniqueAttributeValues(e){return this._attrSummaries[e].unique}orderAttributeValues(e,t){this._attrSummaries[e].unique=t}getRowCount(){return this.data.length}hasAttribute(e){return this._attributes.indexOf(e)>=0}parseAttributeAsDate(t,r){let n=e.timeParse(r);for(let e of this.data){let r=e[t];null==r||null==r?(r="",e[t]=new Date(1899,11,31).getTime()):e[t]=n(r).getTime(),this._dateMap.set(e[t],r)}this._attrTypes[t]=we.Date,this._attrSummaries[t]=Re(this.data.map((e=>e[t])),we.Date)}getRawValue(e,t){return this.getAttributeType(e)===we.Date?this._dateMap.get(t).toString():t}get nonNumericAttributes(){let e=[];for(let t in this._attrTypes)this._attrTypes[t]!=we.Number&&this._attrTypes[t]!=we.Integer&&t!=Nt.RowID&&e.push(t);return e.sort(((e,t)=>this.getUniqueAttributeValues(e).length-this.getUniqueAttributeValues(t).length)),e}get numericAttributes(){let e=[];for(let t in this._attrTypes)this._attrTypes[t]!==we.Number&&this._attrTypes[t]!==we.Integer||t==Nt.RowID||e.push(t);return e}getAttributesByType(e){let t=[];for(let r in this._attrTypes)this._attrTypes[r]===e&&r!=Nt.RowID&&t.push(r);return t}summarize(){for(let e of this._attributes)this._attrSummaries[e]=Re(this.data.map((t=>t[e])),this._attrTypes[e])}_validate(e,t){for(let r of e)for(let e in t){let n,i=t[e],s=r[e];if(null==r[e]||null==r[e])switch(i){case we.Boolean:n=!1;break;case we.Date:n=new Date(1899,11,31).getTime();break;case we.String:n="";break;default:n=0}else switch(i){case we.Boolean:n=s;break;case we.Date:n=Number.isInteger(s)?new Date(s,0).getTime():new Date(s+"").getTime(),this._dateMap.set(n,s);break;case we.String:n=s.toString();break;default:n=s}r[e]=n}}}function Lt(e){let t=pe(e);if(t)return t.dataTable}const Vt="mascot_rowId";function Pt(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 Dt extends Y{constructor(e,t){super(e),this._elem=t}get element(){return this._elem}}class Bt extends Y{constructor(e,t){super(e),this._item=t}get element(){return this._item}}class Mt{constructor(e){this._id=e+"_"+It(),this._type=e,this._vars=[],this._edges=[]}get vars(){return this._vars}get edges(){return this._edges}run(){console.log("-",this._type)}}class Gt{constructor(e,t,r=!0){this._id="e_"+It(),this._fromNode=e,this._toNode=t,this._isDirected=r}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 H||this._fromNode instanceof Mt?this._fromNode:this._toNode}}class jt extends Y{constructor(e,t,r){super(e),this._attribute=t,this._dataset=r}get attribute(){return this._attribute}get dataset(){return this._dataset}}class zt extends Y{constructor(e,t){super(e),this._encs=[t]}addLinkedEncoding(e){this._encs.push(e)}get encodings(){return this._encs}}class Ft extends H{constructor(e){super(e)}run(){super.run();let e=this.outputVar,t=e.encodings[0],r=this.inputVars.find((e=>e instanceof jt)).attribute,n=e.encodings[0].dataTable.getAttributeType(e.encodings[0].attribute),i=[];for(let t of e.encodings){let e=this._computeAttrValues(t,n);i=i.concat(e)}if("angle"===t.channel&&[Tt.Arc,Tt.Pie].indexOf(t.element.type)>=0)for(let n of e.encodings)for(let e of n.scales){let i=n.getElements(e).map((e=>n.attrValues[e.id]));e.domain=t._preferredDomain?t._preferredDomain:n.dataTable.tree?[0,n.dataTable.tree.getRoot()[r]]:this._getDomainForNumbers(i),console.log("domain for",r,e.domain)}else{let s;s=n==we.String||"text"===e.encodings[0].channel?this._getDomainForStrings(i):this._getDomainForNumbers(i);for(let r of e.encodings)for(let e of r.scales)e.domain=t._preferredDomain?t._preferredDomain:s.slice();console.log("domain for",r,s)}}_getDomainForNumbers(e){let t=this.outputVar.encodings[0],r=[Math.min(...e),Math.max(...e)];if(t.includeZero&&r[0]>0&&(r=[0,Math.max(...e)]),t.mapping)r=Object.keys(t.mapping),r=r.map((e=>parseFloat(e))),r.sort(((e,t)=>e-t));else if("sequentialColor"===t.scales[0].type){if(r[0]<0&&r[1]>0){let e=Math.max(Math.abs(r[0]),Math.abs(r[1]));r=[-e,e]}}else if("angle"===t.channel){r=[0,Object.values(e).reduce(((e,t)=>e+t),0)]}return r}_getDomainForStrings(e){let t,r=this.outputVar,n=r.encodings[0];return t="count"==r.encodings[0].aggregator?[0,Math.max(...e)]:Array.from(new Set(e)),n.mapping&&(t=Object.keys(n.mapping)),t}_computeAttrValues(e,t){let r=S(e.element),n={};if(e.element.type===Tt.Area&&["width","height","fillGradient"].indexOf(e.channel)>=0)for(let t of r)for(let r of t.vertices)n[r.id]=pe(r).aggregateNumericalAttribute(e.attribute,e.aggregator);else switch(t){case we.Boolean:break;case we.Date:for(let t of r)n[t.id]=pe(t).getAttributeValue(e.attribute);break;case we.String:try{if("count"==e.aggregator)for(let t of r)n[t.id]=pe(t).getAttributeValues(e.attribute).length;else for(let t of r)n[t.id]=pe(t).getAttributeValue(e.attribute)}catch(t){throw new Error("Cannot bind "+this.channel+" to "+e.attribute+" : "+t)}break;default:if(e.attribute.startsWith("parent.")||e.attribute.startsWith("child.")){let t=e.dataTable.tree.nodeTable,i=e.attribute.split(".")[0],s=e.attribute.split(".")[1];for(let e of r){let r=pe(e).getAttributeValue(i);n[e.id]=new fe(t).cross(xe,r).getAttributeValue(s)}}else for(let t of r)n[t.id]=pe(t).aggregateNumericalAttribute(e.attribute,e.aggregator)}return e.attrValues=n,Object.values(n)}}class Ut{constructor(t,r){switch(this._id="scale_"+It(),this._type=t,r&&(this._args=r),t){case"linear":this._scale=e.scaleLinear();break;case"point":this._scale=e.scalePoint();break;case"ordinal":this._scale=e.scaleOrdinal();break;case"ordinalColor":this._scale=e.scaleOrdinal(e[r.scheme]);break;case"power":this._scale=e.scalePow().exponent(2);break;case"sqrt":this._scale=e.scalePow().exponent(.5);break;case"log":this._scale=e.scaleLog();break;case"identity":case"time":this._scale=e.scaleTime();break;case"sequentialColor":r.scheme?this._scale=e.scaleSequential(e[r.scheme]):this._scale=e.scaleSequential()}}get id(){return this._id}get domain(){return this._scale.domain()}set domain(e){this._scale.domain(e)}get range(){return this._scale.range()}set range(e){this._scale.range(e)}get rangeExtent(){let e=this._scale.range();return Math.abs(e[1]-e[0])}set rangeExtent(e){let t=this._scale.range();t[0]<t[1]?this._scale.range([t[0],t[0]+e]):this._scale.range([t[1]+e,t[1]])}get type(){return this._type}map(e){return this._scale(e)}}const Ht=["schemeBrBG","schemePRGn","schemePiYG","schemePuOr","schemeRdBu","schemeRdGy","schemeRdYlBu","schemeRdYlGn","schemeSpectral"],Wt=["schemeBlues","schemeGreens","schemeGreys","schemeOranges","schemePurples","schemeReds","schemeBuGn","schemeBuPu","schemeGnBu","schemeOrRd","schemePuBuGn","schemePuBu","schemePuRd","schemeRdPu","schemeYlGnBu","schemeYlGn","schemeYlOrBr","schemeYlOrRd"];class Yt extends H{constructor(e){super(e)}run(){super.run();let e=this.outputVar,t=e.encodings,r=t[0],n=r.channel;for(let i=0;i<r.scales.length;i++){let s=r.scales[i],a=r.getElements(s),o=this._buildRange(n,a,r,e);if(o)for(let e of t)e.scales[i].range=o;console.log("range",r.scales[i].range)}e.initialized=!0}_buildRange(e,t,r,n){return"x"===e?this._buildXRange(t,r,n):"y"===e?this._buildYRange(t,r,n):["width","height","radius","area","fontSize","radialDistance","strokeWidth"].includes(e)?this._buildSizeRange(t,r,n):e.indexOf("Color")>0||"fillGradient"===e?this._buildColorRange(t,r):"angle"===e?this._buildAngleRange(t,r):"thickness"===e?this._buildThicknessRange(t,r,n):"src"===e?r.scales[0].domain.slice():void 0}_buildThicknessRange(e,t,r){let n=e.map((e=>e.outerRadius-e.innerRadius));return[0,r.initialized?t.getRangeExtent(e[0]):t._preferredRangeExtent?t._preferredRangeExtent:Math.max(...n)]}_buildAngleRange(e,t){return[0,360]}_buildColorRange(t,r){if(r.mapping){return r.scales[0].domain.map((e=>r.mapping[e+""]))}if("sequentialColor"===r.scales[0].type){let t=this.outputVar,n=r.scales[0].domain;for(let i of t.encodings)if(!r.colorScheme)for(let t of i.scales){let r=t.domain;t._scale=e.scaleSequential(n[0]<0&&n[1]>0?e.interpolatePuOr:e.interpolateTurbo),t._scale.domain(r)}}if((Ht.indexOf(r.colorScheme)>=0||Wt.indexOf(r.colorScheme)>=0)&&"ordinalColor"===r.scales[0].type){let t=this.outputVar,n=r.scales[0].domain;for(let i of t.encodings)for(let t of i.scales){let i=t.domain;t._scale=e.scaleOrdinal(e[r.colorScheme][n.length]),t._scale.domain(i)}}}_buildSizeRange(e,t,r){let n,i;return n=0,i=r.initialized?t.getRangeExtent(e[0]):t._preferredRangeExtent?t._preferredRangeExtent:Math.max(...e.map((e=>"radius"===t.channel?e.refBounds.width/2:"strokeWidth"===t.channel?e.strokeWidth:"radialDistance"===t.channel?e.parent.radius:"area"===t.channel?e.type===Tt.Circle?Math.PI*Math.pow(e.radius,2):e.width*e.height:"fontSize"===t.channel?parseFloat(e.fontSize):e.refBounds[t.channel]))),[0,0+i]}_buildXRange(e,t,r){let n,i;switch(t.scales[0].type,e[0].type){case"vertex":case"segment":var s=e[0].parent.refBounds?e[0].parent.refBounds:e[0].parent.bounds;n=r.initialized?t.getRangeStart(e[0]):s.left,i=r.initialized?t.getRangeExtent(e[0]):t._preferredRangeExtent?t._preferredRangeExtent:s.width;break;default:n=r.initialized?t.getRangeStart(e[0]):D(e[0]).bounds.left+e[0].bounds.width/2,i=r.initialized?t.getRangeExtent(e[0]):t._preferredRangeExtent?t._preferredRangeExtent:450}return t.flipScale?[n+i,n]:[n,n+i]}_buildYRange(e,t,r){let n,i;switch(t.scales[0].type,e[0].type){case"vertex":case"segment":var s=e[0].parent.refBounds?e[0].parent.refBounds:e[0].parent.bounds;n=r.initialized?t.getRangeStart(e[0]):s.top,i=r.initialized?t.getRangeExtent(e[0]):t._preferredRangeExtent?t._preferredRangeExtent:s.height;break;default:n=r.initialized?t.getRangeStart(e[0]):D(e[0]).bounds.top+e[0].bounds.height/2,i=r.initialized?t.getRangeExtent(e[0]):t._preferredRangeExtent?t._preferredRangeExtent:450}return t.flipScale?[n,n+i]:[n+i,n]}}class Xt extends H{constructor(e){super(e)}run(){super.run()}}class qt extends pt{constructor(e){super(),this._type=Tt.Axis,this._id=this._type+It(),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._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 pt,this._ticks._id=this._id+"_ticks",this.addChild(this._ticks),this._labels=new pt,this._labels._id=this._id+"_labels",this.addChild(this._labels),this._title=new xt({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}get pathPos(){return this._pathPos}get attribute(){return this._attribute}get channel(){return this._channel}get orientation(){return this._orientation}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 tickValues(){return this._tickValues}get labelValues(){return this._labelValues}get titleOffset(){return this._titleOffset}get boundsWithoutTitle(){let e=this.children.filter((e=>e.type!==Tt.PointText)),t=e[0].bounds.clone();for(let r=1;r<e.length;r++)"hidden"!=e[r].visibility&&(t=t.union(e[r].bounds));return t}}const Kt="top",Zt="bottom",$t="left";function Jt(t,r,n,i){let s,a=t.domain,o=t.range;switch(t.type){case"linear":case"log":{let l=Math.abs(o[0]-o[1]);s="width"==r||"x"==r?45:30;let u,c=Math.max(2,Math.floor(l/s));if("width"==r||"height"==r){let e=!!i&&(i.elements[0].parent.layout&&i.elements[0].parent.layout.type==F.STACK);a[1]=t._scale.invert(e?d(n)[r]:h(n)[r])}if("log"===t.type){u=[];let e=t._scale.ticks();for(let t of e){let r=Math.log(t)/Math.log(10)+1e-6;Math.abs(r-Math.floor(r))<c/e.length&&u.push(t)}}else u=e.ticks(a[0],a[1],c);return u}case"point":{s="width"==r||"x"==r?80:30;let e=Math.floor(t.rangeExtent/a.length),n=Math.ceil(s/e);return"x"==r?a.filter(((e,t)=>t%n==0)):a}case"time":{s="width"==r||"x"==r?80:30;let t,n,i=Math.floor((o[1]-o[0])/s),l=Math.ceil((a[1]-a[0])/i)/1e3,u=[1,60,3600,86400,2628003,31536e3],c=[e.timeSeconds,e.timeMinutes,e.timeHours,e.timeDays,e.timeMonths,e.timeYears];for(let e=0;e<u.length-1;e++)if(l>=u[e]&&l<u[e+1])return t=Math.floor(l/u[e]),n=c[e],n(a[0],a[1],t);return l>u[u.length-1]?(t=Math.floor(l/u[u.length-1]),n=c[u.length-1],n(a[0],a[1],t)):[]}default:return[]}}function Qt(e,t){t.removeChild(e)}class er extends qt{constructor(e,t,r,n){super(n),this._encoding=e,this._attribute=this._encoding.attribute,this._channel=this._encoding.channel,this._scale=t,this._elems=r,this._flip="flip"in n&&n.flip,this._posArg="x"==this._channel||"width"==this._channel?n.pathY:n.pathX,this._orientation="orientation"in n?n.orientation:"x"===this._channel||"width"==this._channel?Zt:$t,this._titleText="title"in n?n.title:this._encoding.attribute,this._path="angle"===this._channel?new mt({strokeColor:this._strokeColor,id:this._id+"_path"}):new ne({strokeColor:this._strokeColor,id:this._id+"_path"}),this._pathVisible||(this._path.visibility="hidden"),this.addChild(this._path),this.createTicksLabels(n),e.dataTable.getAttributeType(this._attribute)!==we.Date||"labelFormat"in n||(this._labelFormat="%m/%d/%y"),"radialDistance"===this._channel&&"rotation"in n&&(this._rotate=[-n.rotation,this._elems[0].parent.x,this._elems[0].parent.y])}isFlipped(){return this._flip}get elements(){return this._elems}get scale(){return this._scale}createTicksLabels(t){"tickValues"in t?(this._tickValues=t.tickValues,this._labelValues=t.tickValues):(this._tickValues=Jt(this._scale,this._channel,this._elems,this),this._labelValues=this._tickValues),this._ticks.removeAll();for(let e=0;e<this._tickValues.length;e++){let t=new ne({strokeColor:this._strokeColor,id:this._id+"_tick"+e});this._tickVisible||(t.visibility="hidden"),this._ticks.addChild(t)}let r;switch(this._labels.removeAll(),this._encoding.dataTable.getAttributeType(this._attribute)){case we.Date:r=e.timeFormat(this._labelFormat);break;case we.String:r=function(e){return e};break;default:r=e.format(this._labelFormat)}for(let[e,t]of this._labelValues.entries()){let n=new xt({text:r(t),fontSize:this._fontSize,fillColor:this._textColor,id:this._id+"_label"+e});this._labels.addChild(n)}this._title._text=this._titleText}}class tr extends qt{constructor(e,t,r,n){super(n),this._elems=e,this._attribute=r,this._channel=t,this._posArg="x"==this._channel||"width"==this._channel?n.pathY:n.pathX,this._labelAttribute=n.labelAttribute,this._orientation="orientation"in n?n.orientation:"x"===this._channel||"width"==this._channel?Zt:$t,this._titleText="title"in n?n.title:this._attribute,this._path="angle"===this._channel?new mt({strokeColor:this._strokeColor,id:this._id+"_path"}):new ne({strokeColor:this._strokeColor,id:this._id+"_path"}),this._pathVisible||(this._path.visibility="hidden"),this.addChild(this._path),this.createTicksLabels(n),this._elems[0].dataScope.dataTable.getAttributeType(this._attribute)!==we.Date||"labelFormat"in n||(this._labelFormat="%m/%d/%y")}get elements(){if(this.layout.type===F.CLUSTER){const e=new Map(this._elems.map((e=>[e.dataScope.getAttributeValue(xe),e])));return this.layout._d3Root.leaves().map((t=>e.get(t.data[xe])))}return this._elems}get layout(){return this._elems[0].parent.layout}createTicksLabels(t){"tickValues"in t?(this._tickValues=t.tickValues,this._labelValues=t.tickValues):(this._tickValues=this.elements.map((e=>e.dataScope.getAttributeValue(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 ne({strokeColor:this._strokeColor,id:this._id+"_tick"+e});this._tickVisible||(t.visibility="hidden"),this._ticks.addChild(t)}let r;switch(this._labels.removeAll(),this._elems[0].dataScope.dataTable.getAttributeType(this._labelAttribute?this._labelAttribute:this._attribute)){case we.Date:r=e.timeFormat(this._labelFormat);break;case we.String:r=function(e){return e};break;default:r=e.format(this._labelFormat)}for(let[e,t]of this._labelValues.entries()){let n=new xt({text:r(t),fontSize:this._fontSize,fillColor:this._textColor,id:this._id+"_label"+e});this._labels.addChild(n)}this._title._text=this._titleText}}class rr extends H{constructor(e){super(e)}run(){let e=this.inputVars.find((e=>e instanceof Je&&e.property==Qe.AXIS_ORIENTATION)).element;e instanceof er?this._runForEncoding(e):e instanceof tr&&this._runForLayout(e),f(e._path)}_runForLayout(e){let t=e.channel,r=e.elements[0].parent.layout&&e.elements[0].parent.layout.type==F.STACK?d(e.elements):h(e.elements),n=[];if("x"===t){let t=e.orientation===Kt?r.top-2:r.bottom+2;e._pathPos=e._posArg?e._posArg:t,n.push([r.left,e._pathPos]),n.push([r.right,e._pathPos]),e._path._setVertices(n)}else if("y"===t){let t=e.orientation===$t?r.left-2:r.right+2;e._pathPos=e._posArg?e._posArg:t,n.push([e._pathPos,r.top]),n.push([e._pathPos,r.bottom]),e._path._setVertices(n)}else if("angle"===t){let t=e.elements[0].parent.layout;t.type===F.CLUSTER&&(e._path._x=t.x,e._path._y=t.y,e._path._radius=t.radius)}}_runForEncoding(e){let t=e.channel,r=e.elements[0].parent.layout&&e.elements[0].parent.layout.type==F.STACK?d(e.elements):h(e.elements),n=[];if("x"===t){let t=e.orientation===Kt?r.top-2:r.bottom+2;e._pathPos=e._posArg?e._posArg:t,n.push([e.scale.range[0],e._pathPos]),n.push([e.scale.range[1],e._pathPos])}else if("width"===t){let t=e.orientation===Kt?r.top-2:r.bottom+2;e._pathPos=e._posArg?e._posArg:t,n.push([r.left,e._pathPos]),n.push([r.right,e._pathPos])}else if("radialDistance"===t){let t=e.elements[0].parent,r=t.y;e._pathPos=e._posArg?e._posArg:r,n.push([e.scale.range[0]+t.x,e._pathPos]),n.push([e.scale.range[1]+t.x,e._pathPos])}else if("y"===t){let t=e.orientation===$t?r.left-2:r.right+2;e._pathPos=e._posArg?e._posArg:t,n.push([e._pathPos,e.scale.range[0]]),n.push([e._pathPos,e.scale.range[1]])}else if("height"===t){let t=e.orientation===$t?r.left-2:r.right+2;e._pathPos=e._posArg?e._posArg:t,n.push([e._pathPos,r.bottom]),n.push([e._pathPos,r.top])}e._path._setVertices(n)}}class nr extends H{constructor(e){super(e)}run(){let e=this.inputVars.find((e=>e instanceof Je&&e.property==Qe.AXIS_PATH_POSITION)).element;e instanceof er?this._runForEncoding(e):e instanceof tr&&this._runForLayout(e);for(let t of e._ticks.children)t._updateBounds();f(e._ticks)}_runForLayout(e){let t=e.channel;if("x"==t){let t=e.orientation==Zt?e.pathPos+e.tickOffset:e.pathPos-e.tickOffset,r=e.orientation==Zt?e.tickSize:-e.tickSize;for(let[n,i]of e._ticks.children.entries()){let s=e.elements[n].bounds[e.tickAnchor];i._setVertices([[s,t],[s,t+r]])}}else if("y"===t){let t=e.orientation==$t?e.pathPos-e.tickOffset:e.pathPos+e.tickOffset,r=e.orientation==$t?-e.tickSize:e.tickSize;for(let[n,i]of e._ticks.children.entries()){let s=e.elements[n].bounds[e.tickAnchor];i._setVertices([[t,s],[t+r,s]])}}else if("angle"===t){let t=e.elements[0].parent.layout;if(t.type===F.CLUSTER){let r=t._d3Root.leaves();const n=new Map(r.map((e=>[e.data[xe],[e.x,e.y]])));for(let[r,i]of e._ticks.children.entries()){let s=e.elements[r].dataScope.getAttributeValue(xe),a=ce(n.get(s)[0])-90;i._setVertices([[t.x+n.get(s)[1]+e.elements[r].bounds.width/2,t.y],[t.x+n.get(s)[1]+e.elements[r].bounds.width/2+e.tickSize,t.y]]),i._rotate=[a,t.x,t.y]}}}}_runForEncoding(e){let t=e.channel,r=h(e.elements);if("x"==t){let t=e.orientation==Zt?e.pathPos+e.tickOffset:e.pathPos-e.tickOffset,r=e.orientation==Zt?e.tickSize:-e.tickSize;for(let[n,i]of e._ticks.children.entries())i._setVertices([[e.scale.map(e._tickValues[n]),t],[e.scale.map(e._tickValues[n]),t+r]])}else if("width"==t){let t=e.orientation==Zt?e.pathPos+e.tickOffset:e.pathPos-e.tickOffset,n=e.orientation==Zt?e.tickSize:-e.tickSize;if(!!(e.isFlipped()||e.elements[0].type===Tt.Area&&"right"===e.elements[0].baseline))for(let[i,s]of e._ticks.children.entries())s._setVertices([[r.left+e.scale.rangeExtent-e.scale.map(e._tickValues[i]),t],[r.left+e.scale.rangeExtent-e.scale.map(e._tickValues[i]),t+n]]);else for(let[i,s]of e._ticks.children.entries())s._setVertices([[e.scale.map(e._tickValues[i])+r.left,t],[e.scale.map(e._tickValues[i])+r.left,t+n]])}else if("y"===t){let t=e.orientation==$t?e.pathPos-e.tickOffset:e.pathPos+e.tickOffset,r=e.orientation==$t?-e.tickSize:e.tickSize;for(let[n,i]of e._ticks.children.entries())i._setVertices([[t,e.scale.map(e._tickValues[n])],[t+r,e.scale.map(e._tickValues[n])]])}else if("height"===t){let t=e.orientation==$t?e.pathPos-e.tickOffset:e.pathPos+e.tickOffset,n=e.orientation==$t?-e.tickSize:e.tickSize;if(!!(e.isFlipped()||e.elements[0].type===Tt.Area&&"top"===e.elements[0].baseline))for(let[i,s]of e._ticks.children.entries())s._setVertices([[t,r.top+e.scale.map(e._tickValues[i])],[t+n,r.top+e.scale.map(e._tickValues[i])]]);else for(let[i,s]of e._ticks.children.entries()){let a=r.bottom-e.scale.map(e._tickValues[i]);s._setVertices([[t,a],[t+n,a]])}}else if("radialDistance"===t){let t=e.orientation==Zt?e.pathPos+e.tickOffset:e.pathPos-e.tickOffset,r=e.orientation==Zt?e.tickSize:-e.tickSize,n=e.elements[0].parent;for(let[i,s]of e._ticks.children.entries())s._setVertices([[n.x+e.scale.map(e._tickValues[i]),t],[n.x+e.scale.map(e._tickValues[i]),t+r]])}}}class ir extends H{constructor(e){super(e)}run(){let e=this.inputVars.find((e=>e instanceof Je&&e.property==Qe.AXIS_PATH_POSITION)).element;e instanceof er?this._runForEncoding(e):e instanceof tr&&this._runForLayout(e);for(let t of e._labels.children)t._updateBounds();f(e._labels)}_runForLayout(e){let t=e.channel;if("x"==t){let t=e.orientation==Zt?e.labelOffset:-e.labelOffset,r=e.orientation==Zt?[p.CENTER,p.TOP]:[p.CENTER,p.BOTTOM];for(let[n,i]of e._labels.children.entries()){let s=e.elements[n].bounds;i._x=s[e.tickAnchor],i._y=e.pathPos+t,i._anchor=r,e._labelRotation&&(i._rotate=[e._labelRotation,i.x,i.y],i._anchor=[p.RIGHT,p.MIDDLE])}}else if("y"===t){let t=e.orientation==$t?-e.labelOffset:e.labelOffset,r=e.orientation==$t?[p.RIGHT,p.MIDDLE]:[p.LEFT,p.MIDDLE];for(let[n,i]of e._labels.children.entries()){let s=e.elements[n].bounds;i._x=e.pathPos+t,i._y=e.tickAnchor==p.MIDDLE?s.y:s[e.tickAnchor],i._anchor=r,e._labelRotation&&(i._rotate=[e._labelRotation,i.x,i.y],i._anchor=[p.RIGHT,r[1]])}}else if("angle"===t){let t=e.elements[0].parent.layout;if(t.type===F.CLUSTER){let r=t._d3Root.leaves();const n=new Map(r.map((e=>[e.data[xe],[e.x,e.y]])));let i=5;for(let[r,s]of e._labels.children.entries()){let a=e.elements[r].dataScope.getAttributeValue(xe);if(n.get(a)[0]<Math.PI){let o=ce(n.get(a)[0])-90;s._anchor=[p.LEFT,p.MIDDLE],s._x=t.x+n.get(a)[1]+e.elements[r].bounds.width/2+i,s._y=t.y,s._rotate=[o,t.x,t.y]}else{let o=ce(n.get(a)[0])+90;s._anchor=[p.RIGHT,p.MIDDLE],s._x=t.x-n.get(a)[1]-e.elements[r].bounds.width/2-i,s._y=t.y,s._rotate=[o,t.x,t.y]}}}}}_runForEncoding(e){let t=e.channel,r=h(e.elements);if("x"==t){let t=e.orientation==Zt?e.labelOffset:-e.labelOffset,r=e.orientation==Zt?[p.CENTER,p.TOP]:[p.CENTER,p.BOTTOM];for(let[n,i]of e._labels.children.entries())i._x=e.scale.map(e.labelValues[n]),i._y=e.pathPos+t,i._anchor=r,e._labelRotation&&(i._rotate=[e._labelRotation,i.x,i.y],i._anchor=[p.RIGHT,r[1]])}else if("width"===t){let t=e.orientation==Zt?e.labelOffset:-e.labelOffset,n=e.orientation==Zt?[p.CENTER,p.TOP]:[p.CENTER,p.BOTTOM],i=!!(e.isFlipped()||e.elements[0].type===Tt.Area&&"right"===e.elements[0].baseline);for(let[s,a]of e._labels.children.entries())a._x=i?r.left+e.scale.rangeExtent-e.scale.map(e.labelValues[s]):e.scale.map(e.labelValues[s])+r.left,a._y=e.pathPos+t,a._anchor=n,e._labelRotation&&(a._rotate=[e._labelRotation,a.x,a.y],a._anchor=[p.RIGHT,n[1]])}else if("y"===t){let t=e.orientation==$t?-e.labelOffset:e.labelOffset,r=e.orientation==$t?[p.RIGHT,p.MIDDLE]:[p.LEFT,p.MIDDLE];for(let[n,i]of e._labels.children.entries())i._x=e.pathPos+t,i._y=e.scale.map(e.labelValues[n]),i._anchor=r,e._labelRotation&&(i._rotate=[e._labelRotation,i.x,i.y],i._anchor=[p.RIGHT,r[1]])}else if("height"===t){let t=e.orientation==$t?-e.labelOffset:e.labelOffset,n=e.orientation==$t?[p.RIGHT,p.MIDDLE]:[p.LEFT,p.MIDDLE],i=e.elements[0].type===Tt.Area&&"top"===e.elements[0].baseline;for(let[s,a]of e._labels.children.entries())a._x=e.pathPos+t,a._y=i?r.top+e.scale.map(e.labelValues[s]):r.bottom-e.scale.map(e.labelValues[s]),a._anchor=n,e._labelRotation&&(a._rotate=[e._labelRotation,a.x,a.y],a._anchor=[p.RIGHT,n[1]])}else if("radialDistance"==t){let t=e.orientation==Zt?e.labelOffset:-e.labelOffset,r=e.orientation==Zt?[p.CENTER,p.TOP]:[p.CENTER,p.BOTTOM],n=e.elements[0].parent;for(let[i,s]of e._labels.children.entries())s._x=n.x+e.scale.map(e.labelValues[i]),s._y=e.pathPos+t,s._anchor=r,e._labelRotation&&(s._rotate=[e._labelRotation,s.x,s.y],s._anchor=[p.RIGHT,r[1]])}}}class sr extends H{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=S(e.parent);for(let e of t){let t=e.layout;if(!t)return;this.fillGrid(e,t),this.computeCellBounds(e,t),this.placeElements(e,t)}let r=G(e,!0);for(let e of r)f(e)}placeElements(e,t){let r=De(e,"x"),n=De(e,"y");for(let r=0;r<e.children.length;r++){let n=e.children[r],i=t.cellBounds[r],s=0,a=0;switch(t._cellHorzAlignment){case p.LEFT:s=i.left-n.refBounds.left;break;case p.CENTER:s=i.x-n.refBounds.x;break;case p.RIGHT:s=i.right-n.refBounds.right}switch(t._cellVertAlignment){case p.TOP:a=i.top-n.refBounds.top;break;case p.MIDDLE:a=i.y-n.refBounds.y;break;case p.BOTTOM:a=i.bottom-n.refBounds.bottom}je(n,s,a)}if(r.length>0)for(let e of r)for(let r of e.scales){let n=e.getElements(r)[0],i=t.getIndex(n);if(i<0)continue;let s="point"===r.type?t.cellBounds[i].left+n.bounds.width/2:t.cellBounds[i].left,a=s+r.rangeExtent;r.range=r.range[0]<r.range[1]?[s,a]:[a,s]}if(n.length>0)for(let e of n)for(let r of e.scales){let n=e.getElements(r)[0],i=t.getIndex(n);if(i<0)continue;let s="point"===r.type?t.cellBounds[i].top+e.getElements(r)[0].bounds.height/2:t.cellBounds[i].top,a=s+r.rangeExtent;r.range=r.range[0]<r.range[1]?[s,a]:[a,s]}}fillGrid(e,t){t._grid=new Array(t.numRows).fill(null).map((()=>new Array(t.numCols).fill(null)));for(let r=0;r<e.children.length;r++){let e=t.getRowCol(r);t._grid[e.row][e.col]=r}}computeCellBounds(e,t){let r=e.children.map((e=>e.refBounds?e.refBounds:e.bounds)),n=t._colGap,i=t._rowGap;if(void 0===t._left){let e=r.map((e=>e.left)),n=r.map((e=>e.top));t._left=Math.min(...e),t._top=Math.min(...n)}let s=r.map((e=>e.width)),a=r.map((e=>e.height)),o=Math.max(...s),l=Math.max(...a);t._cellBounds=new Array(e.children.length).fill(null);for(let r=0;r<t.numRows;r++)for(let s=0;s<t.numCols;s++){let a=t._grid[r][s];a>=e.children.length||(t._cellBounds[a]=new u(t._left+(o+n)*s+0,t._top+(l+i)*r,o,l))}}}class ar extends H{constructor(e){super(e)}run(){let e=this.outputVar.element;e.scale?this._runForEncoding(e):this._runForLayout(e),f(e)}_runForLayout(e){let t=e.channel,r=h(e.elements),n=[];if("x"===t)for(let t=0;t<e.values.length;t++){let i=e.elements[t].refBounds;n.push({x1:i.x,y1:r.bottom,x2:i.x,y2:r.top})}else if("y"===t)for(let t=0;t<e.values.length;t++){let i=e.elements[t].refBounds;n.push({x1:r.left,y1:i.y,x2:r.right,y2:i.y})}e.lines=n}_runForEncoding(e){let t=e.channel,r=h(e.elements),n=[];if("x"===t)for(let t of e.values)n.push({x1:e.scale.map(t),y1:r.bottom,x2:e.scale.map(t),y2:r.top});else if("width"===t)for(let t of e.values)n.push({x1:e.scale.map(t)+r.left,y1:r.bottom,x2:e.scale.map(t)+r.left,y2:r.top});else if("y"===t)for(let t of e.values)n.push({x1:r.left,y1:e.scale.map(t),x2:r.right,y2:e.scale.map(t)});else if("height"===t)for(let t of e.values)n.push({x1:r.left,y1:r.bottom-e.scale.map(t),x2:r.right,y2:r.bottom-e.scale.map(t)});else if("radialDistance"===t){let t=e.elements[0].parent;for(let r=0;r<e.values.length;r++)n.push({x:t.x,y:t.y,r:e.scale.map(e.values[r])})}e.lines=n}}class or extends H{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=G(e)[0],r=S(e.parent);for(let e of r){let r=e.layout;if(!r)return;switch(t.type){case Tt.Rect:case Tt.Circle:case Tt.Image:this._stackRects(e,r);break;case Tt.Area:e.children[0].orientation===$.HORIZONTAL?this._stackAreasVert(e,r):this._stackAreasHorz(e,r);break;case Tt.Arc:case Tt.Pie:t.parent.classId===e.classId&&this._stackArcs(e,r)}}f(t)}_stackArcs(e,t){if(t.orientation===$.ANGULAR){let t=90;if((this._direction?this._direction:Q.Clockwise)===Q.Clockwise)for(let r of e.children){let e=he(t-r.angle);Fe(r,"startAngle",e),t=e}else for(let r of e.children){let e=he(t+r.angle);Fe(r,"startAngle",e),t=e}}else if(t.orientation===$.RADIAL){let t=Math.min(...e.children.map((e=>e.innerRadius)));for(let r of e.children){let e=r.outerRadius-r.innerRadius;Fe(r,"innerRadius",t),Fe(r,"outerRadius",t+e),t=r._outerRadius}}}_stackAreasVert(e,t){let r=e.children,n=e.bounds,i=t.vertCellAlignment===p.TOP?n.top:n.bottom,s=t.vertCellAlignment===p.TOP?1:-1,a=r[0].vertices.length/2,o=new Array(a).fill(0);for(let e of r){for(let t=0;t<a;t++){let r=e.vertices[t],n=e.vertices[2*a-t-1],l=Math.abs(r.y-n.y),u=i+o[t]*s,c=i+(o[t]+l)*s;je(r,0,u-r.y),je(n,0,c-n.y),o[t]+=l}let t=e.bounds.bottom;e._updateBounds(),e._refBounds.translate(0,e.bounds.bottom-t)}if(t.vertCellAlignment===p.MIDDLE)for(let e of r){for(let t=0;t<a;t++){let r=e.vertices[t],i=e.vertices[2*a-t-1],s=n.middle+o[t]/2;je(r,0,s-n.bottom),je(i,0,s-n.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 r=t._orientation,n=e.children.map((e=>e.bounds)),i=n.map((e=>e.left)),s=n.map((e=>e.top)),a=n.map((e=>e.width)),o=n.map((e=>e.height)),l=null==t._left?Math.min(...i):t._left,u=null==t._top?Math.min(...s):t._top,c=Math.max(...a),h=Math.max(...o);if(r==$.VERTICAL)for(let r=0;r<e.children.length;r++){let n=e.children[r],i=0,s=u+n.bounds.height/2-n.bounds.y;u+=n.bounds.height+t._gap,je(n,i,s),n._updateBounds();let a=0,o=0;if(!Me(n))switch(t._horzCellAlignment){case p.LEFT:a=l-n.bounds.left;break;case p.CENTER:a=l+c/2-n.bounds.x;break;case p.RIGHT:a=l+c-n.bounds.right}je(n,a,o)}else for(let r=0;r<e.children.length;r++){let n=e.children[r],i=l+n.bounds.width/2-n.bounds.x,s=0;l+=n.bounds.width+t._gap,je(n,i,s),n._updateBounds();let a=0,o=0;if(!Be(n))switch(t._vertCellAlignment){case p.TOP:o=u-n.bounds.top;break;case p.MIDDLE:o=u+h/2-n.bounds.y;break;case p.BOTTOM:o=u+h-n.bounds.bottom}je(n,a,o)}}}class lr extends H{constructor(e){super(e)}run(){super.run()}}class ur extends H{constructor(e){super(e)}run(){let t=this.inputVars[0],r=this.outputVar,n=t.attribute,i=r.attribute,s=t.dataset,a=r.dataset,o=s.getAttributeValues(n),l=e.bin()(o),u=this._findBin,c=o.map((e=>{let t=u(e,l);return(t.x0+t.x1)/2+""})),h=l.map((e=>(e.x0+e.x1)/2+""));a._addAttribute(i,we.String,c),a.orderAttributeValues(i,h)}_findBin(e,t){for(let r of t)if(r.indexOf(e)>=0)return r}}class cr extends H{constructor(e){super(e)}run(){let e=this.outputVar,t=e.dataset,r=e.predicate,n=[];for(let[e,i]of t.data.entries())r.testTuple(i)||n.push(e);n.sort(((e,t)=>t-e)),n.forEach((e=>{e>=0&&e<t.data.length&&(t._data.splice(e,1),t._rawData.splice(e,1))}));for(let e of t._attributes)t._attrSummaries[e]=Re(t.data.map((t=>t[e])),t._attrTypes[e])}}class hr extends Y{constructor(e,t,r){super(e),this._dataset=r,this._predicate=t}get dataset(){return this._dataset}get predicate(){return this._predicate}}class dr extends Y{constructor(e,t){super(e),this._group=t}get element(){return this._group}}class fr extends H{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find((e=>e.type===X.AFFIXATION)).affixation,t=e.base,r=e.element,n=S(t),i=S(r),s=e.channels,a=e.attribute;if(x(r)&&x(t)){let e=n.map((e=>e.dataScope.getAttributeValue(a)));i=i.filter((t=>e.includes(t.dataScope.getAttributeValue(a))));let t=(e,t)=>e.dataScope.getAttributeValue(a)<t.dataScope.getAttributeValue(a)?-1:e.dataScope.getAttributeValue(a)>t.dataScope.getAttributeValue(a)?1:0;i.sort(t),n.sort(t)}if(s.includes("x")||s.includes("y"))for(let t of s)this._handleXY(t,i,n,e.getElementAnchor(t),e.getBaseAnchor(t),e.getOffset(t));(s.includes("radialDistance")||s.includes("angle"))&&this._handlePolar(i,n,e);let o=G(r,!0);for(let e of o)f(e)}_handlePolar(e,t,r){let n=r.hasChannel("radialDistance")?r.getBaseAnchor("radialDistance"):p.MIDDLE,i=r.hasChannel("radialDistance")?r.getElementAnchor("radialDistance"):p.MIDDLE,s=r.hasChannel("angle")?r.getBaseAnchor("angle"):p.CENTER;r.hasChannel("angle")?r.getElementAnchor("angle"):p.CENTER;let a=r.hasChannel("radialDistance")?r.getOffset("radialDistance"):0,o=r.hasChannel("angle")?r.getOffset("angle"):0;if([Tt.Arc,Tt.Ring].indexOf(t[0].type)>=0&&e[0].type==Tt.PointText)for(let r=0;r<e.length;r++){let i=t[r],o=e[r],l=n===p.MIDDLE?(i.outerRadius+i.innerRadius)/2:n===p.TOP?i.outerRadius-5:i.innerRadius+5;if(l+=a,i.type===Tt.Arc){let e=Se(i.x,i.y,l,i.startAngle),t=Se(i.x,i.y,l,i.endAngle);i.endAngle>=180&&i.endAngle<=360?o._textPath=["M",e[0],e[1],"A",l,l,i.angle,i.angle>=180?1:0,0,t[0],t[1]].join(" "):o._textPath=["M",t[0],t[1],"A",l,l,i.angle,i.angle>=180?1:0,1,e[0],e[1]].join(" ")}else if(i.type===Tt.Ring){let e=275,t=265,r=350,n=Se(i.x,i.y,l,e),s=Se(i.x,i.y,l,t);o._textPath=["M",s[0],s[1],"A",l,l,r,1,1,n[0],n[1]].join(" ")}o._textPathOffset=s===p.LEFT?"0%":"50%"}else for(let r=0;r<e.length;r++){let l,u,c=t[r],h=e[r];c.type==Tt.Arc||c.type==Tt.Ring?(u="left"==s?c.endAngle+o:"center"==s?c.startAngle+c.angle/2+o:c.startAngle+o,l="top"==n?c.outerRadius+a:"bottom"==n?c.innerRadius+a:(c.outerRadius+c.innerRadius)/2+a):c.type==Tt.Circle&&(u=90,l="top"==n?c.radius+a:"bottom"==n?a:c.radius/2+a),je(h,c.x-h.x,c.y-l-h.bounds[i]),h._rotate=[90-u,c.x,c.y]}}_handleXY(e,t,r,n,i,s){for(let a=0;a<t.length;a++){let o,l=r[a],u=t[a];if(se(l)){o=ie(l,[p.LEFT,p.TOP].includes(i)?0:[p.CENTER,p.MIDDLE].includes(i)?.5:1)[e]}else o=l.bounds[i]+s;t[0].type===Tt.PointText?(u.anchor["x"==e?0:1]=n,Fe(u,e,o)):"x"==e?je(u,o-u.bounds[n],0):je(u,0,o-u.bounds[n])}}}class pr extends Y{constructor(e,t){super(e),this._affx=t}get affixation(){return this._affx}}class _r extends H{constructor(e){super(e)}run(){let e=this.inputVars[0],t=this.outputVar,r=e.attribute,n=t.attribute,i=e.dataset,s=t.dataset,a=this.args,o="min"in a?a.min:i.getAttributeSummary(r).min,l="max"in a?a.max:i.getAttributeSummary(r).max,u=o,c=[];for(;u<l;)c.push(u),u+=a.interval;c.push(u);let h={},d={};if(a.groupBy)for(let e of i.data){let t=a.groupBy.map((t=>e[t])).join("-");t in h||(h[t]=[],d[t]=a.groupBy.map((t=>e[t]))),h[t].push(e[r])}else h[""]=i.data.map((e=>e[r])),d[""]="";let f=[];for(let e in d){let t=gr(yr(a.bandwidth),c,h[e]);for(let i of t){let t={};""!==e&&a.groupBy.forEach(((r,n)=>t[r]=d[e][n])),t[r]=i[0],t[n]=i[1],f.push(t)}}let p={};if(p[r]=i.getAttributeType(r),p[n]=we.Number,a.groupBy)for(let e of a.groupBy)p[e]=i.getAttributeType(e);s.initialize(f,s.url,p)}}function gr(t,r,n){return r.map((r=>[r,e.mean(n,(e=>t(r-e)))]))}function yr(e){return t=>Math.abs(t/=e)<=1?.75*(1-t*t)/e:0}class mr extends H{constructor(e){super(e)}run(){super.run();let t=this._outputVars[0].element,r=S(t.parent);for(let t of r){let r=t.layout;if(!r)return;let n=t.children.map((e=>({name:e.id,radius:e.radius,itm:e}))),i=n.reduce(((e,t)=>e+Math.pow(t.radius,2)),0),s=Math.sqrt(i);void 0===r._width&&(r._width=s),void 0===r._height&&(r._height=s);let a=e.hierarchy({name:"root",children:n}).sum((e=>e.radius?e.radius:0)).sort(((e,t)=>t.value-e.value));e.pack().size([r._width,r._height]).radius((e=>e.value))(a);for(let e of a.children){let t=e.data.itm;je(t,r._x-a.x+e.x-t.x,r._y-a.y+e.y-t.y)}}let n=G(t,!0);for(let e of n)f(e)}}class br extends H{constructor(e){super(e)}run(){let e=this.inputVars.find((e=>e instanceof Je&&e.property==Qe.AXIS_PATH_POSITION)).element;e instanceof er?this._runForEncoding(e):e instanceof tr&&this._runForLayout(e),f(e._title)}_runForEncoding(e){let t=e.channel,r=h(e.elements);if("x"==t)e._title._x=(e.scale.range[0]+e.scale.range[1])/2,e._title._y=e.orientation==Zt?e.pathPos+e.titleOffset:e.pathPos-e.titleOffset;else if("width"==t)e._title._x=r.left+e.scale.rangeExtent/2,e._title._y=e.orientation==Zt?e.pathPos+e.titleOffset:e.pathPos-e.titleOffset;else if("y"===t)e._rotateYTitle?(e._title._x=e.orientation==$t?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==$t?[-90,e._title._x,e._title._y]:[90,e._title._x,e._title._y]):(e._title._x=e.orientation==$t?e.pathPos-e.titleOffset:e.pathPos+e.titleOffset,e._title._y=Math.min(e.scale.range[0],e.scale.range[1])-25,e._title._rotate=void 0);else if("height"===t)e._title._x=r.center,e._title._y=(r.top+r.bottom)/2-r.width/2-e.titleOffset,e._title._rotate=e.orientation==$t?[-90,r.center,r.middle]:[90,r.center,r.middle];else if("radialDistance"===t){let t=e.elements[0].parent;e._title._x=t.x+e.scale.rangeExtent/2,e._title._y=e.orientation==Zt?e.pathPos+e.titleOffset:e.pathPos-e.titleOffset,e._rotate&&(e._title._rotate=e._rotate.slice())}}_runForLayout(e){let t=e.channel,r=e.elements[0].parent.layout&&e.elements[0].parent.layout.type==F.STACK?d(e.elements):h(e.elements);if("x"==t)e._title._x=r.center,e._title._y=e.orientation==Zt?e.pathPos+e.titleOffset:e.pathPos-e.titleOffset;else if("y"===t)e._title._x=r.center,e._title._y=r.middle-r.width/2-e.titleOffset,e._title._rotate=e.orientation==$t?[-90,r.center,r.middle]:[90,r.center,r.middle];else if("angle"===t){let t=e.elements[0].parent.layout;t.type===F.CLUSTER&&(e._title._x=t.x,e._title._y=t.y)}}}class vr extends Mt{constructor(e){super(e)}run(){super.run();let t,r=this.vars.find((e=>e.type===X.ALIGNMENT)).alignment,n=r.anchor,i=r.elements;n==p.Top||n==p.LEFT?t=Math.min(...i.map((e=>e.bounds[n]))):n==p.BOTTOM||n==p.RIGHT?t=Math.max(...i.map((e=>e.bounds[n]))):n!=p.CENTER&&n!=p.MIDDLE||(t=e.mean(i.map((e=>e.bounds[n]))));for(let e of i){let i=Ge(e,r.channel);if(i){let s=t-e.bounds[n];je(i,"x"===r.channel?s:0,"x"===r.channel?0:s)}}for(let e of i)f(e)}}class xr extends Y{constructor(e,t){super(e),this._aln=t}get alignment(){return this._aln}}class Er extends H{constructor(e){super(e)}run(){super.run();let t=this._outputVars[0].element,r=S(t.parent);for(let t of r){let r=t.layout;if(!r)continue;let n=be(t.children[0]);if(!n)continue;let i=n.linkList.map((e=>({source:n.getNode(e.source),target:n.getNode(e.target)}))),s=e.forceSimulation(n.nodeList).force("charge",e.forceManyBody().strength(-r._repulsion)).force("link",e.forceLink(i).id((e=>e.id)).distance(r._linkDistance)).force("x",e.forceX()).force("y",e.forceY()).force("center",e.forceCenter(r._x,r._y).strength(r._attraction));s.stop(),s.tick(r._iterations);for(let e=0;e<t.children.length;e++){let r=t.children[e],i=n.nodeList[e];je(r,i.x-r.x,i.y-r.y)}}let n=G(t,!0);for(let e of n)f(e)}}class wr extends H{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=S(e);switch(e.type){case Tt.Arc:this._updateArcLinks(t);break;case Tt.BezierCurve:this._updateBezierLinks(t);break;case Tt.BundledPath:this._updateBundledLinks(t);break;case Tt.Chord:this._updateChordLinks(t);break;case Tt.Line:default:this._updateLineLinks(t)}f(e)}_updateArcLinks(e){for(let t of e){let e=t.source.x<t.target.x?t.source:t.target,r=t.source.x<t.target.x?t.target:t.source;t._x=(e.x+r.x)/2,t._y=(e.y+r.y)/2,t._innerRadius=Math.sqrt(Math.pow(e.x-r.x,2)+Math.pow(e.y-r.y,2))/2,t._outerRadius=t._innerRadius+t._thickness;let n=de(e.x,e.y,t._x,t._y),i=de(r.x,r.y,t._x,t._y);t.direction===Q.CLOCKWISE&&([n,i]=[i,n]),Fe(t,"startAngle",n),Fe(t,"angle",Math.abs(i-n))}}_updateBezierLinks(e){let t=this._inputVars[0].element,r=S(t),n=t.parent.layout;n.type===F.DIRECTED||n.type===F.TIDYTREE?this._updateBezierLinksForDirectedGraph(r,e,n):n.type===F.CLUSTER&&this._updateBezierLinksForClusteredGraph(r,e,n)}_updateBezierLinksForClusteredGraph(t,r,n){const i=n._d3Root.descendants(),s=new Map(i.map((e=>[Ar(e),e]))),a=new Map(i.map((e=>[e.data[xe],Ar(e)])));if(n.isRadial()){const t=e.linkRadial().angle((e=>e.x)).radius((e=>e.y));for(let e of r){let r=e.source,i=e.target,o=r.dataScope.getAttributeValue(xe),l=i.dataScope.getAttributeValue(xe),u=s.get(a.get(o)),c=s.get(a.get(l));e._d=oe(t({source:u,target:c}),n.x,n.y)}}else if(n.orientation===$.VERTICAL){const t=e.linkVertical().x((e=>e.x)).y((e=>e.y));for(let e of r){let r=e.source,i=e.target,o=r.dataScope.getAttributeValue(xe),l=i.dataScope.getAttributeValue(xe),u=s.get(a.get(o)),c=s.get(a.get(l));e._d=oe(t({source:u,target:c}),n.left-n._x0,n.top)}}else if(n.orientation===$.HORIZONTAL){const t=e.linkHorizontal().x((e=>e.y)).y((e=>e.x));for(let e of r){let r=e.source,i=e.target,o=r.dataScope.getAttributeValue(xe),l=i.dataScope.getAttributeValue(xe),u=s.get(a.get(o)),c=s.get(a.get(l));e._d=oe(t({source:u,target:c}),n.left,n.top-n._x0)}}}_updateBezierLinksForDirectedGraph(e,t,r){let n={},i={},s={},a={};for(let t of e){i[t.id]=0,n[t.id]=0;let e=t.links.filter((e=>e.source===t)),r=t.links.filter((e=>e.target===t));a[t.id]=r.map((e=>e.strokeWidth)).reduce(((e,t)=>e+t),0),s[t.id]=e.map((e=>e.strokeWidth)).reduce(((e,t)=>e+t),0)}r.spreadLinks&&("LR"===r.direction||"RL"===r.direction?t.sort(((e,t)=>de(e.target.bounds.x,e.target.bounds.y,e.source.bounds.x,e.source.bounds.y)-de(t.target.bounds.x,t.target.bounds.y,t.source.bounds.x,t.source.bounds.y))):t.sort(((e,t)=>de(t.target.bounds.x,t.target.bounds.y,t.source.bounds.x,t.source.bounds.y)-de(e.target.bounds.x,e.target.bounds.y,e.source.bounds.x,e.source.bounds.y))));for(let e of t){let t,o,l,u,c=e.source,h=e.target;r.spreadLinks?"LR"===r.direction||"RL"===r.direction?(t=c.bounds[e.sourceAnchor[0]]+e.sourceOffset[0],l=h.bounds[e.targetAnchor[0]]+e.targetOffset[0],o=c.bounds[e.sourceAnchor[1]]+e.sourceOffset[1]-s[c.id]/2+n[c.id]+e.strokeWidth/2,u=h.bounds[e.targetAnchor[1]]+e.targetOffset[1]-a[h.id]/2+i[h.id]+e.strokeWidth/2,n[c.id]+=e.strokeWidth,i[h.id]+=e.strokeWidth):(o=c.bounds[e.sourceAnchor[1]]+e.sourceOffset[1],u=h.bounds[e.targetAnchor[1]]+e.targetOffset[1],t=c.bounds[e.sourceAnchor[0]]+e.sourceOffset[0]-s[c.id]/2+n[c.id]+e.strokeWidth/2,l=h.bounds[e.targetAnchor[0]]+e.targetOffset[0]-a[h.id]/2+i[h.id]+e.strokeWidth/2,n[c.id]+=e.strokeWidth,i[h.id]+=e.strokeWidth):(t=c.bounds[e.sourceAnchor[0]]+e.sourceOffset[0],o=c.bounds[e.sourceAnchor[1]]+e.sourceOffset[1],l=h.bounds[e.targetAnchor[0]]+e.targetOffset[0],u=h.bounds[e.targetAnchor[1]]+e.targetOffset[1]),e.orientation===$.HORIZONTAL?e._setVertices([[t,o],[(t+l)/2,o],[t,u],[l,u]]):e.orientation===$.VERTICAL&&e._setVertices([[t,o],[t,(o+u)/2],[l,o],[l,u]])}}_updateBundledLinks(t){let r=this._inputVars[0].element.parent.layout;if(r.type!==F.CLUSTER)throw"Bundled links must work on a cluster layout";let n=r._d3Root.leaves();const i=new Map(n.map((e=>[Ar(e),e]))),s=new Map(n.map((e=>[e.data[xe],Ar(e)]))),a=e.lineRadial().curve(e.curveBundle.beta(t[0]._strength)).radius((e=>e.y)).angle((e=>e.x));for(let e of t){let t=e.source.dataScope.getAttributeValue(xe),n=e.target.dataScope.getAttributeValue(xe),o=i.get(s.get(t)),l=i.get(s.get(n));(o.outgoing??=[]).push([o,l]),l.incoming??=[];let u=o.path(l);e._d=oe(a(u),r.x,r.y)}}_updateChordLinks(e){for(let t of e){let e=t.source,r=t.target,n=Se(e.x,e.y,e.innerRadius,e.startAngle),i=Se(e.x,e.y,e.innerRadius,e.endAngle),s=Se(r.x,r.y,r.innerRadius,r.startAngle),a=Se(r.x,r.y,r.innerRadius,r.endAngle);t._d=["M",n[0],n[1],"Q",e.x,e.y,a[0],a[1],"A",e.x,e.y,r.angle,r.angle>180?1:0,1,s[0],s[1],"Q",e.x,e.y,i[0],i[1],"A",e.x,e.y,e.angle,e.angle>180?1:0,1,n[0],n[1]].join(" ")}}_updateLineLinks(e){for(let t of e){let e=t.source,r=t.target;t.vertices[0]._x=e.bounds.x,t.vertices[0]._y=e.bounds.y,t.vertices[1]._x=r.bounds.x,t.vertices[1]._y=r.bounds.y}}}function Ar(e){return`${e.parent?Ar(e.parent)+".":""}${e.data[xe]}`}var Cr,Rr,kr,Sr,Tr,Or,Ir,Nr,Lr,Vr,Pr,Dr,Br,Mr,Gr,jr,zr,Fr,Ur,Hr,Wr,Yr,Xr,qr,Kr,Zr,$r,Jr,Qr,en,tn,rn,nn,sn,an,on,ln,un,cn,hn,dn,fn,pn,_n,gn,yn,mn,bn,vn,xn,En,wn,An,Cn,Rn,kn,Sn,Tn,On,In,Nn,Ln,Vn,Pn,Dn,Bn,Mn,Gn,jn,zn,Fn,Un,Hn,Wn,Yn,Xn,qn,Kn,Zn,$n,Jn,Qn,ei,ti,ri,ni,ii,si,ai,oi,li,ui,ci,hi,di,fi,pi,_i,gi,yi,mi,bi,vi,xi,Ei,wi,Ai,Ci,Ri="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function ki(){if(Sr)return kr;return Sr=1,kr=function(e,t){return e===t||e!=e&&t!=t}}function Si(){if(Or)return Tr;Or=1;var e=ki();return Tr=function(t,r){for(var n=t.length;n--;)if(e(t[n][0],r))return n;return-1}}function Ti(){if(jr)return Gr;jr=1;var e=Rr?Cr:(Rr=1,Cr=function(){this.__data__=[],this.size=0}),t=function(){if(Nr)return Ir;Nr=1;var e=Si(),t=Array.prototype.splice;return Ir=function(r){var n=this.__data__,i=e(n,r);return!(i<0||(i==n.length-1?n.pop():t.call(n,i,1),--this.size,0))}}(),r=function(){if(Vr)return Lr;Vr=1;var e=Si();return Lr=function(t){var r=this.__data__,n=e(r,t);return n<0?void 0:r[n][1]}}(),n=function(){if(Dr)return Pr;Dr=1;var e=Si();return Pr=function(t){return e(this.__data__,t)>-1}}(),i=function(){if(Mr)return Br;Mr=1;var e=Si();return Br=function(t,r){var n=this.__data__,i=e(n,t);return i<0?(++this.size,n.push([t,r])):n[i][1]=r,this}}();function s(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}return s.prototype.clear=e,s.prototype.delete=t,s.prototype.get=r,s.prototype.has=n,s.prototype.set=i,Gr=s}function Oi(){if(Zr)return Kr;Zr=1;var e="object"==typeof Ri&&Ri&&Ri.Object===Object&&Ri;return Kr=e}function Ii(){if(Jr)return $r;Jr=1;var e=Oi(),t="object"==typeof self&&self&&self.Object===Object&&self,r=e||t||Function("return this")();return $r=r}function Ni(){if(en)return Qr;en=1;var e=Ii().Symbol;return Qr=e}function Li(){if(on)return an;on=1;var e=Ni(),t=function(){if(rn)return tn;rn=1;var e=Ni(),t=Object.prototype,r=t.hasOwnProperty,n=t.toString,i=e?e.toStringTag:void 0;return tn=
3
3
  /**
4
4
  * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
5
5
  *
@@ -183,4 +183,4 @@ function(r,n,i){return n=t(void 0===n?r.length-1:n,0),function(){for(var s=argum
183
183
  * @private
184
184
  * @param {Function} func The function to apply a rest parameter to.
185
185
  * @returns {Function} Returns the new function.
186
- */return lp=function(n){return r(t(n,void 0,e),n+"")}}()((function(t,r){return null==t?{}:e(t,r)}));return cp=t}(),range:function(){if(yp)return gp;yp=1;var e=Xp()();return gp=e}(),reduce:yd(),sortBy:function(){if(kp)return Rp;kp=1;var e=xd(),t=Kp(),r=Ad(),n=Dp(),i=r((function(r,i){if(null==r)return[];var s=i.length;return s>1&&n(r,i[0],i[1])?i=[]:s>2&&n(i[0],i[1],i[2])&&(i=[i[0]]),t(r,e(i,1),[])}));return Rp=i}(),uniqueId:function(){if(Tp)return Sp;Tp=1;var e=td(),t=0;return Sp=function(r){var n=++t;return e(r)+n},Sp}(),values:Id(),zipObject:function(){if(Lp)return Np;Lp=1;var e=qi(),t=Ip?Op:(Ip=1,Op=function(e,t,r){for(var n=-1,i=e.length,s=t.length,a={};++n<i;){var o=n<s?t[n]:void 0;r(a,e[n],o)}return a});return Np=function(r,n){return t(r||[],n||[],e)}}()}}catch(e){}Vp||(Vp=window._);var Zp=Vp,$p=Jp;function Jp(){var e={};e._next=e._prev=e,this._sentinel=e}function Qp(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function e_(e,t){if("_next"!==e&&"_prev"!==e)return t}Jp.prototype.dequeue=function(){var e=this._sentinel,t=e._prev;if(t!==e)return Qp(t),t},Jp.prototype.enqueue=function(e){var t=this._sentinel;e._prev&&e._next&&Qp(e),e._next=t._next,t._next._prev=e,t._next=e,e._prev=t},Jp.prototype.toString=function(){for(var e=[],t=this._sentinel,r=t._prev;r!==t;)e.push(JSON.stringify(r,e_)),r=r._prev;return"["+e.join(", ")+"]"};var t_=Zp,r_=Pp.Graph,n_=$p,i_=function(e,t){if(e.nodeCount()<=1)return[];var r=function(e,t){var r=new r_,n=0,i=0;t_.forEach(e.nodes(),(function(e){r.setNode(e,{v:e,in:0,out:0})})),t_.forEach(e.edges(),(function(e){var s=r.edge(e.v,e.w)||0,a=t(e),o=s+a;r.setEdge(e.v,e.w,o),i=Math.max(i,r.node(e.v).out+=a),n=Math.max(n,r.node(e.w).in+=a)}));var s=t_.range(i+n+3).map((function(){return new n_})),a=n+1;return t_.forEach(r.nodes(),(function(e){o_(s,a,r.node(e))})),{graph:r,buckets:s,zeroIdx:a}}(e,t||s_),n=function(e,t,r){var n,i=[],s=t[t.length-1],a=t[0];for(;e.nodeCount();){for(;n=a.dequeue();)a_(e,t,r,n);for(;n=s.dequeue();)a_(e,t,r,n);if(e.nodeCount())for(var o=t.length-2;o>0;--o)if(n=t[o].dequeue()){i=i.concat(a_(e,t,r,n,!0));break}}return i}(r.graph,r.buckets,r.zeroIdx);return t_.flatten(t_.map(n,(function(t){return e.outEdges(t.v,t.w)})),!0)},s_=t_.constant(1);function a_(e,t,r,n,i){var s=i?[]:void 0;return t_.forEach(e.inEdges(n.v),(function(n){var a=e.edge(n),o=e.node(n.v);i&&s.push({v:n.v,w:n.w}),o.out-=a,o_(t,r,o)})),t_.forEach(e.outEdges(n.v),(function(n){var i=e.edge(n),s=n.w,a=e.node(s);a.in-=i,o_(t,r,a)})),e.removeNode(n.v),s}function o_(e,t,r){r.out?r.in?e[r.out-r.in+t].enqueue(r):e[e.length-1].enqueue(r):e[0].enqueue(r)}var l_=Zp,u_=i_,c_={run:function(e){var t="greedy"===e.graph().acyclicer?u_(e,function(e){return function(t){return e.edge(t).weight}}(e)):function(e){var t=[],r={},n={};function i(s){l_.has(n,s)||(n[s]=!0,r[s]=!0,l_.forEach(e.outEdges(s),(function(e){l_.has(r,e.w)?t.push(e):i(e.w)})),delete r[s])}return l_.forEach(e.nodes(),i),t}(e);l_.forEach(t,(function(t){var r=e.edge(t);e.removeEdge(t),r.forwardName=t.name,r.reversed=!0,e.setEdge(t.w,t.v,r,l_.uniqueId("rev"))}))},undo:function(e){l_.forEach(e.edges(),(function(t){var r=e.edge(t);if(r.reversed){e.removeEdge(t);var n=r.forwardName;delete r.reversed,delete r.forwardName,e.setEdge(t.w,t.v,r,n)}}))}};var h_=Zp,d_=Pp.Graph,f_={addDummyNode:p_,simplify:function(e){var t=(new d_).setGraph(e.graph());return h_.forEach(e.nodes(),(function(r){t.setNode(r,e.node(r))})),h_.forEach(e.edges(),(function(r){var n=t.edge(r.v,r.w)||{weight:0,minlen:1},i=e.edge(r);t.setEdge(r.v,r.w,{weight:n.weight+i.weight,minlen:Math.max(n.minlen,i.minlen)})})),t},asNonCompoundGraph:function(e){var t=new d_({multigraph:e.isMultigraph()}).setGraph(e.graph());return h_.forEach(e.nodes(),(function(r){e.children(r).length||t.setNode(r,e.node(r))})),h_.forEach(e.edges(),(function(r){t.setEdge(r,e.edge(r))})),t},successorWeights:function(e){var t=h_.map(e.nodes(),(function(t){var r={};return h_.forEach(e.outEdges(t),(function(t){r[t.w]=(r[t.w]||0)+e.edge(t).weight})),r}));return h_.zipObject(e.nodes(),t)},predecessorWeights:function(e){var t=h_.map(e.nodes(),(function(t){var r={};return h_.forEach(e.inEdges(t),(function(t){r[t.v]=(r[t.v]||0)+e.edge(t).weight})),r}));return h_.zipObject(e.nodes(),t)},intersectRect:function(e,t){var r,n,i=e.x,s=e.y,a=t.x-i,o=t.y-s,l=e.width/2,u=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)*u?(o<0&&(u=-u),r=u*a/o,n=u):(a<0&&(l=-l),r=l,n=l*o/a);return{x:i+r,y:s+n}},buildLayerMatrix:function(e){var t=h_.map(h_.range(__(e)+1),(function(){return[]}));return h_.forEach(e.nodes(),(function(r){var n=e.node(r),i=n.rank;h_.isUndefined(i)||(t[i][n.order]=r)})),t},normalizeRanks:function(e){var t=h_.min(h_.map(e.nodes(),(function(t){return e.node(t).rank})));h_.forEach(e.nodes(),(function(r){var n=e.node(r);h_.has(n,"rank")&&(n.rank-=t)}))},removeEmptyRanks:function(e){var t=h_.min(h_.map(e.nodes(),(function(t){return e.node(t).rank}))),r=[];h_.forEach(e.nodes(),(function(n){var i=e.node(n).rank-t;r[i]||(r[i]=[]),r[i].push(n)}));var n=0,i=e.graph().nodeRankFactor;h_.forEach(r,(function(t,r){h_.isUndefined(t)&&r%i!=0?--n:n&&h_.forEach(t,(function(t){e.node(t).rank+=n}))}))},addBorderNode:function(e,t,r,n){var i={width:0,height:0};arguments.length>=4&&(i.rank=r,i.order=n);return p_(e,"border",i,t)},maxRank:__,partition:function(e,t){var r={lhs:[],rhs:[]};return h_.forEach(e,(function(e){t(e)?r.lhs.push(e):r.rhs.push(e)})),r},time:function(e,t){var r=h_.now();try{return t()}finally{console.log(e+" time: "+(h_.now()-r)+"ms")}},notime:function(e,t){return t()}};function p_(e,t,r,n){var i;do{i=h_.uniqueId(n)}while(e.hasNode(i));return r.dummy=t,e.setNode(i,r),i}function __(e){return h_.max(h_.map(e.nodes(),(function(t){var r=e.node(t).rank;if(!h_.isUndefined(r))return r})))}var g_=Zp,y_=f_,m_={run:function(e){e.graph().dummyChains=[],g_.forEach(e.edges(),(function(t){!function(e,t){var r,n,i,s=t.v,a=e.node(s).rank,o=t.w,l=e.node(o).rank,u=t.name,c=e.edge(t),h=c.labelRank;if(l===a+1)return;for(e.removeEdge(t),i=0,++a;a<l;++i,++a)c.points=[],n={width:0,height:0,edgeLabel:c,edgeObj:t,rank:a},r=y_.addDummyNode(e,"edge",n,"_d"),a===h&&(n.width=c.width,n.height=c.height,n.dummy="edge-label",n.labelpos=c.labelpos),e.setEdge(s,r,{weight:c.weight},u),0===i&&e.graph().dummyChains.push(r),s=r;e.setEdge(s,o,{weight:c.weight},u)}(e,t)}))},undo:function(e){g_.forEach(e.graph().dummyChains,(function(t){var r,n=e.node(t),i=n.edgeLabel;for(e.setEdge(n.edgeObj,i);n.dummy;)r=e.successors(t)[0],e.removeNode(t),i.points.push({x:n.x,y:n.y}),"edge-label"===n.dummy&&(i.x=n.x,i.y=n.y,i.width=n.width,i.height=n.height),t=r,n=e.node(t)}))}};var b_=Zp,v_={longestPath:function(e){var t={};b_.forEach(e.sources(),(function r(n){var i=e.node(n);if(b_.has(t,n))return i.rank;t[n]=!0;var s=b_.min(b_.map(e.outEdges(n),(function(t){return r(t.w)-e.edge(t).minlen})));return s!==Number.POSITIVE_INFINITY&&null!=s||(s=0),i.rank=s}))},slack:function(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}};var x_=Zp,E_=Pp.Graph,w_=v_.slack,A_=function(e){var t,r,n=new E_({directed:!1}),i=e.nodes()[0],s=e.nodeCount();n.setNode(i,{});for(;C_(n,e)<s;)t=R_(n,e),r=n.hasNode(t.v)?w_(e,t):-w_(e,t),k_(n,e,r);return n};function C_(e,t){return x_.forEach(e.nodes(),(function r(n){x_.forEach(t.nodeEdges(n),(function(i){var s=i.v,a=n===s?i.w:s;e.hasNode(a)||w_(t,i)||(e.setNode(a,{}),e.setEdge(n,a,{}),r(a))}))})),e.nodeCount()}function R_(e,t){return x_.minBy(t.edges(),(function(r){if(e.hasNode(r.v)!==e.hasNode(r.w))return w_(t,r)}))}function k_(e,t,r){x_.forEach(e.nodes(),(function(e){t.node(e).rank+=r}))}var S_=Zp,T_=A_,O_=v_.slack,I_=v_.longestPath,N_=Pp.alg.preorder,L_=Pp.alg.postorder,V_=f_.simplify,P_=D_;function D_(e){e=V_(e),I_(e);var t,r=T_(e);for(G_(r),B_(r,e);t=z_(r);)U_(r,e,t,F_(r,e,t))}function B_(e,t){var r=L_(e,e.nodes());r=r.slice(0,r.length-1),S_.forEach(r,(function(r){!function(e,t,r){var n=e.node(r),i=n.parent;e.edge(r,i).cutvalue=M_(e,t,r)}(e,t,r)}))}function M_(e,t,r){var n=e.node(r).parent,i=!0,s=t.edge(r,n),a=0;return s||(i=!1,s=t.edge(n,r)),a=s.weight,S_.forEach(t.nodeEdges(r),(function(s){var o,l,u=s.v===r,c=u?s.w:s.v;if(c!==n){var h=u===i,d=t.edge(s).weight;if(a+=h?d:-d,o=r,l=c,e.hasEdge(o,l)){var f=e.edge(r,c).cutvalue;a+=h?-f:f}}})),a}function G_(e,t){arguments.length<2&&(t=e.nodes()[0]),j_(e,{},1,t)}function j_(e,t,r,n,i){var s=r,a=e.node(n);return t[n]=!0,S_.forEach(e.neighbors(n),(function(i){S_.has(t,i)||(r=j_(e,t,r,i,n))})),a.low=s,a.lim=r++,i?a.parent=i:delete a.parent,r}function z_(e){return S_.find(e.edges(),(function(t){return e.edge(t).cutvalue<0}))}function F_(e,t,r){var n=r.v,i=r.w;t.hasEdge(n,i)||(n=r.w,i=r.v);var s=e.node(n),a=e.node(i),o=s,l=!1;s.lim>a.lim&&(o=a,l=!0);var u=S_.filter(t.edges(),(function(t){return l===H_(e,e.node(t.v),o)&&l!==H_(e,e.node(t.w),o)}));return S_.minBy(u,(function(e){return O_(t,e)}))}function U_(e,t,r,n){var i=r.v,s=r.w;e.removeEdge(i,s),e.setEdge(n.v,n.w,{}),G_(e),B_(e,t),function(e,t){var r=S_.find(e.nodes(),(function(e){return!t.node(e).parent})),n=N_(e,r);n=n.slice(1),S_.forEach(n,(function(r){var n=e.node(r).parent,i=t.edge(r,n),s=!1;i||(i=t.edge(n,r),s=!0),t.node(r).rank=t.node(n).rank+(s?i.minlen:-i.minlen)}))}(e,t)}function H_(e,t,r){return r.low<=t.lim&&t.lim<=r.lim}D_.initLowLimValues=G_,D_.initCutValues=B_,D_.calcCutValue=M_,D_.leaveEdge=z_,D_.enterEdge=F_,D_.exchangeEdges=U_;var W_=v_.longestPath,Y_=A_,X_=P_,q_=function(e){switch(e.graph().ranker){case"network-simplex":default:Z_(e);break;case"tight-tree":!function(e){W_(e),Y_(e)}(e);break;case"longest-path":K_(e)}};var K_=W_;function Z_(e){X_(e)}var $_=Zp,J_=function(e){var t=function(e){var t={},r=0;function n(i){var s=r;$_.forEach(e.children(i),n),t[i]={low:s,lim:r++}}return $_.forEach(e.children(),n),t}(e);$_.forEach(e.graph().dummyChains,(function(r){for(var n=e.node(r),i=n.edgeObj,s=function(e,t,r,n){var i,s,a=[],o=[],l=Math.min(t[r].low,t[n].low),u=Math.max(t[r].lim,t[n].lim);i=r;do{i=e.parent(i),a.push(i)}while(i&&(t[i].low>l||u>t[i].lim));s=i,i=n;for(;(i=e.parent(i))!==s;)o.push(i);return{path:a.concat(o.reverse()),lca:s}}(e,t,i.v,i.w),a=s.path,o=s.lca,l=0,u=a[l],c=!0;r!==i.w;){if(n=e.node(r),c){for(;(u=a[l])!==o&&e.node(u).maxRank<n.rank;)l++;u===o&&(c=!1)}if(!c){for(;l<a.length-1&&e.node(u=a[l+1]).minRank<=n.rank;)l++;u=a[l]}e.setParent(r,u),r=e.successors(r)[0]}}))};var Q_=Zp,eg=f_,tg={run:function(e){var t=eg.addDummyNode(e,"root",{},"_root"),r=function(e){var t={};function r(n,i){var s=e.children(n);s&&s.length&&Q_.forEach(s,(function(e){r(e,i+1)})),t[n]=i}return Q_.forEach(e.children(),(function(e){r(e,1)})),t}(e),n=Q_.max(Q_.values(r))-1,i=2*n+1;e.graph().nestingRoot=t,Q_.forEach(e.edges(),(function(t){e.edge(t).minlen*=i}));var s=function(e){return Q_.reduce(e.edges(),(function(t,r){return t+e.edge(r).weight}),0)}(e)+1;Q_.forEach(e.children(),(function(a){rg(e,t,i,s,n,r,a)})),e.graph().nodeRankFactor=i},cleanup:function(e){var t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,Q_.forEach(e.edges(),(function(t){e.edge(t).nestingEdge&&e.removeEdge(t)}))}};function rg(e,t,r,n,i,s,a){var o=e.children(a);if(o.length){var l=eg.addBorderNode(e,"_bt"),u=eg.addBorderNode(e,"_bb"),c=e.node(a);e.setParent(l,a),c.borderTop=l,e.setParent(u,a),c.borderBottom=u,Q_.forEach(o,(function(o){rg(e,t,r,n,i,s,o);var c=e.node(o),h=c.borderTop?c.borderTop:o,d=c.borderBottom?c.borderBottom:o,f=c.borderTop?n:2*n,p=h!==d?1:i-s[a]+1;e.setEdge(l,h,{weight:f,minlen:p,nestingEdge:!0}),e.setEdge(d,u,{weight:f,minlen:p,nestingEdge:!0})})),e.parent(a)||e.setEdge(t,l,{weight:0,minlen:i+s[a]})}else a!==t&&e.setEdge(t,a,{weight:0,minlen:r})}var ng=Zp,ig=f_,sg=function(e){ng.forEach(e.children(),(function t(r){var n=e.children(r),i=e.node(r);if(n.length&&ng.forEach(n,t),ng.has(i,"minRank")){i.borderLeft=[],i.borderRight=[];for(var s=i.minRank,a=i.maxRank+1;s<a;++s)ag(e,"borderLeft","_bl",r,i,s),ag(e,"borderRight","_br",r,i,s)}}))};function ag(e,t,r,n,i,s){var a={width:0,height:0,rank:s,borderType:t},o=i[t][s-1],l=ig.addDummyNode(e,"border",a,r);i[t][s]=l,e.setParent(l,n),o&&e.setEdge(o,l,{weight:1})}var og=Zp,lg={adjust:function(e){var t=e.graph().rankdir.toLowerCase();"lr"!==t&&"rl"!==t||ug(e)},undo:function(e){var t=e.graph().rankdir.toLowerCase();"bt"!==t&&"rl"!==t||function(e){og.forEach(e.nodes(),(function(t){hg(e.node(t))})),og.forEach(e.edges(),(function(t){var r=e.edge(t);og.forEach(r.points,hg),og.has(r,"y")&&hg(r)}))}(e);"lr"!==t&&"rl"!==t||(!function(e){og.forEach(e.nodes(),(function(t){dg(e.node(t))})),og.forEach(e.edges(),(function(t){var r=e.edge(t);og.forEach(r.points,dg),og.has(r,"x")&&dg(r)}))}(e),ug(e))}};function ug(e){og.forEach(e.nodes(),(function(t){cg(e.node(t))})),og.forEach(e.edges(),(function(t){cg(e.edge(t))}))}function cg(e){var t=e.width;e.width=e.height,e.height=t}function hg(e){e.y=-e.y}function dg(e){var t=e.x;e.x=e.y,e.y=t}var fg=Zp,pg=function(e){var t={},r=fg.filter(e.nodes(),(function(t){return!e.children(t).length})),n=fg.max(fg.map(r,(function(t){return e.node(t).rank}))),i=fg.map(fg.range(n+1),(function(){return[]}));function s(r){if(!fg.has(t,r)){t[r]=!0;var n=e.node(r);i[n.rank].push(r),fg.forEach(e.successors(r),s)}}var a=fg.sortBy(r,(function(t){return e.node(t).rank}));return fg.forEach(a,s),i};var _g=Zp,gg=function(e,t){for(var r=0,n=1;n<t.length;++n)r+=yg(e,t[n-1],t[n]);return r};function yg(e,t,r){for(var n=_g.zipObject(r,_g.map(r,(function(e,t){return t}))),i=_g.flatten(_g.map(t,(function(t){return _g.sortBy(_g.map(e.outEdges(t),(function(t){return{pos:n[t.w],weight:e.edge(t).weight}})),"pos")})),!0),s=1;s<r.length;)s<<=1;var a=2*s-1;s-=1;var o=_g.map(new Array(a),(function(){return 0})),l=0;return _g.forEach(i.forEach((function(e){var t=e.pos+s;o[t]+=e.weight;for(var r=0;t>0;)t%2&&(r+=o[t+1]),o[t=t-1>>1]+=e.weight;l+=e.weight*r}))),l}var mg=Zp;var bg=Zp;var vg=Zp,xg=f_;function Eg(e,t,r){for(var n;t.length&&(n=vg.last(t)).i<=r;)t.pop(),e.push(n.vs),r++;return r}var wg=Zp,Ag=function(e,t){return mg.map(t,(function(t){var r=e.inEdges(t);if(r.length){var n=mg.reduce(r,(function(t,r){var n=e.edge(r),i=e.node(r.v);return{sum:t.sum+n.weight*i.order,weight:t.weight+n.weight}}),{sum:0,weight:0});return{v:t,barycenter:n.sum/n.weight,weight:n.weight}}return{v:t}}))},Cg=function(e,t){var r={};return bg.forEach(e,(function(e,t){var n=r[e.v]={indegree:0,in:[],out:[],vs:[e.v],i:t};bg.isUndefined(e.barycenter)||(n.barycenter=e.barycenter,n.weight=e.weight)})),bg.forEach(t.edges(),(function(e){var t=r[e.v],n=r[e.w];bg.isUndefined(t)||bg.isUndefined(n)||(n.indegree++,t.out.push(r[e.w]))})),function(e){var t=[];function r(e){return function(t){t.merged||(bg.isUndefined(t.barycenter)||bg.isUndefined(e.barycenter)||t.barycenter>=e.barycenter)&&function(e,t){var r=0,n=0;e.weight&&(r+=e.barycenter*e.weight,n+=e.weight);t.weight&&(r+=t.barycenter*t.weight,n+=t.weight);e.vs=t.vs.concat(e.vs),e.barycenter=r/n,e.weight=n,e.i=Math.min(t.i,e.i),t.merged=!0}(e,t)}}function n(t){return function(r){r.in.push(t),0==--r.indegree&&e.push(r)}}for(;e.length;){var i=e.pop();t.push(i),bg.forEach(i.in.reverse(),r(i)),bg.forEach(i.out,n(i))}return bg.map(bg.filter(t,(function(e){return!e.merged})),(function(e){return bg.pick(e,["vs","i","barycenter","weight"])}))}(bg.filter(r,(function(e){return!e.indegree})))},Rg=function(e,t){var r=xg.partition(e,(function(e){return vg.has(e,"barycenter")})),n=r.lhs,i=vg.sortBy(r.rhs,(function(e){return-e.i})),s=[],a=0,o=0,l=0;n.sort((u=!!t,function(e,t){return e.barycenter<t.barycenter?-1:e.barycenter>t.barycenter?1:u?t.i-e.i:e.i-t.i})),l=Eg(s,i,l),vg.forEach(n,(function(e){l+=e.vs.length,s.push(e.vs),a+=e.barycenter*e.weight,o+=e.weight,l=Eg(s,i,l)}));var u;var c={vs:vg.flatten(s,!0)};o&&(c.barycenter=a/o,c.weight=o);return c},kg=function e(t,r,n,i){var s=t.children(r),a=t.node(r),o=a?a.borderLeft:void 0,l=a?a.borderRight:void 0,u={};o&&(s=wg.filter(s,(function(e){return e!==o&&e!==l})));var c=Ag(t,s);wg.forEach(c,(function(r){if(t.children(r.v).length){var s=e(t,r.v,n,i);u[r.v]=s,wg.has(s,"barycenter")&&(a=r,o=s,wg.isUndefined(a.barycenter)?(a.barycenter=o.barycenter,a.weight=o.weight):(a.barycenter=(a.barycenter*a.weight+o.barycenter*o.weight)/(a.weight+o.weight),a.weight+=o.weight))}var a,o}));var h=Cg(c,n);!function(e,t){wg.forEach(e,(function(e){e.vs=wg.flatten(e.vs.map((function(e){return t[e]?t[e].vs:e})),!0)}))}(h,u);var d=Rg(h,i);if(o&&(d.vs=wg.flatten([o,d.vs,l],!0),t.predecessors(o).length)){var f=t.node(t.predecessors(o)[0]),p=t.node(t.predecessors(l)[0]);wg.has(d,"barycenter")||(d.barycenter=0,d.weight=0),d.barycenter=(d.barycenter*d.weight+f.order+p.order)/(d.weight+2),d.weight+=2}return d};var Sg=Zp,Tg=Pp.Graph,Og=function(e,t,r){var n=function(e){var t;for(;e.hasNode(t=Sg.uniqueId("_root")););return t}(e),i=new Tg({compound:!0}).setGraph({root:n}).setDefaultNodeLabel((function(t){return e.node(t)}));return Sg.forEach(e.nodes(),(function(s){var a=e.node(s),o=e.parent(s);(a.rank===t||a.minRank<=t&&t<=a.maxRank)&&(i.setNode(s),i.setParent(s,o||n),Sg.forEach(e[r](s),(function(t){var r=t.v===s?t.w:t.v,n=i.edge(r,s),a=Sg.isUndefined(n)?0:n.weight;i.setEdge(r,s,{weight:e.edge(t).weight+a})})),Sg.has(a,"minRank")&&i.setNode(s,{borderLeft:a.borderLeft[t],borderRight:a.borderRight[t]}))})),i};var Ig=Zp;var Ng=Zp,Lg=pg,Vg=gg,Pg=kg,Dg=Og,Bg=function(e,t,r){var n,i={};Ig.forEach(r,(function(r){for(var s,a,o=e.parent(r);o;){if((s=e.parent(o))?(a=i[s],i[s]=o):(a=n,n=o),a&&a!==o)return void t.setEdge(a,o);o=s}}))},Mg=Pp.Graph,Gg=f_,jg=function(e){var t=Gg.maxRank(e),r=zg(e,Ng.range(1,t+1),"inEdges"),n=zg(e,Ng.range(t-1,-1,-1),"outEdges"),i=Lg(e);Ug(e,i);for(var s,a=Number.POSITIVE_INFINITY,o=0,l=0;l<4;++o,++l){Fg(o%2?r:n,o%4>=2),i=Gg.buildLayerMatrix(e);var u=Vg(e,i);u<a&&(l=0,s=Ng.cloneDeep(i),a=u)}Ug(e,s)};function zg(e,t,r){return Ng.map(t,(function(t){return Dg(e,t,r)}))}function Fg(e,t){var r=new Mg;Ng.forEach(e,(function(e){var n=e.graph().root,i=Pg(e,n,r,t);Ng.forEach(i.vs,(function(t,r){e.node(t).order=r})),Bg(e,r,i.vs)}))}function Ug(e,t){Ng.forEach(t,(function(t){Ng.forEach(t,(function(t,r){e.node(t).order=r}))}))}var Hg=Zp,Wg=Pp.Graph,Yg=f_,Xg=function(e){var t,r=Yg.buildLayerMatrix(e),n=Hg.merge(qg(e,r),Kg(e,r)),i={};Hg.forEach(["u","d"],(function(s){t="u"===s?r:Hg.values(r).reverse(),Hg.forEach(["l","r"],(function(r){"r"===r&&(t=Hg.map(t,(function(e){return Hg.values(e).reverse()})));var a=("u"===s?e.predecessors:e.successors).bind(e),o=Jg(e,t,n,a),l=Qg(e,t,o.root,o.align,"r"===r);"r"===r&&(l=Hg.mapValues(l,(function(e){return-e}))),i[s+r]=l}))}));var s=ey(e,i);return ty(i,s),ry(i,e.graph().align)};function qg(e,t){var r={};return Hg.reduce(t,(function(t,n){var i=0,s=0,a=t.length,o=Hg.last(n);return Hg.forEach(n,(function(t,l){var u=function(e,t){if(e.node(t).dummy)return Hg.find(e.predecessors(t),(function(t){return e.node(t).dummy}))}(e,t),c=u?e.node(u).order:a;(u||t===o)&&(Hg.forEach(n.slice(s,l+1),(function(t){Hg.forEach(e.predecessors(t),(function(n){var s=e.node(n),a=s.order;!(a<i||c<a)||s.dummy&&e.node(t).dummy||Zg(r,n,t)}))})),s=l+1,i=c)})),n})),r}function Kg(e,t){var r={};function n(t,n,i,s,a){var o;Hg.forEach(Hg.range(n,i),(function(n){o=t[n],e.node(o).dummy&&Hg.forEach(e.predecessors(o),(function(t){var n=e.node(t);n.dummy&&(n.order<s||n.order>a)&&Zg(r,t,o)}))}))}return Hg.reduce(t,(function(t,r){var i,s=-1,a=0;return Hg.forEach(r,(function(o,l){if("border"===e.node(o).dummy){var u=e.predecessors(o);u.length&&(i=e.node(u[0]).order,n(r,a,l,s,i),a=l,s=i)}n(r,a,r.length,i,t.length)})),r})),r}function Zg(e,t,r){if(t>r){var n=t;t=r,r=n}var i=e[t];i||(e[t]=i={}),i[r]=!0}function $g(e,t,r){if(t>r){var n=t;t=r,r=n}return Hg.has(e[t],r)}function Jg(e,t,r,n){var i={},s={},a={};return Hg.forEach(t,(function(e){Hg.forEach(e,(function(e,t){i[e]=e,s[e]=e,a[e]=t}))})),Hg.forEach(t,(function(e){var t=-1;Hg.forEach(e,(function(e){var o=n(e);if(o.length){o=Hg.sortBy(o,(function(e){return a[e]}));for(var l=(o.length-1)/2,u=Math.floor(l),c=Math.ceil(l);u<=c;++u){var h=o[u];s[e]===e&&t<a[h]&&!$g(r,e,h)&&(s[h]=e,s[e]=i[e]=i[h],t=a[h])}}}))})),{root:i,align:s}}function Qg(e,t,r,n,i){var s={},a=function(e,t,r,n){var i=new Wg,s=e.graph(),a=function(e,t,r){return function(n,i,s){var a,o=n.node(i),l=n.node(s),u=0;if(u+=o.width/2,Hg.has(o,"labelpos"))switch(o.labelpos.toLowerCase()){case"l":a=-o.width/2;break;case"r":a=o.width/2}if(a&&(u+=r?a:-a),a=0,u+=(o.dummy?t:e)/2,u+=(l.dummy?t:e)/2,u+=l.width/2,Hg.has(l,"labelpos"))switch(l.labelpos.toLowerCase()){case"l":a=l.width/2;break;case"r":a=-l.width/2}return a&&(u+=r?a:-a),a=0,u}}(s.nodesep,s.edgesep,n);return Hg.forEach(t,(function(t){var n;Hg.forEach(t,(function(t){var s=r[t];if(i.setNode(s),n){var o=r[n],l=i.edge(o,s);i.setEdge(o,s,Math.max(a(e,t,n),l||0))}n=t}))})),i}(e,t,r,i),o=i?"borderLeft":"borderRight";function l(e,t){for(var r=a.nodes(),n=r.pop(),i={};n;)i[n]?e(n):(i[n]=!0,r.push(n),r=r.concat(t(n))),n=r.pop()}return l((function(e){s[e]=a.inEdges(e).reduce((function(e,t){return Math.max(e,s[t.v]+a.edge(t))}),0)}),a.predecessors.bind(a)),l((function(t){var r=a.outEdges(t).reduce((function(e,t){return Math.min(e,s[t.w]-a.edge(t))}),Number.POSITIVE_INFINITY),n=e.node(t);r!==Number.POSITIVE_INFINITY&&n.borderType!==o&&(s[t]=Math.max(s[t],r))}),a.successors.bind(a)),Hg.forEach(n,(function(e){s[e]=s[r[e]]})),s}function ey(e,t){return Hg.minBy(Hg.values(t),(function(t){var r=Number.NEGATIVE_INFINITY,n=Number.POSITIVE_INFINITY;return Hg.forIn(t,(function(t,i){var s=function(e,t){return e.node(t).width}(e,i)/2;r=Math.max(t+s,r),n=Math.min(t-s,n)})),r-n}))}function ty(e,t){var r=Hg.values(t),n=Hg.min(r),i=Hg.max(r);Hg.forEach(["u","d"],(function(r){Hg.forEach(["l","r"],(function(s){var a,o=r+s,l=e[o];if(l!==t){var u=Hg.values(l);(a="l"===s?n-Hg.min(u):i-Hg.max(u))&&(e[o]=Hg.mapValues(l,(function(e){return e+a})))}}))}))}function ry(e,t){return Hg.mapValues(e.ul,(function(r,n){if(t)return e[t.toLowerCase()][n];var i=Hg.sortBy(Hg.map(e,n));return(i[1]+i[2])/2}))}var ny=Zp,iy=f_,sy=Xg;var ay=Zp,oy=c_,ly=m_,uy=q_,cy=f_.normalizeRanks,hy=J_,dy=f_.removeEmptyRanks,fy=tg,py=sg,_y=lg,gy=jg,yy=function(e){(function(e){var t=iy.buildLayerMatrix(e),r=e.graph().ranksep,n=0;ny.forEach(t,(function(t){var i=ny.max(ny.map(t,(function(t){return e.node(t).height})));ny.forEach(t,(function(t){e.node(t).y=n+i/2})),n+=i+r}))})(e=iy.asNonCompoundGraph(e)),ny.forEach(sy(e),(function(t,r){e.node(r).x=t}))},my=f_,by=Pp.Graph,vy=function(e,t){var r=t&&t.debugTiming?my.time:my.notime;r("layout",(function(){var t=r(" buildLayoutGraph",(function(){return function(e){var t=new by({multigraph:!0,compound:!0}),r=Oy(e.graph());return t.setGraph(ay.merge({},Ey,Ty(r,xy),ay.pick(r,wy))),ay.forEach(e.nodes(),(function(r){var n=Oy(e.node(r));t.setNode(r,ay.defaults(Ty(n,Ay),Cy)),t.setParent(r,e.parent(r))})),ay.forEach(e.edges(),(function(r){var n=Oy(e.edge(r));t.setEdge(r,ay.merge({},ky,Ty(n,Ry),ay.pick(n,Sy)))})),t}(e)}));r(" runLayout",(function(){!function(e,t){t(" makeSpaceForEdgeLabels",(function(){!function(e){var t=e.graph();t.ranksep/=2,ay.forEach(e.edges(),(function(r){var n=e.edge(r);n.minlen*=2,"c"!==n.labelpos.toLowerCase()&&("TB"===t.rankdir||"BT"===t.rankdir?n.width+=n.labeloffset:n.height+=n.labeloffset)}))}(e)})),t(" removeSelfEdges",(function(){!function(e){ay.forEach(e.edges(),(function(t){if(t.v===t.w){var r=e.node(t.v);r.selfEdges||(r.selfEdges=[]),r.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}}))}(e)})),t(" acyclic",(function(){oy.run(e)})),t(" nestingGraph.run",(function(){fy.run(e)})),t(" rank",(function(){uy(my.asNonCompoundGraph(e))})),t(" injectEdgeLabelProxies",(function(){!function(e){ay.forEach(e.edges(),(function(t){var r=e.edge(t);if(r.width&&r.height){var n=e.node(t.v),i={rank:(e.node(t.w).rank-n.rank)/2+n.rank,e:t};my.addDummyNode(e,"edge-proxy",i,"_ep")}}))}(e)})),t(" removeEmptyRanks",(function(){dy(e)})),t(" nestingGraph.cleanup",(function(){fy.cleanup(e)})),t(" normalizeRanks",(function(){cy(e)})),t(" assignRankMinMax",(function(){!function(e){var t=0;ay.forEach(e.nodes(),(function(r){var n=e.node(r);n.borderTop&&(n.minRank=e.node(n.borderTop).rank,n.maxRank=e.node(n.borderBottom).rank,t=ay.max(t,n.maxRank))})),e.graph().maxRank=t}(e)})),t(" removeEdgeLabelProxies",(function(){!function(e){ay.forEach(e.nodes(),(function(t){var r=e.node(t);"edge-proxy"===r.dummy&&(e.edge(r.e).labelRank=r.rank,e.removeNode(t))}))}(e)})),t(" normalize.run",(function(){ly.run(e)})),t(" parentDummyChains",(function(){hy(e)})),t(" addBorderSegments",(function(){py(e)})),t(" order",(function(){gy(e)})),t(" insertSelfEdges",(function(){!function(e){var t=my.buildLayerMatrix(e);ay.forEach(t,(function(t){var r=0;ay.forEach(t,(function(t,n){var i=e.node(t);i.order=n+r,ay.forEach(i.selfEdges,(function(t){my.addDummyNode(e,"selfedge",{width:t.label.width,height:t.label.height,rank:i.rank,order:n+ ++r,e:t.e,label:t.label},"_se")})),delete i.selfEdges}))}))}(e)})),t(" adjustCoordinateSystem",(function(){_y.adjust(e)})),t(" position",(function(){yy(e)})),t(" positionSelfEdges",(function(){!function(e){ay.forEach(e.nodes(),(function(t){var r=e.node(t);if("selfedge"===r.dummy){var n=e.node(r.e.v),i=n.x+n.width/2,s=n.y,a=r.x-i,o=n.height/2;e.setEdge(r.e,r.label),e.removeNode(t),r.label.points=[{x:i+2*a/3,y:s-o},{x:i+5*a/6,y:s-o},{x:i+a,y:s},{x:i+5*a/6,y:s+o},{x:i+2*a/3,y:s+o}],r.label.x=r.x,r.label.y=r.y}}))}(e)})),t(" removeBorderNodes",(function(){!function(e){ay.forEach(e.nodes(),(function(t){if(e.children(t).length){var r=e.node(t),n=e.node(r.borderTop),i=e.node(r.borderBottom),s=e.node(ay.last(r.borderLeft)),a=e.node(ay.last(r.borderRight));r.width=Math.abs(a.x-s.x),r.height=Math.abs(i.y-n.y),r.x=s.x+r.width/2,r.y=n.y+r.height/2}})),ay.forEach(e.nodes(),(function(t){"border"===e.node(t).dummy&&e.removeNode(t)}))}(e)})),t(" normalize.undo",(function(){ly.undo(e)})),t(" fixupEdgeLabelCoords",(function(){!function(e){ay.forEach(e.edges(),(function(t){var r=e.edge(t);if(ay.has(r,"x"))switch("l"!==r.labelpos&&"r"!==r.labelpos||(r.width-=r.labeloffset),r.labelpos){case"l":r.x-=r.width/2+r.labeloffset;break;case"r":r.x+=r.width/2+r.labeloffset}}))}(e)})),t(" undoCoordinateSystem",(function(){_y.undo(e)})),t(" translateGraph",(function(){!function(e){var t=Number.POSITIVE_INFINITY,r=0,n=Number.POSITIVE_INFINITY,i=0,s=e.graph(),a=s.marginx||0,o=s.marginy||0;function l(e){var s=e.x,a=e.y,o=e.width,l=e.height;t=Math.min(t,s-o/2),r=Math.max(r,s+o/2),n=Math.min(n,a-l/2),i=Math.max(i,a+l/2)}ay.forEach(e.nodes(),(function(t){l(e.node(t))})),ay.forEach(e.edges(),(function(t){var r=e.edge(t);ay.has(r,"x")&&l(r)})),t-=a,n-=o,ay.forEach(e.nodes(),(function(r){var i=e.node(r);i.x-=t,i.y-=n})),ay.forEach(e.edges(),(function(r){var i=e.edge(r);ay.forEach(i.points,(function(e){e.x-=t,e.y-=n})),ay.has(i,"x")&&(i.x-=t),ay.has(i,"y")&&(i.y-=n)})),s.width=r-t+a,s.height=i-n+o}(e)})),t(" assignNodeIntersects",(function(){!function(e){ay.forEach(e.edges(),(function(t){var r,n,i=e.edge(t),s=e.node(t.v),a=e.node(t.w);i.points?(r=i.points[0],n=i.points[i.points.length-1]):(i.points=[],r=a,n=s),i.points.unshift(my.intersectRect(s,r)),i.points.push(my.intersectRect(a,n))}))}(e)})),t(" reversePoints",(function(){!function(e){ay.forEach(e.edges(),(function(t){var r=e.edge(t);r.reversed&&r.points.reverse()}))}(e)})),t(" acyclic.undo",(function(){oy.undo(e)}))}(t,r)})),r(" updateInputGraph",(function(){!function(e,t){ay.forEach(e.nodes(),(function(r){var n=e.node(r),i=t.node(r);n&&(n.x=i.x,n.y=i.y,t.children(r).length&&(n.width=i.width,n.height=i.height))})),ay.forEach(e.edges(),(function(r){var n=e.edge(r),i=t.edge(r);n.points=i.points,ay.has(i,"x")&&(n.x=i.x,n.y=i.y)})),e.graph().width=t.graph().width,e.graph().height=t.graph().height}(e,t)}))}))};var xy=["nodesep","edgesep","ranksep","marginx","marginy"],Ey={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},wy=["acyclicer","ranker","rankdir","align"],Ay=["width","height"],Cy={width:0,height:0},Ry=["minlen","weight","width","height","labeloffset"],ky={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},Sy=["labelpos"];function Ty(e,t){return ay.mapValues(ay.pick(e,t),Number)}function Oy(e){var t={};return ay.forEach(e,(function(e,r){t[r.toLowerCase()]=e})),t}var Iy=Zp,Ny=f_,Ly=Pp.Graph;var Vy={graphlib:Pp,layout:vy,debug:{debugOrdering:function(e){var t=Ny.buildLayerMatrix(e),r=new Ly({compound:!0,multigraph:!0}).setGraph({});return Iy.forEach(e.nodes(),(function(t){r.setNode(t,{label:t}),r.setParent(t,"layer"+e.node(t).rank)})),Iy.forEach(e.edges(),(function(e){r.setEdge(e.v,e.w,{},e.name)})),Iy.forEach(t,(function(e,t){var n="layer"+t;r.setNode(n,{rank:"same"}),Iy.reduce(e,(function(e,t){return r.setEdge(e,t,{style:"invis"}),t}))})),r}},util:{time:f_.time,notime:f_.notime},version:"0.8.5"};class Py extends H{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=S(e.parent);for(let e of t){let t=e.layout;if(!t)continue;let n=be(e.children[0]);if(!n)continue;var r=new Vy.graphlib.Graph;r.setGraph({edgesep:t._edgeSep}),r.setDefaultEdgeLabel((function(){return{}})),r.graph().rankdir=this._getDagreDirection(t.direction);let i=new Map;for(let t of e.children){let e=t.dataScope.getAttributeValue(xe);i.set(e,e+""),r.setNode(e,{label:t.text?t.text:"",width:t.bounds.width,height:t.bounds.height})}for(let e of n.linkList)r.setEdge(e.source,e.target);Vy.layout(r);const s={};let a=Math.min(...r.nodes().map((e=>r.node(e).y))),o=Math.min(...r.nodes().map((e=>r.node(e).x))),l=t.left-o,u=t.top-a;for(const e of r.nodes())s[e]={x:r.node(e).x+l,y:r.node(e).y+u};for(let t of e.children){let e=t.dataScope.getAttributeValue(xe);je(t,s[i.get(e)].x-t.x,s[i.get(e)].y-t.y)}}let n=G(e,!0);for(let e of n)f(e)}_getDagreDirection(e){switch(e){case J.Left2Right:return"LR";case J.Right2Left:return"RL";case J.Top2Bottom:return"TB";case J.Bottom2Top:return"BT"}}}class Dy extends H{constructor(e){super(e)}run(){super.run();let t=this._outputVars[0].element,r=S(t.parent);for(let t of r){let r=t.layout;if(!r)continue;let n=ye(t.children[0]);if(!n)continue;let i=e.hierarchy(n._data),s=Math.max(...t.children.map((e=>e.bounds.width))),a=Math.max(...t.children.map((e=>e.bounds.height))),o=r.orientation==$.HORIZONTAL?[r.height,r.width]:[r.width,r.height],l=e.tree().nodeSize([s,a]).size(o)(i);this._apply(l,r,t)}f(t)}_apply(e,t,r){let n,i,s=r.children.filter((t=>t.dataScope.getAttributeValue(xe)==e.data[xe]))[0];switch(t.orientation){case $.HORIZONTAL:n=e.y+t.left,i=e.x+t.top;break;case $.VERTICAL:n=e.x+t.left,i=t.top+e.y}if(je(s,n-s.x,i-s.y),e.children&&e.children.length>0)for(let n of e.children)this._apply(n,t,r)}}class By extends H{constructor(e){super(e)}run(){super.run();let t=this._outputVars[0].element,r=this._inputVars.filter((e=>e.type===X.ORDER))[0].element,n=r.layout,i=n.width?n.width:r.bounds.width,s=n.height?n.height:r.bounds.height,a=void 0===n.top?r.bounds.top:n.top,o=void 0===n.left?r.bounds.left:n.left,l=e.hierarchy(r).sum((e=>e.type===Tt.Rect?e.width*e.height:0));e.treemap().size([i,s])(l),this._apply(l,o,a);let u=G(t,!0);for(let e of u)f(e)}_apply(e,t,r){if(e.data.type==Tt.Collection&&e.children)for(let n of e.children)this._apply(n,t,r);else e.data.type==Tt.Rect&&(e.data.resize(e.x1-e.x0,e.y1-e.y0),je(e.data,e.x0+t-e.data.left,e.y0+r-e.data.top))}}class My extends H{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=S(e.parent);for(let e of t){if(!e.layout)continue;if(0===e.children.length)continue;let t=ye(e.children[0]);if(!t)continue;let r={};for(let t of e.children)r[t.dataScope.getAttributeValue(xe)]=t;e.children[0].type===Tt.Rect?this._layoutRects(t.getRoot(),t,r):this._layoutArcs(t.getRoot(),t,r)}f(e)}_layoutArcs(e,t,r){let n=t.getChildren(e);if(0===n.length)return;let i=r[e[xe]],s=!i||i.type!=Tt.Arc&&i.type!=Tt.Pie?60:i.startAngle;for(let e=0;e<n.length;e++){let i=n[e],a=r[i[xe]];if(a.type===Tt.Arc){let e=he(s+a.angle);a.setAngles(s,e),s=e}this._layoutArcs(i,t,r)}}_layoutRects(e,t,r){let n=t.getChildren(e);if(0===n.length)return;let i,s,a=r[e[xe]];this._direction,J.Top2Bottom,i=a.left,s=a.bottom;for(let e=0;e<n.length;e++){let a=n[e],o=r[a[xe]];je(o,i-o.left,s-o.top),i+=o.width,this._layoutRects(a,t,r)}}}class Gy extends Y{constructor(e,t){super(e),this._trigger=t}get trigger(){return this._trigger}}class jy extends H{constructor(e){super(e)}run(){super.run();let e=this.outputVar.condEncoding,t=e.trigger,r=S(e.target),n={};if(t.type===Ze.ELEMENT){let i=t.elements.length>0?t.elements:[void 0];r.forEach((t=>n[t.id]=i.map((r=>e._targetEval(r,t))).some((e=>e))))}t.type===Ze.MOUSE&&r.forEach((r=>n[r.id]=e._targetEval(t.mouseEvent,r))),e.evalResult=n}}class zy extends H{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=S(e.parent);for(let e of t){let t=e.layout;if(!t)continue;let r=360/e.children.length;for(let[n,i]of e.children.entries())je(i,t.x+t.radius-i.bounds.x,t.y-i.bounds.y),i._rotate=[n*r,t.x,t.y]}let r=G(e,!0);for(let e of r)f(e)}}class Fy extends H{constructor(e){super(e)}run(){super.run();let t=this._outputVars[0].element,r=S(t.parent);for(let n of r){let r=n.layout;if(!r)continue;let i=r._tree?r._tree._data:ye(n.children[0])._data,s=e.hierarchy(i);if(r.isRadial()){s=e.cluster().size([ue(r.angleExtent),r.radius])(s),r._d3Root=s;const t=new Map(s.descendants().map((e=>[e.data[xe],[e.x,e.y]])));for(let e of n.children){let n=e.dataScope.getAttributeValue(xe);je(e,r.x-e.bounds.x,r.y-t.get(n)[1]-e.bounds.y),e._rotate=[ce(t.get(n)[0]),r.x,r.y]}}else if(r.orientation===$.VERTICAL){!r.width||r.width;let i=r.height?r.height:600;s=e.cluster().nodeSize([t.bounds.width+1,i/(s.height+1)])(s),r._d3Root=s;const a=new Map(s.descendants().map((e=>[e.data[xe],[e.x,e.y]])));let o=1/0,l=-o;s.each((e=>{e.x>l&&(l=e.x),e.x<o&&(o=e.x)})),r._x0=o;for(let e of n.children){let t=e.dataScope.getAttributeValue(xe);je(e,a.get(t)[0]-o+r.left-e.bounds.x,a.get(t)[1]+r.top-e.bounds.y)}}else if(r.orientation===$.HORIZONTAL){!r.width||r.width;let i=r.height?r.height:600;s=e.cluster().nodeSize([t.bounds.height,i/(s.height+1)])(s),r._d3Root=s;const a=new Map(s.descendants().map((e=>[e.data[xe],[e.x,e.y]])));let o=1/0,l=-o;s.each((e=>{e.x>l&&(l=e.x),e.x<o&&(o=e.x)})),r._x0=o;for(let e of n.children){let t=e.dataScope.getAttributeValue(xe);je(e,a.get(t)[1]+r.left-e.bounds.x,a.get(t)[0]-o+r.top-e.bounds.y)}}}let n=G(t,!0);for(let e of n)f(e)}}class Uy{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:"DomainVar"===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):t.scale=e.scale,t}));const r={};for(const e in this._operators)r[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===W.DOMAIN_BUILDER?t.aggregator=e.aggregator:e.type===W.SCALE_BUILDER&&(t.channel=e.channel),t}));return{edges:e,variables:t,operators:r}}getVariable(e,...t){if(Object.values(X).indexOf(e)<0)throw new Error("Variable Type Not Known");let r=this.findVariable(e,t);if(r)return r;switch(e){case X.CHANNEL:r=new Te(e,t[0],t[1]),"vertex"!=t[1].type&&"segment"!=t[1].type||this._connectPathElement2Size(t[1],r);break;case X.PROPERTY:r=new Je(e,t[0],t[1]);break;case X.ATTRIBUTE:r=new jt(e,t[0],t[1]);break;case X.ITEMS:r=new hr(e,t[0],t[1]);break;case X.DOMAIN:r=new zt(e,t[0]);break;case X.DATASCOPE:r=new Bt(e,t[0]);break;case X.BOUNDS:r=new Dt(e,t[0]);break;case X.ORDER:r=new dr(e,t[0]);break;case X.SCALE:r=new qe(e,t[0]);break;case X.COND_ENCODING:r=new q(e,t[0]);break;case X.AFFIXATION:r=new pr(e,t[0]);break;case X.ALIGNMENT:r=new xr(e,t[0]);break;case X.TRIGGER:r=new Gy(e,t[0])}return e in this._variables||(this._variables[e]={}),this._variables[e][r.id]=r,r}_connectPathElement2Size(e,t){let r=e.parent,n=t.channel,i=this.findVariable(X.CHANNEL,["x"===n?"width":"height",r]);if(i){let e=i.incomingDataflow;e||(e=this.createOneWayDependency(W.CONDUIT)),this.connect(t,e),this.connect(e,i)}}findIncomingDataflowOperator(e,t){return t.incomingDataflow&&t.incomingDataflow.type===e?t.incomingDataflow:void 0}getIncomingDataflowOperator(e,t){let r=this.findIncomingDataflowOperator(e,t);return r||this.createOneWayDependency(e)}getOutgoingDataflowOperator(e,t){for(let r of t.outgoingEdges)if(r.toNode instanceof H&&r.toNode.type===e)return r.toNode;return this.createOneWayDependency(e)}createOneWayDependency(e,...t){if(Object.values(W).indexOf(e)<0)throw new Error("Dependency Type Not Known");let r;switch(e){case W.EVAL_BBOX:r=new Xt(e);break;case W.AFFIXER:r=new fr(e);break;case W.DOMAIN_BUILDER:r=new Ft(e,t[0]);break;case W.SCALE_BUILDER:r=new Yt(e,t[0]);break;case W.ENCODER:r=new $e(e,t[0]);break;case W.AXIS_PATH_PLACER:r=new rr(e);break;case W.AXIS_TICKS_PLACER:r=new nr(e);break;case W.AXIS_LABELS_PLACER:r=new ir(e);break;case W.AXIS_TITLE_PLACER:r=new br(e);break;case W.LINK_PLACER:r=new wr(e);break;case W.GRID_LAYOUT:r=new sr(e);break;case W.STACK_LAYOUT:r=new or(e);break;case W.PACK_LAYOUT:r=new mr(e);break;case W.FORCE_LAYOUT:r=new Er(e);break;case W.DIRECTED_LAYOUT:r=new Py(e);break;case W.TIDY_TREE_LAYOUT:r=new Dy(e);break;case W.TREEMAP_LAYOUT:r=new By(e);break;case W.STRATA_LAYOUT:r=new My(e);break;case W.CIRCULAR_LAYOUT:r=new zy(e);break;case W.CLUSTER_LAYOUT:r=new Fy(e);break;case W.GRIDLINES_PLACER:r=new ar(e);break;case W.BIN_TRANSFORMER:r=new ur(e);break;case W.FILTER_TRANSFORMER:r=new cr(e);break;case W.KDE_TRANSFORMER:r=new _r(e);break;case W.TARGET_EVALUATOR:r=new jy(e);break;case W.CONDUIT:default:r=new lr(e)}return e in this._operators||(this._operators[e]={}),this._operators[e][r.id]=r,r}createMultiWayDependency(e){if(Object.values(W).indexOf(e)<0)throw new Error("Dependency Type Not Known");let t;return W.ALIGNER,t=new vr(e),e in this._operators||(this._operators[e]={}),this._operators[e][t.id]=t,t}connect(e,t,r=!0){if(e instanceof Y&&t instanceof H){if(!t.inputVars.includes(e)){const n=new Gt(e,t,r);this._edges.push(n),e.outgoingEdges.push(n),t.inputVars.push(e)}}else if(e instanceof H&&t instanceof Y){if(!e.outputVars.includes(t)){const n=new Gt(e,t,r);this._edges.push(n),e.outputVars.push(t),t.incomingEdges.push(n)}}else if(e instanceof Y&&t instanceof Mt){if(!t.vars.includes(e)){const r=new Gt(e,t,!1);this._edges.push(r),t.vars.push(e),t.edges.push(e),e.undirectedEdges.push(r)}}else{if(!(e instanceof Mt&&t instanceof Y))throw new Error("An edge must connect a variable and an operator.");if(!e.vars.includes(t)){const r=new Gt(t,e,!1);this._edges.push(r),e.vars.push(t),e.edges.push(t),t.undirectedEdges.push(r)}}}disconnectChannelVarFromBBoxOperator(e){let t=this.getOutgoingDataflowOperator(W.EVAL_BBOX,e),r=e.outgoingEdges.find((r=>r.fromNode===e&&r.toNode===t));r&&this.disconnect(e,t,r)}disconnect(e,t,r){if(e instanceof Y&&t instanceof H){let n=e.outgoingEdges.findIndex((e=>e===r));n>=0&&(this._edges.splice(this._edges.indexOf(r),1),e.outgoingEdges.splice(n,1));let i=t.inputVars.findIndex((t=>t==e));i>=0&&t.inputVars.splice(i,1)}else if(e instanceof H&&t instanceof Y){let n=t.incomingEdges.findIndex((e=>e===r));n>=0&&(this._edges.splice(this._edges.indexOf(r),1),t.incomingEdges.splice(n,1));let i=e.outputVars.findIndex((e=>e===t));i>=0&&e.outputVars.splice(i,1)}}deleteVariable(e){for(let t=e.incomingEdges.length-1;t>=0;t--){let r=e.incomingEdges[t],n=r.fromNode;this.disconnect(n,e,r),n.isIsolated()&&delete this._operators[n.type][n.id]}for(let t=e.outgoingEdges.length-1;t>=0;t--){let r=e.outgoingEdges[t],n=r.toNode;this.disconnect(e,n,r),n.isIsolated()&&delete this._operators[n.type][n.id]}delete this._variables[e.type][e.id]}deleteOperator(e){for(let t=e.outputVars.length-1;t>=0;t--){let r=e.outputVars[t],n=r.incomingEdges.find((t=>t.fromNode===e&&t.toNode===r));this.disconnect(e,r,n),r.isIsolated()&&delete this._variables[r.type][r.id]}for(let t=e.inputVars.length-1;t>=0;t--){let r=e.inputVars[t],n=r.outgoingEdges.find((t=>t.fromNode===r&&t.toNode===e));this.disconnect(r,e,n),r.isIsolated()&&delete this._variables[r.type][r.id]}delete this._operators[e.type][e.id]}addInteraction(e){}_dfs(e,t,r){if(e&&0!==e.outgoingEdges.length)for(let n of e.outgoingEdges)n.isDirected&&(t.push(n.toNode),this._dfs(n.toNode.outputVars[0],t.slice(),r));else r.push(t)}processChange(e,t,...r){let n=this.findVariable(e,r);if(n){for(let e of n.outgoingEdges)if(e.isDirected){let r=e.toNode;r.run();let n=r.outputVars;if(n.length>0){let e=n[0];switch(e.type){case X.ITEMS:this.processChange(e.type,t,e.predicate,e.dataset);break;case X.ATTRIBUTE:this.processChange(e.type,t,e.attribute,e.dataset);break;case X.BOUNDS:case X.ORDER:this.processChange(e.type,t,e.element);break;case X.CHANNEL:this.processChange(e.type,t,e.channel,e.element);break;case X.PROPERTY:this.processChange(e.type,t,e.property,e.element);break;case X.SCALE:case X.DOMAIN:this.processChange(e.type,t,e.encodings[0]);break;case X.COND_ENCODING:this.processChange(e.type,t,e.condEncoding)}}}for(let e of n.undirectedEdges)t.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 r=Object.values(this._variables[e]);switch(e){case X.CHANNEL:return r.find((e=>e.channel==t[0]&&Pe(e.element)==Pe(t[1])));case X.PROPERTY:return r.find((e=>e.property==t[0]&&e.element==t[1]));case X.COND_ENCODING:return r.find((e=>e.condEncoding==t[0]));case X.AFFIXATION:return r.find((e=>e.affixation==t[0]));case X.ATTRIBUTE:return r.find((e=>e.attribute==t[0]&&e.dataset==t[1]));case X.ITEMS:return r.find((e=>e.dataset==t[1]));case X.DOMAIN:case X.SCALE:return r.find((e=>e.encodings.includes(t[0])));case X.TRIGGER:return r.find((e=>e.trigger===t[0]));case X.DATASCOPE:default:return t[0].classId?r.find((e=>Pe(e.element)==Pe(t[0]))):r.find((e=>e.element.id==t[0].id))}}findVariablesByElement(e){let t={};for(let r in this._variables){let n=Object.values(this._variables[r]).filter((t=>t.element&&Pe(t.element)==Pe(e)));n.length>0&&(t[r]=n)}return t}}function Hy(e){return!(!x(e)&&e.type!=Tt.Glyph||e.dataScope)||e.type===Tt.Collection&&e.firstChild.dataScope.numTuples>1}function Wy(e,t,r,n){let i=n.getAttributeType(r);if(i!=we.String&&i!=we.Date&&i!=we.Integer)throw new Error("Repeat only works on a string or date attribute: "+r+" is "+i);if(!function(e){if(Array.isArray(e)){if(1===e.length)return Hy(e[0]);for(let t of e)if(!x(t)||t.dataScope)return!1;return!0}return Hy(e)}(t))throw new Error("The "+t.type+" is not repeatable");return function(e,t,r,n){let i=n.getAttributeSummary(r).unique.map((e=>t.dataScope?t.dataScope.cross(r,e):new fe(n).cross(r,e)));i=i.filter((e=>!e.isEmpty()));let s=Ct(e);s.dataScope=t.dataScope?t.dataScope.clone():new fe(n),s.addChild(t);for(let e=1;e<i.length;e++){let e=kt(t);s.addChild(e)}return s.children.forEach(((e,t)=>e.dataScope=i[t])),s}(e,t,r,n)}class Yy{constructor(e,t,r,n,i){this._elem=e,this._channel=t,this._attribute=r,this._aggregator=n,this._includeZero=i.includeZero,this._flipScale=i.flipScale,this._mapping=i.mapping,this._preferredRangeExtent=i.rangeExtent,this._preferredDomain=void 0,this._scaleType=i.scaleType,this._colorScheme=i.scheme,this._forLegend=i.forLegend,this._scales=[],this._elemGroups=[],this._elem2scale={},this._refElements=[],["width","height","radius","angle","thickness","radialDistance","strokeWidth","area"].indexOf(this._channel)>=0&&(this._includeZero=!0),this.initialize()}initialize(){this._scales=[];let e=S(this._elem);if(this._elemGroups=[],"x"===this._channel||"y"===this._channel){let t=this._elem,r=D(t);if(r.layout&&r.layout.type==F.GRID){let e="x"===this._channel?r.layout.getElementsByCol(!0,t):r.layout.getElementsByRow(!0,t);for(let t of e)this._createScaleForElems(t)}else if("vertex"===this._elem.type&&(Me(this._elem.parent)||Be(this._elem.parent))){let e=S(this._elem.parent).map((e=>T(this._elem,[e])));for(let t of e)this._createScaleForElems(t)}else this._createScaleForElems(e)}else if("angle"===this._channel){let t=e.reduce(((e,t)=>{const r=t.parent.id;return e[r]||(e[r]=[]),e[r].push(t),e}),{}),r=Object.values(t);for(let e of r)this._createScaleForElems(e)}else this._createScaleForElems(e)}_createScaleForElems(e){this._elemGroups.push(e);var t=function(e){if(e.scaleType)return new Ut(e.scaleType);if("text"===e.channel)return new Ut("ordinal");switch(Lt(e.element).getAttributeType(e.attribute)){case we.Boolean:break;case we.Date:return new Ut("time");case we.String:if("count"==e.aggregator)return new Ut("linear");if(e.channel.indexOf("Color")>=0){let t={};return t.scheme=e.colorScheme?e.colorScheme:"schemeCategory10",new Ut("ordinalColor",t)}return new Ut("point");default:return["strokeColor","fillColor","fillGradient"].indexOf(e.channel)>=0?e.mapping?new Ut("linear"):new Ut("sequentialColor",{scheme:e.colorScheme}):new Ut("linear")}}(this);this._scales.push(t);for(let r of e)this._elem2scale[r.id]=t}getScale(e){return this._elem2scale[e.id]}getElements(e){let t=this._scales.indexOf(e);return this._elemGroups[t]}get element(){return this._elem}get channel(){return this._channel}get attribute(){return this._attribute}get dataTable(){return Lt(this._elem)}get aggregator(){return this._aggregator}hasMultipleScales(){return this._scales.length>0}get scales(){return this._scales}getRangeStart(e){let t=this.getScale(e);return Math.min(...t.range)}getRangeExtent(e){return this.getScale(e).rangeExtent}get scaleType(){return this._scaleType}set scaleType(e){this._scaleType=e}set domain(e){this._preferredDomain=e;for(let t of this._scales)t._scale.domain(e);for(let e of this._refElements)e instanceof er&&e.createTicksLabels({});this._elem.scene.onChange(X.DOMAIN,this)}set rangeExtent(e){for(let t of this._scales)t.rangeExtent=e;for(let e of this._refElements)e instanceof er&&e.createTicksLabels({});this._elem.scene.onChange(X.PROPERTY,Qe.RANGE_EXTENT,this)}set includeZero(e){this._includeZero=e;for(let e of this._refElements)e instanceof er&&e.createTicksLabels({});this._elem.scene.onChange(X.PROPERTY,Qe.INCLUDE_ZERO,this)}get includeZero(){return this._includeZero}set flipScale(e){this._flipScale=e,this._elem.scene.onChange(X.PROPERTY,Qe.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=[]}}class Xy{constructor(e,t,r,n){this._trigger=e,this._target=t.target,this._targetEval=r,this._efxFn=n,this._evalResult={}}get trigger(){return this._trigger}get target(){return this._target}get channels(){return Object.keys(this._rules)}get evalResult(){return this._evalResult}set evalResult(e){this._evalResult=e}}class qy extends ne{constructor(e,t,r,n,i){super(i),this._type=Tt.Gridlines,this._id=this._type+It(),this._attribute=t,this._channel=e,this._scale=r,this._elems=n,"strokeColor"in i||(this.styles.strokeColor="#ddd"),"opacity"in i||(this.styles.opacity=.5),"values"in i?this._values=i.values:this._scale?this._values=Jt(this._scale,this._channel,this._elems):this._values=this._elems.map((e=>e.dataScope.getAttributeValue(this._attribute))),this._lines=[]}get type(){return this._type}get id(){return this._id}getSVGPathData(){let e="";if("radialDistance"===this._channel)for(let t of this._lines)e+="M "+t.x+" "+t.y+" m -"+t.r+" 0 a "+t.r+" "+t.r+" 0 1 0 "+2*t.r+" 0 a "+t.r+" "+t.r+" 0 1 0 -"+2*t.r+" 0 ";else for(let t of this._lines)e+=["M",t.x1,t.y1].join(" ")+[" L",t.x2,t.y2].join(" ")+" ";return e}_updateBounds(){if("radialDistance"===this._channel){let e=this._lines.map((e=>new u(e.x-e.r,e.y-e.y,2*e.r,2*e.r)));this._bounds=c(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))),r=Math.min(...e),n=Math.max(...e),i=Math.min(...t),s=Math.max(...t);this._bounds=new u(r,i,n-r,s-i)}}get elements(){return this._elems}get values(){return this._values}get channel(){return this._channel}get attribute(){return this._attribute}get scale(){return this._scale}get lines(){return this._lines}set lines(e){this._lines=e}}class Ky extends z{constructor(e){super(),this.type=F.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:p.LEFT,this._vertCellAlignment="vertCellAlignment"in e&&e.vertCellAlignment?e.vertCellAlignment:p.BOTTOM,this._gap="gap"in e?e.gap:0}clone(){let e=new Ky({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}}function Zy(e,t,r,n,i){let s=i.getAttributeType(r);if(s!=we.String&&s!=we.Date&&s!=we.Integer)throw new Error("Divide only works on a string or date attribute: "+r+" is "+s);if(!function(e){if([Tt.Line,Tt.Circle,Tt.Rect,Tt.Area,Tt.Ring,Tt.Pie,Tt.Path].indexOf(e.type)<0)return!1;if(e.type===Tt.Path&&(e.closed||!e.firstVertex.dataScope))return!1;if(e.dataScope){let t=S(e);for(let e of t)if(e.dataScope.numTuples>1)return!0;return!1}return!0}(t))throw new Error("The "+t.type+" is not dividable");switch(t.type){case Tt.Line:case Tt.Path:return;case Tt.Circle:return function(e,t,r,n,i){let s,a,o,l=S(t),u=r||$.ANGULAR;if(u!=$.ANGULAR&&u!=$.RADIAL)throw new Error("Unknown orientation: "+u);u===$.ANGULAR&&l.forEach((r=>{let l=r.dataScope?r.dataScope:new fe(i),u=i.getUniqueAttributeValues(n).map((e=>l.cross(n,e)));u=u.filter((e=>!e.isEmpty()));let c=Ct(e);null==a&&(a=c.id),c._classId=a,c.dataScope=r.dataScope?r.dataScope:new fe(i);let h=r.parent;h.removeChild(r),delete e._itemMap[r.id];let d=360/u.length,f=90;for(let e=0;e<u.length;e++){let n=At({type:"arc",innerRadius:0,outerRadius:r.radius,x:r.x,y:r.y,startAngle:he(f-d*(e+1)),endAngle:he(f-d*e),strokeColor:r.strokeColor,fillColor:r.fillColor,strokeWidth:r.strokeWidth,opacity:r.opacity});o||(o=n.id),n.classId=o,n.dataScope=u[e],n._updateBounds(),n._refBounds=n.bounds.clone(),c.addChild(n),c._layout=new Ky({orientation:$.ANGULAR,direction:Q.CLOCKWISE}),c._layout.group=c,h.removeChild(r),h.addChild(c),r===t&&(s=c)}}));return{newMark:s.children[0],collection:s}}(e,t,n,r,i);case Tt.Rect:return function(e,t,r,n,i){let s,a=S(t),o=r||$.HORIZONTAL;if(o!=$.HORIZONTAL&&o!=$.VERTICAL)throw new Error("Unknown orientation: "+o);let l=i.getUniqueAttributeValues(n).map((e=>new fe(i).cross(n,e))),u={},c=0;for(let e of a){let t=l;e.dataScope&&(t=l.map((t=>t.merge(e.dataScope))),t=t.filter((e=>!e.isEmpty()))),t.length>c&&(c=t.length),u[e.id]=t}let h,d=At({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});d._classId=d.id;for(let r of a){let n=Ct(e);null==h&&(h=n.id),n._classId=h,n.dataScope=r.dataScope?r.dataScope:new fe(i);let a=r.parent;a.removeChild(r),delete e._itemMap[r.id];let l=u[r.id],c=r.bounds,f=c.left,p=c.top,_=o==$.HORIZONTAL?c.width/l.length:c.width,g=o==$.HORIZONTAL?c.height:c.height/l.length;for(let e=0;e<l.length;e++){let t=kt(d);t.dataScope=l[e],t.resize(_,g),t._updateBounds(),t._refBounds=t.bounds.clone(),n.addChild(t)}a.addChild(n),n._layout=new Ky({orientation:o,left:f,top:p}),n._layout.group=n,r==t&&(s=n)}return{newMark:s.children[0],collection:s}}(e,t,n,r,i);case Tt.Area:return function(e,t,r,n,i){let s,a=S(t),o=r||$.HORIZONTAL;if(o!=$.HORIZONTAL&&o!=$.VERTICAL)throw new Error("Unknown orientation: "+o);let l,u=i.getUniqueAttributeValues(n).map((e=>new fe(i).cross(n,e))),c={},h=0;for(let e of a){let t=u;e.dataScope&&(t=u.map((t=>t.merge(e.dataScope))),t=t.filter((e=>!e.isEmpty()))),t.length>h&&(h=t.length),c[e.id]=t}let d=Object.assign({},t.styles);d.vertices=t.vertices.map((e=>[e.x,e.y])),d.type="area",d.orientation=t.orientation,d.baseline=t.baseline;let f=At(d);if(f._classId=f.id,t.vertices)for(let e=0;e<t.vertices.length;e++)t.vertices[e].dataScope&&(f.vertices[e]._dataScope=t.vertices[e].dataScope.clone());for(let r of a){let n=Ct(e);null==l&&(l=n.id),n._classId=l,n.dataScope=r.dataScope?r.dataScope:new fe(i);let a=r.parent;a.removeChild(r),delete e._itemMap[r.id];let u=c[r.id],h=r.bounds,d=h.left,p=h.top,_=o==$.HORIZONTAL?h.width/u.length:h.width,g=o==$.HORIZONTAL?h.height:h.height/u.length;for(let e=0;e<u.length;e++){let t=kt(f);t.dataScope=u[e],console.log(t.dataScope),t.resize(_,g),t._updateBounds(),t._refBounds=t.bounds.clone(),n.addChild(t);for(let e of t.vertices)e.dataScope?e.dataScope=t.dataScope.merge(e.dataScope):e.dataScope=t.dataScope}a.addChild(n),n._layout=new Ky({orientation:o,left:d,top:p}),n._layout.group=n,r==t&&(s=n)}return{newMark:s.children[0],collection:s}}(e,t,n,r,i);case Tt.Ring:return function(e,t,r,n,i){let s,a,o,l=S(t),u=r||$.ANGULAR;if(u!=$.ANGULAR&&u!=$.RADIAL)throw new Error("Unknown orientation: "+u);u===$.ANGULAR&&l.forEach((r=>{let l=r.dataScope?r.dataScope:new fe(i),u=i.getUniqueAttributeValues(n).map((e=>l.cross(n,e)));u=u.filter((e=>!e.isEmpty()));let c=Ct(e);null==a&&(a=c.id),c._classId=a,c.dataScope=r.dataScope?r.dataScope:new fe(i);let h=r.parent;h.removeChild(r),delete e._itemMap[r.id];let d=360/u.length,f=90;for(let e=0;e<u.length;e++){let n=At({type:"arc",innerRadius:r.innerRadius,outerRadius:r.outerRadius,x:r.x,y:r.y,startAngle:he(f-d*(e+1)),endAngle:he(f-d*e),strokeColor:r.strokeColor,fillColor:r.fillColor,strokeWidth:r.strokeWidth,opacity:r.opacity});o||(o=n.id),n.classId=o,n.dataScope=u[e],n._updateBounds(),n._refBounds=n.bounds.clone(),c.addChild(n),c._layout=new Ky({orientation:$.ANGULAR,direction:Q.CLOCKWISE}),c._layout.group=c,h.removeChild(r),h.addChild(c),r===t&&(s=c)}}));return{newMark:s.children[0],collection:s}}(e,t,n,r,i);case Tt.Pie:case Tt.Arc:return function(e,t,r,n,i){let s,a,o,l=S(t),u=r||$.ANGULAR;if(u!=$.ANGULAR&&u!=$.RADIAL)throw new Error("Unknown orientation: "+u);u===$.ANGULAR||l.forEach((r=>{let l=r.dataScope?r.dataScope:new fe(i),u=i.getUniqueAttributeValues(n).map((e=>l.cross(n,e)));u=u.filter((e=>!e.isEmpty()));let c=Ct(e);null==a&&(a=c.id),c._classId=a,c.dataScope=r.dataScope?r.dataScope:new fe(i);let h=r.parent;h.removeChild(r),delete e._itemMap[r.id];for(let e=0;e<u.length;e++){let n=At({type:"arc",innerRadius:r.innerRadius+e*(r.outerRadius-r.innerRadius)/u.length,outerRadius:r.innerRadius+(e+1)*(r.outerRadius-r.innerRadius)/u.length,x:r.x,y:r.y,startAngle:r.startAngle,endAngle:r.endAngle,strokeColor:r.strokeColor,fillColor:r.fillColor,strokeWidth:r.strokeWidth,opacity:r.opacity});o||(o=n.id),n.classId=o,n.dataScope=u[e],n._updateBounds(),n._refBounds=n.bounds.clone(),c.addChild(n),c._layout=new Ky({orientation:$.RADIAL}),c._layout.group=c,h.removeChild(r),h.addChild(c),r===t&&(s=c)}}));return{newMark:s.children[0],collection:s}}(e,t,n,r,i)}}function $y(e,t,r,n){let i=n.getAttributeType(r);if(i!=we.String&&i!=we.Date&&i!=we.Integer)throw new Error("Repopulate only works on a string or date attribute: "+r+" is "+i);let s=S(t);for(let e of s){let t=n.getAttributeSummary(r).unique.map((t=>e.dataScope?e.dataScope.cross(r,t):new fe(n).cross(r,t)));t=t.filter((e=>!e.isEmpty()));let i=e.children.length-t.length,s=t.length-e.children.length;for(let t=0;t<i;t++)e.removeChildAt(e.children.length-1);let a=e._children.length;for(let t=0;t<s;t++){let r=kt(e._children[t%a]);e.addChild(r)}e.children.forEach(((e,r)=>e.dataScope=t[r]))}}class Jy{constructor(e,t){this._elem=e,this._base=t,this._id=Qy(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 r={};r.elemAnchor="elementAnchor"in t?t.elementAnchor:"x"==e||"angle"==e?p.CENTER:p.MIDDLE,r.baseAnchor="baseAnchor"in t?t.baseAnchor:"x"==e||"angle"==e?p.CENTER:p.MIDDLE,r.offset="offset"in t?t.offset:0,"attribute"in t&&(this._attribute=t.attribute),this._channels[e]=r}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:Vt}}function Qy(e,t){return(e.classId?e.classId:e.id)+":"+(t.classId?t.classId:t.id)}function em(e,t,r,n){e.dataScope&&e.dataScope.dataTable.hasAttribute(t)?function(e,t,r,n){if(!e.dataScope.dataTable.hasAttribute(t))return void console.warn("Cannot order collection children by an non-existent attribute",t);let i;if(t===Vt)i=(e,r)=>parseInt(e.dataScope.getAttributeValue(t).substring(1))-parseInt(r.dataScope.getAttributeValue(t).substring(1));else{switch(e.children[0].dataScope.getAttributeType(t)){case we.Date:break;case we.Number:case we.Integer:i=(e,r)=>e.dataScope.aggregateNumericalAttribute(t)-r.dataScope.aggregateNumericalAttribute(t);break;case we.String:i=n?(e,r)=>n.indexOf(e.dataScope.getAttributeValue(t))-n.indexOf(r.dataScope.getAttributeValue(t)):(e,r)=>e.dataScope.getAttributeValue(t)<r.dataScope.getAttributeValue(t)?-1:1}}e.children.sort(i),r&&e.children.reverse()}(e,t,r,n):function(e,t,r){let n;switch(t){case"x":case"y":case"width":case"height":n=(e,r)=>e.bounds[t]-r.bounds[t];break;default:n=(e,r)=>e[t]-r[t]}e._children.sort(n),r&&e.children.reverse()}(e,t,r),e._sortBy={property:t,descending:r,vals:n}}function tm(e,t,r,n){e.vertices[0].dataScope&&e.vertices[0].dataScope.dataTable.hasAttribute(t)?function(e,t,r,n){let i;if(t===Vt)i=(e,r)=>parseInt(e.dataScope.getAttributeValue(t).substring(1))-parseInt(r.dataScope.getAttributeValue(t).substring(1));else{switch(e.vertices[0].dataScope.getAttributeType(t)){case we.Date:break;case we.Number:case we.Integer:i=(e,r)=>e.dataScope.aggregateNumericalAttribute(t)-r.dataScope.aggregateNumericalAttribute(t);break;case we.String:i=n?(e,r)=>n.indexOf(e.dataScope.getAttributeValue(t))-n.indexOf(r.dataScope.getAttributeValue(t)):(e,r)=>e.dataScope.getAttributeValue(t)<r.dataScope.getAttributeValue(t)?-1:1}}e.vertices.sort(i),r&&e.vertices.reverse()}(e,t,r,n):function(e,t,r){let n=(e,r)=>e[t]-r[t];e.vertices.sort(n),r&&e.vertices.reverse()}(e,t,r),e._sortBy={property:t,descending:r,vals:n}}class rm extends z{constructor(e){super(),this.type=F.GRID,this._numCols=e.numCols,this._numRows=e.numRows,this._start="start"in e?e.start:Z.TopLeft,this._direction="direction"in e?e.direction:K.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&&U("h",e.horzCellAlignment)?e.horzCellAlignment:p.LEFT,this._cellVertAlignment="vertCellAlignment"in e&&U("v",e.vertCellAlignment)?e.vertCellAlignment:p.BOTTOM,this._numCols||this._numRows||(this._numRows=1),this._left=void 0,this._top=void 0,this._cellBounds=void 0,this._grid=void 0}get cellBounds(){return this._cellBounds}get numCols(){return this._numCols?this._numCols:this._numRows?Math.ceil(this.group.children.length/this._numRows):0}get numRows(){return this._numRows?this._numRows:this._numCols?Math.ceil(this.group.children.length/this._numCols):0}clone(){let e=new rm({numCols:this._numCols,numRows:this._numRows,start:this._start,direction:this._direction,colGap:this._colGap,rowGap:this._rowGap,horzCellAlignment:this._cellHorzAlignment,vertCellAlignment:this._cellVertAlignment});return e._left=this._left,e._top=this._top,this._cellBounds&&(e._cellBounds=this._cellBounds.map((e=>e.clone()))),e}getElementsByRow(e,t){let r=[],n=this.group.children;for(let t=0;t<this.numRows;t++){let i=this._grid[t].filter((e=>null!=e)).map((e=>n[e]));if(e){let e=[];for(let t of i)e=e.concat(G(t));r.push(e)}else r.push(i)}return t&&(r=this._filterElementsByExample(r,t)),r}getElementsByCol(e,t){let r=[],n=this.group.children,i=this._grid;for(let t=0;t<this.numCols;t++){let s=i.map((e=>e[t])).filter((e=>null!=e)).map((e=>n[e]));if(e){let e=[];for(let t of s)e=e.concat(G(t));r.push(e)}else r.push(s)}return t&&(r=this._filterElementsByExample(r,t)),r}getElementsByCell(e,t){let r=[],n=this.group.children;for(let t=0;t<n.length;t++)if(e){let e=G(n[t]);r.push(e)}else r.push(n[t]);return t&&(r=this._filterElementsByExample(r,t)),r}_filterElementsByExample(e,t){let r;return"vertex"===t.type?(r=e.map((e=>e.filter((e=>e.classId===t.parent.classId)))),r=r.map((e=>T(t,e)))):"segment"===t.type?(r=e.map((e=>e.filter((e=>e.classId===t.parent.classId)))),r=r.map((e=>O(t,e)))):r=e.map((e=>e.filter((e=>e.classId===t.classId)))),r}getIndex(e){let t=e;for(;t&&t.parent!==this.group;)t=t.parent;return this.group.children.indexOf(t)}getRowCol(e){let t,r;switch(this._direction){case K.RowFirst:t=Math.floor(e/this.numCols),r=e%this.numCols;break;case K.ColumnFirst:t=e%this.numRows,r=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")&&(r=this.numCols-1-r),{row:t,col:r}}}class nm extends pt{constructor(e,t){super(),this._type=Tt.Axis,this._id=this._type+It(),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:$.VERTICAL,this._numberFormat=t.numberFormat?t.numberFormat:""}get attribute(){return this._enc.attribute}get channel(){return this._enc.channel}get attributeType(){return Lt(this._enc.element).getFieldType(this.attribute)}get orientation(){return this._orientation}get textColor(){return this._textColor}}class im extends nm{constructor(e,t){super(e,t),"numCols"in t||"numRows"in t?(this._numCols=t.numCols,this._numRows=t.numRows):this._orientation===$.VERTICAL?this._numCols=1:this._numRows=1,this._initialize()}_initialize(){let e=this._enc.element.scene,t=this._enc.attribute,r=this._enc.scales[0],n=new Nt(r.domain.map((e=>({category:e,value:r.map(e)})))),i=n.getUniqueAttributeValues("category").sort(((e,t)=>t.length-e.length))[0],s=this._enc.element,a=s instanceof ne&&s.closed?s.strokeWidth:0;if(this._orientation===$.VERTICAL){let r=0;this._showTitle&&(this.addChild(new xt({fillColor:this._textColor,fontSize:this._fontSize,text:t,x:this._x,y:this._y,anchor:["left","top"]})),r=parseFloat(this._fontSize)+5);let o=e.mark("rect",{top:this._y+2+r,left:this._x,width:10,height:10,strokeWidth:a,strokeColor:s.strokeColor,opacity:s.opacity}),l=e.mark("text",{text:i,fillColor:this._textColor,fontSize:this._fontSize,x:this._x+20,y:this._y+r+12+a,anchor:["left","bottom"]}),u=e.glyph(o,l),c=e.repeat(u,n);e.encode(l,{channel:"text",attribute:"category",forLegend:!0}),e.encode(o,{channel:"fillColor",attribute:"category",shareScale:this._enc,forLegend:!0}),c.layout=new rm({numCols:this._numCols,numRows:this._numRows}),this.addChild(c)}else{let t=e.mark("rect",{top:this._y,left:this._x,width:10,height:10,strokeWidth:a,strokeColor:s.strokeColor,opacity:s.opacity}),r=e.mark("text",{text:i,fillColor:this._textColor,fontSize:this._fontSize,x:this._x+15,y:this._y,anchor:["left","top"]}),o=e.glyph(t,r),l=e.repeat(o,n);e.encode(r,{channel:"text",attribute:"category",forLegend:!0}),e.encode(t,{channel:"fillColor",attribute:"category",shareScale:this._enc,forLegend:!0}),l.layout=new rm({numCols:this._numCols,numRows:this._numRows,colGap:15}),this.addChild(l)}}}class sm extends nm{constructor(e,t){super(e,t),this._initialize()}_initialize(){let t,r,n,i=this._enc.element.scene,s=this._enc.attribute;if(this._orientation==$.VERTICAL?(t=15,r=300):(t=300,r=15),this._showTitle){let e=i.mark("text",{fillColor:this._textColor,text:s,x:this._x+t/2,y:this._y,anchor:["center","middle"]});this.addChild(e),n=20}else n=0;let a,o=i.mark("rect",{top:this._y+n,left:this._x,width:t,height:r,strokeWidth:0,opacity:this._enc.element.opacity}),l=Object.values(this._enc.attrValues),u=[Math.min(...l),Math.max(...l)],c=this._enc.mapping,h=[],d=[],f=e.format(this._numberFormat);if(c){let e=Object.keys(c).map((e=>parseFloat(e))).sort(((e,t)=>e-t));this._orientation==$.VERTICAL?(a=new b({x1:0,y1:100,x2:0,y2:0}),e.forEach((e=>{let s=(e-u[0])/(u[1]-u[0]);a.addStop(100*s,c[e],1);let o=i.mark("line",{x1:this._x+t,x2:this._x+t+5,y1:this._y+r-s*r+n,y2:this._y+r-s*r+n,strokeColor:this._strokeColor});d.push(o);let l=i.mark("text",{fillColor:this._textColor,text:this._numberFormat?f(e):e.toFixed(0),x:this._x+t+5+5,y:this._y+r-s*r+n,anchor:["left","middle"]});h.push(l)}))):(a=new b({x1:0,y1:0,x2:100,y2:0}),e.forEach((e=>{let s=(e-u[0])/(u[1]-u[0]);a.addStop(100*s,c[e],1);let o=i.mark("line",{x1:this._x+s*t,x2:this._x+s*t,y1:this._y+20-5+n,y2:this._y+r+5+n,strokeColor:this._strokeColor});d.push(o);let l=i.mark("text",{fillColor:this._textColor,text:this._numberFormat?f(e):e.toFixed(0),x:this._x+s*t,y:this._y+r+5+n,anchor:["center","top"]});h.push(l)})))}else{let e=this._enc.scales[0].domain,o=Lt(this._enc.element),l=o.getAttributeType(s),u=[],c=l===we.Date?o.getUniqueFieldValues(s):[...new Set(Object.values(this._enc.attrValues))];if(c.length<=10)u=c,u.sort(((e,t)=>e-t));else if(l===we.Date){c.sort(((e,t)=>e-t));for(let e=0;e<c.length;e+=Math.ceil(c.length/10))u.push(c[e])}else{let t=(e[1]-e[0])/9;for(let r=0;r<10;r++)u.push(e[0]+r*t)}let p=0,_=(u[u.length-1]-u[0])/u.length;for(;_<1;)_*=10,p++;u=u.map((e=>e.toFixed(p))),this._orientation==$.VERTICAL?(a=new b({x1:0,y1:100,x2:0,y2:0}),u.forEach((u=>{let c=(u-e[0])/(e[1]-e[0]);a.addStop(100*c,this._enc.scales[0].map(u),1);let p=i.mark("line",{x1:this._x+t,x2:this._x+t+5,y1:this._y+r-c*r+n,y2:this._y+r-c*r+n,strokeColor:this._strokeColor});d.push(p);let _=i.mark("text",{fillColor:this._textColor,text:l===we.Date?o.getRawValue(s,u):this._numberFormat?f(u):u,x:this._x+t+5+5,y:this._y+r-c*r+n,anchor:["left","middle"]});h.push(_)}))):(a=new b({x1:0,y1:0,x2:100,y2:0}),u.forEach((u=>{let c=(u-e[0])/(e[1]-e[0]);a.addStop(100*c,this._enc.scale.map(u),1);let f=i.mark("line",{x1:this._x+c*t,x2:this._x+c*t,y1:this._y+r+n,y2:this._y+r+5+n,strokeColor:this._strokeColor});d.push(f);let p=i.mark("text",{fillColor:this._textColor,text:l===we.Date?o.getRawValue(s,u):u,x:this._x+c*t,y:this._y+r+5+n,anchor:["center","top"]});h.push(p)})))}o.styles.fillColor=a,this.addChild(o);for(let e of h)this.addChild(e);for(let e of d)this.addChild(e)}}class am extends pt{constructor(e){super(),this._type=Tt.Composite,this._id=e&&e.id?e.id:this._type+It()}addChild(e){let t=e.parent;super.addChild(e);let r=P(e)._depGraph;t&&st(t,e,r),at(this,e,r)}}class om{constructor(e,t,r){this._elems=e,this._channel=t,this._anchor=r}get elements(){return this._elems}get channel(){return this._channel}get anchor(){return this._anchor}}class lm extends z{constructor(e){super(),this.type=F.STRATA,this._direction=e.direction,this._gap="gap"in e?e.gap:0}clone(){return new lm({direction:this._direction,gap:this._gap})}}function um(e,t,r,n,i,s){switch(t.type){case Tt.Circle:case Tt.Ring:return function(e,t,r,n,i,s){let a,o=r||ee.OUTWARD,l=i||50;if(o!==ee.INWARD&&o!==ee.OUTWARD)throw"Unknown direction to stratify";let u,c=S(t,e),h=Array.isArray(s)?s:[s];if(n){let r=Ct(e);r.dataScope=void 0,null==u&&(u=r.id),r._classId=u;let n=c.map((e=>h[0].getNode(e.dataScope.getAttributeValue(xe))));cm(c,n,h[0],r,t.classId?t.classId:t.id,400,350,o,l),a=r}else c.forEach(((r,n)=>{let i=Ct(e);i.dataScope=void 0,null==u&&(u=i.id),i._classId=u;let s=r.parent;hm(r,t.id,o,l,h[n],h[n].getRoot(),i,e,!0),i._layout=new lm({direction:o}),i._layout.group=i,s.addChild(i),r===t&&(a=i)}));return a}(e,t,r,n,i,s);case Tt.Rect:return function(e,t,r,n,i,s){let a,o,l=r||J.Top2Bottom,u=i||50;if(!Object.values(J).includes(l))throw"Unknown direction to stratify";return S(t).forEach((r=>{let n=Ct(e);n.dataScope=void 0,null==o&&(o=n.id),n._classId=o;let i=r.parent;dm(r,t.id,l,u,s,s.getRoot(),n,e,!0),n._layout=new lm({direction:l}),n._layout.group=n,i.addChild(n),r===t&&(a=n)})),a}(e,t,r,0,i,s)}}function cm(e,t,r,n,i,s,a,o,l){let u=t.map((e=>r.getParent(e))).filter(((e,t,r)=>r.findIndex((t=>t[xe]===e[xe]))===t));if(u=u.filter((e=>e!==r.getRoot())),0===u.length)return;let c=[];for(let t of u){let u,h,d,f=e.filter((e=>r.getParent(r.getNode(e.dataScope.getAttributeValue(xe)))===t));if(f[0].type===Tt.Circle){let e=f.map((e=>A(s,a,e.bounds.x,e.bounds.y)-e.radius)),t=f.map((e=>A(s,a,e.bounds.x,e.bounds.y)+e.radius));d=o===ee.OUTWARD?Math.max(...t):Math.min(...e)-l;let r=f.map((e=>de(e.bounds.x,e.bounds.y,s,a))),n=f.map((e=>de(s+A(s,a,e.bounds.x,e.bounds.y),a-e.radius,s,a))),i=r.map(((e,t)=>e-n[t])),c=r.map(((e,t)=>e+n[t])),p=i.concat(c);u=Math.min(...p),h=Math.max(...p)}else f[0].type===Tt.Arc&&(u=360,h=-360,f.forEach((e=>{let t=e.startAngle,r=e.endAngle;r<t&&(r+=360),u=Math.min(u,t),h=Math.max(h,r)})),u=he(u),h=he(h),d=o===ee.OUTWARD?Math.max(...f.map((e=>e.outerRadius))):Math.min(...f.map((e=>e.innerRadius)))-l);let p=At({type:"arc",innerRadius:d,outerRadius:d+l,x:s,y:a,startAngle:he(u),endAngle:he(h),strokeColor:e[0].strokeColor,fillColor:e[0].fillColor,strokeWidth:e[0].strokeWidth,opacity:e[0].opacity});p._updateBounds(),p.dataScope=r.getNodeDataScope(t),p._classId=i,n.addChild(p),c.push(p)}cm(c,u,r,n,i,s,a,o,l)}function hm(e,t,r,n,i,s,a,o,l){l&&(e.dataScope=i.getNodeDataScope(s),e._classId=t);let u=i.getChildren(s);if(0===u.length)return;let c=e.type===Tt.Circle||e.type===Tt.Ring?60:e.startAngle,h=(e.type===Tt.Circle||e.type===Tt.Ring?360:e.angle)/u.length;for(let s=0;s<u.length;s++){let o,l;l=r===ee.OUTWARD?e.type===Tt.Circle?e.radius:e.outerRadius:e.type===Tt.Circle?e.radius-n:e.innerRadius-n,o=At(360===h?{type:"ring",innerRadius:l,outerRadius:l+n,x:e.x,y:e.y,strokeColor:e.strokeColor,fillColor:e.fillColor,strokeWidth:e.strokeWidth,opacity:e.opacity}:{type:"arc",innerRadius:l,outerRadius:l+n,x:e.x,y:e.y,startAngle:he(c+h*s),endAngle:he(c+h*(s+1)),strokeColor:e.strokeColor,fillColor:e.fillColor,strokeWidth:e.strokeWidth,opacity:e.opacity}),o._updateBounds(),o.dataScope=i.getNodeDataScope(u[s]),o._classId=t+"_strata",a.addChild(o),hm(o,t,r,n,i,u[s],a)}}function dm(e,t,r,n,i,s,a,o,l){l&&(e.dataScope=i.getNodeDataScope(s),e._classId=t,a.addChild(e));let u,c,h,d=i.getChildren(s);if(0!==d.length){switch(r){case J.Top2Bottom:case J.Bottom2Top:case J.Left2Right:case J.Right2Left:}u=e.left,c=e.bottom,h=e.width/d.length;for(let s=0;s<d.length;s++){let o=kt(e);je(o,u-o.left,c-o.top),o.resize(h,n),o._updateBounds(),u+=h,o.dataScope=i.getNodeDataScope(d[s]),o._classId=t,a.addChild(o),dm(o,t,r,n,i,d[s],a)}}}class fm extends Ke{constructor(e,t,r,n){super(e,t),this._elem=r,this._cumulative=n,this._elements=[]}get element(){return this._elem}isCumulative(){return this._cumulative}get elements(){return this._elements}set elements(e){this._elements=e}}class pm extends Ke{constructor(e,t,r){super(e,t),this._key=r}get key(){return this._key}}class _m extends Ke{constructor(e,t,r){super(e,t),this._listener=r,this._elements=[]}get mouseEvent(){return this._mouseEvent}set mouseEvent(e){this._mouseEvent=e}get listener(){return this._listener}get elements(){return this._elements}set elements(e){this._elements=e}}class gm extends Ke{constructor(e,t,r){super(e,t),this._ctrlId=r}get id(){return this._ctrlId}}class ym extends pt{constructor(e){super(),this._itemMap={},this._type=Tt.Scene,this._id=e&&e.id?e.id:this._type+It(),e&&e.fillColor&&(this.fillColor=e.fillColor),this._encodings={},this._relations=[],this._triggers={},this._depGraph=new Uy}get depGraph(){return this._depGraph}get interactionTriggers(){return this._triggers}mark(e,t){if(Object.values(St).indexOf(e)<0)throw new Error("Mascot does not allow directly creating a "+e);let r=void 0===t?{}:t;r.type=e;let n=At(r);return null!==n&&(n._classId=n.id,this.addChild(n),this._itemMap[n.id]=n,et(n,this._depGraph),at(this,n,this._depGraph)),n}glyph(...e){let t=[];for(let r of e)t.push([r.parent,r]);let r=Rt(e);if(null!==r){r._classId=r.id,this.addChild(r),this._itemMap[r.id]=r;for(let e of t)st(e[0],e[1],this._depGraph);!function(e,t){let r=t.getVariable(X.BOUNDS,e),n=t.getIncomingDataflowOperator(W.EVAL_BBOX,r);for(let r of e.children)t.connect(t.getVariable(X.BOUNDS,r),n);t.connect(n,r),n.run()}(r,this._depGraph),at(this,r,this._depGraph)}return r}composite(){let e=new am;return null!==e&&(e._classId=e.id,this.addChild(e),this._itemMap[e.id]=e,function(e,t){let r=t.getVariable(X.BOUNDS,e),n=t.getVariable(X.CHANNEL,"x",e),i=t.getVariable(X.CHANNEL,"y",e),s=t.getVariable(X.CHANNEL,"width",e),a=t.getVariable(X.CHANNEL,"height",e),o=t.createOneWayDependency(W.EVAL_BBOX);t.connect(n,o),t.connect(i,o),t.connect(s,o),t.connect(a,o),t.connect(o,r),o.run()}(e,this._depGraph),at(this,e,this._depGraph)),e}attach(e,t){if(e.type==Tt.Glyph)for(let t of e.children)t._refBounds||(t._refBounds=t.bounds.clone());e.dataScope=new fe(t)}repeat(e,t,r){let n=r||{};if(n.attribute=n.attribute||Vt,console.log("------ repeat by",n.attribute," ----"),function(e,t,r){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 ge||t instanceof me){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 Nt&&Ee(r.attribute,t);if(r.layout&&!(r.layout instanceof z))throw new Error("Invalid layout: "+r.layout)}(e,t,n),t instanceof ge||t instanceof me){let r=e[0].parent,n=e[1].parent,[i,s]=function(e,t,r,n){let i=n.nodeTable.getAttributeSummary(xe).unique.map((e=>t.dataScope?t.dataScope.cross(xe,e):new fe(n.nodeTable).cross(xe,e))),s=Ct(e),a=Ct(e),o={};a.dataScope=t.dataScope?t.dataScope.clone():new fe(n.nodeTable),a.addChild(t);for(let e=1;e<i.length;e++){let e=kt(t);a.addChild(e)}a.children.forEach(((e,t)=>{e.dataScope=i[t],e.links=[],o[e.dataScope.getAttributeValue(xe)]=e}));let l=n.linkTable.getAttributeSummary(Vt).unique.map((e=>r.dataScope?r.dataScope.cross(Vt,e):new fe(n.linkTable).cross(Vt,e)));s.dataScope=r.dataScope?r.dataScope.clone():new fe(n.linkTable),s.addChild(r);for(let e=1;e<l.length;e++){let e=kt(r);s.addChild(e)}s.children.forEach(((e,t)=>e.dataScope=l[t]));let u=n instanceof ge?"parent":"source",c=n instanceof ge?"child":"target";for(let e of s.children){let t=e.dataScope.getAttributeValue(u),r=e.dataScope.getAttributeValue(c),n=o[t],i=o[r];e.source=n,e.target=i,n.links.push(e),i.links.push(e)}return[a,s]}(this,e[0],e[1],t);return st(r,e[0],this._depGraph),st(n,e[1],this._depGraph),it(i,this._depGraph),it(s,this._depGraph),at(i,e[0],this._depGraph),at(i.parent,i,this._depGraph),at(s,e[1],this._depGraph),at(s.parent,s,this._depGraph),[i,s]}if(t instanceof Nt){let r=e.parent,i=Wy(this,e,n.attribute,t);return st(r,e,this._depGraph),it(i,this._depGraph),at(i,e,this._depGraph),at(i.parent,i,this._depGraph),n.layout&&(i.layout=n.layout),i}}divide(e,t,r){let n=r||{};if(n.attribute=n.attribute||Vt,console.log("------ divide by",n.attribute," ----"),function(e,t,r){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");if(t instanceof Nt&&Ee(r.attribute,t),r.layout&&!(r.layout instanceof z))throw new Error("Invalid layout: "+r.layout)}(e,t,n),t instanceof ge||t instanceof me)throw"Not implemented";if(t instanceof Nt){let{newMark:r,collection:i}=Zy(this,e,n.attribute,n.orientation,t);return tt(e,this._depGraph),et(r,this._depGraph),it(i,this._depGraph),at(i,r,this._depGraph),i.parent.type!==Tt.Scene&&at(i.parent,i,this._depGraph),this.onChange(X.CHANNEL,"width",r),{newMark:r,collection:i}}}densify(e,t,r){let n=r||{};if(n.attribute=n.attribute||Vt,console.log("------ densify by",n.attribute," ----"),function(e,t,r){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 Nt&&Ee(r.attribute,t)}(e,t,n),t instanceof ge||t instanceof me)throw"Not implemented";if(t instanceof Nt){let r=ke(0,e,n.attribute,n.orientation,t);return tt(e,this._depGraph),et(r,this._depGraph),r.parent.type!==Tt.Scene&&at(r.parent,r,this._depGraph),this.onChange(X.CHANNEL,"width",r),r}}stratify(e,t,r){if(!(t instanceof ge||Array.isArray(t)&&t.every((e=>e instanceof ge))))throw"Cannot stratify on a non-tree dataset";if(![Tt.Circle,Tt.Rect,Tt.Ring].includes(e.type))throw"Cannot stratify elements that are not rects, circles, or rings";let n=r||{},i=n.direction,s=n.size,a=e.parent,o=um(this,e,i,n.startFromLeaf,s,t);return st(a,e,this._depGraph),it(o,this._depGraph),o.children.length>0&&at(o,o.firstChild,this._depGraph),at(o.parent,o,this._depGraph),o}repopulate(e,t,r){e.dataScope=void 0;let n=e;for(let e in r){$y(0,n,r[e],t);let i=Ne(n.children[0],!0);for(let e of i){Ie(e,this),rt(e,this._depGraph);for(let t of e.refElements)Qt(t,this),nt(t,this._depGraph);e.clearRefElements()}let s=S(n);for(let e of s)if(e.layout){for(let t of e.layout.refElements)Qt(t,this),nt(t,this._depGraph);e.layout.clearRefElements()}n=n.children[0]}e.dataScope=new fe(t),this.onChange(X.CHANNEL,"width",e.children[0])}classify(e,t){let r=t||{};console.log("------ classify by",r.attribute," ----"),function(e,t,r,n){let i=S(t);for(let t of i){let i,s={},a=t.children;for(let e of a){let t=e.dataScope.getAttributeValue(r);t in s||(s[t]=[]),s[t].push(e)}let o=Lt(a[0]);for(let a in s){let l=Ct(e);t.addChild(l),void 0===i&&(i=l.id),l._classId=i,l.dataScope=t.dataScope?t.dataScope.cross(r,a):new fe(o).cross(r,a);for(let e of s[a])l.addChild(e);n&&(l._layout=n.clone(),l._layout.group=l)}}}(this,e,r.attribute,r.layout),st(e,e.firstChild.firstChild,this._depGraph),it(e.firstChild,this._depGraph),at(e.firstChild,e.firstChild.firstChild,this._depGraph),at(e,e.firstChild,this._depGraph),this.onChange(X.CHANNEL,"width",e.firstChild.firstChild)}affix(e,t,r,n){e.dataScope.dataTable!==e.dataScope.dataTable&&console.warn("Affix: elements and base elements are not created from the same table");let i=Qy(e,t),s=this._relations.find((e=>e.id===i));s||(s=new Jy(e,t),this._relations.push(s)),s.addChannel(r,n||{}),function(e,t){let r=t.getVariable(X.AFFIXATION,e),n=t.getOutgoingDataflowOperator(W.AFFIXER,r);t.connect(r,n);for(let r of e.channels){let i=t.getVariable(X.CHANNEL,r,e.element),s=t.getVariable(X.CHANNEL,r,e.base);t.connect(s,n),t.connect(n,i)}n.run()}(s,this._depGraph)}align(e,t,r){let n=new om(e,t,r);!function(e,t){let r=t.createMultiWayDependency(W.ALIGNER),n=t.getVariable(X.ALIGNMENT,e);t.connect(n,r);for(let n of e.elements){let i=t.getVariable(X.CHANNEL,e.channel,n);t.connect(i,r)}r.run()}(n,this._depGraph),this._relations.push(n)}encode(e,t){if("rowId"===t.attribute&&(t.attribute=Vt),function(e,t){if(!e||!("channel"in t)||!("attribute"in t))throw new Error("Incomplete information to do encoding. You must specify an item, a categorical data attribute and a data table");let r=Lt(e);if(r.tree){let e=t.attribute;if(e.indexOf(".")>0&&!r.tree.nodeTable.hasAttribute(e.split(".")[1]))throw new Error("Data attribute does not exist in the data table")}else if(!r||!r.hasAttribute(t.attribute))throw new Error("Data attribute does not exist in the data table");if(!Object.values(Oe).includes(t.channel))throw new Error("Channel Not Supported")}(e,t),t.shareScale){let e=t.shareScale;if(e.channel!=t.channel&&e.channel.indexOf("Color")<0&&t.channel.indexOf("Color")<0)throw new Error("Cannot share scales between "+e.channel+" and "+t.channel+" encodings");t.scheme=t.shareScale.colorScheme}!function(e){let t;"vertex"===e.type&&e.parent.type===Tt.Area?t=e.parent:e.type===Tt.Area&&(t=e),t&&!t._refBounds&&S(t).forEach((e=>e._refBounds=e.bounds.clone()))}(e);let r=t.aggregator?t.aggregator:"sum";console.log("------ encode",t.channel,t.attribute," --");let n=Ve(e,t.channel);if(n&&t.attribute!==n.attribute){Ie(n,this),rt(n,this._depGraph);for(let e of n.refElements)Qt(e,this),nt(e,this._depGraph);n.clearRefElements()}let i=new Yy(e,t.channel,t.attribute,r,t);return this._addAttributeEncoding(i),function(e,t,r){let n=e.attribute,i=e.channel,s=e.element,a=t.createOneWayDependency(W.ENCODER);if(["width","height"].includes(e.channel)&&s.type===Tt.Area){let e=t.getVariable(X.PROPERTY,Qe.BASE_LINE,s);t.connect(e,a)}if(r){let n=t.getVariable(X.DOMAIN,r),o=t.getVariable(X.SCALE,r),l=t.getVariable(X.CHANNEL,i,s);t.connect(o,a),t.connect(a,l),n.addLinkedEncoding(e),o.addLinkedEncoding(e),n.incomingDataflow.run()}else{let r=t.getVariable(X.ATTRIBUTE,n,Lt(s)),o=t.getVariable(X.PROPERTY,Qe.INCLUDE_ZERO,e),l=t.getVariable(X.DOMAIN,e),u=t.getVariable(X.DATASCOPE,s),c=t.createOneWayDependency(W.DOMAIN_BUILDER);t.connect(r,c),t.connect(o,c),t.connect(u,c),t.connect(c,l),c.run();let h=t.getVariable(X.PROPERTY,Qe.RANGE_START,e),d=t.getVariable(X.PROPERTY,Qe.RANGE_EXTENT,e),f=t.getVariable(X.PROPERTY,Qe.FLIP_SCALE,e),p=t.getVariable(X.SCALE,e),_=t.createOneWayDependency(W.SCALE_BUILDER);t.connect(h,_),t.connect(d,_),t.connect(f,_),t.connect(l,_),t.connect(_,p),_.run();let g=t.getVariable(X.CHANNEL,i,s);t.connect(p,a),t.connect(a,g),a.run()}}(i,this._depGraph,t.shareScale),t.shareScale?this.onChange(X.DOMAIN,i):this.onChange(X.CHANNEL,t.channel,e),i}connect(e,t){let r={};e.forEach((e=>r[e.dataScope.getAttributeValue(xe)]=e));let n=t[0].dataScope.dataTable,i=n.tree?"parent":"source",s=n.tree?"child":"target";for(let t of e)t.links=[];for(let e of t){let t=e.dataScope.getAttributeValue(i),n=e.dataScope.getAttributeValue(s),a=r[t],o=r[n];e.source=a,e.target=o,a.links.push(e),o.links.push(e)}ct(e.find((e=>e.links.length>0)),this._depGraph),this.onChange(X.CHANNEL,"x",e[0])}_addAttributeEncoding(e){let t=Pe(e.element);t in this._encodings||(this._encodings[t]={}),this._encodings[t][e.channel]=e}activate(e,t,r,n,i){!function(e,t,r,n,i){if(!("event"in e)||!("type"in e))throw"Event and trigger must be specified";if(![Ze.WIDGET,Ze.KEYBOARD].includes(e.type)){if(!("target"in t)||!("targetChannels"in t))throw"Target must be specified";if("function"!=typeof r)throw"Target evaluator must be a function"}if(e.type===Ze.ELEMENT&&!("element"in e))throw"Element must be specified for trigger";if(Array.isArray(n)){if(!n.every((e=>"function"==typeof e)))throw"Effect setter must be a function";if(i&&!Array.isArray(i))throw"An array of effect setters must be accompanied by an array of animation effects";if(i&&Array.isArray(i)&&i.length!==n.length)throw"the length of effect setters is not equal to the length of animation effects"}else if("function"!=typeof n)throw"Effect setter must be a function"}(e,t,r,n,i);let s=e.event,a=function(e){switch(e.type){case Ze.ELEMENT:return[e.type,e.element.classId?e.element.classId:e.element.id].join("-");case Ze.ATTRIBUTE:return[e.type].join("-");case Ze.WIDGET:return[e.type,e.event,e.listener?e.listener.id:"scene",e.id?e.id:""].join("-");case Ze.MOUSE:return[e.type,e.event,e.listener?e.listener.id:"scene"].join("-");case Ze.KEYBOARD:return[e.type,e.event,e.key].join("-");default:return[e.type,e.event].join("-")}}(e);if(s=0===s.indexOf("brush")?"brush":s,s in this._triggers||(this._triggers[s]={}),a in this._triggers[s]||(this._triggers[s][a]=function(e){switch(e.type){case Ze.ELEMENT:return new fm(e.type,e.event,e.element,"cumulative"in e&&e.cumulative);case Ze.MOUSE:return new _m(e.type,e.event,e.listener);case Ze.KEYBOARD:return new pm(e.type,e.event,e.key);case Ze.WIDGET:return new gm(e.type,e.event,e.id)}}(e)),this._triggers[s][a].animation=i,![Ze.WIDGET,Ze.KEYBOARD].includes(e.type)){let e=this._triggers[s][a],i=new Xy(e,t,r,n);return function(e,t,r){let n=e.target,i=r.getVariable(X.COND_ENCODING,e);for(let s of t){let t=r.getVariable(X.TRIGGER,e.trigger),a=r.findIncomingDataflowOperator(W.TARGET_EVALUATOR,i);a||(a=r.createOneWayDependency(W.TARGET_EVALUATOR,e._targetEval)),r.connect(t,a),r.connect(a,i);let o=r.getVariable(X.CHANNEL,s,n),l=o.incomingDataflow;if(l&&l instanceof $e&&l.outputVar.channel===s)r.connect(i,l);else if(!l){let e=r.createOneWayDependency(W.ENCODER);r.connect(i,e),r.connect(e,o),e.storeValues(n,s)}}}(i,t.targetChannels,this._depGraph),i}this._triggers[s][a].callback=n}onChange(e,...t){if(Object.values(X).indexOf(e)<0)throw new Error("Unknown Variable Type: "+e);let r=[];this._depGraph.processChange(e,r,...t);for(let e of r)e.run()}gridlines(e,t,r){let n=r||{},i=n.element?Ve(n.element,e):Le(t,e,this);if(i){i.attribute!==t&&console.warn("Cannot create a "+e+" axis for "+t);let r=[];if("x"==e)for(let e of i.scales)r.push({scale:e,elems:i.getElements(e)});else if("width"==e){let e=D(i.element),t=i.scales[0];if(e.layout&&e.layout.type==F.GRID&&e.layout.numCols>1){let n=e.layout.getElementsByCol(!0);for(let e of n)r.push({scale:t,elems:e})}else r.push({scale:i.scales[0],elems:i.getElements(i.scales[0])})}else if("y"==e){let e=D(i.element);if(e.layout&&e.layout.type==F.GRID&&e.layout.numRows>1){let t=e.layout.getElementsByRow(!0,i.element);for(let e of t)r.push({scale:i.getScale(e[0]),elems:e})}else r.push({scale:i.scales[0],elems:i.getElements(i.scales[0])})}else if("height"==e){let e=D(i.element),t=i.scales[0];if(e.layout&&e.layout.type==F.GRID&&e.layout.numRows>1){let n=e.layout.getElementsByRow(!0,i.element);for(let e of n)r.push({scale:t,elems:e})}else r.push({scale:t,elems:i.getElements(t)})}else"radialDistance"==e&&r.push({scale:i.scales[0],elems:S(i.element)});for(let e of r){let t=new qy(i.channel,i.attribute,e.scale,e.elems,n);this.addChild(t),i.addRefElement(t),ft(t,this._depGraph),at(this,t,this._depGraph)}}else{let r=n.element?n.element:N(this,t);if(!r)return void console.warn("Cannot create "+e+" gridlines for "+t);let i=L(r.parent);if(!i.layout)return void console.warn("Cannot create "+e+" gridlines for "+t);let s=S(i);for(let r of s){let i=[];r.layout.type==F.GRID&&r.layout.numRows>1&&"x"==e?i=r.layout.getElementsByRow():r.layout.type==F.GRID&&r.layout.numCols>1&&"y"==e?i=r.layout.getElementsByCol():i.push(r.children);for(let s of i){let i=new qy(e,t,null,s,n);this.addChild(i),r.layout.addRefElement(i),ft(i,this._depGraph),at(this,i,this._depGraph)}}}}axis(e,t,r){let n=r||{},i="rowId"==t?Vt:t,s=[],a=n.element?Ve(n.element,e):Le(i,e,this);if(a){a.attribute!==i&&console.warn("Cannot create a "+e+" axis for "+i);let t=[];if("x"==e||"width"==e){let e=D(a.element);if(e.layout&&e.layout.type==F.GRID&&e.layout.numCols>1){let r=e.layout.getElementsByCell(!0,a.element);for(let e of r)t.push({scale:a.getScale(e[0]),elems:e})}else t.push({scale:a.scales[0],elems:a.getElements(a.scales[0])})}else if("y"==e||"height"==e){let e=D(a.element);if(e.layout&&e.layout.type==F.GRID&&e.layout.numRows>1){let r=e.layout.getElementsByCell(!0,a.element);for(let e of r)t.push({scale:a.getScale(e[0]),elems:e})}else t.push({scale:a.scales[0],elems:a.getElements(a.scales[0])})}else"radialDistance"==e&&t.push({scale:a.scales[0],elems:S(a.element)});for(let e of t){let t=new er(a,e.scale,e.elems,n);this.addChild(t),s.push(t),a.addRefElement(t),dt(t,this._depGraph),at(this,t,this._depGraph),this.onChange(X.PROPERTY,Qe.AXIS_PATH_POSITION,t)}}else{let t=n.element?n.element:N(this,i);if(!t)return void console.warn("Cannot create a "+e+" axis for "+i);let r=L(t.parent);if(!r.layout)return void console.warn("Cannot create a "+e+" axis for "+i);let a=S(r);for(let t of a){let r=[];t.layout.type==F.GRID&&t.layout.numRows>1&&"x"==e?r=t.layout.getElementsByRow():t.layout.type==F.GRID&&t.layout.numCols>1&&"y"==e?r=t.layout.getElementsByCol():r.push(t.children);for(let a of r){let r=new tr(a,e,i,n);this.addChild(r),s.push(r),t.layout.addRefElement(r),ht(r,this._depGraph),at(this,r,this._depGraph),this.onChange(X.PROPERTY,Qe.AXIS_PATH_POSITION,r)}}}return s}legend(e,t,r){let n=r||{},i="rowId"==t?Vt:t,s=n.element?Ve(n.element,e):Le(i,e,this);if(s){s.attribute!==t&&console.warn("Cannot create a "+e+" legend for "+t);let r="string"===Lt(s.element).getAttributeType(t)?new im(s,n):new sm(s,n);this.addChild(r),function(e,t){let r=t.getVariable(X.BOUNDS,e),n=t.getVariable(X.PROPERTY,Qe.LEGEND_POSITION,e),i=t.getIncomingDataflowOperator(W.EVAL_BBOX,r);t.connect(n,i),t.connect(i,r)}(r,this._depGraph),at(this,r,this._depGraph),f(r),this.onChange(X.PROPERTY,Qe.LEGEND_POSITION,r)}else console.warn("Cannot create a "+e+" legend for "+i)}setLayout(e,t){if(e.layout&&(lt(e,e.layout,this._depGraph),t.type===F.TREEMAP)){let t=e.firstChild;for(;t&&t.type===Tt.Collection&&t.layout;)lt(t,t.layout,this._depGraph),t=t.firstChild}if(S(e).forEach((e=>{let r=t?t.clone():t;e._layout=r,r&&(r.group=e)})),ut(e,t,this._depGraph),e.children&&e.children.length>0){let t=G(e,!0);for(let e of t)this.onChange(X.CHANNEL,"x",e)}}setProperties(e,t,r){let n=r?[e]:S(e);n.forEach((e=>{for(const[r,n]of Object.entries(t))Fe(e,r,n)})),"width"in t&&n.forEach((e=>e._refBounds.setWidth(t.width))),"height"in t&&n.forEach((e=>e._refBounds.setHeight(t.height)));for(let r in t)["vertex","segment"].includes(e.type)&&!["x","y"].includes(r)||(Object.values(Oe).includes(r)?this.onChange(X.CHANNEL,r,e):this.onChange(X.PROPERTY,r,e))}setLayoutParameters(e,t){let r=S(e);for(let e of r)for(let r in t)e.layout[r]=t[r];this.onChange(X.CHANNEL,"width",e.firstChild)}sortChildren(e,t,r,n){if(e instanceof pt)em(e,t,r,n),this.onChange(X.ORDER,e);else if(e instanceof ne){let i=S(e);for(let e of i)tm(e,t,r,n)}}findElements(e){return I(this,e)}translate(e,t,r){je(e,t,r);let n=G(e,!0);for(let e of n)f(e);for(let e of n)this.onChange(X.CHANNEL,"x",e)}transform(e,t,r){let n=t.clone();switch(e){case"bin":!function(e,t,r,n,i){let s=i.getVariable(X.ATTRIBUTE,e,r),a=i.getVariable(X.ATTRIBUTE,t,n),o=i.createOneWayDependency(W.BIN_TRANSFORMER);i.connect(s,o),i.connect(o,a),o.run()}(r.attribute,r.newAttribute,t,n,this._depGraph);break;case"filter":!function(e,t,r,n){let i=n.getVariable(X.ITEMS,void 0,t),s=n.getVariable(X.ITEMS,e,r),a=n.createOneWayDependency(W.FILTER_TRANSFORMER);n.connect(i,a),n.connect(a,s),a.run()}(o(r),t,n,this._depGraph);break;case"kde":!function(e,t,r,n,i,s){let a=s.getVariable(X.ATTRIBUTE,e,r),o=s.getVariable(X.ATTRIBUTE,t,n),l=s.createOneWayDependency(W.KDE_TRANSFORMER);l.args=i,s.connect(a,l),s.connect(l,o),l.run()}(r.attribute,r.newAttribute,t,n,r,this._depGraph)}return n}}function mm(e,t){let r=new fe(t.tables[e.dt]);for(let t in e.attr2value)r._attr2value[t]=e.attr2value[t],r._updateTuples(t,e.attr2value[t]);return r}class bm extends z{constructor(e){super(),this.type=F.DIRECTED,this._width="width"in e?e.width:500,this._height="height"in e?e.height:300,this._top="top"in e?e.top:0,this._left="left"in e?e.left:0,this._edgeSep="edgeSep"in e?e.edgeSep:50,this._spreadLinks=!("spreadLinks"in e)||e.spreadLinks,this._direction="direction"in e?e.direction:J.Top2Bottom}clone(){return new bm({width:this._width,height:this._height,top:this._top,left:this._left,edgeSep:this._edgeSep,spreadLinks:this._spreadLinks,direction:this._direction})}get width(){return this._width}get height(){return this._height}get top(){return this._top}get left(){return this._left}get edgeSep(){return this._edgeSep}get spreadLinks(){return this._spreadLinks}get direction(){return this._direction}}class vm extends z{constructor(e){super(),this.type=F.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 vm({x:this._x,y:this._y,iterations:this._iterations,repulsion:this._repulsion,attraction:this._attraction,linkDistance:this._linkDistance})}}class xm extends z{constructor(e){super(),this.type=F.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 xm({x:this._x,y:this._y,width:this._width,height:this._height})}}class Em extends z{constructor(e){super(),this.type=F.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:$.HORIZONTAL}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 Em({width:this._width,height:this._height,top:this._top,left:this._left,orientation:this._orientation})}}class wm extends z{constructor(e){super(),this.type=F.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 wm({width:this._width,height:this._height,top:this._top,left:this._left})}}function Am(e){switch(e.type){case F.GRID:return function(e){let t=new rm(e.args);return t._left=e.left,t._top=e.top,t._cellBounds=e.cellBounds.map((e=>Cm(e))),t._grid=e.grid,t}(e);case F.STACK:return function(e){let t=new Ky(e.args);return t}(e);case F.PACKING:return function(e){let t=new xm(e.args);return t}(e);case F.FORCE:return function(e){return new vm(e.args)}(e);case F.DIRECTED:return function(e){return new bm(e.args)}(e);case F.TIDYTREE:return function(e){return new Em(e.args)}(e);case F.TREEMAP:return function(e){return new wm(e.args)}(e);case F.STRATA:return function(e){return new lm(e.args)}(e);default:return void console.warn("unsupported layout type for deserialization:",e.type)}}function Cm(e){return new u(e.x-e.width/2,e.y-e.height/2,e.width,e.height)}function Rm(e,t){e.type===Tt.Pie&&(e.type=Tt.Arc),e.args.type=e.type;let r=At(e.args);return e.id&&(r._id=e.id),e.classId&&(r._classId=e.classId),e.dataScope&&(r._dataScope=mm(e.dataScope,t)),e.bounds&&(r._bounds=Cm(e.bounds)),e.refBounds&&(r._refBounds=Cm(e.refBounds)),function(e,t,r){if(e.vertices){const n=[];for(let i of e.vertices){const e=km(i,t,r);n.push(e)}t.vertices=n,t.segments=[];let i=0;for(let e=1;e<t.vertices.length;e++)t.segments.push(new re(t.vertices[e-1],t.vertices[e],t,i++));t.type===Tt.Rect&&t.segments.push(new re(t.vertices[t.vertices.length-1],t.vertices[0],t,i++))}t.vertexCounter=e.vertexCounter,t.segmentCounter=e.segmentCounter,t.curveMode=e.curveMode}(e,r,t),r}function km(e,t,r){let n=new te(e.x,e.y,t,e.id);return e.dataScope&&(n._dataScope=mm(e.dataScope,r)),"polarAngle"in e&&(n._polarAngle=e.polarAngle),n.shape=e.shape,n.width=e.width,n.height=e.height,n.radius=e.radius,n.fillColor=e.fillColor,n.opacity=e.opacity,n.strokeWidth=e.strokeWidth,n.strokeColor=e.strokeColor,n}function Sm(e){let t={};t.fillColor=e.fillColor;let r=new ym(t),n={};if(e.tables)for(let t in e.tables){let r=e.tables[t];n[t]=new Nt(r.data,r.url,r.attributeTypes),n[t]._id=r.id}r.tables=n;let i={};if(e.scales)for(let t in e.scales)i[t]=Nm(e.scales[t]);if(r.scales=i,Im(e,r,r),Om(e,r),e.encodings)for(let t of e.encodings)r._addAttributeEncoding(Lm(t,r));return delete r.tables,delete r.scales,r._bounds=Cm(e.bounds),r}function Tm(e,t,r){if(e.type===Tt.Collection){let n=Ct(r);t.addChild(n),Im(e,n,r),r._itemMap[n.id]=n}else if(e.type===Tt.Glyph){let n=Rt();t.addChild(n),Im(e,n,r),r._itemMap[n.id]=n}else if(e.type===Tt.Composite){let n=new am;t.addChild(n),Im(e,n,r),r._itemMap[n.id]=n,n._bounds=Cm(e.bounds)}else if(Object.values(E).includes(e.type)){let n=Rm(e,r);r._itemMap[n.id]=n,t.addChild(n)}}function Om(e,t){if(e.children)for(let r of e.children)Om(r,t);else if(Object.values(E).includes(e.type)){let r=t._itemMap[e.id];e.links&&(r.links=e.links.map((e=>t._itemMap[e]))),e.source&&(r.source=t._itemMap[e.source]),e.target&&(r.target=t._itemMap[e.target])}}function Im(e,t,r){if(e.id&&(t._id=e.id),e.classId&&(t._classId=e.classId),e.dataScope&&(t._dataScope=mm(e.dataScope,r)),t._bounds=Cm(e.bounds),e.layout&&(t._layout=Am(e.layout),t._layout.group=t),t._sortBy=e.sortBy,e.children)for(let n of e.children)Tm(n,t,r)}function Nm(e){let t=new Ut(e.type,e.args);return t._id=e.id,t.domain=e.domain,t.range=e.range,t}function Lm(e,t){let r=function(e,t,r){if("vertex"===t){let t=e.split("_v_");return r._itemMap[t[0]].vertices.find((e=>e._id===parseInt(t[1])))}if("segment"===t){let t=e.split("_s_");return r._itemMap[t[0]].segments.find((e=>e._id===parseInt(t[1])))}return r._itemMap[e]}(e.element,e.elementType,t);r||console.warn("element not created:",e.element,e.elementType);let n=new Yy(r,e.channel,e.attr,e.aggregator,e.args);if(e.scales&&(n._scales=e.scales.map((e=>t.scales[e]))),e.elemGroups&&(n._elemGroups=e.elemGroups.map((e=>e.map((e=>t._itemMap[e]))))),e.elem2scale){n._elem2scale={};for(let r in e.elem2scale)n._elem2scale[r]=t.scales[e.elem2scale[r]]}return e.args.startAngle&&(n.startAngle=e.args.startAngle),n}function Vm(e){let t={};return t.id=e._id,t.data=e._rawData,t.attributeTypes=e._attrTypes,t.url=e.url,t}function Pm(e){let t={};return t.dt=e._dt.id,t.attr2value=Object.assign({},e._attr2value),t}function Dm(e,t){t.vertices=[];for(let r of e.vertices)t.vertices.push(Bm(r));t.vertexCounter=e.vertexCounter,t.segmentCounter=e.segmentCounter,t.curveMode=e.curveMode}function Bm(e){let t={};return t.type=e.type,t.id=e._id,t.x=e.x,t.y=e.y,e._dataScope&&(t.dataScope=Pm(e._dataScope)),void 0!==e._polarAngle&&(t.polarAngle=e._polarAngle),t.shape=e.shape,t.width=e.width,t.height=e.height,t.radius=e.radius,t.fillColor=e.fillColor,t.opacity=e.opacity,t.strokeWidth=e.strokeWidth,t.strokeColor=e.strokeColor,t}function Mm(e){return e.type===Tt.Scene?function(e){let t=zm(e,{});t.fillColor=e.fillColor,t.scales={},t.encodings=[];for(let r in e._encodings)for(let n in e._encodings[r]){let i=e._encodings[r][n];i._forLegend||t.encodings.push(jm(i));for(let e of i._scales)e.id in t.scales||(t.scales[e.id]=Gm(e))}t.tables={};let r=function(e){let t={};for(let r in e._encodings)for(let n in e._encodings[r]){let i=e._encodings[r][n];i.dataTable.id in t||i._forLegend||(t[i.dataTable.id]=i.dataTable)}for(let r of e.children)if(![Tt.Axis,Tt.Legend,Tt.Gridlines].includes(r.type)){if(r.dataScope){t[r.dataScope.dataTable.id]=r.dataScope.dataTable;break}if(r.children&&r.children.length>0){let e=r.firstChild;for(;e;){if(e.dataScope){t[e.dataScope.dataTable.id]=e.dataScope.dataTable;break}e=e.children&&e.children.length>0?e.firstChild:void 0}}}return t}(e);for(let e in r)t.tables[e]=Vm(r[e]);return console.log(t.tables),t}(e):e instanceof pt?zm(e,{}):e instanceof v?function(e){let t={args:{}};t.type=e.type,t.id=e.id,e.classId&&(t.classId=e.classId),e._dataScope&&(t.dataScope=Pm(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 r in e.styles)r.indexOf("Color")>0&&e.styles[r]instanceof b?t.args[r]=e.styles[r].toJSON():t.args[r]=e.styles[r];switch(e.type){case Tt.Arc:case Tt.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),Dm(e,t);break;case Tt.Area:!function(e,t){t.args.baseline=e._baseline,t.args.orientation=e._orientation}(e,t),Dm(e,t);break;case Tt.Circle:!function(e,t){t.args.x=e.x,t.args.y=e.y,t.args.radius=e.radius}(e,t);break;case Tt.Image:break;case Tt.Line:case Tt.Path:case Tt.BezierCurve:Dm(e,t);break;case Tt.PointText:!function(e,t){t.args.x=e._x,t.args.y=e._y,t.args.text=e._text,t.args.anchor=e._anchor}(e,t);break;case Tt.Polygon:!function(e,t){t.args.x=e._x,t.args.y=e._y,t.args.radius=e._radius}(e,t),Dm(e,t);break;case Tt.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),Dm(e,t);case Tt.Ring:}return t}(e):(console.warn("unsupported serialization",e.type),{type:e.type})}function Gm(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 jm(e){let t={};t.element=e._elem.id,t.elementType=e._elem.type,e.attrValues&&(t.attrValues=e.attrValues),t.channel=e._channel,t.attr=e._attribute,t.aggregator=e._aggregator,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,t.scales=e._scales.map((e=>e.id)),t.elemGroups=e._elemGroups.map((e=>e.map((e=>e.id)))),t.elem2scale={};for(let r in e._elem2scale)t.elem2scale[r]=e._elem2scale[r].id;return t.refElements=e._refElements.map((e=>e.id)),"angle"==e.channel&&(t.args.startAngle=e.startAngle),t}function zm(e,t){if(t.id=e.id,t.type=e.type,e.classId&&(t.classId=e.classId),e._dataScope&&(t.dataScope=Pm(e._dataScope)),t.bounds=e.bounds.toJSON(),e._layout&&(t.layout=function(e){switch(e.type){case F.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.left=e._left,t.top=e._top,t.cellBounds=e._cellBounds.map((e=>e.toJSON())),t.group=e.group.id,t.grid=e._grid,t}(e);case F.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 F.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 F.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 F.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 F.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 F.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 F.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 F.STRATA:return function(e){let t={args:{}};return t.type=e.type,t.args.direction=e._direction,t.args.gap=e._gap,t}(e);default:throw new Error("unknow layout type "+e.type)}}(e._layout)),t.children=[],e.children.length>0)for(let r of e.children)t.children.push(Mm(r));return t.sortBy=e._sortBy,t}function Fm(t,r,n,i,s){for(let a of t){let t=a.listener?a.listener:n,o=t.type===Tt.Axis?t.boundsWithoutTitle:t.bounds,l=[[o.left,o.top],[o.right,o.bottom]],u="brushX"===a.event?e.brushX():"brushY"===a.event?e.brushY():e.brush();u.extent(l).on("brush end",(e=>{let t,r;if(e&&e.selection)switch(a.event){case"brushX":t=[e.selection[0],e.selection[1]],r=void 0;break;case"brushY":t=void 0,r=[e.selection[0],e.selection[1]];break;default:t=[e.selection[0][0],e.selection[1][0]],r=[e.selection[0][1],e.selection[1][1]]}else t=void 0,r=void 0;a.mouseEvent={xInterval:t,yInterval:r},n.onChange(X.TRIGGER,a),i._render(n,s)})),r.append("g").attr("class","brush").call(u)}}function Um(e,t,r,n,i){t.on("mousemove",(s=>{for(let n of e){let[e,i]=w(t.attr("id"),s.clientX,s.clientY),a=B(r,n.element.type,e,i);a?n.isCumulative&&!n.elements.includes(a)?n.elements.push(a):n.elements=[a]:n.elements=[],n.mouseEvent={x:e,y:i},r.onChange(X.TRIGGER,n)}n._render(r,i)}))}function Hm(t,r,n,i,s){for(let r of t)if(r.type===Ze.WIDGET){console.log(r.id),document.getElementById(r.id).addEventListener("input",(function(){Wm(r,n,i,s)}))}else r.type===Ze.KEYBOARD&&e.select("body").on("keydown",(e=>{e.key===r.key&&Wm(r,n,i,s)}))}function Wm(e,t,r,n){if(Array.isArray(e.callback))for(let i=0;i<e.callback.length;i++)e.callback[i](),r._render(t,n,e.animation[i]);else e.callback(),r._render(t,n,e.animation)}function Ym(e,t,r,n,i){t.on("click",(s=>{for(let n of e){let[e,i]=w(t.attr("id"),s.clientX,s.clientY),a=B(r,n.element.type,e,i);a?n.isCumulative&&!n.elements.includes(a)?n.elements.push(a):n.elements=[a]:n.elements=[],n.mouseEvent={x:e,y:i},r.onChange(X.TRIGGER,n)}n._render(r,i)}))}class Xm{constructor(e){this._svgId=e,this._compMap={},this._decoMap={},this._brushCreated=0}render(t,r){let n=r||{};e.select("#"+this._svgId).select("defs").empty()&&e.select("#"+this._svgId).append("defs"),this._render(t,n),this._registerEvents(t,n)}_render(e,t,r){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,r);for(let e in this._removed)this._compMap[e].remove(),delete this._compMap[e]}_registerEvents(t,r){let n=e.select("#"+this._svgId);for(let e in t.interactionTriggers){let i=Object.values(t.interactionTriggers[e]);switch(e){case"click":n.on("click",null),Ym(i,n,t,this,r);break;case"brush":case"brushX":case"brushY":Fm(i,n,t,this,r);break;case"hover":Um(i,n,t,this,r);break;case"input":Hm(i,0,t,this,r)}}}clear(){let e=document.getElementById(this._svgId);for(;e.firstChild;)e.firstChild.remove();this._compMap={},this._decoMap={}}_renderItem(t,r,n){this._configSVG(t);let i=this._compMap[t.id];switch(t.type){case Tt.Scene:!function(e,t){t.style("background",e.fillColor?e.fillColor:"#fff")}(t,e.select("#"+this._svgId));break;case Tt.Circle:!function(e,t){t.attr("cx",e.x),t.attr("cy",e.y),t.attr("r",e.radius)}(t,i);break;case Tt.Rect:!function(e,t){let r=e.bounds;t.attr("x",r.left).attr("y",r.top).attr("width",r.width).attr("height",r.height)}(t,i);break;case Tt.Path:case Tt.BezierCurve:case Tt.BundledPath:case Tt.Chord:case Tt.Polygon:case Tt.Link:case Tt.Pie:case Tt.Line:case Tt.Area:case Tt.Ring:case Tt.Arc:case Tt.Gridlines:!function(e,t){t.attr("d",e.getSVGPathData()),e.closed||t.style("fill","none"),(e.id.includes("axis")||e.id.includes("gridlines"))&&t.style("shape-rendering","crispEdges"),e.type===Tt.BundledPath&&t.style("mix-blend-mode","multiply")}(t,i);break;case Tt.PointText:!function(t,r){if(r.attr("text-anchor",y(t.anchor[0])).attr("alignment-baseline",y(t.anchor[1])).attr("dominant-baseline",y(t.anchor[1])).attr("x",t.x).attr("y",t.y),t.hasBackground()){let r=e.select("#"+_(t)),n=t.bounds;r.attr("x",n.left-5).attr("y",n.top-5).attr("width",n.width+10).attr("height",n.height+10).attr("rx",5).attr("ry",5).style("fill",t.backgroundColor).style("stroke",t.borderColor).style("strokeWidth",t.borderWidth)}t.textPath?(r.select("textPath").empty()&&r.append("textPath"),r.select("textPath").attr("href","#"+g(t)).attr("startOffset",t.textPathOffset).text(t.text)):r.text(t.text)}(t,i);break;case Tt.Image:!function(e,t){t.attr("href",e.src).attr("x",e.x).attr("y",e.y).attr("width",e.width).attr("height",e.height)}(t,i)}if(function(t,r,n){for(let i in t.styles)if(void 0!==t.styles[i])if(i.indexOf("Color")>0&&t.styles[i].type==Tt.LinearGradient){let e=n.select("defs"),s=t.styles[i];if(e.select("#"+s.id).empty()){let t=e.append("linearGradient").attr("id",s.id);t.attr("x1",s.x1+"%").attr("x2",s.x2+"%").attr("y1",s.y1+"%").attr("y2",s.y2+"%");for(let e of s.stops)t.append("stop").attr("offset",e.offset+"%").style("stop-color",e.color).style("stop-opacity",e.opacity)}r.style(m[i],"url(#"+s.id+")")}else r.style(m[i],t.styles[i]),"visibility"===i&&t.type===Tt.PointText&&t.hasBackground()&&e.select("#"+_(t)).style(m[i],t.styles[i])}(t,i,e.select("#"+this._svgId)),t._rotate&&i.attr("transform","rotate("+t._rotate.join(" ")+")"),n&&(i=i.transition().delay(n.delay?n.delay:0).duration(n.duration?n.duration:0)),t.vertices&&this._renderVertices(t),[Tt.Circle].includes(t.type)&&r&&r.bounds?this._renderBounds(t):x(t)&&r&&r.refBounds&&this._renderRefBounds(t),t.children)for(let e of t.children)this._renderItem(e,r,n)}_configSVG(t){let r,n=t.parent;if(r=n&&n.id&&n.id in this._compMap?e.select("#"+this._svgId).select("#"+n.id):e.select("#"+this._svgId),t.id in this._compMap)delete this._removed[t.id],t.type===Tt.PointText&&(t.hasBackground()&&delete this._removed[_(t)],t.textPath&&delete this._removed[g(t)]);else{if(t.type===Tt.PointText&&(t.hasBackground()&&(this._compMap[_(t)]=r.append("rect").attr("id",_(t))),t.textPath)){let r=e.select("#"+this._svgId).select("defs"),n=g(t);r.select("#"+n).empty()&&(this._compMap[n]=r.append("path").attr("id",n)),this._compMap[n].attr("d",t.textPath).style("fill","none")}this._compMap[t.id]=r.append(this._getSVGElementType(t))}t.type==Tt.Gridlines&&this._compMap[t.id].lower(),this._compMap[t.id].attr("id",t.id),t.classId&&this._compMap[t.id].attr("class",t.classId)}_renderBounds(t){let r=t.bounds;t.layout&&"grid"==t.layout.type&&this._renderLayout(t),t.id in this._decoMap||(this._decoMap[t.id]=e.select("#"+this._svgId).append("rect").attr("class","deco")),this._decoMap[t.id].attr("x",r.left).attr("y",r.top).attr("width",r.width).attr("height",r.height).attr("fill","none").attr("stroke","blue").attr("stroke-width","1px").attr("stroke-dasharray","5,5")}_renderRefBounds(t){let r=t.refBounds;r&&(t.id in this._decoMap||(this._decoMap[t.id]=e.select("#"+this._svgId).append("rect").attr("class","deco")),this._decoMap[t.id].attr("x",r.left).attr("y",r.top).attr("width",r.width).attr("height",r.height).attr("fill","none").attr("stroke","blue").attr("stroke-width","1px").attr("stroke-dasharray","5,5"))}_renderVertices(t){let r=t.id+"-vertices";if(r in this._compMap)delete this._removed[r];else{let n=t.parent,i=n?n.id:this._svgId;this._compMap[r]=e.select("#"+i).append("g").attr("id",r)}if(0===t.vertices.map((e=>e.shape)).filter((e=>void 0!==e)).length)return void this._compMap[r].style("visible","hidden");this._compMap[r].style("visible","visible");let n=t.vertices.filter((e=>void 0!==e.shape));for(let t of n){let n=r+"-"+t.id;n in this._compMap?t.shape!==this._compMap[n].node().tagName?(this._compMap[n].remove(),this._compMap[n]=e.select("#"+r).append(t.shape).attr("id",n),delete this._removed[n]):delete this._removed[n]:this._compMap[n]=e.select("#"+r).append(t.shape).attr("id",n),"rect"==t.shape?e.select("#"+n).attr("x",t.x-t.width/2).attr("y",t.y-t.height/2).attr("width",t.width).attr("height",t.height):"circle"==t.shape&&e.select("#"+n).attr("cx",t.x).attr("cy",t.y).attr("r",t.radius),e.select("#"+n).style("fill",t.fillColor).style("opacity",t.opacity).style("stroke-width",t.strokeWidth).style("stroke",t.strokeColor)}}_renderLayout(t){let r=t.id+"-grid";r in this._decoMap||(this._decoMap[r]=e.select("#"+this._svgId).append("g").attr("id",r).attr("class","deco"));let n=t.layout.cellBounds;t.layout.rowGap,this._decoMap[r].selectAll("rect").remove();for(let e of n)this._decoMap[r].append("rect").attr("x",e.left).attr("y",e.top).attr("width",e.width).attr("height",e.height).attr("stroke","blue").attr("stroke-width","1px").attr("stroke-dasharray","5,5").attr("fill","none")}_getSVGElementType(e){switch(e.type){case Tt.Rect:return"rect";case Tt.Collection:case Tt.Group:case Tt.Glyph:case Tt.Scene:case Tt.Axis:case Tt.Legend:case Tt.Composite:return"g";case Tt.Area:case Tt.Path:case Tt.Polygon:case Tt.Ring:case Tt.Pie:case Tt.Arc:case Tt.BezierCurve:case Tt.BundledPath:case Tt.Chord:case Tt.Line:case Tt.Gridlines:return"path";case Tt.Circle:return"circle";case Tt.PointText:return"text";case"vertex":if("circle"==e.shape)return"circle";if("rect"==e.shape)return"rect";throw"argument exception";case"image":return"image"}}}function qm(e,t){return void 0===e&&void 0===t||void 0!==e&&void 0!==t}function Km(e,t){const r=Object.keys(e),n=Object.keys(t);return r.length===n.length&&(0===r.length||r.every((e=>n.includes(e))))}function Zm(e,t){if(!qm(e.layout,t.layout))return console.log("Not both defined or undefined:",e.bounds,t.bounds),!1;let r=e.layout,n=t.layout;if(!r&&!n)return!0;if(r.type!==n.type)return console.log("layout types are different:",r,n),!1;switch(r.type){case F.GRID:return function(e,t){e._cellBounds.length!==t._cellBounds.length&&console.log("cell bounds length different:",e,t);for(let r=0;r<e._cellBounds;r++)if(!Jm(e._cellBounds[r],t._cellBounds[r]))return console.log("cell bounds not equal:",e,t),!1;for(let r=0;r<e._grid.length;r++)for(let n=0;n<e._grid[r].length;n++)if(e._grid[r][n]!==t._grid[r][n])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._left===t._left&&e._top===t._top}(r,n);case F.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}(r,n);case F.PACKING:return function(e,t){return e._x===t._x&&e._y===t._y&&e._width===t._width&&e._height===t._height}(r,n);case F.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}(r,n);case F.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}(r,n);case F.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}(r,n);case F.STRATA:return function(e,t){return e._direction===t._direction&&e._gap===t._gap}(r,n);case F.TREEMAP:return function(e,t){return e._width===t._width&&e._height===t._height&&e._top===t._top&&e._left===t._left}(r,n);default:return!1}}function $m(e,t){if(!qm(e.bounds,t.bounds))return console.log("Not both defined or undefined:",e.bounds,t.bounds),!1;let r=e.bounds,n=t.bounds;return!r&&!n||Jm(r,n)}function Jm(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Qm(e,t){if(!qm(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(!tb(e,t))return console.log("DataScopes not equal",e,t),!1;if(!$m(e,t))return console.log("Bounds not equal",e,t),!1;if(!qm(e.links,t.links))return console.log("Not both defined or undefined: links ",e.links,t.links),!1;if(!qm(e.source,t.source))return console.log("Not both defined or undefined: source ",e.source,t.source),!1;if(!qm(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&&!Qm(e.source,t.source))return console.log("different sources",e.source,t.source),!1;if(e.target&&t.target&&!Qm(e.target,t.target))return console.log("different targets",e.target,t.target),!1;switch(e.type){case Tt.Arc:case Tt.Pie:return eb(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 Tt.Area:return eb(e,t)?e.baseline===t.baseline&&e.orientation===t.orientation:(console.log("vertices not equal:",e,t),!1);case Tt.Circle:return e.x===t.x&&e.y===t.y&&e.radius===t.radius;case Tt.Image:return console.warn("not implemented"),!0;case Tt.Line:case Tt.Path:case Tt.BezierCurve:return!!eb(e,t)||(console.log("vertices not equal:",e,t),!1);case Tt.PointText: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 Tt.Polygon:return eb(e,t)?e.x===t.x&&e.y===t.y&&e.radius===t.radius:(console.log("vertices not equal:",e,t),!1);case Tt.Rect:return eb(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 Tt.Ring:default:return console.warn("not implemented"),!0}}function eb(e,t){if(e.vertices.length!==t.vertices.length)return console.log("unequal number of vertices:",e,t),!1;for(let r=0;r<e.vertices.length;r++){let n=e.vertices[r],i=t.vertices[r];return n.id!==i.id?(console.log("vertex id not equal:",n,i),!1):n.x!==i.x||n.y!==i.y?(console.log("vertex position not equal:",n,i),!1):tb(n,i)?n._polarAngle===i._polarAngle&&n.shape===i.shape&&n.width===i.width&&n.height==i.height&&n.radius==i.radius&&n.fillColor==i.fillColor&&n.opacity==i.opacity&&n.strokeWidth==i.strokeWidth&&n.strokeColor==i.strokeColor:(console.log("vertex data scopes not equal:",n.dataScope,i.dataScope),!1)}}function tb(e,t){if(!qm(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 r=e.dataScope,n=t.dataScope;if(!Km(r._attr2value,n._attr2value))return!1;for(let e in r._attr2value)if(r._attr2value[e]!==n._attr2value[e])return!1;return r._dt.id===n._dt.id&&r._tuples.length===n._tuples.length}function rb(e,t){return e.type!==t.type&&console.log("Different types:",e.type,t.type),[Tt.Collection,Tt.Glyph,Tt.Composite].includes(e.type)?nb(e,t):e instanceof v?Qm(e,t):void 0}function nb(e,t){let r=e.children.filter((e=>!Object.values(Ot).includes(e.type))),n=t.children.filter((e=>!Object.values(Ot).includes(e.type)));if(r.length!==n.length)return console.log("children length not equal:",r,n),!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(!tb(e,t))return console.log("DataScopes not equal",e.dataScope,t.dataScope),!1;if(!$m(e,t))return console.log("Bounds not equal",e,t),!1;if(!Zm(e,t))return console.log("Layouts not equal",e,t),!1;if(!function(e,t){if(!Km(e,t))return console.log("different keys",e,t),!1;for(let r in e)if(e[r]!==t[r])return!1;return!0}(e._sortBy,t._sortBy))return console.log("SortBy not equal",e,t),!1;for(let e=0;e<r.length;e++)if(!rb(r[e],n[e]))return console.log("Not equal",r[e],n[e]),!1;return!0}class ib extends z{constructor(e){super(),this.type=F.CIRCULAR,this._x="x"in e?e.x:100,this._y="y"in e?e.y:100,this._radius="radius"in e?e.radius:100}get x(){return this._x}get y(){return this._y}get radius(){return this._radius}clone(){return new ib({x:this._x,y:this._y,radius:this._radius})}}class sb extends z{constructor(e){super(),this.type=F.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:$.HORIZONTAL,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 sb({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 ab(e,t){let r=t||{};switch(e.toLowerCase()){case F.STACK:return new Ky(r);case F.PACKING:return new xm(r);case F.FORCE:return new vm(r);case F.DIRECTED:return new bm(r);case F.TIDYTREE:return new Em(r);case F.TREEMAP:return new wm(r);case F.CIRCULAR:return new ib(r);case F.CLUSTER:return new sb(r);case F.GRID:default:return new rm(r)}}function ob(e){return new ym(e)}async function lb(t){return async function(t){let r=await Pt("GET",t),n=e.csvParse(r.trim(),e.autoType);return new Nt(n,t)}(t)}async function ub(e){return async function(e){let t=await Pt("GET",e);return new me(JSON.parse(t),e)}(e)}async function cb(e){return async function(e){let t=await Pt("GET",e);return new ge(JSON.parse(t),e)}(e)}function hb(e,t){return new Xm(t)}function db(e){return Mm(e)}function fb(e){return Sm(e)}function pb(e,t){return function(e,t){return e.fillColor!==t.fillColor?(console.log("fillColor not equal:",e,t),!1):nb(e,t)}(e,t)}export{lb as csv,fb as deserialize,ub as graphJSON,pb as isEqual,ab as layout,hb as renderer,ob as scene,db as serialize,cb as treeJSON};
186
+ */return lp=function(n){return r(t(n,void 0,e),n+"")}}()((function(t,r){return null==t?{}:e(t,r)}));return cp=t}(),range:function(){if(yp)return gp;yp=1;var e=Xp()();return gp=e}(),reduce:yd(),sortBy:function(){if(kp)return Rp;kp=1;var e=xd(),t=Kp(),r=Ad(),n=Dp(),i=r((function(r,i){if(null==r)return[];var s=i.length;return s>1&&n(r,i[0],i[1])?i=[]:s>2&&n(i[0],i[1],i[2])&&(i=[i[0]]),t(r,e(i,1),[])}));return Rp=i}(),uniqueId:function(){if(Tp)return Sp;Tp=1;var e=td(),t=0;return Sp=function(r){var n=++t;return e(r)+n},Sp}(),values:Id(),zipObject:function(){if(Lp)return Np;Lp=1;var e=qi(),t=Ip?Op:(Ip=1,Op=function(e,t,r){for(var n=-1,i=e.length,s=t.length,a={};++n<i;){var o=n<s?t[n]:void 0;r(a,e[n],o)}return a});return Np=function(r,n){return t(r||[],n||[],e)}}()}}catch(e){}Vp||(Vp=window._);var Zp=Vp,$p=Jp;function Jp(){var e={};e._next=e._prev=e,this._sentinel=e}function Qp(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function e_(e,t){if("_next"!==e&&"_prev"!==e)return t}Jp.prototype.dequeue=function(){var e=this._sentinel,t=e._prev;if(t!==e)return Qp(t),t},Jp.prototype.enqueue=function(e){var t=this._sentinel;e._prev&&e._next&&Qp(e),e._next=t._next,t._next._prev=e,t._next=e,e._prev=t},Jp.prototype.toString=function(){for(var e=[],t=this._sentinel,r=t._prev;r!==t;)e.push(JSON.stringify(r,e_)),r=r._prev;return"["+e.join(", ")+"]"};var t_=Zp,r_=Pp.Graph,n_=$p,i_=function(e,t){if(e.nodeCount()<=1)return[];var r=function(e,t){var r=new r_,n=0,i=0;t_.forEach(e.nodes(),(function(e){r.setNode(e,{v:e,in:0,out:0})})),t_.forEach(e.edges(),(function(e){var s=r.edge(e.v,e.w)||0,a=t(e),o=s+a;r.setEdge(e.v,e.w,o),i=Math.max(i,r.node(e.v).out+=a),n=Math.max(n,r.node(e.w).in+=a)}));var s=t_.range(i+n+3).map((function(){return new n_})),a=n+1;return t_.forEach(r.nodes(),(function(e){o_(s,a,r.node(e))})),{graph:r,buckets:s,zeroIdx:a}}(e,t||s_),n=function(e,t,r){var n,i=[],s=t[t.length-1],a=t[0];for(;e.nodeCount();){for(;n=a.dequeue();)a_(e,t,r,n);for(;n=s.dequeue();)a_(e,t,r,n);if(e.nodeCount())for(var o=t.length-2;o>0;--o)if(n=t[o].dequeue()){i=i.concat(a_(e,t,r,n,!0));break}}return i}(r.graph,r.buckets,r.zeroIdx);return t_.flatten(t_.map(n,(function(t){return e.outEdges(t.v,t.w)})),!0)},s_=t_.constant(1);function a_(e,t,r,n,i){var s=i?[]:void 0;return t_.forEach(e.inEdges(n.v),(function(n){var a=e.edge(n),o=e.node(n.v);i&&s.push({v:n.v,w:n.w}),o.out-=a,o_(t,r,o)})),t_.forEach(e.outEdges(n.v),(function(n){var i=e.edge(n),s=n.w,a=e.node(s);a.in-=i,o_(t,r,a)})),e.removeNode(n.v),s}function o_(e,t,r){r.out?r.in?e[r.out-r.in+t].enqueue(r):e[e.length-1].enqueue(r):e[0].enqueue(r)}var l_=Zp,u_=i_,c_={run:function(e){var t="greedy"===e.graph().acyclicer?u_(e,function(e){return function(t){return e.edge(t).weight}}(e)):function(e){var t=[],r={},n={};function i(s){l_.has(n,s)||(n[s]=!0,r[s]=!0,l_.forEach(e.outEdges(s),(function(e){l_.has(r,e.w)?t.push(e):i(e.w)})),delete r[s])}return l_.forEach(e.nodes(),i),t}(e);l_.forEach(t,(function(t){var r=e.edge(t);e.removeEdge(t),r.forwardName=t.name,r.reversed=!0,e.setEdge(t.w,t.v,r,l_.uniqueId("rev"))}))},undo:function(e){l_.forEach(e.edges(),(function(t){var r=e.edge(t);if(r.reversed){e.removeEdge(t);var n=r.forwardName;delete r.reversed,delete r.forwardName,e.setEdge(t.w,t.v,r,n)}}))}};var h_=Zp,d_=Pp.Graph,f_={addDummyNode:p_,simplify:function(e){var t=(new d_).setGraph(e.graph());return h_.forEach(e.nodes(),(function(r){t.setNode(r,e.node(r))})),h_.forEach(e.edges(),(function(r){var n=t.edge(r.v,r.w)||{weight:0,minlen:1},i=e.edge(r);t.setEdge(r.v,r.w,{weight:n.weight+i.weight,minlen:Math.max(n.minlen,i.minlen)})})),t},asNonCompoundGraph:function(e){var t=new d_({multigraph:e.isMultigraph()}).setGraph(e.graph());return h_.forEach(e.nodes(),(function(r){e.children(r).length||t.setNode(r,e.node(r))})),h_.forEach(e.edges(),(function(r){t.setEdge(r,e.edge(r))})),t},successorWeights:function(e){var t=h_.map(e.nodes(),(function(t){var r={};return h_.forEach(e.outEdges(t),(function(t){r[t.w]=(r[t.w]||0)+e.edge(t).weight})),r}));return h_.zipObject(e.nodes(),t)},predecessorWeights:function(e){var t=h_.map(e.nodes(),(function(t){var r={};return h_.forEach(e.inEdges(t),(function(t){r[t.v]=(r[t.v]||0)+e.edge(t).weight})),r}));return h_.zipObject(e.nodes(),t)},intersectRect:function(e,t){var r,n,i=e.x,s=e.y,a=t.x-i,o=t.y-s,l=e.width/2,u=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)*u?(o<0&&(u=-u),r=u*a/o,n=u):(a<0&&(l=-l),r=l,n=l*o/a);return{x:i+r,y:s+n}},buildLayerMatrix:function(e){var t=h_.map(h_.range(__(e)+1),(function(){return[]}));return h_.forEach(e.nodes(),(function(r){var n=e.node(r),i=n.rank;h_.isUndefined(i)||(t[i][n.order]=r)})),t},normalizeRanks:function(e){var t=h_.min(h_.map(e.nodes(),(function(t){return e.node(t).rank})));h_.forEach(e.nodes(),(function(r){var n=e.node(r);h_.has(n,"rank")&&(n.rank-=t)}))},removeEmptyRanks:function(e){var t=h_.min(h_.map(e.nodes(),(function(t){return e.node(t).rank}))),r=[];h_.forEach(e.nodes(),(function(n){var i=e.node(n).rank-t;r[i]||(r[i]=[]),r[i].push(n)}));var n=0,i=e.graph().nodeRankFactor;h_.forEach(r,(function(t,r){h_.isUndefined(t)&&r%i!=0?--n:n&&h_.forEach(t,(function(t){e.node(t).rank+=n}))}))},addBorderNode:function(e,t,r,n){var i={width:0,height:0};arguments.length>=4&&(i.rank=r,i.order=n);return p_(e,"border",i,t)},maxRank:__,partition:function(e,t){var r={lhs:[],rhs:[]};return h_.forEach(e,(function(e){t(e)?r.lhs.push(e):r.rhs.push(e)})),r},time:function(e,t){var r=h_.now();try{return t()}finally{console.log(e+" time: "+(h_.now()-r)+"ms")}},notime:function(e,t){return t()}};function p_(e,t,r,n){var i;do{i=h_.uniqueId(n)}while(e.hasNode(i));return r.dummy=t,e.setNode(i,r),i}function __(e){return h_.max(h_.map(e.nodes(),(function(t){var r=e.node(t).rank;if(!h_.isUndefined(r))return r})))}var g_=Zp,y_=f_,m_={run:function(e){e.graph().dummyChains=[],g_.forEach(e.edges(),(function(t){!function(e,t){var r,n,i,s=t.v,a=e.node(s).rank,o=t.w,l=e.node(o).rank,u=t.name,c=e.edge(t),h=c.labelRank;if(l===a+1)return;for(e.removeEdge(t),i=0,++a;a<l;++i,++a)c.points=[],n={width:0,height:0,edgeLabel:c,edgeObj:t,rank:a},r=y_.addDummyNode(e,"edge",n,"_d"),a===h&&(n.width=c.width,n.height=c.height,n.dummy="edge-label",n.labelpos=c.labelpos),e.setEdge(s,r,{weight:c.weight},u),0===i&&e.graph().dummyChains.push(r),s=r;e.setEdge(s,o,{weight:c.weight},u)}(e,t)}))},undo:function(e){g_.forEach(e.graph().dummyChains,(function(t){var r,n=e.node(t),i=n.edgeLabel;for(e.setEdge(n.edgeObj,i);n.dummy;)r=e.successors(t)[0],e.removeNode(t),i.points.push({x:n.x,y:n.y}),"edge-label"===n.dummy&&(i.x=n.x,i.y=n.y,i.width=n.width,i.height=n.height),t=r,n=e.node(t)}))}};var b_=Zp,v_={longestPath:function(e){var t={};b_.forEach(e.sources(),(function r(n){var i=e.node(n);if(b_.has(t,n))return i.rank;t[n]=!0;var s=b_.min(b_.map(e.outEdges(n),(function(t){return r(t.w)-e.edge(t).minlen})));return s!==Number.POSITIVE_INFINITY&&null!=s||(s=0),i.rank=s}))},slack:function(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}};var x_=Zp,E_=Pp.Graph,w_=v_.slack,A_=function(e){var t,r,n=new E_({directed:!1}),i=e.nodes()[0],s=e.nodeCount();n.setNode(i,{});for(;C_(n,e)<s;)t=R_(n,e),r=n.hasNode(t.v)?w_(e,t):-w_(e,t),k_(n,e,r);return n};function C_(e,t){return x_.forEach(e.nodes(),(function r(n){x_.forEach(t.nodeEdges(n),(function(i){var s=i.v,a=n===s?i.w:s;e.hasNode(a)||w_(t,i)||(e.setNode(a,{}),e.setEdge(n,a,{}),r(a))}))})),e.nodeCount()}function R_(e,t){return x_.minBy(t.edges(),(function(r){if(e.hasNode(r.v)!==e.hasNode(r.w))return w_(t,r)}))}function k_(e,t,r){x_.forEach(e.nodes(),(function(e){t.node(e).rank+=r}))}var S_=Zp,T_=A_,O_=v_.slack,I_=v_.longestPath,N_=Pp.alg.preorder,L_=Pp.alg.postorder,V_=f_.simplify,P_=D_;function D_(e){e=V_(e),I_(e);var t,r=T_(e);for(G_(r),B_(r,e);t=z_(r);)U_(r,e,t,F_(r,e,t))}function B_(e,t){var r=L_(e,e.nodes());r=r.slice(0,r.length-1),S_.forEach(r,(function(r){!function(e,t,r){var n=e.node(r),i=n.parent;e.edge(r,i).cutvalue=M_(e,t,r)}(e,t,r)}))}function M_(e,t,r){var n=e.node(r).parent,i=!0,s=t.edge(r,n),a=0;return s||(i=!1,s=t.edge(n,r)),a=s.weight,S_.forEach(t.nodeEdges(r),(function(s){var o,l,u=s.v===r,c=u?s.w:s.v;if(c!==n){var h=u===i,d=t.edge(s).weight;if(a+=h?d:-d,o=r,l=c,e.hasEdge(o,l)){var f=e.edge(r,c).cutvalue;a+=h?-f:f}}})),a}function G_(e,t){arguments.length<2&&(t=e.nodes()[0]),j_(e,{},1,t)}function j_(e,t,r,n,i){var s=r,a=e.node(n);return t[n]=!0,S_.forEach(e.neighbors(n),(function(i){S_.has(t,i)||(r=j_(e,t,r,i,n))})),a.low=s,a.lim=r++,i?a.parent=i:delete a.parent,r}function z_(e){return S_.find(e.edges(),(function(t){return e.edge(t).cutvalue<0}))}function F_(e,t,r){var n=r.v,i=r.w;t.hasEdge(n,i)||(n=r.w,i=r.v);var s=e.node(n),a=e.node(i),o=s,l=!1;s.lim>a.lim&&(o=a,l=!0);var u=S_.filter(t.edges(),(function(t){return l===H_(e,e.node(t.v),o)&&l!==H_(e,e.node(t.w),o)}));return S_.minBy(u,(function(e){return O_(t,e)}))}function U_(e,t,r,n){var i=r.v,s=r.w;e.removeEdge(i,s),e.setEdge(n.v,n.w,{}),G_(e),B_(e,t),function(e,t){var r=S_.find(e.nodes(),(function(e){return!t.node(e).parent})),n=N_(e,r);n=n.slice(1),S_.forEach(n,(function(r){var n=e.node(r).parent,i=t.edge(r,n),s=!1;i||(i=t.edge(n,r),s=!0),t.node(r).rank=t.node(n).rank+(s?i.minlen:-i.minlen)}))}(e,t)}function H_(e,t,r){return r.low<=t.lim&&t.lim<=r.lim}D_.initLowLimValues=G_,D_.initCutValues=B_,D_.calcCutValue=M_,D_.leaveEdge=z_,D_.enterEdge=F_,D_.exchangeEdges=U_;var W_=v_.longestPath,Y_=A_,X_=P_,q_=function(e){switch(e.graph().ranker){case"network-simplex":default:Z_(e);break;case"tight-tree":!function(e){W_(e),Y_(e)}(e);break;case"longest-path":K_(e)}};var K_=W_;function Z_(e){X_(e)}var $_=Zp,J_=function(e){var t=function(e){var t={},r=0;function n(i){var s=r;$_.forEach(e.children(i),n),t[i]={low:s,lim:r++}}return $_.forEach(e.children(),n),t}(e);$_.forEach(e.graph().dummyChains,(function(r){for(var n=e.node(r),i=n.edgeObj,s=function(e,t,r,n){var i,s,a=[],o=[],l=Math.min(t[r].low,t[n].low),u=Math.max(t[r].lim,t[n].lim);i=r;do{i=e.parent(i),a.push(i)}while(i&&(t[i].low>l||u>t[i].lim));s=i,i=n;for(;(i=e.parent(i))!==s;)o.push(i);return{path:a.concat(o.reverse()),lca:s}}(e,t,i.v,i.w),a=s.path,o=s.lca,l=0,u=a[l],c=!0;r!==i.w;){if(n=e.node(r),c){for(;(u=a[l])!==o&&e.node(u).maxRank<n.rank;)l++;u===o&&(c=!1)}if(!c){for(;l<a.length-1&&e.node(u=a[l+1]).minRank<=n.rank;)l++;u=a[l]}e.setParent(r,u),r=e.successors(r)[0]}}))};var Q_=Zp,eg=f_,tg={run:function(e){var t=eg.addDummyNode(e,"root",{},"_root"),r=function(e){var t={};function r(n,i){var s=e.children(n);s&&s.length&&Q_.forEach(s,(function(e){r(e,i+1)})),t[n]=i}return Q_.forEach(e.children(),(function(e){r(e,1)})),t}(e),n=Q_.max(Q_.values(r))-1,i=2*n+1;e.graph().nestingRoot=t,Q_.forEach(e.edges(),(function(t){e.edge(t).minlen*=i}));var s=function(e){return Q_.reduce(e.edges(),(function(t,r){return t+e.edge(r).weight}),0)}(e)+1;Q_.forEach(e.children(),(function(a){rg(e,t,i,s,n,r,a)})),e.graph().nodeRankFactor=i},cleanup:function(e){var t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,Q_.forEach(e.edges(),(function(t){e.edge(t).nestingEdge&&e.removeEdge(t)}))}};function rg(e,t,r,n,i,s,a){var o=e.children(a);if(o.length){var l=eg.addBorderNode(e,"_bt"),u=eg.addBorderNode(e,"_bb"),c=e.node(a);e.setParent(l,a),c.borderTop=l,e.setParent(u,a),c.borderBottom=u,Q_.forEach(o,(function(o){rg(e,t,r,n,i,s,o);var c=e.node(o),h=c.borderTop?c.borderTop:o,d=c.borderBottom?c.borderBottom:o,f=c.borderTop?n:2*n,p=h!==d?1:i-s[a]+1;e.setEdge(l,h,{weight:f,minlen:p,nestingEdge:!0}),e.setEdge(d,u,{weight:f,minlen:p,nestingEdge:!0})})),e.parent(a)||e.setEdge(t,l,{weight:0,minlen:i+s[a]})}else a!==t&&e.setEdge(t,a,{weight:0,minlen:r})}var ng=Zp,ig=f_,sg=function(e){ng.forEach(e.children(),(function t(r){var n=e.children(r),i=e.node(r);if(n.length&&ng.forEach(n,t),ng.has(i,"minRank")){i.borderLeft=[],i.borderRight=[];for(var s=i.minRank,a=i.maxRank+1;s<a;++s)ag(e,"borderLeft","_bl",r,i,s),ag(e,"borderRight","_br",r,i,s)}}))};function ag(e,t,r,n,i,s){var a={width:0,height:0,rank:s,borderType:t},o=i[t][s-1],l=ig.addDummyNode(e,"border",a,r);i[t][s]=l,e.setParent(l,n),o&&e.setEdge(o,l,{weight:1})}var og=Zp,lg={adjust:function(e){var t=e.graph().rankdir.toLowerCase();"lr"!==t&&"rl"!==t||ug(e)},undo:function(e){var t=e.graph().rankdir.toLowerCase();"bt"!==t&&"rl"!==t||function(e){og.forEach(e.nodes(),(function(t){hg(e.node(t))})),og.forEach(e.edges(),(function(t){var r=e.edge(t);og.forEach(r.points,hg),og.has(r,"y")&&hg(r)}))}(e);"lr"!==t&&"rl"!==t||(!function(e){og.forEach(e.nodes(),(function(t){dg(e.node(t))})),og.forEach(e.edges(),(function(t){var r=e.edge(t);og.forEach(r.points,dg),og.has(r,"x")&&dg(r)}))}(e),ug(e))}};function ug(e){og.forEach(e.nodes(),(function(t){cg(e.node(t))})),og.forEach(e.edges(),(function(t){cg(e.edge(t))}))}function cg(e){var t=e.width;e.width=e.height,e.height=t}function hg(e){e.y=-e.y}function dg(e){var t=e.x;e.x=e.y,e.y=t}var fg=Zp,pg=function(e){var t={},r=fg.filter(e.nodes(),(function(t){return!e.children(t).length})),n=fg.max(fg.map(r,(function(t){return e.node(t).rank}))),i=fg.map(fg.range(n+1),(function(){return[]}));function s(r){if(!fg.has(t,r)){t[r]=!0;var n=e.node(r);i[n.rank].push(r),fg.forEach(e.successors(r),s)}}var a=fg.sortBy(r,(function(t){return e.node(t).rank}));return fg.forEach(a,s),i};var _g=Zp,gg=function(e,t){for(var r=0,n=1;n<t.length;++n)r+=yg(e,t[n-1],t[n]);return r};function yg(e,t,r){for(var n=_g.zipObject(r,_g.map(r,(function(e,t){return t}))),i=_g.flatten(_g.map(t,(function(t){return _g.sortBy(_g.map(e.outEdges(t),(function(t){return{pos:n[t.w],weight:e.edge(t).weight}})),"pos")})),!0),s=1;s<r.length;)s<<=1;var a=2*s-1;s-=1;var o=_g.map(new Array(a),(function(){return 0})),l=0;return _g.forEach(i.forEach((function(e){var t=e.pos+s;o[t]+=e.weight;for(var r=0;t>0;)t%2&&(r+=o[t+1]),o[t=t-1>>1]+=e.weight;l+=e.weight*r}))),l}var mg=Zp;var bg=Zp;var vg=Zp,xg=f_;function Eg(e,t,r){for(var n;t.length&&(n=vg.last(t)).i<=r;)t.pop(),e.push(n.vs),r++;return r}var wg=Zp,Ag=function(e,t){return mg.map(t,(function(t){var r=e.inEdges(t);if(r.length){var n=mg.reduce(r,(function(t,r){var n=e.edge(r),i=e.node(r.v);return{sum:t.sum+n.weight*i.order,weight:t.weight+n.weight}}),{sum:0,weight:0});return{v:t,barycenter:n.sum/n.weight,weight:n.weight}}return{v:t}}))},Cg=function(e,t){var r={};return bg.forEach(e,(function(e,t){var n=r[e.v]={indegree:0,in:[],out:[],vs:[e.v],i:t};bg.isUndefined(e.barycenter)||(n.barycenter=e.barycenter,n.weight=e.weight)})),bg.forEach(t.edges(),(function(e){var t=r[e.v],n=r[e.w];bg.isUndefined(t)||bg.isUndefined(n)||(n.indegree++,t.out.push(r[e.w]))})),function(e){var t=[];function r(e){return function(t){t.merged||(bg.isUndefined(t.barycenter)||bg.isUndefined(e.barycenter)||t.barycenter>=e.barycenter)&&function(e,t){var r=0,n=0;e.weight&&(r+=e.barycenter*e.weight,n+=e.weight);t.weight&&(r+=t.barycenter*t.weight,n+=t.weight);e.vs=t.vs.concat(e.vs),e.barycenter=r/n,e.weight=n,e.i=Math.min(t.i,e.i),t.merged=!0}(e,t)}}function n(t){return function(r){r.in.push(t),0==--r.indegree&&e.push(r)}}for(;e.length;){var i=e.pop();t.push(i),bg.forEach(i.in.reverse(),r(i)),bg.forEach(i.out,n(i))}return bg.map(bg.filter(t,(function(e){return!e.merged})),(function(e){return bg.pick(e,["vs","i","barycenter","weight"])}))}(bg.filter(r,(function(e){return!e.indegree})))},Rg=function(e,t){var r=xg.partition(e,(function(e){return vg.has(e,"barycenter")})),n=r.lhs,i=vg.sortBy(r.rhs,(function(e){return-e.i})),s=[],a=0,o=0,l=0;n.sort((u=!!t,function(e,t){return e.barycenter<t.barycenter?-1:e.barycenter>t.barycenter?1:u?t.i-e.i:e.i-t.i})),l=Eg(s,i,l),vg.forEach(n,(function(e){l+=e.vs.length,s.push(e.vs),a+=e.barycenter*e.weight,o+=e.weight,l=Eg(s,i,l)}));var u;var c={vs:vg.flatten(s,!0)};o&&(c.barycenter=a/o,c.weight=o);return c},kg=function e(t,r,n,i){var s=t.children(r),a=t.node(r),o=a?a.borderLeft:void 0,l=a?a.borderRight:void 0,u={};o&&(s=wg.filter(s,(function(e){return e!==o&&e!==l})));var c=Ag(t,s);wg.forEach(c,(function(r){if(t.children(r.v).length){var s=e(t,r.v,n,i);u[r.v]=s,wg.has(s,"barycenter")&&(a=r,o=s,wg.isUndefined(a.barycenter)?(a.barycenter=o.barycenter,a.weight=o.weight):(a.barycenter=(a.barycenter*a.weight+o.barycenter*o.weight)/(a.weight+o.weight),a.weight+=o.weight))}var a,o}));var h=Cg(c,n);!function(e,t){wg.forEach(e,(function(e){e.vs=wg.flatten(e.vs.map((function(e){return t[e]?t[e].vs:e})),!0)}))}(h,u);var d=Rg(h,i);if(o&&(d.vs=wg.flatten([o,d.vs,l],!0),t.predecessors(o).length)){var f=t.node(t.predecessors(o)[0]),p=t.node(t.predecessors(l)[0]);wg.has(d,"barycenter")||(d.barycenter=0,d.weight=0),d.barycenter=(d.barycenter*d.weight+f.order+p.order)/(d.weight+2),d.weight+=2}return d};var Sg=Zp,Tg=Pp.Graph,Og=function(e,t,r){var n=function(e){var t;for(;e.hasNode(t=Sg.uniqueId("_root")););return t}(e),i=new Tg({compound:!0}).setGraph({root:n}).setDefaultNodeLabel((function(t){return e.node(t)}));return Sg.forEach(e.nodes(),(function(s){var a=e.node(s),o=e.parent(s);(a.rank===t||a.minRank<=t&&t<=a.maxRank)&&(i.setNode(s),i.setParent(s,o||n),Sg.forEach(e[r](s),(function(t){var r=t.v===s?t.w:t.v,n=i.edge(r,s),a=Sg.isUndefined(n)?0:n.weight;i.setEdge(r,s,{weight:e.edge(t).weight+a})})),Sg.has(a,"minRank")&&i.setNode(s,{borderLeft:a.borderLeft[t],borderRight:a.borderRight[t]}))})),i};var Ig=Zp;var Ng=Zp,Lg=pg,Vg=gg,Pg=kg,Dg=Og,Bg=function(e,t,r){var n,i={};Ig.forEach(r,(function(r){for(var s,a,o=e.parent(r);o;){if((s=e.parent(o))?(a=i[s],i[s]=o):(a=n,n=o),a&&a!==o)return void t.setEdge(a,o);o=s}}))},Mg=Pp.Graph,Gg=f_,jg=function(e){var t=Gg.maxRank(e),r=zg(e,Ng.range(1,t+1),"inEdges"),n=zg(e,Ng.range(t-1,-1,-1),"outEdges"),i=Lg(e);Ug(e,i);for(var s,a=Number.POSITIVE_INFINITY,o=0,l=0;l<4;++o,++l){Fg(o%2?r:n,o%4>=2),i=Gg.buildLayerMatrix(e);var u=Vg(e,i);u<a&&(l=0,s=Ng.cloneDeep(i),a=u)}Ug(e,s)};function zg(e,t,r){return Ng.map(t,(function(t){return Dg(e,t,r)}))}function Fg(e,t){var r=new Mg;Ng.forEach(e,(function(e){var n=e.graph().root,i=Pg(e,n,r,t);Ng.forEach(i.vs,(function(t,r){e.node(t).order=r})),Bg(e,r,i.vs)}))}function Ug(e,t){Ng.forEach(t,(function(t){Ng.forEach(t,(function(t,r){e.node(t).order=r}))}))}var Hg=Zp,Wg=Pp.Graph,Yg=f_,Xg=function(e){var t,r=Yg.buildLayerMatrix(e),n=Hg.merge(qg(e,r),Kg(e,r)),i={};Hg.forEach(["u","d"],(function(s){t="u"===s?r:Hg.values(r).reverse(),Hg.forEach(["l","r"],(function(r){"r"===r&&(t=Hg.map(t,(function(e){return Hg.values(e).reverse()})));var a=("u"===s?e.predecessors:e.successors).bind(e),o=Jg(e,t,n,a),l=Qg(e,t,o.root,o.align,"r"===r);"r"===r&&(l=Hg.mapValues(l,(function(e){return-e}))),i[s+r]=l}))}));var s=ey(e,i);return ty(i,s),ry(i,e.graph().align)};function qg(e,t){var r={};return Hg.reduce(t,(function(t,n){var i=0,s=0,a=t.length,o=Hg.last(n);return Hg.forEach(n,(function(t,l){var u=function(e,t){if(e.node(t).dummy)return Hg.find(e.predecessors(t),(function(t){return e.node(t).dummy}))}(e,t),c=u?e.node(u).order:a;(u||t===o)&&(Hg.forEach(n.slice(s,l+1),(function(t){Hg.forEach(e.predecessors(t),(function(n){var s=e.node(n),a=s.order;!(a<i||c<a)||s.dummy&&e.node(t).dummy||Zg(r,n,t)}))})),s=l+1,i=c)})),n})),r}function Kg(e,t){var r={};function n(t,n,i,s,a){var o;Hg.forEach(Hg.range(n,i),(function(n){o=t[n],e.node(o).dummy&&Hg.forEach(e.predecessors(o),(function(t){var n=e.node(t);n.dummy&&(n.order<s||n.order>a)&&Zg(r,t,o)}))}))}return Hg.reduce(t,(function(t,r){var i,s=-1,a=0;return Hg.forEach(r,(function(o,l){if("border"===e.node(o).dummy){var u=e.predecessors(o);u.length&&(i=e.node(u[0]).order,n(r,a,l,s,i),a=l,s=i)}n(r,a,r.length,i,t.length)})),r})),r}function Zg(e,t,r){if(t>r){var n=t;t=r,r=n}var i=e[t];i||(e[t]=i={}),i[r]=!0}function $g(e,t,r){if(t>r){var n=t;t=r,r=n}return Hg.has(e[t],r)}function Jg(e,t,r,n){var i={},s={},a={};return Hg.forEach(t,(function(e){Hg.forEach(e,(function(e,t){i[e]=e,s[e]=e,a[e]=t}))})),Hg.forEach(t,(function(e){var t=-1;Hg.forEach(e,(function(e){var o=n(e);if(o.length){o=Hg.sortBy(o,(function(e){return a[e]}));for(var l=(o.length-1)/2,u=Math.floor(l),c=Math.ceil(l);u<=c;++u){var h=o[u];s[e]===e&&t<a[h]&&!$g(r,e,h)&&(s[h]=e,s[e]=i[e]=i[h],t=a[h])}}}))})),{root:i,align:s}}function Qg(e,t,r,n,i){var s={},a=function(e,t,r,n){var i=new Wg,s=e.graph(),a=function(e,t,r){return function(n,i,s){var a,o=n.node(i),l=n.node(s),u=0;if(u+=o.width/2,Hg.has(o,"labelpos"))switch(o.labelpos.toLowerCase()){case"l":a=-o.width/2;break;case"r":a=o.width/2}if(a&&(u+=r?a:-a),a=0,u+=(o.dummy?t:e)/2,u+=(l.dummy?t:e)/2,u+=l.width/2,Hg.has(l,"labelpos"))switch(l.labelpos.toLowerCase()){case"l":a=l.width/2;break;case"r":a=-l.width/2}return a&&(u+=r?a:-a),a=0,u}}(s.nodesep,s.edgesep,n);return Hg.forEach(t,(function(t){var n;Hg.forEach(t,(function(t){var s=r[t];if(i.setNode(s),n){var o=r[n],l=i.edge(o,s);i.setEdge(o,s,Math.max(a(e,t,n),l||0))}n=t}))})),i}(e,t,r,i),o=i?"borderLeft":"borderRight";function l(e,t){for(var r=a.nodes(),n=r.pop(),i={};n;)i[n]?e(n):(i[n]=!0,r.push(n),r=r.concat(t(n))),n=r.pop()}return l((function(e){s[e]=a.inEdges(e).reduce((function(e,t){return Math.max(e,s[t.v]+a.edge(t))}),0)}),a.predecessors.bind(a)),l((function(t){var r=a.outEdges(t).reduce((function(e,t){return Math.min(e,s[t.w]-a.edge(t))}),Number.POSITIVE_INFINITY),n=e.node(t);r!==Number.POSITIVE_INFINITY&&n.borderType!==o&&(s[t]=Math.max(s[t],r))}),a.successors.bind(a)),Hg.forEach(n,(function(e){s[e]=s[r[e]]})),s}function ey(e,t){return Hg.minBy(Hg.values(t),(function(t){var r=Number.NEGATIVE_INFINITY,n=Number.POSITIVE_INFINITY;return Hg.forIn(t,(function(t,i){var s=function(e,t){return e.node(t).width}(e,i)/2;r=Math.max(t+s,r),n=Math.min(t-s,n)})),r-n}))}function ty(e,t){var r=Hg.values(t),n=Hg.min(r),i=Hg.max(r);Hg.forEach(["u","d"],(function(r){Hg.forEach(["l","r"],(function(s){var a,o=r+s,l=e[o];if(l!==t){var u=Hg.values(l);(a="l"===s?n-Hg.min(u):i-Hg.max(u))&&(e[o]=Hg.mapValues(l,(function(e){return e+a})))}}))}))}function ry(e,t){return Hg.mapValues(e.ul,(function(r,n){if(t)return e[t.toLowerCase()][n];var i=Hg.sortBy(Hg.map(e,n));return(i[1]+i[2])/2}))}var ny=Zp,iy=f_,sy=Xg;var ay=Zp,oy=c_,ly=m_,uy=q_,cy=f_.normalizeRanks,hy=J_,dy=f_.removeEmptyRanks,fy=tg,py=sg,_y=lg,gy=jg,yy=function(e){(function(e){var t=iy.buildLayerMatrix(e),r=e.graph().ranksep,n=0;ny.forEach(t,(function(t){var i=ny.max(ny.map(t,(function(t){return e.node(t).height})));ny.forEach(t,(function(t){e.node(t).y=n+i/2})),n+=i+r}))})(e=iy.asNonCompoundGraph(e)),ny.forEach(sy(e),(function(t,r){e.node(r).x=t}))},my=f_,by=Pp.Graph,vy=function(e,t){var r=t&&t.debugTiming?my.time:my.notime;r("layout",(function(){var t=r(" buildLayoutGraph",(function(){return function(e){var t=new by({multigraph:!0,compound:!0}),r=Oy(e.graph());return t.setGraph(ay.merge({},Ey,Ty(r,xy),ay.pick(r,wy))),ay.forEach(e.nodes(),(function(r){var n=Oy(e.node(r));t.setNode(r,ay.defaults(Ty(n,Ay),Cy)),t.setParent(r,e.parent(r))})),ay.forEach(e.edges(),(function(r){var n=Oy(e.edge(r));t.setEdge(r,ay.merge({},ky,Ty(n,Ry),ay.pick(n,Sy)))})),t}(e)}));r(" runLayout",(function(){!function(e,t){t(" makeSpaceForEdgeLabels",(function(){!function(e){var t=e.graph();t.ranksep/=2,ay.forEach(e.edges(),(function(r){var n=e.edge(r);n.minlen*=2,"c"!==n.labelpos.toLowerCase()&&("TB"===t.rankdir||"BT"===t.rankdir?n.width+=n.labeloffset:n.height+=n.labeloffset)}))}(e)})),t(" removeSelfEdges",(function(){!function(e){ay.forEach(e.edges(),(function(t){if(t.v===t.w){var r=e.node(t.v);r.selfEdges||(r.selfEdges=[]),r.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}}))}(e)})),t(" acyclic",(function(){oy.run(e)})),t(" nestingGraph.run",(function(){fy.run(e)})),t(" rank",(function(){uy(my.asNonCompoundGraph(e))})),t(" injectEdgeLabelProxies",(function(){!function(e){ay.forEach(e.edges(),(function(t){var r=e.edge(t);if(r.width&&r.height){var n=e.node(t.v),i={rank:(e.node(t.w).rank-n.rank)/2+n.rank,e:t};my.addDummyNode(e,"edge-proxy",i,"_ep")}}))}(e)})),t(" removeEmptyRanks",(function(){dy(e)})),t(" nestingGraph.cleanup",(function(){fy.cleanup(e)})),t(" normalizeRanks",(function(){cy(e)})),t(" assignRankMinMax",(function(){!function(e){var t=0;ay.forEach(e.nodes(),(function(r){var n=e.node(r);n.borderTop&&(n.minRank=e.node(n.borderTop).rank,n.maxRank=e.node(n.borderBottom).rank,t=ay.max(t,n.maxRank))})),e.graph().maxRank=t}(e)})),t(" removeEdgeLabelProxies",(function(){!function(e){ay.forEach(e.nodes(),(function(t){var r=e.node(t);"edge-proxy"===r.dummy&&(e.edge(r.e).labelRank=r.rank,e.removeNode(t))}))}(e)})),t(" normalize.run",(function(){ly.run(e)})),t(" parentDummyChains",(function(){hy(e)})),t(" addBorderSegments",(function(){py(e)})),t(" order",(function(){gy(e)})),t(" insertSelfEdges",(function(){!function(e){var t=my.buildLayerMatrix(e);ay.forEach(t,(function(t){var r=0;ay.forEach(t,(function(t,n){var i=e.node(t);i.order=n+r,ay.forEach(i.selfEdges,(function(t){my.addDummyNode(e,"selfedge",{width:t.label.width,height:t.label.height,rank:i.rank,order:n+ ++r,e:t.e,label:t.label},"_se")})),delete i.selfEdges}))}))}(e)})),t(" adjustCoordinateSystem",(function(){_y.adjust(e)})),t(" position",(function(){yy(e)})),t(" positionSelfEdges",(function(){!function(e){ay.forEach(e.nodes(),(function(t){var r=e.node(t);if("selfedge"===r.dummy){var n=e.node(r.e.v),i=n.x+n.width/2,s=n.y,a=r.x-i,o=n.height/2;e.setEdge(r.e,r.label),e.removeNode(t),r.label.points=[{x:i+2*a/3,y:s-o},{x:i+5*a/6,y:s-o},{x:i+a,y:s},{x:i+5*a/6,y:s+o},{x:i+2*a/3,y:s+o}],r.label.x=r.x,r.label.y=r.y}}))}(e)})),t(" removeBorderNodes",(function(){!function(e){ay.forEach(e.nodes(),(function(t){if(e.children(t).length){var r=e.node(t),n=e.node(r.borderTop),i=e.node(r.borderBottom),s=e.node(ay.last(r.borderLeft)),a=e.node(ay.last(r.borderRight));r.width=Math.abs(a.x-s.x),r.height=Math.abs(i.y-n.y),r.x=s.x+r.width/2,r.y=n.y+r.height/2}})),ay.forEach(e.nodes(),(function(t){"border"===e.node(t).dummy&&e.removeNode(t)}))}(e)})),t(" normalize.undo",(function(){ly.undo(e)})),t(" fixupEdgeLabelCoords",(function(){!function(e){ay.forEach(e.edges(),(function(t){var r=e.edge(t);if(ay.has(r,"x"))switch("l"!==r.labelpos&&"r"!==r.labelpos||(r.width-=r.labeloffset),r.labelpos){case"l":r.x-=r.width/2+r.labeloffset;break;case"r":r.x+=r.width/2+r.labeloffset}}))}(e)})),t(" undoCoordinateSystem",(function(){_y.undo(e)})),t(" translateGraph",(function(){!function(e){var t=Number.POSITIVE_INFINITY,r=0,n=Number.POSITIVE_INFINITY,i=0,s=e.graph(),a=s.marginx||0,o=s.marginy||0;function l(e){var s=e.x,a=e.y,o=e.width,l=e.height;t=Math.min(t,s-o/2),r=Math.max(r,s+o/2),n=Math.min(n,a-l/2),i=Math.max(i,a+l/2)}ay.forEach(e.nodes(),(function(t){l(e.node(t))})),ay.forEach(e.edges(),(function(t){var r=e.edge(t);ay.has(r,"x")&&l(r)})),t-=a,n-=o,ay.forEach(e.nodes(),(function(r){var i=e.node(r);i.x-=t,i.y-=n})),ay.forEach(e.edges(),(function(r){var i=e.edge(r);ay.forEach(i.points,(function(e){e.x-=t,e.y-=n})),ay.has(i,"x")&&(i.x-=t),ay.has(i,"y")&&(i.y-=n)})),s.width=r-t+a,s.height=i-n+o}(e)})),t(" assignNodeIntersects",(function(){!function(e){ay.forEach(e.edges(),(function(t){var r,n,i=e.edge(t),s=e.node(t.v),a=e.node(t.w);i.points?(r=i.points[0],n=i.points[i.points.length-1]):(i.points=[],r=a,n=s),i.points.unshift(my.intersectRect(s,r)),i.points.push(my.intersectRect(a,n))}))}(e)})),t(" reversePoints",(function(){!function(e){ay.forEach(e.edges(),(function(t){var r=e.edge(t);r.reversed&&r.points.reverse()}))}(e)})),t(" acyclic.undo",(function(){oy.undo(e)}))}(t,r)})),r(" updateInputGraph",(function(){!function(e,t){ay.forEach(e.nodes(),(function(r){var n=e.node(r),i=t.node(r);n&&(n.x=i.x,n.y=i.y,t.children(r).length&&(n.width=i.width,n.height=i.height))})),ay.forEach(e.edges(),(function(r){var n=e.edge(r),i=t.edge(r);n.points=i.points,ay.has(i,"x")&&(n.x=i.x,n.y=i.y)})),e.graph().width=t.graph().width,e.graph().height=t.graph().height}(e,t)}))}))};var xy=["nodesep","edgesep","ranksep","marginx","marginy"],Ey={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},wy=["acyclicer","ranker","rankdir","align"],Ay=["width","height"],Cy={width:0,height:0},Ry=["minlen","weight","width","height","labeloffset"],ky={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},Sy=["labelpos"];function Ty(e,t){return ay.mapValues(ay.pick(e,t),Number)}function Oy(e){var t={};return ay.forEach(e,(function(e,r){t[r.toLowerCase()]=e})),t}var Iy=Zp,Ny=f_,Ly=Pp.Graph;var Vy={graphlib:Pp,layout:vy,debug:{debugOrdering:function(e){var t=Ny.buildLayerMatrix(e),r=new Ly({compound:!0,multigraph:!0}).setGraph({});return Iy.forEach(e.nodes(),(function(t){r.setNode(t,{label:t}),r.setParent(t,"layer"+e.node(t).rank)})),Iy.forEach(e.edges(),(function(e){r.setEdge(e.v,e.w,{},e.name)})),Iy.forEach(t,(function(e,t){var n="layer"+t;r.setNode(n,{rank:"same"}),Iy.reduce(e,(function(e,t){return r.setEdge(e,t,{style:"invis"}),t}))})),r}},util:{time:f_.time,notime:f_.notime},version:"0.8.5"};class Py extends H{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=S(e.parent);for(let e of t){let t=e.layout;if(!t)continue;let n=be(e.children[0]);if(!n)continue;var r=new Vy.graphlib.Graph;r.setGraph({edgesep:t._edgeSep}),r.setDefaultEdgeLabel((function(){return{}})),r.graph().rankdir=this._getDagreDirection(t.direction);let i=new Map;for(let t of e.children){let e=t.dataScope.getAttributeValue(xe);i.set(e,e+""),r.setNode(e,{label:t.text?t.text:"",width:t.bounds.width,height:t.bounds.height})}for(let e of n.linkList)r.setEdge(e.source,e.target);Vy.layout(r);const s={};let a=Math.min(...r.nodes().map((e=>r.node(e).y))),o=Math.min(...r.nodes().map((e=>r.node(e).x))),l=t.left-o,u=t.top-a;for(const e of r.nodes())s[e]={x:r.node(e).x+l,y:r.node(e).y+u};for(let t of e.children){let e=t.dataScope.getAttributeValue(xe);je(t,s[i.get(e)].x-t.x,s[i.get(e)].y-t.y)}}let n=G(e,!0);for(let e of n)f(e)}_getDagreDirection(e){switch(e){case J.Left2Right:return"LR";case J.Right2Left:return"RL";case J.Top2Bottom:return"TB";case J.Bottom2Top:return"BT"}}}class Dy extends H{constructor(e){super(e)}run(){super.run();let t=this._outputVars[0].element,r=S(t.parent);for(let t of r){let r=t.layout;if(!r)continue;let n=ye(t.children[0]);if(!n)continue;let i=e.hierarchy(n._data),s=Math.max(...t.children.map((e=>e.bounds.width))),a=Math.max(...t.children.map((e=>e.bounds.height))),o=r.orientation==$.HORIZONTAL?[r.height,r.width]:[r.width,r.height],l=e.tree().nodeSize([s,a]).size(o)(i);this._apply(l,r,t)}f(t)}_apply(e,t,r){let n,i,s=r.children.filter((t=>t.dataScope.getAttributeValue(xe)==e.data[xe]))[0];switch(t.orientation){case $.HORIZONTAL:n=e.y+t.left,i=e.x+t.top;break;case $.VERTICAL:n=e.x+t.left,i=t.top+e.y}if(je(s,n-s.x,i-s.y),e.children&&e.children.length>0)for(let n of e.children)this._apply(n,t,r)}}class By extends H{constructor(e){super(e)}run(){super.run();let t=this._outputVars[0].element,r=this._inputVars.filter((e=>e.type===X.ORDER))[0].element,n=r.layout,i=n.width?n.width:r.bounds.width,s=n.height?n.height:r.bounds.height,a=void 0===n.top?r.bounds.top:n.top,o=void 0===n.left?r.bounds.left:n.left,l=e.hierarchy(r).sum((e=>e.type===Tt.Rect?e.width*e.height:0));e.treemap().size([i,s])(l),this._apply(l,o,a);let u=G(t,!0);for(let e of u)f(e)}_apply(e,t,r){if(e.data.type==Tt.Collection&&e.children)for(let n of e.children)this._apply(n,t,r);else e.data.type==Tt.Rect&&(e.data.resize(e.x1-e.x0,e.y1-e.y0),je(e.data,e.x0+t-e.data.left,e.y0+r-e.data.top))}}class My extends H{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=S(e.parent);for(let e of t){if(!e.layout)continue;if(0===e.children.length)continue;let t=ye(e.children[0]);if(!t)continue;let r={};for(let t of e.children)r[t.dataScope.getAttributeValue(xe)]=t;e.children[0].type===Tt.Rect?this._layoutRects(t.getRoot(),t,r):this._layoutArcs(t.getRoot(),t,r)}f(e)}_layoutArcs(e,t,r){let n=t.getChildren(e);if(0===n.length)return;let i=r[e[xe]],s=!i||i.type!=Tt.Arc&&i.type!=Tt.Pie?60:i.startAngle;for(let e=0;e<n.length;e++){let i=n[e],a=r[i[xe]];if(a.type===Tt.Arc){let e=he(s+a.angle);a.setAngles(s,e),s=e}this._layoutArcs(i,t,r)}}_layoutRects(e,t,r){let n=t.getChildren(e);if(0===n.length)return;let i,s,a=r[e[xe]];this._direction,J.Top2Bottom,i=a.left,s=a.bottom;for(let e=0;e<n.length;e++){let a=n[e],o=r[a[xe]];je(o,i-o.left,s-o.top),i+=o.width,this._layoutRects(a,t,r)}}}class Gy extends Y{constructor(e,t){super(e),this._trigger=t}get trigger(){return this._trigger}}class jy extends H{constructor(e){super(e)}run(){super.run();let e=this.outputVar.condEncoding,t=e.trigger,r=S(e.target),n={};if(t.type===Ze.ELEMENT){let i=t.elements.length>0?t.elements:[void 0];r.forEach((t=>n[t.id]=i.map((r=>e._targetEval(r,t))).some((e=>e))))}t.type===Ze.MOUSE&&r.forEach((r=>n[r.id]=e._targetEval(t.mouseEvent,r))),e.evalResult=n}}class zy extends H{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=S(e.parent);for(let e of t){let t=e.layout;if(!t)continue;let r=360/e.children.length;for(let[n,i]of e.children.entries())je(i,t.x+t.radius-i.bounds.x,t.y-i.bounds.y),i._rotate=[n*r,t.x,t.y]}let r=G(e,!0);for(let e of r)f(e)}}class Fy extends H{constructor(e){super(e)}run(){super.run();let t=this._outputVars[0].element,r=S(t.parent);for(let n of r){let r=n.layout;if(!r)continue;let i=r._tree?r._tree._data:ye(n.children[0])._data,s=e.hierarchy(i);if(r.isRadial()){s=e.cluster().size([ue(r.angleExtent),r.radius])(s),r._d3Root=s;const t=new Map(s.descendants().map((e=>[e.data[xe],[e.x,e.y]])));for(let e of n.children){let n=e.dataScope.getAttributeValue(xe);je(e,r.x-e.bounds.x,r.y-t.get(n)[1]-e.bounds.y),e._rotate=[ce(t.get(n)[0]),r.x,r.y]}}else if(r.orientation===$.VERTICAL){!r.width||r.width;let i=r.height?r.height:600;s=e.cluster().nodeSize([t.bounds.width+1,i/(s.height+1)])(s),r._d3Root=s;const a=new Map(s.descendants().map((e=>[e.data[xe],[e.x,e.y]])));let o=1/0,l=-o;s.each((e=>{e.x>l&&(l=e.x),e.x<o&&(o=e.x)})),r._x0=o;for(let e of n.children){let t=e.dataScope.getAttributeValue(xe);je(e,a.get(t)[0]-o+r.left-e.bounds.x,a.get(t)[1]+r.top-e.bounds.y)}}else if(r.orientation===$.HORIZONTAL){!r.width||r.width;let i=r.height?r.height:600;s=e.cluster().nodeSize([t.bounds.height,i/(s.height+1)])(s),r._d3Root=s;const a=new Map(s.descendants().map((e=>[e.data[xe],[e.x,e.y]])));let o=1/0,l=-o;s.each((e=>{e.x>l&&(l=e.x),e.x<o&&(o=e.x)})),r._x0=o;for(let e of n.children){let t=e.dataScope.getAttributeValue(xe);je(e,a.get(t)[1]+r.left-e.bounds.x,a.get(t)[0]-o+r.top-e.bounds.y)}}}let n=G(t,!0);for(let e of n)f(e)}}class Uy{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:"DomainVar"===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):t.scale=e.scale,t}));const r={};for(const e in this._operators)r[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===W.DOMAIN_BUILDER?t.aggregator=e.aggregator:e.type===W.SCALE_BUILDER&&(t.channel=e.channel),t}));return{edges:e,variables:t,operators:r}}getVariable(e,...t){if(Object.values(X).indexOf(e)<0)throw new Error("Variable Type Not Known");let r=this.findVariable(e,t);if(r)return r;switch(e){case X.CHANNEL:r=new Te(e,t[0],t[1]),"vertex"!=t[1].type&&"segment"!=t[1].type||this._connectPathElement2Size(t[1],r);break;case X.PROPERTY:r=new Je(e,t[0],t[1]);break;case X.ATTRIBUTE:r=new jt(e,t[0],t[1]);break;case X.ITEMS:r=new hr(e,t[0],t[1]);break;case X.DOMAIN:r=new zt(e,t[0]);break;case X.DATASCOPE:r=new Bt(e,t[0]);break;case X.BOUNDS:r=new Dt(e,t[0]);break;case X.ORDER:r=new dr(e,t[0]);break;case X.SCALE:r=new qe(e,t[0]);break;case X.COND_ENCODING:r=new q(e,t[0]);break;case X.AFFIXATION:r=new pr(e,t[0]);break;case X.ALIGNMENT:r=new xr(e,t[0]);break;case X.TRIGGER:r=new Gy(e,t[0])}return e in this._variables||(this._variables[e]={}),this._variables[e][r.id]=r,r}_connectPathElement2Size(e,t){let r=e.parent,n=t.channel,i=this.findVariable(X.CHANNEL,["x"===n?"width":"height",r]);if(i){let e=i.incomingDataflow;e||(e=this.createOneWayDependency(W.CONDUIT)),this.connect(t,e),this.connect(e,i)}}findIncomingDataflowOperator(e,t){return t.incomingDataflow&&t.incomingDataflow.type===e?t.incomingDataflow:void 0}getIncomingDataflowOperator(e,t){let r=this.findIncomingDataflowOperator(e,t);return r||this.createOneWayDependency(e)}getOutgoingDataflowOperator(e,t){for(let r of t.outgoingEdges)if(r.toNode instanceof H&&r.toNode.type===e)return r.toNode;return this.createOneWayDependency(e)}createOneWayDependency(e,...t){if(Object.values(W).indexOf(e)<0)throw new Error("Dependency Type Not Known");let r;switch(e){case W.EVAL_BBOX:r=new Xt(e);break;case W.AFFIXER:r=new fr(e);break;case W.DOMAIN_BUILDER:r=new Ft(e,t[0]);break;case W.SCALE_BUILDER:r=new Yt(e,t[0]);break;case W.ENCODER:r=new $e(e,t[0]);break;case W.AXIS_PATH_PLACER:r=new rr(e);break;case W.AXIS_TICKS_PLACER:r=new nr(e);break;case W.AXIS_LABELS_PLACER:r=new ir(e);break;case W.AXIS_TITLE_PLACER:r=new br(e);break;case W.LINK_PLACER:r=new wr(e);break;case W.GRID_LAYOUT:r=new sr(e);break;case W.STACK_LAYOUT:r=new or(e);break;case W.PACK_LAYOUT:r=new mr(e);break;case W.FORCE_LAYOUT:r=new Er(e);break;case W.DIRECTED_LAYOUT:r=new Py(e);break;case W.TIDY_TREE_LAYOUT:r=new Dy(e);break;case W.TREEMAP_LAYOUT:r=new By(e);break;case W.STRATA_LAYOUT:r=new My(e);break;case W.CIRCULAR_LAYOUT:r=new zy(e);break;case W.CLUSTER_LAYOUT:r=new Fy(e);break;case W.GRIDLINES_PLACER:r=new ar(e);break;case W.BIN_TRANSFORMER:r=new ur(e);break;case W.FILTER_TRANSFORMER:r=new cr(e);break;case W.KDE_TRANSFORMER:r=new _r(e);break;case W.TARGET_EVALUATOR:r=new jy(e);break;case W.CONDUIT:default:r=new lr(e)}return e in this._operators||(this._operators[e]={}),this._operators[e][r.id]=r,r}createMultiWayDependency(e){if(Object.values(W).indexOf(e)<0)throw new Error("Dependency Type Not Known");let t;return W.ALIGNER,t=new vr(e),e in this._operators||(this._operators[e]={}),this._operators[e][t.id]=t,t}connect(e,t,r=!0){if(e instanceof Y&&t instanceof H){if(!t.inputVars.includes(e)){const n=new Gt(e,t,r);this._edges.push(n),e.outgoingEdges.push(n),t.inputVars.push(e)}}else if(e instanceof H&&t instanceof Y){if(!e.outputVars.includes(t)){const n=new Gt(e,t,r);this._edges.push(n),e.outputVars.push(t),t.incomingEdges.push(n)}}else if(e instanceof Y&&t instanceof Mt){if(!t.vars.includes(e)){const r=new Gt(e,t,!1);this._edges.push(r),t.vars.push(e),t.edges.push(e),e.undirectedEdges.push(r)}}else{if(!(e instanceof Mt&&t instanceof Y))throw new Error("An edge must connect a variable and an operator.");if(!e.vars.includes(t)){const r=new Gt(t,e,!1);this._edges.push(r),e.vars.push(t),e.edges.push(t),t.undirectedEdges.push(r)}}}disconnectChannelVarFromBBoxOperator(e){let t=this.getOutgoingDataflowOperator(W.EVAL_BBOX,e),r=e.outgoingEdges.find((r=>r.fromNode===e&&r.toNode===t));r&&this.disconnect(e,t,r)}disconnect(e,t,r){if(e instanceof Y&&t instanceof H){let n=e.outgoingEdges.findIndex((e=>e===r));n>=0&&(this._edges.splice(this._edges.indexOf(r),1),e.outgoingEdges.splice(n,1));let i=t.inputVars.findIndex((t=>t==e));i>=0&&t.inputVars.splice(i,1)}else if(e instanceof H&&t instanceof Y){let n=t.incomingEdges.findIndex((e=>e===r));n>=0&&(this._edges.splice(this._edges.indexOf(r),1),t.incomingEdges.splice(n,1));let i=e.outputVars.findIndex((e=>e===t));i>=0&&e.outputVars.splice(i,1)}}deleteVariable(e){for(let t=e.incomingEdges.length-1;t>=0;t--){let r=e.incomingEdges[t],n=r.fromNode;this.disconnect(n,e,r),n.isIsolated()&&delete this._operators[n.type][n.id]}for(let t=e.outgoingEdges.length-1;t>=0;t--){let r=e.outgoingEdges[t],n=r.toNode;this.disconnect(e,n,r),n.isIsolated()&&delete this._operators[n.type][n.id]}delete this._variables[e.type][e.id]}deleteOperator(e){for(let t=e.outputVars.length-1;t>=0;t--){let r=e.outputVars[t],n=r.incomingEdges.find((t=>t.fromNode===e&&t.toNode===r));this.disconnect(e,r,n),r.isIsolated()&&delete this._variables[r.type][r.id]}for(let t=e.inputVars.length-1;t>=0;t--){let r=e.inputVars[t],n=r.outgoingEdges.find((t=>t.fromNode===r&&t.toNode===e));this.disconnect(r,e,n),r.isIsolated()&&delete this._variables[r.type][r.id]}delete this._operators[e.type][e.id]}addInteraction(e){}_dfs(e,t,r){if(e&&0!==e.outgoingEdges.length)for(let n of e.outgoingEdges)n.isDirected&&(t.push(n.toNode),this._dfs(n.toNode.outputVars[0],t.slice(),r));else r.push(t)}processChange(e,t,...r){let n=this.findVariable(e,r);if(n){for(let e of n.outgoingEdges)if(e.isDirected){let r=e.toNode;r.run();let n=r.outputVars;if(n.length>0){let e=n[0];switch(e.type){case X.ITEMS:this.processChange(e.type,t,e.predicate,e.dataset);break;case X.ATTRIBUTE:this.processChange(e.type,t,e.attribute,e.dataset);break;case X.BOUNDS:case X.ORDER:this.processChange(e.type,t,e.element);break;case X.CHANNEL:this.processChange(e.type,t,e.channel,e.element);break;case X.PROPERTY:this.processChange(e.type,t,e.property,e.element);break;case X.SCALE:case X.DOMAIN:this.processChange(e.type,t,e.encodings[0]);break;case X.COND_ENCODING:this.processChange(e.type,t,e.condEncoding)}}}for(let e of n.undirectedEdges)t.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 r=Object.values(this._variables[e]);switch(e){case X.CHANNEL:return r.find((e=>e.channel==t[0]&&Pe(e.element)==Pe(t[1])));case X.PROPERTY:return r.find((e=>e.property==t[0]&&e.element==t[1]));case X.COND_ENCODING:return r.find((e=>e.condEncoding==t[0]));case X.AFFIXATION:return r.find((e=>e.affixation==t[0]));case X.ATTRIBUTE:return r.find((e=>e.attribute==t[0]&&e.dataset==t[1]));case X.ITEMS:return r.find((e=>e.dataset==t[1]));case X.DOMAIN:case X.SCALE:return r.find((e=>e.encodings.includes(t[0])));case X.TRIGGER:return r.find((e=>e.trigger===t[0]));case X.DATASCOPE:default:return t[0].classId?r.find((e=>Pe(e.element)==Pe(t[0]))):r.find((e=>e.element.id==t[0].id))}}findVariablesByElement(e){let t={};for(let r in this._variables){let n=Object.values(this._variables[r]).filter((t=>t.element&&Pe(t.element)==Pe(e)));n.length>0&&(t[r]=n)}return t}}function Hy(e){return!(!x(e)&&e.type!=Tt.Glyph||e.dataScope)||e.type===Tt.Collection&&e.firstChild.dataScope.numTuples>1}function Wy(e,t,r,n){let i=n.getAttributeType(r);if(i!=we.String&&i!=we.Date&&i!=we.Integer)throw new Error("Repeat only works on a string or date attribute: "+r+" is "+i);if(!function(e){if(Array.isArray(e)){if(1===e.length)return Hy(e[0]);for(let t of e)if(!x(t)||t.dataScope)return!1;return!0}return Hy(e)}(t))throw new Error("The "+t.type+" is not repeatable");return function(e,t,r,n){let i=n.getAttributeSummary(r).unique.map((e=>t.dataScope?t.dataScope.cross(r,e):new fe(n).cross(r,e)));i=i.filter((e=>!e.isEmpty()));let s=Ct(e);s.dataScope=t.dataScope?t.dataScope.clone():new fe(n),s.addChild(t),t._refBounds||(t._refBounds=t.bounds.clone());for(let e=1;e<i.length;e++){let e=kt(t);s.addChild(e)}return s.children.forEach(((e,t)=>e.dataScope=i[t])),s}(e,t,r,n)}class Yy{constructor(e,t,r,n,i){this._elem=e,this._channel=t,this._attribute=r,this._aggregator=n,this._includeZero=i.includeZero,this._flipScale=i.flipScale,this._mapping=i.mapping,this._preferredRangeExtent=i.rangeExtent,this._preferredDomain=void 0,this._scaleType=i.scaleType,this._colorScheme=i.scheme,this._forLegend=i.forLegend,this._scales=[],this._elemGroups=[],this._elem2scale={},this._refElements=[],["width","height","radius","angle","thickness","radialDistance","strokeWidth","area"].indexOf(this._channel)>=0&&(this._includeZero=!0),this.initialize()}initialize(){this._scales=[];let e=S(this._elem);if(this._elemGroups=[],"x"===this._channel||"y"===this._channel){let t=this._elem,r=D(t);if(r.layout&&r.layout.type==F.GRID){let e="x"===this._channel?r.layout.getElementsByCol(!0,t):r.layout.getElementsByRow(!0,t);for(let t of e)this._createScaleForElems(t)}else if("vertex"===this._elem.type&&(Me(this._elem.parent)||Be(this._elem.parent))){let e=S(this._elem.parent).map((e=>T(this._elem,[e])));for(let t of e)this._createScaleForElems(t)}else this._createScaleForElems(e)}else if("angle"===this._channel){let t=e.reduce(((e,t)=>{const r=t.parent.id;return e[r]||(e[r]=[]),e[r].push(t),e}),{}),r=Object.values(t);for(let e of r)this._createScaleForElems(e)}else this._createScaleForElems(e)}_createScaleForElems(e){this._elemGroups.push(e);var t=function(e){if(e.scaleType)return new Ut(e.scaleType);if("text"===e.channel)return new Ut("ordinal");switch(Lt(e.element).getAttributeType(e.attribute)){case we.Boolean:break;case we.Date:return new Ut("time");case we.String:if("count"==e.aggregator)return new Ut("linear");if(e.channel.indexOf("Color")>=0){let t={};return t.scheme=e.colorScheme?e.colorScheme:"schemeCategory10",new Ut("ordinalColor",t)}return"src"===e.channel?new Ut("ordinal"):new Ut("point");default:return["strokeColor","fillColor","fillGradient"].indexOf(e.channel)>=0?e.mapping?new Ut("linear"):new Ut("sequentialColor",{scheme:e.colorScheme}):new Ut("linear")}}(this);this._scales.push(t);for(let r of e)this._elem2scale[r.id]=t}getScale(e){return this._elem2scale[e.id]}getElements(e){let t=this._scales.indexOf(e);return this._elemGroups[t]}get element(){return this._elem}get channel(){return this._channel}get attribute(){return this._attribute}get dataTable(){return Lt(this._elem)}get aggregator(){return this._aggregator}hasMultipleScales(){return this._scales.length>0}get scales(){return this._scales}getRangeStart(e){let t=this.getScale(e);return Math.min(...t.range)}getRangeExtent(e){return this.getScale(e).rangeExtent}get scaleType(){return this._scaleType}set scaleType(e){this._scaleType=e}set domain(e){this._preferredDomain=e;for(let t of this._scales)t._scale.domain(e);for(let e of this._refElements)e instanceof er&&e.createTicksLabels({});this._elem.scene.onChange(X.DOMAIN,this)}set rangeExtent(e){for(let t of this._scales)t.rangeExtent=e;for(let e of this._refElements)e instanceof er&&e.createTicksLabels({});this._elem.scene.onChange(X.PROPERTY,Qe.RANGE_EXTENT,this)}set includeZero(e){this._includeZero=e;for(let e of this._refElements)e instanceof er&&e.createTicksLabels({});this._elem.scene.onChange(X.PROPERTY,Qe.INCLUDE_ZERO,this)}get includeZero(){return this._includeZero}set flipScale(e){this._flipScale=e,this._elem.scene.onChange(X.PROPERTY,Qe.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=[]}}class Xy{constructor(e,t,r,n){this._trigger=e,this._target=t.target,this._targetEval=r,this._efxFn=n,this._evalResult={}}get trigger(){return this._trigger}get target(){return this._target}get channels(){return Object.keys(this._rules)}get evalResult(){return this._evalResult}set evalResult(e){this._evalResult=e}}class qy extends ne{constructor(e,t,r,n,i){super(i),this._type=Tt.Gridlines,this._id=this._type+It(),this._attribute=t,this._channel=e,this._scale=r,this._elems=n,"strokeColor"in i||(this.styles.strokeColor="#ddd"),"opacity"in i||(this.styles.opacity=.5),"values"in i?this._values=i.values:this._scale?this._values=Jt(this._scale,this._channel,this._elems):this._values=this._elems.map((e=>e.dataScope.getAttributeValue(this._attribute))),this._lines=[]}get type(){return this._type}get id(){return this._id}getSVGPathData(){let e="";if("radialDistance"===this._channel)for(let t of this._lines)e+="M "+t.x+" "+t.y+" m -"+t.r+" 0 a "+t.r+" "+t.r+" 0 1 0 "+2*t.r+" 0 a "+t.r+" "+t.r+" 0 1 0 -"+2*t.r+" 0 ";else for(let t of this._lines)e+=["M",t.x1,t.y1].join(" ")+[" L",t.x2,t.y2].join(" ")+" ";return e}_updateBounds(){if("radialDistance"===this._channel){let e=this._lines.map((e=>new u(e.x-e.r,e.y-e.y,2*e.r,2*e.r)));this._bounds=c(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))),r=Math.min(...e),n=Math.max(...e),i=Math.min(...t),s=Math.max(...t);this._bounds=new u(r,i,n-r,s-i)}}get elements(){return this._elems}get values(){return this._values}get channel(){return this._channel}get attribute(){return this._attribute}get scale(){return this._scale}get lines(){return this._lines}set lines(e){this._lines=e}}class Ky extends z{constructor(e){super(),this.type=F.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:p.LEFT,this._vertCellAlignment="vertCellAlignment"in e&&e.vertCellAlignment?e.vertCellAlignment:p.BOTTOM,this._gap="gap"in e?e.gap:0}clone(){let e=new Ky({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}}function Zy(e,t,r,n,i){let s=i.getAttributeType(r);if(s!=we.String&&s!=we.Date&&s!=we.Integer)throw new Error("Divide only works on a string or date attribute: "+r+" is "+s);if(!function(e){if([Tt.Line,Tt.Circle,Tt.Rect,Tt.Area,Tt.Ring,Tt.Pie,Tt.Path].indexOf(e.type)<0)return!1;if(e.type===Tt.Path&&(e.closed||!e.firstVertex.dataScope))return!1;if(e.dataScope){let t=S(e);for(let e of t)if(e.dataScope.numTuples>1)return!0;return!1}return!0}(t))throw new Error("The "+t.type+" is not dividable");switch(t.type){case Tt.Line:case Tt.Path:return;case Tt.Circle:return function(e,t,r,n,i){let s,a,o,l=S(t),u=r||$.ANGULAR;if(u!=$.ANGULAR&&u!=$.RADIAL)throw new Error("Unknown orientation: "+u);u===$.ANGULAR&&l.forEach((r=>{let l=r.dataScope?r.dataScope:new fe(i),u=i.getUniqueAttributeValues(n).map((e=>l.cross(n,e)));u=u.filter((e=>!e.isEmpty()));let c=Ct(e);null==a&&(a=c.id),c._classId=a,c.dataScope=r.dataScope?r.dataScope:new fe(i);let h=r.parent;h.removeChild(r),delete e._itemMap[r.id];let d=360/u.length,f=90;for(let e=0;e<u.length;e++){let n=At({type:"arc",innerRadius:0,outerRadius:r.radius,x:r.x,y:r.y,startAngle:he(f-d*(e+1)),endAngle:he(f-d*e),strokeColor:r.strokeColor,fillColor:r.fillColor,strokeWidth:r.strokeWidth,opacity:r.opacity});o||(o=n.id),n.classId=o,n.dataScope=u[e],n._updateBounds(),n._refBounds=n.bounds.clone(),c.addChild(n),c._layout=new Ky({orientation:$.ANGULAR,direction:Q.CLOCKWISE}),c._layout.group=c,h.removeChild(r),h.addChild(c),r===t&&(s=c)}}));return{newMark:s.children[0],collection:s}}(e,t,n,r,i);case Tt.Rect:return function(e,t,r,n,i){let s,a=S(t),o=r||$.HORIZONTAL;if(o!=$.HORIZONTAL&&o!=$.VERTICAL)throw new Error("Unknown orientation: "+o);let l=i.getUniqueAttributeValues(n).map((e=>new fe(i).cross(n,e))),u={},c=0;for(let e of a){let t=l;e.dataScope&&(t=l.map((t=>t.merge(e.dataScope))),t=t.filter((e=>!e.isEmpty()))),t.length>c&&(c=t.length),u[e.id]=t}let h,d=At({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});d._classId=d.id;for(let r of a){let n=Ct(e);null==h&&(h=n.id),n._classId=h,n.dataScope=r.dataScope?r.dataScope:new fe(i);let a=r.parent;a.removeChild(r),delete e._itemMap[r.id];let l=u[r.id],c=r.bounds,f=c.left,p=c.top,_=o==$.HORIZONTAL?c.width/l.length:c.width,g=o==$.HORIZONTAL?c.height:c.height/l.length;for(let e=0;e<l.length;e++){let t=kt(d);t.dataScope=l[e],t.resize(_,g),t._updateBounds(),t._refBounds=t.bounds.clone(),n.addChild(t)}a.addChild(n),n._layout=new Ky({orientation:o,left:f,top:p}),n._layout.group=n,r==t&&(s=n)}return{newMark:s.children[0],collection:s}}(e,t,n,r,i);case Tt.Area:return function(e,t,r,n,i){let s,a=S(t),o=r||$.HORIZONTAL;if(o!=$.HORIZONTAL&&o!=$.VERTICAL)throw new Error("Unknown orientation: "+o);let l,u=i.getUniqueAttributeValues(n).map((e=>new fe(i).cross(n,e))),c={},h=0;for(let e of a){let t=u;e.dataScope&&(t=u.map((t=>t.merge(e.dataScope))),t=t.filter((e=>!e.isEmpty()))),t.length>h&&(h=t.length),c[e.id]=t}let d=Object.assign({},t.styles);d.vertices=t.vertices.map((e=>[e.x,e.y])),d.type="area",d.orientation=t.orientation,d.baseline=t.baseline;let f=At(d);if(f._classId=f.id,t.vertices)for(let e=0;e<t.vertices.length;e++)t.vertices[e].dataScope&&(f.vertices[e]._dataScope=t.vertices[e].dataScope.clone());for(let r of a){let n=Ct(e);null==l&&(l=n.id),n._classId=l,n.dataScope=r.dataScope?r.dataScope:new fe(i);let a=r.parent;a.removeChild(r),delete e._itemMap[r.id];let u=c[r.id],h=r.bounds,d=h.left,p=h.top,_=o==$.HORIZONTAL?h.width/u.length:h.width,g=o==$.HORIZONTAL?h.height:h.height/u.length;for(let e=0;e<u.length;e++){let t=kt(f);t.dataScope=u[e],console.log(t.dataScope),t.resize(_,g),t._updateBounds(),t._refBounds=t.bounds.clone(),n.addChild(t);for(let e of t.vertices)e.dataScope?e.dataScope=t.dataScope.merge(e.dataScope):e.dataScope=t.dataScope}a.addChild(n),n._layout=new Ky({orientation:o,left:d,top:p}),n._layout.group=n,r==t&&(s=n)}return{newMark:s.children[0],collection:s}}(e,t,n,r,i);case Tt.Ring:return function(e,t,r,n,i){let s,a,o,l=S(t),u=r||$.ANGULAR;if(u!=$.ANGULAR&&u!=$.RADIAL)throw new Error("Unknown orientation: "+u);u===$.ANGULAR&&l.forEach((r=>{let l=r.dataScope?r.dataScope:new fe(i),u=i.getUniqueAttributeValues(n).map((e=>l.cross(n,e)));u=u.filter((e=>!e.isEmpty()));let c=Ct(e);null==a&&(a=c.id),c._classId=a,c.dataScope=r.dataScope?r.dataScope:new fe(i);let h=r.parent;h.removeChild(r),delete e._itemMap[r.id];let d=360/u.length,f=90;for(let e=0;e<u.length;e++){let n=At({type:"arc",innerRadius:r.innerRadius,outerRadius:r.outerRadius,x:r.x,y:r.y,startAngle:he(f-d*(e+1)),endAngle:he(f-d*e),strokeColor:r.strokeColor,fillColor:r.fillColor,strokeWidth:r.strokeWidth,opacity:r.opacity});o||(o=n.id),n.classId=o,n.dataScope=u[e],n._updateBounds(),n._refBounds=n.bounds.clone(),c.addChild(n),c._layout=new Ky({orientation:$.ANGULAR,direction:Q.CLOCKWISE}),c._layout.group=c,h.removeChild(r),h.addChild(c),r===t&&(s=c)}}));return{newMark:s.children[0],collection:s}}(e,t,n,r,i);case Tt.Pie:case Tt.Arc:return function(e,t,r,n,i){let s,a,o,l=S(t),u=r||$.ANGULAR;if(u!=$.ANGULAR&&u!=$.RADIAL)throw new Error("Unknown orientation: "+u);u===$.ANGULAR||l.forEach((r=>{let l=r.dataScope?r.dataScope:new fe(i),u=i.getUniqueAttributeValues(n).map((e=>l.cross(n,e)));u=u.filter((e=>!e.isEmpty()));let c=Ct(e);null==a&&(a=c.id),c._classId=a,c.dataScope=r.dataScope?r.dataScope:new fe(i);let h=r.parent;h.removeChild(r),delete e._itemMap[r.id];for(let e=0;e<u.length;e++){let n=At({type:"arc",innerRadius:r.innerRadius+e*(r.outerRadius-r.innerRadius)/u.length,outerRadius:r.innerRadius+(e+1)*(r.outerRadius-r.innerRadius)/u.length,x:r.x,y:r.y,startAngle:r.startAngle,endAngle:r.endAngle,strokeColor:r.strokeColor,fillColor:r.fillColor,strokeWidth:r.strokeWidth,opacity:r.opacity});o||(o=n.id),n.classId=o,n.dataScope=u[e],n._updateBounds(),n._refBounds=n.bounds.clone(),c.addChild(n),c._layout=new Ky({orientation:$.RADIAL}),c._layout.group=c,h.removeChild(r),h.addChild(c),r===t&&(s=c)}}));return{newMark:s.children[0],collection:s}}(e,t,n,r,i)}}function $y(e,t,r,n){let i=n.getAttributeType(r);if(i!=we.String&&i!=we.Date&&i!=we.Integer)throw new Error("Repopulate only works on a string or date attribute: "+r+" is "+i);let s=S(t);for(let e of s){let t=n.getAttributeSummary(r).unique.map((t=>e.dataScope?e.dataScope.cross(r,t):new fe(n).cross(r,t)));t=t.filter((e=>!e.isEmpty()));let i=e.children.length-t.length,s=t.length-e.children.length;for(let t=0;t<i;t++)e.removeChildAt(e.children.length-1);let a=e._children.length;for(let t=0;t<s;t++){let r=kt(e._children[t%a]);e.addChild(r)}e.children.forEach(((e,r)=>e.dataScope=t[r]))}}class Jy{constructor(e,t){this._elem=e,this._base=t,this._id=Qy(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 r={};r.elemAnchor="elementAnchor"in t?t.elementAnchor:"x"==e||"angle"==e?p.CENTER:p.MIDDLE,r.baseAnchor="baseAnchor"in t?t.baseAnchor:"x"==e||"angle"==e?p.CENTER:p.MIDDLE,r.offset="offset"in t?t.offset:0,"attribute"in t&&(this._attribute=t.attribute),this._channels[e]=r}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:Vt}}function Qy(e,t){return(e.classId?e.classId:e.id)+":"+(t.classId?t.classId:t.id)}function em(e,t,r,n){e.dataScope&&e.dataScope.dataTable.hasAttribute(t)?function(e,t,r,n){if(!e.dataScope.dataTable.hasAttribute(t))return void console.warn("Cannot order collection children by an non-existent attribute",t);let i;if(t===Vt)i=(e,r)=>parseInt(e.dataScope.getAttributeValue(t).substring(1))-parseInt(r.dataScope.getAttributeValue(t).substring(1));else{switch(e.children[0].dataScope.getAttributeType(t)){case we.Date:break;case we.Number:case we.Integer:i=(e,r)=>e.dataScope.aggregateNumericalAttribute(t)-r.dataScope.aggregateNumericalAttribute(t);break;case we.String:i=n?(e,r)=>n.indexOf(e.dataScope.getAttributeValue(t))-n.indexOf(r.dataScope.getAttributeValue(t)):(e,r)=>e.dataScope.getAttributeValue(t)<r.dataScope.getAttributeValue(t)?-1:1}}e.children.sort(i),r&&e.children.reverse()}(e,t,r,n):function(e,t,r){let n;switch(t){case"x":case"y":case"width":case"height":n=(e,r)=>e.bounds[t]-r.bounds[t];break;default:n=(e,r)=>e[t]-r[t]}e._children.sort(n),r&&e.children.reverse()}(e,t,r),e._sortBy={property:t,descending:r,vals:n}}function tm(e,t,r,n){e.vertices[0].dataScope&&e.vertices[0].dataScope.dataTable.hasAttribute(t)?function(e,t,r,n){let i;if(t===Vt)i=(e,r)=>parseInt(e.dataScope.getAttributeValue(t).substring(1))-parseInt(r.dataScope.getAttributeValue(t).substring(1));else{switch(e.vertices[0].dataScope.getAttributeType(t)){case we.Date:break;case we.Number:case we.Integer:i=(e,r)=>e.dataScope.aggregateNumericalAttribute(t)-r.dataScope.aggregateNumericalAttribute(t);break;case we.String:i=n?(e,r)=>n.indexOf(e.dataScope.getAttributeValue(t))-n.indexOf(r.dataScope.getAttributeValue(t)):(e,r)=>e.dataScope.getAttributeValue(t)<r.dataScope.getAttributeValue(t)?-1:1}}e.vertices.sort(i),r&&e.vertices.reverse()}(e,t,r,n):function(e,t,r){let n=(e,r)=>e[t]-r[t];e.vertices.sort(n),r&&e.vertices.reverse()}(e,t,r),e._sortBy={property:t,descending:r,vals:n}}class rm extends z{constructor(e){super(),this.type=F.GRID,this._numCols=e.numCols,this._numRows=e.numRows,this._start="start"in e?e.start:Z.TopLeft,this._direction="direction"in e?e.direction:K.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&&U("h",e.horzCellAlignment)?e.horzCellAlignment:p.LEFT,this._cellVertAlignment="vertCellAlignment"in e&&U("v",e.vertCellAlignment)?e.vertCellAlignment:p.BOTTOM,this._numCols||this._numRows||(this._numRows=1),this._left=void 0,this._top=void 0,this._cellBounds=void 0,this._grid=void 0}get cellBounds(){return this._cellBounds}get numCols(){return this._numCols?this._numCols:this._numRows?Math.ceil(this.group.children.length/this._numRows):0}get numRows(){return this._numRows?this._numRows:this._numCols?Math.ceil(this.group.children.length/this._numCols):0}clone(){let e=new rm({numCols:this._numCols,numRows:this._numRows,start:this._start,direction:this._direction,colGap:this._colGap,rowGap:this._rowGap,horzCellAlignment:this._cellHorzAlignment,vertCellAlignment:this._cellVertAlignment});return e._left=this._left,e._top=this._top,this._cellBounds&&(e._cellBounds=this._cellBounds.map((e=>e.clone()))),e}getElementsByRow(e,t){let r=[],n=this.group.children;for(let t=0;t<this.numRows;t++){let i=this._grid[t].filter((e=>null!=e)).map((e=>n[e]));if(e){let e=[];for(let t of i)e=e.concat(G(t));r.push(e)}else r.push(i)}return t&&(r=this._filterElementsByExample(r,t)),r}getElementsByCol(e,t){let r=[],n=this.group.children,i=this._grid;for(let t=0;t<this.numCols;t++){let s=i.map((e=>e[t])).filter((e=>null!=e)).map((e=>n[e]));if(e){let e=[];for(let t of s)e=e.concat(G(t));r.push(e)}else r.push(s)}return t&&(r=this._filterElementsByExample(r,t)),r}getElementsByCell(e,t){let r=[],n=this.group.children;for(let t=0;t<n.length;t++)if(e){let e=G(n[t]);r.push(e)}else r.push(n[t]);return t&&(r=this._filterElementsByExample(r,t)),r}_filterElementsByExample(e,t){let r;return"vertex"===t.type?(r=e.map((e=>e.filter((e=>e.classId===t.parent.classId)))),r=r.map((e=>T(t,e)))):"segment"===t.type?(r=e.map((e=>e.filter((e=>e.classId===t.parent.classId)))),r=r.map((e=>O(t,e)))):r=e.map((e=>e.filter((e=>e.classId===t.classId)))),r}getIndex(e){let t=e;for(;t&&t.parent!==this.group;)t=t.parent;return this.group.children.indexOf(t)}getRowCol(e){let t,r;switch(this._direction){case K.RowFirst:t=Math.floor(e/this.numCols),r=e%this.numCols;break;case K.ColumnFirst:t=e%this.numRows,r=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")&&(r=this.numCols-1-r),{row:t,col:r}}}class nm extends pt{constructor(e,t){super(),this._type=Tt.Axis,this._id=this._type+It(),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:$.VERTICAL,this._numberFormat=t.numberFormat?t.numberFormat:""}get attribute(){return this._enc.attribute}get channel(){return this._enc.channel}get attributeType(){return Lt(this._enc.element).getFieldType(this.attribute)}get orientation(){return this._orientation}get textColor(){return this._textColor}}class im extends nm{constructor(e,t){super(e,t),"numCols"in t||"numRows"in t?(this._numCols=t.numCols,this._numRows=t.numRows):this._orientation===$.VERTICAL?this._numCols=1:this._numRows=1,this._initialize()}_initialize(){let e=this._enc.element.scene,t=this._enc.attribute,r=this._enc.scales[0],n=new Nt(r.domain.map((e=>({category:e,value:r.map(e)})))),i=n.getUniqueAttributeValues("category").sort(((e,t)=>t.length-e.length))[0],s=this._enc.element,a=s instanceof ne&&s.closed?s.strokeWidth:0;if(this._orientation===$.VERTICAL){let r=0;this._showTitle&&(this.addChild(new xt({fillColor:this._textColor,fontSize:this._fontSize,text:t,x:this._x,y:this._y,anchor:["left","top"]})),r=parseFloat(this._fontSize)+5);let o=e.mark("rect",{top:this._y+2+r,left:this._x,width:10,height:10,strokeWidth:a,strokeColor:s.strokeColor,opacity:s.opacity}),l=e.mark("text",{text:i,fillColor:this._textColor,fontSize:this._fontSize,x:this._x+20,y:this._y+r+12+a,anchor:["left","bottom"]}),u=e.glyph(o,l),c=e.repeat(u,n);e.encode(l,{channel:"text",attribute:"category",forLegend:!0}),e.encode(o,{channel:"fillColor",attribute:"category",shareScale:this._enc,forLegend:!0}),c.layout=new rm({numCols:this._numCols,numRows:this._numRows}),this.addChild(c)}else{let t=e.mark("rect",{top:this._y,left:this._x,width:10,height:10,strokeWidth:a,strokeColor:s.strokeColor,opacity:s.opacity}),r=e.mark("text",{text:i,fillColor:this._textColor,fontSize:this._fontSize,x:this._x+15,y:this._y,anchor:["left","top"]}),o=e.glyph(t,r),l=e.repeat(o,n);e.encode(r,{channel:"text",attribute:"category",forLegend:!0}),e.encode(t,{channel:"fillColor",attribute:"category",shareScale:this._enc,forLegend:!0}),l.layout=new rm({numCols:this._numCols,numRows:this._numRows,colGap:15}),this.addChild(l)}}}class sm extends nm{constructor(e,t){super(e,t),this._initialize()}_initialize(){let t,r,n,i=this._enc.element.scene,s=this._enc.attribute;if(this._orientation==$.VERTICAL?(t=15,r=300):(t=300,r=15),this._showTitle){let e=i.mark("text",{fillColor:this._textColor,text:s,x:this._x+t/2,y:this._y,anchor:["center","middle"]});this.addChild(e),n=20}else n=0;let a,o=i.mark("rect",{top:this._y+n,left:this._x,width:t,height:r,strokeWidth:0,opacity:this._enc.element.opacity}),l=Object.values(this._enc.attrValues),u=[Math.min(...l),Math.max(...l)],c=this._enc.mapping,h=[],d=[],f=e.format(this._numberFormat);if(c){let e=Object.keys(c).map((e=>parseFloat(e))).sort(((e,t)=>e-t));this._orientation==$.VERTICAL?(a=new b({x1:0,y1:100,x2:0,y2:0}),e.forEach((e=>{let s=(e-u[0])/(u[1]-u[0]);a.addStop(100*s,c[e],1);let o=i.mark("line",{x1:this._x+t,x2:this._x+t+5,y1:this._y+r-s*r+n,y2:this._y+r-s*r+n,strokeColor:this._strokeColor});d.push(o);let l=i.mark("text",{fillColor:this._textColor,text:this._numberFormat?f(e):e.toFixed(0),x:this._x+t+5+5,y:this._y+r-s*r+n,anchor:["left","middle"]});h.push(l)}))):(a=new b({x1:0,y1:0,x2:100,y2:0}),e.forEach((e=>{let s=(e-u[0])/(u[1]-u[0]);a.addStop(100*s,c[e],1);let o=i.mark("line",{x1:this._x+s*t,x2:this._x+s*t,y1:this._y+20-5+n,y2:this._y+r+5+n,strokeColor:this._strokeColor});d.push(o);let l=i.mark("text",{fillColor:this._textColor,text:this._numberFormat?f(e):e.toFixed(0),x:this._x+s*t,y:this._y+r+5+n,anchor:["center","top"]});h.push(l)})))}else{let e=this._enc.scales[0].domain,o=Lt(this._enc.element),l=o.getAttributeType(s),u=[],c=l===we.Date?o.getUniqueFieldValues(s):[...new Set(Object.values(this._enc.attrValues))];if(c.length<=10)u=c,u.sort(((e,t)=>e-t));else if(l===we.Date){c.sort(((e,t)=>e-t));for(let e=0;e<c.length;e+=Math.ceil(c.length/10))u.push(c[e])}else{let t=(e[1]-e[0])/9;for(let r=0;r<10;r++)u.push(e[0]+r*t)}let p=0,_=(u[u.length-1]-u[0])/u.length;for(;_<1;)_*=10,p++;u=u.map((e=>e.toFixed(p))),this._orientation==$.VERTICAL?(a=new b({x1:0,y1:100,x2:0,y2:0}),u.forEach((u=>{let c=(u-e[0])/(e[1]-e[0]);a.addStop(100*c,this._enc.scales[0].map(u),1);let p=i.mark("line",{x1:this._x+t,x2:this._x+t+5,y1:this._y+r-c*r+n,y2:this._y+r-c*r+n,strokeColor:this._strokeColor});d.push(p);let _=i.mark("text",{fillColor:this._textColor,text:l===we.Date?o.getRawValue(s,u):this._numberFormat?f(u):u,x:this._x+t+5+5,y:this._y+r-c*r+n,anchor:["left","middle"]});h.push(_)}))):(a=new b({x1:0,y1:0,x2:100,y2:0}),u.forEach((u=>{let c=(u-e[0])/(e[1]-e[0]);a.addStop(100*c,this._enc.scale.map(u),1);let f=i.mark("line",{x1:this._x+c*t,x2:this._x+c*t,y1:this._y+r+n,y2:this._y+r+5+n,strokeColor:this._strokeColor});d.push(f);let p=i.mark("text",{fillColor:this._textColor,text:l===we.Date?o.getRawValue(s,u):u,x:this._x+c*t,y:this._y+r+5+n,anchor:["center","top"]});h.push(p)})))}o.styles.fillColor=a,this.addChild(o);for(let e of h)this.addChild(e);for(let e of d)this.addChild(e)}}class am extends pt{constructor(e){super(),this._type=Tt.Composite,this._id=e&&e.id?e.id:this._type+It()}addChild(e){let t=e.parent;super.addChild(e);let r=P(e)._depGraph;t&&st(t,e,r),at(this,e,r)}}class om{constructor(e,t,r){this._elems=e,this._channel=t,this._anchor=r}get elements(){return this._elems}get channel(){return this._channel}get anchor(){return this._anchor}}class lm extends z{constructor(e){super(),this.type=F.STRATA,this._direction=e.direction,this._gap="gap"in e?e.gap:0}clone(){return new lm({direction:this._direction,gap:this._gap})}}function um(e,t,r,n,i,s){switch(t.type){case Tt.Circle:case Tt.Ring:return function(e,t,r,n,i,s){let a,o=r||ee.OUTWARD,l=i||50;if(o!==ee.INWARD&&o!==ee.OUTWARD)throw"Unknown direction to stratify";let u,c=S(t,e),h=Array.isArray(s)?s:[s];if(n){let r=Ct(e);r.dataScope=void 0,null==u&&(u=r.id),r._classId=u;let n=c.map((e=>h[0].getNode(e.dataScope.getAttributeValue(xe))));cm(c,n,h[0],r,t.classId?t.classId:t.id,400,350,o,l),a=r}else c.forEach(((r,n)=>{let i=Ct(e);i.dataScope=void 0,null==u&&(u=i.id),i._classId=u;let s=r.parent;hm(r,t.id,o,l,h[n],h[n].getRoot(),i,e,!0),i._layout=new lm({direction:o}),i._layout.group=i,s.addChild(i),r===t&&(a=i)}));return a}(e,t,r,n,i,s);case Tt.Rect:return function(e,t,r,n,i,s){let a,o,l=r||J.Top2Bottom,u=i||50;if(!Object.values(J).includes(l))throw"Unknown direction to stratify";return S(t).forEach((r=>{let n=Ct(e);n.dataScope=void 0,null==o&&(o=n.id),n._classId=o;let i=r.parent;dm(r,t.id,l,u,s,s.getRoot(),n,e,!0),n._layout=new lm({direction:l}),n._layout.group=n,i.addChild(n),r===t&&(a=n)})),a}(e,t,r,0,i,s)}}function cm(e,t,r,n,i,s,a,o,l){let u=t.map((e=>r.getParent(e))).filter(((e,t,r)=>r.findIndex((t=>t[xe]===e[xe]))===t));if(u=u.filter((e=>e!==r.getRoot())),0===u.length)return;let c=[];for(let t of u){let u,h,d,f=e.filter((e=>r.getParent(r.getNode(e.dataScope.getAttributeValue(xe)))===t));if(f[0].type===Tt.Circle){let e=f.map((e=>A(s,a,e.bounds.x,e.bounds.y)-e.radius)),t=f.map((e=>A(s,a,e.bounds.x,e.bounds.y)+e.radius));d=o===ee.OUTWARD?Math.max(...t):Math.min(...e)-l;let r=f.map((e=>de(e.bounds.x,e.bounds.y,s,a))),n=f.map((e=>de(s+A(s,a,e.bounds.x,e.bounds.y),a-e.radius,s,a))),i=r.map(((e,t)=>e-n[t])),c=r.map(((e,t)=>e+n[t])),p=i.concat(c);u=Math.min(...p),h=Math.max(...p)}else f[0].type===Tt.Arc&&(u=360,h=-360,f.forEach((e=>{let t=e.startAngle,r=e.endAngle;r<t&&(r+=360),u=Math.min(u,t),h=Math.max(h,r)})),u=he(u),h=he(h),d=o===ee.OUTWARD?Math.max(...f.map((e=>e.outerRadius))):Math.min(...f.map((e=>e.innerRadius)))-l);let p=At({type:"arc",innerRadius:d,outerRadius:d+l,x:s,y:a,startAngle:he(u),endAngle:he(h),strokeColor:e[0].strokeColor,fillColor:e[0].fillColor,strokeWidth:e[0].strokeWidth,opacity:e[0].opacity});p._updateBounds(),p.dataScope=r.getNodeDataScope(t),p._classId=i,n.addChild(p),c.push(p)}cm(c,u,r,n,i,s,a,o,l)}function hm(e,t,r,n,i,s,a,o,l){l&&(e.dataScope=i.getNodeDataScope(s),e._classId=t);let u=i.getChildren(s);if(0===u.length)return;let c=e.type===Tt.Circle||e.type===Tt.Ring?60:e.startAngle,h=(e.type===Tt.Circle||e.type===Tt.Ring?360:e.angle)/u.length;for(let s=0;s<u.length;s++){let o,l;l=r===ee.OUTWARD?e.type===Tt.Circle?e.radius:e.outerRadius:e.type===Tt.Circle?e.radius-n:e.innerRadius-n,o=At(360===h?{type:"ring",innerRadius:l,outerRadius:l+n,x:e.x,y:e.y,strokeColor:e.strokeColor,fillColor:e.fillColor,strokeWidth:e.strokeWidth,opacity:e.opacity}:{type:"arc",innerRadius:l,outerRadius:l+n,x:e.x,y:e.y,startAngle:he(c+h*s),endAngle:he(c+h*(s+1)),strokeColor:e.strokeColor,fillColor:e.fillColor,strokeWidth:e.strokeWidth,opacity:e.opacity}),o._updateBounds(),o.dataScope=i.getNodeDataScope(u[s]),o._classId=t+"_strata",a.addChild(o),hm(o,t,r,n,i,u[s],a)}}function dm(e,t,r,n,i,s,a,o,l){l&&(e.dataScope=i.getNodeDataScope(s),e._classId=t,a.addChild(e));let u,c,h,d=i.getChildren(s);if(0!==d.length){switch(r){case J.Top2Bottom:case J.Bottom2Top:case J.Left2Right:case J.Right2Left:}u=e.left,c=e.bottom,h=e.width/d.length;for(let s=0;s<d.length;s++){let o=kt(e);je(o,u-o.left,c-o.top),o.resize(h,n),o._updateBounds(),u+=h,o.dataScope=i.getNodeDataScope(d[s]),o._classId=t,a.addChild(o),dm(o,t,r,n,i,d[s],a)}}}class fm extends Ke{constructor(e,t,r,n){super(e,t),this._elem=r,this._cumulative=n,this._selector="class",this._elements=[]}get element(){return this._elem}get selector(){return this._selector}isCumulative(){return this._cumulative}get elements(){return this._elements}set elements(e){this._elements=e}}class pm extends Ke{constructor(e,t,r){super(e,t),this._key=r}get key(){return this._key}}class _m extends Ke{constructor(e,t,r){super(e,t),this._listener=r,this._elements=[]}get mouseEvent(){return this._mouseEvent}set mouseEvent(e){this._mouseEvent=e}get listener(){return this._listener}get elements(){return this._elements}set elements(e){this._elements=e}}class gm extends Ke{constructor(e,t,r){super(e,t),this._ctrlId=r}get id(){return this._ctrlId}}class ym extends pt{constructor(e){super(),this._itemMap={},this._type=Tt.Scene,this._id=e&&e.id?e.id:this._type+It(),e&&e.fillColor&&(this.fillColor=e.fillColor),this._encodings={},this._relations=[],this._triggers={},this._depGraph=new Uy}get depGraph(){return this._depGraph}get interactionTriggers(){return this._triggers}mark(e,t){if(Object.values(St).indexOf(e)<0)throw new Error("Mascot does not allow directly creating a "+e);let r=void 0===t?{}:t;r.type=e;let n=At(r);return null!==n&&(n._classId=n.id,this.addChild(n),this._itemMap[n.id]=n,et(n,this._depGraph),at(this,n,this._depGraph)),n}glyph(...e){let t=[];for(let r of e)t.push([r.parent,r]);let r=Rt(e);if(null!==r){r._classId=r.id,this.addChild(r),this._itemMap[r.id]=r;for(let e of t)st(e[0],e[1],this._depGraph);!function(e,t){let r=t.getVariable(X.BOUNDS,e),n=t.getIncomingDataflowOperator(W.EVAL_BBOX,r);for(let r of e.children)t.connect(t.getVariable(X.BOUNDS,r),n);t.connect(n,r),n.run()}(r,this._depGraph),at(this,r,this._depGraph)}return r}composite(){let e=new am;return null!==e&&(e._classId=e.id,this.addChild(e),this._itemMap[e.id]=e,function(e,t){let r=t.getVariable(X.BOUNDS,e),n=t.getVariable(X.CHANNEL,"x",e),i=t.getVariable(X.CHANNEL,"y",e),s=t.getVariable(X.CHANNEL,"width",e),a=t.getVariable(X.CHANNEL,"height",e),o=t.createOneWayDependency(W.EVAL_BBOX);t.connect(n,o),t.connect(i,o),t.connect(s,o),t.connect(a,o),t.connect(o,r),o.run()}(e,this._depGraph),at(this,e,this._depGraph)),e}attach(e,t){if(e.type==Tt.Glyph)for(let t of e.children)t._refBounds||(t._refBounds=t.bounds.clone());e.dataScope=new fe(t)}repeat(e,t,r){let n=r||{};if(n.attribute=n.attribute||Vt,console.log("------ repeat by",n.attribute," ----"),function(e,t,r){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 ge||t instanceof me){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 Nt&&Ee(r.attribute,t);if(r.layout&&!(r.layout instanceof z))throw new Error("Invalid layout: "+r.layout)}(e,t,n),t instanceof ge||t instanceof me){let r=e[0].parent,n=e[1].parent,[i,s]=function(e,t,r,n){let i=n.nodeTable.getAttributeSummary(xe).unique.map((e=>t.dataScope?t.dataScope.cross(xe,e):new fe(n.nodeTable).cross(xe,e))),s=Ct(e),a=Ct(e),o={};a.dataScope=t.dataScope?t.dataScope.clone():new fe(n.nodeTable),a.addChild(t);for(let e=1;e<i.length;e++){let e=kt(t);a.addChild(e)}a.children.forEach(((e,t)=>{e.dataScope=i[t],e.links=[],o[e.dataScope.getAttributeValue(xe)]=e}));let l=n.linkTable.getAttributeSummary(Vt).unique.map((e=>r.dataScope?r.dataScope.cross(Vt,e):new fe(n.linkTable).cross(Vt,e)));s.dataScope=r.dataScope?r.dataScope.clone():new fe(n.linkTable),s.addChild(r);for(let e=1;e<l.length;e++){let e=kt(r);s.addChild(e)}s.children.forEach(((e,t)=>e.dataScope=l[t]));let u=n instanceof ge?"parent":"source",c=n instanceof ge?"child":"target";for(let e of s.children){let t=e.dataScope.getAttributeValue(u),r=e.dataScope.getAttributeValue(c),n=o[t],i=o[r];e.source=n,e.target=i,n.links.push(e),i.links.push(e)}return[a,s]}(this,e[0],e[1],t);return st(r,e[0],this._depGraph),st(n,e[1],this._depGraph),it(i,this._depGraph),it(s,this._depGraph),at(i,e[0],this._depGraph),at(i.parent,i,this._depGraph),at(s,e[1],this._depGraph),at(s.parent,s,this._depGraph),[i,s]}if(t instanceof Nt){let r=e.parent,i=Wy(this,e,n.attribute,t);return st(r,e,this._depGraph),it(i,this._depGraph),at(i,e,this._depGraph),at(i.parent,i,this._depGraph),n.layout&&(i.layout=n.layout),i}}divide(e,t,r){let n=r||{};if(n.attribute=n.attribute||Vt,console.log("------ divide by",n.attribute," ----"),function(e,t,r){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");if(t instanceof Nt&&Ee(r.attribute,t),r.layout&&!(r.layout instanceof z))throw new Error("Invalid layout: "+r.layout)}(e,t,n),t instanceof ge||t instanceof me)throw"Not implemented";if(t instanceof Nt){let{newMark:r,collection:i}=Zy(this,e,n.attribute,n.orientation,t);return tt(e,this._depGraph),et(r,this._depGraph),it(i,this._depGraph),at(i,r,this._depGraph),i.parent.type!==Tt.Scene&&at(i.parent,i,this._depGraph),this.onChange(X.CHANNEL,"width",r),{newMark:r,collection:i}}}densify(e,t,r){let n=r||{};if(n.attribute=n.attribute||Vt,console.log("------ densify by",n.attribute," ----"),function(e,t,r){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 Nt&&Ee(r.attribute,t)}(e,t,n),t instanceof ge||t instanceof me)throw"Not implemented";if(t instanceof Nt){let r=ke(0,e,n.attribute,n.orientation,t);return tt(e,this._depGraph),et(r,this._depGraph),r.parent.type!==Tt.Scene&&at(r.parent,r,this._depGraph),this.onChange(X.CHANNEL,"width",r),r}}stratify(e,t,r){if(!(t instanceof ge||Array.isArray(t)&&t.every((e=>e instanceof ge))))throw"Cannot stratify on a non-tree dataset";if(![Tt.Circle,Tt.Rect,Tt.Ring].includes(e.type))throw"Cannot stratify elements that are not rects, circles, or rings";let n=r||{},i=n.direction,s=n.size,a=e.parent,o=um(this,e,i,n.startFromLeaf,s,t);return st(a,e,this._depGraph),it(o,this._depGraph),o.children.length>0&&at(o,o.firstChild,this._depGraph),at(o.parent,o,this._depGraph),o}repopulate(e,t,r){e.dataScope=void 0;let n=e;for(let e in r){$y(0,n,r[e],t);let i=Ne(n.children[0],!0);for(let e of i){Ie(e,this),rt(e,this._depGraph);for(let t of e.refElements)Qt(t,this),nt(t,this._depGraph);e.clearRefElements()}let s=S(n);for(let e of s)if(e.layout){for(let t of e.layout.refElements)Qt(t,this),nt(t,this._depGraph);e.layout.clearRefElements()}n=n.children[0]}e.dataScope=new fe(t),this.onChange(X.CHANNEL,"width",e.children[0])}classify(e,t){let r=t||{};console.log("------ classify by",r.attribute," ----"),function(e,t,r,n){let i=S(t);for(let t of i){let i,s={},a=t.children;for(let e of a){let t=e.dataScope.getAttributeValue(r);t in s||(s[t]=[]),s[t].push(e)}let o=Lt(a[0]);for(let a in s){let l=Ct(e);t.addChild(l),void 0===i&&(i=l.id),l._classId=i,l.dataScope=t.dataScope?t.dataScope.cross(r,a):new fe(o).cross(r,a);for(let e of s[a])l.addChild(e);n&&(l._layout=n.clone(),l._layout.group=l)}}}(this,e,r.attribute,r.layout),st(e,e.firstChild.firstChild,this._depGraph),it(e.firstChild,this._depGraph),at(e.firstChild,e.firstChild.firstChild,this._depGraph),at(e,e.firstChild,this._depGraph),this.onChange(X.CHANNEL,"width",e.firstChild.firstChild)}affix(e,t,r,n){e.dataScope.dataTable!==e.dataScope.dataTable&&console.warn("Affix: elements and base elements are not created from the same table");let i=Qy(e,t),s=this._relations.find((e=>e.id===i));s||(s=new Jy(e,t),this._relations.push(s)),s.addChannel(r,n||{}),function(e,t){let r=t.getVariable(X.AFFIXATION,e),n=t.getOutgoingDataflowOperator(W.AFFIXER,r);t.connect(r,n);for(let r of e.channels){let i=t.getVariable(X.CHANNEL,r,e.element),s=t.getVariable(X.CHANNEL,r,e.base);t.connect(s,n),t.connect(n,i)}n.run()}(s,this._depGraph)}align(e,t,r){let n=new om(e,t,r);!function(e,t){let r=t.createMultiWayDependency(W.ALIGNER),n=t.getVariable(X.ALIGNMENT,e);t.connect(n,r);for(let n of e.elements){let i=t.getVariable(X.CHANNEL,e.channel,n);t.connect(i,r)}r.run()}(n,this._depGraph),this._relations.push(n)}encode(e,t){if("rowId"===t.attribute&&(t.attribute=Vt),function(e,t){if(!e||!("channel"in t)||!("attribute"in t))throw new Error("Incomplete information to do encoding. You must specify an item, a categorical data attribute and a data table");let r=Lt(e);if(r.tree){let e=t.attribute;if(e.indexOf(".")>0&&!r.tree.nodeTable.hasAttribute(e.split(".")[1]))throw new Error("Data attribute does not exist in the data table")}else if(!r||!r.hasAttribute(t.attribute))throw new Error("Data attribute does not exist in the data table");if(!Object.values(Oe).includes(t.channel))throw new Error("Channel Not Supported")}(e,t),t.shareScale){let e=t.shareScale;if(e.channel!=t.channel&&e.channel.indexOf("Color")<0&&t.channel.indexOf("Color")<0)throw new Error("Cannot share scales between "+e.channel+" and "+t.channel+" encodings");t.scheme=t.shareScale.colorScheme}!function(e){let t;"vertex"===e.type&&e.parent.type===Tt.Area?t=e.parent:e.type===Tt.Area&&(t=e),t&&!t._refBounds&&S(t).forEach((e=>e._refBounds=e.bounds.clone()))}(e);let r=t.aggregator?t.aggregator:"sum";console.log("------ encode",t.channel,t.attribute," --");let n=Ve(e,t.channel);if(n&&t.attribute!==n.attribute){Ie(n,this),rt(n,this._depGraph);for(let e of n.refElements)Qt(e,this),nt(e,this._depGraph);n.clearRefElements()}let i=new Yy(e,t.channel,t.attribute,r,t);return this._addAttributeEncoding(i),function(e,t,r){let n=e.attribute,i=e.channel,s=e.element,a=t.createOneWayDependency(W.ENCODER);if(["width","height"].includes(e.channel)&&s.type===Tt.Area){let e=t.getVariable(X.PROPERTY,Qe.BASE_LINE,s);t.connect(e,a)}if(r){let n=t.getVariable(X.DOMAIN,r),o=t.getVariable(X.SCALE,r),l=t.getVariable(X.CHANNEL,i,s);t.connect(o,a),t.connect(a,l),n.addLinkedEncoding(e),o.addLinkedEncoding(e),n.incomingDataflow.run()}else{let r=t.getVariable(X.ATTRIBUTE,n,Lt(s)),o=t.getVariable(X.PROPERTY,Qe.INCLUDE_ZERO,e),l=t.getVariable(X.DOMAIN,e),u=t.getVariable(X.DATASCOPE,s),c=t.createOneWayDependency(W.DOMAIN_BUILDER);t.connect(r,c),t.connect(o,c),t.connect(u,c),t.connect(c,l),c.run();let h=t.getVariable(X.PROPERTY,Qe.RANGE_START,e),d=t.getVariable(X.PROPERTY,Qe.RANGE_EXTENT,e),f=t.getVariable(X.PROPERTY,Qe.FLIP_SCALE,e),p=t.getVariable(X.SCALE,e),_=t.createOneWayDependency(W.SCALE_BUILDER);t.connect(h,_),t.connect(d,_),t.connect(f,_),t.connect(l,_),t.connect(_,p),_.run();let g=t.getVariable(X.CHANNEL,i,s);t.connect(p,a),t.connect(a,g),a.run()}}(i,this._depGraph,t.shareScale),t.shareScale?this.onChange(X.DOMAIN,i):this.onChange(X.CHANNEL,t.channel,e),i}connect(e,t){let r={};e.forEach((e=>r[e.dataScope.getAttributeValue(xe)]=e));let n=t[0].dataScope.dataTable,i=n.tree?"parent":"source",s=n.tree?"child":"target";for(let t of e)t.links=[];for(let e of t){let t=e.dataScope.getAttributeValue(i),n=e.dataScope.getAttributeValue(s),a=r[t],o=r[n];e.source=a,e.target=o,a.links.push(e),o.links.push(e)}ct(e.find((e=>e.links.length>0)),this._depGraph),this.onChange(X.CHANNEL,"x",e[0])}_addAttributeEncoding(e){let t=Pe(e.element);t in this._encodings||(this._encodings[t]={}),this._encodings[t][e.channel]=e}activate(e,t,r,n,i){!function(e,t,r,n,i){if(!("event"in e)||!("type"in e))throw"Event and trigger must be specified";if(![Ze.WIDGET,Ze.KEYBOARD].includes(e.type)){if(!("target"in t)||!("targetChannels"in t))throw"Target must be specified";if("function"!=typeof r)throw"Target evaluator must be a function"}if(e.type===Ze.ELEMENT&&!("element"in e))throw"Element must be specified for trigger";if(Array.isArray(n)){if(!n.every((e=>"function"==typeof e)))throw"Effect setter must be a function";if(i&&!Array.isArray(i))throw"An array of effect setters must be accompanied by an array of animation effects";if(i&&Array.isArray(i)&&i.length!==n.length)throw"the length of effect setters is not equal to the length of animation effects"}else if("function"!=typeof n)throw"Effect setter must be a function"}(e,t,r,n,i);let s=e.event,a=function(e){switch(e.type){case Ze.ELEMENT:return[e.type,e.element.classId?e.element.classId:e.element.id].join("-");case Ze.ATTRIBUTE:return[e.type].join("-");case Ze.WIDGET:return[e.type,e.event,e.listener?e.listener.id:"scene",e.id?e.id:""].join("-");case Ze.MOUSE:return[e.type,e.event,e.listener?e.listener.id:"scene"].join("-");case Ze.KEYBOARD:return[e.type,e.event,e.key].join("-");default:return[e.type,e.event].join("-")}}(e);if(s=0===s.indexOf("brush")?"brush":s,s in this._triggers||(this._triggers[s]={}),a in this._triggers[s]||(this._triggers[s][a]=function(e){switch(e.type){case Ze.ELEMENT:return new fm(e.type,e.event,e.element,"cumulative"in e&&e.cumulative);case Ze.MOUSE:return new _m(e.type,e.event,e.listener);case Ze.KEYBOARD:return new pm(e.type,e.event,e.key);case Ze.WIDGET:return new gm(e.type,e.event,e.id)}}(e)),this._triggers[s][a].animation=i,![Ze.WIDGET,Ze.KEYBOARD].includes(e.type)){let e=this._triggers[s][a],i=new Xy(e,t,r,n);return function(e,t,r){let n=e.target,i=r.getVariable(X.COND_ENCODING,e);for(let s of t){let t=r.getVariable(X.TRIGGER,e.trigger),a=r.findIncomingDataflowOperator(W.TARGET_EVALUATOR,i);a||(a=r.createOneWayDependency(W.TARGET_EVALUATOR,e._targetEval)),r.connect(t,a),r.connect(a,i);let o=r.getVariable(X.CHANNEL,s,n),l=o.incomingDataflow;if(l&&l instanceof $e&&l.outputVar.channel===s)r.connect(i,l);else if(!l){let e=r.createOneWayDependency(W.ENCODER);r.connect(i,e),r.connect(e,o),e.storeValues(n,s)}}}(i,t.targetChannels,this._depGraph),i}this._triggers[s][a].callback=n}onChange(e,...t){if(Object.values(X).indexOf(e)<0)throw new Error("Unknown Variable Type: "+e);let r=[];this._depGraph.processChange(e,r,...t);for(let e of r)e.run()}gridlines(e,t,r){let n=r||{},i=n.element?Ve(n.element,e):Le(t,e,this);if(i){i.attribute!==t&&console.warn("Cannot create a "+e+" axis for "+t);let r=[];if("x"==e)for(let e of i.scales)r.push({scale:e,elems:i.getElements(e)});else if("width"==e){let e=D(i.element),t=i.scales[0];if(e.layout&&e.layout.type==F.GRID&&e.layout.numCols>1){let n=e.layout.getElementsByCol(!0);for(let e of n)r.push({scale:t,elems:e})}else r.push({scale:i.scales[0],elems:i.getElements(i.scales[0])})}else if("y"==e){let e=D(i.element);if(e.layout&&e.layout.type==F.GRID&&e.layout.numRows>1){let t=e.layout.getElementsByRow(!0,i.element);for(let e of t)r.push({scale:i.getScale(e[0]),elems:e})}else r.push({scale:i.scales[0],elems:i.getElements(i.scales[0])})}else if("height"==e){let e=D(i.element),t=i.scales[0];if(e.layout&&e.layout.type==F.GRID&&e.layout.numRows>1){let n=e.layout.getElementsByRow(!0,i.element);for(let e of n)r.push({scale:t,elems:e})}else r.push({scale:t,elems:i.getElements(t)})}else"radialDistance"==e&&r.push({scale:i.scales[0],elems:S(i.element)});for(let e of r){let t=new qy(i.channel,i.attribute,e.scale,e.elems,n);this.addChild(t),i.addRefElement(t),ft(t,this._depGraph),at(this,t,this._depGraph)}}else{let r=n.element?n.element:N(this,t);if(!r)return void console.warn("Cannot create "+e+" gridlines for "+t);let i=L(r.parent);if(!i.layout)return void console.warn("Cannot create "+e+" gridlines for "+t);let s=S(i);for(let r of s){let i=[];r.layout.type==F.GRID&&r.layout.numRows>1&&"x"==e?i=r.layout.getElementsByRow():r.layout.type==F.GRID&&r.layout.numCols>1&&"y"==e?i=r.layout.getElementsByCol():i.push(r.children);for(let s of i){let i=new qy(e,t,null,s,n);this.addChild(i),r.layout.addRefElement(i),ft(i,this._depGraph),at(this,i,this._depGraph)}}}}axis(e,t,r){let n=r||{},i="rowId"==t?Vt:t,s=[],a=n.element?Ve(n.element,e):Le(i,e,this);if(a){a.attribute!==i&&console.warn("Cannot create a "+e+" axis for "+i);let t=[];if("x"==e||"width"==e){let e=D(a.element);if(e.layout&&e.layout.type==F.GRID&&e.layout.numCols>1){let r=e.layout.getElementsByCell(!0,a.element);for(let e of r)t.push({scale:a.getScale(e[0]),elems:e})}else t.push({scale:a.scales[0],elems:a.getElements(a.scales[0])})}else if("y"==e||"height"==e){let e=D(a.element);if(e.layout&&e.layout.type==F.GRID&&e.layout.numRows>1){let r=e.layout.getElementsByCell(!0,a.element);for(let e of r)t.push({scale:a.getScale(e[0]),elems:e})}else t.push({scale:a.scales[0],elems:a.getElements(a.scales[0])})}else"radialDistance"==e&&t.push({scale:a.scales[0],elems:S(a.element)});for(let e of t){let t=new er(a,e.scale,e.elems,n);this.addChild(t),s.push(t),a.addRefElement(t),dt(t,this._depGraph),at(this,t,this._depGraph),this.onChange(X.PROPERTY,Qe.AXIS_PATH_POSITION,t)}}else{let t=n.element?n.element:N(this,i);if(!t)return void console.warn("Cannot create a "+e+" axis for "+i);let r=L(t.parent);if(!r.layout)return void console.warn("Cannot create a "+e+" axis for "+i);let a=S(r);for(let t of a){let r=[];t.layout.type==F.GRID&&t.layout.numRows>1&&"x"==e?r=t.layout.getElementsByRow():t.layout.type==F.GRID&&t.layout.numCols>1&&"y"==e?r=t.layout.getElementsByCol():r.push(t.children);for(let a of r){let r=new tr(a,e,i,n);this.addChild(r),s.push(r),t.layout.addRefElement(r),ht(r,this._depGraph),at(this,r,this._depGraph),this.onChange(X.PROPERTY,Qe.AXIS_PATH_POSITION,r)}}}return s}legend(e,t,r){let n=r||{},i="rowId"==t?Vt:t,s=n.element?Ve(n.element,e):Le(i,e,this);if(s){s.attribute!==t&&console.warn("Cannot create a "+e+" legend for "+t);let r="string"===Lt(s.element).getAttributeType(t)?new im(s,n):new sm(s,n);this.addChild(r),function(e,t){let r=t.getVariable(X.BOUNDS,e),n=t.getVariable(X.PROPERTY,Qe.LEGEND_POSITION,e),i=t.getIncomingDataflowOperator(W.EVAL_BBOX,r);t.connect(n,i),t.connect(i,r)}(r,this._depGraph),at(this,r,this._depGraph),f(r),this.onChange(X.PROPERTY,Qe.LEGEND_POSITION,r)}else console.warn("Cannot create a "+e+" legend for "+i)}setLayout(e,t){if(e.layout&&(lt(e,e.layout,this._depGraph),t.type===F.TREEMAP)){let t=e.firstChild;for(;t&&t.type===Tt.Collection&&t.layout;)lt(t,t.layout,this._depGraph),t=t.firstChild}if(S(e).forEach((e=>{let r=t?t.clone():t;e._layout=r,r&&(r.group=e)})),ut(e,t,this._depGraph),e.children&&e.children.length>0){let t=G(e,!0);for(let e of t)this.onChange(X.CHANNEL,"x",e)}}setProperties(e,t,r){let n=r?[e]:S(e);n.forEach((e=>{for(const[r,n]of Object.entries(t))Fe(e,r,n)})),"width"in t&&n.forEach((e=>e._refBounds.setWidth(t.width))),"height"in t&&n.forEach((e=>e._refBounds.setHeight(t.height)));for(let r in t)["vertex","segment"].includes(e.type)&&!["x","y"].includes(r)||(Object.values(Oe).includes(r)?this.onChange(X.CHANNEL,r,e):this.onChange(X.PROPERTY,r,e))}setLayoutParameters(e,t){let r=S(e);for(let e of r)for(let r in t)e.layout[r]=t[r];this.onChange(X.CHANNEL,"width",e.firstChild)}sortChildren(e,t,r,n){if(e instanceof pt)em(e,t,r,n),this.onChange(X.ORDER,e);else if(e instanceof ne){let i=S(e);for(let e of i)tm(e,t,r,n)}}findElements(e){return I(this,e)}translate(e,t,r){je(e,t,r);let n=G(e,!0);for(let e of n)f(e);for(let e of n)this.onChange(X.CHANNEL,"x",e)}transform(e,t,r){let n=t.clone();switch(e){case"bin":!function(e,t,r,n,i){let s=i.getVariable(X.ATTRIBUTE,e,r),a=i.getVariable(X.ATTRIBUTE,t,n),o=i.createOneWayDependency(W.BIN_TRANSFORMER);i.connect(s,o),i.connect(o,a),o.run()}(r.attribute,r.newAttribute,t,n,this._depGraph);break;case"filter":!function(e,t,r,n){let i=n.getVariable(X.ITEMS,void 0,t),s=n.getVariable(X.ITEMS,e,r),a=n.createOneWayDependency(W.FILTER_TRANSFORMER);n.connect(i,a),n.connect(a,s),a.run()}(o(r),t,n,this._depGraph);break;case"kde":!function(e,t,r,n,i,s){let a=s.getVariable(X.ATTRIBUTE,e,r),o=s.getVariable(X.ATTRIBUTE,t,n),l=s.createOneWayDependency(W.KDE_TRANSFORMER);l.args=i,s.connect(a,l),s.connect(l,o),l.run()}(r.attribute,r.newAttribute,t,n,r,this._depGraph)}return n}}function mm(e,t){let r=new fe(t.tables[e.dt]);for(let t in e.attr2value)r._attr2value[t]=e.attr2value[t],r._updateTuples(t,e.attr2value[t]);return r}class bm extends z{constructor(e){super(),this.type=F.DIRECTED,this._width="width"in e?e.width:500,this._height="height"in e?e.height:300,this._top="top"in e?e.top:0,this._left="left"in e?e.left:0,this._edgeSep="edgeSep"in e?e.edgeSep:50,this._spreadLinks=!("spreadLinks"in e)||e.spreadLinks,this._direction="direction"in e?e.direction:J.Top2Bottom}clone(){return new bm({width:this._width,height:this._height,top:this._top,left:this._left,edgeSep:this._edgeSep,spreadLinks:this._spreadLinks,direction:this._direction})}get width(){return this._width}get height(){return this._height}get top(){return this._top}get left(){return this._left}get edgeSep(){return this._edgeSep}get spreadLinks(){return this._spreadLinks}get direction(){return this._direction}}class vm extends z{constructor(e){super(),this.type=F.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 vm({x:this._x,y:this._y,iterations:this._iterations,repulsion:this._repulsion,attraction:this._attraction,linkDistance:this._linkDistance})}}class xm extends z{constructor(e){super(),this.type=F.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 xm({x:this._x,y:this._y,width:this._width,height:this._height})}}class Em extends z{constructor(e){super(),this.type=F.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:$.HORIZONTAL}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 Em({width:this._width,height:this._height,top:this._top,left:this._left,orientation:this._orientation})}}class wm extends z{constructor(e){super(),this.type=F.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 wm({width:this._width,height:this._height,top:this._top,left:this._left})}}function Am(e){switch(e.type){case F.GRID:return function(e){let t=new rm(e.args);return t._left=e.left,t._top=e.top,t._cellBounds=e.cellBounds.map((e=>Cm(e))),t._grid=e.grid,t}(e);case F.STACK:return function(e){let t=new Ky(e.args);return t}(e);case F.PACKING:return function(e){let t=new xm(e.args);return t}(e);case F.FORCE:return function(e){return new vm(e.args)}(e);case F.DIRECTED:return function(e){return new bm(e.args)}(e);case F.TIDYTREE:return function(e){return new Em(e.args)}(e);case F.TREEMAP:return function(e){return new wm(e.args)}(e);case F.STRATA:return function(e){return new lm(e.args)}(e);default:return void console.warn("unsupported layout type for deserialization:",e.type)}}function Cm(e){return new u(e.x-e.width/2,e.y-e.height/2,e.width,e.height)}function Rm(e,t){e.type===Tt.Pie&&(e.type=Tt.Arc),e.args.type=e.type;let r=At(e.args);return e.id&&(r._id=e.id),e.classId&&(r._classId=e.classId),e.dataScope&&(r._dataScope=mm(e.dataScope,t)),e.bounds&&(r._bounds=Cm(e.bounds)),e.refBounds&&(r._refBounds=Cm(e.refBounds)),function(e,t,r){if(e.vertices){const n=[];for(let i of e.vertices){const e=km(i,t,r);n.push(e)}t.vertices=n,t.segments=[];let i=0;for(let e=1;e<t.vertices.length;e++)t.segments.push(new re(t.vertices[e-1],t.vertices[e],t,i++));t.type===Tt.Rect&&t.segments.push(new re(t.vertices[t.vertices.length-1],t.vertices[0],t,i++))}t.vertexCounter=e.vertexCounter,t.segmentCounter=e.segmentCounter,t.curveMode=e.curveMode}(e,r,t),r}function km(e,t,r){let n=new te(e.x,e.y,t,e.id);return e.dataScope&&(n._dataScope=mm(e.dataScope,r)),"polarAngle"in e&&(n._polarAngle=e.polarAngle),n.shape=e.shape,n.width=e.width,n.height=e.height,n.radius=e.radius,n.fillColor=e.fillColor,n.opacity=e.opacity,n.strokeWidth=e.strokeWidth,n.strokeColor=e.strokeColor,n}function Sm(e){let t={};t.fillColor=e.fillColor;let r=new ym(t),n={};if(e.tables)for(let t in e.tables){let r=e.tables[t];n[t]=new Nt(r.data,r.url,r.attributeTypes),n[t]._id=r.id}r.tables=n;let i={};if(e.scales)for(let t in e.scales)i[t]=Nm(e.scales[t]);if(r.scales=i,Im(e,r,r),Om(e,r),e.encodings)for(let t of e.encodings)r._addAttributeEncoding(Lm(t,r));return delete r.tables,delete r.scales,r._bounds=Cm(e.bounds),r}function Tm(e,t,r){if(e.type===Tt.Collection){let n=Ct(r);t.addChild(n),Im(e,n,r),r._itemMap[n.id]=n}else if(e.type===Tt.Glyph){let n=Rt();t.addChild(n),Im(e,n,r),r._itemMap[n.id]=n}else if(e.type===Tt.Composite){let n=new am;t.addChild(n),Im(e,n,r),r._itemMap[n.id]=n,n._bounds=Cm(e.bounds)}else if(Object.values(E).includes(e.type)){let n=Rm(e,r);r._itemMap[n.id]=n,t.addChild(n)}}function Om(e,t){if(e.children)for(let r of e.children)Om(r,t);else if(Object.values(E).includes(e.type)){let r=t._itemMap[e.id];e.links&&(r.links=e.links.map((e=>t._itemMap[e]))),e.source&&(r.source=t._itemMap[e.source]),e.target&&(r.target=t._itemMap[e.target])}}function Im(e,t,r){if(e.id&&(t._id=e.id),e.classId&&(t._classId=e.classId),e.dataScope&&(t._dataScope=mm(e.dataScope,r)),t._bounds=Cm(e.bounds),e.layout&&(t._layout=Am(e.layout),t._layout.group=t),t._sortBy=e.sortBy,e.children)for(let n of e.children)Tm(n,t,r)}function Nm(e){let t=new Ut(e.type,e.args);return t._id=e.id,t.domain=e.domain,t.range=e.range,t}function Lm(e,t){let r=function(e,t,r){if("vertex"===t){let t=e.split("_v_");return r._itemMap[t[0]].vertices.find((e=>e._id===parseInt(t[1])))}if("segment"===t){let t=e.split("_s_");return r._itemMap[t[0]].segments.find((e=>e._id===parseInt(t[1])))}return r._itemMap[e]}(e.element,e.elementType,t);r||console.warn("element not created:",e.element,e.elementType);let n=new Yy(r,e.channel,e.attr,e.aggregator,e.args);if(e.scales&&(n._scales=e.scales.map((e=>t.scales[e]))),e.elemGroups&&(n._elemGroups=e.elemGroups.map((e=>e.map((e=>t._itemMap[e]))))),e.elem2scale){n._elem2scale={};for(let r in e.elem2scale)n._elem2scale[r]=t.scales[e.elem2scale[r]]}return e.args.startAngle&&(n.startAngle=e.args.startAngle),n}function Vm(e){let t={};return t.id=e._id,t.data=e._rawData,t.attributeTypes=e._attrTypes,t.url=e.url,t}function Pm(e){let t={};return t.dt=e._dt.id,t.attr2value=Object.assign({},e._attr2value),t}function Dm(e,t){t.vertices=[];for(let r of e.vertices)t.vertices.push(Bm(r));t.vertexCounter=e.vertexCounter,t.segmentCounter=e.segmentCounter,t.curveMode=e.curveMode}function Bm(e){let t={};return t.type=e.type,t.id=e._id,t.x=e.x,t.y=e.y,e._dataScope&&(t.dataScope=Pm(e._dataScope)),void 0!==e._polarAngle&&(t.polarAngle=e._polarAngle),t.shape=e.shape,t.width=e.width,t.height=e.height,t.radius=e.radius,t.fillColor=e.fillColor,t.opacity=e.opacity,t.strokeWidth=e.strokeWidth,t.strokeColor=e.strokeColor,t}function Mm(e){return e.type===Tt.Scene?function(e){let t=zm(e,{});t.fillColor=e.fillColor,t.scales={},t.encodings=[];for(let r in e._encodings)for(let n in e._encodings[r]){let i=e._encodings[r][n];i._forLegend||t.encodings.push(jm(i));for(let e of i._scales)e.id in t.scales||(t.scales[e.id]=Gm(e))}t.tables={};let r=function(e){let t={};for(let r in e._encodings)for(let n in e._encodings[r]){let i=e._encodings[r][n];i.dataTable.id in t||i._forLegend||(t[i.dataTable.id]=i.dataTable)}for(let r of e.children)if(![Tt.Axis,Tt.Legend,Tt.Gridlines].includes(r.type)){if(r.dataScope){t[r.dataScope.dataTable.id]=r.dataScope.dataTable;break}if(r.children&&r.children.length>0){let e=r.firstChild;for(;e;){if(e.dataScope){t[e.dataScope.dataTable.id]=e.dataScope.dataTable;break}e=e.children&&e.children.length>0?e.firstChild:void 0}}}return t}(e);for(let e in r)t.tables[e]=Vm(r[e]);return console.log(t.tables),t}(e):e instanceof pt?zm(e,{}):e instanceof v?function(e){let t={args:{}};t.type=e.type,t.id=e.id,e.classId&&(t.classId=e.classId),e._dataScope&&(t.dataScope=Pm(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 r in e.styles)r.indexOf("Color")>0&&e.styles[r]instanceof b?t.args[r]=e.styles[r].toJSON():t.args[r]=e.styles[r];switch(e.type){case Tt.Arc:case Tt.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),Dm(e,t);break;case Tt.Area:!function(e,t){t.args.baseline=e._baseline,t.args.orientation=e._orientation}(e,t),Dm(e,t);break;case Tt.Circle:!function(e,t){t.args.x=e.x,t.args.y=e.y,t.args.radius=e.radius}(e,t);break;case Tt.Image:break;case Tt.Line:case Tt.Path:case Tt.BezierCurve:Dm(e,t);break;case Tt.PointText:!function(e,t){t.args.x=e._x,t.args.y=e._y,t.args.text=e._text,t.args.anchor=e._anchor}(e,t);break;case Tt.Polygon:!function(e,t){t.args.x=e._x,t.args.y=e._y,t.args.radius=e._radius}(e,t),Dm(e,t);break;case Tt.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),Dm(e,t);case Tt.Ring:}return t}(e):(console.warn("unsupported serialization",e.type),{type:e.type})}function Gm(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 jm(e){let t={};t.element=e._elem.id,t.elementType=e._elem.type,e.attrValues&&(t.attrValues=e.attrValues),t.channel=e._channel,t.attr=e._attribute,t.aggregator=e._aggregator,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,t.scales=e._scales.map((e=>e.id)),t.elemGroups=e._elemGroups.map((e=>e.map((e=>e.id)))),t.elem2scale={};for(let r in e._elem2scale)t.elem2scale[r]=e._elem2scale[r].id;return t.refElements=e._refElements.map((e=>e.id)),"angle"==e.channel&&(t.args.startAngle=e.startAngle),t}function zm(e,t){if(t.id=e.id,t.type=e.type,e.classId&&(t.classId=e.classId),e._dataScope&&(t.dataScope=Pm(e._dataScope)),t.bounds=e.bounds.toJSON(),e._layout&&(t.layout=function(e){switch(e.type){case F.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.left=e._left,t.top=e._top,t.cellBounds=e._cellBounds.map((e=>e.toJSON())),t.group=e.group.id,t.grid=e._grid,t}(e);case F.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 F.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 F.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 F.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 F.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 F.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 F.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 F.STRATA:return function(e){let t={args:{}};return t.type=e.type,t.args.direction=e._direction,t.args.gap=e._gap,t}(e);default:throw new Error("unknow layout type "+e.type)}}(e._layout)),t.children=[],e.children.length>0)for(let r of e.children)t.children.push(Mm(r));return t.sortBy=e._sortBy,t}function Fm(t,r,n,i,s){for(let a of t){let t=a.listener?a.listener:n,o=t.type===Tt.Axis?t.boundsWithoutTitle:t.bounds,l=[[o.left,o.top],[o.right,o.bottom]],u="brushX"===a.event?e.brushX():"brushY"===a.event?e.brushY():e.brush();u.extent(l).on("brush end",(e=>{let t,r;if(e&&e.selection)switch(a.event){case"brushX":t=[e.selection[0],e.selection[1]],r=void 0;break;case"brushY":t=void 0,r=[e.selection[0],e.selection[1]];break;default:t=[e.selection[0][0],e.selection[1][0]],r=[e.selection[0][1],e.selection[1][1]]}else t=void 0,r=void 0;a.mouseEvent={xInterval:t,yInterval:r},n.onChange(X.TRIGGER,a),i._render(n,s)})),r.append("g").attr("class","brush").call(u)}}function Um(e,t,r,n,i){t.on("mousemove",(s=>{for(let n of e){let[e,i]=w(t.attr("id"),s.clientX,s.clientY),a=B(r,e,i,n.element.type,n.element.classId);a?n.isCumulative&&!n.elements.includes(a)?n.elements.push(a):n.elements=[a]:n.elements=[],n.mouseEvent={x:e,y:i},r.onChange(X.TRIGGER,n)}n._render(r,i)}))}function Hm(t,r,n,i,s){for(let r of t)if(r.type===Ze.WIDGET){console.log(r.id),document.getElementById(r.id).addEventListener("input",(function(){Wm(r,n,i,s)}))}else r.type===Ze.KEYBOARD&&e.select("body").on("keydown",(e=>{e.key===r.key&&Wm(r,n,i,s)}))}function Wm(e,t,r,n){if(Array.isArray(e.callback))for(let i=0;i<e.callback.length;i++)e.callback[i](),r._render(t,n,e.animation[i]);else e.callback(),r._render(t,n,e.animation)}function Ym(e,t,r,n,i){t.on("click",(s=>{for(let n of e){let[e,i]=w(t.attr("id"),s.clientX,s.clientY),a=B(r,e,i,n.element.type,n.element.classId);a?n.isCumulative&&!n.elements.includes(a)?n.elements.push(a):n.elements=[a]:n.elements=[],n.mouseEvent={x:e,y:i},r.onChange(X.TRIGGER,n)}n._render(r,i)}))}class Xm{constructor(e){this._svgId=e,this._compMap={},this._decoMap={},this._brushCreated=0}render(t,r){let n=r||{};e.select("#"+this._svgId).select("defs").empty()&&e.select("#"+this._svgId).append("defs"),this._render(t,n),this._registerEvents(t,n)}_render(e,t,r){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,r);for(let e in this._removed)this._compMap[e].remove(),delete this._compMap[e]}_registerEvents(t,r){let n=e.select("#"+this._svgId);for(let e in t.interactionTriggers){let i=Object.values(t.interactionTriggers[e]);switch(e){case"click":n.on("click",null),Ym(i,n,t,this,r);break;case"brush":case"brushX":case"brushY":Fm(i,n,t,this,r);break;case"hover":Um(i,n,t,this,r);break;case"input":Hm(i,0,t,this,r)}}}clear(){let e=document.getElementById(this._svgId);for(;e.firstChild;)e.firstChild.remove();this._compMap={},this._decoMap={}}_renderItem(t,r,n){this._configSVG(t);let i=this._compMap[t.id];switch(t.type){case Tt.Scene:!function(e,t){t.style("background",e.fillColor?e.fillColor:"#fff")}(t,e.select("#"+this._svgId));break;case Tt.Circle:!function(e,t){t.attr("cx",e.x),t.attr("cy",e.y),t.attr("r",e.radius)}(t,i);break;case Tt.Rect:!function(e,t){let r=e.bounds;t.attr("x",r.left).attr("y",r.top).attr("width",r.width).attr("height",r.height)}(t,i);break;case Tt.Path:case Tt.BezierCurve:case Tt.BundledPath:case Tt.Chord:case Tt.Polygon:case Tt.Link:case Tt.Pie:case Tt.Line:case Tt.Area:case Tt.Ring:case Tt.Arc:case Tt.Gridlines:!function(e,t){t.attr("d",e.getSVGPathData()),e.closed||t.style("fill","none"),(e.id.includes("axis")||e.id.includes("gridlines"))&&t.style("shape-rendering","crispEdges"),e.type===Tt.BundledPath&&t.style("mix-blend-mode","multiply")}(t,i);break;case Tt.PointText:!function(t,r){if(r.attr("text-anchor",y(t.anchor[0])).attr("alignment-baseline",y(t.anchor[1])).attr("dominant-baseline",y(t.anchor[1])).attr("x",t.x).attr("y",t.y),t.hasBackground()){t._updateBounds();let r=e.select("#"+_(t)),n=t.bounds;r.attr("x",n.left-5).attr("y",n.top-5).attr("width",n.width+10).attr("height",n.height+10).attr("rx",5).attr("ry",5).style("fill",t.backgroundColor).style("stroke",t.borderColor).style("strokeWidth",t.borderWidth)}t.textPath?(r.select("textPath").empty()&&r.append("textPath"),r.select("textPath").attr("href","#"+g(t)).attr("startOffset",t.textPathOffset).text(t.text)):r.text(t.text)}(t,i);break;case Tt.Image:!function(e,t){t.attr("href",e.src).attr("x",e.x).attr("y",e.y).attr("width",e.width).attr("height",e.height)}(t,i)}if(function(t,r,n){for(let i in t.styles)if(void 0!==t.styles[i])if(i.indexOf("Color")>0&&t.styles[i].type==Tt.LinearGradient){let e=n.select("defs"),s=t.styles[i];if(e.select("#"+s.id).empty()){let t=e.append("linearGradient").attr("id",s.id);t.attr("x1",s.x1+"%").attr("x2",s.x2+"%").attr("y1",s.y1+"%").attr("y2",s.y2+"%");for(let e of s.stops)t.append("stop").attr("offset",e.offset+"%").style("stop-color",e.color).style("stop-opacity",e.opacity)}r.style(m[i],"url(#"+s.id+")")}else r.style(m[i],t.styles[i]),"visibility"===i&&t.type===Tt.PointText&&t.hasBackground()&&e.select("#"+_(t)).style(m[i],t.styles[i])}(t,i,e.select("#"+this._svgId)),t._rotate&&i.attr("transform","rotate("+t._rotate.join(" ")+")"),n&&(i=i.transition().delay(n.delay?n.delay:0).duration(n.duration?n.duration:0)),t.vertices&&this._renderVertices(t),[Tt.Circle].includes(t.type)&&r&&r.bounds?this._renderBounds(t):x(t)&&r&&r.refBounds&&this._renderRefBounds(t),t.children)for(let e of t.children)this._renderItem(e,r,n)}_configSVG(t){let r,n=t.parent;if(r=n&&n.id&&n.id in this._compMap?e.select("#"+this._svgId).select("#"+n.id):e.select("#"+this._svgId),t.id in this._compMap)delete this._removed[t.id],t.type===Tt.PointText&&(t.hasBackground()&&delete this._removed[_(t)],t.textPath&&delete this._removed[g(t)]);else{if(t.type===Tt.PointText&&(t.hasBackground()&&(this._compMap[_(t)]=r.append("rect").attr("id",_(t))),t.textPath)){let r=e.select("#"+this._svgId).select("defs"),n=g(t);r.select("#"+n).empty()&&(this._compMap[n]=r.append("path").attr("id",n)),this._compMap[n].attr("d",t.textPath).style("fill","none")}this._compMap[t.id]=r.append(this._getSVGElementType(t))}t.type==Tt.Gridlines&&this._compMap[t.id].lower(),this._compMap[t.id].attr("id",t.id),t.classId&&this._compMap[t.id].attr("class",t.classId)}_renderBounds(t){let r=t.bounds;t.layout&&"grid"==t.layout.type&&this._renderLayout(t),t.id in this._decoMap||(this._decoMap[t.id]=e.select("#"+this._svgId).append("rect").attr("class","deco")),this._decoMap[t.id].attr("x",r.left).attr("y",r.top).attr("width",r.width).attr("height",r.height).attr("fill","none").attr("stroke","blue").attr("stroke-width","1px").attr("stroke-dasharray","5,5")}_renderRefBounds(t){let r=t.refBounds;r&&(t.id in this._decoMap||(this._decoMap[t.id]=e.select("#"+this._svgId).append("rect").attr("class","deco")),this._decoMap[t.id].attr("x",r.left).attr("y",r.top).attr("width",r.width).attr("height",r.height).attr("fill","none").attr("stroke","blue").attr("stroke-width","1px").attr("stroke-dasharray","5,5"))}_renderVertices(t){let r=t.id+"-vertices";if(r in this._compMap)delete this._removed[r];else{let n=t.parent,i=n?n.id:this._svgId;this._compMap[r]=e.select("#"+i).append("g").attr("id",r)}if(0===t.vertices.map((e=>e.shape)).filter((e=>void 0!==e)).length)return void this._compMap[r].style("visible","hidden");this._compMap[r].style("visible","visible");let n=t.vertices.filter((e=>void 0!==e.shape));for(let t of n){let n=r+"-"+t.id;n in this._compMap?t.shape!==this._compMap[n].node().tagName?(this._compMap[n].remove(),this._compMap[n]=e.select("#"+r).append(t.shape).attr("id",n),delete this._removed[n]):delete this._removed[n]:this._compMap[n]=e.select("#"+r).append(t.shape).attr("id",n),"rect"==t.shape?e.select("#"+n).attr("x",t.x-t.width/2).attr("y",t.y-t.height/2).attr("width",t.width).attr("height",t.height):"circle"==t.shape&&e.select("#"+n).attr("cx",t.x).attr("cy",t.y).attr("r",t.radius),e.select("#"+n).style("fill",t.fillColor).style("opacity",t.opacity).style("stroke-width",t.strokeWidth).style("stroke",t.strokeColor)}}_renderLayout(t){let r=t.id+"-grid";r in this._decoMap||(this._decoMap[r]=e.select("#"+this._svgId).append("g").attr("id",r).attr("class","deco"));let n=t.layout.cellBounds;t.layout.rowGap,this._decoMap[r].selectAll("rect").remove();for(let e of n)this._decoMap[r].append("rect").attr("x",e.left).attr("y",e.top).attr("width",e.width).attr("height",e.height).attr("stroke","blue").attr("stroke-width","1px").attr("stroke-dasharray","5,5").attr("fill","none")}_getSVGElementType(e){switch(e.type){case Tt.Rect:return"rect";case Tt.Collection:case Tt.Group:case Tt.Glyph:case Tt.Scene:case Tt.Axis:case Tt.Legend:case Tt.Composite:return"g";case Tt.Area:case Tt.Path:case Tt.Polygon:case Tt.Ring:case Tt.Pie:case Tt.Arc:case Tt.BezierCurve:case Tt.BundledPath:case Tt.Chord:case Tt.Line:case Tt.Gridlines:return"path";case Tt.Circle:return"circle";case Tt.PointText:return"text";case"vertex":if("circle"==e.shape)return"circle";if("rect"==e.shape)return"rect";throw"argument exception";case"image":return"image"}}}function qm(e,t){return void 0===e&&void 0===t||void 0!==e&&void 0!==t}function Km(e,t){const r=Object.keys(e),n=Object.keys(t);return r.length===n.length&&(0===r.length||r.every((e=>n.includes(e))))}function Zm(e,t){if(!qm(e.layout,t.layout))return console.log("Not both defined or undefined:",e.bounds,t.bounds),!1;let r=e.layout,n=t.layout;if(!r&&!n)return!0;if(r.type!==n.type)return console.log("layout types are different:",r,n),!1;switch(r.type){case F.GRID:return function(e,t){e._cellBounds.length!==t._cellBounds.length&&console.log("cell bounds length different:",e,t);for(let r=0;r<e._cellBounds;r++)if(!Jm(e._cellBounds[r],t._cellBounds[r]))return console.log("cell bounds not equal:",e,t),!1;for(let r=0;r<e._grid.length;r++)for(let n=0;n<e._grid[r].length;n++)if(e._grid[r][n]!==t._grid[r][n])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._left===t._left&&e._top===t._top}(r,n);case F.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}(r,n);case F.PACKING:return function(e,t){return e._x===t._x&&e._y===t._y&&e._width===t._width&&e._height===t._height}(r,n);case F.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}(r,n);case F.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}(r,n);case F.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}(r,n);case F.STRATA:return function(e,t){return e._direction===t._direction&&e._gap===t._gap}(r,n);case F.TREEMAP:return function(e,t){return e._width===t._width&&e._height===t._height&&e._top===t._top&&e._left===t._left}(r,n);default:return!1}}function $m(e,t){if(!qm(e.bounds,t.bounds))return console.log("Not both defined or undefined:",e.bounds,t.bounds),!1;let r=e.bounds,n=t.bounds;return!r&&!n||Jm(r,n)}function Jm(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Qm(e,t){if(!qm(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(!tb(e,t))return console.log("DataScopes not equal",e,t),!1;if(!$m(e,t))return console.log("Bounds not equal",e,t),!1;if(!qm(e.links,t.links))return console.log("Not both defined or undefined: links ",e.links,t.links),!1;if(!qm(e.source,t.source))return console.log("Not both defined or undefined: source ",e.source,t.source),!1;if(!qm(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&&!Qm(e.source,t.source))return console.log("different sources",e.source,t.source),!1;if(e.target&&t.target&&!Qm(e.target,t.target))return console.log("different targets",e.target,t.target),!1;switch(e.type){case Tt.Arc:case Tt.Pie:return eb(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 Tt.Area:return eb(e,t)?e.baseline===t.baseline&&e.orientation===t.orientation:(console.log("vertices not equal:",e,t),!1);case Tt.Circle:return e.x===t.x&&e.y===t.y&&e.radius===t.radius;case Tt.Image:return console.warn("not implemented"),!0;case Tt.Line:case Tt.Path:case Tt.BezierCurve:return!!eb(e,t)||(console.log("vertices not equal:",e,t),!1);case Tt.PointText: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 Tt.Polygon:return eb(e,t)?e.x===t.x&&e.y===t.y&&e.radius===t.radius:(console.log("vertices not equal:",e,t),!1);case Tt.Rect:return eb(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 Tt.Ring:default:return console.warn("not implemented"),!0}}function eb(e,t){if(e.vertices.length!==t.vertices.length)return console.log("unequal number of vertices:",e,t),!1;for(let r=0;r<e.vertices.length;r++){let n=e.vertices[r],i=t.vertices[r];return n.id!==i.id?(console.log("vertex id not equal:",n,i),!1):n.x!==i.x||n.y!==i.y?(console.log("vertex position not equal:",n,i),!1):tb(n,i)?n._polarAngle===i._polarAngle&&n.shape===i.shape&&n.width===i.width&&n.height==i.height&&n.radius==i.radius&&n.fillColor==i.fillColor&&n.opacity==i.opacity&&n.strokeWidth==i.strokeWidth&&n.strokeColor==i.strokeColor:(console.log("vertex data scopes not equal:",n.dataScope,i.dataScope),!1)}}function tb(e,t){if(!qm(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 r=e.dataScope,n=t.dataScope;if(!Km(r._attr2value,n._attr2value))return!1;for(let e in r._attr2value)if(r._attr2value[e]!==n._attr2value[e])return!1;return r._dt.id===n._dt.id&&r._tuples.length===n._tuples.length}function rb(e,t){return e.type!==t.type&&console.log("Different types:",e.type,t.type),[Tt.Collection,Tt.Glyph,Tt.Composite].includes(e.type)?nb(e,t):e instanceof v?Qm(e,t):void 0}function nb(e,t){let r=e.children.filter((e=>!Object.values(Ot).includes(e.type))),n=t.children.filter((e=>!Object.values(Ot).includes(e.type)));if(r.length!==n.length)return console.log("children length not equal:",r,n),!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(!tb(e,t))return console.log("DataScopes not equal",e.dataScope,t.dataScope),!1;if(!$m(e,t))return console.log("Bounds not equal",e,t),!1;if(!Zm(e,t))return console.log("Layouts not equal",e,t),!1;if(!function(e,t){if(!Km(e,t))return console.log("different keys",e,t),!1;for(let r in e)if(e[r]!==t[r])return!1;return!0}(e._sortBy,t._sortBy))return console.log("SortBy not equal",e,t),!1;for(let e=0;e<r.length;e++)if(!rb(r[e],n[e]))return console.log("Not equal",r[e],n[e]),!1;return!0}class ib extends z{constructor(e){super(),this.type=F.CIRCULAR,this._x="x"in e?e.x:100,this._y="y"in e?e.y:100,this._radius="radius"in e?e.radius:100}get x(){return this._x}get y(){return this._y}get radius(){return this._radius}clone(){return new ib({x:this._x,y:this._y,radius:this._radius})}}class sb extends z{constructor(e){super(),this.type=F.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:$.HORIZONTAL,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 sb({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 ab(e,t){let r=t||{};switch(e.toLowerCase()){case F.STACK:return new Ky(r);case F.PACKING:return new xm(r);case F.FORCE:return new vm(r);case F.DIRECTED:return new bm(r);case F.TIDYTREE:return new Em(r);case F.TREEMAP:return new wm(r);case F.CIRCULAR:return new ib(r);case F.CLUSTER:return new sb(r);case F.GRID:default:return new rm(r)}}function ob(e){return new ym(e)}function lb(e){return new Nt(e,"")}async function ub(t){return async function(t){let r=await Pt("GET",t),n=e.csvParse(r.trim(),e.autoType);return new Nt(n,t)}(t)}async function cb(e){return async function(e){let t=await Pt("GET",e);return new me(JSON.parse(t),e)}(e)}async function hb(e){return async function(e){let t=await Pt("GET",e);return new ge(JSON.parse(t),e)}(e)}function db(e,t){return new Xm(t)}function fb(e){return Mm(e)}function pb(e){return Sm(e)}function _b(e,t){return function(e,t){return e.fillColor!==t.fillColor?(console.log("fillColor not equal:",e,t),!1):nb(e,t)}(e,t)}export{ub as csv,pb as deserialize,cb as graphJSON,_b as isEqual,ab as layout,db as renderer,ob as scene,fb as serialize,lb as table,hb as treeJSON};