mascot-vis 3.3.0 → 3.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mascot-cjs.cjs +2 -2
- package/dist/mascot-esm.js +2 -2
- package/dist/mascot-umd.js +2 -2
- package/package.json +1 -1
package/dist/mascot-umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* version: 3.3.
|
|
2
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("d3")):"function"==typeof define&&define.amd?define(["exports","d3"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).msc={},e.d3)}(this,function(e,t){"use strict";function i(e){var t=Object.create(null);return e&&Object.keys(e).forEach(function(i){if("default"!==i){var r=Object.getOwnPropertyDescriptor(e,i);Object.defineProperty(t,i,r.get?r:{enumerable:!0,get:function(){return e[i]}})}}),t.default=e,Object.freeze(t)}var r=i(t);class s{constructor(e,t,i){this._id="predicate_"+Mt(),this._type=e||n.POINT,this._variableType=t,this._variableName=i,this._value=void 0}get type(){return this._type}get value(){return this._value}set value(e){this._value=e}get id(){return this._id}get variableType(){return this._variableType}get variableName(){return this._variableName}}const n=Object.freeze({POINT:"point",INTERVAL:"interval",LIST:"list"});class a extends s{constructor(e,t,i){super(e,t,i)}testElement(e){let t;if("attribute"==this._variableType){if(!e.dataScope)return!1;t=e.dataScope.getAttrVal(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 o extends s{constructor(e,t,i){super(e,t,i)}addValue(e){this._value||(this._value=[]),this._value.push(e)}resetValue(){this._value=void 0}testElement(e){if("attribute"==this._variableType){if(!e.dataScope)return!1;let t=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 l extends s{constructor(e,t,i){super(e,t,i)}testElement(e){if("attribute"==this._variableType){if(!e.dataScope)return!1;return e.dataScope.getAttrVal(this._variableName)==this._value}return e[this._variableName]==this._value}testTuple(e){if("attribute"==this._variableType){let t=e[this._variableName];return this._value===t}return!1}equals(e){return this.type===e.type&&this.variableName===e.variableName&&this.value===e.value}}function h(e){let t,i="attribute"in e?"attribute":"property",r=e[i];switch(e.type){case n.LIST:t=new o(e.type,i,r);break;case n.INTERVAL:t=new a(e.type,i,r);break;case n.POINT:default:t=new l(e.type,i,r)}return t.value=e.value,t}function c(e,t){for(let i of t)if(!i.testElement(e))return!1;return!0}const d={svg:void 0,getSVG:function(){return window?(void 0===this.svg&&(this.svg=document.createElementNS("http://www.w3.org/2000/svg","svg"),this.svg.style.visibility="hidden",this.svg.style.pointerEvents="none",this.svg.setAttribute("aria-hidden","true"),document.body.appendChild(this.svg)),this.svg):null}};function u(e,t,i,r,s){const n=s*Math.PI/180,a=e-i,o=t-r;return{x:a*Math.cos(n)-o*Math.sin(n)+i,y:a*Math.sin(n)+o*Math.cos(n)+r}}function p(e,t,i,r){return Math.sqrt(Math.pow(e-i,2)+Math.pow(t-r,2))}function _(e,t,i){const r=document.getElementById(e),s=r.createSVGPoint();s.x=t,s.y=i;const n=s.matrixTransform(r.getScreenCTM().inverse());return[n.x,n.y]}const f=Object.freeze({fillColor:"fill",strokeColor:"stroke",strokeWidth:"stroke-width",fillOpacity:"fill-opacity",strokeOpacity:"stroke-opacity",strokeDash:"stroke-dasharray",opacity:"opacity",fontSize:"font-size",fontFamily:"font-family",fontWeight:"font-weight",visibility:"visibility",cursor:"cursor"});class g{constructor(e,t,i,r){this._x=e+i/2,this._y=t+r/2,this._width=i,this._height=r}translate(e,t){this._x+=e,this._y+=t}toJSON(){let e={};return e.x=this._x,e.y=this._y,e.width=this._width,e.height=this._height,e}union(e){let t=Math.min(this.left,e.left),i=Math.min(this.top,e.top),r=Math.max(this.right,e.right),s=Math.max(this.bottom,e.bottom);return new g(t,i,r-t,s-i)}clone(){return new g(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 v.RIGHT:this._x=this.right-e/2;break;case v.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 v.TOP:this._y=this.top+e/2;break;case v.MIDDLE:this._height=2*e;break;default:this._y=this.bottom-e/2}this._height=e}contains(e,t){return this.left<=e&&this.right>=e&&this.top<=t&&this.bottom>=t}intersects(e){return!(this.right<e.left||this.bottom<e.top||this.left>e.right||this.top>e.bottom)}}function y(e){let t=e[0].clone();for(let i=1;i<e.length;i++)t=t.union(e[i]);return t}function m(e){return y(("vertex"==e[0].type||"segment"==e[0].type?e.map(e=>e.parent):e).map(e=>e.refBounds?e.refBounds:e.bounds))}function b(e){return y(("vertex"==e[0].type||"segment"==e[0].type?e.map(e=>e.parent):e).map(e=>e.bounds))}function x(e){let t=C(e);for(let e of t)e._updateBounds();let i=[];for(let e of t)e.parent&&!i.includes(e.parent)&&i.push(e.parent);for(let e of i)x(e)}const v=Object.freeze({TOP:"top",LEFT:"left",RIGHT:"right",BOTTOM:"bottom",CENTER:"center",MIDDLE:"middle"});class w{constructor(e){if(this._dataScope=void 0,this._type="type"in e?e.type:Vt.Mark,this._id=e.id?e.id:this._type+"_"+Mt(),this._classId=void 0,this._bounds=void 0,this._rotate=void 0,this._refBounds=void 0,this._dirty=!0,this._clipMask=void 0,this._cursor=void 0,this._styles={},void 0!==e)for(let t in f)t in e&&(this.styles[t]=e[t])}get scene(){return N(this)}set strokeColor(e){this.styles.strokeColor=e,this._dirty=!0}get strokeColor(){return this.styles.strokeColor}set strokeWidth(e){this.styles.strokeWidth=e,this._dirty=!0}get strokeWidth(){return this.styles.strokeWidth}set strokeDash(e){this.styles.strokeDash=e,this._dirty=!0}get strokeDash(){return this.styles.strokeDash}set fillColor(e){this.styles.fillColor=e,this._dirty=!0}get fillColor(){return this.styles.fillColor}get rotation(){return this._rotate}get cursor(){return this._cursor}get id(){return this._id}set id(e){this.getScene()?(delete this.getScene()._itemMap[this._id],this._id=e,this.getScene()._itemMap[e]=this):this._id=e}get classId(){return this._classId?this._classId:this._id}set classId(e){this._classId=e}get type(){return this._type}get bounds(){return this._bounds||this._updateBounds(),this._bounds}get refBounds(){return this._refBounds?this._refBounds:this.bounds}set dataScope(e){this._dataScope=e}get dataScope(){return this._dataScope}get styles(){return this._styles}set styles(e){this._styles=e,this._dirty=!0}set visibility(e){this.styles.visibility=e,this._dirty=!0}get visibility(){return this.styles.visibility?this.styles.visibility:"visible"}get opacity(){return"opacity"in this.styles?this.styles.opacity:1}set opacity(e){this.styles.opacity=e,this._dirty=!0}copyPropertiesTo(e){e.styles=Object.assign({},this.styles),this._dataScope&&(e._dataScope=this._dataScope.clone())}createClipMask(){let e=this._bounds;this._clipMask=new g(e.left,e.top,e.width,e.height)}get clipMask(){return this._clipMask}}function E(e){return e instanceof w&&e.type!==Vt.Gridlines}const A=Object.freeze({Area:"area",Rect:"rect",Ellipse:"ellipse",Circle:"circle",Pie:"pie",Ring:"ring",Arc:"arc",Line:"line",Path:"path",Image:"image",SimpleText:"text",RichText:"richText",Polygon:"polygon",BezierCurve:"bezierCurve"});function C(e,t){let i=N(e);if("vertex"===e.type||"segment"===e.type)return function(e,t){let i=N(e),r=t||i;if("vertex"===e.type){return k(e,T(r,[{property:"classId",value:e.parent.classId}]))}if("segment"===e.type){return S(e,T(r,[{property:"classId",value:e.parent.classId}]))}return e.classId?T(r,[{property:"classId",value:e.classId}]):[e]}(e,t);if(!e.classId)return[e];if(e.classId&&i._peerIndex.has(e.classId)){let r=i._peerIndex.get(e.classId);return t?r.filter(e=>function(e,t){let i=e.parent;for(;i;){if(i===t)return!0;i=i.parent}return!1}(e,t)):r}return[e]}function k(e,t){if(!e.classId){if(e.dataScope){let i=e.parent;if(!i)throw new Error("vertex has no parent mark");let r=[];if(i.type===Vt.Area){let s=i.vertices.indexOf(e)<i.vertices.length/2;for(let e of t){let t=s?e.vertices.slice(0,e.vertices.length/2):e.vertices.slice(e.vertices.length/2);r=r.concat(t.filter(e=>e.dataScope))}}else for(let e of t)r=r.concat(e.vertices.filter(e=>e.dataScope));return r}{let i=e.parent;if(!i)throw new Error("vertex has no parent mark");let r=i.vertices.indexOf(e),s=[];for(let e of t)s.push(e.vertices[r]);return s}}}function S(e,t){if(e.dataScope){if(!e.parent)throw new Error("segment has no parent mark");let i=[];for(let e of t)i=i.concat(e.segments);return i}{let i=e.parent;if(!i)throw new Error("segment has no parent mark");let r=i.segments.indexOf(e),s=[];for(let e of t)s.push(e.segments[r]);return s}}function T(e,t){let i=[];return I(e,t.map(e=>h(e)),i),i}function R(e,t){let i=e.children.filter(e=>e.type==Vt.Collection);if(0!==i.length)for(let e of i){let i=e;for(;i&&i.dataScope;){if(i.dataScope.hasAttribute(t))return i;i=i.children?i.children[0]:void 0}}}function O(e){return e.type==Vt.Collection?e:e.parent?O(e.parent):void 0}function I(e,t,i){if(e)if(c(e,t)&&i.push(e),e.vertices)for(let r of e.vertices.concat(e.segments))c(r,t)&&i.push(r);else if(e.children&&e.children.length>0)for(let r of e.children)I(r,t,i)}function N(e){let t=e;for(;t;){if(t.type==Vt.Scene)return t;t=t.parent}}function L(e){let t=e;for("vertex"!=t.type&&"segment"!=t.type||(t=t.parent);t.parent&&[Vt.Collection,Vt.Glyph].includes(t.parent.type);)t=t.parent;return t}function V(e,t){let i=[];if(P(e,i),t){let e={};for(let t of i)e[t.classId]=t;return Object.values(e)}return i}function P(e,t){if(E(e))t.push(e);else if(e.children&&!Object.values(Pt).includes(e.type))for(let i of e.children)P(i,t)}function M(e,t){if(e){if(t(e),e.vertices)for(let i of e.vertices)t(i);if(e.segments)for(let i of e.segments)t(i);if(e.children&&e.children.length>0)for(let i of e.children)M(i,t)}}class D{constructor(){this._refElements=[]}addRefElement(e){this._refElements.push(e)}get refElements(){return this._refElements}clearRefElements(){this._refElements=[]}}const B=Object.freeze({GRID:"grid",STACK:"stack",PACKING:"packing",FORCE:"force",DIRECTED:"directedgraph",TIDYTREE:"tidytree",TREEMAP:"treemap",STRATA:"strata",CIRCULAR:"circular",CLUSTER:"cluster"});function G(e,t){return!!(e.startsWith("h")&&[v.LEFT,v.CENTER,v.RIGHT].indexOf(t)>=0)||(!!(e.startsWith("v")&&[v.TOP,v.MIDDLE,v.BOTTOM].indexOf(t)>=0)||(console.warn("Invalid alignment:",t),!1))}class F{constructor(e){this._id=e+"_"+Mt(),this._type=e,this._inputVars=[],this._outputVars=[]}run(){}get id(){return this._id}get type(){return this._type}get inputVars(){return this._inputVars}get outputVars(){return this._outputVars}get outputVar(){return this._outputVars[0]}isIsolated(){return 0==this._inputVars.length&&0==this._outputVars.length}}const z=Object.freeze({CONDUIT:"conduit",ENCODER:"encoder",LAYOUT:"layout",LINK_PLACER:"linkRouter",CONSTRAINT:"constraint",EVAL_BBOX:"evalBBox",EVAL_REFBOUNDS:"evalRefBounds",AFFIXER:"affixer",ALIGNER:"aligner",DATA_EXTRACTOR:"dataExtractor",SCALE_BUILDER:"scaleBuilder",AXIS_PATH_PLACER:"axisPathPlacer",AXIS_TICKS_PLACER:"axisTicksPlacer",AXIS_LABELS_PLACER:"axisLabelsPlacer",AXIS_TITLE_PLACER:"axisTitlePlacer",GRIDLINES_PLACER:"gridlinesPlacer",GRID_LAYOUT:"gridLayout",STACK_LAYOUT:"stackLayout",PACK_LAYOUT:"packLayout",FORCE_LAYOUT:"forceLayout",DIRECTED_LAYOUT:"directedLayout",TIDY_TREE_LAYOUT:"tidyTreeLayout",TREEMAP_LAYOUT:"treemapLayout",STRATA_LAYOUT:"strataLayout",CIRCULAR_LAYOUT:"circularLayout",CLUSTER_LAYOUT:"clusterLayout",BIN_TRANSFORMER:"binTransformer",FILTER_TRANSFORMER:"filterTransformer",KDE_TRANSFORMER:"kdeTransformer",TARGET_EVALUATOR:"targetEvaluator",TARGET_UPDATER:"targetUpdater"});class j{constructor(e){let t=e||{};this._stops=[],this.type=Vt.LinearGradient,this.id=this.type+Mt(),this.x1="x1"in t?t.x1:0,this.x2="x2"in t?t.x2:100,this.y1="y1"in t?t.y1:0,this.y2="y2"in t?t.y2:0}toJSON(){let e={};return e.type=this.type,e.id=this.id,e.x1=this.x1,e.x2=this.x2,e.y1=this.y1,e.y2=this.y2,e.stops=this._stops,e}addStop(e,t,i){this._stops.push({offset:e,color:t,opacity:i})}get stops(){return this._stops}}const W=Object.freeze({RowFirst:"rowFirst",ColumnFirst:"columnFirst"}),U=Object.freeze({TopLeft:"topLeft",TopRight:"topRight",BottomLeft:"bottomLeft",BottomRight:"bottomRight"}),H="horizontal",Y="vertical",X="angular",q="radial",K={Left2Right:"l2r",Right2Left:"r2l",Top2Bottom:"t2b",Bottom2Top:"b2t"},Z=Object.freeze({CLOCKWISE:"clockwise",ANTI_CLOCKWISE:"anti-clockwise"}),$=Object.freeze({INWARD:"inward",OUTWARD:"outward"});class J{constructor(e,t,i,r){this.type="vertex",this._id=r,this._x=e,this._y=t,this._dataScope=void 0,this.parent=i,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 g(this.x-this.width/2,this.y-this.height/2,this.width,this.height);case"circle":return new g(this.x-this.radius,this.y-this.radius,2*this.radius,2*this.radius);default:return new g(this.x-.5,this.y-.5,1,1)}}get id(){return this.parent.id+"_v_"+this._id}_clone(e){let t=new J(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}}J.styles=["vxShape","vxWidth","vxHeight","vxRadius","vxFillColor","vxStrokeColor","vxStrokeWidth","vxOpacity"];class Q{constructor(e,t,i,r){this.type="segment",this._id=r,this.vertex1=e,this.vertex2=t,this.dataScope=void 0,this.parent=i}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}}let ee=class extends w{constructor(e){super(e),this._type="type"in e?e.type:Vt.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 J.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 i=0;i<e.length;i++)if(i!=e.length-1||e[i][0]!==e[0][0]||e[i][1]!==e[0][1]||this.type!==Vt.Path){t=new J(e[i][0],e[i][1],this,this.vertexCounter++);for(let e of J.styles)if(this[e]){let i=e.replace("vx","");t[i[0].toLowerCase()+i.slice(1)]=this[e]}this.vertices.push(t),i>0&&this.segments.push(new Q(this.vertices[i-1],this.vertices[i],this,this.segmentCounter++))}let i=e[0],r=e[e.length-1];(i[0]===r[0]&&i[1]===r[1]||this.type===Vt.Rect)&&(this.closed=!0,"fillColor"in this.styles||(this.styles.fillColor="#fff"),this.segments.push(new Q(this.vertices[this.vertices.length-1],this.vertices[0],this,this.segmentCounter++))),this._dirty=!0}copyPropertiesTo(e){e.attrs=Object.assign({},this.attrs),e.styles=Object.assign({},this.styles);for(let t of J.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 Q(e.vertices[t-1],e.vertices[t],e,e.segmentCounter++));e.closed&&e.segments.push(new Q(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 strokeDash(){return this.styles.strokeDash}set strokeDash(e){this.styles.strokeDash=e,this._dirty=!0}resize(e,t,i,r){let s=this.bounds,n=0===s.width?1:s.width,a=0===s.height?1:s.height;if("right"===i)for(let t of this.vertices)t._x=s.right-e/n*(s.right-t.x);else for(let t of this.vertices)t._x=s.left+e/n*(t.x-s.left);if("top"===r)for(let e of this.vertices)e._y=s.top+t/a*(e.y-s.top);else for(let e of this.vertices)e._y=s.bottom-t/a*(s.bottom-e.y);this._updateBounds(),this._dirty=!0}_updateBounds(){let e=[],t=[];if(this._d){const i=this._d.match(/[a-zA-Z][^a-zA-Z]*/g),r=" ";i.forEach(i=>{let s=i.slice(1).trim().split(r).map(Number);for(let[i,r]of s.entries())i%2==0?e.push(r):t.push(r)})}else e=this.vertices.map(e=>e.x),t=this.vertices.map(e=>e.y);let i=Math.min(...e),r=Math.min(...t),s=Math.max(...e),n=Math.max(...t),a=s-i,o=n-r;if(this._bounds=new g(i,r,a,o),this.type===Vt.Line||this.type===Vt.Path){let e=this.styles.strokeWidth?this.styles.strokeWidth:1;i===s?this._bounds=new g(i-e/2,r,s-i+e,n-r):r===n&&(this._bounds=new g(i,r-e/2,s-i,n-r+e))}}addVertex(e,t,i){let r=new J(e,t,this,this.vertexCounter++);this.vertices.splice(i,0,r)}sortVertices(e,t){this.vertices.sort((t,i)=>t[e]-i[e]),t&&this.vertices.reverse();for(let e=0;e<this.segments.length;e++){let t=this.segments[e];t.vertex1=this.vertices[e],t.vertex2=this.vertices[(e+1)%this.vertices.length]}this._dirty=!0}sortVerticesByData(e,t,i){let r;r=i?(t,r)=>i.indexOf(t.dataScope.getValue(e))-i.indexOf(r.dataScope.getAttrVal(e)):(t,i)=>t.dataScope.getAttrVal(e)<i.dataScope.getAttrVal(e)?-1:1,this.vertices.sort(r),t&&this.vertices.reverse();for(let e=0;e<this.segments.length;e++){let t=this.segments[e];t.vertex1=this.vertices[e],t.vertex2=this.vertices[(e+1)%this.vertices.length]}this._dirty=!0}getSVGPathData(){if(this._d)return this._d;let e=r.path(),t=this._getD3CurveFunction(this.curveMode)(e);t.lineStart();for(let e of this.vertices)t.point(e.x,e.y);return this.closed&&t.point(this.vertices[0].x,this.vertices[0].y),t.lineEnd(),e._}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(e){switch(e){case re.Natural:return r.curveNatural;case re.Basis:return r.curveBasis;case re.BumpX:return r.curveBumpX;case re.BumpY:return r.curveBumpY;case re.Linear:return r.curveLinear;case re.Step:return r.curveStep;case re.CatmullRom:return r.curveCatmullRom;case re.Cardinal:return r.curveCardinal;case re.Bundle:return r.curveBundle.beta(.5);default:return r.curveLinear}}get vxShape(){return this._vxShape}get vxWidth(){return this._vxWidth}get vxHeight(){return this._vxHeight}get vxRadius(){return this._vxRadius}get vxFillColor(){return this._vxFillColor}get vxStrokeColor(){return this._vxStrokeColor}get vxStrokeWidth(){return this._vxStrokeWidth}get vxOpacity(){return this._vxOpacity}get sourceAnchor(){return this._sourceAnchor}get targetAnchor(){return this._targetAnchor}get sourceOffset(){return this._sourceOffset}get targetOffset(){return this._targetOffset}};function te(e,t){const i=d.getSVG();let r=document.createElementNS("http://www.w3.org/2000/svg","path");r.setAttribute("d",e.getSVGPathData()),i.appendChild(r);let s=r.getTotalLength();return r.getPointAtLength(s*t)}function ie(e){return e instanceof ee&&e.source&&e.target}const re={Natural:"natural",Basis:"basis",BumpX:"bumpX",BumpY:"bumpY",Bundle:"bundle",Linear:"linear",Step:"step",CatmullRom:"CatmullRom",Cardinal:"cardinal"};function se(e,t,i){const r=e.match(/[a-zA-Z][^a-zA-Z]*/g),s=",";return r.map(e=>{const r=e[0],n=e.slice(1).trim();if("M"===r||"L"===r||"T"===r){const[e,a]=n.split(s).map(Number);return`${r}${e+t} ${a+i}`}if("C"===r){const e=n.split(s).map(Number);return`${r}${e[0]+t} ${e[1]+i} ${e[2]+t} ${e[3]+i} ${e[4]+t} ${e[5]+i}`}if("Q"===r){const e=n.split(s).map(Number);return`${r}${e[0]+t} ${e[1]+i} ${e[2]+t} ${e[3]+i}`}if("A"===r){const e=n.split(s).map(Number);return`${r}${e[0]} ${e[1]} ${e[2]} ${e[3]} ${e[4]} ${e[5]+t} ${e[6]+i}`}return"Z"===r||"z"===r?r:e}).join(" ")}class ne extends ee{constructor(e){super(e),this._type=Vt.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=ae(this._startAngle),this._er=ae(this._endAngle),this._direction="direction"in e?e.direction:Z.ANTI_CLOCKWISE;let t=this._x+this._innerRadius*Math.cos(this._sr),i=this._y-this._innerRadius*Math.sin(this._sr),r=this._x+this._innerRadius*Math.cos(this._er),s=this._y-this._innerRadius*Math.sin(this._er),n=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,i],[n,a],[o,l],[r,s]])}get type(){return 0===this._innerRadius?Vt.Pie:Vt.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=ae(this._startAngle),this._er=ae(this._endAngle),this.vertices[0]._x=this._x+this._innerRadius*Math.cos(this._sr),this.vertices[0]._y=this._y-this._innerRadius*Math.sin(this._sr),this.vertices[1]._x=this._x+this._outerRadius*Math.cos(this._sr),this.vertices[1]._y=this._y-this._outerRadius*Math.sin(this._sr),this.vertices[2]._x=this._x+this._outerRadius*Math.cos(this._er),this.vertices[2]._y=this._y-this._outerRadius*Math.sin(this._er),this.vertices[3]._x=this._x+this._innerRadius*Math.cos(this._er),this.vertices[3]._y=this._y-this._innerRadius*Math.sin(this._er),this._dirty=!0}_updateBounds(){let e=this.vertices.map(e=>e.x),t=this.vertices.map(e=>e.y),i=Math.min(...e),r=Math.min(...t),s=Math.max(...e)-i,n=Math.max(...t)-r;this._bounds=new g(i,r,s,n)}copyPropertiesTo(e){super.copyPropertiesTo(e),e._x=this._x,e._y=this._y,e._innerRadius=this._innerRadius,e._outerRadius=this._outerRadius,e._startAngle=this._startAngle,e._endAngle=this._endAngle,e._thickness=this._thickness,e._direction=this._direction,e._sr=this._sr,e._er=this._er}getSVGPathData(){let e=this._endAngle<this._startAngle?this._endAngle+360-this._startAngle:this._endAngle-this._startAngle,t=e>180?1:0;return["M "+this.vertices[0].x+", "+this.vertices[0].y,"L "+this.vertices[1].x+", "+this.vertices[1].y,"A "+[this._outerRadius,this._outerRadius,e,t,0,this.vertices[2].x,this.vertices[2].y].join(" "),"L "+this.vertices[3].x+", "+this.vertices[3].y,"A "+[this._innerRadius,this._innerRadius,e,t,1,this.vertices[0].x,this.vertices[0].y].join(" ")].join(" ")}}function ae(e){return e*Math.PI/180}function oe(e){return 180*e/Math.PI}function le(e){return(e%360+360)%360}function he(e,t,i,r){let s=e-i,n=r-t;return Math.atan2(n,s)*(180/Math.PI)}class ce{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 ce(this._dt);for(let e in this._attr2value)t=t.cross(e,this._attr2value[e]);for(let i in e._attr2value)t=t.cross(i,e._attr2value[i]);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 i=this.clone();return i._attr2value[e]=t,i._updateTuples(e,t),i}derive(e){let t=Object.assign({},this._attr2value);for(let i in e)t[i]=e[i];let i=new ce(this._dt);for(let e in t)i._attr2value[e]=t[e],i._updateTuples(e,t[e]);return i}clone(){let e=new ce(this._dt);return e._attr2value=Object.assign({},this._attr2value),e._tuples=this._tuples.map(e=>e),e}getAttrVal(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(e,t){let i=this._tuples.map(t=>t[e]);switch(t){case ue.Max:return Math.max(...i);case ue.Min:return Math.min(...i);case ue.Avg:case ue.Mean:return r.mean(i);case ue.Median:return r.median(i);case ue.Count:return i.length;case ue.Percentile25:return r.quantile(i,.25);case ue.Percentile75:return r.quantile(i,.75);case ue.Sum:default:return r.sum(i)}}_updateTuples(e,t){this._tuples=this._tuples.filter(i=>i[e]==t)}get tuples(){return this._tuples}}function de(e){return"vertex"==e.type||"segment"==e.type?e.dataScope?e.dataScope:e.parent.dataScope:e.dataScope}const ue={Max:"max",Min:"min",Avg:"avg",Median:"median",Sum:"sum",Count:"count",Mean:"mean",Percentile25:"percentile 25",Percentile75:"percentile 75"};class pe{constructor(e,t){this._id=Vt.TreeData+Mt(),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 Dt(this._nodeList,"nodes"),this._linkTable=new Dt(this._linkList,"links"),this._nodeTable.tree=this,this._linkTable.tree=this}get nodeTable(){return this._nodeTable}get linkTable(){return this._linkTable}_traverse(e,t,i,r=0){let s={};me in e||(e[me]="n"+t.length),t.push(s),e._depth=r;for(let n in e)if("children"==n&&e[n]&&e[n].length>0)for(let s of e[n]){let n=this._traverse(s,t,i,r+1);i.push({parent:e[me],child:n})}else s[n]=e[n];return this._nodeHash[s[me]]=s,s[me]}getNodeDataScope(e){return new ce(this._nodeTable).cross(Gt,e[Gt])}getNode(e){return this._nodeHash[e]}getRoot(){return this._nodeTable.data[0]}getChildren(e){let t=e[me],i=[],r=this._linkTable.data,s=this._nodeTable.data;for(let e in r)if(r[e].parent==t){let t=r[e].child,n=s.findIndex(e=>e[me]==t);i.push(s[n])}return i}getParent(e){let t=e[me],i=this._linkTable.data,r=this._nodeTable.data;for(let e in i)if(i[e].child==t){let t=i[e].parent,s=r.findIndex(e=>e[me]==t);return r[s]}}}function _e(e){return e.dataScope._dt.tree}class fe{constructor(e,t){this._id=Vt.NetworkData+Mt(),this.initialize(e,t)}initialize(e,t){this.url=t,this._nodeTable=new Dt(e.nodes,this._id+"_nodes"),this._linkTable=new Dt(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[me]]=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[me],i=this._rawLinks,r=[];for(let e in i)i[e].target!==t&&i[e].source!==t||r.push(i[e]);return r}buildNodeHierarchy(e){let t={};return t[me]="root",ye(t,this._rawNodes,e),new pe(t,this.url)}}function ge(e){return e.dataScope._dt.graph}function ye(e,t,i){if(0===t.length||0===i.length)return;"children"in e||(e.children=[]);let r={};for(let e of t){let t=e[i[0]];t in r||(r[t]=[]),r[t].push(e)}if(1===i.length)for(let t in r){let i={children:r[t]};i[me]=t,e.children.push(i)}else for(let t in r){let s={};s[me]=t,e.children.push(s),ye(s,r[t],i.slice(1))}}const me="id";function be(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 xe=Object.freeze({Boolean:"boolean",Integer:"integer",Number:"number",Date:"date",String:"string"});function ve(e){var t=Object.values(xe);for(let i=0;i<e.length;i++){let r=e[i];if(null!=r){for(let e=0;e<t.length;e++)we[t[e]](r)||(t.splice(e,1),e-=1);if(1==t.length)return t[0]}}return t[0]}const we={boolean:function(e){return"true"===e||"false"===e||!0===e||!1===e||"[object Boolean]"==toString.call(e)},integer:function(e){return we.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 Ee(e,t){let i={};switch(t){case xe.Boolean:i.trueCount=e.filter(e=>e).length,i.falseCount=e.filter(e=>!e).length;break;case xe.Date:i.min=r.min(e),i.max=r.max(e),i.extent=[i.min,i.max],i.unique=[...new Set(e)];break;case xe.String:i.unique=[...new Set(e)];break;default:i.min=r.min(e),i.max=r.max(e),i.extent=[i.min,i.max],i.mean=r.mean(e),i.median=r.median(e),i.unique=[...new Set(e)]}return i}function Ae(e,t,i,r,s){let n=s.getAttributeType(i);if(n!=xe.String&&n!=xe.Date&&n!=xe.Number&&n!=xe.Integer)throw new Error("Densify only works on a string or date attribute: "+i+" is "+n);if(!ke(t))throw new Error("The "+t.type+" is not dividable");switch(t.type){case Vt.Line:return function(e,t,i){let r,s,n=C(e);for(let a of n){let n=a.dataScope?a.dataScope:new ce(i),o=i.getUniqueAttributeValues(t).map(e=>n.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 J.styles)a[e]&&(l[e]=a[e]);let h=a.vertices[0].x,c=a.vertices[0].y,d=[],u=a.vertices[1].x-h,p=a.vertices[1].y-c;for(let e=0;e<o.length;e++)d.push([h+e*u/(o.length-1),c+e*p/(o.length-1)]);l.vertices=d,l.type="path";let _=Rt(l);s||(s=_.id),_._classId=s,_.dataScope=n,_._updateBounds(),_._refBounds=_.bounds.clone();let f=a.parent;f.addChild(_),f.removeChild(a);for(let[e,t]of _.vertices.entries())t.dataScope?t.dataScope=t.dataScope.merge(o[e]):t.dataScope=o[e];a==e&&(r=_)}return r}(t,i,s);case Vt.Circle:return function(e,t,i){let r,s,n=C(e),a=i.getAttributeType(t);for(let o of n){let n=o.dataScope?o.dataScope:new ce(i),l=i.getUniqueAttributeValues(t).map(e=>n.cross(t,e));l=a==xe.Number?l:l.filter(e=>!e.isEmpty());let h=l.length;if(h<3)throw new Error("INSUFFICIENT_DATA_SCOPES");let c=90,d=360/h,u=[],p=[],_=-1;for(let e=0;e<l.length;e++){let t=c+_*e*d;p[e]=t;let i=Ce(o.x,o.y,o.radius,p[e]);u.push(i)}let f=Object.assign({},o.styles);f.vertices=u,f.type="polygon",f.x=o.x,f.y=o.y,f.radius=o.radius;let g=Rt(f);s||(s=g.id),g._classId=s,g.dataScope=n;let y=o.parent;y.addChild(g),y.removeChild(o);for(let[e,t]of g.vertices.entries())t._polarAngle=p[e],e>=l.length?t.dataScope=n.merge(l[2*l.length-1-e]):t.dataScope=n.merge(l[e]);o===e&&(r=g)}return r}(t,i,s);case Vt.Rect:return function(e,t,i,r){let s,n,a=C(e),o=t||H;if(o!=H&&o!=Y)throw new Error("Unknown orientation: "+o);for(let t of a){let a=r.getAttributeType(i),l=t.dataScope?t.dataScope:new ce(r),h=r.getUniqueAttributeValues(i).map(e=>l.cross(i,e));h=a==xe.Number?h:h.filter(e=>!e.isEmpty()),1===h.length&&h.push(h[0].clone()),a!=xe.Number&&a!=xe.Date||h.sort((e,t)=>e._attr2value[i]>t._attr2value[i]?1:-1);let c=Object.assign({},t.styles),d=t.vertices[0].x,u=t.vertices[0].y,p=t.vertices[t.vertices.length-2].x,_=t.vertices[t.vertices.length-2].y,f=[],g=p-d,y=_-u;for(let e=0;e<h.length;e++)f.push(o==Y?[p,u+e*y/(h.length-1)]:[d+e*g/(h.length-1),u]);for(let e=0;e<h.length;e++)f.push(o==Y?[d,u+(h.length-1-e)*y/(h.length-1)]:[d+(h.length-1-e)*g/(h.length-1),_]);c.vertices=f,c.type="area";let m=Rt(c);n||(n=m.id),m._classId=n,m.dataScope=l,m.orientation=o,m.baseline=o===H?v.BOTTOM:v.LEFT;let b=t.parent;b.addChild(m),b.removeChild(t);for(let[e,t]of m.vertices.entries())e>=h.length?t.dataScope=l.merge(h[2*h.length-1-e]):t.dataScope=l.merge(h[e]);t===e&&(s=m)}return s}(t,r,i,s)}}function Ce(e,t,i,r){return[i*Math.cos(ae(r))+e,t-i*Math.sin(ae(r))]}function ke(e){if([Vt.Line,Vt.Circle,Vt.Rect,Vt.Area].indexOf(e.type)<0)return!1;if(e.dataScope){let t=C(e,e.scene);for(let e of t)if(e.dataScope.numTuples>1)return!0;return!1}return!0}class Se{constructor(e){this._id="v_"+Mt(),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 F)return e.fromNode;return null}isIsolated(){return 0==this._incomings.length&&0==this._outgoings.length}}const Te=Object.freeze({CHANNEL:"channel",PROPERTY:"property",ATTRIBUTE:"attribute",ITEMS:"items",DATASCOPE:"datascope",ATTR_VALUE:"dataValue",BOUNDS:"bounds",SCALE:"scale",CONDITION_RESULT:"conditionResult",AFFIXATION:"affixation",ALIGNMENT:"alignment",EVT_CTX:"evtContext"});class Re extends Se{constructor(e,t,i){super(e),this._channel=t,this._elem=i}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 i=e.scene._encodings[Pe(e)],r=[];i&&(r=r.concat(Object.values(i)));{let t=e.scene;for(let i in t._encodings){let s=i.split("_");s.pop(),s.join("_")===e.classId&&(r=r.concat(Object.values(t._encodings[i])))}}return r}function Le(e,t,i){for(let r in i._encodings){let s=i._encodings[r];if(s[t]&&s[t].attribute==e)return s[t]}return null}function Ve(e,t){let i=e.scene._encodings[Pe(e)];return i&&i[t]?i[t]:null}function Pe(e){if(Array.isArray(e))return e.map(e=>Pe(e)).join("_");if(e.classId)return e.classId;if("vertex"==e.type&&e.dataScope){if(e.parent.type===Vt.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 Me(e,t){if(0==e.children.length)return[];let i=N(e),r=e.type===Vt.Composite?e.children:[e.children[0]],s=Object.keys(i._encodings),n=[];for(let e of r){let t=e;for(;t;){if(t.classId&&n.indexOf(t.classId)<0&&n.push(t.classId),t.type===Vt.Glyph){t.children.forEach(e=>n.push(e.classId));break}if(!t.children)break;t=t.children[0]}}let a=[];for(let e of s)for(let r of n)0===e.indexOf(r)&&i._encodings[e][t]&&a.push(i._encodings[e][t]);return a}function De(e){let t=Ve(e,"y"),i=Ve(e,"height");return t||i&&i.scales[0].domain[0]<0}function Be(e){let t=Ve(e,"x"),i=Ve(e,"width");return t||i&&i.scales[0].domain[0]<0}function Ge(e,t){let i=function(e){let t=e.parent,i=[];for(;t.type!==Vt.Scene;)i.push(t),t=t.parent;return i}(e);for(let e of i)if(Ve(e,t))return!1;return i.length>=2?i[i.length-2]:e}function Fe(e,t,i){switch(e.type){case Vt.Rect:case Vt.Path:case Vt.Line:case Vt.Area:!function(e,t,i){for(let r of e.vertices)ze(r,t,i);e._updateBounds(),e._refBounds&&e._refBounds.translate(t,i)}(e,t,i),0===t&&0===i||(e._dirty=!0);break;case Vt.Group:case Vt.Collection:case Vt.Glyph:!function(e,t,i){for(let r of e.children)Fe(r,t,i);e._layout&&(void 0!==e._layout._left&&(e._layout._left+=t),void 0!==e._layout._top&&(e._layout._top+=i),e._layout._cellBounds&&e._layout._cellBounds.forEach(e=>e.translate(t,i)));e._updateBounds(),e._refBounds&&e._refBounds.translate(t,i)}(e,t,i);break;case"segment":!function(e,t,i){ze(e.vertex1,t,i),ze(e.vertex2,t,i)}(e,t,i),0===t&&0===i||(e.parent._dirty=!0);break;case"vertex":ze(e,t,i),0===t&&0===i||(e.parent._dirty=!0);break;default:!function(e,t,i){e._x+=t,e._y+=i,e._updateBounds(),e._refBounds&&e._refBounds.translate(t,i)}(e,t,i),0===t&&0===i||(e._dirty=!0)}}function ze(e,t,i){e._x+=t,e._y+=i}function je(e,t,i){switch(t){case"x":Ue(e,i);break;case"y":He(e,i);break;case"width":!function(e,t){e.resize(t,e.height)}(e,i);break;case"height":!function(e,t){e.resize(e.width,t)}(e,i);break;case"radius":e.radius=i;break;case"strength":e._strength=i;break;case"area":e.type===Vt.Circle?e.radius=Math.sqrt(i/Math.PI):e.type===Vt.Rect&&e.resize(Math.sqrt(i),Math.sqrt(i)),e._updateBounds();break;case"text":e._text=i;break;case"curveMode":e.curveMode=i;break;case"baseline":e.baseline=i;break;case"angle":[Vt.Arc,Vt.Pie].includes(e.type)&&function(e,t){e._endAngle=le(e._startAngle+t),e._sr=ae(e._startAngle),e._er=ae(e._endAngle),e.vertices[0]._x=e._x+e._innerRadius*Math.cos(e._sr),e.vertices[0]._y=e._y-e._innerRadius*Math.sin(e._sr),e.vertices[1]._x=e._x+e._outerRadius*Math.cos(e._sr),e.vertices[1]._y=e._y-e._outerRadius*Math.sin(e._sr),e.vertices[2]._x=e._x+e._outerRadius*Math.cos(e._er),e.vertices[2]._y=e._y-e._outerRadius*Math.sin(e._er),e.vertices[3]._x=e._x+e._innerRadius*Math.cos(e._er),e.vertices[3]._y=e._y-e._innerRadius*Math.sin(e._er)}(e,i);break;case"startAngle":!function(e,t){let i=e.angle;e._startAngle=t,e._endAngle=le(e._startAngle+i),e._sr=ae(e._startAngle),e._er=ae(e._endAngle),e.vertices[0]._x=e._x+e._innerRadius*Math.cos(e._sr),e.vertices[0]._y=e._y-e._innerRadius*Math.sin(e._sr),e.vertices[1]._x=e._x+e._outerRadius*Math.cos(e._sr),e.vertices[1]._y=e._y-e._outerRadius*Math.sin(e._sr),e.vertices[2]._x=e._x+e._outerRadius*Math.cos(e._er),e.vertices[2]._y=e._y-e._outerRadius*Math.sin(e._er),e.vertices[3]._x=e._x+e._innerRadius*Math.cos(e._er),e.vertices[3]._y=e._y-e._innerRadius*Math.sin(e._er)}(e,i);break;case"thickness":!function(e,t){We(e,e._innerRadius+t)}(e,i);break;case"innerRadius":!function(e,t){e._innerRadius=t,e.vertices[0]._x=e._x+e._innerRadius*Math.cos(e._sr),e.vertices[0]._y=e._y-e._innerRadius*Math.sin(e._sr),e.vertices[3]._x=e._x+e._innerRadius*Math.cos(e._er),e.vertices[3]._y=e._y-e._innerRadius*Math.sin(e._er)}(e,i);break;case"outerRadius":We(e,i);break;case"radialDistance":{let t=Ce(e.parent.x,e.parent.y,i,e.polarAngle);Ue(e,t[0]),He(e,t[1]);break}case"visibility":e.visibility=i;break;case"src":e.src=i;break;default:if("vertex"===e.type)e[t]=i;else if(e instanceof mt)for(let r of e.children)je(r,t,i);else e.styles[t]=i}"vertex"===e.type?e.parent._dirty=!0:e._dirty=!0}function We(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 Ue(e,t){"vertex"==e.type?e._x=t:Fe(e,t-e.x,0)}function He(e,t){"vertex"==e.type?e._y=t:Fe(e,0,t-e.y)}class Ye extends ee{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,i,r){e!==this.width&&("right"===i?(this.vertices[1]._x=this.refBounds.right,this.vertices[2]._x=this.refBounds.right,this.vertices[0]._x=this.vertices[1]._x-e,this.vertices[3]._x=this.vertices[0]._x):(this.vertices[0]._x=this.refBounds.left,this.vertices[3]._x=this.refBounds.left,this.vertices[1]._x=this.vertices[0]._x+e,this.vertices[2]._x=this.vertices[1]._x)),t!==this.height&&("top"===r?(this.vertices[0]._y=this.refBounds.top,this.vertices[1]._y=this.refBounds.top,this.vertices[3]._y=this.vertices[0]._y+t,this.vertices[2]._y=this.vertices[3]._y):(this.vertices[2]._y=this.refBounds.bottom,this.vertices[3]._y=this.refBounds.bottom,this.vertices[0]._y=this.vertices[3]._y-t,this.vertices[1]._y=this.vertices[0]._y)),this._dirty=!0}get leftSegment(){return this.segments[3]}get rightSegment(){return this.segments[1]}get topSegment(){return this.segments[0]}get bottomSegment(){return this.segments[2]}}class Xe extends ee{constructor(e){super(e),this._type=Vt.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 Q(this.vertices[this.vertices.length-1],this.vertices[0],this,this.segmentCounter++))}get topLeftVertex(){return this._orientation===H?this.vertices[0]:this.vertices[this.vertices.length-1]}get bottomLeftVertex(){return this._orientation===H?this.vertices[this.vertices.length-1]:this.vertices[this.vertices.length/2]}get topRightVertex(){return this._orientation===H?this.vertices[this.vertices.length/2-1]:this.vertices[0]}get bottomRightVertex(){return this._orientation===H?this.vertices[this.vertices.length/2]:this.vertices[this.vertices.length/2-1]}get baseline(){return this._baseline}set baseline(e){this._baseline=e,this._dirty=!0}get orientation(){return this._orientation}set orientation(e){this._orientation=e,this._dirty=!0}get firstVertexPair(){return[this.vertices[0],this.vertices[this.vertices.length-1]]}get width(){return this.vertices[this.vertices.length/2].x-this.vertices[0].x}get height(){return this.vertices[this.vertices.length/2].y-this.vertices[0].y}get left(){return this.vertices[0].x}get top(){return this.vertices[0].y}copyPropertiesTo(e){super.copyPropertiesTo(e),e._baseline=this._baseline,e._orientation=this._orientation}getSVGPathData(){return super.getSVGPathData()+" z"}}class qe extends Se{constructor(e,t){super(e),this._encs={},this._encs[t.channel+"_"+Pe(t.element)]=t,this._initialized=!1}addLinkedEncoding(e){this._encs[e.channel+"_"+Pe(e.element)]=e}getEncoding(e,t){let i=e+"_"+Pe(t);return this._encs[i]}get encodings(){return Object.values(this._encs)}get initialized(){return this._initialized}set initialized(e){this._initialized=e}}class Ke extends Se{constructor(e,t,i){super(e),this._result=t,this._condEnc=i}get result(){return this._result}get conditionalEncoding(){return this._condEnc}}class Ze extends F{constructor(e){super(e)}storeValues(e,t){this._storedValues={};let i=C(e);for(let e of i)this._storedValues[e.id]=e[t]}_restoreValues(e){let t=this.outputVar.channel;e.forEach(e=>{e.styles[t]!==this._storedValues[e.id]&&(e._dirty=!0,e.styles[t]=this._storedValues[e.id])})}run(){super.run();let e=this.inputVars.find(e=>e instanceof qe),t=this.outputVar,i=C(t.element),r=["x","y","width","height","radius"].includes(t.channel);if(e){let i=e.getEncoding(t.channel,t.element);for(let e of i.scales){let t=i.getElements(e);this._doMapping(t,e,i.attrValues,i),r&&this._updateRefBounds(t,e,i)}}else this._restoreValues(i);let s=this._getUsableCondEncodings();if(s.length>0&&this._doCondEncoding(i,s.map(e=>e.conditionalEncoding)),r){x(["vertex","segment"].includes(t.element.type)?t.element.parent:t.element)}}_updateRefBounds(e,t,i){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,v.CENTER),e._refBounds.setHeight(2*t.rangeExtent,v.MIDDLE)});break;case"x":"vertex"!=e[0].type&&"segment"!=e[0].type||e.forEach(e=>{let r=e.parent._refBounds;e.parent._refBounds=new g(i.flipScale?t.range[1]:t.range[0],r.top,t.rangeExtent,r.height)});break;case"y":"vertex"!=e[0].type&&"segment"!=e[0].type||e.forEach(e=>{let r=e.parent._refBounds;e.parent._refBounds=new g(r.left,i.flipScale?t.range[0]:t.range[1],r.width,t.rangeExtent)})}}_doMapping(e,t,i,r){switch(this.outputVar.channel){case"width":t.domain[0]<0&&e[0]instanceof Ye?function(e,t,i){for(let r=0;r<e.length;r++){let s=e[r],n=s.refBounds.left+t.map(0),a=s.refBounds.left+t.map(i[s.id]);Fe(s.leftSegment,n-s.leftSegment.x,0),Fe(s.rightSegment,a-s.rightSegment.x,0)}}(e,t,i):t.domain[0]<0&&e[0]instanceof Xe||(e[0].type===Vt.Area?function(e,t,i){let r=e[0].baseline;if(e[0].orientation===Y)switch(r){case"left":for(let r of e)C(r.topLeftVertex,r).forEach(e=>je(e,"x",r.refBounds.left)),C(r.topRightVertex,r).forEach(e=>je(e,"x",r.refBounds.left+t.map(i[e.id])));break;case"right":for(let r of e)C(r.topLeftVertex,r).forEach(e=>je(e,"x",r.refBounds.right-t.map(i[e.id]))),C(r.topRightVertex,r).forEach(e=>je(e,"x",r.refBounds.right));break;case"center":console.log("center");for(let r of e)C(r.topLeftVertex,r).forEach(e=>je(e,"x",r.refBounds.center-t.map(i[e.id])/2)),C(r.topRightVertex,r).forEach(e=>je(e,"x",r.refBounds.center+t.map(i[e.id])/2))}}(e,t,i):this._doStandardMapping(e,t,i));break;case"height":t.domain[0]<0&&e[0]instanceof Ye?function(e,t,i){for(let r=0;r<e.length;r++){let s=e[r],n=s.refBounds.bottom-t.map(0),a=s.refBounds.bottom-t.map(i[s.id]);Fe(s.bottomSegment,0,n-s.bottomSegment.y),Fe(s.topSegment,0,a-s.topSegment.y)}}(e,t,i):t.domain[0]<0&&e[0]instanceof Xe?function(e,t,i){for(let r of e){let e=k(r.topLeftVertex,[r]);for(let s of e)je(s,"y",r.refBounds.bottom-t.map(i[s.id]));k(r.bottomLeftVertex,[r]).forEach(e=>je(e,"y",r.refBounds.bottom-t.map(0)))}}(e,t,i):e[0].type===Vt.Area?function(e,t,i){let r=e[0].baseline;if(e[0].orientation===H)switch(r){case"top":for(let r of e)C(r.bottomLeftVertex,r).forEach(e=>je(e,"y",r.refBounds.top+t.map(i[e.id]))),C(r.topLeftVertex,r).forEach(e=>je(e,"y",r.refBounds.top));break;case"middle":for(let r of e)C(r.topLeftVertex,r).forEach(e=>je(e,"y",r.refBounds.middle-t.map(i[e.id])/2)),C(r.bottomLeftVertex,r).forEach(e=>je(e,"y",r.refBounds.middle+t.map(i[e.id])/2));break;default:for(let r of e)C(r.topLeftVertex,r).forEach(e=>je(e,"y",r.refBounds.bottom-t.map(i[e.id]))),C(r.bottomLeftVertex,r).forEach(e=>je(e,"y",r.refBounds.bottom))}}(e,t,i):this._doStandardMapping(e,t,i);break;case"text":this._doTextMapping(e,i);break;case"fillGradient":!function(e,t,i,r){for(let s of e){let e=s.vertices.map(e=>i[e.id]),n=Math.min(...e),a=Math.max(...e),o="horizontal"===s.orientation?new j({x1:0,y1:100,x2:0,y2:0}):new j({x1:0,y1:0,x2:100,y2:0});if(o.addStop(0,t.map(n),1),r._mapping){let e=Object.keys(r._mapping).map(e=>parseFloat(e)).sort();for(let i of e)i>n&&i<a&&o.addStop(100*(i-n)/(a-n),t.map(i),1)}else"divergingColor"===t.type&&o.addStop(100*-n/(a-n),t.map(0),1);"sequentialColor"===t.type&&o.addStop(100*-n/(a-n),t.map(0),1),o.addStop(100,t.map(a),1),s.fillColor=o}}(e,t,i,r);break;default:this._doStandardMapping(e,t,i)}}_doTextMapping(e,t){let i=this.outputVar.channel;e.forEach(e=>{je(e,i,t[e.id])})}_doStandardMapping(e,t,i){let r=this.outputVar.channel;e.forEach(e=>{let s=t.map(i[e.id]);je(e,r,s),e instanceof ee&&e.firstVertex&&e.firstVertex.shape&&"strokeColor"===r&&e.vertices.forEach(e=>e.fillColor=s)})}_doCondEncoding(e,t){let i=e[0].scene;for(let r of e){let e=t.map(e=>e.evalResult.getValue(r.id)).every(e=>e||void 0===e),s=t[0].eventContext;t[0].stylingFunction(e,s,r,i)}}_updateElement(e,t,i,r){let s;"object"==typeof r&&e.triggerElement?"property"in r?s=e.triggerElement[r.property]:"attribute"in r&&(s=e.triggerElement.dataScope.getAttrVal(r.attribute)):s=r,["x","y"].includes(i)&&"offset"in r&&(s+=r.offset),je(t,i,s)}_getUsableCondEncodings(){return this.inputVars.filter(e=>e instanceof Ke)}}class $e extends Se{constructor(e,t,i){super(e),this._property=t,this._elem=i}get property(){return this._property}get element(){return this._elem}}function Je(e){return e in Qe?Qe[e]:e}const Qe=Object.freeze({numCols:"layoutParameter",numRows:"layoutParameter",startCorner:"layoutParameter",direction:"layoutParameter"}),et=Object.freeze({AXIS_ORIENTATION:"axisOrientation",AXIS_PATH_POSITION:"axisPathPosition",AXIS_TICK_SIZE:"axisTickSize",AXIS_TICK_OFFSET:"axisTickOffset",AXIS_TICKS_POSITION:"axisTicksPosition",AXIS_LABELS_POSITION:"axisLabelsPosition",AXIS_TITLE_POSITION:"axisTitlePosition",AXIS_LABEL_OFFSET:"axisLabelOffset",AXIS_LABEL_FORMAT:"axisLabelFormat",AXIS_FONT_SIZE:"axisFontSize",LEGEND_POSITION:"legendPosition",GRIDLINES_POSITION:"gridlinesPosition",INCLUDE_ZERO:"includeZero",FLIP_SCALE:"flipScale",RANGE_START:"rangeStart",RANGE_EXTENT:"rangeExtent",BASE_LINE:"baseline",LAYOUT_PARAMETER:"layoutParameter",CHILDREN_ORDER:"childrenOrder",TRANSFORM:"transform"});function tt(e,t){if(t.findVariable(Te.BOUNDS,[e]))return;let i=t.getVariable(Te.BOUNDS,e),r=t.createOneWayDependency(z.EVAL_BBOX);switch(t.connect(r,i),e.type){case Vt.Circle:case Vt.Polygon:{let i=t.getVariable(Te.CHANNEL,"x",e),s=t.getVariable(Te.CHANNEL,"y",e),n=t.getVariable(Te.CHANNEL,"radius",e),a=t.getVariable(Te.CHANNEL,"area",e);t.connect(n,r),t.connect(i,r),t.connect(s,r),t.connect(a,r);break}case Vt.Area:case Vt.Line:case Vt.BezierCurve:case Vt.Path:case Vt.Image:{let i=t.getVariable(Te.CHANNEL,"x",e),s=t.getVariable(Te.CHANNEL,"y",e),n=t.getVariable(Te.CHANNEL,"width",e),a=t.getVariable(Te.CHANNEL,"height",e);t.connect(i,r),t.connect(s,r),t.connect(n,r),t.connect(a,r);break}case Vt.Rect:{let i=t.getVariable(Te.CHANNEL,"x",e),s=t.getVariable(Te.CHANNEL,"y",e),n=t.getVariable(Te.CHANNEL,"width",e),a=t.getVariable(Te.CHANNEL,"height",e),o=t.getVariable(Te.CHANNEL,"area",e);t.connect(i,r),t.connect(s,r),t.connect(n,r),t.connect(a,r),t.connect(o,r);break}case Vt.SimpleText:case Vt.RichText:{let i=t.getVariable(Te.CHANNEL,"x",e),s=t.getVariable(Te.CHANNEL,"y",e),n=t.getVariable(Te.CHANNEL,"text",e);t.connect(i,r),t.connect(s,r),t.connect(n,r);break}case Vt.Ring:{let i=t.getVariable(Te.CHANNEL,"x",e),s=t.getVariable(Te.CHANNEL,"y",e),n=t.getVariable(Te.CHANNEL,"innerRadius",e),a=t.getVariable(Te.CHANNEL,"outerRadius",e);t.connect(i,r),t.connect(s,r),t.connect(n,r),t.connect(a,r);break}case Vt.Pie:case Vt.Arc:{let i=t.getVariable(Te.CHANNEL,"x",e),s=t.getVariable(Te.CHANNEL,"y",e),n=t.getVariable(Te.CHANNEL,"innerRadius",e),a=t.getVariable(Te.CHANNEL,"outerRadius",e),o=t.getVariable(Te.CHANNEL,"startAngle",e),l=t.getVariable(Te.CHANNEL,"endAngle",e),h=t.getVariable(Te.CHANNEL,"angle",e),c=t.getVariable(Te.CHANNEL,"thickness",e);t.connect(i,r),t.connect(s,r),t.connect(n,r),t.connect(a,r),t.connect(o,r),t.connect(l,r),t.connect(h,r),t.connect(c,r);break}}r.run()}function it(e,t){let i=t.findVariablesByElement(e);for(let e in i){let r=i[e];for(let e of r)t.deleteVariable(e)}}function rt(e,t){let i=t.findVariable(Te.CHANNEL,[e.channel,e.element]);i||console.warn("cannot find encoding to remove from the dep graph");let r=i.incomingDataflow;t.deleteOperator(r)}function st(e,t){if(e.type===Vt.Axis){let i=t.findVariable(Te.PROPERTY,[et.AXIS_PATH_POSITION,e]).incomingDataflow;t.deleteOperator(i),i=t.findVariable(Te.PROPERTY,[et.AXIS_TICKS_POSITION,e]).incomingDataflow,t.deleteOperator(i),i=t.findVariable(Te.PROPERTY,[et.AXIS_LABELS_POSITION,e]).incomingDataflow,t.deleteOperator(i)}else if(e.type===Vt.Gridlines){let i=t.findVariable(Te.PROPERTY,[et.GRIDLINES_POSITION,e]).incomingDataflow;t.deleteOperator(i)}}function nt(e,t){if(t.findVariable(Te.BOUNDS,[e]))return;let i=t.getVariable(Te.BOUNDS,e),r=t.getVariable(Te.CHANNEL,"x",e),s=t.getVariable(Te.CHANNEL,"y",e),n=t.getVariable(Te.CHANNEL,"width",e),a=t.getVariable(Te.CHANNEL,"height",e),o=t.createOneWayDependency(z.EVAL_BBOX);t.connect(r,o),t.connect(s,o),t.connect(n,o),t.connect(a,o),t.connect(o,i),o.run()}function at(e,t){let i=t.getVariable(Te.BOUNDS,e),r=t.getVariable(Te.CHANNEL,"x",e),s=t.getVariable(Te.CHANNEL,"y",e),n=t.getVariable(Te.CHANNEL,"width",e),a=t.getVariable(Te.CHANNEL,"height",e),o=t.createOneWayDependency(z.EVAL_BBOX);t.connect(r,o),t.connect(s,o),t.connect(n,o),t.connect(a,o),t.connect(o,i),o.run()}function ot(e,t,i){let r=i.getVariable(Te.BOUNDS,e),s=i.getVariable(Te.BOUNDS,t),n=i.getIncomingDataflowOperator(z.EVAL_BBOX,r),a=s.outgoingEdges.find(e=>e.fromNode===s&&e.toNode===n);if(a&&i.disconnect(s,n,a),e.layout){let r=i.getVariable(Te.CHANNEL,"x",t),s=i.getIncomingDataflowOperator(ct(e.layout.type),r);s&&i.deleteOperator(s)}}function lt(e,t,i){let r=i.getVariable(Te.BOUNDS,e),s=i.getVariable(Te.BOUNDS,t),n=i.getIncomingDataflowOperator(z.EVAL_BBOX,r);i.connect(s,n),i.connect(n,r),e.layout&&ut(e,e.layout,i)}function ht(e,t){let i=t.getVariable(Te.BOUNDS,e),r=t.getVariable(Te.CHANNEL,"x",e),s=t.getVariable(Te.CHANNEL,"y",e),n=t.getIncomingDataflowOperator(z.EVAL_BBOX,i);t.connect(r,n),t.connect(s,n);for(let i of e.children)t.connect(t.getVariable(Te.BOUNDS,i),n);t.connect(n,i),n.run()}function ct(e){switch(e){case B.GRID:return z.GRID_LAYOUT;case B.STACK:return z.STACK_LAYOUT;case B.PACKING:return z.PACK_LAYOUT;case B.FORCE:return z.FORCE_LAYOUT;case B.DIRECTED:return z.DIRECTED_LAYOUT;case B.TIDYTREE:return z.TIDY_TREE_LAYOUT;case B.TREEMAP:return z.TREEMAP_LAYOUT;case B.STRATA:return z.STRATA_LAYOUT;case B.CIRCULAR:return z.CIRCULAR_LAYOUT;case B.CLUSTER:return z.CLUSTER_LAYOUT}}function dt(e,t,i){let r=i.getVariable(Te.PROPERTY,et.CHILDREN_ORDER,e),s=i.getOutgoingDataflowOperator(ct(t.type),r);i.deleteOperator(s)}function ut(e,t,i){let r=t?t.type:"none",s=r===B.TREEMAP?V(e)[0]:e.children[0];if(!s)return;let n=i.getVariable(Te.CHANNEL,"width",s),a=i.getVariable(Te.CHANNEL,"height",s),o=i.getVariable(Te.PROPERTY,et.CHILDREN_ORDER,e),l=i.getVariable(Te.CHANNEL,"x",s),h=i.getVariable(Te.CHANNEL,"y",s),c=i.getVariable(Te.CHANNEL,"visibility",s),d=i.getVariable(Te.PROPERTY,et.LAYOUT_PARAMETER,t),u=i.getOutgoingDataflowOperator(ct(r),o);if(i.connect(n,u),i.connect(a,u),i.connect(o,u),i.connect(d,u),i.connect(c,u),i.connect(u,l),i.connect(u,h),i.disconnectChannelVarFromBBoxOperator(n),i.disconnectChannelVarFromBBoxOperator(a),s.type===Vt.Arc||s.type===Vt.Pie){let e=i.getVariable(Te.CHANNEL,"angle",s),t=i.getVariable(Te.CHANNEL,"thickness",s);i.connect(e,u),i.connect(t,u)}else if(s.type===Vt.Circle){let e=i.getVariable(Te.CHANNEL,"area",s),t=i.getVariable(Te.CHANNEL,"radius",s);i.connect(e,u),i.connect(t,u),i.disconnectChannelVarFromBBoxOperator(e),i.disconnectChannelVarFromBBoxOperator(t)}else if(s.type===Vt.Rect){let e=i.getVariable(Te.CHANNEL,"area",s);i.connect(e,u),i.disconnectChannelVarFromBBoxOperator(e)}if(u.run(),s.links&&pt(s,i),s.children&&s.children[0]){let e=i.getVariable(Te.BOUNDS,s.children[0]),t=i.getVariable(Te.CHANNEL,"x",s).incomingDataflow;t&&i.connect(e,t),i.disconnectChannelVarFromBBoxOperator(e)}}function pt(e,t){let i=e.links[0],r=t.getVariable(Te.CHANNEL,"x",e),s=t.getVariable(Te.CHANNEL,"x",i),n=t.getVariable(Te.CHANNEL,"strokeWidth",i),a=t.getVariable(Te.CHANNEL,"strength",i),o=t.createOneWayDependency(z.LINK_PLACER);t.connect(r,o),t.connect(n,o),t.connect(a,o),t.connect(o,s)}function _t(e,t,i){let r=e.attribute,s=e.channel,n=e.element,a=t.createOneWayDependency(z.ENCODER);if(["width","height"].includes(e.channel)&&n.type===Vt.Area){let e=t.getVariable(Te.PROPERTY,et.BASE_LINE,n);t.connect(e,a)}if(i){let r=t.getVariable(Te.ATTR_VALUE,i),o=t.getVariable(Te.SCALE,i),l=t.getVariable(Te.CHANNEL,s,n);t.connect(o,a),t.connect(a,l),r.addLinkedEncoding(e),o.addLinkedEncoding(e),r.incomingDataflow.run()}else{let i=t.getVariable(Te.ATTRIBUTE,r,Bt(n)),o=t.getVariable(Te.PROPERTY,et.INCLUDE_ZERO,e),l=t.getVariable(Te.ATTR_VALUE,e),h=t.getVariable(Te.DATASCOPE,n),c=t.getVariable(Te.PROPERTY,et.TRANSFORM,e),d=t.createOneWayDependency(z.DATA_EXTRACTOR);t.connect(i,d),t.connect(o,d),t.connect(h,d),t.connect(c,d),t.connect(d,l),d.run();let u=t.getVariable(Te.PROPERTY,et.RANGE_START,e),p=t.getVariable(Te.PROPERTY,et.RANGE_EXTENT,e),_=t.getVariable(Te.PROPERTY,et.FLIP_SCALE,e),f=t.getVariable(Te.SCALE,e),g=t.createOneWayDependency(z.SCALE_BUILDER);t.connect(u,g),t.connect(p,g),t.connect(_,g),t.connect(l,g),t.connect(g,f),g.run();let y=t.getVariable(Te.CHANNEL,s,n);t.connect(f,a),t.connect(a,y),a.run()}}function ft(e,t){let i=t.getVariable(Te.PROPERTY,et.AXIS_ORIENTATION,e),r=t.getVariable(Te.BOUNDS,e.elements[0].parent),s=t.getVariable(Te.PROPERTY,et.AXIS_PATH_POSITION,e),n=t.createOneWayDependency(z.AXIS_PATH_PLACER);t.connect(i,n),t.connect(r,n),t.connect(n,s),n.run();let a=t.getVariable(Te.PROPERTY,et.AXIS_TICK_OFFSET,e),o=t.getVariable(Te.PROPERTY,et.AXIS_TICK_SIZE,e),l=t.createOneWayDependency(z.AXIS_TICKS_PLACER),h=t.getVariable(Te.PROPERTY,et.AXIS_TICKS_POSITION,e);t.connect(s,l),t.connect(a,l),t.connect(o,l),t.connect(l,h),l.run();let c=t.getVariable(Te.PROPERTY,et.AXIS_LABEL_OFFSET,e),d=t.getVariable(Te.PROPERTY,et.AXIS_LABEL_FORMAT,e),u=t.getVariable(Te.PROPERTY,et.AXIS_FONT_SIZE,e),p=t.createOneWayDependency(z.AXIS_LABELS_PLACER),_=t.getVariable(Te.PROPERTY,et.AXIS_LABELS_POSITION,e);t.connect(s,p),t.connect(c,p),t.connect(d,p),t.connect(u,p),t.connect(p,_),p.run();let f=t.getVariable(Te.PROPERTY,et.AXIS_TITLE_POSITION,e),g=t.createOneWayDependency(z.AXIS_TITLE_PLACER);t.connect(s,g),t.connect(g,f),g.run();let y=t.getVariable(Te.BOUNDS,e),m=t.getIncomingDataflowOperator(z.EVAL_BBOX,y);t.connect(h,m),t.connect(_,m),t.connect(m,y)}function gt(e,t){let i=t.getVariable(Te.PROPERTY,et.AXIS_ORIENTATION,e),r=t.getVariable(Te.BOUNDS,L(e.elements[0])),s=t.getVariable(Te.PROPERTY,et.AXIS_PATH_POSITION,e),n=t.createOneWayDependency(z.AXIS_PATH_PLACER);t.connect(i,n),t.connect(r,n),t.connect(n,s),n.run();let a=t.getVariable(Te.PROPERTY,et.AXIS_TICK_OFFSET,e),o=t.getVariable(Te.PROPERTY,et.AXIS_TICK_SIZE,e),l=t.createOneWayDependency(z.AXIS_TICKS_PLACER),h=t.getVariable(Te.PROPERTY,et.AXIS_TICKS_POSITION,e);t.connect(s,l),t.connect(a,l),t.connect(o,l),t.connect(l,h),l.run();let c=t.getVariable(Te.PROPERTY,et.AXIS_LABEL_OFFSET,e),d=t.getVariable(Te.PROPERTY,et.AXIS_LABEL_FORMAT,e),u=t.getVariable(Te.PROPERTY,et.AXIS_FONT_SIZE,e),p=t.createOneWayDependency(z.AXIS_LABELS_PLACER),_=t.getVariable(Te.PROPERTY,et.AXIS_LABELS_POSITION,e);t.connect(s,p),t.connect(c,p),t.connect(d,p),t.connect(u,p),t.connect(p,_),p.run();let f=t.getVariable(Te.PROPERTY,et.AXIS_TITLE_POSITION,e),g=t.createOneWayDependency(z.AXIS_TITLE_PLACER);t.connect(s,g),t.connect(g,f),g.run();let y=t.getVariable(Te.BOUNDS,e),m=t.getIncomingDataflowOperator(z.EVAL_BBOX,y);t.connect(h,m),t.connect(_,m),t.connect(m,y)}function yt(e,t){let i=t.getVariable(Te.BOUNDS,L(e.elements[0])),r=t.getVariable(Te.PROPERTY,et.GRIDLINES_POSITION,e),s=t.createOneWayDependency(z.GRIDLINES_PLACER);t.connect(i,s),t.connect(s,r),s.run();let n=t.getVariable(Te.BOUNDS,e),a=t.getIncomingDataflowOperator(z.EVAL_BBOX,n);t.connect(r,a),t.connect(a,n)}class mt{constructor(){this._id=this.type+Mt(),this._type=Vt.Group,this._dataScope=void 0,this._bounds=void 0,this._layout=void 0,this._children=[],this._sortBy={property:Gt,descending:!1}}get id(){return this._id}get type(){return this._type}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],i=this.getScene(),r=Object.keys(i.encodings),s=[];for(;t;){if(t.classId&&s.indexOf(t.classId)<0&&s.push(t.classId),t.type===Vt.Glyph){t.children.forEach(e=>s.push(e.classId));break}if(!t.children)break;t=t.children[0]}let n=[];for(let t of r){let r=t.split("_");for(let a of s)r[0]==a&&i.encodings[t][e]&&n.push(i.encodings[t][e])}return n}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=V(this,!0);for(let t of e)this.scene.onChange(Te.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)),i=Math.min(...e.map(e=>e.top)),r=Math.max(...e.map(e=>e.right)),s=Math.max(...e.map(e=>e.bottom));return new g(t,i,r-t,s-i)}get x(){return this.bounds.x}get y(){return this.bounds.y}_updateBounds(){let e=this.children;if(e.length>0){this._bounds=e[0].bounds.clone();for(let t=1;t<e.length;t++)"hidden"!=e[t].visibility&&(this._bounds=this._bounds.union(e[t].bounds))}else this._bounds=new g(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 N(this)}get sortBy(){return this._sortBy}}class bt extends mt{constructor(){super(),this._type=Vt.Collection,this._id=this.type+"_"+Mt(),this._classId=this.id,this._childrenOrder=void 0,this._clipMask=void 0}get classId(){return this._classId}getSVGPathData(){let e="";for(let t of this.children)if(t.getSVGPathData)e+=t.getSVGPathData();else if(t.bounds){let i=t.bounds;e+=["M",i.left,i.top].join(" "),e+=["L",i.right,i.top].join(" "),e+=["L",i.right,i.bottom].join(" "),e+=["L",i.left,i.bottom,"Z"].join(" ")}return e}createClipMask(){let e=m(this._children);this._clipMask=new g(e.left,e.top,e.width,e.height)}get clipMask(){return this._clipMask}}class xt extends mt{constructor(e){if(super(),this._type=Vt.Glyph,this._id=this.type+"_"+Mt(),this._classId=this._id,e)for(let t of e)this.addChild(t)}get classId(){return this._classId}}class vt extends ee{constructor(e){super(e),this._type=Vt.BezierCurve,this._orientation="orientation"in e?e.orientation:H}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 wt extends w{constructor(e){super(e),this._type=Vt.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,this._dirty=!0}get area(){return Math.PI*Math.pow(this._radius,2)}_updateBounds(){if(this._rotate){let e=u(this._x,this._y,this._rotate[1],this._rotate[2],this._rotate[0]);this._bounds=new g(e.x-this._radius,e.y-this._radius,2*this._radius,2*this._radius)}else this._bounds=new g(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 Et extends w{constructor(e){super(e),this._type=Vt.Image,this._src=e.src,this._x="x"in e?e.x:0,this._y="y"in e?e.y:0,this._width="width"in e?e.width:100,this._height="height"in e?e.height:100}get src(){return this._src}set src(e){this._src=e,this._dirty=!0}get width(){return this._width}set width(e){this._width=e,this._updateBounds(),this._dirty=!0}get height(){return this._height}set height(e){this._height=e,this._updateBounds(),this._dirty=!0}resize(e,t){this._width=e,this._height=t,this._dirty=!0,this._updateBounds()}get x(){return this._x}set x(e){this._x=e,this._dirty=!0,this._updateBounds()}get y(){return this._y}set y(e){this._y=e,this._dirty=!0,this._updateBounds()}get bounds(){return this._bounds||this._updateBounds(),this._bounds}_updateBounds(){this._bounds=new g(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 At extends ee{constructor(e){super(e)}get x1(){return this.vertices[0].x}get y1(){return this.vertices[0].y}get x2(){return this.vertices[1].x}get y2(){return this.vertices[1].y}get x(){return(this.vertices[0].x+this.vertices[1].x)/2}get y(){return(this.vertices[0].y+this.vertices[1].y)/2}set x(e){let t=e-this.x;this.vertices[0]._x+=t,this.vertices[1]._x+=t,this._dirty=!0}set y(e){let t=e-this.y;this.vertices[0]._y+=t,this.vertices[1]._y+=t,this._dirty=!0}set x1(e){this.vertices[0]._x=e,this._dirty=!0}set x2(e){this.vertices[1]._x=e,this._dirty=!0}set y1(e){this.vertices[0]._y=e,this._dirty=!0}set y2(e){this.vertices[1]._y=e,this._dirty=!0}}class Ct extends w{constructor(e){super(e),this._type=Vt.SimpleText,this._x="x"in e?e.x:0,this._y="y"in e?e.y:0,this._text="text"in e?e.text:"",this._anchor="anchor"in e?e.anchor:[v.CENTER,v.MIDDLE],this._textPath=void 0,this._textPathOffset="50%","fontSize"in this.styles||(this.styles.fontSize="12px"),"fontFamily"in this.styles||(this.styles.fontFamily="Arial, sans-serif"),"fontWeight"in this.styles||(this.styles.fontWeight="normal"),"fillColor"in this.styles||(this.styles.fillColor="black"),"backgroundColor"in e&&(this._backgroundColor=e.backgroundColor),"borderWidth"in e&&(this._borderWidth=e.borderWidth),"borderColor"in e&&(this._borderColor=e.borderColor),this._rotate="rotate"in e?e.rotate:void 0}hasBackground(){return this._backgroundColor||this._borderStroke||this._borderColor}_updateBounds(){let e,t,i=function(e,t,i){const r=d.getSVG(),s=document.createElementNS("http://www.w3.org/2000/svg","text");s.setAttribute("font-family",t),s.setAttribute("font-size",i),s.textContent=e,r.appendChild(s);const n=s.getBBox();return r.removeChild(s),{width:n.width,height:n.height}}(this._text,[this.fontWeight,this.fontSize,this.fontFamily].join(" "),parseFloat(this.fontSize)),r=i.width,s=i.height;switch(this._anchor[0]){case v.LEFT:e=this._x;break;case v.RIGHT:e=this._x-r;break;case v.CENTER:e=this._x-r/2;break;default:e=this._x}switch(this._anchor[1]){case v.TOP:t=this._y;break;case v.BOTTOM:t=this._y-s;break;case v.MIDDLE:default:t=this._y-s/2}if(this._rotate&&3===this._rotate.length){let i=[{x:e,y:t},{x:e+r,y:t},{x:e,y:t+s},{x:e+r,y:t+s}].map(e=>u(e.x,e.y,this._rotate[1],this._rotate[2],this._rotate[0])),n=Math.min(...i.map(e=>e.x)),a=Math.max(...i.map(e=>e.x)),o=Math.min(...i.map(e=>e.y)),l=Math.max(...i.map(e=>e.y));this._bounds=new g(n,o,a-n,l-o)}else this._bounds=new g(e,t,r,s)}get x(){return this._x}set x(e){this._x=e,this._dirty=!0}get y(){return this._y}set y(e){this._y=e,this._dirty=!0}get text(){return this._text}set text(e){this._text=e,this._dirty=!0}get anchor(){return this._anchor}get fontFamily(){return this.styles.fontFamily}get fontSize(){return this.styles.fontSize}get fontWeight(){return this.styles.fontWeight}get textPath(){return this._textPath}set textPath(e){this._textPath=e,this._dirty=!0}get textPathOffset(){return this._textPathOffset}set textPathOffset(e){this._textPathOffset=e,this._dirty=!0}get backgroundColor(){return this._backgroundColor?this._backgroundColor:"#fff"}get borderColor(){return this._borderColor?this._borderColor:"#ccc"}get borderWidth(){return this._borderWidth?this._borderWidth:1}copyPropertiesTo(e){e.styles=Object.assign({},this.styles),this._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 kt extends ee{constructor(e){super(e),this._type=Vt.Polygon,this.closed=!0,"x"in e&&(this._x=e.x),"y"in e&&(this._y=e.y),"radius"in e&&(this._radius=e.radius)}get radius(){return this._radius}get x(){return this._x}get y(){return this._y}set x(e){this._x=e,this._dirty=!0}set y(e){this._y=e,this._dirty=!0}set radius(e){this._radius=e,this._dirty=!0}copyPropertiesTo(e){super.copyPropertiesTo(e),e._x=this._x,e._y=this._y,e._radius=this._radius}}class St extends ee{constructor(e){super(e),this._type=Vt.Ring,this.closed=!0,this._x="x"in e?e.x:0,this._y="y"in e?e.y:0,this._innerRadius="innerRadius"in e?e.innerRadius:100,this._outerRadius="outerRadius"in e?e.outerRadius:200}get innerRadius(){return this._innerRadius}get outerRadius(){return this._outerRadius}get x(){return this._x}get y(){return this._y}get thickness(){return this._outerRadius-this._innerRadius}copyPropertiesTo(e){super.copyPropertiesTo(e),e._x=this._x,e._y=this._y,e._innerRadius=this._innerRadius,e._outerRadius=this._outerRadius}getSVGPathData(){return["M "+this._x+" "+this._y,"m 0, -"+this._outerRadius,"a "+this._outerRadius+","+this._outerRadius+", 0, 1, 0, 1, 0","Z","m 0 "+(this._outerRadius-this._innerRadius),"a "+this._innerRadius+", "+this._innerRadius+", 0, 1, 1, -1, 0","Z"].join(" ")}}class Tt extends w{constructor(e){super(e),this._type=Vt.RichText,this._x="x"in e?e.x:0,this._y="y"in e?e.y:0,this._text="text"in e?e.text:"",this._width="width"in e?e.width:200,this._anchor="anchor"in e?e.anchor:[v.CENTER,v.MIDDLE],"fontSize"in this.styles||(this.styles.fontSize="12px"),"fontFamily"in this.styles||(this.styles.fontFamily="Arial, sans-serif"),"fontWeight"in this.styles||(this.styles.fontWeight="normal"),"fillColor"in this.styles||(this.styles.fillColor="black"),"backgroundColor"in e&&(this._backgroundColor=e.backgroundColor),"borderWidth"in e&&(this._borderWidth=e.borderWidth),"borderColor"in e&&(this._borderColor=e.borderColor),this._rotate="rotate"in e?e.rotate:void 0}hasBackground(){return this._backgroundColor||this._borderStroke||this._borderColor}_updateBounds(){let e,t,i=function(e,t,i){const r=d.getSVG(),s=document.createElementNS("http://www.w3.org/2000/svg","text");s.setAttribute("font-family",t),s.setAttribute("font-size",i),s.textContent=e,r.appendChild(s);const n=s.getBBox();return r.removeChild(s),{width:n.width,height:n.height}}(this._text,[this.fontWeight,this.fontSize,this.fontFamily].join(" "),parseFloat(this.fontSize)),r=i.width,s=i.height;switch(this._anchor[0]){case v.LEFT:e=this._x;break;case v.RIGHT:e=this._x-r;break;case v.CENTER:e=this._x-r/2;break;default:e=this._x}switch(this._anchor[1]){case v.TOP:t=this._y;break;case v.BOTTOM:t=this._y-s;break;case v.MIDDLE:default:t=this._y-s/2}if(this._rotate&&3===this._rotate.length){let i=[{x:e,y:t},{x:e+r,y:t},{x:e,y:t+s},{x:e+r,y:t+s}].map(e=>u(e.x,e.y,this._rotate[1],this._rotate[2],this._rotate[0])),n=Math.min(...i.map(e=>e.x)),a=Math.max(...i.map(e=>e.x)),o=Math.min(...i.map(e=>e.y)),l=Math.max(...i.map(e=>e.y));this._bounds=new g(n,o,a-n,l-o)}else this._bounds=new g(e,t,r,s)}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}set textPath(e){this._textPath=e,this._dirty=!0}get textPathOffset(){return this._textPathOffset}set textPathOffset(e){this._textPathOffset=e,this._dirty=!0}get backgroundColor(){return this._backgroundColor?this._backgroundColor:"#fff"}get borderColor(){return this._borderColor?this._borderColor:"#ccc"}get borderWidth(){return this._borderWidth?this._borderWidth:1}get width(){return this._width}copyPropertiesTo(e){e.styles=Object.assign({},this.styles),this._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}}function Rt(e){let t=null;switch(e.type){case Vt.Circle:t=new wt(e);break;case Vt.Line:var i="x1"in e?e.x1:0,r="y1"in e?e.y1:0,s="x2"in e?e.x2:100,n="y2"in e?e.y2:100;e.vertices=[[i,r],[s,n]],t=new At(e);break;case Vt.Rect:var a="top"in e?e.top:0,o="left"in e?e.left:0,l="width"in e?e.width:50,h="height"in e?e.height:30;e.vertices=[[o,a],[o+l,a],[o+l,a+h],[o,a+h]],t=new Ye(e);break;case Vt.SimpleText:t=new Ct(e);break;case Vt.RichText:t=new Tt(e);break;case Vt.Image:t=new Et(e);break;case Vt.BundledPath:case Vt.Chord:case Vt.Path:t=new ee(e);break;case Vt.Area:t=new Xe(e);break;case Vt.Ring:t=new St(e);break;case Vt.Arc:t=new ne(e);break;case Vt.BezierCurve:"vertices"in e||(e.vertices=[[0,100],[20,120],[80,180],[100,200]]),t=new vt(e);break;case Vt.Polygon:t=new kt(e)}return t&&t._updateBounds(),t}function Ot(e){let t=new bt;return e.addChild(t),e._itemMap[t.id]=t,t}function It(e){return new xt(e)}function Nt(e){switch(e.type){case Vt.Collection:return function(e){let t=Ot(e.scene);for(let i=0;i<e.children.length;i++){let r=e.children[i];t.addChild(Nt(r))}if(t._classId=e.classId,e._layout){let i=e._layout.clone();t._layout=i,i.group=t}return t._updateBounds(),t}(e);case Vt.Glyph:return function(e){let t=new xt;for(let i of e.children)t.addChild(Nt(i));t._classId=e.classId,e._dataScope&&(t.dataScope=e._dataScope.clone());return t}(e);default:return function(e){let t=Rt({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 i=0;i<e.vertices.length;i++)e.vertices[i].dataScope&&(t.vertices[i]._dataScope=e.vertices[i].dataScope.clone());return t}(e)}}const Lt=Object.freeze({Rect:"rect",Circle:"circle",Line:"line",Ring:"ring",Path:"path",Image:"image",SimpleText:"text",RichText:"richText",Arc:"arc",BezierCurve:"bezierCurve",BundledPath:"bundledPath",Chord:"chord"}),Vt=Object.freeze({Area:"area",Rect:"rect",Ellipse:"ellipse",Circle:"circle",Pie:"pie",Ring:"ring",Arc:"arc",BezierCurve:"bezierCurve",BundledPath:"bundledPath",Chord:"chord",Line:"line",Path:"path",Image:"image",SimpleText:"text",RichText:"richText",Collection:"collection",Group:"group",Composite:"composite",Scene:"scene",Axis:"axis",Glyph:"glyph",Legend:"legend",Polygon:"polygon",Gridlines:"gridlines",LinearGradient:"LinearGradient",Link:"link",DataTable:"datatable",Layout:"layout",NetworkData:"networkdata",TreeData:"treedata"}),Pt=Object.freeze({Axis:"axis",Legend:"legend",Gridlines:"gridlines"});function Mt(){return Date.now().toString(36)+"_"+Math.random().toString(36).slice(2)}class Dt{constructor(e,t,i){this._id=Vt.DataTable+Mt(),this.initialize(e,t,i)}initialize(e,t,i){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,i)this._attrTypes=i;else{this._attrTypes={};for(let e of this._attributes)this._attrTypes[e]=ve(this.data.map(t=>t[e])),"year"==e.toLowerCase()&&this._attrTypes[e]==xe.Integer&&(this._attrTypes[e]=xe.Date)}this._validate(this.data,this._attrTypes),this._attrSummaries={};for(let e of this._attributes)this._attrSummaries[e]=Ee(this.data.map(t=>t[e]),this._attrTypes[e]);this._attributes.indexOf(Gt)<0&&this._addAttribute(Gt,xe.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 Dt(e,this.url,Object.assign({},this._attrTypes));return t.sourceDataTable=this,t}get id(){return this._id}get name(){return this.url?function(e){var t=e.indexOf("\\")>=0?e.lastIndexOf("\\"):e.lastIndexOf("/"),i=e.substring(t);0!==i.indexOf("\\")&&0!==i.indexOf("/")||(i=i.substring(1));return i}(this.url):this.id}get data(){return this._data}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,i){this._data.forEach((t,r)=>t[e]=i[r]),e!==Gt&&this._rawData.forEach((t,r)=>t[e]=i[r]),this._attrTypes[e]=t,this._attributes.push(e),this._attrSummaries[e]=Ee(i,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(e,t){let i=r.timeParse(t);for(let t of this.data){let r=t[e];null==r||null==r?(r="",t[e]=new Date(1899,11,31).getTime()):t[e]=i(r).getTime(),this._dateMap.set(t[e],r)}this._attrTypes[e]=xe.Date,this._attrSummaries[e]=Ee(this.data.map(t=>t[e]),xe.Date)}getRawValue(e,t){return this.getAttributeType(e)===xe.Date?this._dateMap.get(t).toString():t}get nonNumericAttributes(){let e=[];for(let t in this._attrTypes)this._attrTypes[t]!=xe.Number&&this._attrTypes[t]!=xe.Integer&&t!=Dt.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]!==xe.Number&&this._attrTypes[t]!==xe.Integer||t==Dt.RowID||e.push(t);return e}getAttributesByType(e){let t=[];for(let i in this._attrTypes)this._attrTypes[i]===e&&i!=Dt.RowID&&t.push(i);return t}summarize(){for(let e of this._attributes)this._attrSummaries[e]=Ee(this.data.map(t=>t[e]),this._attrTypes[e])}_validate(e,t){for(let i of e)for(let e in t){let r,s=t[e],n=i[e];if(null==i[e]||null==i[e])switch(s){case xe.Boolean:r=!1;break;case xe.Date:r=new Date(1899,11,31).getTime();break;case xe.String:r="";break;default:r=0}else switch(s){case xe.Boolean:r=n;break;case xe.Date:r=Number.isInteger(n)?new Date(n,0).getTime():new Date(n+"").getTime(),this._dateMap.set(r,n);break;case xe.String:r=n.toString();break;default:r=n}i[e]=r}}}function Bt(e){let t=de(e);if(t)return t.dataTable}const Gt="mascot_rowId";function Ft(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 zt extends Se{constructor(e,t){super(e),this._elem=t}get element(){return this._elem}}class jt extends Se{constructor(e,t){super(e),this._item=t}get element(){return this._item}}class Wt{constructor(e){this._id=e+"_"+Mt(),this._type=e,this._vars=[],this._edges=[]}get vars(){return this._vars}get edges(){return this._edges}run(){console.log("-",this._type)}}class Ut{constructor(e,t,i=!0){this._id="e_"+Mt(),this._fromNode=e,this._toNode=t,this._isDirected=i}get id(){return this._id}get fromNode(){return this._fromNode}get toNode(){return this._toNode}get isDirected(){return this._isDirected}get operator(){return this._fromNode instanceof F||this._fromNode instanceof Wt?this._fromNode:this._toNode}}class Ht extends Se{constructor(e,t,i){super(e),this._attribute=t,this._dataset=i}get attribute(){return this._attribute}get dataset(){return this._dataset}}class Yt{constructor(e,t){switch(this._id="scale_"+Mt(),this._type=e,t&&(this._args=t),e){case"linear":this._scale=r.scaleLinear();break;case"point":this._scale=r.scalePoint();break;case"ordinal":this._scale=r.scaleOrdinal();break;case"ordinalColor":this._scale=r.scaleOrdinal(r[t.scheme]);break;case"power":this._scale=r.scalePow().exponent(2);break;case"sqrt":this._scale=r.scalePow().exponent(.5);break;case"log":this._scale=r.scaleLog();break;case"identity":case"time":this._scale=r.scaleTime();break;case"sequentialColor":t.scheme?this._scale=r.scaleSequential(r[t.scheme]):this._scale=r.scaleSequential()}}get id(){return this._id}get domain(){return this._scale.domain()}set domain(e){this._scale.domain(e)}get range(){return this._scale.range()}set range(e){this._scale.range(e)}get rangeExtent(){let e=this._scale.range();return Math.abs(e[1]-e[0])}set rangeExtent(e){let t=this._scale.range();t[0]<t[1]?this._scale.range([t[0],t[0]+e]):this._scale.range([t[1]+e,t[1]])}get type(){return this._type}map(e){return this._scale(e)}invert(e,t){let i=Math.min(...this._scale.range()),r=Math.max(...this._scale.range()),s=e;return t||(s=Math.max(i,Math.min(e,r))),"time"===this._type?this._scale.invert(s).getTime():this._scale.invert(s)}}const Xt=["schemeBrBG","schemePRGn","schemePiYG","schemePuOr","schemeRdBu","schemeRdGy","schemeRdYlBu","schemeRdYlGn","schemeSpectral"],qt=["schemeBlues","schemeGreens","schemeGreys","schemeOranges","schemePurples","schemeReds","schemeBuGn","schemeBuPu","schemeGnBu","schemeOrRd","schemePuBuGn","schemePuBu","schemePuRd","schemeRdPu","schemeYlGnBu","schemeYlGn","schemeYlOrBr","schemeYlOrRd"];class Kt{constructor(){this._map={}}clear(){this._map={}}setValue(e,t){this._map[e]=t}getValue(e){return this._map[e]}}class Zt extends Se{constructor(e,t){super(e),this._encs=[t],this._valueMap=new Kt}addLinkedEncoding(e){this._encs.push(e)}get encodings(){return this._encs}get attrValues(){return this._valueMap}set attrValues(e){this._valueMap=e}}class $t extends F{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof Zt),t=this.outputVar,i=t.encodings,r=i[0],s=r.channel,n=r.attribute,a=e.encodings[0].dataTable.getAttributeType(e.encodings[0].attribute),o=Object.values(e.attrValues);if("angle"===r.channel&&[Vt.Arc,Vt.Pie].indexOf(r.element.type)>=0)for(let t of e.encodings)for(let e of t.scales){let i=t.getElements(e).map(e=>t.attrValues[e.id]);e.domain=r._preferredDomain?r._preferredDomain:t.dataTable.tree?[0,t.dataTable.tree.getRoot()[n]]:this._getDomainForNumbers(i),console.log("domain for",n,e.domain)}else{let t;t=r._preferredDomain?r._preferredDomain:a==xe.String||"text"===e.encodings[0].channel?this._getDomainForStrings(o):this._getDomainForNumbers(o);for(let i of e.encodings)for(let e of i.scales)e.domain=t.slice()}for(let e=0;e<r.scales.length;e++){let n=r.scales[e],a=r.getElements(n),o=this._buildRange(s,a,r,t);if(o)for(let t of i)t.scales[e].range=o}t.initialized=!0}_getDomainForNumbers(e){let t=this.outputVar.encodings[0],i=[Math.min(...e),Math.max(...e)];if(t.includeZero&&i[0]>0&&(i=[0,Math.max(...e)]),t.mapping)i=Object.keys(t.mapping),i=i.map(e=>parseFloat(e)),i.sort((e,t)=>e-t);else if("sequentialColor"===t.scales[0].type){if(i[0]<0&&i[1]>0){let e=Math.max(Math.abs(i[0]),Math.abs(i[1]));i=[-e,e]}}else if("angle"===t.channel){i=[0,Object.values(e).reduce((e,t)=>e+t,0)]}return i}_getDomainForStrings(e){let t,i=this.outputVar,r=i.encodings[0];return t="count"==i.encodings[0].aggregator?[0,Math.max(...e)]:Array.from(new Set(e)),r.mapping&&(t=Object.keys(r.mapping)),t}_buildRange(e,t,i,r){return"x"===e?this._buildXRange(t,i,r):"y"===e?this._buildYRange(t,i,r):["width","height","radius","area","fontSize","radialDistance","strokeWidth"].includes(e)?this._buildSizeRange(t,i,r):e.indexOf("Color")>0||"fillGradient"===e?this._buildColorRange(t,i):"angle"===e?this._buildAngleRange(t,i):"thickness"===e?this._buildThicknessRange(t,i,r):"src"===e?i.scales[0].domain.slice():void 0}_buildThicknessRange(e,t,i){let r=e.map(e=>e.outerRadius-e.innerRadius);return[0,i.initialized?t.getRangeExtent(e[0]):t._preferredRangeExtent?t._preferredRangeExtent:Math.max(...r)]}_buildAngleRange(e,t){return[0,360]}_buildColorRange(e,t){if(t.mapping){return t.scales[0].domain.map(e=>t.mapping[e+""])}if("sequentialColor"===t.scales[0].type){let e=this.outputVar,i=t.scales[0].domain;for(let s of e.encodings)if(!t.colorScheme)for(let e of s.scales){let t=e.domain;e._scale=r.scaleSequential(i[0]<0&&i[1]>0?r.interpolatePuOr:r.interpolateTurbo),e._scale.domain(t)}}if((Xt.indexOf(t.colorScheme)>=0||qt.indexOf(t.colorScheme)>=0)&&"ordinalColor"===t.scales[0].type){let e=this.outputVar,i=t.scales[0].domain;for(let s of e.encodings)for(let e of s.scales){let s=e.domain;e._scale=r.scaleOrdinal(r[t.colorScheme][i.length]),e._scale.domain(s)}}}_buildSizeRange(e,t,i){let r,s;return r=0,s=i.initialized?t.getRangeExtent(e[0]):t._preferredRangeExtent?t._preferredRangeExtent:Math.max(...e.map(e=>"radius"===t.channel?e.refBounds.width/2:"strokeWidth"===t.channel?e.strokeWidth:"radialDistance"===t.channel?e.parent.radius:"area"===t.channel?e.type===Vt.Circle?Math.PI*Math.pow(e.radius,2):e.width*e.height:"fontSize"===t.channel?parseFloat(e.fontSize):e.refBounds[t.channel])),[0,0+s]}_buildXRange(e,t,i){let r,s;switch(t.scales[0].type,e[0].type){case"vertex":case"segment":var n=e[0].parent.refBounds?e[0].parent.refBounds:e[0].parent.bounds;r=i.initialized?t.getRangeStart(e[0]):n.left,s=i.initialized?t.getRangeExtent(e[0]):t._preferredRangeExtent?t._preferredRangeExtent:n.width;break;default:r=i.initialized?t.getRangeStart(e[0]):t._preferredRangeStart?t._preferredRangeStart:L(e[0]).bounds.left+e[0].bounds.width/2,s=i.initialized?t.getRangeExtent(e[0]):t._preferredRangeExtent?t._preferredRangeExtent:Math.max(450,Math.max(...e.map(e=>e.bounds.x))-Math.min(...e.map(e=>e.bounds.x)))}return t.flipScale?[r+s,r]:[r,r+s]}_buildYRange(e,t,i){let r,s;switch(t.scales[0].type,e[0].type){case"vertex":case"segment":var n=e[0].parent.refBounds?e[0].parent.refBounds:e[0].parent.bounds;r=i.initialized?t.getRangeStart(e[0]):n.top,s=i.initialized?t.getRangeExtent(e[0]):t._preferredRangeExtent?t._preferredRangeExtent:n.height;break;default:r=i.initialized?t.getRangeStart(e[0]):L(e[0]).bounds.top+e[0].bounds.height/2,s=i.initialized?t.getRangeExtent(e[0]):t._preferredRangeExtent?t._preferredRangeExtent:450}return t.flipScale?[r,r+s]:[r+s,r]}}class Jt extends F{constructor(e){super(e)}run(){super.run()}}class Qt extends mt{constructor(e){super(),this._type=Vt.Axis,this._id=e.id?e.id:this._type+Mt(),this._attribute=void 0,this._channel=void 0,this._orientation=void 0,this._strokeColor="strokeColor"in e?e.strokeColor:"#555",this._textColor="textColor"in e?e.textColor:"#555",this._fontSize="fontSize"in e?e.fontSize:"12px",this._tickOffset="tickOffset"in e?e.tickOffset:0,this._tickSize="tickSize"in e?e.tickSize:5,this._tickAnchor=e.tickAnchor,this._tickVisible=!("tickVisible"in e)||e.tickVisible,this._pathVisible=!("pathVisible"in e)||e.pathVisible,this._labelVisible=!("labelVisible"in e)||e.labelVisible,this._labelOffset="labelOffset"in e?e.labelOffset:this._tickSize+this._tickOffset+3,this._labelFormat="labelFormat"in e?e.labelFormat:"",this._titleOffset="titleOffset"in e?e.titleOffset:40,this._rotateYTitle=!("rotateTitle"in e&&!e.rotateTitle),this._showTitle=!("titleVisible"in e)||e.titleVisible,this._labelRotation="labelRotation"in e?e.labelRotation:0,this._ticks=new mt,this._ticks._id=this._id+"_ticks",this.addChild(this._ticks),this._labels=new mt,this._labels._id=this._id+"_labels",this.addChild(this._labels),this._title=new Ct({text:this._titleText,fillColor:this._textColor,fontWeight:"bold"}),this._title._id=this.id+"_title",this.addChild(this._title),this._showTitle||(this._title.visibility="hidden"),this._pathPos=void 0,this._args=e}get id(){return this._id}get 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!==Vt.SimpleText),t=e[0].bounds.clone();for(let i=1;i<e.length;i++)"hidden"!=e[i].visibility&&(t=t.union(e[i].bounds));return t}}const ei="top",ti="bottom",ii="left";function ri(e,t,i,s){let n,a=e.domain,o=e.range;switch(e.type){case"linear":case"log":{let l=Math.abs(o[0]-o[1]);n="width"==t||"x"==t?45:30;let h,c=Math.max(2,Math.floor(l/n));if("width"==t||"height"==t){let r=!!s&&(s.elements[0].parent.layout&&s.elements[0].parent.layout.type==B.STACK);a[1]=e._scale.invert(r?b(i)[t]:m(i)[t])}if("log"===e.type){h=[];let t=e._scale.ticks();for(let e of t){let i=Math.log(e)/Math.log(10)+1e-6;Math.abs(i-Math.floor(i))<c/t.length&&h.push(e)}}else h=r.ticks(a[0],a[1],c);return h}case"point":{n="width"==t||"x"==t?80:30;let i=Math.floor(e.rangeExtent/a.length),r=Math.ceil(n/i);return"x"==t?a.filter((e,t)=>t%r==0):a}case"time":{n="width"==t||"x"==t?80:30;let e,i,s=Math.floor((o[1]-o[0])/n),l=Math.ceil((a[1]-a[0])/s)/1e3,h=[1,60,3600,86400,2628003,31536e3],c=[r.timeSeconds,r.timeMinutes,r.timeHours,r.timeDays,r.timeMonths,r.timeYears];for(let t=0;t<h.length-1;t++)if(l>=h[t]&&l<h[t+1])return e=Math.floor(l/h[t]),i=c[t],i(a[0],a[1],e);return l>h[h.length-1]?(e=Math.floor(l/h[h.length-1]),i=c[h.length-1],i(a[0],a[1],e)):[]}default:return[]}}function si(e,t){t.removeChild(e)}class ni extends Qt{constructor(e,t,i,r){super(r),this._encoding=e,this._attribute=this._encoding.attribute,this._channel=this._encoding.channel,this._scale=t,this._elems=i,this._flip="flip"in r&&r.flip,this._posArg="x"==this._channel||"width"==this._channel?r.pathY:r.pathX,this._orientation="orientation"in r?r.orientation:"x"===this._channel||"width"==this._channel?ti:ii,this._titleText="title"in r?r.title:this._encoding.attribute,this._path="angle"===this._channel?new wt({strokeColor:this._strokeColor,id:this._id+"_path"}):new ee({strokeColor:this._strokeColor,id:this._id+"_path"}),this._pathVisible||(this._path.visibility="hidden"),this.addChild(this._path),this.createTicksLabels(r),e.dataTable.getAttributeType(this._attribute)!==xe.Date||"labelFormat"in r||(this._labelFormat="%m/%d/%y"),"radialDistance"===this._channel&&"rotation"in r&&(this._rotate=[-r.rotation,this._elems[0].parent.x,this._elems[0].parent.y])}isFlipped(){return this._flip}get elements(){return this._elems}get scale(){return this._scale}get encoding(){return this._encoding}createTicksLabels(e){"tickValues"in e?(this._tickValues=e.tickValues,this._labelValues=e.tickValues):(this._tickValues=ri(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 ee({strokeColor:this._strokeColor,id:this._id+"_tick"+e});this._tickVisible||(t.visibility="hidden"),this._ticks.addChild(t)}let t;switch(this._labels.removeAll(),this._encoding.dataTable.getAttributeType(this._attribute)){case xe.Date:t=r.utcFormat(this._labelFormat);break;case xe.String:t=function(e){return e};break;default:t=r.format(this._labelFormat)}for(let[e,i]of this._labelValues.entries()){let r=new Ct({text:t(i),fontSize:this._fontSize,fillColor:this._textColor,id:this._id+"_label"+e});this._labelVisible||(r.visibility="hidden"),this._labels.addChild(r)}this._title._text=this._titleText}}class ai extends Qt{constructor(e,t,i,r){super(r),this._elems=e,this._attribute=i,this._channel=t,this._posArg="x"==this._channel||"width"==this._channel?r.pathY:r.pathX,this._labelAttribute=r.labelAttribute,this._orientation="orientation"in r?r.orientation:"x"===this._channel||"width"==this._channel?ti:ii,this._titleText="title"in r?r.title:this._attribute,this._path="angle"===this._channel?new wt({strokeColor:this._strokeColor,id:this._id+"_path"}):new ee({strokeColor:this._strokeColor,id:this._id+"_path"}),this._pathVisible||(this._path.visibility="hidden"),this.addChild(this._path),this.createTicksLabels(r),this._elems[0].dataScope.dataTable.getAttributeType(this._attribute)!==xe.Date||"labelFormat"in r||(this._labelFormat="%m/%d/%y")}get elements(){if(this.layout.type===B.CLUSTER){const e=new Map(this._elems.map(e=>[e.dataScope.getAttrVal(me),e]));return this.layout._d3Root.leaves().map(t=>e.get(t.data[me]))}return this._elems}get layout(){return this._elems[0].parent.layout}createTicksLabels(e){"tickValues"in e?(this._tickValues=e.tickValues,this._labelValues=e.tickValues):(this._tickValues=this.elements.map(e=>e.dataScope.getAttrVal(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 ee({strokeColor:this._strokeColor,id:this._id+"_tick"+e});this._tickVisible||(t.visibility="hidden"),this._ticks.addChild(t)}let t;switch(this._labels.removeAll(),this._elems[0].dataScope.dataTable.getAttributeType(this._labelAttribute?this._labelAttribute:this._attribute)){case xe.Date:t=r.timeFormat(this._labelFormat);break;case xe.String:t=function(e){return e};break;default:t=r.format(this._labelFormat)}for(let[e,i]of this._labelValues.entries()){let r=new Ct({text:t(i),fontSize:this._fontSize,fillColor:this._textColor,id:this._id+"_label"+e});this._labels.addChild(r)}this._title._text=this._titleText}}class oi extends F{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof $e&&e.property==et.AXIS_ORIENTATION).element;e.createTicksLabels(e._args),e instanceof ni?this._runForEncoding(e):e instanceof ai&&this._runForLayout(e),x(e._path)}_runForLayout(e){let t=e.channel,i=e.elements[0].parent.layout&&e.elements[0].parent.layout.type==B.STACK?b(e.elements):m(e.elements),r=[];if("x"===t){let t=e.orientation===ei?i.top-2:i.bottom+2;e._pathPos=e._posArg?e._posArg:t,r.push([i.left,e._pathPos]),r.push([i.right,e._pathPos]),e._path._setVertices(r)}else if("y"===t){let t=e.orientation===ii?i.left-2:i.right+2;e._pathPos=e._posArg?e._posArg:t,r.push([e._pathPos,i.top]),r.push([e._pathPos,i.bottom]),e._path._setVertices(r)}else if("angle"===t){let t=e.elements[0].parent.layout;t.type===B.CLUSTER&&(e._path._x=t.x,e._path._y=t.y,e._path._radius=t.radius)}}_runForEncoding(e){let t=e.channel,i=e.elements,r=i[0].parent.layout&&i[0].parent.layout.type==B.STACK?b(i):m(i),s=[],n=L(i[0]);if(n&&n.clipMask&&(r=n.clipMask),"x"===t){let t,n,a=Ve(i[0],"y");a?(t=Math.min(...a.getScale(i[0]).range,r.top),n=Math.max(...a.getScale(i[0]).range,r.bottom)):(t=r.top,n=r.bottom);let o=e.orientation===ei?t-2:n+2;e._pathPos=e._posArg?e._posArg:o,s.push([e.scale.range[0],e._pathPos]),s.push([e.scale.range[1],e._pathPos])}else if("width"===t){let t=e.orientation===ei?r.top-2:r.bottom+2;e._pathPos=e._posArg?e._posArg:t,s.push([r.left,e._pathPos]),s.push([r.right,e._pathPos])}else if("radialDistance"===t){let t=e.elements[0].parent,i=t.y;e._pathPos=e._posArg?e._posArg:i,s.push([e.scale.range[0]+t.x,e._pathPos]),s.push([e.scale.range[1]+t.x,e._pathPos])}else if("y"===t){let t,n,a=Ve(i[0],"x");a?(t=Math.min(...a.getScale(i[0]).range,r.left),n=Math.max(...a.getScale(i[0]).range,r.right)):(t=r.left,n=r.right);let o=e.orientation===ii?t-2:n+2;e._pathPos=e._posArg?e._posArg:o,s.push([e._pathPos,e.scale.range[0]]),s.push([e._pathPos,e.scale.range[1]])}else if("height"===t){let t=e.orientation===ii?r.left-2:r.right+2;e._pathPos=e._posArg?e._posArg:t,s.push([e._pathPos,r.bottom]),s.push([e._pathPos,r.top])}e._path._setVertices(s)}}class li extends F{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof $e&&e.property==et.AXIS_PATH_POSITION).element;e instanceof ni?this._runForEncoding(e):e instanceof ai&&this._runForLayout(e);let t=[];if("width"===e.channel||"x"===e.channel){let i=e._ticks.children.map(e=>e.vertices[0].x),r=[e._path.vertices[0].x,e._path.vertices[1].x];t.push([Math.min(...i.concat(r)),e._path.vertices[0].y]),t.push([Math.max(...i.concat(r)),e._path.vertices[0].y]),e._path._setVertices(t)}else if("height"===e.channel||"y"===e.channel){let i=e._ticks.children.map(e=>e.vertices[0].y),r=[e._path.vertices[0].y,e._path.vertices[1].y];t.push([e._pathPos,Math.min(...i.concat(r))]),t.push([e._pathPos,Math.max(...i.concat(r))]),e._path._setVertices(t)}for(let t of e._ticks.children)t._updateBounds();x(e._ticks)}_runForLayout(e){let t=e.channel;if("x"==t){let t=e.orientation==ti?e.pathPos+e.tickOffset:e.pathPos-e.tickOffset,i=e.orientation==ti?e.tickSize:-e.tickSize;for(let[r,s]of e._ticks.children.entries()){let n=e.elements[r].bounds[e.tickAnchor];s._setVertices([[n,t],[n,t+i]])}}else if("y"===t){let t=e.orientation==ii?e.pathPos-e.tickOffset:e.pathPos+e.tickOffset,i=e.orientation==ii?-e.tickSize:e.tickSize;for(let[r,s]of e._ticks.children.entries()){let n=e.elements[r].bounds[e.tickAnchor];s._setVertices([[t,n],[t+i,n]])}}else if("angle"===t){let t=e.elements[0].parent.layout;if(t.type===B.CLUSTER){let i=t._d3Root.leaves();const r=new Map(i.map(e=>[e.data[me],[e.x,e.y]]));for(let[i,s]of e._ticks.children.entries()){let n=e.elements[i].dataScope.getAttrVal(me),a=oe(r.get(n)[0])-90;s._setVertices([[t.x+r.get(n)[1]+e.elements[i].bounds.width/2,t.y],[t.x+r.get(n)[1]+e.elements[i].bounds.width/2+e.tickSize,t.y]]),s._rotate=[a,t.x,t.y]}}}}_runForEncoding(e){let t=e.channel,i=m(e.elements);if("x"==t){let t=e.orientation==ti?e.pathPos+e.tickOffset:e.pathPos-e.tickOffset,i=e.orientation==ti?e.tickSize:-e.tickSize;for(let[r,s]of e._ticks.children.entries())s._setVertices([[e.scale.map(e._tickValues[r]),t],[e.scale.map(e._tickValues[r]),t+i]])}else if("width"==t){let t=e.orientation==ti?e.pathPos+e.tickOffset:e.pathPos-e.tickOffset,r=e.orientation==ti?e.tickSize:-e.tickSize;if(!!(e.isFlipped()||e.elements[0].type===Vt.Area&&"right"===e.elements[0].baseline))for(let[s,n]of e._ticks.children.entries())n._setVertices([[i.left+e.scale.rangeExtent-e.scale.map(e._tickValues[s]),t],[i.left+e.scale.rangeExtent-e.scale.map(e._tickValues[s]),t+r]]);else for(let[s,n]of e._ticks.children.entries())n._setVertices([[e.scale.map(e._tickValues[s])+i.left,t],[e.scale.map(e._tickValues[s])+i.left,t+r]])}else if("y"===t){let t=e.orientation==ii?e.pathPos-e.tickOffset:e.pathPos+e.tickOffset,i=e.orientation==ii?-e.tickSize:e.tickSize;for(let[r,s]of e._ticks.children.entries())s._setVertices([[t,e.scale.map(e._tickValues[r])],[t+i,e.scale.map(e._tickValues[r])]])}else if("height"===t){let t=e.orientation==ii?e.pathPos-e.tickOffset:e.pathPos+e.tickOffset,r=e.orientation==ii?-e.tickSize:e.tickSize;if(!!(e.isFlipped()||e.elements[0].type===Vt.Area&&"top"===e.elements[0].baseline))for(let[s,n]of e._ticks.children.entries())n._setVertices([[t,i.top+e.scale.map(e._tickValues[s])],[t+r,i.top+e.scale.map(e._tickValues[s])]]);else for(let[s,n]of e._ticks.children.entries()){let a=i.bottom-e.scale.map(e._tickValues[s]);n._setVertices([[t,a],[t+r,a]])}}else if("radialDistance"===t){let t=e.orientation==ti?e.pathPos+e.tickOffset:e.pathPos-e.tickOffset,i=e.orientation==ti?e.tickSize:-e.tickSize,r=e.elements[0].parent;for(let[s,n]of e._ticks.children.entries())n._setVertices([[r.x+e.scale.map(e._tickValues[s]),t],[r.x+e.scale.map(e._tickValues[s]),t+i]])}}}class hi extends F{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof $e&&e.property==et.AXIS_PATH_POSITION).element;e instanceof ni?this._runForEncoding(e):e instanceof ai&&this._runForLayout(e);for(let t of e._labels.children)t._updateBounds();x(e._labels)}_runForLayout(e){let t=e.channel;if("x"==t){let t=e.orientation==ti?e.labelOffset:-e.labelOffset,i=e.orientation==ti?[v.CENTER,v.TOP]:[v.CENTER,v.BOTTOM];for(let[r,s]of e._labels.children.entries()){let n=e.elements[r].bounds;s.x=n[e.tickAnchor],s._y=e.pathPos+t,s._anchor=i,e._labelRotation&&(s._rotate=[e._labelRotation,s.x,s.y],s._anchor=[v.RIGHT,v.MIDDLE])}}else if("y"===t){let t=e.orientation==ii?-e.labelOffset:e.labelOffset,i=e.orientation==ii?[v.RIGHT,v.MIDDLE]:[v.LEFT,v.MIDDLE];for(let[r,s]of e._labels.children.entries()){let n=e.elements[r].bounds;s.x=e.pathPos+t,s._y=e.tickAnchor==v.MIDDLE?n.y:n[e.tickAnchor],s._anchor=i,e._labelRotation&&(s._rotate=[e._labelRotation,s.x,s.y],s._anchor=[v.RIGHT,i[1]])}}else if("angle"===t){let t=e.elements[0].parent.layout;if(t.type===B.CLUSTER){let i=t._d3Root.leaves();const r=new Map(i.map(e=>[e.data[me],[e.x,e.y]]));let s=5;for(let[i,n]of e._labels.children.entries()){let a=e.elements[i].dataScope.getAttrVal(me);if(r.get(a)[0]<Math.PI){let o=oe(r.get(a)[0])-90;n._anchor=[v.LEFT,v.MIDDLE],n.x=t.x+r.get(a)[1]+e.elements[i].bounds.width/2+s,n._y=t.y,n._rotate=[o,t.x,t.y]}else{let o=oe(r.get(a)[0])+90;n._anchor=[v.RIGHT,v.MIDDLE],n.x=t.x-r.get(a)[1]-e.elements[i].bounds.width/2-s,n._y=t.y,n._rotate=[o,t.x,t.y]}}}}}_runForEncoding(e){let t=e.channel,i=m(e.elements);if("x"==t){let t=e.orientation==ti?e.labelOffset:-e.labelOffset,i=e.orientation==ti?[v.CENTER,v.TOP]:[v.CENTER,v.BOTTOM];for(let[r,s]of e._labels.children.entries())s.x=e.scale.map(e.labelValues[r]),s._y=e.pathPos+t,s._anchor=i,e._labelRotation&&(s._rotate=[e._labelRotation,s.x,s.y],s._anchor=[v.RIGHT,i[1]])}else if("width"===t){let t=e.orientation==ti?e.labelOffset:-e.labelOffset,r=e.orientation==ti?[v.CENTER,v.TOP]:[v.CENTER,v.BOTTOM],s=!!(e.isFlipped()||e.elements[0].type===Vt.Area&&"right"===e.elements[0].baseline);for(let[n,a]of e._labels.children.entries())a.x=s?i.left+e.scale.rangeExtent-e.scale.map(e.labelValues[n]):e.scale.map(e.labelValues[n])+i.left,a._y=e.pathPos+t,a._anchor=r,e._labelRotation&&(a._rotate=[e._labelRotation,a.x,a.y],a._anchor=[v.RIGHT,r[1]])}else if("y"===t){let t=e.orientation==ii?-e.labelOffset:e.labelOffset,i=e.orientation==ii?[v.RIGHT,v.MIDDLE]:[v.LEFT,v.MIDDLE];for(let[r,s]of e._labels.children.entries())s.x=e.pathPos+t,s._y=e.scale.map(e.labelValues[r]),s._anchor=i,e._labelRotation&&(s._rotate=[e._labelRotation,s.x,s.y],s._anchor=[v.RIGHT,i[1]])}else if("height"===t){let t=e.orientation==ii?-e.labelOffset:e.labelOffset,r=e.orientation==ii?[v.RIGHT,v.MIDDLE]:[v.LEFT,v.MIDDLE],s=e.elements[0].type===Vt.Area&&"top"===e.elements[0].baseline;for(let[n,a]of e._labels.children.entries())a.x=e.pathPos+t,a._y=s?i.top+e.scale.map(e.labelValues[n]):i.bottom-e.scale.map(e.labelValues[n]),a._anchor=r,e._labelRotation&&(a._rotate=[e._labelRotation,a.x,a.y],a._anchor=[v.RIGHT,r[1]])}else if("radialDistance"==t){let t=e.orientation==ti?e.labelOffset:-e.labelOffset,i=e.orientation==ti?[v.CENTER,v.TOP]:[v.CENTER,v.BOTTOM],r=e.elements[0].parent;for(let[s,n]of e._labels.children.entries())n.x=r.x+e.scale.map(e.labelValues[s]),n._y=e.pathPos+t,n._anchor=i,e._labelRotation&&(n._rotate=[e._labelRotation,n.x,n.y],n._anchor=[v.RIGHT,i[1]])}}}class ci extends F{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=C(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 i=V(e,!0);for(let e of i)x(e)}placeElements(e,t){let i=Me(e,"x"),r=Me(e,"y");for(let i=0;i<e.children.length;i++){let r=e.children[i],s=t.cellBounds[i],n=0,a=0;switch(t._cellHorzAlignment){case v.LEFT:n=s.left-r.refBounds.left;break;case v.CENTER:n=s.x-r.refBounds.x;break;case v.RIGHT:n=s.right-r.refBounds.right}switch(t._cellVertAlignment){case v.TOP:a=s.top-r.refBounds.top;break;case v.MIDDLE:a=s.y-r.refBounds.y;break;case v.BOTTOM:a=s.bottom-r.refBounds.bottom}Fe(r,n,a)}if(i.length>0)for(let e of i)for(let i of e.scales){let r=e.getElements(i)[0],s=t.getIndex(r);if(s<0)continue;let n="point"===i.type?t.cellBounds[s].left+r.bounds.width/2:t.cellBounds[s].left,a=n+i.rangeExtent;i.range=i.range[0]<i.range[1]?[n,a]:[a,n]}if(r.length>0)for(let e of r)for(let i of e.scales){let r=e.getElements(i)[0],s=t.getIndex(r);if(s<0)continue;let n="point"===i.type?t.cellBounds[s].top+e.getElements(i)[0].bounds.height/2:t.cellBounds[s].top,a=n+i.rangeExtent;i.range=i.range[0]<i.range[1]?[n,a]:[a,n]}}fillGrid(e,t){t._grid=new Array(t.numRows).fill(null).map(()=>new Array(t.numCols).fill(null));for(let i=0;i<e.children.length;i++){let e=t.getRowCol(i);t._grid[e.row][e.col]=i}}computeCellBounds(e,t){let i=e.children.map(e=>e.refBounds?e.refBounds:e.bounds),r=t._colGap,s=t._rowGap;if(void 0===t._left){let e=i.map(e=>e.left),r=i.map(e=>e.top);t._left=Math.min(...e),t._top=Math.min(...r)}let n=i.map(e=>e.width),a=i.map(e=>e.height),o=Math.max(...n),l=Math.max(...a);t._cellBounds=new Array(e.children.length).fill(null);for(let i=0;i<t.numRows;i++)for(let n=0;n<t.numCols;n++){let a=t._grid[i][n];a>=e.children.length||(t._cellBounds[a]=new g(t._left+(o+r)*n+0,t._top+(l+s)*i,o,l))}}}class di extends F{constructor(e){super(e)}run(){let e=this.outputVar.element;e.updateValues(),e.scale?this._runForEncoding(e):this._runForLayout(e),x(e)}_runForLayout(e){let t=e.channel,i=m(e.elements),r=[];if("x"===t)for(let t=0;t<e.values.length;t++){let s=e.elements[t].refBounds;r.push({x1:s.x,y1:i.bottom,x2:s.x,y2:i.top})}else if("y"===t)for(let t=0;t<e.values.length;t++){let s=e.elements[t].refBounds;r.push({x1:i.left,y1:s.y,x2:i.right,y2:s.y})}e.lines=r,e._dirty=!0}_runForEncoding(e){let t=e.channel,i=m(e.elements),r=[];if("x"===t){let t,s,n=Ve(e.elements[0],"y");n?(t=Math.min(...n.getScale(e.elements[0]).range,i.top),s=Math.max(...n.getScale(e.elements[0]).range,i.bottom)):(t=i.top,s=i.bottom);for(let i of e.values)r.push({x1:e.scale.map(i),y1:s,x2:e.scale.map(i),y2:t})}else if("width"===t)for(let t of e.values)r.push({x1:e.scale.map(t)+i.left,y1:i.bottom,x2:e.scale.map(t)+i.left,y2:i.top});else if("y"===t){let t,s,n=Ve(e.elements[0],"x");n?(t=Math.min(...n.getScale(e.elements[0]).range,i.left),s=Math.max(...n.getScale(e.elements[0]).range,i.right)):(t=i.top,s=i.bottom);for(let i of e.values)r.push({x1:t,y1:e.scale.map(i),x2:s,y2:e.scale.map(i)})}else if("height"===t)for(let t of e.values)r.push({x1:i.left,y1:i.bottom-e.scale.map(t),x2:i.right,y2:i.bottom-e.scale.map(t)});else if("radialDistance"===t){let t=e.elements[0].parent;for(let i=0;i<e.values.length;i++)r.push({x:t.x,y:t.y,r:e.scale.map(e.values[i])})}e.lines=r,e._dirty=!0}}class ui extends F{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=V(e)[0],i=C(e.parent);for(let e of i){let i=e.layout;if(!i)return;switch(t.type){case Vt.Rect:case Vt.Circle:case Vt.Image:this._stackRects(e,i);break;case Vt.Area:e.children[0].orientation===H?this._stackAreasVert(e,i):this._stackAreasHorz(e,i);break;case Vt.Arc:case Vt.Pie:t.parent.classId===e.classId&&this._stackArcs(e,i)}}x(t)}_stackArcs(e,t){if(t.orientation===X){let t=90;if((this._direction?this._direction:Z.Clockwise)===Z.Clockwise)for(let i of e.children){let e=le(t-i.angle);je(i,"startAngle",e),t=e}else for(let i of e.children){let e=le(t+i.angle);je(i,"startAngle",e),t=e}}else if(t.orientation===q){let t=Math.min(...e.children.map(e=>e.innerRadius));for(let i of e.children){let e=i.outerRadius-i.innerRadius;je(i,"innerRadius",t),je(i,"outerRadius",t+e),t=i._outerRadius}}}_stackAreasVert(e,t){let i=e.children.filter(e=>"visible"===e.visibility),r=e.bounds,s=t.vertCellAlignment===v.TOP?r.top:r.bottom,n=t.vertCellAlignment===v.TOP?1:-1;if(0===i.length)return;t.vertCellAlignment===v.BOTTOM&&i.reverse();let a=i[0].vertices.length/2,o=new Array(a).fill(0);for(let e of i){for(let t=0;t<a;t++){let i=e.vertices[t],r=e.vertices[2*a-t-1],l=Math.abs(i.y-r.y),h=s+o[t]*n,c=s+(o[t]+l)*n;Fe(i,0,h-i.y),Fe(r,0,c-r.y),o[t]+=l}let t=e.bounds.bottom;e._updateBounds(),e._refBounds.translate(0,e.bounds.bottom-t)}if(t.vertCellAlignment===v.MIDDLE)for(let e of i){for(let t=0;t<a;t++){let i=e.vertices[t],s=e.vertices[2*a-t-1],n=r.middle+o[t]/2;Fe(i,0,n-r.bottom),Fe(s,0,n-r.bottom)}let t=e.bounds.bottom;e._updateBounds(),e._refBounds.translate(0,e.bounds.bottom-t)}}_stackAreasHorz(e,t){}_stackRects(e,t){e.scene;let i=t._orientation,r=e.children.map(e=>e.bounds),s=r.map(e=>e.left),n=r.map(e=>e.top),a=r.map(e=>e.width),o=r.map(e=>e.height),l=null==t._left?Math.min(...s):t._left,h=null==t._top?Math.min(...n):t._top,c=Math.max(...a),d=Math.max(...o);if(i==Y)for(let i=0;i<e.children.length;i++){let r=e.children[i],s=0,n=h+r.bounds.height/2-r.bounds.y;h+=r.bounds.height+t._gap,Fe(r,s,n),r._updateBounds();let a=0,o=0;if(!Be(r))switch(t._horzCellAlignment){case v.LEFT:a=l-r.bounds.left;break;case v.CENTER:a=l+c/2-r.bounds.x;break;case v.RIGHT:a=l+c-r.bounds.right}Fe(r,a,o)}else for(let i=0;i<e.children.length;i++){let r=e.children[i],s=l+r.bounds.width/2-r.bounds.x,n=0;l+=r.bounds.width+t._gap,Fe(r,s,n),r._updateBounds();let a=0,o=0;if(!De(r))switch(t._vertCellAlignment){case v.TOP:o=h-r.bounds.top;break;case v.MIDDLE:o=h+d/2-r.bounds.y;break;case v.BOTTOM:o=h+d-r.bounds.bottom}Fe(r,a,o)}}}class pi extends F{constructor(e){super(e)}run(){super.run()}}class _i extends F{constructor(e){super(e)}run(){let e=this.inputVars[0],t=this.outputVar,i=e.attribute,s=t.attribute,n=e.dataset,a=t.dataset,o=n.getAttributeValues(i),l=r.bin()(o),h=this._findBin,c=o.map(e=>{let t=h(e,l);return(t.x0+t.x1)/2+""}),d=l.map(e=>(e.x0+e.x1)/2+"");a._addAttribute(s,xe.String,c),a.orderAttributeValues(s,d)}_findBin(e,t){for(let i of t)if(i.indexOf(e)>=0)return i}}class fi extends F{constructor(e){super(e)}run(){let e=this.outputVar,t=e.dataset,i=e.predicate,r=[];for(let[e,s]of t.data.entries())i.testTuple(s)||r.push(e);r.sort((e,t)=>t-e),r.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]=Ee(t.data.map(t=>t[e]),t._attrTypes[e])}}class gi extends F{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e.type===Te.AFFIXATION).affixation,t=e.base,i=e.element,r=C(t),s=C(i),n=e.channels,a=e.attribute;if(E(i)&&E(t)){let e=r.map(e=>e.dataScope.getAttrVal(a));s=s.filter(t=>e.includes(t.dataScope.getAttrVal(a)));let t=(e,t)=>e.dataScope.getAttrVal(a)<t.dataScope.getAttrVal(a)?-1:e.dataScope.getAttrVal(a)>t.dataScope.getAttrVal(a)?1:0;s.sort(t),r.sort(t)}if(n.includes("x")||n.includes("y"))for(let t of n)this._handleXY(t,s,r,e.getElementAnchor(t),e.getBaseAnchor(t),e.getOffset(t));(n.includes("radialDistance")||n.includes("angle"))&&this._handlePolar(s,r,e);let o=V(i,!0);for(let e of o)x(e)}_handlePolar(e,t,i){let r=i.hasChannel("radialDistance")?i.getBaseAnchor("radialDistance"):v.MIDDLE,s=i.hasChannel("radialDistance")?i.getElementAnchor("radialDistance"):v.MIDDLE,n=i.hasChannel("angle")?i.getBaseAnchor("angle"):v.CENTER;i.hasChannel("angle")?i.getElementAnchor("angle"):v.CENTER;let a=i.hasChannel("radialDistance")?i.getOffset("radialDistance"):0,o=i.hasChannel("angle")?i.getOffset("angle"):0;if([Vt.Arc,Vt.Ring].indexOf(t[0].type)>=0&&e[0].type==Vt.SimpleText)for(let i=0;i<e.length;i++){let s=t[i],o=e[i],l=r===v.MIDDLE?(s.outerRadius+s.innerRadius)/2:r===v.TOP?s.outerRadius-5:s.innerRadius+5;if(l+=a,s.type===Vt.Arc){let e=Ce(s.x,s.y,l,s.startAngle),t=Ce(s.x,s.y,l,s.endAngle);s.endAngle>=180&&s.endAngle<=360?o._textPath=["M",e[0],e[1],"A",l,l,s.angle,s.angle>=180?1:0,0,t[0],t[1]].join(" "):o._textPath=["M",t[0],t[1],"A",l,l,s.angle,s.angle>=180?1:0,1,e[0],e[1]].join(" ")}else if(s.type===Vt.Ring){let e=275,t=265,i=350,r=Ce(s.x,s.y,l,e),n=Ce(s.x,s.y,l,t);o._textPath=["M",n[0],n[1],"A",l,l,i,1,1,r[0],r[1]].join(" ")}o.textPathOffset=n===v.LEFT?"0%":"50%"}else for(let i=0;i<e.length;i++){let l,h,c=t[i],d=e[i];c.type==Vt.Arc||c.type==Vt.Ring?(h="left"==n?c.endAngle+o:"center"==n?c.startAngle+c.angle/2+o:c.startAngle+o,l="top"==r?c.outerRadius+a:"bottom"==r?c.innerRadius+a:(c.outerRadius+c.innerRadius)/2+a):c.type==Vt.Circle&&(h=90,l="top"==r?c.radius+a:"bottom"==r?a:c.radius/2+a),Fe(d,c.x-d.x,c.y-l-d.bounds[s]),d._rotate=[90-h,c.x,c.y]}}_handleXY(e,t,i,r,s,n){for(let a=0;a<t.length;a++){let o,l=i[a],h=t[a];if(ie(l)){o=te(l,[v.LEFT,v.TOP].includes(s)?0:[v.CENTER,v.MIDDLE].includes(s)?.5:1)[e]}else o=l.bounds[s]+n;t[0].type===Vt.SimpleText?(h.anchor["x"==e?0:1]=r,je(h,e,o)):"x"==e?Fe(h,o-h.bounds[r],0):Fe(h,0,o-h.bounds[r])}}}class yi extends Se{constructor(e,t){super(e),this._affx=t}get affixation(){return this._affx}}class mi extends F{constructor(e){super(e)}run(){let e=this.inputVars[0],t=this.outputVar,i=e.attribute,r=t.attribute,s=e.dataset,n=t.dataset,a=this.args,o="min"in a?a.min:s.getAttributeSummary(i).min,l="max"in a?a.max:s.getAttributeSummary(i).max,h=o,c=[];for(;h<l;)c.push(h),h+=a.interval;c.push(h);let d={},u={};if(a.groupBy)for(let e of s.data){let t=a.groupBy.map(t=>e[t]).join("-");t in d||(d[t]=[],u[t]=a.groupBy.map(t=>e[t])),d[t].push(e[i])}else d[""]=s.data.map(e=>e[i]),u[""]="";let p=[];for(let e in u){let t=bi(xi(a.bandwidth),c,d[e]);for(let s of t){let t={};""!==e&&a.groupBy.forEach((i,r)=>t[i]=u[e][r]),t[i]=s[0],t[r]=s[1],p.push(t)}}let _={};if(_[i]=s.getAttributeType(i),_[r]=xe.Number,a.groupBy)for(let e of a.groupBy)_[e]=s.getAttributeType(e);n.initialize(p,n.url,_)}}function bi(e,t,i){return t.map(t=>[t,r.mean(i,i=>e(t-i))])}function xi(e){return t=>Math.abs(t/=e)<=1?.75*(1-t*t)/e:0}class vi extends F{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=C(e.parent);for(let e of t){let t=e.layout;if(!t)return;let i=e.children.map(e=>({name:e.id,radius:e.radius,itm:e})),s=i.reduce((e,t)=>e+Math.pow(t.radius,2),0),n=Math.sqrt(s);void 0===t._width&&(t._width=n),void 0===t._height&&(t._height=n);let a=r.hierarchy({name:"root",children:i}).sum(e=>e.radius?e.radius:0).sort((e,t)=>t.value-e.value);r.pack().size([t._width,t._height]).radius(e=>e.value)(a);for(let e of a.children){let i=e.data.itm;Fe(i,t._x-a.x+e.x-i.x,t._y-a.y+e.y-i.y)}}let i=V(e,!0);for(let e of i)x(e)}}class wi extends F{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof $e&&e.property==et.AXIS_PATH_POSITION).element;e instanceof ni?this._runForEncoding(e):e instanceof ai&&this._runForLayout(e),x(e._title)}_runForEncoding(e){let t=e.channel,i=m(e.elements);if("x"==t)e._title.x=(e.scale.range[0]+e.scale.range[1])/2,e._title._y=e.orientation==ti?e.pathPos+e.titleOffset:e.pathPos-e.titleOffset;else if("width"==t)e._title.x=i.left+e.scale.rangeExtent/2,e._title._y=e.orientation==ti?e.pathPos+e.titleOffset:e.pathPos-e.titleOffset;else if("y"===t)e._rotateYTitle?(e._title.x=e.orientation==ii?e.pathPos-e.titleOffset:e.pathPos+e.titleOffset,e._title._y=(e.scale.range[0]+e.scale.range[1])/2,e._title._rotate=e.orientation==ii?[-90,e._title._x,e._title._y]:[90,e._title._x,e._title._y]):(e._title.x=e.orientation==ii?e.pathPos-e.titleOffset:e.pathPos+e.titleOffset,e._title._y=Math.min(e.scale.range[0],e.scale.range[1])-25,e._title._rotate=void 0);else if("height"===t)e._title.x=i.center,e._title._y=(i.top+i.bottom)/2-i.width/2-e.titleOffset,e._title._rotate=e.orientation==ii?[-90,i.center,i.middle]:[90,i.center,i.middle];else if("radialDistance"===t){let t=e.elements[0].parent;e._title.x=t.x+e.scale.rangeExtent/2,e._title._y=e.orientation==ti?e.pathPos+e.titleOffset:e.pathPos-e.titleOffset,e._rotate&&(e._title._rotate=e._rotate.slice())}}_runForLayout(e){let t=e.channel,i=e.elements[0].parent.layout&&e.elements[0].parent.layout.type==B.STACK?b(e.elements):m(e.elements);if("x"==t)e._title.x=i.center,e._title._y=e.orientation==ti?e.pathPos+e.titleOffset:e.pathPos-e.titleOffset;else if("y"===t)e._title.x=i.center,e._title._y=i.middle-i.width/2-e.titleOffset,e._title._rotate=e.orientation==ii?[-90,i.center,i.middle]:[90,i.center,i.middle];else if("angle"===t){let t=e.elements[0].parent.layout;t.type===B.CLUSTER&&(e._title.x=t.x,e._title._y=t.y)}}}class Ei extends Wt{constructor(e){super(e)}run(){super.run();let e,t=this.vars.find(e=>e.type===Te.ALIGNMENT).alignment,i=t.anchor,s=t.elements;i==v.Top||i==v.LEFT?e=Math.min(...s.map(e=>e.bounds[i])):i==v.BOTTOM||i==v.RIGHT?e=Math.max(...s.map(e=>e.bounds[i])):i!=v.CENTER&&i!=v.MIDDLE||(e=r.mean(s.map(e=>e.bounds[i])));for(let r of s){let s=Ge(r,t.channel);if(s){let n=e-r.bounds[i];Fe(s,"x"===t.channel?n:0,"x"===t.channel?0:n)}}for(let e of s)x(e)}}class Ai extends Se{constructor(e,t){super(e),this._aln=t}get alignment(){return this._aln}}class Ci extends F{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=C(e.parent);for(let e of t){let t=e.layout;if(!t)continue;let i=ge(e.children[0]);if(!i)continue;let s=i.linkList.map(e=>({source:i.getNode(e.source),target:i.getNode(e.target)})),n=r.forceSimulation(i.nodeList).force("charge",r.forceManyBody().strength(-t._repulsion)).force("link",r.forceLink(s).id(e=>e.id).distance(t._linkDistance)).force("x",r.forceX()).force("y",r.forceY()).force("center",r.forceCenter(t._x,t._y).strength(t._attraction));n.stop(),n.tick(t._iterations);for(let t=0;t<e.children.length;t++){let r=e.children[t],s=i.nodeList[t];Fe(r,s.x-r.x,s.y-r.y)}}let i=V(e,!0);for(let e of i)x(e)}}class ki extends F{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=C(e);switch(e.type){case Vt.Arc:this._updateArcLinks(t);break;case Vt.BezierCurve:this._updateBezierLinks(t);break;case Vt.BundledPath:this._updateBundledLinks(t);break;case Vt.Chord:this._updateChordLinks(t);break;case Vt.Line:default:this._updateLineLinks(t)}x(e)}_updateArcLinks(e){for(let t of e){let e=t.source.x<t.target.x?t.source:t.target,i=t.source.x<t.target.x?t.target:t.source;t._x=(e.x+i.x)/2,t._y=(e.y+i.y)/2,t._innerRadius=Math.sqrt(Math.pow(e.x-i.x,2)+Math.pow(e.y-i.y,2))/2,t._outerRadius=t._innerRadius+t._thickness;let r=he(e.x,e.y,t._x,t._y),s=he(i.x,i.y,t._x,t._y);t.direction===Z.CLOCKWISE&&([r,s]=[s,r]),je(t,"startAngle",r),je(t,"angle",Math.abs(s-r))}}_updateBezierLinks(e){let t=this._inputVars[0].element,i=C(t),r=t.parent.layout;r.type===B.DIRECTED||r.type===B.TIDYTREE?this._updateBezierLinksForDirectedGraph(i,e,r):r.type===B.CLUSTER&&this._updateBezierLinksForClusteredGraph(i,e,r)}_updateBezierLinksForClusteredGraph(e,t,i){const s=i._d3Root.descendants(),n=new Map(s.map(e=>[Si(e),e])),a=new Map(s.map(e=>[e.data[me],Si(e)]));if(i.isRadial()){const e=r.linkRadial().angle(e=>e.x).radius(e=>e.y);for(let r of t){let t=r.source,s=r.target,o=t.dataScope.getAttrVal(me),l=s.dataScope.getAttrVal(me),h=n.get(a.get(o)),c=n.get(a.get(l));r._d=se(e({source:h,target:c}),i.x,i.y)}}else if(i.orientation===Y){const e=r.linkVertical().x(e=>e.x).y(e=>e.y);for(let r of t){let t=r.source,s=r.target,o=t.dataScope.getAttrVal(me),l=s.dataScope.getAttrVal(me),h=n.get(a.get(o)),c=n.get(a.get(l));r._d=se(e({source:h,target:c}),i.left-i._x0,i.top)}}else if(i.orientation===H){const e=r.linkHorizontal().x(e=>e.y).y(e=>e.x);for(let r of t){let t=r.source,s=r.target,o=t.dataScope.getAttrVal(me),l=s.dataScope.getAttrVal(me),h=n.get(a.get(o)),c=n.get(a.get(l));r._d=se(e({source:h,target:c}),i.left,i.top-i._x0)}}}_updateBezierLinksForDirectedGraph(e,t,i){let r={},s={},n={},a={};for(let t of e){s[t.id]=0,r[t.id]=0;let e=t.links.filter(e=>e.source===t),i=t.links.filter(e=>e.target===t);a[t.id]=i.map(e=>e.strokeWidth).reduce((e,t)=>e+t,0),n[t.id]=e.map(e=>e.strokeWidth).reduce((e,t)=>e+t,0)}i.spreadLinks&&("LR"===i.direction||"RL"===i.direction?t.sort((e,t)=>he(e.target.bounds.x,e.target.bounds.y,e.source.bounds.x,e.source.bounds.y)-he(t.target.bounds.x,t.target.bounds.y,t.source.bounds.x,t.source.bounds.y)):t.sort((e,t)=>he(t.target.bounds.x,t.target.bounds.y,t.source.bounds.x,t.source.bounds.y)-he(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,h,c=e.source,d=e.target;i.spreadLinks?"LR"===i.direction||"RL"===i.direction?(t=c.bounds[e.sourceAnchor[0]]+e.sourceOffset[0],l=d.bounds[e.targetAnchor[0]]+e.targetOffset[0],o=c.bounds[e.sourceAnchor[1]]+e.sourceOffset[1]-n[c.id]/2+r[c.id]+e.strokeWidth/2,h=d.bounds[e.targetAnchor[1]]+e.targetOffset[1]-a[d.id]/2+s[d.id]+e.strokeWidth/2,r[c.id]+=e.strokeWidth,s[d.id]+=e.strokeWidth):(o=c.bounds[e.sourceAnchor[1]]+e.sourceOffset[1],h=d.bounds[e.targetAnchor[1]]+e.targetOffset[1],t=c.bounds[e.sourceAnchor[0]]+e.sourceOffset[0]-n[c.id]/2+r[c.id]+e.strokeWidth/2,l=d.bounds[e.targetAnchor[0]]+e.targetOffset[0]-a[d.id]/2+s[d.id]+e.strokeWidth/2,r[c.id]+=e.strokeWidth,s[d.id]+=e.strokeWidth):(t=c.bounds[e.sourceAnchor[0]]+e.sourceOffset[0],o=c.bounds[e.sourceAnchor[1]]+e.sourceOffset[1],l=d.bounds[e.targetAnchor[0]]+e.targetOffset[0],h=d.bounds[e.targetAnchor[1]]+e.targetOffset[1]),e.orientation===H?e._setVertices([[t,o],[(t+l)/2,o],[t,h],[l,h]]):e.orientation===Y&&e._setVertices([[t,o],[t,(o+h)/2],[l,o],[l,h]])}}_updateBundledLinks(e){let t=this._inputVars[0].element.parent.layout;if(t.type!==B.CLUSTER)throw"Bundled links must work on a cluster layout";let i=t._d3Root.leaves();const s=new Map(i.map(e=>[Si(e),e])),n=new Map(i.map(e=>[e.data[me],Si(e)])),a=r.lineRadial().curve(r.curveBundle.beta(e[0]._strength)).radius(e=>e.y).angle(e=>e.x);for(let i of e){let e=i.source.dataScope.getAttrVal(me),r=i.target.dataScope.getAttrVal(me),o=s.get(n.get(e)),l=s.get(n.get(r));(o.outgoing??=[]).push([o,l]),l.incoming??=[];let h=o.path(l);i._d=se(a(h),t.x,t.y)}}_updateChordLinks(e){for(let t of e){let e=t.source,i=t.target,r=Ce(e.x,e.y,e.innerRadius,e.startAngle),s=Ce(e.x,e.y,e.innerRadius,e.endAngle),n=Ce(i.x,i.y,i.innerRadius,i.startAngle),a=Ce(i.x,i.y,i.innerRadius,i.endAngle);t._d=["M",r[0],r[1],"Q",e.x,e.y,a[0],a[1],"A",e.x,e.y,i.angle,i.angle>180?1:0,1,n[0],n[1],"Q",e.x,e.y,s[0],s[1],"A",e.x,e.y,e.angle,e.angle>180?1:0,1,r[0],r[1]].join(" "),t._dirty=!0}}_updateLineLinks(e){for(let t of e){let e=t.source,i=t.target;t.vertices[0]._x=e.bounds.x,t.vertices[0]._y=e.bounds.y,t.vertices[1]._x=i.bounds.x,t.vertices[1]._y=i.bounds.y,t._dirty=!0}}}function Si(e){return`${e.parent?Si(e.parent)+".":""}${e.data[me]}`}var Ti="\0";function Ri(e,t){e[t]?e[t]++:e[t]=1}function Oi(e,t){--e[t]||delete e[t]}function Ii(e,t,i,r){var s=""+t,n=""+i;if(!e&&s>n){var a=s;s=n,n=a}return s+""+n+""+(void 0===r?"\0":r)}function Ni(e,t){return Ii(e,t.v,t.w,t.name)}var Li=class{_isDirected=!0;_isMultigraph=!1;_isCompound=!1;_label;_defaultNodeLabelFn=()=>{};_defaultEdgeLabelFn=()=>{};_nodes={};_in={};_preds={};_out={};_sucs={};_edgeObjs={};_edgeLabels={};_nodeCount=0;_edgeCount=0;_parent;_children;constructor(e){e&&(this._isDirected=!Object.hasOwn(e,"directed")||e.directed,this._isMultigraph=!!Object.hasOwn(e,"multigraph")&&e.multigraph,this._isCompound=!!Object.hasOwn(e,"compound")&&e.compound),this._isCompound&&(this._parent={},this._children={},this._children[Ti]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(e){return this._label=e,this}graph(){return this._label}setDefaultNodeLabel(e){return this._defaultNodeLabelFn=e,"function"!=typeof e&&(this._defaultNodeLabelFn=()=>e),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var e=this;return this.nodes().filter(t=>0===Object.keys(e._in[t]).length)}sinks(){var e=this;return this.nodes().filter(t=>0===Object.keys(e._out[t]).length)}setNodes(e,t){var i=arguments,r=this;return e.forEach(function(e){i.length>1?r.setNode(e,t):r.setNode(e)}),this}setNode(e,t){return Object.hasOwn(this._nodes,e)?(arguments.length>1&&(this._nodes[e]=t),this):(this._nodes[e]=arguments.length>1?t:this._defaultNodeLabelFn(e),this._isCompound&&(this._parent[e]=Ti,this._children[e]={},this._children[Ti][e]=!0),this._in[e]={},this._preds[e]={},this._out[e]={},this._sucs[e]={},++this._nodeCount,this)}node(e){return this._nodes[e]}hasNode(e){return Object.hasOwn(this._nodes,e)}removeNode(e){var t=this;if(Object.hasOwn(this._nodes,e)){var i=e=>t.removeEdge(t._edgeObjs[e]);delete this._nodes[e],this._isCompound&&(this._removeFromParentsChildList(e),delete this._parent[e],this.children(e).forEach(function(e){t.setParent(e)}),delete this._children[e]),Object.keys(this._in[e]).forEach(i),delete this._in[e],delete this._preds[e],Object.keys(this._out[e]).forEach(i),delete this._out[e],delete this._sucs[e],--this._nodeCount}return this}setParent(e,t){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(void 0===t)t=Ti;else{for(var i=t+="";void 0!==i;i=this.parent(i))if(i===e)throw new Error("Setting "+t+" as parent of "+e+" would create a cycle");this.setNode(t)}return this.setNode(e),this._removeFromParentsChildList(e),this._parent[e]=t,this._children[t][e]=!0,this}_removeFromParentsChildList(e){delete this._children[this._parent[e]][e]}parent(e){if(this._isCompound){var t=this._parent[e];if(t!==Ti)return t}}children(e=Ti){if(this._isCompound){var t=this._children[e];if(t)return Object.keys(t)}else{if(e===Ti)return this.nodes();if(this.hasNode(e))return[]}}predecessors(e){var t=this._preds[e];if(t)return Object.keys(t)}successors(e){var t=this._sucs[e];if(t)return Object.keys(t)}neighbors(e){var t=this.predecessors(e);if(t){const r=new Set(t);for(var i of this.successors(e))r.add(i);return Array.from(r.values())}}isLeaf(e){return 0===(this.isDirected()?this.successors(e):this.neighbors(e)).length}filterNodes(e){var t=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});t.setGraph(this.graph());var i=this;Object.entries(this._nodes).forEach(function([i,r]){e(i)&&t.setNode(i,r)}),Object.values(this._edgeObjs).forEach(function(e){t.hasNode(e.v)&&t.hasNode(e.w)&&t.setEdge(e,i.edge(e))});var r={};function s(e){var n=i.parent(e);return void 0===n||t.hasNode(n)?(r[e]=n,n):n in r?r[n]:s(n)}return this._isCompound&&t.nodes().forEach(e=>t.setParent(e,s(e))),t}setDefaultEdgeLabel(e){return this._defaultEdgeLabelFn=e,"function"!=typeof e&&(this._defaultEdgeLabelFn=()=>e),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(e,t){var i=this,r=arguments;return e.reduce(function(e,s){return r.length>1?i.setEdge(e,s,t):i.setEdge(e,s),s}),this}setEdge(){var e,t,i,r,s=!1,n=arguments[0];"object"==typeof n&&null!==n&&"v"in n?(e=n.v,t=n.w,i=n.name,2===arguments.length&&(r=arguments[1],s=!0)):(e=n,t=arguments[1],i=arguments[3],arguments.length>2&&(r=arguments[2],s=!0)),e=""+e,t=""+t,void 0!==i&&(i=""+i);var a=Ii(this._isDirected,e,t,i);if(Object.hasOwn(this._edgeLabels,a))return s&&(this._edgeLabels[a]=r),this;if(void 0!==i&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(e),this.setNode(t),this._edgeLabels[a]=s?r:this._defaultEdgeLabelFn(e,t,i);var o=function(e,t,i,r){var s=""+t,n=""+i;if(!e&&s>n){var a=s;s=n,n=a}var o={v:s,w:n};r&&(o.name=r);return o}(this._isDirected,e,t,i);return e=o.v,t=o.w,Object.freeze(o),this._edgeObjs[a]=o,Ri(this._preds[t],e),Ri(this._sucs[e],t),this._in[t][a]=o,this._out[e][a]=o,this._edgeCount++,this}edge(e,t,i){var r=1===arguments.length?Ni(this._isDirected,arguments[0]):Ii(this._isDirected,e,t,i);return this._edgeLabels[r]}edgeAsObj(){const e=this.edge(...arguments);return"object"!=typeof e?{label:e}:e}hasEdge(e,t,i){var r=1===arguments.length?Ni(this._isDirected,arguments[0]):Ii(this._isDirected,e,t,i);return Object.hasOwn(this._edgeLabels,r)}removeEdge(e,t,i){var r=1===arguments.length?Ni(this._isDirected,arguments[0]):Ii(this._isDirected,e,t,i),s=this._edgeObjs[r];return s&&(e=s.v,t=s.w,delete this._edgeLabels[r],delete this._edgeObjs[r],Oi(this._preds[t],e),Oi(this._sucs[e],t),delete this._in[t][r],delete this._out[e][r],this._edgeCount--),this}inEdges(e,t){var i=this._in[e];if(i){var r=Object.values(i);return t?r.filter(e=>e.v===t):r}}outEdges(e,t){var i=this._out[e];if(i){var r=Object.values(i);return t?r.filter(e=>e.w===t):r}}nodeEdges(e,t){var i=this.inEdges(e,t);if(i)return i.concat(this.outEdges(e,t))}},Vi={Graph:Li,version:"2.2.4"},Pi=Li,Mi={write:function(e){var t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:Di(e),edges:Bi(e)};void 0!==e.graph()&&(t.value=structuredClone(e.graph()));return t},read:function(e){var t=new Pi(e.options).setGraph(e.value);return e.nodes.forEach(function(e){t.setNode(e.v,e.value),e.parent&&t.setParent(e.v,e.parent)}),e.edges.forEach(function(e){t.setEdge({v:e.v,w:e.w,name:e.name},e.value)}),t}};function Di(e){return e.nodes().map(function(t){var i=e.node(t),r=e.parent(t),s={v:t};return void 0!==i&&(s.value=i),void 0!==r&&(s.parent=r),s})}function Bi(e){return e.edges().map(function(t){var i=e.edge(t),r={v:t.v,w:t.w};return void 0!==t.name&&(r.name=t.name),void 0!==i&&(r.value=i),r})}var Gi=function(e){var t,i={},r=[];function s(r){Object.hasOwn(i,r)||(i[r]=!0,t.push(r),e.successors(r).forEach(s),e.predecessors(r).forEach(s))}return e.nodes().forEach(function(e){t=[],s(e),t.length&&r.push(t)}),r};var Fi=class{_arr=[];_keyIndices={};size(){return this._arr.length}keys(){return this._arr.map(function(e){return e.key})}has(e){return Object.hasOwn(this._keyIndices,e)}priority(e){var t=this._keyIndices[e];if(void 0!==t)return this._arr[t].priority}min(){if(0===this.size())throw new Error("Queue underflow");return this._arr[0].key}add(e,t){var i=this._keyIndices;if(e=String(e),!Object.hasOwn(i,e)){var r=this._arr,s=r.length;return i[e]=s,r.push({key:e,priority:t}),this._decrease(s),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var e=this._arr.pop();return delete this._keyIndices[e.key],this._heapify(0),e.key}decrease(e,t){var i=this._keyIndices[e];if(t>this._arr[i].priority)throw new Error("New priority is greater than current priority. Key: "+e+" Old: "+this._arr[i].priority+" New: "+t);this._arr[i].priority=t,this._decrease(i)}_heapify(e){var t=this._arr,i=2*e,r=i+1,s=e;i<t.length&&(s=t[i].priority<t[s].priority?i:s,r<t.length&&(s=t[r].priority<t[s].priority?r:s),s!==e&&(this._swap(e,s),this._heapify(s)))}_decrease(e){for(var t,i=this._arr,r=i[e].priority;0!==e&&!(i[t=e>>1].priority<r);)this._swap(e,t),e=t}_swap(e,t){var i=this._arr,r=this._keyIndices,s=i[e],n=i[t];i[e]=n,i[t]=s,r[n.key]=e,r[s.key]=t}},zi=Fi,ji=function(e,t,i,r){return function(e,t,i,r){var s,n,a={},o=new zi,l=function(e){var t=e.v!==s?e.v:e.w,r=a[t],l=i(e),h=n.distance+l;if(l<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+e+" Weight: "+l);h<r.distance&&(r.distance=h,r.predecessor=s,o.decrease(t,h))};e.nodes().forEach(function(e){var i=e===t?0:Number.POSITIVE_INFINITY;a[e]={distance:i},o.add(e,i)});for(;o.size()>0&&(s=o.removeMin(),(n=a[s]).distance!==Number.POSITIVE_INFINITY);)r(s).forEach(l);return a}(e,String(t),i||Wi,r||function(t){return e.outEdges(t)})},Wi=()=>1;var Ui=ji,Hi=function(e,t,i){return e.nodes().reduce(function(r,s){return r[s]=Ui(e,s,t,i),r},{})};var Yi=function(e){var t=0,i=[],r={},s=[];function n(a){var o=r[a]={onStack:!0,lowlink:t,index:t++};if(i.push(a),e.successors(a).forEach(function(e){Object.hasOwn(r,e)?r[e].onStack&&(o.lowlink=Math.min(o.lowlink,r[e].index)):(n(e),o.lowlink=Math.min(o.lowlink,r[e].lowlink))}),o.lowlink===o.index){var l,h=[];do{l=i.pop(),r[l].onStack=!1,h.push(l)}while(a!==l);s.push(h)}}return e.nodes().forEach(function(e){Object.hasOwn(r,e)||n(e)}),s};var Xi=Yi,qi=function(e){return Xi(e).filter(function(t){return t.length>1||1===t.length&&e.hasEdge(t[0],t[0])})};var Ki=function(e,t,i){return function(e,t,i){var r={},s=e.nodes();return s.forEach(function(e){r[e]={},r[e][e]={distance:0},s.forEach(function(t){e!==t&&(r[e][t]={distance:Number.POSITIVE_INFINITY})}),i(e).forEach(function(i){var s=i.v===e?i.w:i.v,n=t(i);r[e][s]={distance:n,predecessor:e}})}),s.forEach(function(e){var t=r[e];s.forEach(function(i){var n=r[i];s.forEach(function(i){var r=n[e],s=t[i],a=n[i],o=r.distance+s.distance;o<a.distance&&(a.distance=o,a.predecessor=s.predecessor)})})}),r}(e,t||Zi,i||function(t){return e.outEdges(t)})},Zi=()=>1;function $i(e){var t={},i={},r=[];if(e.sinks().forEach(function s(n){if(Object.hasOwn(i,n))throw new Ji;Object.hasOwn(t,n)||(i[n]=!0,t[n]=!0,e.predecessors(n).forEach(s),delete i[n],r.push(n))}),Object.keys(t).length!==e.nodeCount())throw new Ji;return r}class Ji extends Error{constructor(){super(...arguments)}}var Qi=$i;$i.CycleException=Ji;var er=Qi;var tr=function(e,t,i){Array.isArray(t)||(t=[t]);var r=e.isDirected()?t=>e.successors(t):t=>e.neighbors(t),s="post"===i?ir:rr,n=[],a={};return t.forEach(t=>{if(!e.hasNode(t))throw new Error("Graph does not have node: "+t);s(t,r,a,n)}),n};function ir(e,t,i,r){for(var s=[[e,!1]];s.length>0;){var n=s.pop();n[1]?r.push(n[0]):Object.hasOwn(i,n[0])||(i[n[0]]=!0,s.push([n[0],!0]),sr(t(n[0]),e=>s.push([e,!1])))}}function rr(e,t,i,r){for(var s=[e];s.length>0;){var n=s.pop();Object.hasOwn(i,n)||(i[n]=!0,r.push(n),sr(t(n),e=>s.push(e)))}}function sr(e,t){for(var i=e.length;i--;)t(e[i],i,e);return e}var nr=tr;var ar=tr;var or=Li,lr=Fi;var hr={Graph:Vi.Graph,json:Mi,alg:{components:Gi,dijkstra:ji,dijkstraAll:Hi,findCycles:qi,floydWarshall:Ki,isAcyclic:function(e){try{er(e)}catch(e){if(e instanceof er.CycleException)return!1;throw e}return!0},postorder:function(e,t){return nr(e,t,"post")},preorder:function(e,t){return ar(e,t,"pre")},prim:function(e,t){var i,r=new or,s={},n=new lr;function a(e){var r=e.v===i?e.w:e.v,a=n.priority(r);if(void 0!==a){var o=t(e);o<a&&(s[r]=i,n.decrease(r,o))}}if(0===e.nodeCount())return r;e.nodes().forEach(function(e){n.add(e,Number.POSITIVE_INFINITY),r.setNode(e)}),n.decrease(e.nodes()[0],0);var o=!1;for(;n.size()>0;){if(i=n.removeMin(),Object.hasOwn(s,i))r.setEdge(i,s[i]);else{if(o)throw new Error("Input graph is not connected: "+e);o=!0}e.nodeEdges(i).forEach(a)}return r},tarjan:Yi,topsort:Qi},version:Vi.version};function cr(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function dr(e,t){if("_next"!==e&&"_prev"!==e)return t}let ur=hr.Graph,pr=class{constructor(){let e={};e._next=e._prev=e,this._sentinel=e}dequeue(){let e=this._sentinel,t=e._prev;if(t!==e)return cr(t),t}enqueue(e){let t=this._sentinel;e._prev&&e._next&&cr(e),e._next=t._next,t._next._prev=e,t._next=e,e._prev=t}toString(){let e=[],t=this._sentinel,i=t._prev;for(;i!==t;)e.push(JSON.stringify(i,dr)),i=i._prev;return"["+e.join(", ")+"]"}};var _r=function(e,t){if(e.nodeCount()<=1)return[];let i=function(e,t){let i=new ur,r=0,s=0;e.nodes().forEach(e=>{i.setNode(e,{v:e,in:0,out:0})}),e.edges().forEach(e=>{let n=i.edge(e.v,e.w)||0,a=t(e),o=n+a;i.setEdge(e.v,e.w,o),s=Math.max(s,i.node(e.v).out+=a),r=Math.max(r,i.node(e.w).in+=a)});let n=function(e){const t=[];for(let i=0;i<e;i++)t.push(i);return t}(s+r+3).map(()=>new pr),a=r+1;return i.nodes().forEach(e=>{yr(n,a,i.node(e))}),{graph:i,buckets:n,zeroIdx:a}}(e,t||fr);return function(e,t,i){let r,s=[],n=t[t.length-1],a=t[0];for(;e.nodeCount();){for(;r=a.dequeue();)gr(e,t,i,r);for(;r=n.dequeue();)gr(e,t,i,r);if(e.nodeCount())for(let n=t.length-2;n>0;--n)if(r=t[n].dequeue(),r){s=s.concat(gr(e,t,i,r,!0));break}}return s}(i.graph,i.buckets,i.zeroIdx).flatMap(t=>e.outEdges(t.v,t.w))};let fr=()=>1;function gr(e,t,i,r,s){let n=s?[]:void 0;return e.inEdges(r.v).forEach(r=>{let a=e.edge(r),o=e.node(r.v);s&&n.push({v:r.v,w:r.w}),o.out-=a,yr(t,i,o)}),e.outEdges(r.v).forEach(r=>{let s=e.edge(r),n=r.w,a=e.node(n);a.in-=s,yr(t,i,a)}),e.removeNode(r.v),n}function yr(e,t,i){i.out?i.in?e[i.out-i.in+t].enqueue(i):e[e.length-1].enqueue(i):e[0].enqueue(i)}let mr=hr.Graph;var br={addBorderNode:function(e,t,i,r){let s={width:0,height:0};arguments.length>=4&&(s.rank=i,s.order=r);return xr(e,"border",s,t)},addDummyNode:xr,applyWithChunking:wr,asNonCompoundGraph:function(e){let t=new mr({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(i=>{e.children(i).length||t.setNode(i,e.node(i))}),e.edges().forEach(i=>{t.setEdge(i,e.edge(i))}),t},buildLayerMatrix:function(e){let t=kr(Er(e)+1).map(()=>[]);return e.nodes().forEach(i=>{let r=e.node(i),s=r.rank;void 0!==s&&(t[s][r.order]=i)}),t},intersectRect:function(e,t){let i,r,s=e.x,n=e.y,a=t.x-s,o=t.y-n,l=e.width/2,h=e.height/2;if(!a&&!o)throw new Error("Not possible to find intersection inside of the rectangle");Math.abs(o)*l>Math.abs(a)*h?(o<0&&(h=-h),i=h*a/o,r=h):(a<0&&(l=-l),i=l,r=l*o/a);return{x:s+i,y:n+r}},mapValues:function(e,t){let i=t;"string"==typeof t&&(i=e=>e[t]);return Object.entries(e).reduce((e,[t,r])=>(e[t]=i(r,t),e),{})},maxRank:Er,normalizeRanks:function(e){let t=e.nodes().map(t=>{let i=e.node(t).rank;return void 0===i?Number.MAX_VALUE:i}),i=wr(Math.min,t);e.nodes().forEach(t=>{let r=e.node(t);Object.hasOwn(r,"rank")&&(r.rank-=i)})},notime:function(e,t){return t()},partition:function(e,t){let i={lhs:[],rhs:[]};return e.forEach(e=>{t(e)?i.lhs.push(e):i.rhs.push(e)}),i},pick:function(e,t){const i={};for(const r of t)void 0!==e[r]&&(i[r]=e[r]);return i},predecessorWeights:function(e){let t=e.nodes().map(t=>{let i={};return e.inEdges(t).forEach(t=>{i[t.v]=(i[t.v]||0)+e.edge(t).weight}),i});return Sr(e.nodes(),t)},range:kr,removeEmptyRanks:function(e){let t=e.nodes().map(t=>e.node(t).rank),i=wr(Math.min,t),r=[];e.nodes().forEach(t=>{let s=e.node(t).rank-i;r[s]||(r[s]=[]),r[s].push(t)});let s=0,n=e.graph().nodeRankFactor;Array.from(r).forEach((t,i)=>{void 0===t&&i%n!==0?--s:void 0!==t&&s&&t.forEach(t=>e.node(t).rank+=s)})},simplify:function(e){let t=(new mr).setGraph(e.graph());return e.nodes().forEach(i=>t.setNode(i,e.node(i))),e.edges().forEach(i=>{let r=t.edge(i.v,i.w)||{weight:0,minlen:1},s=e.edge(i);t.setEdge(i.v,i.w,{weight:r.weight+s.weight,minlen:Math.max(r.minlen,s.minlen)})}),t},successorWeights:function(e){let t=e.nodes().map(t=>{let i={};return e.outEdges(t).forEach(t=>{i[t.w]=(i[t.w]||0)+e.edge(t).weight}),i});return Sr(e.nodes(),t)},time:function(e,t){let i=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-i)+"ms")}},uniqueId:Cr,zipObject:Sr};function xr(e,t,i,r){for(var s=r;e.hasNode(s);)s=Cr(r);return i.dummy=t,e.setNode(s,i),s}const vr=65535;function wr(e,t){if(t.length>vr){const i=function(e,t=vr){const i=[];for(let r=0;r<e.length;r+=t){const s=e.slice(r,r+t);i.push(s)}return i}(t);return e.apply(null,i.map(t=>e.apply(null,t)))}return e.apply(null,t)}function Er(e){const t=e.nodes().map(t=>{let i=e.node(t).rank;return void 0===i?Number.MIN_VALUE:i});return wr(Math.max,t)}let Ar=0;function Cr(e){return e+""+ ++Ar}function kr(e,t,i=1){null==t&&(t=e,e=0);let r=e=>e<t;i<0&&(r=e=>t<e);const s=[];for(let t=e;r(t);t+=i)s.push(t);return s}function Sr(e,t){return e.reduce((e,i,r)=>(e[i]=t[r],e),{})}let Tr=_r,Rr=br.uniqueId;var Or={run:function(e){("greedy"===e.graph().acyclicer?Tr(e,function(e){return t=>e.edge(t).weight}(e)):function(e){let t=[],i={},r={};function s(n){Object.hasOwn(r,n)||(r[n]=!0,i[n]=!0,e.outEdges(n).forEach(e=>{Object.hasOwn(i,e.w)?t.push(e):s(e.w)}),delete i[n])}return e.nodes().forEach(s),t}(e)).forEach(t=>{let i=e.edge(t);e.removeEdge(t),i.forwardName=t.name,i.reversed=!0,e.setEdge(t.w,t.v,i,Rr("rev"))})},undo:function(e){e.edges().forEach(t=>{let i=e.edge(t);if(i.reversed){e.removeEdge(t);let r=i.forwardName;delete i.reversed,delete i.forwardName,e.setEdge(t.w,t.v,i,r)}})}};let Ir=br;var Nr={run:function(e){e.graph().dummyChains=[],e.edges().forEach(t=>function(e,t){let i,r,s,n=t.v,a=e.node(n).rank,o=t.w,l=e.node(o).rank,h=t.name,c=e.edge(t),d=c.labelRank;if(l===a+1)return;for(e.removeEdge(t),s=0,++a;a<l;++s,++a)c.points=[],r={width:0,height:0,edgeLabel:c,edgeObj:t,rank:a},i=Ir.addDummyNode(e,"edge",r,"_d"),a===d&&(r.width=c.width,r.height=c.height,r.dummy="edge-label",r.labelpos=c.labelpos),e.setEdge(n,i,{weight:c.weight},h),0===s&&e.graph().dummyChains.push(i),n=i;e.setEdge(n,o,{weight:c.weight},h)}(e,t))},undo:function(e){e.graph().dummyChains.forEach(t=>{let i,r=e.node(t),s=r.edgeLabel;for(e.setEdge(r.edgeObj,s);r.dummy;)i=e.successors(t)[0],e.removeNode(t),s.points.push({x:r.x,y:r.y}),"edge-label"===r.dummy&&(s.x=r.x,s.y=r.y,s.width=r.width,s.height=r.height),t=i,r=e.node(t)})}};const{applyWithChunking:Lr}=br;var Vr={longestPath:function(e){var t={};e.sources().forEach(function i(r){var s=e.node(r);if(Object.hasOwn(t,r))return s.rank;t[r]=!0;let n=e.outEdges(r).map(t=>null==t?Number.POSITIVE_INFINITY:i(t.w)-e.edge(t).minlen);var a=Lr(Math.min,n);return a===Number.POSITIVE_INFINITY&&(a=0),s.rank=a})},slack:function(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}};var Pr=hr.Graph,Mr=Vr.slack,Dr=function(e){var t,i,r=new Pr({directed:!1}),s=e.nodes()[0],n=e.nodeCount();r.setNode(s,{});for(;Br(r,e)<n;)t=Gr(r,e),i=r.hasNode(t.v)?Mr(e,t):-Mr(e,t),Fr(r,e,i);return r};function Br(e,t){return e.nodes().forEach(function i(r){t.nodeEdges(r).forEach(s=>{var n=s.v,a=r===n?s.w:n;e.hasNode(a)||Mr(t,s)||(e.setNode(a,{}),e.setEdge(r,a,{}),i(a))})}),e.nodeCount()}function Gr(e,t){return t.edges().reduce((i,r)=>{let s=Number.POSITIVE_INFINITY;return e.hasNode(r.v)!==e.hasNode(r.w)&&(s=Mr(t,r)),s<i[0]?[s,r]:i},[Number.POSITIVE_INFINITY,null])[1]}function Fr(e,t,i){e.nodes().forEach(e=>t.node(e).rank+=i)}var zr=Dr,jr=Vr.slack,Wr=Vr.longestPath,Ur=hr.alg.preorder,Hr=hr.alg.postorder,Yr=br.simplify,Xr=qr;function qr(e){e=Yr(e),Wr(e);var t,i=zr(e);for($r(i),Kr(i,e);t=Qr(i);)ts(i,e,t,es(i,e,t))}function Kr(e,t){var i=Hr(e,e.nodes());(i=i.slice(0,i.length-1)).forEach(i=>function(e,t,i){var r=e.node(i),s=r.parent;e.edge(i,s).cutvalue=Zr(e,t,i)}(e,t,i))}function Zr(e,t,i){var r=e.node(i).parent,s=!0,n=t.edge(i,r),a=0;return n||(s=!1,n=t.edge(r,i)),a=n.weight,t.nodeEdges(i).forEach(n=>{var o,l,h=n.v===i,c=h?n.w:n.v;if(c!==r){var d=h===s,u=t.edge(n).weight;if(a+=d?u:-u,o=i,l=c,e.hasEdge(o,l)){var p=e.edge(i,c).cutvalue;a+=d?-p:p}}}),a}function $r(e,t){arguments.length<2&&(t=e.nodes()[0]),Jr(e,{},1,t)}function Jr(e,t,i,r,s){var n=i,a=e.node(r);return t[r]=!0,e.neighbors(r).forEach(s=>{Object.hasOwn(t,s)||(i=Jr(e,t,i,s,r))}),a.low=n,a.lim=i++,s?a.parent=s:delete a.parent,i}function Qr(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function es(e,t,i){var r=i.v,s=i.w;t.hasEdge(r,s)||(r=i.w,s=i.v);var n=e.node(r),a=e.node(s),o=n,l=!1;n.lim>a.lim&&(o=a,l=!0);var h=t.edges().filter(t=>l===is(e,e.node(t.v),o)&&l!==is(e,e.node(t.w),o));return h.reduce((e,i)=>jr(t,i)<jr(t,e)?i:e)}function ts(e,t,i,r){var s=i.v,n=i.w;e.removeEdge(s,n),e.setEdge(r.v,r.w,{}),$r(e),Kr(e,t),function(e,t){var i=e.nodes().find(e=>!t.node(e).parent),r=Ur(e,i);(r=r.slice(1)).forEach(i=>{var r=e.node(i).parent,s=t.edge(i,r),n=!1;s||(s=t.edge(r,i),n=!0),t.node(i).rank=t.node(r).rank+(n?s.minlen:-s.minlen)})}(e,t)}function is(e,t,i){return i.low<=t.lim&&t.lim<=i.lim}qr.initLowLimValues=$r,qr.initCutValues=Kr,qr.calcCutValue=Zr,qr.leaveEdge=Qr,qr.enterEdge=es,qr.exchangeEdges=ts;var rs=Vr.longestPath,ss=Dr,ns=Xr,as=function(e){var t=e.graph().ranker;if(t instanceof Function)return t(e);switch(e.graph().ranker){case"network-simplex":default:ls(e);break;case"tight-tree":!function(e){rs(e),ss(e)}(e);break;case"longest-path":os(e);case"none":}};var os=rs;function ls(e){ns(e)}var hs=function(e){let t=function(e){let t={},i=0;function r(s){let n=i;e.children(s).forEach(r),t[s]={low:n,lim:i++}}return e.children().forEach(r),t}(e);e.graph().dummyChains.forEach(i=>{let r=e.node(i),s=r.edgeObj,n=function(e,t,i,r){let s,n,a=[],o=[],l=Math.min(t[i].low,t[r].low),h=Math.max(t[i].lim,t[r].lim);s=i;do{s=e.parent(s),a.push(s)}while(s&&(t[s].low>l||h>t[s].lim));n=s,s=r;for(;(s=e.parent(s))!==n;)o.push(s);return{path:a.concat(o.reverse()),lca:n}}(e,t,s.v,s.w),a=n.path,o=n.lca,l=0,h=a[l],c=!0;for(;i!==s.w;){if(r=e.node(i),c){for(;(h=a[l])!==o&&e.node(h).maxRank<r.rank;)l++;h===o&&(c=!1)}if(!c){for(;l<a.length-1&&e.node(h=a[l+1]).minRank<=r.rank;)l++;h=a[l]}e.setParent(i,h),i=e.successors(i)[0]}})};let cs=br;var ds={run:function(e){let t=cs.addDummyNode(e,"root",{},"_root"),i=function(e){var t={};function i(r,s){var n=e.children(r);n&&n.length&&n.forEach(e=>i(e,s+1)),t[r]=s}return e.children().forEach(e=>i(e,1)),t}(e),r=Object.values(i),s=cs.applyWithChunking(Math.max,r)-1,n=2*s+1;e.graph().nestingRoot=t,e.edges().forEach(t=>e.edge(t).minlen*=n);let a=function(e){return e.edges().reduce((t,i)=>t+e.edge(i).weight,0)}(e)+1;e.children().forEach(r=>us(e,t,n,a,s,i,r)),e.graph().nodeRankFactor=n},cleanup:function(e){var t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(t=>{e.edge(t).nestingEdge&&e.removeEdge(t)})}};function us(e,t,i,r,s,n,a){let o=e.children(a);if(!o.length)return void(a!==t&&e.setEdge(t,a,{weight:0,minlen:i}));let l=cs.addBorderNode(e,"_bt"),h=cs.addBorderNode(e,"_bb"),c=e.node(a);e.setParent(l,a),c.borderTop=l,e.setParent(h,a),c.borderBottom=h,o.forEach(o=>{us(e,t,i,r,s,n,o);let c=e.node(o),d=c.borderTop?c.borderTop:o,u=c.borderBottom?c.borderBottom:o,p=c.borderTop?r:2*r,_=d!==u?1:s-n[a]+1;e.setEdge(l,d,{weight:p,minlen:_,nestingEdge:!0}),e.setEdge(u,h,{weight:p,minlen:_,nestingEdge:!0})}),e.parent(a)||e.setEdge(t,l,{weight:0,minlen:s+n[a]})}let ps=br;var _s=function(e){e.children().forEach(function t(i){let r=e.children(i),s=e.node(i);if(r.length&&r.forEach(t),Object.hasOwn(s,"minRank")){s.borderLeft=[],s.borderRight=[];for(let t=s.minRank,r=s.maxRank+1;t<r;++t)fs(e,"borderLeft","_bl",i,s,t),fs(e,"borderRight","_br",i,s,t)}})};function fs(e,t,i,r,s,n){let a={width:0,height:0,rank:n,borderType:t},o=s[t][n-1],l=ps.addDummyNode(e,"border",a,i);s[t][n]=l,e.setParent(l,r),o&&e.setEdge(o,l,{weight:1})}function gs(e){e.nodes().forEach(t=>ys(e.node(t))),e.edges().forEach(t=>ys(e.edge(t)))}function ys(e){let t=e.width;e.width=e.height,e.height=t}function ms(e){e.y=-e.y}function bs(e){let t=e.x;e.x=e.y,e.y=t}let xs=br;var vs=function(e){let t={},i=e.nodes().filter(t=>!e.children(t).length),r=i.map(t=>e.node(t).rank),s=xs.applyWithChunking(Math.max,r),n=xs.range(s+1).map(()=>[]);function a(i){if(t[i])return;t[i]=!0;let r=e.node(i);n[r.rank].push(i),e.successors(i).forEach(a)}return i.sort((t,i)=>e.node(t).rank-e.node(i).rank).forEach(a),n};let ws=br.zipObject;function Es(e,t,i){let r=ws(i,i.map((e,t)=>t)),s=t.flatMap(t=>e.outEdges(t).map(t=>({pos:r[t.w],weight:e.edge(t).weight})).sort((e,t)=>e.pos-t.pos)),n=1;for(;n<i.length;)n<<=1;let a=2*n-1;n-=1;let o=new Array(a).fill(0),l=0;return s.forEach(e=>{let t=e.pos+n;o[t]+=e.weight;let i=0;for(;t>0;)t%2&&(i+=o[t+1]),t=t-1>>1,o[t]+=e.weight;l+=e.weight*i}),l}let As=br;let Cs=br;function ks(e,t,i){let r;for(;t.length&&(r=t[t.length-1]).i<=i;)t.pop(),e.push(r.vs),i++;return i}let Ss=function(e,t=[]){return t.map(t=>{let i=e.inEdges(t);if(i.length){let r=i.reduce((t,i)=>{let r=e.edge(i),s=e.node(i.v);return{sum:t.sum+r.weight*s.order,weight:t.weight+r.weight}},{sum:0,weight:0});return{v:t,barycenter:r.sum/r.weight,weight:r.weight}}return{v:t}})},Ts=function(e,t){let i={};return e.forEach((e,t)=>{let r=i[e.v]={indegree:0,in:[],out:[],vs:[e.v],i:t};void 0!==e.barycenter&&(r.barycenter=e.barycenter,r.weight=e.weight)}),t.edges().forEach(e=>{let t=i[e.v],r=i[e.w];void 0!==t&&void 0!==r&&(r.indegree++,t.out.push(i[e.w]))}),function(e){let t=[];function i(e){return t=>{t.merged||(void 0===t.barycenter||void 0===e.barycenter||t.barycenter>=e.barycenter)&&function(e,t){let i=0,r=0;e.weight&&(i+=e.barycenter*e.weight,r+=e.weight);t.weight&&(i+=t.barycenter*t.weight,r+=t.weight);e.vs=t.vs.concat(e.vs),e.barycenter=i/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}(e,t)}}function r(t){return i=>{i.in.push(t),0===--i.indegree&&e.push(i)}}for(;e.length;){let s=e.pop();t.push(s),s.in.reverse().forEach(i(s)),s.out.forEach(r(s))}return t.filter(e=>!e.merged).map(e=>As.pick(e,["vs","i","barycenter","weight"]))}(Object.values(i).filter(e=>!e.indegree))},Rs=function(e,t){let i=Cs.partition(e,e=>Object.hasOwn(e,"barycenter")),r=i.lhs,s=i.rhs.sort((e,t)=>t.i-e.i),n=[],a=0,o=0,l=0;r.sort((h=!!t,(e,t)=>e.barycenter<t.barycenter?-1:e.barycenter>t.barycenter?1:h?t.i-e.i:e.i-t.i)),l=ks(n,s,l),r.forEach(e=>{l+=e.vs.length,n.push(e.vs),a+=e.barycenter*e.weight,o+=e.weight,l=ks(n,s,l)});var h;let c={vs:n.flat(!0)};o&&(c.barycenter=a/o,c.weight=o);return c};var Os=function e(t,i,r,s){let n=t.children(i),a=t.node(i),o=a?a.borderLeft:void 0,l=a?a.borderRight:void 0,h={};o&&(n=n.filter(e=>e!==o&&e!==l));let c=Ss(t,n);c.forEach(i=>{if(t.children(i.v).length){let o=e(t,i.v,r,s);h[i.v]=o,Object.hasOwn(o,"barycenter")&&(a=o,void 0!==(n=i).barycenter?(n.barycenter=(n.barycenter*n.weight+a.barycenter*a.weight)/(n.weight+a.weight),n.weight+=a.weight):(n.barycenter=a.barycenter,n.weight=a.weight))}var n,a});let d=Ts(c,r);!function(e,t){e.forEach(e=>{e.vs=e.vs.flatMap(e=>t[e]?t[e].vs:e)})}(d,h);let u=Rs(d,s);if(o&&(u.vs=[o,u.vs,l].flat(!0),t.predecessors(o).length)){let e=t.node(t.predecessors(o)[0]),i=t.node(t.predecessors(l)[0]);Object.hasOwn(u,"barycenter")||(u.barycenter=0,u.weight=0),u.barycenter=(u.barycenter*u.weight+e.order+i.order)/(u.weight+2),u.weight+=2}return u};let Is=hr.Graph,Ns=br;var Ls=function(e,t,i,r){r||(r=e.nodes());let s=function(e){var t;for(;e.hasNode(t=Ns.uniqueId("_root")););return t}(e),n=new Is({compound:!0}).setGraph({root:s}).setDefaultNodeLabel(t=>e.node(t));return r.forEach(r=>{let a=e.node(r),o=e.parent(r);(a.rank===t||a.minRank<=t&&t<=a.maxRank)&&(n.setNode(r),n.setParent(r,o||s),e[i](r).forEach(t=>{let i=t.v===r?t.w:t.v,s=n.edge(i,r),a=void 0!==s?s.weight:0;n.setEdge(i,r,{weight:e.edge(t).weight+a})}),Object.hasOwn(a,"minRank")&&n.setNode(r,{borderLeft:a.borderLeft[t],borderRight:a.borderRight[t]}))}),n};let Vs=vs,Ps=function(e,t){let i=0;for(let r=1;r<t.length;++r)i+=Es(e,t[r-1],t[r]);return i},Ms=Os,Ds=Ls,Bs=function(e,t,i){let r,s={};i.forEach(i=>{let n,a,o=e.parent(i);for(;o;){if(n=e.parent(o),n?(a=s[n],s[n]=o):(a=r,r=o),a&&a!==o)return void t.setEdge(a,o);o=n}})},Gs=hr.Graph,Fs=br;var zs=function e(t,i){if(i&&"function"==typeof i.customOrder)return void i.customOrder(t,e);let r=Fs.maxRank(t),s=js(t,Fs.range(1,r+1),"inEdges"),n=js(t,Fs.range(r-1,-1,-1),"outEdges"),a=Vs(t);if(Us(t,a),i&&i.disableOptimalOrderHeuristic)return;let o,l=Number.POSITIVE_INFINITY;for(let e=0,i=0;i<4;++e,++i){Ws(e%2?s:n,e%4>=2),a=Fs.buildLayerMatrix(t);let r=Ps(t,a);r<l&&(i=0,o=Object.assign({},a),l=r)}Us(t,o)};function js(e,t,i){const r=new Map,s=(e,t)=>{r.has(e)||r.set(e,[]),r.get(e).push(t)};for(const t of e.nodes()){const i=e.node(t);if("number"==typeof i.rank&&s(i.rank,t),"number"==typeof i.minRank&&"number"==typeof i.maxRank)for(let e=i.minRank;e<=i.maxRank;e++)e!==i.rank&&s(e,t)}return t.map(function(t){return Ds(e,t,i,r.get(t)||[])})}function Ws(e,t){let i=new Gs;e.forEach(function(e){let r=e.graph().root,s=Ms(e,r,i,t);s.vs.forEach((t,i)=>e.node(t).order=i),Bs(e,i,s.vs)})}function Us(e,t){Object.values(t).forEach(t=>t.forEach((t,i)=>e.node(t).order=i))}let Hs=hr.Graph,Ys=br;var Xs=function(e){let t,i=Ys.buildLayerMatrix(e),r=Object.assign(function(e,t){let i={};function r(t,r){let s=0,n=0,a=t.length,o=r[r.length-1];return r.forEach((t,l)=>{let h=function(e,t){if(e.node(t).dummy)return e.predecessors(t).find(t=>e.node(t).dummy)}(e,t),c=h?e.node(h).order:a;(h||t===o)&&(r.slice(n,l+1).forEach(t=>{e.predecessors(t).forEach(r=>{let n=e.node(r),a=n.order;!(a<s||c<a)||n.dummy&&e.node(t).dummy||qs(i,r,t)})}),n=l+1,s=c)}),r}return t.length&&t.reduce(r),i}(e,i),function(e,t){let i={};function r(t,r,s,n,a){let o;Ys.range(r,s).forEach(r=>{o=t[r],e.node(o).dummy&&e.predecessors(o).forEach(t=>{let r=e.node(t);r.dummy&&(r.order<n||r.order>a)&&qs(i,t,o)})})}function s(t,i){let s,n=-1,a=0;return i.forEach((o,l)=>{if("border"===e.node(o).dummy){let t=e.predecessors(o);t.length&&(s=e.node(t[0]).order,r(i,a,l,n,s),a=l,n=s)}r(i,a,i.length,s,t.length)}),i}return t.length&&t.reduce(s),i}(e,i)),s={};["u","d"].forEach(n=>{t="u"===n?i:Object.values(i).reverse(),["l","r"].forEach(i=>{"r"===i&&(t=t.map(e=>Object.values(e).reverse()));let a=("u"===n?e.predecessors:e.successors).bind(e),o=function(e,t,i,r){let s={},n={},a={};return t.forEach(e=>{e.forEach((e,t)=>{s[e]=e,n[e]=e,a[e]=t})}),t.forEach(e=>{let t=-1;e.forEach(e=>{let o=r(e);if(o.length){o=o.sort((e,t)=>a[e]-a[t]);let r=(o.length-1)/2;for(let l=Math.floor(r),h=Math.ceil(r);l<=h;++l){let r=o[l];n[e]===e&&t<a[r]&&!Ks(i,e,r)&&(n[r]=e,n[e]=s[e]=s[r],t=a[r])}}})}),{root:s,align:n}}(0,t,r,a),l=function(e,t,i,r,s){let n={},a=function(e,t,i,r){let s=new Hs,n=e.graph(),a=function(e,t,i){return(r,s,n)=>{let a,o=r.node(s),l=r.node(n),h=0;if(h+=o.width/2,Object.hasOwn(o,"labelpos"))switch(o.labelpos.toLowerCase()){case"l":a=-o.width/2;break;case"r":a=o.width/2}if(a&&(h+=i?a:-a),a=0,h+=(o.dummy?t:e)/2,h+=(l.dummy?t:e)/2,h+=l.width/2,Object.hasOwn(l,"labelpos"))switch(l.labelpos.toLowerCase()){case"l":a=l.width/2;break;case"r":a=-l.width/2}return a&&(h+=i?a:-a),a=0,h}}(n.nodesep,n.edgesep,r);return t.forEach(t=>{let r;t.forEach(t=>{let n=i[t];if(s.setNode(n),r){var o=i[r],l=s.edge(o,n);s.setEdge(o,n,Math.max(a(e,t,r),l||0))}r=t})}),s}(e,t,i,s),o=s?"borderLeft":"borderRight";function l(e,t){let i=a.nodes(),r=i.pop(),s={};for(;r;)s[r]?e(r):(s[r]=!0,i.push(r),i=i.concat(t(r))),r=i.pop()}function h(e){n[e]=a.inEdges(e).reduce((e,t)=>Math.max(e,n[t.v]+a.edge(t)),0)}function c(t){let i=a.outEdges(t).reduce((e,t)=>Math.min(e,n[t.w]-a.edge(t)),Number.POSITIVE_INFINITY),r=e.node(t);i!==Number.POSITIVE_INFINITY&&r.borderType!==o&&(n[t]=Math.max(n[t],i))}return l(h,a.predecessors.bind(a)),l(c,a.successors.bind(a)),Object.keys(r).forEach(e=>n[e]=n[i[e]]),n}(e,t,o.root,o.align,"r"===i);"r"===i&&(l=Ys.mapValues(l,e=>-e)),s[n+i]=l})});let n=function(e,t){return Object.values(t).reduce((t,i)=>{let r=Number.NEGATIVE_INFINITY,s=Number.POSITIVE_INFINITY;Object.entries(i).forEach(([t,i])=>{let n=function(e,t){return e.node(t).width}(e,t)/2;r=Math.max(i+n,r),s=Math.min(i-n,s)});const n=r-s;return n<t[0]&&(t=[n,i]),t},[Number.POSITIVE_INFINITY,null])[1]}(e,s);return function(e,t){let i=Object.values(t),r=Ys.applyWithChunking(Math.min,i),s=Ys.applyWithChunking(Math.max,i);["u","d"].forEach(i=>{["l","r"].forEach(n=>{let a=i+n,o=e[a];if(o===t)return;let l=Object.values(o),h=r-Ys.applyWithChunking(Math.min,l);"l"!==n&&(h=s-Ys.applyWithChunking(Math.max,l)),h&&(e[a]=Ys.mapValues(o,e=>e+h))})})}(s,n),function(e,t){return Ys.mapValues(e.ul,(i,r)=>{if(t)return e[t.toLowerCase()][r];{let t=Object.values(e).map(e=>e[r]).sort((e,t)=>e-t);return(t[1]+t[2])/2}})}(s,e.graph().align)};function qs(e,t,i){if(t>i){let e=t;t=i,i=e}let r=e[t];r||(e[t]=r={}),r[i]=!0}function Ks(e,t,i){if(t>i){let e=t;t=i,i=e}return!!e[t]&&Object.hasOwn(e[t],i)}let Zs=br,$s=Xs;let Js=Or,Qs=Nr,en=as,tn=br.normalizeRanks,rn=hs,sn=br.removeEmptyRanks,nn=ds,an=_s,on={adjust:function(e){let t=e.graph().rankdir.toLowerCase();"lr"!==t&&"rl"!==t||gs(e)},undo:function(e){let t=e.graph().rankdir.toLowerCase();"bt"!==t&&"rl"!==t||function(e){e.nodes().forEach(t=>ms(e.node(t))),e.edges().forEach(t=>{let i=e.edge(t);i.points.forEach(ms),Object.hasOwn(i,"y")&&ms(i)})}(e);"lr"!==t&&"rl"!==t||(!function(e){e.nodes().forEach(t=>bs(e.node(t))),e.edges().forEach(t=>{let i=e.edge(t);i.points.forEach(bs),Object.hasOwn(i,"x")&&bs(i)})}(e),gs(e))}},ln=zs,hn=function(e){(function(e){let t=Zs.buildLayerMatrix(e),i=e.graph().ranksep,r=0;t.forEach(t=>{const s=t.reduce((t,i)=>{const r=e.node(i).height;return t>r?t:r},0);t.forEach(t=>e.node(t).y=r+s/2),r+=s+i})})(e=Zs.asNonCompoundGraph(e)),Object.entries($s(e)).forEach(([t,i])=>e.node(t).x=i)},cn=br,dn=hr.Graph;var un=function(e,t){let i=t&&t.debugTiming?cn.time:cn.notime;i("layout",()=>{let r=i(" buildLayoutGraph",()=>function(e){let t=new dn({multigraph:!0,compound:!0}),i=wn(e.graph());return t.setGraph(Object.assign({},_n,vn(i,pn),cn.pick(i,fn))),e.nodes().forEach(i=>{const r=vn(wn(e.node(i)),gn);Object.keys(yn).forEach(e=>{void 0===r[e]&&(r[e]=yn[e])}),t.setNode(i,r),t.setParent(i,e.parent(i))}),e.edges().forEach(i=>{let r=wn(e.edge(i));t.setEdge(i,Object.assign({},bn,vn(r,mn),cn.pick(r,xn)))}),t}(e));i(" runLayout",()=>function(e,t,i){t(" makeSpaceForEdgeLabels",()=>function(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(i=>{let r=e.edge(i);r.minlen*=2,"c"!==r.labelpos.toLowerCase()&&("TB"===t.rankdir||"BT"===t.rankdir?r.width+=r.labeloffset:r.height+=r.labeloffset)})}(e)),t(" removeSelfEdges",()=>function(e){e.edges().forEach(t=>{if(t.v===t.w){var i=e.node(t.v);i.selfEdges||(i.selfEdges=[]),i.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}(e)),t(" acyclic",()=>Js.run(e)),t(" nestingGraph.run",()=>nn.run(e)),t(" rank",()=>en(cn.asNonCompoundGraph(e))),t(" injectEdgeLabelProxies",()=>function(e){e.edges().forEach(t=>{let i=e.edge(t);if(i.width&&i.height){let i=e.node(t.v),r={rank:(e.node(t.w).rank-i.rank)/2+i.rank,e:t};cn.addDummyNode(e,"edge-proxy",r,"_ep")}})}(e)),t(" removeEmptyRanks",()=>sn(e)),t(" nestingGraph.cleanup",()=>nn.cleanup(e)),t(" normalizeRanks",()=>tn(e)),t(" assignRankMinMax",()=>function(e){let t=0;e.nodes().forEach(i=>{let r=e.node(i);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=Math.max(t,r.maxRank))}),e.graph().maxRank=t}(e)),t(" removeEdgeLabelProxies",()=>function(e){e.nodes().forEach(t=>{let i=e.node(t);"edge-proxy"===i.dummy&&(e.edge(i.e).labelRank=i.rank,e.removeNode(t))})}(e)),t(" normalize.run",()=>Qs.run(e)),t(" parentDummyChains",()=>rn(e)),t(" addBorderSegments",()=>an(e)),t(" order",()=>ln(e,i)),t(" insertSelfEdges",()=>function(e){var t=cn.buildLayerMatrix(e);t.forEach(t=>{var i=0;t.forEach((t,r)=>{var s=e.node(t);s.order=r+i,(s.selfEdges||[]).forEach(t=>{cn.addDummyNode(e,"selfedge",{width:t.label.width,height:t.label.height,rank:s.rank,order:r+ ++i,e:t.e,label:t.label},"_se")}),delete s.selfEdges})})}(e)),t(" adjustCoordinateSystem",()=>on.adjust(e)),t(" position",()=>hn(e)),t(" positionSelfEdges",()=>function(e){e.nodes().forEach(t=>{var i=e.node(t);if("selfedge"===i.dummy){var r=e.node(i.e.v),s=r.x+r.width/2,n=r.y,a=i.x-s,o=r.height/2;e.setEdge(i.e,i.label),e.removeNode(t),i.label.points=[{x:s+2*a/3,y:n-o},{x:s+5*a/6,y:n-o},{x:s+a,y:n},{x:s+5*a/6,y:n+o},{x:s+2*a/3,y:n+o}],i.label.x=i.x,i.label.y=i.y}})}(e)),t(" removeBorderNodes",()=>function(e){e.nodes().forEach(t=>{if(e.children(t).length){let i=e.node(t),r=e.node(i.borderTop),s=e.node(i.borderBottom),n=e.node(i.borderLeft[i.borderLeft.length-1]),a=e.node(i.borderRight[i.borderRight.length-1]);i.width=Math.abs(a.x-n.x),i.height=Math.abs(s.y-r.y),i.x=n.x+i.width/2,i.y=r.y+i.height/2}}),e.nodes().forEach(t=>{"border"===e.node(t).dummy&&e.removeNode(t)})}(e)),t(" normalize.undo",()=>Qs.undo(e)),t(" fixupEdgeLabelCoords",()=>function(e){e.edges().forEach(t=>{let i=e.edge(t);if(Object.hasOwn(i,"x"))switch("l"!==i.labelpos&&"r"!==i.labelpos||(i.width-=i.labeloffset),i.labelpos){case"l":i.x-=i.width/2+i.labeloffset;break;case"r":i.x+=i.width/2+i.labeloffset}})}(e)),t(" undoCoordinateSystem",()=>on.undo(e)),t(" translateGraph",()=>function(e){let t=Number.POSITIVE_INFINITY,i=0,r=Number.POSITIVE_INFINITY,s=0,n=e.graph(),a=n.marginx||0,o=n.marginy||0;function l(e){let n=e.x,a=e.y,o=e.width,l=e.height;t=Math.min(t,n-o/2),i=Math.max(i,n+o/2),r=Math.min(r,a-l/2),s=Math.max(s,a+l/2)}e.nodes().forEach(t=>l(e.node(t))),e.edges().forEach(t=>{let i=e.edge(t);Object.hasOwn(i,"x")&&l(i)}),t-=a,r-=o,e.nodes().forEach(i=>{let s=e.node(i);s.x-=t,s.y-=r}),e.edges().forEach(i=>{let s=e.edge(i);s.points.forEach(e=>{e.x-=t,e.y-=r}),Object.hasOwn(s,"x")&&(s.x-=t),Object.hasOwn(s,"y")&&(s.y-=r)}),n.width=i-t+a,n.height=s-r+o}(e)),t(" assignNodeIntersects",()=>function(e){e.edges().forEach(t=>{let i,r,s=e.edge(t),n=e.node(t.v),a=e.node(t.w);s.points?(i=s.points[0],r=s.points[s.points.length-1]):(s.points=[],i=a,r=n),s.points.unshift(cn.intersectRect(n,i)),s.points.push(cn.intersectRect(a,r))})}(e)),t(" reversePoints",()=>function(e){e.edges().forEach(t=>{let i=e.edge(t);i.reversed&&i.points.reverse()})}(e)),t(" acyclic.undo",()=>Js.undo(e))}(r,i,t)),i(" updateInputGraph",()=>function(e,t){e.nodes().forEach(i=>{let r=e.node(i),s=t.node(i);r&&(r.x=s.x,r.y=s.y,r.rank=s.rank,t.children(i).length&&(r.width=s.width,r.height=s.height))}),e.edges().forEach(i=>{let r=e.edge(i),s=t.edge(i);r.points=s.points,Object.hasOwn(s,"x")&&(r.x=s.x,r.y=s.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}(e,r))})};let pn=["nodesep","edgesep","ranksep","marginx","marginy"],_n={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},fn=["acyclicer","ranker","rankdir","align"],gn=["width","height","rank"],yn={width:0,height:0},mn=["minlen","weight","width","height","labeloffset"],bn={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},xn=["labelpos"];function vn(e,t){return cn.mapValues(cn.pick(e,t),Number)}function wn(e){var t={};return e&&Object.entries(e).forEach(([e,i])=>{"string"==typeof e&&(e=e.toLowerCase()),t[e]=i}),t}let En=br,An=hr.Graph;var Cn={graphlib:hr,layout:un,debug:{debugOrdering:function(e){let t=En.buildLayerMatrix(e),i=new An({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(t=>{i.setNode(t,{label:t}),i.setParent(t,"layer"+e.node(t).rank)}),e.edges().forEach(e=>i.setEdge(e.v,e.w,{},e.name)),t.forEach((e,t)=>{let r="layer"+t;i.setNode(r,{rank:"same"}),e.reduce((e,t)=>(i.setEdge(e,t,{style:"invis"}),t))}),i}},util:{time:br.time,notime:br.notime},version:"1.1.8"};class kn extends F{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=C(e.parent);for(let e of t){let t=e.layout;if(!t)continue;let r=ge(e.children[0]);if(!r)continue;var i=new Cn.graphlib.Graph;i.setGraph({edgesep:t._edgeSep}),i.setDefaultEdgeLabel(function(){return{}}),i.graph().rankdir=this._getDagreDirection(t.direction);let s=new Map;for(let t of e.children){let e=t.dataScope.getAttrVal(me);s.set(e,e+""),i.setNode(e,{label:t.text?t.text:"",width:t.bounds.width,height:t.bounds.height})}for(let e of r.linkList)i.setEdge(e.source,e.target);Cn.layout(i);const n={};let a=Math.min(...i.nodes().map(e=>i.node(e).y)),o=Math.min(...i.nodes().map(e=>i.node(e).x)),l=t.left-o,h=t.top-a;for(const e of i.nodes())n[e]={x:i.node(e).x+l,y:i.node(e).y+h};for(let t of e.children){let e=t.dataScope.getAttrVal(me);Fe(t,n[s.get(e)].x-t.x,n[s.get(e)].y-t.y)}}let r=V(e,!0);for(let e of r)x(e)}_getDagreDirection(e){switch(e){case K.Left2Right:return"LR";case K.Right2Left:return"RL";case K.Top2Bottom:return"TB";case K.Bottom2Top:return"BT"}}}class Sn extends F{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=C(e.parent);for(let e of t){let t=e.layout;if(!t)continue;let i=_e(e.children[0]);if(!i)continue;let s=r.hierarchy(i._data),n=Math.max(...e.children.map(e=>e.bounds.width)),a=Math.max(...e.children.map(e=>e.bounds.height)),o=t.orientation==H?[t.height,t.width]:[t.width,t.height],l=r.tree().nodeSize([n,a]).size(o)(s);this._apply(l,t,e)}x(e)}_apply(e,t,i){let r,s,n=i.children.filter(t=>t.dataScope.getAttrVal(me)==e.data[me])[0];switch(t.orientation){case H:r=e.y+t.left,s=e.x+t.top;break;case Y:r=e.x+t.left,s=t.top+e.y}if(Fe(n,r-n.x,s-n.y),e.children&&e.children.length>0)for(let r of e.children)this._apply(r,t,i)}}class Tn extends F{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=this._inputVars.filter(e=>e.type===Te.PROPERTY&&e.property===et.CHILDREN_ORDER)[0].element,i=t.layout,s=i.width?i.width:t.bounds.width,n=i.height?i.height:t.bounds.height,a=void 0===i.top?t.bounds.top:i.top,o=void 0===i.left?t.bounds.left:i.left,l=r.hierarchy(t).sum(e=>e.type===Vt.Rect?e.width*e.height:0);r.treemap().size([s,n])(l),this._apply(l,o,a);let h=V(e,!0);for(let e of h)x(e)}_apply(e,t,i){if(e.data.type==Vt.Collection&&e.children)for(let r of e.children)this._apply(r,t,i);else e.data.type==Vt.Rect&&(e.data.resize(e.x1-e.x0,e.y1-e.y0),Fe(e.data,e.x0+t-e.data.left,e.y0+i-e.data.top))}}class Rn extends F{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=C(e.parent);for(let e of t){if(!e.layout)continue;if(0===e.children.length)continue;let t=_e(e.children[0]);if(!t)continue;let i={};for(let t of e.children)i[t.dataScope.getAttrVal(me)]=t;e.children[0].type===Vt.Rect?this._layoutRects(t.getRoot(),t,i):this._layoutArcs(t.getRoot(),t,i)}x(e)}_layoutArcs(e,t,i){let r=t.getChildren(e);if(0===r.length)return;let s=i[e[me]],n=!s||s.type!=Vt.Arc&&s.type!=Vt.Pie?60:s.startAngle;for(let e=0;e<r.length;e++){let s=r[e],a=i[s[me]];if(a.type===Vt.Arc){let e=le(n+a.angle);a.setAngles(n,e),n=e}this._layoutArcs(s,t,i)}}_layoutRects(e,t,i){let r=t.getChildren(e);if(0===r.length)return;let s,n,a=i[e[me]];this._direction,s=a.left,n=a.bottom;for(let e=0;e<r.length;e++){let a=r[e],o=i[a[me]];Fe(o,s-o.left,n-o.top),s+=o.width,this._layoutRects(a,t,i)}}}class On extends F{constructor(e){super(e)}run(){super.run();let e=this.outputVar,t=this.inputVars[0],i=e.conditionalEncoding,r=t.context,s=e.result,n=i.responderComponent;s.clear();let a=Array.isArray(n)?n:[n];if(i.evalFunction)for(let e of a){C(e).forEach(e=>s.setValue(e.id,i.evalFunction(r,e)))}}}class In extends F{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=C(e.parent);for(let e of t){let t=e.layout;if(!t)continue;let i=360/e.children.length;for(let[r,s]of e.children.entries())Fe(s,t.x+t.radius-s.bounds.x,t.y-s.bounds.y),s._rotate=[r*i,t.x,t.y]}let i=V(e,!0);for(let e of i)x(e)}}class Nn extends F{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=C(e.parent);for(let i of t){let t=i.layout;if(!t)continue;let s=t._tree?t._tree._data:_e(i.children[0])._data,n=r.hierarchy(s);if(t.isRadial()){n=r.cluster().size([ae(t.angleExtent),t.radius])(n),t._d3Root=n;const e=new Map(n.descendants().map(e=>[e.data[me],[e.x,e.y]]));for(let r of i.children){let i=r.dataScope.getAttrVal(me);Fe(r,t.x-r.bounds.x,t.y-e.get(i)[1]-r.bounds.y),r._rotate=[oe(e.get(i)[0]),t.x,t.y]}}else if(t.orientation===Y){!t.width||t.width;let s=t.height?t.height:600;n=r.cluster().nodeSize([e.bounds.width+1,s/(n.height+1)])(n),t._d3Root=n;const a=new Map(n.descendants().map(e=>[e.data[me],[e.x,e.y]]));let o=1/0,l=-o;n.each(e=>{e.x>l&&(l=e.x),e.x<o&&(o=e.x)}),t._x0=o;for(let e of i.children){let i=e.dataScope.getAttrVal(me);Fe(e,a.get(i)[0]-o+t.left-e.bounds.x,a.get(i)[1]+t.top-e.bounds.y)}}else if(t.orientation===H){!t.width||t.width;let s=t.height?t.height:600;n=r.cluster().nodeSize([e.bounds.height,s/(n.height+1)])(n),t._d3Root=n;const a=new Map(n.descendants().map(e=>[e.data[me],[e.x,e.y]]));let o=1/0,l=-o;n.each(e=>{e.x>l&&(l=e.x),e.x<o&&(o=e.x)}),t._x0=o;for(let e of i.children){let i=e.dataScope.getAttrVal(me);Fe(e,a.get(i)[1]+t.left-e.bounds.x,a.get(i)[0]-o+t.top-e.bounds.y)}}}let i=V(e,!0);for(let e of i)x(e)}}class Ln extends Se{constructor(e,t){super(e),this._cond=t}get context(){return this._cond}}class Vn extends F{constructor(e,t,i){super(e),this._fn=t,this._compnt=i}run(){super.run();let e=this.inputVars.find(e=>e instanceof Ln);this.outputVar,this._fn(void 0,e.context,this._compnt)}}class Pn extends F{constructor(e){super(e)}run(){super.run();let e=this.outputVar,t=this.inputVars.find(e=>e instanceof Ht),i=e.encodings[0].dataTable.getAttributeType(t.attribute),r={};for(let t of e.encodings){let e=this._computeAttrValues(t,i);Object.assign(r,e)}e.attrValues=r}_computeAttrValues(e,t){let i=C(e.element),r={};if(e.element.type===Vt.Area&&["width","height","fillGradient"].indexOf(e.channel)>=0)for(let t of i)for(let i of t.vertices)r[i.id]=de(i).aggregateNumericalAttribute(e.attribute,e.aggregator);else switch(t){case xe.Boolean:break;case xe.Date:for(let t of i)r[t.id]=de(t).getAttrVal(e.attribute);break;case xe.String:try{if("count"==e.aggregator)for(let t of i)r[t.id]=de(t).getAttributeValues(e.attribute).length;else for(let t of i)r[t.id]=de(t).getAttrVal(e.attribute)}catch(t){throw new Error("Cannot bind "+this.channel+" to "+e.attribute+" : "+t)}break;default:if(e.attribute.startsWith("parent.")||e.attribute.startsWith("child.")){let t=e.dataTable.tree.nodeTable,s=e.attribute.split(".")[0],n=e.attribute.split(".")[1];for(let e of i){let i=de(e).getAttrVal(s);r[e.id]=new ce(t).cross(me,i).getAttrVal(n)}}else for(let t of i)r[t.id]=de(t).aggregateNumericalAttribute(e.attribute,e.aggregator)}if(e.transform)for(let t of i)r[t.id]=e.transform(r[t.id],t);return e.attrValues=r,r}}class Mn extends Se{constructor(e,t,i){super(e),this._dataset=i,this._predicate=t}get dataset(){return this._dataset}get predicate(){return this._predicate}}class Dn{constructor(){this._variables={},this._operators={},this._edges=[]}toJSON(){const e=this._edges.map(e=>({from:e.fromNode.id,to:e.toNode.id,isDirected:e.isDirected})),t={};for(const e in this._variables)t[e]=Object.values(this._variables[e]).map(e=>{let t={id:e.id,type:e.type,incoming:e.incomingEdges.map(e=>e.id),outgoing:e.outgoingEdges.map(e=>e.id),undirected:e.undirectedEdges.map(e=>e.id)};return"ChannelVar"===e.type?(t.channel=e.channel,t.element=e.element):"BoundsVar"===e.type||"DataScopeVar"===e.type?t.element=e.element:"dataValue"===e.type?(t.scale=e.scale,t.attrValues=e.attrValues):"FieldVar"===e.type?(t.field=e.field,t.dataset=e.dataset):"PropertyVar"===e.type?(t.property=e.property,t.element=e.element):t.scale=e.scale,t});const i={};for(const e in this._operators)i[e]=Object.values(this._operators[e]).map(e=>{let t={id:e.id,type:e.type,inputVars:e.inputVars.map(e=>e.id),outputVar:e.outputVar?e.outputVar.id:null};return e.type===z.DOMAIN_BUILDER?t.aggregator=e.aggregator:e.type===z.SCALE_BUILDER&&(t.channel=e.channel),t});return{edges:e,variables:t,operators:i}}getVariable(e,...t){if(Object.values(Te).indexOf(e)<0)throw console.log(e),new Error("Variable Type Not Known");let i=this.findVariable(e,t);if(i)return i;switch(e){case Te.CHANNEL:i=new Re(e,t[0],t[1]),"vertex"!=t[1].type&&"segment"!=t[1].type||this._connectPathElement2Size(t[1],i);break;case Te.PROPERTY:i=new $e(e,t[0],t[1]);break;case Te.ATTRIBUTE:i=new Ht(e,t[0],t[1]);break;case Te.ITEMS:i=new Mn(e,t[0],t[1]);break;case Te.ATTR_VALUE:i=new Zt(e,t[0]);break;case Te.DATASCOPE:i=new jt(e,t[0]);break;case Te.BOUNDS:i=new zt(e,t[0]);break;case Te.SCALE:i=new qe(e,t[0]);break;case Te.AFFIXATION:i=new yi(e,t[0]);break;case Te.ALIGNMENT:i=new Ai(e,t[0]);break;case Te.EVT_CTX:i=new Ln(e,t[0],t[1]);break;case Te.CONDITION_RESULT:i=new Ke(e,t[0],t[1])}return e in this._variables||(this._variables[e]={}),this._variables[e][i.id]=i,i}_connectPathElement2Size(e,t){let i=e.parent,r=t.channel,s=this.findVariable(Te.CHANNEL,["x"===r?"width":"height",i]);if(s){let e=s.incomingDataflow;e||(e=this.createOneWayDependency(z.CONDUIT)),this.connect(t,e),this.connect(e,s)}}findIncomingDataflowOperator(e,t){return t.incomingDataflow&&t.incomingDataflow.type===e?t.incomingDataflow:void 0}getIncomingDataflowOperator(e,t){let i=this.findIncomingDataflowOperator(e,t);return i||this.createOneWayDependency(e)}getOutgoingDataflowOperator(e,t){for(let i of t.outgoingEdges)if(i.toNode instanceof F&&i.toNode.type===e)return i.toNode;return this.createOneWayDependency(e)}createOneWayDependency(e,...t){if(Object.values(z).indexOf(e)<0)throw new Error("Dependency Type Not Known");let i;switch(e){case z.EVAL_BBOX:i=new Jt(e);break;case z.AFFIXER:i=new gi(e);break;case z.DATA_EXTRACTOR:i=new Pn(e,t[0]);break;case z.SCALE_BUILDER:i=new $t(e,t[0]);break;case z.ENCODER:i=new Ze(e,t[0]);break;case z.AXIS_PATH_PLACER:i=new oi(e);break;case z.AXIS_TICKS_PLACER:i=new li(e);break;case z.AXIS_LABELS_PLACER:i=new hi(e);break;case z.AXIS_TITLE_PLACER:i=new wi(e);break;case z.LINK_PLACER:i=new ki(e);break;case z.GRID_LAYOUT:i=new ci(e);break;case z.STACK_LAYOUT:i=new ui(e);break;case z.PACK_LAYOUT:i=new vi(e);break;case z.FORCE_LAYOUT:i=new Ci(e);break;case z.DIRECTED_LAYOUT:i=new kn(e);break;case z.TIDY_TREE_LAYOUT:i=new Sn(e);break;case z.TREEMAP_LAYOUT:i=new Tn(e);break;case z.STRATA_LAYOUT:i=new Rn(e);break;case z.CIRCULAR_LAYOUT:i=new In(e);break;case z.CLUSTER_LAYOUT:i=new Nn(e);break;case z.GRIDLINES_PLACER:i=new di(e);break;case z.BIN_TRANSFORMER:i=new _i(e);break;case z.FILTER_TRANSFORMER:i=new fi(e);break;case z.KDE_TRANSFORMER:i=new mi(e);break;case z.TARGET_EVALUATOR:i=new On(e);break;case z.TARGET_UPDATER:i=new Vn(e,t[0],t[1]);break;case z.CONDUIT:default:i=new pi(e)}return e in this._operators||(this._operators[e]={}),this._operators[e][i.id]=i,i}createMultiWayDependency(e){if(Object.values(z).indexOf(e)<0)throw new Error("Dependency Type Not Known");let t;return z.ALIGNER,t=new Ei(e),e in this._operators||(this._operators[e]={}),this._operators[e][t.id]=t,t}connect(e,t,i=!0){if(e instanceof Se&&t instanceof F){if(!t.inputVars.includes(e)){const r=new Ut(e,t,i);this._edges.push(r),e.outgoingEdges.push(r),t.inputVars.push(e)}}else if(e instanceof F&&t instanceof Se){if(!e.outputVars.includes(t)){const r=new Ut(e,t,i);this._edges.push(r),e.outputVars.push(t),t.incomingEdges.push(r)}}else if(e instanceof Se&&t instanceof Wt){if(!t.vars.includes(e)){const i=new Ut(e,t,!1);this._edges.push(i),t.vars.push(e),t.edges.push(e),e.undirectedEdges.push(i)}}else{if(!(e instanceof Wt&&t instanceof Se))throw new Error("An edge must connect a variable and an operator.");if(!e.vars.includes(t)){const i=new Ut(t,e,!1);this._edges.push(i),e.vars.push(t),e.edges.push(t),t.undirectedEdges.push(i)}}}disconnectChannelVarFromBBoxOperator(e){let t=this.getOutgoingDataflowOperator(z.EVAL_BBOX,e),i=e.outgoingEdges.find(i=>i.fromNode===e&&i.toNode===t);i&&this.disconnect(e,t,i)}disconnect(e,t,i){if(e instanceof Se&&t instanceof F){let r=e.outgoingEdges.findIndex(e=>e===i);r>=0&&(this._edges.splice(this._edges.indexOf(i),1),e.outgoingEdges.splice(r,1));let s=t.inputVars.findIndex(t=>t==e);s>=0&&t.inputVars.splice(s,1)}else if(e instanceof F&&t instanceof Se){let r=t.incomingEdges.findIndex(e=>e===i);r>=0&&(this._edges.splice(this._edges.indexOf(i),1),t.incomingEdges.splice(r,1));let s=e.outputVars.findIndex(e=>e===t);s>=0&&e.outputVars.splice(s,1)}}deleteVariable(e){for(let t=e.incomingEdges.length-1;t>=0;t--){let i=e.incomingEdges[t],r=i.fromNode;this.disconnect(r,e,i),r.isIsolated()&&delete this._operators[r.type][r.id]}for(let t=e.outgoingEdges.length-1;t>=0;t--){let i=e.outgoingEdges[t],r=i.toNode;this.disconnect(e,r,i),r.isIsolated()&&delete this._operators[r.type][r.id]}delete this._variables[e.type][e.id]}deleteOperator(e){for(let t=e.outputVars.length-1;t>=0;t--){let i=e.outputVars[t],r=i.incomingEdges.find(t=>t.fromNode===e&&t.toNode===i);this.disconnect(e,i,r),i.isIsolated()&&delete this._variables[i.type][i.id]}for(let t=e.inputVars.length-1;t>=0;t--){let i=e.inputVars[t],r=i.outgoingEdges.find(t=>t.fromNode===i&&t.toNode===e);this.disconnect(i,e,r),i.isIsolated()&&delete this._variables[i.type][i.id]}delete this._operators[e.type][e.id]}addInteraction(e){}_dfs(e,t,i){if(e&&0!==e.outgoingEdges.length)for(let r of e.outgoingEdges)r.isDirected&&(t.push(r.toNode),this._dfs(r.toNode.outputVars[0],t.slice(),i));else i.push(t)}processChange(e,t,...i){let r=this.findVariable(e,i);if(r){for(let e of r.outgoingEdges)if(e.isDirected){let i=e.toNode;i.run();let r=i.outputVars;if(r.length>0){let e=r[0];switch(e.type){case Te.ITEMS:this.processChange(e.type,t,e.predicate,e.dataset);break;case Te.ATTRIBUTE:this.processChange(e.type,t,e.attribute,e.dataset);break;case Te.BOUNDS:this.processChange(e.type,t,e.element);break;case Te.CHANNEL:this.processChange(e.type,t,e.channel,e.element);break;case Te.PROPERTY:this.processChange(e.type,t,e.property,e.element);break;case Te.SCALE:case Te.ATTR_VALUE:this.processChange(e.type,t,e.encodings[0]);break;case Te.CONDITION_RESULT:this.processChange(e.type,t,e.result)}}}for(let e of r.undirectedEdges)t.push(e.operator)}else console.warn("Unable to find variables matching the described change: ",e,i)}findVariable(e,t){if(!(e in this._variables))return null;let i=Object.values(this._variables[e]);switch(e){case Te.CHANNEL:return i.find(e=>e.channel==t[0]&&Pe(e.element)==Pe(t[1]));case Te.PROPERTY:return i.find(e=>e.property==t[0]&&e.element==t[1]);case Te.AFFIXATION:return i.find(e=>e.affixation==t[0]);case Te.ATTRIBUTE:return i.find(e=>e.attribute==t[0]&&e.dataset==t[1]);case Te.ITEMS:return i.find(e=>e.dataset==t[1]);case Te.ATTR_VALUE:case Te.SCALE:return i.find(e=>e.encodings.includes(t[0]));case Te.EVT_CTX:return i.find(e=>e.context===t[0]);case Te.CONDITION_RESULT:return i.find(e=>e.result==t[0]);case Te.DATASCOPE:default:return t[0].classId?i.find(e=>Pe(e.element)==Pe(t[0])):i.find(e=>e.element.id==t[0].id)}}findVariablesByElement(e){let t={};for(let i in this._variables){let r=Object.values(this._variables[i]).filter(t=>t.element&&Pe(t.element)==Pe(e));r.length>0&&(t[i]=r)}return t}}function Bn(e){return!(!E(e)&&e.type!=Vt.Glyph||e.dataScope)||e.type===Vt.Collection&&e.firstChild.dataScope.numTuples>1}function Gn(e,t,i,r){let s=r.getAttributeType(i);if(s!=xe.String&&s!=xe.Date&&s!=xe.Integer)throw new Error("Repeat only works on a string or date attribute: "+i+" is "+s);if(!function(e){if(Array.isArray(e)){if(1===e.length)return Bn(e[0]);for(let t of e)if(!E(t)||t.dataScope)return!1;return!0}return Bn(e)}(t))throw new Error("The "+t.type+" is not repeatable");return function(e,t,i,r){let s=r.getAttributeSummary(i).unique.map(e=>t.dataScope?t.dataScope.cross(i,e):new ce(r).cross(i,e));s=s.filter(e=>!e.isEmpty());let n=Ot(e);n.dataScope=t.dataScope?t.dataScope.clone():new ce(r),n.addChild(t),t._refBounds||(t._refBounds=t.bounds.clone());for(let e=1;e<s.length;e++){let e=Nt(t);n.addChild(e)}return n.children.forEach((e,t)=>e.dataScope=s[t]),n}(e,t,i,r)}class Fn{constructor(e,t,i,r,s){this._id="encoding_"+Mt(),this._elem=e,this._channel=t,this._attribute=i,this._table=s.table,this._aggregator=r,this._includeZero=s.includeZero,this._flipScale=s.flipScale,this._mapping=s.mapping,this._preferredRangeExtent=s.rangeExtent,this._preferredRangeStart=s.rangeStart,this._preferredDomain=s.domain,this._scaleType=s.scaleType,this._colorScheme=s.scheme,this._forLegend=s.forLegend,this._transform=s.transform,s.shareScale&&(this._baseEnc=s.shareScale),this._scales=[],this._elemGroups=[],this._elem2scale={},this._refElements=[],["width","height","radius","angle","thickness","radialDistance","strokeWidth","area"].indexOf(this._channel)>=0&&(this._includeZero=!0),this.initialize()}get id(){return this._id}initialize(){this._scales=[];let e=C(this._elem);if(this._elemGroups=[],"x"===this._channel||"y"===this._channel){let t=this._elem,i=L(t);if(i.layout&&i.layout.type==B.GRID){let e="x"===this._channel?i.layout.getElementsByCol(!0,t):i.layout.getElementsByRow(!0,t);for(let t of e)this._createScaleForElems(t)}else if("vertex"===this._elem.type&&(Be(this._elem.parent)||De(this._elem.parent))){let e=C(this._elem.parent).map(e=>k(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 i=t.parent.id;return e[i]||(e[i]=[]),e[i].push(t),e},{}),i=Object.values(t);for(let e of i)this._createScaleForElems(e)}else this._createScaleForElems(e)}_createScaleForElems(e){this._elemGroups.push(e);var t=function(e){if(e.scaleType)return new Yt(e.scaleType);if("text"===e.channel)return new Yt("ordinal");switch(e.dataTable.getAttributeType(e.attribute)){case xe.Boolean:break;case xe.Date:return new Yt("time");case xe.String:if("count"==e.aggregator)return new Yt("linear");if(e.channel.indexOf("Color")>=0){let t={};return t.scheme=e.colorScheme?e.colorScheme:"schemeCategory10",new Yt("ordinalColor",t)}return"src"===e.channel?new Yt("ordinal"):new Yt("point");default:return["strokeColor","fillColor","fillGradient"].indexOf(e.channel)>=0?e.mapping?new Yt("linear"):new Yt("sequentialColor",{scheme:e.colorScheme}):new Yt("linear")}}(this);this._scales.push(t);for(let i of e)this._elem2scale[i.id]=t}getScale(e){return this._elem2scale[e.id]}getAttrValue(e,t,i){let s=this.getScale(t).invert(e,i),n=this._attribute;if(this.dataTable.getAttributeType(n)===xe.Date){let e=C(t).map(e=>e.dataScope.getAttrVal(n));return e.sort((e,t)=>e-t),e[r.bisectLeft(e,s)]}return s}getChannelValue(e,t){return this.getScale(t).map(e)}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 this._table}get aggregator(){return this._aggregator}hasMultipleScales(){return this._scales.length>0}get scales(){return this._scales}getRangeStart(e){let t=this.getScale(e);return Math.min(...t.range)}getRangeExtent(e){return this.getScale(e).rangeExtent}get domain(){if(1===this._scales.length)return this._scales[0].domain;throw new Error("AttributeEncoding: multiple scales exist, specify element to get domain.")}get rangeExtent(){if(1===this._scales.length)return this._scales[0].rangeExtent;throw new Error("AttributeEncoding: multiple scales exist, specify element to get rangeExtent.")}get scaleType(){return this._scaleType}set scaleType(e){this._scaleType=e}getDomain(e){return this.getScale(e).domain}set domain(e){this._preferredDomain=e;for(let t of this._scales)t._scale.domain(e);for(let e of this._refElements)e instanceof ni&&e.createTicksLabels({});this._elem.scene.onChange(Te.ATTR_VALUE,this)}set rangeExtent(e){for(let t of this._scales)t.rangeExtent=e;for(let e of this._refElements)e instanceof ni&&e.createTicksLabels({});this._elem.scene.onChange(Te.PROPERTY,et.RANGE_EXTENT,this)}get transform(){return this._transform}set transform(e){this._transform=e,this._elem.scene.onChange(Te.PROPERTY,et.TRANSFORM,this)}set includeZero(e){this._includeZero=e;for(let e of this._refElements)e instanceof ni&&e.createTicksLabels({});this._elem.scene.onChange(Te.PROPERTY,et.INCLUDE_ZERO,this)}get includeZero(){return this._includeZero}set flipScale(e){this._flipScale=e,this._elem.scene.onChange(Te.PROPERTY,et.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=[]}pan(e,t,i){let r=i||this._elem;r.scene.createMask(r);let s=this.getDomain(r),n=Math.min(...s),a=Math.max(...s),o="log"!==this._scales[0].type,l=this.getAttrValue(e,r,o)-this.getAttrValue(e+t,r,o);(o||n+l>0)&&(this.domain=[n+l,a+l])}zoom(e,t,i,r){let s=r||this._elem;s.scene.createMask(s);let n=this.getDomain(s),a=Math.min(...n),o=Math.max(...n),l="log"!==this._scales[0].type,h=this.getAttrValue(t,s,l),c=a-(h-a)*e*i,d=o+(o-h)*e*i;c!==d&&(!l&&c<=0||(this.domain=[c,d]))}}class zn{constructor(){this._vals={},this._vals.elements=[]}set(e,t){this._vals[e]=t}get(e){return this._vals[e]}clear(){this._vals={},this._vals.elements=[]}}class jn{constructor(e,t,i,r){this._respCompnt=t,this._responderEval=i,this._efxFn=r,this._evtCtx=e,this._evalResult=new Kt}get responderComponent(){return this._respCompnt}get eventContext(){return this._evtCtx}get evalResult(){return this._evalResult}get evalFunction(){return this._responderEval}get stylingFunction(){return this._efxFn}}class Wn extends ee{constructor(e,t,i,r,s){super(s),this._type=Vt.Gridlines,this._id=this._type+Mt(),this._attribute=t,this._channel=e,this._scale=i,this._elems=r,this._args=s,"strokeColor"in s||(this.styles.strokeColor="#ddd"),"opacity"in s||(this.styles.opacity=.5),this.updateValues(),this._lines=[]}updateValues(){"values"in this._args?this._values=this._args.values:this._scale?this._values=ri(this._scale,this._channel,this._elems):this._values=this._elems.map(e=>e.dataScope.getAttrVal(this._attribute))}get type(){return this._type}get id(){return this._id}getSVGPathData(){let e="";if("radialDistance"===this._channel)for(let t of this._lines)e+="M "+t.x+" "+t.y+" m -"+t.r+" 0 a "+t.r+" "+t.r+" 0 1 0 "+2*t.r+" 0 a "+t.r+" "+t.r+" 0 1 0 -"+2*t.r+" 0 ";else for(let t of this._lines)e+=["M",t.x1,t.y1].join(" ")+[" L",t.x2,t.y2].join(" ")+" ";return e}_updateBounds(){if("radialDistance"===this._channel){let e=this._lines.map(e=>new g(e.x-e.r,e.y-e.y,2*e.r,2*e.r));this._bounds=y(e)}else{let e=this._lines.map(e=>e.x1).concat(this._lines.map(e=>e.x2)),t=this._lines.map(e=>e.y1).concat(this._lines.map(e=>e.y2)),i=Math.min(...e),r=Math.max(...e),s=Math.min(...t),n=Math.max(...t);this._bounds=new g(i,s,r-i,n-s)}}get elements(){return this._elems}get values(){return this._values}get channel(){return this._channel}get attribute(){return this._attribute}get scale(){return this._scale}get lines(){return this._lines}set lines(e){this._lines=e}}class Un extends D{constructor(e){super(),this.type=B.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:v.LEFT,this._vertCellAlignment="vertCellAlignment"in e&&e.vertCellAlignment?e.vertCellAlignment:v.BOTTOM,this._gap="gap"in e?e.gap:0}clone(){let e=new Un({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 Hn(e,t,i,r,s){let n=s.getAttributeType(i);if(n!=xe.String&&n!=xe.Date&&n!=xe.Integer)throw new Error("Divide only works on a string or date attribute: "+i+" is "+n);if(!Yn(t))throw new Error("The "+t.type+" is not dividable");switch(t.type){case Vt.Line:case Vt.Path:return;case Vt.Circle:return function(e,t,i,r,s){let n,a,o,l=C(t),h=i||X;if(h!=X&&h!=q)throw new Error("Unknown orientation: "+h);h===X&&l.forEach(i=>{let l=i.dataScope?i.dataScope:new ce(s),h=s.getUniqueAttributeValues(r).map(e=>l.cross(r,e));h=h.filter(e=>!e.isEmpty());let c=Ot(e);null==a&&(a=c.id),c._classId=a,c.dataScope=i.dataScope?i.dataScope:new ce(s);let d=i.parent;d.removeChild(i),delete e._itemMap[i.id];let u=360/h.length,p=90;for(let e=0;e<h.length;e++){let r=Rt({type:"arc",innerRadius:0,outerRadius:i.radius,x:i.x,y:i.y,startAngle:le(p-u*(e+1)),endAngle:le(p-u*e),strokeColor:i.strokeColor,fillColor:i.fillColor,strokeWidth:i.strokeWidth,opacity:i.opacity});o||(o=r.id),r.classId=o,r.dataScope=h[e],r._updateBounds(),r._refBounds=r.bounds.clone(),c.addChild(r),c._layout=new Un({orientation:X,direction:Z.CLOCKWISE}),c._layout.group=c,d.removeChild(i),d.addChild(c),i===t&&(n=c)}});return{newMark:n.children[0],collection:n}}(e,t,r,i,s);case Vt.Rect:return function(e,t,i,r,s){let n,a=C(t),o=i||H;if(o!=H&&o!=Y)throw new Error("Unknown orientation: "+o);let l=s.getUniqueAttributeValues(r).map(e=>new ce(s).cross(r,e)),h={},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),h[e.id]=t}let d,u=Rt({type:"rect",left:t.bounds.left,top:t.bounds.top,width:t.bounds.width,height:t.bounds.height,strokeColor:t.strokeColor,fillColor:t.fillColor,strokeWidth:t.strokeWidth,opacity:t.opacity});u._classId=u.id;for(let i of a){let r=Ot(e);null==d&&(d=r.id),r._classId=d,r.dataScope=i.dataScope?i.dataScope:new ce(s);let a=i.parent;a.removeChild(i),delete e._itemMap[i.id];let l=h[i.id],c=i.bounds,p=c.left,_=c.top,f=o==H?c.width/l.length:c.width,g=o==H?c.height:c.height/l.length;for(let e=0;e<l.length;e++){let t=Nt(u);t.dataScope=l[e],t.resize(f,g),t._updateBounds(),t._refBounds=t.bounds.clone(),r.addChild(t)}a.addChild(r),r._layout=new Un({orientation:o,left:p,top:_}),r._layout.group=r,i==t&&(n=r)}return{newMark:n.children[0],collection:n}}(e,t,r,i,s);case Vt.Area:return function(e,t,i,r,s){let n,a=C(t),o=i||H;if(o!=H&&o!=Y)throw new Error("Unknown orientation: "+o);let l,h=s.getUniqueAttributeValues(r).map(e=>new ce(s).cross(r,e)),c={},d=0;for(let e of a){let t=h;e.dataScope&&(t=h.map(t=>t.merge(e.dataScope)),t=t.filter(e=>!e.isEmpty())),t.length>d&&(d=t.length),c[e.id]=t}let u=Object.assign({},t.styles);u.vertices=t.vertices.map(e=>[e.x,e.y]),u.type="area",u.orientation=t.orientation,u.baseline=t.baseline;let p=Rt(u);if(p._classId=p.id,t.vertices)for(let e=0;e<t.vertices.length;e++)t.vertices[e].dataScope&&(p.vertices[e]._dataScope=t.vertices[e].dataScope.clone());for(let i of a){let r=Ot(e);null==l&&(l=r.id),r._classId=l,r.dataScope=i.dataScope?i.dataScope:new ce(s);let a=i.parent;a.removeChild(i),delete e._itemMap[i.id];let h=c[i.id],d=i.bounds,u=d.left,_=d.top,f=o==H?d.width/h.length:d.width,g=o==H?d.height:d.height/h.length;for(let e=0;e<h.length;e++){let t=Nt(p);t.dataScope=h[e],console.log(t.dataScope),t.resize(f,g),t._updateBounds(),t._refBounds=t.bounds.clone(),r.addChild(t);for(let e of t.vertices)e.dataScope?e.dataScope=t.dataScope.merge(e.dataScope):e.dataScope=t.dataScope}a.addChild(r),r._layout=new Un({orientation:o,left:u,top:_}),r._layout.group=r,i==t&&(n=r)}return{newMark:n.children[0],collection:n}}(e,t,r,i,s);case Vt.Ring:return function(e,t,i,r,s){let n,a,o,l=C(t),h=i||X;if(h!=X&&h!=q)throw new Error("Unknown orientation: "+h);h===X&&l.forEach(i=>{let l=i.dataScope?i.dataScope:new ce(s),h=s.getUniqueAttributeValues(r).map(e=>l.cross(r,e));h=h.filter(e=>!e.isEmpty());let c=Ot(e);null==a&&(a=c.id),c._classId=a,c.dataScope=i.dataScope?i.dataScope:new ce(s);let d=i.parent;d.removeChild(i),delete e._itemMap[i.id];let u=360/h.length,p=90;for(let e=0;e<h.length;e++){let r=Rt({type:"arc",innerRadius:i.innerRadius,outerRadius:i.outerRadius,x:i.x,y:i.y,startAngle:le(p-u*(e+1)),endAngle:le(p-u*e),strokeColor:i.strokeColor,fillColor:i.fillColor,strokeWidth:i.strokeWidth,opacity:i.opacity});o||(o=r.id),r.classId=o,r.dataScope=h[e],r._updateBounds(),r._refBounds=r.bounds.clone(),c.addChild(r),c._layout=new Un({orientation:X,direction:Z.CLOCKWISE}),c._layout.group=c,d.removeChild(i),d.addChild(c),i===t&&(n=c)}});return{newMark:n.children[0],collection:n}}(e,t,r,i,s);case Vt.Pie:case Vt.Arc:return function(e,t,i,r,s){let n,a,o,l=C(t),h=i||X;if(h!=X&&h!=q)throw new Error("Unknown orientation: "+h);h===X||l.forEach(i=>{let l=i.dataScope?i.dataScope:new ce(s),h=s.getUniqueAttributeValues(r).map(e=>l.cross(r,e));h=h.filter(e=>!e.isEmpty());let c=Ot(e);null==a&&(a=c.id),c._classId=a,c.dataScope=i.dataScope?i.dataScope:new ce(s);let d=i.parent;d.removeChild(i),delete e._itemMap[i.id];for(let e=0;e<h.length;e++){let r=Rt({type:"arc",innerRadius:i.innerRadius+e*(i.outerRadius-i.innerRadius)/h.length,outerRadius:i.innerRadius+(e+1)*(i.outerRadius-i.innerRadius)/h.length,x:i.x,y:i.y,startAngle:i.startAngle,endAngle:i.endAngle,strokeColor:i.strokeColor,fillColor:i.fillColor,strokeWidth:i.strokeWidth,opacity:i.opacity});o||(o=r.id),r.classId=o,r.dataScope=h[e],r._updateBounds(),r._refBounds=r.bounds.clone(),c.addChild(r),c._layout=new Un({orientation:q}),c._layout.group=c,d.removeChild(i),d.addChild(c),i===t&&(n=c)}});return{newMark:n.children[0],collection:n}}(e,t,r,i,s)}}function Yn(e){if([Vt.Line,Vt.Circle,Vt.Rect,Vt.Area,Vt.Ring,Vt.Pie,Vt.Path].indexOf(e.type)<0)return!1;if(e.type===Vt.Path&&(e.closed||!e.firstVertex.dataScope))return!1;if(e.dataScope){let t=C(e);for(let e of t)if(e.dataScope.numTuples>1)return!0;return!1}return!0}function Xn(e,t,i,r){let s=r.getAttributeType(i);if(s!=xe.String&&s!=xe.Date&&s!=xe.Integer)throw new Error("Repopulate only works on a string or date attribute: "+i+" is "+s);let n=C(t);for(let e of n){let t=r.getAttributeSummary(i).unique.map(t=>e.dataScope?e.dataScope.cross(i,t):new ce(r).cross(i,t));t=t.filter(e=>!e.isEmpty());let s=e.children.length-t.length,n=t.length-e.children.length;for(let t=0;t<s;t++)e.removeChildAt(e.children.length-1);let a=e._children.length;for(let t=0;t<n;t++){let i=Nt(e._children[t%a]);e.addChild(i)}e.children.forEach((e,i)=>e.dataScope=t[i])}}class qn{constructor(e,t){this._elem=e,this._base=t,this._id=Kn(e,t),this._channels={},this._attribute=void 0}get id(){return this._id}get element(){return this._elem}get base(){return this._base}get channels(){return Object.keys(this._channels)}addChannel(e,t){let i={};i.elemAnchor="elementAnchor"in t?t.elementAnchor:"x"==e||"angle"==e?v.CENTER:v.MIDDLE,i.baseAnchor="baseAnchor"in t?t.baseAnchor:"x"==e||"angle"==e?v.CENTER:v.MIDDLE,i.offset="offset"in t?t.offset:0,"attribute"in t&&(this._attribute=t.attribute),this._channels[e]=i}hasChannel(e){return e in this._channels}getElementAnchor(e){return this._channels[e].elemAnchor}getBaseAnchor(e){return this._channels[e].baseAnchor}getOffset(e){return this._channels[e].offset}get attribute(){return this._attribute?this._attribute:Gt}}function Kn(e,t){return(e.classId?e.classId:e.id)+":"+(t.classId?t.classId:t.id)}function Zn(e,t,i,r){e.dataScope&&e.dataScope.dataTable.hasAttribute(t)?function(e,t,i,r){if(!e.dataScope.dataTable.hasAttribute(t))return void console.warn("Cannot order collection children by an non-existent attribute",t);let s;if(t===Gt)s=(e,i)=>parseInt(e.dataScope.getAttrVal(t).substring(1))-parseInt(i.dataScope.getAttrVal(t).substring(1));else{switch(e.children[0].dataScope.getAttributeType(t)){case xe.Date:break;case xe.Number:case xe.Integer:s=(e,i)=>e.dataScope.aggregateNumericalAttribute(t)-i.dataScope.aggregateNumericalAttribute(t);break;case xe.String:s=r?(e,i)=>r.indexOf(e.dataScope.getAttrVal(t))-r.indexOf(i.dataScope.getAttrVal(t)):(e,i)=>e.dataScope.getAttrVal(t)<i.dataScope.getAttrVal(t)?-1:1}}e.children.sort(s),i&&e.children.reverse()}(e,t,i,r):function(e,t,i){let r;switch(t){case"x":case"y":case"width":case"height":r=(e,i)=>e.bounds[t]-i.bounds[t];break;default:r=(e,i)=>e[t]-i[t]}e._children.sort(r),i&&e.children.reverse()}(e,t,i),e._sortBy={property:t,descending:i,vals:r}}function $n(e,t,i,r){e.vertices[0].dataScope&&e.vertices[0].dataScope.dataTable.hasAttribute(t)?function(e,t,i,r){let s;if(t===Gt)s=(e,i)=>parseInt(e.dataScope.getAttrVal(t).substring(1))-parseInt(i.dataScope.getAttrVal(t).substring(1));else{switch(e.vertices[0].dataScope.getAttributeType(t)){case xe.Date:break;case xe.Number:case xe.Integer:s=(e,i)=>e.dataScope.aggregateNumericalAttribute(t)-i.dataScope.aggregateNumericalAttribute(t);break;case xe.String:s=r?(e,i)=>r.indexOf(e.dataScope.getAttrVal(t))-r.indexOf(i.dataScope.getAttrVal(t)):(e,i)=>e.dataScope.getAttrVal(t)<i.dataScope.getAttrVal(t)?-1:1}}e.vertices.sort(s),i&&e.vertices.reverse()}(e,t,i,r):function(e,t,i){let r=(e,i)=>e[t]-i[t];e.vertices.sort(r),i&&e.vertices.reverse()}(e,t,i),e._sortBy={property:t,descending:i,vals:r}}class Jn extends D{constructor(e){super(),this.type=B.GRID,this._numCols=e.numCols,this._numRows=e.numRows,this._start="start"in e?e.start:U.TopLeft,this._direction="direction"in e?e.direction:W.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&&G("h",e.horzCellAlignment)?e.horzCellAlignment:v.LEFT,this._cellVertAlignment="vertCellAlignment"in e&&G("v",e.vertCellAlignment)?e.vertCellAlignment:v.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}set numCols(e){this._numCols=e}set numRows(e){this._numRows=e}get numRows(){return this._numRows?this._numRows:this._numCols?Math.ceil(this.group.children.length/this._numCols):0}clone(){let e=new Jn({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 i=[],r=this.group.children;for(let t=0;t<this.numRows;t++){let s=this._grid[t].filter(e=>null!=e).map(e=>r[e]);if(e){let e=[];for(let t of s)e=e.concat(V(t));i.push(e)}else i.push(s)}return t&&(i=this._filterElementsByExample(i,t)),i}getElementsByCol(e,t){let i=[],r=this.group.children,s=this._grid;for(let t=0;t<this.numCols;t++){let n=s.map(e=>e[t]).filter(e=>null!=e).map(e=>r[e]);if(e){let e=[];for(let t of n)e=e.concat(V(t));i.push(e)}else i.push(n)}return t&&(i=this._filterElementsByExample(i,t)),i}getElementsByCell(e,t){let i=[],r=this.group.children;for(let t=0;t<r.length;t++)if(e){let e=V(r[t]);i.push(e)}else i.push(r[t]);return t&&(i=this._filterElementsByExample(i,t)),i}_filterElementsByExample(e,t){let i;return"vertex"===t.type?(i=e.map(e=>e.filter(e=>e.classId===t.parent.classId)),i=i.map(e=>k(t,e))):"segment"===t.type?(i=e.map(e=>e.filter(e=>e.classId===t.parent.classId)),i=i.map(e=>S(t,e))):i=e.map(e=>e.filter(e=>e.classId===t.classId)),i}getIndex(e){let t=e;for(;t&&t.parent!==this.group;)t=t.parent;return this.group.children.indexOf(t)}getRowCol(e){let t,i;switch(this._direction){case W.RowFirst:t=Math.floor(e/this.numCols),i=e%this.numCols;break;case W.ColumnFirst:t=e%this.numRows,i=Math.floor(e/this.numRows);break;default:throw new Error("Invalid fill direction. Use 'row_first' or 'column_first'.")}return this._start.toLowerCase().includes("bottom")&&(t=this.numRows-1-t),this._start.toLowerCase().includes("right")&&(i=this.numCols-1-i),{row:t,col:i}}get startCorner(){return this._start}set startCorner(e){this._start=e}get direction(){return this._direction}set direction(e){this._direction=e}}class Qn extends mt{constructor(e,t){super(),this._type=Vt.Axis,this._id=this._type+Mt(),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:Y,this._numberFormat=t.numberFormat?t.numberFormat:""}get attribute(){return this._enc.attribute}get channel(){return this._enc.channel}get attributeType(){return Bt(this._enc.element).getFieldType(this.attribute)}get orientation(){return this._orientation}get textColor(){return this._textColor}}class ea extends Qn{constructor(e,t){super(e,t),"numCols"in t||"numRows"in t?(this._numCols=t.numCols,this._numRows=t.numRows):this._orientation===Y?this._numCols=1:this._numRows=1,this._initialize()}_initialize(){let e=this._enc.element.scene,t=this._enc.attribute,i=this._enc.scales[0],r=new Dt(i.domain.map(e=>({category:e,value:i.map(e)}))),s=r.getUniqueAttributeValues("category").sort((e,t)=>t.length-e.length)[0],n=this._enc.element,a=n instanceof ee&&n.closed&&"strokeColor"!==this._enc.channel?n.strokeWidth:0;if(this._orientation===Y){let i=0;this._showTitle&&(this.addChild(new Ct({fillColor:this._textColor,fontSize:this._fontSize,text:t,x:this._x,y:this._y,anchor:["left","top"]})),i=parseFloat(this._fontSize)+5);let o=e.mark("rect",{top:this._y+2+i,left:this._x,width:10,height:10,strokeWidth:a,strokeColor:n.strokeColor,opacity:n.opacity}),l=e.mark("text",{text:s,fillColor:this._textColor,fontSize:this._fontSize,x:this._x+20,y:this._y+i+12+a,anchor:["left","bottom"]}),h=e.glyph(o,l),c=e.repeat(h,r);e.encode(l,{channel:"text",attribute:"category",forLegend:!0}),e.encode(o,{channel:"fillColor",attribute:"category",shareScale:this._enc,forLegend:!0}),c.layout=new Jn({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:n.strokeColor,opacity:n.opacity}),i=e.mark("text",{text:s,fillColor:this._textColor,fontSize:this._fontSize,x:this._x+15,y:this._y,anchor:["left","top"]}),o=e.glyph(t,i),l=e.repeat(o,r);e.encode(i,{channel:"text",attribute:"category",forLegend:!0}),e.encode(t,{channel:"fillColor",attribute:"category",shareScale:this._enc,forLegend:!0}),l.layout=new Jn({numCols:this._numCols,numRows:this._numRows,colGap:15}),this.addChild(l)}}}class ta extends Qn{constructor(e,t){super(e,t),this._initialize()}_initialize(){let e,t,i,s=this._enc.element.scene,n=this._enc.attribute;if(this._orientation==Y?(e=15,t=300):(e=300,t=15),this._showTitle){let t=s.mark("text",{fillColor:this._textColor,text:n,x:this._x+e/2,y:this._y,anchor:["center","middle"]});this.addChild(t),i=20}else i=0;let a,o=s.mark("rect",{top:this._y+i,left:this._x,width:e,height:t,strokeWidth:0,opacity:this._enc.element.opacity}),l=Object.values(this._enc.attrValues),h=[Math.min(...l),Math.max(...l)],c=this._enc.mapping,d=[],u=[],p=r.format(this._numberFormat);if(c){let r=Object.keys(c).map(e=>parseFloat(e)).sort((e,t)=>e-t);this._orientation==Y?(a=new j({x1:0,y1:100,x2:0,y2:0}),r.forEach(r=>{let n=(r-h[0])/(h[1]-h[0]);a.addStop(100*n,c[r],1);let o=s.mark("line",{x1:this._x+e,x2:this._x+e+5,y1:this._y+t-n*t+i,y2:this._y+t-n*t+i,strokeColor:this._strokeColor});u.push(o);let l=s.mark("text",{fillColor:this._textColor,text:this._numberFormat?p(r):r.toFixed(0),x:this._x+e+5+5,y:this._y+t-n*t+i,anchor:["left","middle"]});d.push(l)})):(a=new j({x1:0,y1:0,x2:100,y2:0}),r.forEach(r=>{let n=(r-h[0])/(h[1]-h[0]);a.addStop(100*n,c[r],1);let o=s.mark("line",{x1:this._x+n*e,x2:this._x+n*e,y1:this._y+20-5+i,y2:this._y+t+5+i,strokeColor:this._strokeColor});u.push(o);let l=s.mark("text",{fillColor:this._textColor,text:this._numberFormat?p(r):r.toFixed(0),x:this._x+n*e,y:this._y+t+5+i,anchor:["center","top"]});d.push(l)}))}else{let r=this._enc.scales[0].domain,o=Bt(this._enc.element),l=o.getAttributeType(n),h=[],c=l===xe.Date?o.getUniqueFieldValues(n):[...new Set(Object.values(this._enc.attrValues))];if(c.length<=10)h=c,h.sort((e,t)=>e-t);else if(l===xe.Date){c.sort((e,t)=>e-t);for(let e=0;e<c.length;e+=Math.ceil(c.length/10))h.push(c[e])}else{let e=(r[1]-r[0])/9;for(let t=0;t<10;t++)h.push(r[0]+t*e)}let _=0,f=(h[h.length-1]-h[0])/h.length;for(;f<1;)f*=10,_++;h=h.map(e=>e.toFixed(_)),this._orientation==Y?(a=new j({x1:0,y1:100,x2:0,y2:0}),h.forEach(h=>{let c=(h-r[0])/(r[1]-r[0]);a.addStop(100*c,this._enc.scales[0].map(h),1);let _=s.mark("line",{x1:this._x+e,x2:this._x+e+5,y1:this._y+t-c*t+i,y2:this._y+t-c*t+i,strokeColor:this._strokeColor});u.push(_);let f=s.mark("text",{fillColor:this._textColor,text:l===xe.Date?o.getRawValue(n,h):this._numberFormat?p(h):h,x:this._x+e+5+5,y:this._y+t-c*t+i,anchor:["left","middle"]});d.push(f)})):(a=new j({x1:0,y1:0,x2:100,y2:0}),h.forEach(h=>{let c=(h-r[0])/(r[1]-r[0]);a.addStop(100*c,this._enc.scale.map(h),1);let p=s.mark("line",{x1:this._x+c*e,x2:this._x+c*e,y1:this._y+t+i,y2:this._y+t+5+i,strokeColor:this._strokeColor});u.push(p);let _=s.mark("text",{fillColor:this._textColor,text:l===xe.Date?o.getRawValue(n,h):h,x:this._x+c*e,y:this._y+t+5+i,anchor:["center","top"]});d.push(_)}))}o.styles.fillColor=a,this.addChild(o);for(let e of d)this.addChild(e);for(let e of u)this.addChild(e)}}class ia extends mt{constructor(e){super(),this._type=Vt.Composite,this._id=e&&e.id?e.id:this._type+Mt()}addChild(e){let t=e.parent;super.addChild(e);let i=N(e)._depGraph;t&&ot(t,e,i),lt(this,e,i)}}class ra{constructor(e,t,i){this._elems=e,this._channel=t,this._anchor=i}get elements(){return this._elems}get channel(){return this._channel}get anchor(){return this._anchor}}class sa extends D{constructor(e){super(),this.type=B.STRATA,this._direction=e.direction,this._gap="gap"in e?e.gap:0}clone(){return new sa({direction:this._direction,gap:this._gap})}}function na(e,t,i,r,s,n){switch(t.type){case Vt.Circle:case Vt.Ring:return function(e,t,i,r,s,n){let a,o=i||$.OUTWARD,l=s||50;if(o!==$.INWARD&&o!==$.OUTWARD)throw"Unknown direction to stratify";let h,c=C(t,e),d=Array.isArray(n)?n:[n];if(r){let i=Ot(e);i.dataScope=void 0,null==h&&(h=i.id),i._classId=h;let r=c.map(e=>d[0].getNode(e.dataScope.getAttrVal(me)));aa(c,r,d[0],i,t.classId?t.classId:t.id,400,350,o,l),a=i}else c.forEach((i,r)=>{let s=Ot(e);s.dataScope=void 0,null==h&&(h=s.id),s._classId=h;let n=i.parent;oa(i,t.id,o,l,d[r],d[r].getRoot(),s,e,!0),s._layout=new sa({direction:o}),s._layout.group=s,n.addChild(s),i===t&&(a=s)});return a}(e,t,i,r,s,n);case Vt.Rect:return function(e,t,i,r,s,n){let a,o,l=i||K.Top2Bottom,h=s||50;if(!Object.values(K).includes(l))throw"Unknown direction to stratify";return C(t).forEach(i=>{let r=Ot(e);r.dataScope=void 0,null==o&&(o=r.id),r._classId=o;let s=i.parent;la(i,t.id,l,h,n,n.getRoot(),r,e,!0),r._layout=new sa({direction:l}),r._layout.group=r,s.addChild(r),i===t&&(a=r)}),a}(e,t,i,0,s,n)}}function aa(e,t,i,r,s,n,a,o,l){let h=t.map(e=>i.getParent(e)).filter((e,t,i)=>i.findIndex(t=>t[me]===e[me])===t);if(h=h.filter(e=>e!==i.getRoot()),0===h.length)return;let c=[];for(let t of h){let h,d,u,_=e.filter(e=>i.getParent(i.getNode(e.dataScope.getAttrVal(me)))===t);if(_[0].type===Vt.Circle){let e=_.map(e=>p(n,a,e.bounds.x,e.bounds.y)-e.radius),t=_.map(e=>p(n,a,e.bounds.x,e.bounds.y)+e.radius);u=o===$.OUTWARD?Math.max(...t):Math.min(...e)-l;let i=_.map(e=>he(e.bounds.x,e.bounds.y,n,a)),r=_.map(e=>he(n+p(n,a,e.bounds.x,e.bounds.y),a-e.radius,n,a)),s=i.map((e,t)=>e-r[t]),c=i.map((e,t)=>e+r[t]),f=s.concat(c);h=Math.min(...f),d=Math.max(...f)}else _[0].type===Vt.Arc&&(h=360,d=-360,_.forEach(e=>{let t=e.startAngle,i=e.endAngle;i<t&&(i+=360),h=Math.min(h,t),d=Math.max(d,i)}),h=le(h),d=le(d),u=o===$.OUTWARD?Math.max(..._.map(e=>e.outerRadius)):Math.min(..._.map(e=>e.innerRadius))-l);let f=Rt({type:"arc",innerRadius:u,outerRadius:u+l,x:n,y:a,startAngle:le(h),endAngle:le(d),strokeColor:e[0].strokeColor,fillColor:e[0].fillColor,strokeWidth:e[0].strokeWidth,opacity:e[0].opacity});f._updateBounds(),f.dataScope=i.getNodeDataScope(t),f._classId=s,r.addChild(f),c.push(f)}aa(c,h,i,r,s,n,a,o,l)}function oa(e,t,i,r,s,n,a,o,l){l&&(e.dataScope=s.getNodeDataScope(n),e._classId=t);let h=s.getChildren(n);if(0===h.length)return;let c=e.type===Vt.Circle||e.type===Vt.Ring?60:e.startAngle,d=(e.type===Vt.Circle||e.type===Vt.Ring?360:e.angle)/h.length;for(let n=0;n<h.length;n++){let o,l;l=i===$.OUTWARD?e.type===Vt.Circle?e.radius:e.outerRadius:e.type===Vt.Circle?e.radius-r:e.innerRadius-r,o=Rt(360===d?{type:"ring",innerRadius:l,outerRadius:l+r,x:e.x,y:e.y,strokeColor:e.strokeColor,fillColor:e.fillColor,strokeWidth:e.strokeWidth,opacity:e.opacity}:{type:"arc",innerRadius:l,outerRadius:l+r,x:e.x,y:e.y,startAngle:le(c+d*n),endAngle:le(c+d*(n+1)),strokeColor:e.strokeColor,fillColor:e.fillColor,strokeWidth:e.strokeWidth,opacity:e.opacity}),o._updateBounds(),o.dataScope=s.getNodeDataScope(h[n]),o._classId=t+"_strata",a.addChild(o),oa(o,t,i,r,s,h[n],a)}}function la(e,t,i,r,s,n,a,o,l){l&&(e.dataScope=s.getNodeDataScope(n),e._classId=t,a.addChild(e));let h,c,d,u=s.getChildren(n);if(0!==u.length){h=e.left,c=e.bottom,d=e.width/u.length;for(let n=0;n<u.length;n++){let o=Nt(e);Fe(o,h-o.left,c-o.top),o.resize(d,r),o._updateBounds(),h+=d,o.dataScope=s.getNodeDataScope(u[n]),o._classId=t,a.addChild(o),la(o,t,i,r,s,u[n],a)}}}class ha{constructor(e,t,i,r){this._id=e,this._event=i,this._target=t,this._evtCtx=new zn,this._cumulative=r}get id(){return this._id}get event(){return this._event}get eventContext(){return this._evtCtx}get target(){return this._target}isCumulative(){return this._cumulative}isMouseDriven(){return["brush","brushX","brushY","click","hover"].includes(this._event)}isKeyboardDriven(){return["keydown","keyup"].includes(this._event)}isWidgetDriven(){return["change","input"].includes(this._event)}}class ca extends mt{constructor(e){super(),this._itemMap={},this._peerIndex=new Map,this._type=Vt.Scene,this._id=e&&e.id?e.id:this._type+Mt(),e&&e.fillColor&&(this.fillColor=e.fillColor),this._encodings={},this._relations=[],this._triggers={},this._condEncodings={},this._depGraph=new Dn}get depGraph(){return this._depGraph}get interactionTriggers(){return this._triggers}buildPeerIndex(){this._peerIndex=new Map;let e=this._peerIndex;M(this,t=>{t.classId&&(e.has(t.classId)||e.set(t.classId,[]),e.get(t.classId).push(t))})}mark(e,t){if(Object.values(Lt).indexOf(e)<0)throw new Error("Mascot does not allow directly creating a "+e);let i=void 0===t?{}:t;i.type=e;let r=Rt(i);return null!==r&&(r._classId=r.id,this.addChild(r),this._itemMap[r.id]=r,tt(r,this._depGraph),lt(this,r,this._depGraph)),r}glyph(...e){let t=[];for(let i of e)t.push([i.parent,i]);let i=It(e);if(null!==i){i._classId=i.id,this.addChild(i),this._itemMap[i.id]=i;for(let e of t)ot(e[0],e[1],this._depGraph);ht(i,this._depGraph),lt(this,i,this._depGraph)}return i}composite(){let e=new ia;return null!==e&&(e._classId=e.id,this.addChild(e),this._itemMap[e.id]=e,at(e,this._depGraph),lt(this,e,this._depGraph)),e}attach(e,t){if(e.type==Vt.Glyph)for(let t of e.children)t._refBounds||(t._refBounds=t.bounds.clone());e.dataScope=new ce(t)}repeat(e,t,i){let r=i||{};if(r.attribute=r.attribute||Gt,function(e,t,i){if(!e||void 0===t)throw new Error("Incomplete information to do repeat. You must specify an element, a categorical data attribute and a data table");if(t instanceof pe||t instanceof fe){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 Dt&&be(i.attribute,t);if(i.layout&&!(i.layout instanceof D))throw new Error("Invalid layout: "+i.layout)}(e,t,r),t instanceof pe||t instanceof fe){let i=e[0].parent,r=e[1].parent,[s,n]=function(e,t,i,r){let s=r.nodeTable.getAttributeSummary(me).unique.map(e=>t.dataScope?t.dataScope.cross(me,e):new ce(r.nodeTable).cross(me,e)),n=Ot(e),a=Ot(e),o={};a.dataScope=t.dataScope?t.dataScope.clone():new ce(r.nodeTable),a.addChild(t);for(let e=1;e<s.length;e++){let e=Nt(t);a.addChild(e)}a.children.forEach((e,t)=>{e.dataScope=s[t],e.links=[],o[e.dataScope.getAttrVal(me)]=e});let l=r.linkTable.getAttributeSummary(Gt).unique.map(e=>i.dataScope?i.dataScope.cross(Gt,e):new ce(r.linkTable).cross(Gt,e));n.dataScope=i.dataScope?i.dataScope.clone():new ce(r.linkTable),n.addChild(i);for(let e=1;e<l.length;e++){let e=Nt(i);n.addChild(e)}n.children.forEach((e,t)=>e.dataScope=l[t]);let h=r instanceof pe?"parent":"source",c=r instanceof pe?"child":"target";for(let e of n.children){let t=e.dataScope.getAttrVal(h),i=e.dataScope.getAttrVal(c),r=o[t],s=o[i];e.source=r,e.target=s,r.links.push(e),s.links.push(e)}return[a,n]}(this,e[0],e[1],t);return this.buildPeerIndex(),ot(i,e[0],this._depGraph),ot(r,e[1],this._depGraph),nt(s,this._depGraph),nt(n,this._depGraph),lt(s,e[0],this._depGraph),lt(s.parent,s,this._depGraph),lt(n,e[1],this._depGraph),lt(n.parent,n,this._depGraph),[s,n]}if(t instanceof Dt){let i=e.parent,s=Gn(this,e,r.attribute,t);return this.buildPeerIndex(),ot(i,e,this._depGraph),nt(s,this._depGraph),lt(s,e,this._depGraph),lt(s.parent,s,this._depGraph),r.layout&&(s.layout=r.layout),s}}divide(e,t,i){let r=i||{};if(r.attribute=r.attribute||Gt,console.log("------ divide by",r.attribute," ----"),function(e,t,i){if(!e||void 0===t)throw new Error("Incomplete information to do divide. You must specify an element, a categorical data attribute and a data table");if(t instanceof Dt&&be(i.attribute,t),i.layout&&!(i.layout instanceof D))throw new Error("Invalid layout: "+i.layout)}(e,t,r),t instanceof pe||t instanceof fe)throw"Not implemented";if(t instanceof Dt){let{newMark:i,collection:s}=Hn(this,e,r.attribute,r.orientation,t);return this.buildPeerIndex(),it(e,this._depGraph),tt(i,this._depGraph),nt(s,this._depGraph),lt(s,i,this._depGraph),s.parent.type!==Vt.Scene&<(s.parent,s,this._depGraph),this.onChange(Te.CHANNEL,"width",i),{newMark:i,collection:s}}}densify(e,t,i){let r=i||{};if(r.attribute=r.attribute||Gt,console.log("------ densify by",r.attribute," ----"),function(e,t,i){if(!e||void 0===t)throw new Error("Incomplete information to do densification. You must specify an element, a categorical data attribute and a data table");t instanceof Dt&&be(i.attribute,t)}(e,t,r),t instanceof pe||t instanceof fe)throw"Not implemented";if(t instanceof Dt){let i=Ae(0,e,r.attribute,r.orientation,t);return this.buildPeerIndex(),it(e,this._depGraph),tt(i,this._depGraph),i.parent.type!==Vt.Scene&<(i.parent,i,this._depGraph),this.onChange(Te.CHANNEL,"width",i),i}}stratify(e,t,i){if(!(t instanceof pe||Array.isArray(t)&&t.every(e=>e instanceof pe)))throw"Cannot stratify on a non-tree dataset";if(![Vt.Circle,Vt.Rect,Vt.Ring].includes(e.type))throw"Cannot stratify elements that are not rects, circles, or rings";let r=i||{},s=r.direction,n=r.size,a=e.parent,o=na(this,e,s,r.startFromLeaf,n,t);return this.buildPeerIndex(),ot(a,e,this._depGraph),nt(o,this._depGraph),o.children.length>0&<(o,o.firstChild,this._depGraph),lt(o.parent,o,this._depGraph),o}repopulate(e,t,i){e.dataScope=void 0;let r=e;for(let e in i){Xn(0,r,i[e],t);let s=Ne(r.children[0]);for(let e of s){Ie(e,this),rt(e,this._depGraph);for(let t of e.refElements)si(t,this),st(t,this._depGraph);e.clearRefElements()}let n=C(r);for(let e of n)if(e.layout){for(let t of e.layout.refElements)si(t,this),st(t,this._depGraph);e.layout.clearRefElements()}r=r.children[0]}e.dataScope=new ce(t),this.buildPeerIndex(),this.onChange(Te.CHANNEL,"width",e.children[0])}classify(e,t){let i=t||{};console.log("------ classify by",i.attribute," ----"),function(e,t,i,r){let s=C(t);for(let t of s){let s,n={},a=t.children;for(let e of a){let t=e.dataScope.getAttrVal(i);t in n||(n[t]=[]),n[t].push(e)}let o=Bt(a[0]);for(let a in n){let l=Ot(e);t.addChild(l),void 0===s&&(s=l.id),l._classId=s,l.dataScope=t.dataScope?t.dataScope.cross(i,a):new ce(o).cross(i,a);for(let e of n[a])l.addChild(e);r&&(l._layout=r.clone(),l._layout.group=l)}}}(this,e,i.attribute,i.layout),this.buildPeerIndex(),ot(e,e.firstChild.firstChild,this._depGraph),nt(e.firstChild,this._depGraph),lt(e.firstChild,e.firstChild.firstChild,this._depGraph),lt(e,e.firstChild,this._depGraph),this.onChange(Te.CHANNEL,"width",e.firstChild.firstChild)}affix(e,t,i,r){e.dataScope.dataTable!==e.dataScope.dataTable&&console.warn("Affix: elements and base elements are not created from the same table");let s=Kn(e,t),n=this._relations.find(e=>e.id===s);n||(n=new qn(e,t),this._relations.push(n)),n.addChannel(i,r||{}),function(e,t){let i=t.getVariable(Te.AFFIXATION,e),r=t.getOutgoingDataflowOperator(z.AFFIXER,i);t.connect(i,r);for(let i of e.channels){let s=t.getVariable(Te.CHANNEL,i,e.element),n=t.getVariable(Te.CHANNEL,i,e.base);t.connect(n,r),t.connect(r,s)}r.run()}(n,this._depGraph)}align(e,t,i){let r=new ra(e,t,i);!function(e,t){let i=t.createMultiWayDependency(z.ALIGNER),r=t.getVariable(Te.ALIGNMENT,e);t.connect(r,i);for(let r of e.elements){let s=t.getVariable(Te.CHANNEL,e.channel,r);t.connect(s,i)}i.run()}(r,this._depGraph),this._relations.push(r)}encode(e,t){if("rowId"===t.attribute&&(t.attribute=Gt),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 i=Bt(e);if(i.tree){let e=t.attribute;if(e.indexOf(".")>0&&!i.tree.nodeTable.hasAttribute(e.split(".")[1]))throw new Error("Data attribute does not exist in the data table")}else if(!i||!i.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===Vt.Area?t=e.parent:e.type===Vt.Area&&(t=e),t&&!t._refBounds&&C(t).forEach(e=>e._refBounds=e.bounds.clone())}(e);let i=t.aggregator?t.aggregator:"sum";console.log("------ encode",t.channel,t.attribute," --");let r=Ve(e,t.channel);if(r&&t.attribute!==r.attribute){Ie(r,this),rt(r,this._depGraph);for(let e of r.refElements)si(e,this),st(e,this._depGraph);r.clearRefElements()}t.table=Bt(e);let s=new Fn(e,t.channel,t.attribute,i,t);return this._addAttributeEncoding(s),_t(s,this._depGraph,t.shareScale),t.shareScale?this.onChange(Te.ATTR_VALUE,s):this.onChange(Te.CHANNEL,t.channel,e),s}connect(e,t){let i={};e.forEach(e=>i[e.dataScope.getAttrVal(me)]=e);let r=t[0].dataScope.dataTable,s=r.tree?"parent":"source",n=r.tree?"child":"target";for(let t of e)t.links=[];for(let e of t){let t=e.dataScope.getAttrVal(s),r=e.dataScope.getAttrVal(n),a=i[t],o=i[r];e.source=a,e.target=o,a.links.push(e),o.links.push(e)}pt(e.find(e=>e.links.length>0),this._depGraph),this.onChange(Te.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,i,r,s){!function(e,t,i,r,s){if(!("event"in e)||!("target"in e))throw"Target and event must be specified in the trigger";if(!("component"in i))throw"Responder component must be specified";if(Array.isArray(r)){if(!r.every(e=>"function"==typeof e))throw"Styling rules must be a function";if(s&&!Array.isArray(s))throw"An array of effect setters must be accompanied by an array of animation effects";if(s&&Array.isArray(s)&&s.length!==r.length)throw"the length of effect setters is not equal to the length of animation effects"}else if("function"!=typeof r)throw"Styling rules must be a function"}(e,0,t,r,s);let n=e.event,a=function(e){return["string"==typeof e.target?e.target:e.target.classId?e.target.classId:e.target.id,e.event].join("-")}(e);n=0===n.indexOf("brush")?"brush":0===n.indexOf("drag")?"drag":n,n in this._triggers||(this._triggers[n]={}),a in this._triggers[n]||(this._triggers[n][a]=new ha(a,e.target,e.event,e.cumulative));let o=this._triggers[n][a].eventContext,l=new jn(o,t.component,i,r);return a in this._condEncodings||(this._condEncodings[a]=[]),this._condEncodings[a].push(l),function(e,t,i,r){let s=t.responderComponent,n=r.getVariable(Te.EVT_CTX,e),a=i.properties?i.properties:i.channels;if(t.evalFunction){let e=r.getVariable(Te.CONDITION_RESULT,t.evalResult,t),i=r.findIncomingDataflowOperator(z.TARGET_EVALUATOR,e);i||(i=r.createOneWayDependency(z.TARGET_EVALUATOR,t.evalFunction)),r.connect(n,i),r.connect(i,e);for(let t of a){let i=Array.isArray(s)?s:[s];for(let s of i){let i=r.getVariable(Te.CHANNEL,t,s),n=i.incomingDataflow;if(n&&n instanceof Ze&&n.outputVar.channel===t)r.connect(e,n);else if(!n){let n=r.createOneWayDependency(z.ENCODER);r.connect(e,n),r.connect(n,i),n.storeValues(s,t)}}}}else for(let e of a){Object.values(Oe).includes(e)?r.getVariable(Te.CHANNEL,e,s):r.getVariable(Te.PROPERTY,Je(e),s);let i=r.createOneWayDependency(z.TARGET_UPDATER,t.stylingFunction,s);r.connect(n,i)}}(o,l,t,this._depGraph),this._triggers[n][a]}onChange(e,...t){if(Object.values(Te).indexOf(e)<0)throw new Error("Unknown Variable Type: "+e);let i=[];this._depGraph.processChange(e,i,...t);for(let e of i)e.run()}gridlines(e,t,i){let r=i||{},s=r.element?Ve(r.element,e):Le(t,e,this);if(s){s.attribute!==t&&console.warn("Cannot create a "+e+" axis for "+t);let i=[];if("x"==e)for(let e of s.scales)i.push({scale:e,elems:s.getElements(e)});else if("width"==e){let e=L(s.element),t=s.scales[0];if(e.layout&&e.layout.type==B.GRID&&e.layout.numCols>1){let r=e.layout.getElementsByCol(!0);for(let e of r)i.push({scale:t,elems:e})}else i.push({scale:s.scales[0],elems:s.getElements(s.scales[0])})}else if("y"==e){let e=L(s.element);if(e.layout&&e.layout.type==B.GRID&&e.layout.numRows>1){let t=e.layout.getElementsByRow(!0,s.element);for(let e of t)i.push({scale:s.getScale(e[0]),elems:e})}else i.push({scale:s.scales[0],elems:s.getElements(s.scales[0])})}else if("height"==e){let e=L(s.element),t=s.scales[0];if(e.layout&&e.layout.type==B.GRID&&e.layout.numRows>1){let r=e.layout.getElementsByRow(!0,s.element);for(let e of r)i.push({scale:t,elems:e})}else i.push({scale:t,elems:s.getElements(t)})}else if("radialDistance"==e){let e=r.element?r.element:s.element;i.push({scale:s.scales[0],elems:C(e,e.parent)})}for(let e of i){let t=new Wn(s.channel,s.attribute,e.scale,e.elems,r);this.addChild(t),s.addRefElement(t),yt(t,this._depGraph),lt(this,t,this._depGraph)}}else{let i=r.element?r.element:R(this,t);if(!i)return void console.warn("Cannot create "+e+" gridlines for "+t);let s=O(i.parent);if(!s.layout)return void console.warn("Cannot create "+e+" gridlines for "+t);let n=C(s);for(let i of n){let s=[];i.layout.type==B.GRID&&i.layout.numRows>1&&"x"==e?s=i.layout.getElementsByRow():i.layout.type==B.GRID&&i.layout.numCols>1&&"y"==e?s=i.layout.getElementsByCol():s.push(i.children);for(let n of s){let s=new Wn(e,t,null,n,r);this.addChild(s),i.layout.addRefElement(s),yt(s,this._depGraph),lt(this,s,this._depGraph)}}}}axis(e,t,i){let r=i||{},s="rowId"==t?Gt:t,n=[],a=r.element?Ve(r.element,e):Le(s,e,this);if(a){a.attribute!==s&&console.warn("Cannot create a "+e+" axis for "+s);let t=[];if("x"==e||"width"==e){let e=L(r.element?r.element:a.element);if(e.layout&&e.layout.type==B.GRID&&e.layout.numCols>1){let i=e.layout.getElementsByCell(!0,a.element);for(let e of i)t.push({scale:a.getScale(e[0]),elems:e})}else t.push({scale:a.scales[0],elems:a.getElements(a.scales[0])})}else if("y"==e||"height"==e){let e=L(r.element?r.element:a.element);if(e.layout&&e.layout.type==B.GRID&&e.layout.numRows>1){let i=e.layout.getElementsByCell(!0,a.element);for(let e of i)t.push({scale:a.getScale(e[0]),elems:e})}else t.push({scale:a.scales[0],elems:a.getElements(a.scales[0])})}else if("radialDistance"==e){let e=r.element?r.element:a.element;t.push({scale:a.scales[0],elems:C(e,e.parent)})}for(let e of t){let t=new ni(a,e.scale,e.elems,r);this.addChild(t),n.push(t),a.addRefElement(t),gt(t,this._depGraph),lt(this,t,this._depGraph),this.onChange(Te.PROPERTY,et.AXIS_PATH_POSITION,t)}}else{let t=r.element?r.element:R(this,s);if(!t)return void console.warn("Cannot create a "+e+" axis for "+s);let i=O(t.parent);if(!i.layout)return void console.warn("Cannot create a "+e+" axis for "+s);let a=C(i);for(let t of a){let i=[];t.layout.type==B.GRID&&t.layout.numRows>1&&"x"==e?i=t.layout.getElementsByRow():t.layout.type==B.GRID&&t.layout.numCols>1&&"y"==e?i=t.layout.getElementsByCol():i.push(t.children);for(let a of i){let i=new ai(a.slice(),e,s,r);this.addChild(i),n.push(i),t.layout.addRefElement(i),ft(i,this._depGraph),lt(this,i,this._depGraph),this.onChange(Te.PROPERTY,et.AXIS_PATH_POSITION,i)}}}return n.length>1?n:n[0]}legend(e,t,i){let r=i||{},s="rowId"==t?Gt:t,n=r.element?Ve(r.element,e):Le(s,e,this);if(n){n.attribute!==t&&console.warn("Cannot create a "+e+" legend for "+t);let i="string"===Bt(n.element).getAttributeType(t)?new ea(n,r):new ta(n,r);this.addChild(i),function(e,t){let i=t.getVariable(Te.BOUNDS,e),r=t.getVariable(Te.PROPERTY,et.LEGEND_POSITION,e),s=t.getIncomingDataflowOperator(z.EVAL_BBOX,i);t.connect(r,s),t.connect(s,i)}(i,this._depGraph),lt(this,i,this._depGraph),x(i),this.onChange(Te.PROPERTY,et.LEGEND_POSITION,i)}else console.warn("Cannot create a "+e+" legend for "+s)}createMask(e){let t=L(e),i=t||e;i.clipMask||i.createClipMask()}setLayout(e,t){if(e.layout&&(dt(e,e.layout,this._depGraph),t.type===B.TREEMAP)){let t=e.firstChild;for(;t&&t.type===Vt.Collection&&t.layout;)dt(t,t.layout,this._depGraph),t=t.firstChild}if(C(e).forEach(e=>{let i=t?t.clone():t;e._layout=i,i&&(i.group=e)}),ut(e,t,this._depGraph),e.children&&e.children.length>0){let t=V(e,!0);for(let e of t)this.onChange(Te.CHANNEL,"x",e)}}setProperties(e,t,i){let r=i?[e]:C(e);r.forEach(e=>{for(const[i,r]of Object.entries(t))je(e,i,r)}),"width"in t&&r.forEach(e=>{e._refBounds&&e._refBounds.setWidth(t.width)}),"height"in t&&r.forEach(e=>{e._refBounds&&e._refBounds.setHeight(t.height)});for(let i in t)["vertex","segment"].includes(e.type)&&!["x","y"].includes(i)||(Object.values(Oe).includes(i)?this.onChange(Te.CHANNEL,i,e):this.onChange(Te.PROPERTY,i,e))}setLayoutParameters(e,t){let i=C(e);for(let e of i)for(let i in t)e.layout[i]=t[i];this.onChange(Te.CHANNEL,"width",e.firstChild)}sortChildren(e,t,i,r){if(e instanceof mt)Zn(e,t,i,r),this.onChange(Te.PROPERTY,et.CHILDREN_ORDER,e);else if(e instanceof ee){let s=C(e);for(let e of s)$n(e,t,i,r)}}translate(e,t,i){Fe(e,t,i);let r=V(e,!0);for(let e of r)x(e);for(let e of r)this.onChange(Te.CHANNEL,"x",e)}transform(e,t,i){let r=t.clone();switch(e){case"bin":!function(e,t,i,r,s){let n=s.getVariable(Te.ATTRIBUTE,e,i),a=s.getVariable(Te.ATTRIBUTE,t,r),o=s.createOneWayDependency(z.BIN_TRANSFORMER);s.connect(n,o),s.connect(o,a),o.run()}(i.attribute,i.newAttribute,t,r,this._depGraph);break;case"filter":!function(e,t,i,r){let s=r.getVariable(Te.ITEMS,void 0,t),n=r.getVariable(Te.ITEMS,e,i),a=r.createOneWayDependency(z.FILTER_TRANSFORMER);r.connect(s,a),r.connect(a,n),a.run()}(h(i),t,r,this._depGraph);break;case"kde":!function(e,t,i,r,s,n){let a=n.getVariable(Te.ATTRIBUTE,e,i),o=n.getVariable(Te.ATTRIBUTE,t,r),l=n.createOneWayDependency(z.KDE_TRANSFORMER);l.args=s,n.connect(a,l),n.connect(l,o),l.run()}(i.attribute,i.newAttribute,t,r,i,this._depGraph)}return r}getEncodingByAttribute(e,t){return Le(e,t,this)}getEncodingByElement(e,t){return Ve(e,t)}getAxis(e,t){return Le(e,t,this).refElements[0]}}function da(e,t){let i=new ce(t.tables[e.dt]);for(let t in e.attr2value)i._attr2value[t]=e.attr2value[t],i._updateTuples(t,e.attr2value[t]);return i}class ua extends D{constructor(e){super(),this.type=B.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:K.Top2Bottom}clone(){return new ua({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 pa extends D{constructor(e){super(),this.type=B.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 pa({x:this._x,y:this._y,iterations:this._iterations,repulsion:this._repulsion,attraction:this._attraction,linkDistance:this._linkDistance})}}class _a extends D{constructor(e){super(),this.type=B.PACKING,this._x="x"in e?e.x:400,this._y="y"in e?e.y:400,this._width=e.width,this._height=e.height}clone(){return new _a({x:this._x,y:this._y,width:this._width,height:this._height})}}class fa extends D{constructor(e){super(),this.type=B.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:H}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 fa({width:this._width,height:this._height,top:this._top,left:this._left,orientation:this._orientation})}}class ga extends D{constructor(e){super(),this.type=B.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 ga({width:this._width,height:this._height,top:this._top,left:this._left})}}function ya(e){switch(e.type){case B.GRID:return function(e){let t=new Jn(e.args);"left"in e&&(t._left=e.left);"top"in e&&(t._top=e.top);"cellBounds"in e&&(t._cellBounds=e.cellBounds.map(e=>ma(e)));"grid"in e&&(t._grid=e.grid);return t}(e);case B.STACK:return function(e){let t=new Un(e.args);return t}(e);case B.PACKING:return function(e){let t=new _a(e.args);return t}(e);case B.FORCE:return function(e){return new pa(e.args)}(e);case B.DIRECTED:return function(e){return new ua(e.args)}(e);case B.TIDYTREE:return function(e){return new fa(e.args)}(e);case B.TREEMAP:return function(e){return new ga(e.args)}(e);case B.STRATA:return function(e){return new sa(e.args)}(e);default:return void console.warn("unsupported layout type for deserialization:",e.type)}}function ma(e){return new g(e.x-e.width/2,e.y-e.height/2,e.width,e.height)}function ba(e,t){e.type===Vt.Pie&&(e.type=Vt.Arc),e.args.type=e.type;let i=Rt(e.args);return e.id&&(i._id=e.id),e.classId&&(i._classId=e.classId),e.dataScope&&(i._dataScope=da(e.dataScope,t)),e.bounds&&(i._bounds=ma(e.bounds)),e.refBounds&&(i._refBounds=ma(e.refBounds)),function(e,t,i){if(e.vertices){const r=[];for(let s of e.vertices){const e=xa(s,t,i);r.push(e)}t.vertices=r,t.segments=[];let s=0;for(let e=1;e<t.vertices.length;e++)t.segments.push(new Q(t.vertices[e-1],t.vertices[e],t,s++));t.type===Vt.Rect&&t.segments.push(new Q(t.vertices[t.vertices.length-1],t.vertices[0],t,s++))}t.vertexCounter=e.vertexCounter,t.segmentCounter=e.segmentCounter,t.curveMode=e.curveMode}(e,i,t),i}function xa(e,t,i){let r=new J(e.x,e.y,t,e.id);return e.dataScope&&(r._dataScope=da(e.dataScope,i)),"polarAngle"in e&&(r._polarAngle=e.polarAngle),r.shape=e.shape,r.width=e.width,r.height=e.height,r.radius=e.radius,r.fillColor=e.fillColor,r.opacity=e.opacity,r.strokeWidth=e.strokeWidth,r.strokeColor=e.strokeColor,r}function va(e){let t={};t.fillColor=e.fillColor;let i=new ca(t);console.log("======== deserialization =========");let r={};if(e.tables)for(let t in e.tables){let i=e.tables[t];r[t]=new Dt(i.data,i.url,i.attributeTypes),r[t]._id=i.id}i.tables=r;let s={};if(e.scales)for(let t in e.scales)s[t]=Ca(e.scales[t]);if(i.scales=s,Aa(e,i,i),Ea(e,i),i.buildPeerIndex(),e.encodings){let t={};for(let r of e.encodings){let e=ka(r,i);t[e.id]=e}for(let e in t){i._addAttributeEncoding(t[e]);let r=t[e]._baseEnc?t[t[e]._baseEnc]:void 0;_t(t[e],i._depGraph,r),r?i.onChange(Te.ATTR_VALUE,t[e]):i.onChange(Te.CHANNEL,t[e].channel,t[e].element)}}if(e.axes)for(let t of e.axes){let e=t.args?t.args:{};e.tickValues&&Object.values(i.tables)[0].getAttributeType(t.attr)===xe.Date&&(e.tickValues=e.tickValues.map(e=>new Date(new Date(e).toISOString()))),t.id&&(e.id=t.id),i.axis(t.channel,t.attr,e)}if(e.gridlines)for(let t of e.gridlines)i.gridlines(t.channel,t.attr,t.args);return e.bounds&&(i._bounds=ma(e.bounds)),delete i.tables,delete i.scales,i}function wa(e,t,i){if(e.type===Vt.Collection){let r=Ot(i);e.classId&&(r._classId=e.classId),t.addChild(r),i._itemMap[r.id]=r,nt(r,i._depGraph),lt(t,r,i._depGraph),Aa(e,r,i)}else if(e.type===Vt.Glyph){let r=It();e.classId&&(r._classId=e.classId),t.addChild(r),i._itemMap[r.id]=r,ht(r,i._depGraph),lt(t,r,i._depGraph),Aa(e,r,i)}else if(e.type===Vt.Composite){let r=new ia;t.addChild(r),i._itemMap[r.id]=r,at(r,i._depGraph),lt(t,r,i._depGraph),Aa(e,r,i),r._bounds=ma(e.bounds)}else if(e.type===Vt.Axis){let r=new Qt({});t.addChild(r),function(e,t,i){e.id&&(t._id=e.id);if(t._children=[],e.labels){let r=new mt;Aa(e.labels,r,i),t._labels=r,t._children.push(r)}e.path&&(t._path=wa(e.path,t,i));if(e.ticks){let r=new mt;Aa(e.ticks,r,i),t._ticks=r,t._children.push(r)}e.title&&(t._title=wa(e.title,t,i))}(e,r,i),i._itemMap[r.id]=r}else if(Object.values(A).includes(e.type)){let r=ba(e,i);return i._itemMap[r.id]=r,t.addChild(r),tt(r,i._depGraph),lt(t,r,i._depGraph),r}}function Ea(e,t){if(e.children)for(let i of e.children)Ea(i,t);else if(Object.values(A).includes(e.type)){let i=t._itemMap[e.id];e.links&&(i.links=e.links.map(e=>t._itemMap[e])),e.source&&(i.source=t._itemMap[e.source]),e.target&&(i.target=t._itemMap[e.target])}}function Aa(e,t,i){if(e.id&&(t._id=e.id),e.classId&&(t._classId=e.classId),e.dataScope&&(t._dataScope=da(e.dataScope,i)),e.bounds&&(t._bounds=ma(e.bounds)),t._sortBy=e.sortBy,e.children)for(let r of e.children)wa(r,t,i);e.layout&&(t._layout=ya(e.layout),t._layout.group=t,ut(t,t._layout,i._depGraph))}function Ca(e){let t=new Yt(e.type,e.args);return t._id=e.id,t.domain=e.domain,t.range=e.range,t}function ka(e,t){let i=Sa(e.element,e.elementType,t);i||console.warn("element not created:",e.element,e.elementType);let r=e.args?e.args:{};e.table&&(r.table=t.tables[e.table]);let s=new Fn(i,e.channel,e.attr,e.aggregator?e.aggregator:"sum",r);if(s._id=e.id,e.scales&&(s._scales=e.scales.map(e=>t.scales[e])),r.baseEnc&&(s._baseEnc=e.args.baseEnc),e.elemGroups&&(s._elemGroups=e.elemGroups.map(e=>e.map(e=>Sa(e,i.type,t)))),e.elem2scale){s._elem2scale={};for(let i in e.elem2scale)s._elem2scale[i]=t.scales[e.elem2scale[i]]}return r.startAngle&&(s.startAngle=r.startAngle),s}function Sa(e,t,i){if("vertex"===t){let t=e.split("_v_");return i._itemMap[t[0]].vertices.find(e=>e._id===parseInt(t[1]))}if("segment"===t){let t=e.split("_s_");return i._itemMap[t[0]].segments.find(e=>e._id===parseInt(t[1]))}return i._itemMap[e]}function Ta(e){let t={};return t.id=e._id,t.data=e._rawData,t.attributeTypes=e._attrTypes,t.url=e.url,t}function Ra(e){let t={};return t.dt=e._dt.id,t.attr2value=Object.assign({},e._attr2value),t}function Oa(e,t){t.vertices=[];for(let i of e.vertices)t.vertices.push(Ia(i));t.vertexCounter=e.vertexCounter,t.segmentCounter=e.segmentCounter,t.curveMode=e.curveMode}function Ia(e){let t={};return t.type=e.type,t.id=e._id,t.x=e.x,t.y=e.y,e._dataScope&&(t.dataScope=Ra(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 Na(e){return e.type===Vt.Scene?function(e){let t=Pa(e,{});t.fillColor=e.fillColor,t.scales={},t.encodings=[];for(let i in e._encodings)for(let r in e._encodings[i]){let s=e._encodings[i][r];s._forLegend||t.encodings.push(Va(s));for(let e of s._scales)e.id in t.scales||(t.scales[e.id]=La(e))}t.tables={};let i=function(e){let t={};for(let i in e._encodings)for(let r in e._encodings[i]){let s=e._encodings[i][r];s.dataTable.id in t||s._forLegend||(t[s.dataTable.id]=s.dataTable)}for(let i of e.children)if(![Vt.Axis,Vt.Legend,Vt.Gridlines].includes(i.type)){if(i.dataScope){t[i.dataScope.dataTable.id]=i.dataScope.dataTable;break}if(i.children&&i.children.length>0){let e=i.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 i)t.tables[e]=Ta(i[e]);return console.log("======== serialization ========="),console.log(t),t}(e):[Vt.Collection,Vt.Glyph,Vt.Composite].includes(e.type)?Pa(e,{}):e instanceof w?function(e){let t={args:{}};t.type=e.type,t.id=e.id,e.classId&&(t.classId=e.classId),e._dataScope&&(t.dataScope=Ra(e._dataScope)),e.bounds&&(t.bounds=e.bounds.toJSON()),e.refBounds&&(t.refBounds=e.refBounds.toJSON()),e.links&&(t.links=e.links.map(e=>e.id)),e.source&&(t.source=e.source.id),e.target&&(t.target=e.target.id);for(let i in e.styles)i.indexOf("Color")>0&&e.styles[i]instanceof j?t.args[i]=e.styles[i].toJSON():t.args[i]=e.styles[i];switch(e.type){case Vt.Arc:case Vt.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),Oa(e,t);break;case Vt.Area:!function(e,t){t.args.baseline=e._baseline,t.args.orientation=e._orientation}(e,t),Oa(e,t);break;case Vt.Circle:!function(e,t){t.args.x=e.x,t.args.y=e.y,t.args.radius=e.radius}(e,t);break;case Vt.Image:break;case Vt.Line:case Vt.Path:case Vt.BezierCurve:Oa(e,t);break;case Vt.SimpleText:!function(e,t){t.args.x=e._x,t.args.y=e._y,t.args.text=e._text,t.args.anchor=e._anchor,e._backgroundColor&&(t.args.backgroundColor=e._backgroundColor),e._borderWidth&&(t.args.borderWidth=e._borderWidth),e._borderColor&&(t.args.borderColor=e._borderColor)}(e,t);break;case Vt.Polygon:!function(e,t){t.args.x=e._x,t.args.y=e._y,t.args.radius=e._radius}(e,t),Oa(e,t);break;case Vt.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),Oa(e,t);case Vt.Ring:}return t}(e):(console.warn("unsupported serialization",e.type),{type:e.type})}function La(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 Va(e){let t={};t.id=e._id,t.element=e._elem.id,t.elementType=e._elem.type,t.channel=e._channel,t.attr=e._attribute,t.aggregator=e._aggregator,t.table=e._table.id,t.args={},t.args.includeZero=e._includeZero,t.args.flipScale=e._flipScale,t.args.mapping=e._mapping,t.args.rangeExtent=e._preferredRangeExtent,t.args.domain=e._preferredDomain,t.args.scaleType=e._scaleType,t.args.scheme=e._colorScheme,e._baseEnc&&(t.args.baseEnc=e._baseEnc.id),t.scales=e._scales.map(e=>e.id),t.elemGroups=e._elemGroups.map(e=>e.map(e=>e.id)),t.elem2scale={};for(let i in e._elem2scale)t.elem2scale[i]=e._elem2scale[i].id;return"angle"==e.channel&&(t.args.startAngle=e.startAngle),t}function Pa(e,t){if(t.id=e.id,t.type=e.type,e.classId&&(t.classId=e.classId),e._dataScope&&(t.dataScope=Ra(e._dataScope)),t.bounds=e.bounds.toJSON(),e._layout&&(t.layout=function(e){switch(e.type){case B.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.group=e.group.id,t}(e);case B.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 B.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 B.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 B.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 B.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 B.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 B.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 B.STRATA:return function(e){let t={args:{}};return t.type=e.type,t.args.direction=e._direction,t.args.gap=e._gap,t}(e);default:throw new Error("unknow layout type "+e.type)}}(e._layout)),t.children=[],e.children.length>0)for(let i of e.children)i instanceof Qt?Ma(i,t):i instanceof Wn?Da(i,t):t.children.push(Na(i));return t.sortBy=e._sortBy,t}function Ma(e,t){t.axes??=[];let i={};i.type=e._type,i.id=e._id,i.attr=e._attribute,i.channel=e._channel,i.args={},i.args.orientation=e._orientation,i.args.strokeColor=e._strokeColor,i.args.textColor=e._textColor,i.args.fontSize=e._fontSize,i.args.tickOffset=e._tickOffset,i.args.tickSize=e._tickSize,i.args.tickAnchor=e._tickAnchor,i.args.tickVisible=e._tickVisible,i.args.pathVisible=e._pathVisible,i.args.labelOffset=e._labelOffset,i.args.labelFormat=e._labelFormat,i.args.titleOffset=e._titleOffset,i.args.title=e._titleText,i.args.rotateTitle=e._rotateTitle,i.args.titleVisible=e._showTitle,i.args.labelRotation=e._labelRotation,t.axes.push(i)}function Da(e,t){t.gridlines??=[];let i={};i.type=e._type,i.id=e._id,i.attr=e._attribute,i.channel=e._channel,i.args=e._args,t.gridlines.push(i)}function Ba(e,t,i,s,n){for(let o of e){let e="background"===o.target?i:o.target;e=Array.isArray(e)?e:[e];let l="brushX"===o.event?r.brushX():"brushY"===o.event?r.brushY():r.brush();var a;l.on("start",function(t){a&&e.length>1&&r.select(a).call(l.move,null),a=this}),l.on("brush end",function(e){let t,a;if(e&&e.selection)switch(o.event){case"brushX":t=[e.selection[0],e.selection[1]],a=void 0;break;case"brushY":t=void 0,a=[e.selection[0],e.selection[1]];break;default:t=[e.selection[0][0],e.selection[1][0]],a=[e.selection[0][1],e.selection[1][1]]}else t=void 0,a=void 0;let l=o.eventContext;l.clear(),l.set("xInterval",t),l.set("yInterval",a),l.set("target",r.select(this).attr("id").replace("brush-","")),i.onChange(Te.EVT_CTX,l),s._render(i,n)});for(let i of e){let e=i.type===Vt.Axis?i.boundsWithoutTitle:i.bounds,r=[[e.left,e.top],[e.right,e.bottom]];t.append("g").attr("class","brush").attr("id","brush-"+i.id).call(l.extent(r))}}}function Ga(e,t,i,s,n){for(let a of e){let e="background"===a.target?t:t.select("#"+a.target.id),o=r.drag();o.on("drag",e=>{let[r,o]=_(t.attr("id"),e.sourceEvent.clientX,e.sourceEvent.clientY),l=a.eventContext;l.set("x",r),l.set("y",o),l.set("dx",e.dx),l.set("dy",e.dy),i.onChange(Te.EVT_CTX,l),s._render(i,n)}),e.call(o)}}function Fa(e,t,i,r,s){for(let n of e){let e="background"===n.target?t:n.target.classId?t.selectAll("."+n.target.classId):t.select("#"+n.target.id);e.on("mouseover",e=>{let[a,o]=_(t.attr("id"),e.clientX,e.clientY),l=n.eventContext;l.set("x",a),l.set("y",o);let h=e.target.__data__;l.set("elements",[h]),l.set("element",h),i.onChange(Te.EVT_CTX,l),r._render(i,s)}),e.on("mouseout",e=>{let t=n.eventContext;t.set("elements",[]),t.set("element",void 0),i.onChange(Te.EVT_CTX,t),r._render(i,s)})}}function za(e,t,i,s,n){for(let t of e)if(t.isWidgetDriven()){let e=(Array.isArray(t.target)?t.target:[t.target]).map(e=>document.getElementById(e)),r=t.eventContext;for(let a of e)a.addEventListener(t.event,function(){r.set("inputValue",a.value),"checkbox"===a.type&&r.set("checked",a.checked),i.onChange(Te.EVT_CTX,r),s._render(i,n)})}else t.isKeyboardDriven()&&r.select("body").on("keydown",e=>{e.key===t.key&&Wa(t,i,s,n)})}function ja(e,t,i,r,s){t.on("wheel",n=>{for(let r of e){n.preventDefault(),n.stopPropagation();let[e,s]=_(t.attr("id"),n.clientX,n.clientY),a=r.eventContext;a.set("deltaX",n.deltaX),a.set("deltaY",n.deltaY),a.set("x",e),a.set("y",s),i.onChange(Te.EVT_CTX,a)}r._render(i,s)})}function Wa(e,t,i,r){if(Array.isArray(e.callback))for(let s=0;s<e.callback.length;s++)e.callback[s](),i._render(t,r,e.animation[s]);else e.callback(),i._render(t,r,e.animation)}function Ua(e,t,i,r,s){t.on("click",n=>{for(let r of e){let[e,s]=_(t.attr("id"),n.clientX,n.clientY),a=r.eventContext,o=[];r.target.type&&o.push({property:"type",value:r.target.type}),r.target.classId&&o.push({property:"classId",value:r.target.classId});let l=elementHitTest(i,e,s,o),h=a.get("elements").slice();l?r.isCumulative&&!a.get("elements").includes(l)?h.push(l):h=[l]:h=[],h.length===a.get("elements").length&&h.every((e,t)=>e===a.get("elements")[t])||(a.clear(),a.set("x",e),a.set("y",s),a.set("elements",h),a.set("element",h.length>0?h[h.length-1]:void 0),i.onChange(Te.EVT_CTX,a))}r._render(i,s)})}function Ha(e){return e.id+"-bg"}function Ya(e){return e.id+"-path"}function Xa(e){switch(e){case v.TOP:return"text-before-edge";case v.BOTTOM:return"auto";case v.LEFT:return"start";case v.RIGHT:return"end";case v.CENTER:case v.MIDDLE:return"middle";default:return e}}class qa{constructor(e){this._svgId=e,this._svg=document.getElementById(this._svgId),this._compMap={},this._decoMap={},this._brushCreated=0,this._lastTriggerEvt=void 0}render(e,t){this._compMap={},this._decoMap={},this._brushCreated=0;let i=t||{};if(!this._svg.querySelector("defs")){const e=document.createElementNS("http://www.w3.org/2000/svg","defs");this._svg.appendChild(e)}this._render(e,i),this._registerEvents(e,i)}_render(e,t,i){for(let e in this._decoMap)this._decoMap[e].remove(),delete this._decoMap[e];this._removed={};for(let e in this._compMap)this._removed[e]=1;this._renderItem(e,t,i);for(let e in this._removed)this._compMap[e].remove(),delete this._compMap[e]}_registerEvents(e,t){let i=r.select("#"+this._svgId);for(let r in e.interactionTriggers){let s=Object.values(e.interactionTriggers[r]);switch(r){case"click":i.on("click",null),Ua(s,i,e,this,t);break;case"brush":case"brushX":case"brushY":Ba(s,i,e,this,t);break;case"drag":case"dragX":case"dragY":Ga(s,i,e,this,t);break;case"hover":Fa(s,i,e,this,t);break;case"change":case"input":za(s,0,e,this,t);break;case"scroll":ja(s,i,e,this,t)}}}clear(){for(;this._svg.firstChild;)this._svg.firstChild.remove();const e=this._svg.cloneNode(!0);this._svg.parentNode.replaceChild(e,this._svg),this._svg=e,this._compMap={},this._decoMap={}}_renderItem(e,t,i){if(this._configSVG(e),!e.children&&!1===e._dirty)return;let r=this._compMap[e.id];if(i){const e=i.delay||0,t=i.duration||0;r.style.transition=`all ${t}ms ease ${e}ms`}switch(e.type){case Vt.Scene:!function(e,t){t.style.background=e.fillColor?e.fillColor:"#fff"}(e,this._svg);break;case Vt.Circle:!function(e,t){t.setAttribute("cx",e.x),t.setAttribute("cy",e.y),t.setAttribute("r",e.radius)}(e,r);break;case Vt.Rect:!function(e,t){let i=e.bounds;t.setAttribute("x",i.left),t.setAttribute("y",i.top),t.setAttribute("width",i.width),t.setAttribute("height",i.height)}(e,r);break;case Vt.Path:case Vt.BezierCurve:case Vt.BundledPath:case Vt.Chord:case Vt.Polygon:case Vt.Link:case Vt.Pie:case Vt.Line:case Vt.Area:case Vt.Ring:case Vt.Arc:case Vt.Gridlines:!function(e,t){t.setAttribute("d",e.getSVGPathData()),e.closed||(t.style.fill="none"),(e.id.includes("axis")||e.id.includes("gridlines"))&&(t.style.shapeRendering="crispEdges"),e.type===Vt.BundledPath&&(t.style.mixBlendMode="multiply")}(e,r);break;case Vt.SimpleText:!function(e,t,i){if(t.setAttribute("text-anchor",Xa(e.anchor[0])),t.setAttribute("alignment-baseline",Xa(e.anchor[1])),t.setAttribute("dominant-baseline",Xa(e.anchor[1])),t.setAttribute("x",e.x),t.setAttribute("y",e.y),i){e._updateBounds();let t=e.bounds;i.setAttribute("x",t.left-5),i.setAttribute("y",t.top-5),i.setAttribute("width",t.width+10),i.setAttribute("height",t.height+10),i.setAttribute("rx",5),i.setAttribute("ry",5),i.style.fill=e.backgroundColor,i.style.stroke=e.borderColor,i.style.strokeWidth=e.borderWidth}if(e.textPath){let i=t.querySelector("textPath");i||(i=document.createElementNS("http://www.w3.org/2000/svg","textPath"),t.appendChild(i)),i.setAttribute("href","#"+Ya(e)),i.setAttribute("startOffset",e.textPathOffset),i.textContent=e.text}else t.textContent=e.text}(e,r,this._compMap[Ha(e)]);break;case Vt.RichText:!function(e,t){for(;t.firstChild;)t.firstChild.remove();t.setAttribute("width",e.width),t.setAttribute("x",e.x),t.setAttribute("y",e.y),t.style.border="1px solid #ddd";let i=document.createElementNS("http://www.w3.org/1999/xhtml","div");i.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),i.style.width="100%",i.style.padding="10px",i.style.backgroundColor="rgba(255, 255, 255, 0.85)",i.style.color="black",i.style.visibility="visible",i.style.boxSizing="border-box",i.style.opacity="1",i.innerHTML=e.text,t.appendChild(i),t.setAttribute("height",i.offsetHeight)}(e,r);break;case Vt.Image:!function(e,t){t.setAttribute("href",e.src),t.setAttribute("x",e.x),t.setAttribute("y",e.y),t.setAttribute("width",e.width),t.setAttribute("height",e.height)}(e,r)}if(e._rotate&&r.setAttribute("transform","rotate("+e._rotate.join(" ")+")"),function(e,t,i){if(!e.styles)return;let r=Object.keys(e.styles);e.type===Vt.RichText&&(r=r.filter(e=>["textAnchor","fillColor"].indexOf(e)<0));for(let s of r)if(void 0!==e.styles[s])if(s.indexOf("Color")>0&&e.styles[s].type==Vt.LinearGradient){const r=i.querySelector("defs"),n=e.styles[s];if(!r.querySelector("#"+n.id)){const e=document.createElementNS("http://www.w3.org/2000/svg","linearGradient");e.setAttribute("id",n.id),e.setAttribute("x1",n.x1+"%"),e.setAttribute("x2",n.x2+"%"),e.setAttribute("y1",n.y1+"%"),e.setAttribute("y2",n.y2+"%");for(let t of n.stops){const i=document.createElementNS("http://www.w3.org/2000/svg","stop");i.setAttribute("offset",t.offset+"%"),i.style.stopColor=t.color,i.style.stopOpacity=t.opacity,e.appendChild(i)}r.appendChild(e)}t.style[f[s]]="url(#"+n.id+")"}else if(t.style[f[s]]=e.styles[s],"visibility"===s)if(e.type===Vt.SimpleText){if(e.hasBackground()){const t=i.querySelector("#"+Ha(e));t&&(t.style[f[s]]=e.styles[s])}}else if(e.type===Vt.RichText){const i=t.querySelector("div");i&&(i.style.visibility=e.styles[s])}}(e,r,this._svg),e.vertices&&e.vertices.length>0&&e.vertices.map(e=>e.shape).filter(e=>void 0!==e).length>0&&this._renderVertices(e),t&&t.bounds?this._renderBounds(e):E(e)&&t&&t.refBounds&&this._renderRefBounds(e),e.clipMask){const t=this._svg.querySelector("defs");let i=t.querySelector("#"+e.id+"-clipPath");i||(i=document.createElementNS("http://www.w3.org/2000/svg","clipPath"),i.setAttribute("id",e.id+"-clipPath"),t.appendChild(i));let s=i.querySelector("rect");s||(s=document.createElementNS("http://www.w3.org/2000/svg","rect"),i.appendChild(s)),s.setAttribute("x",e.clipMask.left),s.setAttribute("y",e.clipMask.top),s.setAttribute("width",e.clipMask.width),s.setAttribute("height",e.clipMask.height),r.setAttribute("clip-path","url(#"+e.id+"-clipPath)")}if(e.children)for(let r of e.children)this._renderItem(r,t,i);else e._dirty=!1}_configSVG(e){if(e.id in this._compMap)delete this._removed[e.id],e.type===Vt.SimpleText&&(e.hasBackground()&&delete this._removed[Ha(e)],e.textPath&&delete this._removed[Ya(e)]);else{let t,i=e.parent;if(t=i&&i.id&&i.id in this._compMap?this._svg.querySelector("#"+i.id):this._svg,e.type===Vt.SimpleText){if(e.hasBackground()){const i=document.createElementNS("http://www.w3.org/2000/svg","rect");i.setAttribute("id",Ha(e)),t.appendChild(i),this._compMap[Ha(e)]=i}if(e.textPath){const t=this._svg.querySelector("defs"),i=Ya(e);let r=t.querySelector("#"+i);r||(r=document.createElementNS("http://www.w3.org/2000/svg","path"),r.setAttribute("id",i),t.appendChild(r),this._compMap[i]=r),r.setAttribute("d",e.textPath),r.style.fill="none"}}const r=document.createElementNS("http://www.w3.org/2000/svg",this._getSVGElementType(e));t?t.appendChild(r):console.warn("Parent element not found for ",e),this._compMap[e.id]=r}if(e.type==Vt.Gridlines){const t=this._compMap[e.id].parentNode;t.insertBefore(this._compMap[e.id],t.firstChild)}this._compMap[e.id].setAttribute("id",e.id),this._compMap[e.id].__data__=e;let t=e.type;e.classId&&(t+=" "+e.classId),e.parent&&e.parent.type===Vt.Axis&&(t+=e.id.endsWith("_ticks")?" axis_ticks":e.id.endsWith("_labels")?" axis_labels":""),this._compMap[e.id].setAttribute("class",t)}_renderBounds(e){let t=e.bounds;if(e.layout&&"grid"==e.layout.type&&this._renderLayout(e),!(e.id in this._decoMap)){const t=document.createElementNS("http://www.w3.org/2000/svg","rect");t.setAttribute("class","deco"),this._svg.appendChild(t),this._decoMap[e.id]=t}const i=this._decoMap[e.id];i.setAttribute("x",t.left),i.setAttribute("y",t.top),i.setAttribute("width",t.width),i.setAttribute("height",t.height),i.setAttribute("fill","none"),i.setAttribute("stroke","blue"),i.setAttribute("stroke-width","1px"),i.setAttribute("stroke-dasharray","5,5")}_renderRefBounds(e){let t=e.refBounds;if(t){if(!(e.id in this._decoMap)){const t=document.createElementNS("http://www.w3.org/2000/svg","rect");t.setAttribute("class","deco"),this._svg.appendChild(t),this._decoMap[e.id]=t}const i=this._decoMap[e.id];i.setAttribute("x",t.left),i.setAttribute("y",t.top),i.setAttribute("width",t.width),i.setAttribute("height",t.height),i.setAttribute("fill","none"),i.setAttribute("stroke","blue"),i.setAttribute("stroke-width","1px"),i.setAttribute("stroke-dasharray","5,5")}}_renderVertices(e){let t=e.id+"-vertices";if(t in this._compMap)delete this._removed[t];else{let i=e.parent,r=i?i.id:this._svgId;const s=this._svg.querySelector("#"+r),n=document.createElementNS("http://www.w3.org/2000/svg","g");n.setAttribute("id",t),s.appendChild(n),this._compMap[t]=n}if(0===e.vertices.map(e=>e.shape).filter(e=>void 0!==e).length)return void(this._compMap[t].style.visibility="hidden");this._compMap[t].style.visibility="visible";let i=e.vertices.filter(e=>void 0!==e.shape);for(let e of i){let i=t+"-"+e.id;if(i in this._compMap)if(e.shape!==this._compMap[i].tagName){this._compMap[i].remove();const r=document.createElementNS("http://www.w3.org/2000/svg",e.shape);r.setAttribute("id",i),this._compMap[t].appendChild(r),this._compMap[i]=r,delete this._removed[i]}else delete this._removed[i];else{const r=document.createElementNS("http://www.w3.org/2000/svg",e.shape);r.setAttribute("id",i),this._compMap[t].appendChild(r),this._compMap[i]=r}const r=this._compMap[i];"rect"==e.shape?(r.setAttribute("x",e.x-e.width/2),r.setAttribute("y",e.y-e.height/2),r.setAttribute("width",e.width),r.setAttribute("height",e.height)):"circle"==e.shape&&(r.setAttribute("cx",e.x),r.setAttribute("cy",e.y),r.setAttribute("r",e.radius)),r.style.fill=e.fillColor,r.style.opacity=e.opacity,r.style.strokeWidth=e.strokeWidth,r.style.stroke=e.strokeColor}}_renderLayout(e){let t=e.id+"-grid";if(!(t in this._decoMap)){const e=document.createElementNS("http://www.w3.org/2000/svg","g");e.setAttribute("id",t),e.setAttribute("class","deco"),this._svg.appendChild(e),this._decoMap[t]=e}let i=e.layout.cellBounds;e.layout.rowGap;this._decoMap[t].querySelectorAll("rect").forEach(e=>e.remove());for(let e of i){const i=document.createElementNS("http://www.w3.org/2000/svg","rect");i.setAttribute("x",e.left),i.setAttribute("y",e.top),i.setAttribute("width",e.width),i.setAttribute("height",e.height),i.setAttribute("stroke","blue"),i.setAttribute("stroke-width","1px"),i.setAttribute("stroke-dasharray","5,5"),i.setAttribute("fill","none"),this._decoMap[t].appendChild(i)}}_getSVGElementType(e){switch(e.type){case Vt.Rect:return"rect";case Vt.Collection:case Vt.Group:case Vt.Glyph:case Vt.Scene:case Vt.Axis:case Vt.Legend:case Vt.Composite:return"g";case Vt.Area:case Vt.Path:case Vt.Polygon:case Vt.Ring:case Vt.Pie:case Vt.Arc:case Vt.BezierCurve:case Vt.BundledPath:case Vt.Chord:case Vt.Line:case Vt.Gridlines:return"path";case Vt.Circle:return"circle";case Vt.SimpleText:return"text";case Vt.RichText:return"foreignObject";case"vertex":if("circle"==e.shape)return"circle";if("rect"==e.shape)return"rect";throw"argument exception";case"image":return"image"}}}function Ka(e,t){return void 0===e&&void 0===t||void 0!==e&&void 0!==t}function Za(e,t){const i=Object.keys(e),r=Object.keys(t);return i.length===r.length&&(0===i.length||i.every(e=>r.includes(e)))}function $a(e,t){if(!Ka(e.layout,t.layout))return console.log("Not both defined or undefined:",e.bounds,t.bounds),!1;let i=e.layout,r=t.layout;if(!i&&!r)return!0;if(i.type!==r.type)return console.log("layout types are different:",i,r),!1;switch(i.type){case B.GRID:return function(e,t){e._cellBounds.length!==t._cellBounds.length&&console.log("cell bounds length different:",e,t);for(let i=0;i<e._cellBounds;i++)if(!Qa(e._cellBounds[i],t._cellBounds[i]))return console.log("cell bounds not equal:",e,t),!1;for(let i=0;i<e._grid.length;i++)for(let r=0;r<e._grid[i].length;r++)if(e._grid[i][r]!==t._grid[i][r])return console.log("grid not equal",e,t),!1;return e._numCols===t._numCols&&e._numRows===t._numRows&&e._start===t._start&&e._direction===t._direction&&e._rowGap===t._rowGap&&e._colGap===t._colGap&&e._cellHorzAlignment===t._cellHorzAlignment&&e._cellVertAlignment===t._cellVertAlignment&&e._left===t._left&&e._top===t._top}(i,r);case B.STACK:return function(e,t){return e._orientation===t._orientation&&e._direction===t._direction&&e._left===t._left&&e._top===t._top&&e._horzCellAlignment===t._horzCellAlignment&&e._vertCellAlignment===t._vertCellAlignment&&e._gap===t._gap}(i,r);case B.PACKING:return function(e,t){return e._x===t._x&&e._y===t._y&&e._width===t._width&&e._height===t._height}(i,r);case B.FORCE:return function(e,t){return e._x===t._x&&e._y===t._y&&e._iterations===t._iterations&&e._repulsion===t._repulsion&&e._attraction===t._attraction&&e._linkDistance===t._linkDistance}(i,r);case B.DIRECTED:return function(e,t){return e._width===t._width&&e._height===t._height&&e._top===t._top&&e._left===t._left&&e._edgeSep===t._edgeSep&&e._spreadLinks===t._spreadLinks&&e._direction===t._direction}(i,r);case B.TIDYTREE:return function(e,t){return e._width===t._width&&e._height===t._height&&e._top===t._top&&e._left===t._left&&e._orientation===t._orientation}(i,r);case B.STRATA:return function(e,t){return e._direction===t._direction&&e._gap===t._gap}(i,r);case B.TREEMAP:return function(e,t){return e._width===t._width&&e._height===t._height&&e._top===t._top&&e._left===t._left}(i,r);default:return!1}}function Ja(e,t){if(!Ka(e.bounds,t.bounds))return console.log("Not both defined or undefined:",e.bounds,t.bounds),!1;let i=e.bounds,r=t.bounds;return!i&&!r||Qa(i,r)}function Qa(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function eo(e,t){if(!Ka(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(!io(e,t))return console.log("DataScopes not equal",e,t),!1;if(!Ja(e,t))return console.log("Bounds not equal",e,t),!1;if(!Ka(e.links,t.links))return console.log("Not both defined or undefined: links ",e.links,t.links),!1;if(!Ka(e.source,t.source))return console.log("Not both defined or undefined: source ",e.source,t.source),!1;if(!Ka(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&&!eo(e.source,t.source))return console.log("different sources",e.source,t.source),!1;if(e.target&&t.target&&!eo(e.target,t.target))return console.log("different targets",e.target,t.target),!1;switch(e.type){case Vt.Arc:case Vt.Pie:return to(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 Vt.Area:return to(e,t)?e.baseline===t.baseline&&e.orientation===t.orientation:(console.log("vertices not equal:",e,t),!1);case Vt.Circle:return e.x===t.x&&e.y===t.y&&e.radius===t.radius;case Vt.Image:return console.warn("not implemented"),!0;case Vt.Line:case Vt.Path:case Vt.BezierCurve:return!!to(e,t)||(console.log("vertices not equal:",e,t),!1);case Vt.SimpleText:return e.x===t.x&&e.y===t.y&&e.text===t.text&&e.anchor[0]===t.anchor[0]&&e.anchor[1]===t.anchor[1];case Vt.Polygon:return to(e,t)?e.x===t.x&&e.y===t.y&&e.radius===t.radius:(console.log("vertices not equal:",e,t),!1);case Vt.Rect:return to(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 Vt.Ring:default:return console.warn("not implemented"),!0}}function to(e,t){if(e.vertices.length!==t.vertices.length)return console.log("unequal number of vertices:",e,t),!1;for(let i=0;i<e.vertices.length;i++){let r=e.vertices[i],s=t.vertices[i];return r.id!==s.id?(console.log("vertex id not equal:",r,s),!1):r.x!==s.x||r.y!==s.y?(console.log("vertex position not equal:",r,s),!1):io(r,s)?r._polarAngle===s._polarAngle&&r.shape===s.shape&&r.width===s.width&&r.height==s.height&&r.radius==s.radius&&r.fillColor==s.fillColor&&r.opacity==s.opacity&&r.strokeWidth==s.strokeWidth&&r.strokeColor==s.strokeColor:(console.log("vertex data scopes not equal:",r.dataScope,s.dataScope),!1)}}function io(e,t){if(!Ka(e.dataScope,t.dataScope))return console.log("Not both defined or undefined:",e.dataScope,t.dataScope),!1;if(!e.dataScope&&!t.dataScope)return!0;let i=e.dataScope,r=t.dataScope;if(!Za(i._attr2value,r._attr2value))return!1;for(let e in i._attr2value)if(i._attr2value[e]!==r._attr2value[e])return!1;return i._dt.id===r._dt.id&&i._tuples.length===r._tuples.length}function ro(e,t){return e.type!==t.type&&console.log("Different types:",e.type,t.type),[Vt.Collection,Vt.Glyph,Vt.Composite].includes(e.type)?so(e,t):e instanceof w?eo(e,t):void 0}function so(e,t){let i=e.children.filter(e=>!Object.values(Pt).includes(e.type)),r=t.children.filter(e=>!Object.values(Pt).includes(e.type));if(i.length!==r.length)return console.log("children length not equal:",i,r),!1;if(e.id!==t.id)return console.log("id not equal:",e,t),!1;if(e.classId!==t.classId)return console.log("class id not equal:",e,t),!1;if(!io(e,t))return console.log("DataScopes not equal",e.dataScope,t.dataScope),!1;if(!Ja(e,t))return console.log("Bounds not equal",e,t),!1;if(!$a(e,t))return console.log("Layouts not equal",e,t),!1;if(!function(e,t){if(!Za(e,t))return console.log("different keys",e,t),!1;for(let i in e)if(e[i]!==t[i])return!1;return!0}(e._sortBy,t._sortBy))return console.log("SortBy not equal",e,t),!1;for(let e=0;e<i.length;e++)if(!ro(i[e],r[e]))return console.log("Not equal",i[e],r[e]),!1;return!0}class no extends D{constructor(e){super(),this.type=B.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 no({x:this._x,y:this._y,radius:this._radius})}}class ao extends D{constructor(e){super(),this.type=B.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:H,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 ao({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 oo(e,t,i){if(!e.bounds.contains(t,i))return!1;switch(e.type){case ElementType.Path:case ElementType.Arc:case ElementType.BezierCurve:case ElementType.Line:{let r=CanvasProvider.getContext(),s=CanvasProvider.getPath2D(e.getSVGPathData());return r.lineWidth=Math.max(e.strokeWidth,2.5),r.stroke(s),e.closed?r.isPointInPath(s,t,i):r.isPointInStroke(s,t,i)}case ElementType.Circle:{let r=e.x,s=e.y;if(e.rotation){let t=u(r,s,e.rotation[1],e.rotation[2],e.rotation[0]);r=t.x,s=t.y}return Math.sqrt(Math.pow(t-r,2)+Math.pow(i-s,2))<=e.radius+e.strokeWidth}case ElementType.Collection:if([ElementType.Arc,ElementType.Pie,ElementType.Polygon,ElementType.Area].indexOf(e.firstChild.type)>=0){let r=e.getSVGPathData();if(""!==r){let s=CanvasProvider.getContext(),n=CanvasProvider.getPath2D(r);return s.lineWidth=Math.max(e.firstChild.strokeWidth,2.5),s.stroke(n),s.isPointInPath(n,t,i)}}return e.bounds.contains(t,i);default:return e.bounds.contains(t,i)}}e.canClassify=function(e){return e.type===Vt.Collection&&!(e.children.length<2)},e.canDensify=ke,e.canDivide=Yn,e.canRepeat=Bn,e.csv=async function(e){return async function(e){let t=await Ft("GET",e),i=r.csvParse(t.trim(),r.autoType);return new Dt(i,e)}(e)},e.csvString=function(e){return function(e){let t=r.csvParse(e.trim(),r.autoType);return new Dt(t,"fromString")}(e)},e.deserialize=function(e){return va(e)},e.elementHitTest=function(e,t,i,r){let s=T(e,r);for(let e of s)if(oo(e,t,i))return e},e.elementHitTestByRect=function(e,t,i){let r=T(e,i);for(let e of r)if(e.bounds.intersects(t))return e},e.findElements=T,e.getLeafMarks=V,e.getPeers=C,e.graphJSON=async function(e){return async function(e){let t=await Ft("GET",e);return new fe(JSON.parse(t),e)}(e)},e.isEqual=function(e,t){return function(e,t){return e.fillColor!==t.fillColor?(console.log("fillColor not equal:",e,t),!1):so(e,t)}(e,t)},e.isMark=E,e.isRefElement=function(e){return e.type===Vt.Axis||e.type===Vt.Legend||e.type===Vt.Gridlines},e.layout=function(e,t){let i=t||{};switch(e.toLowerCase()){case B.STACK:return new Un(i);case B.PACKING:return new _a(i);case B.FORCE:return new pa(i);case B.DIRECTED:return new ua(i);case B.TIDYTREE:return new fa(i);case B.TREEMAP:return new ga(i);case B.CIRCULAR:return new no(i);case B.CLUSTER:return new ao(i);case B.GRID:default:return new Jn(i)}},e.markPrimitiveHitTest=function(e,t,i,r){let s,n=V(e),a=r||2,o=CanvasProvider.getContext();for(let e of n){if(!(e instanceof Path))continue;let r=CanvasProvider.getPath2D(e.getSVGPathData());if(o.lineWidth=Math.max(e.strokeWidth,2*a),o.stroke(r),o.isPointInStroke(r,t,i)){s=e;break}}if(!s)return null;let l=[];for(let e of s.vertices){let t=Math.max(a,e.width,2*e.radius),i=Math.max(a,e.height,2*e.radius);l.push({i:e,b:new g(e.x-t/2,e.y-i/2,t,i)})}for(let e of l)if(e.b.contains(t,i))return e.i;if(s.segments&&s.segments.length>0)for(let e of s.segments){let r=CanvasProvider.getPath2D();if(r.moveTo(e.vertex1.x,e.vertex1.y),r.lineTo(e.vertex2.x,e.vertex2.y),o.lineWidth=Math.max(s.strokeWidth,a),o.stroke(r),o.isPointInStroke(r,t,i))return e}return null},e.markPrimitiveHitTestByRect=function e(t,i,r){let s=r||2;if(E(t)){let e=[];for(let i of t.vertices){let t=Math.max(s,i.width,2*i.radius),r=Math.max(s,i.height,2*i.radius);e.push({i:i,b:new g(i.x-t/2,i.y-r/2,t,r)})}if(t.type===ItemType.Rect)for(let i of t.segments){let r=Math.max(t.strokeWidth,s);"v"===(i.vertex1.x===i.vertex2.x?"v":"h")?e.push({i:i,b:new g(i.vertex1.x-r/2,Math.min(i.vertex1.y,i.vertex2.y)-r/2,r,Math.abs(i.vertex1.y-i.vertex2.y))}):e.push({i:i,b:new g(Math.min(i.vertex1.x,i.vertex2.x)-r/2,i.vertex1.y-r/2,Math.abs(i.vertex1.x-i.vertex2.x),r)})}for(let t of e)if(t.b.intersects(i))return t.i;return null}if(!isGuide(t)&&t.children&&t.children.length>0){for(let r of t.children)if(r.bounds.intersects(i)){let t=e(r,i,s);if(t)return t}return null}return null},e.renderer=function(e,t){return new qa(t)},e.scene=function(e){return new ca(e)},e.serialize=function(e){return Na(e)},e.table=function(e){return new Dt(e,"")},e.treeJSON=async function(e){return async function(e){let t=await Ft("GET",e);return new pe(JSON.parse(t),e)}(e)}});
|
|
1
|
+
/* version: 3.3.2 */
|
|
2
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("d3")):"function"==typeof define&&define.amd?define(["exports","d3"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).msc={},e.d3)}(this,function(e,t){"use strict";function i(e){var t=Object.create(null);return e&&Object.keys(e).forEach(function(i){if("default"!==i){var r=Object.getOwnPropertyDescriptor(e,i);Object.defineProperty(t,i,r.get?r:{enumerable:!0,get:function(){return e[i]}})}}),t.default=e,Object.freeze(t)}var r=i(t);class s{constructor(e,t,i){this._id="predicate_"+Mt(),this._type=e||n.POINT,this._variableType=t,this._variableName=i,this._value=void 0}get type(){return this._type}get value(){return this._value}set value(e){this._value=e}get id(){return this._id}get variableType(){return this._variableType}get variableName(){return this._variableName}}const n=Object.freeze({POINT:"point",INTERVAL:"interval",LIST:"list"});class a extends s{constructor(e,t,i){super(e,t,i)}testElement(e){let t;if("attribute"==this._variableType){if(!e.dataScope)return!1;t=e.dataScope.getAttrVal(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 o extends s{constructor(e,t,i){super(e,t,i)}addValue(e){this._value||(this._value=[]),this._value.push(e)}resetValue(){this._value=void 0}testElement(e){if("attribute"==this._variableType){if(!e.dataScope)return!1;let t=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 l extends s{constructor(e,t,i){super(e,t,i)}testElement(e){if("attribute"==this._variableType){if(!e.dataScope)return!1;return e.dataScope.getAttrVal(this._variableName)==this._value}return e[this._variableName]==this._value}testTuple(e){if("attribute"==this._variableType){let t=e[this._variableName];return this._value===t}return!1}equals(e){return this.type===e.type&&this.variableName===e.variableName&&this.value===e.value}}function h(e){let t,i="attribute"in e?"attribute":"property",r=e[i];switch(e.type){case n.LIST:t=new o(e.type,i,r);break;case n.INTERVAL:t=new a(e.type,i,r);break;case n.POINT:default:t=new l(e.type,i,r)}return t.value=e.value,t}function c(e,t){for(let i of t)if(!i.testElement(e))return!1;return!0}const d={svg:void 0,getSVG:function(){return window?(void 0===this.svg&&(this.svg=document.createElementNS("http://www.w3.org/2000/svg","svg"),this.svg.style.visibility="hidden",this.svg.style.pointerEvents="none",this.svg.setAttribute("aria-hidden","true"),document.body.appendChild(this.svg)),this.svg):null}};function u(e,t,i,r,s){const n=s*Math.PI/180,a=e-i,o=t-r;return{x:a*Math.cos(n)-o*Math.sin(n)+i,y:a*Math.sin(n)+o*Math.cos(n)+r}}function _(e,t,i,r){return Math.sqrt(Math.pow(e-i,2)+Math.pow(t-r,2))}function p(e,t,i){const r=document.getElementById(e),s=r.createSVGPoint();s.x=t,s.y=i;const n=s.matrixTransform(r.getScreenCTM().inverse());return[n.x,n.y]}const f=Object.freeze({fillColor:"fill",strokeColor:"stroke",strokeWidth:"stroke-width",fillOpacity:"fill-opacity",strokeOpacity:"stroke-opacity",strokeDash:"stroke-dasharray",opacity:"opacity",fontSize:"font-size",fontFamily:"font-family",fontWeight:"font-weight",visibility:"visibility",cursor:"cursor"});class g{constructor(e,t,i,r){this._x=e+i/2,this._y=t+r/2,this._width=i,this._height=r}translate(e,t){this._x+=e,this._y+=t}toJSON(){let e={};return e.x=this._x,e.y=this._y,e.width=this._width,e.height=this._height,e}union(e){let t=Math.min(this.left,e.left),i=Math.min(this.top,e.top),r=Math.max(this.right,e.right),s=Math.max(this.bottom,e.bottom);return new g(t,i,r-t,s-i)}clone(){return new g(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 v.RIGHT:this._x=this.right-e/2;break;case v.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 v.TOP:this._y=this.top+e/2;break;case v.MIDDLE:this._height=2*e;break;default:this._y=this.bottom-e/2}this._height=e}contains(e,t){return this.left<=e&&this.right>=e&&this.top<=t&&this.bottom>=t}intersects(e){return!(this.right<e.left||this.bottom<e.top||this.left>e.right||this.top>e.bottom)}}function y(e){let t=e[0].clone();for(let i=1;i<e.length;i++)t=t.union(e[i]);return t}function m(e){return y(("vertex"==e[0].type||"segment"==e[0].type?e.map(e=>e.parent):e).map(e=>e.refBounds?e.refBounds:e.bounds))}function b(e){return y(("vertex"==e[0].type||"segment"==e[0].type?e.map(e=>e.parent):e).map(e=>e.bounds))}function x(e){let t=C(e);for(let e of t)e._updateBounds();let i=[];for(let e of t)e.parent&&!i.includes(e.parent)&&i.push(e.parent);for(let e of i)x(e)}const v=Object.freeze({TOP:"top",LEFT:"left",RIGHT:"right",BOTTOM:"bottom",CENTER:"center",MIDDLE:"middle"});class w{constructor(e){if(this._dataScope=void 0,this._type="type"in e?e.type:Vt.Mark,this._id=e.id?e.id:this._type+"_"+Mt(),this._classId=void 0,this._bounds=void 0,this._rotate=void 0,this._refBounds=void 0,this._dirty=!0,this._clipMask=void 0,this._cursor=void 0,this._styles={},void 0!==e)for(let t in f)t in e&&(this.styles[t]=e[t])}get scene(){return N(this)}set strokeColor(e){this.styles.strokeColor=e,this._dirty=!0}get strokeColor(){return this.styles.strokeColor}set strokeWidth(e){this.styles.strokeWidth=e,this._dirty=!0}get strokeWidth(){return this.styles.strokeWidth}set strokeDash(e){this.styles.strokeDash=e,this._dirty=!0}get strokeDash(){return this.styles.strokeDash}set fillColor(e){this.styles.fillColor=e,this._dirty=!0}get fillColor(){return this.styles.fillColor}get rotation(){return this._rotate}get cursor(){return this._cursor}get id(){return this._id}set id(e){this.getScene()?(delete this.getScene()._itemMap[this._id],this._id=e,this.getScene()._itemMap[e]=this):this._id=e}get classId(){return this._classId?this._classId:this._id}set classId(e){this._classId=e}get type(){return this._type}get bounds(){return this._bounds||this._updateBounds(),this._bounds}get refBounds(){return this._refBounds?this._refBounds:this.bounds}set dataScope(e){this._dataScope=e}get dataScope(){return this._dataScope}get styles(){return this._styles}set styles(e){this._styles=e,this._dirty=!0}set visibility(e){this.styles.visibility=e,this._dirty=!0}get visibility(){return this.styles.visibility?this.styles.visibility:"visible"}get opacity(){return"opacity"in this.styles?this.styles.opacity:1}set opacity(e){this.styles.opacity=e,this._dirty=!0}copyPropertiesTo(e){e.styles=Object.assign({},this.styles),this._dataScope&&(e._dataScope=this._dataScope.clone())}createClipMask(){let e=this._bounds;this._clipMask=new g(e.left,e.top,e.width,e.height)}get clipMask(){return this._clipMask}}function E(e){return e instanceof w&&e.type!==Vt.Gridlines}const A=Object.freeze({Area:"area",Rect:"rect",Ellipse:"ellipse",Circle:"circle",Pie:"pie",Ring:"ring",Arc:"arc",Line:"line",Path:"path",Image:"image",SimpleText:"text",RichText:"richText",Polygon:"polygon",BezierCurve:"bezierCurve"});function C(e,t){let i=N(e);if("vertex"===e.type||"segment"===e.type)return function(e,t){let i=N(e),r=t||i;if("vertex"===e.type){return k(e,T(r,[{property:"classId",value:e.parent.classId}]))}if("segment"===e.type){return S(e,T(r,[{property:"classId",value:e.parent.classId}]))}return e.classId?T(r,[{property:"classId",value:e.classId}]):[e]}(e,t);if(!e.classId)return[e];if(e.classId&&i._peerIndex.has(e.classId)){let r=i._peerIndex.get(e.classId);return t?r.filter(e=>function(e,t){let i=e.parent;for(;i;){if(i===t)return!0;i=i.parent}return!1}(e,t)):r}return[e]}function k(e,t){if(!e.classId){if(e.dataScope){let i=e.parent;if(!i)throw new Error("vertex has no parent mark");let r=[];if(i.type===Vt.Area){let s=i.vertices.indexOf(e)<i.vertices.length/2;for(let e of t){let t=s?e.vertices.slice(0,e.vertices.length/2):e.vertices.slice(e.vertices.length/2);r=r.concat(t.filter(e=>e.dataScope))}}else for(let e of t)r=r.concat(e.vertices.filter(e=>e.dataScope));return r}{let i=e.parent;if(!i)throw new Error("vertex has no parent mark");let r=i.vertices.indexOf(e),s=[];for(let e of t)s.push(e.vertices[r]);return s}}}function S(e,t){if(e.dataScope){if(!e.parent)throw new Error("segment has no parent mark");let i=[];for(let e of t)i=i.concat(e.segments);return i}{let i=e.parent;if(!i)throw new Error("segment has no parent mark");let r=i.segments.indexOf(e),s=[];for(let e of t)s.push(e.segments[r]);return s}}function T(e,t){let i=[];return I(e,t?t.map(e=>h(e)):[],i),i}function R(e,t){let i=e.children.filter(e=>e.type==Vt.Collection);if(0!==i.length)for(let e of i){let i=e;for(;i&&i.dataScope;){if(i.dataScope.hasAttribute(t))return i;i=i.children?i.children[0]:void 0}}}function O(e){return e.type==Vt.Collection?e:e.parent?O(e.parent):void 0}function I(e,t,i){if(e)if(c(e,t)&&i.push(e),e.vertices)for(let r of e.vertices.concat(e.segments))c(r,t)&&i.push(r);else if(e.children&&e.children.length>0)for(let r of e.children)I(r,t,i)}function N(e){let t=e;for(;t;){if(t.type==Vt.Scene)return t;t=t.parent}}function L(e){let t=e;for("vertex"!=t.type&&"segment"!=t.type||(t=t.parent);t.parent&&[Vt.Collection,Vt.Glyph].includes(t.parent.type);)t=t.parent;return t}function V(e,t){let i=[];if(P(e,i),t){let e={};for(let t of i)e[t.classId]=t;return Object.values(e)}return i}function P(e,t){if(E(e))t.push(e);else if(e.children&&!Object.values(Pt).includes(e.type))for(let i of e.children)P(i,t)}function M(e,t){if(e){if(t(e),e.vertices)for(let i of e.vertices)t(i);if(e.segments)for(let i of e.segments)t(i);if(e.children&&e.children.length>0)for(let i of e.children)M(i,t)}}class D{constructor(){this._refElements=[]}addRefElement(e){this._refElements.push(e)}get refElements(){return this._refElements}clearRefElements(){this._refElements=[]}}const B=Object.freeze({GRID:"grid",STACK:"stack",PACKING:"packing",FORCE:"force",DIRECTED:"directedgraph",TIDYTREE:"tidytree",TREEMAP:"treemap",STRATA:"strata",CIRCULAR:"circular",CLUSTER:"cluster"});function G(e,t){return!!(e.startsWith("h")&&[v.LEFT,v.CENTER,v.RIGHT].indexOf(t)>=0)||(!!(e.startsWith("v")&&[v.TOP,v.MIDDLE,v.BOTTOM].indexOf(t)>=0)||(console.warn("Invalid alignment:",t),!1))}class F{constructor(e){this._id=e+"_"+Mt(),this._type=e,this._inputVars=[],this._outputVars=[]}run(){}get id(){return this._id}get type(){return this._type}get inputVars(){return this._inputVars}get outputVars(){return this._outputVars}get outputVar(){return this._outputVars[0]}isIsolated(){return 0==this._inputVars.length&&0==this._outputVars.length}}const z=Object.freeze({CONDUIT:"conduit",ENCODER:"encoder",LAYOUT:"layout",LINK_PLACER:"linkRouter",CONSTRAINT:"constraint",EVAL_BBOX:"evalBBox",EVAL_REFBOUNDS:"evalRefBounds",AFFIXER:"affixer",ALIGNER:"aligner",DATA_EXTRACTOR:"dataExtractor",SCALE_BUILDER:"scaleBuilder",AXIS_PATH_PLACER:"axisPathPlacer",AXIS_TICKS_PLACER:"axisTicksPlacer",AXIS_LABELS_PLACER:"axisLabelsPlacer",AXIS_TITLE_PLACER:"axisTitlePlacer",GRIDLINES_PLACER:"gridlinesPlacer",GRID_LAYOUT:"gridLayout",STACK_LAYOUT:"stackLayout",PACK_LAYOUT:"packLayout",FORCE_LAYOUT:"forceLayout",DIRECTED_LAYOUT:"directedLayout",TIDY_TREE_LAYOUT:"tidyTreeLayout",TREEMAP_LAYOUT:"treemapLayout",STRATA_LAYOUT:"strataLayout",CIRCULAR_LAYOUT:"circularLayout",CLUSTER_LAYOUT:"clusterLayout",BIN_TRANSFORMER:"binTransformer",FILTER_TRANSFORMER:"filterTransformer",KDE_TRANSFORMER:"kdeTransformer",TARGET_EVALUATOR:"targetEvaluator",TARGET_UPDATER:"targetUpdater"});class j{constructor(e){let t=e||{};this._stops=[],this.type=Vt.LinearGradient,this.id=this.type+Mt(),this.x1="x1"in t?t.x1:0,this.x2="x2"in t?t.x2:100,this.y1="y1"in t?t.y1:0,this.y2="y2"in t?t.y2:0}toJSON(){let e={};return e.type=this.type,e.id=this.id,e.x1=this.x1,e.x2=this.x2,e.y1=this.y1,e.y2=this.y2,e.stops=this._stops,e}addStop(e,t,i){this._stops.push({offset:e,color:t,opacity:i})}get stops(){return this._stops}}const W=Object.freeze({RowFirst:"rowFirst",ColumnFirst:"columnFirst"}),U=Object.freeze({TopLeft:"topLeft",TopRight:"topRight",BottomLeft:"bottomLeft",BottomRight:"bottomRight"}),H="horizontal",Y="vertical",X="angular",q="radial",K={Left2Right:"l2r",Right2Left:"r2l",Top2Bottom:"t2b",Bottom2Top:"b2t"},Z=Object.freeze({CLOCKWISE:"clockwise",ANTI_CLOCKWISE:"anti-clockwise"}),$=Object.freeze({INWARD:"inward",OUTWARD:"outward"});class J{constructor(e,t,i,r){this.type="vertex",this._id=r,this._x=e,this._y=t,this._dataScope=void 0,this.parent=i,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 g(this.x-this.width/2,this.y-this.height/2,this.width,this.height);case"circle":return new g(this.x-this.radius,this.y-this.radius,2*this.radius,2*this.radius);default:return new g(this.x-.5,this.y-.5,1,1)}}get id(){return this.parent.id+"_v_"+this._id}_clone(e){let t=new J(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}}J.styles=["vxShape","vxWidth","vxHeight","vxRadius","vxFillColor","vxStrokeColor","vxStrokeWidth","vxOpacity"];class Q{constructor(e,t,i,r){this.type="segment",this._id=r,this.vertex1=e,this.vertex2=t,this.dataScope=void 0,this.parent=i}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}}let ee=class extends w{constructor(e){super(e),this._type="type"in e?e.type:Vt.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 J.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 i=0;i<e.length;i++)if(i!=e.length-1||e[i][0]!==e[0][0]||e[i][1]!==e[0][1]||this.type!==Vt.Path){t=new J(e[i][0],e[i][1],this,this.vertexCounter++);for(let e of J.styles)if(this[e]){let i=e.replace("vx","");t[i[0].toLowerCase()+i.slice(1)]=this[e]}this.vertices.push(t),i>0&&this.segments.push(new Q(this.vertices[i-1],this.vertices[i],this,this.segmentCounter++))}let i=e[0],r=e[e.length-1];(i[0]===r[0]&&i[1]===r[1]||this.type===Vt.Rect)&&(this.closed=!0,"fillColor"in this.styles||(this.styles.fillColor="#fff"),this.segments.push(new Q(this.vertices[this.vertices.length-1],this.vertices[0],this,this.segmentCounter++))),this._dirty=!0}copyPropertiesTo(e){e.attrs=Object.assign({},this.attrs),e.styles=Object.assign({},this.styles);for(let t of J.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 Q(e.vertices[t-1],e.vertices[t],e,e.segmentCounter++));e.closed&&e.segments.push(new Q(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 strokeDash(){return this.styles.strokeDash}set strokeDash(e){this.styles.strokeDash=e,this._dirty=!0}resize(e,t,i,r){let s=this.bounds,n=0===s.width?1:s.width,a=0===s.height?1:s.height;if("right"===i)for(let t of this.vertices)t._x=s.right-e/n*(s.right-t.x);else for(let t of this.vertices)t._x=s.left+e/n*(t.x-s.left);if("top"===r)for(let e of this.vertices)e._y=s.top+t/a*(e.y-s.top);else for(let e of this.vertices)e._y=s.bottom-t/a*(s.bottom-e.y);this._updateBounds(),this._dirty=!0}_updateBounds(){let e=[],t=[];if(this._d){const i=this._d.match(/[a-zA-Z][^a-zA-Z]*/g),r=" ";i.forEach(i=>{let s=i.slice(1).trim().split(r).map(Number);for(let[i,r]of s.entries())i%2==0?e.push(r):t.push(r)})}else e=this.vertices.map(e=>e.x),t=this.vertices.map(e=>e.y);let i=Math.min(...e),r=Math.min(...t),s=Math.max(...e),n=Math.max(...t),a=s-i,o=n-r;if(this._bounds=new g(i,r,a,o),this.type===Vt.Line||this.type===Vt.Path){let e=this.styles.strokeWidth?this.styles.strokeWidth:1;i===s?this._bounds=new g(i-e/2,r,s-i+e,n-r):r===n&&(this._bounds=new g(i,r-e/2,s-i,n-r+e))}}addVertex(e,t,i){let r=new J(e,t,this,this.vertexCounter++);this.vertices.splice(i,0,r)}sortVertices(e,t){this.vertices.sort((t,i)=>t[e]-i[e]),t&&this.vertices.reverse();for(let e=0;e<this.segments.length;e++){let t=this.segments[e];t.vertex1=this.vertices[e],t.vertex2=this.vertices[(e+1)%this.vertices.length]}this._dirty=!0}sortVerticesByData(e,t,i){let r;r=i?(t,r)=>i.indexOf(t.dataScope.getValue(e))-i.indexOf(r.dataScope.getAttrVal(e)):(t,i)=>t.dataScope.getAttrVal(e)<i.dataScope.getAttrVal(e)?-1:1,this.vertices.sort(r),t&&this.vertices.reverse();for(let e=0;e<this.segments.length;e++){let t=this.segments[e];t.vertex1=this.vertices[e],t.vertex2=this.vertices[(e+1)%this.vertices.length]}this._dirty=!0}getSVGPathData(){if(this._d)return this._d;let e=r.path(),t=this._getD3CurveFunction(this.curveMode)(e);t.lineStart();for(let e of this.vertices)t.point(e.x,e.y);return this.closed&&t.point(this.vertices[0].x,this.vertices[0].y),t.lineEnd(),e._}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(e){switch(e){case re.Natural:return r.curveNatural;case re.Basis:return r.curveBasis;case re.BumpX:return r.curveBumpX;case re.BumpY:return r.curveBumpY;case re.Linear:return r.curveLinear;case re.Step:return r.curveStep;case re.CatmullRom:return r.curveCatmullRom;case re.Cardinal:return r.curveCardinal;case re.Bundle:return r.curveBundle.beta(.5);default:return r.curveLinear}}get vxShape(){return this._vxShape}get vxWidth(){return this._vxWidth}get vxHeight(){return this._vxHeight}get vxRadius(){return this._vxRadius}get vxFillColor(){return this._vxFillColor}get vxStrokeColor(){return this._vxStrokeColor}get vxStrokeWidth(){return this._vxStrokeWidth}get vxOpacity(){return this._vxOpacity}get sourceAnchor(){return this._sourceAnchor}get targetAnchor(){return this._targetAnchor}get sourceOffset(){return this._sourceOffset}get targetOffset(){return this._targetOffset}};function te(e,t){const i=d.getSVG();let r=document.createElementNS("http://www.w3.org/2000/svg","path");r.setAttribute("d",e.getSVGPathData()),i.appendChild(r);let s=r.getTotalLength();return r.getPointAtLength(s*t)}function ie(e){return e instanceof ee&&e.source&&e.target}const re={Natural:"natural",Basis:"basis",BumpX:"bumpX",BumpY:"bumpY",Bundle:"bundle",Linear:"linear",Step:"step",CatmullRom:"CatmullRom",Cardinal:"cardinal"};function se(e,t,i){const r=e.match(/[a-zA-Z][^a-zA-Z]*/g),s=",";return r.map(e=>{const r=e[0],n=e.slice(1).trim();if("M"===r||"L"===r||"T"===r){const[e,a]=n.split(s).map(Number);return`${r}${e+t} ${a+i}`}if("C"===r){const e=n.split(s).map(Number);return`${r}${e[0]+t} ${e[1]+i} ${e[2]+t} ${e[3]+i} ${e[4]+t} ${e[5]+i}`}if("Q"===r){const e=n.split(s).map(Number);return`${r}${e[0]+t} ${e[1]+i} ${e[2]+t} ${e[3]+i}`}if("A"===r){const e=n.split(s).map(Number);return`${r}${e[0]} ${e[1]} ${e[2]} ${e[3]} ${e[4]} ${e[5]+t} ${e[6]+i}`}return"Z"===r||"z"===r?r:e}).join(" ")}class ne extends ee{constructor(e){super(e),this._type=Vt.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=ae(this._startAngle),this._er=ae(this._endAngle),this._direction="direction"in e?e.direction:Z.ANTI_CLOCKWISE;let t=this._x+this._innerRadius*Math.cos(this._sr),i=this._y-this._innerRadius*Math.sin(this._sr),r=this._x+this._innerRadius*Math.cos(this._er),s=this._y-this._innerRadius*Math.sin(this._er),n=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,i],[n,a],[o,l],[r,s]])}get type(){return 0===this._innerRadius?Vt.Pie:Vt.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=ae(this._startAngle),this._er=ae(this._endAngle),this.vertices[0]._x=this._x+this._innerRadius*Math.cos(this._sr),this.vertices[0]._y=this._y-this._innerRadius*Math.sin(this._sr),this.vertices[1]._x=this._x+this._outerRadius*Math.cos(this._sr),this.vertices[1]._y=this._y-this._outerRadius*Math.sin(this._sr),this.vertices[2]._x=this._x+this._outerRadius*Math.cos(this._er),this.vertices[2]._y=this._y-this._outerRadius*Math.sin(this._er),this.vertices[3]._x=this._x+this._innerRadius*Math.cos(this._er),this.vertices[3]._y=this._y-this._innerRadius*Math.sin(this._er),this._dirty=!0}_updateBounds(){let e=this.vertices.map(e=>e.x),t=this.vertices.map(e=>e.y),i=Math.min(...e),r=Math.min(...t),s=Math.max(...e)-i,n=Math.max(...t)-r;this._bounds=new g(i,r,s,n)}copyPropertiesTo(e){super.copyPropertiesTo(e),e._x=this._x,e._y=this._y,e._innerRadius=this._innerRadius,e._outerRadius=this._outerRadius,e._startAngle=this._startAngle,e._endAngle=this._endAngle,e._thickness=this._thickness,e._direction=this._direction,e._sr=this._sr,e._er=this._er}getSVGPathData(){let e=this._endAngle<this._startAngle?this._endAngle+360-this._startAngle:this._endAngle-this._startAngle,t=e>180?1:0;return["M "+this.vertices[0].x+", "+this.vertices[0].y,"L "+this.vertices[1].x+", "+this.vertices[1].y,"A "+[this._outerRadius,this._outerRadius,e,t,0,this.vertices[2].x,this.vertices[2].y].join(" "),"L "+this.vertices[3].x+", "+this.vertices[3].y,"A "+[this._innerRadius,this._innerRadius,e,t,1,this.vertices[0].x,this.vertices[0].y].join(" ")].join(" ")}}function ae(e){return e*Math.PI/180}function oe(e){return 180*e/Math.PI}function le(e){return(e%360+360)%360}function he(e,t,i,r){let s=e-i,n=r-t;return Math.atan2(n,s)*(180/Math.PI)}class ce{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 ce(this._dt);for(let e in this._attr2value)t=t.cross(e,this._attr2value[e]);for(let i in e._attr2value)t=t.cross(i,e._attr2value[i]);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 i=this.clone();return i._attr2value[e]=t,i._updateTuples(e,t),i}derive(e){let t=Object.assign({},this._attr2value);for(let i in e)t[i]=e[i];let i=new ce(this._dt);for(let e in t)i._attr2value[e]=t[e],i._updateTuples(e,t[e]);return i}clone(){let e=new ce(this._dt);return e._attr2value=Object.assign({},this._attr2value),e._tuples=this._tuples.map(e=>e),e}getAttrVal(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(e,t){let i=this._tuples.map(t=>t[e]);switch(t){case ue.Max:return Math.max(...i);case ue.Min:return Math.min(...i);case ue.Avg:case ue.Mean:return r.mean(i);case ue.Median:return r.median(i);case ue.Count:return i.length;case ue.Percentile25:return r.quantile(i,.25);case ue.Percentile75:return r.quantile(i,.75);case ue.Sum:default:return r.sum(i)}}_updateTuples(e,t){this._tuples=this._tuples.filter(i=>i[e]==t)}get tuples(){return this._tuples}}function de(e){return"vertex"==e.type||"segment"==e.type?e.dataScope?e.dataScope:e.parent.dataScope:e.dataScope}const ue={Max:"max",Min:"min",Avg:"avg",Median:"median",Sum:"sum",Count:"count",Mean:"mean",Percentile25:"percentile 25",Percentile75:"percentile 75"};class _e{constructor(e,t){this._id=Vt.TreeData+Mt(),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 Dt(this._nodeList,"nodes"),this._linkTable=new Dt(this._linkList,"links"),this._nodeTable.tree=this,this._linkTable.tree=this}get nodeTable(){return this._nodeTable}get linkTable(){return this._linkTable}_traverse(e,t,i,r=0){let s={};me in e||(e[me]="n"+t.length),t.push(s),e._depth=r;for(let n in e)if("children"==n&&e[n]&&e[n].length>0)for(let s of e[n]){let n=this._traverse(s,t,i,r+1);i.push({parent:e[me],child:n})}else s[n]=e[n];return this._nodeHash[s[me]]=s,s[me]}getNodeDataScope(e){return new ce(this._nodeTable).cross(Gt,e[Gt])}getNode(e){return this._nodeHash[e]}getRoot(){return this._nodeTable.data[0]}getChildren(e){let t=e[me],i=[],r=this._linkTable.data,s=this._nodeTable.data;for(let e in r)if(r[e].parent==t){let t=r[e].child,n=s.findIndex(e=>e[me]==t);i.push(s[n])}return i}getParent(e){let t=e[me],i=this._linkTable.data,r=this._nodeTable.data;for(let e in i)if(i[e].child==t){let t=i[e].parent,s=r.findIndex(e=>e[me]==t);return r[s]}}}function pe(e){return e.dataScope._dt.tree}class fe{constructor(e,t){this._id=Vt.NetworkData+Mt(),this.initialize(e,t)}initialize(e,t){this.url=t,this._nodeTable=new Dt(e.nodes,this._id+"_nodes"),this._linkTable=new Dt(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[me]]=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[me],i=this._rawLinks,r=[];for(let e in i)i[e].target!==t&&i[e].source!==t||r.push(i[e]);return r}buildNodeHierarchy(e){let t={};return t[me]="root",ye(t,this._rawNodes,e),new _e(t,this.url)}}function ge(e){return e.dataScope._dt.graph}function ye(e,t,i){if(0===t.length||0===i.length)return;"children"in e||(e.children=[]);let r={};for(let e of t){let t=e[i[0]];t in r||(r[t]=[]),r[t].push(e)}if(1===i.length)for(let t in r){let i={children:r[t]};i[me]=t,e.children.push(i)}else for(let t in r){let s={};s[me]=t,e.children.push(s),ye(s,r[t],i.slice(1))}}const me="id";function be(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 xe=Object.freeze({Boolean:"boolean",Integer:"integer",Number:"number",Date:"date",String:"string"});function ve(e){var t=Object.values(xe);for(let i=0;i<e.length;i++){let r=e[i];if(null!=r){for(let e=0;e<t.length;e++)we[t[e]](r)||(t.splice(e,1),e-=1);if(1==t.length)return t[0]}}return t[0]}const we={boolean:function(e){return"true"===e||"false"===e||!0===e||!1===e||"[object Boolean]"==toString.call(e)},integer:function(e){return we.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 Ee(e,t){let i={};switch(t){case xe.Boolean:i.trueCount=e.filter(e=>e).length,i.falseCount=e.filter(e=>!e).length;break;case xe.Date:i.min=r.min(e),i.max=r.max(e),i.extent=[i.min,i.max],i.unique=[...new Set(e)];break;case xe.String:i.unique=[...new Set(e)];break;default:i.min=r.min(e),i.max=r.max(e),i.extent=[i.min,i.max],i.mean=r.mean(e),i.median=r.median(e),i.unique=[...new Set(e)]}return i}function Ae(e,t,i,r,s){let n=s.getAttributeType(i);if(n!=xe.String&&n!=xe.Date&&n!=xe.Number&&n!=xe.Integer)throw new Error("Densify only works on a string or date attribute: "+i+" is "+n);if(!ke(t))throw new Error("The "+t.type+" is not dividable");switch(t.type){case Vt.Line:return function(e,t,i){let r,s,n=C(e);for(let a of n){let n=a.dataScope?a.dataScope:new ce(i),o=i.getUniqueAttributeValues(t).map(e=>n.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 J.styles)a[e]&&(l[e]=a[e]);let h=a.vertices[0].x,c=a.vertices[0].y,d=[],u=a.vertices[1].x-h,_=a.vertices[1].y-c;for(let e=0;e<o.length;e++)d.push([h+e*u/(o.length-1),c+e*_/(o.length-1)]);l.vertices=d,l.type="path";let p=Rt(l);s||(s=p.id),p._classId=s,p.dataScope=n,p._updateBounds(),p._refBounds=p.bounds.clone();let f=a.parent;f.addChild(p),f.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&&(r=p)}return r}(t,i,s);case Vt.Circle:return function(e,t,i){let r,s,n=C(e),a=i.getAttributeType(t);for(let o of n){let n=o.dataScope?o.dataScope:new ce(i),l=i.getUniqueAttributeValues(t).map(e=>n.cross(t,e));l=a==xe.Number?l:l.filter(e=>!e.isEmpty());let h=l.length;if(h<3)throw new Error("INSUFFICIENT_DATA_SCOPES");let c=90,d=360/h,u=[],_=[],p=-1;for(let e=0;e<l.length;e++){let t=c+p*e*d;_[e]=t;let i=Ce(o.x,o.y,o.radius,_[e]);u.push(i)}let f=Object.assign({},o.styles);f.vertices=u,f.type="polygon",f.x=o.x,f.y=o.y,f.radius=o.radius;let g=Rt(f);s||(s=g.id),g._classId=s,g.dataScope=n;let y=o.parent;y.addChild(g),y.removeChild(o);for(let[e,t]of g.vertices.entries())t._polarAngle=_[e],e>=l.length?t.dataScope=n.merge(l[2*l.length-1-e]):t.dataScope=n.merge(l[e]);o===e&&(r=g)}return r}(t,i,s);case Vt.Rect:return function(e,t,i,r){let s,n,a=C(e),o=t||H;if(o!=H&&o!=Y)throw new Error("Unknown orientation: "+o);for(let t of a){let a=r.getAttributeType(i),l=t.dataScope?t.dataScope:new ce(r),h=r.getUniqueAttributeValues(i).map(e=>l.cross(i,e));h=a==xe.Number?h:h.filter(e=>!e.isEmpty()),1===h.length&&h.push(h[0].clone()),a!=xe.Number&&a!=xe.Date||h.sort((e,t)=>e._attr2value[i]>t._attr2value[i]?1:-1);let c=Object.assign({},t.styles),d=t.vertices[0].x,u=t.vertices[0].y,_=t.vertices[t.vertices.length-2].x,p=t.vertices[t.vertices.length-2].y,f=[],g=_-d,y=p-u;for(let e=0;e<h.length;e++)f.push(o==Y?[_,u+e*y/(h.length-1)]:[d+e*g/(h.length-1),u]);for(let e=0;e<h.length;e++)f.push(o==Y?[d,u+(h.length-1-e)*y/(h.length-1)]:[d+(h.length-1-e)*g/(h.length-1),p]);c.vertices=f,c.type="area";let m=Rt(c);n||(n=m.id),m._classId=n,m.dataScope=l,m.orientation=o,m.baseline=o===H?v.BOTTOM:v.LEFT;let b=t.parent;b.addChild(m),b.removeChild(t);for(let[e,t]of m.vertices.entries())e>=h.length?t.dataScope=l.merge(h[2*h.length-1-e]):t.dataScope=l.merge(h[e]);t===e&&(s=m)}return s}(t,r,i,s)}}function Ce(e,t,i,r){return[i*Math.cos(ae(r))+e,t-i*Math.sin(ae(r))]}function ke(e){if([Vt.Line,Vt.Circle,Vt.Rect,Vt.Area].indexOf(e.type)<0)return!1;if(e.dataScope){let t=C(e,e.scene);for(let e of t)if(e.dataScope.numTuples>1)return!0;return!1}return!0}class Se{constructor(e){this._id="v_"+Mt(),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 F)return e.fromNode;return null}isIsolated(){return 0==this._incomings.length&&0==this._outgoings.length}}const Te=Object.freeze({CHANNEL:"channel",PROPERTY:"property",ATTRIBUTE:"attribute",ITEMS:"items",DATASCOPE:"datascope",ATTR_VALUE:"dataValue",BOUNDS:"bounds",SCALE:"scale",CONDITION_RESULT:"conditionResult",AFFIXATION:"affixation",ALIGNMENT:"alignment",EVT_CTX:"evtContext"});class Re extends Se{constructor(e,t,i){super(e),this._channel=t,this._elem=i}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 i=e.scene._encodings[Pe(e)],r=[];i&&(r=r.concat(Object.values(i)));{let t=e.scene;for(let i in t._encodings){let s=i.split("_");s.pop(),s.join("_")===e.classId&&(r=r.concat(Object.values(t._encodings[i])))}}return r}function Le(e,t,i){for(let r in i._encodings){let s=i._encodings[r];if(s[t]&&s[t].attribute==e)return s[t]}return null}function Ve(e,t){let i=e.scene._encodings[Pe(e)];return i&&i[t]?i[t]:null}function Pe(e){if(Array.isArray(e))return e.map(e=>Pe(e)).join("_");if(e.classId)return e.classId;if("vertex"==e.type&&e.dataScope){if(e.parent.type===Vt.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 Me(e,t){if(0==e.children.length)return[];let i=N(e),r=e.type===Vt.Composite?e.children:[e.children[0]],s=Object.keys(i._encodings),n=[];for(let e of r){let t=e;for(;t;){if(t.classId&&n.indexOf(t.classId)<0&&n.push(t.classId),t.type===Vt.Glyph){t.children.forEach(e=>n.push(e.classId));break}if(!t.children)break;t=t.children[0]}}let a=[];for(let e of s)for(let r of n)0===e.indexOf(r)&&i._encodings[e][t]&&a.push(i._encodings[e][t]);return a}function De(e){let t=Ve(e,"y"),i=Ve(e,"height");return t||i&&i.scales[0].domain[0]<0}function Be(e){let t=Ve(e,"x"),i=Ve(e,"width");return t||i&&i.scales[0].domain[0]<0}function Ge(e,t){let i=function(e){let t=e.parent,i=[];for(;t.type!==Vt.Scene;)i.push(t),t=t.parent;return i}(e);for(let e of i)if(Ve(e,t))return!1;return i.length>=2?i[i.length-2]:e}function Fe(e,t,i){switch(e.type){case Vt.Rect:case Vt.Path:case Vt.Line:case Vt.Area:!function(e,t,i){for(let r of e.vertices)ze(r,t,i);e._updateBounds(),e._refBounds&&e._refBounds.translate(t,i)}(e,t,i),0===t&&0===i||(e._dirty=!0);break;case Vt.Group:case Vt.Collection:case Vt.Glyph:!function(e,t,i){for(let r of e.children)Fe(r,t,i);e._layout&&(void 0!==e._layout._left&&(e._layout._left+=t),void 0!==e._layout._top&&(e._layout._top+=i),e._layout._cellBounds&&e._layout._cellBounds.forEach(e=>e.translate(t,i)));e._updateBounds(),e._refBounds&&e._refBounds.translate(t,i)}(e,t,i);break;case"segment":!function(e,t,i){ze(e.vertex1,t,i),ze(e.vertex2,t,i)}(e,t,i),0===t&&0===i||(e.parent._dirty=!0);break;case"vertex":ze(e,t,i),0===t&&0===i||(e.parent._dirty=!0);break;default:!function(e,t,i){e._x+=t,e._y+=i,e._updateBounds(),e._refBounds&&e._refBounds.translate(t,i)}(e,t,i),0===t&&0===i||(e._dirty=!0)}}function ze(e,t,i){e._x+=t,e._y+=i}function je(e,t,i){switch(t){case"x":Ue(e,i);break;case"y":He(e,i);break;case"width":!function(e,t){e.resize(t,e.height)}(e,i);break;case"height":!function(e,t){e.resize(e.width,t)}(e,i);break;case"radius":e.radius=i;break;case"strength":e._strength=i;break;case"area":e.type===Vt.Circle?e.radius=Math.sqrt(i/Math.PI):e.type===Vt.Rect&&e.resize(Math.sqrt(i),Math.sqrt(i)),e._updateBounds();break;case"text":e._text=i;break;case"curveMode":e.curveMode=i;break;case"baseline":e.baseline=i;break;case"angle":[Vt.Arc,Vt.Pie].includes(e.type)&&function(e,t){e._endAngle=le(e._startAngle+t),e._sr=ae(e._startAngle),e._er=ae(e._endAngle),e.vertices[0]._x=e._x+e._innerRadius*Math.cos(e._sr),e.vertices[0]._y=e._y-e._innerRadius*Math.sin(e._sr),e.vertices[1]._x=e._x+e._outerRadius*Math.cos(e._sr),e.vertices[1]._y=e._y-e._outerRadius*Math.sin(e._sr),e.vertices[2]._x=e._x+e._outerRadius*Math.cos(e._er),e.vertices[2]._y=e._y-e._outerRadius*Math.sin(e._er),e.vertices[3]._x=e._x+e._innerRadius*Math.cos(e._er),e.vertices[3]._y=e._y-e._innerRadius*Math.sin(e._er)}(e,i);break;case"startAngle":!function(e,t){let i=e.angle;e._startAngle=t,e._endAngle=le(e._startAngle+i),e._sr=ae(e._startAngle),e._er=ae(e._endAngle),e.vertices[0]._x=e._x+e._innerRadius*Math.cos(e._sr),e.vertices[0]._y=e._y-e._innerRadius*Math.sin(e._sr),e.vertices[1]._x=e._x+e._outerRadius*Math.cos(e._sr),e.vertices[1]._y=e._y-e._outerRadius*Math.sin(e._sr),e.vertices[2]._x=e._x+e._outerRadius*Math.cos(e._er),e.vertices[2]._y=e._y-e._outerRadius*Math.sin(e._er),e.vertices[3]._x=e._x+e._innerRadius*Math.cos(e._er),e.vertices[3]._y=e._y-e._innerRadius*Math.sin(e._er)}(e,i);break;case"thickness":!function(e,t){We(e,e._innerRadius+t)}(e,i);break;case"innerRadius":!function(e,t){e._innerRadius=t,e.vertices[0]._x=e._x+e._innerRadius*Math.cos(e._sr),e.vertices[0]._y=e._y-e._innerRadius*Math.sin(e._sr),e.vertices[3]._x=e._x+e._innerRadius*Math.cos(e._er),e.vertices[3]._y=e._y-e._innerRadius*Math.sin(e._er)}(e,i);break;case"outerRadius":We(e,i);break;case"radialDistance":{let t=Ce(e.parent.x,e.parent.y,i,e.polarAngle);Ue(e,t[0]),He(e,t[1]);break}case"visibility":e.visibility=i;break;case"src":e.src=i;break;default:if("vertex"===e.type)e[t]=i;else if(e instanceof mt)for(let r of e.children)je(r,t,i);else e.styles[t]=i}"vertex"===e.type?e.parent._dirty=!0:e._dirty=!0}function We(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 Ue(e,t){"vertex"==e.type?e._x=t:Fe(e,t-e.x,0)}function He(e,t){"vertex"==e.type?e._y=t:Fe(e,0,t-e.y)}class Ye extends ee{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,i,r){e!==this.width&&("right"===i?(this.vertices[1]._x=this.refBounds.right,this.vertices[2]._x=this.refBounds.right,this.vertices[0]._x=this.vertices[1]._x-e,this.vertices[3]._x=this.vertices[0]._x):(this.vertices[0]._x=this.refBounds.left,this.vertices[3]._x=this.refBounds.left,this.vertices[1]._x=this.vertices[0]._x+e,this.vertices[2]._x=this.vertices[1]._x)),t!==this.height&&("top"===r?(this.vertices[0]._y=this.refBounds.top,this.vertices[1]._y=this.refBounds.top,this.vertices[3]._y=this.vertices[0]._y+t,this.vertices[2]._y=this.vertices[3]._y):(this.vertices[2]._y=this.refBounds.bottom,this.vertices[3]._y=this.refBounds.bottom,this.vertices[0]._y=this.vertices[3]._y-t,this.vertices[1]._y=this.vertices[0]._y)),this._dirty=!0}get leftSegment(){return this.segments[3]}get rightSegment(){return this.segments[1]}get topSegment(){return this.segments[0]}get bottomSegment(){return this.segments[2]}}class Xe extends ee{constructor(e){super(e),this._type=Vt.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 Q(this.vertices[this.vertices.length-1],this.vertices[0],this,this.segmentCounter++))}get topLeftVertex(){return this._orientation===H?this.vertices[0]:this.vertices[this.vertices.length-1]}get bottomLeftVertex(){return this._orientation===H?this.vertices[this.vertices.length-1]:this.vertices[this.vertices.length/2]}get topRightVertex(){return this._orientation===H?this.vertices[this.vertices.length/2-1]:this.vertices[0]}get bottomRightVertex(){return this._orientation===H?this.vertices[this.vertices.length/2]:this.vertices[this.vertices.length/2-1]}get baseline(){return this._baseline}set baseline(e){this._baseline=e,this._dirty=!0}get orientation(){return this._orientation}set orientation(e){this._orientation=e,this._dirty=!0}get firstVertexPair(){return[this.vertices[0],this.vertices[this.vertices.length-1]]}get width(){return this.vertices[this.vertices.length/2].x-this.vertices[0].x}get height(){return this.vertices[this.vertices.length/2].y-this.vertices[0].y}get left(){return this.vertices[0].x}get top(){return this.vertices[0].y}copyPropertiesTo(e){super.copyPropertiesTo(e),e._baseline=this._baseline,e._orientation=this._orientation}getSVGPathData(){return super.getSVGPathData()+" z"}}class qe extends Se{constructor(e,t){super(e),this._encs={},this._encs[t.channel+"_"+Pe(t.element)]=t,this._initialized=!1}addLinkedEncoding(e){this._encs[e.channel+"_"+Pe(e.element)]=e}getEncoding(e,t){let i=e+"_"+Pe(t);return this._encs[i]}get encodings(){return Object.values(this._encs)}get initialized(){return this._initialized}set initialized(e){this._initialized=e}}class Ke extends Se{constructor(e,t,i){super(e),this._result=t,this._condEnc=i}get result(){return this._result}get conditionalEncoding(){return this._condEnc}}class Ze extends F{constructor(e){super(e)}storeValues(e,t){this._storedValues={};let i=C(e);for(let e of i)this._storedValues[e.id]=e[t]}_restoreValues(e){let t=this.outputVar.channel;e.forEach(e=>{e.styles[t]!==this._storedValues[e.id]&&(e._dirty=!0,e.styles[t]=this._storedValues[e.id])})}run(){super.run();let e=this.inputVars.find(e=>e instanceof qe),t=this.outputVar,i=C(t.element),r=["x","y","width","height","radius"].includes(t.channel);if(e){let i=e.getEncoding(t.channel,t.element);for(let e of i.scales){let t=i.getElements(e);this._doMapping(t,e,i.attrValues,i),r&&this._updateRefBounds(t,e,i)}}else this._restoreValues(i);let s=this._getUsableCondEncodings();if(s.length>0&&this._doCondEncoding(i,s.map(e=>e.conditionalEncoding)),r){x(["vertex","segment"].includes(t.element.type)?t.element.parent:t.element)}}_updateRefBounds(e,t,i){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,v.CENTER),e._refBounds.setHeight(2*t.rangeExtent,v.MIDDLE)});break;case"x":"vertex"!=e[0].type&&"segment"!=e[0].type||e.forEach(e=>{let r=e.parent._refBounds;e.parent._refBounds=new g(i.flipScale?t.range[1]:t.range[0],r.top,t.rangeExtent,r.height)});break;case"y":"vertex"!=e[0].type&&"segment"!=e[0].type||e.forEach(e=>{let r=e.parent._refBounds;e.parent._refBounds=new g(r.left,i.flipScale?t.range[0]:t.range[1],r.width,t.rangeExtent)})}}_doMapping(e,t,i,r){switch(this.outputVar.channel){case"width":t.domain[0]<0&&e[0]instanceof Ye?function(e,t,i){for(let r=0;r<e.length;r++){let s=e[r],n=s.refBounds.left+t.map(0),a=s.refBounds.left+t.map(i[s.id]);Fe(s.leftSegment,n-s.leftSegment.x,0),Fe(s.rightSegment,a-s.rightSegment.x,0)}}(e,t,i):t.domain[0]<0&&e[0]instanceof Xe||(e[0].type===Vt.Area?function(e,t,i){let r=e[0].baseline;if(e[0].orientation===Y)switch(r){case"left":for(let r of e)C(r.topLeftVertex,r).forEach(e=>je(e,"x",r.refBounds.left)),C(r.topRightVertex,r).forEach(e=>je(e,"x",r.refBounds.left+t.map(i[e.id])));break;case"right":for(let r of e)C(r.topLeftVertex,r).forEach(e=>je(e,"x",r.refBounds.right-t.map(i[e.id]))),C(r.topRightVertex,r).forEach(e=>je(e,"x",r.refBounds.right));break;case"center":console.log("center");for(let r of e)C(r.topLeftVertex,r).forEach(e=>je(e,"x",r.refBounds.center-t.map(i[e.id])/2)),C(r.topRightVertex,r).forEach(e=>je(e,"x",r.refBounds.center+t.map(i[e.id])/2))}}(e,t,i):this._doStandardMapping(e,t,i));break;case"height":t.domain[0]<0&&e[0]instanceof Ye?function(e,t,i){for(let r=0;r<e.length;r++){let s=e[r],n=s.refBounds.bottom-t.map(0),a=s.refBounds.bottom-t.map(i[s.id]);Fe(s.bottomSegment,0,n-s.bottomSegment.y),Fe(s.topSegment,0,a-s.topSegment.y)}}(e,t,i):t.domain[0]<0&&e[0]instanceof Xe?function(e,t,i){for(let r of e){let e=k(r.topLeftVertex,[r]);for(let s of e)je(s,"y",r.refBounds.bottom-t.map(i[s.id]));k(r.bottomLeftVertex,[r]).forEach(e=>je(e,"y",r.refBounds.bottom-t.map(0)))}}(e,t,i):e[0].type===Vt.Area?function(e,t,i){let r=e[0].baseline;if(e[0].orientation===H)switch(r){case"top":for(let r of e)C(r.bottomLeftVertex,r).forEach(e=>je(e,"y",r.refBounds.top+t.map(i[e.id]))),C(r.topLeftVertex,r).forEach(e=>je(e,"y",r.refBounds.top));break;case"middle":for(let r of e)C(r.topLeftVertex,r).forEach(e=>je(e,"y",r.refBounds.middle-t.map(i[e.id])/2)),C(r.bottomLeftVertex,r).forEach(e=>je(e,"y",r.refBounds.middle+t.map(i[e.id])/2));break;default:for(let r of e)C(r.topLeftVertex,r).forEach(e=>je(e,"y",r.refBounds.bottom-t.map(i[e.id]))),C(r.bottomLeftVertex,r).forEach(e=>je(e,"y",r.refBounds.bottom))}}(e,t,i):this._doStandardMapping(e,t,i);break;case"text":this._doTextMapping(e,i);break;case"fillGradient":!function(e,t,i,r){for(let s of e){let e=s.vertices.map(e=>i[e.id]),n=Math.min(...e),a=Math.max(...e),o="horizontal"===s.orientation?new j({x1:0,y1:100,x2:0,y2:0}):new j({x1:0,y1:0,x2:100,y2:0});if(o.addStop(0,t.map(n),1),r._mapping){let e=Object.keys(r._mapping).map(e=>parseFloat(e)).sort();for(let i of e)i>n&&i<a&&o.addStop(100*(i-n)/(a-n),t.map(i),1)}else"divergingColor"===t.type&&o.addStop(100*-n/(a-n),t.map(0),1);"sequentialColor"===t.type&&o.addStop(100*-n/(a-n),t.map(0),1),o.addStop(100,t.map(a),1),s.fillColor=o}}(e,t,i,r);break;default:this._doStandardMapping(e,t,i)}}_doTextMapping(e,t){let i=this.outputVar.channel;e.forEach(e=>{je(e,i,t[e.id])})}_doStandardMapping(e,t,i){let r=this.outputVar.channel;e.forEach(e=>{let s=t.map(i[e.id]);je(e,r,s),e instanceof ee&&e.firstVertex&&e.firstVertex.shape&&"strokeColor"===r&&e.vertices.forEach(e=>e.fillColor=s)})}_doCondEncoding(e,t){let i=e[0].scene;for(let r of e){let e=t.map(e=>e.evalResult.getValue(r.id)).every(e=>e||void 0===e),s=t[0].eventContext;t[0].stylingFunction(e,s,r,i)}}_updateElement(e,t,i,r){let s;"object"==typeof r&&e.triggerElement?"property"in r?s=e.triggerElement[r.property]:"attribute"in r&&(s=e.triggerElement.dataScope.getAttrVal(r.attribute)):s=r,["x","y"].includes(i)&&"offset"in r&&(s+=r.offset),je(t,i,s)}_getUsableCondEncodings(){return this.inputVars.filter(e=>e instanceof Ke)}}class $e extends Se{constructor(e,t,i){super(e),this._property=t,this._elem=i}get property(){return this._property}get element(){return this._elem}}function Je(e){return e in Qe?Qe[e]:e}const Qe=Object.freeze({numCols:"layoutParameter",numRows:"layoutParameter",startCorner:"layoutParameter",direction:"layoutParameter"}),et=Object.freeze({AXIS_ORIENTATION:"axisOrientation",AXIS_PATH_POSITION:"axisPathPosition",AXIS_TICK_SIZE:"axisTickSize",AXIS_TICK_OFFSET:"axisTickOffset",AXIS_TICKS_POSITION:"axisTicksPosition",AXIS_LABELS_POSITION:"axisLabelsPosition",AXIS_TITLE_POSITION:"axisTitlePosition",AXIS_LABEL_OFFSET:"axisLabelOffset",AXIS_LABEL_FORMAT:"axisLabelFormat",AXIS_FONT_SIZE:"axisFontSize",LEGEND_POSITION:"legendPosition",GRIDLINES_POSITION:"gridlinesPosition",INCLUDE_ZERO:"includeZero",FLIP_SCALE:"flipScale",RANGE_START:"rangeStart",RANGE_EXTENT:"rangeExtent",BASE_LINE:"baseline",LAYOUT_PARAMETER:"layoutParameter",CHILDREN_ORDER:"childrenOrder",TRANSFORM:"transform"});function tt(e,t){if(t.findVariable(Te.BOUNDS,[e]))return;let i=t.getVariable(Te.BOUNDS,e),r=t.createOneWayDependency(z.EVAL_BBOX);switch(t.connect(r,i),e.type){case Vt.Circle:case Vt.Polygon:{let i=t.getVariable(Te.CHANNEL,"x",e),s=t.getVariable(Te.CHANNEL,"y",e),n=t.getVariable(Te.CHANNEL,"radius",e),a=t.getVariable(Te.CHANNEL,"area",e);t.connect(n,r),t.connect(i,r),t.connect(s,r),t.connect(a,r);break}case Vt.Area:case Vt.Line:case Vt.BezierCurve:case Vt.Path:case Vt.Image:{let i=t.getVariable(Te.CHANNEL,"x",e),s=t.getVariable(Te.CHANNEL,"y",e),n=t.getVariable(Te.CHANNEL,"width",e),a=t.getVariable(Te.CHANNEL,"height",e);t.connect(i,r),t.connect(s,r),t.connect(n,r),t.connect(a,r);break}case Vt.Rect:{let i=t.getVariable(Te.CHANNEL,"x",e),s=t.getVariable(Te.CHANNEL,"y",e),n=t.getVariable(Te.CHANNEL,"width",e),a=t.getVariable(Te.CHANNEL,"height",e),o=t.getVariable(Te.CHANNEL,"area",e);t.connect(i,r),t.connect(s,r),t.connect(n,r),t.connect(a,r),t.connect(o,r);break}case Vt.SimpleText:case Vt.RichText:{let i=t.getVariable(Te.CHANNEL,"x",e),s=t.getVariable(Te.CHANNEL,"y",e),n=t.getVariable(Te.CHANNEL,"text",e);t.connect(i,r),t.connect(s,r),t.connect(n,r);break}case Vt.Ring:{let i=t.getVariable(Te.CHANNEL,"x",e),s=t.getVariable(Te.CHANNEL,"y",e),n=t.getVariable(Te.CHANNEL,"innerRadius",e),a=t.getVariable(Te.CHANNEL,"outerRadius",e);t.connect(i,r),t.connect(s,r),t.connect(n,r),t.connect(a,r);break}case Vt.Pie:case Vt.Arc:{let i=t.getVariable(Te.CHANNEL,"x",e),s=t.getVariable(Te.CHANNEL,"y",e),n=t.getVariable(Te.CHANNEL,"innerRadius",e),a=t.getVariable(Te.CHANNEL,"outerRadius",e),o=t.getVariable(Te.CHANNEL,"startAngle",e),l=t.getVariable(Te.CHANNEL,"endAngle",e),h=t.getVariable(Te.CHANNEL,"angle",e),c=t.getVariable(Te.CHANNEL,"thickness",e);t.connect(i,r),t.connect(s,r),t.connect(n,r),t.connect(a,r),t.connect(o,r),t.connect(l,r),t.connect(h,r),t.connect(c,r);break}}r.run()}function it(e,t){let i=t.findVariablesByElement(e);for(let e in i){let r=i[e];for(let e of r)t.deleteVariable(e)}}function rt(e,t){let i=t.findVariable(Te.CHANNEL,[e.channel,e.element]);i||console.warn("cannot find encoding to remove from the dep graph");let r=i.incomingDataflow;t.deleteOperator(r)}function st(e,t){if(e.type===Vt.Axis){let i=t.findVariable(Te.PROPERTY,[et.AXIS_PATH_POSITION,e]).incomingDataflow;t.deleteOperator(i),i=t.findVariable(Te.PROPERTY,[et.AXIS_TICKS_POSITION,e]).incomingDataflow,t.deleteOperator(i),i=t.findVariable(Te.PROPERTY,[et.AXIS_LABELS_POSITION,e]).incomingDataflow,t.deleteOperator(i)}else if(e.type===Vt.Gridlines){let i=t.findVariable(Te.PROPERTY,[et.GRIDLINES_POSITION,e]).incomingDataflow;t.deleteOperator(i)}}function nt(e,t){if(t.findVariable(Te.BOUNDS,[e]))return;let i=t.getVariable(Te.BOUNDS,e),r=t.getVariable(Te.CHANNEL,"x",e),s=t.getVariable(Te.CHANNEL,"y",e),n=t.getVariable(Te.CHANNEL,"width",e),a=t.getVariable(Te.CHANNEL,"height",e),o=t.createOneWayDependency(z.EVAL_BBOX);t.connect(r,o),t.connect(s,o),t.connect(n,o),t.connect(a,o),t.connect(o,i),o.run()}function at(e,t){let i=t.getVariable(Te.BOUNDS,e),r=t.getVariable(Te.CHANNEL,"x",e),s=t.getVariable(Te.CHANNEL,"y",e),n=t.getVariable(Te.CHANNEL,"width",e),a=t.getVariable(Te.CHANNEL,"height",e),o=t.createOneWayDependency(z.EVAL_BBOX);t.connect(r,o),t.connect(s,o),t.connect(n,o),t.connect(a,o),t.connect(o,i),o.run()}function ot(e,t,i){let r=i.getVariable(Te.BOUNDS,e),s=i.getVariable(Te.BOUNDS,t),n=i.getIncomingDataflowOperator(z.EVAL_BBOX,r),a=s.outgoingEdges.find(e=>e.fromNode===s&&e.toNode===n);if(a&&i.disconnect(s,n,a),e.layout){let r=i.getVariable(Te.CHANNEL,"x",t),s=i.getIncomingDataflowOperator(ct(e.layout.type),r);s&&i.deleteOperator(s)}}function lt(e,t,i){let r=i.getVariable(Te.BOUNDS,e),s=i.getVariable(Te.BOUNDS,t),n=i.getIncomingDataflowOperator(z.EVAL_BBOX,r);i.connect(s,n),i.connect(n,r),e.layout&&ut(e,e.layout,i)}function ht(e,t){let i=t.getVariable(Te.BOUNDS,e),r=t.getVariable(Te.CHANNEL,"x",e),s=t.getVariable(Te.CHANNEL,"y",e),n=t.getIncomingDataflowOperator(z.EVAL_BBOX,i);t.connect(r,n),t.connect(s,n);for(let i of e.children)t.connect(t.getVariable(Te.BOUNDS,i),n);t.connect(n,i),n.run()}function ct(e){switch(e){case B.GRID:return z.GRID_LAYOUT;case B.STACK:return z.STACK_LAYOUT;case B.PACKING:return z.PACK_LAYOUT;case B.FORCE:return z.FORCE_LAYOUT;case B.DIRECTED:return z.DIRECTED_LAYOUT;case B.TIDYTREE:return z.TIDY_TREE_LAYOUT;case B.TREEMAP:return z.TREEMAP_LAYOUT;case B.STRATA:return z.STRATA_LAYOUT;case B.CIRCULAR:return z.CIRCULAR_LAYOUT;case B.CLUSTER:return z.CLUSTER_LAYOUT}}function dt(e,t,i){let r=i.getVariable(Te.PROPERTY,et.CHILDREN_ORDER,e),s=i.getOutgoingDataflowOperator(ct(t.type),r);i.deleteOperator(s)}function ut(e,t,i){let r=t?t.type:"none",s=r===B.TREEMAP?V(e)[0]:e.children[0];if(!s)return;let n=i.getVariable(Te.CHANNEL,"width",s),a=i.getVariable(Te.CHANNEL,"height",s),o=i.getVariable(Te.PROPERTY,et.CHILDREN_ORDER,e),l=i.getVariable(Te.CHANNEL,"x",s),h=i.getVariable(Te.CHANNEL,"y",s),c=i.getVariable(Te.CHANNEL,"visibility",s),d=i.getVariable(Te.PROPERTY,et.LAYOUT_PARAMETER,t),u=i.getOutgoingDataflowOperator(ct(r),o);if(i.connect(n,u),i.connect(a,u),i.connect(o,u),i.connect(d,u),i.connect(c,u),i.connect(u,l),i.connect(u,h),i.disconnectChannelVarFromBBoxOperator(n),i.disconnectChannelVarFromBBoxOperator(a),s.type===Vt.Arc||s.type===Vt.Pie){let e=i.getVariable(Te.CHANNEL,"angle",s),t=i.getVariable(Te.CHANNEL,"thickness",s);i.connect(e,u),i.connect(t,u)}else if(s.type===Vt.Circle){let e=i.getVariable(Te.CHANNEL,"area",s),t=i.getVariable(Te.CHANNEL,"radius",s);i.connect(e,u),i.connect(t,u),i.disconnectChannelVarFromBBoxOperator(e),i.disconnectChannelVarFromBBoxOperator(t)}else if(s.type===Vt.Rect){let e=i.getVariable(Te.CHANNEL,"area",s);i.connect(e,u),i.disconnectChannelVarFromBBoxOperator(e)}if(u.run(),s.links&&_t(s,i),s.children&&s.children[0]){let e=i.getVariable(Te.BOUNDS,s.children[0]),t=i.getVariable(Te.CHANNEL,"x",s).incomingDataflow;t&&i.connect(e,t),i.disconnectChannelVarFromBBoxOperator(e)}}function _t(e,t){let i=e.links[0],r=t.getVariable(Te.CHANNEL,"x",e),s=t.getVariable(Te.CHANNEL,"x",i),n=t.getVariable(Te.CHANNEL,"strokeWidth",i),a=t.getVariable(Te.CHANNEL,"strength",i),o=t.createOneWayDependency(z.LINK_PLACER);t.connect(r,o),t.connect(n,o),t.connect(a,o),t.connect(o,s)}function pt(e,t,i){let r=e.attribute,s=e.channel,n=e.element,a=t.createOneWayDependency(z.ENCODER);if(["width","height"].includes(e.channel)&&n.type===Vt.Area){let e=t.getVariable(Te.PROPERTY,et.BASE_LINE,n);t.connect(e,a)}if(i){let r=t.getVariable(Te.ATTR_VALUE,i),o=t.getVariable(Te.SCALE,i),l=t.getVariable(Te.CHANNEL,s,n);t.connect(o,a),t.connect(a,l),r.addLinkedEncoding(e),o.addLinkedEncoding(e),r.incomingDataflow.run()}else{let i=t.getVariable(Te.ATTRIBUTE,r,Bt(n)),o=t.getVariable(Te.PROPERTY,et.INCLUDE_ZERO,e),l=t.getVariable(Te.ATTR_VALUE,e),h=t.getVariable(Te.DATASCOPE,n),c=t.getVariable(Te.PROPERTY,et.TRANSFORM,e),d=t.createOneWayDependency(z.DATA_EXTRACTOR);t.connect(i,d),t.connect(o,d),t.connect(h,d),t.connect(c,d),t.connect(d,l),d.run();let u=t.getVariable(Te.PROPERTY,et.RANGE_START,e),_=t.getVariable(Te.PROPERTY,et.RANGE_EXTENT,e),p=t.getVariable(Te.PROPERTY,et.FLIP_SCALE,e),f=t.getVariable(Te.SCALE,e),g=t.createOneWayDependency(z.SCALE_BUILDER);t.connect(u,g),t.connect(_,g),t.connect(p,g),t.connect(l,g),t.connect(g,f),g.run();let y=t.getVariable(Te.CHANNEL,s,n);t.connect(f,a),t.connect(a,y),a.run()}}function ft(e,t){let i=t.getVariable(Te.PROPERTY,et.AXIS_ORIENTATION,e),r=t.getVariable(Te.BOUNDS,e.elements[0].parent),s=t.getVariable(Te.PROPERTY,et.AXIS_PATH_POSITION,e),n=t.createOneWayDependency(z.AXIS_PATH_PLACER);t.connect(i,n),t.connect(r,n),t.connect(n,s),n.run();let a=t.getVariable(Te.PROPERTY,et.AXIS_TICK_OFFSET,e),o=t.getVariable(Te.PROPERTY,et.AXIS_TICK_SIZE,e),l=t.createOneWayDependency(z.AXIS_TICKS_PLACER),h=t.getVariable(Te.PROPERTY,et.AXIS_TICKS_POSITION,e);t.connect(s,l),t.connect(a,l),t.connect(o,l),t.connect(l,h),l.run();let c=t.getVariable(Te.PROPERTY,et.AXIS_LABEL_OFFSET,e),d=t.getVariable(Te.PROPERTY,et.AXIS_LABEL_FORMAT,e),u=t.getVariable(Te.PROPERTY,et.AXIS_FONT_SIZE,e),_=t.createOneWayDependency(z.AXIS_LABELS_PLACER),p=t.getVariable(Te.PROPERTY,et.AXIS_LABELS_POSITION,e);t.connect(s,_),t.connect(c,_),t.connect(d,_),t.connect(u,_),t.connect(_,p),_.run();let f=t.getVariable(Te.PROPERTY,et.AXIS_TITLE_POSITION,e),g=t.createOneWayDependency(z.AXIS_TITLE_PLACER);t.connect(s,g),t.connect(g,f),g.run();let y=t.getVariable(Te.BOUNDS,e),m=t.getIncomingDataflowOperator(z.EVAL_BBOX,y);t.connect(h,m),t.connect(p,m),t.connect(m,y)}function gt(e,t){let i=t.getVariable(Te.PROPERTY,et.AXIS_ORIENTATION,e),r=t.getVariable(Te.BOUNDS,L(e.elements[0])),s=t.getVariable(Te.PROPERTY,et.AXIS_PATH_POSITION,e),n=t.createOneWayDependency(z.AXIS_PATH_PLACER);t.connect(i,n),t.connect(r,n),t.connect(n,s),n.run();let a=t.getVariable(Te.PROPERTY,et.AXIS_TICK_OFFSET,e),o=t.getVariable(Te.PROPERTY,et.AXIS_TICK_SIZE,e),l=t.createOneWayDependency(z.AXIS_TICKS_PLACER),h=t.getVariable(Te.PROPERTY,et.AXIS_TICKS_POSITION,e);t.connect(s,l),t.connect(a,l),t.connect(o,l),t.connect(l,h),l.run();let c=t.getVariable(Te.PROPERTY,et.AXIS_LABEL_OFFSET,e),d=t.getVariable(Te.PROPERTY,et.AXIS_LABEL_FORMAT,e),u=t.getVariable(Te.PROPERTY,et.AXIS_FONT_SIZE,e),_=t.createOneWayDependency(z.AXIS_LABELS_PLACER),p=t.getVariable(Te.PROPERTY,et.AXIS_LABELS_POSITION,e);t.connect(s,_),t.connect(c,_),t.connect(d,_),t.connect(u,_),t.connect(_,p),_.run();let f=t.getVariable(Te.PROPERTY,et.AXIS_TITLE_POSITION,e),g=t.createOneWayDependency(z.AXIS_TITLE_PLACER);t.connect(s,g),t.connect(g,f),g.run();let y=t.getVariable(Te.BOUNDS,e),m=t.getIncomingDataflowOperator(z.EVAL_BBOX,y);t.connect(h,m),t.connect(p,m),t.connect(m,y)}function yt(e,t){let i=t.getVariable(Te.BOUNDS,L(e.elements[0])),r=t.getVariable(Te.PROPERTY,et.GRIDLINES_POSITION,e),s=t.createOneWayDependency(z.GRIDLINES_PLACER);t.connect(i,s),t.connect(s,r),s.run();let n=t.getVariable(Te.BOUNDS,e),a=t.getIncomingDataflowOperator(z.EVAL_BBOX,n);t.connect(r,a),t.connect(a,n)}class mt{constructor(){this._id=this.type+Mt(),this._type=Vt.Group,this._dataScope=void 0,this._bounds=void 0,this._layout=void 0,this._children=[],this._sortBy={property:Gt,descending:!1}}get id(){return this._id}get type(){return this._type}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],i=this.getScene(),r=Object.keys(i.encodings),s=[];for(;t;){if(t.classId&&s.indexOf(t.classId)<0&&s.push(t.classId),t.type===Vt.Glyph){t.children.forEach(e=>s.push(e.classId));break}if(!t.children)break;t=t.children[0]}let n=[];for(let t of r){let r=t.split("_");for(let a of s)r[0]==a&&i.encodings[t][e]&&n.push(i.encodings[t][e])}return n}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=V(this,!0);for(let t of e)this.scene.onChange(Te.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)),i=Math.min(...e.map(e=>e.top)),r=Math.max(...e.map(e=>e.right)),s=Math.max(...e.map(e=>e.bottom));return new g(t,i,r-t,s-i)}get x(){return this.bounds.x}get y(){return this.bounds.y}_updateBounds(){let e=this.children;if(e.length>0){this._bounds=e[0].bounds.clone();for(let t=1;t<e.length;t++)"hidden"!=e[t].visibility&&(this._bounds=this._bounds.union(e[t].bounds))}else this._bounds=new g(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 N(this)}get sortBy(){return this._sortBy}}class bt extends mt{constructor(){super(),this._type=Vt.Collection,this._id=this.type+"_"+Mt(),this._classId=this.id,this._childrenOrder=void 0,this._clipMask=void 0}get classId(){return this._classId}getSVGPathData(){let e="";for(let t of this.children)if(t.getSVGPathData)e+=t.getSVGPathData();else if(t.bounds){let i=t.bounds;e+=["M",i.left,i.top].join(" "),e+=["L",i.right,i.top].join(" "),e+=["L",i.right,i.bottom].join(" "),e+=["L",i.left,i.bottom,"Z"].join(" ")}return e}createClipMask(){let e=m(this._children);this._clipMask=new g(e.left,e.top,e.width,e.height)}get clipMask(){return this._clipMask}}class xt extends mt{constructor(e){if(super(),this._type=Vt.Glyph,this._id=this.type+"_"+Mt(),this._classId=this._id,e)for(let t of e)this.addChild(t)}get classId(){return this._classId}}class vt extends ee{constructor(e){super(e),this._type=Vt.BezierCurve,this._orientation="orientation"in e?e.orientation:H}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 wt extends w{constructor(e){super(e),this._type=Vt.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,this._dirty=!0}get area(){return Math.PI*Math.pow(this._radius,2)}_updateBounds(){if(this._rotate){let e=u(this._x,this._y,this._rotate[1],this._rotate[2],this._rotate[0]);this._bounds=new g(e.x-this._radius,e.y-this._radius,2*this._radius,2*this._radius)}else this._bounds=new g(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 Et extends w{constructor(e){super(e),this._type=Vt.Image,this._src=e.src,this._x="x"in e?e.x:0,this._y="y"in e?e.y:0,this._width="width"in e?e.width:100,this._height="height"in e?e.height:100}get src(){return this._src}set src(e){this._src=e,this._dirty=!0}get width(){return this._width}set width(e){this._width=e,this._updateBounds(),this._dirty=!0}get height(){return this._height}set height(e){this._height=e,this._updateBounds(),this._dirty=!0}resize(e,t){this._width=e,this._height=t,this._dirty=!0,this._updateBounds()}get x(){return this._x}set x(e){this._x=e,this._dirty=!0,this._updateBounds()}get y(){return this._y}set y(e){this._y=e,this._dirty=!0,this._updateBounds()}get bounds(){return this._bounds||this._updateBounds(),this._bounds}_updateBounds(){this._bounds=new g(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 At extends ee{constructor(e){super(e)}get x1(){return this.vertices[0].x}get y1(){return this.vertices[0].y}get x2(){return this.vertices[1].x}get y2(){return this.vertices[1].y}get x(){return(this.vertices[0].x+this.vertices[1].x)/2}get y(){return(this.vertices[0].y+this.vertices[1].y)/2}set x(e){let t=e-this.x;this.vertices[0]._x+=t,this.vertices[1]._x+=t,this._dirty=!0}set y(e){let t=e-this.y;this.vertices[0]._y+=t,this.vertices[1]._y+=t,this._dirty=!0}set x1(e){this.vertices[0]._x=e,this._dirty=!0}set x2(e){this.vertices[1]._x=e,this._dirty=!0}set y1(e){this.vertices[0]._y=e,this._dirty=!0}set y2(e){this.vertices[1]._y=e,this._dirty=!0}}class Ct extends w{constructor(e){super(e),this._type=Vt.SimpleText,this._x="x"in e?e.x:0,this._y="y"in e?e.y:0,this._text="text"in e?e.text:"",this._anchor="anchor"in e?e.anchor:[v.CENTER,v.MIDDLE],this._textPath=void 0,this._textPathOffset="50%","fontSize"in this.styles||(this.styles.fontSize="12px"),"fontFamily"in this.styles||(this.styles.fontFamily="Arial, sans-serif"),"fontWeight"in this.styles||(this.styles.fontWeight="normal"),"fillColor"in this.styles||(this.styles.fillColor="black"),"backgroundColor"in e&&(this._backgroundColor=e.backgroundColor),"borderWidth"in e&&(this._borderWidth=e.borderWidth),"borderColor"in e&&(this._borderColor=e.borderColor),this._rotate="rotate"in e?e.rotate:void 0}hasBackground(){return this._backgroundColor||this._borderStroke||this._borderColor}_updateBounds(){let e,t,i=function(e,t,i){const r=d.getSVG(),s=document.createElementNS("http://www.w3.org/2000/svg","text");s.setAttribute("font-family",t),s.setAttribute("font-size",i),s.textContent=e,r.appendChild(s);const n=s.getBBox();return r.removeChild(s),{width:n.width,height:n.height}}(this._text,[this.fontWeight,this.fontSize,this.fontFamily].join(" "),parseFloat(this.fontSize)),r=i.width,s=i.height;switch(this._anchor[0]){case v.LEFT:e=this._x;break;case v.RIGHT:e=this._x-r;break;case v.CENTER:e=this._x-r/2;break;default:e=this._x}switch(this._anchor[1]){case v.TOP:t=this._y;break;case v.BOTTOM:t=this._y-s;break;case v.MIDDLE:default:t=this._y-s/2}if(this._rotate&&3===this._rotate.length){let i=[{x:e,y:t},{x:e+r,y:t},{x:e,y:t+s},{x:e+r,y:t+s}].map(e=>u(e.x,e.y,this._rotate[1],this._rotate[2],this._rotate[0])),n=Math.min(...i.map(e=>e.x)),a=Math.max(...i.map(e=>e.x)),o=Math.min(...i.map(e=>e.y)),l=Math.max(...i.map(e=>e.y));this._bounds=new g(n,o,a-n,l-o)}else this._bounds=new g(e,t,r,s)}get x(){return this._x}set x(e){this._x=e,this._dirty=!0}get y(){return this._y}set y(e){this._y=e,this._dirty=!0}get text(){return this._text}set text(e){this._text=e,this._dirty=!0}get anchor(){return this._anchor}get fontFamily(){return this.styles.fontFamily}get fontSize(){return this.styles.fontSize}get fontWeight(){return this.styles.fontWeight}get textPath(){return this._textPath}set textPath(e){this._textPath=e,this._dirty=!0}get textPathOffset(){return this._textPathOffset}set textPathOffset(e){this._textPathOffset=e,this._dirty=!0}get backgroundColor(){return this._backgroundColor?this._backgroundColor:"#fff"}get borderColor(){return this._borderColor?this._borderColor:"#ccc"}get borderWidth(){return this._borderWidth?this._borderWidth:1}copyPropertiesTo(e){e.styles=Object.assign({},this.styles),this._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 kt extends ee{constructor(e){super(e),this._type=Vt.Polygon,this.closed=!0,"x"in e&&(this._x=e.x),"y"in e&&(this._y=e.y),"radius"in e&&(this._radius=e.radius)}get radius(){return this._radius}get x(){return this._x}get y(){return this._y}set x(e){this._x=e,this._dirty=!0}set y(e){this._y=e,this._dirty=!0}set radius(e){this._radius=e,this._dirty=!0}copyPropertiesTo(e){super.copyPropertiesTo(e),e._x=this._x,e._y=this._y,e._radius=this._radius}}class St extends ee{constructor(e){super(e),this._type=Vt.Ring,this.closed=!0,this._x="x"in e?e.x:0,this._y="y"in e?e.y:0,this._innerRadius="innerRadius"in e?e.innerRadius:100,this._outerRadius="outerRadius"in e?e.outerRadius:200}get innerRadius(){return this._innerRadius}get outerRadius(){return this._outerRadius}get x(){return this._x}get y(){return this._y}get thickness(){return this._outerRadius-this._innerRadius}copyPropertiesTo(e){super.copyPropertiesTo(e),e._x=this._x,e._y=this._y,e._innerRadius=this._innerRadius,e._outerRadius=this._outerRadius}getSVGPathData(){return["M "+this._x+" "+this._y,"m 0, -"+this._outerRadius,"a "+this._outerRadius+","+this._outerRadius+", 0, 1, 0, 1, 0","Z","m 0 "+(this._outerRadius-this._innerRadius),"a "+this._innerRadius+", "+this._innerRadius+", 0, 1, 1, -1, 0","Z"].join(" ")}}class Tt extends w{constructor(e){super(e),this._type=Vt.RichText,this._x="x"in e?e.x:0,this._y="y"in e?e.y:0,this._text="text"in e?e.text:"",this._width="width"in e?e.width:200,this._anchor="anchor"in e?e.anchor:[v.CENTER,v.MIDDLE],"fontSize"in this.styles||(this.styles.fontSize="12px"),"fontFamily"in this.styles||(this.styles.fontFamily="Arial, sans-serif"),"fontWeight"in this.styles||(this.styles.fontWeight="normal"),"fillColor"in this.styles||(this.styles.fillColor="black"),"backgroundColor"in e&&(this._backgroundColor=e.backgroundColor),"borderWidth"in e&&(this._borderWidth=e.borderWidth),"borderColor"in e&&(this._borderColor=e.borderColor),this._rotate="rotate"in e?e.rotate:void 0}hasBackground(){return this._backgroundColor||this._borderStroke||this._borderColor}_updateBounds(){let e,t,i=function(e,t,i){const r=d.getSVG(),s=document.createElementNS("http://www.w3.org/2000/svg","text");s.setAttribute("font-family",t),s.setAttribute("font-size",i),s.textContent=e,r.appendChild(s);const n=s.getBBox();return r.removeChild(s),{width:n.width,height:n.height}}(this._text,[this.fontWeight,this.fontSize,this.fontFamily].join(" "),parseFloat(this.fontSize)),r=i.width,s=i.height;switch(this._anchor[0]){case v.LEFT:e=this._x;break;case v.RIGHT:e=this._x-r;break;case v.CENTER:e=this._x-r/2;break;default:e=this._x}switch(this._anchor[1]){case v.TOP:t=this._y;break;case v.BOTTOM:t=this._y-s;break;case v.MIDDLE:default:t=this._y-s/2}if(this._rotate&&3===this._rotate.length){let i=[{x:e,y:t},{x:e+r,y:t},{x:e,y:t+s},{x:e+r,y:t+s}].map(e=>u(e.x,e.y,this._rotate[1],this._rotate[2],this._rotate[0])),n=Math.min(...i.map(e=>e.x)),a=Math.max(...i.map(e=>e.x)),o=Math.min(...i.map(e=>e.y)),l=Math.max(...i.map(e=>e.y));this._bounds=new g(n,o,a-n,l-o)}else this._bounds=new g(e,t,r,s)}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}set textPath(e){this._textPath=e,this._dirty=!0}get textPathOffset(){return this._textPathOffset}set textPathOffset(e){this._textPathOffset=e,this._dirty=!0}get backgroundColor(){return this._backgroundColor?this._backgroundColor:"#fff"}get borderColor(){return this._borderColor?this._borderColor:"#ccc"}get borderWidth(){return this._borderWidth?this._borderWidth:1}get width(){return this._width}copyPropertiesTo(e){e.styles=Object.assign({},this.styles),this._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}}function Rt(e){let t=null;switch(e.type){case Vt.Circle:t=new wt(e);break;case Vt.Line:var i="x1"in e?e.x1:0,r="y1"in e?e.y1:0,s="x2"in e?e.x2:100,n="y2"in e?e.y2:100;e.vertices=[[i,r],[s,n]],t=new At(e);break;case Vt.Rect:var a="top"in e?e.top:0,o="left"in e?e.left:0,l="width"in e?e.width:50,h="height"in e?e.height:30;e.vertices=[[o,a],[o+l,a],[o+l,a+h],[o,a+h]],t=new Ye(e);break;case Vt.SimpleText:t=new Ct(e);break;case Vt.RichText:t=new Tt(e);break;case Vt.Image:t=new Et(e);break;case Vt.BundledPath:case Vt.Chord:case Vt.Path:t=new ee(e);break;case Vt.Area:t=new Xe(e);break;case Vt.Ring:t=new St(e);break;case Vt.Arc:t=new ne(e);break;case Vt.BezierCurve:"vertices"in e||(e.vertices=[[0,100],[20,120],[80,180],[100,200]]),t=new vt(e);break;case Vt.Polygon:t=new kt(e)}return t&&t._updateBounds(),t}function Ot(e){let t=new bt;return e.addChild(t),e._itemMap[t.id]=t,t}function It(e){return new xt(e)}function Nt(e){switch(e.type){case Vt.Collection:return function(e){let t=Ot(e.scene);for(let i=0;i<e.children.length;i++){let r=e.children[i];t.addChild(Nt(r))}if(t._classId=e.classId,e._layout){let i=e._layout.clone();t._layout=i,i.group=t}return t._updateBounds(),t}(e);case Vt.Glyph:return function(e){let t=new xt;for(let i of e.children)t.addChild(Nt(i));t._classId=e.classId,e._dataScope&&(t.dataScope=e._dataScope.clone());return t}(e);default:return function(e){let t=Rt({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 i=0;i<e.vertices.length;i++)e.vertices[i].dataScope&&(t.vertices[i]._dataScope=e.vertices[i].dataScope.clone());return t}(e)}}const Lt=Object.freeze({Rect:"rect",Circle:"circle",Line:"line",Ring:"ring",Path:"path",Image:"image",SimpleText:"text",RichText:"richText",Arc:"arc",BezierCurve:"bezierCurve",BundledPath:"bundledPath",Chord:"chord"}),Vt=Object.freeze({Area:"area",Rect:"rect",Ellipse:"ellipse",Circle:"circle",Pie:"pie",Ring:"ring",Arc:"arc",BezierCurve:"bezierCurve",BundledPath:"bundledPath",Chord:"chord",Line:"line",Path:"path",Image:"image",SimpleText:"text",RichText:"richText",Collection:"collection",Group:"group",Composite:"composite",Scene:"scene",Axis:"axis",Glyph:"glyph",Legend:"legend",Polygon:"polygon",Gridlines:"gridlines",LinearGradient:"LinearGradient",Link:"link",DataTable:"datatable",Layout:"layout",NetworkData:"networkdata",TreeData:"treedata"}),Pt=Object.freeze({Axis:"axis",Legend:"legend",Gridlines:"gridlines"});function Mt(){return Date.now().toString(36)+"_"+Math.random().toString(36).slice(2)}class Dt{constructor(e,t,i){this._id=Vt.DataTable+Mt(),this.initialize(e,t,i)}initialize(e,t,i){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,i)this._attrTypes=i;else{this._attrTypes={};for(let e of this._attributes)this._attrTypes[e]=ve(this.data.map(t=>t[e])),"year"==e.toLowerCase()&&this._attrTypes[e]==xe.Integer&&(this._attrTypes[e]=xe.Date)}this._validate(this.data,this._attrTypes),this._attrSummaries={};for(let e of this._attributes)this._attrSummaries[e]=Ee(this.data.map(t=>t[e]),this._attrTypes[e]);this._attributes.indexOf(Gt)<0&&this._addAttribute(Gt,xe.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 Dt(e,this.url,Object.assign({},this._attrTypes));return t.sourceDataTable=this,t}get id(){return this._id}get name(){return this.url?function(e){var t=e.indexOf("\\")>=0?e.lastIndexOf("\\"):e.lastIndexOf("/"),i=e.substring(t);0!==i.indexOf("\\")&&0!==i.indexOf("/")||(i=i.substring(1));return i}(this.url):this.id}get data(){return this._data}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,i){this._data.forEach((t,r)=>t[e]=i[r]),e!==Gt&&this._rawData.forEach((t,r)=>t[e]=i[r]),this._attrTypes[e]=t,this._attributes.push(e),this._attrSummaries[e]=Ee(i,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(e,t){let i=r.timeParse(t);for(let t of this.data){let r=t[e];null==r||null==r?(r="",t[e]=new Date(1899,11,31).getTime()):t[e]=i(r).getTime(),this._dateMap.set(t[e],r)}this._attrTypes[e]=xe.Date,this._attrSummaries[e]=Ee(this.data.map(t=>t[e]),xe.Date)}getRawValue(e,t){return this.getAttributeType(e)===xe.Date?this._dateMap.get(t).toString():t}get nonNumericAttributes(){let e=[];for(let t in this._attrTypes)this._attrTypes[t]!=xe.Number&&this._attrTypes[t]!=xe.Integer&&t!=Dt.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]!==xe.Number&&this._attrTypes[t]!==xe.Integer||t==Dt.RowID||e.push(t);return e}getAttributesByType(e){let t=[];for(let i in this._attrTypes)this._attrTypes[i]===e&&i!=Dt.RowID&&t.push(i);return t}summarize(){for(let e of this._attributes)this._attrSummaries[e]=Ee(this.data.map(t=>t[e]),this._attrTypes[e])}_validate(e,t){for(let i of e)for(let e in t){let r,s=t[e],n=i[e];if(null==i[e]||null==i[e])switch(s){case xe.Boolean:r=!1;break;case xe.Date:r=new Date(1899,11,31).getTime();break;case xe.String:r="";break;default:r=0}else switch(s){case xe.Boolean:r=n;break;case xe.Date:r=Number.isInteger(n)?new Date(n,0).getTime():new Date(n+"").getTime(),this._dateMap.set(r,n);break;case xe.String:r=n.toString();break;default:r=n}i[e]=r}}}function Bt(e){let t=de(e);if(t)return t.dataTable}const Gt="mascot_rowId";function Ft(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 zt extends Se{constructor(e,t){super(e),this._elem=t}get element(){return this._elem}}class jt extends Se{constructor(e,t){super(e),this._item=t}get element(){return this._item}}class Wt{constructor(e){this._id=e+"_"+Mt(),this._type=e,this._vars=[],this._edges=[]}get vars(){return this._vars}get edges(){return this._edges}run(){console.log("-",this._type)}}class Ut{constructor(e,t,i=!0){this._id="e_"+Mt(),this._fromNode=e,this._toNode=t,this._isDirected=i}get id(){return this._id}get fromNode(){return this._fromNode}get toNode(){return this._toNode}get isDirected(){return this._isDirected}get operator(){return this._fromNode instanceof F||this._fromNode instanceof Wt?this._fromNode:this._toNode}}class Ht extends Se{constructor(e,t,i){super(e),this._attribute=t,this._dataset=i}get attribute(){return this._attribute}get dataset(){return this._dataset}}class Yt{constructor(e,t){switch(this._id="scale_"+Mt(),this._type=e,t&&(this._args=t),e){case"linear":this._scale=r.scaleLinear();break;case"point":this._scale=r.scalePoint();break;case"ordinal":this._scale=r.scaleOrdinal();break;case"ordinalColor":this._scale=r.scaleOrdinal(r[t.scheme]);break;case"power":this._scale=r.scalePow().exponent(2);break;case"sqrt":this._scale=r.scalePow().exponent(.5);break;case"log":this._scale=r.scaleLog();break;case"identity":case"time":this._scale=r.scaleTime();break;case"sequentialColor":t.scheme?this._scale=r.scaleSequential(r[t.scheme]):this._scale=r.scaleSequential()}}get id(){return this._id}get domain(){return this._scale.domain()}set domain(e){this._scale.domain(e)}get range(){return this._scale.range()}set range(e){this._scale.range(e)}get rangeExtent(){let e=this._scale.range();return Math.abs(e[1]-e[0])}set rangeExtent(e){let t=this._scale.range();t[0]<t[1]?this._scale.range([t[0],t[0]+e]):this._scale.range([t[1]+e,t[1]])}get type(){return this._type}map(e){return this._scale(e)}invert(e,t){let i=Math.min(...this._scale.range()),r=Math.max(...this._scale.range()),s=e;return t||(s=Math.max(i,Math.min(e,r))),"time"===this._type?this._scale.invert(s).getTime():this._scale.invert(s)}}const Xt=["schemeBrBG","schemePRGn","schemePiYG","schemePuOr","schemeRdBu","schemeRdGy","schemeRdYlBu","schemeRdYlGn","schemeSpectral"],qt=["schemeBlues","schemeGreens","schemeGreys","schemeOranges","schemePurples","schemeReds","schemeBuGn","schemeBuPu","schemeGnBu","schemeOrRd","schemePuBuGn","schemePuBu","schemePuRd","schemeRdPu","schemeYlGnBu","schemeYlGn","schemeYlOrBr","schemeYlOrRd"];class Kt{constructor(){this._map={}}clear(){this._map={}}setValue(e,t){this._map[e]=t}getValue(e){return this._map[e]}}class Zt extends Se{constructor(e,t){super(e),this._encs=[t],this._valueMap=new Kt}addLinkedEncoding(e){this._encs.push(e)}get encodings(){return this._encs}get attrValues(){return this._valueMap}set attrValues(e){this._valueMap=e}}class $t extends F{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof Zt),t=this.outputVar,i=t.encodings,r=i[0],s=r.channel,n=r.attribute,a=e.encodings[0].dataTable.getAttributeType(e.encodings[0].attribute),o=Object.values(e.attrValues);if("angle"===r.channel&&[Vt.Arc,Vt.Pie].indexOf(r.element.type)>=0)for(let t of e.encodings)for(let e of t.scales){let i=t.getElements(e).map(e=>t.attrValues[e.id]);e.domain=r._preferredDomain?r._preferredDomain:t.dataTable.tree?[0,t.dataTable.tree.getRoot()[n]]:this._getDomainForNumbers(i),console.log("domain for",n,e.domain)}else{let t;t=r._preferredDomain?r._preferredDomain:a==xe.String||"text"===e.encodings[0].channel?this._getDomainForStrings(o):this._getDomainForNumbers(o);for(let i of e.encodings)for(let e of i.scales)e.domain=t.slice()}for(let e=0;e<r.scales.length;e++){let n=r.scales[e],a=r.getElements(n),o=this._buildRange(s,a,r,t);if(o)for(let t of i)t.scales[e].range=o}t.initialized=!0}_getDomainForNumbers(e){let t=this.outputVar.encodings[0],i=[Math.min(...e),Math.max(...e)];if(t.includeZero&&i[0]>0&&(i=[0,Math.max(...e)]),t.mapping)i=Object.keys(t.mapping),i=i.map(e=>parseFloat(e)),i.sort((e,t)=>e-t);else if("sequentialColor"===t.scales[0].type){if(i[0]<0&&i[1]>0){let e=Math.max(Math.abs(i[0]),Math.abs(i[1]));i=[-e,e]}}else if("angle"===t.channel){i=[0,Object.values(e).reduce((e,t)=>e+t,0)]}return i}_getDomainForStrings(e){let t,i=this.outputVar,r=i.encodings[0];return t="count"==i.encodings[0].aggregator?[0,Math.max(...e)]:Array.from(new Set(e)),r.mapping&&(t=Object.keys(r.mapping)),t}_buildRange(e,t,i,r){return"x"===e?this._buildXRange(t,i,r):"y"===e?this._buildYRange(t,i,r):["width","height","radius","area","fontSize","radialDistance","strokeWidth"].includes(e)?this._buildSizeRange(t,i,r):e.indexOf("Color")>0||"fillGradient"===e?this._buildColorRange(t,i):"angle"===e?this._buildAngleRange(t,i):"thickness"===e?this._buildThicknessRange(t,i,r):"src"===e?i.scales[0].domain.slice():void 0}_buildThicknessRange(e,t,i){let r=e.map(e=>e.outerRadius-e.innerRadius);return[0,i.initialized?t.getRangeExtent(e[0]):t._preferredRangeExtent?t._preferredRangeExtent:Math.max(...r)]}_buildAngleRange(e,t){return[0,360]}_buildColorRange(e,t){if(t.mapping){return t.scales[0].domain.map(e=>t.mapping[e+""])}if("sequentialColor"===t.scales[0].type){let e=this.outputVar,i=t.scales[0].domain;for(let s of e.encodings)if(!t.colorScheme)for(let e of s.scales){let t=e.domain;e._scale=r.scaleSequential(i[0]<0&&i[1]>0?r.interpolatePuOr:r.interpolateTurbo),e._scale.domain(t)}}if((Xt.indexOf(t.colorScheme)>=0||qt.indexOf(t.colorScheme)>=0)&&"ordinalColor"===t.scales[0].type){let e=this.outputVar,i=t.scales[0].domain;for(let s of e.encodings)for(let e of s.scales){let s=e.domain;e._scale=r.scaleOrdinal(r[t.colorScheme][i.length]),e._scale.domain(s)}}}_buildSizeRange(e,t,i){let r,s;return r=0,s=i.initialized?t.getRangeExtent(e[0]):t._preferredRangeExtent?t._preferredRangeExtent:Math.max(...e.map(e=>"radius"===t.channel?e.refBounds.width/2:"strokeWidth"===t.channel?e.strokeWidth:"radialDistance"===t.channel?e.parent.radius:"area"===t.channel?e.type===Vt.Circle?Math.PI*Math.pow(e.radius,2):e.width*e.height:"fontSize"===t.channel?parseFloat(e.fontSize):e.refBounds[t.channel])),[0,0+s]}_buildXRange(e,t,i){let r,s;switch(t.scales[0].type,e[0].type){case"vertex":case"segment":var n=e[0].parent.refBounds?e[0].parent.refBounds:e[0].parent.bounds;r=i.initialized?t.getRangeStart(e[0]):n.left,s=i.initialized?t.getRangeExtent(e[0]):t._preferredRangeExtent?t._preferredRangeExtent:n.width;break;default:r=i.initialized?t.getRangeStart(e[0]):t._preferredRangeStart?t._preferredRangeStart:L(e[0]).bounds.left+e[0].bounds.width/2,s=i.initialized?t.getRangeExtent(e[0]):t._preferredRangeExtent?t._preferredRangeExtent:Math.max(450,Math.max(...e.map(e=>e.bounds.x))-Math.min(...e.map(e=>e.bounds.x)))}return t.flipScale?[r+s,r]:[r,r+s]}_buildYRange(e,t,i){let r,s;switch(t.scales[0].type,e[0].type){case"vertex":case"segment":var n=e[0].parent.refBounds?e[0].parent.refBounds:e[0].parent.bounds;r=i.initialized?t.getRangeStart(e[0]):n.top,s=i.initialized?t.getRangeExtent(e[0]):t._preferredRangeExtent?t._preferredRangeExtent:n.height;break;default:r=i.initialized?t.getRangeStart(e[0]):L(e[0]).bounds.top+e[0].bounds.height/2,s=i.initialized?t.getRangeExtent(e[0]):t._preferredRangeExtent?t._preferredRangeExtent:450}return t.flipScale?[r,r+s]:[r+s,r]}}class Jt extends F{constructor(e){super(e)}run(){super.run()}}class Qt extends mt{constructor(e){super(),this._type=Vt.Axis,this._id=e.id?e.id:this._type+Mt(),this._attribute=void 0,this._channel=void 0,this._orientation=void 0,this._strokeColor="strokeColor"in e?e.strokeColor:"#555",this._textColor="textColor"in e?e.textColor:"#555",this._fontSize="fontSize"in e?e.fontSize:"12px",this._tickOffset="tickOffset"in e?e.tickOffset:0,this._tickSize="tickSize"in e?e.tickSize:5,this._tickAnchor=e.tickAnchor,this._tickVisible=!("tickVisible"in e)||e.tickVisible,this._pathVisible=!("pathVisible"in e)||e.pathVisible,this._labelVisible=!("labelVisible"in e)||e.labelVisible,this._labelOffset="labelOffset"in e?e.labelOffset:this._tickSize+this._tickOffset+3,this._labelFormat="labelFormat"in e?e.labelFormat:"",this._titleOffset="titleOffset"in e?e.titleOffset:40,this._rotateYTitle=!("rotateTitle"in e&&!e.rotateTitle),this._showTitle=!("titleVisible"in e)||e.titleVisible,this._labelRotation="labelRotation"in e?e.labelRotation:0,this._ticks=new mt,this._ticks._id=this._id+"_ticks",this.addChild(this._ticks),this._labels=new mt,this._labels._id=this._id+"_labels",this.addChild(this._labels),this._title=new Ct({text:this._titleText,fillColor:this._textColor,fontWeight:"bold"}),this._title._id=this.id+"_title",this.addChild(this._title),this._showTitle||(this._title.visibility="hidden"),this._pathPos=void 0,this._args=e}get id(){return this._id}get 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!==Vt.SimpleText),t=e[0].bounds.clone();for(let i=1;i<e.length;i++)"hidden"!=e[i].visibility&&(t=t.union(e[i].bounds));return t}}const ei="top",ti="bottom",ii="left";function ri(e,t,i,s){let n,a=e.domain,o=e.range;switch(e.type){case"linear":case"log":{let l=Math.abs(o[0]-o[1]);n="width"==t||"x"==t?45:30;let h,c=Math.max(2,Math.floor(l/n));if("width"==t||"height"==t){let r=!!s&&(s.elements[0].parent.layout&&s.elements[0].parent.layout.type==B.STACK);a[1]=e._scale.invert(r?b(i)[t]:m(i)[t])}if("log"===e.type){h=[];let t=e._scale.ticks();for(let e of t){let i=Math.log(e)/Math.log(10)+1e-6;Math.abs(i-Math.floor(i))<c/t.length&&h.push(e)}}else h=r.ticks(a[0],a[1],c);return h}case"point":{n="width"==t||"x"==t?80:30;let i=Math.floor(e.rangeExtent/a.length),r=Math.ceil(n/i);return"x"==t?a.filter((e,t)=>t%r==0):a}case"time":{n="width"==t||"x"==t?80:30;let e,i,s=Math.floor((o[1]-o[0])/n),l=Math.ceil((a[1]-a[0])/s)/1e3,h=[1,60,3600,86400,2628003,31536e3],c=[r.timeSeconds,r.timeMinutes,r.timeHours,r.timeDays,r.timeMonths,r.timeYears];for(let t=0;t<h.length-1;t++)if(l>=h[t]&&l<h[t+1])return e=Math.floor(l/h[t]),i=c[t],i(a[0],a[1],e);return l>h[h.length-1]?(e=Math.floor(l/h[h.length-1]),i=c[h.length-1],i(a[0],a[1],e)):[]}default:return[]}}function si(e,t){t.removeChild(e)}class ni extends Qt{constructor(e,t,i,r){super(r),this._encoding=e,this._attribute=this._encoding.attribute,this._channel=this._encoding.channel,this._scale=t,this._elems=i,this._flip="flip"in r&&r.flip,this._posArg="x"==this._channel||"width"==this._channel?r.pathY:r.pathX,this._orientation="orientation"in r?r.orientation:"x"===this._channel||"width"==this._channel?ti:ii,this._titleText="title"in r?r.title:this._encoding.attribute,this._path="angle"===this._channel?new wt({strokeColor:this._strokeColor,id:this._id+"_path"}):new ee({strokeColor:this._strokeColor,id:this._id+"_path"}),this._pathVisible||(this._path.visibility="hidden"),this.addChild(this._path),this.createTicksLabels(r),e.dataTable.getAttributeType(this._attribute)!==xe.Date||"labelFormat"in r||(this._labelFormat="%m/%d/%y"),"radialDistance"===this._channel&&"rotation"in r&&(this._rotate=[-r.rotation,this._elems[0].parent.x,this._elems[0].parent.y])}isFlipped(){return this._flip}get elements(){return this._elems}get scale(){return this._scale}get encoding(){return this._encoding}createTicksLabels(e){"tickValues"in e?(this._tickValues=e.tickValues,this._labelValues=e.tickValues):(this._tickValues=ri(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 ee({strokeColor:this._strokeColor,id:this._id+"_tick"+e});this._tickVisible||(t.visibility="hidden"),this._ticks.addChild(t)}let t;switch(this._labels.removeAll(),this._encoding.dataTable.getAttributeType(this._attribute)){case xe.Date:t=r.utcFormat(this._labelFormat);break;case xe.String:t=function(e){return e};break;default:t=r.format(this._labelFormat)}for(let[e,i]of this._labelValues.entries()){let r=new Ct({text:t(i),fontSize:this._fontSize,fillColor:this._textColor,id:this._id+"_label"+e});this._labelVisible||(r.visibility="hidden"),this._labels.addChild(r)}this._title._text=this._titleText}}class ai extends Qt{constructor(e,t,i,r){super(r),this._elems=e,this._attribute=i,this._channel=t,this._posArg="x"==this._channel||"width"==this._channel?r.pathY:r.pathX,this._labelAttribute=r.labelAttribute,this._orientation="orientation"in r?r.orientation:"x"===this._channel||"width"==this._channel?ti:ii,this._titleText="title"in r?r.title:this._attribute,this._path="angle"===this._channel?new wt({strokeColor:this._strokeColor,id:this._id+"_path"}):new ee({strokeColor:this._strokeColor,id:this._id+"_path"}),this._pathVisible||(this._path.visibility="hidden"),this.addChild(this._path),this.createTicksLabels(r),this._elems[0].dataScope.dataTable.getAttributeType(this._attribute)!==xe.Date||"labelFormat"in r||(this._labelFormat="%m/%d/%y")}get elements(){if(this.layout.type===B.CLUSTER){const e=new Map(this._elems.map(e=>[e.dataScope.getAttrVal(me),e]));return this.layout._d3Root.leaves().map(t=>e.get(t.data[me]))}return this._elems}get layout(){return this._elems[0].parent.layout}createTicksLabels(e){"tickValues"in e?(this._tickValues=e.tickValues,this._labelValues=e.tickValues):(this._tickValues=this.elements.map(e=>e.dataScope.getAttrVal(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 ee({strokeColor:this._strokeColor,id:this._id+"_tick"+e});this._tickVisible||(t.visibility="hidden"),this._ticks.addChild(t)}let t;switch(this._labels.removeAll(),this._elems[0].dataScope.dataTable.getAttributeType(this._labelAttribute?this._labelAttribute:this._attribute)){case xe.Date:t=r.timeFormat(this._labelFormat);break;case xe.String:t=function(e){return e};break;default:t=r.format(this._labelFormat)}for(let[e,i]of this._labelValues.entries()){let r=new Ct({text:t(i),fontSize:this._fontSize,fillColor:this._textColor,id:this._id+"_label"+e});this._labels.addChild(r)}this._title._text=this._titleText}}class oi extends F{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof $e&&e.property==et.AXIS_ORIENTATION).element;e.createTicksLabels(e._args),e instanceof ni?this._runForEncoding(e):e instanceof ai&&this._runForLayout(e),x(e._path)}_runForLayout(e){let t=e.channel,i=e.elements[0].parent.layout&&e.elements[0].parent.layout.type==B.STACK?b(e.elements):m(e.elements),r=[];if("x"===t){let t=e.orientation===ei?i.top-2:i.bottom+2;e._pathPos=e._posArg?e._posArg:t,r.push([i.left,e._pathPos]),r.push([i.right,e._pathPos]),e._path._setVertices(r)}else if("y"===t){let t=e.orientation===ii?i.left-2:i.right+2;e._pathPos=e._posArg?e._posArg:t,r.push([e._pathPos,i.top]),r.push([e._pathPos,i.bottom]),e._path._setVertices(r)}else if("angle"===t){let t=e.elements[0].parent.layout;t.type===B.CLUSTER&&(e._path._x=t.x,e._path._y=t.y,e._path._radius=t.radius)}}_runForEncoding(e){let t=e.channel,i=e.elements,r=i[0].parent.layout&&i[0].parent.layout.type==B.STACK?b(i):m(i),s=[],n=L(i[0]);if(n&&n.clipMask&&(r=n.clipMask),"x"===t){let t,n,a=Ve(i[0],"y");a?(t=Math.min(...a.getScale(i[0]).range,r.top),n=Math.max(...a.getScale(i[0]).range,r.bottom)):(t=r.top,n=r.bottom);let o=e.orientation===ei?t-2:n+2;e._pathPos=e._posArg?e._posArg:o,s.push([e.scale.range[0],e._pathPos]),s.push([e.scale.range[1],e._pathPos])}else if("width"===t){let t=e.orientation===ei?r.top-2:r.bottom+2;e._pathPos=e._posArg?e._posArg:t,s.push([r.left,e._pathPos]),s.push([r.right,e._pathPos])}else if("radialDistance"===t){let t=e.elements[0].parent,i=t.y;e._pathPos=e._posArg?e._posArg:i,s.push([e.scale.range[0]+t.x,e._pathPos]),s.push([e.scale.range[1]+t.x,e._pathPos])}else if("y"===t){let t,n,a=Ve(i[0],"x");a?(t=Math.min(...a.getScale(i[0]).range,r.left),n=Math.max(...a.getScale(i[0]).range,r.right)):(t=r.left,n=r.right);let o=e.orientation===ii?t-2:n+2;e._pathPos=e._posArg?e._posArg:o,s.push([e._pathPos,e.scale.range[0]]),s.push([e._pathPos,e.scale.range[1]])}else if("height"===t){let t=e.orientation===ii?r.left-2:r.right+2;e._pathPos=e._posArg?e._posArg:t,s.push([e._pathPos,r.bottom]),s.push([e._pathPos,r.top])}e._path._setVertices(s)}}class li extends F{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof $e&&e.property==et.AXIS_PATH_POSITION).element;e instanceof ni?this._runForEncoding(e):e instanceof ai&&this._runForLayout(e);let t=[];if("width"===e.channel||"x"===e.channel){let i=e._ticks.children.map(e=>e.vertices[0].x),r=[e._path.vertices[0].x,e._path.vertices[1].x];t.push([Math.min(...i.concat(r)),e._path.vertices[0].y]),t.push([Math.max(...i.concat(r)),e._path.vertices[0].y]),e._path._setVertices(t)}else if("height"===e.channel||"y"===e.channel){let i=e._ticks.children.map(e=>e.vertices[0].y),r=[e._path.vertices[0].y,e._path.vertices[1].y];t.push([e._pathPos,Math.min(...i.concat(r))]),t.push([e._pathPos,Math.max(...i.concat(r))]),e._path._setVertices(t)}for(let t of e._ticks.children)t._updateBounds();x(e._ticks)}_runForLayout(e){let t=e.channel;if("x"==t){let t=e.orientation==ti?e.pathPos+e.tickOffset:e.pathPos-e.tickOffset,i=e.orientation==ti?e.tickSize:-e.tickSize;for(let[r,s]of e._ticks.children.entries()){let n=e.elements[r].bounds[e.tickAnchor];s._setVertices([[n,t],[n,t+i]])}}else if("y"===t){let t=e.orientation==ii?e.pathPos-e.tickOffset:e.pathPos+e.tickOffset,i=e.orientation==ii?-e.tickSize:e.tickSize;for(let[r,s]of e._ticks.children.entries()){let n=e.elements[r].bounds[e.tickAnchor];s._setVertices([[t,n],[t+i,n]])}}else if("angle"===t){let t=e.elements[0].parent.layout;if(t.type===B.CLUSTER){let i=t._d3Root.leaves();const r=new Map(i.map(e=>[e.data[me],[e.x,e.y]]));for(let[i,s]of e._ticks.children.entries()){let n=e.elements[i].dataScope.getAttrVal(me),a=oe(r.get(n)[0])-90;s._setVertices([[t.x+r.get(n)[1]+e.elements[i].bounds.width/2,t.y],[t.x+r.get(n)[1]+e.elements[i].bounds.width/2+e.tickSize,t.y]]),s._rotate=[a,t.x,t.y]}}}}_runForEncoding(e){let t=e.channel,i=m(e.elements);if("x"==t){let t=e.orientation==ti?e.pathPos+e.tickOffset:e.pathPos-e.tickOffset,i=e.orientation==ti?e.tickSize:-e.tickSize;for(let[r,s]of e._ticks.children.entries())s._setVertices([[e.scale.map(e._tickValues[r]),t],[e.scale.map(e._tickValues[r]),t+i]])}else if("width"==t){let t=e.orientation==ti?e.pathPos+e.tickOffset:e.pathPos-e.tickOffset,r=e.orientation==ti?e.tickSize:-e.tickSize;if(!!(e.isFlipped()||e.elements[0].type===Vt.Area&&"right"===e.elements[0].baseline))for(let[s,n]of e._ticks.children.entries())n._setVertices([[i.left+e.scale.rangeExtent-e.scale.map(e._tickValues[s]),t],[i.left+e.scale.rangeExtent-e.scale.map(e._tickValues[s]),t+r]]);else for(let[s,n]of e._ticks.children.entries())n._setVertices([[e.scale.map(e._tickValues[s])+i.left,t],[e.scale.map(e._tickValues[s])+i.left,t+r]])}else if("y"===t){let t=e.orientation==ii?e.pathPos-e.tickOffset:e.pathPos+e.tickOffset,i=e.orientation==ii?-e.tickSize:e.tickSize;for(let[r,s]of e._ticks.children.entries())s._setVertices([[t,e.scale.map(e._tickValues[r])],[t+i,e.scale.map(e._tickValues[r])]])}else if("height"===t){let t=e.orientation==ii?e.pathPos-e.tickOffset:e.pathPos+e.tickOffset,r=e.orientation==ii?-e.tickSize:e.tickSize;if(!!(e.isFlipped()||e.elements[0].type===Vt.Area&&"top"===e.elements[0].baseline))for(let[s,n]of e._ticks.children.entries())n._setVertices([[t,i.top+e.scale.map(e._tickValues[s])],[t+r,i.top+e.scale.map(e._tickValues[s])]]);else for(let[s,n]of e._ticks.children.entries()){let a=i.bottom-e.scale.map(e._tickValues[s]);n._setVertices([[t,a],[t+r,a]])}}else if("radialDistance"===t){let t=e.orientation==ti?e.pathPos+e.tickOffset:e.pathPos-e.tickOffset,i=e.orientation==ti?e.tickSize:-e.tickSize,r=e.elements[0].parent;for(let[s,n]of e._ticks.children.entries())n._setVertices([[r.x+e.scale.map(e._tickValues[s]),t],[r.x+e.scale.map(e._tickValues[s]),t+i]])}}}class hi extends F{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof $e&&e.property==et.AXIS_PATH_POSITION).element;e instanceof ni?this._runForEncoding(e):e instanceof ai&&this._runForLayout(e);for(let t of e._labels.children)t._updateBounds();x(e._labels)}_runForLayout(e){let t=e.channel;if("x"==t){let t=e.orientation==ti?e.labelOffset:-e.labelOffset,i=e.orientation==ti?[v.CENTER,v.TOP]:[v.CENTER,v.BOTTOM];for(let[r,s]of e._labels.children.entries()){let n=e.elements[r].bounds;s.x=n[e.tickAnchor],s._y=e.pathPos+t,s._anchor=i,e._labelRotation&&(s._rotate=[e._labelRotation,s.x,s.y],s._anchor=[v.RIGHT,v.MIDDLE])}}else if("y"===t){let t=e.orientation==ii?-e.labelOffset:e.labelOffset,i=e.orientation==ii?[v.RIGHT,v.MIDDLE]:[v.LEFT,v.MIDDLE];for(let[r,s]of e._labels.children.entries()){let n=e.elements[r].bounds;s.x=e.pathPos+t,s._y=e.tickAnchor==v.MIDDLE?n.y:n[e.tickAnchor],s._anchor=i,e._labelRotation&&(s._rotate=[e._labelRotation,s.x,s.y],s._anchor=[v.RIGHT,i[1]])}}else if("angle"===t){let t=e.elements[0].parent.layout;if(t.type===B.CLUSTER){let i=t._d3Root.leaves();const r=new Map(i.map(e=>[e.data[me],[e.x,e.y]]));let s=5;for(let[i,n]of e._labels.children.entries()){let a=e.elements[i].dataScope.getAttrVal(me);if(r.get(a)[0]<Math.PI){let o=oe(r.get(a)[0])-90;n._anchor=[v.LEFT,v.MIDDLE],n.x=t.x+r.get(a)[1]+e.elements[i].bounds.width/2+s,n._y=t.y,n._rotate=[o,t.x,t.y]}else{let o=oe(r.get(a)[0])+90;n._anchor=[v.RIGHT,v.MIDDLE],n.x=t.x-r.get(a)[1]-e.elements[i].bounds.width/2-s,n._y=t.y,n._rotate=[o,t.x,t.y]}}}}}_runForEncoding(e){let t=e.channel,i=m(e.elements);if("x"==t){let t=e.orientation==ti?e.labelOffset:-e.labelOffset,i=e.orientation==ti?[v.CENTER,v.TOP]:[v.CENTER,v.BOTTOM];for(let[r,s]of e._labels.children.entries())s.x=e.scale.map(e.labelValues[r]),s._y=e.pathPos+t,s._anchor=i,e._labelRotation&&(s._rotate=[e._labelRotation,s.x,s.y],s._anchor=[v.RIGHT,i[1]])}else if("width"===t){let t=e.orientation==ti?e.labelOffset:-e.labelOffset,r=e.orientation==ti?[v.CENTER,v.TOP]:[v.CENTER,v.BOTTOM],s=!!(e.isFlipped()||e.elements[0].type===Vt.Area&&"right"===e.elements[0].baseline);for(let[n,a]of e._labels.children.entries())a.x=s?i.left+e.scale.rangeExtent-e.scale.map(e.labelValues[n]):e.scale.map(e.labelValues[n])+i.left,a._y=e.pathPos+t,a._anchor=r,e._labelRotation&&(a._rotate=[e._labelRotation,a.x,a.y],a._anchor=[v.RIGHT,r[1]])}else if("y"===t){let t=e.orientation==ii?-e.labelOffset:e.labelOffset,i=e.orientation==ii?[v.RIGHT,v.MIDDLE]:[v.LEFT,v.MIDDLE];for(let[r,s]of e._labels.children.entries())s.x=e.pathPos+t,s._y=e.scale.map(e.labelValues[r]),s._anchor=i,e._labelRotation&&(s._rotate=[e._labelRotation,s.x,s.y],s._anchor=[v.RIGHT,i[1]])}else if("height"===t){let t=e.orientation==ii?-e.labelOffset:e.labelOffset,r=e.orientation==ii?[v.RIGHT,v.MIDDLE]:[v.LEFT,v.MIDDLE],s=e.elements[0].type===Vt.Area&&"top"===e.elements[0].baseline;for(let[n,a]of e._labels.children.entries())a.x=e.pathPos+t,a._y=s?i.top+e.scale.map(e.labelValues[n]):i.bottom-e.scale.map(e.labelValues[n]),a._anchor=r,e._labelRotation&&(a._rotate=[e._labelRotation,a.x,a.y],a._anchor=[v.RIGHT,r[1]])}else if("radialDistance"==t){let t=e.orientation==ti?e.labelOffset:-e.labelOffset,i=e.orientation==ti?[v.CENTER,v.TOP]:[v.CENTER,v.BOTTOM],r=e.elements[0].parent;for(let[s,n]of e._labels.children.entries())n.x=r.x+e.scale.map(e.labelValues[s]),n._y=e.pathPos+t,n._anchor=i,e._labelRotation&&(n._rotate=[e._labelRotation,n.x,n.y],n._anchor=[v.RIGHT,i[1]])}}}class ci extends F{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=C(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 i=V(e,!0);for(let e of i)x(e)}placeElements(e,t){let i=Me(e,"x"),r=Me(e,"y");for(let i=0;i<e.children.length;i++){let r=e.children[i],s=t.cellBounds[i],n=0,a=0;switch(t._cellHorzAlignment){case v.LEFT:n=s.left-r.refBounds.left;break;case v.CENTER:n=s.x-r.refBounds.x;break;case v.RIGHT:n=s.right-r.refBounds.right}switch(t._cellVertAlignment){case v.TOP:a=s.top-r.refBounds.top;break;case v.MIDDLE:a=s.y-r.refBounds.y;break;case v.BOTTOM:a=s.bottom-r.refBounds.bottom}Fe(r,n,a)}if(i.length>0)for(let e of i)for(let i of e.scales){let r=e.getElements(i)[0],s=t.getIndex(r);if(s<0)continue;let n="point"===i.type?t.cellBounds[s].left+r.bounds.width/2:t.cellBounds[s].left,a=n+i.rangeExtent;i.range=i.range[0]<i.range[1]?[n,a]:[a,n]}if(r.length>0)for(let e of r)for(let i of e.scales){let r=e.getElements(i)[0],s=t.getIndex(r);if(s<0)continue;let n="point"===i.type?t.cellBounds[s].top+e.getElements(i)[0].bounds.height/2:t.cellBounds[s].top,a=n+i.rangeExtent;i.range=i.range[0]<i.range[1]?[n,a]:[a,n]}}fillGrid(e,t){t._grid=new Array(t.numRows).fill(null).map(()=>new Array(t.numCols).fill(null));for(let i=0;i<e.children.length;i++){let e=t.getRowCol(i);t._grid[e.row][e.col]=i}}computeCellBounds(e,t){let i=e.children.map(e=>e.refBounds?e.refBounds:e.bounds),r=t._colGap,s=t._rowGap;if(void 0===t._left){let e=i.map(e=>e.left),r=i.map(e=>e.top);t._left=Math.min(...e),t._top=Math.min(...r)}let n=i.map(e=>e.width),a=i.map(e=>e.height),o=Math.max(...n),l=Math.max(...a);t._cellBounds=new Array(e.children.length).fill(null);for(let i=0;i<t.numRows;i++)for(let n=0;n<t.numCols;n++){let a=t._grid[i][n];a>=e.children.length||(t._cellBounds[a]=new g(t._left+(o+r)*n+0,t._top+(l+s)*i,o,l))}}}class di extends F{constructor(e){super(e)}run(){let e=this.outputVar.element;e.updateValues(),e.scale?this._runForEncoding(e):this._runForLayout(e),x(e)}_runForLayout(e){let t=e.channel,i=m(e.elements),r=[];if("x"===t)for(let t=0;t<e.values.length;t++){let s=e.elements[t].refBounds;r.push({x1:s.x,y1:i.bottom,x2:s.x,y2:i.top})}else if("y"===t)for(let t=0;t<e.values.length;t++){let s=e.elements[t].refBounds;r.push({x1:i.left,y1:s.y,x2:i.right,y2:s.y})}e.lines=r,e._dirty=!0}_runForEncoding(e){let t=e.channel,i=m(e.elements),r=[];if("x"===t){let t,s,n=Ve(e.elements[0],"y");n?(t=Math.min(...n.getScale(e.elements[0]).range,i.top),s=Math.max(...n.getScale(e.elements[0]).range,i.bottom)):(t=i.top,s=i.bottom);for(let i of e.values)r.push({x1:e.scale.map(i),y1:s,x2:e.scale.map(i),y2:t})}else if("width"===t)for(let t of e.values)r.push({x1:e.scale.map(t)+i.left,y1:i.bottom,x2:e.scale.map(t)+i.left,y2:i.top});else if("y"===t){let t,s,n=Ve(e.elements[0],"x");n?(t=Math.min(...n.getScale(e.elements[0]).range,i.left),s=Math.max(...n.getScale(e.elements[0]).range,i.right)):(t=i.top,s=i.bottom);for(let i of e.values)r.push({x1:t,y1:e.scale.map(i),x2:s,y2:e.scale.map(i)})}else if("height"===t)for(let t of e.values)r.push({x1:i.left,y1:i.bottom-e.scale.map(t),x2:i.right,y2:i.bottom-e.scale.map(t)});else if("radialDistance"===t){let t=e.elements[0].parent;for(let i=0;i<e.values.length;i++)r.push({x:t.x,y:t.y,r:e.scale.map(e.values[i])})}e.lines=r,e._dirty=!0}}class ui extends F{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=V(e)[0],i=C(e.parent);for(let e of i){let i=e.layout;if(!i)return;switch(t.type){case Vt.Rect:case Vt.Circle:case Vt.Image:this._stackRects(e,i);break;case Vt.Area:e.children[0].orientation===H?this._stackAreasVert(e,i):this._stackAreasHorz(e,i);break;case Vt.Arc:case Vt.Pie:t.parent.classId===e.classId&&this._stackArcs(e,i)}}x(t)}_stackArcs(e,t){if(t.orientation===X){let t=90;if((this._direction?this._direction:Z.Clockwise)===Z.Clockwise)for(let i of e.children){let e=le(t-i.angle);je(i,"startAngle",e),t=e}else for(let i of e.children){let e=le(t+i.angle);je(i,"startAngle",e),t=e}}else if(t.orientation===q){let t=Math.min(...e.children.map(e=>e.innerRadius));for(let i of e.children){let e=i.outerRadius-i.innerRadius;je(i,"innerRadius",t),je(i,"outerRadius",t+e),t=i._outerRadius}}}_stackAreasVert(e,t){let i=e.children.filter(e=>"visible"===e.visibility),r=e.bounds,s=t.vertCellAlignment===v.TOP?r.top:r.bottom,n=t.vertCellAlignment===v.TOP?1:-1;if(0===i.length)return;t.vertCellAlignment===v.BOTTOM&&i.reverse();let a=i[0].vertices.length/2,o=new Array(a).fill(0);for(let e of i){for(let t=0;t<a;t++){let i=e.vertices[t],r=e.vertices[2*a-t-1],l=Math.abs(i.y-r.y),h=s+o[t]*n,c=s+(o[t]+l)*n;Fe(i,0,h-i.y),Fe(r,0,c-r.y),o[t]+=l}let t=e.bounds.bottom;e._updateBounds(),e._refBounds.translate(0,e.bounds.bottom-t)}if(t.vertCellAlignment===v.MIDDLE)for(let e of i){for(let t=0;t<a;t++){let i=e.vertices[t],s=e.vertices[2*a-t-1],n=r.middle+o[t]/2;Fe(i,0,n-r.bottom),Fe(s,0,n-r.bottom)}let t=e.bounds.bottom;e._updateBounds(),e._refBounds.translate(0,e.bounds.bottom-t)}}_stackAreasHorz(e,t){}_stackRects(e,t){e.scene;let i=t._orientation,r=e.children.map(e=>e.bounds),s=r.map(e=>e.left),n=r.map(e=>e.top),a=r.map(e=>e.width),o=r.map(e=>e.height),l=null==t._left?Math.min(...s):t._left,h=null==t._top?Math.min(...n):t._top,c=Math.max(...a),d=Math.max(...o);if(i==Y)for(let i=0;i<e.children.length;i++){let r=e.children[i],s=0,n=h+r.bounds.height/2-r.bounds.y;h+=r.bounds.height+t._gap,Fe(r,s,n),r._updateBounds();let a=0,o=0;if(!Be(r))switch(t._horzCellAlignment){case v.LEFT:a=l-r.bounds.left;break;case v.CENTER:a=l+c/2-r.bounds.x;break;case v.RIGHT:a=l+c-r.bounds.right}Fe(r,a,o)}else for(let i=0;i<e.children.length;i++){let r=e.children[i],s=l+r.bounds.width/2-r.bounds.x,n=0;l+=r.bounds.width+t._gap,Fe(r,s,n),r._updateBounds();let a=0,o=0;if(!De(r))switch(t._vertCellAlignment){case v.TOP:o=h-r.bounds.top;break;case v.MIDDLE:o=h+d/2-r.bounds.y;break;case v.BOTTOM:o=h+d-r.bounds.bottom}Fe(r,a,o)}}}class _i extends F{constructor(e){super(e)}run(){super.run()}}class pi extends F{constructor(e){super(e)}run(){let e=this.inputVars[0],t=this.outputVar,i=e.attribute,s=t.attribute,n=e.dataset,a=t.dataset,o=n.getAttributeValues(i),l=r.bin()(o),h=this._findBin,c=o.map(e=>{let t=h(e,l);return(t.x0+t.x1)/2+""}),d=l.map(e=>(e.x0+e.x1)/2+"");a._addAttribute(s,xe.String,c),a.orderAttributeValues(s,d)}_findBin(e,t){for(let i of t)if(i.indexOf(e)>=0)return i}}class fi extends F{constructor(e){super(e)}run(){let e=this.outputVar,t=e.dataset,i=e.predicate,r=[];for(let[e,s]of t.data.entries())i.testTuple(s)||r.push(e);r.sort((e,t)=>t-e),r.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]=Ee(t.data.map(t=>t[e]),t._attrTypes[e])}}class gi extends F{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e.type===Te.AFFIXATION).affixation,t=e.base,i=e.element,r=C(t),s=C(i),n=e.channels,a=e.attribute;if(E(i)&&E(t)){let e=r.map(e=>e.dataScope.getAttrVal(a));s=s.filter(t=>e.includes(t.dataScope.getAttrVal(a)));let t=(e,t)=>e.dataScope.getAttrVal(a)<t.dataScope.getAttrVal(a)?-1:e.dataScope.getAttrVal(a)>t.dataScope.getAttrVal(a)?1:0;s.sort(t),r.sort(t)}if(n.includes("x")||n.includes("y"))for(let t of n)this._handleXY(t,s,r,e.getElementAnchor(t),e.getBaseAnchor(t),e.getOffset(t));(n.includes("radialDistance")||n.includes("angle"))&&this._handlePolar(s,r,e);let o=V(i,!0);for(let e of o)x(e)}_handlePolar(e,t,i){let r=i.hasChannel("radialDistance")?i.getBaseAnchor("radialDistance"):v.MIDDLE,s=i.hasChannel("radialDistance")?i.getElementAnchor("radialDistance"):v.MIDDLE,n=i.hasChannel("angle")?i.getBaseAnchor("angle"):v.CENTER;i.hasChannel("angle")?i.getElementAnchor("angle"):v.CENTER;let a=i.hasChannel("radialDistance")?i.getOffset("radialDistance"):0,o=i.hasChannel("angle")?i.getOffset("angle"):0;if([Vt.Arc,Vt.Ring].indexOf(t[0].type)>=0&&e[0].type==Vt.SimpleText)for(let i=0;i<e.length;i++){let s=t[i],o=e[i],l=r===v.MIDDLE?(s.outerRadius+s.innerRadius)/2:r===v.TOP?s.outerRadius-5:s.innerRadius+5;if(l+=a,s.type===Vt.Arc){let e=Ce(s.x,s.y,l,s.startAngle),t=Ce(s.x,s.y,l,s.endAngle);s.endAngle>=180&&s.endAngle<=360?o._textPath=["M",e[0],e[1],"A",l,l,s.angle,s.angle>=180?1:0,0,t[0],t[1]].join(" "):o._textPath=["M",t[0],t[1],"A",l,l,s.angle,s.angle>=180?1:0,1,e[0],e[1]].join(" ")}else if(s.type===Vt.Ring){let e=275,t=265,i=350,r=Ce(s.x,s.y,l,e),n=Ce(s.x,s.y,l,t);o._textPath=["M",n[0],n[1],"A",l,l,i,1,1,r[0],r[1]].join(" ")}o.textPathOffset=n===v.LEFT?"0%":"50%"}else for(let i=0;i<e.length;i++){let l,h,c=t[i],d=e[i];c.type==Vt.Arc||c.type==Vt.Ring?(h="left"==n?c.endAngle+o:"center"==n?c.startAngle+c.angle/2+o:c.startAngle+o,l="top"==r?c.outerRadius+a:"bottom"==r?c.innerRadius+a:(c.outerRadius+c.innerRadius)/2+a):c.type==Vt.Circle&&(h=90,l="top"==r?c.radius+a:"bottom"==r?a:c.radius/2+a),Fe(d,c.x-d.x,c.y-l-d.bounds[s]),d._rotate=[90-h,c.x,c.y]}}_handleXY(e,t,i,r,s,n){for(let a=0;a<t.length;a++){let o,l=i[a],h=t[a];if(ie(l)){o=te(l,[v.LEFT,v.TOP].includes(s)?0:[v.CENTER,v.MIDDLE].includes(s)?.5:1)[e]}else o=l.bounds[s]+n;t[0].type===Vt.SimpleText?(h.anchor["x"==e?0:1]=r,je(h,e,o)):"x"==e?Fe(h,o-h.bounds[r],0):Fe(h,0,o-h.bounds[r])}}}class yi extends Se{constructor(e,t){super(e),this._affx=t}get affixation(){return this._affx}}class mi extends F{constructor(e){super(e)}run(){let e=this.inputVars[0],t=this.outputVar,i=e.attribute,r=t.attribute,s=e.dataset,n=t.dataset,a=this.args,o="min"in a?a.min:s.getAttributeSummary(i).min,l="max"in a?a.max:s.getAttributeSummary(i).max,h=o,c=[];for(;h<l;)c.push(h),h+=a.interval;c.push(h);let d={},u={};if(a.groupBy)for(let e of s.data){let t=a.groupBy.map(t=>e[t]).join("-");t in d||(d[t]=[],u[t]=a.groupBy.map(t=>e[t])),d[t].push(e[i])}else d[""]=s.data.map(e=>e[i]),u[""]="";let _=[];for(let e in u){let t=bi(xi(a.bandwidth),c,d[e]);for(let s of t){let t={};""!==e&&a.groupBy.forEach((i,r)=>t[i]=u[e][r]),t[i]=s[0],t[r]=s[1],_.push(t)}}let p={};if(p[i]=s.getAttributeType(i),p[r]=xe.Number,a.groupBy)for(let e of a.groupBy)p[e]=s.getAttributeType(e);n.initialize(_,n.url,p)}}function bi(e,t,i){return t.map(t=>[t,r.mean(i,i=>e(t-i))])}function xi(e){return t=>Math.abs(t/=e)<=1?.75*(1-t*t)/e:0}class vi extends F{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=C(e.parent);for(let e of t){let t=e.layout;if(!t)return;let i=e.children.map(e=>({name:e.id,radius:e.radius,itm:e})),s=i.reduce((e,t)=>e+Math.pow(t.radius,2),0),n=Math.sqrt(s);void 0===t._width&&(t._width=n),void 0===t._height&&(t._height=n);let a=r.hierarchy({name:"root",children:i}).sum(e=>e.radius?e.radius:0).sort((e,t)=>t.value-e.value);r.pack().size([t._width,t._height]).radius(e=>e.value)(a);for(let e of a.children){let i=e.data.itm;Fe(i,t._x-a.x+e.x-i.x,t._y-a.y+e.y-i.y)}}let i=V(e,!0);for(let e of i)x(e)}}class wi extends F{constructor(e){super(e)}run(){super.run();let e=this.inputVars.find(e=>e instanceof $e&&e.property==et.AXIS_PATH_POSITION).element;e instanceof ni?this._runForEncoding(e):e instanceof ai&&this._runForLayout(e),x(e._title)}_runForEncoding(e){let t=e.channel,i=m(e.elements);if("x"==t)e._title.x=(e.scale.range[0]+e.scale.range[1])/2,e._title._y=e.orientation==ti?e.pathPos+e.titleOffset:e.pathPos-e.titleOffset;else if("width"==t)e._title.x=i.left+e.scale.rangeExtent/2,e._title._y=e.orientation==ti?e.pathPos+e.titleOffset:e.pathPos-e.titleOffset;else if("y"===t)e._rotateYTitle?(e._title.x=e.orientation==ii?e.pathPos-e.titleOffset:e.pathPos+e.titleOffset,e._title._y=(e.scale.range[0]+e.scale.range[1])/2,e._title._rotate=e.orientation==ii?[-90,e._title._x,e._title._y]:[90,e._title._x,e._title._y]):(e._title.x=e.orientation==ii?e.pathPos-e.titleOffset:e.pathPos+e.titleOffset,e._title._y=Math.min(e.scale.range[0],e.scale.range[1])-25,e._title._rotate=void 0);else if("height"===t)e._title.x=i.center,e._title._y=(i.top+i.bottom)/2-i.width/2-e.titleOffset,e._title._rotate=e.orientation==ii?[-90,i.center,i.middle]:[90,i.center,i.middle];else if("radialDistance"===t){let t=e.elements[0].parent;e._title.x=t.x+e.scale.rangeExtent/2,e._title._y=e.orientation==ti?e.pathPos+e.titleOffset:e.pathPos-e.titleOffset,e._rotate&&(e._title._rotate=e._rotate.slice())}}_runForLayout(e){let t=e.channel,i=e.elements[0].parent.layout&&e.elements[0].parent.layout.type==B.STACK?b(e.elements):m(e.elements);if("x"==t)e._title.x=i.center,e._title._y=e.orientation==ti?e.pathPos+e.titleOffset:e.pathPos-e.titleOffset;else if("y"===t)e._title.x=i.center,e._title._y=i.middle-i.width/2-e.titleOffset,e._title._rotate=e.orientation==ii?[-90,i.center,i.middle]:[90,i.center,i.middle];else if("angle"===t){let t=e.elements[0].parent.layout;t.type===B.CLUSTER&&(e._title.x=t.x,e._title._y=t.y)}}}class Ei extends Wt{constructor(e){super(e)}run(){super.run();let e,t=this.vars.find(e=>e.type===Te.ALIGNMENT).alignment,i=t.anchor,s=t.elements;i==v.Top||i==v.LEFT?e=Math.min(...s.map(e=>e.bounds[i])):i==v.BOTTOM||i==v.RIGHT?e=Math.max(...s.map(e=>e.bounds[i])):i!=v.CENTER&&i!=v.MIDDLE||(e=r.mean(s.map(e=>e.bounds[i])));for(let r of s){let s=Ge(r,t.channel);if(s){let n=e-r.bounds[i];Fe(s,"x"===t.channel?n:0,"x"===t.channel?0:n)}}for(let e of s)x(e)}}class Ai extends Se{constructor(e,t){super(e),this._aln=t}get alignment(){return this._aln}}class Ci extends F{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=C(e.parent);for(let e of t){let t=e.layout;if(!t)continue;let i=ge(e.children[0]);if(!i)continue;let s=i.linkList.map(e=>({source:i.getNode(e.source),target:i.getNode(e.target)})),n=r.forceSimulation(i.nodeList).force("charge",r.forceManyBody().strength(-t._repulsion)).force("link",r.forceLink(s).id(e=>e.id).distance(t._linkDistance)).force("x",r.forceX()).force("y",r.forceY()).force("center",r.forceCenter(t._x,t._y).strength(t._attraction));n.stop(),n.tick(t._iterations);for(let t=0;t<e.children.length;t++){let r=e.children[t],s=i.nodeList[t];Fe(r,s.x-r.x,s.y-r.y)}}let i=V(e,!0);for(let e of i)x(e)}}class ki extends F{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=C(e);switch(e.type){case Vt.Arc:this._updateArcLinks(t);break;case Vt.BezierCurve:this._updateBezierLinks(t);break;case Vt.BundledPath:this._updateBundledLinks(t);break;case Vt.Chord:this._updateChordLinks(t);break;case Vt.Line:default:this._updateLineLinks(t)}x(e)}_updateArcLinks(e){for(let t of e){let e=t.source.x<t.target.x?t.source:t.target,i=t.source.x<t.target.x?t.target:t.source;t._x=(e.x+i.x)/2,t._y=(e.y+i.y)/2,t._innerRadius=Math.sqrt(Math.pow(e.x-i.x,2)+Math.pow(e.y-i.y,2))/2,t._outerRadius=t._innerRadius+t._thickness;let r=he(e.x,e.y,t._x,t._y),s=he(i.x,i.y,t._x,t._y);t.direction===Z.CLOCKWISE&&([r,s]=[s,r]),je(t,"startAngle",r),je(t,"angle",Math.abs(s-r))}}_updateBezierLinks(e){let t=this._inputVars[0].element,i=C(t),r=t.parent.layout;r.type===B.DIRECTED||r.type===B.TIDYTREE?this._updateBezierLinksForDirectedGraph(i,e,r):r.type===B.CLUSTER&&this._updateBezierLinksForClusteredGraph(i,e,r)}_updateBezierLinksForClusteredGraph(e,t,i){const s=i._d3Root.descendants(),n=new Map(s.map(e=>[Si(e),e])),a=new Map(s.map(e=>[e.data[me],Si(e)]));if(i.isRadial()){const e=r.linkRadial().angle(e=>e.x).radius(e=>e.y);for(let r of t){let t=r.source,s=r.target,o=t.dataScope.getAttrVal(me),l=s.dataScope.getAttrVal(me),h=n.get(a.get(o)),c=n.get(a.get(l));r._d=se(e({source:h,target:c}),i.x,i.y)}}else if(i.orientation===Y){const e=r.linkVertical().x(e=>e.x).y(e=>e.y);for(let r of t){let t=r.source,s=r.target,o=t.dataScope.getAttrVal(me),l=s.dataScope.getAttrVal(me),h=n.get(a.get(o)),c=n.get(a.get(l));r._d=se(e({source:h,target:c}),i.left-i._x0,i.top)}}else if(i.orientation===H){const e=r.linkHorizontal().x(e=>e.y).y(e=>e.x);for(let r of t){let t=r.source,s=r.target,o=t.dataScope.getAttrVal(me),l=s.dataScope.getAttrVal(me),h=n.get(a.get(o)),c=n.get(a.get(l));r._d=se(e({source:h,target:c}),i.left,i.top-i._x0)}}}_updateBezierLinksForDirectedGraph(e,t,i){let r={},s={},n={},a={};for(let t of e){s[t.id]=0,r[t.id]=0;let e=t.links.filter(e=>e.source===t),i=t.links.filter(e=>e.target===t);a[t.id]=i.map(e=>e.strokeWidth).reduce((e,t)=>e+t,0),n[t.id]=e.map(e=>e.strokeWidth).reduce((e,t)=>e+t,0)}i.spreadLinks&&("LR"===i.direction||"RL"===i.direction?t.sort((e,t)=>he(e.target.bounds.x,e.target.bounds.y,e.source.bounds.x,e.source.bounds.y)-he(t.target.bounds.x,t.target.bounds.y,t.source.bounds.x,t.source.bounds.y)):t.sort((e,t)=>he(t.target.bounds.x,t.target.bounds.y,t.source.bounds.x,t.source.bounds.y)-he(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,h,c=e.source,d=e.target;i.spreadLinks?"LR"===i.direction||"RL"===i.direction?(t=c.bounds[e.sourceAnchor[0]]+e.sourceOffset[0],l=d.bounds[e.targetAnchor[0]]+e.targetOffset[0],o=c.bounds[e.sourceAnchor[1]]+e.sourceOffset[1]-n[c.id]/2+r[c.id]+e.strokeWidth/2,h=d.bounds[e.targetAnchor[1]]+e.targetOffset[1]-a[d.id]/2+s[d.id]+e.strokeWidth/2,r[c.id]+=e.strokeWidth,s[d.id]+=e.strokeWidth):(o=c.bounds[e.sourceAnchor[1]]+e.sourceOffset[1],h=d.bounds[e.targetAnchor[1]]+e.targetOffset[1],t=c.bounds[e.sourceAnchor[0]]+e.sourceOffset[0]-n[c.id]/2+r[c.id]+e.strokeWidth/2,l=d.bounds[e.targetAnchor[0]]+e.targetOffset[0]-a[d.id]/2+s[d.id]+e.strokeWidth/2,r[c.id]+=e.strokeWidth,s[d.id]+=e.strokeWidth):(t=c.bounds[e.sourceAnchor[0]]+e.sourceOffset[0],o=c.bounds[e.sourceAnchor[1]]+e.sourceOffset[1],l=d.bounds[e.targetAnchor[0]]+e.targetOffset[0],h=d.bounds[e.targetAnchor[1]]+e.targetOffset[1]),e.orientation===H?e._setVertices([[t,o],[(t+l)/2,o],[t,h],[l,h]]):e.orientation===Y&&e._setVertices([[t,o],[t,(o+h)/2],[l,o],[l,h]])}}_updateBundledLinks(e){let t=this._inputVars[0].element.parent.layout;if(t.type!==B.CLUSTER)throw"Bundled links must work on a cluster layout";let i=t._d3Root.leaves();const s=new Map(i.map(e=>[Si(e),e])),n=new Map(i.map(e=>[e.data[me],Si(e)])),a=r.lineRadial().curve(r.curveBundle.beta(e[0]._strength)).radius(e=>e.y).angle(e=>e.x);for(let i of e){let e=i.source.dataScope.getAttrVal(me),r=i.target.dataScope.getAttrVal(me),o=s.get(n.get(e)),l=s.get(n.get(r));(o.outgoing??=[]).push([o,l]),l.incoming??=[];let h=o.path(l);i._d=se(a(h),t.x,t.y)}}_updateChordLinks(e){for(let t of e){let e=t.source,i=t.target,r=Ce(e.x,e.y,e.innerRadius,e.startAngle),s=Ce(e.x,e.y,e.innerRadius,e.endAngle),n=Ce(i.x,i.y,i.innerRadius,i.startAngle),a=Ce(i.x,i.y,i.innerRadius,i.endAngle);t._d=["M",r[0],r[1],"Q",e.x,e.y,a[0],a[1],"A",e.x,e.y,i.angle,i.angle>180?1:0,1,n[0],n[1],"Q",e.x,e.y,s[0],s[1],"A",e.x,e.y,e.angle,e.angle>180?1:0,1,r[0],r[1]].join(" "),t._dirty=!0}}_updateLineLinks(e){for(let t of e){let e=t.source,i=t.target;t.vertices[0]._x=e.bounds.x,t.vertices[0]._y=e.bounds.y,t.vertices[1]._x=i.bounds.x,t.vertices[1]._y=i.bounds.y,t._dirty=!0}}}function Si(e){return`${e.parent?Si(e.parent)+".":""}${e.data[me]}`}var Ti="\0";function Ri(e,t){e[t]?e[t]++:e[t]=1}function Oi(e,t){--e[t]||delete e[t]}function Ii(e,t,i,r){var s=""+t,n=""+i;if(!e&&s>n){var a=s;s=n,n=a}return s+""+n+""+(void 0===r?"\0":r)}function Ni(e,t){return Ii(e,t.v,t.w,t.name)}var Li=class{_isDirected=!0;_isMultigraph=!1;_isCompound=!1;_label;_defaultNodeLabelFn=()=>{};_defaultEdgeLabelFn=()=>{};_nodes={};_in={};_preds={};_out={};_sucs={};_edgeObjs={};_edgeLabels={};_nodeCount=0;_edgeCount=0;_parent;_children;constructor(e){e&&(this._isDirected=!Object.hasOwn(e,"directed")||e.directed,this._isMultigraph=!!Object.hasOwn(e,"multigraph")&&e.multigraph,this._isCompound=!!Object.hasOwn(e,"compound")&&e.compound),this._isCompound&&(this._parent={},this._children={},this._children[Ti]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(e){return this._label=e,this}graph(){return this._label}setDefaultNodeLabel(e){return this._defaultNodeLabelFn=e,"function"!=typeof e&&(this._defaultNodeLabelFn=()=>e),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var e=this;return this.nodes().filter(t=>0===Object.keys(e._in[t]).length)}sinks(){var e=this;return this.nodes().filter(t=>0===Object.keys(e._out[t]).length)}setNodes(e,t){var i=arguments,r=this;return e.forEach(function(e){i.length>1?r.setNode(e,t):r.setNode(e)}),this}setNode(e,t){return Object.hasOwn(this._nodes,e)?(arguments.length>1&&(this._nodes[e]=t),this):(this._nodes[e]=arguments.length>1?t:this._defaultNodeLabelFn(e),this._isCompound&&(this._parent[e]=Ti,this._children[e]={},this._children[Ti][e]=!0),this._in[e]={},this._preds[e]={},this._out[e]={},this._sucs[e]={},++this._nodeCount,this)}node(e){return this._nodes[e]}hasNode(e){return Object.hasOwn(this._nodes,e)}removeNode(e){var t=this;if(Object.hasOwn(this._nodes,e)){var i=e=>t.removeEdge(t._edgeObjs[e]);delete this._nodes[e],this._isCompound&&(this._removeFromParentsChildList(e),delete this._parent[e],this.children(e).forEach(function(e){t.setParent(e)}),delete this._children[e]),Object.keys(this._in[e]).forEach(i),delete this._in[e],delete this._preds[e],Object.keys(this._out[e]).forEach(i),delete this._out[e],delete this._sucs[e],--this._nodeCount}return this}setParent(e,t){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(void 0===t)t=Ti;else{for(var i=t+="";void 0!==i;i=this.parent(i))if(i===e)throw new Error("Setting "+t+" as parent of "+e+" would create a cycle");this.setNode(t)}return this.setNode(e),this._removeFromParentsChildList(e),this._parent[e]=t,this._children[t][e]=!0,this}_removeFromParentsChildList(e){delete this._children[this._parent[e]][e]}parent(e){if(this._isCompound){var t=this._parent[e];if(t!==Ti)return t}}children(e=Ti){if(this._isCompound){var t=this._children[e];if(t)return Object.keys(t)}else{if(e===Ti)return this.nodes();if(this.hasNode(e))return[]}}predecessors(e){var t=this._preds[e];if(t)return Object.keys(t)}successors(e){var t=this._sucs[e];if(t)return Object.keys(t)}neighbors(e){var t=this.predecessors(e);if(t){const r=new Set(t);for(var i of this.successors(e))r.add(i);return Array.from(r.values())}}isLeaf(e){return 0===(this.isDirected()?this.successors(e):this.neighbors(e)).length}filterNodes(e){var t=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});t.setGraph(this.graph());var i=this;Object.entries(this._nodes).forEach(function([i,r]){e(i)&&t.setNode(i,r)}),Object.values(this._edgeObjs).forEach(function(e){t.hasNode(e.v)&&t.hasNode(e.w)&&t.setEdge(e,i.edge(e))});var r={};function s(e){var n=i.parent(e);return void 0===n||t.hasNode(n)?(r[e]=n,n):n in r?r[n]:s(n)}return this._isCompound&&t.nodes().forEach(e=>t.setParent(e,s(e))),t}setDefaultEdgeLabel(e){return this._defaultEdgeLabelFn=e,"function"!=typeof e&&(this._defaultEdgeLabelFn=()=>e),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(e,t){var i=this,r=arguments;return e.reduce(function(e,s){return r.length>1?i.setEdge(e,s,t):i.setEdge(e,s),s}),this}setEdge(){var e,t,i,r,s=!1,n=arguments[0];"object"==typeof n&&null!==n&&"v"in n?(e=n.v,t=n.w,i=n.name,2===arguments.length&&(r=arguments[1],s=!0)):(e=n,t=arguments[1],i=arguments[3],arguments.length>2&&(r=arguments[2],s=!0)),e=""+e,t=""+t,void 0!==i&&(i=""+i);var a=Ii(this._isDirected,e,t,i);if(Object.hasOwn(this._edgeLabels,a))return s&&(this._edgeLabels[a]=r),this;if(void 0!==i&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(e),this.setNode(t),this._edgeLabels[a]=s?r:this._defaultEdgeLabelFn(e,t,i);var o=function(e,t,i,r){var s=""+t,n=""+i;if(!e&&s>n){var a=s;s=n,n=a}var o={v:s,w:n};r&&(o.name=r);return o}(this._isDirected,e,t,i);return e=o.v,t=o.w,Object.freeze(o),this._edgeObjs[a]=o,Ri(this._preds[t],e),Ri(this._sucs[e],t),this._in[t][a]=o,this._out[e][a]=o,this._edgeCount++,this}edge(e,t,i){var r=1===arguments.length?Ni(this._isDirected,arguments[0]):Ii(this._isDirected,e,t,i);return this._edgeLabels[r]}edgeAsObj(){const e=this.edge(...arguments);return"object"!=typeof e?{label:e}:e}hasEdge(e,t,i){var r=1===arguments.length?Ni(this._isDirected,arguments[0]):Ii(this._isDirected,e,t,i);return Object.hasOwn(this._edgeLabels,r)}removeEdge(e,t,i){var r=1===arguments.length?Ni(this._isDirected,arguments[0]):Ii(this._isDirected,e,t,i),s=this._edgeObjs[r];return s&&(e=s.v,t=s.w,delete this._edgeLabels[r],delete this._edgeObjs[r],Oi(this._preds[t],e),Oi(this._sucs[e],t),delete this._in[t][r],delete this._out[e][r],this._edgeCount--),this}inEdges(e,t){var i=this._in[e];if(i){var r=Object.values(i);return t?r.filter(e=>e.v===t):r}}outEdges(e,t){var i=this._out[e];if(i){var r=Object.values(i);return t?r.filter(e=>e.w===t):r}}nodeEdges(e,t){var i=this.inEdges(e,t);if(i)return i.concat(this.outEdges(e,t))}},Vi={Graph:Li,version:"2.2.4"},Pi=Li,Mi={write:function(e){var t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:Di(e),edges:Bi(e)};void 0!==e.graph()&&(t.value=structuredClone(e.graph()));return t},read:function(e){var t=new Pi(e.options).setGraph(e.value);return e.nodes.forEach(function(e){t.setNode(e.v,e.value),e.parent&&t.setParent(e.v,e.parent)}),e.edges.forEach(function(e){t.setEdge({v:e.v,w:e.w,name:e.name},e.value)}),t}};function Di(e){return e.nodes().map(function(t){var i=e.node(t),r=e.parent(t),s={v:t};return void 0!==i&&(s.value=i),void 0!==r&&(s.parent=r),s})}function Bi(e){return e.edges().map(function(t){var i=e.edge(t),r={v:t.v,w:t.w};return void 0!==t.name&&(r.name=t.name),void 0!==i&&(r.value=i),r})}var Gi=function(e){var t,i={},r=[];function s(r){Object.hasOwn(i,r)||(i[r]=!0,t.push(r),e.successors(r).forEach(s),e.predecessors(r).forEach(s))}return e.nodes().forEach(function(e){t=[],s(e),t.length&&r.push(t)}),r};var Fi=class{_arr=[];_keyIndices={};size(){return this._arr.length}keys(){return this._arr.map(function(e){return e.key})}has(e){return Object.hasOwn(this._keyIndices,e)}priority(e){var t=this._keyIndices[e];if(void 0!==t)return this._arr[t].priority}min(){if(0===this.size())throw new Error("Queue underflow");return this._arr[0].key}add(e,t){var i=this._keyIndices;if(e=String(e),!Object.hasOwn(i,e)){var r=this._arr,s=r.length;return i[e]=s,r.push({key:e,priority:t}),this._decrease(s),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var e=this._arr.pop();return delete this._keyIndices[e.key],this._heapify(0),e.key}decrease(e,t){var i=this._keyIndices[e];if(t>this._arr[i].priority)throw new Error("New priority is greater than current priority. Key: "+e+" Old: "+this._arr[i].priority+" New: "+t);this._arr[i].priority=t,this._decrease(i)}_heapify(e){var t=this._arr,i=2*e,r=i+1,s=e;i<t.length&&(s=t[i].priority<t[s].priority?i:s,r<t.length&&(s=t[r].priority<t[s].priority?r:s),s!==e&&(this._swap(e,s),this._heapify(s)))}_decrease(e){for(var t,i=this._arr,r=i[e].priority;0!==e&&!(i[t=e>>1].priority<r);)this._swap(e,t),e=t}_swap(e,t){var i=this._arr,r=this._keyIndices,s=i[e],n=i[t];i[e]=n,i[t]=s,r[n.key]=e,r[s.key]=t}},zi=Fi,ji=function(e,t,i,r){return function(e,t,i,r){var s,n,a={},o=new zi,l=function(e){var t=e.v!==s?e.v:e.w,r=a[t],l=i(e),h=n.distance+l;if(l<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+e+" Weight: "+l);h<r.distance&&(r.distance=h,r.predecessor=s,o.decrease(t,h))};e.nodes().forEach(function(e){var i=e===t?0:Number.POSITIVE_INFINITY;a[e]={distance:i},o.add(e,i)});for(;o.size()>0&&(s=o.removeMin(),(n=a[s]).distance!==Number.POSITIVE_INFINITY);)r(s).forEach(l);return a}(e,String(t),i||Wi,r||function(t){return e.outEdges(t)})},Wi=()=>1;var Ui=ji,Hi=function(e,t,i){return e.nodes().reduce(function(r,s){return r[s]=Ui(e,s,t,i),r},{})};var Yi=function(e){var t=0,i=[],r={},s=[];function n(a){var o=r[a]={onStack:!0,lowlink:t,index:t++};if(i.push(a),e.successors(a).forEach(function(e){Object.hasOwn(r,e)?r[e].onStack&&(o.lowlink=Math.min(o.lowlink,r[e].index)):(n(e),o.lowlink=Math.min(o.lowlink,r[e].lowlink))}),o.lowlink===o.index){var l,h=[];do{l=i.pop(),r[l].onStack=!1,h.push(l)}while(a!==l);s.push(h)}}return e.nodes().forEach(function(e){Object.hasOwn(r,e)||n(e)}),s};var Xi=Yi,qi=function(e){return Xi(e).filter(function(t){return t.length>1||1===t.length&&e.hasEdge(t[0],t[0])})};var Ki=function(e,t,i){return function(e,t,i){var r={},s=e.nodes();return s.forEach(function(e){r[e]={},r[e][e]={distance:0},s.forEach(function(t){e!==t&&(r[e][t]={distance:Number.POSITIVE_INFINITY})}),i(e).forEach(function(i){var s=i.v===e?i.w:i.v,n=t(i);r[e][s]={distance:n,predecessor:e}})}),s.forEach(function(e){var t=r[e];s.forEach(function(i){var n=r[i];s.forEach(function(i){var r=n[e],s=t[i],a=n[i],o=r.distance+s.distance;o<a.distance&&(a.distance=o,a.predecessor=s.predecessor)})})}),r}(e,t||Zi,i||function(t){return e.outEdges(t)})},Zi=()=>1;function $i(e){var t={},i={},r=[];if(e.sinks().forEach(function s(n){if(Object.hasOwn(i,n))throw new Ji;Object.hasOwn(t,n)||(i[n]=!0,t[n]=!0,e.predecessors(n).forEach(s),delete i[n],r.push(n))}),Object.keys(t).length!==e.nodeCount())throw new Ji;return r}class Ji extends Error{constructor(){super(...arguments)}}var Qi=$i;$i.CycleException=Ji;var er=Qi;var tr=function(e,t,i){Array.isArray(t)||(t=[t]);var r=e.isDirected()?t=>e.successors(t):t=>e.neighbors(t),s="post"===i?ir:rr,n=[],a={};return t.forEach(t=>{if(!e.hasNode(t))throw new Error("Graph does not have node: "+t);s(t,r,a,n)}),n};function ir(e,t,i,r){for(var s=[[e,!1]];s.length>0;){var n=s.pop();n[1]?r.push(n[0]):Object.hasOwn(i,n[0])||(i[n[0]]=!0,s.push([n[0],!0]),sr(t(n[0]),e=>s.push([e,!1])))}}function rr(e,t,i,r){for(var s=[e];s.length>0;){var n=s.pop();Object.hasOwn(i,n)||(i[n]=!0,r.push(n),sr(t(n),e=>s.push(e)))}}function sr(e,t){for(var i=e.length;i--;)t(e[i],i,e);return e}var nr=tr;var ar=tr;var or=Li,lr=Fi;var hr={Graph:Vi.Graph,json:Mi,alg:{components:Gi,dijkstra:ji,dijkstraAll:Hi,findCycles:qi,floydWarshall:Ki,isAcyclic:function(e){try{er(e)}catch(e){if(e instanceof er.CycleException)return!1;throw e}return!0},postorder:function(e,t){return nr(e,t,"post")},preorder:function(e,t){return ar(e,t,"pre")},prim:function(e,t){var i,r=new or,s={},n=new lr;function a(e){var r=e.v===i?e.w:e.v,a=n.priority(r);if(void 0!==a){var o=t(e);o<a&&(s[r]=i,n.decrease(r,o))}}if(0===e.nodeCount())return r;e.nodes().forEach(function(e){n.add(e,Number.POSITIVE_INFINITY),r.setNode(e)}),n.decrease(e.nodes()[0],0);var o=!1;for(;n.size()>0;){if(i=n.removeMin(),Object.hasOwn(s,i))r.setEdge(i,s[i]);else{if(o)throw new Error("Input graph is not connected: "+e);o=!0}e.nodeEdges(i).forEach(a)}return r},tarjan:Yi,topsort:Qi},version:Vi.version};function cr(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function dr(e,t){if("_next"!==e&&"_prev"!==e)return t}let ur=hr.Graph,_r=class{constructor(){let e={};e._next=e._prev=e,this._sentinel=e}dequeue(){let e=this._sentinel,t=e._prev;if(t!==e)return cr(t),t}enqueue(e){let t=this._sentinel;e._prev&&e._next&&cr(e),e._next=t._next,t._next._prev=e,t._next=e,e._prev=t}toString(){let e=[],t=this._sentinel,i=t._prev;for(;i!==t;)e.push(JSON.stringify(i,dr)),i=i._prev;return"["+e.join(", ")+"]"}};var pr=function(e,t){if(e.nodeCount()<=1)return[];let i=function(e,t){let i=new ur,r=0,s=0;e.nodes().forEach(e=>{i.setNode(e,{v:e,in:0,out:0})}),e.edges().forEach(e=>{let n=i.edge(e.v,e.w)||0,a=t(e),o=n+a;i.setEdge(e.v,e.w,o),s=Math.max(s,i.node(e.v).out+=a),r=Math.max(r,i.node(e.w).in+=a)});let n=function(e){const t=[];for(let i=0;i<e;i++)t.push(i);return t}(s+r+3).map(()=>new _r),a=r+1;return i.nodes().forEach(e=>{yr(n,a,i.node(e))}),{graph:i,buckets:n,zeroIdx:a}}(e,t||fr);return function(e,t,i){let r,s=[],n=t[t.length-1],a=t[0];for(;e.nodeCount();){for(;r=a.dequeue();)gr(e,t,i,r);for(;r=n.dequeue();)gr(e,t,i,r);if(e.nodeCount())for(let n=t.length-2;n>0;--n)if(r=t[n].dequeue(),r){s=s.concat(gr(e,t,i,r,!0));break}}return s}(i.graph,i.buckets,i.zeroIdx).flatMap(t=>e.outEdges(t.v,t.w))};let fr=()=>1;function gr(e,t,i,r,s){let n=s?[]:void 0;return e.inEdges(r.v).forEach(r=>{let a=e.edge(r),o=e.node(r.v);s&&n.push({v:r.v,w:r.w}),o.out-=a,yr(t,i,o)}),e.outEdges(r.v).forEach(r=>{let s=e.edge(r),n=r.w,a=e.node(n);a.in-=s,yr(t,i,a)}),e.removeNode(r.v),n}function yr(e,t,i){i.out?i.in?e[i.out-i.in+t].enqueue(i):e[e.length-1].enqueue(i):e[0].enqueue(i)}let mr=hr.Graph;var br={addBorderNode:function(e,t,i,r){let s={width:0,height:0};arguments.length>=4&&(s.rank=i,s.order=r);return xr(e,"border",s,t)},addDummyNode:xr,applyWithChunking:wr,asNonCompoundGraph:function(e){let t=new mr({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(i=>{e.children(i).length||t.setNode(i,e.node(i))}),e.edges().forEach(i=>{t.setEdge(i,e.edge(i))}),t},buildLayerMatrix:function(e){let t=kr(Er(e)+1).map(()=>[]);return e.nodes().forEach(i=>{let r=e.node(i),s=r.rank;void 0!==s&&(t[s][r.order]=i)}),t},intersectRect:function(e,t){let i,r,s=e.x,n=e.y,a=t.x-s,o=t.y-n,l=e.width/2,h=e.height/2;if(!a&&!o)throw new Error("Not possible to find intersection inside of the rectangle");Math.abs(o)*l>Math.abs(a)*h?(o<0&&(h=-h),i=h*a/o,r=h):(a<0&&(l=-l),i=l,r=l*o/a);return{x:s+i,y:n+r}},mapValues:function(e,t){let i=t;"string"==typeof t&&(i=e=>e[t]);return Object.entries(e).reduce((e,[t,r])=>(e[t]=i(r,t),e),{})},maxRank:Er,normalizeRanks:function(e){let t=e.nodes().map(t=>{let i=e.node(t).rank;return void 0===i?Number.MAX_VALUE:i}),i=wr(Math.min,t);e.nodes().forEach(t=>{let r=e.node(t);Object.hasOwn(r,"rank")&&(r.rank-=i)})},notime:function(e,t){return t()},partition:function(e,t){let i={lhs:[],rhs:[]};return e.forEach(e=>{t(e)?i.lhs.push(e):i.rhs.push(e)}),i},pick:function(e,t){const i={};for(const r of t)void 0!==e[r]&&(i[r]=e[r]);return i},predecessorWeights:function(e){let t=e.nodes().map(t=>{let i={};return e.inEdges(t).forEach(t=>{i[t.v]=(i[t.v]||0)+e.edge(t).weight}),i});return Sr(e.nodes(),t)},range:kr,removeEmptyRanks:function(e){let t=e.nodes().map(t=>e.node(t).rank),i=wr(Math.min,t),r=[];e.nodes().forEach(t=>{let s=e.node(t).rank-i;r[s]||(r[s]=[]),r[s].push(t)});let s=0,n=e.graph().nodeRankFactor;Array.from(r).forEach((t,i)=>{void 0===t&&i%n!==0?--s:void 0!==t&&s&&t.forEach(t=>e.node(t).rank+=s)})},simplify:function(e){let t=(new mr).setGraph(e.graph());return e.nodes().forEach(i=>t.setNode(i,e.node(i))),e.edges().forEach(i=>{let r=t.edge(i.v,i.w)||{weight:0,minlen:1},s=e.edge(i);t.setEdge(i.v,i.w,{weight:r.weight+s.weight,minlen:Math.max(r.minlen,s.minlen)})}),t},successorWeights:function(e){let t=e.nodes().map(t=>{let i={};return e.outEdges(t).forEach(t=>{i[t.w]=(i[t.w]||0)+e.edge(t).weight}),i});return Sr(e.nodes(),t)},time:function(e,t){let i=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-i)+"ms")}},uniqueId:Cr,zipObject:Sr};function xr(e,t,i,r){for(var s=r;e.hasNode(s);)s=Cr(r);return i.dummy=t,e.setNode(s,i),s}const vr=65535;function wr(e,t){if(t.length>vr){const i=function(e,t=vr){const i=[];for(let r=0;r<e.length;r+=t){const s=e.slice(r,r+t);i.push(s)}return i}(t);return e.apply(null,i.map(t=>e.apply(null,t)))}return e.apply(null,t)}function Er(e){const t=e.nodes().map(t=>{let i=e.node(t).rank;return void 0===i?Number.MIN_VALUE:i});return wr(Math.max,t)}let Ar=0;function Cr(e){return e+""+ ++Ar}function kr(e,t,i=1){null==t&&(t=e,e=0);let r=e=>e<t;i<0&&(r=e=>t<e);const s=[];for(let t=e;r(t);t+=i)s.push(t);return s}function Sr(e,t){return e.reduce((e,i,r)=>(e[i]=t[r],e),{})}let Tr=pr,Rr=br.uniqueId;var Or={run:function(e){("greedy"===e.graph().acyclicer?Tr(e,function(e){return t=>e.edge(t).weight}(e)):function(e){let t=[],i={},r={};function s(n){Object.hasOwn(r,n)||(r[n]=!0,i[n]=!0,e.outEdges(n).forEach(e=>{Object.hasOwn(i,e.w)?t.push(e):s(e.w)}),delete i[n])}return e.nodes().forEach(s),t}(e)).forEach(t=>{let i=e.edge(t);e.removeEdge(t),i.forwardName=t.name,i.reversed=!0,e.setEdge(t.w,t.v,i,Rr("rev"))})},undo:function(e){e.edges().forEach(t=>{let i=e.edge(t);if(i.reversed){e.removeEdge(t);let r=i.forwardName;delete i.reversed,delete i.forwardName,e.setEdge(t.w,t.v,i,r)}})}};let Ir=br;var Nr={run:function(e){e.graph().dummyChains=[],e.edges().forEach(t=>function(e,t){let i,r,s,n=t.v,a=e.node(n).rank,o=t.w,l=e.node(o).rank,h=t.name,c=e.edge(t),d=c.labelRank;if(l===a+1)return;for(e.removeEdge(t),s=0,++a;a<l;++s,++a)c.points=[],r={width:0,height:0,edgeLabel:c,edgeObj:t,rank:a},i=Ir.addDummyNode(e,"edge",r,"_d"),a===d&&(r.width=c.width,r.height=c.height,r.dummy="edge-label",r.labelpos=c.labelpos),e.setEdge(n,i,{weight:c.weight},h),0===s&&e.graph().dummyChains.push(i),n=i;e.setEdge(n,o,{weight:c.weight},h)}(e,t))},undo:function(e){e.graph().dummyChains.forEach(t=>{let i,r=e.node(t),s=r.edgeLabel;for(e.setEdge(r.edgeObj,s);r.dummy;)i=e.successors(t)[0],e.removeNode(t),s.points.push({x:r.x,y:r.y}),"edge-label"===r.dummy&&(s.x=r.x,s.y=r.y,s.width=r.width,s.height=r.height),t=i,r=e.node(t)})}};const{applyWithChunking:Lr}=br;var Vr={longestPath:function(e){var t={};e.sources().forEach(function i(r){var s=e.node(r);if(Object.hasOwn(t,r))return s.rank;t[r]=!0;let n=e.outEdges(r).map(t=>null==t?Number.POSITIVE_INFINITY:i(t.w)-e.edge(t).minlen);var a=Lr(Math.min,n);return a===Number.POSITIVE_INFINITY&&(a=0),s.rank=a})},slack:function(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}};var Pr=hr.Graph,Mr=Vr.slack,Dr=function(e){var t,i,r=new Pr({directed:!1}),s=e.nodes()[0],n=e.nodeCount();r.setNode(s,{});for(;Br(r,e)<n;)t=Gr(r,e),i=r.hasNode(t.v)?Mr(e,t):-Mr(e,t),Fr(r,e,i);return r};function Br(e,t){return e.nodes().forEach(function i(r){t.nodeEdges(r).forEach(s=>{var n=s.v,a=r===n?s.w:n;e.hasNode(a)||Mr(t,s)||(e.setNode(a,{}),e.setEdge(r,a,{}),i(a))})}),e.nodeCount()}function Gr(e,t){return t.edges().reduce((i,r)=>{let s=Number.POSITIVE_INFINITY;return e.hasNode(r.v)!==e.hasNode(r.w)&&(s=Mr(t,r)),s<i[0]?[s,r]:i},[Number.POSITIVE_INFINITY,null])[1]}function Fr(e,t,i){e.nodes().forEach(e=>t.node(e).rank+=i)}var zr=Dr,jr=Vr.slack,Wr=Vr.longestPath,Ur=hr.alg.preorder,Hr=hr.alg.postorder,Yr=br.simplify,Xr=qr;function qr(e){e=Yr(e),Wr(e);var t,i=zr(e);for($r(i),Kr(i,e);t=Qr(i);)ts(i,e,t,es(i,e,t))}function Kr(e,t){var i=Hr(e,e.nodes());(i=i.slice(0,i.length-1)).forEach(i=>function(e,t,i){var r=e.node(i),s=r.parent;e.edge(i,s).cutvalue=Zr(e,t,i)}(e,t,i))}function Zr(e,t,i){var r=e.node(i).parent,s=!0,n=t.edge(i,r),a=0;return n||(s=!1,n=t.edge(r,i)),a=n.weight,t.nodeEdges(i).forEach(n=>{var o,l,h=n.v===i,c=h?n.w:n.v;if(c!==r){var d=h===s,u=t.edge(n).weight;if(a+=d?u:-u,o=i,l=c,e.hasEdge(o,l)){var _=e.edge(i,c).cutvalue;a+=d?-_:_}}}),a}function $r(e,t){arguments.length<2&&(t=e.nodes()[0]),Jr(e,{},1,t)}function Jr(e,t,i,r,s){var n=i,a=e.node(r);return t[r]=!0,e.neighbors(r).forEach(s=>{Object.hasOwn(t,s)||(i=Jr(e,t,i,s,r))}),a.low=n,a.lim=i++,s?a.parent=s:delete a.parent,i}function Qr(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function es(e,t,i){var r=i.v,s=i.w;t.hasEdge(r,s)||(r=i.w,s=i.v);var n=e.node(r),a=e.node(s),o=n,l=!1;n.lim>a.lim&&(o=a,l=!0);var h=t.edges().filter(t=>l===is(e,e.node(t.v),o)&&l!==is(e,e.node(t.w),o));return h.reduce((e,i)=>jr(t,i)<jr(t,e)?i:e)}function ts(e,t,i,r){var s=i.v,n=i.w;e.removeEdge(s,n),e.setEdge(r.v,r.w,{}),$r(e),Kr(e,t),function(e,t){var i=e.nodes().find(e=>!t.node(e).parent),r=Ur(e,i);(r=r.slice(1)).forEach(i=>{var r=e.node(i).parent,s=t.edge(i,r),n=!1;s||(s=t.edge(r,i),n=!0),t.node(i).rank=t.node(r).rank+(n?s.minlen:-s.minlen)})}(e,t)}function is(e,t,i){return i.low<=t.lim&&t.lim<=i.lim}qr.initLowLimValues=$r,qr.initCutValues=Kr,qr.calcCutValue=Zr,qr.leaveEdge=Qr,qr.enterEdge=es,qr.exchangeEdges=ts;var rs=Vr.longestPath,ss=Dr,ns=Xr,as=function(e){var t=e.graph().ranker;if(t instanceof Function)return t(e);switch(e.graph().ranker){case"network-simplex":default:ls(e);break;case"tight-tree":!function(e){rs(e),ss(e)}(e);break;case"longest-path":os(e);case"none":}};var os=rs;function ls(e){ns(e)}var hs=function(e){let t=function(e){let t={},i=0;function r(s){let n=i;e.children(s).forEach(r),t[s]={low:n,lim:i++}}return e.children().forEach(r),t}(e);e.graph().dummyChains.forEach(i=>{let r=e.node(i),s=r.edgeObj,n=function(e,t,i,r){let s,n,a=[],o=[],l=Math.min(t[i].low,t[r].low),h=Math.max(t[i].lim,t[r].lim);s=i;do{s=e.parent(s),a.push(s)}while(s&&(t[s].low>l||h>t[s].lim));n=s,s=r;for(;(s=e.parent(s))!==n;)o.push(s);return{path:a.concat(o.reverse()),lca:n}}(e,t,s.v,s.w),a=n.path,o=n.lca,l=0,h=a[l],c=!0;for(;i!==s.w;){if(r=e.node(i),c){for(;(h=a[l])!==o&&e.node(h).maxRank<r.rank;)l++;h===o&&(c=!1)}if(!c){for(;l<a.length-1&&e.node(h=a[l+1]).minRank<=r.rank;)l++;h=a[l]}e.setParent(i,h),i=e.successors(i)[0]}})};let cs=br;var ds={run:function(e){let t=cs.addDummyNode(e,"root",{},"_root"),i=function(e){var t={};function i(r,s){var n=e.children(r);n&&n.length&&n.forEach(e=>i(e,s+1)),t[r]=s}return e.children().forEach(e=>i(e,1)),t}(e),r=Object.values(i),s=cs.applyWithChunking(Math.max,r)-1,n=2*s+1;e.graph().nestingRoot=t,e.edges().forEach(t=>e.edge(t).minlen*=n);let a=function(e){return e.edges().reduce((t,i)=>t+e.edge(i).weight,0)}(e)+1;e.children().forEach(r=>us(e,t,n,a,s,i,r)),e.graph().nodeRankFactor=n},cleanup:function(e){var t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(t=>{e.edge(t).nestingEdge&&e.removeEdge(t)})}};function us(e,t,i,r,s,n,a){let o=e.children(a);if(!o.length)return void(a!==t&&e.setEdge(t,a,{weight:0,minlen:i}));let l=cs.addBorderNode(e,"_bt"),h=cs.addBorderNode(e,"_bb"),c=e.node(a);e.setParent(l,a),c.borderTop=l,e.setParent(h,a),c.borderBottom=h,o.forEach(o=>{us(e,t,i,r,s,n,o);let c=e.node(o),d=c.borderTop?c.borderTop:o,u=c.borderBottom?c.borderBottom:o,_=c.borderTop?r:2*r,p=d!==u?1:s-n[a]+1;e.setEdge(l,d,{weight:_,minlen:p,nestingEdge:!0}),e.setEdge(u,h,{weight:_,minlen:p,nestingEdge:!0})}),e.parent(a)||e.setEdge(t,l,{weight:0,minlen:s+n[a]})}let _s=br;var ps=function(e){e.children().forEach(function t(i){let r=e.children(i),s=e.node(i);if(r.length&&r.forEach(t),Object.hasOwn(s,"minRank")){s.borderLeft=[],s.borderRight=[];for(let t=s.minRank,r=s.maxRank+1;t<r;++t)fs(e,"borderLeft","_bl",i,s,t),fs(e,"borderRight","_br",i,s,t)}})};function fs(e,t,i,r,s,n){let a={width:0,height:0,rank:n,borderType:t},o=s[t][n-1],l=_s.addDummyNode(e,"border",a,i);s[t][n]=l,e.setParent(l,r),o&&e.setEdge(o,l,{weight:1})}function gs(e){e.nodes().forEach(t=>ys(e.node(t))),e.edges().forEach(t=>ys(e.edge(t)))}function ys(e){let t=e.width;e.width=e.height,e.height=t}function ms(e){e.y=-e.y}function bs(e){let t=e.x;e.x=e.y,e.y=t}let xs=br;var vs=function(e){let t={},i=e.nodes().filter(t=>!e.children(t).length),r=i.map(t=>e.node(t).rank),s=xs.applyWithChunking(Math.max,r),n=xs.range(s+1).map(()=>[]);function a(i){if(t[i])return;t[i]=!0;let r=e.node(i);n[r.rank].push(i),e.successors(i).forEach(a)}return i.sort((t,i)=>e.node(t).rank-e.node(i).rank).forEach(a),n};let ws=br.zipObject;function Es(e,t,i){let r=ws(i,i.map((e,t)=>t)),s=t.flatMap(t=>e.outEdges(t).map(t=>({pos:r[t.w],weight:e.edge(t).weight})).sort((e,t)=>e.pos-t.pos)),n=1;for(;n<i.length;)n<<=1;let a=2*n-1;n-=1;let o=new Array(a).fill(0),l=0;return s.forEach(e=>{let t=e.pos+n;o[t]+=e.weight;let i=0;for(;t>0;)t%2&&(i+=o[t+1]),t=t-1>>1,o[t]+=e.weight;l+=e.weight*i}),l}let As=br;let Cs=br;function ks(e,t,i){let r;for(;t.length&&(r=t[t.length-1]).i<=i;)t.pop(),e.push(r.vs),i++;return i}let Ss=function(e,t=[]){return t.map(t=>{let i=e.inEdges(t);if(i.length){let r=i.reduce((t,i)=>{let r=e.edge(i),s=e.node(i.v);return{sum:t.sum+r.weight*s.order,weight:t.weight+r.weight}},{sum:0,weight:0});return{v:t,barycenter:r.sum/r.weight,weight:r.weight}}return{v:t}})},Ts=function(e,t){let i={};return e.forEach((e,t)=>{let r=i[e.v]={indegree:0,in:[],out:[],vs:[e.v],i:t};void 0!==e.barycenter&&(r.barycenter=e.barycenter,r.weight=e.weight)}),t.edges().forEach(e=>{let t=i[e.v],r=i[e.w];void 0!==t&&void 0!==r&&(r.indegree++,t.out.push(i[e.w]))}),function(e){let t=[];function i(e){return t=>{t.merged||(void 0===t.barycenter||void 0===e.barycenter||t.barycenter>=e.barycenter)&&function(e,t){let i=0,r=0;e.weight&&(i+=e.barycenter*e.weight,r+=e.weight);t.weight&&(i+=t.barycenter*t.weight,r+=t.weight);e.vs=t.vs.concat(e.vs),e.barycenter=i/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}(e,t)}}function r(t){return i=>{i.in.push(t),0===--i.indegree&&e.push(i)}}for(;e.length;){let s=e.pop();t.push(s),s.in.reverse().forEach(i(s)),s.out.forEach(r(s))}return t.filter(e=>!e.merged).map(e=>As.pick(e,["vs","i","barycenter","weight"]))}(Object.values(i).filter(e=>!e.indegree))},Rs=function(e,t){let i=Cs.partition(e,e=>Object.hasOwn(e,"barycenter")),r=i.lhs,s=i.rhs.sort((e,t)=>t.i-e.i),n=[],a=0,o=0,l=0;r.sort((h=!!t,(e,t)=>e.barycenter<t.barycenter?-1:e.barycenter>t.barycenter?1:h?t.i-e.i:e.i-t.i)),l=ks(n,s,l),r.forEach(e=>{l+=e.vs.length,n.push(e.vs),a+=e.barycenter*e.weight,o+=e.weight,l=ks(n,s,l)});var h;let c={vs:n.flat(!0)};o&&(c.barycenter=a/o,c.weight=o);return c};var Os=function e(t,i,r,s){let n=t.children(i),a=t.node(i),o=a?a.borderLeft:void 0,l=a?a.borderRight:void 0,h={};o&&(n=n.filter(e=>e!==o&&e!==l));let c=Ss(t,n);c.forEach(i=>{if(t.children(i.v).length){let o=e(t,i.v,r,s);h[i.v]=o,Object.hasOwn(o,"barycenter")&&(a=o,void 0!==(n=i).barycenter?(n.barycenter=(n.barycenter*n.weight+a.barycenter*a.weight)/(n.weight+a.weight),n.weight+=a.weight):(n.barycenter=a.barycenter,n.weight=a.weight))}var n,a});let d=Ts(c,r);!function(e,t){e.forEach(e=>{e.vs=e.vs.flatMap(e=>t[e]?t[e].vs:e)})}(d,h);let u=Rs(d,s);if(o&&(u.vs=[o,u.vs,l].flat(!0),t.predecessors(o).length)){let e=t.node(t.predecessors(o)[0]),i=t.node(t.predecessors(l)[0]);Object.hasOwn(u,"barycenter")||(u.barycenter=0,u.weight=0),u.barycenter=(u.barycenter*u.weight+e.order+i.order)/(u.weight+2),u.weight+=2}return u};let Is=hr.Graph,Ns=br;var Ls=function(e,t,i,r){r||(r=e.nodes());let s=function(e){var t;for(;e.hasNode(t=Ns.uniqueId("_root")););return t}(e),n=new Is({compound:!0}).setGraph({root:s}).setDefaultNodeLabel(t=>e.node(t));return r.forEach(r=>{let a=e.node(r),o=e.parent(r);(a.rank===t||a.minRank<=t&&t<=a.maxRank)&&(n.setNode(r),n.setParent(r,o||s),e[i](r).forEach(t=>{let i=t.v===r?t.w:t.v,s=n.edge(i,r),a=void 0!==s?s.weight:0;n.setEdge(i,r,{weight:e.edge(t).weight+a})}),Object.hasOwn(a,"minRank")&&n.setNode(r,{borderLeft:a.borderLeft[t],borderRight:a.borderRight[t]}))}),n};let Vs=vs,Ps=function(e,t){let i=0;for(let r=1;r<t.length;++r)i+=Es(e,t[r-1],t[r]);return i},Ms=Os,Ds=Ls,Bs=function(e,t,i){let r,s={};i.forEach(i=>{let n,a,o=e.parent(i);for(;o;){if(n=e.parent(o),n?(a=s[n],s[n]=o):(a=r,r=o),a&&a!==o)return void t.setEdge(a,o);o=n}})},Gs=hr.Graph,Fs=br;var zs=function e(t,i){if(i&&"function"==typeof i.customOrder)return void i.customOrder(t,e);let r=Fs.maxRank(t),s=js(t,Fs.range(1,r+1),"inEdges"),n=js(t,Fs.range(r-1,-1,-1),"outEdges"),a=Vs(t);if(Us(t,a),i&&i.disableOptimalOrderHeuristic)return;let o,l=Number.POSITIVE_INFINITY;for(let e=0,i=0;i<4;++e,++i){Ws(e%2?s:n,e%4>=2),a=Fs.buildLayerMatrix(t);let r=Ps(t,a);r<l&&(i=0,o=Object.assign({},a),l=r)}Us(t,o)};function js(e,t,i){const r=new Map,s=(e,t)=>{r.has(e)||r.set(e,[]),r.get(e).push(t)};for(const t of e.nodes()){const i=e.node(t);if("number"==typeof i.rank&&s(i.rank,t),"number"==typeof i.minRank&&"number"==typeof i.maxRank)for(let e=i.minRank;e<=i.maxRank;e++)e!==i.rank&&s(e,t)}return t.map(function(t){return Ds(e,t,i,r.get(t)||[])})}function Ws(e,t){let i=new Gs;e.forEach(function(e){let r=e.graph().root,s=Ms(e,r,i,t);s.vs.forEach((t,i)=>e.node(t).order=i),Bs(e,i,s.vs)})}function Us(e,t){Object.values(t).forEach(t=>t.forEach((t,i)=>e.node(t).order=i))}let Hs=hr.Graph,Ys=br;var Xs=function(e){let t,i=Ys.buildLayerMatrix(e),r=Object.assign(function(e,t){let i={};function r(t,r){let s=0,n=0,a=t.length,o=r[r.length-1];return r.forEach((t,l)=>{let h=function(e,t){if(e.node(t).dummy)return e.predecessors(t).find(t=>e.node(t).dummy)}(e,t),c=h?e.node(h).order:a;(h||t===o)&&(r.slice(n,l+1).forEach(t=>{e.predecessors(t).forEach(r=>{let n=e.node(r),a=n.order;!(a<s||c<a)||n.dummy&&e.node(t).dummy||qs(i,r,t)})}),n=l+1,s=c)}),r}return t.length&&t.reduce(r),i}(e,i),function(e,t){let i={};function r(t,r,s,n,a){let o;Ys.range(r,s).forEach(r=>{o=t[r],e.node(o).dummy&&e.predecessors(o).forEach(t=>{let r=e.node(t);r.dummy&&(r.order<n||r.order>a)&&qs(i,t,o)})})}function s(t,i){let s,n=-1,a=0;return i.forEach((o,l)=>{if("border"===e.node(o).dummy){let t=e.predecessors(o);t.length&&(s=e.node(t[0]).order,r(i,a,l,n,s),a=l,n=s)}r(i,a,i.length,s,t.length)}),i}return t.length&&t.reduce(s),i}(e,i)),s={};["u","d"].forEach(n=>{t="u"===n?i:Object.values(i).reverse(),["l","r"].forEach(i=>{"r"===i&&(t=t.map(e=>Object.values(e).reverse()));let a=("u"===n?e.predecessors:e.successors).bind(e),o=function(e,t,i,r){let s={},n={},a={};return t.forEach(e=>{e.forEach((e,t)=>{s[e]=e,n[e]=e,a[e]=t})}),t.forEach(e=>{let t=-1;e.forEach(e=>{let o=r(e);if(o.length){o=o.sort((e,t)=>a[e]-a[t]);let r=(o.length-1)/2;for(let l=Math.floor(r),h=Math.ceil(r);l<=h;++l){let r=o[l];n[e]===e&&t<a[r]&&!Ks(i,e,r)&&(n[r]=e,n[e]=s[e]=s[r],t=a[r])}}})}),{root:s,align:n}}(0,t,r,a),l=function(e,t,i,r,s){let n={},a=function(e,t,i,r){let s=new Hs,n=e.graph(),a=function(e,t,i){return(r,s,n)=>{let a,o=r.node(s),l=r.node(n),h=0;if(h+=o.width/2,Object.hasOwn(o,"labelpos"))switch(o.labelpos.toLowerCase()){case"l":a=-o.width/2;break;case"r":a=o.width/2}if(a&&(h+=i?a:-a),a=0,h+=(o.dummy?t:e)/2,h+=(l.dummy?t:e)/2,h+=l.width/2,Object.hasOwn(l,"labelpos"))switch(l.labelpos.toLowerCase()){case"l":a=l.width/2;break;case"r":a=-l.width/2}return a&&(h+=i?a:-a),a=0,h}}(n.nodesep,n.edgesep,r);return t.forEach(t=>{let r;t.forEach(t=>{let n=i[t];if(s.setNode(n),r){var o=i[r],l=s.edge(o,n);s.setEdge(o,n,Math.max(a(e,t,r),l||0))}r=t})}),s}(e,t,i,s),o=s?"borderLeft":"borderRight";function l(e,t){let i=a.nodes(),r=i.pop(),s={};for(;r;)s[r]?e(r):(s[r]=!0,i.push(r),i=i.concat(t(r))),r=i.pop()}function h(e){n[e]=a.inEdges(e).reduce((e,t)=>Math.max(e,n[t.v]+a.edge(t)),0)}function c(t){let i=a.outEdges(t).reduce((e,t)=>Math.min(e,n[t.w]-a.edge(t)),Number.POSITIVE_INFINITY),r=e.node(t);i!==Number.POSITIVE_INFINITY&&r.borderType!==o&&(n[t]=Math.max(n[t],i))}return l(h,a.predecessors.bind(a)),l(c,a.successors.bind(a)),Object.keys(r).forEach(e=>n[e]=n[i[e]]),n}(e,t,o.root,o.align,"r"===i);"r"===i&&(l=Ys.mapValues(l,e=>-e)),s[n+i]=l})});let n=function(e,t){return Object.values(t).reduce((t,i)=>{let r=Number.NEGATIVE_INFINITY,s=Number.POSITIVE_INFINITY;Object.entries(i).forEach(([t,i])=>{let n=function(e,t){return e.node(t).width}(e,t)/2;r=Math.max(i+n,r),s=Math.min(i-n,s)});const n=r-s;return n<t[0]&&(t=[n,i]),t},[Number.POSITIVE_INFINITY,null])[1]}(e,s);return function(e,t){let i=Object.values(t),r=Ys.applyWithChunking(Math.min,i),s=Ys.applyWithChunking(Math.max,i);["u","d"].forEach(i=>{["l","r"].forEach(n=>{let a=i+n,o=e[a];if(o===t)return;let l=Object.values(o),h=r-Ys.applyWithChunking(Math.min,l);"l"!==n&&(h=s-Ys.applyWithChunking(Math.max,l)),h&&(e[a]=Ys.mapValues(o,e=>e+h))})})}(s,n),function(e,t){return Ys.mapValues(e.ul,(i,r)=>{if(t)return e[t.toLowerCase()][r];{let t=Object.values(e).map(e=>e[r]).sort((e,t)=>e-t);return(t[1]+t[2])/2}})}(s,e.graph().align)};function qs(e,t,i){if(t>i){let e=t;t=i,i=e}let r=e[t];r||(e[t]=r={}),r[i]=!0}function Ks(e,t,i){if(t>i){let e=t;t=i,i=e}return!!e[t]&&Object.hasOwn(e[t],i)}let Zs=br,$s=Xs;let Js=Or,Qs=Nr,en=as,tn=br.normalizeRanks,rn=hs,sn=br.removeEmptyRanks,nn=ds,an=ps,on={adjust:function(e){let t=e.graph().rankdir.toLowerCase();"lr"!==t&&"rl"!==t||gs(e)},undo:function(e){let t=e.graph().rankdir.toLowerCase();"bt"!==t&&"rl"!==t||function(e){e.nodes().forEach(t=>ms(e.node(t))),e.edges().forEach(t=>{let i=e.edge(t);i.points.forEach(ms),Object.hasOwn(i,"y")&&ms(i)})}(e);"lr"!==t&&"rl"!==t||(!function(e){e.nodes().forEach(t=>bs(e.node(t))),e.edges().forEach(t=>{let i=e.edge(t);i.points.forEach(bs),Object.hasOwn(i,"x")&&bs(i)})}(e),gs(e))}},ln=zs,hn=function(e){(function(e){let t=Zs.buildLayerMatrix(e),i=e.graph().ranksep,r=0;t.forEach(t=>{const s=t.reduce((t,i)=>{const r=e.node(i).height;return t>r?t:r},0);t.forEach(t=>e.node(t).y=r+s/2),r+=s+i})})(e=Zs.asNonCompoundGraph(e)),Object.entries($s(e)).forEach(([t,i])=>e.node(t).x=i)},cn=br,dn=hr.Graph;var un=function(e,t){let i=t&&t.debugTiming?cn.time:cn.notime;i("layout",()=>{let r=i(" buildLayoutGraph",()=>function(e){let t=new dn({multigraph:!0,compound:!0}),i=wn(e.graph());return t.setGraph(Object.assign({},pn,vn(i,_n),cn.pick(i,fn))),e.nodes().forEach(i=>{const r=vn(wn(e.node(i)),gn);Object.keys(yn).forEach(e=>{void 0===r[e]&&(r[e]=yn[e])}),t.setNode(i,r),t.setParent(i,e.parent(i))}),e.edges().forEach(i=>{let r=wn(e.edge(i));t.setEdge(i,Object.assign({},bn,vn(r,mn),cn.pick(r,xn)))}),t}(e));i(" runLayout",()=>function(e,t,i){t(" makeSpaceForEdgeLabels",()=>function(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(i=>{let r=e.edge(i);r.minlen*=2,"c"!==r.labelpos.toLowerCase()&&("TB"===t.rankdir||"BT"===t.rankdir?r.width+=r.labeloffset:r.height+=r.labeloffset)})}(e)),t(" removeSelfEdges",()=>function(e){e.edges().forEach(t=>{if(t.v===t.w){var i=e.node(t.v);i.selfEdges||(i.selfEdges=[]),i.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}(e)),t(" acyclic",()=>Js.run(e)),t(" nestingGraph.run",()=>nn.run(e)),t(" rank",()=>en(cn.asNonCompoundGraph(e))),t(" injectEdgeLabelProxies",()=>function(e){e.edges().forEach(t=>{let i=e.edge(t);if(i.width&&i.height){let i=e.node(t.v),r={rank:(e.node(t.w).rank-i.rank)/2+i.rank,e:t};cn.addDummyNode(e,"edge-proxy",r,"_ep")}})}(e)),t(" removeEmptyRanks",()=>sn(e)),t(" nestingGraph.cleanup",()=>nn.cleanup(e)),t(" normalizeRanks",()=>tn(e)),t(" assignRankMinMax",()=>function(e){let t=0;e.nodes().forEach(i=>{let r=e.node(i);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=Math.max(t,r.maxRank))}),e.graph().maxRank=t}(e)),t(" removeEdgeLabelProxies",()=>function(e){e.nodes().forEach(t=>{let i=e.node(t);"edge-proxy"===i.dummy&&(e.edge(i.e).labelRank=i.rank,e.removeNode(t))})}(e)),t(" normalize.run",()=>Qs.run(e)),t(" parentDummyChains",()=>rn(e)),t(" addBorderSegments",()=>an(e)),t(" order",()=>ln(e,i)),t(" insertSelfEdges",()=>function(e){var t=cn.buildLayerMatrix(e);t.forEach(t=>{var i=0;t.forEach((t,r)=>{var s=e.node(t);s.order=r+i,(s.selfEdges||[]).forEach(t=>{cn.addDummyNode(e,"selfedge",{width:t.label.width,height:t.label.height,rank:s.rank,order:r+ ++i,e:t.e,label:t.label},"_se")}),delete s.selfEdges})})}(e)),t(" adjustCoordinateSystem",()=>on.adjust(e)),t(" position",()=>hn(e)),t(" positionSelfEdges",()=>function(e){e.nodes().forEach(t=>{var i=e.node(t);if("selfedge"===i.dummy){var r=e.node(i.e.v),s=r.x+r.width/2,n=r.y,a=i.x-s,o=r.height/2;e.setEdge(i.e,i.label),e.removeNode(t),i.label.points=[{x:s+2*a/3,y:n-o},{x:s+5*a/6,y:n-o},{x:s+a,y:n},{x:s+5*a/6,y:n+o},{x:s+2*a/3,y:n+o}],i.label.x=i.x,i.label.y=i.y}})}(e)),t(" removeBorderNodes",()=>function(e){e.nodes().forEach(t=>{if(e.children(t).length){let i=e.node(t),r=e.node(i.borderTop),s=e.node(i.borderBottom),n=e.node(i.borderLeft[i.borderLeft.length-1]),a=e.node(i.borderRight[i.borderRight.length-1]);i.width=Math.abs(a.x-n.x),i.height=Math.abs(s.y-r.y),i.x=n.x+i.width/2,i.y=r.y+i.height/2}}),e.nodes().forEach(t=>{"border"===e.node(t).dummy&&e.removeNode(t)})}(e)),t(" normalize.undo",()=>Qs.undo(e)),t(" fixupEdgeLabelCoords",()=>function(e){e.edges().forEach(t=>{let i=e.edge(t);if(Object.hasOwn(i,"x"))switch("l"!==i.labelpos&&"r"!==i.labelpos||(i.width-=i.labeloffset),i.labelpos){case"l":i.x-=i.width/2+i.labeloffset;break;case"r":i.x+=i.width/2+i.labeloffset}})}(e)),t(" undoCoordinateSystem",()=>on.undo(e)),t(" translateGraph",()=>function(e){let t=Number.POSITIVE_INFINITY,i=0,r=Number.POSITIVE_INFINITY,s=0,n=e.graph(),a=n.marginx||0,o=n.marginy||0;function l(e){let n=e.x,a=e.y,o=e.width,l=e.height;t=Math.min(t,n-o/2),i=Math.max(i,n+o/2),r=Math.min(r,a-l/2),s=Math.max(s,a+l/2)}e.nodes().forEach(t=>l(e.node(t))),e.edges().forEach(t=>{let i=e.edge(t);Object.hasOwn(i,"x")&&l(i)}),t-=a,r-=o,e.nodes().forEach(i=>{let s=e.node(i);s.x-=t,s.y-=r}),e.edges().forEach(i=>{let s=e.edge(i);s.points.forEach(e=>{e.x-=t,e.y-=r}),Object.hasOwn(s,"x")&&(s.x-=t),Object.hasOwn(s,"y")&&(s.y-=r)}),n.width=i-t+a,n.height=s-r+o}(e)),t(" assignNodeIntersects",()=>function(e){e.edges().forEach(t=>{let i,r,s=e.edge(t),n=e.node(t.v),a=e.node(t.w);s.points?(i=s.points[0],r=s.points[s.points.length-1]):(s.points=[],i=a,r=n),s.points.unshift(cn.intersectRect(n,i)),s.points.push(cn.intersectRect(a,r))})}(e)),t(" reversePoints",()=>function(e){e.edges().forEach(t=>{let i=e.edge(t);i.reversed&&i.points.reverse()})}(e)),t(" acyclic.undo",()=>Js.undo(e))}(r,i,t)),i(" updateInputGraph",()=>function(e,t){e.nodes().forEach(i=>{let r=e.node(i),s=t.node(i);r&&(r.x=s.x,r.y=s.y,r.rank=s.rank,t.children(i).length&&(r.width=s.width,r.height=s.height))}),e.edges().forEach(i=>{let r=e.edge(i),s=t.edge(i);r.points=s.points,Object.hasOwn(s,"x")&&(r.x=s.x,r.y=s.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}(e,r))})};let _n=["nodesep","edgesep","ranksep","marginx","marginy"],pn={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},fn=["acyclicer","ranker","rankdir","align"],gn=["width","height","rank"],yn={width:0,height:0},mn=["minlen","weight","width","height","labeloffset"],bn={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},xn=["labelpos"];function vn(e,t){return cn.mapValues(cn.pick(e,t),Number)}function wn(e){var t={};return e&&Object.entries(e).forEach(([e,i])=>{"string"==typeof e&&(e=e.toLowerCase()),t[e]=i}),t}let En=br,An=hr.Graph;var Cn={graphlib:hr,layout:un,debug:{debugOrdering:function(e){let t=En.buildLayerMatrix(e),i=new An({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(t=>{i.setNode(t,{label:t}),i.setParent(t,"layer"+e.node(t).rank)}),e.edges().forEach(e=>i.setEdge(e.v,e.w,{},e.name)),t.forEach((e,t)=>{let r="layer"+t;i.setNode(r,{rank:"same"}),e.reduce((e,t)=>(i.setEdge(e,t,{style:"invis"}),t))}),i}},util:{time:br.time,notime:br.notime},version:"1.1.8"};class kn extends F{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=C(e.parent);for(let e of t){let t=e.layout;if(!t)continue;let r=ge(e.children[0]);if(!r)continue;var i=new Cn.graphlib.Graph;i.setGraph({edgesep:t._edgeSep}),i.setDefaultEdgeLabel(function(){return{}}),i.graph().rankdir=this._getDagreDirection(t.direction);let s=new Map;for(let t of e.children){let e=t.dataScope.getAttrVal(me);s.set(e,e+""),i.setNode(e,{label:t.text?t.text:"",width:t.bounds.width,height:t.bounds.height})}for(let e of r.linkList)i.setEdge(e.source,e.target);Cn.layout(i);const n={};let a=Math.min(...i.nodes().map(e=>i.node(e).y)),o=Math.min(...i.nodes().map(e=>i.node(e).x)),l=t.left-o,h=t.top-a;for(const e of i.nodes())n[e]={x:i.node(e).x+l,y:i.node(e).y+h};for(let t of e.children){let e=t.dataScope.getAttrVal(me);Fe(t,n[s.get(e)].x-t.x,n[s.get(e)].y-t.y)}}let r=V(e,!0);for(let e of r)x(e)}_getDagreDirection(e){switch(e){case K.Left2Right:return"LR";case K.Right2Left:return"RL";case K.Top2Bottom:return"TB";case K.Bottom2Top:return"BT"}}}class Sn extends F{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=C(e.parent);for(let e of t){let t=e.layout;if(!t)continue;let i=pe(e.children[0]);if(!i)continue;let s=r.hierarchy(i._data),n=Math.max(...e.children.map(e=>e.bounds.width)),a=Math.max(...e.children.map(e=>e.bounds.height)),o=t.orientation==H?[t.height,t.width]:[t.width,t.height],l=r.tree().nodeSize([n,a]).size(o)(s);this._apply(l,t,e)}x(e)}_apply(e,t,i){let r,s,n=i.children.filter(t=>t.dataScope.getAttrVal(me)==e.data[me])[0];switch(t.orientation){case H:r=e.y+t.left,s=e.x+t.top;break;case Y:r=e.x+t.left,s=t.top+e.y}if(Fe(n,r-n.x,s-n.y),e.children&&e.children.length>0)for(let r of e.children)this._apply(r,t,i)}}class Tn extends F{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=this._inputVars.filter(e=>e.type===Te.PROPERTY&&e.property===et.CHILDREN_ORDER)[0].element,i=t.layout,s=i.width?i.width:t.bounds.width,n=i.height?i.height:t.bounds.height,a=void 0===i.top?t.bounds.top:i.top,o=void 0===i.left?t.bounds.left:i.left,l=r.hierarchy(t).sum(e=>e.type===Vt.Rect?e.width*e.height:0);r.treemap().size([s,n])(l),this._apply(l,o,a);let h=V(e,!0);for(let e of h)x(e)}_apply(e,t,i){if(e.data.type==Vt.Collection&&e.children)for(let r of e.children)this._apply(r,t,i);else e.data.type==Vt.Rect&&(e.data.resize(e.x1-e.x0,e.y1-e.y0),Fe(e.data,e.x0+t-e.data.left,e.y0+i-e.data.top))}}class Rn extends F{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=C(e.parent);for(let e of t){if(!e.layout)continue;if(0===e.children.length)continue;let t=pe(e.children[0]);if(!t)continue;let i={};for(let t of e.children)i[t.dataScope.getAttrVal(me)]=t;e.children[0].type===Vt.Rect?this._layoutRects(t.getRoot(),t,i):this._layoutArcs(t.getRoot(),t,i)}x(e)}_layoutArcs(e,t,i){let r=t.getChildren(e);if(0===r.length)return;let s=i[e[me]],n=!s||s.type!=Vt.Arc&&s.type!=Vt.Pie?60:s.startAngle;for(let e=0;e<r.length;e++){let s=r[e],a=i[s[me]];if(a.type===Vt.Arc){let e=le(n+a.angle);a.setAngles(n,e),n=e}this._layoutArcs(s,t,i)}}_layoutRects(e,t,i){let r=t.getChildren(e);if(0===r.length)return;let s,n,a=i[e[me]];this._direction,s=a.left,n=a.bottom;for(let e=0;e<r.length;e++){let a=r[e],o=i[a[me]];Fe(o,s-o.left,n-o.top),s+=o.width,this._layoutRects(a,t,i)}}}class On extends F{constructor(e){super(e)}run(){super.run();let e=this.outputVar,t=this.inputVars[0],i=e.conditionalEncoding,r=t.context,s=e.result,n=i.responderComponent;s.clear();let a=Array.isArray(n)?n:[n];if(i.evalFunction)for(let e of a){C(e).forEach(e=>s.setValue(e.id,i.evalFunction(r,e)))}}}class In extends F{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=C(e.parent);for(let e of t){let t=e.layout;if(!t)continue;let i=360/e.children.length;for(let[r,s]of e.children.entries())Fe(s,t.x+t.radius-s.bounds.x,t.y-s.bounds.y),s._rotate=[r*i,t.x,t.y]}let i=V(e,!0);for(let e of i)x(e)}}class Nn extends F{constructor(e){super(e)}run(){super.run();let e=this._outputVars[0].element,t=C(e.parent);for(let i of t){let t=i.layout;if(!t)continue;let s=t._tree?t._tree._data:pe(i.children[0])._data,n=r.hierarchy(s);if(t.isRadial()){n=r.cluster().size([ae(t.angleExtent),t.radius])(n),t._d3Root=n;const e=new Map(n.descendants().map(e=>[e.data[me],[e.x,e.y]]));for(let r of i.children){let i=r.dataScope.getAttrVal(me);Fe(r,t.x-r.bounds.x,t.y-e.get(i)[1]-r.bounds.y),r._rotate=[oe(e.get(i)[0]),t.x,t.y]}}else if(t.orientation===Y){!t.width||t.width;let s=t.height?t.height:600;n=r.cluster().nodeSize([e.bounds.width+1,s/(n.height+1)])(n),t._d3Root=n;const a=new Map(n.descendants().map(e=>[e.data[me],[e.x,e.y]]));let o=1/0,l=-o;n.each(e=>{e.x>l&&(l=e.x),e.x<o&&(o=e.x)}),t._x0=o;for(let e of i.children){let i=e.dataScope.getAttrVal(me);Fe(e,a.get(i)[0]-o+t.left-e.bounds.x,a.get(i)[1]+t.top-e.bounds.y)}}else if(t.orientation===H){!t.width||t.width;let s=t.height?t.height:600;n=r.cluster().nodeSize([e.bounds.height,s/(n.height+1)])(n),t._d3Root=n;const a=new Map(n.descendants().map(e=>[e.data[me],[e.x,e.y]]));let o=1/0,l=-o;n.each(e=>{e.x>l&&(l=e.x),e.x<o&&(o=e.x)}),t._x0=o;for(let e of i.children){let i=e.dataScope.getAttrVal(me);Fe(e,a.get(i)[1]+t.left-e.bounds.x,a.get(i)[0]-o+t.top-e.bounds.y)}}}let i=V(e,!0);for(let e of i)x(e)}}class Ln extends Se{constructor(e,t){super(e),this._cond=t}get context(){return this._cond}}class Vn extends F{constructor(e,t,i){super(e),this._fn=t,this._compnt=i}run(){super.run();let e=this.inputVars.find(e=>e instanceof Ln);this.outputVar,this._fn(void 0,e.context,this._compnt)}}class Pn extends F{constructor(e){super(e)}run(){super.run();let e=this.outputVar,t=this.inputVars.find(e=>e instanceof Ht),i=e.encodings[0].dataTable.getAttributeType(t.attribute),r={};for(let t of e.encodings){let e=this._computeAttrValues(t,i);Object.assign(r,e)}e.attrValues=r}_computeAttrValues(e,t){let i=C(e.element),r={};if(e.element.type===Vt.Area&&["width","height","fillGradient"].indexOf(e.channel)>=0)for(let t of i)for(let i of t.vertices)r[i.id]=de(i).aggregateNumericalAttribute(e.attribute,e.aggregator);else switch(t){case xe.Boolean:break;case xe.Date:for(let t of i)r[t.id]=de(t).getAttrVal(e.attribute);break;case xe.String:try{if("count"==e.aggregator)for(let t of i)r[t.id]=de(t).getAttributeValues(e.attribute).length;else for(let t of i)r[t.id]=de(t).getAttrVal(e.attribute)}catch(t){throw new Error("Cannot bind "+this.channel+" to "+e.attribute+" : "+t)}break;default:if(e.attribute.startsWith("parent.")||e.attribute.startsWith("child.")){let t=e.dataTable.tree.nodeTable,s=e.attribute.split(".")[0],n=e.attribute.split(".")[1];for(let e of i){let i=de(e).getAttrVal(s);r[e.id]=new ce(t).cross(me,i).getAttrVal(n)}}else for(let t of i)r[t.id]=de(t).aggregateNumericalAttribute(e.attribute,e.aggregator)}if(e.transform)for(let t of i)r[t.id]=e.transform(r[t.id],t);return e.attrValues=r,r}}class Mn extends Se{constructor(e,t,i){super(e),this._dataset=i,this._predicate=t}get dataset(){return this._dataset}get predicate(){return this._predicate}}class Dn{constructor(){this._variables={},this._operators={},this._edges=[]}toJSON(){const e=this._edges.map(e=>({from:e.fromNode.id,to:e.toNode.id,isDirected:e.isDirected})),t={};for(const e in this._variables)t[e]=Object.values(this._variables[e]).map(e=>{let t={id:e.id,type:e.type,incoming:e.incomingEdges.map(e=>e.id),outgoing:e.outgoingEdges.map(e=>e.id),undirected:e.undirectedEdges.map(e=>e.id)};return"ChannelVar"===e.type?(t.channel=e.channel,t.element=e.element):"BoundsVar"===e.type||"DataScopeVar"===e.type?t.element=e.element:"dataValue"===e.type?(t.scale=e.scale,t.attrValues=e.attrValues):"FieldVar"===e.type?(t.field=e.field,t.dataset=e.dataset):"PropertyVar"===e.type?(t.property=e.property,t.element=e.element):t.scale=e.scale,t});const i={};for(const e in this._operators)i[e]=Object.values(this._operators[e]).map(e=>{let t={id:e.id,type:e.type,inputVars:e.inputVars.map(e=>e.id),outputVar:e.outputVar?e.outputVar.id:null};return e.type===z.DOMAIN_BUILDER?t.aggregator=e.aggregator:e.type===z.SCALE_BUILDER&&(t.channel=e.channel),t});return{edges:e,variables:t,operators:i}}getVariable(e,...t){if(Object.values(Te).indexOf(e)<0)throw console.log(e),new Error("Variable Type Not Known");let i=this.findVariable(e,t);if(i)return i;switch(e){case Te.CHANNEL:i=new Re(e,t[0],t[1]),"vertex"!=t[1].type&&"segment"!=t[1].type||this._connectPathElement2Size(t[1],i);break;case Te.PROPERTY:i=new $e(e,t[0],t[1]);break;case Te.ATTRIBUTE:i=new Ht(e,t[0],t[1]);break;case Te.ITEMS:i=new Mn(e,t[0],t[1]);break;case Te.ATTR_VALUE:i=new Zt(e,t[0]);break;case Te.DATASCOPE:i=new jt(e,t[0]);break;case Te.BOUNDS:i=new zt(e,t[0]);break;case Te.SCALE:i=new qe(e,t[0]);break;case Te.AFFIXATION:i=new yi(e,t[0]);break;case Te.ALIGNMENT:i=new Ai(e,t[0]);break;case Te.EVT_CTX:i=new Ln(e,t[0],t[1]);break;case Te.CONDITION_RESULT:i=new Ke(e,t[0],t[1])}return e in this._variables||(this._variables[e]={}),this._variables[e][i.id]=i,i}_connectPathElement2Size(e,t){let i=e.parent,r=t.channel,s=this.findVariable(Te.CHANNEL,["x"===r?"width":"height",i]);if(s){let e=s.incomingDataflow;e||(e=this.createOneWayDependency(z.CONDUIT)),this.connect(t,e),this.connect(e,s)}}findIncomingDataflowOperator(e,t){return t.incomingDataflow&&t.incomingDataflow.type===e?t.incomingDataflow:void 0}getIncomingDataflowOperator(e,t){let i=this.findIncomingDataflowOperator(e,t);return i||this.createOneWayDependency(e)}getOutgoingDataflowOperator(e,t){for(let i of t.outgoingEdges)if(i.toNode instanceof F&&i.toNode.type===e)return i.toNode;return this.createOneWayDependency(e)}createOneWayDependency(e,...t){if(Object.values(z).indexOf(e)<0)throw new Error("Dependency Type Not Known");let i;switch(e){case z.EVAL_BBOX:i=new Jt(e);break;case z.AFFIXER:i=new gi(e);break;case z.DATA_EXTRACTOR:i=new Pn(e,t[0]);break;case z.SCALE_BUILDER:i=new $t(e,t[0]);break;case z.ENCODER:i=new Ze(e,t[0]);break;case z.AXIS_PATH_PLACER:i=new oi(e);break;case z.AXIS_TICKS_PLACER:i=new li(e);break;case z.AXIS_LABELS_PLACER:i=new hi(e);break;case z.AXIS_TITLE_PLACER:i=new wi(e);break;case z.LINK_PLACER:i=new ki(e);break;case z.GRID_LAYOUT:i=new ci(e);break;case z.STACK_LAYOUT:i=new ui(e);break;case z.PACK_LAYOUT:i=new vi(e);break;case z.FORCE_LAYOUT:i=new Ci(e);break;case z.DIRECTED_LAYOUT:i=new kn(e);break;case z.TIDY_TREE_LAYOUT:i=new Sn(e);break;case z.TREEMAP_LAYOUT:i=new Tn(e);break;case z.STRATA_LAYOUT:i=new Rn(e);break;case z.CIRCULAR_LAYOUT:i=new In(e);break;case z.CLUSTER_LAYOUT:i=new Nn(e);break;case z.GRIDLINES_PLACER:i=new di(e);break;case z.BIN_TRANSFORMER:i=new pi(e);break;case z.FILTER_TRANSFORMER:i=new fi(e);break;case z.KDE_TRANSFORMER:i=new mi(e);break;case z.TARGET_EVALUATOR:i=new On(e);break;case z.TARGET_UPDATER:i=new Vn(e,t[0],t[1]);break;case z.CONDUIT:default:i=new _i(e)}return e in this._operators||(this._operators[e]={}),this._operators[e][i.id]=i,i}createMultiWayDependency(e){if(Object.values(z).indexOf(e)<0)throw new Error("Dependency Type Not Known");let t;return z.ALIGNER,t=new Ei(e),e in this._operators||(this._operators[e]={}),this._operators[e][t.id]=t,t}connect(e,t,i=!0){if(e instanceof Se&&t instanceof F){if(!t.inputVars.includes(e)){const r=new Ut(e,t,i);this._edges.push(r),e.outgoingEdges.push(r),t.inputVars.push(e)}}else if(e instanceof F&&t instanceof Se){if(!e.outputVars.includes(t)){const r=new Ut(e,t,i);this._edges.push(r),e.outputVars.push(t),t.incomingEdges.push(r)}}else if(e instanceof Se&&t instanceof Wt){if(!t.vars.includes(e)){const i=new Ut(e,t,!1);this._edges.push(i),t.vars.push(e),t.edges.push(e),e.undirectedEdges.push(i)}}else{if(!(e instanceof Wt&&t instanceof Se))throw new Error("An edge must connect a variable and an operator.");if(!e.vars.includes(t)){const i=new Ut(t,e,!1);this._edges.push(i),e.vars.push(t),e.edges.push(t),t.undirectedEdges.push(i)}}}disconnectChannelVarFromBBoxOperator(e){let t=this.getOutgoingDataflowOperator(z.EVAL_BBOX,e),i=e.outgoingEdges.find(i=>i.fromNode===e&&i.toNode===t);i&&this.disconnect(e,t,i)}disconnect(e,t,i){if(e instanceof Se&&t instanceof F){let r=e.outgoingEdges.findIndex(e=>e===i);r>=0&&(this._edges.splice(this._edges.indexOf(i),1),e.outgoingEdges.splice(r,1));let s=t.inputVars.findIndex(t=>t==e);s>=0&&t.inputVars.splice(s,1)}else if(e instanceof F&&t instanceof Se){let r=t.incomingEdges.findIndex(e=>e===i);r>=0&&(this._edges.splice(this._edges.indexOf(i),1),t.incomingEdges.splice(r,1));let s=e.outputVars.findIndex(e=>e===t);s>=0&&e.outputVars.splice(s,1)}}deleteVariable(e){for(let t=e.incomingEdges.length-1;t>=0;t--){let i=e.incomingEdges[t],r=i.fromNode;this.disconnect(r,e,i),r.isIsolated()&&delete this._operators[r.type][r.id]}for(let t=e.outgoingEdges.length-1;t>=0;t--){let i=e.outgoingEdges[t],r=i.toNode;this.disconnect(e,r,i),r.isIsolated()&&delete this._operators[r.type][r.id]}delete this._variables[e.type][e.id]}deleteOperator(e){for(let t=e.outputVars.length-1;t>=0;t--){let i=e.outputVars[t],r=i.incomingEdges.find(t=>t.fromNode===e&&t.toNode===i);this.disconnect(e,i,r),i.isIsolated()&&delete this._variables[i.type][i.id]}for(let t=e.inputVars.length-1;t>=0;t--){let i=e.inputVars[t],r=i.outgoingEdges.find(t=>t.fromNode===i&&t.toNode===e);this.disconnect(i,e,r),i.isIsolated()&&delete this._variables[i.type][i.id]}delete this._operators[e.type][e.id]}addInteraction(e){}_dfs(e,t,i){if(e&&0!==e.outgoingEdges.length)for(let r of e.outgoingEdges)r.isDirected&&(t.push(r.toNode),this._dfs(r.toNode.outputVars[0],t.slice(),i));else i.push(t)}processChange(e,t,...i){let r=this.findVariable(e,i);if(r){for(let e of r.outgoingEdges)if(e.isDirected){let i=e.toNode;i.run();let r=i.outputVars;if(r.length>0){let e=r[0];switch(e.type){case Te.ITEMS:this.processChange(e.type,t,e.predicate,e.dataset);break;case Te.ATTRIBUTE:this.processChange(e.type,t,e.attribute,e.dataset);break;case Te.BOUNDS:this.processChange(e.type,t,e.element);break;case Te.CHANNEL:this.processChange(e.type,t,e.channel,e.element);break;case Te.PROPERTY:this.processChange(e.type,t,e.property,e.element);break;case Te.SCALE:case Te.ATTR_VALUE:this.processChange(e.type,t,e.encodings[0]);break;case Te.CONDITION_RESULT:this.processChange(e.type,t,e.result)}}}for(let e of r.undirectedEdges)t.push(e.operator)}else console.warn("Unable to find variables matching the described change: ",e,i)}findVariable(e,t){if(!(e in this._variables))return null;let i=Object.values(this._variables[e]);switch(e){case Te.CHANNEL:return i.find(e=>e.channel==t[0]&&Pe(e.element)==Pe(t[1]));case Te.PROPERTY:return i.find(e=>e.property==t[0]&&e.element==t[1]);case Te.AFFIXATION:return i.find(e=>e.affixation==t[0]);case Te.ATTRIBUTE:return i.find(e=>e.attribute==t[0]&&e.dataset==t[1]);case Te.ITEMS:return i.find(e=>e.dataset==t[1]);case Te.ATTR_VALUE:case Te.SCALE:return i.find(e=>e.encodings.includes(t[0]));case Te.EVT_CTX:return i.find(e=>e.context===t[0]);case Te.CONDITION_RESULT:return i.find(e=>e.result==t[0]);case Te.DATASCOPE:default:return t[0].classId?i.find(e=>Pe(e.element)==Pe(t[0])):i.find(e=>e.element.id==t[0].id)}}findVariablesByElement(e){let t={};for(let i in this._variables){let r=Object.values(this._variables[i]).filter(t=>t.element&&Pe(t.element)==Pe(e));r.length>0&&(t[i]=r)}return t}}function Bn(e){return!(!E(e)&&e.type!=Vt.Glyph||e.dataScope)||e.type===Vt.Collection&&e.firstChild.dataScope.numTuples>1}function Gn(e,t,i,r){let s=r.getAttributeType(i);if(s!=xe.String&&s!=xe.Date&&s!=xe.Integer)throw new Error("Repeat only works on a string or date attribute: "+i+" is "+s);if(!function(e){if(Array.isArray(e)){if(1===e.length)return Bn(e[0]);for(let t of e)if(!E(t)||t.dataScope)return!1;return!0}return Bn(e)}(t))throw new Error("The "+t.type+" is not repeatable");return function(e,t,i,r){let s=r.getAttributeSummary(i).unique.map(e=>t.dataScope?t.dataScope.cross(i,e):new ce(r).cross(i,e));s=s.filter(e=>!e.isEmpty());let n=Ot(e);n.dataScope=t.dataScope?t.dataScope.clone():new ce(r),n.addChild(t),t._refBounds||(t._refBounds=t.bounds.clone());for(let e=1;e<s.length;e++){let e=Nt(t);n.addChild(e)}return n.children.forEach((e,t)=>e.dataScope=s[t]),n}(e,t,i,r)}class Fn{constructor(e,t,i,r,s){this._id="encoding_"+Mt(),this._elem=e,this._channel=t,this._attribute=i,this._table=s.table,this._aggregator=r,this._includeZero=s.includeZero,this._flipScale=s.flipScale,this._mapping=s.mapping,this._preferredRangeExtent=s.rangeExtent,this._preferredRangeStart=s.rangeStart,this._preferredDomain=s.domain,this._scaleType=s.scaleType,this._colorScheme=s.scheme,this._forLegend=s.forLegend,this._transform=s.transform,s.shareScale&&(this._baseEnc=s.shareScale),this._scales=[],this._elemGroups=[],this._elem2scale={},this._refElements=[],["width","height","radius","angle","thickness","radialDistance","strokeWidth","area"].indexOf(this._channel)>=0&&(this._includeZero=!0),this.initialize()}get id(){return this._id}initialize(){this._scales=[];let e=C(this._elem);if(this._elemGroups=[],"x"===this._channel||"y"===this._channel){let t=this._elem,i=L(t);if(i.layout&&i.layout.type==B.GRID){let e="x"===this._channel?i.layout.getElementsByCol(!0,t):i.layout.getElementsByRow(!0,t);for(let t of e)this._createScaleForElems(t)}else if("vertex"===this._elem.type&&(Be(this._elem.parent)||De(this._elem.parent))){let e=C(this._elem.parent).map(e=>k(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 i=t.parent.id;return e[i]||(e[i]=[]),e[i].push(t),e},{}),i=Object.values(t);for(let e of i)this._createScaleForElems(e)}else this._createScaleForElems(e)}_createScaleForElems(e){this._elemGroups.push(e);var t=function(e){if(e.scaleType)return new Yt(e.scaleType);if("text"===e.channel)return new Yt("ordinal");switch(e.dataTable.getAttributeType(e.attribute)){case xe.Boolean:break;case xe.Date:return new Yt("time");case xe.String:if("count"==e.aggregator)return new Yt("linear");if(e.channel.indexOf("Color")>=0){let t={};return t.scheme=e.colorScheme?e.colorScheme:"schemeCategory10",new Yt("ordinalColor",t)}return"src"===e.channel?new Yt("ordinal"):new Yt("point");default:return["strokeColor","fillColor","fillGradient"].indexOf(e.channel)>=0?e.mapping?new Yt("linear"):new Yt("sequentialColor",{scheme:e.colorScheme}):new Yt("linear")}}(this);this._scales.push(t);for(let i of e)this._elem2scale[i.id]=t}getScale(e){return this._elem2scale[e.id]}getAttrValue(e,t,i){let s=this.getScale(t).invert(e,i),n=this._attribute;if(this.dataTable.getAttributeType(n)===xe.Date){let e=C(t).map(e=>e.dataScope.getAttrVal(n));return e.sort((e,t)=>e-t),e[r.bisectLeft(e,s)]}return s}getChannelValue(e,t){return this.getScale(t).map(e)}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 this._table}get aggregator(){return this._aggregator}hasMultipleScales(){return this._scales.length>0}get scales(){return this._scales}getRangeStart(e){let t=this.getScale(e);return Math.min(...t.range)}getRangeExtent(e){return this.getScale(e).rangeExtent}get domain(){if(1===this._scales.length)return this._scales[0].domain;throw new Error("AttributeEncoding: multiple scales exist, specify element to get domain.")}get rangeExtent(){if(1===this._scales.length)return this._scales[0].rangeExtent;throw new Error("AttributeEncoding: multiple scales exist, specify element to get rangeExtent.")}get scaleType(){return this._scaleType}set scaleType(e){this._scaleType=e}getDomain(e){return this.getScale(e).domain}set domain(e){this._preferredDomain=e;for(let t of this._scales)t._scale.domain(e);for(let e of this._refElements)e instanceof ni&&e.createTicksLabels({});this._elem.scene.onChange(Te.ATTR_VALUE,this)}set rangeExtent(e){for(let t of this._scales)t.rangeExtent=e;for(let e of this._refElements)e instanceof ni&&e.createTicksLabels({});this._elem.scene.onChange(Te.PROPERTY,et.RANGE_EXTENT,this)}get transform(){return this._transform}set transform(e){this._transform=e,this._elem.scene.onChange(Te.PROPERTY,et.TRANSFORM,this)}set includeZero(e){this._includeZero=e;for(let e of this._refElements)e instanceof ni&&e.createTicksLabels({});this._elem.scene.onChange(Te.PROPERTY,et.INCLUDE_ZERO,this)}get includeZero(){return this._includeZero}set flipScale(e){this._flipScale=e,this._elem.scene.onChange(Te.PROPERTY,et.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=[]}pan(e,t,i){let r=i||this._elem;r.scene.createMask(r);let s=this.getDomain(r),n=Math.min(...s),a=Math.max(...s),o="log"!==this._scales[0].type,l=this.getAttrValue(e,r,o)-this.getAttrValue(e+t,r,o);(o||n+l>0)&&(this.domain=[n+l,a+l])}zoom(e,t,i,r){let s=r||this._elem;s.scene.createMask(s);let n=this.getDomain(s),a=Math.min(...n),o=Math.max(...n),l="log"!==this._scales[0].type,h=this.getAttrValue(t,s,l),c=a-(h-a)*e*i,d=o+(o-h)*e*i;c!==d&&(!l&&c<=0||(this.domain=[c,d]))}}class zn{constructor(){this._vals={},this._vals.elements=[]}set(e,t){this._vals[e]=t}get(e){return this._vals[e]}clear(){this._vals={},this._vals.elements=[]}}class jn{constructor(e,t,i,r){this._respCompnt=t,this._responderEval=i,this._efxFn=r,this._evtCtx=e,this._evalResult=new Kt}get responderComponent(){return this._respCompnt}get eventContext(){return this._evtCtx}get evalResult(){return this._evalResult}get evalFunction(){return this._responderEval}get stylingFunction(){return this._efxFn}}class Wn extends ee{constructor(e,t,i,r,s){super(s),this._type=Vt.Gridlines,this._id=this._type+Mt(),this._attribute=t,this._channel=e,this._scale=i,this._elems=r,this._args=s,"strokeColor"in s||(this.styles.strokeColor="#ddd"),"opacity"in s||(this.styles.opacity=.5),this.updateValues(),this._lines=[]}updateValues(){"values"in this._args?this._values=this._args.values:this._scale?this._values=ri(this._scale,this._channel,this._elems):this._values=this._elems.map(e=>e.dataScope.getAttrVal(this._attribute))}get type(){return this._type}get id(){return this._id}getSVGPathData(){let e="";if("radialDistance"===this._channel)for(let t of this._lines)e+="M "+t.x+" "+t.y+" m -"+t.r+" 0 a "+t.r+" "+t.r+" 0 1 0 "+2*t.r+" 0 a "+t.r+" "+t.r+" 0 1 0 -"+2*t.r+" 0 ";else for(let t of this._lines)e+=["M",t.x1,t.y1].join(" ")+[" L",t.x2,t.y2].join(" ")+" ";return e}_updateBounds(){if("radialDistance"===this._channel){let e=this._lines.map(e=>new g(e.x-e.r,e.y-e.y,2*e.r,2*e.r));this._bounds=y(e)}else{let e=this._lines.map(e=>e.x1).concat(this._lines.map(e=>e.x2)),t=this._lines.map(e=>e.y1).concat(this._lines.map(e=>e.y2)),i=Math.min(...e),r=Math.max(...e),s=Math.min(...t),n=Math.max(...t);this._bounds=new g(i,s,r-i,n-s)}}get elements(){return this._elems}get values(){return this._values}get channel(){return this._channel}get attribute(){return this._attribute}get scale(){return this._scale}get lines(){return this._lines}set lines(e){this._lines=e}}class Un extends D{constructor(e){super(),this.type=B.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:v.LEFT,this._vertCellAlignment="vertCellAlignment"in e&&e.vertCellAlignment?e.vertCellAlignment:v.BOTTOM,this._gap="gap"in e?e.gap:0}clone(){let e=new Un({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 Hn(e,t,i,r,s){let n=s.getAttributeType(i);if(n!=xe.String&&n!=xe.Date&&n!=xe.Integer)throw new Error("Divide only works on a string or date attribute: "+i+" is "+n);if(!Yn(t))throw new Error("The "+t.type+" is not dividable");switch(t.type){case Vt.Line:case Vt.Path:return;case Vt.Circle:return function(e,t,i,r,s){let n,a,o,l=C(t),h=i||X;if(h!=X&&h!=q)throw new Error("Unknown orientation: "+h);h===X&&l.forEach(i=>{let l=i.dataScope?i.dataScope:new ce(s),h=s.getUniqueAttributeValues(r).map(e=>l.cross(r,e));h=h.filter(e=>!e.isEmpty());let c=Ot(e);null==a&&(a=c.id),c._classId=a,c.dataScope=i.dataScope?i.dataScope:new ce(s);let d=i.parent;d.removeChild(i),delete e._itemMap[i.id];let u=360/h.length,_=90;for(let e=0;e<h.length;e++){let r=Rt({type:"arc",innerRadius:0,outerRadius:i.radius,x:i.x,y:i.y,startAngle:le(_-u*(e+1)),endAngle:le(_-u*e),strokeColor:i.strokeColor,fillColor:i.fillColor,strokeWidth:i.strokeWidth,opacity:i.opacity});o||(o=r.id),r.classId=o,r.dataScope=h[e],r._updateBounds(),r._refBounds=r.bounds.clone(),c.addChild(r),c._layout=new Un({orientation:X,direction:Z.CLOCKWISE}),c._layout.group=c,d.removeChild(i),d.addChild(c),i===t&&(n=c)}});return{newMark:n.children[0],collection:n}}(e,t,r,i,s);case Vt.Rect:return function(e,t,i,r,s){let n,a=C(t),o=i||H;if(o!=H&&o!=Y)throw new Error("Unknown orientation: "+o);let l=s.getUniqueAttributeValues(r).map(e=>new ce(s).cross(r,e)),h={},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),h[e.id]=t}let d,u=Rt({type:"rect",left:t.bounds.left,top:t.bounds.top,width:t.bounds.width,height:t.bounds.height,strokeColor:t.strokeColor,fillColor:t.fillColor,strokeWidth:t.strokeWidth,opacity:t.opacity});u._classId=u.id;for(let i of a){let r=Ot(e);null==d&&(d=r.id),r._classId=d,r.dataScope=i.dataScope?i.dataScope:new ce(s);let a=i.parent;a.removeChild(i),delete e._itemMap[i.id];let l=h[i.id],c=i.bounds,_=c.left,p=c.top,f=o==H?c.width/l.length:c.width,g=o==H?c.height:c.height/l.length;for(let e=0;e<l.length;e++){let t=Nt(u);t.dataScope=l[e],t.resize(f,g),t._updateBounds(),t._refBounds=t.bounds.clone(),r.addChild(t)}a.addChild(r),r._layout=new Un({orientation:o,left:_,top:p}),r._layout.group=r,i==t&&(n=r)}return{newMark:n.children[0],collection:n}}(e,t,r,i,s);case Vt.Area:return function(e,t,i,r,s){let n,a=C(t),o=i||H;if(o!=H&&o!=Y)throw new Error("Unknown orientation: "+o);let l,h=s.getUniqueAttributeValues(r).map(e=>new ce(s).cross(r,e)),c={},d=0;for(let e of a){let t=h;e.dataScope&&(t=h.map(t=>t.merge(e.dataScope)),t=t.filter(e=>!e.isEmpty())),t.length>d&&(d=t.length),c[e.id]=t}let u=Object.assign({},t.styles);u.vertices=t.vertices.map(e=>[e.x,e.y]),u.type="area",u.orientation=t.orientation,u.baseline=t.baseline;let _=Rt(u);if(_._classId=_.id,t.vertices)for(let e=0;e<t.vertices.length;e++)t.vertices[e].dataScope&&(_.vertices[e]._dataScope=t.vertices[e].dataScope.clone());for(let i of a){let r=Ot(e);null==l&&(l=r.id),r._classId=l,r.dataScope=i.dataScope?i.dataScope:new ce(s);let a=i.parent;a.removeChild(i),delete e._itemMap[i.id];let h=c[i.id],d=i.bounds,u=d.left,p=d.top,f=o==H?d.width/h.length:d.width,g=o==H?d.height:d.height/h.length;for(let e=0;e<h.length;e++){let t=Nt(_);t.dataScope=h[e],console.log(t.dataScope),t.resize(f,g),t._updateBounds(),t._refBounds=t.bounds.clone(),r.addChild(t);for(let e of t.vertices)e.dataScope?e.dataScope=t.dataScope.merge(e.dataScope):e.dataScope=t.dataScope}a.addChild(r),r._layout=new Un({orientation:o,left:u,top:p}),r._layout.group=r,i==t&&(n=r)}return{newMark:n.children[0],collection:n}}(e,t,r,i,s);case Vt.Ring:return function(e,t,i,r,s){let n,a,o,l=C(t),h=i||X;if(h!=X&&h!=q)throw new Error("Unknown orientation: "+h);h===X&&l.forEach(i=>{let l=i.dataScope?i.dataScope:new ce(s),h=s.getUniqueAttributeValues(r).map(e=>l.cross(r,e));h=h.filter(e=>!e.isEmpty());let c=Ot(e);null==a&&(a=c.id),c._classId=a,c.dataScope=i.dataScope?i.dataScope:new ce(s);let d=i.parent;d.removeChild(i),delete e._itemMap[i.id];let u=360/h.length,_=90;for(let e=0;e<h.length;e++){let r=Rt({type:"arc",innerRadius:i.innerRadius,outerRadius:i.outerRadius,x:i.x,y:i.y,startAngle:le(_-u*(e+1)),endAngle:le(_-u*e),strokeColor:i.strokeColor,fillColor:i.fillColor,strokeWidth:i.strokeWidth,opacity:i.opacity});o||(o=r.id),r.classId=o,r.dataScope=h[e],r._updateBounds(),r._refBounds=r.bounds.clone(),c.addChild(r),c._layout=new Un({orientation:X,direction:Z.CLOCKWISE}),c._layout.group=c,d.removeChild(i),d.addChild(c),i===t&&(n=c)}});return{newMark:n.children[0],collection:n}}(e,t,r,i,s);case Vt.Pie:case Vt.Arc:return function(e,t,i,r,s){let n,a,o,l=C(t),h=i||X;if(h!=X&&h!=q)throw new Error("Unknown orientation: "+h);h===X||l.forEach(i=>{let l=i.dataScope?i.dataScope:new ce(s),h=s.getUniqueAttributeValues(r).map(e=>l.cross(r,e));h=h.filter(e=>!e.isEmpty());let c=Ot(e);null==a&&(a=c.id),c._classId=a,c.dataScope=i.dataScope?i.dataScope:new ce(s);let d=i.parent;d.removeChild(i),delete e._itemMap[i.id];for(let e=0;e<h.length;e++){let r=Rt({type:"arc",innerRadius:i.innerRadius+e*(i.outerRadius-i.innerRadius)/h.length,outerRadius:i.innerRadius+(e+1)*(i.outerRadius-i.innerRadius)/h.length,x:i.x,y:i.y,startAngle:i.startAngle,endAngle:i.endAngle,strokeColor:i.strokeColor,fillColor:i.fillColor,strokeWidth:i.strokeWidth,opacity:i.opacity});o||(o=r.id),r.classId=o,r.dataScope=h[e],r._updateBounds(),r._refBounds=r.bounds.clone(),c.addChild(r),c._layout=new Un({orientation:q}),c._layout.group=c,d.removeChild(i),d.addChild(c),i===t&&(n=c)}});return{newMark:n.children[0],collection:n}}(e,t,r,i,s)}}function Yn(e){if([Vt.Line,Vt.Circle,Vt.Rect,Vt.Area,Vt.Ring,Vt.Pie,Vt.Path].indexOf(e.type)<0)return!1;if(e.type===Vt.Path&&(e.closed||!e.firstVertex.dataScope))return!1;if(e.dataScope){let t=C(e);for(let e of t)if(e.dataScope.numTuples>1)return!0;return!1}return!0}function Xn(e,t,i,r){let s=r.getAttributeType(i);if(s!=xe.String&&s!=xe.Date&&s!=xe.Integer)throw new Error("Repopulate only works on a string or date attribute: "+i+" is "+s);let n=C(t);for(let e of n){let t=r.getAttributeSummary(i).unique.map(t=>e.dataScope?e.dataScope.cross(i,t):new ce(r).cross(i,t));t=t.filter(e=>!e.isEmpty());let s=e.children.length-t.length,n=t.length-e.children.length;for(let t=0;t<s;t++)e.removeChildAt(e.children.length-1);let a=e._children.length;for(let t=0;t<n;t++){let i=Nt(e._children[t%a]);e.addChild(i)}e.children.forEach((e,i)=>e.dataScope=t[i])}}class qn{constructor(e,t){this._elem=e,this._base=t,this._id=Kn(e,t),this._channels={},this._attribute=void 0}get id(){return this._id}get element(){return this._elem}get base(){return this._base}get channels(){return Object.keys(this._channels)}addChannel(e,t){let i={};i.elemAnchor="elementAnchor"in t?t.elementAnchor:"x"==e||"angle"==e?v.CENTER:v.MIDDLE,i.baseAnchor="baseAnchor"in t?t.baseAnchor:"x"==e||"angle"==e?v.CENTER:v.MIDDLE,i.offset="offset"in t?t.offset:0,"attribute"in t&&(this._attribute=t.attribute),this._channels[e]=i}hasChannel(e){return e in this._channels}getElementAnchor(e){return this._channels[e].elemAnchor}getBaseAnchor(e){return this._channels[e].baseAnchor}getOffset(e){return this._channels[e].offset}get attribute(){return this._attribute?this._attribute:Gt}}function Kn(e,t){return(e.classId?e.classId:e.id)+":"+(t.classId?t.classId:t.id)}function Zn(e,t,i,r){e.dataScope&&e.dataScope.dataTable.hasAttribute(t)?function(e,t,i,r){if(!e.dataScope.dataTable.hasAttribute(t))return void console.warn("Cannot order collection children by an non-existent attribute",t);let s;if(t===Gt)s=(e,i)=>parseInt(e.dataScope.getAttrVal(t).substring(1))-parseInt(i.dataScope.getAttrVal(t).substring(1));else{switch(e.children[0].dataScope.getAttributeType(t)){case xe.Date:break;case xe.Number:case xe.Integer:s=(e,i)=>e.dataScope.aggregateNumericalAttribute(t)-i.dataScope.aggregateNumericalAttribute(t);break;case xe.String:s=r?(e,i)=>r.indexOf(e.dataScope.getAttrVal(t))-r.indexOf(i.dataScope.getAttrVal(t)):(e,i)=>e.dataScope.getAttrVal(t)<i.dataScope.getAttrVal(t)?-1:1}}e.children.sort(s),i&&e.children.reverse()}(e,t,i,r):function(e,t,i){let r;switch(t){case"x":case"y":case"width":case"height":r=(e,i)=>e.bounds[t]-i.bounds[t];break;default:r=(e,i)=>e[t]-i[t]}e._children.sort(r),i&&e.children.reverse()}(e,t,i),e._sortBy={property:t,descending:i,vals:r}}function $n(e,t,i,r){e.vertices[0].dataScope&&e.vertices[0].dataScope.dataTable.hasAttribute(t)?function(e,t,i,r){let s;if(t===Gt)s=(e,i)=>parseInt(e.dataScope.getAttrVal(t).substring(1))-parseInt(i.dataScope.getAttrVal(t).substring(1));else{switch(e.vertices[0].dataScope.getAttributeType(t)){case xe.Date:break;case xe.Number:case xe.Integer:s=(e,i)=>e.dataScope.aggregateNumericalAttribute(t)-i.dataScope.aggregateNumericalAttribute(t);break;case xe.String:s=r?(e,i)=>r.indexOf(e.dataScope.getAttrVal(t))-r.indexOf(i.dataScope.getAttrVal(t)):(e,i)=>e.dataScope.getAttrVal(t)<i.dataScope.getAttrVal(t)?-1:1}}e.vertices.sort(s),i&&e.vertices.reverse()}(e,t,i,r):function(e,t,i){let r=(e,i)=>e[t]-i[t];e.vertices.sort(r),i&&e.vertices.reverse()}(e,t,i),e._sortBy={property:t,descending:i,vals:r}}class Jn extends D{constructor(e){super(),this.type=B.GRID,this._numCols=e.numCols,this._numRows=e.numRows,this._start="start"in e?e.start:U.TopLeft,this._direction="direction"in e?e.direction:W.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&&G("h",e.horzCellAlignment)?e.horzCellAlignment:v.LEFT,this._cellVertAlignment="vertCellAlignment"in e&&G("v",e.vertCellAlignment)?e.vertCellAlignment:v.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}set numCols(e){this._numCols=e}set numRows(e){this._numRows=e}get numRows(){return this._numRows?this._numRows:this._numCols?Math.ceil(this.group.children.length/this._numCols):0}clone(){let e=new Jn({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 i=[],r=this.group.children;for(let t=0;t<this.numRows;t++){let s=this._grid[t].filter(e=>null!=e).map(e=>r[e]);if(e){let e=[];for(let t of s)e=e.concat(V(t));i.push(e)}else i.push(s)}return t&&(i=this._filterElementsByExample(i,t)),i}getElementsByCol(e,t){let i=[],r=this.group.children,s=this._grid;for(let t=0;t<this.numCols;t++){let n=s.map(e=>e[t]).filter(e=>null!=e).map(e=>r[e]);if(e){let e=[];for(let t of n)e=e.concat(V(t));i.push(e)}else i.push(n)}return t&&(i=this._filterElementsByExample(i,t)),i}getElementsByCell(e,t){let i=[],r=this.group.children;for(let t=0;t<r.length;t++)if(e){let e=V(r[t]);i.push(e)}else i.push(r[t]);return t&&(i=this._filterElementsByExample(i,t)),i}_filterElementsByExample(e,t){let i;return"vertex"===t.type?(i=e.map(e=>e.filter(e=>e.classId===t.parent.classId)),i=i.map(e=>k(t,e))):"segment"===t.type?(i=e.map(e=>e.filter(e=>e.classId===t.parent.classId)),i=i.map(e=>S(t,e))):i=e.map(e=>e.filter(e=>e.classId===t.classId)),i}getIndex(e){let t=e;for(;t&&t.parent!==this.group;)t=t.parent;return this.group.children.indexOf(t)}getRowCol(e){let t,i;switch(this._direction){case W.RowFirst:t=Math.floor(e/this.numCols),i=e%this.numCols;break;case W.ColumnFirst:t=e%this.numRows,i=Math.floor(e/this.numRows);break;default:throw new Error("Invalid fill direction. Use 'row_first' or 'column_first'.")}return this._start.toLowerCase().includes("bottom")&&(t=this.numRows-1-t),this._start.toLowerCase().includes("right")&&(i=this.numCols-1-i),{row:t,col:i}}get startCorner(){return this._start}set startCorner(e){this._start=e}get direction(){return this._direction}set direction(e){this._direction=e}}class Qn extends mt{constructor(e,t){super(),this._type=Vt.Axis,this._id=this._type+Mt(),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:Y,this._numberFormat=t.numberFormat?t.numberFormat:""}get attribute(){return this._enc.attribute}get channel(){return this._enc.channel}get attributeType(){return Bt(this._enc.element).getFieldType(this.attribute)}get orientation(){return this._orientation}get textColor(){return this._textColor}}class ea extends Qn{constructor(e,t){super(e,t),"numCols"in t||"numRows"in t?(this._numCols=t.numCols,this._numRows=t.numRows):this._orientation===Y?this._numCols=1:this._numRows=1,this._initialize()}_initialize(){let e=this._enc.element.scene,t=this._enc.attribute,i=this._enc.scales[0],r=new Dt(i.domain.map(e=>({category:e,value:i.map(e)}))),s=r.getUniqueAttributeValues("category").sort((e,t)=>t.length-e.length)[0],n=this._enc.element,a=n instanceof ee&&n.closed&&"strokeColor"!==this._enc.channel?n.strokeWidth:0;if(this._orientation===Y){let i=0;this._showTitle&&(this.addChild(new Ct({fillColor:this._textColor,fontSize:this._fontSize,text:t,x:this._x,y:this._y,anchor:["left","top"]})),i=parseFloat(this._fontSize)+5);let o=e.mark("rect",{top:this._y+2+i,left:this._x,width:10,height:10,strokeWidth:a,strokeColor:n.strokeColor,opacity:n.opacity}),l=e.mark("text",{text:s,fillColor:this._textColor,fontSize:this._fontSize,x:this._x+20,y:this._y+i+12+a,anchor:["left","bottom"]}),h=e.glyph(o,l),c=e.repeat(h,r);e.encode(l,{channel:"text",attribute:"category",forLegend:!0}),e.encode(o,{channel:"fillColor",attribute:"category",shareScale:this._enc,forLegend:!0}),c.layout=new Jn({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:n.strokeColor,opacity:n.opacity}),i=e.mark("text",{text:s,fillColor:this._textColor,fontSize:this._fontSize,x:this._x+15,y:this._y,anchor:["left","top"]}),o=e.glyph(t,i),l=e.repeat(o,r);e.encode(i,{channel:"text",attribute:"category",forLegend:!0}),e.encode(t,{channel:"fillColor",attribute:"category",shareScale:this._enc,forLegend:!0}),l.layout=new Jn({numCols:this._numCols,numRows:this._numRows,colGap:15}),this.addChild(l)}}}class ta extends Qn{constructor(e,t){super(e,t),this._initialize()}_initialize(){let e,t,i,s=this._enc.element.scene,n=this._enc.attribute;if(this._orientation==Y?(e=15,t=300):(e=300,t=15),this._showTitle){let t=s.mark("text",{fillColor:this._textColor,text:n,x:this._x+e/2,y:this._y,anchor:["center","middle"]});this.addChild(t),i=20}else i=0;let a,o=s.mark("rect",{top:this._y+i,left:this._x,width:e,height:t,strokeWidth:0,opacity:this._enc.element.opacity}),l=Object.values(this._enc.attrValues),h=[Math.min(...l),Math.max(...l)],c=this._enc.mapping,d=[],u=[],_=r.format(this._numberFormat);if(c){let r=Object.keys(c).map(e=>parseFloat(e)).sort((e,t)=>e-t);this._orientation==Y?(a=new j({x1:0,y1:100,x2:0,y2:0}),r.forEach(r=>{let n=(r-h[0])/(h[1]-h[0]);a.addStop(100*n,c[r],1);let o=s.mark("line",{x1:this._x+e,x2:this._x+e+5,y1:this._y+t-n*t+i,y2:this._y+t-n*t+i,strokeColor:this._strokeColor});u.push(o);let l=s.mark("text",{fillColor:this._textColor,text:this._numberFormat?_(r):r.toFixed(0),x:this._x+e+5+5,y:this._y+t-n*t+i,anchor:["left","middle"]});d.push(l)})):(a=new j({x1:0,y1:0,x2:100,y2:0}),r.forEach(r=>{let n=(r-h[0])/(h[1]-h[0]);a.addStop(100*n,c[r],1);let o=s.mark("line",{x1:this._x+n*e,x2:this._x+n*e,y1:this._y+20-5+i,y2:this._y+t+5+i,strokeColor:this._strokeColor});u.push(o);let l=s.mark("text",{fillColor:this._textColor,text:this._numberFormat?_(r):r.toFixed(0),x:this._x+n*e,y:this._y+t+5+i,anchor:["center","top"]});d.push(l)}))}else{let r=this._enc.scales[0].domain,o=Bt(this._enc.element),l=o.getAttributeType(n),h=[],c=l===xe.Date?o.getUniqueFieldValues(n):[...new Set(Object.values(this._enc.attrValues))];if(c.length<=10)h=c,h.sort((e,t)=>e-t);else if(l===xe.Date){c.sort((e,t)=>e-t);for(let e=0;e<c.length;e+=Math.ceil(c.length/10))h.push(c[e])}else{let e=(r[1]-r[0])/9;for(let t=0;t<10;t++)h.push(r[0]+t*e)}let p=0,f=(h[h.length-1]-h[0])/h.length;for(;f<1;)f*=10,p++;h=h.map(e=>e.toFixed(p)),this._orientation==Y?(a=new j({x1:0,y1:100,x2:0,y2:0}),h.forEach(h=>{let c=(h-r[0])/(r[1]-r[0]);a.addStop(100*c,this._enc.scales[0].map(h),1);let p=s.mark("line",{x1:this._x+e,x2:this._x+e+5,y1:this._y+t-c*t+i,y2:this._y+t-c*t+i,strokeColor:this._strokeColor});u.push(p);let f=s.mark("text",{fillColor:this._textColor,text:l===xe.Date?o.getRawValue(n,h):this._numberFormat?_(h):h,x:this._x+e+5+5,y:this._y+t-c*t+i,anchor:["left","middle"]});d.push(f)})):(a=new j({x1:0,y1:0,x2:100,y2:0}),h.forEach(h=>{let c=(h-r[0])/(r[1]-r[0]);a.addStop(100*c,this._enc.scale.map(h),1);let _=s.mark("line",{x1:this._x+c*e,x2:this._x+c*e,y1:this._y+t+i,y2:this._y+t+5+i,strokeColor:this._strokeColor});u.push(_);let p=s.mark("text",{fillColor:this._textColor,text:l===xe.Date?o.getRawValue(n,h):h,x:this._x+c*e,y:this._y+t+5+i,anchor:["center","top"]});d.push(p)}))}o.styles.fillColor=a,this.addChild(o);for(let e of d)this.addChild(e);for(let e of u)this.addChild(e)}}class ia extends mt{constructor(e){super(),this._type=Vt.Composite,this._id=e&&e.id?e.id:this._type+Mt()}addChild(e){let t=e.parent;super.addChild(e);let i=N(e)._depGraph;t&&ot(t,e,i),lt(this,e,i)}}class ra{constructor(e,t,i){this._elems=e,this._channel=t,this._anchor=i}get elements(){return this._elems}get channel(){return this._channel}get anchor(){return this._anchor}}class sa extends D{constructor(e){super(),this.type=B.STRATA,this._direction=e.direction,this._gap="gap"in e?e.gap:0}clone(){return new sa({direction:this._direction,gap:this._gap})}}function na(e,t,i,r,s,n){switch(t.type){case Vt.Circle:case Vt.Ring:return function(e,t,i,r,s,n){let a,o=i||$.OUTWARD,l=s||50;if(o!==$.INWARD&&o!==$.OUTWARD)throw"Unknown direction to stratify";let h,c=C(t,e),d=Array.isArray(n)?n:[n];if(r){let i=Ot(e);i.dataScope=void 0,null==h&&(h=i.id),i._classId=h;let r=c.map(e=>d[0].getNode(e.dataScope.getAttrVal(me)));aa(c,r,d[0],i,t.classId?t.classId:t.id,400,350,o,l),a=i}else c.forEach((i,r)=>{let s=Ot(e);s.dataScope=void 0,null==h&&(h=s.id),s._classId=h;let n=i.parent;oa(i,t.id,o,l,d[r],d[r].getRoot(),s,e,!0),s._layout=new sa({direction:o}),s._layout.group=s,n.addChild(s),i===t&&(a=s)});return a}(e,t,i,r,s,n);case Vt.Rect:return function(e,t,i,r,s,n){let a,o,l=i||K.Top2Bottom,h=s||50;if(!Object.values(K).includes(l))throw"Unknown direction to stratify";return C(t).forEach(i=>{let r=Ot(e);r.dataScope=void 0,null==o&&(o=r.id),r._classId=o;let s=i.parent;la(i,t.id,l,h,n,n.getRoot(),r,e,!0),r._layout=new sa({direction:l}),r._layout.group=r,s.addChild(r),i===t&&(a=r)}),a}(e,t,i,0,s,n)}}function aa(e,t,i,r,s,n,a,o,l){let h=t.map(e=>i.getParent(e)).filter((e,t,i)=>i.findIndex(t=>t[me]===e[me])===t);if(h=h.filter(e=>e!==i.getRoot()),0===h.length)return;let c=[];for(let t of h){let h,d,u,p=e.filter(e=>i.getParent(i.getNode(e.dataScope.getAttrVal(me)))===t);if(p[0].type===Vt.Circle){let e=p.map(e=>_(n,a,e.bounds.x,e.bounds.y)-e.radius),t=p.map(e=>_(n,a,e.bounds.x,e.bounds.y)+e.radius);u=o===$.OUTWARD?Math.max(...t):Math.min(...e)-l;let i=p.map(e=>he(e.bounds.x,e.bounds.y,n,a)),r=p.map(e=>he(n+_(n,a,e.bounds.x,e.bounds.y),a-e.radius,n,a)),s=i.map((e,t)=>e-r[t]),c=i.map((e,t)=>e+r[t]),f=s.concat(c);h=Math.min(...f),d=Math.max(...f)}else p[0].type===Vt.Arc&&(h=360,d=-360,p.forEach(e=>{let t=e.startAngle,i=e.endAngle;i<t&&(i+=360),h=Math.min(h,t),d=Math.max(d,i)}),h=le(h),d=le(d),u=o===$.OUTWARD?Math.max(...p.map(e=>e.outerRadius)):Math.min(...p.map(e=>e.innerRadius))-l);let f=Rt({type:"arc",innerRadius:u,outerRadius:u+l,x:n,y:a,startAngle:le(h),endAngle:le(d),strokeColor:e[0].strokeColor,fillColor:e[0].fillColor,strokeWidth:e[0].strokeWidth,opacity:e[0].opacity});f._updateBounds(),f.dataScope=i.getNodeDataScope(t),f._classId=s,r.addChild(f),c.push(f)}aa(c,h,i,r,s,n,a,o,l)}function oa(e,t,i,r,s,n,a,o,l){l&&(e.dataScope=s.getNodeDataScope(n),e._classId=t);let h=s.getChildren(n);if(0===h.length)return;let c=e.type===Vt.Circle||e.type===Vt.Ring?60:e.startAngle,d=(e.type===Vt.Circle||e.type===Vt.Ring?360:e.angle)/h.length;for(let n=0;n<h.length;n++){let o,l;l=i===$.OUTWARD?e.type===Vt.Circle?e.radius:e.outerRadius:e.type===Vt.Circle?e.radius-r:e.innerRadius-r,o=Rt(360===d?{type:"ring",innerRadius:l,outerRadius:l+r,x:e.x,y:e.y,strokeColor:e.strokeColor,fillColor:e.fillColor,strokeWidth:e.strokeWidth,opacity:e.opacity}:{type:"arc",innerRadius:l,outerRadius:l+r,x:e.x,y:e.y,startAngle:le(c+d*n),endAngle:le(c+d*(n+1)),strokeColor:e.strokeColor,fillColor:e.fillColor,strokeWidth:e.strokeWidth,opacity:e.opacity}),o._updateBounds(),o.dataScope=s.getNodeDataScope(h[n]),o._classId=t+"_strata",a.addChild(o),oa(o,t,i,r,s,h[n],a)}}function la(e,t,i,r,s,n,a,o,l){l&&(e.dataScope=s.getNodeDataScope(n),e._classId=t,a.addChild(e));let h,c,d,u=s.getChildren(n);if(0!==u.length){h=e.left,c=e.bottom,d=e.width/u.length;for(let n=0;n<u.length;n++){let o=Nt(e);Fe(o,h-o.left,c-o.top),o.resize(d,r),o._updateBounds(),h+=d,o.dataScope=s.getNodeDataScope(u[n]),o._classId=t,a.addChild(o),la(o,t,i,r,s,u[n],a)}}}class ha{constructor(e,t,i,r){this._id=e,this._event=i,this._target=t,this._evtCtx=new zn,this._cumulative=r}get id(){return this._id}get event(){return this._event}get eventContext(){return this._evtCtx}get target(){return this._target}isCumulative(){return this._cumulative}isMouseDriven(){return["brush","brushX","brushY","click","hover"].includes(this._event)}isKeyboardDriven(){return["keydown","keyup"].includes(this._event)}isWidgetDriven(){return["change","input"].includes(this._event)}}class ca extends mt{constructor(e){super(),this._itemMap={},this._peerIndex=new Map,this._type=Vt.Scene,this._id=e&&e.id?e.id:this._type+Mt(),e&&e.fillColor&&(this.fillColor=e.fillColor),this._encodings={},this._relations=[],this._triggers={},this._condEncodings={},this._depGraph=new Dn}get depGraph(){return this._depGraph}get interactionTriggers(){return this._triggers}buildPeerIndex(){this._peerIndex=new Map;let e=this._peerIndex;M(this,t=>{t.classId&&(e.has(t.classId)||e.set(t.classId,[]),e.get(t.classId).push(t))})}mark(e,t){if(Object.values(Lt).indexOf(e)<0)throw new Error("Mascot does not allow directly creating a "+e);let i=void 0===t?{}:t;i.type=e;let r=Rt(i);return null!==r&&(r._classId=r.id,this.addChild(r),this._itemMap[r.id]=r,tt(r,this._depGraph),lt(this,r,this._depGraph)),r}glyph(...e){let t=[];for(let i of e)t.push([i.parent,i]);let i=It(e);if(null!==i){i._classId=i.id,this.addChild(i),this._itemMap[i.id]=i;for(let e of t)ot(e[0],e[1],this._depGraph);ht(i,this._depGraph),lt(this,i,this._depGraph)}return i}composite(){let e=new ia;return null!==e&&(e._classId=e.id,this.addChild(e),this._itemMap[e.id]=e,at(e,this._depGraph),lt(this,e,this._depGraph)),e}attach(e,t){if(e.type==Vt.Glyph)for(let t of e.children)t._refBounds||(t._refBounds=t.bounds.clone());e.dataScope=new ce(t)}repeat(e,t,i){let r=i||{};if(r.attribute=r.attribute||Gt,function(e,t,i){if(!e||void 0===t)throw new Error("Incomplete information to do repeat. You must specify an element, a categorical data attribute and a data table");if(t instanceof _e||t instanceof fe){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 Dt&&be(i.attribute,t);if(i.layout&&!(i.layout instanceof D))throw new Error("Invalid layout: "+i.layout)}(e,t,r),t instanceof _e||t instanceof fe){let i=e[0].parent,r=e[1].parent,[s,n]=function(e,t,i,r){let s=r.nodeTable.getAttributeSummary(me).unique.map(e=>t.dataScope?t.dataScope.cross(me,e):new ce(r.nodeTable).cross(me,e)),n=Ot(e),a=Ot(e),o={};a.dataScope=t.dataScope?t.dataScope.clone():new ce(r.nodeTable),a.addChild(t);for(let e=1;e<s.length;e++){let e=Nt(t);a.addChild(e)}a.children.forEach((e,t)=>{e.dataScope=s[t],e.links=[],o[e.dataScope.getAttrVal(me)]=e});let l=r.linkTable.getAttributeSummary(Gt).unique.map(e=>i.dataScope?i.dataScope.cross(Gt,e):new ce(r.linkTable).cross(Gt,e));n.dataScope=i.dataScope?i.dataScope.clone():new ce(r.linkTable),n.addChild(i);for(let e=1;e<l.length;e++){let e=Nt(i);n.addChild(e)}n.children.forEach((e,t)=>e.dataScope=l[t]);let h=r instanceof _e?"parent":"source",c=r instanceof _e?"child":"target";for(let e of n.children){let t=e.dataScope.getAttrVal(h),i=e.dataScope.getAttrVal(c),r=o[t],s=o[i];e.source=r,e.target=s,r.links.push(e),s.links.push(e)}return[a,n]}(this,e[0],e[1],t);return this.buildPeerIndex(),ot(i,e[0],this._depGraph),ot(r,e[1],this._depGraph),nt(s,this._depGraph),nt(n,this._depGraph),lt(s,e[0],this._depGraph),lt(s.parent,s,this._depGraph),lt(n,e[1],this._depGraph),lt(n.parent,n,this._depGraph),[s,n]}if(t instanceof Dt){let i=e.parent,s=Gn(this,e,r.attribute,t);return this.buildPeerIndex(),ot(i,e,this._depGraph),nt(s,this._depGraph),lt(s,e,this._depGraph),lt(s.parent,s,this._depGraph),r.layout&&(s.layout=r.layout),s}}divide(e,t,i){let r=i||{};if(r.attribute=r.attribute||Gt,console.log("------ divide by",r.attribute," ----"),function(e,t,i){if(!e||void 0===t)throw new Error("Incomplete information to do divide. You must specify an element, a categorical data attribute and a data table");if(t instanceof Dt&&be(i.attribute,t),i.layout&&!(i.layout instanceof D))throw new Error("Invalid layout: "+i.layout)}(e,t,r),t instanceof _e||t instanceof fe)throw"Not implemented";if(t instanceof Dt){let{newMark:i,collection:s}=Hn(this,e,r.attribute,r.orientation,t);return this.buildPeerIndex(),it(e,this._depGraph),tt(i,this._depGraph),nt(s,this._depGraph),lt(s,i,this._depGraph),s.parent.type!==Vt.Scene&<(s.parent,s,this._depGraph),this.onChange(Te.CHANNEL,"width",i),{newMark:i,collection:s}}}densify(e,t,i){let r=i||{};if(r.attribute=r.attribute||Gt,console.log("------ densify by",r.attribute," ----"),function(e,t,i){if(!e||void 0===t)throw new Error("Incomplete information to do densification. You must specify an element, a categorical data attribute and a data table");t instanceof Dt&&be(i.attribute,t)}(e,t,r),t instanceof _e||t instanceof fe)throw"Not implemented";if(t instanceof Dt){let i=Ae(0,e,r.attribute,r.orientation,t);return this.buildPeerIndex(),it(e,this._depGraph),tt(i,this._depGraph),i.parent.type!==Vt.Scene&<(i.parent,i,this._depGraph),this.onChange(Te.CHANNEL,"width",i),i}}stratify(e,t,i){if(!(t instanceof _e||Array.isArray(t)&&t.every(e=>e instanceof _e)))throw"Cannot stratify on a non-tree dataset";if(![Vt.Circle,Vt.Rect,Vt.Ring].includes(e.type))throw"Cannot stratify elements that are not rects, circles, or rings";let r=i||{},s=r.direction,n=r.size,a=e.parent,o=na(this,e,s,r.startFromLeaf,n,t);return this.buildPeerIndex(),ot(a,e,this._depGraph),nt(o,this._depGraph),o.children.length>0&<(o,o.firstChild,this._depGraph),lt(o.parent,o,this._depGraph),o}repopulate(e,t,i){e.dataScope=void 0;let r=e;for(let e in i){Xn(0,r,i[e],t);let s=Ne(r.children[0]);for(let e of s){Ie(e,this),rt(e,this._depGraph);for(let t of e.refElements)si(t,this),st(t,this._depGraph);e.clearRefElements()}let n=C(r);for(let e of n)if(e.layout){for(let t of e.layout.refElements)si(t,this),st(t,this._depGraph);e.layout.clearRefElements()}r=r.children[0]}e.dataScope=new ce(t),this.buildPeerIndex(),this.onChange(Te.CHANNEL,"width",e.children[0])}classify(e,t){let i=t||{};console.log("------ classify by",i.attribute," ----"),function(e,t,i,r){let s=C(t);for(let t of s){let s,n={},a=t.children;for(let e of a){let t=e.dataScope.getAttrVal(i);t in n||(n[t]=[]),n[t].push(e)}let o=Bt(a[0]);for(let a in n){let l=Ot(e);t.addChild(l),void 0===s&&(s=l.id),l._classId=s,l.dataScope=t.dataScope?t.dataScope.cross(i,a):new ce(o).cross(i,a);for(let e of n[a])l.addChild(e);r&&(l._layout=r.clone(),l._layout.group=l)}}}(this,e,i.attribute,i.layout),this.buildPeerIndex(),ot(e,e.firstChild.firstChild,this._depGraph),nt(e.firstChild,this._depGraph),lt(e.firstChild,e.firstChild.firstChild,this._depGraph),lt(e,e.firstChild,this._depGraph),this.onChange(Te.CHANNEL,"width",e.firstChild.firstChild)}affix(e,t,i,r){e.dataScope.dataTable!==e.dataScope.dataTable&&console.warn("Affix: elements and base elements are not created from the same table");let s=Kn(e,t),n=this._relations.find(e=>e.id===s);n||(n=new qn(e,t),this._relations.push(n)),n.addChannel(i,r||{}),function(e,t){let i=t.getVariable(Te.AFFIXATION,e),r=t.getOutgoingDataflowOperator(z.AFFIXER,i);t.connect(i,r);for(let i of e.channels){let s=t.getVariable(Te.CHANNEL,i,e.element),n=t.getVariable(Te.CHANNEL,i,e.base);t.connect(n,r),t.connect(r,s)}r.run()}(n,this._depGraph)}align(e,t,i){let r=new ra(e,t,i);!function(e,t){let i=t.createMultiWayDependency(z.ALIGNER),r=t.getVariable(Te.ALIGNMENT,e);t.connect(r,i);for(let r of e.elements){let s=t.getVariable(Te.CHANNEL,e.channel,r);t.connect(s,i)}i.run()}(r,this._depGraph),this._relations.push(r)}encode(e,t){if("rowId"===t.attribute&&(t.attribute=Gt),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 i=Bt(e);if(i.tree){let e=t.attribute;if(e.indexOf(".")>0&&!i.tree.nodeTable.hasAttribute(e.split(".")[1]))throw new Error("Data attribute does not exist in the data table")}else if(!i||!i.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===Vt.Area?t=e.parent:e.type===Vt.Area&&(t=e),t&&!t._refBounds&&C(t).forEach(e=>e._refBounds=e.bounds.clone())}(e);let i=t.aggregator?t.aggregator:"sum";console.log("------ encode",t.channel,t.attribute," --");let r=Ve(e,t.channel);if(r&&t.attribute!==r.attribute){Ie(r,this),rt(r,this._depGraph);for(let e of r.refElements)si(e,this),st(e,this._depGraph);r.clearRefElements()}t.table=Bt(e);let s=new Fn(e,t.channel,t.attribute,i,t);return this._addAttributeEncoding(s),pt(s,this._depGraph,t.shareScale),t.shareScale?this.onChange(Te.ATTR_VALUE,s):this.onChange(Te.CHANNEL,t.channel,e),s}connect(e,t){let i={};e.forEach(e=>i[e.dataScope.getAttrVal(me)]=e);let r=t[0].dataScope.dataTable,s=r.tree?"parent":"source",n=r.tree?"child":"target";for(let t of e)t.links=[];for(let e of t){let t=e.dataScope.getAttrVal(s),r=e.dataScope.getAttrVal(n),a=i[t],o=i[r];e.source=a,e.target=o,a.links.push(e),o.links.push(e)}_t(e.find(e=>e.links.length>0),this._depGraph),this.onChange(Te.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,i,r,s){!function(e,t,i,r,s){if(!("event"in e)||!("target"in e))throw"Target and event must be specified in the trigger";if(!("component"in i))throw"Responder component must be specified";if(Array.isArray(r)){if(!r.every(e=>"function"==typeof e))throw"Styling rules must be a function";if(s&&!Array.isArray(s))throw"An array of effect setters must be accompanied by an array of animation effects";if(s&&Array.isArray(s)&&s.length!==r.length)throw"the length of effect setters is not equal to the length of animation effects"}else if("function"!=typeof r)throw"Styling rules must be a function"}(e,0,t,r,s);let n=e.event,a=function(e){return["string"==typeof e.target?e.target:e.target.classId?e.target.classId:e.target.id,e.event].join("-")}(e);n=0===n.indexOf("brush")?"brush":0===n.indexOf("drag")?"drag":n,n in this._triggers||(this._triggers[n]={}),a in this._triggers[n]||(this._triggers[n][a]=new ha(a,e.target,e.event,e.cumulative));let o=this._triggers[n][a].eventContext,l=new jn(o,t.component,i,r);return a in this._condEncodings||(this._condEncodings[a]=[]),this._condEncodings[a].push(l),function(e,t,i,r){let s=t.responderComponent,n=r.getVariable(Te.EVT_CTX,e),a=i.properties?i.properties:i.channels;if(t.evalFunction){let e=r.getVariable(Te.CONDITION_RESULT,t.evalResult,t),i=r.findIncomingDataflowOperator(z.TARGET_EVALUATOR,e);i||(i=r.createOneWayDependency(z.TARGET_EVALUATOR,t.evalFunction)),r.connect(n,i),r.connect(i,e);for(let t of a){let i=Array.isArray(s)?s:[s];for(let s of i){let i=r.getVariable(Te.CHANNEL,t,s),n=i.incomingDataflow;if(n&&n instanceof Ze&&n.outputVar.channel===t)r.connect(e,n);else if(!n){let n=r.createOneWayDependency(z.ENCODER);r.connect(e,n),r.connect(n,i),n.storeValues(s,t)}}}}else for(let e of a){Object.values(Oe).includes(e)?r.getVariable(Te.CHANNEL,e,s):r.getVariable(Te.PROPERTY,Je(e),s);let i=r.createOneWayDependency(z.TARGET_UPDATER,t.stylingFunction,s);r.connect(n,i)}}(o,l,t,this._depGraph),this._triggers[n][a]}onChange(e,...t){if(Object.values(Te).indexOf(e)<0)throw new Error("Unknown Variable Type: "+e);let i=[];this._depGraph.processChange(e,i,...t);for(let e of i)e.run()}gridlines(e,t,i){let r=i||{},s=r.element?Ve(r.element,e):Le(t,e,this);if(s){s.attribute!==t&&console.warn("Cannot create a "+e+" axis for "+t);let i=[];if("x"==e)for(let e of s.scales)i.push({scale:e,elems:s.getElements(e)});else if("width"==e){let e=L(s.element),t=s.scales[0];if(e.layout&&e.layout.type==B.GRID&&e.layout.numCols>1){let r=e.layout.getElementsByCol(!0);for(let e of r)i.push({scale:t,elems:e})}else i.push({scale:s.scales[0],elems:s.getElements(s.scales[0])})}else if("y"==e){let e=L(s.element);if(e.layout&&e.layout.type==B.GRID&&e.layout.numRows>1){let t=e.layout.getElementsByRow(!0,s.element);for(let e of t)i.push({scale:s.getScale(e[0]),elems:e})}else i.push({scale:s.scales[0],elems:s.getElements(s.scales[0])})}else if("height"==e){let e=L(s.element),t=s.scales[0];if(e.layout&&e.layout.type==B.GRID&&e.layout.numRows>1){let r=e.layout.getElementsByRow(!0,s.element);for(let e of r)i.push({scale:t,elems:e})}else i.push({scale:t,elems:s.getElements(t)})}else if("radialDistance"==e){let e=r.element?r.element:s.element;i.push({scale:s.scales[0],elems:C(e,e.parent)})}for(let e of i){let t=new Wn(s.channel,s.attribute,e.scale,e.elems,r);this.addChild(t),s.addRefElement(t),yt(t,this._depGraph),lt(this,t,this._depGraph)}}else{let i=r.element?r.element:R(this,t);if(!i)return void console.warn("Cannot create "+e+" gridlines for "+t);let s=O(i.parent);if(!s.layout)return void console.warn("Cannot create "+e+" gridlines for "+t);let n=C(s);for(let i of n){let s=[];i.layout.type==B.GRID&&i.layout.numRows>1&&"x"==e?s=i.layout.getElementsByRow():i.layout.type==B.GRID&&i.layout.numCols>1&&"y"==e?s=i.layout.getElementsByCol():s.push(i.children);for(let n of s){let s=new Wn(e,t,null,n,r);this.addChild(s),i.layout.addRefElement(s),yt(s,this._depGraph),lt(this,s,this._depGraph)}}}}axis(e,t,i){let r=i||{},s="rowId"==t?Gt:t,n=[],a=r.element?Ve(r.element,e):Le(s,e,this);if(a){a.attribute!==s&&console.warn("Cannot create a "+e+" axis for "+s);let t=[];if("x"==e||"width"==e){let e=L(r.element?r.element:a.element);if(e.layout&&e.layout.type==B.GRID&&e.layout.numCols>1){let i=e.layout.getElementsByCell(!0,a.element);for(let e of i)t.push({scale:a.getScale(e[0]),elems:e})}else t.push({scale:a.scales[0],elems:a.getElements(a.scales[0])})}else if("y"==e||"height"==e){let e=L(r.element?r.element:a.element);if(e.layout&&e.layout.type==B.GRID&&e.layout.numRows>1){let i=e.layout.getElementsByCell(!0,a.element);for(let e of i)t.push({scale:a.getScale(e[0]),elems:e})}else t.push({scale:a.scales[0],elems:a.getElements(a.scales[0])})}else if("radialDistance"==e){let e=r.element?r.element:a.element;t.push({scale:a.scales[0],elems:C(e,e.parent)})}for(let e of t){let t=new ni(a,e.scale,e.elems,r);this.addChild(t),n.push(t),a.addRefElement(t),gt(t,this._depGraph),lt(this,t,this._depGraph),this.onChange(Te.PROPERTY,et.AXIS_PATH_POSITION,t)}}else{let t=r.element?r.element:R(this,s);if(!t)return void console.warn("Cannot create a "+e+" axis for "+s);let i=O(t.parent);if(!i.layout)return void console.warn("Cannot create a "+e+" axis for "+s);let a=C(i);for(let t of a){let i=[];t.layout.type==B.GRID&&t.layout.numRows>1&&"x"==e?i=t.layout.getElementsByRow():t.layout.type==B.GRID&&t.layout.numCols>1&&"y"==e?i=t.layout.getElementsByCol():i.push(t.children);for(let a of i){let i=new ai(a.slice(),e,s,r);this.addChild(i),n.push(i),t.layout.addRefElement(i),ft(i,this._depGraph),lt(this,i,this._depGraph),this.onChange(Te.PROPERTY,et.AXIS_PATH_POSITION,i)}}}return n.length>1?n:n[0]}legend(e,t,i){let r=i||{},s="rowId"==t?Gt:t,n=r.element?Ve(r.element,e):Le(s,e,this);if(n){n.attribute!==t&&console.warn("Cannot create a "+e+" legend for "+t);let i="string"===Bt(n.element).getAttributeType(t)?new ea(n,r):new ta(n,r);this.addChild(i),function(e,t){let i=t.getVariable(Te.BOUNDS,e),r=t.getVariable(Te.PROPERTY,et.LEGEND_POSITION,e),s=t.getIncomingDataflowOperator(z.EVAL_BBOX,i);t.connect(r,s),t.connect(s,i)}(i,this._depGraph),lt(this,i,this._depGraph),x(i),this.onChange(Te.PROPERTY,et.LEGEND_POSITION,i)}else console.warn("Cannot create a "+e+" legend for "+s)}createMask(e){let t=L(e),i=t||e;i.clipMask||i.createClipMask()}setLayout(e,t){if(e.layout&&(dt(e,e.layout,this._depGraph),t.type===B.TREEMAP)){let t=e.firstChild;for(;t&&t.type===Vt.Collection&&t.layout;)dt(t,t.layout,this._depGraph),t=t.firstChild}if(C(e).forEach(e=>{let i=t?t.clone():t;e._layout=i,i&&(i.group=e)}),ut(e,t,this._depGraph),e.children&&e.children.length>0){let t=V(e,!0);for(let e of t)this.onChange(Te.CHANNEL,"x",e)}}setProperties(e,t,i){let r=i?[e]:C(e);r.forEach(e=>{for(const[i,r]of Object.entries(t))je(e,i,r)}),"width"in t&&r.forEach(e=>{e._refBounds&&e._refBounds.setWidth(t.width)}),"height"in t&&r.forEach(e=>{e._refBounds&&e._refBounds.setHeight(t.height)});for(let i in t)["vertex","segment"].includes(e.type)&&!["x","y"].includes(i)||(Object.values(Oe).includes(i)?this.onChange(Te.CHANNEL,i,e):this.onChange(Te.PROPERTY,i,e))}setLayoutParameters(e,t){let i=C(e);for(let e of i)for(let i in t)e.layout[i]=t[i];this.onChange(Te.CHANNEL,"width",e.firstChild)}sortChildren(e,t,i,r){if(e instanceof mt)Zn(e,t,i,r),this.onChange(Te.PROPERTY,et.CHILDREN_ORDER,e);else if(e instanceof ee){let s=C(e);for(let e of s)$n(e,t,i,r)}}translate(e,t,i){Fe(e,t,i);let r=V(e,!0);for(let e of r)x(e);for(let e of r)this.onChange(Te.CHANNEL,"x",e)}transform(e,t,i){let r=t.clone();switch(e){case"bin":!function(e,t,i,r,s){let n=s.getVariable(Te.ATTRIBUTE,e,i),a=s.getVariable(Te.ATTRIBUTE,t,r),o=s.createOneWayDependency(z.BIN_TRANSFORMER);s.connect(n,o),s.connect(o,a),o.run()}(i.attribute,i.newAttribute,t,r,this._depGraph);break;case"filter":!function(e,t,i,r){let s=r.getVariable(Te.ITEMS,void 0,t),n=r.getVariable(Te.ITEMS,e,i),a=r.createOneWayDependency(z.FILTER_TRANSFORMER);r.connect(s,a),r.connect(a,n),a.run()}(h(i),t,r,this._depGraph);break;case"kde":!function(e,t,i,r,s,n){let a=n.getVariable(Te.ATTRIBUTE,e,i),o=n.getVariable(Te.ATTRIBUTE,t,r),l=n.createOneWayDependency(z.KDE_TRANSFORMER);l.args=s,n.connect(a,l),n.connect(l,o),l.run()}(i.attribute,i.newAttribute,t,r,i,this._depGraph)}return r}getEncodingByAttribute(e,t){return Le(e,t,this)}getEncodingByElement(e,t){return Ve(e,t)}getAxis(e,t){return Le(e,t,this).refElements[0]}}function da(e,t){let i=new ce(t.tables[e.dt]);for(let t in e.attr2value)i._attr2value[t]=e.attr2value[t],i._updateTuples(t,e.attr2value[t]);return i}class ua extends D{constructor(e){super(),this.type=B.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:K.Top2Bottom}clone(){return new ua({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 _a extends D{constructor(e){super(),this.type=B.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 _a({x:this._x,y:this._y,iterations:this._iterations,repulsion:this._repulsion,attraction:this._attraction,linkDistance:this._linkDistance})}}class pa extends D{constructor(e){super(),this.type=B.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 pa({x:this._x,y:this._y,width:this._width,height:this._height})}}class fa extends D{constructor(e){super(),this.type=B.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:H}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 fa({width:this._width,height:this._height,top:this._top,left:this._left,orientation:this._orientation})}}class ga extends D{constructor(e){super(),this.type=B.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 ga({width:this._width,height:this._height,top:this._top,left:this._left})}}function ya(e){switch(e.type){case B.GRID:return function(e){let t=new Jn(e.args);"left"in e&&(t._left=e.left);"top"in e&&(t._top=e.top);"cellBounds"in e&&(t._cellBounds=e.cellBounds.map(e=>ma(e)));"grid"in e&&(t._grid=e.grid);return t}(e);case B.STACK:return function(e){let t=new Un(e.args);return t}(e);case B.PACKING:return function(e){let t=new pa(e.args);return t}(e);case B.FORCE:return function(e){return new _a(e.args)}(e);case B.DIRECTED:return function(e){return new ua(e.args)}(e);case B.TIDYTREE:return function(e){return new fa(e.args)}(e);case B.TREEMAP:return function(e){return new ga(e.args)}(e);case B.STRATA:return function(e){return new sa(e.args)}(e);default:return void console.warn("unsupported layout type for deserialization:",e.type)}}function ma(e){return new g(e.x-e.width/2,e.y-e.height/2,e.width,e.height)}function ba(e,t){e.type===Vt.Pie&&(e.type=Vt.Arc),e.args.type=e.type;let i=Rt(e.args);return e.id&&(i._id=e.id),e.classId&&(i._classId=e.classId),e.dataScope&&(i._dataScope=da(e.dataScope,t)),e.bounds&&(i._bounds=ma(e.bounds)),e.refBounds&&(i._refBounds=ma(e.refBounds)),function(e,t,i){if(e.vertices){const r=[];for(let s of e.vertices){const e=xa(s,t,i);r.push(e)}t.vertices=r,t.segments=[];let s=0;for(let e=1;e<t.vertices.length;e++)t.segments.push(new Q(t.vertices[e-1],t.vertices[e],t,s++));t.type===Vt.Rect&&t.segments.push(new Q(t.vertices[t.vertices.length-1],t.vertices[0],t,s++))}t.vertexCounter=e.vertexCounter,t.segmentCounter=e.segmentCounter,t.curveMode=e.curveMode}(e,i,t),i}function xa(e,t,i){let r=new J(e.x,e.y,t,e.id);return e.dataScope&&(r._dataScope=da(e.dataScope,i)),"polarAngle"in e&&(r._polarAngle=e.polarAngle),r.shape=e.shape,r.width=e.width,r.height=e.height,r.radius=e.radius,r.fillColor=e.fillColor,r.opacity=e.opacity,r.strokeWidth=e.strokeWidth,r.strokeColor=e.strokeColor,r}function va(e){let t={};t.fillColor=e.fillColor;let i=new ca(t);console.log("======== deserialization =========");let r={};if(e.tables)for(let t in e.tables){let i=e.tables[t];r[t]=new Dt(i.data,i.url,i.attributeTypes),r[t]._id=i.id}i.tables=r;let s={};if(e.scales)for(let t in e.scales)s[t]=Ca(e.scales[t]);if(i.scales=s,Aa(e,i,i),Ea(e,i),i.buildPeerIndex(),e.encodings){let t={};for(let r of e.encodings){let e=ka(r,i);t[e.id]=e}for(let e in t){i._addAttributeEncoding(t[e]);let r=t[e]._baseEnc?t[t[e]._baseEnc]:void 0;pt(t[e],i._depGraph,r),r?i.onChange(Te.ATTR_VALUE,t[e]):i.onChange(Te.CHANNEL,t[e].channel,t[e].element)}}if(e.axes)for(let t of e.axes){let e=t.args?t.args:{};e.tickValues&&Object.values(i.tables)[0].getAttributeType(t.attr)===xe.Date&&(e.tickValues=e.tickValues.map(e=>new Date(new Date(e).toISOString()))),t.id&&(e.id=t.id),i.axis(t.channel,t.attr,e)}if(e.gridlines)for(let t of e.gridlines)i.gridlines(t.channel,t.attr,t.args);return e.bounds&&(i._bounds=ma(e.bounds)),delete i.tables,delete i.scales,i}function wa(e,t,i){if(e.type===Vt.Collection){let r=Ot(i);e.classId&&(r._classId=e.classId),t.addChild(r),i._itemMap[r.id]=r,nt(r,i._depGraph),lt(t,r,i._depGraph),Aa(e,r,i)}else if(e.type===Vt.Glyph){let r=It();e.classId&&(r._classId=e.classId),t.addChild(r),i._itemMap[r.id]=r,ht(r,i._depGraph),lt(t,r,i._depGraph),Aa(e,r,i)}else if(e.type===Vt.Composite){let r=new ia;t.addChild(r),i._itemMap[r.id]=r,at(r,i._depGraph),lt(t,r,i._depGraph),Aa(e,r,i),r._bounds=ma(e.bounds)}else if(e.type===Vt.Axis){let r=new Qt({});t.addChild(r),function(e,t,i){e.id&&(t._id=e.id);if(t._children=[],e.labels){let r=new mt;Aa(e.labels,r,i),t._labels=r,t._children.push(r)}e.path&&(t._path=wa(e.path,t,i));if(e.ticks){let r=new mt;Aa(e.ticks,r,i),t._ticks=r,t._children.push(r)}e.title&&(t._title=wa(e.title,t,i))}(e,r,i),i._itemMap[r.id]=r}else if(Object.values(A).includes(e.type)){let r=ba(e,i);return i._itemMap[r.id]=r,t.addChild(r),tt(r,i._depGraph),lt(t,r,i._depGraph),r}}function Ea(e,t){if(e.children)for(let i of e.children)Ea(i,t);else if(Object.values(A).includes(e.type)){let i=t._itemMap[e.id];e.links&&(i.links=e.links.map(e=>t._itemMap[e])),e.source&&(i.source=t._itemMap[e.source]),e.target&&(i.target=t._itemMap[e.target])}}function Aa(e,t,i){if(e.id&&(t._id=e.id),e.classId&&(t._classId=e.classId),e.dataScope&&(t._dataScope=da(e.dataScope,i)),e.bounds&&(t._bounds=ma(e.bounds)),t._sortBy=e.sortBy,e.children)for(let r of e.children)wa(r,t,i);e.layout&&(t._layout=ya(e.layout),t._layout.group=t,ut(t,t._layout,i._depGraph))}function Ca(e){let t=new Yt(e.type,e.args);return t._id=e.id,t.domain=e.domain,t.range=e.range,t}function ka(e,t){let i=Sa(e.element,e.elementType,t);i||console.warn("element not created:",e.element,e.elementType);let r=e.args?e.args:{};e.table&&(r.table=t.tables[e.table]);let s=new Fn(i,e.channel,e.attr,e.aggregator?e.aggregator:"sum",r);if(s._id=e.id,e.scales&&(s._scales=e.scales.map(e=>t.scales[e])),r.baseEnc&&(s._baseEnc=e.args.baseEnc),e.elemGroups&&(s._elemGroups=e.elemGroups.map(e=>e.map(e=>Sa(e,i.type,t)))),e.elem2scale){s._elem2scale={};for(let i in e.elem2scale)s._elem2scale[i]=t.scales[e.elem2scale[i]]}return r.startAngle&&(s.startAngle=r.startAngle),s}function Sa(e,t,i){if("vertex"===t){let t=e.split("_v_");return i._itemMap[t[0]].vertices.find(e=>e._id===parseInt(t[1]))}if("segment"===t){let t=e.split("_s_");return i._itemMap[t[0]].segments.find(e=>e._id===parseInt(t[1]))}return i._itemMap[e]}function Ta(e){let t={};return t.id=e._id,t.data=e._rawData,t.attributeTypes=e._attrTypes,t.url=e.url,t}function Ra(e){let t={};return t.dt=e._dt.id,t.attr2value=Object.assign({},e._attr2value),t}function Oa(e,t){t.vertices=[];for(let i of e.vertices)t.vertices.push(Ia(i));t.vertexCounter=e.vertexCounter,t.segmentCounter=e.segmentCounter,t.curveMode=e.curveMode}function Ia(e){let t={};return t.type=e.type,t.id=e._id,t.x=e.x,t.y=e.y,e._dataScope&&(t.dataScope=Ra(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 Na(e){return e.type===Vt.Scene?function(e){let t=Pa(e,{});t.fillColor=e.fillColor,t.scales={},t.encodings=[];for(let i in e._encodings)for(let r in e._encodings[i]){let s=e._encodings[i][r];s._forLegend||t.encodings.push(Va(s));for(let e of s._scales)e.id in t.scales||(t.scales[e.id]=La(e))}t.tables={};let i=function(e){let t={};for(let i in e._encodings)for(let r in e._encodings[i]){let s=e._encodings[i][r];s.dataTable.id in t||s._forLegend||(t[s.dataTable.id]=s.dataTable)}for(let i of e.children)if(![Vt.Axis,Vt.Legend,Vt.Gridlines].includes(i.type)){if(i.dataScope){t[i.dataScope.dataTable.id]=i.dataScope.dataTable;break}if(i.children&&i.children.length>0){let e=i.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 i)t.tables[e]=Ta(i[e]);return console.log("======== serialization ========="),console.log(t),t}(e):[Vt.Collection,Vt.Glyph,Vt.Composite].includes(e.type)?Pa(e,{}):e instanceof w?function(e){let t={args:{}};t.type=e.type,t.id=e.id,e.classId&&(t.classId=e.classId),e._dataScope&&(t.dataScope=Ra(e._dataScope)),e.bounds&&(t.bounds=e.bounds.toJSON()),e.refBounds&&(t.refBounds=e.refBounds.toJSON()),e.links&&(t.links=e.links.map(e=>e.id)),e.source&&(t.source=e.source.id),e.target&&(t.target=e.target.id);for(let i in e.styles)i.indexOf("Color")>0&&e.styles[i]instanceof j?t.args[i]=e.styles[i].toJSON():t.args[i]=e.styles[i];switch(e.type){case Vt.Arc:case Vt.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),Oa(e,t);break;case Vt.Area:!function(e,t){t.args.baseline=e._baseline,t.args.orientation=e._orientation}(e,t),Oa(e,t);break;case Vt.Circle:!function(e,t){t.args.x=e.x,t.args.y=e.y,t.args.radius=e.radius}(e,t);break;case Vt.Image:break;case Vt.Line:case Vt.Path:case Vt.BezierCurve:Oa(e,t);break;case Vt.SimpleText:!function(e,t){t.args.x=e._x,t.args.y=e._y,t.args.text=e._text,t.args.anchor=e._anchor,e._backgroundColor&&(t.args.backgroundColor=e._backgroundColor),e._borderWidth&&(t.args.borderWidth=e._borderWidth),e._borderColor&&(t.args.borderColor=e._borderColor)}(e,t);break;case Vt.Polygon:!function(e,t){t.args.x=e._x,t.args.y=e._y,t.args.radius=e._radius}(e,t),Oa(e,t);break;case Vt.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),Oa(e,t);case Vt.Ring:}return t}(e):(console.warn("unsupported serialization",e.type),{type:e.type})}function La(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 Va(e){let t={};t.id=e._id,t.element=e._elem.id,t.elementType=e._elem.type,t.channel=e._channel,t.attr=e._attribute,t.aggregator=e._aggregator,t.table=e._table.id,t.args={},t.args.includeZero=e._includeZero,t.args.flipScale=e._flipScale,t.args.mapping=e._mapping,t.args.rangeExtent=e._preferredRangeExtent,t.args.domain=e._preferredDomain,t.args.scaleType=e._scaleType,t.args.scheme=e._colorScheme,e._baseEnc&&(t.args.baseEnc=e._baseEnc.id),t.scales=e._scales.map(e=>e.id),t.elemGroups=e._elemGroups.map(e=>e.map(e=>e.id)),t.elem2scale={};for(let i in e._elem2scale)t.elem2scale[i]=e._elem2scale[i].id;return"angle"==e.channel&&(t.args.startAngle=e.startAngle),t}function Pa(e,t){if(t.id=e.id,t.type=e.type,e.classId&&(t.classId=e.classId),e._dataScope&&(t.dataScope=Ra(e._dataScope)),t.bounds=e.bounds.toJSON(),e._layout&&(t.layout=function(e){switch(e.type){case B.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.group=e.group.id,t}(e);case B.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 B.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 B.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 B.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 B.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 B.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 B.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 B.STRATA:return function(e){let t={args:{}};return t.type=e.type,t.args.direction=e._direction,t.args.gap=e._gap,t}(e);default:throw new Error("unknow layout type "+e.type)}}(e._layout)),t.children=[],e.children.length>0)for(let i of e.children)i instanceof Qt?Ma(i,t):i instanceof Wn?Da(i,t):t.children.push(Na(i));return t.sortBy=e._sortBy,t}function Ma(e,t){t.axes??=[];let i={};i.type=e._type,i.id=e._id,i.attr=e._attribute,i.channel=e._channel,i.args={},i.args.orientation=e._orientation,i.args.strokeColor=e._strokeColor,i.args.textColor=e._textColor,i.args.fontSize=e._fontSize,i.args.tickOffset=e._tickOffset,i.args.tickSize=e._tickSize,i.args.tickAnchor=e._tickAnchor,i.args.tickVisible=e._tickVisible,i.args.pathVisible=e._pathVisible,i.args.labelOffset=e._labelOffset,i.args.labelFormat=e._labelFormat,i.args.titleOffset=e._titleOffset,i.args.title=e._titleText,i.args.rotateTitle=e._rotateTitle,i.args.titleVisible=e._showTitle,i.args.labelRotation=e._labelRotation,t.axes.push(i)}function Da(e,t){t.gridlines??=[];let i={};i.type=e._type,i.id=e._id,i.attr=e._attribute,i.channel=e._channel,i.args=e._args,t.gridlines.push(i)}function Ba(e,t,i,s,n){for(let o of e){let e="background"===o.target?i:o.target;e=Array.isArray(e)?e:[e];let l="brushX"===o.event?r.brushX():"brushY"===o.event?r.brushY():r.brush();var a;l.on("start",function(t){a&&e.length>1&&r.select(a).call(l.move,null),a=this}),l.on("brush end",function(e){let t,a;if(e&&e.selection)switch(o.event){case"brushX":t=[e.selection[0],e.selection[1]],a=void 0;break;case"brushY":t=void 0,a=[e.selection[0],e.selection[1]];break;default:t=[e.selection[0][0],e.selection[1][0]],a=[e.selection[0][1],e.selection[1][1]]}else t=void 0,a=void 0;let l=o.eventContext;l.clear(),l.set("xInterval",t),l.set("yInterval",a),l.set("target",r.select(this).attr("id").replace("brush-","")),i.onChange(Te.EVT_CTX,l),s._render(i,n)});for(let i of e){let e=i.type===Vt.Axis?i.boundsWithoutTitle:i.bounds,r=[[e.left,e.top],[e.right,e.bottom]];t.append("g").attr("class","brush").attr("id","brush-"+i.id).call(l.extent(r))}}}function Ga(e,t,i,s,n){for(let a of e){let e="background"===a.target?t:t.select("#"+a.target.id),o=r.drag();o.on("drag",e=>{let[r,o]=p(t.attr("id"),e.sourceEvent.clientX,e.sourceEvent.clientY),l=a.eventContext;l.set("x",r),l.set("y",o),l.set("dx",e.dx),l.set("dy",e.dy),i.onChange(Te.EVT_CTX,l),s._render(i,n)}),e.call(o)}}function Fa(e,t,i,r,s){for(let n of e){let e="background"===n.target?t:n.target.classId?t.selectAll("."+n.target.classId):t.select("#"+n.target.id);e.on("mouseover",e=>{let[a,o]=p(t.attr("id"),e.clientX,e.clientY),l=n.eventContext;l.set("x",a),l.set("y",o);let h=e.target.__data__;l.set("elements",[h]),l.set("element",h),i.onChange(Te.EVT_CTX,l),r._render(i,s)}),e.on("mouseout",e=>{let t=n.eventContext;t.set("elements",[]),t.set("element",void 0),i.onChange(Te.EVT_CTX,t),r._render(i,s)})}}function za(e,t,i,s,n){for(let t of e)if(t.isWidgetDriven()){let e=(Array.isArray(t.target)?t.target:[t.target]).map(e=>document.getElementById(e)),r=t.eventContext;for(let a of e)a.addEventListener(t.event,function(){r.set("inputValue",a.value),"checkbox"===a.type&&r.set("checked",a.checked),i.onChange(Te.EVT_CTX,r),s._render(i,n)})}else t.isKeyboardDriven()&&r.select("body").on("keydown",e=>{e.key===t.key&&Wa(t,i,s,n)})}function ja(e,t,i,r,s){t.on("wheel",n=>{for(let r of e){n.preventDefault(),n.stopPropagation();let[e,s]=p(t.attr("id"),n.clientX,n.clientY),a=r.eventContext;a.set("deltaX",n.deltaX),a.set("deltaY",n.deltaY),a.set("x",e),a.set("y",s),i.onChange(Te.EVT_CTX,a)}r._render(i,s)})}function Wa(e,t,i,r){if(Array.isArray(e.callback))for(let s=0;s<e.callback.length;s++)e.callback[s](),i._render(t,r,e.animation[s]);else e.callback(),i._render(t,r,e.animation)}function Ua(e,t,i,r,s){t.on("click",n=>{for(let r of e){let[e,s]=p(t.attr("id"),n.clientX,n.clientY),a=r.eventContext,o=[];r.target.type&&o.push({property:"type",value:r.target.type}),r.target.classId&&o.push({property:"classId",value:r.target.classId});let l=elementHitTest(i,e,s,o),h=a.get("elements").slice();l?r.isCumulative&&!a.get("elements").includes(l)?h.push(l):h=[l]:h=[],h.length===a.get("elements").length&&h.every((e,t)=>e===a.get("elements")[t])||(a.clear(),a.set("x",e),a.set("y",s),a.set("elements",h),a.set("element",h.length>0?h[h.length-1]:void 0),i.onChange(Te.EVT_CTX,a))}r._render(i,s)})}function Ha(e){return e.id+"-bg"}function Ya(e){return e.id+"-path"}function Xa(e){switch(e){case v.TOP:return"text-before-edge";case v.BOTTOM:return"auto";case v.LEFT:return"start";case v.RIGHT:return"end";case v.CENTER:case v.MIDDLE:return"middle";default:return e}}class qa{constructor(e){this._svgId=e,this._svg=document.getElementById(this._svgId),this._compMap={},this._decoMap={},this._brushCreated=0,this._lastTriggerEvt=void 0}render(e,t){if(!this._svg&&(this._svg=document.getElementById(this._svgId),!this._svg)){const i=()=>{this._svg=document.getElementById(this._svgId),this._svg?this.render(e,t):console.error("SVGRenderer: SVG element '#"+this._svgId+"' not found after DOMContentLoaded.")};return void("loading"===document.readyState?document.addEventListener("DOMContentLoaded",i,{once:!0}):Promise.resolve().then(i))}this._compMap={},this._decoMap={},this._brushCreated=0;let i=t||{};if(!this._svg.querySelector("defs")){const e=document.createElementNS("http://www.w3.org/2000/svg","defs");this._svg.appendChild(e)}this._render(e,i),this._registerEvents(e,i)}_render(e,t,i){for(let e in this._decoMap)this._decoMap[e].remove(),delete this._decoMap[e];this._removed={};for(let e in this._compMap)this._removed[e]=1;this._renderItem(e,t,i);for(let e in this._removed)this._compMap[e].remove(),delete this._compMap[e]}_registerEvents(e,t){let i=r.select("#"+this._svgId);for(let r in e.interactionTriggers){let s=Object.values(e.interactionTriggers[r]);switch(r){case"click":i.on("click",null),Ua(s,i,e,this,t);break;case"brush":case"brushX":case"brushY":Ba(s,i,e,this,t);break;case"drag":case"dragX":case"dragY":Ga(s,i,e,this,t);break;case"hover":Fa(s,i,e,this,t);break;case"change":case"input":za(s,0,e,this,t);break;case"scroll":ja(s,i,e,this,t)}}}clear(){for(;this._svg.firstChild;)this._svg.firstChild.remove();const e=this._svg.cloneNode(!0);this._svg.parentNode.replaceChild(e,this._svg),this._svg=e,this._compMap={},this._decoMap={}}_renderItem(e,t,i){if(this._configSVG(e),!e.children&&!1===e._dirty)return;let r=this._compMap[e.id];if(i){const e=i.delay||0,t=i.duration||0;r.style.transition=`all ${t}ms ease ${e}ms`}switch(e.type){case Vt.Scene:!function(e,t){t.style.background=e.fillColor?e.fillColor:"#fff"}(e,this._svg);break;case Vt.Circle:!function(e,t){t.setAttribute("cx",e.x),t.setAttribute("cy",e.y),t.setAttribute("r",e.radius)}(e,r);break;case Vt.Rect:!function(e,t){let i=e.bounds;t.setAttribute("x",i.left),t.setAttribute("y",i.top),t.setAttribute("width",i.width),t.setAttribute("height",i.height)}(e,r);break;case Vt.Path:case Vt.BezierCurve:case Vt.BundledPath:case Vt.Chord:case Vt.Polygon:case Vt.Link:case Vt.Pie:case Vt.Line:case Vt.Area:case Vt.Ring:case Vt.Arc:case Vt.Gridlines:!function(e,t){t.setAttribute("d",e.getSVGPathData()),e.closed||(t.style.fill="none"),(e.id.includes("axis")||e.id.includes("gridlines"))&&(t.style.shapeRendering="crispEdges"),e.type===Vt.BundledPath&&(t.style.mixBlendMode="multiply")}(e,r);break;case Vt.SimpleText:!function(e,t,i){if(t.setAttribute("text-anchor",Xa(e.anchor[0])),t.setAttribute("alignment-baseline",Xa(e.anchor[1])),t.setAttribute("dominant-baseline",Xa(e.anchor[1])),t.setAttribute("x",e.x),t.setAttribute("y",e.y),i){e._updateBounds();let t=e.bounds;i.setAttribute("x",t.left-5),i.setAttribute("y",t.top-5),i.setAttribute("width",t.width+10),i.setAttribute("height",t.height+10),i.setAttribute("rx",5),i.setAttribute("ry",5),i.style.fill=e.backgroundColor,i.style.stroke=e.borderColor,i.style.strokeWidth=e.borderWidth}if(e.textPath){let i=t.querySelector("textPath");i||(i=document.createElementNS("http://www.w3.org/2000/svg","textPath"),t.appendChild(i)),i.setAttribute("href","#"+Ya(e)),i.setAttribute("startOffset",e.textPathOffset),i.textContent=e.text}else t.textContent=e.text}(e,r,this._compMap[Ha(e)]);break;case Vt.RichText:!function(e,t){for(;t.firstChild;)t.firstChild.remove();t.setAttribute("width",e.width),t.setAttribute("x",e.x),t.setAttribute("y",e.y),t.style.border="1px solid #ddd";let i=document.createElementNS("http://www.w3.org/1999/xhtml","div");i.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),i.style.width="100%",i.style.padding="10px",i.style.backgroundColor="rgba(255, 255, 255, 0.85)",i.style.color="black",i.style.visibility="visible",i.style.boxSizing="border-box",i.style.opacity="1",i.innerHTML=e.text,t.appendChild(i),t.setAttribute("height",i.offsetHeight)}(e,r);break;case Vt.Image:!function(e,t){t.setAttribute("href",e.src),t.setAttribute("x",e.x),t.setAttribute("y",e.y),t.setAttribute("width",e.width),t.setAttribute("height",e.height)}(e,r)}if(e._rotate&&r.setAttribute("transform","rotate("+e._rotate.join(" ")+")"),function(e,t,i){if(!e.styles)return;let r=Object.keys(e.styles);e.type===Vt.RichText&&(r=r.filter(e=>["textAnchor","fillColor"].indexOf(e)<0));for(let s of r)if(void 0!==e.styles[s])if(s.indexOf("Color")>0&&e.styles[s].type==Vt.LinearGradient){const r=i.querySelector("defs"),n=e.styles[s];if(!r.querySelector("#"+n.id)){const e=document.createElementNS("http://www.w3.org/2000/svg","linearGradient");e.setAttribute("id",n.id),e.setAttribute("x1",n.x1+"%"),e.setAttribute("x2",n.x2+"%"),e.setAttribute("y1",n.y1+"%"),e.setAttribute("y2",n.y2+"%");for(let t of n.stops){const i=document.createElementNS("http://www.w3.org/2000/svg","stop");i.setAttribute("offset",t.offset+"%"),i.style.stopColor=t.color,i.style.stopOpacity=t.opacity,e.appendChild(i)}r.appendChild(e)}t.style[f[s]]="url(#"+n.id+")"}else if(t.style[f[s]]=e.styles[s],"visibility"===s)if(e.type===Vt.SimpleText){if(e.hasBackground()){const t=i.querySelector("#"+Ha(e));t&&(t.style[f[s]]=e.styles[s])}}else if(e.type===Vt.RichText){const i=t.querySelector("div");i&&(i.style.visibility=e.styles[s])}}(e,r,this._svg),e.vertices&&e.vertices.length>0&&e.vertices.map(e=>e.shape).filter(e=>void 0!==e).length>0&&this._renderVertices(e),t&&t.bounds?this._renderBounds(e):E(e)&&t&&t.refBounds&&this._renderRefBounds(e),e.clipMask){const t=this._svg.querySelector("defs");let i=t.querySelector("#"+e.id+"-clipPath");i||(i=document.createElementNS("http://www.w3.org/2000/svg","clipPath"),i.setAttribute("id",e.id+"-clipPath"),t.appendChild(i));let s=i.querySelector("rect");s||(s=document.createElementNS("http://www.w3.org/2000/svg","rect"),i.appendChild(s)),s.setAttribute("x",e.clipMask.left),s.setAttribute("y",e.clipMask.top),s.setAttribute("width",e.clipMask.width),s.setAttribute("height",e.clipMask.height),r.setAttribute("clip-path","url(#"+e.id+"-clipPath)")}if(e.children)for(let r of e.children)this._renderItem(r,t,i);else e._dirty=!1}_configSVG(e){if(e.id in this._compMap)delete this._removed[e.id],e.type===Vt.SimpleText&&(e.hasBackground()&&delete this._removed[Ha(e)],e.textPath&&delete this._removed[Ya(e)]);else{let t,i=e.parent;if(t=i&&i.id&&i.id in this._compMap?this._svg.querySelector("#"+i.id):this._svg,e.type===Vt.SimpleText){if(e.hasBackground()){const i=document.createElementNS("http://www.w3.org/2000/svg","rect");i.setAttribute("id",Ha(e)),t.appendChild(i),this._compMap[Ha(e)]=i}if(e.textPath){const t=this._svg.querySelector("defs"),i=Ya(e);let r=t.querySelector("#"+i);r||(r=document.createElementNS("http://www.w3.org/2000/svg","path"),r.setAttribute("id",i),t.appendChild(r),this._compMap[i]=r),r.setAttribute("d",e.textPath),r.style.fill="none"}}const r=document.createElementNS("http://www.w3.org/2000/svg",this._getSVGElementType(e));t?t.appendChild(r):console.warn("Parent element not found for ",e),this._compMap[e.id]=r}if(e.type==Vt.Gridlines){const t=this._compMap[e.id].parentNode;t.insertBefore(this._compMap[e.id],t.firstChild)}this._compMap[e.id].setAttribute("id",e.id),this._compMap[e.id].__data__=e;let t=e.type;e.classId&&(t+=" "+e.classId),e.parent&&e.parent.type===Vt.Axis&&(t+=e.id.endsWith("_ticks")?" axis_ticks":e.id.endsWith("_labels")?" axis_labels":""),this._compMap[e.id].setAttribute("class",t)}_renderBounds(e){let t=e.bounds;if(e.layout&&"grid"==e.layout.type&&this._renderLayout(e),!(e.id in this._decoMap)){const t=document.createElementNS("http://www.w3.org/2000/svg","rect");t.setAttribute("class","deco"),this._svg.appendChild(t),this._decoMap[e.id]=t}const i=this._decoMap[e.id];i.setAttribute("x",t.left),i.setAttribute("y",t.top),i.setAttribute("width",t.width),i.setAttribute("height",t.height),i.setAttribute("fill","none"),i.setAttribute("stroke","blue"),i.setAttribute("stroke-width","1px"),i.setAttribute("stroke-dasharray","5,5")}_renderRefBounds(e){let t=e.refBounds;if(t){if(!(e.id in this._decoMap)){const t=document.createElementNS("http://www.w3.org/2000/svg","rect");t.setAttribute("class","deco"),this._svg.appendChild(t),this._decoMap[e.id]=t}const i=this._decoMap[e.id];i.setAttribute("x",t.left),i.setAttribute("y",t.top),i.setAttribute("width",t.width),i.setAttribute("height",t.height),i.setAttribute("fill","none"),i.setAttribute("stroke","blue"),i.setAttribute("stroke-width","1px"),i.setAttribute("stroke-dasharray","5,5")}}_renderVertices(e){let t=e.id+"-vertices";if(t in this._compMap)delete this._removed[t];else{let i=e.parent,r=i?i.id:this._svgId;const s=this._svg.querySelector("#"+r),n=document.createElementNS("http://www.w3.org/2000/svg","g");n.setAttribute("id",t),s.appendChild(n),this._compMap[t]=n}if(0===e.vertices.map(e=>e.shape).filter(e=>void 0!==e).length)return void(this._compMap[t].style.visibility="hidden");this._compMap[t].style.visibility="visible";let i=e.vertices.filter(e=>void 0!==e.shape);for(let e of i){let i=t+"-"+e.id;if(i in this._compMap)if(e.shape!==this._compMap[i].tagName){this._compMap[i].remove();const r=document.createElementNS("http://www.w3.org/2000/svg",e.shape);r.setAttribute("id",i),this._compMap[t].appendChild(r),this._compMap[i]=r,delete this._removed[i]}else delete this._removed[i];else{const r=document.createElementNS("http://www.w3.org/2000/svg",e.shape);r.setAttribute("id",i),this._compMap[t].appendChild(r),this._compMap[i]=r}const r=this._compMap[i];"rect"==e.shape?(r.setAttribute("x",e.x-e.width/2),r.setAttribute("y",e.y-e.height/2),r.setAttribute("width",e.width),r.setAttribute("height",e.height)):"circle"==e.shape&&(r.setAttribute("cx",e.x),r.setAttribute("cy",e.y),r.setAttribute("r",e.radius)),r.style.fill=e.fillColor,r.style.opacity=e.opacity,r.style.strokeWidth=e.strokeWidth,r.style.stroke=e.strokeColor}}_renderLayout(e){let t=e.id+"-grid";if(!(t in this._decoMap)){const e=document.createElementNS("http://www.w3.org/2000/svg","g");e.setAttribute("id",t),e.setAttribute("class","deco"),this._svg.appendChild(e),this._decoMap[t]=e}let i=e.layout.cellBounds;e.layout.rowGap;this._decoMap[t].querySelectorAll("rect").forEach(e=>e.remove());for(let e of i){const i=document.createElementNS("http://www.w3.org/2000/svg","rect");i.setAttribute("x",e.left),i.setAttribute("y",e.top),i.setAttribute("width",e.width),i.setAttribute("height",e.height),i.setAttribute("stroke","blue"),i.setAttribute("stroke-width","1px"),i.setAttribute("stroke-dasharray","5,5"),i.setAttribute("fill","none"),this._decoMap[t].appendChild(i)}}_getSVGElementType(e){switch(e.type){case Vt.Rect:return"rect";case Vt.Collection:case Vt.Group:case Vt.Glyph:case Vt.Scene:case Vt.Axis:case Vt.Legend:case Vt.Composite:return"g";case Vt.Area:case Vt.Path:case Vt.Polygon:case Vt.Ring:case Vt.Pie:case Vt.Arc:case Vt.BezierCurve:case Vt.BundledPath:case Vt.Chord:case Vt.Line:case Vt.Gridlines:return"path";case Vt.Circle:return"circle";case Vt.SimpleText:return"text";case Vt.RichText:return"foreignObject";case"vertex":if("circle"==e.shape)return"circle";if("rect"==e.shape)return"rect";throw"argument exception";case"image":return"image"}}}function Ka(e,t){return void 0===e&&void 0===t||void 0!==e&&void 0!==t}function Za(e,t){const i=Object.keys(e),r=Object.keys(t);return i.length===r.length&&(0===i.length||i.every(e=>r.includes(e)))}function $a(e,t){if(!Ka(e.layout,t.layout))return console.log("Not both defined or undefined:",e.bounds,t.bounds),!1;let i=e.layout,r=t.layout;if(!i&&!r)return!0;if(i.type!==r.type)return console.log("layout types are different:",i,r),!1;switch(i.type){case B.GRID:return function(e,t){e._cellBounds.length!==t._cellBounds.length&&console.log("cell bounds length different:",e,t);for(let i=0;i<e._cellBounds;i++)if(!Qa(e._cellBounds[i],t._cellBounds[i]))return console.log("cell bounds not equal:",e,t),!1;for(let i=0;i<e._grid.length;i++)for(let r=0;r<e._grid[i].length;r++)if(e._grid[i][r]!==t._grid[i][r])return console.log("grid not equal",e,t),!1;return e._numCols===t._numCols&&e._numRows===t._numRows&&e._start===t._start&&e._direction===t._direction&&e._rowGap===t._rowGap&&e._colGap===t._colGap&&e._cellHorzAlignment===t._cellHorzAlignment&&e._cellVertAlignment===t._cellVertAlignment&&e._left===t._left&&e._top===t._top}(i,r);case B.STACK:return function(e,t){return e._orientation===t._orientation&&e._direction===t._direction&&e._left===t._left&&e._top===t._top&&e._horzCellAlignment===t._horzCellAlignment&&e._vertCellAlignment===t._vertCellAlignment&&e._gap===t._gap}(i,r);case B.PACKING:return function(e,t){return e._x===t._x&&e._y===t._y&&e._width===t._width&&e._height===t._height}(i,r);case B.FORCE:return function(e,t){return e._x===t._x&&e._y===t._y&&e._iterations===t._iterations&&e._repulsion===t._repulsion&&e._attraction===t._attraction&&e._linkDistance===t._linkDistance}(i,r);case B.DIRECTED:return function(e,t){return e._width===t._width&&e._height===t._height&&e._top===t._top&&e._left===t._left&&e._edgeSep===t._edgeSep&&e._spreadLinks===t._spreadLinks&&e._direction===t._direction}(i,r);case B.TIDYTREE:return function(e,t){return e._width===t._width&&e._height===t._height&&e._top===t._top&&e._left===t._left&&e._orientation===t._orientation}(i,r);case B.STRATA:return function(e,t){return e._direction===t._direction&&e._gap===t._gap}(i,r);case B.TREEMAP:return function(e,t){return e._width===t._width&&e._height===t._height&&e._top===t._top&&e._left===t._left}(i,r);default:return!1}}function Ja(e,t){if(!Ka(e.bounds,t.bounds))return console.log("Not both defined or undefined:",e.bounds,t.bounds),!1;let i=e.bounds,r=t.bounds;return!i&&!r||Qa(i,r)}function Qa(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function eo(e,t){if(!Ka(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(!io(e,t))return console.log("DataScopes not equal",e,t),!1;if(!Ja(e,t))return console.log("Bounds not equal",e,t),!1;if(!Ka(e.links,t.links))return console.log("Not both defined or undefined: links ",e.links,t.links),!1;if(!Ka(e.source,t.source))return console.log("Not both defined or undefined: source ",e.source,t.source),!1;if(!Ka(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&&!eo(e.source,t.source))return console.log("different sources",e.source,t.source),!1;if(e.target&&t.target&&!eo(e.target,t.target))return console.log("different targets",e.target,t.target),!1;switch(e.type){case Vt.Arc:case Vt.Pie:return to(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 Vt.Area:return to(e,t)?e.baseline===t.baseline&&e.orientation===t.orientation:(console.log("vertices not equal:",e,t),!1);case Vt.Circle:return e.x===t.x&&e.y===t.y&&e.radius===t.radius;case Vt.Image:return console.warn("not implemented"),!0;case Vt.Line:case Vt.Path:case Vt.BezierCurve:return!!to(e,t)||(console.log("vertices not equal:",e,t),!1);case Vt.SimpleText:return e.x===t.x&&e.y===t.y&&e.text===t.text&&e.anchor[0]===t.anchor[0]&&e.anchor[1]===t.anchor[1];case Vt.Polygon:return to(e,t)?e.x===t.x&&e.y===t.y&&e.radius===t.radius:(console.log("vertices not equal:",e,t),!1);case Vt.Rect:return to(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 Vt.Ring:default:return console.warn("not implemented"),!0}}function to(e,t){if(e.vertices.length!==t.vertices.length)return console.log("unequal number of vertices:",e,t),!1;for(let i=0;i<e.vertices.length;i++){let r=e.vertices[i],s=t.vertices[i];return r.id!==s.id?(console.log("vertex id not equal:",r,s),!1):r.x!==s.x||r.y!==s.y?(console.log("vertex position not equal:",r,s),!1):io(r,s)?r._polarAngle===s._polarAngle&&r.shape===s.shape&&r.width===s.width&&r.height==s.height&&r.radius==s.radius&&r.fillColor==s.fillColor&&r.opacity==s.opacity&&r.strokeWidth==s.strokeWidth&&r.strokeColor==s.strokeColor:(console.log("vertex data scopes not equal:",r.dataScope,s.dataScope),!1)}}function io(e,t){if(!Ka(e.dataScope,t.dataScope))return console.log("Not both defined or undefined:",e.dataScope,t.dataScope),!1;if(!e.dataScope&&!t.dataScope)return!0;let i=e.dataScope,r=t.dataScope;if(!Za(i._attr2value,r._attr2value))return!1;for(let e in i._attr2value)if(i._attr2value[e]!==r._attr2value[e])return!1;return i._dt.id===r._dt.id&&i._tuples.length===r._tuples.length}function ro(e,t){return e.type!==t.type&&console.log("Different types:",e.type,t.type),[Vt.Collection,Vt.Glyph,Vt.Composite].includes(e.type)?so(e,t):e instanceof w?eo(e,t):void 0}function so(e,t){let i=e.children.filter(e=>!Object.values(Pt).includes(e.type)),r=t.children.filter(e=>!Object.values(Pt).includes(e.type));if(i.length!==r.length)return console.log("children length not equal:",i,r),!1;if(e.id!==t.id)return console.log("id not equal:",e,t),!1;if(e.classId!==t.classId)return console.log("class id not equal:",e,t),!1;if(!io(e,t))return console.log("DataScopes not equal",e.dataScope,t.dataScope),!1;if(!Ja(e,t))return console.log("Bounds not equal",e,t),!1;if(!$a(e,t))return console.log("Layouts not equal",e,t),!1;if(!function(e,t){if(!Za(e,t))return console.log("different keys",e,t),!1;for(let i in e)if(e[i]!==t[i])return!1;return!0}(e._sortBy,t._sortBy))return console.log("SortBy not equal",e,t),!1;for(let e=0;e<i.length;e++)if(!ro(i[e],r[e]))return console.log("Not equal",i[e],r[e]),!1;return!0}class no extends D{constructor(e){super(),this.type=B.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 no({x:this._x,y:this._y,radius:this._radius})}}class ao extends D{constructor(e){super(),this.type=B.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:H,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 ao({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 oo(e,t,i){if(!e.bounds.contains(t,i))return!1;switch(e.type){case ElementType.Path:case ElementType.Arc:case ElementType.BezierCurve:case ElementType.Line:{let r=CanvasProvider.getContext(),s=CanvasProvider.getPath2D(e.getSVGPathData());return r.lineWidth=Math.max(e.strokeWidth,2.5),r.stroke(s),e.closed?r.isPointInPath(s,t,i):r.isPointInStroke(s,t,i)}case ElementType.Circle:{let r=e.x,s=e.y;if(e.rotation){let t=u(r,s,e.rotation[1],e.rotation[2],e.rotation[0]);r=t.x,s=t.y}return Math.sqrt(Math.pow(t-r,2)+Math.pow(i-s,2))<=e.radius+e.strokeWidth}case ElementType.Collection:if([ElementType.Arc,ElementType.Pie,ElementType.Polygon,ElementType.Area].indexOf(e.firstChild.type)>=0){let r=e.getSVGPathData();if(""!==r){let s=CanvasProvider.getContext(),n=CanvasProvider.getPath2D(r);return s.lineWidth=Math.max(e.firstChild.strokeWidth,2.5),s.stroke(n),s.isPointInPath(n,t,i)}}return e.bounds.contains(t,i);default:return e.bounds.contains(t,i)}}e.canClassify=function(e){return e.type===Vt.Collection&&!(e.children.length<2)},e.canDensify=ke,e.canDivide=Yn,e.canRepeat=Bn,e.csv=async function(e){return async function(e){let t=await Ft("GET",e),i=r.csvParse(t.trim(),r.autoType);return new Dt(i,e)}(e)},e.csvString=function(e){return function(e){let t=r.csvParse(e.trim(),r.autoType);return new Dt(t,"fromString")}(e)},e.deserialize=function(e){return va(e)},e.elementHitTest=function(e,t,i,r){let s=T(e,r);for(let e of s)if(oo(e,t,i))return e},e.elementHitTestByRect=function(e,t,i){let r=T(e,i);for(let e of r)if(e.bounds.intersects(t))return e},e.findElements=T,e.getLeafMarks=V,e.getPeers=C,e.graphJSON=async function(e){return async function(e){let t=await Ft("GET",e);return new fe(JSON.parse(t),e)}(e)},e.isEqual=function(e,t){return function(e,t){return e.fillColor!==t.fillColor?(console.log("fillColor not equal:",e,t),!1):so(e,t)}(e,t)},e.isMark=E,e.isRefElement=function(e){return e.type===Vt.Axis||e.type===Vt.Legend||e.type===Vt.Gridlines},e.layout=function(e,t){let i=t||{};switch(e.toLowerCase()){case B.STACK:return new Un(i);case B.PACKING:return new pa(i);case B.FORCE:return new _a(i);case B.DIRECTED:return new ua(i);case B.TIDYTREE:return new fa(i);case B.TREEMAP:return new ga(i);case B.CIRCULAR:return new no(i);case B.CLUSTER:return new ao(i);case B.GRID:default:return new Jn(i)}},e.markPrimitiveHitTest=function(e,t,i,r){let s,n=V(e),a=r||2,o=CanvasProvider.getContext();for(let e of n){if(!(e instanceof Path))continue;let r=CanvasProvider.getPath2D(e.getSVGPathData());if(o.lineWidth=Math.max(e.strokeWidth,2*a),o.stroke(r),o.isPointInStroke(r,t,i)){s=e;break}}if(!s)return null;let l=[];for(let e of s.vertices){let t=Math.max(a,e.width,2*e.radius),i=Math.max(a,e.height,2*e.radius);l.push({i:e,b:new g(e.x-t/2,e.y-i/2,t,i)})}for(let e of l)if(e.b.contains(t,i))return e.i;if(s.segments&&s.segments.length>0)for(let e of s.segments){let r=CanvasProvider.getPath2D();if(r.moveTo(e.vertex1.x,e.vertex1.y),r.lineTo(e.vertex2.x,e.vertex2.y),o.lineWidth=Math.max(s.strokeWidth,a),o.stroke(r),o.isPointInStroke(r,t,i))return e}return null},e.markPrimitiveHitTestByRect=function e(t,i,r){let s=r||2;if(E(t)){let e=[];for(let i of t.vertices){let t=Math.max(s,i.width,2*i.radius),r=Math.max(s,i.height,2*i.radius);e.push({i:i,b:new g(i.x-t/2,i.y-r/2,t,r)})}if(t.type===ItemType.Rect)for(let i of t.segments){let r=Math.max(t.strokeWidth,s);"v"===(i.vertex1.x===i.vertex2.x?"v":"h")?e.push({i:i,b:new g(i.vertex1.x-r/2,Math.min(i.vertex1.y,i.vertex2.y)-r/2,r,Math.abs(i.vertex1.y-i.vertex2.y))}):e.push({i:i,b:new g(Math.min(i.vertex1.x,i.vertex2.x)-r/2,i.vertex1.y-r/2,Math.abs(i.vertex1.x-i.vertex2.x),r)})}for(let t of e)if(t.b.intersects(i))return t.i;return null}if(!isGuide(t)&&t.children&&t.children.length>0){for(let r of t.children)if(r.bounds.intersects(i)){let t=e(r,i,s);if(t)return t}return null}return null},e.renderer=function(e,t){return new qa(t)},e.scene=function(e){return new ca(e)},e.serialize=function(e){return Na(e)},e.table=function(e){return new Dt(e,"")},e.treeJSON=async function(e){return async function(e){let t=await Ft("GET",e);return new _e(JSON.parse(t),e)}(e)}});
|