mascot-vis 1.9.3 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mascot-min.js +2 -2
- package/dist/mascot.js +104 -48
- package/package.json +1 -1
package/dist/mascot-min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/* version: 1.
|
|
2
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("d3"),require("pixi.js")):"function"==typeof define&&define.amd?define(["exports","d3","pixi.js"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).msc={},t.d3,t.PIXI)}(this,(function(t,e,i){"use strict";function s(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(i){if("default"!==i){var s=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,s.get?s:{enumerable:!0,get:function(){return t[i]}})}})),e.default=t,Object.freeze(e)}var n=s(e),r=s(i);class a{constructor(t,e,i,s){this.left=t,this.top=e,this.width=i,this.height=s}toJSON(){let t={};return t.left=this.left,t.top=this.top,t.width=this.width,t.height=this.height,t}union(t){let e=Math.min(this.left,t.left),i=Math.min(this.top,t.top),s=Math.max(this.right,t.right),n=Math.max(this.bottom,t.bottom);return new a(e,i,s-e,n-i)}clone(){return new a(this.left,this.top,this.width,this.height)}get right(){return this.left+this.width}get bottom(){return this.top+this.height}get x(){return(this.left+this.right)/2}get y(){return(this.top+this.bottom)/2}get center(){return(this.left+this.right)/2}get middle(){return(this.top+this.bottom)/2}contains(t,e){return this.left<=t&&this.right>=t&&this.top<=e&&this.bottom>=e}overlap(t){return!(this.right<t.left||this.bottom<t.top||this.left>t.right||this.top>t.bottom)}}const o="id",h="atlas_rowId",l=["linear","power","log","sqrt","symlog","identity","time","ordinal","band","point","ordinalColor","sequentialColor","divergingColor"],c="natural",d="basis",u="bumpX",f="bumpY",p="linear",g="step",_="CatmullRom",m="cardinal",y={Grid:"grid",Circular:"circular",Stack:"stack",Treemap:"treemap",Packing:"packing",Force:"force",TidyTree:"tidytree",Sugiyama:"sugiyama",Strata:"strata"},v="vertical",b="horizontal",x="angular",w="radial",k={Up:"up",Down:"down",Left:"left",Right:"right",Inward:"inward",Outward:"outward",Clockwise:"clockwise",Anticlockwise:"anticlockwise"},C={Top:"top",Left:"left",Bottom:"bottom",Right:"right",Center:"center",Middle:"middle"},S="alignment",E="affixation",T={Area:"area",Rect:"rect",Ellipse:"ellipse",Circle:"circle",Pie:"pie",Ring:"ring",Arc:"arc",Line:"line",Path:"path",Image:"image",PointText:"pointText",Collection:"collection",Group:"group",Scene:"scene",Axis:"axis",Glyph:"glyph",Legend:"legend",Polygon:"polygon",Gridlines:"gridlines",LinearGradient:"LinearGradient",Link:"link",DataTable:"datatable"},A={Boolean:"boolean",Integer:"integer",Number:"number",Date:"date",String:"string"},I="max",O="min",M="avg",R="median",N="sum",F="count",P="mean",B="percentile 25",L="percentile 75",D={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"},j="Cannot find relevant information to create an axis for ",V="Cannot change scale type to ",G={FIELD_NONEXISTENT:"Data field does not exist in the data table",INCOMPLETE_REPEAT_INFO:"Incomplete information to do repeat. You must specify an item, a categorical data field and a data table",REPEAT_BY_NONCAT:"Repeat only works on a string or date field",PARTITION_BY_NONCAT:"Divide only works on a string or date field",DENSIFY_BY_NONCAT:"Densify only works on a string or date field",INCOMPLETE_REPOPULATE_INFO:"Incomplete information to re-populate. You must specify an item, a categorical data field and a data table",REPOPULATE_BY_NONCAT:"Repopulate only works on a string or date field",REPOPULATE_DT_MISMATCH:"Cannot repopulate with a data table that is different from the item's parent's data table",COMPNT_NON_REPEATABLE:"Item not repeatable",REPEAT_NODE_LINK:"To repeat with a tree or a network, you need to provide two marks, one for node and one for link",INCOMPLETE_PARTITION_INFO:"Incomplete information to divide. You must specify an item, a categorical data field and a data table",COMPNT_NON_PARTITIONABLE:"Item cannot be divided",INCOMPLETE_DENSIFY_INFO:"Incomplete information to densify. You must specify an item, a categorical data field and a data table",COMPNT_NON_DENSIFIABLE:"Item cannot be densified",STRATIFY_WITHOUT_TREE:"Stratify only works on a tree dataset",STRATIFY_WRONG_ITEM:"Stratify only works on a circle or a rectangle",BIND_WITHOUT_DATASCOPE:"Item must be repeated or divided by data first before applyng binding",UNKNOWN_ALIGNMENT:"Unkown alignment",UNKNOWN_Orientation:"Unkown orientation",UNKNOWN_DIRECTION:"Unkown direction",UNKOWNN_SCALE_TYPE:"Unknown scale type",UNKNOWN_ANCHOR:"Unknown anchor",INCOMPLETE_BINDING_INFO:"Incomplete binding information. You must specify an item, a data field and a visual channel",MULTIPLE_VALUES_PER_FIELD:"Multiple distinct field values exist",DIFFERENT_SCALE_TYPE:"Cannot merge different types of scale",INSUFFICIENT_DATA_SCOPES:"Insufficient data to divide or densify a mark",INCORRECT_CONSTRAINT_INFO:"Constrain information is incorreclty passed",FEATURE_NOT_IMPLEMENTED:"This feature has not been implemented yet",LAYOUT_WITHOUT_TREE:"The layout can only be applied to a tree",UNSUPPORTED_FIELDTYPE:"Unsupported field type for encoding "};class z{constructor(t){this.group=void 0}run(){}clone(){}}class W extends z{constructor(t){super(),this.type="grid",this._numCols=t.numCols,this._numRows=t.numRows,this._dir="dir"in t?t.dir:[W.direction.Left2Right,W.direction.Top2Bottom],this._rowGap="rowGap"in t&&void 0!==t.rowGap?t.rowGap:5,this._colGap="colGap"in t&&void 0!==t.colGap?t.colGap:5,this._cellHorzAlignment="horzCellAlignment"in t&&this._validateCellAlignment("h",t.horzCellAlignment)?t.horzCellAlignment:C.Left,this._cellVertAlignment="vertCellAlignment"in t&&this._validateCellAlignment("v",t.vertCellAlignment)?t.vertCellAlignment:C.Bottom}_validateCellAlignment(t,e){return"h"===t&&[C.Left,C.Center,C.Right].indexOf(e)>=0||("v"===t&&[C.Top,C.Middle,C.Bottom].indexOf(e)>=0||(console.warn("Invalid alignment:",e),!1))}toJSON(){let t={args:{}};return t.type=this.type,t.args.numCols=this._numCols,t.args.numRows=this._numRows,t.args.colGap=this._colGap,t.args.rowGap=this._rowGap,t.args.horzCellAlignment=this._cellHorzAlignment,t.args.vertCellAlignment=this._cellVertAlignment,t.left=this._left,t.top=this._top,t.args.dir=this._dir,t}clone(){return new W({numCols:this._numCols,numRows:this._numRows,dir:this._dir,colGap:this._colGap,rowGap:this._rowGap})}get cellBounds(){let t,e,i=this.group,s=this._colGap,n=this._rowGap;this._numRows?(e=this._numRows,t=Math.ceil(this.group.children.length/this._numRows)):this._numCols&&(t=this._numCols,e=Math.ceil(this.group.children.length/this._numCols));let r=i.children.map((t=>t.bounds));if(void 0===this._left){let t=r.map((t=>t.left)),e=r.map((t=>t.top));this._left=Math.min(...t),this._top=Math.min(...e)}let o=r.map((t=>t.width)),h=r.map((t=>t.height)),l=Math.max(...o),c=Math.max(...h),d=i.getInternalEncodings("x"),u=i.getInternalEncodings("y"),f=i.getInternalEncodings("width"),p=i.getInternalEncodings("height"),g=0;if(d.length>0){let t=d[d.length-1];l=t.scale.rangeExtent,g=t.scale.range[0],"point"===t.scale.type&&(l+=t.anyItem.bounds.width)}else f.length>0&&f[f.length-1]._rectNegativeValues&&(l=f[f.length-1].scale.rangeExtent,g=f[f.length-1].scale.range[0]);if(u.length>0){let t=u[u.length-1];c=t.scale.rangeExtent,"point"===t.scale.type&&(c+=t.anyItem.bounds.height)}else p.length>0&&p[p.length-1]._rectNegativeValues&&(c=p[p.length-1].scale.rangeExtent);let _=[],m=e*t;switch(this._dir[0]){case W.direction.Left2Right:switch(this._dir[1]){case W.direction.Top2Bottom:for(let e=0;e<m;e++)_.push(new a(this._left+(l+s)*(e%t)+g,this._top+(c+n)*Math.floor(e/t),l,c));break;case W.direction.Bottom2Top:for(let e=0;e<m;e++)_.push(new a(this._left+(l+s)*(e%t)+g,this._top+(this.numRows-1-Math.floor(e/t))*(c+n),l,c))}break;case W.direction.Right2Left:switch(this._dir[1]){case W.direction.Top2Bottom:for(let e=0;e<m;e++)_.push(new a(g+this._left+(t-1)*(l+s)-(l+s)*(e%t),this._top+(c+n)*Math.floor(e/t),l,c));break;case W.direction.Bottom2Top:for(let e=0;e<m;e++)_.push(new a(g+this._left+(t-1-e%t)*(l+s),this._top+(this.numRows-1-Math.floor(e/t))*(c+n),l,c))}break;case W.direction.Top2Bottom:switch(this._dir[1]){case W.direction.Left2Right:for(let t=0;t<m;t++)_.push(new a(g+this._left+(l+s)*Math.floor(t/this.numRows),this._top+(c+n)*(t%this.numRows),l,c));break;case W.direction.Right2Left:for(let t=0;t<m;t++)_.push(new a(g+this._left+(l+s)*(this.numCols-1)-(l+s)*Math.floor(t/this.numRows),this._top+(c+n)*(t%this.numRows),l,c))}break;case W.direction.Bottom2Top:switch(this._dir[1]){case W.direction.Left2Right:for(let t=0;t<m;t++)_.push(new a(g+this._left+(l+s)*Math.floor(t/this.numRows),this._top+(c+n)*(this.numRows-1)-(c+n)*(t%this.numRows),l,c));break;case W.direction.Right2Left:for(let t=0;t<m;t++)_.push(new a(g+this._left+(l+s)*(this.numCols-1)-(l+s)*Math.floor(t/this.numRows),this._top+(c+n)*(this.numRows-1)-(c+n)*(t%this.numRows),l,c))}}return _}run(){if(null==this.group||!this.group.children||0===this.group.children.length)return;let t=this.cellBounds,e=this.group.getInternalEncodings("x"),i=this.group.getInternalEncodings("y"),s=this.group.getInternalEncodings("width"),n=this.group.getInternalEncodings("height");for(let s=0;s<this.group.children.length;s++){let n=this.group.children[s],r=t[s],a=r.x-n.bounds.x,o=r.y-n.bounds.y;n._doTranslate(a,o);let h=0,l=0;if(0==e.length)switch(this._cellHorzAlignment){case C.Left:h=r.left-n.bounds.left;break;case C.Center:h=r.x-n.bounds.x;break;case C.Right:h=r.right-n.bounds.right}if(0==i.length)switch(this._cellVertAlignment){case C.Top:l=r.top-n.bounds.top;break;case C.Middle:l=r.y-n.bounds.y;break;case C.Bottom:l=r.bottom-n.bounds.bottom}n._doTranslate(h,l)}if(e.length>0)for(let t of e)t._apply();else if(s.length>0){let t=s[s.length-1];t._rectNegativeValues&&t._apply()}if(i.length>0)for(let t of i)t._apply();else if(n.length>0){let t=n[n.length-1];t._rectNegativeValues&&t._apply()}this.group._updateBounds()}set rowGap(t){this._rowGap=t,this.run(),this.group.getScene()._relayoutAncestors(this.group)}get rowGap(){return this._rowGap}set colGap(t){this._colGap=t,this.run(),this.group.getScene()._relayoutAncestors(this.group)}get colGap(){return this._colGap}set numCols(t){t<0||t>this.group.children.length?console.warn("Cannot set",t,"columns for",this.group.children.length,"items in grid"):(this._numCols=t,this._numRows=Math.ceil(this.group.children.length/t),this.run(),this.group.getScene()._relayoutAncestors(this.group))}get numCols(){return this._numCols?this._numCols:this._numRows?Math.ceil(this.group.children.length/this._numRows):0}set numRows(t){t<0||t>this.group.children.length?console.warn("Cannot set",t,"rows for",this.group.children.length,"items in grid"):(this._numRows=t,this._numCols=Math.ceil(this.group.children.length/t),this.run(),this.group.getScene()._relayoutAncestors(this.group))}get numRows(){return this._numRows?this._numRows:this._numCols?Math.ceil(this.group.children.length/this._numCols):0}set vertCellAlignment(t){if(t!=C.Top&&t!=C.Bottom&&t!=C.Middle)throw G.UNKOWN_ALIGNMENT;this._cellVertAlignment=t,this.run()}get vertCellAlignment(){return this._cellVertAlignment}set horzCellAlignment(t){if(t!=C.Left&&t!=C.Center&&t!=C.Right)throw G.UNKOWN_ALIGNMENT;this._cellHorzAlignment=t,this.run()}get horzCellAlignment(){return this._cellHorzAlignment}}W.direction={Left2Right:"l2r",Right2Left:"r2l",Top2Bottom:"t2b",Bottom2Top:"b2t"};class U{constructor(t){this._stops=[],this.type=T.LinearGradient,this.id=this.type+pt[this.type]++,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 t={};return t.type=this.type,t.id=this.id,t.x1=this.x1,t.x2=this.x2,t.y1=this.y1,t.y2=this.y2,t.stops=this._stops,t}addStop(t,e,i){this._stops.push({offset:t,color:e,opacity:i})}get stops(){return this._stops}}class q{constructor(t){if(this._dataScope=void 0,this._id=void 0,this.attrs={},this.styles={},this.staticProperties={},void 0!==t)for(let e in D)e in t&&(this.styles[e]=t[e])}get id(){return this._id}set id(t){this.getScene()?(delete this.getScene()._itemMap[this._id],this._id=t,this.getScene()._itemMap[t]=this):this._id=t}contains(t,e){if(!this._bounds)return!1;if(!this._bounds.contains(t,e))return!1;switch(this.type){case T.Rect:case T.PointText:return!0;case T.Circle:return Math.sqrt(Math.pow(t-this.x,2)+Math.pow(e-this.y,2))<=this.radius+this.strokeWidth;case T.Path:{let i=mt.getContext(),s=new Path2D(this.getSVGPathData());return i.lineWidth=Math.max(this.strokeWidth,2.5),i.stroke(s),this.closed?i.isPointInPath(s,t,e):i.isPointInStroke(s,t,e)}case T.Line:{let i=mt.getContext(),s=new Path2D(this.getSVGPathData());return i.lineWidth=Math.max(this.strokeWidth,2.5),i.stroke(s),i.isPointInStroke(s,t,e)}default:{let i=mt.getContext(),s=new Path2D(this.getSVGPathData());return i.isPointInPath(s,t,e)}}}toJSON(){let t={};t.type=this.type,t.id=this.id,this.classId&&(t.classId=this.classId),this._dataScope&&(t.dataScope=this._dataScope.toJSON()),t.args={};for(let e in this.attrs)t.args[e]=this.attrs[e];for(let e in this.styles)e.indexOf("Color")>0&&this.styles[e]instanceof U?t.args[e]=this.styles[e].toJSON():t.args[e]=this.styles[e];return t}getScene(){let t=this;for(;t;){if(t.type==T.Scene)return t;t=t.parent}}set dataScope(t){this._dataScope=t}get dataScope(){return this._dataScope}duplicate(){let t=this.getScene().mark(this.type);return this.copyPropertiesTo(t),t.classId=this.classId,this._dataScope&&(t._dataScope=this._dataScope.clone()),t}_doTranslate(t,e){}set visibility(t){this.styles.visibility=t}get visibility(){return this.styles.visibility?this.styles.visibility:"visible"}get opacity(){return"opacity"in this.styles?this.styles.opacity:1}set opacity(t){this.styles.opacity=t}}function J(t){return t>=-1e-12&&t<=1e-12}class Y{constructor(t,e){this.x=t,this.y=e}transform(t){return t?t._transformPoint(this):this}negate(){return new Y(-this.x,-this.y)}subtract(t){return new Y(this.x-t.x,this.y-t.y)}isZero(){return J(this.x)&&J(this.y)}isCollinear(t){let e=this.x,i=this.y,s=t.x,n=t.y;return Math.abs(e*n-i*s)<=1e-8*Math.sqrt((e*e+i*i)*(s*s+n*n))}}class H{constructor(t,e,i){this.type="vertex",this._id=i,this.x=t.x,this.y=t.y,this.dataScope=void 0,this.parent=e,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 bounds(){switch(this.shape){case"rect":return new a(this.x-this.width/2,this.y-this.height/2,this.width,this.height);case"circle":return new a(this.x-this.radius,this.y-this.radius,2*this.radius,2*this.radius);default:return new a(this.x-.5,this.y-.5,1,1)}}get id(){return this.parent.id+"_v_"+this._id}toJSON(){let t={};return t.type=this.type,t.id=this._id,t.x=this.x,t.y=this.y,this.dataScope&&(t.dataScope=this.dataScope.toJSON()),void 0!==this._polarAngle&&(t.polarAngle=this._polarAngle),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}static fromJSON(t,e){let i=new H(t,e,t.id);return t.dataScope&&(i.dataScope=t.dataScope),"polarAngle"in t&&(i.polarAngle=t.polarAngle),i.shape=t.shape,i.width=t.width,i.height=t.height,i.radius=t.radius,i.fillColor=t.fillColor,i.opacity=t.opacity,i.strokeWidth=t.strokeWidth,i.strokeColor=t.strokeColor,i}_doTranslate(t,e){this.x+=t,this.y+=e}_clone(t){let e=new H(new Y(this.x,this.y),t,this._id);return this.dataScope&&(e.dataScope=this.dataScope.clone()),e.shape=this.shape,e.width=this.width,e.height=this.height,e.radius=this.radius,e.fillColor=this.fillColor,e.opacity=this.opacity,e.strokeWidth=this.strokeWidth,e.strokeColor=this.strokeColor,e}set polarAngle(t){this._polarAngle=t}get polarAngle(){return this._polarAngle}}H.styles=["vxShape","vxWidth","vxHeight","vxRadius","vxFillColor","vxStrokeColor","vxStrokeWidth","vxOpacity"];class ${constructor(t,e,i,s){this.type="segment",this._id=s,this.vertex1=t,this.vertex2=e,this.dataScope=void 0,this.parent=i}get id(){return this.parent.id+"_s_"+this._id}_doTranslate(t,e){this.vertex1._doTranslate(t,e),this.vertex2._doTranslate(t,e)}get x(){return(this.vertex1.x+this.vertex2.x)/2}get y(){return(this.vertex1.y+this.vertex2.y)/2}}class Z extends q{constructor(t){if(super(t),this.type="type"in t?t.type:T.Path,"strokeColor"in this.styles||(this.styles.strokeColor="#ccc"),"strokeWidth"in this.styles||(this.styles.strokeWidth=1),"strokeDash"in this.styles||(this.styles.strokeDash="none"),this.vertices=[],this.vertexCounter=0,this.segmentCounter=0,this.segments=[],this.anchor=void 0,this.closed=!1,this.curveMode="linear",this.boundsOffsets={top:0,bottom:0,left:0,right:0},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,void 0!==t){for(let e of H.styles)e in t&&(this["_"+e]=t[e]);"vertices"in t&&this._setVertices(t.vertices)}}toJSON(){let t=super.toJSON();switch(t.type=this.type,t.id=this.id,this.type){case T.Rect:t.args.width=this.width,t.args.height=this.height,t.args.top=this.top,t.args.left=this.left;break;case T.Circle:t.args.x=this.x,t.args.y=this.y,t.args.radius=this.radius;break;case T.Arc:case T.Pie:t.args.x=this._x,t.args.y=this._y,t.args.innerRadius=this._innerRadius,t.args.outerRadius=this._outerRadius,t.args.startAngle=this._startAngle,t.args.endAngle=this._endAngle;break;default:t.vertices=[];for(let e of this.vertices)t.vertices.push(e.toJSON());this.type===T.Polygon?(t.args.x=this._x,t.args.y=this._y,t.args.radius=this._radius):this.type===T.Area&&(t.args.baseline=this._baseline,t.args.orientation=this._orientation)}t.vertexCounter=this.vertexCounter,t.segmentCounter=this.segmentCounter,t.curveMode=this.curveMode,this._bounds&&(t.bounds=this._bounds.toJSON()),t.boundsOffsets=this.boundsOffsets;for(let e of H.styles)t.args[e]=this[e];return t}_setVertices(t){let e,i;this.vertices=[],this.segments=[];for(let s=0;s<t.length;s++)if(s!=t.length-1||t[s][0]!==t[0][0]||t[s][1]!==t[0][1]||this.type!==T.Path){i=new Y(t[s][0],t[s][1]),e=new H(i,this,this.vertexCounter++);for(let t of H.styles)if(this[t]){let i=t.replace("vx","");e[i[0].toLowerCase()+i.slice(1)]=this[t]}this.vertices.push(e),s>0&&this.segments.push(new $(this.vertices[s-1],this.vertices[s],this,this.segmentCounter++))}let s=t[0],n=t[t.length-1];(s[0]===n[0]&&s[1]===n[1]||this.type===T.Rect)&&(this.closed=!0,"fillColor"in this.styles||(this.styles.fillColor="#fff"),this.segments.push(new $(this.vertices[this.vertices.length-1],this.vertices[0],this,this.segmentCounter++)))}copyPropertiesTo(t){t.attrs=Object.assign({},this.attrs),t.styles=Object.assign({},this.styles);for(let e of H.styles)this["_"+e]&&(t["_"+e]=this["_"+e]);this._dataScope&&(t._dataScope=this._dataScope.clone()),t.closed=this.closed,t.curveMode=this.curveMode,t.vertices=[],t.segments=[];for(let e of this.vertices)t.vertices.push(e._clone(t));t.segmentCounter=0;for(let e=1;e<t.vertices.length;e++)t.segments.push(new $(t.vertices[e-1],t.vertices[e],t,t.segmentCounter++));t.closed&&t.segments.push(new $(t.vertices[t.vertices.length-1],t.vertices[0],t,t.segmentCounter++))}get bounds(){return this._bounds||this._updateBounds(),this._bounds}get refBounds(){this._bounds||this._updateBounds();let t=this._bounds.bottom+this.boundsOffsets.bottom-(this._bounds.top-this.boundsOffsets.top),e=this._bounds.right+this.boundsOffsets.right-(this._bounds.left-this.boundsOffsets.left);return new a(this._bounds.left-this.boundsOffsets.left,this._bounds.top-this.boundsOffsets.top,e,t)}get x(){return this.bounds.x}get y(){return this.bounds.y}get strokeColor(){return this.styles.strokeColor}set strokeColor(t){this.styles.strokeColor=t}get strokeWidth(){return this.styles.strokeWidth}set strokeWidth(t){this.styles.strokeWidth=t}get fillColor(){return this.styles.fillColor}set fillColor(t){this.styles.fillColor=t}get strokeDash(){return this.styles.strokeDash}set strokeDash(t){this.styles.strokeDash=t}_doTranslate(t,e){for(let i of this.vertices)i._doTranslate(t,e);this._updateBounds()}resize(t,e,i,s){let n=this.bounds,r=0===n.width?1:n.width,a=0===n.height?1:n.height;if("right"===i)for(let e of this.vertices)e.x=n.right-t/r*(n.right-e.x);else for(let e of this.vertices)e.x=n.left+t/r*(e.x-n.left);if("top"===s)for(let t of this.vertices)t.y=n.top+e/a*(t.y-n.top);else for(let t of this.vertices)t.y=n.bottom-e/a*(n.bottom-t.y);this._updateBounds()}_updateBounds(){let t=this.vertices.map((t=>t.x)),e=this.vertices.map((t=>t.y)),i=Math.min(...t),s=Math.min(...e),n=Math.max(...t),r=Math.max(...e);this._bounds=new a(i,s,n-i,r-s)}addVertex(t,e,i){let s=new H(new Y(t,e),this,this.vertexCounter++);this.vertices.splice(i,0,s)}sortVertices(t,e){this.vertices.sort(((e,i)=>e[t]-i[t])),e&&this.vertices.reverse();for(let t=0;t<this.segments.length;t++){let e=this.segments[t];e.vertex1=this.vertices[t],e.vertex2=this.vertices[(t+1)%this.vertices.length]}}sortVerticesByData(t,e,i){let s;s=i?(e,s)=>i.indexOf(e.dataScope.getFieldValue(t))-i.indexOf(s.dataScope.getFieldValue(t)):(e,i)=>e.dataScope.getFieldValue(t)<i.dataScope.getFieldValue(t)?-1:1,this.vertices.sort(s),e&&this.vertices.reverse();for(let t=0;t<this.segments.length;t++){let e=this.segments[t];e.vertex1=this.vertices[t],e.vertex2=this.vertices[(t+1)%this.vertices.length]}}getSVGPathData(){let t=n.path(),e=this._getD3CurveFunction(this.curveMode)(t);e.lineStart();for(let t of this.vertices)e.point(t.x,t.y);return this.closed&&e.point(this.vertices[0].x,this.vertices[0].y),e.lineEnd(),t._}get firstVertex(){return this.vertices[0]}get firstSegment(){return this.segments[0]}get lastVertex(){return this.vertices[this.vertices.length-1]}get lastSegment(){return this.segments[this.segments.length-1]}_getD3CurveFunction(t){switch(t){case c:return n.curveNatural;case d:return n.curveBasis;case u:return n.curveBumpX;case f:return n.curveBumpY;case p:return n.curveLinear;case g:return n.curveStep;case _:return n.curveCatmullRom;case m:return n.curveCardinal;default:return n.curveLinear}}get vxShape(){return this._vxShape}set vxShape(t){this._vxShape=t;for(let e of this.vertices)e.shape=t}get vxWidth(){return this._vxWidth}set vxWidth(t){this._vxWidth=t;for(let e of this.vertices)e.width=t}get vxHeight(){return this._vxHeight}set vxHeight(t){this._vxHeight=t;for(let e of this.vertices)e.height=t}get vxRadius(){return this._vxRadius}set vxRadius(t){this._vxRadius=t;for(let e of this.vertices)e.radius=t}get vxFillColor(){return this._vxFillColor}set vxFillColor(t){this._vxFillColor=t;for(let e of this.vertices)e.fillColor=t}get vxStrokeColor(){return this._vxStrokeColor}set vxStrokeColor(t){this._vxStrokeColor=t;for(let e of this.vertices)e.strokeColor=t}get vxStrokeWidth(){return this._vxStrokeWidth}set vxStrokeWidth(t){this._vxStrokeWidth=t;for(let e of this.vertices)e.strokeWidth=t}get vxOpacity(){return this._vxOpacity}set vxOpacity(t){this._vxOpacity=t;for(let e of this.vertices)e.opacity=t}}function K(t,e){if("field"in e){if(!t.dataScope)return!1;let i=e.field;if("value"in e)return t.dataScope.getFieldValue(i)===e.value;if("interval"in e){let s=t.dataScope.getFieldValue(i);return s>=e.interval[0]&&s<=e.interval[1]}return"values"in e?e.values.indexOf(t.dataScope.getFieldValue(i))>=0:t.dataScope.hasField(i)}if("channel"in e){let i=e.channel;if("value"in e)return t[i]===e.value;if("interval"in e)return t[i]>=e.interval[0]&&t[i]<=e.interval[1];if("values"in e)return e.values.indexOf(t[i])>=0}else{if("type"in e)return t.type===e.type;if("id"in e)return t.id===e.id;if("classId"in e)return t.classId===e.classId;if("fields"in e){if(!t.dataScope)return!1;let i=e.fields[0],s=e.fields[1],n=t.dataScope.getFieldValue(i),r=t.dataScope.getFieldValue(s);switch(e.operator){case"==":return n==r;case">":return n>r;case">=":return n>=r;case"<":return n<r;case"<=":return n<=r}}}return!1}function X(t,e){let i=[];return Q(t,e,i),i}function Q(t,e,i){if(t&&"axis"!=t.type&&"legend"!=t.type&&"gridlines"!=t.type)if(tt(t,e)&&i.push(t),t.vertices)for(let s of t.vertices.concat(t.segments))tt(s,e)&&i.push(s);else if(t.children&&t.children.length>0)for(let s of t.children)Q(s,e,i)}function tt(t,e){for(let i of e)if(!K(t,i))return!1;return!0}function et(t,e){return"vertex"==t.type?function(t,e){if(!t.classId){if(t.dataScope){let i=t.parent;if(!i)throw new Error("vertex has no parent mark");let s=X(e,[{classId:i.classId}]),n=[];if(i.type===T.Area){let e=i.vertices.indexOf(t)<i.vertices.length/2;for(let t of s){let i=e?t.vertices.slice(0,t.vertices.length/2):t.vertices.slice(t.vertices.length/2);n=n.concat(i.filter((t=>t.dataScope)))}}else for(let t of s)n=n.concat(t.vertices.filter((t=>t.dataScope)));return n}{let i=t.parent;if(!i)throw new Error("vertex has no parent mark");let s=i.vertices.indexOf(t),n=X(e,[{classId:i.classId}]),r=[];for(let t of n)r.push(t.vertices[s]);return r}}}(t,e):"segment"==t.type?function(t,e){if(t.dataScope){let i=t.parent;if(!i)throw new Error("segment has no parent mark");let s=X(e,[{classId:i.classId}]),n=[];for(let t of s)n=n.concat(t.segments);return n}{let i=t.parent;if(!i)throw new Error("segment has no parent mark");let s=i.segments.indexOf(t),n=X(e,[{classId:i.classId}]),r=[];for(let t of n)r.push(t.segments[s]);return r}}(t,e):t.classId?X(e,[{classId:t.classId}]):[]}function it(t,e){let i=t.parent;for(;i&&i.type!=T.Scene;){if(i.layout&&(!e||e&&i.layout.type===e))return i.layout;i=i.parent}}function st(t){let e=t,i=t.parent;for(;i&&i.type!=T.Scene;){if(i.layout){let t=i.children.findIndex((t=>t==e));return i.layout.cellBounds[t]}e=e.parent,i=e.parent}}function nt(t){let e=t,i=t.parent;for(;i&&i.type!=T.Scene;){if(i.layout&&i.layout.type==y.Grid){let t=i.children.findIndex((t=>t==e));return i.layout.cellBounds[t]}e=e.parent,i=e.parent}}function rt(t,e){let i,s=t.parent;for(;s&&s.type!==T.Scene;)s.layout&&(!e||e&&s.layout.type===e)&&(i=s.layout),s=s.parent;return i}function at(t){if(t.classId)return t.classId;if("vertex"==t.type&&t.dataScope){if(t.parent.type===T.Area){let e=t.parent.vertices.indexOf(t)<t.parent.vertices.length/2;return t.parent.classId+"_v_"+(e?0:t.parent.vertices.length-1)}return t.parent.classId+"_v"}return"vertex"==t.type?t.parent.classId+"_v_"+t.parent.vertices.indexOf(t):"segment"==t.type&&t.dataScope?t.parent.classId+"_s":"segment"==t.type?t.parent.classId+"_s_"+t.parent.segments.indexOf(t):null}function ot(t){let e=[];for(let i of t)i.parent&&e.indexOf(i.parent)<0&&e.push(i.parent);return e}function ht(t){let e=[];if(t.children&&t.children.length>0)for(let i of t.children)e.push(i),e=e.concat(ht(i));return e}function lt(t){let e=[];if(ut(t))e.push(t);else if(t.children&&t.children.length>0&&!dt(t))for(let i of t.children)e=e.concat(lt(i));return e}function ct(t){let e=[];if(t.children&&t.children.length>0)for(let i of t.children)e=e.concat(ct(i));else e.push(t);return e}function dt(t){return t.type===T.Axis||t.type===T.Legend||t.type===T.Gridlines}function ut(t){return t instanceof q}function ft(t){return t instanceof Z}const pt={area:0,rect:0,circle:0,pie:0,line:0,path:0,ring:0,arc:0,image:0,pointText:0,collection:0,group:0,scene:0,axis:0,glyph:0,legend:0,polygon:0,gridlines:0,LinearGradient:0,link:0,scale:0,datatable:0};function gt(t,e){if(e.getEncodingByItem(t,"x"))return!1;if(t.parent&&t.parent.layout){let e=t.parent.layout;if(e.type==y.Grid&&e.numCols>1)return!1}return!t.parent||t.parent.type==T.Scene||gt(t.parent,e)}function _t(t,e){if(e.getEncodingByItem(t,"y"))return!1;if(t.parent&&t.parent.layout){let e=t.parent.layout;if(e.type==y.Grid&&e.numRows>1)return!1}return!t.parent||t.parent.type==T.Scene||_t(t.parent,e)}var mt={canvas:void 0,getCanvas:function(){return window?(void 0===this.canvas&&(this.canvas=document.createElement("canvas")),this.canvas):null},getContext:function(){var t=this.getCanvas();return t?t.getContext("2d"):null}},yt={svg:void 0,getSVG:function(){return window?(void 0===this.svg&&(this.svg=document.createElement("svg")),this.svg):null}};function vt(t){let e=t.parent;return e.type==T.Scene?t:vt(e)}function bt(t){let e=t.parent;return t.type==T.Collection?e.type==T.Collection?bt(e):t:e.type!=T.Scene?bt(e):void 0}function xt(t,e,i,s){return[i*Math.cos(kt(s))+t,e-i*Math.sin(kt(s))]}function wt(t,e,i,s){let n=function(t){return 180*t/Math.PI}(Math.atan2(s-e,t-i));n=Math.round(10*n+Number.EPSILON)/10,n<0&&(n+=360);let r=Math.sqrt(Math.pow(t-i,2)+Math.pow(e-s,2));return r=Math.round(10*r+Number.EPSILON)/10,[n,r]}function kt(t){return t*Math.PI/180}function Ct(t){let e=t.vertices.length;for(let i=0;i<t.vertices.length/2;i++){let s=i,n=e-i-1,r=t.vertices[s],a=t.vertices[n];if(r.x!=a.x||r.y!=a.y)return r.x==a.x?"horizontal":"vertical"}}class St{constructor(){this.children=[],this._dataScope=void 0,this._layout=void 0,this.type=T.Group,this._id=this.type+pt[this.type]++}get id(){return this._id}set id(t){this.type!==T.Scene&&this.getScene()?(delete this.getScene()._itemMap[this._id],this._id=t,this.getScene()._itemMap[t]=this):this._id=t}contains(t,e){return this._bounds||this._updateBounds(),this._bounds.contains(t,e)}toJSON(){let t={};if(t.type=this.type,t.id=this.id,this._dataScope&&(t.dataScope=this._dataScope.toJSON()),this.classId&&(t.classId=this.classId),this._layout&&(t.layout=this._layout.toJSON()),this._bounds&&(t.bounds=this._bounds.toJSON()),t.children=[],this.children.length>0&&this.type!=T.Axis)for(let e of this.children)t.children.push(e.toJSON());return this.childrenOrder&&(t.childrenOrder=this.childrenOrder),t}addChild(t){this.children.indexOf(t)>=0||(t.parent&&t.parent.removeChild(t),this.children.push(t),t.parent=this)}addChildAt(t,e){t.parent&&t.parent.removeChild(t),this.children.splice(e,0,t),t.parent=this}removeChild(t){let e=this.children.indexOf(t);e>=0&&(this.children.splice(e,1),t.parent=null)}removeChildAt(t){this.children[t].parent=null,this.children.splice(t,1)}removeAll(){for(let t of this.children)t.parent=null;this.children=[]}getScene(){let t=this;for(;t;){if(t.type==T.Scene)return t;t=t.parent}}get dataScope(){return this._dataScope}set dataScope(t){if(this._dataScope=t,void 0===t)for(let e of this.children)e.dataScope=t;else for(let e of this.children)e.dataScope?e.dataScope=e.dataScope.merge(t):e.dataScope=t}_doTranslate(t,e){for(let i of this.children)i._doTranslate(t,e);this._updateBounds(),this._layout&&(void 0!==this._layout._left&&(this._layout._left+=t),void 0!==this._layout._top&&(this._layout._top+=e),void 0!==this._layout.x&&(this._layout.x+=t),void 0!==this._layout.y&&(this._layout.y+=e)),this._updateBounds()}getInternalEncodings(t){if(0==this.children.length)return[];let e=this.children[0],i=this.getScene(),s=Object.keys(i.encodings),n=[];for(;e&&(e.classId&&n.indexOf(e.classId)<0&&n.push(e.classId),e.children);)e=e.children[0];let r=[];for(let e of s){let s=e.split("_");for(let a of n)s[0]==a&&i.encodings[e][t]&&r.push(i.encodings[e][t])}return r}get firstChild(){return this.children[0]}get lastChild(){return this.children[this.children.length-1]}set layout(t){if(this._layout=t,t)t.group=this,this._layout.run();else{let t=this.getInternalEncodings("x"),e=this.getInternalEncodings("y");for(let e of t)e._map(),e._apply();for(let t of e)t._map(),t._apply()}}get layout(){return this._layout}get bounds(){return this._bounds||this._updateBounds(),this._bounds}get refBounds(){let t=this.children.map((t=>t.refBounds)),e=Math.min(...t.map((t=>t.left))),i=Math.min(...t.map((t=>t.top))),s=Math.max(...t.map((t=>t.right))),n=Math.max(...t.map((t=>t.bottom)));return new a(e,i,s-e,n-i)}get x(){return this.bounds.x}get y(){return this.bounds.y}_updateBounds(){if(this.children.length>0){this._bounds=this.children[0].bounds.clone();for(let t=1;t<this.children.length;t++)"hidden"!=this.children[t].visibility&&(this._bounds=this._bounds.union(this.children[t].bounds));if(this._layout&&"grid"==this._layout.type){let t=this._layout.cellBounds;for(let e=0;e<t.length;e++)this._bounds=this._bounds.union(t[e])}}else this._bounds=new a(0,0,0,0)}sortChildrenByData(t,e,i){let s;switch(this.children[0].dataScope.getFieldType(t)){case A.Date:break;case A.Number:case A.Integer:s=(e,i)=>e.dataScope.aggregateNumericalField(t)-i.dataScope.aggregateNumericalField(t);break;case A.String:s=i?(e,s)=>i.indexOf(e.dataScope.getFieldValue(t))-i.indexOf(s.dataScope.getFieldValue(t)):(e,i)=>e.dataScope.getFieldValue(t)<i.dataScope.getFieldValue(t)?-1:1}this.children.sort(s),e&&this.children.reverse(),this.layout&&this.layout.run(),this._childrenOrder={field:t,direction:e?"desc":"asc",ranking:i}}sortChildren(t,e){let i;switch(t){case"x":case"y":case"width":case"height":i=(e,i)=>e.bounds[t]-i.bounds[t];break;default:i=(e,i)=>e[t]-i[t]}this.children.sort(i),e&&this.children.reverse(),this.layout&&this.layout.run(),this.childrenOrder={channel:t,reverse:e}}set visibility(t){this._visibility="hidden"==t?t:"visible";for(let e of this.children)e.visibility=t}get visibility(){return this._visibility?this._visibility:"visible"}}function Et(t){return[...new Set(t)]}function Tt(t,e){if(e.hasField(t))return!0;if(e.tree&&e.tree.nodeTable.hasField(t.split(".")[1]))return!0;throw new Error(G.FIELD_NONEXISTENT+", field: "+t+", data table: "+e.name)}function At(t){return t<0?t+360:t>360?t-360:t}class It{constructor(t){this._field2value={},this._dt=t,this._tuples=this._dt.data}toJSON(){let t={};return t.dt=this._dt.id,t.f2v=Object.assign({},this._field2value),t}isFullTable(){return 0===Object.keys(this._field2value).length}isEmpty(){return 0==this._tuples.length}get numTuples(){return this._tuples.length}get fields(){return Object.keys(this._field2value)}get dataTable(){return this._dt}get filters(){return this._field2value}merge(t){let e=new It(this._dt);for(let i in t._field2value)e=e.cross(i,t._field2value[i]);for(let t in this._field2value)e=e.cross(t,this._field2value[t]);return e}cross(t,e){let i=this.clone();return i._field2value[t]=e,i._updateTuples(t,e),i}clone(){let t=new It(this._dt);return t._field2value=Object.assign({},this._field2value),t._tuples=this._tuples.map((t=>t)),t}getFieldValue(t){let e=this._tuples.map((e=>e[t]));return e=[...new Set(e)],e.length,e[0]}getUniqueFieldValues(t){let e=this._tuples.map((e=>e[t]));return[...new Set(e)]}hasField(t){return t in this._field2value}getFieldType(t){return this._dt.getFieldType(t)}aggregateNumericalField(t,e){let i=this._tuples.map((e=>e[t]));switch(e){case I:return Math.max(...i);case O:return Math.min(...i);case M:case P:return n.mean(i);case R:return n.median(i);case F:return i.length;case B:return n.quantile(i,.25);case L:return n.quantile(i,.75);case N:default:return n.sum(i)}}_updateTuples(t,e){this._tuples=this._tuples.filter((i=>i[t]==e))}}function Ot(t,e,i,s,n){let r=n?s.transformField(i,n):i,a=s.getFieldType(r);if(a!=A.String&&a!=A.Date&&a!=A.Integer)throw new Error(G.REPEAT_BY_NONCAT+": "+r+" is "+a);if(!Xc(e))throw new Error(G.COMPNT_NON_REPEATABLE);return function(t,e,i,s){let n=s.getFieldSummary(i).unique.map((t=>e.dataScope?e.dataScope.cross(i,t):new It(s).cross(i,t)));n=n.filter((t=>!t.isEmpty()));let r=t.collection();r.dataScope=e.dataScope?e.dataScope.clone():new It(s),r.addChild(e);for(let t=1;t<n.length;t++){let t=e.duplicate();r.addChild(t)}return r.children.forEach(((t,e)=>t.dataScope=n[e])),t._reapplySizeBindings(e),r}(t,e,r,s)}class Mt extends z{constructor(t){super(t),this.type=y.Stack,this._orientation=t.orientation,this._direction=t.direction,this._left=t.left,this._top=t.top,this._horzCellAlignment="horzCellAlignment"in t&&t.horzCellAlignment?t.horzCellAlignment:C.Left,this._vertCellAlignment="vertCellAlignment"in t&&t.vertCellAlignment?t.vertCellAlignment:C.Bottom,this._gap="gap"in t?t.gap:0}toJSON(){let t={args:{}};return t.type=this.type,t.args.orientation=this._orientation,t.args.direction=this._direction,t.args.left=this._left,t.args.top=this._top,t.args.gap=this._gap,t.args.horzCellAlignment=this._horzCellAlignment,t.args.vertCellAlignment=this._vertCellAlignment,t}clone(){let t=new Mt({orientation:this._orientation,direction:this._direction,left:this._left,top:this._top});return t._horzCellAlignment=this._horzCellAlignment,t._vertCellAlignment=this._vertCellAlignment,t}_stackAreasVert(){let t=this.group.children,e=this.group.bounds,i=this._vertCellAlignment===C.Top?e.top:e.bottom,s=this._vertCellAlignment===C.Top?1:-1,n=t[0].vertices.length/2,r=new Array(n).fill(0);for(let e of t){for(let t=0;t<n;t++){let a=e.vertices[t],o=e.vertices[2*n-t-1],h=Math.abs(a.y-o.y),l=i+r[t]*s,c=i+(r[t]+h)*s;a._doTranslate(0,l-a.y),o._doTranslate(0,c-o.y),r[t]+=h}e._updateBounds()}if(this.vertCellAlignment===C.Middle)for(let i of t){for(let t=0;t<n;t++){let s=i.vertices[t],a=i.vertices[2*n-t-1],o=e.middle+r[t]/2;s._doTranslate(0,o-e.bottom),a._doTranslate(0,o-e.bottom)}i._updateBounds()}this.group._updateBounds()}_stackAreasHorz(){let t=this.group.children,e=this.group.bounds,i=this._horzCellAlignment===C.Right?e.right:e.left,s=this._horzCellAlignment===C.Right?-1:1,n=t[0].vertices.length/2,r=new Array(n).fill(0);for(let e of t){for(let t=0;t<n;t++){let a=e.vertices[t],o=e.vertices[2*n-t-1],h=Math.abs(a.x-o.x),l=i+r[t]*s,c=i+(r[t]+h)*s;a._doTranslate(0,l-a.y),o._doTranslate(0,c-o.y),r[t]+=h}e._updateBounds()}if(this._horzCellAlignment===C.Center)for(let i of t){for(let t=0;t<n;t++){let s=i.vertices[t],a=i.vertices[2*n-t-1],o=e.center-r[t]/2;s._doTranslate(0,o-e.left),a._doTranslate(0,o-e.left)}i._updateBounds()}this.group._updateBounds()}_stackAreas(){this.group.children[0].orientation===b?this._stackAreasVert():this._stackAreasHorz()}_stackArcs(){let t=this.group,e=this.startAngle?this.startAngle:90;if((this._direction?this._direction:k.Clockwise)===k.Clockwise)for(let i of t.children){let t=At(e-i.angle);i.adjustAngle(t,e),e=t}else for(let i of t.children){let t=At(e+i.angle);i.adjustAngle(e,t),e=t}}_stackRects(){let t=this.group.getScene(),e=this.group,i=this._orientation,s=e.children.map((t=>t.bounds)),n=s.map((t=>t.left)),r=s.map((t=>t.top)),a=s.map((t=>t.width)),o=s.map((t=>t.height)),h=null==this._left?Math.min(...n):this._left,l=null==this._top?Math.min(...r):this._top,c=Math.max(...a),d=Math.max(...o);if(i==v){let i=h+c/2;for(let s=0;s<e.children.length;s++){let n=e.children[s],r=i-n.bounds.x,a=l+n.bounds.height/2-n.bounds.y;l+=n.bounds.height+this._gap,n._doTranslate(r,a);let o=0,d=0;if(!t.getEncodingByItem(n,"x"))switch(this._horzCellAlignment){case C.Left:o=h-n.bounds.left;break;case C.Center:o=h+c/2-n.bounds.x;break;case C.Right:o=h+c-n.bounds.right}n._doTranslate(o,d)}}else{let i=l+d/2;for(let s=0;s<e.children.length;s++){let n=e.children[s],r=h+n.bounds.width/2-n.bounds.x,a=i-n.bounds.y;h+=n.bounds.width+this._gap,n._doTranslate(r,a);let o=0,c=0;if(!t.getEncodingByItem(n,"y"))switch(this._vertCellAlignment){case C.Top:c=l-n.bounds.top;break;case C.Middle:c=l+d/2-n.bounds.y;break;case C.Bottom:c=l+d-n.bounds.bottom}n._doTranslate(o,c)}}this.group._updateBounds()}run(){null!=this.group&&this.group.children&&0!==this.group.children.length&&("area"==this.group.children[0].type?this._stackAreas():this.group.children[0].type==T.Arc||this.group.children[0].type==T.Pie?this._stackArcs():this._stackRects())}set vertCellAlignment(t){if(t!=C.Top&&t!=C.Bottom&&t!=C.Middle)throw G.UNKOWN_ALIGNMENT;this._vertCellAlignment=t,this.run()}get vertCellAlignment(){return this._vertCellAlignment}set horzCellAlignment(t){if(t!=C.Left&&t!=C.Center&&t!=C.Right)throw G.UNKOWN_ALIGNMENT;this._horzCellAlignment=t,this.run()}get horzCellAlignment(){return this._horzCellAlignment}get cellBounds(){return this.group.children.map((t=>t.bounds))}get orientation(){return this._orientation}set orientation(t){this._orientation=t,this.run()}}function Rt(t,e,i,s,n,r){let a=r?n.transformField(s,r):s,o=n.getFieldType(a);if(o!=A.String&&o!=A.Date)throw new Error(G.PARTITION_BY_NONCAT+": "+a+" is "+o);if(!Qc(e))throw new Error(G.COMPNT_NON_PARTITIONABLE);switch(e.type){case T.Line:return function(t,e,i,s){let n,r,a=et(e,t),o=s.getFieldSummary(i).unique.map((t=>new It(s).cross(i,t))),h={},l=0;for(let t of a){let e=o;t.dataScope&&(e=o.map((e=>e.merge(t.dataScope))),e=e.filter((t=>!t.isEmpty()))),e.length>l&&(l=e.length),h[t.id]=e}for(let i of a){let s=t.collection();null==r&&(r=s.id),s.classId=r,s.dataScope=i.dataScope,i.parent.addChild(s);let a=h[i.id],o=i.vertices[0].x,c=i.vertices[0].y,d=i.vertices[1].x,u=i.vertices[1].y;i.classId=e.id,i.vertices[0].x=o,i.vertices[0].y=c,i.vertices[1].x=o+(d-o)/l,i.vertices[1].y=c+(u-c)/l,i.dataScope=a[0],s.addChild(i);for(let t=1;t<a.length;t++){let e=i.duplicate();e.vertices[0].x=o+(d-o)*t/l,e.vertices[0].y=c+(u-c)*t/l,e.vertices[1].x=o+(d-o)*(t+1)/l,e.vertices[1].y=c+(u-c)*(t+1)/l,e.dataScope=a[t],s.addChild(e)}i==e&&(n=s)}return n}(t,e,a,n);case T.Circle:return function(t,e,i,s,n){let r,a,o=i||x,h=et(e,t);if(o==x)h.forEach((i=>{let o=i.dataScope?i.dataScope:new It(n),h=n.getFieldSummary(s).unique.map((t=>o.cross(s,t)));h=h.filter((t=>!t.isEmpty()));let l=h.length,c=t.collection();c.dataScope=o,null==a&&(a=c.id),c.classId=a;let d=i.parent,u=360/l,f=90;for(let s=0;s<l;s++){let n=t.mark("pie",{innerRadius:0,outerRadius:i.radius,x:i.x,y:i.y,startAngle:At(f-u*(s+1)),endAngle:At(f-u*s),strokeColor:i.strokeColor,fillColor:i.styles.fillColor});n.dataScope=h[s],n.classId=e.id,c.addChild(n)}c.layout=Hc("stack",{direction:k.Clockwise}),d.removeChild(i),d.addChild(c),i==e&&(r=c)}));else{if(o!=w)throw G.UNKNOWN_Orientation+": "+o;h.forEach((i=>{let o=i.dataScope?i.dataScope:new It(n),h=n.getFieldSummary(s).unique.map((t=>o.cross(s,t)));h=h.filter((t=>!t.isEmpty()));let l=h.length,c=t.collection();c.dataScope=o,null==a&&(a=c.id),c.classId=a;let d=i.parent,u=i.radius/l;for(let s=0;s<l;s++){let n=t.mark("ring",{x:i.x,y:i.y,innerRadius:s*u,outerRadius:(s+1)*u,strokeColor:i.strokeColor,fillColor:i.styles.fillColor});n.dataScope=h[s],n.classId=e.id,c.addChild(n)}d.removeChild(i),d.addChild(c),i==e&&(r=c)}))}return r}(t,e,i,a,n);case T.Rect:return function(t,e,i,s,n){let r,a=et(e,t),o=i||b;if(o!=b&&o!=v)throw G.UNKNOWN_Orientation+": "+o;let h,l=n.getFieldSummary(s).unique.map((t=>new It(n).cross(s,t))),c={},d=0;for(let t of a){let e=l;t.dataScope&&(e=l.map((e=>e.merge(t.dataScope))),e=e.filter((t=>!t.isEmpty()))),e.length>d&&(d=e.length),c[t.id]=e}for(let i of a){let s=t.collection();null==h&&(h=s.id),s.classId=h,s.dataScope=i.dataScope?i.dataScope:new It(n),i.parent.addChild(s);let a=c[i.id],l=i.bounds,u=l.left,f=l.top,p=o==b?l.width/d:l.width,g=o==b?l.height:l.height/d;i.classId=e.id,i.resize(p,g),i.dataScope=a[0],s.addChild(i);for(let t=1;t<a.length;t++){let e=i.duplicate();e.resize(p,g),e.dataScope=a[t],s.addChild(e)}s.layout=new Mt({orientation:o,left:u,top:f}),i==e&&(r=s)}t._reapplySizeBindings(r);let u=t.getRelatedAxes(e);for(let i of u)i._item.classId===e.classId&&(i._item=r,i._items=et(r,t));return r}(t,e,i,a,n);case T.Area:return function(t,e,i,s,n){let r,a=et(e,t),o=a[0];if(4==o.vertices.length&&i==b&&o.vertices[0].x!==o.vertices[1].x)for(let t of a){let e=t.vertices[1];t.vertices[1]=t.vertices[3],t.vertices[3]=e}let h,l=n.getFieldSummary(s).unique.map((t=>new It(n).cross(s,t)));for(let s of a){let a=t.collection();null==h&&(h=a.id),a.classId=h,a.dataScope=s.dataScope?s.dataScope:new It(n),s.parent.addChild(a);let o=s.left,c=s.top,d=i==b?s.width/l.length:s.width,u=i==b?s.height:s.height/l.length;s.classId=e.id,s.resizeArea(d,u),a.addChild(s);for(let t=1;t<l.length;t++){let t=s.duplicate();t.resizeArea(d,u),a.addChild(t)}for(let t=0;t<a.children.length;t++){let e=a.children[t];e.dataScope?e.dataScope=e.dataScope.merge(l[t]):e.dataScope=l[t];for(let t of e.vertices)t.dataScope?t.dataScope=e.dataScope.merge(t.dataScope):t.dataScope=e.dataScope}a.layout=new Mt({orientation:i,left:o,top:c}),s==e&&(r=a)}return t._reapplySizeBindings(r),r}(t,e,i,a,n);case T.Ring:return function(t,e,i,s,n){let r,a,o=i||x,h=et(e,t);if(o==x)return h.forEach((i=>{let o=i.dataScope?i.dataScope:new It(n),h=n.getFieldSummary(s).unique.map((t=>o.cross(s,t)));h=h.filter((t=>!t.isEmpty()));let l=h.length,c=t.collection();c.dataScope=o,null==a&&(a=c.id),c.classId=a;let d=i.parent,u=360/l,f=90;for(let s=0;s<l;s++){let n=t.mark("arc",{innerRadius:i.innerRadius,outerRadius:i.outerRadius,x:i.x,y:i.y,startAngle:At(f-u*(s+1)),endAngle:At(f-u*s),strokeColor:i.strokeColor,fillColor:i.fillColor,strokeWidth:i.strokeWidth,opacity:i.opacity});n.dataScope=h[s],n.classId=e.id,c.addChild(n)}c.layout=Hc("stack",{direction:k.Clockwise}),d.removeChild(i),d.addChild(c),i==e&&(r=c)})),r;throw G.UNKNOWN_Orientation+": "+o}(t,e,i,a,n);case T.Pie:case T.Arc:return function(t,e,i,s,n){let r,a,o=i||w,h=et(e,t);if(o==w)return h.forEach((i=>{let o=i.dataScope?i.dataScope:new It(n),h=n.getFieldSummary(s).unique.map((t=>o.cross(s,t)));h=h.filter((t=>!t.isEmpty()));let l=h.length,c=t.collection();c.dataScope=o,null==a&&(a=c.id),c.classId=a;let d=i.parent;for(let s=0;s<l;s++){let n=t.mark("arc",{innerRadius:s*i.outerRadius/l,outerRadius:(s+1)*i.outerRadius/l,x:i.x,y:i.y,startAngle:i.startAngle,endAngle:i.endAngle,strokeColor:i.strokeColor,fillColor:i.fillColor,strokeWidth:i.strokeWidth,opacity:i.opacity});n.dataScope=h[s],n.classId=e.id,c.addChild(n)}d.removeChild(i),d.addChild(c),i==e&&(r=c)})),r;throw G.UNKNOWN_Orientation+": "+o}(t,e,i,a,n)}}function Nt(t,e,i,s,n,r,a,o){let h=r?n.transformField(s,r):s,l=n.getFieldType(h);if(l!=A.String&&l!=A.Date&&l!=A.Number)throw new Error(G.DENSIFY_BY_NONCAT+": "+h+" is "+l);if(!td(e))throw new Error(G.COMPNT_NON_DENSIFIABLE);switch(e.type){case T.Line:return function(t,e,i,s){let n,r=et(e,t);for(let a of r){let r=a.dataScope?a.dataScope:new It(s),o=s.getFieldSummary(i).unique.map((t=>r.cross(i,t)));o=o.filter((t=>!t.isEmpty()));let h=Object.assign({},a.styles);for(let t of H.styles)a[t]&&(h[t]=a[t]);let l=a.vertices[0].x,c=a.vertices[0].y,d=[],u=a.vertices[1].x-l,f=a.vertices[1].y-c;for(let t=0;t<o.length;t++)d.push([l+t*u/(o.length-1),c+t*f/(o.length-1)]);h.vertices=d;let p=t.mark("path",h);p.classId=e.id,p.dataScope=r;let g=a.parent;g.addChild(p),g.removeChild(a);for(let[t,e]of p.vertices.entries())e.dataScope?e.dataScope=e.dataScope.merge(o[t]):e.dataScope=o[t];a==e&&(n=p)}return n}(t,e,h,n);case T.Circle:return function(t,e,i,s,n,r){let a;return et(e,t).forEach((o=>{let h=o.dataScope?o.dataScope:new It(s),l=s.getFieldSummary(i).unique.map((t=>h.cross(i,t)));l=l.filter((t=>!t.isEmpty()));let c=l.length;if(c<3)throw Error(G.INSUFFICIENT_DATA_SCOPES);let d=360/c,u=[],f=[],p="clockwise"==r?-1:1;for(let t=0;t<l.length;t++){let e=n+p*t*d;f[t]=e;let i=xt(o.x,o.y,o.radius,f[t]);u.push(i)}let g=t.mark("polygon",{x:o.x,y:o.y,radius:o.radius,vertices:u});g.dataScope=h,g.styles=Object.assign({},o.styles);for(let t of H.styles)o[t]&&(g[t]=o[t]);let _=o.parent;_.addChild(g),_.removeChild(o);for(let[t,e]of g.vertices.entries())e.polarAngle=f[t],e.dataScope?e.dataScope=e.dataScope.merge(l[t]):e.dataScope=l[t];o==e&&(a=g)})),a}(t,e,h,n,a,o);case T.Rect:case T.Area:return function(t,e,i,s,n){let r,a=et(e,t);for(let o of a){let a=n.getFieldType(s),h=o.dataScope?o.dataScope:new It(n),l=n.getFieldSummary(s).unique.map((t=>h.cross(s,t)));l=a==A.Number?l:l.filter((t=>!t.isEmpty())),a!=A.Number&&a!=A.Date||l.sort(((t,e)=>t._field2value[s]>e._field2value[s]?1:-1));let c=Object.assign({},o.styles),d=o.vertices[0].x,u=o.vertices[0].y,f=o.vertices[o.vertices.length-2].x,p=o.vertices[o.vertices.length-2].y,g=[],_=f-d,m=p-u;for(let t=0;t<l.length;t++)g.push(i==v?[f,u+(l.length-1-t)*m/(l.length-1)]:[d+t*_/(l.length-1),u]);for(let t=0;t<l.length;t++)g.push(i==v?[d,u+t*m/(l.length-1)]:[d+(l.length-1-t)*_/(l.length-1),p]);c.vertices=g;let y=t.mark("area",c);y.classId="area"==o.type?o.classId:"area"+o.classId.substring(9),y.dataScope=h,y.orientation=i,y.baseline=i===b?C.Bottom:C.Left;let x=o.parent;x.addChild(y),x.removeChild(o);for(let[t,e]of y.vertices.entries())t>=l.length?e.dataScope=h.merge(l[2*l.length-1-t]):e.dataScope=h.merge(l[t]);o==e&&(r=y)}return r}(t,e,i,h,n)}}class Ft extends Z{constructor(t){super(t)}get width(){return this.vertices[1].x-this.vertices[0].x}get height(){return this.vertices[2].y-this.vertices[1].y}set height(t){this.resize(this.width,t)}set width(t){this.resize(t,this.height)}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(t,e,i,s){"right"===i?(this.vertices[0].x=this.vertices[1].x-t,this.vertices[3].x=this.vertices[0].x):(this.vertices[1].x=this.vertices[0].x+t,this.vertices[2].x=this.vertices[1].x),"top"===s?(this.vertices[3].y=this.vertices[0].y+e,this.vertices[2].y=this.vertices[3].y):(this.vertices[0].y=this.vertices[3].y-e,this.vertices[1].y=this.vertices[0].y),this._updateBounds()}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 Pt extends Z{constructor(t){super(t),this.attrs.x="x"in t?t.x:0,this.attrs.y="y"in t?t.y:0,this.attrs.radius="radius"in t?t.radius:100}get radius(){return this.attrs.radius}get x(){return this.attrs.x}get y(){return this.attrs.y}get area(){return Math.PI*Math.pow(this.radius,2)}set x(t){this.attrs.x=t,this._updateBounds()}set y(t){this.attrs.y=t,this._updateBounds()}set radius(t){this.attrs.radius=t,this._updateBounds()}resize(t,e,i,s){let n=Math.min(t,e)/2,r=n-this.attrs.radius;this.attrs.radius=n,"right"==i?this.attrs.x-=r:this.attrs.x+=r,"top"==s?this.attrs.y+=r:this.attrs.y-=r,this._updateBounds()}_doTranslate(t,e){this.attrs.x+=t,this.attrs.y+=e,this._updateBounds()}_updateBounds(){this._bounds=new a(this.attrs.x-this.attrs.radius,this.attrs.y-this.attrs.radius,2*this.attrs.radius,2*this.attrs.radius)}copyPropertiesTo(t){super.copyPropertiesTo(t),t.attrs.x=this.attrs.x,t.attrs.y=this.attrs.y,t.attrs.radius=this.attrs.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(" ")}}function Bt(t){return t._query=function(){this.data=[];let t=this.field,e=this.items,i=this.aggregator;switch(this.datatable.getFieldType(t)){case A.Boolean:break;case A.Date:this.data=e.map((e=>e.dataScope.getFieldValue(t)));break;case A.String:break;default:this.data=e.map((e=>e.dataScope.aggregateNumericalField(t,i)))}},t._map=function(){let t,e=this.items,i=this.data,s=this.channel;if(t=Yc(this.scaleType),null==this.data.find((t=>t<0))||"width"!=s&&"height"!=s||0!=e[0].type.indexOf("rect")){let n,r;t.domain=[0,Math.max(...i)],"radius"==s||"outerRadius"==s||"innerRadius"==s?(n=0,r=Math.max(...e.map((t=>t[s]))),r<20&&(r=20)):"area"==s?(n=0,r=Math.max(...e.map((t=>t.bounds.width*t.bounds.height))),r<400&&(r=400)):"fontSize"==s?(n=2,r=Math.max(...e.map((t=>parseFloat(t.styles.fontSize))))):"strokeWidth"==s?(n=1,r=Math.max(...e.map((t=>parseFloat(t.styles.strokeWidth)))),r==n&&(r=n+5)):(n=0,r=Math.max(...e.map((t=>t.bounds[s])))),this.rangeExtent&&(r=n+this.rangeExtent),this.range&&(n=this.range[0],r=this.range[1]),t._setRange([n,r])}else this._rectNegativeValues=!0,t.domain=[Math.min(...i),Math.max(...i)],"width"==s?t._setRange([0,Math.max(...e.map((t=>t.width)))]):t._setRange([0,Math.max(...e.map((t=>t.height)))]);this.scale||(this.scale=t),this.scale._addEncoding(this)},t._apply=function(){if("radius"==this.channel||"outerRadius"==this.channel||"innerRadius"==this.channel){for(let t=0;t<this.items.length;t++){this.items[t][this.channel]=this.scale.map(this.data[t])}this.scene._relayoutAncestors(this.anyItem,this.items)}else if(this._rectNegativeValues){let t=Math.max(...this.data),e=Math.min(...this.data),i="width"===this.channel?Math.min(...this.items.map((t=>t.bounds.left))):Math.min(...this.items.map((t=>t.bounds.top)))+this.scale.rangeExtent,s="width"===this.channel?"right":"top",n="width"===this.channel?"left":"bottom";for(let r=0;r<this.items.length;r++){let a,o=this.items[r];if(o.parent&&o.parent.type===T.Collection){let t=o.parent.parent;if(t.type===T.Collection&&t.layout&&t.layout.type===y.Grid){let e=t.children.indexOf(o.parent);a=t.layout.cellBounds[e][n]}else a=o.parent.refBounds[n]}else a=i;"width"===this.channel?(o.leftSegment._doTranslate(a+this.scale.map(0)-o.leftSegment.vertex1.x,0),o.rightSegment._doTranslate(a+this.scale.map(this.data[r])-o.rightSegment.vertex1.x,0)):(o.topSegment._doTranslate(0,a-this.scale.map(this.data[r])-o.topSegment.vertex1.y),o.bottomSegment._doTranslate(0,a-this.scale.map(0)-o.bottomSegment.vertex1.y)),o._updateBounds(),this.data[r]>0?(o.boundsOffsets[s]=this.scale.map(t)-this.scale.map(this.data[r]),o.boundsOffsets[n]=this.scale.map(0)-this.scale.map(e)):(o.boundsOffsets[n]=this.scale.map(this.data[r])-this.scale.map(e),o.boundsOffsets[s]=this.scale.map(t)-this.scale.map(0))}}else if("area"==this.channel){for(let t=0;t<this.items.length;t++){let e=this.items[t],i=Math.sqrt(this.scale.map(this.data[t]));e.resize(i,i)}this.scene._relayoutAncestors(this.anyItem,this.items)}else if("fontSize"==this.channel){for(let t=0;t<this.items.length;t++){let e=this.items[t],i=this.scale.map(this.data[t]);e.styles.fontSize=i+"px"}this.scene._relayoutAncestors(this.anyItem,this.items)}else if("strokeWidth"==this.channel){for(let t=0;t<this.items.length;t++){let e=this.items[t],i=this.scale.map(this.data[t]);e.styles.strokeWidth=i}this.scene._relayoutAncestors(this.anyItem,this.items)}else{let t="left",e="bottom";if(this.anyItem.parent&&this.anyItem.parent.type==T.Glyph){let i=this.anyItem.parent.children;1==Et(i.map((t=>t.bounds.right))).length&&(t="right"),1==Et(i.map((t=>t.bounds.top))).length&&(e="top")}if(this.anyItem.type===T.Collection&&this.anyItem.layout&&this.anyItem.layout[this.channel])for(let t=0;t<this.items.length;t++){let e=this.items[t],i=this.scale.map(this.data[t]);e.layout[this.channel]=i}else for(let i=0;i<this.items.length;i++){let s=this.items[i],n=this.scale.map(this.data[i]),r="width"==this.channel?n:s.bounds.width,a="height"==this.channel?n:s.bounds.height;s.resize(r,a,t,e)}this.scene._relayoutAncestors(this.anyItem,this.items)}},t.run(),t}function Lt(t){return t._query=function(){this.data=[],this.areas=et(this.items[0],this.scene);let t=this.areas.length;this.areaNum=t,this._vertices=[],this.indicator=[];for(let t of this.areas)for(let e=0;e<t.vertices.length;e++)this._vertices.push(t.vertices[e]),e<t.vertices.length/2?this.indicator.push(1):this.indicator.push(0);let e=this.field,i=this._vertices.map((t=>t.dataScope));switch(this.datatable.getFieldType(e)){case A.Boolean:break;case A.Date:this.data=i.map((t=>t.getFieldValue(e)));break;case A.String:this.data=i.map(((t,i)=>0==this.indicator[i]?0:t.aggregateNumericalField(e,this.aggregator)));break;default:"x"==this.channel||"y"==this.channel?this.data=i.map((t=>t._field2value[e])):this.data=i.map(((t,i)=>0==this.indicator[i]?0:t.aggregateNumericalField(e,this.aggregator)))}},t._map=function(){"fillGradient"===this.channel?this._mapToGradient():"width"!=this.channel&&"height"!=this.channel||this._mapToSize()},t._mapToGradient=function(){if(this.scale){if(!this._mapping){let t=this.scale.domain.concat(this.data);this.scale.domain=[Math.min(...t),Math.max(...t)]}}else if(this._mapping)this.scale=Yc("linear",this._mapping);else{let t,e=Math.min(...this.data),i=Math.max(...this.data),s=Math.max(Math.abs(e),Math.abs(i));e<0&&i>0?(t="interpolatePuOr",e=-s,i=s,this.scale=Yc("divergingColor",this._scheme?this._scheme:t)):(t="interpolateTurbo",this.scale=Yc("sequentialColor",this._scheme?this._scheme:t)),this.scale.domain=[e,i]}this.scale._addEncoding(this)},t._mapToSize=function(){let t,e,i;switch(this.datatable.getFieldType(this.field)){case A.Boolean:break;case A.Date:t=Yc("time"),e=Math.min(...this.data),i=Math.max(...this.data),t.domain=[e,i];break;case A.String:t=Yc("linear"),e=Math.min(...this.data),i=Math.max(...this.data),t.domain=this._includeZero||e<0?[0,i]:[e,i];break;default:t=Yc("linear"),e=Math.min(...this.data),i=Math.max(...this.data),t.domain=e<0?[0,i]:[e,i]}let s,n=Ct(this.areas[0]),r=it(this.anyItem);if(r){let t=r.cellBounds;s="width"==this.channel||"height"==this.channel?n==v?t[0].width:t[0].height:n==v?t[0].height:t[0].width}else s="width"==this.channel?Math.max(...this.areas.map((t=>t.bounds.width))):Math.max(...this.areas.map((t=>t.bounds.height)));e<0?(t._scale.domain([e,i]),t._setRange([0,s])):t._setRange([0,s]),this.scale?this.scale._merge(t):this.scale=t,this.scale._addEncoding(this)},t._apply=function(){"fillGradient"===this.channel?this._applyToGradient():"width"!=this.channel&&"height"!=this.channel||this._applyToSize()},t._applyToGradient=function(){let t=0;for(let e of this.areas){let i=this.data.slice(t,t+e.vertices.length),s=Math.min(...i),n=Math.max(...i),r="horizontal"===e.orientation?$c({x1:0,y1:100,x2:0,y2:0}):$c({x1:0,y1:0,x2:100,y2:0});if(r.addStop(0,this.scale.map(s),1),this._mapping){let t=Object.keys(this._mapping).map((t=>parseFloat(t))).sort();for(let e of t)e>s&&e<n&&r.addStop(100*(e-s)/(n-s),this.scale.map(e),1)}else"divergingColor"===this.scale.type&&r.addStop(100*-s/(n-s),this.scale.map(0),1);r.addStop(100,this.scale.map(n),1),e.fillColor=r,t+=e.vertices.length}},t._applyToSize=function(){let t=[],e=this.channel;for(let e of this.scale.encodings)t=t.concat(e.items);let i=this.areas[0].orientation;if("width"===e||"height"===e){if(it(this.areas[0])){let t=0,e=this.areas.map((t=>st(t))),s=this.areas.map((t=>it(t)));for(let[n,r]of this.areas.entries()){let a=e[n],o=s[n];for(let e=0;e<r.vertices.length;e++){let s,n,h=this._vertices[e+t];if(i===b)if(s=0,o.type===y.Stack)n=a.bottom-this.scale.map(this.data[e+t])-h.y;else if(o.type===y.Grid){switch(r.baseline){case"top":n=a.top+this.scale.map(this.data[e+t])-h.y;break;case"bottom":n=a.bottom-this.scale.map(this.data[e+t])-h.y;break;case"middle":{let i=r.vertices.length-1-e,s=Math.abs(this.scale.map(this.data[e+t])-this.scale.map(this.data[i+t]));n=this.indicator[e+t]?a.middle-s/2-h.y:a.middle+s/2-h.y;break}}}else n=0;else if(n=0,o.type===y.Stack)s=a.left+this.scale.map(this.data[e+t])-h.x;else if(o.type===y.Grid){switch(r.baseline){case"left":s=a.left+this.scale.map(this.data[e+t])-h.x;break;case"right":s=a.right-this.scale.map(this.data[e+t])-h.x;break;case"center":{let i=r.vertices.length-1-e,n=Math.abs(this.scale.map(this.data[e+t])-this.scale.map(this.data[i+t]));s=this.indicator[e+t]?a.center-n/2-h.x:a.center+n/2-h.x;break}}}else s=0;h._doTranslate(s,n)}t+=r.vertices.length}}else{let t="center"==this.areas[0].baseline||"middle"==this.areas[0].baseline,e=0,s=i==v?"left":"bottom",n=i==i==v?"right":"top";for(let t of this.areas){for(let s=e;s<e+t.vertices.length;s++){let e=this._vertices[s],n=i==v?t.baseline!==C.Right?t.bounds.left-t.boundsOffsets.left:t.bounds.right+t.boundsOffsets.right:t.baseline!=C.Top?t.bounds.bottom+t.boundsOffsets.bottom:t.bounds.top-t.boundsOffsets.top,r=i==v?t.baseline!==C.Right?n+this.scale.map(this.data[s])-e.x:n-this.scale.map(this.data[s])-e.x:0,a=i==v?0:t.baseline!=C.Top?n-this.scale.map(this.data[s])-e.y:n+this.scale.map(this.data[s])-e.y;e._doTranslate(r,a)}let r=this.data.slice(e,e+t.vertices.length),a=Math.min(...r),o=Math.max(...r);t.boundsOffsets[n]=this.scale.map(Math.max(...this.data))-this.scale.map(o),t.boundsOffsets[s]=this.scale.map(a)-this.scale.map(Math.min(...this.data)),e+=t.vertices.length}if(1==t){let t=this._vertices.length/this.areaNum,e=ot(this._vertices),s=i==v?Math.min(...e.map((t=>t.bounds.x))):Math.max(...e.map((t=>t.bounds.y)));for(let e=0;e<this.areaNum;e++)for(let n=0;n<t/2;n++){let r=e*t+n,a=(e+1)*t-n-1,o=this._vertices[r],h=this._vertices[a],l=i==v?o.x-h.x:h.y-o.y,c=i==v?s+l/2-o.x:0,d=i==v?0:s+l/2-o.y,u=i==v?s-l/2-h.x:0,f=i==v?0:s-l/2-h.y;o._doTranslate(c,d),h._doTranslate(u,f)}}}}for(let t of this.areas)t._updateBounds();"width"!=e&&"height"!=e||this.scene._relayoutAncestors(this.areas[0],this.areas)},t.run(),t}class Dt{constructor(t,e,i,s,n){this.items=t,this.anyItem=this.items[0],this.scene=e,this.channel=i,this.field=s,this._aggregator=n.aggregator,this.datatable=n.datatable,this.scale=n.scale,this.scale?(this._flipScale=this.scale.isFlipped,this.scaleType=this.scale.type,this._includeZero=this.scale.includeZero):(this._flipScale=n.flipScale,this.scaleType=n.scaleType,this._includeZero=n.includeZero),this._mapping=n.mapping,this.rangeExtent=n.rangeExtent,this._scheme=n.scheme,this.range=n.range,"angle"==this.channel&&(this.startAngle="startAngle"in n?n.startAngle:90),this._query=void 0,this._map=void 0,this._apply=void 0}get id(){return["enc",at(this.anyItem),this.channel,this.field].join("-")}set aggregator(t){this._aggregator=t,this.scale=void 0,this.run()}get aggregator(){return this._aggregator}toJSON(){let t={};return t.anyItem=this.anyItem.id,t.items=this.items.map((t=>t.id)),this.data&&(t.data=this.data),this._rectNegativeValues&&(t._rectNegativeValues=!0),t.args={},t.args.channel=this.channel,t.args.field=this.field,t.args.aggregator=this.aggregator,t.args.datatable=this.datatable.id,t.args.scale=this.scale.id,t.args.mapping=this._mapping,t.args.rangeExtent=this.rangeExtent,t.args.scheme=this._scheme,t.args.scaleType=this.scaleType,t.args.range=this.range,"angle"==this.channel&&(t.args.startAngle=this.startAngle),t}run(){this._query(),this._map(),this._apply()}get dataTable(){return this.datatable}_inferTickValues(){let t,e=this,i=e.scale.domain,s=e.scale.range;switch(e.scale.type){case"linear":case"log":{let r=Math.abs(s[0]-s[1]);if("width"==e.channel||"height"==e.channel){let t=rt(e.anyItem,"stack");if(t){let s=et(t.group,e.scene);r=Math.max(...s.map((t=>t.bounds[e.channel]))),i[1]=e.scale.invert(r)}}t="width"==e.channel||"x"==e.channel?45:30;let a,o=Math.floor(r/t);if("log"===e.scale.type){a=[];let t=e.scale._scale.ticks();for(let e of t){let i=Math.log(e)/Math.log(10)+1e-6;Math.abs(i-Math.floor(i))<o/t.length&&a.push(e)}}else a=n.ticks(i[0],i[1],o);return a}case"point":{t="width"==e.channel||"x"==e.channel?80:30;let s=Math.floor(e.scale.rangeExtent/i.length),n=Math.ceil(t/s);return"x"==e.channel?i.filter(((t,e)=>e%n==0)):i}case"time":{t="width"==e.channel||"x"==e.channel?80:30;let r,a,o=Math.floor((s[1]-s[0])/t),h=Math.ceil((i[1]-i[0])/o)/1e3,l=[1,60,3600,86400,2628003,31536e3],c=[n.timeSeconds,n.timeMinutes,n.timeHours,n.timeDays,n.timeMonths,n.timeYears];for(let t=0;t<l.length-1;t++)if(h>=l[t]&&h<l[t+1])return r=Math.floor(h/l[t]),a=c[t],a(i[0],i[1],r);return h>l[l.length-1]?(r=Math.floor(h/l[l.length-1]),a=c[l.length-1],a(i[0],i[1],r)):[]}default:return[]}}getScaleRange(t){let e=t||this.anyItem;if(e.type!=T.Area&&("vertex"!=e.type||e.parent.type!=T.Area)){if("x"==this.channel){let t=it(e);if(t&&t.type==y.Grid){let i=t.cellBounds,s=e.parent.parent.children.findIndex((t=>e.parent==t||e.parent.parent==t));return[i[s].left,i[s].left+this.scale.rangeExtent]}if("vertex"==e.type||"segment"==e.type){let t=this.scale.offset;return[t,t+this.scale.rangeExtent]}{let t=this.scale.offset;return[t,t+this.scale.rangeExtent]}}if("y"==this.channel){let t=it(e);if(t&&t.type==y.Grid){let i=t.cellBounds,s=e.parent.parent.children.findIndex((t=>e.parent==t||e.parent.parent==t));return[i[s].bottom,i[s].bottom-this.scale.rangeExtent]}if("vertex"==e.type||"segment"==e.type){let t=this.scale.offset;return[t+this.scale.rangeExtent,t]}{let t=this.scale.offset;return[t+this.scale.rangeExtent,t]}}if("width"==this.channel){let t=rt(e);if("grid"===t.type){let i=t.cellBounds,s=e.parent.parent.children.findIndex((t=>e.parent==t||e.parent.parent==t));return[i[s].left,i[s].right]}if("stack"===t.type&&"horizontal"==t.orientation)return[t.group.bounds.left,t.group.bounds.right];{let t=et(e,this.scene),i=Math.min(...t.map((t=>t.bounds.left)));return[i,i+this.scale.rangeExtent]}}if("height"==this.channel){let t=rt(e,"grid");if(t){let i=t.cellBounds,s=e.parent.parent.children.findIndex((t=>e.parent===t||e.parent.parent===t));return[i[s].bottom,i[s].bottom-i[s].height]}{let t=et(e,this.scene),i=Math.max(...t.map((t=>t.bounds.bottom)));return[i,i-this.scale.rangeExtent]}}if("radialDistance"==this.channel){let t=e.parent;return[t.x,t.x+this.scale.rangeExtent]}return this.scale.range}{let t,i=e.type==T.Area?e:e.parent,s=Ct(i),n=it(i);t=n?s==v?n.horzCellAlignment===C.Left:n.vertCellAlignment===C.Bottom:s==v?i.baseline==C.Left:i.baseline==C.Bottom;let r=nt(i);if(r)switch(this.channel){case"x":return[r.left,r.left+this.scale.rangeExtent];case"width":return t?[r.left,r.left+this.scale.rangeExtent]:[r.right,r.right-this.scale.rangeExtent];case"y":return[r.bottom,r.bottom-this.scale.rangeExtent];case"height":return t?[r.bottom,r.bottom-this.scale.rangeExtent]:[r.top+this.scale.rangeExtent,r.top]}else if(n&&"stack"===n.type)switch(r=n.group.bounds,this.channel){case"x":return[r.left,r.left+this.scale.rangeExtent];case"width":return t?[r.left,r.left+this.scale.rangeExtent]:[r.right,r.right-this.scale.rangeExtent];case"y":return[r.bottom,r.bottom-this.scale.rangeExtent];case"height":return t?[r.bottom,r.bottom-this.scale.rangeExtent]:[r.top+this.scale.rangeExtent,r.top]}if(s==b)switch(this.channel){case"width":case"height":{let e=this._vertices,i=t?Math.max(...e.map((t=>t.y))):Math.min(...e.map((t=>t.y)));return t?[i,i-this.scale.rangeExtent]:[i+this.scale.rangeExtent,i]}case"x":case"y":{let t=et(i.firstVertex,this.scene),e=Math.min(...t.map((t=>t.x)));return[e,e+this.scale.rangeExtent]}}else if(s==v)switch(this.channel){case"x":case"y":{let t=et(i.firstVertex,this.scene),e=Math.max(...t.map((t=>t.y)));return[e,e-this.scale.rangeExtent]}case"height":case"width":{let e=et(i.firstVertex,this.scene),s=t?Math.min(...e.map((t=>t.x))):Math.max(...e.map((t=>t.x)));return t?[s,s+this.scale.rangeExtent]:[s-this.scale.rangeExtent,s]}}}}}function jt(t,e,i){return e.map((e=>[e,n.mean(i,(i=>t(e-i)))]))}function Vt(t){return e=>Math.abs(e/=t)<=1?.75*(1-e*e)/t:0}function Gt(t,e){if("field"in e){let i=e.field;if("value"in e)return t[i]==e.value;if("range"in e)return t[i]>=e.range[0]&&t[i]<=e.range[1];if("values"in e)return e.values.indexOf(t[i])>=0}else if("fields"in e){let i=e.fields[0],s=e.fields[1],n=t[i],r=t[s];switch(e.operator){case"==":return n==r;case">":return n>r;case">=":return n>=r;case"<":return n<r;case"<=":return n<=r}return!1}}class zt{constructor(t,e,i){if(this.url=e,this.id=T.DataTable+pt[T.DataTable]++,this.data=t,this.rawData=JSON.parse(JSON.stringify(t)),this._dateMap=new Map,this._fields=Object.keys(this.data[0]),this._newField=0,i)this._fieldTypes=i;else{this._fieldTypes={};for(let t of this._fields)this._fieldTypes[t]=qt(this.data.map((e=>e[t]))),"year"==t.toLowerCase()&&this._fieldTypes[t]==A.Integer&&(this._fieldTypes[t]=A.Date)}this._validate(this.data,this._fieldTypes),this._fieldSummaries={};for(let t of this._fields)this._fieldSummaries[t]=Wt(this.data.map((e=>e[t])),this._fieldTypes[t]);this._fields.indexOf(h)<0&&this._addField(h,A.String,this.data.map(((t,e)=>"r"+e)))}get name(){return this.url?function(t){var e=t.indexOf("\\")>=0?t.lastIndexOf("\\"):t.lastIndexOf("/"),i=t.substring(e);0!==i.indexOf("\\")&&0!==i.indexOf("/")||(i=i.substring(1));return i}(this.url):this.id}set sourceDataTable(t){this._sourceDataTable=t}get sourceDataTable(){return this._sourceDataTable}getEncodableFields(t){switch(t){case"x":case"y":case"width":case"height":case"radius":case"fillColor":case"strokeColor":return this.numericFields.concat(this.nonNumericFields);case"area":case"strokeWidth":default:return this.numericFields}}toJSON(){let t={};return t.data=this.rawData,t.fieldTypes=this._fieldTypes,t.url=this.url,t.id=this.id,t.sourceDataTable=this._sourceDataTable,t.transform=this._transform,t.dateMap={},t}transformField(t,e,i){let s=this.data.map((i=>e(i[t]))),n=qt(s),r=i||Date.now()+"_field"+this._newField++;return this._addField(r,n,s),r}setValueOrder(t,e){this._fieldSummaries[t].unique=e}_addField(t,e,i){this.data.forEach(((e,s)=>e[t]=i[s])),this._fieldTypes[t]=e,this._fields.push(t),this._fieldSummaries[t]=Wt(i,e)}getFieldType(t){return this._fieldTypes[t]}get fields(){return this._fields}getFieldSummary(t){return this._fieldSummaries[t]}getFieldValues(t){return this.data.map((e=>e[t]))}getUniqueFieldValues(t){return this._fieldSummaries[t].unique}getRowCount(){return this.data.length}hasField(t){return this._fields.indexOf(t)>=0}parseFieldAsDate(t,e){let i=n.timeParse(e);for(let e of this.data){let s=e[t];null==s||null==s?(s="",e[t]=new Date(1899,11,31).getTime()):e[t]=i(s).getTime(),this._dateMap.set(e[t],s)}this._fieldTypes[t]=A.Date,this._fieldSummaries[t]=Wt(this.data.map((e=>e[t])),A.Date)}getRawValue(t,e){return this.getFieldType(t)===A.Date?this._dateMap.get(e).toString():e}static get RowID(){return h}get nonNumericFields(){let t=[];for(let e in this._fieldTypes)this._fieldTypes[e]!=A.Number&&this._fieldTypes[e]!=A.Integer&&e!=zt.RowID&&t.push(e);return t}get numericFields(){let t=[];for(let e in this._fieldTypes)this._fieldTypes[e]!==A.Number&&this._fieldTypes[e]!==A.Integer||e==zt.RowID||t.push(e);return t}getFieldsByType(t){let e=[];for(let i in this._fieldTypes)this._fieldTypes[i]===t&&i!=zt.RowID&&e.push(i);return e}transform(t,e,i){let s=i||{};switch(t){case"kde":return function(t,e,i){let s=e[0],n=t.nonNumericFields,r={};for(let e of t.data){let t=n.map((t=>String(e[t]))).join("_");t in r||(r[t]=n.map((t=>e[t])),r[t].push([])),r[t][r[t].length-1].push(e[s])}let a="min"in i?i.min:t.getFieldSummary(s).min,o="max"in i?i.max:t.getFieldSummary(s).max,h=a,l=[];for(;h<o;)l.push(h),h+=i.interval;l.push(h);let c=[];for(let t in r){let e=r[t].pop(),a=jt(Vt(i.bandwidth),l,e);for(let e of a){let i={};r[t].forEach(((t,e)=>i[n[e]]=t)),i[s]=e[0],i[s+"_density"]=e[1],c.push(i)}}let d={};return n.forEach((e=>d[e]=t.getFieldType(e))),d[s]=A.Number,d[s+"_density"]=A.Number,new zt(c,t.url,d)}(this,e,s);case"bin":return function(t,e,i){let s=e[0],r=t.nonNumericFields,a={};for(let e of t.data){let t=r.map((t=>String(e[t]))).join("_");a.hasOwnProperty(t)||(a[t]=r.map((t=>e[t])),a[t].push([])),a[t][a[t].length-1].push(e[s])}let o=[];for(let t in a){let e=a[t].pop(),i=n.bin()(e);for(let e of i){let i={};a[t].forEach(((t,e)=>i[r[e]]=t)),i.x0=e.x0,i.x1=e.x1,i[s+"_count"]=e.length,o.push(i)}}let h={};r.forEach((e=>h[e]=t.getFieldType(e))),h.x0=A.Number,h.x1=A.Number,h[s+"_count"]=A.Number;let l=new zt(o,t.url,h);return l.sourceDataTable=t,l.transform={type:"bin",args:e},l}(this,e);case"sort":return function(t,e,i){t.data.sort(((t,i)=>function(t,e,i,s){for(let s of i){if(t[s]<e[s])return-1;if(t[s]>e[s])return 1}return 0}(t,i,e))),t.summarize()}(this,e);case"filter":return function(t,e){let i=[];for(let s of t.data){let t=!0;for(let i of e)if(!Gt(s,i)){t=!1;break}t&&i.push(s)}let s=new zt(i,t.url);return s.sourceDataTable=t,s.transform={type:"filter",args:e},s}(this,e)}}summarize(){for(let t of this._fields)this._fieldSummaries[t]=Wt(this.data.map((e=>e[t])),this._fieldTypes[t])}_validate(t,e){for(let i of t)for(let t in e){let s,n=e[t],r=i[t];if(null==i[t]||null==i[t])switch(n){case A.Boolean:s=!1;break;case A.Date:s=new Date(1899,11,31).getTime();break;case A.String:s="";break;default:s=0}else switch(n){case A.Boolean:s=r;break;case A.Date:s=Number.isInteger(r)?new Date(r,0).getTime():new Date(r+"").getTime(),this._dateMap.set(s,r);break;case A.String:s=r.toString();break;default:s=r}i[t]=s}}}function Wt(t,e){var i={};switch(e){case A.Boolean:i.trueCount=t.filter((t=>t)).length,i.falseCount=t.filter((t=>!t)).length;break;case A.Date:i.min=n.min(t),i.max=n.max(t),i.extent=[i.min,i.max],i.unique=[...new Set(t)];break;case A.String:i.unique=[...new Set(t)];break;default:i.min=n.min(t),i.max=n.max(t),i.extent=[i.min,i.max],i.mean=n.mean(t),i.median=n.median(t),i.unique=[...new Set(t)]}return i}var Ut={boolean:function(t){return"true"===t||"false"===t||!0===t||!1===t||"[object Boolean]"==toString.call(t)},integer:function(t){return Ut.number(t)&&(t=+t)==~~t},number:function(t){return!isNaN(+t)&&"[object Date]"!=toString.call(t)},date:function(t){let e=new Date(t);return null!=e&&!isNaN(e)},string:function(t){return!0}};function qt(t){var e=Object.values(A);for(let i=0;i<t.length;i++){let s=t[i];if(null!=s){for(let t=0;t<e.length;t++)Ut[e[t]](s)||(e.splice(t,1),t-=1);if(1==e.length)return e[0]}}return e[0]}class Jt extends q{constructor(t){super(t),this.type=T.PointText,this.attrs.x=0,this.attrs.y=0,"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"),void 0!==t&&("x"in t&&(this.attrs.x=t.x),"y"in t&&(this.attrs.y=t.y),this.attrs.text="text"in t?t.text:"",this.attrs.anchor="anchor"in t?t.anchor:["center","middle"]),this._updateBounds()}copyPropertiesTo(t){t.styles=Object.assign({},this.styles),this._dataScope&&(t._dataScope=this._dataScope.clone()),t.x=this.attrs.x,t.y=this.attrs.y,t.text=this.text,t.anchor=[this.anchor[0],this.anchor[1]]}get bounds(){return this._bounds||this._updateBounds(),this._bounds}get refBounds(){return this.bounds}set text(t){this.attrs.text=t,this._updateBounds()}get text(){return this.attrs.text}_doTranslate(t,e){this.attrs.x+=t,this.attrs.y+=e,this._updateBounds()}_updateBounds(){let t,e,i=function(t,e,i){let s=mt.getContext();s.font=e;let n=s.measureText(t);return n.fontBoundingBoxAscent?{width:n.width,height:n.fontBoundingBoxAscent+n.fontBoundingBoxDescent}:n.actualBoundingBoxAscent?{width:n.width,height:n.actualBoundingBoxAscent+n.actualBoundingBoxDescent}:{width:n.width,height:i}}(this.attrs.text,[this.fontWeight,this.styles.fontSize,this.fontFamily].join(" "),parseFloat(this.fontSize)),s=i.width,n=i.height;switch(this.attrs.anchor[0]){case"left":t=this.attrs.x;break;case"right":t=this.attrs.x-s;break;case"center":t=this.attrs.x-s/2;break;default:t=this.attrs.x}switch(this.attrs.anchor[1]){case"top":e=this.attrs.y;break;case"bottom":e=this.attrs.y-n;break;case"middle":e=this.attrs.y-n/2}this._bounds=new a(t,e,s,n)}get center(){return{x:this.bounds.left+this.bounds.width/2,y:this.bounds.top+this.bounds.height/2}}get x(){return this.attrs.x}set x(t){this.attrs.x=t,this._updateBounds()}get y(){return this.attrs.y}set y(t){this.attrs.y=t,this._updateBounds()}get anchor(){return this.attrs.anchor}set anchor(t){this.attrs.anchor=t,this._updateBounds()}get fontSize(){return parseFloat(this.styles.fontSize)}set fontSize(t){this.styles.fontSize="number"==typeof t?t+"px":t,this._updateBounds()}get fontWeight(){return this.styles.fontWeight}set fontWeight(t){this.styles.fontWeight=t,this._updateBounds()}get fontFamily(){return this.styles.fontFamily}set fontFamily(t){this.styles.fontFamily=t,this._updateBounds()}get fillColor(){return this.styles.fillColor}set fillColor(t){this.styles.fillColor=t}}class Yt extends St{constructor(t){super(),this.type=T.Axis,this.id=this.type+pt[this.type]++,this._strokeColor="strokeColor"in t?t.strokeColor:"#555",this._textColor="textColor"in t?t.textColor:"#555",this._fontSize="fontSize"in t?t.fontSize:"12px",this._tickOffset="tickOffset"in t?t.tickOffset:0,this._tickSize="tickSize"in t?t.tickSize:5,this._tickAnchor=t.tickAnchor?t.tickAnchor:"middle",this._tickVisible=!("tickVisible"in t)||t.tickVisible,this._pathVisible=!("pathVisible"in t)||t.pathVisible,this._labelOffset="labelOffset"in t?t.labelOffset:15,this._labelFormat="labelFormat"in t?t.labelFormat:"",this._titleOffset="titleOffset"in t?t.titleOffset:40,"titleAnchor"in t?this._titleAnchor=t.titleAnchor:"x"==this.channel||"width"==this.channel?this._titleAnchor="top"==this._orientation?["center","bottom"]:["center","top"]:this._titleAnchor="left"==this._orientation?["right","middle"]:["left","middle"],this._rotateYTitle=!("rotateTitle"in t&&!t.rotateTitle),this._titlePosition=t.titlePosition,this._labelRotation="labelRotation"in t?t.labelRotation:0}toJSON(){let t={args:{}};return t.type=this.type,t.id=this.id,t.field=this._field,t.channel=this._channel,"args"in t||(t.args={}),t.args.orientation=this._orientation,t.args.strokeColor=this._strokeColor,t.args.textColor=this._textColor,t.args.tickOffset=this._tickOffset,t.args.tickSize=this._tickSize,t.args.tickAnchor=this._tickAnchor,t.args.tickVisible=this._tickVisible,t.args.pathVisible=this._pathVisible,t.args.labelOffset=this._labelOffset,t.args.labelFormat=this._labelFormat,this._labelRotation&&(t.args.labelRotation=this._labelRotation),t.args.showTitle=this._showTitle,t.args.tickValues=this._tickValues,t.args.titleAnchor=this._titleAnchor,t.args.titleOffset=this._titleOffset,t.args.titlePosition=this._titlePosition,t.args.rotateTitle=this._rotateYTitle,t}get field(){return this._field}get channel(){return this._channel}get orientation(){return this._orientation}set orientation(t){this._orientation=t,this.reposition()}get pathX(){if("y"==this.channel||"height"==this.channel){if(void 0!==this._position)return this._position;if(this._path)return this._path.vertices[0].x;if(this._rules&&this._rules.firstChild)return this._rules.firstChild.vertices[0].x}}set pathX(t){"y"!=this.channel&&"height"!=this.channel||(this._posArg=t),this.reposition()}get pathPosition(){return"x"==this.channel||"width"==this.channel?this.pathY:this.pathX}set pathPosition(t){"x"==this.channel||"width"==this.channel?this.pathY=t:"y"!=this.channel&&"height"!=this.channel||(this.pathX=t)}get pathY(){if("x"==this.channel||"width"==this.channel){if(void 0!==this._position)return this._position;if(this._path)return this._path.vertices[0].y;if(this._rules&&this._rules.firstChild)return this._rules.firstChild.vertices[0].y}}set pathY(t){"x"!=this.channel&&"width"!=this.channel||(this._posArg=t),this.reposition()}get tickOffset(){return this._tickOffset}set tickOffset(t){this._tickOffset=t,this._positionTicks()}get titleOffset(){return this._titleOffset}set titleOffset(t){this._titleOffset=t}get tickSize(){return this._tickSize}set tickSize(t){this._tickSize=t,this._positionTicks()}set tickValues(t){this._tickValues=t,this._generateTicks(),this._positionTicks()}get tickValues(){return this._tickValues}set labelValues(t){this._labelValues=t,this._generateLabels(),this._positionLabels()}get labelValues(){return this._labelValues}get tickAnchor(){return this._tickAnchor}set tickAnchor(t){this._tickAnchor=t}get tickVisible(){return this._tickVisible}set tickVisible(t){this._tickVisible=t;for(let e of this._ticks.children)e.visibility=t?"visible":"hidden"}get pathVisible(){return this._pathVisible}set pathVisible(t){this._pathVisible=t;let e=[];this._path&&e.push(this._path),this._rules&&this._rules.children.forEach((t=>e.push(t)));for(let i of e)i.visibility=t?"visible":"hidden"}get labelOffset(){return this._labelOffset}set labelOffset(t){this._labelOffset=t,this._positionLabels()}get labelFormat(){return this._labelFormat}set labelFormat(t){this._labelFormat=t,this._generateLabels(),this._positionLabels()}get labelRotation(){return this._labelRotation}set labelRotation(t){if(this._labelRotation=t,this._labels&&this._labels.children){let e="bottom"==this._orientation?["center","top"]:["center","bottom"];if(t)for(let t of this._labels.children)t._rotate=[this._labelRotation,t.x,t.y],t.anchor=["right",e[1]];else for(let t of this._labels.children)t._rotate=void 0}}get showTitle(){return this._showTitle}set showTitle(t){this._showTitle=t,this._title||(this._generateTitle(),this._positionTitle()),this._title.visibility=t?"visible":"hidden"}get titleAnchor(){return this._titleAnchor}set titleAnchor(t){this._titleAnchor=t}get titlePosition(){return this._titlePosition}set titlePosition(t){this._titlePosition=t}get rotateTitle(){return this._rotateYTitle}set rotateTitle(t){this._rotateYTitle=t}get title(){return this._titleText}set title(t){this._titleText=t}get includeZero(){return!!this.encoding&&this.encoding.scale.includeZero}set includeZero(t){this.encoding&&(this.encoding.scale.includeZero=t)}_generatePath(){}_generateTicks(){}_generateLabels(){}_generateTitle(){this._title=new Jt({text:this._titleText,fillColor:this._textColor,fontWeight:"bold"}),this._title.id=this.id+"-title",this.addChild(this._title)}_positionPath(){}_positionTicks(){}_positionLabels(){}_positionTitle(){}matches(t){}reposition(){this._positionPath(),this._positionTicks(),this._positionLabels(),this._showTitle&&this._positionTitle(),"radialDistance"===this._channel&&this._rotate&&(this._rotate=[this._rotate[0],this._item.parent.x,this._item.parent.y]),this._updateBounds()}}class Ht extends Yt{constructor(t,e,i){super(i),this.encoding=t,this._field=this.encoding.field,this._channel=this.encoding.channel,this._orientation="orientation"in i?i.orientation:"x"===this._channel||"width"==this._channel?"bottom":"left",this._posArg="x"==this._channel||"width"==this._channel?i.pathY:i.pathX,this._position=this._posArg,this._titleText="title"in i?i.title:this.encoding.field,this._item=e,this._ticks=new St,this._ticks.id=this.id+"ticks",this.addChild(this._ticks),this._labels=new St,this._labels.id=this.id+"labels",this.addChild(this._labels),"radialDistance"===this._channel&&"rotation"in i&&(this._rotate=[-i.rotation,this._item.parent.x,this._item.parent.y]),this._showTitle=!("showTitle"in i)||i.showTitle,this._determineAxisFlip(),this._generatePath(),this._positionPath(),this._showTitle&&this._generateTitle(),this._showTitle&&this._positionTitle()}autoUpdateTicks(){let t=this.encoding._inferTickValues();this.tickValues=t,this.labelValues=t}_updateBounds(){this._bounds=this._path.bounds,this._ticks.children.length>0&&(this._bounds=this._bounds.union(this._ticks.bounds)),this._labels.children.length>0&&(this._bounds=this._bounds.union(this._labels.bounds)),this._title&&(this._bounds=this._bounds.union(this._title.bounds))}toJSON(){let t=super.toJSON();return t.args.item=this._item.id,"time"===this.encoding.scale.type&&(t.args.isDate=!0),this._rotate&&(t.args.rotation=this._rotate[0]),"x"==this._channel||"width"==this._channel?t.args.pathY=this._posArg:t.args.pathX=this._posArg,t}get ticks(){return this._ticks}get labels(){return this._labels}get path(){return this._path}set strokeColor(t){this._strokeColor=t;for(let e of this._ticks.children)e.strokeColor=t;this._path.strokeColor=t}get strokeColor(){return this._strokeColor}set textColor(t){this._textColor=t;for(let e of this._labels.children)e.fillColor=t;this._title&&(this._title.fillColor=t)}get textColor(){return this._textColor}_generatePath(){this._path=new Z({strokeColor:this._strokeColor}),this._pathVisible||(this._path.visibility="hidden"),this._path.type=T.Line,this._path.id=this.id+"path",this.addChild(this._path)}_generateTicks(){this._ticks.removeAll();for(let t=0;t<this._tickValues.length;t++){let e=new Z({strokeColor:this._strokeColor});this._tickVisible||(e.visibility="hidden"),e.type=T.Line,e.id=this.id+"tick"+t,this._ticks.addChild(e)}}_generateLabels(){let t;switch(this._labels.removeAll(),this.encoding.datatable.getFieldType(this.encoding.field)){case A.Date:t=n.timeFormat(this._labelFormat);break;case A.String:t=function(t){return t};break;default:t=n.format(this._labelFormat)}for(let[e,i]of this._labelValues.entries()){let s=new Jt({text:t(i),fontSize:this._fontSize,fillColor:this._textColor});s.id=this.id+"label"+e,this._labels.addChild(s)}}_positionPath(){this._range=this.encoding.getScaleRange(this._item),void 0===this._posArg?this._position=this._computePosition():this._position=this._posArg;let t=[];if("x"==this._channel||"radialDistance"==this._channel||"width"==this._channel){let e=this._ticks.children.map((t=>t.vertices[0].x));t.push([Math.min(...e.concat(this._range)),this._position]),t.push([Math.max(...e.concat(this._range)),this._position])}else if("y"==this._channel||"height"==this._channel){let e=this._ticks.children.map((t=>t.vertices[0].y));t.push([this._position,Math.min(...e.concat(this._range))]),t.push([this._position,Math.max(...e.concat(this._range))])}this._path._setVertices(t),this._path._updateBounds(),this._showTitle&&this._title&&this._positionTitle(),this._updateBounds()}_isAlignedLeft(t){switch(t.type){case y.Stack:case y.Grid:return t.horzCellAlignment===C.Left;default:return!0}}_isAlignedBottom(t){switch(t.type){case y.Stack:case y.Grid:return t.vertCellAlignment===C.Bottom;default:return!0}}_determineAxisFlip(){if("x"==this._channel||"radialDistance"==this._channel||"width"==this._channel){if("width"==this._channel){let t=bt(this._item)?bt(this._item).layout:it(this._item);if(t)this._flip=!this._isAlignedLeft(t);else if("area"==this._item.type){let t=this._item.baseline==C.Left||this._item.baseline==C.Center||this._item.baseline==C.Middle||null==this._item.baseline;this._flip=!t}}}else if(("y"==this._channel||"height"==this._channel)&&"height"==this._channel){let t=bt(this._item)?bt(this._item).layout:it(this._item);if(t)this._flip=!this._isAlignedBottom(t);else if("area"==this._item.type){let t=this._item.baseline==C.Bottom||this._item.baseline==C.Center||this._item.baseline==C.Middle||null==this._item.baseline;this._flip=!t}}}_positionLabels(){if(void 0===this._posArg?this._position=this._computePosition():this._position=this._posArg,"x"==this._channel||"radialDistance"==this._channel||"width"==this._channel){let t="bottom"==this._orientation?this._tickSize:-this._tickSize,e="bottom"==this._orientation?["center","top"]:["center","bottom"];if(this._flip)for(let[i,s]of this._labels.children.entries())s.x=this._range[1]-this.encoding.scale.map(this._labelValues[i]),s.y=this._position+t,s.anchor=e,this._labelRotation&&(s._rotate=[this._labelRotation,s.x,s.y],s.anchor=["right",e[1]]);else if(this.encoding.scale.isFlipped)for(let[i,s]of this._labels.children.entries())s.x=this._range[0]+this.encoding.scale.map(this._labelValues[i]),s.y=this._position+t,s.anchor=e,this._labelRotation&&(s._rotate=[this._labelRotation,s.x,s.y],s.anchor=["right",e[1]]);else for(let[i,s]of this._labels.children.entries())s.x=this._range[0]+this.encoding.scale.map(this._labelValues[i])-this.encoding.scale.range[0],s.y=this._position+t,s.anchor=e,this._labelRotation&&(s._rotate=[this._labelRotation,s.x,s.y],s.anchor=["right",e[1]])}else if("y"==this._channel||"height"==this._channel){let t="left"==this._orientation?-this._tickSize:this._tickSize,e="left"==this._orientation?["right","middle"]:["left","middle"];if(this._flip)for(let[i,s]of this._labels.children.entries())s.x=this._position+t,s.y=this._range[1]+this.encoding.scale.map(this._labelValues[i]),s.anchor=e;else if(this.encoding.scale.isFlipped)for(let[i,s]of this._labels.children.entries())s.x=this._position+t,s.y=this._range[1]-this.encoding.scale.map(this._labelValues[i])+this.encoding.scale.range[1],s.anchor=e;else for(let[i,s]of this._labels.children.entries())s.x=this._position+t,s.y=this._range[0]-this.encoding.scale.map(this._labelValues[i])+this.encoding.scale.range[0],s.anchor=e}this._labels._updateBounds(),this._updateBounds()}_computePosition(){let t;if("vertex"===this._item.type&&!this._item.parent.closed){let t=et(this._item,this._item.parent.getScene());if("x"===this._channel&&1==Et(t.map((t=>t.bounds.middle))).length)return this._item.bounds.middle;if("y"===this._channel&&1==Et(t.map((t=>t.bounds.center))).length)return this._item.bounds.center;if("radialDistance"===this._channel)return this._item.parent.y}if(this._item.type==T.Area&&(t=nt(this._item)),void 0===t){let e=bt(this._item);void 0===e&&(e=vt(this._item)),t=e.bounds}return"x"===this._channel||"width"===this._channel?"top"==this._orientation?t.top-this._tickSize:t.bottom+this._tickSize:"y"===this._channel||"height"===this._channel?"left"==this._orientation?t.left-this._tickSize:t.right+this._tickSize:"radialDistance"===this._channel?this._item.parent.y:void 0}_positionTicks(){if(void 0===this._posArg?this._position=this._computePosition():this._position=this._posArg,this._range=this.encoding.getScaleRange(this._item),"x"==this._channel||"radialDistance"==this._channel||"width"==this._channel){let t="bottom"==this._orientation?this._tickSize:-this._tickSize;if(this._flip)for(let[e,i]of this._ticks.children.entries())i._setVertices([[this._range[1]-this.encoding.scale.map(this._tickValues[e]),this._position],[this._range[1]-this.encoding.scale.map(this._tickValues[e]),this._position+t]]),i._updateBounds();else if(this.encoding.scale.isFlipped)for(let[e,i]of this._ticks.children.entries())i._setVertices([[this._range[0]+this.encoding.scale.map(this._tickValues[e]),this._position],[this._range[0]+this.encoding.scale.map(this._tickValues[e]),this._position+t]]),i._updateBounds();else for(let[e,i]of this._ticks.children.entries())i._setVertices([[this._range[0]+this.encoding.scale.map(this._tickValues[e])-this.encoding.scale.range[0],this._position],[this._range[0]+this.encoding.scale.map(this._tickValues[e])-this.encoding.scale.range[0],this._position+t]]),i._updateBounds()}else if("y"==this._channel||"height"==this._channel){let t="left"==this._orientation?-this._tickSize:this._tickSize;if(this._flip)for(let[e,i]of this._ticks.children.entries())i._setVertices([[this._position+t,this._range[1]+this.encoding.scale.map(this._tickValues[e])],[this._position,this._range[1]+this.encoding.scale.map(this._tickValues[e])]]),i._updateBounds();else if(this.encoding.scale.isFlipped)for(let[e,i]of this._ticks.children.entries()){let s=this._range[1]-this.encoding.scale.map(this._tickValues[e])+this.encoding.scale.range[1];i._setVertices([[this._position+t,s],[this._position,s]]),i._updateBounds()}else for(let[e,i]of this._ticks.children.entries())i._setVertices([[this._position+t,this._range[0]-this.encoding.scale.map(this._tickValues[e])+this.encoding.scale.range[0]],[this._position,this._range[0]-this.encoding.scale.map(this._tickValues[e])+this.encoding.scale.range[0]]]),i._updateBounds()}this._positionPath(),this._ticks._updateBounds(),this._updateBounds()}_positionTitle(){let t=this._path.bounds;this._title.achor=this._titleAnchor,this._titlePosition?(this._title.x=this._titlePosition[0],this._title.y=this._titlePosition[1],"y"!=this._channel&&"height"!=this._channel||this._rotateYTitle&&(this._title._rotate="left"==this._orientation?[-90,this._title.bounds.x,this._title.bounds.y]:[90,this._title.bounds.x,this._title.bounds.y])):"x"==this._channel||"width"==this._channel?(this._title.x=t.x,this._title.y="top"==this._orientation?t.top-this._titleOffset:t.bottom+this._titleOffset):(this._title.x="left"==this._orientation?t.left-this._titleOffset:t.right+this._titleOffset,this._title.y=t.y,this._rotateYTitle&&(this._title._rotate="left"==this._orientation?[-90,this._title.bounds.x,this._title.bounds.y]:[90,this._title.bounds.x,this._title.bounds.y])),this._title._updateBounds(),this._updateBounds()}matches(t){let e=at(t).split("_")[0],i=this.encoding.scale.encodings;for(let t of i){if(at(t.anyItem).split("_")[0]===e)return!0}return!1}get isFlipped(){return!!this._flip||!!this.encoding.scale.isFlipped}}class $t extends Yt{constructor(t,e,i,s,n){super(n),this._channel=i,this._orientation="orientation"in n?n.orientation:"x"===this._channel||"width"==this._channel?"bottom":"left",this._posArg="x"==this._channel||"width"==this._channel?n.pathY:n.pathX,this._item=t[0],this._items=t,this._mlayout=e,this._field=s,this._titleText="title"in n?n.title:this._field,this._showTitle="showTitle"in n&&n.showTitle,this._ticks=new St,this._ticks.id=this.id+"ticks",this.addChild(this._ticks),this._labels=new St,this._labels.id=this.id+"labels",this.addChild(this._labels),this._rules=new St,this._rules.id=this.id+"paths",this.addChild(this._rules),this._generatePath(),this._generateTicks(),this._generateLabels(),this._showTitle&&this._generateTitle(),this._positionPath(),this._positionTicks(),this._positionLabels(),this._showTitle&&this._positionTitle()}toJSON(){let t=super.toJSON();return t.args.item=this._item.id,"x"==this._channel||"width"==this._channel?t.args.pathY=this._posArg:t.args.pathX=this._posArg,this.classId&&(t.classId=this.classId),t}set strokeColor(t){this._strokeColor=t;for(let e of this._ticks.children)e.strokeColor=t;for(let e of this._rules.children)e.strokeColor=t}get strokeColor(){return this._strokeColor}set textColor(t){this._textColor=t;for(let e of this._labels.children)e.fillColor=t;this._title&&(this._title.fillColor=t)}get textColor(){return this._textColor}_updateBounds(){this._bounds=this._rules.bounds.clone(),this._bounds=this._bounds.union(this._ticks.bounds),this._bounds=this._bounds.union(this._labels.bounds),this._showTitle&&(this._bounds=this._bounds.union(this._title.bounds))}_generatePath(){if(this._rules.removeAll(),this._mlayout.type==y.Grid){let t="x"==this._channel?this._mlayout.numRows:this._mlayout.numCols;for(let e=0;e<t;e++){let t=new Z({strokeColor:this._strokeColor});this._pathVisible||(t.visibility="hidden"),t.type=T.Line,t.id=this.id+"rule"+e,this._rules.addChild(t)}}else if(this._mlayout.type===y.Stack){let t=new Z({strokeColor:this._strokeColor});this._pathVisible||(t.visibility="hidden"),t.type=T.Line,t.id=this.id+"rule",this._rules.addChild(t)}}_generateTicks(){this._ticks.removeAll();for(let t=0;t<this._mlayout.group.children.length;t++){let e=new Z({strokeColor:this._strokeColor});this._tickVisible||(e.visibility="hidden"),e.type=T.Line,e.id=this.id+"tick"+t,this._ticks.addChild(e)}}_generateLabels(){let t;switch(this._labels.removeAll(),this._item.dataScope.getFieldType(this._field)){case A.Date:t=n.timeFormat(this._labelFormat);break;case A.String:t=function(t){return t};break;default:t=n.format(this._labelFormat)}let e=this._mlayout.cellBounds;for(let i=0;i<e.length&&!(i>=this._mlayout.group.children.length);i++){let e=this._mlayout.group.children[i],s=new Jt({fillColor:this._textColor,fontSize:this._fontSize,text:t(e.dataScope.getFieldValue(this._field))});s.id=this.id+"label"+i,this._labels.addChild(s)}}_positionPath(){if(this._mlayout.type==y.Grid){let t=this._mlayout.cellBounds,e="x"==this._channel?this._mlayout.numRows:this._mlayout.numCols;if("x"==this._channel){let i=t[0].left,s=this._mlayout.numCols;for(let n=0;n<e;n++)this._rules.children[n]._setVertices([[i,this._posArg?t[n*s][this._orientation]+this._posArg-t[0][this._orientation]:t[n*s][this._orientation]],[i+t[0].width*s+this._mlayout.colGap*(s-1),this._posArg?t[n*s][this._orientation]+this._posArg-t[0][this._orientation]:t[n*s][this._orientation]]])}else{let i=t[0].top,s=this._mlayout.numRows;for(let n=0;n<e;n++)this._rules.children[n]._setVertices([[this._posArg?t[n*s][this._orientation]+this._posArg-t[0][this._orientation]:this._mlayout.group.bounds[this._orientation],i],[this._posArg?t[n*s][this._orientation]+this._posArg-t[0][this._orientation]:this._mlayout.group.bounds[this._orientation],i+t[0].height*s+this._mlayout.rowGap*(s-1)]])}}else if(this._mlayout.type===y.Stack){let t=this._mlayout.group.bounds;"x"==this._channel?this._rules.children[0]._setVertices([[t.left,this._posArg?this._posArg:t[this._orientation]],[t.right,this._posArg?this._posArg:t[this._orientation]]]):this._rules.children[0]._setVertices([[this._posArg?this._posArg:t[this._orientation],t.top],[this._posArg?this._posArg:t[this._orientation],t.bottom]])}this._rules.children.forEach((t=>t._updateBounds())),this._rules._updateBounds(),this._updateBounds()}_positionTicks(){let t=this._mlayout.cellBounds;if("x"==this._channel){let e="bottom"==this._orientation?1:-1;for(let[i,s]of this._ticks.children.entries()){let n=this._posArg?t[i][this._orientation]+this._posArg-t[0][this._orientation]+this._tickOffset*e:t[i][this._orientation]+this._tickOffset*e;s._setVertices([[t[i].x,n],[t[i].x,n+e*this._tickSize]]),s._updateBounds()}}else if("y"==this._channel){let e="left"==this._orientation?-1:1;for(let[i,s]of this._ticks.children.entries()){let n=this._posArg?t[i][this._orientation]+this._posArg-t[0][this._orientation]+this._tickOffset*e:this._mlayout.group.bounds[this._orientation]+this._tickOffset*e,r="middle"==this._tickAnchor?t[i].y:t[i][this._tickAnchor];s._setVertices([[n,r],[n+e*this._tickSize,r]]),s._updateBounds()}}this._ticks._updateBounds(),this._updateBounds()}_positionLabels(){let t=this._mlayout.cellBounds;if("x"==this._channel){let e="bottom"==this._orientation?["center","top"]:["center","bottom"],i="bottom"==this._orientation?this._labelOffset:-this._labelOffset;for(let[s,n]of this._labels.children.entries())n.x=t[s].x,n.y=this._posArg?t[s][this._orientation]+this._posArg-t[0][this._orientation]+i:t[s][this._orientation]+i,n.anchor=e,this._labelRotation&&(n._rotate=[this._labelRotation,n.x,n.y],n.anchor=["right",e[1]])}else if("y"==this._channel){let e="left"==this._orientation?["right","middle"]:["left","middle"],i="left"==this._orientation?-this._labelOffset:this._labelOffset;for(let[s,n]of this._labels.children.entries())n.x=this._posArg?t[s][this._orientation]+this._posArg-t[0][this._orientation]+i:this._mlayout.group.bounds[this._orientation]+i,n.y="middle"==this._tickAnchor?t[s].y:t[s][this._tickAnchor],n.anchor=e,this._labelRotation&&(n._rotate=[this._labelRotation,n.x,n.y])}this._labels._updateBounds(),this._updateBounds()}_positionTitle(){let t=this._rules.bounds;this._title.achor=this._titleAnchor,this._titlePosition?(this._title.x=this._titlePosition[0],this._title.y=this._titlePosition[1],"y"!=this._channel&&"height"!=this._channel||this._rotateYTitle&&(this._title._rotate="left"==this._orientation?[-90,this._title.bounds.x,this._title.bounds.y]:[90,this._title.bounds.x,this._title.bounds.y])):"x"==this._channel?(this._title.x=t.x,this._titleOffset=this._labels.bounds.height+this._labelOffset+15,this._title.y="top"==this._orientation?t.top-this._titleOffset:t.bottom+this._titleOffset):(this._titleOffset=this._labels.bounds.width+this._labelOffset+15,this._title.x="left"==this._orientation?t.left-this._titleOffset:t.right+this._titleOffset,this._title.y=t.y,this._rotateYTitle&&(this._title._rotate="left"==this._orientation?[-90,this._title.bounds.x,this._title.bounds.y]:[90,this._title.bounds.x,this._title.bounds.y])),this._title._updateBounds(),this._updateBounds()}matches(t){return at(this._item).split("_")[0]===at(t).split("_")[0]}}class Zt extends St{constructor(t,e){super(),this.type=T.Legend,this.id=this.type+pt[this.type]++,this.encoding=t,this._textColor="textColor"in e?e.textColor:"#555",this._strokeColor="strokeColor"in e?e.strokeColor:"#555",this._fontSize="fontSize"in e?e.fontSize:"12px",this._x="x"in e?e.x:0,this._y="y"in e?e.y:0,this._showTitle=!("showTitle"in e)||e.showTitle,"numCols"in e||"numRows"in e?(this._numCols=e.numCols,this._numRows=e.numRows):this._numCols=1,this._orientation="orientation"in e?e.orientation:v,this._initialize()}toJSON(){let t=super.toJSON();return"args"in t||(t.args={}),t.args.textColor=this._textColor,t.channel=this.encoding.channel,t.field=this.encoding.field,t.args.strokeColor=this._strokeColor,t.args.x=this._x,t.args.y=this._y,t.args.orientation=this._orientation,t}get field(){return this.encoding.field}get channel(){return this.encoding.channel}get fieldType(){return this.encoding.datatable.getFieldType(this.field)}_initialize(){let t=this.encoding.scene,e=this.encoding.field;switch(this.encoding.datatable.getFieldType(e)){case A.String:this._createCategoricalColorLegend(t,e);break;case A.Date:case A.Number:case A.Integer:this._createNumericalColorLegend(t,e)}this._updateBounds()}_createNumericalColorLegend(t,e){let i,s,n;if(this._orientation==v?(i=15,s=300):(i=300,s=15),this._showTitle){let s=t.mark("text",{fillColor:this._textColor,text:e,x:this._x+i/2,y:this._y,anchor:["center","middle"]});this.addChild(s),n=20}else n=0;let r,a=t.mark("rect",{top:this._y+n,left:this._x,width:i,height:s,strokeWidth:0,opacity:this.encoding.anyItem.opacity}),o=[Math.min(...this.encoding.data),Math.max(...this.encoding.data)],h=this.encoding.scale.mapping,l=[],c=[];if(h){let e=Object.keys(h).map((t=>parseFloat(t))).sort(((t,e)=>t-e));this._orientation==v?(r=new U({x1:0,y1:100,x2:0,y2:0}),e.forEach((e=>{let a=(e-o[0])/(o[1]-o[0]);r.addStop(100*a,h[e],1);let d=t.mark("line",{x1:this._x+i,x2:this._x+i+5,y1:this._y+s-a*s+n,y2:this._y+s-a*s+n,strokeColor:this._strokeColor});c.push(d);let u=t.mark("text",{fillColor:this._textColor,text:e.toFixed(0),x:this._x+i+5+5,y:this._y+s-a*s+n,anchor:["left","middle"]});l.push(u)}))):(r=new U({x1:0,y1:0,x2:100,y2:0}),e.forEach((e=>{let a=(e-o[0])/(o[1]-o[0]);r.addStop(100*a,h[e],1);let d=t.mark("line",{x1:this._x+a*i,x2:this._x+a*i,y1:this._y+20-5+n,y2:this._y+s+5+n,strokeColor:this._strokeColor});c.push(d);let u=t.mark("text",{fillColor:this._textColor,text:e.toFixed(0),x:this._x+a*i,y:this._y+s+5+n,anchor:["center","top"]});l.push(u)})))}else{let a=this.encoding.scale.domain,o=this.encoding.datatable,h=o.getFieldType(e),d=[],u=h===A.Date?o.getUniqueFieldValues(e):Et(this.encoding.data);if(u.length<=10)d=u,d.sort(((t,e)=>t-e));else if(h===A.Date){u.sort(((t,e)=>t-e));for(let t=0;t<u.length;t+=Math.ceil(u.length/10))d.push(u[t])}else{let t=(a[1]-a[0])/9;for(let e=0;e<10;e++)d.push(a[0]+e*t);let e=0;for(;t<1;)t*=10,e++;d=d.map((t=>t.toFixed(e)))}this._orientation==v?(r=new U({x1:0,y1:100,x2:0,y2:0}),d.forEach((d=>{let u=(d-a[0])/(a[1]-a[0]);r.addStop(100*u,this.encoding.scale.map(d),1);let f=t.mark("line",{x1:this._x+i,x2:this._x+i+5,y1:this._y+s-u*s+n,y2:this._y+s-u*s+n,strokeColor:this._strokeColor});c.push(f);let p=t.mark("text",{fillColor:this._textColor,text:h===A.Date?o.getRawValue(e,d):d,x:this._x+i+5+5,y:this._y+s-u*s+n,anchor:["left","middle"]});l.push(p)}))):(r=new U({x1:0,y1:0,x2:100,y2:0}),d.forEach((d=>{let u=(d-a[0])/(a[1]-a[0]);r.addStop(100*u,this.encoding.scale.map(d),1);let f=t.mark("line",{x1:this._x+u*i,x2:this._x+u*i,y1:this._y+s+n,y2:this._y+s+5+n,strokeColor:this._strokeColor});c.push(f);let p=t.mark("text",{fillColor:this._textColor,text:h===A.Date?o.getRawValue(e,d):d,x:this._x+u*i,y:this._y+s+5+n,anchor:["center","top"]});l.push(p)})))}a.styles.fillColor=r,this.addChild(a);for(let t of l)this.addChild(t);for(let t of c)this.addChild(t)}get textColor(){return this._textColor}set textColor(t){this._textColor=t,this.setTextColor(this)}get orientation(){return this._orientation}set orientation(t){this._orientation=t,this.removeAll(),this._initialize()}setTextColor(t){if(t.children&&0!==t.children.length)for(let e of t.children)e.type===T.PointText?e.fillColor=this._textColor:e.children&&e.children.length>0&&this.setTextColor(e)}_createCategoricalColorLegend(t,e){let i=0;this._showTitle&&(this.addChild(new Jt({fillColor:this._textColor,fontSize:this._fontSize,text:e,x:this._x,y:this._y,anchor:["left","top"]})),i=parseFloat(this._fontSize)+5);let s=t.mark("rect",{top:this._y+2+i,left:this._x,width:10,height:10,strokeWidth:0,opacity:this.encoding.anyItem.opacity}),n=t.mark("text",{fillColor:this._textColor,fontSize:this._fontSize,x:this._x+20,y:this._y+i,anchor:["left","top"]}),r=t.glyph(s,n),a=this.encoding.scale,o=new zt(a.domain.map((t=>({category:t,value:a.map(t)})))),h=t.repeat(r,o);t.encode(n,{channel:"text",field:"category",_remember:!1}),t.encode(s,{channel:"fillColor",field:"category",_remember:!1,scale:a}),h.layout=Hc("grid",{numCols:this._numCols,numRows:this._numRows}),this.addChild(h)}pathHitTest(t,e){let i=ct(this);for(let s=i.length-1;s>=0;s--){let n=i[s];if(ft(n)&&n.contains(t,e))return n}return null}matches(t){let e=at(t).split("_")[0],i=this.encoding.scale.encodings;for(let t of i){if(at(t.anyItem).split("_")[0]===e)return!0}return!1}}class Kt extends St{constructor(t){if(super(),this.type=T.Glyph,this._id=this.type+pt[this.type]++,t)for(let e of t)this.addChild(e)}duplicate(){let t=this.getScene().glyph();for(let e of this.children)t.addChild(e.duplicate());return t.classId=this.classId,this._dataScope&&(t.dataScope=this._dataScope.clone()),t}}class Xt extends Z{constructor(t){super(t),this.type=T.Area,this.closed=!0,this._orientation="orientation"in t?t.orientation:void 0,this._baseline="baseline"in t?t.baseline:void 0,t&&"vertices"in t&&this.segments.push(new $(this.vertices[this.vertices.length-1],this.vertices[0],this,this.segmentCounter++))}get baseline(){return this._baseline}set baseline(t){this._baseline=t}get orientation(){return this._orientation}set orientation(t){this._orientation=t}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(t){super.copyPropertiesTo(t),t._baseline=this._baseline}resizeArea(t,e){let i=this.vertices[this.vertices.length/2].x,s=this.vertices[this.vertices.length/2].y,n=this.width,r=this.height;for(let a of this.vertices)a.x=i+t/n*(a.x-i),a.y=s+e/r*(a.y-s);this._updateBounds()}getSVGPathData(){return super.getSVGPathData()+" z"}}class Qt extends Z{constructor(t){super(t),this.type=T.Ring,this.closed=!0,this._x="x"in t?t.x:0,this._y="y"in t?t.y:0,this._innerRadius="innerRadius"in t?t.innerRadius:100,this._outerRadius="outerRadius"in t?t.outerRadius:200}get innerRadius(){return this._innerRadius}set innerRadius(t){this._innerRadius=t}get outerRadius(){return this._outerRadius}set outerRadius(t){this._outerRadius=t,this._updateBounds()}get x(){return this._x}get y(){return this._y}get center(){return new Y(this._x,this._y)}set x(t){this._x=t,this._updateBounds()}set y(t){this._y=t,this._updateBounds()}get thickness(){return this._outerRadius-this._innerRadius}_doTranslate(t,e){this._x+=t,this._y+=e,this._updateBounds()}_updateBounds(){this._bounds=new a(this._x-this._outerRadius,this._y-this._outerRadius,2*this._outerRadius,2*this._outerRadius)}copyPropertiesTo(t){super.copyPropertiesTo(t),t._x=this._x,t._y=this._y,t._innerRadius=this._innerRadius,t._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 te extends Z{constructor(t){super(t),this.type=T.Polygon,this.closed=!0,"x"in t&&(this._x=t.x),"y"in t&&(this._y=t.y),"radius"in t&&(this._radius=t.radius)}get radius(){return this._radius}get x(){return this._x}get y(){return this._y}get center(){return new Y(this._x,this._y)}set x(t){this._x=t,this._updateBounds()}set y(t){this._y=t,this._updateBounds()}set radius(t){this._radius=t,this._updateBounds()}copyPropertiesTo(t){super.copyPropertiesTo(t),t._x=this._x,t._y=this._y,t._radius=this._radius}_doTranslate(t,e){this._x+=t,this._y+=e,super._doTranslate(t,e)}}class ee{constructor(t,e){this.direction=e,this.items=t,this.type=S,this.id=this.type+"_"+[...new Set(this.items.map((t=>t.classId)))].join("_")}apply(){let t,e=this.direction;this.direction==C.Top||this.direction==C.Left?t=Math.min(...this.items.map((t=>t.bounds[e]))):this.direction==C.Bottom||this.direction==C.Right?t=Math.max(...this.items.map((t=>t.bounds[e]))):this.direction!=C.Center&&this.direction!=C.Middle||(t=n.mean(this.items.map((t=>t.bounds[e]))));let i=this.items.map((i=>t-i.bounds[e])),s=e==C.TOP||e==C.Middle||e==C.Bottom?"y":"x";this.items.forEach(((t,e)=>{if(t.parent&&t.parent.layout&&t.parent.layout.type==y.Stack){let n="x"==s?i[e]:0,r="y"==s?i[e]:0;t.parent._doTranslate(n,r)}else{let n="x"==s?i[e]:0,r="y"==s?i[e]:0;t._doTranslate(n,r)}}));let r={};this.items.forEach((t=>r[t.classId]=t)),Object.values(r).forEach((t=>t.getScene()._updateAncestorBounds(t)))}toJSON(){let t={};return t.items=this.items.map((t=>t.id)),t.direction=this.direction,t.type=this.type,t.id=this.id,t}}class ie{constructor(t,e,i,s,n,r,a){this.item=t,this.baseItem=e,this.scene=i,this.channel=s,this.itemAnchor=n,this.baseAnchor=r,this.offset=a,this.type=E,this.id=this.type+"_"+this.item.classId+"_"+this.baseItem.classId+"_"+s}apply(){let t=et(this.item,this.scene),e=et(this.baseItem,this.scene),i=this.itemAnchor,s=this.baseAnchor,n=this.item.type==T.PointText;if("radialDistance"==this.channel)for(let n=0;n<t.length;n++){let r,a=e[n],o=t[n];a.type==T.Arc||a.type==T.Ring?r="top"==s?a.outerRadius+this.offset:"bottom"==s?a.innerRadius+this.offset:(a.outerRadius+a.innerRadius)/2+this.offset:a.type==T.Circle&&(r="top"==s?a.radius+this.offset:"bottom"==s?this.offset:a.radius/2+this.offset),o._doTranslate(a.x-o.x,a.y-r-o.bounds[i]),o._rotate?o._rotate=[o._rotate[0],a.x,a.y]:o._rotate=[0,a.x,a.y]}else if("angle"==this.channel)for(let n=0;n<t.length;n++){let r,a=e[n],o=t[n];r=a.type==T.Arc?"left"==s?a.endAngle+this.offset:"center"==s?a.startAngle+a.angle/2+this.offset:a.startAngle+this.offset:90,o._rotate?o._rotate[0]=90-r:(o._doTranslate(a.x-o.bounds[i],a.y-t[n].y),o._rotate=[90-r,e[n].x,e[n].y])}else{let r;if(this.baseItem.type==T.Link)switch(s){case"left":case"top":r=0;break;case"center":case"middle":r=.5;break;case"right":case"bottom":r=1}for(let a=0;a<t.length;a++){let o=this.baseItem.type==T.Link?e[a].getPointAt(r)[this.channel]:e[a].bounds[s]+this.offset;n?(t[a].anchor["x"==this.channel?0:1]=this.itemAnchor,t[a][this.channel]=o):"x"==this.channel?t[a]._doTranslate(o-t[a].bounds[i],0):t[a]._doTranslate(0,o-t[a].bounds[i])}}this.item.getScene()._updateAncestorBounds(this.item),this.baseItem.getScene()._updateAncestorBounds(this.baseItem)}toJSON(){let t={};return t.item=this.item.id,t.baseItem=this.baseItem.id,t.channel=this.channel,t.itemAnchor=this.itemAnchor,t.baseAnchor=this.baseAnchor,t.offset=this.offset,t.type="affixation",t.id=this.id,t}}class se extends St{constructor(t,e,i){super(),this.type=T.Gridlines,this.id=this.type+pt[this.type]++,this.encoding=t,this.channel=this.encoding.channel,this._item=e,this._strokeColor="strokeColor"in i?i.strokeColor:"#ddd",this._strokeWidth="strokeWidth"in i?i.strokeWidth:1,"radialDistance"==this.channel&&"angle"in i&&(this._rotate=[-i.angle,this.encoding.x,this.encoding.y])}toJSON(){let t={args:{}};return t.type=this.type,t.id=this.id,t.args.item=this._item.id,t.args.strokeColor=this._strokeColor,t.args.strokeWidth=this._strokeWidth,t.args.values=this._values,"time"===this.encoding.scale.type&&(t.args.isDate=!0),t.channel=this.encoding.channel,t.field=this.encoding.field,this._rotate&&(t.args.angle=this._rotate[0]),t}get values(){return this._values}set values(t){this._values=t,this.updateLines(),this.updateLinePositions()}get strokeColor(){return this._strokeColor}set strokeColor(t){this._strokeColor=t;for(let e of this.children)e.strokeColor=t}get strokeWidth(){return this._strokeWidth}set strokeWidth(t){this._strokeWidth=t;for(let e of this.children)e.strokeWidth=t}matches(t){let e=at(t).split("_")[0],i=this.encoding.scale.encodings;for(let t of i){if(at(t.anyItem).split("_")[0]===e)return!0}return!1}updateLinePositions(){let t=bt(this._item)?bt(this._item):vt(this._item);if("x"==this.channel||"width"==this.channel){let e=t.bounds,i=this.encoding.getScaleRange(this._item);for(let[t,s]of this.children.entries()){let n=i[0]+this.encoding.scale.map(this._values[t])-this.encoding.scale.range[0];s._setVertices([[n,e.top],[n,e.bottom]])}}else if("y"==this.channel||"height"==this.channel){let e=t.bounds,i=this.encoding.getScaleRange(this._item);if(this.encoding.flip)for(let[t,s]of this.children.entries()){let n=i[1]-this.encoding.scale.map(this._values[t])+this.encoding.scale.range[0];s._setVertices([[e.left,n],[e.right,n]])}else for(let[t,s]of this.children.entries()){let n=i[0]-this.encoding.scale.map(this._values[t])+this.encoding.scale.range[0];s._setVertices([[e.left,n],[e.right,n]])}}else if("radialDistance"==this.channel)for(let[t,e]of this.children.entries())e.x=this._item.parent.x,e.y=this._item.parent.y,e.radius=this.encoding.scale.map(this._values[t]);for(let t of this.children)t._updateBounds();this._updateBounds()}updateLines(){if(this.children=[],"x"==this.channel||"y"==this.channel||"width"==this.channel||"height"==this.channel)for(let t=0;t<this._values.length;t++){let e=new Z({strokeColor:this._strokeColor,fillColor:"none",strokeWidth:this._strokeWidth});e.type=T.Line,e.id=this.id+"line"+t,this.addChild(e)}else if("radialDistance"==this.channel)for(let t=0;t<this._values.length;t++){let e=new Pt({strokeColor:this._strokeColor,fillColor:"none",strokeWidth:this._strokeWidth});e.type=T.Circle,e.id=this.id+"line"+t,this.addChild(e)}}}class ne extends St{constructor(){super(),this.type=T.Collection,this._id=this.type+pt[this.type]++,this.classId=this.id,this._childrenOrder=void 0}get childrenOrder(){return this._childrenOrder?this._childrenOrder:{field:"atlas_rowId",direction:"asc"}}set childrenOrder(t){if(!("field"in t)&&!("direction"in t))return;let e,i=t.field;if(this.dataScope.dataTable.hasField(i)){if(this._childrenOrder=t,i===h)e=(t,e)=>parseInt(t.dataScope.getFieldValue(i).substring(1))-parseInt(e.dataScope.getFieldValue(i).substring(1));else{switch(this.children[0].dataScope.getFieldType(i)){case A.Date:break;case A.Number:case A.Integer:e=(t,e)=>t.dataScope.aggregateNumericalField(i)-e.dataScope.aggregateNumericalField(i);break;case A.String:e=t.ranking?(e,s)=>t.ranking.indexOf(e.dataScope.getFieldValue(i))-t.ranking.indexOf(s.dataScope.getFieldValue(i)):(t,e)=>t.dataScope.getFieldValue(i)<e.dataScope.getFieldValue(i)?-1:1}}this.children.sort(e),"desc"==t.direction&&this.children.reverse(),this.layout&&this.layout.run()}else console.warn("Cannot order collection children by an non-existent field",t.field)}duplicate(){let t=this.getScene().collection();for(let e=0;e<this.children.length;e++){let i=this.children[e];t.addChild(i.duplicate())}if(t.classId=this.classId,this.parent.addChild(t),this._layout){let e=this._layout.clone();t.layout=e}return t}contains(t,e){let i=this.getSVGPathData();if(""!==i){let s=mt.getContext(),n=new Path2D(i);return s.lineWidth=Math.max(this.strokeWidth,2.5),s.stroke(n),s.isPointInPath(n,t,e)}return this._bounds||this._updateBounds(),this._bounds.contains(t,e)}getSVGPathData(){let t="";for(let e of this.children)if(e.getSVGPathData)t+=e.getSVGPathData();else if(e.bounds){let i=e.bounds;t+=["M",i.left,i.top].join(" "),t+=["L",i.right,i.top].join(" "),t+=["L",i.right,i.bottom].join(" "),t+=["L",i.left,i.bottom,"Z"].join(" ")}return t}}class re extends Z{constructor(t){super(t),this._type=T.Arc,this.closed=!0,this._x="x"in t?t.x:0,this._y="y"in t?t.y:0,this._innerRadius="innerRadius"in t?t.innerRadius:100,this._outerRadius="outerRadius"in t?t.outerRadius:200,this._startAngle="startAngle"in t?t.startAngle:0,this._endAngle="endAngle"in t?t.endAngle:90,this._sr=kt(this._startAngle),this._er=kt(this._endAngle);let e=this._x+this._innerRadius*Math.cos(this._sr),i=this._y-this._innerRadius*Math.sin(this._sr),s=this._x+this._innerRadius*Math.cos(this._er),n=this._y-this._innerRadius*Math.sin(this._er),r=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),h=this._y-this._outerRadius*Math.sin(this._er);this._setVertices([[e,i],[r,a],[o,h],[s,n]])}get type(){return 0===this._innerRadius?T.Pie:T.Arc}set type(t){this._type=t}get innerRadius(){return this._innerRadius}set innerRadius(t){this._innerRadius=t,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[3].x=this._x+this._innerRadius*Math.cos(this._er),this.vertices[3].y=this._y-this._innerRadius*Math.sin(this._er),this._updateBounds()}get outerRadius(){return this._outerRadius}get thickness(){return this._outerRadius-this._innerRadius}set outerRadius(t){this._outerRadius=t,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._updateBounds()}get x(){return this._x}get y(){return this._y}get center(){return new Y(this._x,this._y)}set x(t){this._x=t,this.vertices[0].x=this._x+this._innerRadius*Math.cos(this._sr),this.vertices[1].x=this._x+this._outerRadius*Math.cos(this._sr),this.vertices[2].x=this._x+this._outerRadius*Math.cos(this._er),this.vertices[3].x=this._x+this._innerRadius*Math.cos(this._er),this._updateBounds()}set y(t){this._y=t,this.vertices[0].y=this._y-this._innerRadius*Math.sin(this._sr),this.vertices[1].y=this._y-this._outerRadius*Math.sin(this._sr),this.vertices[2].y=this._y-this._outerRadius*Math.sin(this._er),this.vertices[3].y=this._y-this._innerRadius*Math.sin(this._er),this._updateBounds()}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}sweepOver(t){let e=this.startAngle,i=this.endAngle;i<e&&(i+=360);let s=t.startAngle,n=t.endAngle;return n<s&&(n+=360),s>=e&&s<=i&&n>=e&&n<=i}_doTranslate(t,e){this._x+=t,this._y+=e,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._updateBounds()}_updateBounds(){this._bounds=new a(this._x-this._outerRadius,this._y-this._outerRadius,2*this._outerRadius,2*this._outerRadius)}copyPropertiesTo(t){super.copyPropertiesTo(t),t._x=this._x,t._y=this._y,t._innerRadius=this._innerRadius,t._outerRadius=this._outerRadius,t._startAngle=this._startAngle,t._endAngle=this._endAngle,t._sr=this._sr,t._er=this._er}getSVGPathData(){let t=this._endAngle<this._startAngle?this._endAngle+360-this._startAngle:this._endAngle-this._startAngle,e=t>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,t,e,0,this.vertices[2].x,this.vertices[2].y].join(" "),"L "+this.vertices[3].x+", "+this.vertices[3].y,"A "+[this._innerRadius,this._innerRadius,t,e,1,this.vertices[0].x,this.vertices[0].y].join(" ")].join(" ")}adjustAngle(t,e){this._startAngle=t,this._endAngle=e,this._sr=kt(this._startAngle),this._er=kt(this._endAngle),this.vertices[0].x=this._x+this._innerRadius*Math.cos(this._sr),this.vertices[0].y=this._y-this._innerRadius*Math.sin(this._sr),this.vertices[1].x=this._x+this._outerRadius*Math.cos(this._sr),this.vertices[1].y=this._y-this._outerRadius*Math.sin(this._sr),this.vertices[2].x=this._x+this._outerRadius*Math.cos(this._er),this.vertices[2].y=this._y-this._outerRadius*Math.sin(this._er),this.vertices[3].x=this._x+this._innerRadius*Math.cos(this._er),this.vertices[3].y=this._y-this._innerRadius*Math.sin(this._er)}}class ae extends q{constructor(t){super(t),this.type=T.Image,this._src=t.src,this._x="x"in t?t.x:0,this._y="y"in t?t.y:0,this._width="width"in t?t.width:100,this._height="height"in t?t.height:100}toJSON(){let t=super.toJSON();return t.src=this._src,t.x=this._x,t.y=this._y,t.width=this._width,t.height=this._height,t}get src(){return this._src}set src(t){this._src=t}get width(){return this._width}set width(t){this._width=t,this._updateBounds()}get height(){return this._height}set height(t){this._height=t,this._updateBounds()}get x(){return this._x}set x(t){this._x=t,this._updateBounds()}get y(){return this._y}set y(t){this._y=t,this._updateBounds()}get bounds(){return this._bounds||this._updateBounds(),this._bounds}_updateBounds(){this._bounds=new a(this._x,this._y,this._width,this._height)}copyPropertiesTo(t){t.attrs=Object.assign({},this.attrs),t.styles=Object.assign({},this.styles),this._dataScope&&(t._dataScope=this._dataScope.clone()),t.x=this._x,t.y=this._y,t.width=this._width,t.height=this._height,t.src=this._src}_doTranslate(t,e){this._x+=t,this._y+=e,this._updateBounds()}}class oe extends Z{constructor(t){super(t),this.type=T.Link,this.mode="mode"in t?t.mode:"linear",this.source=void 0,this.target=void 0,this.sourceAnchor="sourceAnchor"in t?t.sourceAnchor:["center","middle"],this.targetAnchor="targetAnchor"in t?t.targetAnchor:["center","middle"],this.sourceOffset="sourceOffset"in t?t.sourceOffset:[0,0],this.targetOffset="targetOffset"in t?t.targetOffset:[0,0]}radialvalue(t,e){let i=t-Math.PI/2;return[t=e*Math.cos(i),e*=Math.sin(t)]}bezierCurveHorizontal(t,e,i,s){return`M ${t} ${e} C ${(t+i)/2} ${e} ${t} ${s} ${i} ${s}`}bezierCurveVertical(t,e,i,s){return`M ${t} ${e} C ${t} ${(e+s)/2} ${i} ${e} ${i} ${s}`}bezierCurveRadial(t,e,i,s){let n=this.radialvalue(t,e),r=this.radialvalue(t,(e+s)/2),a=this.radialvalue(i,e),o=this.radialvalue(i,s);return`M ${n[0]} ${n[1]} C ${r[0]} ${r[1]} ${a[0]} ${a[1]} ${o[0]} ${o[1]}`}_updateBounds(){if(null!=this.source&&null!=this.target){let t=this.source.bounds[this.sourceAnchor[0]]+this.sourceOffset[0],e=this.source.bounds[this.sourceAnchor[1]]+this.sourceOffset[1],i=this.target.bounds[this.targetAnchor[0]]+this.targetOffset[0],s=this.target.bounds[this.targetAnchor[1]]+this.targetOffset[1];this._bounds=new a(Math.min(t,i),Math.min(e,s),Math.abs(t-i),Math.abs(e-s))}else this._bounds=new a(0,0,0,0)}getSVGPathData(){if(void 0===this.source||void 0===this.target)return"";let t=this.source.bounds[this.sourceAnchor[0]]+this.sourceOffset[0],e=this.source.bounds[this.sourceAnchor[1]]+this.sourceOffset[1],i=this.target.bounds[this.targetAnchor[0]]+this.targetOffset[0],s=this.target.bounds[this.targetAnchor[1]]+this.targetOffset[1];switch(this.mode){case"curveHorizontal":return this.bezierCurveHorizontal(t,e,i,s);case"curveVertical":return this.bezierCurveVertical(t,e,i,s);case"linear":default:return`M ${t} ${e} L ${i} ${s}`}}copyPropertiesTo(t){super.copyPropertiesTo(t),t.sourceAnchor=this.sourceAnchor.slice(),t.targetAnchor=this.targetAnchor.slice(),t.sourceOffset=this.sourceOffset.slice(),t.targetOffset=this.targetOffset.slice(),t.mode=this.mode}getPointAt(t){const e=yt.getSVG();let i=document.createElementNS("http://www.w3.org/2000/svg","path");i.setAttribute("d",this.getSVGPathData()),e.appendChild(i);let s=i.getTotalLength();return i.getPointAtLength(s*t)}}const he=function(t,e,i){let s=t.getScene();dt(t)||s._reapplyConstraints(t),s.getRelatedAxes(t).forEach((t=>{t.encoding&&void 0!==t.encoding.scale.offset&&(t.encoding.scale.offset+="x"===t.channel||"width"===t.channel?e:i),0===i||"x"!==t.channel&&"width"!==t.channel||void 0===t._posArg||(t._posArg=t._posArg+i),0===e||"y"!==t.channel&&"height"!==t.channel||void 0===t._posArg||(t._posArg=t._posArg+e),t.reposition()})),s.getRelatedGridlines(t).forEach((t=>t.updateLinePositions()))},le=function(t,e,i){let s=t.getScene();s._relayoutAncestors(t,e);let n=[t],r=t.firstChild;for(;r;)n.push(r),r=r.firstChild;for(let t of n)t.getScene()._reapplyConstraints(t);if(i)s.reCreateRelatedAxes(t);else{s.getRelatedAxes(t).forEach((t=>t.reposition()))}s.getRelatedGridlines(t).forEach((t=>t.updateLinePositions()))},ce=function(t){for(let e of t.encodings)e._map(),e._apply();for(let e of t.encodings)e.scene._updateAncestorBounds(e.item,e.items);let e=t.encodings.map((t=>t.anyItem)),i={};for(let t of e)"vertex"===t.type||"segment"===t.type?i[t.parent.classId]=t.parent:i[t.classId]=t;for(let t of Object.values(i))t.getScene()._reapplyConstraints(t);for(let e of t.encodings){let i=e.anyItem,s=e.scene.getRelatedAxes(i);for(let i of s)i.encoding&&i.encoding.scale===t&&(i.tickValues=e.scene._inferTickValues(e),i.labelValues=e.scene._inferTickValues(e),i._positionPath(),i._showTitle&&i._positionTitle(),"radialDistance"===i._channel&&i._rotate&&(i._rotate=[i._rotate[0],i._item.parent.x,i._item.parent.y]),i._updateBounds());e.scene.getRelatedGridlines(i).forEach((t=>t.updateLinePositions()))}},de=function(t){for(let e of t.encodings)e._apply();for(let e of t.encodings)e.scene._updateAncestorBounds(e.item,e.items);let e=t.encodings.map((t=>t.anyItem)),i={};for(let t of e)"vertex"===t.type||"segment"===t.type?i[t.parent.classId]=t.parent:i[t.classId]=t;for(let t of Object.values(i))t.getScene()._reapplyConstraints(t);for(let e of t.encodings){let t=e.anyItem;e.scene.getRelatedAxes(t).forEach((t=>t.reposition())),e.scene.getRelatedGridlines(t).forEach((t=>t.updateLinePositions()))}},ue=function(t,e){let i=t.getScene();i._relayoutAncestors(t,e),i._reapplyConstraints(t),i.getRelatedAxes(t).forEach((t=>t.reposition())),i.getRelatedGridlines(t).forEach((t=>t.updateLinePositions()))},fe=function(t,e){let i=e.getScene(),s=i.encodings[at(t)];if(s){i.encodings[at(e)]={};for(let n of["x","y"]){const r=s[n];r&&(r.anyItem=e,r.items=et(e,i),i.encodings[at(e)][n]=r,delete i.encodings[at(t)][n])}0===Object.keys(s)&&delete i.encodings[at(t)]}},pe=function(t,e){let i=e.getScene(),s=i.encodings[at(t)];if(s){i.encodings[at(e)]={};for(let n of["x","y"]){const r=s[n];r&&(r.anyItem=e,r.items=et(e,i),i.encodings[at(e)][n]=r,delete i.encodings[at(t)][n])}0===Object.keys(s)&&delete i.encodings[at(t)]}let n=i.getRelatedAxes(t);for(let s of n)s._item.classId===t.classId&&(s._item=e,s._items=et(e,i))},ge=function(t){let e=t.getScene(),i=e.encodings[at(t)];for(let t in i)i[t]._apply();e.getRelatedAxes(t).forEach((t=>t.reposition())),e.getRelatedGridlines(t).forEach((t=>t.updateLinePositions()))};function _e(t,e,i,s){let n=s.getFieldType(i);if(n!=A.String&&n!=A.Date&&n!=A.Integer)throw new Error(G.REPOPULATE_BY_NONCAT+": "+i+" is "+n);if(e.parent&&e.parent.dataScope&&!e.parent.dataScope.isFullTable()&&e.parent.dataScope.dataTable!=s)throw new Error(G.REPOPULATE_DT_MISMATCH);return function(t,e,i,s){let n=et(e.parent,t);1===n.length&&(e.parent.dataScope=void 0);for(let t of n){let e=s.getFieldSummary(i).unique.map((e=>t.dataScope?t.dataScope.cross(i,e):new It(s).cross(i,e)));e=e.filter((t=>!t.isEmpty()));const n=e.length-t.children.length,r=t.children.length-e.length;for(let e=0;e<r;e++)t.removeChildAt(t.children.length-1);const a=t.children.length;for(let e=0;e<n;e++){let e=t.children[Math.floor(Math.random()*a)].duplicate();t.addChild(e)}t.children.forEach(((t,i)=>t.dataScope=e[i]))}t._relayoutAncestors(e)}(t,e,i,s)}function me(t,e){let i=t.item;if(e.innerRadius===i.outerRadius&&i.sweepOver(e))t.children.push({item:e,children:[]});else if(t.children&&t.children.length>0&&e.innerRadius>i.outerRadius&&i.sweepOver(e))for(let i of t.children)me(i,e)}function ye(t,e,i,s){let n=t.item;if(n.innerRadius=e,n.outerRadius=e+s.map(i[n.id]),t.children&&t.children.length>0)for(let e of t.children)ye(e,n.outerRadius,i,s)}class ve{constructor(t,e){this._type="tree";let i=[],s=[];this._nodeHash={},this._traverse(t,i,s),this._nodeTable=new zt(i,"nodes"),this._linkTable=new zt(s,"links"),this._nodeTable.tree=this,this._linkTable.tree=this,this._data=t,this.aggregateFromLeaves("value","average")}get type(){return this._type}_traverse(t,e,i,s=0){let n={};o in t||(t.id="n"+e.length),e.push(n),t._depth=s;for(let r in t)if("children"==r&&t[r]&&t[r].length>0)for(let n of t[r]){let r=this._traverse(n,e,i,s+1);i.push({parent:t.id,child:r})}else n[r]=t[r];return this._nodeHash[n.id]=n,n.id}getParent(t){let e,i=t.id,s=this._linkTable.data,n=this._nodeTable.data;for(let t in s)if(s[t].child==i){e=s[t].parent;let i=n.findIndex((t=>t.id==e));return n[i]}}getChildren(t){let e=t.id,i=[],s=this._linkTable.data,n=this._nodeTable.data;for(let t in s)if(s[t].parent==e){let e=s[t].child,r=n.findIndex((t=>t.id==e));i.push(n[r])}return i}getNodeDataScope(t){return new It(this._nodeTable).cross(h,t.atlas_rowId)}getMaxDepth(){return this._nodeTable._fieldSummaries._depth.max}getRoot(){return this._nodeTable.data[0]}get nodeTable(){return this._nodeTable}get linkTable(){return this._linkTable}getNode(t){return this._nodeTable.data.filter((e=>e.id==t))[0]}sumLeaves(t,e){if(!t)return 0;let i=t.id,s=[];if(s=this.getChildren(t),s&&s.length>0){let t=0;for(let i of s)t+=this.sumLeaves(i,e);this.getNode(i)["sum"+e]=t}else this.getNode(i)["sum"+e]=t[e];return t["sum"+e]}countLeaves(t,e){if(!t)return 0;let i=t.id,s=[];s=this.getChildren(t);let n=0;if(s&&s.length>0)for(let t of s)n+=this.countLeaves(t,e);else n=1;return this.getNode(i)["count"+e]=n,t["count"+e]}averageLeaves(t,e){if(!t)return 0;let i=t.id,s=[];s=this.getChildren(t);let n=0;if(s&&s.length>0){for(let t of s)n+=this.averageLeaves(t,e);n/=s.length,this.getNode(i)["average"+e]=n}else this.getNode(i)["average"+e]=t[e];return t["average"+e]}medianLeaves(t,e){if(!t)return 0;let i=t.id,s=[];s=this.getChildren(t);let n=[];if(s&&s.length>0){for(let t of s)n.push(this.medianLeaves(t,e));n.sort((function(t,e){return t-e}));let t=Math.floor(n.length/2);n.length%2?this.getNode(i)["median"+e]=n[t]:this.getNode(i)["median"+e]=(n[t-1]+n[t])/2}else this.getNode(i)["median"+e]=t[e];return t["median"+e]}maxLeaves(t,e){if(!t)return 0;let i=t.id,s=[];s=this.getChildren(t);let n=[];if(s&&s.length>0){for(let t of s)n.push(this.maxLeaves(t,e));this.getNode(i)["max"+e]=Math.max(...n)}else this.getNode(i)["max"+e]=t[e];return t["max"+e]}minLeaves(t,e){if(!t)return 0;let i=t.id,s=[];s=this.getChildren(t);let n=[];if(s&&s.length>0){for(let t of s)n.push(this.minLeaves(t,e));this.getNode(i)["min"+e]=Math.min(...n)}else this.getNode(i)["min"+e]=t[e];return t["min"+e]}aggregateFromLeaves(t,e){let i=this.getRoot();switch(e){case"sum":this.sumLeaves(i,t);break;case"count":this.countLeaves(i,t);break;case"average":this.averageLeaves(i,t);break;case"median":this.medianLeaves(i,t);break;case"max":this.maxLeaves(i,t);break;case"min":this.minLeaves(i,t)}}}function be(t,e,i,s,n){switch(e.type){case T.Circle:return function(t,e,i,s,n){let r,a,o=i||k.Outward,h=s||50;if(o!==k.Inward&&o!==k.Outward)throw G.UNKNOWN_DIRECTION+" "+o;return et(e,t).forEach((i=>{let s=t.collection();s.dataScope=void 0,null==a&&(a=s.id),s.classId=a;let l=i.parent;xe(i,e.id,o,h,n,n.getRoot(),s,t,!0),s.layout=Hc("strata",{direction:o,rootMark:i}),l.addChild(s),i===e&&(r=s)})),r}(t,e,i,s,n);case T.Rect:return function(t,e,i,s,n){let r,a,o=i||k.Down,h=s||50;if([k.Up,k.Down,k.Left,k.Right].indexOf(o)<0)throw G.UNKNOWN_DIRECTION+" "+o;return et(e,t).forEach((i=>{let s=t.collection();s.dataScope=void 0,null==a&&(a=s.id),s.classId=a;let l=i.parent;we(i,e.id,o,h,n,n.getRoot(),s,t,!0),s.layout=Hc("strata",{direction:o,rootMark:i}),l.addChild(s),i===e&&(r=s)})),r}(t,e,i,s,n)}}function xe(t,e,i,s,n,r,a,o,h){h&&(t.dataScope=n.getNodeDataScope(r),t.classId=e,a.addChild(t));let l=n.getChildren(r);if(0===l.length)return;let c=t.type===T.Circle||t.type===T.Ring?90:t.startAngle,d=(t.type===T.Circle||t.type===T.Ring?360:t.angle)/l.length;for(let r=0;r<l.length;r++){let h,u=t.type===T.Circle?t.radius:t.outerRadius;h=360===d?o.mark("ring",{innerRadius:u,outerRadius:u+s,x:t.x,y:t.y,strokeColor:t.strokeColor,fillColor:t.fillColor,strokeWidth:t.strokeWidth,opacity:t.opacity}):o.mark("arc",{innerRadius:u,outerRadius:u+s,x:t.x,y:t.y,startAngle:At(c+d*r),endAngle:At(c+d*(r+1)),strokeColor:t.strokeColor,fillColor:t.fillColor,strokeWidth:t.strokeWidth,opacity:t.opacity}),h.dataScope=n.getNodeDataScope(l[r]),h.classId=e,a.addChild(h),xe(h,e,i,s,n,l[r],a,o)}}function we(t,e,i,s,n,r,a,o,h){h&&(t.dataScope=n.getNodeDataScope(r),t.classId=e,a.addChild(t));let l,c,d,u=n.getChildren(r);if(0!==u.length){switch(i){case k.Up:case k.Down:case k.Left:case k.Right:default:l=t.left,c=t.bottom,d=t.width/u.length}for(let r=0;r<u.length;r++){let h=o.mark("rect",{left:l,top:c,width:d,height:s,strokeColor:t.strokeColor,fillColor:t.fillColor,strokeWidth:t.strokeWidth,opacity:t.opacity});l+=d,h.dataScope=n.getNodeDataScope(u[r]),h.classId=e,a.addChild(h),we(h,e,i,s,n,u[r],a,o)}}}class ke{constructor(t,e,i,s){this._listener=t,this._eventType=e,this._selDef=i,this._targetDef=s}getCallbackFunction(t,e){let i=this;return function(s){s.stopPropagation();let r,a=e._getSelection(s,i.selectionDef,i._listener,t.getItem(n.select(this).attr("id"))),o=et(i.targetDef.item,t);i.selectionDef.remember?(e.addGlobalPredicate(t,a.predicate),r=e.getGlobalPredicates(t)):r=e.getGlobalPredicates(t).concat([a.predicate]);for(let t of o){let e=!0;for(let i of r)if(!K(t,i)){e=!1;break}for(let s in i.targetDef.effect)s in t.staticProperties||(t.staticProperties[s]=t[s]),e?t[s]=i.targetDef.effect[s].selected:"unselected"in i.targetDef.effect[s]?t[s]=i.targetDef.effect[s].unselected:s in t.staticProperties&&(t[s]=t.staticProperties[s])}e._renderer.render(t,{visualOnly:!0})}}getRestoreFunction(t,e,i){let s=this;return function(){let n=et(s.targetDef.item,t);if(s.targetDef.effect)for(let t of n)for(let e in s.targetDef.effect)t[e]=t.staticProperties[e];else for(let t of n)for(let e in t.staticProperties)t[e]=t.staticProperties[e];i&&(e._globalPredicates={}),e._renderer.render(t,{visualOnly:!0})}}get listener(){return this._listener}get selectionDef(){return this._selDef}get targetDef(){return this._targetDef}get eventType(){return this._eventType}}class Ce extends St{constructor(t){super(),t&&t.fillColor&&(this.fillColor=t.fillColor),this.type=T.Scene,this._id=this.type+pt[this.type]++,this.encodings={},this.constraints={},this._itemMap={},this._interactions=[]}clear(){this.removeAll(),this.encodings={},this.constraints={},this._itemMap={}}group(t){let e=new St;if(e.classId=e.id,this.addChild(e),t&&t.length>0)for(let i of t)e.addChild(i);return this._itemMap[e.id]=e,e}mark(t,e){let i=void 0===e?{}:e,s=null;switch(i.type=t,t){case T.Rect:{"top"in i||(i.top=0),"left"in i||(i.left=0),"width"in i||(i.width=100),"height"in i||(i.height=100);let t=i.top,e=i.left,n=i.width,r=i.height;i.vertices=[[e,t],[e+n,t],[e+n,t+r],[e,t+r]],delete i.top,delete i.left,delete i.width,delete i.height,"fillColor"in i||(i.fillColor="none"),s=new Ft(i);break}case T.Area:if(void 0!==i&&"x1"in i&&"y1"in i&&"x2"in i&&"y2"in i){let t=i.x1,e=i.y1,s=i.x2,n=i.y2;i.vertices=[[t,e],[s,e],[s,n],[t,n]],delete i.x1,delete i.y1,delete i.x2,delete i.y2}s=new Xt(i);break;case T.Line:if(void 0!==i&&"x1"in i&&"y1"in i&&"x2"in i&&"y2"in i){let t=i.x1,e=i.y1,s=i.x2,n=i.y2;i.vertices=[[t,e],[s,n]],delete i.x1,delete i.y1,delete i.x2,delete i.y2}s=new Z(i),s.type=T.Line;break;case T.Path:s=new Z(i);break;case T.Circle:s=new Pt(i);break;case T.Ring:s=new Qt(i);break;case T.Arc:case T.Pie:s=new re(i);break;case T.Polygon:s=new te(i);break;case"text":case T.PointText:"anchor"in i||(i.anchor=["center","middle"]),s=new Jt(i);break;case T.Image:s=new ae(i);break;case T.Link:s=new oe(i)}return null!==s&&(s.id="id"in i?i.id:s.type+pt[s.type]++,s.classId=s.id,this.addChild(s),this._itemMap[s.id]=s),s}glyph(...t){let e=new Kt(t);return e.classId=e.id,this.addChild(e),this._itemMap[e.id]=e,e}collection(){let t=new ne;return this.addChild(t),this._itemMap[t.id]=t,t}attach(t,e){t.dataScope=new It(e)}repeat(t,e,i){if(!t||void 0===e)throw G.INCOMPLETE_REPEAT_INFO;if(e.nodeTable&&e.linkTable){if(!Array.isArray(t)||2!==t.length)throw G.REPEAT_NODE_LINK;return function(t,e,i,s){let n=s.nodeTable.getFieldSummary(o).unique.map((t=>e.dataScope?e.dataScope.cross(o,t):new It(s.nodeTable).cross(o,t))),r=t.collection(),a={};r.dataScope=e.dataScope?e.dataScope.clone():new It(s.nodeTable),r.addChild(e);for(let t=1;t<n.length;t++){let t=e.duplicate();r.addChild(t)}r.children.forEach(((t,e)=>{t.dataScope=n[e],a[t.dataScope.getFieldValue(o)]=t}));let l=s.linkTable.getFieldSummary(h).unique.map((t=>i.dataScope?i.dataScope.cross(h,t):new It(s.linkTable).cross(h,t))),c=t.collection();c.dataScope=i.dataScope?i.dataScope.clone():new It(s.linkTable),c.addChild(i);for(let t=1;t<l.length;t++){let t=i.duplicate();c.addChild(t)}c.children.forEach(((t,e)=>t.dataScope=l[e]));let d="tree"===s.type?"parent":"source",u="tree"===s.type?"child":"target";for(let t of c.children){let e=t.dataScope.getFieldValue(d),i=t.dataScope.getFieldValue(u);t.source=a[e],t.target=a[i],t._updateBounds()}return t.addChild(c),t.addChild(r),[r,c]}(this,t[0],t[1],e)}{let s=i||{},n=s.field?s.field:zt.RowID,r=s.callback;Tt(n,e);let a=Ot(this,t,n,e,r);return s.layout&&(a.layout=s.layout),a}}repopulate(t,e,i){if(!t||void 0===e)throw G.INCOMPLETE_REPEAT_INFO;let s=i||{},n=s.field?s.field:zt.RowID;Tt(n,e),_e(this,t,n,e)}densify(t,e,i){if(!t||void 0===e)throw G.INCOMPLETE_PARTITION_INFO;let s=i||{},n=s.orientation,r=s.field?s.field:zt.RowID,a="startAngle"in s?s.startAngle:90,o="direction"in s?s.direction:"clockwise",h=s.callback;Tt(r,e);let l=Nt(this,t,n,r,e,h,a,o);return pe(t,l),l}stratify(t,e,i){if(!(e instanceof ve))throw G.STRATIFY_WITHOUT_TREE;if(t.type!==T.Circle&&t.type!==T.Rect)throw G.STRATIFY_WRONG_ITEM;let s=i||{};return be(this,t,s.direction,s.size,e)}divide(t,e,i){if(!t||null==e)throw G.INCOMPLETE_PARTITION_INFO;let s=i||{},n=s.orientation,r=s.field?s.field:zt.RowID,a=s.callback;Tt(r,e);let o=Rt(this,t,n,r,e,a);return s.layout&&(o.layout=s.layout),fe(t,o),o}_validateEncodeArgs(t,e){if(!t||!("channel"in e)||!("field"in e))throw G.INCOMPLETE_BINDING_INFO;let i=e.field;if("vertex"==t.type||"segment"==t.type){if(!t.parent.dataScope&&!t.dataScope)throw G.BIND_WITHOUT_DATASCOPE}else if(!t.dataScope)throw G.BIND_WITHOUT_DATASCOPE;let s=e.table?e.table:t.dataScope?t.dataScope._dt:t.parent.dataScope._dt,n=s.getFieldType(i);if("fillGradient"===e.channel&&[A.String,A.Boolean,A.Date].indexOf(n)>=0)throw G.UNSUPPORTED_FIELDTYPE+e.channel+": "+n;Tt(i,s)}encode(t,e){let i,s=Array.isArray(t)?t:[t],n=[];for(let t of s){let s;if(this._validateEncodeArgs(t,e),"vertex"==t.type&&t.parent.type==T.Area){let e=et(t.parent,this);s=[];let i=t.parent.vertices.indexOf(t)<t.parent.vertices.length/2;for(let t of e)s=i?s.concat(t.vertices.slice(0,t.vertices.length/2)):s.concat(t.vertices.slice(t.vertices.length/2))}else s=et(t,this);if(1===s.length&&s[0].type===T.Area&&("x"===e.channel||"y"===e.channel))return void console.warn("Only 1 "+t.type+" found, cannot encode "+e.field);!e.scale&&i&&(e.scale=i);let r=this._doEncode(s,e);i||(i=r.scale),n.push(r)}return n.length>1?n:n[0]}_doEncode(t,e){let i=t[0],s=e.channel,n=e.field;"datatable"in e||(e.datatable=i.dataScope?i.dataScope.dataTable:i.parent.dataScope.dataTable),"aggregator"in e||(e.aggregator="sum"),"flipScale"in e||(e.flipScale=!1),"includeZero"in e||(e.includeZero=!1),"scaleType"in e||(e.scaleType="linear");let r=new Dt(t,this,s,n,e);switch(s){case"width":case"height":case"radius":case"outerRadius":case"innerRadius":case"area":case"fontSize":i.type==T.Area?Lt(r):Bt(r);break;case"strokeWidth":i.type==T.Link?function(t){t._query=function(){let t=this.field,e=this.channel,i=this.items.map((t=>t.dataScope));if("strokeWidth"==e)if(this.datatable.hasField(t))this.data=i.map((e=>e.getFieldValue(t)));else if(t.startsWith("parent.")||t.startsWith("child.")){let e=this.datatable.tree.nodeTable,s=t.split(".")[0],n=t.split(".")[1],r=i.map((t=>t.getFieldValue(s)));this.data=r.map((t=>new It(e).cross(o,t).getFieldValue(n)))}},t._map=function(){let t,e=this.channel,i=this.items;if("strokeWidth"==e){let e,s;t=Yc(this.scaleType),t.domain=[0,Math.max(...this.data)],e=1,s=Math.max(...i.map((t=>parseFloat(t.styles.strokeWidth)))),s==e&&(s=e+5),this.rangeExtent&&(s=e+this.rangeExtent),this.range&&(e=this.range[0],s=this.range[1]),t._setRange([e,s]),this.scale||(this.scale=t),this.scale._addEncoding(this)}},t._apply=function(){if("strokeWidth"==this.channel)for(let t=0;t<this.data.length;t++)this.items[t].styles.strokeWidth=this.scale.map(this.data[t])},t.run()}(r):Bt(r);break;case"x":case"y":!function(t){t._query=function(){this.data=[];let t=this.field,e=this.items,i="vertex"!=this.anyItem.type&&"segment"!=this.anyItem.type||this.anyItem.dataScope?e.map((t=>t.dataScope)):e.map((t=>t.parent.dataScope));switch(this.datatable.getFieldType(t)){case A.Boolean:break;case A.Date:this.data=i.map((e=>e.getFieldValue(t)));break;case A.String:try{this.data=i.map((e=>e.getFieldValue(t)))}catch(e){throw new Error("Cannot bind "+this.channel+" to "+t+" : "+e)}break;default:this.data=i.map((e=>e.aggregateNumericalField(t,this.aggregator)))}},t._map=function(){let t,e,i,s,n,r=this.channel,a=this.datatable.getFieldType(this.field),o=it(this.anyItem);if(o&&o.type==y.Grid){let e=o.cellBounds;t="x"==r?e[0].width:e[0].height}else if("vertex"===this.anyItem.type&&this.anyItem.parent.type===T.Area)t="x"==r?this.anyItem.parent.bounds.width:this.anyItem.parent.bounds.height;else{let e=this.items.map((t=>t[r]));t=Math.max(...e)-Math.min(...e),t<100?t=100:t>500&&(t=500)}switch(this.rangeExtent&&(t=this.rangeExtent),a){case A.Boolean:break;case A.Date:if(e=Math.min(...this.data),i=Math.max(...this.data),s=[e,i],this.scale){let t=s.concat(this.scale.domain);s=[Math.min(...t),Math.max(...t)],n=this.scale.range}else this.scale=Yc("time"),this.scale.isFlipped=this._flipScale,n=[0,t];break;case A.String:if(s=Array.from(new Set(this.data)),n=[0,t],this.scale){let t=this.scale.domain;for(let e of s)t.indexOf(e)<0&&t.push(e);s=t,n=this.scale.range}else this.scale=Yc("point"),this.scale.isFlipped=this._flipScale,n=[0,t];break;default:if(e=Math.min(...this.data),i=Math.max(...this.data),s=[e,i],this.scale){let t=s.concat(this.scale._scale.domain());s=[Math.min(...t),Math.max(...t)],n=this.scale.range}else this.scale=Yc(this.scaleType),this.scale.isFlipped=this._flipScale,this.scale.includeZero=this._includeZero,n=[0,t];s[0]==s[1]&&(s[1]=1.1*s[0])}this.scale._scale.domain(s),this.scale._setRange(n),this.scale._addEncoding(this)},t._apply=function(){let t=[],e=this.channel;for(let e of this.scale.encodings)t=t.concat(e.items);if("x"==e){let i=it(this.anyItem,"grid");if(i&&i.type==y.Grid)for(let t=0;t<this.items.length;t++){let i=this.items[t],s=st(i).left+this.scale.map(this.data[t])-i[e],n=0;i._doTranslate(s,n),"vertex"!=i.type&&"segment"!=i.type||i.parent._updateBounds()}else if("vertex"===this.anyItem.type&&this.anyItem.parent.type===T.Area){let t=ot(this.items);void 0===this.scale.offset&&(this.scale.offset=Math.min(...t.map((t=>t.bounds.left))));for(let t=0;t<this.items.length;t++){let i=this.items[t],s=i.parent.bounds.left+this.scale.map(this.data[t])-i[e],n=0;i._doTranslate(s,n),i.parent._updateBounds()}}else if("vertex"==this.anyItem.type||"segment"==this.anyItem.type){let t=ot(this.items);void 0===this.scale.offset&&(this.scale.offset=Math.min(...t.map((t=>t.bounds.left))));for(let t=0;t<this.items.length;t++){let i=this.items[t],s=this.scale.offset+this.scale.map(this.data[t])-i[e],n=0;i._doTranslate(s,n),i.parent._updateBounds()}}else{void 0===this.scale.offset&&(this.scale.offset=Math.min(...t.map((t=>t[e]))));for(let t=0;t<this.items.length;t++){let i=this.items[t],s=this.scale.offset+this.scale.map(this.data[t])-i[e],n=0;i._doTranslate(s,n)}}}else{let i=it(this.anyItem,"grid");if(i&&i.type==y.Grid){let t=this.items.map((t=>st(t)));for(let i=0;i<this.items.length;i++){let s=this.items[i],n=0,r=t[i].bottom-this.scale.map(this.data[i])-s[e];s._doTranslate(n,r),"vertex"!=s.type&&"segment"!=s.type||s.parent._updateBounds()}}else if("vertex"===this.anyItem.type&&this.anyItem.parent.type===T.Area){void 0===this.scale.offset&&(this.scale.offset=Math.min(...this.items.map((t=>t.y))));for(let t=0;t<this.items.length;t++){let i=this.items[t],s=0,n=i.parent.bounds.top+this.scale.rangeExtent-this.scale.map(this.data[t])-i[e];i._doTranslate(s,n),i.parent._updateBounds()}}else if("vertex"==this.anyItem.type||"segment"==this.anyItem.type){void 0===this.scale.offset&&(this.scale.offset=Math.min(...this.items.map((t=>t.y))));for(let t=0;t<this.items.length;t++){let i=this.items[t],s=0,n=this.scale.offset+this.scale.rangeExtent-this.scale.map(this.data[t])-i[e];i._doTranslate(s,n),i.parent._updateBounds()}}else{void 0===this.scale.offset&&(this.scale.offset=Math.min(...t.map((t=>t.bounds.y))));for(let t=0;t<this.items.length;t++){let i=this.items[t],s=0,n=this.scale.offset+this.scale.rangeExtent-this.scale.map(this.data[t])-i.refBounds[e];i._doTranslate(s,n)}}}},t.run()}(r);break;case"fillColor":case"strokeColor":!function(t){t._query=function(){this.data=[];let t=this.field,e=this.items,i="vertex"!=this.anyItem.type&&"segment"!=this.anyItem.type||this.anyItem.dataScope?e.map((t=>t.dataScope)):e.map((t=>t.parent.dataScope));switch(this.datatable.getFieldType(t)){case A.Boolean:this.data=[!0,!1];break;case A.Date:this.data=i.map((e=>e.getFieldValue(t)));break;case A.String:try{this.data=i.map((e=>e.getFieldValue(t)))}catch(e){throw new Error("Cannot bind "+this.channel+" to "+t+" : "+e)}break;default:this.data=i.map((e=>e.aggregateNumericalField(t,this.aggregator)))}},t._map=function(){switch(this.datatable.getFieldType(this.field)){case A.Boolean:if(!this.scale&&(this.scale=Yc("ordinalColor"),this.scale.domain=this.data,this._mapping)){let t=this.scale.domain.map((t=>t in this._mapping?this._mapping[t]:"black"));this.scale._scale.range(t)}break;case A.String:if(this.scale)this.scale.domain=Array.from(new Set(this.scale.domain.concat(this.data)));else if(this.scale=Yc("ordinalColor",this._scheme?this._scheme:"schemeCategory10"),this.scale.domain=this.data,this._mapping){let t=this.scale.domain.map((t=>t in this._mapping?this._mapping[t]:"black"));this.scale._scale.range(t)}break;default:if(this.scale){if(!this._mapping){let t=this.scale.domain.concat(this.data);this.scale.domain=[Math.min(...t),Math.max(...t)]}}else if(this._mapping)this.scale=Yc("linear",this._mapping);else{let t,e=Math.min(...this.data),i=Math.max(...this.data),s=Math.max(Math.abs(e),Math.abs(i));e<0&&i>0?(t="interpolatePuOr",e=-s,i=s,this.scale=Yc("divergingColor",this._scheme?this._scheme:t)):(t="interpolateTurbo",this.scale=Yc("sequentialColor",this._scheme?this._scheme:t)),this.scale.domain=[e,i]}}this.scale._addEncoding(this)},t._apply=function(){for(let t=0;t<this.items.length;t++){let e=this.items[t],i=this.scale.map(this.data[t]);"vertex"==e.type||"segment"==e.type?e[this.channel]=i:e.styles[this.channel]=i,e.vertices&&"strokeColor"==this.channel&&e.vertices.forEach((t=>t.fillColor=i))}},t.run()}(r);break;case"fillGradient":i.type===T.Area&&Lt(r);break;case"angle":!function(t){t._query=function(){this.data=[],this.id2data={};let t=this.field,e=this.items;switch(this.datatable.getFieldType(t)){case A.Boolean:break;case A.Date:this.data=e.map((e=>e.dataScope.getFieldValue(t)));break;case A.String:break;default:this.data=e.map((e=>e.dataScope.aggregateNumericalField(t,this.aggregator)))}for(let t=0;t<this.data.length;t++)this.id2data[e[t].id]=this.data[t]},t._map=function(){this.scale||(this.scale=Yc("linear"),this.scale.domain=this.datatable.tree?[0,Math.max(...this.data)]:[0,this.data.reduce(((t,e)=>t+e),0)],this.scale._setRange([0,360]),this.scale._addEncoding(this))},t._apply=function(){let t;for(let e=0;e<this.items.length;e++)t=this.items[e],t.type!==T.Arc&&t.type!==T.Pie||t.adjustAngle(t.startAngle,At(t.startAngle+this.scale.map(this.data[e])));this.scene._relayoutAncestors(this.anyItem,this.items)},t.run()}(r);break;case"text":!function(t){t._query=function(){this.data=[];let t,e,i=this.items;if(this.field.startsWith("parent.")||this.field.startsWith("child.")){e=this.datatable.tree.nodeTable,t=this.field.split(".")[1];let s=this.field.split(".")[0],n=i.map((t=>t.dataScope)).map((t=>t.getFieldValue(s)));e.getFieldType(t)==A.Integer||e.getFieldType(t)==A.Number?this.data=n.map((i=>new It(e).cross(o,i).aggregateNumericalField(t))):this.data=n.map((i=>new It(e).cross(o,i).getFieldValue(t)))}else e=this.datatable,t=this.field,e.getFieldType(t)==A.Integer||e.getFieldType(t)==A.Number?this.data=i.map((e=>e.dataScope.aggregateNumericalField(t,this.aggregator))):this.data=i.map((e=>e.dataScope.getFieldValue(t)))},t._map=function(){if(this.scale);else switch(this.datatable.getFieldType(this.field)){case A.Boolean:case A.Date:break;case A.String:default:this.scale=Yc("ordinal"),this.scale.domain=[...new Set(this.data)],this.scale._scale.range(this.scale.domain.map((t=>t+"")))}},t._apply=function(){for(let t=0;t<this.items.length;t++){let e=this.items[t],i=this.scale.map(this.data[t]);e.text=i}},t.run()}(r);break;case"radialDistance":!function(t){t._query=function(){this.data=[];let t=this.field,e=this.items,i="vertex"!=this.anyItem.type&&"segment"!=this.anyItem.type||this.anyItem.dataScope?e.map((t=>t.dataScope)):e.map((t=>t.parent.dataScope));switch(this.datatable.getFieldType(t)){case A.Boolean:break;case A.Date:this.data=i.map((e=>e.getFieldValue(t)));break;case A.String:try{this.data=i.map((e=>e.getFieldValue(t)))}catch(e){throw new Error("Cannot bind "+this.channel+" to "+t+" : "+e)}break;default:this.data=i.map((e=>e.aggregateNumericalField(t,this.aggregator)))}},t._map=function(){let t=this.data;this.scale||(this.scale=Yc("linear"),this.scale.domain=[0,Math.max(...t)],this.scale._setRange([0,this.anyItem.parent.radius])),this.scale._addEncoding(this)},t._apply=function(){for(let t=0;t<this.items.length;t++){let e=this.items[t],i=this.scale.map(this.data[t]),s=xt(this.anyItem.parent.x,this.anyItem.parent.y,i,e.polarAngle);e.x=s[0],e.y=s[1]}this.scene._relayoutAncestors(this.anyItem,this.items)},t.run()}(r);break;case"thickness":!function(t){t._query=function(){this.data={};let t=this.field,e=this.items,i=e.map((t=>t.dataScope));switch(this.datatable.getFieldType(t)){case A.Boolean:break;case A.Date:for(let s=0;s<e.length;s++)this.data[e[s].id]=i[s].getFieldValue(t);break;case A.String:try{for(let s=0;s<e.length;s++)this.data[e[s].id]=i[s].getFieldValue(t)}catch(e){throw new Error("Cannot bind "+this.channel+" to "+t+" : "+e)}break;default:for(let s=0;s<e.length;s++)this.data[e[s].id]=i[s].aggregateNumericalField(t,this.aggregator)}},t._map=function(){let t=this.data;if(!this.scale){this.scale=Yc(this.scaleType),this.scale.domain=[0,Math.max(...Object.values(t))];let e=1,i=this.rangeExtent?e+this.rangeExtent:Math.max(...this.items.map((t=>t.outerRadius)));this.scale._setRange([e,i])}this.scale._addEncoding(this)},t._apply=function(){this.items.sort(((t,e)=>(t.innerRadius+t.outerRadius)/2-(e.innerRadius+e.outerRadius)/2));let t={item:new re({outerRadius:0,startAngle:0,endAngle:360}),children:[]};for(let e of this.items)me(t,e);for(let e of t.children)ye(e,e.item.innerRadius,this.data,this.scale)},t.run()}(r)}return"_remember"in e&&1!=e._remember||this._registerBinding(r),s.indexOf("Color")<0&&this._updateAncestorBounds(i,r.items),r}encodeWithinCollection(t,e){this._validateEncodeArgs(t,e);let i=function(t,e){let i={},s=et(t,e);for(let t of s){let e=t.parent.id;e in i||(i[e]=[]),i[e].push(t)}return Object.keys(i).map((t=>i[t]))}(t,this),s=[];for(let t of i){let i=this._doEncode(t,e);s.push(i)}return s}getPeers(t){return et(t,this)}find(t){return X(this,t)}align(t,e){if(!function(t,e,i){if(e==C.Top||e==C.Bottom||e==C.Middle){for(let e of t)if(!_t(e,i))return!1;return!0}if(e==C.Left||e==C.Right||e==C.Center){for(let e of t)if(!gt(e,i))return!1;return!0}}(t,e,this))return!1;let i=new ee(t,e);if(i.id in this.constraints)return console.warn("constraint has been added"),!1;this.constraints[i.id]=i,i.apply(),this._updateAncestorBounds(t[0])}removeAllConstraints(){this.constraints={}}affix(t,e,i,s){let n=s||{},r="offset"in n?n.offset:0,a="itemAnchor"in n?n.itemAnchor:"x"==i||"angle"==i?"center":"middle",o="baseAnchor"in n?n.baseAnchor:"x"==i||"angle"==i?"center":"middle",h=new ie(t,e,this,i,a,o,r);h.id,this.constraints,this.constraints[h.id]=h,h.apply()}axis(t,e,i){let s=this.getEncodingByField(e,t),n=i||{};if(s){s.datatable.getFieldType(e)!==A.Date||"labelFormat"in n||(n.labelFormat="%m/%d/%y");let t=new Ht(s,n.item?n.item:s.anyItem,n);return"tickValues"in n?(t.tickValues=n.tickValues,t.labelValues=n.tickValues):(t.tickValues=s._inferTickValues(),t.labelValues=s._inferTickValues()),this.addChildAt(t,0),this._itemMap[t.id]=t,this._updateBounds(),t}let r=n.item?n.item:X(this,[{field:e}])[0];void 0===r&&console.warn(j+e);let a=it(r);if(a&&(a.type===y.Grid||a.type===y.Stack)){if(a&&("x"==t||"y"==t)){let i,s,r=et(a.group,this);for(let a of r){let r=X(a,[{field:e}])[0],o=et(r,a);r.dataScope.dataTable.getFieldType(e)!==A.Date||"labelFormat"in n||(n.labelFormat="%m/%d/%y"),i=new $t(o,a.layout,t,e,n),null==s&&(s=i.id),i.classId=s,this.addChildAt(i,0),this._itemMap[i.id]=i}return this._updateBounds(),i}console.warn(j+e)}}getRelatedAxes(t){let e=[];if(dt(t))return e;for(let i of this.children){if(i.type!==T.Axis)continue;if(i.matches(t)){e.push(i);continue}let s=i._item,n=!1;for(;s.children&&s.children.length>0;){for(let r of s.children)if(r.classId===t.classId){n=!0,e.push(i);break}if(n)break;s=s.children[0]}let r=ht(t),a={};for(let t of r)t.classId in a||(a[t.classId]=t);let o=Object.values(a);for(let t of o)if(i.matches(t)){e.push(i);break}}return e}removeItem(t){if(!dt(t)){let e=this.getRelatedEncodings(t);for(let t of e)this.removeEncoding(t);let i=this.getRelatedAxes(t);for(let t of i)this.removeItem(t);for(let e of this.getRelatedGridlines(t))this.removeItem(e)}delete this._itemMap[t.id],this.removeChild(t),this._updateBounds()}getRelatedEncodings(t){let e=[],i=t;for(;i;)if(e.push(at(i)),i.type==T.Collection)i=i.firstChild;else if(i.type==T.Glyph){for(let t of i.children)e.push(at(t));i=void 0}else i=void 0;let s=Object.keys(this.encodings),n=[];for(let t of s){let i=t.split("_")[0];if(e.indexOf(i)>=0)for(let e in this.encodings[t])n.push(this.encodings[t][e])}return n}removeAllEncodings(){this.encodings={},this.removeAllItemsByType(T.Axis),this.removeAllItemsByType(T.Legend),this.removeAllItemsByType(T.Gridlines)}removeEncoding(t){let e=at(t.anyItem);delete this.encodings[e][t.channel];let i=[];for(let e of this.children)dt(e)&&e.encoding&&e.encoding===t&&i.push(e);for(let t of i)this.removeItem(t);this._updateBounds()}removeAllItemsByType(t){let e=[];for(let i of this.children)i.type===t&&e.push(i);for(let t of e)this.removeItem(t);this._updateBounds()}reCreateRelatedAxes(t){let e=this.getRelatedAxes(t),i=[];e.forEach((t=>{let e=t.toJSON().args;e.item&&(e.item=this.getItem(e.item)),delete e.tickValues,delete e.labelValues,this.removeItem(t),t instanceof $t?i.indexOf(t.classId)<0&&(this.axis(t.channel,t.field,e),i.push(t.classId)):this.axis(t.channel,t.field,e)})),this._updateBounds()}reCreateRelatedLegends(t){this.getRelatedLegends(t).forEach((t=>{let e=t.toJSON().args;e.item&&(e.item=this.getItem(e.item)),this.removeItem(t),this.legend(t.channel,t.field,e)})),this._updateBounds()}legend(t,e,i){let s=i||{},n=this.getEncodingByField(e,t);if(!n)throw G.INCORRECT_LEGEND_INFO+e;"x"in s||(s.x=100),"y"in s||(s.y=100);let r=new Zt(n,s);return this.addChild(r),this._itemMap[r.id]=r,this._updateBounds(),r}gridlines(t,e,i){let s=this.getEncodingByField(e,t),n=i||{};if(!s)return!1;let r=new se(s,n.item?n.item:s.anyItem,n);return r.values="values"in n?n.values:s._inferTickValues(),this.addChildAt(r,0),this._itemMap[r.id]=r,this._updateBounds(),r}getRelatedLegends(t){let e=[];if(dt(t))return e;for(let i of this.children)i.type===T.Legend&&i.matches(t)&&e.push(i);return e}getRelatedGridlines(t){let e=[];if(dt(t))return e;for(let i of this.children){if(i.type!==T.Gridlines)continue;if(i.matches(t)){e.push(i);continue}let s=i._item,n=!1;for(;s.children&&s.children.length>0;){for(let r of s.children)if(r.classId===t.classId){n=!0,e.push(i);break}if(n)break;s=s.children[0]}let r=ht(t),a={};for(let t of r)t.classId in a||(a[t.classId]=t);let o=Object.values(a);for(let t of o)if(i.matches(t)){e.push(i);break}}return e}propagate(t,e,...i){let s=et(t,this);for(let t of s)t[e](...i)}classify(t,e,i){let s,n={},r=t[0].parent;for(let i of t){let t=i.dataScope.getFieldValue(e);t in n||(n[t]=[]),n[t].push(i)}let a=[],o=t[0].dataScope._dt;for(let t in n){let r=this.collection();i.addChild(r),void 0===s&&(s=r.id),r.classId=s,r.dataScope=new It(o).cross(e,t);for(let e of n[t])r.addChild(e);a.push(r)}return 0===r.children.length&&r.parent.removeChild(r),a}getEncodingByItem(t,e){let i=this.encodings[at(t)];return i&&i[e]?i[e]:null}getEncodingByField(t,e){for(let i in this.encodings){let s=this.encodings[i];if(s[e]&&s[e].field==t)return s[e]}return null}positionBound(t,e){let i=this.getEncodingByItem(t,e);if(i)return i;if(!ft(t))return null;for(let i in this.encodings){if(i.split("_")[0]===t.classId&&e in this.encodings[i])return this.encodings[i][e]}}sizeBound(t,e){let i=this.getEncodingByItem(t,e);if(i)return i;if(ft(t)){let i="width"===e||"height"===e||"radius"===e?["area"]:["width","height"],s="width"===e?["x"]:"height"===e?["y"]:["x","y"];for(let e in this.encodings){let n=e.split("_")[0];if(e.indexOf("_")<0){for(let s of i)if(n===t.classId&&s in this.encodings[e])return this.encodings[e][s]}else for(let i of s)if(n===t.classId&&i in this.encodings[e])return this.encodings[e][i]}}return null}setProperties(t,e){let i,s={};for(let t in e)s[t]=!0;if(Object.values(y).indexOf(t.type)>-1&&t.group){i=et(t.group,this);for(let t of i)for(let i in e)t.layout[i]=e[i]}else if(i=et(t,this),"vertex"===t.type)for(let t of i)for(let i in e)t[i]=e[i];else if(t instanceof q)for(let n in e)if("x"!==n&&"y"!==n||!this.positionBound(t,n))if("width"!==n&&"height"!==n&&"radius"!==n||!this.sizeBound(t,n))t.type!==T.Rect&&t.type!==T.Line||"width"!==n&&"height"!==n?t.type==T.Circle&&"radius"==n?i.forEach((t=>t.resize(2*e[n],2*e[n],e.xRef,e.yRef))):i.forEach((t=>t[n]=e[n])):"width"===n?i.forEach((t=>t.resize(e[n],t.bounds.height,e.xRef))):i.forEach((t=>t.resize(t.bounds.width,e[n],void 0,e.yRef)));else{let i=this.getEncodingByItem(t,n);i||"radius"!=n||(i=this.getEncodingByItem(t,"area"));let s=i.scale.rangeExtent*e[n]/t[n];i.scale.rangeExtent=s}else s[n]=!1;else if("collection"==t.type||"group"==t.type)for(let t of i)for(let i in e)t[i]="layout"===i&&void 0!==e[i]?e[i].clone():e[i];let n=Object.keys(s).filter((t=>s[t])),r=["width","height","fontSize","area","radius"];for(let e of r)if(n.indexOf(e)>=0&&ut(t)){ue(t,i);break}n.indexOf("baseline")>=0&&t.type===T.Area&&ge(t,i);let a=["layout","rowGap","colGap","numRows","numCols","vertCellAlignment","horzCellAlignment"];for(let t of a)if(n.indexOf(t)>=0){let t=n.indexOf("numRows")>=0||n.indexOf("numCols")>=0||n.indexOf("layout")>=0;le(i[0],i,t);break}return s}_canTranslate(t){let e={x:!0,y:!0};return t.type==T.Axis?("x"===t.channel||"width"===t.channel?e.x=!1:"y"!==t.channel&&"height"!==t.channel||(e.y=!1),e):(t.parent.type===T.Collection&&t.parent.layout&&(e.x=!1,e.y=!1),this.positionBound(t,"x")&&(e.x=!1),this.positionBound(t,"y")&&(e.y=!1),e)}translate(t,e,i){let s=this._canTranslate(t);if(!s.x&&!s.y)return s;const n=s.x?e:0,r=s.y?i:0;return t._doTranslate(n,r),this._updateAncestorBounds(t),he(t,n,r),s}_updateAncestorBounds(t,e){let i=ot(e||et(t,this));for(;i.length>0;){for(let t of i)(t.children&&t.children.length>0||t.vertices)&&t._updateBounds();i=ot(i)}}_reapplyConstraints(t){let e=t,i=[t];for(;e.children;)e.type==T.Collection?i.push(e.firstChild):i=i.concat(e.children),e=e.firstChild;for(e=t.parent;e&&e.type!==T.Scene;)i.push(e),e=e.parent;const s=i.map((t=>t.classId));for(let t in this.constraints){const e=this.constraints[t];switch(e.type){case E:(s.indexOf(e.item.classId)>=0||s.indexOf(e.baseItem.classId)>=0)&&e.apply();break;case S:for(let t of e.items)if(s.indexOf(t.classId)>=0){e.apply();break}}}}_relayoutAncestors(t,e){let i=ot(e||et(t,this));for(;i.length>0;){for(let t of i)t.layout&&t.layout.run(),t.children&&t.children.length>0&&t._updateBounds(),t.vertices&&t._updateBounds();i=ot(i)}}_reapplySizeBindings(t){let e=["width","height"];for(let i in this.encodings){if(t.classId!=i)continue;let s=this.encodings[i],n=X(this,[{classId:i}]);for(let t of e){let e=s[t];e&&e.run()}this._relayoutAncestors(n[0],n)}}_registerBinding(t){let e=this.encodings,i=at(t.anyItem);return i in e||(e[i]={}),e[i][t.channel]=t,!0}toJSON(){let t=super.toJSON();this.fillColor&&(t.fillColor=this.fillColor);let e={};t.encodings=[],t.itemCounter=pt;for(let i in this.encodings)for(let s in this.encodings[i]){let n=this.encodings[i][s];t.encodings.push(n.toJSON()),n.scale&&!(n.scale.id in e)&&(e[n.scale.id]=n.scale.toJSON())}t.scales=e,t.constraints={};for(let e in this.constraints)t.constraints[e]=this.constraints[e].toJSON();t.tables={};let i=this.getDataTables();for(let e in i)t.tables[e]=i[e].toJSON();return t}getDataTables(){let t={};for(let e in this.encodings)for(let i in this.encodings[e]){let s=this.encodings[e][i];s.datatable.id in t||(t[s.datatable.id]=s.datatable)}for(let e of this.children)if(!dt(e)){if(e.dataScope){t[e.dataScope.dataTable.id]=e.dataScope.dataTable;break}if(e.children&&e.children.length>0){let i=e.firstChild;for(;i;){if(i.dataScope){t[i.dataScope.dataTable.id]=i.dataScope.dataTable;break}i=i.children&&i.children.length>0?i.firstChild:void 0}}}return t}getItem(t){let e=t.split("_")[0];if(t.indexOf("_v_")>0){let i=parseInt(t.split("_v_")[1]);return this._itemMap[e].vertices.find((t=>t._id===i))}if(t.indexOf("_s_")>0){let i=parseInt(t.split("_s_")[1]);return this._itemMap[e].segments.find((t=>t._id===i))}return this._itemMap[t]}addInteraction(t,e,i,s){let n=new ke(t,e,i,s);this._interactions.push(n)}}class Se{constructor(t){this._renderer=t,this._globalPredicates={}}processInteraction(t,e){let i=t.listener;if(ut(i)){let s=i.classId?"."+i.classId:"#"+i.id;switch(t.eventType){case"hover":n.selectAll(s).on("mouseover",t.getCallbackFunction(e,this)),n.selectAll(s).on("mouseleave",t.getRestoreFunction(e,this));break;case"click":n.selectAll(s).on("mousedown",t.getCallbackFunction(e,this))}}else if(i.type==T.Scene){if(!t.targetDef||!t.targetDef.item)return;t.selectionDef.item||n.select("#"+this._renderer._svgId).on("mousedown",t.getRestoreFunction(e,this,!0))}}_getSelection(t,e,i,s){let n={};s?n.item=s:e.item;let r=e.field?e.field:h;return n.item&&(n.predicate={field:r,value:n.item.dataScope.getFieldValue(r)}),n}addGlobalPredicate(t,e){t.id in this._globalPredicates||(this._globalPredicates[t.id]={}),this._globalPredicates[t.id][e.field]=e}getGlobalPredicates(t){return t.id in this._globalPredicates?Object.values(this._globalPredicates[t.id]):[]}}class Ee{constructor(t){this._svgId=t,this._compMap={},this._decoMap={},this._interactionHandler=new Se(this)}render(t,e){let i=e||{};for(let t in this._decoMap)this._decoMap[t].remove(),delete this._decoMap[t];this._removed={};for(let t in this._compMap)this._removed[t]=1;this._renderItem(t,i);for(let t in this._removed)this._compMap[t].remove(),delete this._compMap[t];if(!("visualOnly"in i))for(let e of t._interactions)this._interactionHandler.processInteraction(e,t)}clear(){let t=document.getElementById(this._svgId);for(;t.firstChild;)t.firstChild.remove();this._compMap={},this._decoMap={}}_renderItem(t,e){let i,s=t.id,r=t.parent;i=r&&r.id&&r.id in this._compMap?n.select("#"+this._svgId).select("#"+r.id):n.select("#"+this._svgId),s in this._compMap?delete this._removed[s]:this._compMap[s]=i.append(this._getSVGElementType(t)),t.type==T.Gridlines&&this._compMap[s].lower();let a=this._compMap[s];if(a.attr("id",s),t.classId&&a.attr("class",t.classId),t.type==T.Scene&&n.select("#"+this._svgId).style("background",t.fillColor?t.fillColor:"#fff"),"vertex"!=t.type){if(t.type==T.Path||t.type==T.Polygon||t.type==T.Link)a.attr("d",t.getSVGPathData()),t.closed||a.style("fill","none"),0==s.indexOf("axis")&&a.style("shape-rendering","crispEdges");else if(t.type==T.Line)a.attr("x1",t.vertices[0].x),a.attr("y1",t.vertices[0].y),a.attr("x2",t.vertices[1].x),a.attr("y2",t.vertices[1].y),0==s.indexOf("axis")&&a.style("shape-rendering","crispEdges");else if(t.type==T.Circle)a.attr("cx",t.x),a.attr("cy",t.y),a.attr("r",t.radius);else if(t.type==T.Rect){let e=t.bounds;a.attr("x",e.left).attr("y",e.top).attr("width",e.width).attr("height",e.height)}else t.type==T.PointText?a.attr("text-anchor",this._getTextAnchor(t.anchor[0])).attr("alignment-baseline",this._getTextAnchor(t.anchor[1])).attr("dominant-baseline",this._getTextAnchor(t.anchor[1])).text(t.text).attr("x",t.x).attr("y",t.y):t.type==T.Pie||t.type==T.Area?(a.attr("d",t.getSVGPathData()),t.closed||a.style("fill","none"),0==s.indexOf("axis")&&a.style("shape-rendering","crispEdges")):t.type==T.Ring||t.type==T.Arc?a.attr("d",t.getSVGPathData()):t.type==T.Image&&a.attr("href",t.src).attr("x",t.x).attr("y",t.y).attr("width",t.width).attr("height",t.height);for(let e in t.styles)if(void 0!==t.styles[e])if(e.indexOf("Color")>0&&t.styles[e].type==T.LinearGradient){n.select("#"+this._svgId).select("defs").empty()&&n.select("#"+this._svgId).append("defs");let i=n.select("defs"),s=t.styles[e];if(i.select("#"+s.id).empty()){let t=i.append("linearGradient").attr("id",s.id);t.attr("x1",s.x1+"%").attr("x2",s.x2+"%").attr("y1",s.y1+"%").attr("y2",s.y2+"%");for(let e of s.stops)t.append("stop").attr("offset",e.offset+"%").style("stop-color",e.color).style("stop-opacity",e.opacity)}a.style(D[e],"url(#"+s.id+")")}else a.style(D[e],t.styles[e]);if(t._rotate&&a.attr("transform","rotate("+t._rotate.join(" ")+")"),t.vertices&&this._renderVertices(t),t.type==T.Collection&&e&&e.collectionBounds){let e=t.bounds;t.layout&&"grid"==t.layout.type?this._renderLayout(t):(t.id in this._decoMap||(this._decoMap[t.id]=n.select("#"+this._svgId).append("rect").attr("class","deco")),this._decoMap[t.id].attr("x",e.left).attr("y",e.top).attr("width",e.width).attr("height",e.height).attr("fill","none").attr("stroke","#1ecb40").attr("stroke-width","2px").attr("stroke-dasharray","5,5"))}if(t.children)for(let i of t.children)this._renderItem(i,e)}}_renderVertices(t){let e=t.id+"-vertices";if(e in this._compMap)delete this._removed[e];else{let i=t.parent,s=i?i.id:this._svgId;this._compMap[e]=n.select("#"+s).append("g").attr("id",e)}if(0===t.vertices.map((t=>t.shape)).filter((t=>void 0!==t)).length)return void this._compMap[e].style("visible","hidden");this._compMap[e].style("visible","visible");let i=t.vertices.filter((t=>void 0!==t.shape));for(let t of i){let i=e+"-"+t.id;i in this._compMap?t.shape!==this._compMap[i].node().tagName?(this._compMap[i].remove(),this._compMap[i]=n.select("#"+e).append(t.shape).attr("id",i),delete this._removed[i]):delete this._removed[i]:this._compMap[i]=n.select("#"+e).append(t.shape).attr("id",i),"rect"==t.shape?n.select("#"+i).attr("x",t.x-t.width/2).attr("y",t.y-t.height/2).attr("width",t.width).attr("height",t.height):"circle"==t.shape&&n.select("#"+i).attr("cx",t.x).attr("cy",t.y).attr("r",t.radius),n.select("#"+i).style("fill",t.fillColor).style("opacity",t.opacity).style("stroke-width",t.strokeWidth).style("stroke",t.strokeColor)}}_renderLayout(t){let e=t.id+"-grid";e in this._decoMap||(this._decoMap[e]=n.select("#"+this._svgId).append("g").attr("id",e).attr("class","deco"));let i=t.layout.cellBounds,s=t.layout.rowGap;this._decoMap[e].selectAll("rect").remove(),this._decoMap[e].selectAll("rect").data(i.slice(0,i.length-1)).enter().append("rect").attr("x",(t=>t.left)).attr("y",(t=>t.bottom)).attr("width",(t=>t.width)).attr("height",s).style("fill","pink").style("opacity",.5);let r=Math.min(...i.map((t=>t.left))),a=Math.min(...i.map((t=>t.top)));this._decoMap[e].append("rect").attr("x",r).attr("y",a).attr("width",t.bounds.width).attr("height",t.bounds.height).attr("stroke","blue").attr("stroke-width","1px").attr("stroke-dasharray","5,5").attr("fill","none")}_getTextAnchor(t){switch(t){case"top":return"text-before-edge";case"bottom":return"text-after-edge";case"left":return"start";case"right":return"end";case"center":case"middle":return"middle";default:return t}}_getSVGElementType(t){switch(t.type){case T.Rect:return"rect";case T.Collection:case T.Group:case T.Glyph:case T.Scene:case T.Axis:case T.Legend:case T.Gridlines:return"g";case T.Area:case T.Path:case T.Polygon:case T.Ring:case T.Pie:case T.Arc:case T.Link:return"path";case T.Circle:return"circle";case T.Line:return"line";case T.PointText:return"text";case"vertex":if("circle"==t.shape)return"circle";if("rect"==t.shape)return"rect";throw"argument exception";case"image":return"image"}}}class Te{constructor(t,e){switch(this._type=t,this._offset=void 0,this.id="scale"+pt.scale++,this._flipped=!1,this._includeZero=!1,t){case"linear":if(e){let t=Object.keys(e).map((t=>parseFloat(t))).sort(((t,e)=>t-e)),i=t.map((t=>e[t]));this._scale=n.scaleLinear(t,i),"clamp"in e&&this._scale.clamp(e.clamp),this._mapping=e}else this._scale=n.scaleLinear();break;case"point":this._scale=n.scalePoint();break;case"ordinal":this._scale=n.scaleOrdinal();break;case"ordinalColor":this._scale=n.scaleOrdinal(e&&"string"==typeof e?n[e]:n.schemeCategory10);break;case"power":this._scale=n.scalePow().exponent(2);break;case"sqrt":this._scale=n.scalePow().exponent(.5);break;case"log":this._scale=n.scaleLog();break;case"identity":case"time":this._scale=n.scaleTime();break;case"sequentialColor":case"divergingColor":e&&"string"==typeof e?(this._scale=n.scaleSequential(n[e]),this._scheme=e):this._scale=n.scaleSequential()}this.encodings=[]}set scheme(t){if(this._type.indexOf("Color")<0&&"linear"!==this._type)return;let e=n.scaleSequential(n[t]),i=this._scale.domain();if(Math.min(...i)*Math.max(...i)<0){let t=Math.max(Math.abs(Math.min(...i)),Math.abs(Math.max(...i)));i=[-t,t]}e.domain(i),this._scheme=t,this._scale=e,"linear"===this._type&&(this._type=this._scale.domain()[0]*this._scale.domain()[1]<0?"divergingColor":"sequentialColor",this._mapping&&(this._mapping=void 0));for(let e of this.encodings)e._mapping&&(e._mapping=void 0),e._scheme=t,e._apply()}get scheme(){return this._scheme}get type(){return this._type}set type(t){let e;switch(t){case"linear":e=n.scaleLinear();break;case"power":e=n.scalePow().exponent(2);break;case"sqrt":e=n.scalePow().exponent(.5);break;case"log":e=n.scaleLog()}if(e){this._type=t,e.domain(this._scale.domain()).range(this._scale.range()),this._scale=e;for(let t of this.encodings)t._apply();for(let t of this.encodings)t.scene._updateAncestorBounds(t.item,t.items)}else console.warn(V+t)}toJSON(){let t={};return t.type=this.type,t.id=this.id,t.offset=this._offset,this._scheme&&(t.scheme=this._scheme),t.domain=this._scale.domain(),t.range=this.range,t.clamp=this.clamp,t.isFlipped=this.isFlipped,t.includeZero=this.includeZero,this._mapping&&(t.mapping=this._mapping),t}_merge(t){if(this.type!=t.type)throw G.DIFFERENT_SCALE_TYPE;let e,i;switch(this.type){case"linear":case"time":e=[Math.min(this.domain[0],t.domain[0]),Math.max(this.domain[1],t.domain[1])],i=[0,this.map(e[1])-this.map(e[0])];break;case"point":case"ordinalColor":e=[...new Set(this.domain.concat(t.domain))],i=[];break;default:console.log("TODO: merge scale type",this.type)}this._scale.domain(e),this._scale.range(i)}get domain(){if(this._includeZero){return[0,this._scale.domain()[1]]}return this._scale.domain()}set domain(t){this._scale.domain(t);for(let t of this.encodings)t._apply()}get range(){return this._scale.range()}
|
|
1
|
+
/* version: 1.10.0 */
|
|
2
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("d3"),require("pixi.js")):"function"==typeof define&&define.amd?define(["exports","d3","pixi.js"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).msc={},t.d3,t.PIXI)}(this,(function(t,e,i){"use strict";function s(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(i){if("default"!==i){var s=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,s.get?s:{enumerable:!0,get:function(){return t[i]}})}})),e.default=t,Object.freeze(e)}var n=s(e),r=s(i);class a{constructor(t,e,i,s){this.left=t,this.top=e,this.width=i,this.height=s}toJSON(){let t={};return t.left=this.left,t.top=this.top,t.width=this.width,t.height=this.height,t}union(t){let e=Math.min(this.left,t.left),i=Math.min(this.top,t.top),s=Math.max(this.right,t.right),n=Math.max(this.bottom,t.bottom);return new a(e,i,s-e,n-i)}clone(){return new a(this.left,this.top,this.width,this.height)}get right(){return this.left+this.width}get bottom(){return this.top+this.height}get x(){return(this.left+this.right)/2}get y(){return(this.top+this.bottom)/2}get center(){return(this.left+this.right)/2}get middle(){return(this.top+this.bottom)/2}contains(t,e){return this.left<=t&&this.right>=t&&this.top<=e&&this.bottom>=e}overlap(t){return!(this.right<t.left||this.bottom<t.top||this.left>t.right||this.top>t.bottom)}}const o="id",h="atlas_rowId",l=["linear","power","log","sqrt","symlog","identity","time","ordinal","band","point","ordinalColor","sequentialColor","divergingColor"],c="natural",d="basis",u="bumpX",f="bumpY",p="linear",g="step",_="CatmullRom",m="cardinal",y={Grid:"grid",Circular:"circular",Stack:"stack",Treemap:"treemap",Packing:"packing",Force:"force",TidyTree:"tidytree",Sugiyama:"sugiyama",Strata:"strata"},v="vertical",b="horizontal",x="angular",w="radial",k={Up:"up",Down:"down",Left:"left",Right:"right",Inward:"inward",Outward:"outward",Clockwise:"clockwise",Anticlockwise:"anticlockwise"},C={Top:"top",Left:"left",Bottom:"bottom",Right:"right",Center:"center",Middle:"middle"},S="alignment",E="affixation",T={Area:"area",Rect:"rect",Ellipse:"ellipse",Circle:"circle",Pie:"pie",Ring:"ring",Arc:"arc",Line:"line",Path:"path",Image:"image",PointText:"pointText",Collection:"collection",Group:"group",Scene:"scene",Axis:"axis",Glyph:"glyph",Legend:"legend",Polygon:"polygon",Gridlines:"gridlines",LinearGradient:"LinearGradient",Link:"link",DataTable:"datatable"},A={Boolean:"boolean",Integer:"integer",Number:"number",Date:"date",String:"string"},I="max",O="min",M="avg",R="median",N="sum",F="count",P="mean",B="percentile 25",L="percentile 75",D={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"},j="Cannot find relevant information to create an axis for ",V="Cannot change scale type to ",G={FIELD_NONEXISTENT:"Data field does not exist in the data table",INCOMPLETE_REPEAT_INFO:"Incomplete information to do repeat. You must specify an item, a categorical data field and a data table",REPEAT_BY_NONCAT:"Repeat only works on a string or date field",PARTITION_BY_NONCAT:"Divide only works on a string or date field",DENSIFY_BY_NONCAT:"Densify only works on a string or date field",INCOMPLETE_REPOPULATE_INFO:"Incomplete information to re-populate. You must specify an item, a categorical data field and a data table",REPOPULATE_BY_NONCAT:"Repopulate only works on a string or date field",REPOPULATE_DT_MISMATCH:"Cannot repopulate with a data table that is different from the item's parent's data table",COMPNT_NON_REPEATABLE:"Item not repeatable",REPEAT_NODE_LINK:"To repeat with a tree or a network, you need to provide two marks, one for node and one for link",INCOMPLETE_PARTITION_INFO:"Incomplete information to divide. You must specify an item, a categorical data field and a data table",COMPNT_NON_PARTITIONABLE:"Item cannot be divided",INCOMPLETE_DENSIFY_INFO:"Incomplete information to densify. You must specify an item, a categorical data field and a data table",COMPNT_NON_DENSIFIABLE:"Item cannot be densified",STRATIFY_WITHOUT_TREE:"Stratify only works on a tree dataset",STRATIFY_WRONG_ITEM:"Stratify only works on a circle or a rectangle",BIND_WITHOUT_DATASCOPE:"Item must be repeated or divided by data first before applyng binding",UNKNOWN_ALIGNMENT:"Unkown alignment",UNKNOWN_Orientation:"Unkown orientation",UNKNOWN_DIRECTION:"Unkown direction",UNKOWNN_SCALE_TYPE:"Unknown scale type",UNKNOWN_ANCHOR:"Unknown anchor",INCOMPLETE_BINDING_INFO:"Incomplete binding information. You must specify an item, a data field and a visual channel",MULTIPLE_VALUES_PER_FIELD:"Multiple distinct field values exist",DIFFERENT_SCALE_TYPE:"Cannot merge different types of scale",INSUFFICIENT_DATA_SCOPES:"Insufficient data to divide or densify a mark",INCORRECT_CONSTRAINT_INFO:"Constrain information is incorreclty passed",FEATURE_NOT_IMPLEMENTED:"This feature has not been implemented yet",LAYOUT_WITHOUT_TREE:"The layout can only be applied to a tree",UNSUPPORTED_FIELDTYPE:"Unsupported field type for encoding "};class z{constructor(t){this.group=void 0}run(){}clone(){}}class W extends z{constructor(t){super(),this.type="grid",this._numCols=t.numCols,this._numRows=t.numRows,this._dir="dir"in t?t.dir:[W.direction.Left2Right,W.direction.Top2Bottom],this._rowGap="rowGap"in t&&void 0!==t.rowGap?t.rowGap:5,this._colGap="colGap"in t&&void 0!==t.colGap?t.colGap:5,this._cellHorzAlignment="horzCellAlignment"in t&&this._validateCellAlignment("h",t.horzCellAlignment)?t.horzCellAlignment:C.Left,this._cellVertAlignment="vertCellAlignment"in t&&this._validateCellAlignment("v",t.vertCellAlignment)?t.vertCellAlignment:C.Bottom}_validateCellAlignment(t,e){return"h"===t&&[C.Left,C.Center,C.Right].indexOf(e)>=0||("v"===t&&[C.Top,C.Middle,C.Bottom].indexOf(e)>=0||(console.warn("Invalid alignment:",e),!1))}toJSON(){let t={args:{}};return t.type=this.type,t.args.numCols=this._numCols,t.args.numRows=this._numRows,t.args.colGap=this._colGap,t.args.rowGap=this._rowGap,t.args.horzCellAlignment=this._cellHorzAlignment,t.args.vertCellAlignment=this._cellVertAlignment,t.left=this._left,t.top=this._top,t.args.dir=this._dir,t}clone(){return new W({numCols:this._numCols,numRows:this._numRows,dir:this._dir,colGap:this._colGap,rowGap:this._rowGap})}get cellBounds(){let t,e,i=this.group,s=this._colGap,n=this._rowGap;this._numRows?(e=this._numRows,t=Math.ceil(this.group.children.length/this._numRows)):this._numCols&&(t=this._numCols,e=Math.ceil(this.group.children.length/this._numCols));let r=i.children.map((t=>t.bounds));if(void 0===this._left){let t=r.map((t=>t.left)),e=r.map((t=>t.top));this._left=Math.min(...t),this._top=Math.min(...e)}let o=r.map((t=>t.width)),h=r.map((t=>t.height)),l=Math.max(...o),c=Math.max(...h),d=i.getInternalEncodings("x"),u=i.getInternalEncodings("y"),f=i.getInternalEncodings("width"),p=i.getInternalEncodings("height"),g=0;if(d.length>0){let t=d[d.length-1];l=t.scale.rangeExtent,g=t.scale.range[0],"point"===t.scale.type&&(l+=t.anyItem.bounds.width)}else f.length>0&&f[f.length-1]._rectNegativeValues&&(l=f[f.length-1].scale.rangeExtent,g=f[f.length-1].scale.range[0]);if(u.length>0){let t=u[u.length-1];c=t.scale.rangeExtent,"point"===t.scale.type&&(c+=t.anyItem.bounds.height)}else p.length>0&&p[p.length-1]._rectNegativeValues&&(c=p[p.length-1].scale.rangeExtent);let _=[],m=e*t;switch(this._dir[0]){case W.direction.Left2Right:switch(this._dir[1]){case W.direction.Top2Bottom:for(let e=0;e<m;e++)_.push(new a(this._left+(l+s)*(e%t)+g,this._top+(c+n)*Math.floor(e/t),l,c));break;case W.direction.Bottom2Top:for(let e=0;e<m;e++)_.push(new a(this._left+(l+s)*(e%t)+g,this._top+(this.numRows-1-Math.floor(e/t))*(c+n),l,c))}break;case W.direction.Right2Left:switch(this._dir[1]){case W.direction.Top2Bottom:for(let e=0;e<m;e++)_.push(new a(g+this._left+(t-1)*(l+s)-(l+s)*(e%t),this._top+(c+n)*Math.floor(e/t),l,c));break;case W.direction.Bottom2Top:for(let e=0;e<m;e++)_.push(new a(g+this._left+(t-1-e%t)*(l+s),this._top+(this.numRows-1-Math.floor(e/t))*(c+n),l,c))}break;case W.direction.Top2Bottom:switch(this._dir[1]){case W.direction.Left2Right:for(let t=0;t<m;t++)_.push(new a(g+this._left+(l+s)*Math.floor(t/this.numRows),this._top+(c+n)*(t%this.numRows),l,c));break;case W.direction.Right2Left:for(let t=0;t<m;t++)_.push(new a(g+this._left+(l+s)*(this.numCols-1)-(l+s)*Math.floor(t/this.numRows),this._top+(c+n)*(t%this.numRows),l,c))}break;case W.direction.Bottom2Top:switch(this._dir[1]){case W.direction.Left2Right:for(let t=0;t<m;t++)_.push(new a(g+this._left+(l+s)*Math.floor(t/this.numRows),this._top+(c+n)*(this.numRows-1)-(c+n)*(t%this.numRows),l,c));break;case W.direction.Right2Left:for(let t=0;t<m;t++)_.push(new a(g+this._left+(l+s)*(this.numCols-1)-(l+s)*Math.floor(t/this.numRows),this._top+(c+n)*(this.numRows-1)-(c+n)*(t%this.numRows),l,c))}}return _}run(){if(null==this.group||!this.group.children||0===this.group.children.length)return;let t=this.cellBounds,e=this.group.getInternalEncodings("x"),i=this.group.getInternalEncodings("y"),s=this.group.getInternalEncodings("width"),n=this.group.getInternalEncodings("height");for(let s=0;s<this.group.children.length;s++){let n=this.group.children[s],r=t[s],a=r.x-n.bounds.x,o=r.y-n.bounds.y;n._doTranslate(a,o);let h=0,l=0;if(0==e.length)switch(this._cellHorzAlignment){case C.Left:h=r.left-n.bounds.left;break;case C.Center:h=r.x-n.bounds.x;break;case C.Right:h=r.right-n.bounds.right}if(0==i.length)switch(this._cellVertAlignment){case C.Top:l=r.top-n.bounds.top;break;case C.Middle:l=r.y-n.bounds.y;break;case C.Bottom:l=r.bottom-n.bounds.bottom}n._doTranslate(h,l)}if(e.length>0)for(let t of e)t._apply();else if(s.length>0){let t=s[s.length-1];t._rectNegativeValues&&t._apply()}if(i.length>0)for(let t of i)t._apply();else if(n.length>0){let t=n[n.length-1];t._rectNegativeValues&&t._apply()}this.group._updateBounds()}set rowGap(t){this._rowGap=t,this.run(),this.group.getScene()._relayoutAncestors(this.group)}get rowGap(){return this._rowGap}set colGap(t){this._colGap=t,this.run(),this.group.getScene()._relayoutAncestors(this.group)}get colGap(){return this._colGap}set numCols(t){t<0||t>this.group.children.length?console.warn("Cannot set",t,"columns for",this.group.children.length,"items in grid"):(this._numCols=t,this._numRows=Math.ceil(this.group.children.length/t),this.run(),this.group.getScene()._relayoutAncestors(this.group))}get numCols(){return this._numCols?this._numCols:this._numRows?Math.ceil(this.group.children.length/this._numRows):0}set numRows(t){t<0||t>this.group.children.length?console.warn("Cannot set",t,"rows for",this.group.children.length,"items in grid"):(this._numRows=t,this._numCols=Math.ceil(this.group.children.length/t),this.run(),this.group.getScene()._relayoutAncestors(this.group))}get numRows(){return this._numRows?this._numRows:this._numCols?Math.ceil(this.group.children.length/this._numCols):0}set vertCellAlignment(t){if(t!=C.Top&&t!=C.Bottom&&t!=C.Middle)throw G.UNKOWN_ALIGNMENT;this._cellVertAlignment=t,this.run()}get vertCellAlignment(){return this._cellVertAlignment}set horzCellAlignment(t){if(t!=C.Left&&t!=C.Center&&t!=C.Right)throw G.UNKOWN_ALIGNMENT;this._cellHorzAlignment=t,this.run()}get horzCellAlignment(){return this._cellHorzAlignment}}W.direction={Left2Right:"l2r",Right2Left:"r2l",Top2Bottom:"t2b",Bottom2Top:"b2t"};class U{constructor(t){this._stops=[],this.type=T.LinearGradient,this.id=this.type+pt[this.type]++,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 t={};return t.type=this.type,t.id=this.id,t.x1=this.x1,t.x2=this.x2,t.y1=this.y1,t.y2=this.y2,t.stops=this._stops,t}addStop(t,e,i){this._stops.push({offset:t,color:e,opacity:i})}get stops(){return this._stops}}class q{constructor(t){if(this._dataScope=void 0,this._id=void 0,this.attrs={},this.styles={},this.staticProperties={},void 0!==t)for(let e in D)e in t&&(this.styles[e]=t[e])}get id(){return this._id}set id(t){this.getScene()?(delete this.getScene()._itemMap[this._id],this._id=t,this.getScene()._itemMap[t]=this):this._id=t}contains(t,e){if(!this._bounds)return!1;if(!this._bounds.contains(t,e))return!1;switch(this.type){case T.Rect:case T.PointText:return!0;case T.Circle:return Math.sqrt(Math.pow(t-this.x,2)+Math.pow(e-this.y,2))<=this.radius+this.strokeWidth;case T.Path:{let i=mt.getContext(),s=new Path2D(this.getSVGPathData());return i.lineWidth=Math.max(this.strokeWidth,2.5),i.stroke(s),this.closed?i.isPointInPath(s,t,e):i.isPointInStroke(s,t,e)}case T.Line:{let i=mt.getContext(),s=new Path2D(this.getSVGPathData());return i.lineWidth=Math.max(this.strokeWidth,2.5),i.stroke(s),i.isPointInStroke(s,t,e)}default:{let i=mt.getContext(),s=new Path2D(this.getSVGPathData());return i.isPointInPath(s,t,e)}}}toJSON(){let t={};t.type=this.type,t.id=this.id,this.classId&&(t.classId=this.classId),this._dataScope&&(t.dataScope=this._dataScope.toJSON()),t.args={};for(let e in this.attrs)t.args[e]=this.attrs[e];for(let e in this.styles)e.indexOf("Color")>0&&this.styles[e]instanceof U?t.args[e]=this.styles[e].toJSON():t.args[e]=this.styles[e];return t}getScene(){let t=this;for(;t;){if(t.type==T.Scene)return t;t=t.parent}}set dataScope(t){this._dataScope=t}get dataScope(){return this._dataScope}duplicate(){let t=this.getScene().mark(this.type);return this.copyPropertiesTo(t),t.classId=this.classId,this._dataScope&&(t._dataScope=this._dataScope.clone()),t}_doTranslate(t,e){}set visibility(t){this.styles.visibility=t}get visibility(){return this.styles.visibility?this.styles.visibility:"visible"}get opacity(){return"opacity"in this.styles?this.styles.opacity:1}set opacity(t){this.styles.opacity=t}}function J(t){return t>=-1e-12&&t<=1e-12}class Y{constructor(t,e){this.x=t,this.y=e}transform(t){return t?t._transformPoint(this):this}negate(){return new Y(-this.x,-this.y)}subtract(t){return new Y(this.x-t.x,this.y-t.y)}isZero(){return J(this.x)&&J(this.y)}isCollinear(t){let e=this.x,i=this.y,s=t.x,n=t.y;return Math.abs(e*n-i*s)<=1e-8*Math.sqrt((e*e+i*i)*(s*s+n*n))}}class H{constructor(t,e,i){this.type="vertex",this._id=i,this.x=t.x,this.y=t.y,this.dataScope=void 0,this.parent=e,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 bounds(){switch(this.shape){case"rect":return new a(this.x-this.width/2,this.y-this.height/2,this.width,this.height);case"circle":return new a(this.x-this.radius,this.y-this.radius,2*this.radius,2*this.radius);default:return new a(this.x-.5,this.y-.5,1,1)}}get id(){return this.parent.id+"_v_"+this._id}toJSON(){let t={};return t.type=this.type,t.id=this._id,t.x=this.x,t.y=this.y,this.dataScope&&(t.dataScope=this.dataScope.toJSON()),void 0!==this._polarAngle&&(t.polarAngle=this._polarAngle),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}static fromJSON(t,e){let i=new H(t,e,t.id);return t.dataScope&&(i.dataScope=t.dataScope),"polarAngle"in t&&(i.polarAngle=t.polarAngle),i.shape=t.shape,i.width=t.width,i.height=t.height,i.radius=t.radius,i.fillColor=t.fillColor,i.opacity=t.opacity,i.strokeWidth=t.strokeWidth,i.strokeColor=t.strokeColor,i}_doTranslate(t,e){this.x+=t,this.y+=e}_clone(t){let e=new H(new Y(this.x,this.y),t,this._id);return this.dataScope&&(e.dataScope=this.dataScope.clone()),e.shape=this.shape,e.width=this.width,e.height=this.height,e.radius=this.radius,e.fillColor=this.fillColor,e.opacity=this.opacity,e.strokeWidth=this.strokeWidth,e.strokeColor=this.strokeColor,e}set polarAngle(t){this._polarAngle=t}get polarAngle(){return this._polarAngle}}H.styles=["vxShape","vxWidth","vxHeight","vxRadius","vxFillColor","vxStrokeColor","vxStrokeWidth","vxOpacity"];class ${constructor(t,e,i,s){this.type="segment",this._id=s,this.vertex1=t,this.vertex2=e,this.dataScope=void 0,this.parent=i}get id(){return this.parent.id+"_s_"+this._id}_doTranslate(t,e){this.vertex1._doTranslate(t,e),this.vertex2._doTranslate(t,e)}get x(){return(this.vertex1.x+this.vertex2.x)/2}get y(){return(this.vertex1.y+this.vertex2.y)/2}}class Z extends q{constructor(t){if(super(t),this.type="type"in t?t.type:T.Path,"strokeColor"in this.styles||(this.styles.strokeColor="#ccc"),"strokeWidth"in this.styles||(this.styles.strokeWidth=1),"strokeDash"in this.styles||(this.styles.strokeDash="none"),this.vertices=[],this.vertexCounter=0,this.segmentCounter=0,this.segments=[],this.anchor=void 0,this.closed=!1,this.curveMode="linear",this.boundsOffsets={top:0,bottom:0,left:0,right:0},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,void 0!==t){for(let e of H.styles)e in t&&(this["_"+e]=t[e]);"vertices"in t&&this._setVertices(t.vertices)}}toJSON(){let t=super.toJSON();switch(t.type=this.type,t.id=this.id,this.type){case T.Rect:t.args.width=this.width,t.args.height=this.height,t.args.top=this.top,t.args.left=this.left;break;case T.Circle:t.args.x=this.x,t.args.y=this.y,t.args.radius=this.radius;break;case T.Arc:case T.Pie:t.args.x=this._x,t.args.y=this._y,t.args.innerRadius=this._innerRadius,t.args.outerRadius=this._outerRadius,t.args.startAngle=this._startAngle,t.args.endAngle=this._endAngle;break;default:t.vertices=[];for(let e of this.vertices)t.vertices.push(e.toJSON());this.type===T.Polygon?(t.args.x=this._x,t.args.y=this._y,t.args.radius=this._radius):this.type===T.Area&&(t.args.baseline=this._baseline,t.args.orientation=this._orientation)}t.vertexCounter=this.vertexCounter,t.segmentCounter=this.segmentCounter,t.curveMode=this.curveMode,this._bounds&&(t.bounds=this._bounds.toJSON()),t.boundsOffsets=this.boundsOffsets;for(let e of H.styles)t.args[e]=this[e];return t}_setVertices(t){let e,i;this.vertices=[],this.segments=[];for(let s=0;s<t.length;s++)if(s!=t.length-1||t[s][0]!==t[0][0]||t[s][1]!==t[0][1]||this.type!==T.Path){i=new Y(t[s][0],t[s][1]),e=new H(i,this,this.vertexCounter++);for(let t of H.styles)if(this[t]){let i=t.replace("vx","");e[i[0].toLowerCase()+i.slice(1)]=this[t]}this.vertices.push(e),s>0&&this.segments.push(new $(this.vertices[s-1],this.vertices[s],this,this.segmentCounter++))}let s=t[0],n=t[t.length-1];(s[0]===n[0]&&s[1]===n[1]||this.type===T.Rect)&&(this.closed=!0,"fillColor"in this.styles||(this.styles.fillColor="#fff"),this.segments.push(new $(this.vertices[this.vertices.length-1],this.vertices[0],this,this.segmentCounter++)))}copyPropertiesTo(t){t.attrs=Object.assign({},this.attrs),t.styles=Object.assign({},this.styles);for(let e of H.styles)this["_"+e]&&(t["_"+e]=this["_"+e]);this._dataScope&&(t._dataScope=this._dataScope.clone()),t.closed=this.closed,t.curveMode=this.curveMode,t.vertices=[],t.segments=[];for(let e of this.vertices)t.vertices.push(e._clone(t));t.segmentCounter=0;for(let e=1;e<t.vertices.length;e++)t.segments.push(new $(t.vertices[e-1],t.vertices[e],t,t.segmentCounter++));t.closed&&t.segments.push(new $(t.vertices[t.vertices.length-1],t.vertices[0],t,t.segmentCounter++))}get bounds(){return this._bounds||this._updateBounds(),this._bounds}get refBounds(){this._bounds||this._updateBounds();let t=this._bounds.bottom+this.boundsOffsets.bottom-(this._bounds.top-this.boundsOffsets.top),e=this._bounds.right+this.boundsOffsets.right-(this._bounds.left-this.boundsOffsets.left);return new a(this._bounds.left-this.boundsOffsets.left,this._bounds.top-this.boundsOffsets.top,e,t)}get x(){return this.bounds.x}get y(){return this.bounds.y}get strokeColor(){return this.styles.strokeColor}set strokeColor(t){this.styles.strokeColor=t}get strokeWidth(){return this.styles.strokeWidth}set strokeWidth(t){this.styles.strokeWidth=t}get fillColor(){return this.styles.fillColor}set fillColor(t){this.styles.fillColor=t}get strokeDash(){return this.styles.strokeDash}set strokeDash(t){this.styles.strokeDash=t}_doTranslate(t,e){for(let i of this.vertices)i._doTranslate(t,e);this._updateBounds()}resize(t,e,i,s){let n=this.bounds,r=0===n.width?1:n.width,a=0===n.height?1:n.height;if("right"===i)for(let e of this.vertices)e.x=n.right-t/r*(n.right-e.x);else for(let e of this.vertices)e.x=n.left+t/r*(e.x-n.left);if("top"===s)for(let t of this.vertices)t.y=n.top+e/a*(t.y-n.top);else for(let t of this.vertices)t.y=n.bottom-e/a*(n.bottom-t.y);this._updateBounds()}_updateBounds(){let t=this.vertices.map((t=>t.x)),e=this.vertices.map((t=>t.y)),i=Math.min(...t),s=Math.min(...e),n=Math.max(...t),r=Math.max(...e);this._bounds=new a(i,s,n-i,r-s)}addVertex(t,e,i){let s=new H(new Y(t,e),this,this.vertexCounter++);this.vertices.splice(i,0,s)}sortVertices(t,e){this.vertices.sort(((e,i)=>e[t]-i[t])),e&&this.vertices.reverse();for(let t=0;t<this.segments.length;t++){let e=this.segments[t];e.vertex1=this.vertices[t],e.vertex2=this.vertices[(t+1)%this.vertices.length]}}sortVerticesByData(t,e,i){let s;s=i?(e,s)=>i.indexOf(e.dataScope.getFieldValue(t))-i.indexOf(s.dataScope.getFieldValue(t)):(e,i)=>e.dataScope.getFieldValue(t)<i.dataScope.getFieldValue(t)?-1:1,this.vertices.sort(s),e&&this.vertices.reverse();for(let t=0;t<this.segments.length;t++){let e=this.segments[t];e.vertex1=this.vertices[t],e.vertex2=this.vertices[(t+1)%this.vertices.length]}}getSVGPathData(){let t=n.path(),e=this._getD3CurveFunction(this.curveMode)(t);e.lineStart();for(let t of this.vertices)e.point(t.x,t.y);return this.closed&&e.point(this.vertices[0].x,this.vertices[0].y),e.lineEnd(),t._}get firstVertex(){return this.vertices[0]}get firstSegment(){return this.segments[0]}get lastVertex(){return this.vertices[this.vertices.length-1]}get lastSegment(){return this.segments[this.segments.length-1]}_getD3CurveFunction(t){switch(t){case c:return n.curveNatural;case d:return n.curveBasis;case u:return n.curveBumpX;case f:return n.curveBumpY;case p:return n.curveLinear;case g:return n.curveStep;case _:return n.curveCatmullRom;case m:return n.curveCardinal;default:return n.curveLinear}}get vxShape(){return this._vxShape}set vxShape(t){this._vxShape=t;for(let e of this.vertices)e.shape=t}get vxWidth(){return this._vxWidth}set vxWidth(t){this._vxWidth=t;for(let e of this.vertices)e.width=t}get vxHeight(){return this._vxHeight}set vxHeight(t){this._vxHeight=t;for(let e of this.vertices)e.height=t}get vxRadius(){return this._vxRadius}set vxRadius(t){this._vxRadius=t;for(let e of this.vertices)e.radius=t}get vxFillColor(){return this._vxFillColor}set vxFillColor(t){this._vxFillColor=t;for(let e of this.vertices)e.fillColor=t}get vxStrokeColor(){return this._vxStrokeColor}set vxStrokeColor(t){this._vxStrokeColor=t;for(let e of this.vertices)e.strokeColor=t}get vxStrokeWidth(){return this._vxStrokeWidth}set vxStrokeWidth(t){this._vxStrokeWidth=t;for(let e of this.vertices)e.strokeWidth=t}get vxOpacity(){return this._vxOpacity}set vxOpacity(t){this._vxOpacity=t;for(let e of this.vertices)e.opacity=t}}function K(t,e){if("field"in e){if(!t.dataScope)return!1;let i=e.field;if("value"in e)return t.dataScope.getFieldValue(i)===e.value;if("interval"in e){let s=t.dataScope.getFieldValue(i);return s>=e.interval[0]&&s<=e.interval[1]}return"values"in e?e.values.indexOf(t.dataScope.getFieldValue(i))>=0:t.dataScope.hasField(i)}if("channel"in e){let i=e.channel;if("value"in e)return t[i]===e.value;if("interval"in e)return t[i]>=e.interval[0]&&t[i]<=e.interval[1];if("values"in e)return e.values.indexOf(t[i])>=0}else{if("type"in e)return t.type===e.type;if("id"in e)return t.id===e.id;if("classId"in e)return t.classId===e.classId;if("fields"in e){if(!t.dataScope)return!1;let i=e.fields[0],s=e.fields[1],n=t.dataScope.getFieldValue(i),r=t.dataScope.getFieldValue(s);switch(e.operator){case"==":return n==r;case">":return n>r;case">=":return n>=r;case"<":return n<r;case"<=":return n<=r}}}return!1}function X(t,e){let i=[];return Q(t,e,i),i}function Q(t,e,i){if(t&&"axis"!=t.type&&"legend"!=t.type&&"gridlines"!=t.type)if(tt(t,e)&&i.push(t),t.vertices)for(let s of t.vertices.concat(t.segments))tt(s,e)&&i.push(s);else if(t.children&&t.children.length>0)for(let s of t.children)Q(s,e,i)}function tt(t,e){for(let i of e)if(!K(t,i))return!1;return!0}function et(t,e){return"vertex"==t.type?function(t,e){if(!t.classId){if(t.dataScope){let i=t.parent;if(!i)throw new Error("vertex has no parent mark");let s=X(e,[{classId:i.classId}]),n=[];if(i.type===T.Area){let e=i.vertices.indexOf(t)<i.vertices.length/2;for(let t of s){let i=e?t.vertices.slice(0,t.vertices.length/2):t.vertices.slice(t.vertices.length/2);n=n.concat(i.filter((t=>t.dataScope)))}}else for(let t of s)n=n.concat(t.vertices.filter((t=>t.dataScope)));return n}{let i=t.parent;if(!i)throw new Error("vertex has no parent mark");let s=i.vertices.indexOf(t),n=X(e,[{classId:i.classId}]),r=[];for(let t of n)r.push(t.vertices[s]);return r}}}(t,e):"segment"==t.type?function(t,e){if(t.dataScope){let i=t.parent;if(!i)throw new Error("segment has no parent mark");let s=X(e,[{classId:i.classId}]),n=[];for(let t of s)n=n.concat(t.segments);return n}{let i=t.parent;if(!i)throw new Error("segment has no parent mark");let s=i.segments.indexOf(t),n=X(e,[{classId:i.classId}]),r=[];for(let t of n)r.push(t.segments[s]);return r}}(t,e):t.classId?X(e,[{classId:t.classId}]):[]}function it(t,e){let i=t.parent;for(;i&&i.type!=T.Scene;){if(i.layout&&(!e||e&&i.layout.type===e))return i.layout;i=i.parent}}function st(t){let e=t,i=t.parent;for(;i&&i.type!=T.Scene;){if(i.layout){let t=i.children.findIndex((t=>t==e));return i.layout.cellBounds[t]}e=e.parent,i=e.parent}}function nt(t){let e=t,i=t.parent;for(;i&&i.type!=T.Scene;){if(i.layout&&i.layout.type==y.Grid){let t=i.children.findIndex((t=>t==e));return i.layout.cellBounds[t]}e=e.parent,i=e.parent}}function rt(t,e){let i,s=t.parent;for(;s&&s.type!==T.Scene;)s.layout&&(!e||e&&s.layout.type===e)&&(i=s.layout),s=s.parent;return i}function at(t){if(t.classId)return t.classId;if("vertex"==t.type&&t.dataScope){if(t.parent.type===T.Area){let e=t.parent.vertices.indexOf(t)<t.parent.vertices.length/2;return t.parent.classId+"_v_"+(e?0:t.parent.vertices.length-1)}return t.parent.classId+"_v"}return"vertex"==t.type?t.parent.classId+"_v_"+t.parent.vertices.indexOf(t):"segment"==t.type&&t.dataScope?t.parent.classId+"_s":"segment"==t.type?t.parent.classId+"_s_"+t.parent.segments.indexOf(t):null}function ot(t){let e=[];for(let i of t)i.parent&&e.indexOf(i.parent)<0&&e.push(i.parent);return e}function ht(t){let e=[];if(t.children&&t.children.length>0)for(let i of t.children)e.push(i),e=e.concat(ht(i));return e}function lt(t){let e=[];if(ut(t))e.push(t);else if(t.children&&t.children.length>0&&!dt(t))for(let i of t.children)e=e.concat(lt(i));return e}function ct(t){let e=[];if(t.children&&t.children.length>0)for(let i of t.children)e=e.concat(ct(i));else e.push(t);return e}function dt(t){return t.type===T.Axis||t.type===T.Legend||t.type===T.Gridlines}function ut(t){return t instanceof q}function ft(t){return t instanceof Z}const pt={area:0,rect:0,circle:0,pie:0,line:0,path:0,ring:0,arc:0,image:0,pointText:0,collection:0,group:0,scene:0,axis:0,glyph:0,legend:0,polygon:0,gridlines:0,LinearGradient:0,link:0,scale:0,datatable:0};function gt(t,e){if(e.getEncodingByItem(t,"x"))return!1;if(t.parent&&t.parent.layout){let e=t.parent.layout;if(e.type==y.Grid&&e.numCols>1)return!1}return!t.parent||t.parent.type==T.Scene||gt(t.parent,e)}function _t(t,e){if(e.getEncodingByItem(t,"y"))return!1;if(t.parent&&t.parent.layout){let e=t.parent.layout;if(e.type==y.Grid&&e.numRows>1)return!1}return!t.parent||t.parent.type==T.Scene||_t(t.parent,e)}var mt={canvas:void 0,getCanvas:function(){return window?(void 0===this.canvas&&(this.canvas=document.createElement("canvas")),this.canvas):null},getContext:function(){var t=this.getCanvas();return t?t.getContext("2d"):null}},yt={svg:void 0,getSVG:function(){return window?(void 0===this.svg&&(this.svg=document.createElement("svg")),this.svg):null}};function vt(t){let e=t.parent;return e.type==T.Scene?t:vt(e)}function bt(t){let e=t.parent;return t.type==T.Collection?e.type==T.Collection?bt(e):t:e.type!=T.Scene?bt(e):void 0}function xt(t,e,i,s){return[i*Math.cos(kt(s))+t,e-i*Math.sin(kt(s))]}function wt(t,e,i,s){let n=function(t){return 180*t/Math.PI}(Math.atan2(s-e,t-i));n=Math.round(10*n+Number.EPSILON)/10,n<0&&(n+=360);let r=Math.sqrt(Math.pow(t-i,2)+Math.pow(e-s,2));return r=Math.round(10*r+Number.EPSILON)/10,[n,r]}function kt(t){return t*Math.PI/180}function Ct(t){let e=t.vertices.length;for(let i=0;i<t.vertices.length/2;i++){let s=i,n=e-i-1,r=t.vertices[s],a=t.vertices[n];if(r.x!=a.x||r.y!=a.y)return r.x==a.x?"horizontal":"vertical"}}class St{constructor(){this.children=[],this._dataScope=void 0,this._layout=void 0,this.type=T.Group,this._id=this.type+pt[this.type]++}get id(){return this._id}set id(t){this.type!==T.Scene&&this.getScene()?(delete this.getScene()._itemMap[this._id],this._id=t,this.getScene()._itemMap[t]=this):this._id=t}contains(t,e){return this._bounds||this._updateBounds(),this._bounds.contains(t,e)}toJSON(){let t={};if(t.type=this.type,t.id=this.id,this._dataScope&&(t.dataScope=this._dataScope.toJSON()),this.classId&&(t.classId=this.classId),this._layout&&(t.layout=this._layout.toJSON()),this._bounds&&(t.bounds=this._bounds.toJSON()),t.children=[],this.children.length>0&&this.type!=T.Axis)for(let e of this.children)t.children.push(e.toJSON());return this.childrenOrder&&(t.childrenOrder=this.childrenOrder),t}addChild(t){this.children.indexOf(t)>=0||(t.parent&&t.parent.removeChild(t),this.children.push(t),t.parent=this)}addChildAt(t,e){t.parent&&t.parent.removeChild(t),this.children.splice(e,0,t),t.parent=this}removeChild(t){let e=this.children.indexOf(t);e>=0&&(this.children.splice(e,1),t.parent=null)}removeChildAt(t){this.children[t].parent=null,this.children.splice(t,1)}removeAll(){for(let t of this.children)t.parent=null;this.children=[]}getScene(){let t=this;for(;t;){if(t.type==T.Scene)return t;t=t.parent}}get dataScope(){return this._dataScope}set dataScope(t){if(this._dataScope=t,void 0===t)for(let e of this.children)e.dataScope=t;else for(let e of this.children)e.dataScope?e.dataScope=e.dataScope.merge(t):e.dataScope=t}_doTranslate(t,e){for(let i of this.children)i._doTranslate(t,e);this._updateBounds(),this._layout&&(void 0!==this._layout._left&&(this._layout._left+=t),void 0!==this._layout._top&&(this._layout._top+=e),void 0!==this._layout.x&&(this._layout.x+=t),void 0!==this._layout.y&&(this._layout.y+=e)),this._updateBounds()}getInternalEncodings(t){if(0==this.children.length)return[];let e=this.children[0],i=this.getScene(),s=Object.keys(i.encodings),n=[];for(;e&&(e.classId&&n.indexOf(e.classId)<0&&n.push(e.classId),e.children);)e=e.children[0];let r=[];for(let e of s){let s=e.split("_");for(let a of n)s[0]==a&&i.encodings[e][t]&&r.push(i.encodings[e][t])}return r}get firstChild(){return this.children[0]}get lastChild(){return this.children[this.children.length-1]}set layout(t){if(this._layout=t,t)t.group=this,this._layout.run();else{let t=this.getInternalEncodings("x"),e=this.getInternalEncodings("y");for(let e of t)e._map(),e._apply();for(let t of e)t._map(),t._apply()}}get layout(){return this._layout}get bounds(){return this._bounds||this._updateBounds(),this._bounds}get refBounds(){let t=this.children.map((t=>t.refBounds)),e=Math.min(...t.map((t=>t.left))),i=Math.min(...t.map((t=>t.top))),s=Math.max(...t.map((t=>t.right))),n=Math.max(...t.map((t=>t.bottom)));return new a(e,i,s-e,n-i)}get x(){return this.bounds.x}get y(){return this.bounds.y}_updateBounds(){if(this.children.length>0){this._bounds=this.children[0].bounds.clone();for(let t=1;t<this.children.length;t++)"hidden"!=this.children[t].visibility&&(this._bounds=this._bounds.union(this.children[t].bounds));if(this._layout&&"grid"==this._layout.type){let t=this._layout.cellBounds;for(let e=0;e<t.length;e++)this._bounds=this._bounds.union(t[e])}}else this._bounds=new a(0,0,0,0)}sortChildrenByData(t,e,i){let s;switch(this.children[0].dataScope.getFieldType(t)){case A.Date:break;case A.Number:case A.Integer:s=(e,i)=>e.dataScope.aggregateNumericalField(t)-i.dataScope.aggregateNumericalField(t);break;case A.String:s=i?(e,s)=>i.indexOf(e.dataScope.getFieldValue(t))-i.indexOf(s.dataScope.getFieldValue(t)):(e,i)=>e.dataScope.getFieldValue(t)<i.dataScope.getFieldValue(t)?-1:1}this.children.sort(s),e&&this.children.reverse(),this.layout&&this.layout.run(),this._childrenOrder={field:t,direction:e?"desc":"asc",ranking:i}}sortChildren(t,e){let i;switch(t){case"x":case"y":case"width":case"height":i=(e,i)=>e.bounds[t]-i.bounds[t];break;default:i=(e,i)=>e[t]-i[t]}this.children.sort(i),e&&this.children.reverse(),this.layout&&this.layout.run(),this.childrenOrder={channel:t,reverse:e}}set visibility(t){this._visibility="hidden"==t?t:"visible";for(let e of this.children)e.visibility=t}get visibility(){return this._visibility?this._visibility:"visible"}}function Et(t){return[...new Set(t)]}function Tt(t,e){if(e.hasField(t))return!0;if(e.tree&&e.tree.nodeTable.hasField(t.split(".")[1]))return!0;throw new Error(G.FIELD_NONEXISTENT+", field: "+t+", data table: "+e.name)}function At(t){return t<0?t+360:t>360?t-360:t}class It{constructor(t){this._field2value={},this._dt=t,this._tuples=this._dt.data}toJSON(){let t={};return t.dt=this._dt.id,t.f2v=Object.assign({},this._field2value),t}isFullTable(){return 0===Object.keys(this._field2value).length}isEmpty(){return 0==this._tuples.length}get numTuples(){return this._tuples.length}get fields(){return Object.keys(this._field2value)}get dataTable(){return this._dt}get filters(){return this._field2value}merge(t){let e=new It(this._dt);for(let i in t._field2value)e=e.cross(i,t._field2value[i]);for(let t in this._field2value)e=e.cross(t,this._field2value[t]);return e}cross(t,e){let i=this.clone();return i._field2value[t]=e,i._updateTuples(t,e),i}clone(){let t=new It(this._dt);return t._field2value=Object.assign({},this._field2value),t._tuples=this._tuples.map((t=>t)),t}getFieldValue(t){let e=this._tuples.map((e=>e[t]));return e=[...new Set(e)],e.length,e[0]}getUniqueFieldValues(t){let e=this._tuples.map((e=>e[t]));return[...new Set(e)]}hasField(t){return t in this._field2value}getFieldType(t){return this._dt.getFieldType(t)}aggregateNumericalField(t,e){let i=this._tuples.map((e=>e[t]));switch(e){case I:return Math.max(...i);case O:return Math.min(...i);case M:case P:return n.mean(i);case R:return n.median(i);case F:return i.length;case B:return n.quantile(i,.25);case L:return n.quantile(i,.75);case N:default:return n.sum(i)}}_updateTuples(t,e){this._tuples=this._tuples.filter((i=>i[t]==e))}}function Ot(t,e,i,s,n){let r=n?s.transformField(i,n):i,a=s.getFieldType(r);if(a!=A.String&&a!=A.Date&&a!=A.Integer)throw new Error(G.REPEAT_BY_NONCAT+": "+r+" is "+a);if(!Xc(e))throw new Error(G.COMPNT_NON_REPEATABLE);return function(t,e,i,s){let n=s.getFieldSummary(i).unique.map((t=>e.dataScope?e.dataScope.cross(i,t):new It(s).cross(i,t)));n=n.filter((t=>!t.isEmpty()));let r=t.collection();r.dataScope=e.dataScope?e.dataScope.clone():new It(s),r.addChild(e);for(let t=1;t<n.length;t++){let t=e.duplicate();r.addChild(t)}return r.children.forEach(((t,e)=>t.dataScope=n[e])),t._reapplySizeBindings(e),r}(t,e,r,s)}class Mt extends z{constructor(t){super(t),this.type=y.Stack,this._orientation=t.orientation,this._direction=t.direction,this._left=t.left,this._top=t.top,this._horzCellAlignment="horzCellAlignment"in t&&t.horzCellAlignment?t.horzCellAlignment:C.Left,this._vertCellAlignment="vertCellAlignment"in t&&t.vertCellAlignment?t.vertCellAlignment:C.Bottom,this._gap="gap"in t?t.gap:0}toJSON(){let t={args:{}};return t.type=this.type,t.args.orientation=this._orientation,t.args.direction=this._direction,t.args.left=this._left,t.args.top=this._top,t.args.gap=this._gap,t.args.horzCellAlignment=this._horzCellAlignment,t.args.vertCellAlignment=this._vertCellAlignment,t}clone(){let t=new Mt({orientation:this._orientation,direction:this._direction,left:this._left,top:this._top});return t._horzCellAlignment=this._horzCellAlignment,t._vertCellAlignment=this._vertCellAlignment,t}_stackAreasVert(){let t=this.group.children,e=this.group.bounds,i=this._vertCellAlignment===C.Top?e.top:e.bottom,s=this._vertCellAlignment===C.Top?1:-1,n=t[0].vertices.length/2,r=new Array(n).fill(0);for(let e of t){for(let t=0;t<n;t++){let a=e.vertices[t],o=e.vertices[2*n-t-1],h=Math.abs(a.y-o.y),l=i+r[t]*s,c=i+(r[t]+h)*s;a._doTranslate(0,l-a.y),o._doTranslate(0,c-o.y),r[t]+=h}e._updateBounds()}if(this.vertCellAlignment===C.Middle)for(let i of t){for(let t=0;t<n;t++){let s=i.vertices[t],a=i.vertices[2*n-t-1],o=e.middle+r[t]/2;s._doTranslate(0,o-e.bottom),a._doTranslate(0,o-e.bottom)}i._updateBounds()}this.group._updateBounds()}_stackAreasHorz(){let t=this.group.children,e=this.group.bounds,i=this._horzCellAlignment===C.Right?e.right:e.left,s=this._horzCellAlignment===C.Right?-1:1,n=t[0].vertices.length/2,r=new Array(n).fill(0);for(let e of t){for(let t=0;t<n;t++){let a=e.vertices[t],o=e.vertices[2*n-t-1],h=Math.abs(a.x-o.x),l=i+r[t]*s,c=i+(r[t]+h)*s;a._doTranslate(0,l-a.y),o._doTranslate(0,c-o.y),r[t]+=h}e._updateBounds()}if(this._horzCellAlignment===C.Center)for(let i of t){for(let t=0;t<n;t++){let s=i.vertices[t],a=i.vertices[2*n-t-1],o=e.center-r[t]/2;s._doTranslate(0,o-e.left),a._doTranslate(0,o-e.left)}i._updateBounds()}this.group._updateBounds()}_stackAreas(){this.group.children[0].orientation===b?this._stackAreasVert():this._stackAreasHorz()}_stackArcs(){let t=this.group,e=this.startAngle?this.startAngle:90;if((this._direction?this._direction:k.Clockwise)===k.Clockwise)for(let i of t.children){let t=At(e-i.angle);i.adjustAngle(t,e),e=t}else for(let i of t.children){let t=At(e+i.angle);i.adjustAngle(e,t),e=t}}_stackRects(){let t=this.group.getScene(),e=this.group,i=this._orientation,s=e.children.map((t=>t.bounds)),n=s.map((t=>t.left)),r=s.map((t=>t.top)),a=s.map((t=>t.width)),o=s.map((t=>t.height)),h=null==this._left?Math.min(...n):this._left,l=null==this._top?Math.min(...r):this._top,c=Math.max(...a),d=Math.max(...o);if(i==v){let i=h+c/2;for(let s=0;s<e.children.length;s++){let n=e.children[s],r=i-n.bounds.x,a=l+n.bounds.height/2-n.bounds.y;l+=n.bounds.height+this._gap,n._doTranslate(r,a);let o=0,d=0;if(!t.getEncodingByItem(n,"x"))switch(this._horzCellAlignment){case C.Left:o=h-n.bounds.left;break;case C.Center:o=h+c/2-n.bounds.x;break;case C.Right:o=h+c-n.bounds.right}n._doTranslate(o,d)}}else{let i=l+d/2;for(let s=0;s<e.children.length;s++){let n=e.children[s],r=h+n.bounds.width/2-n.bounds.x,a=i-n.bounds.y;h+=n.bounds.width+this._gap,n._doTranslate(r,a);let o=0,c=0;if(!t.getEncodingByItem(n,"y"))switch(this._vertCellAlignment){case C.Top:c=l-n.bounds.top;break;case C.Middle:c=l+d/2-n.bounds.y;break;case C.Bottom:c=l+d-n.bounds.bottom}n._doTranslate(o,c)}}this.group._updateBounds()}run(){null!=this.group&&this.group.children&&0!==this.group.children.length&&("area"==this.group.children[0].type?this._stackAreas():this.group.children[0].type==T.Arc||this.group.children[0].type==T.Pie?this._stackArcs():this._stackRects())}set vertCellAlignment(t){if(t!=C.Top&&t!=C.Bottom&&t!=C.Middle)throw G.UNKOWN_ALIGNMENT;this._vertCellAlignment=t,this.run()}get vertCellAlignment(){return this._vertCellAlignment}set horzCellAlignment(t){if(t!=C.Left&&t!=C.Center&&t!=C.Right)throw G.UNKOWN_ALIGNMENT;this._horzCellAlignment=t,this.run()}get horzCellAlignment(){return this._horzCellAlignment}get cellBounds(){return this.group.children.map((t=>t.bounds))}get orientation(){return this._orientation}set orientation(t){this._orientation=t,this.run()}}function Rt(t,e,i,s,n,r){let a=r?n.transformField(s,r):s,o=n.getFieldType(a);if(o!=A.String&&o!=A.Date)throw new Error(G.PARTITION_BY_NONCAT+": "+a+" is "+o);if(!Qc(e))throw new Error(G.COMPNT_NON_PARTITIONABLE);switch(e.type){case T.Line:return function(t,e,i,s){let n,r,a=et(e,t),o=s.getFieldSummary(i).unique.map((t=>new It(s).cross(i,t))),h={},l=0;for(let t of a){let e=o;t.dataScope&&(e=o.map((e=>e.merge(t.dataScope))),e=e.filter((t=>!t.isEmpty()))),e.length>l&&(l=e.length),h[t.id]=e}for(let i of a){let s=t.collection();null==r&&(r=s.id),s.classId=r,s.dataScope=i.dataScope;let a=i.parent;a.addChild(s);let o=h[i.id],c=i.vertices[0].x,d=i.vertices[0].y,u=i.vertices[1].x,f=i.vertices[1].y;for(let t=0;t<o.length;t++){let n=i.duplicate();n.classId=e.id,n.vertices[0].x=c+(u-c)*t/l,n.vertices[0].y=d+(f-d)*t/l,n.vertices[1].x=c+(u-c)*(t+1)/l,n.vertices[1].y=d+(f-d)*(t+1)/l,n.dataScope=o[t],s.addChild(n)}a.removeChild(i),i==e&&(n=s)}return n}(t,e,a,n);case T.Circle:return function(t,e,i,s,n){let r,a,o=i||x,h=et(e,t);if(o==x)h.forEach((i=>{let o=i.dataScope?i.dataScope:new It(n),h=n.getFieldSummary(s).unique.map((t=>o.cross(s,t)));h=h.filter((t=>!t.isEmpty()));let l=h.length,c=t.collection();c.dataScope=o,null==a&&(a=c.id),c.classId=a;let d=i.parent,u=360/l,f=90;for(let s=0;s<l;s++){let n=t.mark("pie",{innerRadius:0,outerRadius:i.radius,x:i.x,y:i.y,startAngle:At(f-u*(s+1)),endAngle:At(f-u*s),strokeColor:i.strokeColor,fillColor:i.styles.fillColor});n.dataScope=h[s],n.classId=e.id,c.addChild(n)}c.layout=Hc("stack",{orientation:x,direction:k.Clockwise}),d.removeChild(i),d.addChild(c),i==e&&(r=c)}));else{if(o!=w)throw G.UNKNOWN_Orientation+": "+o;h.forEach((i=>{let o=i.dataScope?i.dataScope:new It(n),h=n.getFieldSummary(s).unique.map((t=>o.cross(s,t)));h=h.filter((t=>!t.isEmpty()));let l=h.length,c=t.collection();c.dataScope=o,null==a&&(a=c.id),c.classId=a;let d=i.parent,u=i.radius/l;for(let s=0;s<l;s++){let n=t.mark("ring",{x:i.x,y:i.y,innerRadius:s*u,outerRadius:(s+1)*u,strokeColor:i.strokeColor,fillColor:i.styles.fillColor});n.dataScope=h[s],n.classId=e.id,c.addChild(n)}d.removeChild(i),d.addChild(c),i==e&&(r=c)}))}return r}(t,e,i,a,n);case T.Rect:return function(t,e,i,s,n){let r,a=et(e,t),o=i||b;if(o!=b&&o!=v)throw G.UNKNOWN_Orientation+": "+o;let h,l=n.getFieldSummary(s).unique.map((t=>new It(n).cross(s,t))),c={},d=0;for(let t of a){let e=l;t.dataScope&&(e=l.map((e=>e.merge(t.dataScope))),e=e.filter((t=>!t.isEmpty()))),e.length>d&&(d=e.length),c[t.id]=e}for(let i of a){let s=t.collection();null==h&&(h=s.id),s.classId=h,s.dataScope=i.dataScope?i.dataScope:new It(n);let a=i.parent;a.addChild(s);let l=c[i.id],u=i.bounds,f=u.left,p=u.top,g=o==b?u.width/d:u.width,_=o==b?u.height:u.height/d;for(let t=0;t<l.length;t++){let n=i.duplicate();n.classId=e.id,n.resize(g,_),n.dataScope=l[t],s.addChild(n)}s.layout=new Mt({orientation:o,left:f,top:p}),a.removeChild(i),i==e&&(r=s)}return t._reapplySizeBindings(r),r}(t,e,i,a,n);case T.Area:return function(t,e,i,s,n){let r,a=et(e,t),o=a[0];if(4==o.vertices.length&&i==b&&o.vertices[0].x!==o.vertices[1].x)for(let t of a){let e=t.vertices[1];t.vertices[1]=t.vertices[3],t.vertices[3]=e}let h,l=n.getFieldSummary(s).unique.map((t=>new It(n).cross(s,t)));for(let s of a){let a=t.collection();null==h&&(h=a.id),a.classId=h,a.dataScope=s.dataScope?s.dataScope:new It(n);let o=s.parent;o.addChild(a);let c=s.left,d=s.top,u=i==b?s.width/l.length:s.width,f=i==b?s.height:s.height/l.length;for(let t=0;t<l.length;t++){let t=s.duplicate();t.classId=e.id,t.resizeArea(u,f),a.addChild(t)}o.removeChild(s);for(let t=0;t<a.children.length;t++){let e=a.children[t];e.dataScope?e.dataScope=e.dataScope.merge(l[t]):e.dataScope=l[t];for(let t of e.vertices)t.dataScope?t.dataScope=e.dataScope.merge(t.dataScope):t.dataScope=e.dataScope}a.layout=new Mt({orientation:i,left:c,top:d}),s==e&&(r=a)}return t._reapplySizeBindings(r),r}(t,e,i,a,n);case T.Ring:return function(t,e,i,s,n){let r,a,o=i||x,h=et(e,t);if(o==x)return h.forEach((i=>{let o=i.dataScope?i.dataScope:new It(n),h=n.getFieldSummary(s).unique.map((t=>o.cross(s,t)));h=h.filter((t=>!t.isEmpty()));let l=h.length,c=t.collection();c.dataScope=o,null==a&&(a=c.id),c.classId=a;let d=i.parent,u=360/l,f=90;for(let s=0;s<l;s++){let n=t.mark("arc",{innerRadius:i.innerRadius,outerRadius:i.outerRadius,x:i.x,y:i.y,startAngle:At(f-u*(s+1)),endAngle:At(f-u*s),strokeColor:i.strokeColor,fillColor:i.fillColor,strokeWidth:i.strokeWidth,opacity:i.opacity});n.dataScope=h[s],n.classId=e.id,c.addChild(n)}c.layout=Hc("stack",{direction:k.Clockwise}),d.removeChild(i),d.addChild(c),i==e&&(r=c)})),r;throw G.UNKNOWN_Orientation+": "+o}(t,e,i,a,n);case T.Pie:case T.Arc:return function(t,e,i,s,n){let r,a,o=i||w,h=et(e,t);if(o==w)return h.forEach((i=>{let o=i.dataScope?i.dataScope:new It(n),h=n.getFieldSummary(s).unique.map((t=>o.cross(s,t)));h=h.filter((t=>!t.isEmpty()));let l=h.length,c=t.collection();c.dataScope=o,null==a&&(a=c.id),c.classId=a;let d=i.parent;for(let s=0;s<l;s++){let n=t.mark("arc",{innerRadius:s*i.outerRadius/l,outerRadius:(s+1)*i.outerRadius/l,x:i.x,y:i.y,startAngle:i.startAngle,endAngle:i.endAngle,strokeColor:i.strokeColor,fillColor:i.fillColor,strokeWidth:i.strokeWidth,opacity:i.opacity});n.dataScope=h[s],n.classId=e.id,c.addChild(n)}d.removeChild(i),d.addChild(c),i==e&&(r=c)})),r;throw G.UNKNOWN_Orientation+": "+o}(t,e,i,a,n)}}function Nt(t,e,i,s,n,r,a,o){let h=r?n.transformField(s,r):s,l=n.getFieldType(h);if(l!=A.String&&l!=A.Date&&l!=A.Number)throw new Error(G.DENSIFY_BY_NONCAT+": "+h+" is "+l);if(!td(e))throw new Error(G.COMPNT_NON_DENSIFIABLE);switch(e.type){case T.Line:return function(t,e,i,s){let n,r=et(e,t);for(let a of r){let r=a.dataScope?a.dataScope:new It(s),o=s.getFieldSummary(i).unique.map((t=>r.cross(i,t)));o=o.filter((t=>!t.isEmpty()));let h=Object.assign({},a.styles);for(let t of H.styles)a[t]&&(h[t]=a[t]);let l=a.vertices[0].x,c=a.vertices[0].y,d=[],u=a.vertices[1].x-l,f=a.vertices[1].y-c;for(let t=0;t<o.length;t++)d.push([l+t*u/(o.length-1),c+t*f/(o.length-1)]);h.vertices=d;let p=t.mark("path",h);p.classId=e.id,p.dataScope=r;let g=a.parent;g.addChild(p),g.removeChild(a);for(let[t,e]of p.vertices.entries())e.dataScope?e.dataScope=e.dataScope.merge(o[t]):e.dataScope=o[t];a==e&&(n=p)}return n}(t,e,h,n);case T.Circle:return function(t,e,i,s,n,r){let a;return et(e,t).forEach((o=>{let h=o.dataScope?o.dataScope:new It(s),l=s.getFieldSummary(i).unique.map((t=>h.cross(i,t)));l=l.filter((t=>!t.isEmpty()));let c=l.length;if(c<3)throw Error(G.INSUFFICIENT_DATA_SCOPES);let d=360/c,u=[],f=[],p="clockwise"==r?-1:1;for(let t=0;t<l.length;t++){let e=n+p*t*d;f[t]=e;let i=xt(o.x,o.y,o.radius,f[t]);u.push(i)}let g=t.mark("polygon",{x:o.x,y:o.y,radius:o.radius,vertices:u});g.dataScope=h,g.styles=Object.assign({},o.styles);for(let t of H.styles)o[t]&&(g[t]=o[t]);let _=o.parent;_.addChild(g),_.removeChild(o);for(let[t,e]of g.vertices.entries())e.polarAngle=f[t],e.dataScope?e.dataScope=e.dataScope.merge(l[t]):e.dataScope=l[t];o==e&&(a=g)})),a}(t,e,h,n,a,o);case T.Rect:case T.Area:return function(t,e,i,s,n){let r,a=et(e,t);for(let o of a){let a=n.getFieldType(s),h=o.dataScope?o.dataScope:new It(n),l=n.getFieldSummary(s).unique.map((t=>h.cross(s,t)));l=a==A.Number?l:l.filter((t=>!t.isEmpty())),a!=A.Number&&a!=A.Date||l.sort(((t,e)=>t._field2value[s]>e._field2value[s]?1:-1));let c=Object.assign({},o.styles),d=o.vertices[0].x,u=o.vertices[0].y,f=o.vertices[o.vertices.length-2].x,p=o.vertices[o.vertices.length-2].y,g=[],_=f-d,m=p-u;for(let t=0;t<l.length;t++)g.push(i==v?[f,u+(l.length-1-t)*m/(l.length-1)]:[d+t*_/(l.length-1),u]);for(let t=0;t<l.length;t++)g.push(i==v?[d,u+t*m/(l.length-1)]:[d+(l.length-1-t)*_/(l.length-1),p]);c.vertices=g;let y=t.mark("area",c);y.classId="area"==o.type?o.classId:"area"+o.classId.substring(9),y.dataScope=h,y.orientation=i,y.baseline=i===b?C.Bottom:C.Left;let x=o.parent;x.addChild(y),x.removeChild(o);for(let[t,e]of y.vertices.entries())t>=l.length?e.dataScope=h.merge(l[2*l.length-1-t]):e.dataScope=h.merge(l[t]);o==e&&(r=y)}return r}(t,e,i,h,n)}}class Ft extends Z{constructor(t){super(t)}get width(){return this.vertices[1].x-this.vertices[0].x}get height(){return this.vertices[2].y-this.vertices[1].y}set height(t){this.resize(this.width,t)}set width(t){this.resize(t,this.height)}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(t,e,i,s){"right"===i?(this.vertices[0].x=this.vertices[1].x-t,this.vertices[3].x=this.vertices[0].x):(this.vertices[1].x=this.vertices[0].x+t,this.vertices[2].x=this.vertices[1].x),"top"===s?(this.vertices[3].y=this.vertices[0].y+e,this.vertices[2].y=this.vertices[3].y):(this.vertices[0].y=this.vertices[3].y-e,this.vertices[1].y=this.vertices[0].y),this._updateBounds()}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 Pt extends Z{constructor(t){super(t),this.attrs.x="x"in t?t.x:0,this.attrs.y="y"in t?t.y:0,this.attrs.radius="radius"in t?t.radius:100}get radius(){return this.attrs.radius}get x(){return this.attrs.x}get y(){return this.attrs.y}get area(){return Math.PI*Math.pow(this.radius,2)}set x(t){this.attrs.x=t,this._updateBounds()}set y(t){this.attrs.y=t,this._updateBounds()}set radius(t){this.attrs.radius=t,this._updateBounds()}resize(t,e,i,s){let n=Math.min(t,e)/2,r=n-this.attrs.radius;this.attrs.radius=n,"right"==i?this.attrs.x-=r:this.attrs.x+=r,"top"==s?this.attrs.y+=r:this.attrs.y-=r,this._updateBounds()}_doTranslate(t,e){this.attrs.x+=t,this.attrs.y+=e,this._updateBounds()}_updateBounds(){this._bounds=new a(this.attrs.x-this.attrs.radius,this.attrs.y-this.attrs.radius,2*this.attrs.radius,2*this.attrs.radius)}copyPropertiesTo(t){super.copyPropertiesTo(t),t.attrs.x=this.attrs.x,t.attrs.y=this.attrs.y,t.attrs.radius=this.attrs.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(" ")}}function Bt(t){return t._query=function(){this.data=[];let t=this.field,e=this.items,i=this.aggregator;switch(this.datatable.getFieldType(t)){case A.Boolean:break;case A.Date:this.data=e.map((e=>e.dataScope.getFieldValue(t)));break;case A.String:break;default:this.data=e.map((e=>e.dataScope.aggregateNumericalField(t,i)))}},t._map=function(){let t,e=this.items,i=this.data,s=this.channel;if(t=Yc(this.scaleType),null==this.data.find((t=>t<0))||"width"!=s&&"height"!=s||0!=e[0].type.indexOf("rect")){let n,r;t.domain=[0,Math.max(...i)],"radius"==s||"outerRadius"==s||"innerRadius"==s?(n=0,r=Math.max(...e.map((t=>t[s]))),r<20&&(r=20)):"area"==s?(n=0,r=Math.max(...e.map((t=>t.bounds.width*t.bounds.height))),r<400&&(r=400)):"fontSize"==s?(n=2,r=Math.max(...e.map((t=>parseFloat(t.styles.fontSize))))):"strokeWidth"==s?(n=1,r=Math.max(...e.map((t=>parseFloat(t.styles.strokeWidth)))),r==n&&(r=n+5)):(n=0,r=Math.max(...e.map((t=>t.bounds[s])))),this.rangeExtent&&(r=n+this.rangeExtent),this.range&&(n=this.range[0],r=this.range[1]),t._setRange([n,r])}else this._rectNegativeValues=!0,t.domain=[Math.min(...i),Math.max(...i)],"width"==s?t._setRange([0,Math.max(...e.map((t=>t.width)))]):t._setRange([0,Math.max(...e.map((t=>t.height)))]);this.scale||(this.scale=t),this.scale._addEncoding(this)},t._apply=function(){if("radius"==this.channel||"outerRadius"==this.channel||"innerRadius"==this.channel){for(let t=0;t<this.items.length;t++){this.items[t][this.channel]=this.scale.map(this.data[t])}this.scene._relayoutAncestors(this.anyItem,this.items)}else if(this._rectNegativeValues){let t=Math.max(...this.data),e=Math.min(...this.data),i="width"===this.channel?Math.min(...this.items.map((t=>t.bounds.left))):Math.min(...this.items.map((t=>t.bounds.top)))+this.scale.rangeExtent,s="width"===this.channel?"right":"top",n="width"===this.channel?"left":"bottom";for(let r=0;r<this.items.length;r++){let a,o=this.items[r];if(o.parent&&o.parent.type===T.Collection){let t=o.parent.parent;if(t.type===T.Collection&&t.layout&&t.layout.type===y.Grid){let e=t.children.indexOf(o.parent);a=t.layout.cellBounds[e][n]}else a=o.parent.refBounds[n]}else a=i;"width"===this.channel?(o.leftSegment._doTranslate(a+this.scale.map(0)-o.leftSegment.vertex1.x,0),o.rightSegment._doTranslate(a+this.scale.map(this.data[r])-o.rightSegment.vertex1.x,0)):(o.topSegment._doTranslate(0,a-this.scale.map(this.data[r])-o.topSegment.vertex1.y),o.bottomSegment._doTranslate(0,a-this.scale.map(0)-o.bottomSegment.vertex1.y)),o._updateBounds(),this.data[r]>0?(o.boundsOffsets[s]=this.scale.map(t)-this.scale.map(this.data[r]),o.boundsOffsets[n]=this.scale.map(0)-this.scale.map(e)):(o.boundsOffsets[n]=this.scale.map(this.data[r])-this.scale.map(e),o.boundsOffsets[s]=this.scale.map(t)-this.scale.map(0))}}else if("area"==this.channel){for(let t=0;t<this.items.length;t++){let e=this.items[t],i=Math.sqrt(this.scale.map(this.data[t]));e.resize(i,i)}this.scene._relayoutAncestors(this.anyItem,this.items)}else if("fontSize"==this.channel){for(let t=0;t<this.items.length;t++){let e=this.items[t],i=this.scale.map(this.data[t]);e.styles.fontSize=i+"px"}this.scene._relayoutAncestors(this.anyItem,this.items)}else if("strokeWidth"==this.channel){for(let t=0;t<this.items.length;t++){let e=this.items[t],i=this.scale.map(this.data[t]);e.styles.strokeWidth=i}this.scene._relayoutAncestors(this.anyItem,this.items)}else{let t="left",e="bottom";if(this.anyItem.parent&&this.anyItem.parent.type==T.Glyph){let i=this.anyItem.parent.children;1==Et(i.map((t=>t.bounds.right))).length&&(t="right"),1==Et(i.map((t=>t.bounds.top))).length&&(e="top")}if(this.anyItem.type===T.Collection&&this.anyItem.layout&&this.anyItem.layout[this.channel])for(let t=0;t<this.items.length;t++){let e=this.items[t],i=this.scale.map(this.data[t]);e.layout[this.channel]=i}else for(let i=0;i<this.items.length;i++){let s=this.items[i],n=this.scale.map(this.data[i]),r="width"==this.channel?n:s.bounds.width,a="height"==this.channel?n:s.bounds.height;s.resize(r,a,t,e)}this.scene._relayoutAncestors(this.anyItem,this.items)}},t.run(),t}function Lt(t){return t._query=function(){this.data=[],this.areas=et(this.items[0],this.scene);let t=this.areas.length;this.areaNum=t,this._vertices=[],this.indicator=[];for(let t of this.areas)for(let e=0;e<t.vertices.length;e++)this._vertices.push(t.vertices[e]),e<t.vertices.length/2?this.indicator.push(1):this.indicator.push(0);let e=this.field,i=this._vertices.map((t=>t.dataScope));switch(this.datatable.getFieldType(e)){case A.Boolean:break;case A.Date:this.data=i.map((t=>t.getFieldValue(e)));break;case A.String:this.data=i.map(((t,i)=>0==this.indicator[i]?0:t.aggregateNumericalField(e,this.aggregator)));break;default:"x"==this.channel||"y"==this.channel?this.data=i.map((t=>t._field2value[e])):this.data=i.map(((t,i)=>0==this.indicator[i]?0:t.aggregateNumericalField(e,this.aggregator)))}},t._map=function(){"fillGradient"===this.channel?this._mapToGradient():"width"!=this.channel&&"height"!=this.channel||this._mapToSize()},t._mapToGradient=function(){if(this.scale){if(!this._mapping){let t=this.scale.domain.concat(this.data);this.scale.domain=[Math.min(...t),Math.max(...t)]}}else if(this._mapping)this.scale=Yc("linear",this._mapping);else{let t,e=Math.min(...this.data),i=Math.max(...this.data),s=Math.max(Math.abs(e),Math.abs(i));e<0&&i>0?(t="interpolatePuOr",e=-s,i=s,this.scale=Yc("divergingColor",this._scheme?this._scheme:t)):(t="interpolateTurbo",this.scale=Yc("sequentialColor",this._scheme?this._scheme:t)),this.scale.domain=[e,i]}this.scale._addEncoding(this)},t._mapToSize=function(){let t,e,i;switch(this.datatable.getFieldType(this.field)){case A.Boolean:break;case A.Date:t=Yc("time"),e=Math.min(...this.data),i=Math.max(...this.data),t.domain=[e,i];break;case A.String:t=Yc("linear"),e=Math.min(...this.data),i=Math.max(...this.data),t.domain=this._includeZero||e<0?[0,i]:[e,i];break;default:t=Yc("linear"),e=Math.min(...this.data),i=Math.max(...this.data),t.domain=e<0?[0,i]:[e,i]}let s,n=Ct(this.areas[0]),r=it(this.anyItem);if(r){let t=r.cellBounds;s="width"==this.channel||"height"==this.channel?n==v?t[0].width:t[0].height:n==v?t[0].height:t[0].width}else s="width"==this.channel?Math.max(...this.areas.map((t=>t.bounds.width))):Math.max(...this.areas.map((t=>t.bounds.height)));e<0?(t._scale.domain([e,i]),t._setRange([0,s])):t._setRange([0,s]),this.scale?this.scale._merge(t):this.scale=t,this.scale._addEncoding(this)},t._apply=function(){"fillGradient"===this.channel?this._applyToGradient():"width"!=this.channel&&"height"!=this.channel||this._applyToSize()},t._applyToGradient=function(){let t=0;for(let e of this.areas){let i=this.data.slice(t,t+e.vertices.length),s=Math.min(...i),n=Math.max(...i),r="horizontal"===e.orientation?$c({x1:0,y1:100,x2:0,y2:0}):$c({x1:0,y1:0,x2:100,y2:0});if(r.addStop(0,this.scale.map(s),1),this._mapping){let t=Object.keys(this._mapping).map((t=>parseFloat(t))).sort();for(let e of t)e>s&&e<n&&r.addStop(100*(e-s)/(n-s),this.scale.map(e),1)}else"divergingColor"===this.scale.type&&r.addStop(100*-s/(n-s),this.scale.map(0),1);r.addStop(100,this.scale.map(n),1),e.fillColor=r,t+=e.vertices.length}},t._applyToSize=function(){let t=[],e=this.channel;for(let e of this.scale.encodings)t=t.concat(e.items);let i=this.areas[0].orientation;if("width"===e||"height"===e){if(it(this.areas[0])){let t=0,e=this.areas.map((t=>st(t))),s=this.areas.map((t=>it(t)));for(let[n,r]of this.areas.entries()){let a=e[n],o=s[n];for(let e=0;e<r.vertices.length;e++){let s,n,h=this._vertices[e+t];if(i===b)if(s=0,o.type===y.Stack)n=a.bottom-this.scale.map(this.data[e+t])-h.y;else if(o.type===y.Grid){switch(r.baseline){case"top":n=a.top+this.scale.map(this.data[e+t])-h.y;break;case"bottom":n=a.bottom-this.scale.map(this.data[e+t])-h.y;break;case"middle":{let i=r.vertices.length-1-e,s=Math.abs(this.scale.map(this.data[e+t])-this.scale.map(this.data[i+t]));n=this.indicator[e+t]?a.middle-s/2-h.y:a.middle+s/2-h.y;break}}}else n=0;else if(n=0,o.type===y.Stack)s=a.left+this.scale.map(this.data[e+t])-h.x;else if(o.type===y.Grid){switch(r.baseline){case"left":s=a.left+this.scale.map(this.data[e+t])-h.x;break;case"right":s=a.right-this.scale.map(this.data[e+t])-h.x;break;case"center":{let i=r.vertices.length-1-e,n=Math.abs(this.scale.map(this.data[e+t])-this.scale.map(this.data[i+t]));s=this.indicator[e+t]?a.center-n/2-h.x:a.center+n/2-h.x;break}}}else s=0;h._doTranslate(s,n)}t+=r.vertices.length}}else{let t="center"==this.areas[0].baseline||"middle"==this.areas[0].baseline,e=0,s=i==v?"left":"bottom",n=i==i==v?"right":"top";for(let t of this.areas){for(let s=e;s<e+t.vertices.length;s++){let e=this._vertices[s],n=i==v?t.baseline!==C.Right?t.bounds.left-t.boundsOffsets.left:t.bounds.right+t.boundsOffsets.right:t.baseline!=C.Top?t.bounds.bottom+t.boundsOffsets.bottom:t.bounds.top-t.boundsOffsets.top,r=i==v?t.baseline!==C.Right?n+this.scale.map(this.data[s])-e.x:n-this.scale.map(this.data[s])-e.x:0,a=i==v?0:t.baseline!=C.Top?n-this.scale.map(this.data[s])-e.y:n+this.scale.map(this.data[s])-e.y;e._doTranslate(r,a)}let r=this.data.slice(e,e+t.vertices.length),a=Math.min(...r),o=Math.max(...r);t.boundsOffsets[n]=this.scale.map(Math.max(...this.data))-this.scale.map(o),t.boundsOffsets[s]=this.scale.map(a)-this.scale.map(Math.min(...this.data)),e+=t.vertices.length}if(1==t){let t=this._vertices.length/this.areaNum,e=ot(this._vertices),s=i==v?Math.min(...e.map((t=>t.bounds.x))):Math.max(...e.map((t=>t.bounds.y)));for(let e=0;e<this.areaNum;e++)for(let n=0;n<t/2;n++){let r=e*t+n,a=(e+1)*t-n-1,o=this._vertices[r],h=this._vertices[a],l=i==v?o.x-h.x:h.y-o.y,c=i==v?s+l/2-o.x:0,d=i==v?0:s+l/2-o.y,u=i==v?s-l/2-h.x:0,f=i==v?0:s-l/2-h.y;o._doTranslate(c,d),h._doTranslate(u,f)}}}}for(let t of this.areas)t._updateBounds();"width"!=e&&"height"!=e||this.scene._relayoutAncestors(this.areas[0],this.areas)},t.run(),t}class Dt{constructor(t,e,i,s,n){this.items=t,this.anyItem=this.items[0],this.scene=e,this.channel=i,this.field=s,this._aggregator=n.aggregator,this.datatable=n.datatable,this.scale=n.scale,this.scale?(this._flipScale=this.scale.isFlipped,this.scaleType=this.scale.type,this._includeZero=this.scale.includeZero):(this._flipScale=n.flipScale,this.scaleType=n.scaleType,this._includeZero=n.includeZero),this._mapping=n.mapping,this.rangeExtent=n.rangeExtent,this._scheme=n.scheme,this.range=n.range,"angle"==this.channel&&(this.startAngle="startAngle"in n?n.startAngle:90),this._query=void 0,this._map=void 0,this._apply=void 0}get id(){return["enc",at(this.anyItem),this.channel,this.field].join("-")}set aggregator(t){this._aggregator=t,this.scale=void 0,this.run()}get aggregator(){return this._aggregator}toJSON(){let t={};return t.anyItem=this.anyItem.id,t.items=this.items.map((t=>t.id)),this.data&&(t.data=this.data),this._rectNegativeValues&&(t._rectNegativeValues=!0),t.args={},t.args.channel=this.channel,t.args.field=this.field,t.args.aggregator=this.aggregator,t.args.datatable=this.datatable.id,t.args.scale=this.scale.id,t.args.mapping=this._mapping,t.args.rangeExtent=this.rangeExtent,t.args.scheme=this._scheme,t.args.scaleType=this.scaleType,t.args.range=this.range,"angle"==this.channel&&(t.args.startAngle=this.startAngle),t}run(){this._query(),this._map(),this._apply()}get dataTable(){return this.datatable}_inferTickValues(){let t,e=this,i=e.scale.domain,s=e.scale.range;switch(e.scale.type){case"linear":case"log":{let r=Math.abs(s[0]-s[1]);if("width"==e.channel||"height"==e.channel){let t=rt(e.anyItem,"stack");if(t){let s=et(t.group,e.scene);r=Math.max(...s.map((t=>t.refBounds[e.channel]))),i[1]=e.scale.invert(r)}}t="width"==e.channel||"x"==e.channel?45:30;let a,o=Math.max(2,Math.floor(r/t));if("log"===e.scale.type){a=[];let t=e.scale._scale.ticks();for(let e of t){let i=Math.log(e)/Math.log(10)+1e-6;Math.abs(i-Math.floor(i))<o/t.length&&a.push(e)}}else a=n.ticks(i[0],i[1],o);return a}case"point":{t="width"==e.channel||"x"==e.channel?80:30;let s=Math.floor(e.scale.rangeExtent/i.length),n=Math.ceil(t/s);return"x"==e.channel?i.filter(((t,e)=>e%n==0)):i}case"time":{t="width"==e.channel||"x"==e.channel?80:30;let r,a,o=Math.floor((s[1]-s[0])/t),h=Math.ceil((i[1]-i[0])/o)/1e3,l=[1,60,3600,86400,2628003,31536e3],c=[n.timeSeconds,n.timeMinutes,n.timeHours,n.timeDays,n.timeMonths,n.timeYears];for(let t=0;t<l.length-1;t++)if(h>=l[t]&&h<l[t+1])return r=Math.floor(h/l[t]),a=c[t],a(i[0],i[1],r);return h>l[l.length-1]?(r=Math.floor(h/l[l.length-1]),a=c[l.length-1],a(i[0],i[1],r)):[]}default:return[]}}getScaleRange(t){let e=t||this.anyItem;if(e.type!=T.Area&&("vertex"!=e.type||e.parent.type!=T.Area)){if("x"==this.channel){let t=it(e);if(t&&t.type==y.Grid){let i=t.cellBounds,s=e.parent.parent.children.findIndex((t=>e.parent==t||e.parent.parent==t));return[i[s].left,i[s].left+this.scale.rangeExtent]}if("vertex"==e.type||"segment"==e.type){let t=this.scale.offset;return[t,t+this.scale.rangeExtent]}{let t=this.scale.offset;return[t,t+this.scale.rangeExtent]}}if("y"==this.channel){let t=it(e);if(t&&t.type==y.Grid){let i=t.cellBounds,s=e.parent.parent.children.findIndex((t=>e.parent==t||e.parent.parent==t));return[i[s].bottom,i[s].bottom-this.scale.rangeExtent]}if("vertex"==e.type||"segment"==e.type){let t=this.scale.offset;return[t+this.scale.rangeExtent,t]}{let t=this.scale.offset;return[t+this.scale.rangeExtent,t]}}if("width"==this.channel){let t=rt(e);if("grid"===t.type){let i=t.cellBounds,s=e.parent.parent.children.findIndex((t=>e.parent==t||e.parent.parent==t));return[i[s].left,i[s].right]}if("stack"===t.type&&"horizontal"==t.orientation)return[t.group.bounds.left,t.group.bounds.right];{let t=et(e,this.scene),i=Math.min(...t.map((t=>t.bounds.left)));return[i,i+this.scale.rangeExtent]}}if("height"==this.channel){let t=bt(e);if(t&&t.layout&&["grid","stack"].indexOf(t.layout.type)>=0){let i=t.layout.cellBounds,s=e.parent.parent.children.findIndex((t=>e.parent===t||e.parent.parent===t));return[i[s].bottom,i[s].bottom-i[s].height]}{let t=et(e,this.scene),i=Math.min(...t.map((t=>t.refBounds.bottom)));return[i,i-this.scale.rangeExtent]}}if("radialDistance"==this.channel){let t=e.parent;return[t.x,t.x+this.scale.rangeExtent]}return this.scale.range}{let t,i=e.type==T.Area?e:e.parent,s=Ct(i),n=it(i);t=n?s==v?n.horzCellAlignment===C.Left:n.vertCellAlignment===C.Bottom:s==v?i.baseline==C.Left:i.baseline==C.Bottom;let r=nt(i);if(r)switch(this.channel){case"x":return[r.left,r.left+this.scale.rangeExtent];case"width":return t?[r.left,r.left+this.scale.rangeExtent]:[r.right,r.right-this.scale.rangeExtent];case"y":return[r.bottom,r.bottom-this.scale.rangeExtent];case"height":return t?[r.bottom,r.bottom-this.scale.rangeExtent]:[r.top+this.scale.rangeExtent,r.top]}else if(n&&"stack"===n.type)switch(r=n.group.bounds,this.channel){case"x":return[r.left,r.left+this.scale.rangeExtent];case"width":return t?[r.left,r.left+this.scale.rangeExtent]:[r.right,r.right-this.scale.rangeExtent];case"y":return[r.bottom,r.bottom-this.scale.rangeExtent];case"height":return t?[r.bottom,r.bottom-this.scale.rangeExtent]:[r.top+this.scale.rangeExtent,r.top]}if(s==b)switch(this.channel){case"width":case"height":{let e=this._vertices,i=t?Math.max(...e.map((t=>t.y))):Math.min(...e.map((t=>t.y)));return t?[i,i-this.scale.rangeExtent]:[i+this.scale.rangeExtent,i]}case"x":case"y":{let t=et(i.firstVertex,this.scene),e=Math.min(...t.map((t=>t.x)));return[e,e+this.scale.rangeExtent]}}else if(s==v)switch(this.channel){case"x":case"y":{let t=et(i.firstVertex,this.scene),e=Math.max(...t.map((t=>t.y)));return[e,e-this.scale.rangeExtent]}case"height":case"width":{let e=et(i.firstVertex,this.scene),s=t?Math.min(...e.map((t=>t.x))):Math.max(...e.map((t=>t.x)));return t?[s,s+this.scale.rangeExtent]:[s-this.scale.rangeExtent,s]}}}}}function jt(t,e,i){return e.map((e=>[e,n.mean(i,(i=>t(e-i)))]))}function Vt(t){return e=>Math.abs(e/=t)<=1?.75*(1-e*e)/t:0}function Gt(t,e){if("field"in e){let i=e.field;if("value"in e)return t[i]==e.value;if("range"in e)return t[i]>=e.range[0]&&t[i]<=e.range[1];if("values"in e)return e.values.indexOf(t[i])>=0}else if("fields"in e){let i=e.fields[0],s=e.fields[1],n=t[i],r=t[s];switch(e.operator){case"==":return n==r;case">":return n>r;case">=":return n>=r;case"<":return n<r;case"<=":return n<=r}return!1}}class zt{constructor(t,e,i){if(this.url=e,this.id=T.DataTable+pt[T.DataTable]++,this.data=t,this.rawData=JSON.parse(JSON.stringify(t)),this._dateMap=new Map,this._fields=Object.keys(this.data[0]),this._newField=0,i)this._fieldTypes=i;else{this._fieldTypes={};for(let t of this._fields)this._fieldTypes[t]=qt(this.data.map((e=>e[t]))),"year"==t.toLowerCase()&&this._fieldTypes[t]==A.Integer&&(this._fieldTypes[t]=A.Date)}this._validate(this.data,this._fieldTypes),this._fieldSummaries={};for(let t of this._fields)this._fieldSummaries[t]=Wt(this.data.map((e=>e[t])),this._fieldTypes[t]);this._fields.indexOf(h)<0&&this._addField(h,A.String,this.data.map(((t,e)=>"r"+e)))}get name(){return this.url?function(t){var e=t.indexOf("\\")>=0?t.lastIndexOf("\\"):t.lastIndexOf("/"),i=t.substring(e);0!==i.indexOf("\\")&&0!==i.indexOf("/")||(i=i.substring(1));return i}(this.url):this.id}set sourceDataTable(t){this._sourceDataTable=t}get sourceDataTable(){return this._sourceDataTable}getEncodableFields(t){switch(t){case"x":case"y":case"width":case"height":case"radius":case"fillColor":case"strokeColor":case"text":return this.numericFields.concat(this.nonNumericFields);case"area":case"strokeWidth":default:return this.numericFields}}toJSON(){let t={};return t.data=this.rawData,t.fieldTypes=this._fieldTypes,t.url=this.url,t.id=this.id,t.sourceDataTable=this._sourceDataTable,t.transform=this._transform,t.dateMap={},t}transformField(t,e,i){let s=this.data.map((i=>e(i[t]))),n=qt(s),r=i||Date.now()+"_field"+this._newField++;return this._addField(r,n,s),r}setValueOrder(t,e){this._fieldSummaries[t].unique=e}_addField(t,e,i){this.data.forEach(((e,s)=>e[t]=i[s])),this._fieldTypes[t]=e,this._fields.push(t),this._fieldSummaries[t]=Wt(i,e)}getFieldType(t){return this._fieldTypes[t]}get fields(){return this._fields}getFieldSummary(t){return this._fieldSummaries[t]}getFieldValues(t){return this.data.map((e=>e[t]))}getUniqueFieldValues(t){return this._fieldSummaries[t].unique}getRowCount(){return this.data.length}hasField(t){return this._fields.indexOf(t)>=0}parseFieldAsDate(t,e){let i=n.timeParse(e);for(let e of this.data){let s=e[t];null==s||null==s?(s="",e[t]=new Date(1899,11,31).getTime()):e[t]=i(s).getTime(),this._dateMap.set(e[t],s)}this._fieldTypes[t]=A.Date,this._fieldSummaries[t]=Wt(this.data.map((e=>e[t])),A.Date)}getRawValue(t,e){return this.getFieldType(t)===A.Date?this._dateMap.get(e).toString():e}static get RowID(){return h}get nonNumericFields(){let t=[];for(let e in this._fieldTypes)this._fieldTypes[e]!=A.Number&&this._fieldTypes[e]!=A.Integer&&e!=zt.RowID&&t.push(e);return t}get numericFields(){let t=[];for(let e in this._fieldTypes)this._fieldTypes[e]!==A.Number&&this._fieldTypes[e]!==A.Integer||e==zt.RowID||t.push(e);return t}getFieldsByType(t){let e=[];for(let i in this._fieldTypes)this._fieldTypes[i]===t&&i!=zt.RowID&&e.push(i);return e}transform(t,e,i){let s=i||{};switch(t){case"kde":return function(t,e,i){let s=e[0],n=t.nonNumericFields,r={};for(let e of t.data){let t=n.map((t=>String(e[t]))).join("_");t in r||(r[t]=n.map((t=>e[t])),r[t].push([])),r[t][r[t].length-1].push(e[s])}let a="min"in i?i.min:t.getFieldSummary(s).min,o="max"in i?i.max:t.getFieldSummary(s).max,h=a,l=[];for(;h<o;)l.push(h),h+=i.interval;l.push(h);let c=[];for(let t in r){let e=r[t].pop(),a=jt(Vt(i.bandwidth),l,e);for(let e of a){let i={};r[t].forEach(((t,e)=>i[n[e]]=t)),i[s]=e[0],i[s+"_density"]=e[1],c.push(i)}}let d={};return n.forEach((e=>d[e]=t.getFieldType(e))),d[s]=A.Number,d[s+"_density"]=A.Number,new zt(c,t.url,d)}(this,e,s);case"bin":return function(t,e,i){let s=e[0],r=t.nonNumericFields,a={};for(let e of t.data){let t=r.map((t=>String(e[t]))).join("_");a.hasOwnProperty(t)||(a[t]=r.map((t=>e[t])),a[t].push([])),a[t][a[t].length-1].push(e[s])}let o=[];for(let t in a){let e=a[t].pop(),i=n.bin()(e);for(let e of i){let i={};a[t].forEach(((t,e)=>i[r[e]]=t)),i.x0=e.x0,i.x1=e.x1,i[s+"_count"]=e.length,o.push(i)}}let h={};r.forEach((e=>h[e]=t.getFieldType(e))),h.x0=A.Number,h.x1=A.Number,h[s+"_count"]=A.Number;let l=new zt(o,t.url,h);return l.sourceDataTable=t,l.transform={type:"bin",args:e},l}(this,e);case"sort":return function(t,e,i){t.data.sort(((t,i)=>function(t,e,i,s){for(let s of i){if(t[s]<e[s])return-1;if(t[s]>e[s])return 1}return 0}(t,i,e))),t.summarize()}(this,e);case"filter":return function(t,e){let i=[];for(let s of t.data){let t=!0;for(let i of e)if(!Gt(s,i)){t=!1;break}t&&i.push(s)}let s=new zt(i,t.url);return s.sourceDataTable=t,s.transform={type:"filter",args:e},s}(this,e)}}summarize(){for(let t of this._fields)this._fieldSummaries[t]=Wt(this.data.map((e=>e[t])),this._fieldTypes[t])}_validate(t,e){for(let i of t)for(let t in e){let s,n=e[t],r=i[t];if(null==i[t]||null==i[t])switch(n){case A.Boolean:s=!1;break;case A.Date:s=new Date(1899,11,31).getTime();break;case A.String:s="";break;default:s=0}else switch(n){case A.Boolean:s=r;break;case A.Date:s=Number.isInteger(r)?new Date(r,0).getTime():new Date(r+"").getTime(),this._dateMap.set(s,r);break;case A.String:s=r.toString();break;default:s=r}i[t]=s}}}function Wt(t,e){var i={};switch(e){case A.Boolean:i.trueCount=t.filter((t=>t)).length,i.falseCount=t.filter((t=>!t)).length;break;case A.Date:i.min=n.min(t),i.max=n.max(t),i.extent=[i.min,i.max],i.unique=[...new Set(t)];break;case A.String:i.unique=[...new Set(t)];break;default:i.min=n.min(t),i.max=n.max(t),i.extent=[i.min,i.max],i.mean=n.mean(t),i.median=n.median(t),i.unique=[...new Set(t)]}return i}var Ut={boolean:function(t){return"true"===t||"false"===t||!0===t||!1===t||"[object Boolean]"==toString.call(t)},integer:function(t){return Ut.number(t)&&(t=+t)==~~t},number:function(t){return!isNaN(+t)&&"[object Date]"!=toString.call(t)},date:function(t){let e=new Date(t);return null!=e&&!isNaN(e)},string:function(t){return!0}};function qt(t){var e=Object.values(A);for(let i=0;i<t.length;i++){let s=t[i];if(null!=s){for(let t=0;t<e.length;t++)Ut[e[t]](s)||(e.splice(t,1),t-=1);if(1==e.length)return e[0]}}return e[0]}class Jt extends q{constructor(t){super(t),this.type=T.PointText,this.attrs.x=0,this.attrs.y=0,"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"),void 0!==t&&("x"in t&&(this.attrs.x=t.x),"y"in t&&(this.attrs.y=t.y),this.attrs.text="text"in t?t.text:"",this.attrs.anchor="anchor"in t?t.anchor:["center","middle"]),this._updateBounds()}copyPropertiesTo(t){t.styles=Object.assign({},this.styles),this._dataScope&&(t._dataScope=this._dataScope.clone()),t.x=this.attrs.x,t.y=this.attrs.y,t.text=this.text,t.anchor=[this.anchor[0],this.anchor[1]]}get bounds(){return this._bounds||this._updateBounds(),this._bounds}get refBounds(){return this.bounds}set text(t){this.attrs.text=t,this._updateBounds()}get text(){return this.attrs.text}_doTranslate(t,e){this.attrs.x+=t,this.attrs.y+=e,this._updateBounds()}_updateBounds(){let t,e,i=function(t,e,i){let s=mt.getContext();s.font=e;let n=s.measureText(t);return n.fontBoundingBoxAscent?{width:n.width,height:n.fontBoundingBoxAscent+n.fontBoundingBoxDescent}:n.actualBoundingBoxAscent?{width:n.width,height:n.actualBoundingBoxAscent+n.actualBoundingBoxDescent}:{width:n.width,height:i}}(this.attrs.text,[this.fontWeight,this.styles.fontSize,this.fontFamily].join(" "),parseFloat(this.fontSize)),s=i.width,n=i.height;switch(this.attrs.anchor[0]){case"left":t=this.attrs.x;break;case"right":t=this.attrs.x-s;break;case"center":t=this.attrs.x-s/2;break;default:t=this.attrs.x}switch(this.attrs.anchor[1]){case"top":e=this.attrs.y;break;case"bottom":e=this.attrs.y-n;break;case"middle":e=this.attrs.y-n/2}this._bounds=new a(t,e,s,n)}get center(){return{x:this.bounds.left+this.bounds.width/2,y:this.bounds.top+this.bounds.height/2}}get x(){return this.attrs.x}set x(t){this.attrs.x=t,this._updateBounds()}get y(){return this.attrs.y}set y(t){this.attrs.y=t,this._updateBounds()}get anchor(){return this.attrs.anchor}set anchor(t){this.attrs.anchor=t,this._updateBounds()}get horzAnchor(){return this.attrs.anchor[0]}get vertAnchor(){return this.attrs.anchor[1]}set horzAnchor(t){this.attrs.anchor[0]=t,this._updateBounds()}set vertAnchor(t){this.attrs.anchor[1]=t,this._updateBounds()}get fontSize(){return parseFloat(this.styles.fontSize)}set fontSize(t){this.styles.fontSize="number"==typeof t?t+"px":t,this._updateBounds()}get fontWeight(){return this.styles.fontWeight}set fontWeight(t){this.styles.fontWeight=t,this._updateBounds()}get fontFamily(){return this.styles.fontFamily}set fontFamily(t){this.styles.fontFamily=t,this._updateBounds()}get fillColor(){return this.styles.fillColor}set fillColor(t){this.styles.fillColor=t}}class Yt extends St{constructor(t){super(),this.type=T.Axis,this.id=this.type+pt[this.type]++,this._strokeColor="strokeColor"in t?t.strokeColor:"#555",this._textColor="textColor"in t?t.textColor:"#555",this._fontSize="fontSize"in t?t.fontSize:"12px",this._tickOffset="tickOffset"in t?t.tickOffset:0,this._tickSize="tickSize"in t?t.tickSize:5,this._tickAnchor=t.tickAnchor?t.tickAnchor:"middle",this._tickVisible=!("tickVisible"in t)||t.tickVisible,this._pathVisible=!("pathVisible"in t)||t.pathVisible,this._labelOffset="labelOffset"in t?t.labelOffset:15,this._labelFormat="labelFormat"in t?t.labelFormat:"",this._titleOffset="titleOffset"in t?t.titleOffset:40,"titleAnchor"in t?this._titleAnchor=t.titleAnchor:"x"==this.channel||"width"==this.channel?this._titleAnchor="top"==this._orientation?["center","bottom"]:["center","top"]:this._titleAnchor="left"==this._orientation?["right","middle"]:["left","middle"],this._rotateYTitle=!("rotateTitle"in t&&!t.rotateTitle),this._titlePosition=t.titlePosition,this._labelRotation="labelRotation"in t?t.labelRotation:0}toJSON(){let t={args:{}};return t.type=this.type,t.id=this.id,t.field=this._field,t.channel=this._channel,"args"in t||(t.args={}),t.args.orientation=this._orientation,t.args.strokeColor=this._strokeColor,t.args.textColor=this._textColor,t.args.tickOffset=this._tickOffset,t.args.tickSize=this._tickSize,t.args.tickAnchor=this._tickAnchor,t.args.tickVisible=this._tickVisible,t.args.pathVisible=this._pathVisible,t.args.labelOffset=this._labelOffset,t.args.labelFormat=this._labelFormat,this._labelRotation&&(t.args.labelRotation=this._labelRotation),t.args.showTitle=this._showTitle,t.args.tickValues=this._tickValues,t.args.titleAnchor=this._titleAnchor,t.args.titleOffset=this._titleOffset,t.args.titlePosition=this._titlePosition,t.args.rotateTitle=this._rotateYTitle,t}get field(){return this._field}get channel(){return this._channel}get orientation(){return this._orientation}set orientation(t){this._orientation=t,this.reposition()}get pathX(){if("y"==this.channel||"height"==this.channel){if(void 0!==this._position)return this._position;if(this._path)return this._path.vertices[0].x;if(this._rules&&this._rules.firstChild)return this._rules.firstChild.vertices[0].x}}set pathX(t){"y"!=this.channel&&"height"!=this.channel||(this._posArg=t),this.reposition()}get pathPosition(){return"x"==this.channel||"width"==this.channel?this.pathY:this.pathX}set pathPosition(t){"x"==this.channel||"width"==this.channel?this.pathY=t:"y"!=this.channel&&"height"!=this.channel||(this.pathX=t)}get pathY(){if("x"==this.channel||"width"==this.channel){if(void 0!==this._position)return this._position;if(this._path)return this._path.vertices[0].y;if(this._rules&&this._rules.firstChild)return this._rules.firstChild.vertices[0].y}}set pathY(t){"x"!=this.channel&&"width"!=this.channel||(this._posArg=t),this.reposition()}get tickOffset(){return this._tickOffset}set tickOffset(t){this._tickOffset=t,this._positionTicks()}get titleOffset(){return this._titleOffset}set titleOffset(t){this._titleOffset=t}get tickSize(){return this._tickSize}set tickSize(t){this._tickSize=t,this._positionTicks()}set tickValues(t){this._tickValues=t,this._generateTicks(),this._positionTicks()}get tickValues(){return this._tickValues}set labelValues(t){this._labelValues=t,this._generateLabels(),this._positionLabels()}get labelValues(){return this._labelValues}get tickAnchor(){return this._tickAnchor}set tickAnchor(t){this._tickAnchor=t}get tickVisible(){return this._tickVisible}set tickVisible(t){this._tickVisible=t;for(let e of this._ticks.children)e.visibility=t?"visible":"hidden"}get pathVisible(){return this._pathVisible}set pathVisible(t){this._pathVisible=t;let e=[];this._path&&e.push(this._path),this._rules&&this._rules.children.forEach((t=>e.push(t)));for(let i of e)i.visibility=t?"visible":"hidden"}get labelOffset(){return this._labelOffset}set labelOffset(t){this._labelOffset=t,this._positionLabels()}get labelFormat(){return this._labelFormat}set labelFormat(t){this._labelFormat=t,this._generateLabels(),this._positionLabels()}get labelRotation(){return this._labelRotation}set labelRotation(t){if(this._labelRotation=t,this._labels&&this._labels.children){let e="bottom"==this._orientation?["center","top"]:["center","bottom"];if(t)for(let t of this._labels.children)t._rotate=[this._labelRotation,t.x,t.y],t.anchor=["right",e[1]];else for(let t of this._labels.children)t._rotate=void 0}}get showTitle(){return this._showTitle}set showTitle(t){this._showTitle=t,this._title||(this._generateTitle(),this._positionTitle()),this._title.visibility=t?"visible":"hidden"}get titleAnchor(){return this._titleAnchor}set titleAnchor(t){this._titleAnchor=t}get titlePosition(){return this._titlePosition}set titlePosition(t){this._titlePosition=t}get rotateTitle(){return this._rotateYTitle}set rotateTitle(t){this._rotateYTitle=t}get title(){return this._titleText}set title(t){this._titleText=t}get includeZero(){return!!this.encoding&&this.encoding.scale.includeZero}set includeZero(t){this.encoding&&(this.encoding.scale.includeZero=t)}_generatePath(){}_generateTicks(){}_generateLabels(){}_generateTitle(){this._title=new Jt({text:this._titleText,fillColor:this._textColor,fontWeight:"bold"}),this._title.id=this.id+"-title",this.addChild(this._title)}_positionPath(){}_positionTicks(){}_positionLabels(){}_positionTitle(){}matches(t){}reposition(){this._positionPath(),this._positionTicks(),this._positionLabels(),this._showTitle&&this._positionTitle(),"radialDistance"===this._channel&&this._rotate&&(this._rotate=[this._rotate[0],this._item.parent.x,this._item.parent.y]),this._updateBounds()}}class Ht extends Yt{constructor(t,e,i){super(i),this.encoding=t,this._field=this.encoding.field,this._channel=this.encoding.channel,this._orientation="orientation"in i?i.orientation:"x"===this._channel||"width"==this._channel?"bottom":"left",this._posArg="x"==this._channel||"width"==this._channel?i.pathY:i.pathX,this._position=this._posArg,this._titleText="title"in i?i.title:this.encoding.field,this._item=e,this._ticks=new St,this._ticks.id=this.id+"ticks",this.addChild(this._ticks),this._labels=new St,this._labels.id=this.id+"labels",this.addChild(this._labels),"radialDistance"===this._channel&&"rotation"in i&&(this._rotate=[-i.rotation,this._item.parent.x,this._item.parent.y]),this._showTitle=!("showTitle"in i)||i.showTitle,this._determineAxisFlip(),this._generatePath(),this._positionPath(),this._showTitle&&this._generateTitle(),this._showTitle&&this._positionTitle()}autoUpdateTicks(){let t=this.encoding._inferTickValues();this.tickValues=t,this.labelValues=t}_updateBounds(){this._bounds=this._path.bounds,this._ticks.children.length>0&&(this._bounds=this._bounds.union(this._ticks.bounds)),this._labels.children.length>0&&(this._bounds=this._bounds.union(this._labels.bounds)),this._title&&(this._bounds=this._bounds.union(this._title.bounds))}toJSON(){let t=super.toJSON();return t.args.item=this._item.id,"time"===this.encoding.scale.type&&(t.args.isDate=!0),this._rotate&&(t.args.rotation=this._rotate[0]),"x"==this._channel||"width"==this._channel?t.args.pathY=this._posArg:t.args.pathX=this._posArg,t}get ticks(){return this._ticks}get labels(){return this._labels}get path(){return this._path}set strokeColor(t){this._strokeColor=t;for(let e of this._ticks.children)e.strokeColor=t;this._path.strokeColor=t}get strokeColor(){return this._strokeColor}set textColor(t){this._textColor=t;for(let e of this._labels.children)e.fillColor=t;this._title&&(this._title.fillColor=t)}get textColor(){return this._textColor}_generatePath(){this._path=new Z({strokeColor:this._strokeColor}),this._pathVisible||(this._path.visibility="hidden"),this._path.type=T.Line,this._path.id=this.id+"path",this.addChild(this._path)}_generateTicks(){this._ticks.removeAll();for(let t=0;t<this._tickValues.length;t++){let e=new Z({strokeColor:this._strokeColor});this._tickVisible||(e.visibility="hidden"),e.type=T.Line,e.id=this.id+"tick"+t,this._ticks.addChild(e)}}_generateLabels(){let t;switch(this._labels.removeAll(),this.encoding.datatable.getFieldType(this.encoding.field)){case A.Date:t=n.timeFormat(this._labelFormat);break;case A.String:t=function(t){return t};break;default:t=n.format(this._labelFormat)}for(let[e,i]of this._labelValues.entries()){let s=new Jt({text:t(i),fontSize:this._fontSize,fillColor:this._textColor});s.id=this.id+"label"+e,this._labels.addChild(s)}}_positionPath(){this._range=this.encoding.getScaleRange(this._item),void 0===this._posArg?this._position=this._computePosition():this._position=this._posArg;let t=[];if("x"==this._channel||"radialDistance"==this._channel||"width"==this._channel){let e=this._ticks.children.map((t=>t.vertices[0].x));t.push([Math.min(...e.concat(this._range)),this._position]),t.push([Math.max(...e.concat(this._range)),this._position])}else if("y"==this._channel||"height"==this._channel){let e=this._ticks.children.map((t=>t.vertices[0].y));t.push([this._position,Math.min(...e.concat(this._range))]),t.push([this._position,Math.max(...e.concat(this._range))])}this._path._setVertices(t),this._path._updateBounds(),this._showTitle&&this._title&&this._positionTitle(),this._updateBounds()}_isAlignedLeft(t){switch(t.type){case y.Stack:case y.Grid:return t.horzCellAlignment===C.Left;default:return!0}}_isAlignedBottom(t){switch(t.type){case y.Stack:case y.Grid:return t.vertCellAlignment===C.Bottom;default:return!0}}_determineAxisFlip(){if("x"==this._channel||"radialDistance"==this._channel||"width"==this._channel){if("width"==this._channel){let t=bt(this._item)?bt(this._item).layout:it(this._item);if(t)this._flip=!this._isAlignedLeft(t);else if("area"==this._item.type){let t=this._item.baseline==C.Left||this._item.baseline==C.Center||this._item.baseline==C.Middle||null==this._item.baseline;this._flip=!t}}}else if(("y"==this._channel||"height"==this._channel)&&"height"==this._channel){let t=bt(this._item)?bt(this._item).layout:it(this._item);if(t)this._flip=!this._isAlignedBottom(t);else if("area"==this._item.type){let t=this._item.baseline==C.Bottom||this._item.baseline==C.Center||this._item.baseline==C.Middle||null==this._item.baseline;this._flip=!t}}}_positionLabels(){if(void 0===this._posArg?this._position=this._computePosition():this._position=this._posArg,"x"==this._channel||"radialDistance"==this._channel||"width"==this._channel){let t="bottom"==this._orientation?this._tickSize:-this._tickSize,e="bottom"==this._orientation?["center","top"]:["center","bottom"];if(this._flip)for(let[i,s]of this._labels.children.entries())s.x=this._range[1]-this.encoding.scale.map(this._labelValues[i]),s.y=this._position+t,s.anchor=e,this._labelRotation&&(s._rotate=[this._labelRotation,s.x,s.y],s.anchor=["right",e[1]]);else if(this.encoding.scale.isFlipped)for(let[i,s]of this._labels.children.entries())s.x=this._range[0]+this.encoding.scale.map(this._labelValues[i]),s.y=this._position+t,s.anchor=e,this._labelRotation&&(s._rotate=[this._labelRotation,s.x,s.y],s.anchor=["right",e[1]]);else for(let[i,s]of this._labels.children.entries())s.x=this._range[0]+this.encoding.scale.map(this._labelValues[i])-this.encoding.scale.range[0],s.y=this._position+t,s.anchor=e,this._labelRotation&&(s._rotate=[this._labelRotation,s.x,s.y],s.anchor=["right",e[1]])}else if("y"==this._channel||"height"==this._channel){let t="left"==this._orientation?-this._tickSize:this._tickSize,e="left"==this._orientation?["right","middle"]:["left","middle"];if(this._flip)for(let[i,s]of this._labels.children.entries())s.x=this._position+t,s.y=this._range[1]+this.encoding.scale.map(this._labelValues[i]),s.anchor=e;else if(this.encoding.scale.isFlipped)for(let[i,s]of this._labels.children.entries())s.x=this._position+t,s.y=this._range[1]-this.encoding.scale.map(this._labelValues[i])+this.encoding.scale.range[1],s.anchor=e;else for(let[i,s]of this._labels.children.entries())s.x=this._position+t,s.y=this._range[0]-this.encoding.scale.map(this._labelValues[i])+this.encoding.scale.range[0],s.anchor=e}this._labels._updateBounds(),this._updateBounds()}_computePosition(){let t;if("vertex"===this._item.type&&!this._item.parent.closed){let t=et(this._item,this._item.parent.getScene());if("x"===this._channel&&1==Et(t.map((t=>t.bounds.middle))).length)return this._item.bounds.middle;if("y"===this._channel&&1==Et(t.map((t=>t.bounds.center))).length)return this._item.bounds.center;if("radialDistance"===this._channel)return this._item.parent.y}if(this._item.type==T.Area&&(t=nt(this._item)),void 0===t){let e=bt(this._item);void 0===e&&(e=vt(this._item)),t=e.bounds}return"x"===this._channel||"width"===this._channel?"top"==this._orientation?t.top-this._tickSize:t.bottom+this._tickSize:"y"===this._channel||"height"===this._channel?"left"==this._orientation?t.left-this._tickSize:t.right+this._tickSize:"radialDistance"===this._channel?this._item.parent.y:void 0}_positionTicks(){if(void 0===this._posArg?this._position=this._computePosition():this._position=this._posArg,this._range=this.encoding.getScaleRange(this._item),"x"==this._channel||"radialDistance"==this._channel||"width"==this._channel){let t="bottom"==this._orientation?this._tickSize:-this._tickSize;if(this._flip)for(let[e,i]of this._ticks.children.entries())i._setVertices([[this._range[1]-this.encoding.scale.map(this._tickValues[e]),this._position],[this._range[1]-this.encoding.scale.map(this._tickValues[e]),this._position+t]]),i._updateBounds();else if(this.encoding.scale.isFlipped)for(let[e,i]of this._ticks.children.entries())i._setVertices([[this._range[0]+this.encoding.scale.map(this._tickValues[e]),this._position],[this._range[0]+this.encoding.scale.map(this._tickValues[e]),this._position+t]]),i._updateBounds();else for(let[e,i]of this._ticks.children.entries())i._setVertices([[this._range[0]+this.encoding.scale.map(this._tickValues[e])-this.encoding.scale.range[0],this._position],[this._range[0]+this.encoding.scale.map(this._tickValues[e])-this.encoding.scale.range[0],this._position+t]]),i._updateBounds()}else if("y"==this._channel||"height"==this._channel){let t="left"==this._orientation?-this._tickSize:this._tickSize;if(this._flip)for(let[e,i]of this._ticks.children.entries())i._setVertices([[this._position+t,this._range[1]+this.encoding.scale.map(this._tickValues[e])],[this._position,this._range[1]+this.encoding.scale.map(this._tickValues[e])]]),i._updateBounds();else if(this.encoding.scale.isFlipped)for(let[e,i]of this._ticks.children.entries()){let s=this._range[1]-this.encoding.scale.map(this._tickValues[e])+this.encoding.scale.range[1];i._setVertices([[this._position+t,s],[this._position,s]]),i._updateBounds()}else for(let[e,i]of this._ticks.children.entries())i._setVertices([[this._position+t,this._range[0]-this.encoding.scale.map(this._tickValues[e])+this.encoding.scale.range[0]],[this._position,this._range[0]-this.encoding.scale.map(this._tickValues[e])+this.encoding.scale.range[0]]]),i._updateBounds()}this._positionPath(),this._ticks._updateBounds(),this._updateBounds()}_positionTitle(){let t=this._path.bounds;this._title.achor=this._titleAnchor,this._titlePosition?(this._title.x=this._titlePosition[0],this._title.y=this._titlePosition[1],"y"!=this._channel&&"height"!=this._channel||this._rotateYTitle&&(this._title._rotate="left"==this._orientation?[-90,this._title.bounds.x,this._title.bounds.y]:[90,this._title.bounds.x,this._title.bounds.y])):"x"==this._channel||"width"==this._channel?(this._title.x=t.x,this._title.y="top"==this._orientation?t.top-this._titleOffset:t.bottom+this._titleOffset):(this._title.x="left"==this._orientation?t.left-this._titleOffset:t.right+this._titleOffset,this._title.y=t.y,this._rotateYTitle&&(this._title._rotate="left"==this._orientation?[-90,this._title.bounds.x,this._title.bounds.y]:[90,this._title.bounds.x,this._title.bounds.y])),this._title._updateBounds(),this._updateBounds()}matches(t){let e=at(t).split("_")[0],i=this.encoding.scale.encodings;for(let t of i){if(at(t.anyItem).split("_")[0]===e)return!0}return!1}get isFlipped(){return!!this._flip||!!this.encoding.scale.isFlipped}}class $t extends Yt{constructor(t,e,i,s,n){super(n),this._channel=i,this._orientation="orientation"in n?n.orientation:"x"===this._channel||"width"==this._channel?"bottom":"left",this._posArg="x"==this._channel||"width"==this._channel?n.pathY:n.pathX,this._item=t[0],this._items=t,this._mlayout=e,this._field=s,this._titleText="title"in n?n.title:this._field,this._showTitle="showTitle"in n&&n.showTitle,this._ticks=new St,this._ticks.id=this.id+"ticks",this.addChild(this._ticks),this._labels=new St,this._labels.id=this.id+"labels",this.addChild(this._labels),this._rules=new St,this._rules.id=this.id+"paths",this.addChild(this._rules),this._generatePath(),this._generateTicks(),this._generateLabels(),this._showTitle&&this._generateTitle(),this._positionPath(),this._positionTicks(),this._positionLabels(),this._showTitle&&this._positionTitle()}toJSON(){let t=super.toJSON();return t.args.item=this._item.id,"x"==this._channel||"width"==this._channel?t.args.pathY=this._posArg:t.args.pathX=this._posArg,this.classId&&(t.classId=this.classId),t}set strokeColor(t){this._strokeColor=t;for(let e of this._ticks.children)e.strokeColor=t;for(let e of this._rules.children)e.strokeColor=t}get strokeColor(){return this._strokeColor}set textColor(t){this._textColor=t;for(let e of this._labels.children)e.fillColor=t;this._title&&(this._title.fillColor=t)}get textColor(){return this._textColor}_updateBounds(){this._bounds=this._rules.bounds.clone(),this._bounds=this._bounds.union(this._ticks.bounds),this._bounds=this._bounds.union(this._labels.bounds),this._showTitle&&(this._bounds=this._bounds.union(this._title.bounds))}_generatePath(){if(this._rules.removeAll(),this._mlayout.type==y.Grid){let t="x"==this._channel?this._mlayout.numRows:this._mlayout.numCols;for(let e=0;e<t;e++){let t=new Z({strokeColor:this._strokeColor});this._pathVisible||(t.visibility="hidden"),t.type=T.Line,t.id=this.id+"rule"+e,this._rules.addChild(t)}}else if(this._mlayout.type===y.Stack){let t=new Z({strokeColor:this._strokeColor});this._pathVisible||(t.visibility="hidden"),t.type=T.Line,t.id=this.id+"rule",this._rules.addChild(t)}}_generateTicks(){this._ticks.removeAll();for(let t=0;t<this._mlayout.group.children.length;t++){let e=new Z({strokeColor:this._strokeColor});this._tickVisible||(e.visibility="hidden"),e.type=T.Line,e.id=this.id+"tick"+t,this._ticks.addChild(e)}}_generateLabels(){let t;switch(this._labels.removeAll(),this._item.dataScope.getFieldType(this._field)){case A.Date:t=n.timeFormat(this._labelFormat);break;case A.String:t=function(t){return t};break;default:t=n.format(this._labelFormat)}let e=this._mlayout.cellBounds;for(let i=0;i<e.length&&!(i>=this._mlayout.group.children.length);i++){let e=this._mlayout.group.children[i],s=new Jt({fillColor:this._textColor,fontSize:this._fontSize,text:t(e.dataScope.getFieldValue(this._field))});s.id=this.id+"label"+i,this._labels.addChild(s)}}_positionPath(){if(this._mlayout.type==y.Grid){let t=this._mlayout.cellBounds,e="x"==this._channel?this._mlayout.numRows:this._mlayout.numCols;if("x"==this._channel){let i=t[0].left,s=this._mlayout.numCols;for(let n=0;n<e;n++)this._rules.children[n]._setVertices([[i,this._posArg?t[n*s][this._orientation]+this._posArg-t[0][this._orientation]:t[n*s][this._orientation]],[i+t[0].width*s+this._mlayout.colGap*(s-1),this._posArg?t[n*s][this._orientation]+this._posArg-t[0][this._orientation]:t[n*s][this._orientation]]])}else{let i=t[0].top,s=this._mlayout.numRows;for(let n=0;n<e;n++)this._rules.children[n]._setVertices([[this._posArg?t[n*s][this._orientation]+this._posArg-t[0][this._orientation]:this._mlayout.group.bounds[this._orientation],i],[this._posArg?t[n*s][this._orientation]+this._posArg-t[0][this._orientation]:this._mlayout.group.bounds[this._orientation],i+t[0].height*s+this._mlayout.rowGap*(s-1)]])}}else if(this._mlayout.type===y.Stack){let t=this._mlayout.group.bounds;"x"==this._channel?this._rules.children[0]._setVertices([[t.left,this._posArg?this._posArg:t[this._orientation]],[t.right,this._posArg?this._posArg:t[this._orientation]]]):this._rules.children[0]._setVertices([[this._posArg?this._posArg:t[this._orientation],t.top],[this._posArg?this._posArg:t[this._orientation],t.bottom]])}this._rules.children.forEach((t=>t._updateBounds())),this._rules._updateBounds(),this._updateBounds()}_positionTicks(){let t=this._mlayout.cellBounds;if("x"==this._channel){let e="bottom"==this._orientation?1:-1;for(let[i,s]of this._ticks.children.entries()){let n=this._posArg?t[i][this._orientation]+this._posArg-t[0][this._orientation]+this._tickOffset*e:t[i][this._orientation]+this._tickOffset*e;s._setVertices([[t[i].x,n],[t[i].x,n+e*this._tickSize]]),s._updateBounds()}}else if("y"==this._channel){let e="left"==this._orientation?-1:1;for(let[i,s]of this._ticks.children.entries()){let n=this._posArg?t[i][this._orientation]+this._posArg-t[0][this._orientation]+this._tickOffset*e:this._mlayout.group.bounds[this._orientation]+this._tickOffset*e,r="middle"==this._tickAnchor?t[i].y:t[i][this._tickAnchor];s._setVertices([[n,r],[n+e*this._tickSize,r]]),s._updateBounds()}}this._ticks._updateBounds(),this._updateBounds()}_positionLabels(){let t=this._mlayout.cellBounds;if("x"==this._channel){let e="bottom"==this._orientation?["center","top"]:["center","bottom"],i="bottom"==this._orientation?this._labelOffset:-this._labelOffset;for(let[s,n]of this._labels.children.entries())n.x=t[s].x,n.y=this._posArg?t[s][this._orientation]+this._posArg-t[0][this._orientation]+i:t[s][this._orientation]+i,n.anchor=e,this._labelRotation&&(n._rotate=[this._labelRotation,n.x,n.y],n.anchor=["right",e[1]])}else if("y"==this._channel){let e="left"==this._orientation?["right","middle"]:["left","middle"],i="left"==this._orientation?-this._labelOffset:this._labelOffset;for(let[s,n]of this._labels.children.entries())n.x=this._posArg?t[s][this._orientation]+this._posArg-t[0][this._orientation]+i:this._mlayout.group.bounds[this._orientation]+i,n.y="middle"==this._tickAnchor?t[s].y:t[s][this._tickAnchor],n.anchor=e,this._labelRotation&&(n._rotate=[this._labelRotation,n.x,n.y])}this._labels._updateBounds(),this._updateBounds()}_positionTitle(){let t=this._rules.bounds;this._title.achor=this._titleAnchor,this._titlePosition?(this._title.x=this._titlePosition[0],this._title.y=this._titlePosition[1],"y"!=this._channel&&"height"!=this._channel||this._rotateYTitle&&(this._title._rotate="left"==this._orientation?[-90,this._title.bounds.x,this._title.bounds.y]:[90,this._title.bounds.x,this._title.bounds.y])):"x"==this._channel?(this._title.x=t.x,this._titleOffset=this._labels.bounds.height+this._labelOffset+15,this._title.y="top"==this._orientation?t.top-this._titleOffset:t.bottom+this._titleOffset):(this._titleOffset=this._labels.bounds.width+this._labelOffset+15,this._title.x="left"==this._orientation?t.left-this._titleOffset:t.right+this._titleOffset,this._title.y=t.y,this._rotateYTitle&&(this._title._rotate="left"==this._orientation?[-90,this._title.bounds.x,this._title.bounds.y]:[90,this._title.bounds.x,this._title.bounds.y])),this._title._updateBounds(),this._updateBounds()}matches(t){return at(this._item).split("_")[0]===at(t).split("_")[0]}}class Zt extends St{constructor(t,e){super(),this.type=T.Legend,this.id=this.type+pt[this.type]++,this.encoding=t,this._textColor="textColor"in e?e.textColor:"#555",this._strokeColor="strokeColor"in e?e.strokeColor:"#555",this._fontSize="fontSize"in e?e.fontSize:"12px",this._x="x"in e?e.x:0,this._y="y"in e?e.y:0,this._showTitle=!("showTitle"in e)||e.showTitle,"numCols"in e||"numRows"in e?(this._numCols=e.numCols,this._numRows=e.numRows):this._numCols=1,this._orientation="orientation"in e?e.orientation:v,this._initialize()}toJSON(){let t=super.toJSON();return"args"in t||(t.args={}),t.args.textColor=this._textColor,t.channel=this.encoding.channel,t.field=this.encoding.field,t.args.strokeColor=this._strokeColor,t.args.x=this._x,t.args.y=this._y,t.args.orientation=this._orientation,t}get field(){return this.encoding.field}get channel(){return this.encoding.channel}get fieldType(){return this.encoding.datatable.getFieldType(this.field)}_initialize(){let t=this.encoding.scene,e=this.encoding.field;switch(this.encoding.datatable.getFieldType(e)){case A.String:this._createCategoricalColorLegend(t,e);break;case A.Date:case A.Number:case A.Integer:this._createNumericalColorLegend(t,e)}this._updateBounds()}_createNumericalColorLegend(t,e){let i,s,n;if(this._orientation==v?(i=15,s=300):(i=300,s=15),this._showTitle){let s=t.mark("text",{fillColor:this._textColor,text:e,x:this._x+i/2,y:this._y,anchor:["center","middle"]});this.addChild(s),n=20}else n=0;let r,a=t.mark("rect",{top:this._y+n,left:this._x,width:i,height:s,strokeWidth:0,opacity:this.encoding.anyItem.opacity}),o=[Math.min(...this.encoding.data),Math.max(...this.encoding.data)],h=this.encoding.scale.mapping,l=[],c=[];if(h){let e=Object.keys(h).map((t=>parseFloat(t))).sort(((t,e)=>t-e));this._orientation==v?(r=new U({x1:0,y1:100,x2:0,y2:0}),e.forEach((e=>{let a=(e-o[0])/(o[1]-o[0]);r.addStop(100*a,h[e],1);let d=t.mark("line",{x1:this._x+i,x2:this._x+i+5,y1:this._y+s-a*s+n,y2:this._y+s-a*s+n,strokeColor:this._strokeColor});c.push(d);let u=t.mark("text",{fillColor:this._textColor,text:e.toFixed(0),x:this._x+i+5+5,y:this._y+s-a*s+n,anchor:["left","middle"]});l.push(u)}))):(r=new U({x1:0,y1:0,x2:100,y2:0}),e.forEach((e=>{let a=(e-o[0])/(o[1]-o[0]);r.addStop(100*a,h[e],1);let d=t.mark("line",{x1:this._x+a*i,x2:this._x+a*i,y1:this._y+20-5+n,y2:this._y+s+5+n,strokeColor:this._strokeColor});c.push(d);let u=t.mark("text",{fillColor:this._textColor,text:e.toFixed(0),x:this._x+a*i,y:this._y+s+5+n,anchor:["center","top"]});l.push(u)})))}else{let a=this.encoding.scale.domain,o=this.encoding.datatable,h=o.getFieldType(e),d=[],u=h===A.Date?o.getUniqueFieldValues(e):Et(this.encoding.data);if(u.length<=10)d=u,d.sort(((t,e)=>t-e));else if(h===A.Date){u.sort(((t,e)=>t-e));for(let t=0;t<u.length;t+=Math.ceil(u.length/10))d.push(u[t])}else{let t=(a[1]-a[0])/9;for(let e=0;e<10;e++)d.push(a[0]+e*t);let e=0;for(;t<1;)t*=10,e++;d=d.map((t=>t.toFixed(e)))}this._orientation==v?(r=new U({x1:0,y1:100,x2:0,y2:0}),d.forEach((d=>{let u=(d-a[0])/(a[1]-a[0]);r.addStop(100*u,this.encoding.scale.map(d),1);let f=t.mark("line",{x1:this._x+i,x2:this._x+i+5,y1:this._y+s-u*s+n,y2:this._y+s-u*s+n,strokeColor:this._strokeColor});c.push(f);let p=t.mark("text",{fillColor:this._textColor,text:h===A.Date?o.getRawValue(e,d):d,x:this._x+i+5+5,y:this._y+s-u*s+n,anchor:["left","middle"]});l.push(p)}))):(r=new U({x1:0,y1:0,x2:100,y2:0}),d.forEach((d=>{let u=(d-a[0])/(a[1]-a[0]);r.addStop(100*u,this.encoding.scale.map(d),1);let f=t.mark("line",{x1:this._x+u*i,x2:this._x+u*i,y1:this._y+s+n,y2:this._y+s+5+n,strokeColor:this._strokeColor});c.push(f);let p=t.mark("text",{fillColor:this._textColor,text:h===A.Date?o.getRawValue(e,d):d,x:this._x+u*i,y:this._y+s+5+n,anchor:["center","top"]});l.push(p)})))}a.styles.fillColor=r,this.addChild(a);for(let t of l)this.addChild(t);for(let t of c)this.addChild(t)}get textColor(){return this._textColor}set textColor(t){this._textColor=t,this.setTextColor(this)}get orientation(){return this._orientation}set orientation(t){this._orientation=t,this.removeAll(),this._initialize()}setTextColor(t){if(t.children&&0!==t.children.length)for(let e of t.children)e.type===T.PointText?e.fillColor=this._textColor:e.children&&e.children.length>0&&this.setTextColor(e)}_createCategoricalColorLegend(t,e){let i=0;this._showTitle&&(this.addChild(new Jt({fillColor:this._textColor,fontSize:this._fontSize,text:e,x:this._x,y:this._y,anchor:["left","top"]})),i=parseFloat(this._fontSize)+5);let s=t.mark("rect",{top:this._y+2+i,left:this._x,width:10,height:10,strokeWidth:0,opacity:this.encoding.anyItem.opacity}),n=t.mark("text",{fillColor:this._textColor,fontSize:this._fontSize,x:this._x+20,y:this._y+i,anchor:["left","top"]}),r=t.glyph(s,n),a=this.encoding.scale,o=new zt(a.domain.map((t=>({category:t,value:a.map(t)})))),h=t.repeat(r,o);t.encode(n,{channel:"text",field:"category",_remember:!1}),t.encode(s,{channel:"fillColor",field:"category",_remember:!1,scale:a}),h.layout=Hc("grid",{numCols:this._numCols,numRows:this._numRows}),this.addChild(h)}pathHitTest(t,e){let i=ct(this);for(let s=i.length-1;s>=0;s--){let n=i[s];if(ft(n)&&n.contains(t,e))return n}return null}matches(t){let e=at(t).split("_")[0],i=this.encoding.scale.encodings;for(let t of i){if(at(t.anyItem).split("_")[0]===e)return!0}return!1}}class Kt extends St{constructor(t){if(super(),this.type=T.Glyph,this._id=this.type+pt[this.type]++,t)for(let e of t)this.addChild(e)}duplicate(){let t=this.getScene().glyph();for(let e of this.children)t.addChild(e.duplicate());return t.classId=this.classId,this._dataScope&&(t.dataScope=this._dataScope.clone()),t}}class Xt extends Z{constructor(t){super(t),this.type=T.Area,this.closed=!0,this._orientation="orientation"in t?t.orientation:void 0,this._baseline="baseline"in t?t.baseline:void 0,t&&"vertices"in t&&this.segments.push(new $(this.vertices[this.vertices.length-1],this.vertices[0],this,this.segmentCounter++))}get baseline(){return this._baseline}set baseline(t){this._baseline=t}get orientation(){return this._orientation}set orientation(t){this._orientation=t}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(t){super.copyPropertiesTo(t),t._baseline=this._baseline,t._orientation=this._orientation}resizeArea(t,e){let i=this.vertices[this.vertices.length/2].x,s=this.vertices[this.vertices.length/2].y,n=this.width,r=this.height;for(let a of this.vertices)a.x=i+t/n*(a.x-i),a.y=s+e/r*(a.y-s);this._updateBounds()}getSVGPathData(){return super.getSVGPathData()+" z"}}class Qt extends Z{constructor(t){super(t),this.type=T.Ring,this.closed=!0,this._x="x"in t?t.x:0,this._y="y"in t?t.y:0,this._innerRadius="innerRadius"in t?t.innerRadius:100,this._outerRadius="outerRadius"in t?t.outerRadius:200}get innerRadius(){return this._innerRadius}set innerRadius(t){this._innerRadius=t}get outerRadius(){return this._outerRadius}set outerRadius(t){this._outerRadius=t,this._updateBounds()}get x(){return this._x}get y(){return this._y}get center(){return new Y(this._x,this._y)}set x(t){this._x=t,this._updateBounds()}set y(t){this._y=t,this._updateBounds()}get thickness(){return this._outerRadius-this._innerRadius}_doTranslate(t,e){this._x+=t,this._y+=e,this._updateBounds()}_updateBounds(){this._bounds=new a(this._x-this._outerRadius,this._y-this._outerRadius,2*this._outerRadius,2*this._outerRadius)}copyPropertiesTo(t){super.copyPropertiesTo(t),t._x=this._x,t._y=this._y,t._innerRadius=this._innerRadius,t._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 te extends Z{constructor(t){super(t),this.type=T.Polygon,this.closed=!0,"x"in t&&(this._x=t.x),"y"in t&&(this._y=t.y),"radius"in t&&(this._radius=t.radius)}get radius(){return this._radius}get x(){return this._x}get y(){return this._y}get center(){return new Y(this._x,this._y)}set x(t){this._x=t,this._updateBounds()}set y(t){this._y=t,this._updateBounds()}set radius(t){this._radius=t,this._updateBounds()}copyPropertiesTo(t){super.copyPropertiesTo(t),t._x=this._x,t._y=this._y,t._radius=this._radius}_doTranslate(t,e){this._x+=t,this._y+=e,super._doTranslate(t,e)}}class ee{constructor(t,e){this.direction=e,this.items=t,this.type=S,this.id=this.type+"_"+[...new Set(this.items.map((t=>t.classId)))].join("_")}apply(){let t,e=this.direction;this.direction==C.Top||this.direction==C.Left?t=Math.min(...this.items.map((t=>t.bounds[e]))):this.direction==C.Bottom||this.direction==C.Right?t=Math.max(...this.items.map((t=>t.bounds[e]))):this.direction!=C.Center&&this.direction!=C.Middle||(t=n.mean(this.items.map((t=>t.bounds[e]))));let i=this.items.map((i=>t-i.bounds[e])),s=e==C.TOP||e==C.Middle||e==C.Bottom?"y":"x";this.items.forEach(((t,e)=>{if(t.parent&&t.parent.layout&&t.parent.layout.type==y.Stack){let n="x"==s?i[e]:0,r="y"==s?i[e]:0;t.parent._doTranslate(n,r)}else{let n="x"==s?i[e]:0,r="y"==s?i[e]:0;t._doTranslate(n,r)}}));let r={};this.items.forEach((t=>r[t.classId]=t)),Object.values(r).forEach((t=>t.getScene()._updateAncestorBounds(t)))}toJSON(){let t={};return t.items=this.items.map((t=>t.id)),t.direction=this.direction,t.type=this.type,t.id=this.id,t}}class ie{constructor(t,e,i,s,n,r,a){this.item=t,this.baseItem=e,this.scene=i,this.channel=s,this.itemAnchor=n,this.baseAnchor=r,this.offset=a,this.type=E,this.id=this.type+"_"+this.item.classId+"_"+this.baseItem.classId+"_"+s}apply(){let t=et(this.item,this.scene),e=et(this.baseItem,this.scene),i=this.itemAnchor,s=this.baseAnchor,n=this.item.type==T.PointText;if("radialDistance"==this.channel)for(let n=0;n<t.length;n++){let r,a=e[n],o=t[n];a.type==T.Arc||a.type==T.Ring?r="top"==s?a.outerRadius+this.offset:"bottom"==s?a.innerRadius+this.offset:(a.outerRadius+a.innerRadius)/2+this.offset:a.type==T.Circle&&(r="top"==s?a.radius+this.offset:"bottom"==s?this.offset:a.radius/2+this.offset),o._doTranslate(a.x-o.x,a.y-r-o.bounds[i]),o._rotate?o._rotate=[o._rotate[0],a.x,a.y]:o._rotate=[0,a.x,a.y]}else if("angle"==this.channel)for(let n=0;n<t.length;n++){let r,a=e[n],o=t[n];r=a.type==T.Arc?"left"==s?a.endAngle+this.offset:"center"==s?a.startAngle+a.angle/2+this.offset:a.startAngle+this.offset:90,o._rotate?o._rotate[0]=90-r:(o._doTranslate(a.x-o.bounds[i],a.y-t[n].y),o._rotate=[90-r,e[n].x,e[n].y])}else{let r;if(this.baseItem.type==T.Link)switch(s){case"left":case"top":r=0;break;case"center":case"middle":r=.5;break;case"right":case"bottom":r=1}for(let a=0;a<t.length;a++){let o=this.baseItem.type==T.Link?e[a].getPointAt(r)[this.channel]:e[a].bounds[s]+this.offset;n?(t[a].anchor["x"==this.channel?0:1]=this.itemAnchor,t[a][this.channel]=o):"x"==this.channel?t[a]._doTranslate(o-t[a].bounds[i],0):t[a]._doTranslate(0,o-t[a].bounds[i])}}this.item.getScene()._updateAncestorBounds(this.item),this.baseItem.getScene()._updateAncestorBounds(this.baseItem)}toJSON(){let t={};return t.item=this.item.id,t.baseItem=this.baseItem.id,t.channel=this.channel,t.itemAnchor=this.itemAnchor,t.baseAnchor=this.baseAnchor,t.offset=this.offset,t.type="affixation",t.id=this.id,t}}class se extends St{constructor(t,e,i){super(),this.type=T.Gridlines,this.id=this.type+pt[this.type]++,this.encoding=t,this.channel=this.encoding.channel,this._item=e,this._strokeColor="strokeColor"in i?i.strokeColor:"#ddd",this._strokeWidth="strokeWidth"in i?i.strokeWidth:1,"radialDistance"==this.channel&&"angle"in i&&(this._rotate=[-i.angle,this.encoding.x,this.encoding.y])}toJSON(){let t={args:{}};return t.type=this.type,t.id=this.id,t.args.item=this._item.id,t.args.strokeColor=this._strokeColor,t.args.strokeWidth=this._strokeWidth,t.args.values=this._values,"time"===this.encoding.scale.type&&(t.args.isDate=!0),t.channel=this.encoding.channel,t.field=this.encoding.field,this._rotate&&(t.args.angle=this._rotate[0]),t}get values(){return this._values}set values(t){this._values=t,this.updateLines(),this.updateLinePositions()}get strokeColor(){return this._strokeColor}set strokeColor(t){this._strokeColor=t;for(let e of this.children)e.strokeColor=t}get strokeWidth(){return this._strokeWidth}set strokeWidth(t){this._strokeWidth=t;for(let e of this.children)e.strokeWidth=t}matches(t){let e=at(t).split("_")[0],i=this.encoding.scale.encodings;for(let t of i){if(at(t.anyItem).split("_")[0]===e)return!0}return!1}updateLinePositions(){let t=bt(this._item)?bt(this._item):vt(this._item);if("x"==this.channel||"width"==this.channel){let e=t.bounds,i=this.encoding.getScaleRange(this._item);for(let[t,s]of this.children.entries()){let n=i[0]+this.encoding.scale.map(this._values[t])-this.encoding.scale.range[0];s._setVertices([[n,e.top],[n,e.bottom]])}}else if("y"==this.channel||"height"==this.channel){let e=t.bounds,i=this.encoding.getScaleRange(this._item);if(this.encoding.flip)for(let[t,s]of this.children.entries()){let n=i[1]-this.encoding.scale.map(this._values[t])+this.encoding.scale.range[0];s._setVertices([[e.left,n],[e.right,n]])}else for(let[t,s]of this.children.entries()){let n=i[0]-this.encoding.scale.map(this._values[t])+this.encoding.scale.range[0];s._setVertices([[e.left,n],[e.right,n]])}}else if("radialDistance"==this.channel)for(let[t,e]of this.children.entries())e.x=this._item.parent.x,e.y=this._item.parent.y,e.radius=this.encoding.scale.map(this._values[t]);for(let t of this.children)t._updateBounds();this._updateBounds()}updateLines(){if(this.children=[],"x"==this.channel||"y"==this.channel||"width"==this.channel||"height"==this.channel)for(let t=0;t<this._values.length;t++){let e=new Z({strokeColor:this._strokeColor,fillColor:"none",strokeWidth:this._strokeWidth});e.type=T.Line,e.id=this.id+"line"+t,this.addChild(e)}else if("radialDistance"==this.channel)for(let t=0;t<this._values.length;t++){let e=new Pt({strokeColor:this._strokeColor,fillColor:"none",strokeWidth:this._strokeWidth});e.type=T.Circle,e.id=this.id+"line"+t,this.addChild(e)}}}class ne extends St{constructor(){super(),this.type=T.Collection,this._id=this.type+pt[this.type]++,this.classId=this.id,this._childrenOrder=void 0}get childrenOrder(){return this._childrenOrder?this._childrenOrder:{field:"atlas_rowId",direction:"asc"}}set childrenOrder(t){if(!("field"in t)&&!("direction"in t))return;let e,i=t.field;if(this.dataScope.dataTable.hasField(i)){if(this._childrenOrder=t,i===h)e=(t,e)=>parseInt(t.dataScope.getFieldValue(i).substring(1))-parseInt(e.dataScope.getFieldValue(i).substring(1));else{switch(this.children[0].dataScope.getFieldType(i)){case A.Date:break;case A.Number:case A.Integer:e=(t,e)=>t.dataScope.aggregateNumericalField(i)-e.dataScope.aggregateNumericalField(i);break;case A.String:e=t.ranking?(e,s)=>t.ranking.indexOf(e.dataScope.getFieldValue(i))-t.ranking.indexOf(s.dataScope.getFieldValue(i)):(t,e)=>t.dataScope.getFieldValue(i)<e.dataScope.getFieldValue(i)?-1:1}}this.children.sort(e),"desc"==t.direction&&this.children.reverse(),this.layout&&this.layout.run()}else console.warn("Cannot order collection children by an non-existent field",t.field)}duplicate(){let t=this.getScene().collection();for(let e=0;e<this.children.length;e++){let i=this.children[e];t.addChild(i.duplicate())}if(t.classId=this.classId,this.parent.addChild(t),this._layout){let e=this._layout.clone();t.layout=e}return t}contains(t,e){if([T.Arc,T.Pie,T.Polygon,T.Area].indexOf(this.firstChild.type)>=0){let i=this.getSVGPathData();if(""!==i){let s=mt.getContext(),n=new Path2D(i);return s.lineWidth=Math.max(this.strokeWidth,2.5),s.stroke(n),s.isPointInPath(n,t,e)}}return this._bounds||this._updateBounds(),this._bounds.contains(t,e)}getSVGPathData(){let t="";for(let e of this.children)if(e.getSVGPathData)t+=e.getSVGPathData();else if(e.bounds){let i=e.bounds;t+=["M",i.left,i.top].join(" "),t+=["L",i.right,i.top].join(" "),t+=["L",i.right,i.bottom].join(" "),t+=["L",i.left,i.bottom,"Z"].join(" ")}return t}}class re extends Z{constructor(t){super(t),this._type=T.Arc,this.closed=!0,this._x="x"in t?t.x:0,this._y="y"in t?t.y:0,this._innerRadius="innerRadius"in t?t.innerRadius:100,this._outerRadius="outerRadius"in t?t.outerRadius:200,this._startAngle="startAngle"in t?t.startAngle:0,this._endAngle="endAngle"in t?t.endAngle:90,this._sr=kt(this._startAngle),this._er=kt(this._endAngle);let e=this._x+this._innerRadius*Math.cos(this._sr),i=this._y-this._innerRadius*Math.sin(this._sr),s=this._x+this._innerRadius*Math.cos(this._er),n=this._y-this._innerRadius*Math.sin(this._er),r=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),h=this._y-this._outerRadius*Math.sin(this._er);this._setVertices([[e,i],[r,a],[o,h],[s,n]])}get type(){return 0===this._innerRadius?T.Pie:T.Arc}set type(t){this._type=t}get innerRadius(){return this._innerRadius}set innerRadius(t){this._innerRadius=t,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[3].x=this._x+this._innerRadius*Math.cos(this._er),this.vertices[3].y=this._y-this._innerRadius*Math.sin(this._er),this._updateBounds()}get outerRadius(){return this._outerRadius}get thickness(){return this._outerRadius-this._innerRadius}set outerRadius(t){this._outerRadius=t,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._updateBounds()}get x(){return this._x}get y(){return this._y}get center(){return new Y(this._x,this._y)}set x(t){this._x=t,this.vertices[0].x=this._x+this._innerRadius*Math.cos(this._sr),this.vertices[1].x=this._x+this._outerRadius*Math.cos(this._sr),this.vertices[2].x=this._x+this._outerRadius*Math.cos(this._er),this.vertices[3].x=this._x+this._innerRadius*Math.cos(this._er),this._updateBounds()}set y(t){this._y=t,this.vertices[0].y=this._y-this._innerRadius*Math.sin(this._sr),this.vertices[1].y=this._y-this._outerRadius*Math.sin(this._sr),this.vertices[2].y=this._y-this._outerRadius*Math.sin(this._er),this.vertices[3].y=this._y-this._innerRadius*Math.sin(this._er),this._updateBounds()}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}sweepOver(t){let e=this.startAngle,i=this.endAngle;i<e&&(i+=360);let s=t.startAngle,n=t.endAngle;return n<s&&(n+=360),s>=e&&s<=i&&n>=e&&n<=i}_doTranslate(t,e){this._x+=t,this._y+=e,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._updateBounds()}_updateBounds(){this._bounds=new a(this._x-this._outerRadius,this._y-this._outerRadius,2*this._outerRadius,2*this._outerRadius)}copyPropertiesTo(t){super.copyPropertiesTo(t),t._x=this._x,t._y=this._y,t._innerRadius=this._innerRadius,t._outerRadius=this._outerRadius,t._startAngle=this._startAngle,t._endAngle=this._endAngle,t._sr=this._sr,t._er=this._er}getSVGPathData(){let t=this._endAngle<this._startAngle?this._endAngle+360-this._startAngle:this._endAngle-this._startAngle,e=t>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,t,e,0,this.vertices[2].x,this.vertices[2].y].join(" "),"L "+this.vertices[3].x+", "+this.vertices[3].y,"A "+[this._innerRadius,this._innerRadius,t,e,1,this.vertices[0].x,this.vertices[0].y].join(" ")].join(" ")}adjustAngle(t,e){this._startAngle=t,this._endAngle=e,this._sr=kt(this._startAngle),this._er=kt(this._endAngle),this.vertices[0].x=this._x+this._innerRadius*Math.cos(this._sr),this.vertices[0].y=this._y-this._innerRadius*Math.sin(this._sr),this.vertices[1].x=this._x+this._outerRadius*Math.cos(this._sr),this.vertices[1].y=this._y-this._outerRadius*Math.sin(this._sr),this.vertices[2].x=this._x+this._outerRadius*Math.cos(this._er),this.vertices[2].y=this._y-this._outerRadius*Math.sin(this._er),this.vertices[3].x=this._x+this._innerRadius*Math.cos(this._er),this.vertices[3].y=this._y-this._innerRadius*Math.sin(this._er)}}class ae extends q{constructor(t){super(t),this.type=T.Image,this._src=t.src,this._x="x"in t?t.x:0,this._y="y"in t?t.y:0,this._width="width"in t?t.width:100,this._height="height"in t?t.height:100}toJSON(){let t=super.toJSON();return t.src=this._src,t.x=this._x,t.y=this._y,t.width=this._width,t.height=this._height,t}get src(){return this._src}set src(t){this._src=t}get width(){return this._width}set width(t){this._width=t,this._updateBounds()}get height(){return this._height}set height(t){this._height=t,this._updateBounds()}get x(){return this._x}set x(t){this._x=t,this._updateBounds()}get y(){return this._y}set y(t){this._y=t,this._updateBounds()}get bounds(){return this._bounds||this._updateBounds(),this._bounds}_updateBounds(){this._bounds=new a(this._x,this._y,this._width,this._height)}copyPropertiesTo(t){t.attrs=Object.assign({},this.attrs),t.styles=Object.assign({},this.styles),this._dataScope&&(t._dataScope=this._dataScope.clone()),t.x=this._x,t.y=this._y,t.width=this._width,t.height=this._height,t.src=this._src}_doTranslate(t,e){this._x+=t,this._y+=e,this._updateBounds()}}class oe extends Z{constructor(t){super(t),this.type=T.Link,this.mode="mode"in t?t.mode:"linear",this.source=void 0,this.target=void 0,this.sourceAnchor="sourceAnchor"in t?t.sourceAnchor:["center","middle"],this.targetAnchor="targetAnchor"in t?t.targetAnchor:["center","middle"],this.sourceOffset="sourceOffset"in t?t.sourceOffset:[0,0],this.targetOffset="targetOffset"in t?t.targetOffset:[0,0]}radialvalue(t,e){let i=t-Math.PI/2;return[t=e*Math.cos(i),e*=Math.sin(t)]}bezierCurveHorizontal(t,e,i,s){return`M ${t} ${e} C ${(t+i)/2} ${e} ${t} ${s} ${i} ${s}`}bezierCurveVertical(t,e,i,s){return`M ${t} ${e} C ${t} ${(e+s)/2} ${i} ${e} ${i} ${s}`}bezierCurveRadial(t,e,i,s){let n=this.radialvalue(t,e),r=this.radialvalue(t,(e+s)/2),a=this.radialvalue(i,e),o=this.radialvalue(i,s);return`M ${n[0]} ${n[1]} C ${r[0]} ${r[1]} ${a[0]} ${a[1]} ${o[0]} ${o[1]}`}_updateBounds(){if(null!=this.source&&null!=this.target){let t=this.source.bounds[this.sourceAnchor[0]]+this.sourceOffset[0],e=this.source.bounds[this.sourceAnchor[1]]+this.sourceOffset[1],i=this.target.bounds[this.targetAnchor[0]]+this.targetOffset[0],s=this.target.bounds[this.targetAnchor[1]]+this.targetOffset[1];this._bounds=new a(Math.min(t,i),Math.min(e,s),Math.abs(t-i),Math.abs(e-s))}else this._bounds=new a(0,0,0,0)}getSVGPathData(){if(void 0===this.source||void 0===this.target)return"";let t=this.source.bounds[this.sourceAnchor[0]]+this.sourceOffset[0],e=this.source.bounds[this.sourceAnchor[1]]+this.sourceOffset[1],i=this.target.bounds[this.targetAnchor[0]]+this.targetOffset[0],s=this.target.bounds[this.targetAnchor[1]]+this.targetOffset[1];switch(this.mode){case"curveHorizontal":return this.bezierCurveHorizontal(t,e,i,s);case"curveVertical":return this.bezierCurveVertical(t,e,i,s);case"linear":default:return`M ${t} ${e} L ${i} ${s}`}}copyPropertiesTo(t){super.copyPropertiesTo(t),t.sourceAnchor=this.sourceAnchor.slice(),t.targetAnchor=this.targetAnchor.slice(),t.sourceOffset=this.sourceOffset.slice(),t.targetOffset=this.targetOffset.slice(),t.mode=this.mode}getPointAt(t){const e=yt.getSVG();let i=document.createElementNS("http://www.w3.org/2000/svg","path");i.setAttribute("d",this.getSVGPathData()),e.appendChild(i);let s=i.getTotalLength();return i.getPointAtLength(s*t)}}const he=function(t,e,i){let s=t.getScene();dt(t)||s._reapplyConstraints(t),s.getRelatedAxes(t).forEach((t=>{t.encoding&&void 0!==t.encoding.scale.offset&&(t.encoding.scale.offset+="x"===t.channel||"width"===t.channel?e:i),0===i||"x"!==t.channel&&"width"!==t.channel||void 0===t._posArg||(t._posArg=t._posArg+i),0===e||"y"!==t.channel&&"height"!==t.channel||void 0===t._posArg||(t._posArg=t._posArg+e),t.reposition()})),s.getRelatedGridlines(t).forEach((t=>t.updateLinePositions()))},le=function(t,e,i){let s=t.getScene();s._relayoutAncestors(t,e);let n=[t],r=t.firstChild;for(;r;)n.push(r),r=r.firstChild;for(let t of n)t.getScene()._reapplyConstraints(t);if(i)s.reCreateRelatedAxes(t);else{s.getRelatedAxes(t).forEach((t=>t.reposition()))}s.getRelatedGridlines(t).forEach((t=>t.updateLinePositions()))},ce=function(t){for(let e of t.encodings)e._map(),e._apply();for(let e of t.encodings)e.scene._updateAncestorBounds(e.item,e.items);let e=t.encodings.map((t=>t.anyItem)),i={};for(let t of e)"vertex"===t.type||"segment"===t.type?i[t.parent.classId]=t.parent:i[t.classId]=t;for(let t of Object.values(i))t.getScene()._reapplyConstraints(t);for(let e of t.encodings){let i=e.anyItem,s=e.scene.getRelatedAxes(i);for(let i of s)i.encoding&&i.encoding.scale===t&&(i.tickValues=e.scene._inferTickValues(e),i.labelValues=e.scene._inferTickValues(e),i._positionPath(),i._showTitle&&i._positionTitle(),"radialDistance"===i._channel&&i._rotate&&(i._rotate=[i._rotate[0],i._item.parent.x,i._item.parent.y]),i._updateBounds());e.scene.getRelatedGridlines(i).forEach((t=>t.updateLinePositions()))}},de=function(t){for(let e of t.encodings)e._apply();for(let e of t.encodings)e.scene._updateAncestorBounds(e.item,e.items);let e=t.encodings.map((t=>t.anyItem)),i={};for(let t of e)"vertex"===t.type||"segment"===t.type?i[t.parent.classId]=t.parent:i[t.classId]=t;for(let t of Object.values(i))t.getScene()._reapplyConstraints(t);for(let e of t.encodings){let t=e.anyItem;e.scene.getRelatedAxes(t).forEach((t=>t.reposition())),e.scene.getRelatedGridlines(t).forEach((t=>t.updateLinePositions()))}},ue=function(t,e){let i=t.getScene();i._relayoutAncestors(t,e),i._reapplyConstraints(t),i.getRelatedAxes(t).forEach((t=>t.reposition())),i.getRelatedGridlines(t).forEach((t=>t.updateLinePositions()))},fe=function(t,e){let i=e.getScene(),s=i.getRelatedAxes(t);for(let n of s)n._item.classId===t.classId&&(n._item=e,n._items=et(e,i));let n=i.encodings[at(t)];if(n){i.encodings[at(e)]={};for(let s of["x","y"]){const r=n[s];r&&(r.anyItem=e,r.items=et(e,i),i.encodings[at(e)][s]=r,delete i.encodings[at(t)][s])}0===Object.keys(n).length&&delete i.encodings[at(t)]}},pe=function(t,e){let i=e.getScene(),s=i.encodings[at(t)];if(s){i.encodings[at(e)]={};for(let n of["x","y"]){const r=s[n];r&&(r.anyItem=e,r.items=et(e,i),i.encodings[at(e)][n]=r,delete i.encodings[at(t)][n])}0===Object.keys(s)&&delete i.encodings[at(t)]}let n=i.getRelatedAxes(t);for(let s of n)s._item.classId===t.classId&&(s._item=e,s._items=et(e,i))},ge=function(t){let e=t.getScene(),i=e.encodings[at(t)];for(let t in i)i[t]._apply();e.getRelatedAxes(t).forEach((t=>t.reposition())),e.getRelatedGridlines(t).forEach((t=>t.updateLinePositions()))};function _e(t,e,i,s){let n=s.getFieldType(i);if(n!=A.String&&n!=A.Date&&n!=A.Integer)throw new Error(G.REPOPULATE_BY_NONCAT+": "+i+" is "+n);if(e.parent&&e.parent.dataScope&&!e.parent.dataScope.isFullTable()&&e.parent.dataScope.dataTable!=s)throw new Error(G.REPOPULATE_DT_MISMATCH);return function(t,e,i,s){let n=et(e.parent,t);1===n.length&&(e.parent.dataScope=void 0);for(let t of n){let e=s.getFieldSummary(i).unique.map((e=>t.dataScope?t.dataScope.cross(i,e):new It(s).cross(i,e)));e=e.filter((t=>!t.isEmpty()));const n=e.length-t.children.length,r=t.children.length-e.length;for(let e=0;e<r;e++)t.removeChildAt(t.children.length-1);const a=t.children.length;for(let e=0;e<n;e++){let e=t.children[Math.floor(Math.random()*a)].duplicate();t.addChild(e)}t.children.forEach(((t,i)=>t.dataScope=e[i]))}t._relayoutAncestors(e)}(t,e,i,s)}function me(t,e){let i=t.item;if(e.innerRadius===i.outerRadius&&i.sweepOver(e))t.children.push({item:e,children:[]});else if(t.children&&t.children.length>0&&e.innerRadius>i.outerRadius&&i.sweepOver(e))for(let i of t.children)me(i,e)}function ye(t,e,i,s){let n=t.item;if(n.innerRadius=e,n.outerRadius=e+s.map(i[n.id]),t.children&&t.children.length>0)for(let e of t.children)ye(e,n.outerRadius,i,s)}class ve{constructor(t,e){this._type="tree";let i=[],s=[];this._nodeHash={},this._traverse(t,i,s),this._nodeTable=new zt(i,"nodes"),this._linkTable=new zt(s,"links"),this._nodeTable.tree=this,this._linkTable.tree=this,this._data=t,this.aggregateFromLeaves("value","average")}get type(){return this._type}_traverse(t,e,i,s=0){let n={};o in t||(t.id="n"+e.length),e.push(n),t._depth=s;for(let r in t)if("children"==r&&t[r]&&t[r].length>0)for(let n of t[r]){let r=this._traverse(n,e,i,s+1);i.push({parent:t.id,child:r})}else n[r]=t[r];return this._nodeHash[n.id]=n,n.id}getParent(t){let e,i=t.id,s=this._linkTable.data,n=this._nodeTable.data;for(let t in s)if(s[t].child==i){e=s[t].parent;let i=n.findIndex((t=>t.id==e));return n[i]}}getChildren(t){let e=t.id,i=[],s=this._linkTable.data,n=this._nodeTable.data;for(let t in s)if(s[t].parent==e){let e=s[t].child,r=n.findIndex((t=>t.id==e));i.push(n[r])}return i}getNodeDataScope(t){return new It(this._nodeTable).cross(h,t.atlas_rowId)}getMaxDepth(){return this._nodeTable._fieldSummaries._depth.max}getRoot(){return this._nodeTable.data[0]}get nodeTable(){return this._nodeTable}get linkTable(){return this._linkTable}getNode(t){return this._nodeTable.data.filter((e=>e.id==t))[0]}sumLeaves(t,e){if(!t)return 0;let i=t.id,s=[];if(s=this.getChildren(t),s&&s.length>0){let t=0;for(let i of s)t+=this.sumLeaves(i,e);this.getNode(i)["sum"+e]=t}else this.getNode(i)["sum"+e]=t[e];return t["sum"+e]}countLeaves(t,e){if(!t)return 0;let i=t.id,s=[];s=this.getChildren(t);let n=0;if(s&&s.length>0)for(let t of s)n+=this.countLeaves(t,e);else n=1;return this.getNode(i)["count"+e]=n,t["count"+e]}averageLeaves(t,e){if(!t)return 0;let i=t.id,s=[];s=this.getChildren(t);let n=0;if(s&&s.length>0){for(let t of s)n+=this.averageLeaves(t,e);n/=s.length,this.getNode(i)["average"+e]=n}else this.getNode(i)["average"+e]=t[e];return t["average"+e]}medianLeaves(t,e){if(!t)return 0;let i=t.id,s=[];s=this.getChildren(t);let n=[];if(s&&s.length>0){for(let t of s)n.push(this.medianLeaves(t,e));n.sort((function(t,e){return t-e}));let t=Math.floor(n.length/2);n.length%2?this.getNode(i)["median"+e]=n[t]:this.getNode(i)["median"+e]=(n[t-1]+n[t])/2}else this.getNode(i)["median"+e]=t[e];return t["median"+e]}maxLeaves(t,e){if(!t)return 0;let i=t.id,s=[];s=this.getChildren(t);let n=[];if(s&&s.length>0){for(let t of s)n.push(this.maxLeaves(t,e));this.getNode(i)["max"+e]=Math.max(...n)}else this.getNode(i)["max"+e]=t[e];return t["max"+e]}minLeaves(t,e){if(!t)return 0;let i=t.id,s=[];s=this.getChildren(t);let n=[];if(s&&s.length>0){for(let t of s)n.push(this.minLeaves(t,e));this.getNode(i)["min"+e]=Math.min(...n)}else this.getNode(i)["min"+e]=t[e];return t["min"+e]}aggregateFromLeaves(t,e){let i=this.getRoot();switch(e){case"sum":this.sumLeaves(i,t);break;case"count":this.countLeaves(i,t);break;case"average":this.averageLeaves(i,t);break;case"median":this.medianLeaves(i,t);break;case"max":this.maxLeaves(i,t);break;case"min":this.minLeaves(i,t)}}}function be(t,e,i,s,n){switch(e.type){case T.Circle:return function(t,e,i,s,n){let r,a,o=i||k.Outward,h=s||50;if(o!==k.Inward&&o!==k.Outward)throw G.UNKNOWN_DIRECTION+" "+o;return et(e,t).forEach((i=>{let s=t.collection();s.dataScope=void 0,null==a&&(a=s.id),s.classId=a;let l=i.parent;xe(i,e.id,o,h,n,n.getRoot(),s,t,!0),s.layout=Hc("strata",{direction:o,rootMark:i}),l.addChild(s),i===e&&(r=s)})),r}(t,e,i,s,n);case T.Rect:return function(t,e,i,s,n){let r,a,o=i||k.Down,h=s||50;if([k.Up,k.Down,k.Left,k.Right].indexOf(o)<0)throw G.UNKNOWN_DIRECTION+" "+o;return et(e,t).forEach((i=>{let s=t.collection();s.dataScope=void 0,null==a&&(a=s.id),s.classId=a;let l=i.parent;we(i,e.id,o,h,n,n.getRoot(),s,t,!0),s.layout=Hc("strata",{direction:o,rootMark:i}),l.addChild(s),i===e&&(r=s)})),r}(t,e,i,s,n)}}function xe(t,e,i,s,n,r,a,o,h){h&&(t.dataScope=n.getNodeDataScope(r),t.classId=e,a.addChild(t));let l=n.getChildren(r);if(0===l.length)return;let c=t.type===T.Circle||t.type===T.Ring?90:t.startAngle,d=(t.type===T.Circle||t.type===T.Ring?360:t.angle)/l.length;for(let r=0;r<l.length;r++){let h,u=t.type===T.Circle?t.radius:t.outerRadius;h=360===d?o.mark("ring",{innerRadius:u,outerRadius:u+s,x:t.x,y:t.y,strokeColor:t.strokeColor,fillColor:t.fillColor,strokeWidth:t.strokeWidth,opacity:t.opacity}):o.mark("arc",{innerRadius:u,outerRadius:u+s,x:t.x,y:t.y,startAngle:At(c+d*r),endAngle:At(c+d*(r+1)),strokeColor:t.strokeColor,fillColor:t.fillColor,strokeWidth:t.strokeWidth,opacity:t.opacity}),h.dataScope=n.getNodeDataScope(l[r]),h.classId=e,a.addChild(h),xe(h,e,i,s,n,l[r],a,o)}}function we(t,e,i,s,n,r,a,o,h){h&&(t.dataScope=n.getNodeDataScope(r),t.classId=e,a.addChild(t));let l,c,d,u=n.getChildren(r);if(0!==u.length){switch(i){case k.Up:case k.Down:case k.Left:case k.Right:default:l=t.left,c=t.bottom,d=t.width/u.length}for(let r=0;r<u.length;r++){let h=o.mark("rect",{left:l,top:c,width:d,height:s,strokeColor:t.strokeColor,fillColor:t.fillColor,strokeWidth:t.strokeWidth,opacity:t.opacity});l+=d,h.dataScope=n.getNodeDataScope(u[r]),h.classId=e,a.addChild(h),we(h,e,i,s,n,u[r],a,o)}}}class ke{constructor(t,e,i,s){this._listener=t,this._eventType=e,this._selDef=i,this._targetDef=s}getCallbackFunction(t,e){let i=this;return function(s){s.stopPropagation();let r,a=e._getSelection(s,i.selectionDef,i._listener,t.getItem(n.select(this).attr("id"))),o=et(i.targetDef.item,t);i.selectionDef.remember?(e.addGlobalPredicate(t,a.predicate),r=e.getGlobalPredicates(t)):r=e.getGlobalPredicates(t).concat([a.predicate]);for(let t of o){let e=!0;for(let i of r)if(!K(t,i)){e=!1;break}for(let s in i.targetDef.effect)s in t.staticProperties||(t.staticProperties[s]=t[s]),e?t[s]=i.targetDef.effect[s].selected:"unselected"in i.targetDef.effect[s]?t[s]=i.targetDef.effect[s].unselected:s in t.staticProperties&&(t[s]=t.staticProperties[s])}e._renderer.render(t,{visualOnly:!0})}}getRestoreFunction(t,e,i){let s=this;return function(){let n=et(s.targetDef.item,t);if(s.targetDef.effect)for(let t of n)for(let e in s.targetDef.effect)t[e]=t.staticProperties[e];else for(let t of n)for(let e in t.staticProperties)t[e]=t.staticProperties[e];i&&(e._globalPredicates={}),e._renderer.render(t,{visualOnly:!0})}}get listener(){return this._listener}get selectionDef(){return this._selDef}get targetDef(){return this._targetDef}get eventType(){return this._eventType}}class Ce extends St{constructor(t){super(),t&&t.fillColor&&(this.fillColor=t.fillColor),this.type=T.Scene,this._id=this.type+pt[this.type]++,this.encodings={},this.constraints={},this._itemMap={},this._interactions=[]}clear(){this.removeAll(),this.encodings={},this.constraints={},this._itemMap={}}group(t){let e=new St;if(e.classId=e.id,this.addChild(e),t&&t.length>0)for(let i of t)e.addChild(i);return this._itemMap[e.id]=e,e}mark(t,e){let i=void 0===e?{}:e,s=null;switch(i.type=t,t){case T.Rect:{"top"in i||(i.top=0),"left"in i||(i.left=0),"width"in i||(i.width=100),"height"in i||(i.height=100);let t=i.top,e=i.left,n=i.width,r=i.height;i.vertices=[[e,t],[e+n,t],[e+n,t+r],[e,t+r]],delete i.top,delete i.left,delete i.width,delete i.height,"fillColor"in i||(i.fillColor="none"),s=new Ft(i);break}case T.Area:if(void 0!==i&&"x1"in i&&"y1"in i&&"x2"in i&&"y2"in i){let t=i.x1,e=i.y1,s=i.x2,n=i.y2;i.vertices=[[t,e],[s,e],[s,n],[t,n]],delete i.x1,delete i.y1,delete i.x2,delete i.y2}s=new Xt(i);break;case T.Line:if(void 0!==i&&"x1"in i&&"y1"in i&&"x2"in i&&"y2"in i){let t=i.x1,e=i.y1,s=i.x2,n=i.y2;i.vertices=[[t,e],[s,n]],delete i.x1,delete i.y1,delete i.x2,delete i.y2}s=new Z(i),s.type=T.Line;break;case T.Path:s=new Z(i);break;case T.Circle:s=new Pt(i);break;case T.Ring:s=new Qt(i);break;case T.Arc:case T.Pie:s=new re(i);break;case T.Polygon:s=new te(i);break;case"text":case T.PointText:"anchor"in i||(i.anchor=["center","middle"]),s=new Jt(i);break;case T.Image:s=new ae(i);break;case T.Link:s=new oe(i)}return null!==s&&(s.id="id"in i?i.id:s.type+pt[s.type]++,s.classId=s.id,this.addChild(s),this._itemMap[s.id]=s),s}glyph(...t){let e=new Kt(t);return e.classId=e.id,this.addChild(e),this._itemMap[e.id]=e,e}collection(){let t=new ne;return this.addChild(t),this._itemMap[t.id]=t,t}attach(t,e){t.dataScope=new It(e)}repeat(t,e,i){if(!t||void 0===e)throw G.INCOMPLETE_REPEAT_INFO;if(e.nodeTable&&e.linkTable){if(!Array.isArray(t)||2!==t.length)throw G.REPEAT_NODE_LINK;return function(t,e,i,s){let n=s.nodeTable.getFieldSummary(o).unique.map((t=>e.dataScope?e.dataScope.cross(o,t):new It(s.nodeTable).cross(o,t))),r=t.collection(),a={};r.dataScope=e.dataScope?e.dataScope.clone():new It(s.nodeTable),r.addChild(e);for(let t=1;t<n.length;t++){let t=e.duplicate();r.addChild(t)}r.children.forEach(((t,e)=>{t.dataScope=n[e],a[t.dataScope.getFieldValue(o)]=t}));let l=s.linkTable.getFieldSummary(h).unique.map((t=>i.dataScope?i.dataScope.cross(h,t):new It(s.linkTable).cross(h,t))),c=t.collection();c.dataScope=i.dataScope?i.dataScope.clone():new It(s.linkTable),c.addChild(i);for(let t=1;t<l.length;t++){let t=i.duplicate();c.addChild(t)}c.children.forEach(((t,e)=>t.dataScope=l[e]));let d="tree"===s.type?"parent":"source",u="tree"===s.type?"child":"target";for(let t of c.children){let e=t.dataScope.getFieldValue(d),i=t.dataScope.getFieldValue(u);t.source=a[e],t.target=a[i],t._updateBounds()}return t.addChild(c),t.addChild(r),[r,c]}(this,t[0],t[1],e)}{let s=i||{},n=s.field?s.field:zt.RowID,r=s.callback;Tt(n,e);let a=Ot(this,t,n,e,r);return s.layout&&(a.layout=s.layout),a}}repopulate(t,e,i){if(!t||void 0===e)throw G.INCOMPLETE_REPEAT_INFO;let s=i||{},n=s.field?s.field:zt.RowID;Tt(n,e),_e(this,t,n,e)}densify(t,e,i){if(!t||void 0===e)throw G.INCOMPLETE_PARTITION_INFO;let s=i||{},n=s.orientation,r=s.field?s.field:zt.RowID,a="startAngle"in s?s.startAngle:90,o="direction"in s?s.direction:"clockwise",h=s.callback;Tt(r,e);let l=Nt(this,t,n,r,e,h,a,o);return pe(t,l),l}stratify(t,e,i){if(!(e instanceof ve))throw G.STRATIFY_WITHOUT_TREE;if(t.type!==T.Circle&&t.type!==T.Rect)throw G.STRATIFY_WRONG_ITEM;let s=i||{};return be(this,t,s.direction,s.size,e)}divide(t,e,i){if(!t||null==e)throw G.INCOMPLETE_PARTITION_INFO;let s=i||{},n=s.orientation,r=s.field?s.field:zt.RowID,a=s.callback;Tt(r,e);let o=Rt(this,t,n,r,e,a);return s.layout&&(o.layout=s.layout),fe(t,o),o}_validateEncodeArgs(t,e){if(!t||!("channel"in e)||!("field"in e))throw G.INCOMPLETE_BINDING_INFO;let i=e.field;if("vertex"==t.type||"segment"==t.type){if(!t.parent.dataScope&&!t.dataScope)throw G.BIND_WITHOUT_DATASCOPE}else if(!t.dataScope)throw G.BIND_WITHOUT_DATASCOPE;let s=e.table?e.table:t.dataScope?t.dataScope._dt:t.parent.dataScope._dt,n=s.getFieldType(i);if("fillGradient"===e.channel&&[A.String,A.Boolean,A.Date].indexOf(n)>=0)throw G.UNSUPPORTED_FIELDTYPE+e.channel+": "+n;Tt(i,s)}encode(t,e){let i,s=Array.isArray(t)?t:[t],n=[];for(let r of s){let s;if([T.Pie,T.Arc].indexOf(t.type)>=0&&"angle"===e.channel){let i=t.parent;if(i.type===T.Collection&&i.layout&&i.layout.orientation===x){n.push(this._encodeWithinCollection(r,e));continue}}if(this._validateEncodeArgs(r,e),"vertex"==r.type&&r.parent.type==T.Area){let t=et(r.parent,this);s=[];let e=r.parent.vertices.indexOf(r)<r.parent.vertices.length/2;for(let i of t)s=e?s.concat(i.vertices.slice(0,i.vertices.length/2)):s.concat(i.vertices.slice(i.vertices.length/2))}else s=et(r,this);if(1===s.length&&s[0].type===T.Area&&("x"===e.channel||"y"===e.channel))return void console.warn("Only 1 "+r.type+" found, cannot encode "+e.field);!e.scale&&i&&(e.scale=i);let a=this._doEncode(s,e);i||(i=a.scale),n.push(a)}return n.length>1?n:n[0]}_doEncode(t,e){let i=t[0],s=e.channel,n=e.field;"datatable"in e||(e.datatable=i.dataScope?i.dataScope.dataTable:i.parent.dataScope.dataTable),"aggregator"in e||(e.aggregator="sum"),"flipScale"in e||(e.flipScale=!1),"includeZero"in e||(e.includeZero=!1),"scaleType"in e||(e.scaleType="linear");let r=new Dt(t,this,s,n,e);switch(s){case"width":case"height":case"radius":case"outerRadius":case"innerRadius":case"area":case"fontSize":i.type==T.Area?Lt(r):Bt(r);break;case"strokeWidth":i.type==T.Link?function(t){t._query=function(){let t=this.field,e=this.channel,i=this.items.map((t=>t.dataScope));if("strokeWidth"==e)if(this.datatable.hasField(t))this.data=i.map((e=>e.getFieldValue(t)));else if(t.startsWith("parent.")||t.startsWith("child.")){let e=this.datatable.tree.nodeTable,s=t.split(".")[0],n=t.split(".")[1],r=i.map((t=>t.getFieldValue(s)));this.data=r.map((t=>new It(e).cross(o,t).getFieldValue(n)))}},t._map=function(){let t,e=this.channel,i=this.items;if("strokeWidth"==e){let e,s;t=Yc(this.scaleType),t.domain=[0,Math.max(...this.data)],e=1,s=Math.max(...i.map((t=>parseFloat(t.styles.strokeWidth)))),s==e&&(s=e+5),this.rangeExtent&&(s=e+this.rangeExtent),this.range&&(e=this.range[0],s=this.range[1]),t._setRange([e,s]),this.scale||(this.scale=t),this.scale._addEncoding(this)}},t._apply=function(){if("strokeWidth"==this.channel)for(let t=0;t<this.data.length;t++)this.items[t].styles.strokeWidth=this.scale.map(this.data[t])},t.run()}(r):Bt(r);break;case"x":case"y":!function(t){t._query=function(){this.data=[];let t=this.field,e=this.items,i="vertex"!=this.anyItem.type&&"segment"!=this.anyItem.type||this.anyItem.dataScope?e.map((t=>t.dataScope)):e.map((t=>t.parent.dataScope));switch(this.datatable.getFieldType(t)){case A.Boolean:break;case A.Date:this.data=i.map((e=>e.getFieldValue(t)));break;case A.String:try{this.data=i.map((e=>e.getFieldValue(t)))}catch(e){throw new Error("Cannot bind "+this.channel+" to "+t+" : "+e)}break;default:this.data=i.map((e=>e.aggregateNumericalField(t,this.aggregator)))}},t._map=function(){let t,e,i,s,n,r=this.channel,a=this.datatable.getFieldType(this.field),o=it(this.anyItem);if(o&&o.type==y.Grid){let e=o.cellBounds;t="x"==r?e[0].width:e[0].height}else if("vertex"===this.anyItem.type&&this.anyItem.parent.type===T.Area)t="x"==r?this.anyItem.parent.bounds.width:this.anyItem.parent.bounds.height;else{let e=this.items.map((t=>t[r]));t=Math.max(...e)-Math.min(...e),t<100?t=100:t>500&&(t=500)}switch(this.rangeExtent&&(t=this.rangeExtent),a){case A.Boolean:break;case A.Date:if(e=Math.min(...this.data),i=Math.max(...this.data),s=[e,i],this.scale){let t=s.concat(this.scale.domain);s=[Math.min(...t),Math.max(...t)],n=this.scale.range}else this.scale=Yc("time"),this.scale.isFlipped=this._flipScale,n=[0,t];break;case A.String:if(s=Array.from(new Set(this.data)),n=[0,t],this.scale){let t=this.scale.domain;for(let e of s)t.indexOf(e)<0&&t.push(e);s=t,n=this.scale.range}else this.scale=Yc("point"),this.scale.isFlipped=this._flipScale,n=[0,t];break;default:if(e=Math.min(...this.data),i=Math.max(...this.data),s=[e,i],this.scale){let t=s.concat(this.scale._scale.domain());s=[Math.min(...t),Math.max(...t)],n=this.scale.range}else this.scale=Yc(this.scaleType),this.scale.isFlipped=this._flipScale,this.scale.includeZero=this._includeZero,n=[0,t];s[0]==s[1]&&(s[1]=1.1*s[0])}this.scale._scale.domain(s),this.scale._setRange(n),this.scale._addEncoding(this)},t._apply=function(){let t=[],e=this.channel;for(let e of this.scale.encodings)t=t.concat(e.items);if("x"==e){let i=it(this.anyItem,"grid");if(i&&i.type==y.Grid)for(let t=0;t<this.items.length;t++){let i=this.items[t],s=st(i).left+this.scale.map(this.data[t])-i[e],n=0;i._doTranslate(s,n),"vertex"!=i.type&&"segment"!=i.type||i.parent._updateBounds()}else if("vertex"===this.anyItem.type&&this.anyItem.parent.type===T.Area){let t=ot(this.items);void 0===this.scale.offset&&(this.scale.offset=Math.min(...t.map((t=>t.bounds.left))));for(let t=0;t<this.items.length;t++){let i=this.items[t],s=i.parent.bounds.left+this.scale.map(this.data[t])-i[e],n=0;i._doTranslate(s,n),i.parent._updateBounds()}}else if("vertex"==this.anyItem.type||"segment"==this.anyItem.type){let t=ot(this.items);void 0===this.scale.offset&&(this.scale.offset=Math.min(...t.map((t=>t.bounds.left))));for(let t=0;t<this.items.length;t++){let i=this.items[t],s=this.scale.offset+this.scale.map(this.data[t])-i[e],n=0;i._doTranslate(s,n),i.parent._updateBounds()}}else{void 0===this.scale.offset&&(this.scale.offset=Math.min(...t.map((t=>t[e])))),this.items[0].type===T.PointText&&this.items.forEach((t=>t.horzAnchor="center"));for(let t=0;t<this.items.length;t++){let i=this.items[t],s=this.scale.offset+this.scale.map(this.data[t])-i[e],n=0;i._doTranslate(s,n)}}}else{let i=it(this.anyItem,"grid");if(i&&i.type==y.Grid){let t=this.items.map((t=>st(t)));for(let i=0;i<this.items.length;i++){let s=this.items[i],n=0,r=t[i].bottom-this.scale.map(this.data[i])-s[e];s._doTranslate(n,r),"vertex"!=s.type&&"segment"!=s.type||s.parent._updateBounds()}}else if("vertex"===this.anyItem.type&&this.anyItem.parent.type===T.Area){void 0===this.scale.offset&&(this.scale.offset=Math.min(...this.items.map((t=>t.y))));for(let t=0;t<this.items.length;t++){let i=this.items[t],s=0,n=i.parent.bounds.top+this.scale.rangeExtent-this.scale.map(this.data[t])-i[e];i._doTranslate(s,n),i.parent._updateBounds()}}else if("vertex"==this.anyItem.type||"segment"==this.anyItem.type){void 0===this.scale.offset&&(this.scale.offset=Math.min(...this.items.map((t=>t.y))));for(let t=0;t<this.items.length;t++){let i=this.items[t],s=0,n=this.scale.offset+this.scale.rangeExtent-this.scale.map(this.data[t])-i[e];i._doTranslate(s,n),i.parent._updateBounds()}}else{void 0===this.scale.offset&&(this.scale.offset=Math.min(...t.map((t=>t.bounds.y)))),this.items[0].type===T.PointText&&this.items.forEach((t=>t.vertAnchor="middle"));for(let t=0;t<this.items.length;t++){let i=this.items[t],s=0,n=this.scale.offset+this.scale.rangeExtent-this.scale.map(this.data[t])-i.refBounds[e];i._doTranslate(s,n)}}}},t.run()}(r);break;case"fillColor":case"strokeColor":!function(t){t._query=function(){this.data=[];let t=this.field,e=this.items,i="vertex"!=this.anyItem.type&&"segment"!=this.anyItem.type||this.anyItem.dataScope?e.map((t=>t.dataScope)):e.map((t=>t.parent.dataScope));switch(this.datatable.getFieldType(t)){case A.Boolean:this.data=[!0,!1];break;case A.Date:this.data=i.map((e=>e.getFieldValue(t)));break;case A.String:try{this.data=i.map((e=>e.getFieldValue(t)))}catch(e){throw new Error("Cannot bind "+this.channel+" to "+t+" : "+e)}break;default:this.data=i.map((e=>e.aggregateNumericalField(t,this.aggregator)))}},t._map=function(){switch(this.datatable.getFieldType(this.field)){case A.Boolean:if(!this.scale&&(this.scale=Yc("ordinalColor"),this.scale.domain=this.data,this._mapping)){let t=this.scale.domain.map((t=>t in this._mapping?this._mapping[t]:"black"));this.scale._scale.range(t)}break;case A.String:if(this.scale)this.scale.domain=Array.from(new Set(this.scale.domain.concat(this.data)));else if(this.scale=Yc("ordinalColor",this._scheme?this._scheme:"schemeCategory10"),this.scale.domain=this.data,this._mapping){let t=this.scale.domain.map((t=>t in this._mapping?this._mapping[t]:"black"));this.scale._scale.range(t)}break;default:if(this.scale){if(!this._mapping){let t=this.scale.domain.concat(this.data);this.scale.domain=[Math.min(...t),Math.max(...t)]}}else if(this._mapping)this.scale=Yc("linear",this._mapping);else{let t,e=Math.min(...this.data),i=Math.max(...this.data),s=Math.max(Math.abs(e),Math.abs(i));e<0&&i>0?(t="interpolatePuOr",e=-s,i=s,this.scale=Yc("divergingColor",this._scheme?this._scheme:t)):(t="interpolateTurbo",this.scale=Yc("sequentialColor",this._scheme?this._scheme:t)),this.scale.domain=[e,i]}}this.scale._addEncoding(this)},t._apply=function(){for(let t=0;t<this.items.length;t++){let e=this.items[t],i=this.scale.map(this.data[t]);"vertex"==e.type||"segment"==e.type?e[this.channel]=i:e.styles[this.channel]=i,e.vertices&&"strokeColor"==this.channel&&e.vertices.forEach((t=>t.fillColor=i))}},t.run()}(r);break;case"fillGradient":i.type===T.Area&&Lt(r);break;case"angle":!function(t){t._query=function(){this.data=[],this.id2data={};let t=this.field,e=this.items;switch(this.datatable.getFieldType(t)){case A.Boolean:break;case A.Date:this.data=e.map((e=>e.dataScope.getFieldValue(t)));break;case A.String:break;default:this.data=e.map((e=>e.dataScope.aggregateNumericalField(t,this.aggregator)))}for(let t=0;t<this.data.length;t++)this.id2data[e[t].id]=this.data[t]},t._map=function(){this.scale||(this.scale=Yc("linear"),this.scale.domain=this.datatable.tree?[0,Math.max(...this.data)]:[0,this.data.reduce(((t,e)=>t+e),0)],this.scale._setRange([0,360]),this.scale._addEncoding(this))},t._apply=function(){let t;for(let e=0;e<this.items.length;e++)t=this.items[e],t.type!==T.Arc&&t.type!==T.Pie||t.adjustAngle(t.startAngle,At(t.startAngle+this.scale.map(this.data[e])));this.scene._relayoutAncestors(this.anyItem,this.items)},t.run()}(r);break;case"text":!function(t){t._query=function(){this.data=[];let t,e,i=this.items;if(this.field.startsWith("parent.")||this.field.startsWith("child.")){e=this.datatable.tree.nodeTable,t=this.field.split(".")[1];let s=this.field.split(".")[0],n=i.map((t=>t.dataScope)).map((t=>t.getFieldValue(s)));e.getFieldType(t)==A.Integer||e.getFieldType(t)==A.Number?this.data=n.map((i=>new It(e).cross(o,i).aggregateNumericalField(t))):this.data=n.map((i=>new It(e).cross(o,i).getFieldValue(t)))}else e=this.datatable,t=this.field,e.getFieldType(t)==A.Integer||e.getFieldType(t)==A.Number?this.data=i.map((e=>e.dataScope.aggregateNumericalField(t,this.aggregator))):this.data=i.map((e=>e.dataScope.getFieldValue(t)))},t._map=function(){if(this.scale);else switch(this.datatable.getFieldType(this.field)){case A.Boolean:case A.Date:break;case A.String:default:this.scale=Yc("ordinal"),this.scale.domain=[...new Set(this.data)],this.scale._scale.range(this.scale.domain.map((t=>t+"")))}},t._apply=function(){for(let t=0;t<this.items.length;t++){let e=this.items[t],i=this.scale.map(this.data[t]);e.text=i}},t.run()}(r);break;case"radialDistance":!function(t){t._query=function(){this.data=[];let t=this.field,e=this.items,i="vertex"!=this.anyItem.type&&"segment"!=this.anyItem.type||this.anyItem.dataScope?e.map((t=>t.dataScope)):e.map((t=>t.parent.dataScope));switch(this.datatable.getFieldType(t)){case A.Boolean:break;case A.Date:this.data=i.map((e=>e.getFieldValue(t)));break;case A.String:try{this.data=i.map((e=>e.getFieldValue(t)))}catch(e){throw new Error("Cannot bind "+this.channel+" to "+t+" : "+e)}break;default:this.data=i.map((e=>e.aggregateNumericalField(t,this.aggregator)))}},t._map=function(){let t=this.data;this.scale||(this.scale=Yc("linear"),this.scale.domain=[0,Math.max(...t)],this.scale._setRange([0,this.anyItem.parent.radius])),this.scale._addEncoding(this)},t._apply=function(){for(let t=0;t<this.items.length;t++){let e=this.items[t],i=this.scale.map(this.data[t]),s=xt(this.anyItem.parent.x,this.anyItem.parent.y,i,e.polarAngle);e.x=s[0],e.y=s[1]}this.scene._relayoutAncestors(this.anyItem,this.items)},t.run()}(r);break;case"thickness":!function(t){t._query=function(){this.data={};let t=this.field,e=this.items,i=e.map((t=>t.dataScope));switch(this.datatable.getFieldType(t)){case A.Boolean:break;case A.Date:for(let s=0;s<e.length;s++)this.data[e[s].id]=i[s].getFieldValue(t);break;case A.String:try{for(let s=0;s<e.length;s++)this.data[e[s].id]=i[s].getFieldValue(t)}catch(e){throw new Error("Cannot bind "+this.channel+" to "+t+" : "+e)}break;default:for(let s=0;s<e.length;s++)this.data[e[s].id]=i[s].aggregateNumericalField(t,this.aggregator)}},t._map=function(){let t=this.data;if(!this.scale){this.scale=Yc(this.scaleType),this.scale.domain=[0,Math.max(...Object.values(t))];let e=1,i=this.rangeExtent?e+this.rangeExtent:Math.max(...this.items.map((t=>t.outerRadius)));this.scale._setRange([e,i])}this.scale._addEncoding(this)},t._apply=function(){this.items.sort(((t,e)=>(t.innerRadius+t.outerRadius)/2-(e.innerRadius+e.outerRadius)/2));let t=Math.min(...this.items.map((t=>t.innerRadius))),e={item:new re({outerRadius:t,startAngle:0,endAngle:360}),children:[]};for(let t of this.items)me(e,t);for(let t of e.children)ye(t,t.item.innerRadius,this.data,this.scale)},t.run()}(r)}return"_remember"in e&&1!=e._remember||this._registerBinding(r),s.indexOf("Color")<0&&this._updateAncestorBounds(i,r.items),r}_encodeWithinCollection(t,e){this._validateEncodeArgs(t,e);let i=function(t,e){let i={},s=et(t,e);for(let t of s){let e=t.parent.id;e in i||(i[e]=[]),i[e].push(t)}return Object.keys(i).map((t=>i[t]))}(t,this),s=[];for(let t of i){let i=this._doEncode(t,e);s.push(i)}return s}getPeers(t){return et(t,this)}find(t){return X(this,t)}align(t,e){if(!function(t,e,i){if(e==C.Top||e==C.Bottom||e==C.Middle){for(let e of t)if(!_t(e,i))return!1;return!0}if(e==C.Left||e==C.Right||e==C.Center){for(let e of t)if(!gt(e,i))return!1;return!0}}(t,e,this))return!1;let i=new ee(t,e);if(i.id in this.constraints)return console.warn("constraint has been added"),!1;this.constraints[i.id]=i,i.apply(),this._updateAncestorBounds(t[0])}removeAllConstraints(){this.constraints={}}affix(t,e,i,s){let n=s||{},r="offset"in n?n.offset:0,a="itemAnchor"in n?n.itemAnchor:"x"==i||"angle"==i?"center":"middle",o="baseAnchor"in n?n.baseAnchor:"x"==i||"angle"==i?"center":"middle",h=new ie(t,e,this,i,a,o,r);h.id,this.constraints,this.constraints[h.id]=h,h.apply()}axis(t,e,i){let s=i||{},n=s.item?this.getEncodingByItem(s.item,t):this.getEncodingByField(e,t);if(n){if(n.datatable.getFieldType(e)!==A.Date||"labelFormat"in s||(s.labelFormat="%m/%d/%y"),"width"===n.channel){let t=this.children.filter((t=>t.type===T.Axis)).map((t=>t.channel));"orientation"in s||(s.orientation=t.indexOf("x")>=0?"top":"bottom")}else if("height"===n.channel){let t=this.children.filter((t=>t.type===T.Axis)).map((t=>t.channel));"orientation"in s||(s.orientation=t.indexOf("y")>=0?"right":"left")}let t=new Ht(n,s.item?s.item:n.anyItem,s);return"tickValues"in s?(t.tickValues=s.tickValues,t.labelValues=s.tickValues):(t.tickValues=n._inferTickValues(),t.labelValues=n._inferTickValues()),this.addChildAt(t,0),this._itemMap[t.id]=t,this._updateBounds(),t}let r=s.item?s.item:X(this,[{field:e}])[0];void 0===r&&console.warn(j+e);let a=it(r);if(a&&(a.type===y.Grid||a.type===y.Stack)){if(a&&("x"==t||"y"==t)){let i,n,r=et(a.group,this);for(let a of r){let r=X(a,[{field:e}])[0],o=et(r,a);r.dataScope.dataTable.getFieldType(e)!==A.Date||"labelFormat"in s||(s.labelFormat="%m/%d/%y"),i=new $t(o,a.layout,t,e,s),null==n&&(n=i.id),i.classId=n,this.addChildAt(i,0),this._itemMap[i.id]=i}return this._updateBounds(),i}console.warn(j+e)}}getRelatedAxes(t){let e=[];if(dt(t))return e;for(let i of this.children){if(i.type!==T.Axis)continue;if(i.matches(t)){e.push(i);continue}let s=i._item,n=!1;for(;s.children&&s.children.length>0;){for(let r of s.children)if(r.classId===t.classId){n=!0,e.push(i);break}if(n)break;s=s.children[0]}let r=ht(t),a={};for(let t of r)t.classId in a||(a[t.classId]=t);let o=Object.values(a);for(let t of o)if(i.matches(t)){e.push(i);break}}return e}removeItem(t){if(!dt(t)){let e=this.getRelatedEncodings(t);for(let t of e)this.removeEncoding(t);let i=this.getRelatedAxes(t);for(let t of i)this.removeItem(t);for(let e of this.getRelatedGridlines(t))this.removeItem(e)}delete this._itemMap[t.id],this.removeChild(t),this._updateBounds()}getRelatedEncodings(t){let e=[],i=t;for(;i;)if(e.push(at(i)),i.type==T.Collection)i=i.firstChild;else if(i.type==T.Glyph){for(let t of i.children)e.push(at(t));i=void 0}else i=void 0;let s=Object.keys(this.encodings),n=[];for(let t of s){let i=t.split("_")[0];if(e.indexOf(i)>=0)for(let e in this.encodings[t])n.push(this.encodings[t][e])}return n}removeAllEncodings(){this.encodings={},this.removeAllItemsByType(T.Axis),this.removeAllItemsByType(T.Legend),this.removeAllItemsByType(T.Gridlines)}removeEncoding(t){let e=at(t.anyItem);delete this.encodings[e][t.channel],0===Object.keys(this.encodings[e]).length&&delete this.encodings[e];let i=[];for(let e of this.children)dt(e)&&e.encoding&&e.encoding===t&&i.push(e);for(let t of i)this.removeItem(t);this._updateBounds()}removeAllItemsByType(t){let e=[];for(let i of this.children)i.type===t&&e.push(i);for(let t of e)this.removeItem(t);this._updateBounds()}reCreateRelatedAxes(t){let e=this.getRelatedAxes(t),i=[];e.forEach((t=>{let e=t.toJSON().args;e.item&&(e.item=this.getItem(e.item)),delete e.tickValues,delete e.labelValues,this.removeItem(t),t instanceof $t?i.indexOf(t.classId)<0&&(this.axis(t.channel,t.field,e),i.push(t.classId)):this.axis(t.channel,t.field,e)})),this._updateBounds()}reCreateRelatedLegends(t){this.getRelatedLegends(t).forEach((t=>{let e=t.toJSON().args;e.item&&(e.item=this.getItem(e.item)),this.removeItem(t),this.legend(t.channel,t.field,e)})),this._updateBounds()}legend(t,e,i){let s=i||{},n=this.getEncodingByField(e,t);if(!n)throw G.INCORRECT_LEGEND_INFO+e;"x"in s||(s.x=100),"y"in s||(s.y=100);let r=new Zt(n,s);return this.addChild(r),this._itemMap[r.id]=r,this._updateBounds(),r}gridlines(t,e,i){let s=this.getEncodingByField(e,t),n=i||{};if(!s)return!1;let r=new se(s,n.item?n.item:s.anyItem,n);return r.values="values"in n?n.values:s._inferTickValues(),this.addChildAt(r,0),this._itemMap[r.id]=r,this._updateBounds(),r}getRelatedLegends(t){let e=[];if(dt(t))return e;for(let i of this.children)i.type===T.Legend&&i.matches(t)&&e.push(i);return e}getRelatedGridlines(t){let e=[];if(dt(t))return e;for(let i of this.children){if(i.type!==T.Gridlines)continue;if(i.matches(t)){e.push(i);continue}let s=i._item,n=!1;for(;s.children&&s.children.length>0;){for(let r of s.children)if(r.classId===t.classId){n=!0,e.push(i);break}if(n)break;s=s.children[0]}let r=ht(t),a={};for(let t of r)t.classId in a||(a[t.classId]=t);let o=Object.values(a);for(let t of o)if(i.matches(t)){e.push(i);break}}return e}propagate(t,e,...i){let s=et(t,this);for(let t of s)t[e](...i)}classify(t,e,i){let s,n={},r=t[0].parent;for(let i of t){let t=i.dataScope.getFieldValue(e);t in n||(n[t]=[]),n[t].push(i)}let a=[],o=t[0].dataScope._dt;for(let t in n){let r=this.collection();i.addChild(r),void 0===s&&(s=r.id),r.classId=s,r.dataScope=new It(o).cross(e,t);for(let e of n[t])r.addChild(e);a.push(r)}return 0===r.children.length&&r.parent.removeChild(r),a}getEncodingByItem(t,e){let i=this.encodings[at(t)];return i&&i[e]?i[e]:null}getEncodingByField(t,e){for(let i in this.encodings){let s=this.encodings[i];if(s[e]&&s[e].field==t)return s[e]}return null}positionBound(t,e){let i=this.getEncodingByItem(t,e);if(i)return i;if(!ft(t))return null;for(let i in this.encodings){if(i.split("_")[0]===t.classId&&e in this.encodings[i])return this.encodings[i][e]}}sizeBound(t,e){let i=this.getEncodingByItem(t,e);if(i)return i;if(ft(t)){let i="width"===e||"height"===e||"radius"===e?["area"]:["width","height"],s="width"===e?["x"]:"height"===e?["y"]:["x","y"];for(let e in this.encodings){let n=e.split("_")[0];if(e.indexOf("_")<0){for(let s of i)if(n===t.classId&&s in this.encodings[e])return this.encodings[e][s]}else for(let i of s)if(n===t.classId&&i in this.encodings[e])return this.encodings[e][i]}}return null}setProperties(t,e){let i,s={};for(let t in e)s[t]=!0;if(Object.values(y).indexOf(t.type)>-1&&t.group){i=et(t.group,this);for(let t of i)for(let i in e)t.layout[i]=e[i]}else if(i=et(t,this),"vertex"===t.type)for(let t of i)for(let i in e)t[i]=e[i];else if(t instanceof q)for(let n in e)if("x"!==n&&"y"!==n||!this.positionBound(t,n))if("width"!==n&&"height"!==n&&"radius"!==n||!this.sizeBound(t,n))t.type!==T.Rect&&t.type!==T.Line||"width"!==n&&"height"!==n?t.type==T.Circle&&"radius"==n?i.forEach((t=>t.resize(2*e[n],2*e[n],e.xRef,e.yRef))):i.forEach((t=>t[n]=e[n])):"width"===n?i.forEach((t=>t.resize(e[n],t.bounds.height,e.xRef))):i.forEach((t=>t.resize(t.bounds.width,e[n],void 0,e.yRef)));else{let i=this.getEncodingByItem(t,n);i||"radius"!=n||(i=this.getEncodingByItem(t,"area"));let s=i.scale.rangeExtent*e[n]/t[n];i.scale.rangeExtent=s}else s[n]=!1;else if("collection"==t.type||"group"==t.type)for(let t of i)for(let i in e)t[i]="layout"===i&&void 0!==e[i]?e[i].clone():e[i];let n=Object.keys(s).filter((t=>s[t])),r=["width","height","fontSize","area","radius"];for(let e of r)if(n.indexOf(e)>=0&&ut(t)){ue(t,i);break}n.indexOf("baseline")>=0&&t.type===T.Area&&ge(t,i);let a=["layout","rowGap","colGap","numRows","numCols","vertCellAlignment","horzCellAlignment"];for(let t of a)if(n.indexOf(t)>=0){let t=n.indexOf("numRows")>=0||n.indexOf("numCols")>=0||n.indexOf("layout")>=0;le(i[0],i,t);break}return s}_canTranslate(t){let e={x:!0,y:!0};return t.type==T.Axis?("x"===t.channel||"width"===t.channel?e.x=!1:"y"!==t.channel&&"height"!==t.channel||(e.y=!1),e):(t.parent.type===T.Collection&&t.parent.layout&&(e.x=!1,e.y=!1),this.positionBound(t,"x")&&(e.x=!1),this.positionBound(t,"y")&&(e.y=!1),e)}translate(t,e,i){let s=this._canTranslate(t);if(!s.x&&!s.y)return s;const n=s.x?e:0,r=s.y?i:0;return t._doTranslate(n,r),this._updateAncestorBounds(t),he(t,n,r),s}_updateAncestorBounds(t,e){let i=ot(e||et(t,this));for(;i.length>0;){for(let t of i)(t.children&&t.children.length>0||t.vertices)&&t._updateBounds();i=ot(i)}}_reapplyConstraints(t){let e=t,i=[t];for(;e.children;)e.type==T.Collection?i.push(e.firstChild):i=i.concat(e.children),e=e.firstChild;for(e=t.parent;e&&e.type!==T.Scene;)i.push(e),e=e.parent;const s=i.map((t=>t.classId));for(let t in this.constraints){const e=this.constraints[t];switch(e.type){case E:(s.indexOf(e.item.classId)>=0||s.indexOf(e.baseItem.classId)>=0)&&e.apply();break;case S:for(let t of e.items)if(s.indexOf(t.classId)>=0){e.apply();break}}}}_relayoutAncestors(t,e){let i=ot(e||et(t,this));for(;i.length>0;){for(let t of i)t.layout&&t.layout.run(),t.children&&t.children.length>0&&t._updateBounds(),t.vertices&&t._updateBounds();i=ot(i)}}_reapplySizeBindings(t){let e=["width","height"];for(let i in this.encodings){if(t.classId!=i)continue;let s=this.encodings[i],n=X(this,[{classId:i}]);for(let t of e){let e=s[t];e&&e.run()}this._relayoutAncestors(n[0],n)}}_registerBinding(t){let e=this.encodings,i=at(t.anyItem);return i in e||(e[i]={}),e[i][t.channel]=t,!0}toJSON(){let t=super.toJSON();this.fillColor&&(t.fillColor=this.fillColor);let e={};t.encodings=[],t.itemCounter=pt;for(let i in this.encodings)for(let s in this.encodings[i]){let n=this.encodings[i][s];t.encodings.push(n.toJSON()),n.scale&&!(n.scale.id in e)&&(e[n.scale.id]=n.scale.toJSON())}t.scales=e,t.constraints={};for(let e in this.constraints)t.constraints[e]=this.constraints[e].toJSON();t.tables={};let i=this.getDataTables();for(let e in i)t.tables[e]=i[e].toJSON();return t}getDataTables(){let t={};for(let e in this.encodings)for(let i in this.encodings[e]){let s=this.encodings[e][i];s.datatable.id in t||(t[s.datatable.id]=s.datatable)}for(let e of this.children)if(!dt(e)){if(e.dataScope){t[e.dataScope.dataTable.id]=e.dataScope.dataTable;break}if(e.children&&e.children.length>0){let i=e.firstChild;for(;i;){if(i.dataScope){t[i.dataScope.dataTable.id]=i.dataScope.dataTable;break}i=i.children&&i.children.length>0?i.firstChild:void 0}}}return t}getItem(t){let e=t.split("_")[0];if(t.indexOf("_v_")>0){let i=parseInt(t.split("_v_")[1]);return this._itemMap[e].vertices.find((t=>t._id===i))}if(t.indexOf("_s_")>0){let i=parseInt(t.split("_s_")[1]);return this._itemMap[e].segments.find((t=>t._id===i))}return this._itemMap[t]}addInteraction(t,e,i,s){let n=new ke(t,e,i,s);this._interactions.push(n)}}class Se{constructor(t){this._renderer=t,this._globalPredicates={}}processInteraction(t,e){let i=t.listener;if(ut(i)){let s=i.classId?"."+i.classId:"#"+i.id;switch(t.eventType){case"hover":n.selectAll(s).on("mouseover",t.getCallbackFunction(e,this)),n.selectAll(s).on("mouseleave",t.getRestoreFunction(e,this));break;case"click":n.selectAll(s).on("mousedown",t.getCallbackFunction(e,this))}}else if(i.type==T.Scene){if(!t.targetDef||!t.targetDef.item)return;t.selectionDef.item||n.select("#"+this._renderer._svgId).on("mousedown",t.getRestoreFunction(e,this,!0))}}_getSelection(t,e,i,s){let n={};s?n.item=s:e.item;let r=e.field?e.field:h;return n.item&&(n.predicate={field:r,value:n.item.dataScope.getFieldValue(r)}),n}addGlobalPredicate(t,e){t.id in this._globalPredicates||(this._globalPredicates[t.id]={}),this._globalPredicates[t.id][e.field]=e}getGlobalPredicates(t){return t.id in this._globalPredicates?Object.values(this._globalPredicates[t.id]):[]}}class Ee{constructor(t){this._svgId=t,this._compMap={},this._decoMap={},this._interactionHandler=new Se(this)}render(t,e){let i=e||{};for(let t in this._decoMap)this._decoMap[t].remove(),delete this._decoMap[t];this._removed={};for(let t in this._compMap)this._removed[t]=1;this._renderItem(t,i);for(let t in this._removed)this._compMap[t].remove(),delete this._compMap[t];if(!("visualOnly"in i))for(let e of t._interactions)this._interactionHandler.processInteraction(e,t)}clear(){let t=document.getElementById(this._svgId);for(;t.firstChild;)t.firstChild.remove();this._compMap={},this._decoMap={}}_renderItem(t,e){let i,s=t.id,r=t.parent;i=r&&r.id&&r.id in this._compMap?n.select("#"+this._svgId).select("#"+r.id):n.select("#"+this._svgId),s in this._compMap?delete this._removed[s]:this._compMap[s]=i.append(this._getSVGElementType(t)),t.type==T.Gridlines&&this._compMap[s].lower();let a=this._compMap[s];if(a.attr("id",s),t.classId&&a.attr("class",t.classId),t.type==T.Scene&&n.select("#"+this._svgId).style("background",t.fillColor?t.fillColor:"#fff"),"vertex"!=t.type){if(t.type==T.Path||t.type==T.Polygon||t.type==T.Link)a.attr("d",t.getSVGPathData()),t.closed||a.style("fill","none"),0==s.indexOf("axis")&&a.style("shape-rendering","crispEdges");else if(t.type==T.Line)a.attr("x1",t.vertices[0].x),a.attr("y1",t.vertices[0].y),a.attr("x2",t.vertices[1].x),a.attr("y2",t.vertices[1].y),0==s.indexOf("axis")&&a.style("shape-rendering","crispEdges");else if(t.type==T.Circle)a.attr("cx",t.x),a.attr("cy",t.y),a.attr("r",t.radius);else if(t.type==T.Rect){let e=t.bounds;a.attr("x",e.left).attr("y",e.top).attr("width",e.width).attr("height",e.height)}else t.type==T.PointText?a.attr("text-anchor",this._getTextAnchor(t.anchor[0])).attr("alignment-baseline",this._getTextAnchor(t.anchor[1])).attr("dominant-baseline",this._getTextAnchor(t.anchor[1])).text(t.text).attr("x",t.x).attr("y",t.y):t.type==T.Pie||t.type==T.Area?(a.attr("d",t.getSVGPathData()),t.closed||a.style("fill","none"),0==s.indexOf("axis")&&a.style("shape-rendering","crispEdges")):t.type==T.Ring||t.type==T.Arc?a.attr("d",t.getSVGPathData()):t.type==T.Image&&a.attr("href",t.src).attr("x",t.x).attr("y",t.y).attr("width",t.width).attr("height",t.height);for(let e in t.styles)if(void 0!==t.styles[e])if(e.indexOf("Color")>0&&t.styles[e].type==T.LinearGradient){n.select("#"+this._svgId).select("defs").empty()&&n.select("#"+this._svgId).append("defs");let i=n.select("defs"),s=t.styles[e];if(i.select("#"+s.id).empty()){let t=i.append("linearGradient").attr("id",s.id);t.attr("x1",s.x1+"%").attr("x2",s.x2+"%").attr("y1",s.y1+"%").attr("y2",s.y2+"%");for(let e of s.stops)t.append("stop").attr("offset",e.offset+"%").style("stop-color",e.color).style("stop-opacity",e.opacity)}a.style(D[e],"url(#"+s.id+")")}else a.style(D[e],t.styles[e]);if(t._rotate&&a.attr("transform","rotate("+t._rotate.join(" ")+")"),t.vertices&&this._renderVertices(t),t.type==T.Collection&&e&&e.collectionBounds){let e=t.bounds;t.layout&&"grid"==t.layout.type?this._renderLayout(t):(t.id in this._decoMap||(this._decoMap[t.id]=n.select("#"+this._svgId).append("rect").attr("class","deco")),this._decoMap[t.id].attr("x",e.left).attr("y",e.top).attr("width",e.width).attr("height",e.height).attr("fill","none").attr("stroke","#1ecb40").attr("stroke-width","2px").attr("stroke-dasharray","5,5"))}if(t.children)for(let i of t.children)this._renderItem(i,e)}}_renderVertices(t){let e=t.id+"-vertices";if(e in this._compMap)delete this._removed[e];else{let i=t.parent,s=i?i.id:this._svgId;this._compMap[e]=n.select("#"+s).append("g").attr("id",e)}if(0===t.vertices.map((t=>t.shape)).filter((t=>void 0!==t)).length)return void this._compMap[e].style("visible","hidden");this._compMap[e].style("visible","visible");let i=t.vertices.filter((t=>void 0!==t.shape));for(let t of i){let i=e+"-"+t.id;i in this._compMap?t.shape!==this._compMap[i].node().tagName?(this._compMap[i].remove(),this._compMap[i]=n.select("#"+e).append(t.shape).attr("id",i),delete this._removed[i]):delete this._removed[i]:this._compMap[i]=n.select("#"+e).append(t.shape).attr("id",i),"rect"==t.shape?n.select("#"+i).attr("x",t.x-t.width/2).attr("y",t.y-t.height/2).attr("width",t.width).attr("height",t.height):"circle"==t.shape&&n.select("#"+i).attr("cx",t.x).attr("cy",t.y).attr("r",t.radius),n.select("#"+i).style("fill",t.fillColor).style("opacity",t.opacity).style("stroke-width",t.strokeWidth).style("stroke",t.strokeColor)}}_renderLayout(t){let e=t.id+"-grid";e in this._decoMap||(this._decoMap[e]=n.select("#"+this._svgId).append("g").attr("id",e).attr("class","deco"));let i=t.layout.cellBounds,s=t.layout.rowGap;this._decoMap[e].selectAll("rect").remove(),this._decoMap[e].selectAll("rect").data(i.slice(0,i.length-1)).enter().append("rect").attr("x",(t=>t.left)).attr("y",(t=>t.bottom)).attr("width",(t=>t.width)).attr("height",s).style("fill","pink").style("opacity",.5);let r=Math.min(...i.map((t=>t.left))),a=Math.min(...i.map((t=>t.top)));this._decoMap[e].append("rect").attr("x",r).attr("y",a).attr("width",t.bounds.width).attr("height",t.bounds.height).attr("stroke","blue").attr("stroke-width","1px").attr("stroke-dasharray","5,5").attr("fill","none")}_getTextAnchor(t){switch(t){case"top":return"text-before-edge";case"bottom":return"text-after-edge";case"left":return"start";case"right":return"end";case"center":case"middle":return"middle";default:return t}}_getSVGElementType(t){switch(t.type){case T.Rect:return"rect";case T.Collection:case T.Group:case T.Glyph:case T.Scene:case T.Axis:case T.Legend:case T.Gridlines:return"g";case T.Area:case T.Path:case T.Polygon:case T.Ring:case T.Pie:case T.Arc:case T.Link:return"path";case T.Circle:return"circle";case T.Line:return"line";case T.PointText:return"text";case"vertex":if("circle"==t.shape)return"circle";if("rect"==t.shape)return"rect";throw"argument exception";case"image":return"image"}}}class Te{constructor(t,e){switch(this._type=t,this._offset=void 0,this.id="scale"+pt.scale++,this._flipped=!1,this._includeZero=!1,t){case"linear":if(e){let t=Object.keys(e).map((t=>parseFloat(t))).sort(((t,e)=>t-e)),i=t.map((t=>e[t]));this._scale=n.scaleLinear(t,i),"clamp"in e&&this._scale.clamp(e.clamp),this._mapping=e}else this._scale=n.scaleLinear();break;case"point":this._scale=n.scalePoint();break;case"ordinal":this._scale=n.scaleOrdinal();break;case"ordinalColor":this._scale=n.scaleOrdinal(e&&"string"==typeof e?n[e]:n.schemeCategory10);break;case"power":this._scale=n.scalePow().exponent(2);break;case"sqrt":this._scale=n.scalePow().exponent(.5);break;case"log":this._scale=n.scaleLog();break;case"identity":case"time":this._scale=n.scaleTime();break;case"sequentialColor":case"divergingColor":e&&"string"==typeof e?(this._scale=n.scaleSequential(n[e]),this._scheme=e):this._scale=n.scaleSequential()}this.encodings=[]}set scheme(t){if(this._type.indexOf("Color")<0&&"linear"!==this._type)return;let e=n.scaleSequential(n[t]),i=this._scale.domain();if(Math.min(...i)*Math.max(...i)<0){let t=Math.max(Math.abs(Math.min(...i)),Math.abs(Math.max(...i)));i=[-t,t]}e.domain(i),this._scheme=t,this._scale=e,"linear"===this._type&&(this._type=this._scale.domain()[0]*this._scale.domain()[1]<0?"divergingColor":"sequentialColor",this._mapping&&(this._mapping=void 0));for(let e of this.encodings)e._mapping&&(e._mapping=void 0),e._scheme=t,e._apply()}get scheme(){return this._scheme}get type(){return this._type}set type(t){let e;switch(t){case"linear":e=n.scaleLinear();break;case"power":e=n.scalePow().exponent(2);break;case"sqrt":e=n.scalePow().exponent(.5);break;case"log":e=n.scaleLog()}if(e){this._type=t,e.domain(this._scale.domain()).range(this._scale.range()),this._scale=e;for(let t of this.encodings)t._apply();for(let t of this.encodings)t.scene._updateAncestorBounds(t.item,t.items)}else console.warn(V+t)}toJSON(){let t={};return t.type=this.type,t.id=this.id,t.offset=this._offset,this._scheme&&(t.scheme=this._scheme),t.domain=this._scale.domain(),t.range=this.range,t.clamp=this.clamp,t.isFlipped=this.isFlipped,t.includeZero=this.includeZero,this._mapping&&(t.mapping=this._mapping),t}_merge(t){if(this.type!=t.type)throw G.DIFFERENT_SCALE_TYPE;let e,i;switch(this.type){case"linear":case"time":e=[Math.min(this.domain[0],t.domain[0]),Math.max(this.domain[1],t.domain[1])],i=[0,this.map(e[1])-this.map(e[0])];break;case"point":case"ordinalColor":e=[...new Set(this.domain.concat(t.domain))],i=[];break;default:console.log("TODO: merge scale type",this.type)}this._scale.domain(e),this._scale.range(i)}get domain(){if(this._includeZero){return[0,this._scale.domain()[1]]}return this._scale.domain()}set domain(t){this._scale.domain(t);for(let t of this.encodings)t._apply()}get range(){return this._scale.range()}
|
|
3
3
|
//to support this, the argument should be in real screen coordinates and need to do internal conversion
|
|
4
4
|
set range(t){this._scale.range(t);for(let t of this.encodings)t._apply();for(let t of this.encodings)t.scene._updateAncestorBounds(t.item,t.items)}_setRange(t){this._scale.range(t),de(this)}get clamp(){return"linear"==this.type&&this._scale.clamp()}set clamp(t){"linear"==this.type&&this._scale.clamp(t)}set rangeExtent(t){let e=this._scale.range();this._setRange([e[0],e[0]+t])}get rangeExtent(){let t=this._scale.range();return Math.abs(t[1]-t[0])}_addEncoding(t){this.encodings.indexOf(t)<0&&this.encodings.push(t)}map(t){let e=this._scale.copy();return e.domain(this.domain),this._flipped?(e.range(this._scale.range().reverse()),e(t)):e(t)}invert(t){return this._scale.invert(t)}get offset(){return this._offset}set offset(t){this._offset=t;for(let t of this.encodings)t._apply()}get isFlipped(){return this._flipped}set isFlipped(t){this._flipped=t}get includeZero(){return this._includeZero}set includeZero(t){this._includeZero=t,ce(this)}get mapping(){return this._mapping}getEncodedChannels(){let t={};for(let e of this.encodings)t[e.channel]=!0;return Object.keys(t)}}class Ae extends z{constructor(t){super(t),this.type="packing",this.x="x"in t?t.x:400,this.y="y"in t?t.y:400,this.width=t.width,this.height=t.height}toJSON(){let t={args:{}};return t.type=this.type,t.args.x=this.x,t.args.y=this.y,t.args.width=this.width,t.args.height=this.height,t}clone(){return new Ae({x:this.x,y:this.y,width:this.width,height:this.height})}run(){if(null==this.group)return;let t=this.group.children.map((t=>({name:t.id,radius:t.radius,itm:t}))),e=t.reduce(((t,e)=>t+Math.pow(e.radius,2)),0),i=Math.sqrt(e);void 0===this.width&&(this.width=i),void 0===this.height&&(this.height=i);let s=n.hierarchy({name:"root",children:t}).sum((t=>t.radius?t.radius:0)).sort(((t,e)=>e.value-t.value));n.pack().size([this.width,this.height]).radius((t=>t.value))(s);for(let t of s.children){let e=t.data.itm,i=this.x-s.x+t.x-e.x,n=this.y-s.y+t.y-e.y;e._doTranslate(i,n)}this.group._updateBounds()}}class Ie extends z{constructor(t){super(t),this.type="treemap",this._width=t.width,this._height=t.height,this._top=t.top,this._left=t.left}toJSON(){let t={args:{}};return t.type=this.type,t.args.left=this._left,t.args.top=this._top,t.args.width=this._width,t.args.height=this._height,t}clone(){return new Ie({})}run(){if(null==this.group||!this.group.children||0==this.group.children.length)return;let t=this._width?this._width:this.group.bounds.width,e=this._height?this._height:this.group.bounds.height,i=void 0===this._top?this.group.bounds.top:this._top,s=void 0===this._left?this.group.bounds.left:this._left,r=n.hierarchy(this.group).sum((t=>"rect"==t.type?t.bounds.width*t.bounds.height:0));n.treemap().size([t,e])(r),this._apply(r,s,i),this.group.getScene()._updateAncestorBounds(r.leaves()[0].data)}_apply(t,e,i){if("collection"==t.data.type&&t.children)for(let s of t.children)this._apply(s,e,i);else"rect"==t.data.type&&(t.data.resize(t.x1-t.x0,t.y1-t.y0),t.data._doTranslate(t.x0+e-t.data.bounds.left,t.y0+i-t.data.bounds.top))}get width(){return this._width}set width(t){this._width=t,this.run()}get height(){return this._width}set height(t){this._height=t,this.run()}get top(){return this._top}set top(t){this._top=t,this.run()}get left(){return this._left}set left(t){this._left=t,this.run()}}function Oe(t,e){let i=[t[0]],s=[e[0]];for(let n=1;n<e.length;n++){let r=!1,a=e[n];for(let e=0;e<s.length;e++){let o=s[e],h=new Set(a);if(o.forEach((t=>h.add(t))),h.size<a.length+o.length){s[e]=[...h],i[e]=i[e].concat(t[n]),r=!0;break}}r||(s.push(a),i.push(t[n]))}return{grouping:i,subgraphs:s}}class Me{constructor(t,e){this._type="network",this._nodeTable=new zt(t.nodes,"nodes"),this._linkTable=new zt(t.links,"links"),this._nodeTable.graph=this,this._linkTable.graph=this,this._nodes=t.nodes,this._links=t.links,this._name=e,this._nodeHash={};for(let e of t.nodes)this._nodeHash[e.id]=e}get type(){return this._type}get nodeTable(){return this._nodeTable}get linkTable(){return this._linkTable}get nodes(){return this._nodes}get links(){return this._links}getNode(t){return this._nodeHash[t]}getSources(t){let e,i=t.id,s=this._links.data,n=this._nodes.data,r=[];for(let t in s)if(s[t].target==i){e=s[t].source;let i=n.findIndex((t=>t.id===e));r.push(n[i])}return r}getTargets(t){let e,i=t.id,s=this._links.data,n=this._nodes.data,r=[];for(let t in s)if(s[t].source==i){e=s[t].target;let i=n.findIndex((t=>t.id===e));r.push(n[i])}return r}transform(t,e,i){switch(t){case"partition":return function(t){let e=t.nodes,i=t.links,s=i.map(((t,e)=>[e])),n=i.map((t=>[t.source,t.target])),r=Oe(s,n);for(;r.grouping.length!=s.length;)s=r.grouping,n=r.subgraphs,r=Oe(s,n);let a=[];for(let[t,s]of r.grouping.entries()){let n={nodes:[],links:[]};n.links=s.map((t=>i[t]));const o=r.subgraphs[t];n.nodes=e.filter((t=>o.indexOf(t.id)>=0)),a.push(new Me(n))}return a}(this)}}isLinear(){let t={},e={};for(let i of this._links)i.source in e||(e[i.source]=0),i.target in t||(t[i.target]=0),e[i.source]++,t[i.target]++;for(let e in t)if(t[e]>1)return!1;for(let t in e)if(e[t]>1)return!1;return!0}}class Re extends z{constructor(t){super(t),this.type=y.TidyTree,this._width="width"in t?t.width:500,this._height="height"in t?t.height:500,this._left="left"in t?t.left:100,this._top="top"in t?t.top:100,this._orientation="orientation"in t?t.orientation:b}toJSON(){let t={args:{}};return t.args.type=this.type,t.args.orientation=this._orientation,t.args.left=this._left,t.args.top=this._top,t.args.width=this._width,t.args.height=this._height,t}run(){if(null==this.group)return;let t=this.group.children[0].dataScope._dt;if(!t.tree)throw G.LAYOUT_WITHOUT_TREE;{let e=n.hierarchy(t.tree._data),i=Math.max(...this.group.children.map((t=>t.bounds.width))),s=Math.max(...this.group.children.map((t=>t.bounds.height))),r=this._orientation==b?[this._height,this._width]:[this._width,this._height],a=n.tree().nodeSize([i,s]).size(r)(e);this._apply(a,this.group)}}_apply(t,e){let i,s,n=e.children.filter((e=>e.dataScope.getFieldValue(o)==t.data.id))[0];switch(this._orientation){case b:i=t.y+this._left,s=t.x+this._top;break;case v:i=t.x+this._left,s=this._top+t.y}if(n.x=i,n.y=s,t.children&&t.children.length>0)for(let i of t.children)this._apply(i,e)}get orientation(){return this._orientation}set orientation(t){this._orientation=t,this.run()}get width(){return this._width}set width(t){this._width=t,this.run()}get height(){return this._width}set height(t){this._height=t,this.run()}get size(){return[this._width,this._height]}set size(t){this._width=t[0],this._height=t[1],this.run()}}class Ne extends z{constructor(t){super(t),this.type=y.Force,this._x="x"in t?t.x:0,this._y="y"in t?t.y:0,this._iterations="iterations"in t?t.iterations:1,this._repulsion="repulsion"in t?t.repulsion:30,this._attraction="attraction"in t?t.attraction:1,this._linkDistance="linkDistance"in t?t.linkDistance:30}toJSON(){let t={args:{}};return t.type=this.type,t.args.x=this._x,t.args.y=this._y,t.args.iterations=this._iterations,t}run(){if(null==this.group)return;let t=this.group.children[0].dataScope._dt.graph;if(t){let e=t.links.map((e=>({source:t.getNode(e.source),target:t.getNode(e.target)}))),i=n.forceSimulation(t.nodes).force("charge",n.forceManyBody().strength(-this._repulsion)).force("link",n.forceLink(e).id((t=>t.id)).distance(this._linkDistance)).force("x",n.forceX()).force("y",n.forceY()).force("center",n.forceCenter(this._x,this._y).strength(this._attraction));i.stop(),i.tick(this._iterations);for(let e=0;e<this.group.children.length;e++)this.group.children[e].x=t.nodes[e].x,this.group.children[e].y=t.nodes[e].y}}}class Fe{constructor(){this.axes={},this.guideCmds=[],this.collectionCmds=[],this.glyphCmds=[],this.spec=[]}run(t){for(let e of t.children)switch(e.type){case T.Axis:{let t=e.classId?e.classId:e.id;this.axes[t]=e;break}case T.Gridlines:case T.Legend:{let t=e.toJSON();this.guideCmds.push({cmd:e.type,channel:t.channel,field:t.field,args:t.args});break}case T.Collection:case T.Group:case T.Glyph:{let i=[];this._analyze(e,i);for(let t=i.length-1;t>0;t--)for(let e of i[t].fields)i[t-1].fields.delete(e);for(let[e,s]of i.entries()){if(s.item instanceof q){let e={cmd:"mark",type:s.item.type,output:s.item,args:s.item.toJSON().args};this._inferMarkArgs(e,t),this.collectionCmds.push(e)}else if(s.item instanceof Kt)this.collectionCmds.push({cmd:"glyph",output:s.item,input:i.slice(0,e).map((t=>t.item)),args:{}});else if(s.item instanceof ne){let t=[...i[e-1].fields][0],n={cmd:"join",input:i[e-1].item,output:s.item,data:i[e-1].item.dataScope.dataTable.id,args:{field:t}};t==h&&delete n.field,this.collectionCmds.push(n)}s.item.dataScope&&0==s.item.dataScope.fields.length&&!s.item.parent.dataScope&&this.collectionCmds.push({cmd:"attach",input:s.item,data:s.item.dataScope.dataTable.id})}break}default:if(e instanceof q){let i={cmd:"mark",type:e.type,output:e,args:e.toJSON().args};this._inferMarkArgs(i,t),this.glyphCmds.push(i)}}this._inferJoin(),this._inferArgs(t);for(let t in this.axes){let e=this.axes[t].toJSON();this.guideCmds.push({cmd:e.type,channel:e.channel,field:e.field,args:e.args})}return this._generateFullSpec(t),this.spec}_inferJoin(){for(let t of this.collectionCmds){if("join"!=t.cmd)continue;let e=t.input,i=e.parent;switch(e.type){case T.Rect:i.layout&&i.layout.type==y.Stack?t.cmd="divide":t.cmd="repeat";break;default:t.cmd="repeat"}}}_inferArgs(t){for(let e of this.collectionCmds)switch(e.cmd){case"mark":this._inferMarkArgs(e,t);break;case"divide":this._inferDivideArgs(e,t)}}_inferDivideArgs(t){t.args.orientation=t.output.layout.orientation}_inferMarkArgs(t,e){let i=t.output,s=i.parent,n=et(i,e),r=et(s,e);switch(i.type){case T.Rect:s.layout&&s.layout.type==y.Grid?(t.args.width=s.layout.cellBounds[0].width,t.args.height=s.layout.cellBounds[0].height):s.layout&&s.layout.type==y.Stack?(t.args.width=Math.max(...r.map((t=>t.bounds.width))),t.args.height=Math.max(...r.map((t=>t.bounds.height)))):(t.args.width=Math.max(...n.map((t=>t.bounds.width))),t.args.height=Math.max(...n.map((t=>t.bounds.height)))),t.args.left=Math.min(...n.map((t=>t.bounds.left))),t.args.top=Math.min(...n.map((t=>t.bounds.top)));break;case T.Line:t.args.x1=Math.min(...n.map((t=>t.vertices[0].x))),t.args.y1=Math.min(...n.map((t=>t.vertices[0].y))),t.args.x2=Math.min(...n.map((t=>t.vertices[1].x))),t.args.y2=Math.min(...n.map((t=>t.vertices[1].y)));break;case T.Arc:t.args.x=i.x,t.args.y=i.y,t.args.innerRadius=i.innerRadius,t.args.outerRadius=i.outerRadius}for(let e in i.styles)t.args[e]=i.styles[e]}_analyze(t,e){if(t instanceof Kt)for(let i of t.children)this._analyze(i,e);else t instanceof St&&this._analyze(t.firstChild,e);let i={type:t.type,item:t};t.dataScope?i.fields=new Set(t.dataScope.fields):i.fields=new Set,e.push(i)}_generateFullSpec(t){this.spec=[],this.spec.push({cmd:"scene",args:{fillColor:t.fillColor}});let e=t.getDataTables(),i={},s=[];for(let t in e){let n=e[t];if(n.sourceDataTable)for(;n.sourceDataTable;)s.push({cmd:"transform",type:n.transform.type,args:n.transform.args,input:n.sourceDataTable.id,output:n.id}),n=n.sourceDataTable;n.id in i||(i[n.id]={cmd:"data",url:n.url,output:n.id})}this.spec=this.spec.concat(Object.values(i)),this.spec=this.spec.concat(s);let n=[];for(let t of this.collectionCmds){let e;t.output&&t.output.layout&&(e={cmd:"layout",type:t.output.layout.type,input:t.output.id,args:t.output.layout.toJSON().args}),this.spec.push(t),t.output&&t.output.childrenOrder&&n.push({cmd:"sortChildren",args:t.output.childrenOrder,input:t.output.id}),e&&this.spec.push(e),t.input&&Array.isArray(t.input)?t.input=t.input.map((t=>t.classId?t.classId:t.id)):t.input&&(t.input=t.input.classId?t.input.classId:t.input.id),t.output&&(t.output=t.output.classId?t.output.classId:t.output.id)}let r={},a=[];for(let e in t.encodings)for(let i in t.encodings[e]){let s=t.encodings[e][i];s.scale&&!(s.scale.id in r)&&(r[s.scale.id]=s.scale.toJSON());let n=s.toJSON().args;n.field=s.field,n.channel=s.channel,delete n.datatable,a.push({cmd:"encode",input:at(s.anyItem),scale:s.scale.id,args:n})}for(let t in r){let e=r[t];e.cmd="scale",this.spec.push(e)}this.spec=this.spec.concat(a),this.spec=this.spec.concat(n);for(let e in t.constraints){let i=t.constraints[e],s={cmd:"constraint",type:i.type,args:{}};switch(i.type){case E:s.item=i.item.classId?i.item.classId:i.item.id,s.baseItem=i.baseItem.classId?i.baseItem.classId:i.baseItem.id,s.channel=i.channel,s.args.itemAnchor=i.itemAnchor,s.args.baseAnchor=i.baseAnchor,s.args.offset=i.offset;break;case S:s.items=i.items.map((t=>t.classId?t.classId:t.id)),s.anchor=i.anchor}this.spec.push(s)}for(let t of this.guideCmds)this.spec.push(t);for(let t of this.glyphCmds)t.output&&(t.output=t.output.classId?t.output.classId:t.output.id),this.spec.push(t)}}class Pe{constructor(){this.axes={},this.legends=[],this.gridlines=[],this.scales={},this.tables={}}load(t){let e={};if(t.fillColor&&(e.fillColor=t.fillColor),t.itemCounter)for(let e in t.itemCounter)pt[e]=t.itemCounter[e];let i=Jc(e);if(i.id=t.id,i.type=t.type,t.bounds&&(i._bounds=new a(t.bounds.left,t.bounds.top,t.bounds.width,t.bounds.height)),t.tables)for(let e in t.tables)this.tables[e]=new zt(t.tables[e].data,t.tables[e].url,t.tables[e].fieldTypes),this.tables[e].id=t.tables[e].id;for(let e of t.children)this._processItem(i,e,i);if(t.scales)for(let e in t.scales)this._loadScale(t.scales[e],i);if(t.encodings)for(let e of t.encodings)this._loadEncoding(e,i);if(t.constraints)for(let e in t.constraints)this._loadConstraint(t.constraints[e],i);for(let t in this.axes)this._createGuide(i,this.axes[t]);for(let t of this.legends)this._createGuide(i,t);for(let t of this.gridlines)this._createGuide(i,t);return i}_loadScale(t){let e;t.type.indexOf("Color")>0&&t.scheme?e=Yc(t.type,t.scheme):(e=Yc(t.type),e.range=t.range),e.domain="time"==t.type?t.domain.map((t=>new Date(t))):t.domain,e.id=t.id,"offset"in t&&(e.offset=t.offset),e.isFlipped=t.isFlipped,e.clamp=t.clamp,e._mapping=t.mapping,"includeZero"in t&&(e.includeZero=t.includeZero),this.scales[e.id]=e}_loadEncoding(t,e){t.args.datatable&&(t.args.datatable=this.tables[t.args.datatable]),t.args.scale&&(t.args.scale=this.scales[t.args.scale]);let i=t.items.map((t=>e.getItem(t)));e._doEncode(i,t.args)}_createGuide(t,e){switch(e.type){case T.Axis:e.args.item&&(e.args.item=t.getItem(e.args.item)),t.axis(e.channel,e.field,e.args);break;case T.Legend:t.legend(e.channel,e.field,e.args);break;case T.Gridlines:e.args.item&&(e.args.item=t.getItem(e.args.item)),t.gridlines(e.channel,e.field,e.args)}}_processItem(t,e,i){switch(e.type){case T.Axis:{let t=e.classId?e.classId:e.id;e.args.tickValues&&e.args.isDate&&(e.args.tickValues=e.args.tickValues.map((t=>new Date(t)))),this.axes[t]=e;break}case T.Gridlines:e.args.values&&e.args.isDate&&(e.args.values=e.args.values.map((t=>new Date(t)))),this.gridlines.push(e);break;case T.Legend:this.legends.push(e);break;case T.Collection:{let s=i.collection();t.addChild(s),this._loadGroup(s,e,i);break}case T.Group:{let s=i.group();t.addChild(s),this._loadGroup(s,e,i);break}case T.Glyph:{let s=i.glyph();t.addChild(s),this._loadGroup(s,e,i);break}default:this._loadMark(t,e,i)}}_loadConstraint(t,e){switch(t.type){case"affixation":{let i=e.getItem(t.item),s=e.getItem(t.baseItem),n=new ie(i,s,e,t.channel,t.itemAnchor,t.baseAnchor,t.offset);return n.id=t.id,e.constraints[t.id]=n,n.apply(),n}case"alignment":{let i=t.items.map((t=>e.getItem(t))),s=new ee(i,t.direction);return s.id=t.id,e.constraints[t.id]=s,s.apply(),s}}}_loadDataScope(t){let e=new It(this.tables[t.dt]);for(let i in t.f2v)e._field2value[i]=t.f2v[i],e._updateTuples(i,t.f2v[i]);return e}_loadGroup(t,e,i){if(t.id=e.id,e.classId&&(t.classId=e.classId),e.dataScope&&(t.dataScope=this._loadDataScope(e.dataScope)),e.children)for(let s of e.children)this._processItem(t,s,i);if(e.layout){let i=this._loadLayout(e.layout);i.group=t,t._layout=i}e.bounds&&(t._bounds=new a(e.bounds.left,e.bounds.top,e.bounds.width,e.bounds.height))}_loadMark(t,e,i){if(e.args.fillColor&&"LinearGradient"===e.args.fillColor.type){let t=e.args.fillColor;e.args.fillColor=$c(t),e.args.fillColor.id=t.id,e.args.fillColor._stops=t.stops}"id"in e&&(e.args.id=e.id);let s=i.mark(e.type,e.args);if(e.classId&&(s.classId=e.classId),e.dataScope&&(s.dataScope=this._loadDataScope(e.dataScope)),e.vertices){const t=[];for(let i of e.vertices){const e=H.fromJSON(i,s);e.dataScope&&(e.dataScope=this._loadDataScope(e.dataScope)),t.push(e)}s.vertices=t,s.segments=[];for(let t=1;t<s.vertices.length;t++)s.segments.push(new $(s.vertices[t-1],s.vertices[t],s,s.segmentCounter++))}e.bounds&&(s._bounds=new a(e.bounds.left,e.bounds.top,e.bounds.width,e.bounds.height)),e.boundsOffsets&&(s.boundsOffsets=e.boundsOffsets),ft(s)?(s.vertexCounter=e.vertexCounter,s.segmentCounter=e.segmentCounter,s.curveMode=e.curveMode):e.type===T.Image&&(s.src=e.src,s.width=e.width,s.height=e.height,s.x=e.x,s.y=e.y),t.addChild(s)}_loadLayout(t){let e=Hc(t.type,t.args);switch(t.type){case y.Grid:e._left=t.left,e._top=t.top}return e}}class Be{constructor(){}async run(t){let e,i,s={},n={},r={};for(let a of t)switch(a.cmd){case"scene":e=Jc(a.args);break;case"data":i=await Kc(a.url),n[a.output]=i;break;case"transform":n[a.output]=n[a.input].transform(a.type,a.args);break;case"mark":s[a.output]=e.mark(a.type,a.args);break;case"glyph":s[a.output]=e.glyph(...a.input.map((t=>s[t])));break;case"attach":e.attach(s[a.input],n[a.data]);break;case"repeat":{let t=e.repeat(s[a.input],n[a.data],a.args);s[a.output]=t;break}case"divide":{let t=e.divide(s[a.input],n[a.data],a.args);s[a.output]=t;break}case"layout":s[a.input].layout=Hc(a.type,a.args);break;case"sortChildren":"field"in a.args?s[a.input].sortChildrenByData(a.args.field,a.args.reverse,a.args.order):"channel"in a.args&&s[a.input].sortChildren(a.args.channel,a.args.reverse);break;case"scale":{let t=Yc(a.type);t.id=a.id,t.domain="time"==a.type?a.domain.map((t=>new Date(t))):a.domain,t.range=a.range,t.clamp=a.clamp,t.isFlipped=a.isFlipped,"offset"in a&&(t.offset=a.offset),r[t.id]=t;break}case"encode":let t,o=a.input;if(o.indexOf("_v_")>0){let e=parseInt(o.split("_v_")[1]);t=s[o.split("_v_")[0]].vertices[e]}else if(o.indexOf("_v")>0);else if(o.indexOf("_s_")>0){let e=parseInt(o.split("_s_")[1]);t=s[o.split("_s_")[0]].segments[e]}else o.indexOf("_s")>0||(t=s[a.input]);a.scale&&r[a.scale]&&(a.args.scale=r[a.scale]),e.encode(t,a.args);break;case"constraint":switch(a.type){case E:e.affix(s[a.item],s[a.baseItem],a.channel,a.args)}break;case"axis":e.axis(a.channel,a.field,a.args);break;case"legend":e.legend(a.channel,a.field,a.args);break;case"gridlines":e.gridlines(a.channel,a.field,a.args)}return e}}let Le=Math.PI/180;class De{constructor(t){this._canvasId=t,this._doesCollectionHaveBounds=!1,this._app=new r.Application({antialias:!0,width:1600,height:1e3,view:document.getElementById(this._canvasId)}),this._app.renderer.autoResize=!0}render(t,e){let i=e||{};this._app.renderer.backgroundColor=Ge(t.fillColor?t.fillColor:"#fff"),this._doesCollectionHaveBounds=!!i.collectionBounds,this._app.stage.removeChildren(),this._app.renderer.clear();let s=this._renderItem(t);this._app.stage.addChild(s)}_renderItem(t){switch(t.type){case T.Ellipse:case T.LinearGradient:Ue("mark",t,G.FEATURE_NOT_IMPLEMENTED);break;case T.Circle:return this._renderCircle(t);case T.Pie:return this._renderArc(t);case T.Area:return this._renderArea(t);case T.Polygon:return this._renderPolygon(t);case T.Axis:return this._renderAxis(t);case T.Collection:return this._renderCollection(t);case T.Glyph:case T.Group:case T.Gridlines:case T.Legend:case T.Scene:return this._renderGroup(t);case T.Path:return this._renderPath(t);case T.Line:return this._renderLinearPath(t);case T.Rect:return this._renderRectangle(t);case T.PointText:return this._renderText(t);case T.Arc:return this._renderArc(t);case T.Image:return this._renderImage(t);case T.Link:return this._renderLink(t);case T.Ring:return this._renderRing(t);default:throw console.log(t.type),new Error(`Expect: itemType, Actual: ${t}\nWait that's illegal`)}}_renderRectangle(t){let e=new i.Graphics;return je(e,t.styles),e.lineStyle(t.styles.strokeWidth,Ge(t.styles.strokeColor)),qe(t.styles,e,t.height),e.drawRect(0,0,t.width,t.height),e.x=t.left,e.y=t.top,e.endFill(),e}_renderText(t){let e=new i.TextStyle({fontSize:t.styles.fontSize,fontFamily:t.styles.fontFamily,fontWeight:Ve(t.styles.fontWeight),fill:Ge(t.styles.fillColor)}),s=new r.Text(t.text,e),n=new i.Container;je(s,t.styles),s.x=t.x,s.y=t.y,s.anchor.set(...function(t){let e,i;switch(t[0]){case"left":e=0;break;case"center":e=.5;break;case"right":e=1;break;default:Ue("x anchor",t[0],G.UNKNOWN_ANCHOR)}switch(t[1]){case"hanging":case"top":i=0;break;case"central":case"middle":i=.5;break;case"bottom":i=1;break;default:Ue("y anchor",t[1],G.UNKNOWN_ANCHOR)}return[e,i]}(t.anchor)),n.addChild(s);let a=We(t._rotate);return n.pivot.set(a[0],a[1]),n.angle=ze(t._rotate),n.position.set(a[0],a[1]),n}_renderGroup(t){let e=new i.Container;for(const i of t.children){let t=this._renderItem(i);if(null==t)throw new Error;e.addChild(t)}return e}_renderAxis(t){let e=this._renderGroup(t),i=We(t._rotate);return e.pivot.set(i[0],i[1]),e.angle=ze(t._rotate),e.position.set(i[0],i[1]),e}_renderCollection(t){let e=new i.Container,s=this._renderGroup(t);if(e.addChild(s),!this._doesCollectionHaveBounds)return e;let n=new i.Graphics,r=0,a=t.bounds,o=a.left,h=a.right,l=a.top,c=a.bottom,d={strokeWidth:1,color:2018112,dashLength:5,dashSpacing:5};return r=u(o,h,l,r,d,n),r=u(l,c,-h,r,d,n),r=u(h,o,c,r,d,n),u(c,l,-o,r,d,n),e.addChild(n),e;function u(t,e,i,s,n,r){let a=t<=e?1:-1,o=s>=0?{point:t+s*a}:{point:t},h=i>0?[o,{point:i}]:[{point:-i},o];r.lineStyle({width:n.strokeWidth,color:n.color}),r.moveTo(h[0].point,h[1].point),o.point=s*a+t+n.dashLength*a,r.lineTo(h[0].point,h[1].point);let l=!1;for(o.point+=n.dashLength*a;o.point*a<=e*a;)l?(r.lineTo(h[0].point,h[1].point),l=!1,o.point+=n.dashSpacing*a):(r.moveTo(h[0].point,h[1].point),l=!0,o.point+=n.dashLength*a);return l?(i>0?r.lineTo(e,i):r.lineTo(-i,e),(e-o.point)*a):(o.point-e)*a}}_renderArea(t){switch(t.curveMode){case"linear":return this._renderPolygon(t);case"basis":return this._renderBezierArea(t);default:return Ue("areaPath",t,G.FEATURE_NOT_IMPLEMENTED)}}_renderBezierArea(t){let e=new i.Graphics;je(e,t.styles),e.lineStyle({width:t.styles.strokeWidth,color:Ge(t.styles.strokeColor)});let s=$e(t.getSVGPathData());return qe(t.styles,e,t.bounds.height),Ye(e,s),e.endFill(),e}_renderPolygon(t){let e=new r.Container,i=this._renderLinearPath(t);i.getChildAt(0).lineTo(t.vertices[0].x,t.vertices[0].y);let s=new r.Graphics;je(s,t.styles);let n=[];for(const e of t.vertices)n.push(e.x-t.bounds.left),n.push(e.y-t.bounds.top);return qe(t.styles,s,t.bounds.height),s.drawPolygon(n),s.x+=t.bounds.left,s.y+=t.bounds.top,s.endFill(),e.addChild(s),e.addChild(i),e}_renderPath(t){switch(t.curveMode){case"linear":return this._renderLinearPath(t);case"bumpX":case"natural":return this._renderBezierPath(t);default:Ue("path",t,G.FEATURE_NOT_IMPLEMENTED)}}_renderLinearPath(t){let e=new i.Container,s=new i.Graphics,n="none"==t.styles.strokeDash;je(s,t.styles);let r=t.vertices[0];if(s.lineStyle({width:t.styles.strokeWidth,color:Ge(t.styles.strokeColor)}),s.moveTo(r.x,r.y),n)for(let e=1;e<t.vertices.length;e++){const i=t.vertices[e];s.lineTo(i.x,i.y)}else!function(t,e,i){let s,n,r,a=0,o=0,h=e.split(" "),l=Number(h[0]),c=Number(h[1]);for(s=0;s<t.length&&(n=t[s],s!=t.length-1);s++){r=t[s+1];let e=r.x-n.x,h=r.y-n.y,d=Math.sqrt(e*e+h*h),u={x:e/d,y:h/d},f=0;for(i.moveTo(n.x+o*u.x,n.y+o*u.y);f<=d;)f+=o,f+=a>0?a:l,f>d?(a=f-d,f=d):a=0,i.lineTo(n.x+f*u.x,n.y+f*u.y),f+=c,f>d&&0==a?o=f-d:(o=0,i.moveTo(n.x+f*u.x,n.y+f*u.y))}}(t.vertices,t.styles.strokeDash,s);e.addChild(s);for(let i=0;i<t.vertices.length;i++){let s=t.vertices[i],n=this._renderVertex(s);null!=n&&e.addChild(n)}return e}_renderBezierPath(t){let e=new i.Container,s=new i.Graphics;je(s,t.styles),s.lineStyle({width:t.styles.strokeWidth,color:Ge(t.styles.strokeColor)}),Ye(s,$e(t.getSVGPathData())),e.addChild(s);for(let i=0;i<t.vertices.length;i++){let s=t.vertices[i],n=this._renderVertex(s);null!=n&&e.addChild(n)}return e}_renderVertex(t){switch(t.shape){case"rect":return function(t){let e=new r.Graphics;return e.lineStyle({width:t.strokeWidth,color:Ge(t.strokeColor)}),e.beginFill(Ge(t.fillColor)),e.drawRect(t.x-t.width/2,t.y-t.height/2,t.width,t.height),e.endFill(),e}(t);case"circle":return function(t){let e=new r.Graphics;return e.lineStyle({width:t.strokeWidth,color:Ge(t.strokeColor)}),e.beginFill(Ge(t.fillColor)),e.drawCircle(t.x,t.y,t.radius),e.endFill(),e}(t);case void 0:return null;default:Ue("vertex shape",t.shape,G.FEATURE_NOT_IMPLEMENTED)}}_renderCircle(t){let e=new i.Graphics;return je(e,t.styles),e.lineStyle(t.styles.strokeWidth,Ge(t.styles.strokeColor)),qe(t.styles,e,t.height),e.drawCircle(t.x,t.y,t.radius),e.endFill(),e}_renderRing(t){let e=new i.Graphics;return e.lineStyle(t.outerRadius-t.innerRadius,Ge(t.styles.fillColor)),e.drawCircle(t.x,t.y,(t.innerRadius+t.outerRadius)/2),e.endFill(),e}_renderArc(t){let e=new i.Graphics;return e.lineStyle({color:Ge(t.styles.strokeColor),width:t.styles.strokeWidth}),e.beginFill(Ge(t.styles.fillColor)),e.arc(t.x,t.y,t.outerRadius,-t.endAngle*Le,-t.startAngle*Le),e.arc(t.x,t.y,t.innerRadius,-t.startAngle*Le,-t.endAngle*Le,!0),e.endFill(),e}_renderImage(t){let e=r.Sprite.from(t.src);return e.x=t.x,e.y=t.y,e.width=t.width,e.height=t.height,e}_renderLink(t){switch(t.curveMode){case"linear":return function(t){let e=new i.Graphics;return je(e,t.styles),e.lineStyle({color:Ge(t.styles.strokeColor),width:t.styles.strokeWidth}),Ye(e,$e(t.getSVGPathData())),e}(t);default:Ue("link",t.curveMode,"unexpected curvemode")}}}function je(t,e){t.visible=function(t){switch(t){case"hidden":return!1;case null:case void 0:case"visible":default:return!0}}(e.visibility),t.alpha=function(t){switch(t){case void 0:case null:return 1;default:return t}}(e.opacity)}function Ve(t){switch(t){case"regular":case"normal":return"normal";case"bold":return"bold";default:console.log(t),Ue("font weight",t,G.FEATURE_NOT_IMPLEMENTED)}}function Ge(t){let e=n.color(t);if(null==e)return null;{let t=e.formatHex();return r.utils.string2hex(t)}}function ze(t){return void 0===t||"number"!=typeof t[0]?0:t[0]}function We(t){return void 0===t||"number"!=typeof t[0]?[0,0]:t.slice(1)}function Ue(t,e,i){throw console.log(e),new Error(`${i}. Source: ${t}, Actual: `)}function qe(t,e,i){let s=t.fillColor;if("none"==s)return;let n=Ge(s);null!=n?e.beginFill(n):e.beginTextureFill({color:16777215,texture:Je(i,s.stops,s.y1>s.y2)})}function Je(t,e,i){const s=document.createElement("canvas");s.height=t,s.width=1;const n=s.getContext("2d"),a=n.createLinearGradient(0,0,0,t);for(let t=0;t<e.length;t++)i?a.addColorStop(1-e[t].offset/100,e[t].color):a.addColorStop(e[t].offset/100,e[t].color);return n.fillStyle=a,n.fillRect(0,0,1,t),r.Texture.from(s)}function Ye(t,e){let i=e.pop(),s=()=>{};"Z"==i.code.toUpperCase()?s=()=>t.lineTo(e[0].end.x,e[0].end.y):e.push(i);for(const i of e)He(i,t);s()}function He(t,e){switch(t.code.toUpperCase()){case"M":e.moveTo(t.end.x,t.end.y);break;case"L":e.lineTo(t.end.x,t.end.y);break;case"Q":e.bezierCurveTo(t.cp1.x,t.cp1.y,t.cp1.x,t.cp1.y,t.end.x,t.end.y);break;case"C":e.bezierCurveTo(t.cp1.x,t.cp1.y,t.cp2.x,t.cp2.y,t.end.x,t.end.y);break;case"Z":throw new Error('Unexpected "z" marker. There\'s something wrong, I can feel it');default:return Ue("data",t,G.FEATURE_NOT_IMPLEMENTED)}}function $e(t){let e={command:/\s*([achlmqstvz])/gi,number:/\s*([+-]?\d*\.?\d+(?:e[+-]?\d+)?)/gi,comma:/\s*(?:(,)|\s)/g,flag:/\s*([01])/g},i={number:function(t){return+a("number",t)},"coordinate pair":function(t){let e=a("number",t);return null!==e||t?(a("comma"),{x:+e,y:+a("number",!0)}):null},"arc definition":function(t){let e=i["coordinate pair"](t);if(!e&&!t)return null;a("comma");let s=+a("number",!0);a("comma",!0);let n=!!+a("flag",!0);a("comma");let r=!!+a("flag",!0);return a("comma"),{radii:e,rotation:s,large:n,clockwise:r,end:i["coordinate pair"](!0)}}},s=0,n=[];for(;s<t.length;){let t,e=a("command"),i=e.toUpperCase(),h=e!==i;switch(i){case"M":t=o("coordinate pair").map((function(t,i){return 1===i&&(e=h?"l":"L"),r({end:t},e,h)}));break;case"L":case"T":t=o("coordinate pair").map((function(t){return r({end:t},e,h)}));break;case"C":if(t=o("coordinate pair"),t.length%3)throw Error("Expected coordinate pair triplet at position "+s);t=t.reduce((function(t,i,s){let n=s%3;if(n){t[t.length-1][1===n?"cp2":"end"]=i}else t.push(r({cp1:i},e,h));return t}),[]);break;case"Q":case"S":if(t=o("coordinate pair"),1&t.length)throw Error("Expected coordinate pair couple at position "+s);t=t.reduce((function(t,i,s){if(1&s){t[t.length-1].end=i}else t.push(r({cp:i},e,h));return t}),[]);break;case"H":case"V":t=o("number").map((function(t){return r({value:t},e,h)}));break;case"A":t=o("arc definition").map(r,e,h);break;case"Z":t=[{code:"Z"}]}n.push.apply(n,t)}return n;function r(t,e,i){return t.code=e,t.relative=i,t}function a(i,n){e[i].lastIndex=s;let r=e[i].exec(t);if(!r||r.index!==s){if(!n)return null;throw Error("Expected "+i+" at position "+s)}return s=e[i].lastIndex,r[1]}function o(t){let e,s=[],n=!0;for(;null!==(e=i[t](n));)s.push(e),n=!!a("comma");return s}}var Ze="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function Ke(t,e){return t(e={exports:{}},e.exports),e.exports}var Xe=function(){this.__data__=[],this.size=0};var Qe=function(t,e){return t===e||t!=t&&e!=e};var ti=function(t,e){for(var i=t.length;i--;)if(Qe(t[i][0],e))return i;return-1},ei=Array.prototype.splice;var ii=function(t){var e=this.__data__,i=ti(e,t);return!(i<0)&&(i==e.length-1?e.pop():ei.call(e,i,1),--this.size,!0)};var si=function(t){var e=this.__data__,i=ti(e,t);return i<0?void 0:e[i][1]};var ni=function(t){return ti(this.__data__,t)>-1};var ri=function(t,e){var i=this.__data__,s=ti(i,t);return s<0?(++this.size,i.push([t,e])):i[s][1]=e,this};function ai(t){var e=-1,i=null==t?0:t.length;for(this.clear();++e<i;){var s=t[e];this.set(s[0],s[1])}}ai.prototype.clear=Xe,ai.prototype.delete=ii,ai.prototype.get=si,ai.prototype.has=ni,ai.prototype.set=ri;var oi=ai;var hi=function(){this.__data__=new oi,this.size=0};var li=function(t){var e=this.__data__,i=e.delete(t);return this.size=e.size,i};var ci=function(t){return this.__data__.get(t)};var di=function(t){return this.__data__.has(t)},ui="object"==typeof Ze&&Ze&&Ze.Object===Object&&Ze,fi="object"==typeof self&&self&&self.Object===Object&&self,pi=ui||fi||Function("return this")(),gi=pi.Symbol,_i=Object.prototype,mi=_i.hasOwnProperty,yi=_i.toString,vi=gi?gi.toStringTag:void 0;var bi=
|
|
5
5
|
/**
|